akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;

#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ

signed main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int k1=a[0],k2=a[0]+1;
    rep(i,n-1){
        if(k1!=a[i+1]&&k1!=a[i+1]+1) k1=-1;
        if(k2!=a[i+1]&&k2!=a[i+1]+1) k2=-1;
    }
    //cout << k1 << " " << k2 << endl;
    if(k1!=-1){
        int ex=0;
        rep(i,n){
            if(k1==a[i]) ex++; //not unique
        }
        if(ex==n){
            if(ex/2>=k1){
                cout << "Yes" << endl;
                return 0;
            }
        }
        else{
            if(n-ex+ex/2>=k1&&k1>n-ex){
            cout << "Yes" << endl;
            return 0;
            }
        }
    }
    if(k2!=-1){
        int ex=0;
        rep(i,n){
            if(k2==a[i]) ex++;
        }
        if(ex==0){
            if(k2==n){
                cout << "Yes" << endl;
                return 0;
            }
        }
        else if(ex==n){
            if(ex/2>=k2){
                cout << "Yes" << endl;
                return 0;
            }
            
        }
        else{
            if(n-ex+ex/2>=k2&&k2>n-ex){
            cout << "Yes" << endl;
            return 0;
            }
        }
    }
        cout << "No" << endl;
}


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

using namespace std;
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define floot10 cout<<fixed<<setprecision(10);
#define int long long
int h[600000],n;

void solve(int now){
	int maxi=now;
	if(2*now<=n){
		if(h[maxi]<h[now*2]) maxi=now*2;
	}
	if(2*now<n){
		if(h[2*now+1]>h[maxi]) maxi=now*2+1;
	}
	if(now!=maxi){
		swap(h[now],h[maxi]);
		solve(maxi);
	}
}

signed main(){
	cin>>n;
	lp(i,n){
		cin>>h[i+1];
	}
	for(int i=n/2;i>0;i--){
		solve(i);
	}
	lp(i,n){
		cout<<" "<<h[i+1];
	}
	cout<<endl;
	return 0;
}



Measured memory_bytes: 6952
#include <stdio.h>
#include <math.h>
int main(void){
    // Your code here!
    int n,m;
    int s;
    int c;
    
    scanf("%d %d",&n,&m);
    
    int p=0;
    
    int fal=0;
    
    if(n>1){
    for(int i=0;i<m;i++){
        scanf("%d %d",&s,&c);
                if(s==1 && c==0){
            fal++;
            break;
        }else if((int)(p/pow(10,n-s))%10!=0 && (int)(p/pow(10,n-s))%10!=c){
            fal++;
            break;
        }else if((int)(p/pow(10,n-s))%10==c){
        
        }else{
            p+=pow(10,n-s)*c;
        }
        //printf("%d %d %d\n",i,p,fal);
    }
    
    if(p<pow(10,n-1)){
        p+=pow(10,n-1);
    }
    }else{
        for(int i=0;i<m;i++){
        scanf("%d %d",&s,&c);
        if((int)(p/pow(10,n-s))%10!=0 && (int)(p/pow(10,n-s))%10!=c){
            fal++;
            break;
        }else if((int)(p/pow(10,n-s))%10==c){
        
        }else{
            p+=pow(10,n-s)*c;
        }
        //printf("%d %d %d\n",i,p,fal);
    }
    }
    
    if(fal){
        printf("-1\n");
    }else{
        printf("%d\n",p);
    }
    return 0;
}


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

char getGrade(int m, int f, int r){
        // 判定

        char grade;

        // 1
        if(-1 == m || -1 == f){
            return 'F';
        }
        // 2
        if(80 <= m + f){
            return 'A';
        }
        // 3
        if(65 <= m + f && 80 > m + f){
            return 'B';
        }
        // 4
        if(50 <= m + f && 65 > m + f){
            return 'C';
        }
        // 5
        if(30 <= m + f && 50 > m + f){
            if(50 <= r){
                return 'C';
            }else{
                return 'D';
            }
        }
        // 6
        if(30 > m + f){
            return 'F';
        }
}

int main(){
    int m, f, r;
    // 読み込み
    while(1){
        cin >> m >> f >> r;
        if(-1 == m && -1 == f && -1 == r){
            break;
        }

        // cout << m << f << r << endl;
        char grade;
        grade = getGrade(m, f, r);


        // 出力
        cout << grade << endl;
    }



    return 0;
}


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

//typedef
typedef unsigned int UINT;
typedef unsigned long long ULL;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef tuple<LL, LL, LL> TLL3;
typedef tuple<LL, LL, LL, LL> TLL4;
typedef set<LL, greater<LL> > setdownLL;
#define PQ priority_queue
typedef PQ<LL, vector<LL>, greater<LL> > pqupLL;
//container utill
#define ALL(v) (v).begin(),(v).end()
#define CR [](auto element1, auto element2){return element1>element2;}
#define LB lower_bound
#define UP upper_bound
#define PB push_back
#define MP make_pair
#define MT make_tuple
//constant
#define PI 3.141592653589793

int N,M;
vector<int> G[100001];
bool visited[100001];
int con=0;

void vis(int v){
    int i;
    for(i=0; i<G[v].size(); i++){
        if(visited[G[v][i]]==0){
            visited[G[v][i]]=1;
            vis(G[v][i]);
        }
    }
}

void sear(){
    fill(visited,visited+100001,0);
    int i;
    for(i=1; i<=N; i++){
        if(visited[i]==0){
            visited[i]=1;
            vis(i);
            con++;
        }
    }
}


int main(){
    cin >> N >> M;
    int i;
    int A,B;
    for(i=0; i<M; i++){
        cin >> A >> B;
        G[A].PB(B);
        G[B].PB(A);
    }
    sear();
    cout << con-1 << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 9748
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
#define FOR(i,l,r) for (int i = (l); i < (r); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<int,int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const int INF = 1 << 30;
// const ll INF = 1LL << 62;
// --------------------------------------------------------


int binary_search_A(vector<int> &a, int key) {
    // Meguru type binary search
    int ok = -1;
    int ng = a.size();

    auto is_ok = [&] (int idx) {
        if (a[idx] < key) {
            return true;
        } else {
            return false;
        }
    };

    int mid;
    while (abs(ok - ng) > 1) {
        mid = (ok + ng) / 2;
        if (is_ok(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    return ok;
}


int binary_search_C(vector<int> &a, int key) {
    // Meguru type binary search
    int ng = -1;
    int ok = a.size();

    auto is_ok = [&] (int idx) {
        if (key < a[idx]) {
            return true;
        } else {
            return false;
        }
    };

    int mid;
    while (abs(ok - ng) > 1) {
        mid = (ok + ng) / 2;
        if (is_ok(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    return ok;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);

    int N; cin >> N;
    VI A(N); REP(i,N) cin >> A[i];
    VI B(N); REP(i,N) cin >> B[i];
    VI C(N); REP(i,N) cin >> C[i];

    SORT(A);
    SORT(B);
    SORT(C);

    ll ans = 0;
    for (auto b : B) {
        int ia = binary_search_A(A, b);
        int ic = binary_search_C(C, b);
        ans += (ll)(ia + 1) * (N - ic);
    }
    cout << ans << '\n';

    return 0;
}


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

int a, b;

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

	cin >> a >> b;

	int num = 1, ans = -1;
	while (num * 8 / 100 <= a && num * 10 / 100 <= b) {
		if (num * 8 / 100 == a && num * 10 / 100 == b) {
			ans = num;
			break;
		}

		num++;
	}

	cout << ans << '\n';

	return 0;
}

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

int main()
{
  int n;
  cin >> n;
  int ncopy = n;
  int numsum = 0;
  while(ncopy != 0)
  {
    numsum += ncopy % 10;
    ncopy /= 10;
  }
  if(n % numsum == 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define each(it,v) for(auto &it : v)
#define mod 1000000007
#define All(v) (v).begin(),(v).end()
#define vi vector<int>
#define vl vector<long>
#define P pair<int,int>
#define Graph vector<vector<int>>
using namespace std;

main()
{
        int n;cin>>n;
        map<int,int> dm;
        rep(i,n)
        {
                int d; cin>>d;
                dm[d]++;
        }
        int m; cin>>m;
        bool flag=true;
        rep(i,m)
        {
                int t; cin>>t;
                if(dm[t])
                {
                        dm[t]--;
                }else
                {
                        flag=false;
                }
        }
        cout<<(flag?"YES":"NO")<<endl;
}

Measured memory_bytes: 9600
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

const char NUL = '\0';
bool hash_t[1 << 25] = { false };
char key[256] = { 0 };

int
hash(const char* s)
{
	int u = 1;
	while (*s != NUL)
	{
		u = u * 4 + key[(int)*s];
		s++;
	}

	return u;
}

int
main(int argc, char** argv)
{
	char command[8];
	char str[14];
	int n;

	key['A'] = 0;
	key['C'] = 1;
	key['G'] = 2;
	key['T'] = 3;

	scanf("%d", &n);
	while (n--)
	{
		scanf("%s %s", command, str);
		int h = hash(str);
		switch (command[0])
		{
		case 'i':
			hash_t[h] = true;
			break;

		case 'f':
		default:
			if (hash_t[h])
				printf("yes\n");
			else
				printf("no\n");
			break;
		}
	}

	return 0;
}

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

string IntToStr(int tmp){
    ostringstream out;
    out << tmp;
    return out.str();
}


int main() {
    int n;
    cin>>n;
    cout<<(n*(n+1))/2<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  if (n <= k) cout << n*x << endl;
  else cout << k*x + (n-k)*y << endl;
}


Measured memory_bytes: 256
n=int(input())
orgn=n
m=n-1
orgm=m
ncounter=1
mcounter=1
for i in range(2,int(m**0.5)+1):
	if m % i == 0:
		tmpc=1
		m //= i
		while m % i ==0:
			tmpc += 1
			m //= i
		mcounter *= tmpc + 1

if m == orgm and m != 1:
	mcounter += 1
elif m > int(orgm**0.5):
	mcounter *= 2
mcounter -= 1


for i in range(2,int(n**0.5)+1):
	if orgn % i == 0:
		n = orgn // i
		while n % i ==0:
			n //= i
		if n % i == 1:
			ncounter += 1

print(ncounter+mcounter)



Measured memory_bytes: 9476
## coding: UTF-8
#DP
N = int(input())
U = list(map(int,input().split()))
D = list(map(int,input().split()))

#dp = [[0] * 2] * N #これだとアドレスごとコピーされている
dp = []
for i in range(N):
    dp.append([0] * 2)
dp[0][0] = U[0]
dp[0][1] = U[0] + D[0]
for i in range(1, N):
    dp[i][0] = dp[i-1][0] + U[i]
    dp[i][1] = max(dp[i-1][1], dp[i][0]) + D[i]
    #print(dp)
print(dp[N-1][1])

Measured memory_bytes: 3064
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x, t; cin >> x >> t;
	cout << max(0, x - t) << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N;
    vector<pair<int, int>> VC;

    cin >> N;

    for(int i=0; i<N; i++)
        VC.push_back(pair<int, int>(0, 0));

    for(int i=0; i<N; i++)
        cin >> VC[i].first;

    for(int i=0; i<N; i++)
        cin >> VC[i].second;

    sort(VC.begin(), VC.end(), [](const auto& a, const auto& b) {
        return a.first - a.second > b.first - b.second;
    });

    int ans = 0;
    for(int i=0; i<N; i++)
        if(VC[i].first - VC[i].second > 0)
            ans += VC[i].first - VC[i].second;

    cout << ans << endl;

    return 0;
}

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

int main()
{
    int n,p[51];
    cin>>n;
    for (size_t i = 0; i < n; i++)
    {
        cin>>p[i];
    }
    int k=0;
    for (size_t i = 0; i < n; i++)
    {
        if(p[i]!=i+1){
            k++;
        } 
    }
    if(k==0 || k==2){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    
    return 0;
}

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

int G[110][110];
int N,num,lines,tar;
int D[1000];
int ret[1000];

void bfs(int src);

int main() {
	for (int i=0;i<110;i++) {
		for(int j=0;j<110;j++) {
			G[i][j] = 0;
		}
	}
	for(int i=0;i<1000;i++) {
		D[i] = 100;
	}
	cin >> N;
	for(int i=0;i<N;i++) {
		cin >> num >> lines;
		for(int j=0;j<lines;j++) {
			cin >> tar;
			G[num][tar] = 1;
		}
	}
	/*
	for(int i=0;i<num+1;i++) {
		for(int j=0;j<num+1;j++) {
			cout << G[i][j] << " ";
		}
		cout << endl;
	}
	*/
	bfs(1);
	for(int i=1;i<num+1;i++) {
		if((ret[i] == 0) && (i>1)) ret[i] = -1;
		cout << i << " " << ret[i] << endl;
	}

}
void bfs(int src) {
	int cur,dst;
	//cerr << "bfs root = " << src << endl;
	queue<int> Q; // ??´??°????????????????????\????????????
	Q.push(src);
	D[src] = 0; // ?????????
	while (! Q.empty()) {
		int cur = Q.front(); // ??????????´????????????????
		Q.pop();
// ???????¢??????¨??¨???
		ret[cur] = D[cur];
		//cerr << cur << " " << D[cur] << endl;
		for (int dst=1;dst<N+1;dst++) { // ???????????? dst ????????????
			if ((G[cur][dst] == 1) && (D[dst] == 100)) { // cur ?????? dst ??????????????????dst ???????¨??????????
				D[dst] = D[cur]+1; //
				Q.push(dst); // dst ????¨???????????????????
			}
		}
	}
}

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

int main(){
  int N,K;
  cin >> N >> K;
  vector<char> data(N,'x');
  int d,A;
  for(int i=0;i<K;i++){
    cin >> d;
    for(int j=0;j<d;j++){
      cin >>A;
      A--;
      data.at(A) = 'o';
    }
  }
  
  int l =0;
  for(int i=0;i<N;i++){
    if(data.at(i) == 'x'){
      l++;
    }
  }
  cout << l<<endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int n, a[100005];
int main () {
	scanf("%d", &n);
	for (int i=0; i<2*n; i++) scanf("%d", &a[i]);
	sort(a, a+2*n);
	int sum=0;
	for (int i=0; i<2*n; i+=2) sum+=a[i];
	printf("%d\n", sum);
	return 0; 
}

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

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define MP make_pair
#define FI first
#define SE second
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;

const double EPS = 1e-9;
const double PI = acos(-1);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

ll addMod(ll a, ll b){
	return (a+b) % MOD;
}

ll mulMod(ll a, ll b){
	return (a*b) % MOD;
}

ll fast(ll a, ll b){
	if(b == 0) return 1;
	ll tmp = fast(a,b/2);
	tmp = mulMod(tmp, tmp);
	if(b & 1) tmp = mulMod(tmp, a);
	return tmp;
}

/////////////////////////////////////////////////////////

const int N = 2e5;

int n;
int m;
int arr[N + 5];
vi lst[N + 5];
ll dp[N + 5];
int nxt[N + 5];

ll solve(int idx){
	if(idx == m+1){
		return 1;
	}
	ll& ret = dp[idx];
	if(ret != -1) return ret;
	ret = solve(idx+1);
	if(nxt[idx] != -1) ret = addMod(ret, solve(nxt[idx]));
	return ret;
}


int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	memset(nxt,-1,sizeof nxt);
	m = 0;
	cin >> n;
	int bef = -1;
	int x;
	REP(i,1,n){
		cin >> x;
		if(x != bef){
			arr[++m] = x;
			bef = x;
			lst[x].PB(m);
		}
	}
	REP(i,1,N){
		if(lst[i].size() > 1){
			FOR(j,lst[i].size()-1){
				nxt[lst[i][j]] = lst[i][j+1];
			}
		}
	}
	memset(dp,-1,sizeof dp);
	cout << solve(1) << endl;
	return 0;
}

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

int main() {
    int a, b;
    string winner;

    cin >> a >> b;

    if (a == 1) a = 14;
    if (b == 1) b = 14;

    if (a > b)      winner = "Alice";
    else if (a < b) winner = "Bob";
    else            winner = "Draw";

    cout << winner << endl;

    return 0;
}


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

int main(){
	int mayors[50]{0};
	vector<int> ansvec;

	while (1){
		int n, p;
		cin >> n >> p;
		if (n == 0) break;

		for (int i = 0; i < n; i++) mayors[i] = 0;
		int bowlp = p;
		int turn = 0;
		while (1){
			if (bowlp == 1 && mayors[turn] == p - 1) break;
			else if (bowlp == 0){
				bowlp += mayors[turn];
				mayors[turn] = 0;
			}
			else{
				mayors[turn]++;
				bowlp--;
			}

			if (turn == n - 1) turn = 0;
			else turn++;
		}
		ansvec.push_back(turn);
	}

	for (int ans : ansvec){
		cout << ans << endl;
	}

	return 0;
}

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define REPC(var, start, end) for(int var = start; var <= (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cerr << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
    string s;
    cin >> s;

    cout << "ABC" << s << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int S = sc.nextInt();
		sc.close();
		System.out.println(three(K, S));

	}

	private static int one(int K, int S)
	{
		return 0 <= S && S <= K ? 1 : 0; 
	}
	
	private static int two(int K, int S)
	{
		int result = 0;
		for (int i = 0; i <= K; i++){
			result += one(K, S - i);
		}
		return result;
	}
	
	private static int three(int K, int S)
	{
		int result = 0;
		for (int i = 0; i <= K; i++){
			result += two(K, S - i);
		}
		return result;
	}
}

Measured memory_bytes: 10316
#include <stdio.h>
#define NMAX 1000000
 
int cnt = 0;
int A[NMAX];
 
void insertionSort(int A[], int n, int g)
{
    int v;
    int i, j;
 
    for(i=g; i<n; i++) {
        v = A[i];
        j = i - g;
        while(j>=0 && A[j] > v) {
            A[j+g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j+g] = v;
    }
}
 
void shellSort(int A[], int n)
{
    int i;
    int m = 13;
    int G[13] = {1, 4, 13, 40, 121, 364, 1093, 3280, 9841, 29524, 88573, 265720, 797161};
    cnt = 0;
 
    while(G[m-1] > n) m--;
    printf("%d\n%d", m, G[m-1]);
    for(i=m-2; i>=0; i--) printf(" %d", G[i]);
    putchar('\n');
 
    for(i=m-1; i>=0; i--) {
        insertionSort(A, n, G[i]);
    }
}
 
int main()
{
    int i, n;
 
    scanf("%d", &n);
    for(i=0; i<n; i++) {
        scanf("%d", &A[i]);
    }
    shellSort(A, n);
    printf("%d\n", cnt);
    for(i=0; i<n; i++) printf("%d\n", A[i]);
    return 0;
}

Measured memory_bytes: 4508
#![allow(unused_imports)]
#![allow(dead_code)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

use std::cmp::*;
use std::collections::*;
use std::ops::*;
use std::io::{Write, BufWriter};

// static MOD: usize = 998244353;
static MOD: usize = 1000000007;

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! println_stderr(
    ($($arg:tt)*) => { {
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

fn solve() {
    input! {
        n: usize,
        a: chars,
    }  
    let mut ans = 1;
    for i in 1..n {
        if a[i]!=a[i-1] {ans+=1;}
    }
    println!("{}", ans);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
using namespace std;

int main()
{
  ios::sync_with_stdio(false);

  long long N,K;
  cin>>N>>K;
  vector<vector<long long>>dp(N+1,vector<long long>(K+1,-1));
  vector<long long>a(N+1);
  for(long long i=0;i<N;i++)
  {
    cin>>a[i+1];
  }
  for(long long i=0;i<K+1;i++)
  {
    if(a[1]>=i)dp[1][i]=i+1;
    else  dp[1][i]=a[1]+1;
  }
  for(long long i=2;i<N+1;i++)
  {
    dp[i][0]=1;
    for(long long j=1;j<K+1;j++)
    {
      if(j>a[i])dp[i][j]=dp[i][j-1]+dp[i-1][j]-dp[i-1][j-a[i]-1];
      else dp[i][j]=dp[i][j-1]+dp[i-1][j];
      dp[i][j]%=1000000007;
      if(dp[i][j]<0){dp[i][j]+=1000000007;}
    }
  }
  if(dp[N][K]<0){dp[N][K]+=1000000007;}
  long long res=dp[N][K]-dp[N][K-1];
  if(res<0){res+=1000000007;}
  if(K>0){cout<<res;return 0;}
  cout<<dp[N][K];
  cout<<endl;

}


Measured memory_bytes: 80256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	//	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func bitCount(bits int) int {

	bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555)
	bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333)
	bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f)
	bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff)
	return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff)
}

type say struct {
	x, y int
}

type person struct {
	n int
	s []say
}

func check(tbl []int, N int, A []person) bool {
	for i := 0; i < N; i++ {
		for _, v := range A[i].s {
			if tbl[i] == 1 && tbl[v.x] != v.y {
				return false
			}
			//			if tbl[i] == 0 && tbl[v.x] == v.y {
			//				return false
			//			}
		}
	}
	return true
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	A := make([]person, N)
	for i := 0; i < N; i++ {
		n := getInt()
		A[i].s = make([]say, n)
		for j := 0; j < n; j++ {
			A[i].s[j] = say{getInt() - 1, getInt()}
		}
	}

	out(N)
	for i := 0; i < N; i++ {
		out(A[i])
	}

	ans := 0
	for i := 0; i < 1<<uint(N); i++ {
		tbl := make([]int, N)
		for j := 0; j < N; j++ {
			tbl[j] = (i >> uint(j)) % 2
		}
		res := check(tbl, N, A)
		n := bitCount(i)
		if res == true && ans < n {
			ans = n
		}
		out(tbl, res, ans)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 4864
use std::cmp::*;
use std::io::*;

fn lower_bound<T: PartialOrd>(x: T, a: &Vec<T>) -> usize {
    let mut l: usize = 0;
    let mut r: usize = a.len();
    while r != l {
        let mid = (l + r) >> 1;
        if a[mid] < x {
            l = mid + 1;
        } else {
            r = mid;
        }
    }
    l
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();

    let n: usize = itr.next().unwrap().parse().unwrap();
    let d: i64 = itr.next().unwrap().parse().unwrap();
    let a: i64 = itr.next().unwrap().parse().unwrap();
    let mut xh: Vec<(i64, i64)> = (0..n)
        .map(|_| {
            (
                itr.next().unwrap().parse().unwrap(),
                itr.next().unwrap().parse().unwrap(),
            )
        })
        .collect();
    xh.sort();
    // 体力と座標をかんり

    let mut sum = vec![0i64; n + 5];
    let mut ans = 0;
    for i in 0..n {
        if xh[i].1 + sum[i] > 0 {
            let num = (xh[i].1 + sum[i] + a - 1) / a;
            // d * 2 hani
            let idx = lower_bound((xh[i].0 + d * 2 + 1, -(1 << 30)), &xh);
            sum[i] -= num * a;
            sum[idx] += num * a;
            ans += num;
        }
        sum[i + 1] += sum[i];
    }
    println!("{}", ans);
}


Measured memory_bytes: 15608
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=(a),_ed=(b);i<=_ed;++i)
#define DREP(i,a,b) for(int i=(a),_ed=(b);i>=_ed;--i)
typedef long long ll;
inline int read(){
    register int x=0,f=1;register char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();}
    while(isdigit(ch)){x=x*10+(ch^'0');ch=getchar();}
    return f?x:-x;
}

const int N=1e5+5;
int n,m,num,head[N],ecnt,cnt[3],flg,col[N];
struct edge{int to,val,next;} e[N<<1];
inline void add(int u,int v){
    e[++num]=(edge){v,1,head[u]},head[u]=num;
    e[++num]=(edge){u,2,head[v]},head[v]=num;
}

inline void dfs(int u){
    ++cnt[col[u]];
    for(int i=head[u];i;i=e[i].next){
	if(e[i].val==1)++ecnt;
	int v=e[i].to;
	if(!~col[v])col[v]=(col[u]+e[i].val)%3,dfs(v);
	else if(col[v]!=(col[u]+e[i].val)%3)flg=1;
    }
}

int main(){
    //freopen("in.in","r",stdin);
    n=read(),m=read();
    REP(i,1,m){int u=read(),v=read();add(u,v);}
    memset(col,-1,sizeof col);
    ll ans=0;
    REP(i,1,n)if(!~col[i]){
	ecnt=cnt[0]=cnt[1]=cnt[2]=flg=0;
	col[i]=0;dfs(i);
	if(flg){ans+=1ll*(cnt[0]+cnt[1]+cnt[2])*(cnt[0]+cnt[1]+cnt[2]);continue;}
	if(!cnt[0]||!cnt[1]||!cnt[2]){ans+=ecnt;continue;}
	ans+=1ll*cnt[0]*cnt[1];
	ans+=1ll*cnt[1]*cnt[2];
	ans+=1ll*cnt[2]*cnt[0];
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 5248
////////////////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
ll gcd(ll a, ll b) {  // O( log(a) )
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * (b / my::gcd(a, b)); }  // O( log(a) )
bool isPrime(ll n) {                                    // O( sqrt(n) )
  bool flag = true;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      flag = false;
      break;
    }
  }
  return flag;
}
vector<pair<ll, ll>> primeFac(ll n) {  // O( sqrt(n) )
  vector<pair<ll, ll>> ret;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll exp = 0;
    while (n % i == 0) {
      n /= i;
      exp++;
    }
    ret.push_back(make_pair(i, exp));
  }
  if (n != 1) ret.push_back(make_pair(n, 1));
  return ret;
}
template <typename T>
void input_vec(vector<T> &a, ll n) {
  for (ll i = 0; i < n; i++) {
    T tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
}
template <typename T>
void input_set(set<T> &a, ll n) {
  for (ll i = 0; i < n; i++) {
    T tmp;
    cin >> tmp;
    a.insert(tmp);
  }
}
}  // namespace my
////////////////////////////////////////////////

int main() {
  ll h, w, m;
  cin >> h >> w >> m;
  vector<pair<ll, ll>> bomb;
  vector<ll> bh(h, 0), bw(w, 0);
  for (int i = 0; i < m; i++) {
    ll hi, wi;
    cin >> hi >> wi;
    bomb.push_back(make_pair(--hi, --wi));
    bh.at(hi)++;
    bw.at(wi)++;
  }

  vector<bool> hKouho(h, false), wKouho(w, false);
  ll bhMax, bwMax;
  ll tmp = 0;
  ll cnth = 0, cntw = 0;
  for (auto &bhi : bh) tmp = max(tmp, bhi);
  for (ll i = 0; i < h; i++) {
    if (bh.at(i) == tmp) {
      hKouho.at(i) = true;
      cnth++;
    }
  }
  bhMax = tmp;

  tmp = 0;
  for (auto &bwi : bw) tmp = max(tmp, bwi);
  for (ll i = 0; i < w; i++) {
    if (bw.at(i) == tmp) {
      wKouho.at(i) = true;
      cntw++;
    }
  }
  bwMax = tmp;

  ll ans = bhMax + bwMax;
  ll kouho = cnth * cntw;
  for (auto &bombi : bomb) {
    if (hKouho.at(bombi.first) && wKouho.at(bombi.second)) kouho--;
  }
  if (kouho <= 0) ans--;
  // cout << kouho << endl;

  cout << ans << endl;
}

Measured memory_bytes: 16308
import sys
f = sys.stdin
while True:
    n = int(f.readline())
    if n == 0:
        break
    myset = set()
    diff = sys.maxsize
    for tmp in f.readline().split():
        tmp = int(tmp)
        for score in myset:
            if abs(tmp - score) < diff:
                diff = abs(tmp - score)
                if diff == 0:
                    break
        myset.add(tmp)
    print(diff)



Measured memory_bytes: 5652
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
typedef long long ll;

int main() {
    int n,m;
    cin >> n >> m;

    vector<pair<int,int> > v;
    rep(i,n) {
        int x,y;
        cin >> x >> y;
        v.push_back(make_pair(x,y));
    }

    sort(v.begin(),v.end());

    rep(i,m) {
        int ans = 0;
        int x1,y1,x2,y2;
        cin >> x1 >> y1 >> x2 >> y2;

        rep(j,n) {
            int X = v[j].first;
            int Y = v[j].second;

            if(X < x1) continue;
            
            REP(k,j,n) {
                int X2 = v[k].first;
                int Y2 = v[k].second;

                if(X2 > x2) break;
                if(y1 <= Y2 && Y2 <= y2) ans++;
            }
            break;
        }

        cout << ans << endl;
    }


    return 0;
}

Measured memory_bytes: 1304
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()

using namespace std;
typedef unsigned long long ll;


int main(void){
    int n,a,same=1,ans=0;
    cin>>n;
    vector<int> c;//call
    for(int i=0;i<n;++i){
        cin>>a;
        c.push_back(a);
    }
    sort(ALL(c));
    for(int i=0;i<n-1;++i){
        if(c[i]==c[i+1]){
            ++same;
        }
        else{
            ans+=same%2;
            same=1;
        }
    }
    ans+=same%2;
    cout<<ans;
}

Measured memory_bytes: 892
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A'&&s[i+1]=='C'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

struct SC{
	int s;
	int c;
};

struct SC sc[5];

int main(){
	int n, m;
	int i, flag = 0;
	int ans[3] = {-1, -1, -1};

	scanf("%d %d", &n, &m);
	for(i=0; i<m; i++){
		scanf("%d %d", &(sc[i].s), &(sc[i].c));
	}

	for(i=0; i<m; i++){
		if(n > 1 && sc[i].s == 1 && sc[i].c == 0){
			flag = 1;
			break;
		}

		if(ans[sc[i].s-1] == -1){
			ans[sc[i].s-1] = sc[i].c;
		}else if(ans[sc[i].s-1] != sc[i].c){
			flag = 1;
			break;
		}
	}

	if(ans[0] == -1){
		if(m == 0 && n == 1){
			ans[0] = 0;
		}else{
			ans[0] = 1;
		}
	}
	if(flag == 1){
		printf("-1");
	}else{
		for(i=0; i<n; i++){
			if(ans[i] == -1){
				printf("0");
			}else{
				printf("%d", ans[i]);
			}
		}
	}

	return 0;
}


Measured memory_bytes: 128
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    A, B, C = [int(x) for x in input().split()]

    if C - A - B < 0:
        print("No")
        return
    if 4 * A * B < (C - A - B) ** 2:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

std::vector<I> enum_div(I n)//nの約数を列挙
{
	std::vector<I> ret;
	for(I i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  I n;
  cin >> n;
  auto a = enum_div(n);
  I t=MAX;
  REP(i,a.size()){
    I b = n / a.at(i);
    t = min(a.at(i) + b-2, t);
  }
  cout << t << endl;
  return 0;
}



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

int main(){
  int n;
  cin >> n;
  vector<int> mt(n);
  vector<int> maxmt(n);
  for (int i=0; i<n; i++){
    cin >> mt[i];
  }
  maxmt[0]=mt[0];
  for (int i=1; i<n; i++){
    maxmt[i]=max(maxmt[i-1], mt[i]);
  }
  int c=0;
  for (int i=0; i<n; i++){
    if (mt[i] == maxmt[i]){
      c++;
    }
  }
  cout << c;
}

Measured memory_bytes: 256
W,H,x,y,r = gets.split.map(&:to_i)

if x <= W-r && x-r >=0 && y <= H-r && y-r >=0

puts "Yes"

else x-r < 0 || x+r > W && y-r < 0 || y+r > W
 puts "No"
end


Measured memory_bytes: 6872
/*


                 """Bismillahir Rahmanur Rahim"""

*/
#include<bits/stdc++.h>
using namespace std;
#define pi 2*acos(0.0)
#define ll long long int
#define inf 922337203470075000
#define pb push_back
#define pf push_front
const ll sz = 1000001;
#define ek(x) __builtin_popcount(x)
#define ses '\n'
#define in(x) scanf("%lld",&x);
#define out(x) printf("%lld\n",x);
#define stm istringstream
#define all(x) x.begin(),x.end()
#define ghora ios_base::sync_with_stdio(0);cin.tie(0);
#define gcd __gcd
ll lcm(ll x,ll y){return (x*y)/gcd(x,y);}
#define tin ll T;cin>>T; for(ll o=1;o<=T;o++)
#define tout cout<<"Case "<<o<<": ";
#define spc printf(" ");
std::vector<ll> v[100050];
ll n,k;
ll dp[100020][3];
ll f(ll i,ll j)
{
    if(i==n-1)
     {
        if(j==0)
            return max(v[i][1],v[i][2]);
        if(j==1)
             return max(v[i][0],v[i][2]);

         else  return max(v[i][1],v[i][0]);
     }
    if(dp[i][j]>0) 
    {
        return dp[i][j];
        
    }
   
    ll x=-1,y=-1,z=-1;
   if(j!=0)
      x=v[i][0]+f(i+1,0);
  if(j!=1)
      y=v[i][1]+f(i+1,1);
  if(j!=2)
      z=v[i][2]+f(i+1,2);
   return dp[i][j]=max(z,max(x,y));
}
int main()
{
     ll p,a,b,c;
     memset(dp,-1,sizeof(dp));
     cin>>n;
     for(ll i=0;i<n;i++)
     {
        cin>>a>>b>>c;
        v[i].pb(a);
         v[i].pb(b);
          v[i].pb(c);
     }
     ll x=f(0,-1);
     cout<<x<<ses;
    return 0;
}
/*   --------------------
    |      ~SOHAN~       |
    |   ~Chandler68~     |
     --------------------
    || VALAR MORGULIS||==|| ALL MEN MUST DIE ||
    \\ Power Is Power//
    || I Can Do This All day ||
    // We are on a Break \\ // How you doin'? \\
    || Say My Name || ~~ || I Am The Who Knocks ||
    // I Am Ted Mosby Architect \\
    || It Is Legen --wait for it -- dary ,Legendary ||
    \\ Penny - Penny - Penny // -- Bazinga

*/

Measured memory_bytes: 15872
#include<bits/stdc++.h>
#define int int64_t

using namespace std;

const int mod = 1e9+7;
int dp[1000][1000];
char a[1000][1000];
int solve(int i,int j){
	

	if(i == 0 and j == 0)
		return 1;
	if(i<0 or j<0) return 0;
	if(a[i][j] == '#') return 0;
	int &ans = dp[i][j];
	if(ans != -1) 
		return ans;
	else{
		ans = (solve(i-1,j)%mod + solve(i,j-1)%mod)%mod;
	}
	
	return ans;
	
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int r,c;
	cin>>r>>c;
	
	
	for(int i =0;i<r;i++){
		for(int j=0;j<c;j++){
			cin>>a[i][j];
		}
	}
	
	for(int i=0;i<r;i++)
		for(int j=0;j<c;j++)
			dp[i][j] = -1;
			
			
	cout<<solve(r-1,c-1);
	
		
}

Measured memory_bytes: 12536
#include<iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
using namespace std;


#define li			long long int
#define rep(i,to)	for(int i=0;i<((int)(to));i++)
#define repp(i,start,to)	for(int i=(int)(start);i<((int)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl

bool prime[1000000];
li sum[1000000];

int main(){
	rep(i,1e+6)prime[i]=true;
	prime[0]=prime[1]=false;
	
	repp(i,2,sqrt(1e+6)+1){
		for(li j=2; j*i<=1e+6; j++){
			prime[i*j]=false;
		}
	}
	
	sum[0]=0;
	repp(i,1,1e+6)sum[i]=sum[i-1]+(prime[i]?1:0);
	
	li n;
	while(cin>>n){
		cout<<sum[n]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 9944
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=4000 +117;
const int MM=2000 +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n;
vector<int> p[NN]={};
int fa[NN]={};
int dep[NN]={};
vector<int> t[NN]={};
int te[NN][2]={};
int e[NN][2]={};
int trans[NN]={};
int ecnt=0;
int val[NN]={};
void dfs(int x,int f){
	dep[x]=dep[f]+1;
	fa[x]=f;
	for(int i=0;i<p[x].size();++i){
		int cur=p[x][i];
		if(cur!=f){
			dfs(cur,x);
		}
	}
}
void walk(int x,int y,int id){
	while(x!=y){
		if(dep[x]<dep[y])swap(x,y);
		t[x].push_back(id);
		x=fa[x];
	}
}
vector<int> tp;
void calc(int x){
	for(int i=0;i<p[x].size();++i){
		int cur=p[x][i];
		if(cur!=fa[x])calc(cur);
	}
	tp.clear();
	for(int i=0;i<t[x].size();++i){
		if(!trans[t[x][i]]&&e[t[x][i]][0]!=e[t[x][i]][1])tp.push_back(t[x][i]);
	}
	if(tp.size()>=2){
		int a=*tp.rbegin();
		int b=*(tp.rbegin()+1);
		++ecnt;
		if(e[a][0]==x){
			val[a]=1;
			e[ecnt][0]=e[a][1];
		}
		else e[ecnt][0]=e[a][0];
		if(e[b][1]==x){
			val[b]=1;
			e[ecnt][1]=e[b][0];
		}
		else e[ecnt][1]=e[b][1];
		walk(e[ecnt][0],e[ecnt][1],ecnt);
		trans[a]=ecnt;
		trans[b]=ecnt;
		tp.erase(tp.end()-1);
		tp.erase(tp.end()-1);
	}
	for(int i=0;i<tp.size();++i){
		int k=tp[i];
		if(e[k][0]==x)e[k][0]=fa[x];
		else e[k][1]=fa[x];
	}
}
int main(){
	//open();
	n=read();
	m=read();
	for(int i=1;i<n;++i){
		int x=read();
		int y=read();
		p[x].push_back(y);
		p[y].push_back(x);
	}
	dfs(1,0);
	for(int i=1;i<=m;++i){
		te[i][0]=e[i][0]=read();
		te[i][1]=e[i][1]=read();
		walk(e[i][1],e[i][0],i);
	}
	ecnt=m;
	int ans=0;
	for(int i=2;i<=n;++i){
		ans+=min((int)t[i].size(),2);
	}
	calc(1);
	for(int i=ecnt;i;--i){
		val[i]=val[i]^val[trans[i]];
	}
	printf("%d\n",ans);
	for(int i=1;i<=m;++i){
		if(val[i])printf("%d %d\n",te[i][1],te[i][0]);
		else printf("%d %d\n",te[i][0],te[i][1]);
	}
	close();
	return 0;
}

Measured memory_bytes: 12288
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	static long []fac ;
	static long []finv;
	static int n;
	
	static int mod = 1000000007;
	
	public static void main(String []args) {
		Scanner sc = new Scanner(System.in);
		
		 n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		
		int []a = new int [n];
		fac = new long[n+1];
		finv = new long[n+1];
		
		COMinit();
		long []up = new long [n+1];
		long []low = new long [n+1];
		
		for(int i = 0 ; i < n ;i++) {
			a[i] = Integer.parseInt(sc.next());
		}
		Arrays.sort(a);
		
		long ans = 0;
		
		for(int i = 0 ; i < n ;i++) {
			ans = (ans + (a[i] * (COM(i,k-1)-COM(n-i-1,k-1))%mod)%mod)%mod;
		}
		System.out.println(ans);
		
		
	}
	

	public static void COMinit() {
	    fac[0] = fac[1] = 1;
	    finv[0] = finv[1] = 1;
	    for (int i = 2; i <= n; i++){
	        fac[i] = fac[i - 1] * i % mod;
	        finv[i] = finv[i - 1] * Modpow(i,mod-2) % mod;
	    }
	}
 
	// 二項係数計算
	public static 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;
	}
 
	//a^n mod
	public static  long Modpow(long a, long n) {
		long res = 1;
		while(n > 0) {
			if((n & 1) == 1) {
				res = res * a % mod;
			}
			a = a * a % mod;
			n >>= 1;
		}
		return res;
	}
}


Measured memory_bytes: 48892
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC169
{
    class D
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var Res = new long[100000000];
            var dict = new Dictionary<long, long>();
            long j;

            if (IsPrime(N)) { Console.WriteLine(1); return; }
            //Console.WriteLine("--- 1 --");
            j = 2;
            var Ntemp = N;
            while (j * j <= N)
            {
                while (Ntemp % j == 0)
                {
                    if (!dict.ContainsKey(j)) dict.Add(j, 1);
                    else dict[j]++;
                    //Res[j]++;
                    Ntemp /= j;
                }
                j++;
            }
            // Console.WriteLine("--- 2 --");


            var res = 0;
            if (Ntemp != 1) res = 1;

            foreach (var i in dict.Values)
            {
                var temp = i;
                var index = 1;
                while (index <= temp)
                {
                    temp -= index;
                    index++;
                    res++;
                }
            }
            Console.WriteLine(res);
        }

        public static bool IsPrime(long num)
        {
            if (num < 2) return false;
            else if (num == 2) return true;
            else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

            double sqrtNum = Math.Sqrt(num);
            for (int i = 3; i <= sqrtNum; i += 2)
            {
                if (num % i == 0)
                {
                    // 素数ではない
                    return false;
                }
            }

            // 素数である
            return true;
        }
    }
}


Measured memory_bytes: 28352
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n; cin >> n;
	VI a(n); REP(i,n) cin >> a[i];
	if(n%2==0){
		ll dp[n][2];
		REP(i,n)REP(j,2)dp[i][j]=-(LINF/2);
		REP(i,n){
			if(i<2){
				if(i==0) dp[i][0]=a[i];
				else dp[i][1]=a[i];
			}
			if(i>=2)
				dp[i][0]=dp[i-2][0]+a[i];
			if(i>=3)
				dp[i][1]=max(dp[i-3][0]+a[i],dp[i-2][1]+a[i]);
		}
		ll ans=-LINF;
		REP(i,2)ans=max(ans,dp[n-1-i][1-i]);
		cout << ans << endl;
	}
	else{
		ll dp[n][3];
		REP(i,n)REP(j,3)dp[i][j]=-(LINF/2);
		REP(i,n){
			if(i<3){
				if(i==0) dp[i][0]=a[i];
				else if(i==1) dp[i][1]=a[i];
				else if(i==2) dp[i][2]=a[i];
			}
			if(i>=2)
				dp[i][0]=dp[i-2][0]+a[i];
			if(i>=3){
				dp[i][1]=max(dp[i-3][0]+a[i],dp[i-2][1]+a[i]);
				dp[i][2]=max(dp[i-3][1]+a[i],dp[i-2][2]+a[i]);
			}
			if(i>=4)
				dp[i][2]=max(dp[i-4][0]+a[i],dp[i][2]);
		}
		ll ans=-LINF;
		REP(i,3)ans=max(ans,dp[n-1-i][2-i]);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 9500
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#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 each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n, m, s, g1, g2;
	while (cin >> n >> m >> s >> g1 >> g2, n || m || s || g1 || g2) {
		g1--; g2--; s--;
		vector<vector<int> >d(n, vector<int>(n, 1000000));
		rep(i, 0, n)d[i][i] = 0;
		rep(i, 0, m) {
			int b1, b2, c; cin >> b1 >> b2 >> c; b1--; b2--;
			d[b1][b2] = c;
		}
		rep(k, 0, n) {
			rep(i, 0, n) {
				rep(j, 0, n) {
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
		int ans = INF;
		rep(i, 0, n)ans = min(ans, d[s][i] + d[i][g1] + d[i][g2]);
		cout << ans << endl;

	}
	return 0;
}

Measured memory_bytes: 3092