akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const double PI = 3.1415926535897932384626433832795;
const int mod = 1000000007;
const int INF = 1001001001;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  int n, k;
  cin >> n >> k;
  ll l = 0, r = 0;
  for(int i = 0; i <= n; ++i) {
    l += i;
  }
  r = l;

  mint ans = 0;
  for(int i = n + 1; i >= k; --i) {
    ans += r - l + 1;
    r -= (n - (i - 1));
    l -= i - 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
using namespace std;
int INF = 1001001001;

int main(){
	int x;
	cin >> x;
	int a,b;
	a = x/100;
	b = x%100;
	if(a*5 >=b){
		cout << 1 << endl;
	}else cout << 0 << endl;
	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef int64_t  ll;

int main () {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p.at(i);
  sort(p.begin(), p.end());
  int ans = 0;
  rep(i, k) ans += p.at(i);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int DN=1e5+5;
int n,M,f,g,viz[DN],dp[DN],z[DN],rez[DN],pr[DN];
vector<int>v[DN];
void dfs(int nod)
{
    viz[nod]=1;
    dp[nod]=1;
    for(auto i:v[nod])
        if(i!=pr[nod])
    {
        pr[i]=nod;
        dfs(i);
        dp[nod]=(1LL*dp[nod]*(dp[i]+1))%M;
    }
}
void dfs2(int nod)
{
  //  cout<<nod<<'\n';
    z[nod]=(z[nod]+1)%M;
    rez[nod]=(1LL*dp[nod]*z[nod])%M;
    viz[nod]=1;
    f=z[nod];
    for(auto i:v[nod])
        if(i!=pr[nod])
    {
        z[i]=f;
        f=(1LL*f*(dp[i]+1))%M;
    }
    reverse(v[nod].begin(),v[nod].end());
    f=1;
    for(auto i:v[nod])
    if(i!=pr[nod])
    {
        z[i]=(1LL*z[i]*f)%M;
        f=(1LL*f*(dp[i]+1))%M;
    }
    for(auto i:v[nod])
    if(i!=pr[nod])
        dfs2(i);
}
int main()
{
    cin>>n>>M;
    for(int i=1;i<n;i++)
    {
        cin>>f>>g;
        v[f].pb(g);
        v[g].pb(f);
    }
    dfs(1);
    for(int i=1;i<=n;i++)
        viz[i]=0;
    dfs2(1);
    for(int i=1;i<=n;i++)
        cout<<rez[i]<<'\n';
}


Measured memory_bytes: 11904
n = int(input())
nums = list(map(int, input().split()))

num_dvd = 0
 
can_devide = True
temp_list = []
while can_devide:
  for num in nums:
    if num % 2 == 1:
      can_devide = False
      print(num_dvd)
      break
    else:
      temp_list.append(num // 2)
  num_dvd += 1
  nums, temp_list = temp_list, []

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

int n, m;
string a[55], b[55];
int main(void){
	cin >> n >> m;
	rep(i, n) cin >> a[i];
	rep(i, m) cin >> b[i];
	if(n < m){
		printf("No\n");
		return 0;
	}else{
		rep(y, n - m + 1)rep(x, n - m + 1){
			bool flag = true;
			rep(i, m){
				rep(j, m){
					if(a[i + y][j + x] != b[i][j]){
						flag = false;
						break;
					}
				}
				if(!flag) break;
			}
			if(flag){
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> X(M),Y(M);
  for(int i=0;i<M;i++){
    cin >> X.at(i) >> Y.at(i);
  }
  vector<bool> red(N,false);
  red.at(0)=true;
  vector<int> num(N,1);
  for(int i=0;i<M;i++){
    num.at(X.at(i)-1)--;
    num.at(Y.at(i)-1)++;
    if(red.at(X.at(i)-1)){
      red.at(Y.at(i)-1)=true;
    }
    if(num.at(X.at(i)-1)==0){
      red.at(X.at(i)-1)=false;
    }
  }
  int count=0;
  for(int i=0;i<N;i++){
    if(red.at(i)){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 4432
import numpy as np
N, M = [int(x) for x in input().split()]
H = [float(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for _ in range(M)]

max_h = [0 for _ in range(N)]

for A, B in AB:
  max_h[A-1] = max(max_h[A-1], H[B-1])
  max_h[B-1] = max(max_h[B-1], H[A-1])

ans = 0
for i in range(N):
  if(H[i]>max_h[i]):
    ans += 1
print(ans)

Measured memory_bytes: 48872
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String s = sc.next();

		int cnt0 = 0;
		int cnt1 = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == '0') cnt0++;
			else cnt1++;
		}

		System.out.println(Math.min(cnt0, cnt1) * 2);
	}

}


Measured memory_bytes: 26872
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl
#define isort(a) sort(a.begin(),a.end())

using namespace std;

#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

typedef pair<ll,ll> Pair;
const ll inf =1000000007;

void dsolve(){
    ll x;
    cin >> x;
    ll a,b;
    for(ll i=1;i<=2000;i++){
        for(ll j=-2000;j<2000;j++){
            ll score=pow(i,5)-pow(j,5);
            if(score==x){
                a=i;
                b=j;
                break;
            }
        }
    }
    cout << a <<" "<< b<< endl;
}

void bsolve(){
    ll n,k;
    cin >> n >>k;
    ll w[n];
    rep(i,n) w[i]=0;
    rep(i,k){
        ll d;
        cin>>d;
        rep(j,d){
            ll a;
            cin >>a;
            a--;
            w[a]++;
        }
    }
    ll ans=0;
    rep(i,n){
        if(w[i]==0){
            ans++;
            //kaku(i);
        }
    }
    kaku(ans);
}

void asolve(){
    string s;
    cin >>s;
    if(s=="ABC"){
        cout <<"ARC" << endl;
    }
    else{
        cout <<"ABC" << endl;
    }
}

void csolve(){
    ll n,m;
    cin >> n >>m;
    ll h[n];
    rep(i,n) cin >> h[i];
    vector<ll> g[n];
    Pair ma[n];
    rep(i,n) ma[i]=make(h[i],1);
    rep(i,m){
        ll a,b;
        cin >>a >>b;
        a--;b--;
        g[a].pb(b);
        g[b].pb(a);
        if(ma[a].first<h[b]) ma[a]=make(h[b],1);
        else if(ma[a].first==h[b]) ma[a]=make(h[b],0);
        if(ma[b].first<h[a]) ma[b]=make(h[a],1);
        else if(ma[b].first==h[a]) ma[b]=make(h[a],0);
    }
    ll ans=0;
    for(ll i=0;i<n;i++){
        if(ma[i].first==h[i]&& ma[i].second==1) ans++;
    }
    kaku(ans);
}
int main() {
   dsolve();
}






Measured memory_bytes: 4236
# include <bits/stdc++.h>
//# pragma GCC optimize("Ofast")
# define pb push_back
# define ll long long
# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define forn(i, n) for (int i = 0; i < int(n); i++)
# define ford(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define fore(i, l, r) for (int i = int(l); i < int(r); i++)
# define fors(i, s) for (int i = 0; s[i]; i++)
# define in freopen("input.txt", "r", stdin)
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
  
using namespace std;
  
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 7;
 
int n, a[N], cnt = 1;

int main()
{      
	speed;
	cin >> n;
	forn( i, n ) {
		cin >> a[i];
		if ( a[i] == cnt ) {
			cnt++;
		}
	}
	if ( cnt == 1 ) {
		cout << -1;
		return 0;
	}
	cout << n - cnt + 1 << endl;
	time; 
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
using ping = pair<ll, ll>;

int main(){
    ll N, M;
    cin >> N>>M;
    vector<ping> S(N);
    for (int i = 0; i < N; i++) cin >> S[i].first >> S[i].second;
    sort(S.begin(), S.end());

    ll price = 0, num = 0;
    for (int i = 0; i<N; i++){
      for (int j = 1; j <= S[i].second; j++){
        num++;
        if(num==M || j==S[i].second){
          price += S[i].first * j;
          break;
        }
      }
      if (num == M) break;
    }
    cout << price << endl;
    return 0;
}

Measured memory_bytes: 4852
import java.lang.*;
import java.util.*;
public class Main 
{
    ///atcoder
    public static void main(final String args[]) 
    {
        final Scanner s = new Scanner(System.in);
        int n=s.nextInt();
        int m=s.nextInt();
        int a,sum=0;
        for(int i=0;i<m;i++)
        {
            a=s.nextInt();
            sum=sum+a;
        }
        if(sum<=n)
        {
            System.out.println(n-sum);
        }
        else
        {
            System.out.println("-1");
        }
    }
}

Measured memory_bytes: 39112
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,m=LI()
  return abs((m-2)*(n-2))

print(main())


Measured memory_bytes: 6432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, begin, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string S;
    cin >> S;
    sort(all(S));
    if ((S.at(0) == S.at(1)) && (S.at(2) == S.at(3)) && (S.at(1) != S.at(3)))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
using namespace std;

int main() {
	int a[9],b[9],d,e;
	string c[9];
	for(int i=0;i<9;i++){
		cin>>c[i]>>a[i]>>b[i];
	}
	for(int i=0;i<9;i++){
		d=a[i]+b[i];
		e=a[i]*200+b[i]*300;
		cout<<c[i]<<" "<<d<<" "<<e<<endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3024
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"

int main() {

    FAST_IO;

    int k, x;
    cin >> k >> x;

    if (k*500 >= x) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define pb push_back
using namespace std;
typedef long long ll;

class UnionFind {
  // まとめる 判定 サイズを知る
 public:
  // Aから見た親の番号を格納する。rootだったら-1*その集合のサイズ。
  vector<int> Parent;

  // 初期化
  UnionFind(int N) {
    Parent = vector<int>(N, -1);
  }

  // Aのrootを調べる
  int root(int A) {
    if (Parent[A] < 0) return A;  // マイナスならそれはroot
    return Parent[A] = root(Parent[A]);
  }

  // rootの値をプラスに戻して返す(サイズ)
  int size(int A) {
    return -Parent[root(A)];
  }

  // くっつける関数
  bool connect(int A, int B) {
    // AとBのroot同士をくっつける
    A = root(A);  // ここのAは、"rootの場所"の意味
    B = root(B);
    if (A == B) return false;  // 既にくっついている
    if (size(A) < size(B))
      swap(A, B);            // 大きい方にくっつけるために中身交換
    Parent[A] += Parent[B];  // 中身更新
    Parent[B] = A;
    return true;
  }
};

const ll mod = 1e9 + 7;
int main() {
    int n, m;
    cin >> n >> m;
    
    UnionFind tree(n);

    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        tree.connect(a, b);
    }
    int ans = 0;
    rep(i,n){
        ans = max(ans, tree.size(i));
    }
    cout <<ans<<endl;
}

Measured memory_bytes: 4048
#include<cstdio>
#include<vector>
#include<algorithm>
//#include<numeric>
#include<functional>
//#include<deque>
//#include<string>
//#include<iostream>

using namespace std;
const int one = 1;
const int big = (one<<30);
typedef long long int llint;
//11:10～13:00
int main(void){
	int N,C,K,a,i,ans=0,minwait=0,waitN=0;//C人までの人、Kまでの時間,ans=答え,
	//minwait=待ってる人の中で一番早い人,waitN=人数
	vector<int> T;
	scanf("%d %d %d",&N,&C,&K);
	for(i=0;i<N;i++){
		scanf("%d",&a);
		T.push_back(a);
	}
	sort(T.begin(),T.end());//Tをソート
	minwait=T[0];
	for(i=0;i<N;i++){
		if(minwait+K<T[i]||waitN>=C){
			ans++;
			minwait=T[i];
			waitN=1;
		} else{
			waitN++;
		}
	}
	ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <tuple>

using namespace std;

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define cina(s, n, a) for(int i = s; i < n; i++) cin >> a[i]
#define couta(n, a) for(int i = 0; i < n; i++) cout << a[i] << ' '
#define copy(s, n, a, b) for(int i = s; i < n; i++) b[i] = a[i]
#define yesno(ok) cout << (ok ? "Yes" : "No")
#define mod(a, b) (b + (a % b)) % b
#define MOD  (ll)1e9 + 7
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<pii> vpii;

void solve(){
    ll n, k;
    cin >> n >> k;
    vi a(n);
    cina(0, n, a);
    sort(all(a));
    ll ans = 0;
    for(int i = 0; i < n - k; i++){
        ans += a[i];
    }
    cout << ans;
}

int main(){
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int q = 1;
    //cin >> q;
    for(int i = 1; i <= q; i++){
        solve();
    }
}


Measured memory_bytes: 1024
def main():

    S = int(input())
    mod = pow(10, 9) + 7

    if S < 3: return 0

    g1 = [1, 1]
    g2 = [1, 1]
    inv = [0, 1]

    for i in range(2, S+1):
        g1.append((g1[-1] * i) % mod)
        inv.append( ( -inv[mod % i] * (mod//i)) % mod )
        g2.append((g2[-1] * inv[-1]) % mod)

    def combi(n, r):
      r = min(r, n-r)
      return g1[n]*g2[r]*g2[n-r]%mod

    ans = 1
    for i in range(2, S//3 + 1):
        v = S - 3*i + i-1
        if v > 0:
            u = combi(v, i-1)
            ans += u
            ans %= mod
    return ans

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 65104
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

bool valid(string s) {
	int a = 0;
	rep(i, 0, s.size()) {
		if (s[i] == '(')a++;
		else if (s[i] == ')')a--;
		if (a < 0)return false;
	}
	return true;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	string s;
	cin >> N >> s;

	string ans = s;
	bool flag = true;
	while (flag) {
		dump(ans);
		flag = false;
		int a = 0;
		rep(i, 0, ans.size()) {
			if (ans[i] == '(')a++;
			else if (ans[i] == ')')a--;
			if (a < 0) {
				ans = "(" + ans;
				flag = true;
				break;
			}
		}
	}

	flag = true;
	while (flag) {
		dump(ans);
		flag = false;
		int a = 0;
		rrep(i, 0, ans.size()) {
			if (ans[i] == '(')a++;
			else if (ans[i] == ')')a--;
			if (a > 0) {
				ans = ans + ")";
				flag = true;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    int n;
    cin >> n;
    int t = 0, x = 0, y = 0;
    for (int i = 0; i < n; ++i) {
        int tt, xx, yy;
        scanf("%d %d %d", &tt, &xx, &yy);
        if((((tt-t)-(xx-x)-(yy-y))%2) || ((tt-t)-abs(xx-x)-abs(yy-y) < 0)) {
            cout << "No" << "\n";
            return 0;
        }
        t = tt, x = xx, y = yy;
    }
    cout << "Yes" << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map> // pair
using namespace std;

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
#define dpair pair<double,double>

template <typename Val>
Val gcd(Val a, Val b) {
//use ll or int for gcd
    if (b==0) return a;
    else return gcd(b, a%b);
}
template <typename Val>
Val vec_max(vector<Val> v){
  return *max_element(v.begin(),v.end());
}
template <typename Val>
Val vec_min(vector<Val> v){
  return *min_element(v.begin(),v.end());
}
template <typename Val>
void show_vec(vector<Val> *v){
  cout<<endl;
  rep(i,v->size()){
    cout<<v->at(i)<<" ";
  }
  cout<<endl;
}
//---------------------------------------------------------------
int main(){

  int A,B;
  cin>>A>>B;

  cout<<A*B<<endl;




}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;

int main()
{
 int a1,a2,a3;
  cin >> a1 >> a2 >> a3;
  
  if (a1+a2+a3 >= 22)
    cout << "bust" << endl;
  else
    cout << "win" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 100005
#define ALL(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)


using namespace std;


int32_t main()
{
    IOS;

    int tt=1;
	//cin >> tt;
	while (tt--)
	{
		int n; cin >> n;
		string s; cin >> s;
		vector<vector<int>> v(3);
		for (int i = 0; i < n; i++)
		{
			if(s[i] == 'R') v[0].EB(i);
			else if(s[i] == 'G') v[1].EB(i);
			else v[2].EB(i);
		}
		int ans = 1;
		for (int i = 0; i < 3; i++)
		{
			ans *=v[i].size();
		}
		for (int i = 0; i < n; i++)
		{
			for(int j = 1; i + 2*j < n; j++)
			{
				if(s[i] == s[i + j]) continue;
				if(s[i] == s[i + 2*j]) continue;
				if(s[i + j] == s[i + 2*j]) continue;
				ans--;
			}
		}
		
		cout << max(ans,0LL);
		
	}
    return 0;
}


Measured memory_bytes: 3728
#include <iostream>
using namespace std;

int main(){
  int H, W, N;
  int a, b;
  cin >> H >> W >> N;
  a = N / H;
  b = N / W;
  if(a >= b){
    if((N % W) != 0){
      cout << b + 1;
    }
    if((N % W) == 0){
      cout << b;
    }
  } 
  if(a < b){ 
    if((N % H) != 0){
      cout << a + 1;
    }
    if((N % H) == 0){
      cout << a;
    }
  }

  return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int H, W; cin >> H >> W; 
	int INF = 1145141919; 
	char C[110][110] = {}; 
	for(int i = 0; i < 110; i++){
		for(int j = 0; j < 110; j++){
			C[i][j] = '.'; 
		}
	}
	for(int i = 1; i <= H; i++){
		for(int j = 1; j <= W; j++){
			cin >> C[i][j]; 
		}
	}
	deque<pair<int, int>> que; 
	que.push_front(make_pair(0, 1)); 
	int D[110][110] = {}; 
	for(int i = 1; i <= H+1; i++){
		for(int j = 1; j <= W+1; j++){
			D[i][j] = INF; 
		}
	}
	D[0][1] = 0; 
	while(que.size()){
		pair<int, int> p = que.front(); que.pop_front(); 
		int i = p.first; int j = p.second; 
		if(i < H && D[i+1][j] == INF && C[i+1][j] != C[i][j]){
			D[i+1][j] = D[i][j] + 1; que.push_back(make_pair(i+1, j)); 
		}
		else if(i < H && D[i+1][j] == INF){
			D[i+1][j] = D[i][j]; que.push_front(make_pair(i+1, j)); 
		}
		if(j < W && D[i][j+1] == INF && C[i][j+1] != C[i][j]){
			D[i][j+1] = D[i][j] + 1; que.push_back(make_pair(i, j+1)); 
		}
		else if(j < W && D[i][j+1] == INF){
			D[i][j+1] = D[i][j]; que.push_front(make_pair(i, j+1)); 
		}
		if(i == 0 && j == 1){
			if(C[1][1] != C[0][1]){
				D[i+1][j] = D[i][j] + 1; que.push_back(make_pair(i+1, j)); 
			}
			else{
				D[i+1][j] = D[i][j]; que.push_front(make_pair(i+1, j)); 
			}
		}
		if(i == H && j == W){
			if(C[H+1][W] != C[H][W]){
				D[i+1][j] = D[i][j] + 1; que.push_back(make_pair(i+1, j)); 
			}
			else{
				D[i+1][j] = D[i][j]; que.push_front(make_pair(i+1, j)); 
			}
		}
	}
	cout << (D[H+1][W] + 1) / 2 << endl; 
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];
#define vll(a,n) vll a(n); rep(i, n) cin >> a[i];
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int n, m; cin >> n >> m;
    string a[n], b[m];
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];

    rep(i, n-m+1){
        rep(j, n-m+1){
            bool flg = true;
            rep(k, m) rep(l, m){
                if(a[i+k][j+l] != b[k][l]) flg = false;
            }
            if(flg) {pr("Yes"); return 0;}
        }
    }

    pr("No");
    return 0;}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef pair<int, int> P;

const long double EPS = 1e-10;
const long long INF = 1e18;
const int MOD = (int)1e9 + 7;
const long double PI = acos(-1.0L);

vector<long long> enum_divisors(long long N) {
  vector<long long> res;
  for (long long i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      res.push_back(i);
      // 重複しないならば i の相方である N/i も push
      if (N / i != i) res.push_back(N / i);
    }
  }
  // 小さい順に並び替える
  sort(res.begin(), res.end());
  return res;
}

int calc_digit(long long N) {
  int res = 0;
  while (N) {
    res++;
    N /= 10;
  }
  return res;
}

int main() {  // TODO
  ll n;
  cin >> n;
  int ans = 1e9;
  for (ll a = 1; a * a <= n; a++) {
    if (n % a == 0) {
      ll b = n / a;
      ans = min(ans, (max(calc_digit(a), calc_digit(b))));
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;


int main(){
    int n;cin>>n;
    vector<pair<int,int>>pairs(n);
    for(int i = 0;i<n;i++){
        int x,y;cin>>x>>y;
        //期限が早いもの順にソート
        pairs[i]=make_pair(y,x);
    }

    sort(pairs.begin(),pairs.end());
    ll count = 0;
    int x = 0;
    rep(i,n){
        count+=pairs[i].second;
        x = pairs[i].first;

        if(pairs[i].first<count){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;

}


Measured memory_bytes: 4828
a = input()
b = input()
dp = [[0 for j in range(len(b)+1)] for i in range(len(a)+1)]
for i in range(1, len(a)+1):
    for j in range(1, len(b)+1):
        if a[i-1] == b[j-1] :
            dp[i][j] = dp[i-1][j-1] + 1
            continue
        dp[i][j] = max(dp[i-1][j], dp[i][j-1])
m = dp[-1][-1]
ans = ''
i,j=-1,-1
while(len(ans)<m):
    if a[i] == b[j]:
        ans = a[i] + ans
        i-=1
        j-=1
    elif dp[i-1][j] > dp[i][j-1]:
        i-=1
    else:
        j-=1
print(ans)

Measured memory_bytes: 153056
s = input()
bool = True
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] != 'R' and s[i] != 'U' and s[i] != 'D':
            bool = False
    else:
        if s[i] != 'L' and s[i] != 'U' and s[i] != 'D':
            bool = False
if bool:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9088
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
const ll T = 1e9+7;
int main(){
        ll n;
        cin >> n;
        string str;
        cin >> str;
        ll c[26]={};
        for(int i=0;i<n;i++){
                c[str[i]-'a']++;
        }
        ll ans = 1;
        for(int i=0;i<26;i++){
                ans *= c[i]+1;
                ans %= T;
        }
        ans--;
        ans %= T;
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long int
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define mp make_pair
#define inputv(a) forall(i,0,a.size()) cin>>a[i]
#define outputv(a) for(auto i:a) cout<<i<<" ";br;
#define fs first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define minv(a) *min_element(all(a))
#define maxv(a) *max_element(all(a))
#define br cout<<"\n"
using namespace std;


int dr[]={1,-1,0,0};
int dc[]={0,0,1,-1};
ll mod=1000000007;
ll po(ll x,ll n){
    ll res = 1;
    while(n>0){
        if(n%2==1)
            res = ((res)*(x))%mod;
        x = (x*x)%mod;
        n = n/2;
    }
    return res%mod;
}
ll ceil(ll x,ll y)
{
    if(x%y==0)
        return x/y;
    else
        return(x/y)+1;
}
ll binomialCoeff(int n, int k)
{
    ll res = 1;
    if (k > n - k)
        k = n - k;

    for (int i = 0; i < k; ++i) {
        res *= (n - i);
        res /= (i + 1);
    }

    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;

    vector<ll> ans(n+1,0);
    for(ll i=1;i<=sqrt(n);i++)
    {
        for(ll j=1;j<=sqrt(n);j++)
        {
            for(ll k=1;k<=sqrt(n);k++)
            {
                ll tmp=i*i+j*j+k*k+i*j+j*k+i*k;
                if(tmp<=n)
                    ans[tmp]++;
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        cout<<ans[i];
        br;
    }
	return 0;
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#include<string.h>
#define inf 1000000000000000000
#define maxn 1000001
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
#define endl '\n'
#define mapint_iterator map<int,int> :: iterator
#define mapll_iterator map<ll,ll> :: iterator
#define setint_iterator set<int> :: iterator
#define setll_iterator set<ll> :: iterator
#define setpint_iterator set<pint> :: iterator
#define setpll_iterator set<pll> :: iterator
#define trace(x) cout<<#x<<": "<<x<<" "<<endl
#define trace2(x,y) cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x,y,z) cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a,b,c,d) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define cout1(a) cout<<a<<endl
#define cout2(a,b) cout<<a<<" "<<b<<endl
#define cout3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define cout4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl
#define vcout(v,i) cout<<v[i].fi<<" "<<v[i].se<<endl
typedef priority_queue<ll,vector<ll>,greater<ll> > pqset;
typedef priority_queue<pint,vector<pint>,greater<pint> > pqset_ll;
#define pb push_back
#define fi first
#define se second
#include<ext/pb_ds/assoc_container.hpp>
ll dxk[]={0,0,1,-1,1,1,-1,-1};
ll dyk[]={1,-1,0,0,1,-1,1,-1};
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pll,null_type,less<pll>,rb_tree_tag,tree_order_statistics_node_update> os_pair;
#define mp make_pair
#define acc (ios::sync_with_stdio(false),cin.tie(0))
#define rep(i,n) for(ll i=0;i<n;i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define per1(i,n) for(ll i=n;i>0;i--)
#define repeat(i,start,n) for(ll i=start;i<n;i++)
#define print(a,n) for(ll i=0;i<n;i++){ cout<<a[i]<<" ";}
ll ll_max(ll a,ll b,ll c){return max(a,max(b,c));}
int int_max(int a,int b,int c){return max(a,max(b,c));}
ll ll_min(ll a,ll b,ll c){return min(a,min(b,c));}
int int_min(int a,int b,int c){return min(a,min(b,c));}
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);} 
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}
//ifstream cin("b_read_on.txt"); ofstream cout("output3.txt");
//Chronology: Binary Search,Greedy,dp,dfs and similar
//Use (<<) for multiplication
//Use (>>) for division
// In dp, first try top-down,then bottom-up
//ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout<<fixed;cerr.tie(NULL);cout.precision(10);
// find_by_order -> value at index
// order_of_key -> index of value
void solve(int countu){
	ll x;
	ll sum=0;
	cin>>x;
	sum+=1000*(x/500);
	x-=(x/500)*500;
	sum+=(x/5)*5;
	cout1(sum);
}
int main(){
    int t=1;
	//cin>>t;
	int countu=1;
    while(t--){
    	solve(countu);
    	countu++;
    }
}

Measured memory_bytes: 256
N = gets.to_i
MOD = 10**9 + 7

def f(s, x)
  return 1 if s == 0
  @m ||= {}
  @m[[s, x]] ||= (f(s/2, x/2) + f((s - 1)/2, (x - 1)/2) + (s >= 2 ? f((s - 2)/2, x/2) : 0)) % MOD
end

puts f(N, N)

Measured memory_bytes: 1788
n = int(input())
print("{}:".format(n), end='')
x = int(pow(n, 0.5))+1
for i in range(2, x):
    while n % i == 0:
        print(" {}".format(i), end='')
        n //= i
print(' {}'.format(n) if n != 1 else '')

Measured memory_bytes: 7748
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int A, B, C, D, E; char CH;
	while (cin >> A >> CH >> B >> CH >> C >> CH >> D >> CH >> E) {
		VI a = { A,B,C,D,E };
		VI cnt(9);
		SORT(a);
		int i = 0;
		while (i < 5) {
			int elem = a[i], Cnt = 0;
			while (i < 5 && a[i] == elem) { Cnt++; i++; }
			cnt[Cnt]++;
		}

		//check
		int ans = -1;
		if (cnt[4] == 1)ans = 7;
		else if (cnt[3] == 1 && cnt[2] == 1)ans = 6;
		else {
			bool flag = false;
			if (a[0] + 1 == a[1] && a[1] + 1 == a[2] && a[2] + 1 == a[3] && a[3] + 1 == a[4])flag = true;
			else if (a[0] == 1 && a[1] == 10 && a[2] == 11 && a[3] == 12 && a[4] == 13)flag = true;
			if (flag)ans = 5;
		}

		if (ans == -1) {
			if (cnt[3] == 1)ans = 4;
			else if (cnt[2] == 2)ans = 3;
			else if (cnt[2] == 1)ans = 2;
			else ans = 1;
		}

		string str;
		switch (ans) {
		case 1:
			str = "null";
			break;
		case 2:
			str = "one pair";
			break;
		case 3:
			str = "two pair";
			break;
		case 4:
			str = "three card";
			break;
		case 5:
			str = "straight";
			break;
		case 6:
			str = "full house";
			break;
		case 7:
			str = "four card";
			break;
		}

		cout << str << endl;
	}
}


Measured memory_bytes: 3104
#include <bits/stdc++.h> 

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N;
  cin>>N;
  vector<int>t(N),x(N),y(N);
  for(int i=0;i<N;i++)cin>>t[i]>>x[i]>>y[i];

  int nx=0,ny=0;
  for(int i=0;i<N;i++){
    int d=abs(nx-x[i])+abs(ny-y[i]);
    int T;
    if(i==0)T=t[i];
    else T=t[i]-t[i-1];
    if(d>T){
      cout<<"No"<<endl;
      return 0;
    }
    if((T-d)%2){
      cout<<"No"<<endl;
      return 0;
    }
    nx=x[i];
    ny=y[i];
  }

  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 1408
N, x =map(int, input().split())
a = sorted(map(int, input().split()))

i = 0

while (i<N) and (x>=0):
    x -= a[i]
    if x>=0:
        i += 1

if (i == N) and (x>0) :
    print(N-1)
else:
    print(i)


Measured memory_bytes: 2940
#include <stdio.h>

long long gcd(long long a, long long b)
{
    long long r=0, t=0;

    if(a<b){
        t=a;
        a=b;
        b=t;
    }
    while(b!=0){
        r=a%b;
        a=b;
        b=r;
    }

    return a;
}        
long long lcm(long long a, long long b)
{
    return (a*b)/gcd(a, b);
}

int main(void)
{
    int n;
    scanf("%d", &n);
    long long t[n], ans=1, i;
    for(i=0;i<n;i++){
        scanf("%lld", &t[i]);
    }

    for(i=0;i<n;i++){
        ans=t[i]/gcd(t[i], ans)*ans;
    }
    
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, m, n) for (int i = m; i < n; ++i)
const int MOD = 1000000007;

int main() {
  int a, p;
  cin >> a >> p;
  int k = 3 * a + p;
  cout << k / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
ans = 1
zouka = True
not_change = True
for i in range(1, n):
    if not not_change:
        if (a[i] > a[i - 1] and not zouka) or (a[i] < a[i - 1] and zouka):
            ans += 1
            not_change = True
    else:
        if a[i] > a[i - 1]:
            zouka = True
            not_change = False
        elif a[i] < a[i - 1]:
            zouka = False
            not_change = False
print(ans)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, m, ans;
int fa[maxn], siz[maxn];
int getfa(int x){ return x == fa[x] ? x : fa[x] = getfa(fa[x]);}
int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) fa[i] = i, siz[i] = 1;
	for(int i = 1; i <= m; ++i){
		int u, v;
		scanf("%d%d", &u, &v);
		u = getfa(u), v = getfa(v);
		if(u == v) continue;
		fa[u] = v;
		siz[v] += siz[u];
	}
	for(int i = 1; i <= n; ++i) if(getfa(i) == i) ans = max(ans, siz[i]);
	cout << ans << endl;	
	return 0;
}

Measured memory_bytes: 11436
n, k, l = map(int, raw_input().split())

def root(x):
    if x == parent[x]: return x
    parent[x] = root(parent[x])
    return parent[x]
def unite(x, y):
    px = root(x)
    py = root(y)
    if px < py:
        parent[py] = px
    else:
        parent[px] = py

parent = range(n)
for i in xrange(k):
    p, q = map(int, raw_input().split())
    unite(p-1, q-1)
parent1 = parent
for i in xrange(n):root(i)

parent = range(n)
for i in xrange(l):
    r, s = map(int, raw_input().split())
    unite(r-1, s-1)
parent2 = parent
for i in xrange(n):root(i)

dic = {}
for p1, p2 in zip(parent1, parent2):
    dic[p1, p2] = dic.get((p1, p2), 0) + 1

ans = [dic[p1, p2] for p1, p2 in zip(parent1, parent2)]
print " ".join(map(str, ans))


Measured memory_bytes: 60728
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cfloat>
#include <algorithm>
#include <memory>
#define ll long long
#define ull unsigned long long
#define uint unsigned
#define l_double long double
#define PB push_back
#define EB emplace_back
#define gcd __gcd
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define PIE (3.1415926535897932384626433832795)
#define MOD 1'00'00'00'007
#define TEST uint _ {}; cin >> _; while (_--)
using namespace std;
ull lcm (ull a, ull b) { return ((a*b)/gcd(a, b)); }
ull countDigits(const ull &N) { return (floor(log10(N)) + 1); }
bool isPowOfTwo(ull const &N) { return (N && (!(N&(N-1)))); }
// ----------------------------------------------------------

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<boolalpha<<fixed<<setprecision(3);
    // --------------------------------------

    int x {};
    cin >> x;
    int points {};
    points = (x/500) * 1000;
    x -= (x/500)*500;
    points += (x/5) * 5;
    cout<<points<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
int main()
{
	int K;
	std::cin >> K;
	std::string S;
	std::cin >> S;
	if (S.size() > K) {
		S.resize(K);
		std::cout << S << "..." << std::endl;
	}
	else
	{
		std::cout << S << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int n;
	while(scanf("%d",&n)==1){
		getchar();
		string s,t;
		cin>>s>>t;
		//cout<<s<<" "<<t<<endl;
		
		int i=0, common = 0; 
		for(int i=n-1;i>=0;i--){
			string sub = s.substr(i);
			if(t.find(sub)!=-1) {
				common = n-i;
				//printf("%s %d\n", sub.c_str(), common);
			}
		}
		printf("%d\n", 2*n-common);
	}
	return 0;
}

Measured memory_bytes: 3756
#include<iostream>
#include<string>

char kukaku[101][101];
int H, W;

int dx[] = { -1, 0, 0, 1 };
int dy[] = { 0, -1, 1, 0 };
void dfs(int x, int y){
	char ch = kukaku[x][y];
	kukaku[x][y] = '.';
	for (int i = 0; i < 4; ++i){
		int nx = x + dx[i], ny = y + dy[i];
		if (nx >= 0 && nx < H && ny >= 0 && ny < W){
			if (kukaku[nx][ny] == ch)dfs(nx, ny);
		}
	}
	return;
}

int main(){
	while (1){
		std::cin >> H >> W;
		if (H == 0 && W == 0)break;
		for (int i = 0; i < 101; ++i){
			for (int j = 0; j < 101; ++j){
				kukaku[i][j]='.';
			}
		}
		for (int i = 0; i < H; ++i){
			std::string s;
			std::cin >> s;
			for (int j = 0; j < W; ++j)kukaku[i][j] = s[j];
		}
		int res = 0;
		for (int i = 0; i < H; ++i){
			for (int j = 0; j < W; ++j){
				if (kukaku[i][j] != '.'){
					dfs(i, j);
					res++;
				}
			}
		}
		std::cout << res << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1684
/*  ex3_4
    pptenshi  */

#include<stdio.h>

int main(void) {
    int num;  // N

    //input
    scanf("%d", &num);

    //output
    for (int i = 1; i < 10; i++) {

        // nがiの段かどうかを判定
        if (num % i == 0 && num / i < 10) {
            printf("Yes\n");
            return 0;
        }
    }
    // 条件を満たさない場合
    printf("No\n");
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  if (a+b > d+c) {
    cout << "Left" << endl;
  }
  else if (a+b < d+c) {
    cout << "Right" << endl;
  }
   if (a+b == d+c) {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int a, b, c, d;
  int A_SUM, B_SUM;
  cin >> a >> b >> c >> d;
  A_SUM = a + b + c + d;
  cin >> a >> b >> c >> d;
  B_SUM = a + b + c + d;

  cout << max(A_SUM, B_SUM) << endl;
}



Measured memory_bytes: 3100
#include <iostream>
#include <queue>
#define INF 1000000000
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;
typedef pair<int, int> pii;
struct state { int y, x, s, c; };

int H, W;
char S[60][30];
int dp[60][30][2];
bool g[60][30];

const int dd[2][9][2] = {
  {
    { 2, -1 }, { 1, -1 }, { 0, -1 }, { -1, -1 }, { -2, -1 },
    { 1, -2 }, { 0, -2 }, { -1, -2 }, { 0, -3 }
  }, {
    { 2, 1 }, { 1, 1 }, { 0, 1 }, { -1, 1 }, { -2, 1 },
    { 1, 2 }, { 0, 2 }, { -1, 2 }, { 0, 3 }
  }
};

class Compare {
public:
  bool operator()(struct state a, struct state b) {
    return a.c > b.c;
  }
};

bool isin(int y, int x) {
  return 0 <= y && y < H && 0 <= x && x < W && S[y][x] != 'X';
}

int main(void) {
  while(cin >> W >> H, H && W) {
    priority_queue<struct state, vector<struct state>, Compare> q;

    REP(i, 0, H) {
      REP(j, 0, W) {
        cin >> S[i][j];
        if(S[i][j] == 'S') {
          struct state sl = { i, j, 0, 0 };
          struct state sr = { i, j, 1, 0 };
          q.push(sl);
          q.push(sr);
          S[i][j] = '0';
        }
        if(S[i][j] == 'T') {
          g[i][j] = true;
          S[i][j] = '0';
        } else {
          g[i][j] = false;
        }
      }
    }

    REP(i, 0, H) REP(j, 0, W) REP(k, 0, 2) dp[i][j][k] = INF;

    int ans = -1;
    while(!q.empty()) {
      struct state c = q.top();
      q.pop();

      // cout << c.y << " " << c.x << " " << c.s << " " << c.c << endl;

      if(dp[c.y][c.x][c.s] <= c.c) continue;
      dp[c.y][c.x][c.s] = c.c;

      if(g[c.y][c.x]) {
        ans = dp[c.y][c.x][c.s];
        break;
      }

      int ns = 1 - c.s;
      REP(i, 0, 9) {
        int ny = c.y + dd[ns][i][0];
        int nx = c.x + dd[ns][i][1];
        if(isin(ny, nx)) {
          struct state n = { ny, nx, ns, c.c + (S[ny][nx] - '0') };
          if(dp[n.y][n.x][n.s] >= n.c) q.push(n);
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
// const ll MOD = 1e9+7;
#define REP(i,j,n) for(int i=j;i<n;i++)
#define rep(i,n) REP(i,0,n)

const int MAX = 5100000;
const ll MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// int main() {
//     // 前処理
//     COMinit();

//     // 計算例
//     cout << COM(100000, 50000) << endl;
// }

template< typename T>
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}


// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    COMinit();

    int k;
    string s;
    int n;
    cin >> k >> s;
    n = s.size();

    ll ans = 0;
    rep(i,k+1)
    {
        if (COM(n+k-i-1, n-1) < 0) cout << i << " " << COM(n+k-i-1, n-1) << endl; 
        ll tmpans = COM(n+k-i-1, n-1) * mod_pow((ll)25, (ll)k-i, MOD)%MOD * mod_pow((ll)26, (ll)i, MOD)% MOD;
        // if (tmpans < 0) cout << i << " " << tmpans << endl;
        ans += tmpans;
    }
    cout << ans%MOD << endl;
}


Measured memory_bytes: 123760
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG

int n, k;
vector<int> w;

bool ok(int p) {
  int i = 0;
  for (int j = 0; j < k; ++j) {
    int now = p;
    while (now - w.at(i) >= 0) {
      now -= w.at(i);
      i++;
      if (i == n)
        return true;
    }
  }
  return false;
}

int main() {
  cin >> n >> k;
  w = vector<int>(n);
  for (int i = 0; i < n; i++)
    cin >> w[i];
  int l = 0, h = 1e9 + 10;
  while (l + 1 < h) {
    int med = (l + h) / 2;
    if (ok(med))
      h = med;
    else
      l = med;
  }
  cout << l + 1 << endl;
}



Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>

using namespace std;

void solve(long long n, long long a, long long b) {
    long long ans = 0LL;
    if (a > b) {
        std::cout << 0 << std::endl;
    } else if(a == b){
            std::cout << 1 << std::endl;
    } else {
        if (n == 1) {
            std::cout << 0 << std::endl;
        } else {
            if (n == 2) {
                std::cout << 1 << std::endl;
            } else {
                ans += b-a + 1;
                if (n > 3) {
                    ans += (b-a)*(n-3);
                }
                std::cout << ans << std::endl;
            }
        }
    }
}

int main() {
    struct timeval start,end;
    long long span;
    long long n, a, b;

    gettimeofday(&start,NULL);

    std::cin >> n >> a >> b;
    solve(n, a, b);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define int long long
#define pb push_back
#define inf 1e9
#define mod 1000000007

const int maxn = 100010;
int n, arr[maxn], dp[maxn], k;

void solve()
{
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> arr[i];

	fill(dp, dp + maxn, inf);
	dp[1] = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = i + 1; j <= i + k; j++)
		{
			dp[j] = min(dp[j], dp[i] + abs(arr[i] - arr[j]));
		}
	}
	cout << dp[n];
}

int32_t main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	solve();
	return 0;
}


Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;

long long n, k;
vector<long long> a;

bool need(long long x);
long long solve();

int main() {
  cin >> n >> k;
  for(long long i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    a.push_back(x);
  }
  sort(a.begin(), a.end());
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long l = 0, r = n - 1, now;
  while(l <= r) {
    if(r - l < 2) {
      if(need(l))
        return l;
      else if(need(r))
        return r;
      else
        return r + 1;
    }
    now = (l + r) / 2;
    if(need(now))
      r = now;
    else
      l = now;
  }
  return -1;
}

bool need(long long x) {
  if(a[x] >= k) return 1;
  bool memo[2][10005] = {0};
  memo[1][a[x]] = 1;
  for(long long i = 0; i < n; ++i)
    for(long long j = 0; j <= 10000; ++j) {
      memo[i % 2][j] = memo[1 - i % 2][j];
      if(i != x && j - a[i] >= 0 &&
         memo[1 - i % 2][j - a[i]])
        memo[i % 2][j] = 1;
    }
  for(long long i = k; i < k + a[x]; ++i)
    if(memo[(n - 1) % 2][i]) return 1;
  return 0;
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void) {
	int n, sec, min, hour;
	scanf("%d",&n);
	sec = n % 60;
	hour = n / 3600;
	min = (n-hour*3600) / 60;
	printf("%d:%d:%d\n", hour,min,sec);
	return 0;
}

Measured memory_bytes: 592