akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

const int mod = 1e9 + 7;

long long inv(long long x){
  long long m = mod, u = 1, v = 0;
  while(m){
    long long t = x / m;
    x -= t * m; swap(x, m);
    u -= t * v; swap(u, v);
  }
  u %= mod;
  if(u < 0) u += mod;
  return u;
}

long long power(long long a, long long e){
  if(e == 0) return 1ll;
  if(e & 1){
    return power(a, e - 1) * a % mod;
  }
  long long re = power(a, e >> 1);
  return re * re % mod;
}

int main(){
  int n;
  cin >> n;
  
  int a, b;
  cin >> a >> b;
  
  long long bouquet = power(2ll, n) - 1;
  long long fac = 1;
  for(int i = 0; i < a; i++){
    fac *= n - i;
    fac %= mod;
    fac *= inv(i + 1);
    fac %= mod;
  }
  
  bouquet -= fac;
  bouquet %= mod;
  
  fac = 1;
  for(int i = 0; i < b; i++){
    fac *= n - i;
    fac %= mod;
    fac *= inv(i + 1);
    fac %= mod;
  }
  bouquet -= fac;
  bouquet %= mod;
  if(bouquet < 0) bouquet += mod;
  
  cout << bouquet << endl;
  
  return 0;
}

Measured memory_bytes: 256
ss=['A','G','C','T']
s=list(input())
ans=0
for i in range(len(s)):
  if s[i] in ss:
    j=i
    cnt=0
    while j<len(s):
      if s[j] in ss:
        cnt+=1
        j+=1
      else:
        break
      
    ans=max(ans,cnt)
      
print(ans)

Measured memory_bytes: 9012
#include <iostream>
using namespace std;
int main(){
  int n,m,k;cin>>n>>m>>k;
  for(int i = 0; n >= i; i++){
    for(int j = 0; m >= j; j++){
      //i行とj列を反転させる
      //cout << i << " " << j << ":" << n*m << " " << i*m << " " << n*j << " " << i*j << endl;
      if(n*m-i*m-n*j+i*j*2 == k){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
facs = []
M = 1000000007

def modulo(n):
    global facs
    facs = [1]*(n+1)
    last = 1
    for i in range(1,n+1):
        last = facs[i] = mulmod(last,i,M)
        
def mulmod(x,y,p):
    return x*y % p
def divmod(x,y,p):
    return mulmod(x,powmod(y,p-2,p),p)

def ncr(n,r):
    if n<r:
        return 0
    if n==r:
        return 1
    res = facs[n]
    res = divmod(res,facs[r],M)
    res = divmod(res,facs[n-r],M)
    return res

def powmod(x,y,p):
    if y==0:
        return 1
    elif y==1:
        return x % p
    elif (y%2)==0:
        return powmod(x,y//2,p)**2 % p
    else:
        return powmod(x,y//2,p)**2 * x % p

import sys
input = sys.stdin.readline

MAX= 2005
def resolve():
    n,k = map(int,input().split())
    red = n-k
    modulo(MAX)
    print(n-k+1)
    for i in range(2,k+1):
        if i>red+1:
            print(0)
        else:
            ans = 1
            if(red-i+1)>0:
                ans = ans * ncr(red+1,red-i+1)
            if(k-i)>0:
                ans = ans * ncr(k-1,k-i)
            print(ans%M)

if __name__ == "__main__":
    resolve()

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

int A[105], B[105];

int main() {
    int N, a, b;
    scanf("%d", &N);
    for (int i = 1; i <= N; i++) {
        scanf("%d", &a);
        A[i] = A[i-1] + a;
    }
    for (int i = 1; i <= N; i++) {
        scanf("%d", &b);
        B[i] = B[i-1] + b;
    }
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        ans = max(ans, A[i] + B[N] - B[i-1]);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>

using namespace std;



int main(){
    int N;
    cin >> N;
    vector<long long> A(N);
    map<long long, long long> mp; // map seisu to count
    for(long long i = 0; i < N; i++){
        int seisu;
        cin >> seisu;
        A[i] = seisu;
        mp[seisu]++;
    }

    long long all = 0;
    for(auto i : mp){
        if(i.second < 2) continue;
        all += (i.second * (i.second - 1)) / 2;
    }


    for(long long k = 0; k < N; k++){
        mp[A[k]]--;

        if(mp[A[k]] == 1){
            cout << all - 1 << endl;;
        }else if(mp[A[k]] > 1){
            cout << all - ((mp[A[k]] + 1) * mp[A[k]]) / 2 + (mp[A[k]] * (mp[A[k]] - 1)) / 2 << endl;
        }else{
            // 0 になった
            cout << all << endl;
        }

        // 戻す
        mp[A[k]]++;
    }

    return 0;
}


Measured memory_bytes: 11008
data class Scores(val a: Int, val b: Int, val c: Int, val d: Int)
data class Tyouka(val iwana: Int, val yamame:Int){
    fun score(scores: Scores): Int {
        return iwana * scores.a + (iwana / 10) * scores.c + yamame * scores.b + (yamame / 20) * scores.d
    }
}
fun main(args:Array<String>): Unit {
    val hiroshi = readLine()!!.trim().split(' ').map(String::toInt).let{(a, b) -> Tyouka(a, b)}
    val kenjiro = readLine()!!.trim().split(' ').map(String::toInt).let{(a, b) -> Tyouka(a, b)}
    val scores = readLine()!!.trim().split(' ').map(String::toInt).let{(a, b, c, d) -> Scores(a, b, c, d)}
    println(
            when{
                hiroshi.score(scores) == kenjiro.score(scores) -> "even"
                hiroshi.score(scores) > kenjiro.score(scores) -> "hiroshi"
                else -> "kenjiro"
            }
    )
}


Measured memory_bytes: 33968
def solve(h, w, d, AA, q, LR):
    Ainv = {
        AA[y][x]: (x, y)
        for x in range(w)
        for y in range(h)
    }
    costs = [0] * (h * w)
    for i in range(d , h * w):
        xf, yf = Ainv[i - d + 1]
        xt, yt = Ainv[i + 1]
        costs[i] = costs[i - d] + abs(xt - xf) + abs(yt - yf)

    ret = [0] * q
    for i, (l, r) in enumerate(LR):
        ret[i] = costs[r - 1] - costs[l - 1]

    return ret

_h, _w, _d = map(int, input().split())
_AA = [list(map(int, input().split())) for _ in range(_h)]
_q = int(input())
_LR = [list(map(int, input().split())) for _ in range(_q)]
print(*solve(_h, _w, _d, _AA, _q, _LR), sep='\n')


Measured memory_bytes: 50728
import java.util.*;
import java.math.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int count=0;
		int q=n+1;
		for(int i=0; i<n; i++){
			int p=sc.nextInt();
			if(q>p){
				count++;
				q=p;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 61472
#include <bits/stdc++.h>
#define int long long 
#define pb push_back
#define fr first
#define sc second
#define sz(v) ((int)(v).size())
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repd(i,a,p) for(int i=a-1;i>=p;i--) 
#define M 1000000007
#define vi vector<int>
#define vp vector<pair<int,int> >
#define ml map<int,int>
#define MPI 3.1415926536
using namespace std;
//priority_queue is best for traversing elements when it is needed in a sorted order
//dsu is pel concept
int n,m,k=0,t,i,j,c=0,x,s=0,a,b;string s1;
vector <int>  divisor(int k)
{
	vi v;
	for(int i=1;i*i<=k;i++)
	{
		if(k%i==0)
	     {
	     	v.pb(i);
	     	if(i*i!=k)
	     	v.pb(k/i);
		 }
	}
	sort(all(v));
	return (v);
}
signed main()
{
	cin>>n;
	int ans=0;
	vi v2(n);
	map <int,int> m1;
	rep(i,0,n)
	{
		cin>>v2[i];
		m1[v2[i]]++;
	}
	for(int i=0;i<n;i++)
	{
		int k2=1;
		for(auto it:divisor(v2[i]))
		{
			if(m1.count(it))
			{
				if(it==v2[i]&&m1[it]==1)
				continue;
			    k2=0;
			    break;
			}
		}
		if(k2)
		ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 17156
#include <stdio.h>
#define max 100

int selectionSort(int*,int);


int main(){
    int n,num[max];
    int count;

    scanf("%d",&n);

    for(int i = 0;i < n;i++)scanf("%d",&num[i]);

    count = selectionSort(num,n);

    for(int i = 0;i < n;i++){
        printf("%d",num[i]);
        if(i < n-1)printf(" ");
    }

    printf("\n%d\n",count);

    return 0;
}

int selectionSort(int *num,int n){
    int minj,tmp;
    int count = 0;
    int flag;

    for(int i = 0;i < n;i++){
        minj = i;
        flag = 0;
        for(int j = i;j < n;j++){
            if(num[j] < num[minj]){
                minj = j;
                flag = 1;
            }
        }
        if(flag == 1){
            tmp = num[minj];
            num[minj] = num[i];
            num[i] = tmp;
            count++;
        }
    }

    return count;
}


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

int main() {
	long long n,m;cin>>n>>m;
	long long ans=0;
	if(2*n<m){
		ans+=n;
		m-=2*n;
	}else{
		ans+=m/2;
		m=0;
	}
	if(m){
		ans+=m/4;
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

int main()
{


 int a,b,c,d;
 cin>>a>>b>>c>>d;
 int X=(a+d-1)/d;
 int Y=(c+b-1)/b;
 cout<<(X>=Y?"Yes":"No")<<"\n";

    return 0;

}


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

typedef long long ll;
#define pb push_back
#define ii pair<int ,int >
#define vi vector<int >
#define vii vector < pair<int ,int > >
#define IO ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define IOfiles freopen("input.txt","r+",stdin) ; freopen("output.txt","w+",stdout)
#define PI 3.14159265
const double eps = 1e-9;

int main()
{
	IO;
	int x, y, a, b, c;
	int total;
	cin >> x >> y >> a >> b >> c;
	total=x+y;
	vii apples;
	for (int i = 0; i < a; i++) {
		int v;
		cin >> v;
		apples.pb(make_pair(v, 0));
	}
	for (int i = 0; i < b; i++) {
		int v;
		cin >> v;
		apples.pb(make_pair(v, 1));
	}
	for (int i = 0; i < c; i++) {
		int v;
		cin >> v;
		apples.pb(make_pair(v, 2));
	}
	sort(apples.begin(), apples.end());
	ll ans = 0;
	vi tot;
	for (int i = apples.size() - 1; i >= 0; i--) {
		if (apples[i].second == 0 && x) {
			tot.pb(apples[i].first);
			x--;
		}
		else if (apples[i].second == 1 && y) {
			tot.pb(apples[i].first);
			y--;
		}
		else if (apples[i].second == 2)
			tot.pb(apples[i].first);
		if (x == 0 && y == 0) {
			break;
		}
	}

	/*for (int i = 0; i < tot.size(); i++)
		cout << tot[i] << " ";
	cout << endl;*/
	for(int i=0;i<total;i++){
		//cout<<tot[i]<<endl;
		ans+=tot[i];
	}
	cout << ans << endl;


}

Measured memory_bytes: 8172
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p == NIL) printf("root, ");
  else if(T[u].l == NIL) printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");

}

void calcDepth(int u, int p){
  D[u] = p;
  if(T[u].r != NIL) calcDepth(T[u].r, p);
  if(T[u].l != NIL) calcDepth(T[u].l, p + 1);
}

int main(){
  int i, j, k;
  int n;
  int id, sib, child;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;

  for(i=0; i<n; i++){
    scanf("%d %d", &id, &k);
    for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
      else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
      sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
    }
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }

  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);

  //出力 (output)
  for(i=0; i<n; i++) print(i);

  return 0;
}



Measured memory_bytes: 6420
#include <iostream>
#include <vector>
#include <bits/stdc++.h> 
using namespace std;
int main ()
{
	long long int n, brojac=0, priv=1;
	cin>>n;
	if (n==1)
	{
		cout<<1<<endl;
		return 0;	
	}
	while (n>0)
	{
		brojac=brojac+priv;
		n/=2;
		priv*=2;
	}
	cout<<brojac<<endl;
	
	return 0;
}

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

int main(){
	/*#ifndef ONLINE_JUDGE
	freopen("/home/shubham/Desktop/codesinput.txt", "r", stdin);
	freopen("/home/shubham/Desktop/codes/output.txt", "w", stdout);
	#endif*/
	ll a,b;
	cin>>a>>b;
	if(a>9 || b>9){
		cout<<"-1"<<endl;
	}
	else{
		cout<<a*b<<endl;
	}


	return 0;
}


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

using namespace std;

int main(){

    int N;
    cin >> N;
    vector<int> X(N);
    for(int i = 0; i < N; i++){
        cin >> X[i];
    }

    vector<int> A = X;

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

    int med = A[(N + 1) / 2 - 1];
    for(int i = 0; i < N; i++){
        int temp = X[i];
        if(N % 2 == 0){
            if(temp <= med){
                cout << A[(N + 1) / 2] << "\n";
            }  
            else{
                cout << med << "\n";
            }
        }
        else{
            if(temp < med){
                cout << med << "\n";
            }
            else{
                cout << A[(N + 1) / 2] << "\n";
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <list>
#include <stdio.h>

using namespace std;


int day(int y, int m, int d){
    int d_sum=d;
    
    if(y%3==0){
        d_sum+=(m-1)*20;
    }else if(m%2==0){
        d_sum+=(m/2)*(19+20)-19;
    }else{
        d_sum+=((m-1)/2)*(19+20);
    }
    
    int y_20_20=(y-1)/3;
    int y_20_19=(y-1)-y_20_20;
    
    d_sum+=y_20_20*20*10+y_20_19*(19+20)*5;
    
    return d_sum;    
}


int main(){
    int maou=day(1000,1,1);
    
    int num;
    cin>>num;
    for(int i=0; i<num; i++){
        int y,m,d;
        cin>>y>>m>>d;
        int d_sum=day(y,m,d);
        cout<<maou-d_sum<<endl;
    }
    
    
    
    
    
}

Measured memory_bytes: 1160
#include <cstdio>
#include <vector>

using namespace std;

int main()
{
  vector<int> h, w;
  short in_h, in_w;

  while(1)
  {
    scanf("%hd %hd", &in_h, &in_w);
    if(in_h == 0 && in_w == 0)break;
    h.push_back(in_h);
    w.push_back(in_w);
  }
  for(int i=0; i < h.size(); i++)
  {
    for (int j=0; j<h[i]; j++)
    {
      for(int k=0; k<w[i]; k++)
      {
        if(j%2==0 && k%2==1)
        {
          printf(".");
          continue;
        }
        if(j%2==1 && k%2==0)
        {
          printf(".");
          continue;
        }
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }

  return 0;

}


Measured memory_bytes: 2652
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;
// scanf
#pragma warning(disable: 4996)
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値
#define _ceil(x) ceil(x)

int main()
{
	string s;
	string result;

	for (uint32_t i = 0; i < 3; i++) {
		cin >> s;
		result += s[i];
	}
	printf("%s\n", result.c_str());
	return 0;
	//	std::cout << "Hello World!\n"; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

int main()
{
    ll N,C,K;
    cin >> N >> C >> K;
    vll T(N);
    cin >> T;
    sort(T.begin(),T.end());
    ll ans = 0;
    int i=0;
    while(i<N){
        int j=i;
        for(;i<N && i<j+C && T[i]-T[j]<=K; i++);
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3980
input_line1 = input()
str_list = input().split()
num_list = [int(a) for a in str_list]
flag = True
count = -1
while flag:
    for i in range(len(num_list)):
        if num_list[i] % 2 == 0:
            num_list[i] = num_list[i] // 2
        else:
            flag = False
    count += 1

print(count)

Measured memory_bytes: 3060
#include<iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;
#define INT_MAX       2147483647    // maximum (signed) int value

int gcd(int p, int q) {
    if (p % q == 0)return q;
    return gcd(q, p % q);
}

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

    vector<long long> a(n,0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    sort(a.begin(), a.end());
    long long sum = 0;
    sum = a[n - 1];
    int x = n - 2;

    for (int i = 0; i <n-2; i++) {
        sum += a[x];
        if (i <n-3 ) {
            sum += a[x];
            x--;
            i++;
        }
    }

    cout << sum;
   

    return 0;
}



Measured memory_bytes: 4832
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int N;
	ll X,n;
	ll m = LINF;
	cin >> N >> X;

	for (int i = 0;i < N;i++){
		cin >> n;
		X -= n;
		m = min(m,n); 
	}
	cout << N + X / m << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
const int inf = 1 << 30;
const ll linf = 1e18;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int a, b, c;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << " " << b << " " << c << endl;
    return 0;
}

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

using namespace std;
using llong = long long;
const int MOD=1000000007;

int main(int argc, char**argv){
    int n;
    cin >> n;
    int max = 0;
    int ans = 1;
    for (int i = 1; i <= n; i++){
        // cout << i << endl;
        int target = i;
        int counter = 0;
        while (true){
            if (target % 2 != 0){
                if (counter >= max){
                    max = counter;
                    ans = i;
                }
                break;
            }
            target /= 2;
            counter++;
        }
    }
    cout << ans << endl;

    return 0;
}







Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
using namespace std;
 
int compare(const void *x, const void *y)
{
	return *(int*)y - *(int*)x;
}
 
int main() {
	int N;
	long a[300000], ans = 0;
	cin >> N;
	for (int i = 0; i < N * 3; ++i) cin >> a[i];
	qsort(a, N * 3, sizeof(long), compare);
	for (int i = 1; i < N * 2; i += 2) ans += a[i];
	cout << ans;
}

Measured memory_bytes: 4860
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

void solve() {
	ll n;cin >> n;
	vector<ll> v(n);REP(i, n)cin >> v[i];
	string str;cin >> str;

	vector<ll> mp;
	REV(i, n){
		ll now = v[i];
		REP(j, mp.size())now = min(now, now ^ mp[j]);
		if(now == 0)continue;
		if(str[i] == '1'){
			cout << 1 << endl;
			return;
		}
		else {
			mp.PB(now);
		}
	}
	cout << 0 << endl;
}

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

	ll t;cin >> t;
	REP(i, t)solve();

	return 0;
}


Measured memory_bytes: 3660
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<queue>
#include<algorithm>
#include<complex>
#include<cstdlib>
#include<cctype>

#define REP(i,n) for(int i = 0;i < (n);i++)
#define PB push_back
#define MP make_pair
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cout << v[i] << ' ';cout << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cout << v[a][b] << ' ';cout << endl;}cout << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> ivv;


int main()
{
	int n;
	
	while(cin >> n,n)
	{
		iv v;
		REP(i,n)
		{
			int tmp;
			cin >> tmp;
			v.PB(tmp);
		}
		
		sort(ALL(v));
		
		int ans = 1e9;
		
		REP(i,n-1)
		{
			ans = min(ans , v[i+1] - v[i]);
		}
		
		cout << ans << endl;
		
	}
	
	
	
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S;
    cin >> S;
    int count = 0;
   for(int i = 0; i < S.size(); i++){
   if(S.at(i)=='x'){
     count++;
    }
   }
   if(count > 7){
     cout << "NO" << endl;
   }
  
   else{
   cout << "YES" << endl;
   }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>

using namespace std;
typedef long long ll;

ll DP[101][100001]; // 種類、重さ

int main()
{
	int N, W;
	ll w[101];
	ll v[101];
	cin >> N >> W;
	for(int i = 1; i <= N; i++){
		cin >> w[i] >> v[i];
	}
	
	for(int i = 0; i <= N; i++){
		for(int j = 0; j <= W; j++){
			DP[i][j] = 0;
		}
	}
	
	for(int i = 1; i <= N; i++){
		for(int j = 0; j <= W; j++){
			if(j-w[i] >= 0){
				DP[i][j] = DP[i-1][j-w[i]] + v[i];
			}
			DP[i][j] = max(DP[i][j], DP[i-1][j]);
		}
	}
	
	cout << DP[N][W] << endl;
	
	return 0;
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
    cin>>s;
    int n=s.size();
    int x=1<<(n-1);
    long long ans=0;
    for(int i=0;i<x;i++)
    {
        long long x=s[0]-'0';
        for(int j=0;j<n;j++)
        {
            if(j==n-1||i&1<<j)
            {
                ans+=x;
                x=0;
                if(j==n-1)
				break;
            }
            x*=10;
            x+=s[j+1]-'0';
        }
    }
    cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }                            /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }                            /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void)
{
  int n, k;
  char s[MAX];
  scanf("%d %d %s", &n, &k, s);

  int nsize = 0, nums[MAX]; // 1-0-...-0-1と並ぶ配列
  int now = 1;              // 今見ている数
  int cnt = 0;              // 今見ている数の連続して並んでいる数
  rep(i, 0, n) {
    if (s[i] == (char)('0' + now)) cnt++;
    else {
      nums[nsize++] = cnt;
      now = 1 - now;
      cnt = 1;
    }
  }
  nums[nsize++] = cnt;

  // 最後が0で終わっている場合(1-0-...1-0)
  // 最後を1で終わっている配列にする(1-0-...-0-1)
  if (nsize % 2 == 0) nums[nsize++] = 0;

  //　尺取法

  int range = 2 * k + 1; // 尺
  int ans = 0;

  int left = 0;
  int right = 0;
  int tmp = 0; // [left, right)のsum(仮ans)

  for (int i = 0; i < nsize; i += 2) { // 左端に合わせてループ
    int nleft = i;
    int nright = min(nleft + range, nsize);

    // 左差分を計算
    while (left < nleft) {
      tmp -= nums[left];
      left++;
    }

    // 右差分を計算
    while (right < nright) {
      tmp += nums[right];
      right++;
    }

    ans = max(ans, tmp);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 640
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

const LL M=1e9+7;
const int L=5000;
int N;
string s;
LL dp[L+2][L+2];
LL dp2[L+2];
LL ps[L+2];
int f(int N,int s){
	LL ret=0;
	for(int i=0;i<N;i++){
		int d=N-i-s;
		int v=i==0?1:dp2[i-1];
		if(d>=0&&d%2==0){
			//cerr << i << ", " << dp2[i] << ", " << dp[N-i][s] << ", " << ps[d/2] << endl;
			ret+=v*dp[N-i][s]%M*ps[d/2]%M;
			ret%=M;
		}
	}
	return ret;
}
// a>=0, b>=0, x*a+y*b=gcd>=0, a>0,b>0=>abs(y)<=a,abs(x)<=b
LL gcdex(LL a,LL b,LL& x, LL& y){
	LL ax=1,ay=0;
	LL bx=0,by=1;
	while(b){
		LL r=a/b;
		LL t=a-r*b; a=b; b=t;
		LL tx=ax-r*bx; ax=bx; bx=tx;
		LL ty=ay-r*by; ay=by; by=ty;
	}
	x=ax;
	y=ay;
	return a;
}

LL modinv(LL a, LL m){
	LL x,y;
	gcdex(a,m,x,y);
	if(x<0){
		x+=m;
	} else if(x>=m){
		x-=m;
	}
	return x;
}
// powmod p^n%mod
LL powmod(LL p,LL n,LL mod){
	LL q=p%mod;
	LL pow=1;
	while(n){
		if(n&1){
			pow*=q;
			pow%=mod;
		}
		q=q*q;
		q%=mod;
		n/=2;
	}
	return pow;
}
map<string,int> cnt;
void g(int rem,string cur){
	if(rem==0){
		cnt[cur]++;
		return;
	}
	g(rem-1,cur+"0");
	g(rem-1,cur+"1");
	if(cur.size()){
		cur.pop_back();
	}
	g(rem-1,cur);
}
int main() {
	cin >> N >> s;
	ps[0]=1;
	for(int i=1;i<=L;i++){
		ps[i]=ps[i-1]*2%M;
	}
	dp[0][0]=1;
	for(int k=1;k<=N;k++){
		for(int l=0;l<=k;l++){
			if(l>0){
				dp[k][l]=2*dp[k-1][l-1]%M;
			}
			else{
				dp[k][l]=dp[k-1][l];
			}
			dp[k][l]+=dp[k-1][l+1];
			dp[k][l]%=M;
		}
	}
	cout << dp[N][s.size()]*modinv(powmod(2,s.size(),M),M) %M<< endl;

	return 0;
}



Measured memory_bytes: 194048
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for (ll& a : A) {
        cin >> a;
    }

    ll ans = 1e18;
    for (int i = 0; i < (1 << N); i++) {
        int n = i;
        vector<bool> visible(N, false);
        for (int j = 0; j < N; j++) {
            if (n % 2 == 0) {
                visible[j] = true;
            }
            n /= 2;
        }

        ll H = 0;
        ll cost = 0;
        int cnt = 0;
        for (int j = 0; j < N; j++) {
            if (visible[j]) {
                if (H >= A[j]) {
                    cost += H - A[j] + 1;
                    H++;
                }
                cnt++;
            } else {
                if (H < A[j]) {
                    cnt++;
                }
            }
            H = max(H, A[j]);
        }
        if (cnt >= K) {
            ans = min(ans, cost);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))

int main(void) {
  char s[200];
  scanf("%s", s);
  
  int ans = 10000;
  int n = strlen(s); 
  for (int ch = 'a'; ch <= 'z'; ch++) {    
    int idx = n, req = 0;
    for (int i = n-1; i >= 0; i--) {
      if (s[i] != ch) {
        req = MAX(req, idx-i);
      } else {
        idx = i;
      }
    }
    ans = MIN(req, ans);
  }
  
  printf("%i\n", ans);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <iomanip>
using namespace std;
long long n,a,b,c,d,i,j;
int main()
{
	cin>>n>>a>>b>>c>>d;
	d-=c;
	n-=1;
	for (i=0;i<=n;i++)
	{
		j=n-i;
		if (b-a>=-d*j+i*c-j*c&&b-a<=d*i+i*c-j*c)
		{
			cout<<"YES";
			return 0;
		}
	} 
	cout<<"NO";
	return 0;
}

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

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (b < a) a = b; }

using ll = long long;
using ld = long double;
using namespace std;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n, a; cin >> n >> a;
  
  int x = n % 500;
  if (x <= a) cout << "Yes\n";
  else cout << "No\n";
  
  return (0);
}

Measured memory_bytes: 3652
from collections import Counter
import sys
import math
from functools import cmp_to_key

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)


def main():
    n = int(input())
    ans = 0
    for a in range(1, n+1):
        ans += (n-1) // a
    print(ans)

main()


Measured memory_bytes: 9572
s = input()
if 1<=int(s[0:2])<=12 and 1<=int(s[2:4])<=12:
    print("AMBIGUOUS")
elif 1<=int(s[0:2])<=12:
    print("MMYY")
elif 1<=int(s[2:4])<=12:
    print("YYMM")
else:
    print("NA")

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



int main() {
    
    int *a=new int[10000];
    for(int i=1;i<=105;i++){
        for(int j=1;j<=105;j++){
            for(int k=1;k<=105;k++){
                int t=i*i+j*j+k*k+i*j+i*k+j*k;
                if(t<=10050)
                a[t]++;
            }
        }
    }
    
    int n;
    cin>>n;
    
    for(int l=0;l<n;l++){
        cout<<a[l+1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3588
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}
int mod = 1000000000 + 7;
int dp[101][4][4][4];
int main()
{
        //input->compute->output//

        int A, B;
        cin >> A >> B;
        cout << max({2 * A - 1, 2 * B - 1, A + B}) << endl;
        
        return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A.sort()

num = [0] * int(1e5)
for i in A:
    num[i] += 1

need = 0
for i in num:
    need += max(i-1, 0)

if need % 2 == 1:
    need += 1

ans = N - need
print(ans)

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

struct Node{
    Node* left;
    Node* right;
};

Node* newNode(){
    Node* ret = (Node*)malloc(sizeof(Node));
    ret->left = NULL;
    ret->right = NULL;
    return ret;
}

Node* build(int &pos, const string s){
    if(s[pos] != '(')   return NULL;
    Node* ret = newNode();
    pos++;  // (
    ret->left = build(pos, s);
    pos++;  // ,
    ret->right = build(pos, s);
    pos++;  // )
    return ret;
}

void print(Node* root){
    cout << "(";
    if(root->left != NULL)  print(root->left);
    cout << ",";
    if(root->right != NULL) print(root->right);
    cout << ")";
}

Node* op(char c, Node* x, Node* y){
    int cnt = (x!=NULL) + (y!=NULL);
    if((cnt == 2 && c == 'i') || (cnt > 0 && c == 'u')){
        Node* root = newNode();
        root->left = op(c, (x==NULL ? NULL : x->left), (y==NULL ? NULL : y->left));
        root->right = op(c, (x==NULL ? NULL : x->right), (y==NULL ? NULL : y->right));
        return root;
    }else{
        return NULL;
    }
}

int main(){
    char c;
    string a, b;
    while(cin >> c >> a >> b){
        int pos = 0;
        Node* x = build(pos, a);
        pos = 0;
        Node* y = build(pos, b);
        print(op(c, x, y));
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3024
n, m = map(int, input().split())
pyo = []
for i in range(m):
    p, y = map(int, input().split())
    pyo.append([p, y, i])

sortpy = sorted(pyo, key=lambda x:x[1])

yy = [0]*(n+1)
ans = [""]*m
for i, j, k in sortpy:
    pp = str(i).zfill(6)
    yy[i] += 1
    ans[k] = pp + str(yy[i]).zfill(6)

for i in range(m):
    print(ans[i])

Measured memory_bytes: 99996
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
struct DisjointSparseTable{
    function<T(T, T)> f;
    vector<vector<T>> v;

    DisjointSparseTable(vector<T>& inp, function<T(T, T)> f) : f(f){
        int n = inp.size();
        int b;
        for(b = 0; (1 << b) <= inp.size(); ++b);
        v.assign(b, vector<T>(n));
        for(int i = 0; i < n; ++i)
            v[0][i] = inp[i];
        for(int i = 1; i < b; ++i){
            int siz = 1 << i;
            for(int j = 0; j < n; j += siz << 1){
                int t = min(j + siz, n);
                v[i][t - 1] = inp[t - 1];
                for(int k = t - 2; k >= j; --k)
                    v[i][k] = f(inp[k], v[i][k + 1]);
                if(t >= n)
                    break;
                v[i][t] = inp[t];
                int r = min(t + siz, n);
                for(int k = t + 1; k < r; ++k)
                    v[i][k] = f(v[i][k - 1], inp[k]);
            }
        }
    }

    T get(int l, int r){
        if(l >= --r)
            return v[0][l];
        int p = 31 - __builtin_clz(l ^ r);
        return f(v[p][l], v[p][r]);
    }
};



void solve(long long n, long long k, std::vector<long long> p){
    vector<double> s(n);
    for(int i = 0; i < n; ++i)
        s[i] = (1 + p[i]) / 2.0;
    DisjointSparseTable<double> d(s, [](auto x, auto y){return x + y;});
    double ans = -INF;
    for(int i = 0; i < n - k + 1; ++i)
        chmax(ans, d.get(i, i + k));
    printf("%.20lf\n", ans);
}


signed main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    solve(N, K, std::move(p));
    return 0;
}


Measured memory_bytes: 33024
t=[0]
x=[0]
y=[0]
(N=gets.to_i).times do
	a,b,c=gets.split.map(&:to_i)
	t.push(a)
	x.push(b)
	y.push(c)
end

for i in 1..N do
	dx = (x[i]-x[i-1]).abs + (y[i]-y[i-1]).abs
	dt = t[i]-t[i-1]
	if dx<=dt && (dx+dt).even?
		ans = "Yes"
	else
		ans = "No"
		break
	end
end
puts ans


Measured memory_bytes: 4204
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

ll n, m;

ll f(ll p, ll q)
{
    if(p == q) return 0;
    if(q >= p - q) return f(q, p - q) + p;
    else return 2 * q * (p / q - 1) + f(p - (q * (p / q - 1)), q);
}

int main()
{
    cin>>n>>m;
    cout<<f(n, n - m) + m;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
  while(1){
    int i,ans = 0;
    char x[1001];
    scanf("%s",x);
    if(x[0] == '0') break;
    for(i = 0; x[i] != '\0'; i++) ans += x[i] - '0';
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 536
// B.

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{
	int n, a = 0, b = 0;
	cin >> n;
	vector<int> x(n);
	for (int i = 0; i < n; ++i) {
		cin >> x[i];

	}
	sort(x.rbegin(), x.rend());
	for (int i = 0; i < n; ++i) {
		((i % 2) ? b : a) += x[i];
	}
	int ans = a - b;
	cout << ans << endl;
	return 0;
}


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

int main(){
  int N; 
  cin >> N;
  vector<int> p(N);
  for(int i=0; i<N; i++){
    cin >> p[i];
  }
  int counter=0;
  for(int i=1; i<N-1; i++){
    if(p[i-1]<p[i] && p[i]<p[i+1])counter+=1;
    if(p[i-1]>p[i] && p[i]>p[i+1])counter+=1;
  }
  cout << counter << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int A, B, C; cin >> A >> B >> C;
    if (A == B) cout << C << endl;
    if (A == C) cout << B << endl;
    if (B == C) cout << A << endl;
}

Measured memory_bytes: 256
with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Float_Text_IO;
 use Ada.Text_IO, Ada.Integer_Text_IO, Ada.Float_Text_IO;

procedure main is
   A: Integer;
   B: Integer;
begin
   get(A);
   get(B);
   if (A <= 9 and then B <= 9) then put(A * B, 0);
   else put(-1, 0);
   end if;
end main;

Measured memory_bytes: 3652
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import deque

h,w=nii()
s=[list(input()) for i in range(h)]

def BFS(sy,sx,ans):
  s[sy][sx]='B'

  que=deque()
  que.append((sy,sx))

  b_cnt=1
  w_cnt=0

  while que:
    y,x=que.popleft()
    for dy,dx in [[-1,0],[0,-1],[1,0],[0,1]]:
      ny=y+dy
      nx=x+dx
      if 0<=ny<h and 0<=nx<w:
        if s[y][x]=='B' and s[ny][nx]=='.':
          w_cnt+=1
          s[ny][nx]='W'
          que.append((ny,nx))
        if s[y][x]=='W' and s[ny][nx]=='#':
          b_cnt+=1
          s[ny][nx]='B'
          que.append((ny,nx))

  ans+=b_cnt*w_cnt
  return ans

ans=0
for i in range(h):
  for j in range(w):
    if s[i][j]=='#':
      ans=BFS(i,j,ans)

print(ans)


Measured memory_bytes: 10576
import java.util.*;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if ((a-b)<c){
            System.out.println(c-(a-b));
        }else{
            System.out.println(0);
        }

    }
}

Measured memory_bytes: 23380
N, M = map(int, input().split())

AB_list=[]

for i in range(N):
    A, B = map(int,input().split())
    AB_list.append([A, B])

AB_list = sorted(AB_list)
cost = 0
num = 0
for AB in AB_list:
    num = AB[1]
    if M > num:
        cost += AB[0]*num
        M -= num
    else:
        cost += AB[0]*M
        break

print(cost)

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

static int grid[1000][1000];
static uint path_count[1000][1000];
static const uint mod = 1'000'000'007;

int main()
{
  int h, w;
  cin >> h >> w;

  for (auto row = 0; row < h; row++) {
    for (auto col = 0; col < w; col++) {
      char c;
      cin >> c;
      grid[row][col] = c == '#' ? 1 : 0;
    }
  }
  path_count[0][0] = 1;
  for (auto i = 0; i < h + w - 1; i++) {
    for (auto j = 0; j < w; j++) {
      int col = j;
      int row = i - j;
      if (row >= h) continue;
      if (row < 0) break;
      if (grid[row][col] != 0) continue;
      if (col + 1 < w && grid[row][col + 1] == 0) {
        path_count[row][col + 1] += path_count[row][col];
        path_count[row][col + 1] %= mod;
      }
      if (row + 1 < h && grid[row + 1][col] == 0) {
        path_count[row + 1][col] += path_count[row][col];
        path_count[row + 1][col] %= mod;
      }
    }
  }
  cout << path_count[h - 1][w - 1] << endl;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int iLeft1,iLeft2,iRight1,iRight2;
    cin>>iLeft1>>iLeft2>>iRight1>>iRight2;
    if (iLeft1+iLeft2>iRight1+iRight2)
        cout << "Left\n";
    else if(iLeft1+iLeft2==iRight1+iRight2)
        cout<<"Balanced\n";
    else 
        cout<<"Right\n";
    return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i,s,n) for(ll i=(s);i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
int main(){
    const ll c=1000000007;
    ll n,k;
    cin>>n>>k;
    ll sum=0;
    rep2(i,k,n+2){
        sum+=(i*(n-i+1)+1)%c;
        sum%=c;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3640
h,w = map(int,input().split())
s = [[i for i in input()] for j in range(h)]


"""
s_idx = [-1,-1]
g_idx = [-1,-1]

for i in range(h):
    for j in range(w):
        if s[i][j] == 'S':
            s_idx[0] = i
            s_idx[1] = j
        if s[i][j] == 'G':
            g_idx[0] = i
            g_idx[1] = j
"""

tate = [0,0,1,-1]
yoko = [-1,1,0,0]

mat=[[10**18 for i in range(w*h)] for j in range(w*h)]

for i in range(w*h):
    mat[i][i] = 0

for i in range(w*h):
    for j in range(4):
        next_idx = i + w*tate[j] + yoko[j]
        if next_idx < 0 or next_idx >= w*h:
            continue
        if i % w == 0:
            if j == 0:
                continue
        if i % w == w - 1:
            if j == 1:
                continue
        if s[next_idx//w][next_idx%w] == '#':
            mat[i][next_idx] = 10**18
        else:
            mat[i][next_idx] = 1

for i in range(w*h):
    #print(i,i,i,i,i,i,i,i,i)
    for x in range(w*h):
        for y in range(w*h):
            """
            if x == s_idx[0]*w+s_idx[1] and y == g_idx[0]*w+g_idx[1]:
                print(mat[x][y],mat[x][i] , mat[i][y],i)
            """
            mat[x][y] = min(mat[x][y], mat[x][i] + mat[i][y])
    
ans = 10**18
tmp = []

for i in range(w*h):
    for j in range(w*h):
        if s[i//w][i%w] == '#':
            continue
        if s[j//w][j%w] == '#':
            continue
        if ans > mat[i][j]:
            tmp.append(mat[i][j])
            
print(max(tmp))



Measured memory_bytes: 50908
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

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

typedef struct {
    int h;
    int w;
    int warp;
} point;

bool operator>(const point &student1, const point &student2) {
  return student1.warp > student2.warp;
};

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

vector<vector<int>> minim;
int h, w;
int dh, dw;

bool isvalid(int x, int y, int cost) {
  return x >= 0 && x < w && y >= 0 && y < h && minim[y][x] != -1 && cost < minim[y][x];
}

int main(){
    cin >> h >> w;
    int ch, cw;
    cin >> ch >> cw;
    ch--;
    cw--;
    cin >> dh >> dw;
    dh--;
    dw--;
    rep(i, h){
        string x;
        cin >> x;
        vector<int> tmpa(w, INT32_MAX);
        rep(j, w){
            if(x[j]=='#'){
                tmpa[j] = -1;
            }
        }
        minim.push_back(tmpa);
    }

    point p = {ch, cw, 0};
    minim[p.h][p.w] = p.warp;

    priority_queue< point, vector<point>, greater<point> > pq;
    pq.push(p);

    while(!pq.empty()){
        point now = pq.top();
        pq.pop();

        rep(i, 4){
            int x = now.w + dx[i], y = now.h + dy[i];
            if(isvalid(x, y, now.warp)){
                p = {y, x, now.warp};
                minim[y][x] = now.warp;
                pq.push(p);
            }
        }

        rep2(i, -2, 3){
            rep2(j, -2, 3){
                int x = now.w + j, y = now.h + i;
                if(isvalid(x, y, now.warp+1)){
                    p = {y, x, now.warp+1};
                    minim[y][x] = now.warp+1;
                    pq.push(p);
                }
            }
        }
    }

    if(minim[dh][dw]==INT32_MAX){
        minim[dh][dw] = -1;
    }
    cout << minim[dh][dw] << endl;
    return 0;
}

Measured memory_bytes: 7508
require "bigdecimal"
require "bigdecimal/util"

def gi() gets.to_i end
def gs() gets.chomp end
def gmi() gets.split.map(&:to_i) end
def gms() gets.split.map(&:chomp) end
def YesNo1(bool, yes="Yes", no="No") puts (bool ? yes : no) end
def YESNO2(bool, yes="YES", no="NO") puts (bool ? yes : no) end


#####
#
a = gi
b = gi
h = gi
puts (a+b)*h/2

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

using namespace std;


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

    int n;
    string s, t;

    cin >> n >> s >> t;
    for (int len = n; len > 0; len--) {
        string a = string(s.end() - len, s.end());
        string b = string(t.begin(), t.begin() + len);

        if (a == b) {
            cout << 2 * n - len;
            return 0;
        }
    }

    cout << 2 * n;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>

int main() {
	int a, n, i, a2 = 0, a4 = 0, x;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &a);
		if (a % 4 == 0) {
			a4++;
		}
		else if (a % 2 == 0) {
			a2++;
		}
	}

	x = a4 + a2 / 2;

	if (n % 2 == 1) {
		if (n / 2 <= x || n / 2 - 1 == x) {
			printf("Yes");
		}
		else {
			printf("No");
		}
	}
	else {
		if (n / 2 <= x) {
			printf("Yes");
		}
		else {
			printf("No");
		}
	}

}

Measured memory_bytes: 1712
open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f
    let readChars() = read string |> Seq.toArray
    let readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<AutoOpen>]
module Cout =
    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let print (s: string) = writer.Write s
    let println (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = string s |> println

// -----------------------------------------------------------------------------------------------------

// -----------------------------------------------------------------------------------------------------

let main() =
    let s = read string
    String('x', s.Length) |> puts

    ()

// -----------------------------------------------------------------------------------------------------
main()
writer.Dispose()


Measured memory_bytes: 13268