akhauriyash/Code-Regression huggingface dataset:
using System;
using System.IO;

namespace Contest
{

    class Program
    {
        private Scanner sc;

        public void Solve()
        {
            sc = new Scanner();
            int X = sc.NextInt();
            int A = sc.NextInt();
            if (X < A)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(10);
            }
        }

        static void Main() => new Program().Solve();
    }
}



class Scanner
{
    public Scanner()
    {
        _stream = new StreamReader(Console.OpenStandardInput());
        _pos = 0;
        _line = new string[0];
        _separator = ' ';
    }
    private readonly char _separator;
    private readonly StreamReader _stream;
    private int _pos;
    private string[] _line;
    #region get a element
    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = _stream.ReadLine().Split(_separator);
            _pos = 0;
        }
        return _line[_pos++];
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    #endregion
    #region convert array
    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }
    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }
    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }
    #endregion
    #region get array
    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = _stream.ReadLine().Split(_separator);
        _pos = _line.Length;
        return _line;
    }
    public int[] IntArray()
    {
        return ToIntArray(Array());
    }
    public long[] LongArray()
    {
        return ToLongArray(Array());
    }
    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }
    #endregion
}

Measured memory_bytes: 11092
N = int(input())
matrix = [[0 for i in range(N)] for j in range(N)]
for n in range(N):
    A = int(input())
    for a in range(A):
        array = [int(i) for i in input().split()]
        matrix[n][array[0]-1] = 1 if array[1] == 1 else -1
l = [True,False]
from itertools import product
for pattern in product(l,repeat=N):
    able = True
    for i,p in enumerate(pattern):
        if p:
            for a,b in zip(matrix[i],pattern):
                if (b==True and a==-1) or (b==False and a == 1):
                    able = False
                    break
            if able == False:
                break
        else:
            pass
    if able == True:
        break
print(sum(pattern))


Measured memory_bytes: 3064
fun main() {
    val input = rsp()
    val input2 = rsp()
    function(input, input2)
}

fun function(in1: List<String>, in2: List<String>) {
    val sum = in2.sumBy { it.toInt() }
    val days = in1[0].toInt()
    if (sum > days) {
        println(-1)
    } else {
        println(days - sum)
    }
}

inline fun rsp() = readLine()!!.split(" ")

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

int n,m,q,s[2010][2010],a[2010][2010],b[2010][2010],c[2010][2010];
char ch[2010];

void work()
{
	scanf("%d %d %d\n",&n,&m,&q);
	for (int i=1; i<=n; i++)
		{
			scanf("%s\n",ch+1);
			for (int j=1; j<=m; j++)
				s[i][j]=(ch[j]=='1');
		}
	for (int i=1; i<=n; i++)
		for (int j=1; j<=m; j++)
			a[i][j]=s[i][j]+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
	for (int i=1; i<=n; i++)
		for (int j=2; j<=m; j++)
			b[i][j]=(s[i][j]&s[i][j-1])+b[i-1][j]+b[i][j-1]-b[i-1][j-1];
	for (int i=2; i<=n; i++)
		for (int j=1; j<=m; j++)
			c[i][j]=(s[i][j]&s[i-1][j])+c[i-1][j]+c[i][j-1]-c[i-1][j-1];
	for (int i=1,xl,yl,xr,yr,ans; i<=q; i++)
		{
			scanf("%d %d %d %d",&xl,&yl,&xr,&yr);
			ans=a[xr][yr]-a[xr][yl-1]-a[xl-1][yr]+a[xl-1][yl-1];
			ans-=b[xr][yr]-b[xr][yl]-b[xl-1][yr]+b[xl-1][yl];
			ans-=c[xr][yr]-c[xr][yl-1]-c[xl][yr]+c[xl][yl-1];
			printf("%d\n",ans);
		}
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 64896
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef vector<int> VI;

int check(int x, int N, int Q, string S, char* T, int* D) {
  REP(i, Q) {
    if(S[x] == T[i]) {
      x += D[i];
      if(x < 0) return -1;
      if(x >= N) return 1;
    }
  }
  return 0;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  char T[200000];
  int D[200000];
  REP(i, Q) {
    char d;
    cin >> T[i] >> d;
    D[i] = d == 'L' ? -1 : 1;
  }
  
  int L, R;
  { //左に消えない右端
    int min = 0, max = N;
    while(min < max) {
      int mid = (max + min) / 2;
      if(check(mid, N, Q, S, T, D) == -1) {
        min = mid + 1;
      } else {
        max = mid;
      }
    }
    L = min;
  }
  { //右に消える左端
    int min = 0, max = N;
    while(min < max) {
      int mid = (max + min) / 2;
      if(check(mid, N, Q, S, T, D) == 1) {
        max = mid;
      } else {
        min = mid + 1;
      }
    }
    R = min;
  }
  cout << R - L << endl;
}

Measured memory_bytes: 1812
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<queue>
#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
const int mod=1e9+7;
const int inf=1e9+7;
  
//const int maxn=
  
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
      
    int n;
    cin>>n;
    
    string str;
    map<string,int>book;
    int maxx=-1;
    vector<string>v;
    for(int i=0;i<n;i++)
    {
    	cin>>str;
    	book[str]++;
    	
    	if(book[str]>maxx)
    	{
    		maxx=book[str];
    		v.clear();
    		v.push_back(str);
		}
		else if(book[str]==maxx)
		{
			v.push_back(str);
		}
	}
	
	sort(v.begin(),v.end());
	
	for(int i=0;i<v.size();i++)
		cout<<v[i]<<endl;
  
    return 0;
}

Measured memory_bytes: 25456
#include<iostream>
#include<vector>
using namespace std;
using ll=long long;

int main(){
    int N;
    cin>>N;
    vector<int> X(N,0);
    for(int i=0;i<N;i++){
        cin>>X[i];
    }
    ll value=INT64_MAX;
    for(int x=1;x<=100;x++){
        ll sum=0;
        for(int n=0;n<N;n++){
            sum+=(X[n]-x)*(X[n]-x);
        }
        value=min(value,sum);
    }
    cout<<value<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
        long long int n,data[100000],tmp=1,count=0,wrong=0;
        cin >> n;
        for(long long int i=0;i<n;i++){
            cin >> data[i];
        }
        
        sort(data,data+n);
        reverse(data,data+n);
        
        for(long long int i=0;i<n;i++){
            
            
             if(data[0]==data[1] && data[1]==data[2] && data[2]==data[3] ){
            tmp=data[i]*data[i];
            break;
            }
            
             if(data[i]==data[i+1] && data[i]!=data[i-1]){
                count++;
                if(count==3){
                   break;
               }
               tmp*=data[i];
            }
            
            else if(data[i]!=data[i+1]){
                wrong++;
            }
        }
   
    
    if(wrong==n){
        cout << "0" << endl;
        }
        else{
            cout << tmp << endl;
        }
}


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

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

    vector<int> d(n);
    for (int i = 0; i < n; i++) cin >> d.at(i);

    sort(d.begin(), d.end());
    d.erase(unique(d.begin(), d.end()), d.end());

    cout << d.size() << endl;

    return 0;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int N=20,M=1000010,P=1e9+7;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int INF=0xcfcfcfcf;
const db eps=1e-9,pi=asin(1)*2;
inline ll read();
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
inline int ADD(int a,int b) { return a+b>=P?a+b-P:a+b; }
inline int MINUS(int a,int b) { return a-b<0?a-b+P:a-b; }
#define plus(a,b) a=ADD(a,b)
#define minus(a,b) a=MINUS(a,b)
#define mul(a,b) a=(1ll*a*(b))%P
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define mp(x,y) make_pair(x,y)

int n;
int a[N];
inline ll dfs(int l,int r,int x,int y)
{
	if(l>r) return 0;
	ll ans=inf;
	for(int i=l;i<=r;i++)
		cmin(ans,dfs(l,i-1,x,x+y)+dfs(i+1,r,x+y,y)+1ll*(x+y)*a[i]);
	return ans;
}

#ifdef FILE
const int RS=1<<20;
char buf[RS],*p1=buf,*p2=buf;
#define getchar() p1==p2&&(p2=(p1=buf)+fread(buf,1,RS,stdin),p1==p2)?EOF:*p1++
#endif
inline ll read()
{
	ll s=0;
	bool flag=false;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') flag=true;
	for(;'0'<=ch&&ch<='9';ch=getchar()) s=(s<<3)+(s<<1)+(ch^'0');
	if(flag) return -s;
	return s;
}

int main()
{
#ifdef FILE
	freopen(FILE ".in","r",stdin);
	freopen(FILE ".out","w",stdout);
#endif
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	printf("%lld\n",dfs(2,n-1,1,1)+a[1]+a[n]);
	return 0;
}

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

typedef long long ll ; 
const int N  = 2e5+5 ;

int h[N] , a[N] ;
ll dp[N] , seg[4*N] ; 

void update(int p , int s , int e   , int idx , ll val) {
	if (s==e) {
		 seg[p] = val ;
		 return ;
	}
  
  
	if (idx <= (s+e)/2 )
		update (p*2 , s , (s+e)/2 , idx , val) ;
	else 
		update (p*2+1  , (s+e)/2+1  , e , idx , val) ;
	
	
	seg[p] = max(seg[p*2],seg[p*2+1]) ;
}


ll get(int p  , int s , int e , int a , int b) {
	
	
	if (s > b ||  e<a)
		return 0;
 
	if (s>=a && e<=b){
	
		return seg[p] ; 
	}
 
	return max(get(p*2 , s , (s+e)/2 , a , b) ,  get(p*2+1 , (s+e)/2+1 , e , a , b)); 
}
 
 
int main() {
	int n ; 
	scanf("%d" , &n) ; 
	for (int i=0 ; i<n ;++i) {
		scanf("%d" , &h[i]) ; 
		h[i]--;
	}
	for (int i =0 ; i<n ; ++i) {
		scanf("%d" , &a[i]) ; 
	 
	}
	
	ll mx = 0 ;
	for (int i =0 ; i<n ; ++i) {
		ll ans = get(1 ,0 , n-1 , 0 , h[i]-1) ; 
		dp[i] = ans+1ll*a[i] ; 
		update(1 , 0 , n-1 , h[i] , dp[i]) ; 
		mx = max(mx , dp[i]) ;
	}
	printf("%lld\n" , mx) ; 
	return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end() 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
int main(){
    ll t1,t2,a1,a2,b1,b2;
    cin>>t1>>t2>>a1>>a2>>b1>>b2;
    if(a1*t1+a2*t2==b1*t1+b2*t2){
        cout<<"infinity"<<endl;
        return 0;
    }
    if((a1>b1&&a1*t1+a2*t2>b1*t1+b2*t2)||(a1<b1&&a1*t1+a2*t2<b1*t1+b2*t2)){
        cout<<0<<endl;
        return 0;
    }
    ll ans=0;
    if(a1>b1){
        ll dis1=(a1-b1)*t1,dis2=(b2-a2)*t2;
        if(dis1<dis2){
            ll k=dis2-dis1;
            if(dis1%k!=0)ans=(dis1/k)*2+1;
            else ans=(dis1/k-1)*2+2;
        }
    }else{
        ll dis1=-(a1-b1)*t1,dis2=-(b2-a2)*t2;

        if(dis1<dis2){
            ll k=dis2-dis1;
            if(dis1%k!=0)ans=(dis1/k)*2+1;
            else ans=(dis1/k-1)*2+2;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
    int N;
    ll a[300000],f[300000],b[300000];
    cin>>N;
    rep(i,3*N) cin>>a[i];
    priority_queue<ll,vector<ll>,greater<ll>> q;
    priority_queue<ll> Q;
    ll s=0,S=0;
    rep(i,3*N){
        if(i<N){
            s+=a[i];
            q.push(a[i]);
            f[i]=s;
            
            S+=a[3*N-1-i];
            Q.push(a[3*N-1-i]);
            b[3*N-1-i]=S;

            continue;
        }
        if(q.top()<a[i]){
            s=s-q.top()+a[i];
            f[i]=s;
            q.pop();
            q.push(a[i]);
        }else f[i]=s;

        if(Q.top()>a[3*N-1-i]){
            S=S-Q.top()+a[3*N-1-i];
            b[3*N-1-i]=S;
            Q.pop();
            Q.push(a[3*N-1-i]);
        }else b[3*N-1-i]=S;
    }
    ll ans=-1e18;

    rep(i,N+1){
        ans=max(ans,f[i+N-1]-b[i+N]);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 9076
# 数値の取得
num_cnt = int(input())
num_list = list(map(int,input().split()))

# 数値の検査後メッセージを出力
judge = "APPROVED"
for cnt in range(0,num_cnt,1):
    if num_list[cnt] % 2 == 0\
    and num_list[cnt] % 3 != 0\
    and num_list[cnt] % 5 != 0:
      judge = "DENIED"
      
print(judge)

Measured memory_bytes: 9052
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

## BFS

#入力受け取り
N, Q = mi()
x = li2(N-1)

cnt = [0]*(N+1)
for i in range(Q):
    p0, p1 = mi()
    cnt[p0] += p1

#隣接リスト作成
adj = [[] for i in range(N+1)]
for i in range(N-1):
    #x[i][0] -= 1
    #x[i][1] -= 1
    adj[x[i][0]].append(x[i][1])
    adj[x[i][1]].append(x[i][0])

global ans
ans = [0]*(N+1)

def dfs(fr, nx):
    ans[nx] += ans[fr] + cnt[nx]
    for v in adj[nx]:
        if v != fr:
            dfs(nx, v)

dfs(1, 1)

for i in range(1, N+1):
    print(ans[i], '', end='')

Measured memory_bytes: 260712
#include <bits/stdc++.h>
#define MaxN 100000
using namespace std;

vector<int> L[MaxN+1];
int luat[MaxN+1];
int deja[MaxN+1];
int is[MaxN+1];
int p[MaxN+1];
int N, M, res;

void DFS(int x)
{
    ++is[x];
    ++is[ p[x] ];

    luat[x] = deja[x] = 1;
    for(auto y : L[x])
        if(!deja[y]) DFS(y);

    if(is[x] > 1) ++res, --is[x];
    if(is[ p[x] ] > 1) ++res, --is[ p[x] ];
}

void Undo(int x)
{
    is[x] = 0;
    is[ p[x] ] = 0;

    deja[x] = 0;
    for(auto y : L[x])
        if(deja[y]) Undo(y);
}

int main(){


    int i, x, y;

    scanf("%d %d", &N, &M);
    for(i = 1; i <= N; ++i) scanf("%d", &p[i]);
    for(i = 1; i <= M; ++i)
    {
        scanf("%d %d", &x, &y);
        L[x].push_back(y);
        L[y].push_back(x);
    }

    for(i = 1; i <= N; ++i)
        if(!luat[i]){
            DFS(i);
            Undo(i);
        }

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


return 0;
}


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

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

	int res10000 = -1, res5000 = -1, res1000 = -1;

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j + i <= n; j++) {
			int k = n - i - j;
			int total = 10000 * i + 5000 * j + 1000 * k;
			if (total == y) {
				res10000 = i; res5000 = j; res1000 = k;
			}
		}
	}

	cout << res10000 << " " << res5000 << " " << res1000 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n,M[N][N];//グラフ情報
int color[N],d[N],f[N],tt;
int nt[N];

//uに隣接するvを番号順に取得
int next(int u){
    for(int v = nt[u]; v < n;v++){
        nt[u] = v + 1 ;
        if(M[u][v]) return v;
    }
    return -1;
}

//深さ優先探索
void dfs_visit(int r){
    for(int i=0;i<n;i++)nt[i] =0;

    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while(!S.empty()){
        int u = S.top();
        int v = next(u);
        if (v != -1){
            if(color[v] == WHITE){
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs(){
    //初期化
    for(int i=0;i<n;i++){
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;
    for(int u=0;u<n;u++){
        if(color[u]== WHITE) dfs_visit(u);
    }
    for(int i=0;i<n;i++){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}
int main(){
    int u,k,v;

    cin >> n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            M[i][j] = 0;
        }
    }
    for(int i=0;i<n;i++){
        cin >> u >> k;
        u--;
        for(int j = 0;j<k;j++){
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    dfs();
    return 0;
}


Measured memory_bytes: 3144
/*
よかった点
・全て列挙しようとしたところは大変よかった。
しかし、最初に制約に忠実に従ったものを列挙しようとしてしまっていたために、正確に全てを列挙することが難しくなった。
条件を緩くして、3,5,7を含むものを全て列挙する。その中で条件を満たすものと変化させるとよかった。

*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
int hantei(ll n)
{
    string s = to_string(n);
    int a = 0;
    int b = 0;
    int c = 0;
    for (char x : s)
    {
        if (x == '3')
        {
            a = 1;
        }
        else if (x == '5')
        {
            b = 1;
        }
        else if (x == '7')
        {
            c = 1;
        }
    }
    if (a == 1 && b == 1 && c == 1)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
int main()
{

    ll n;
    cin >> n;
    //実際にそれが何個あるのかを数えていくだけでいけそうな問題
    vector<ll> store;
    // queue<ll> que; //まずqを用意
    priority_queue<ll, vector<ll>, greater<ll>> que;
    que.push(0);
    int i = 0; //一つ退けるごとにi+=1
    while (1)
    {
        que.push(que.top() * 10 + 3);
        que.push(que.top() * 10 + 5);
        que.push(que.top() * 10 + 7);
        if (que.top() <= n)
        {

            if (hantei(que.top()))
            {
                i++;
            }
            que.pop();
        }
        else
        {
            break;
        }
    }
    cout << i << endl;
}

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

using namespace std;

#define int long long

typedef pair<int, int> P;

struct Edge {
	int to, cap, cost, rev;
};

const int MAX_V = 500;

const int inf = 1e9;

int V;
vector<Edge> G[MAX_V];
int h[MAX_V] = {0};
int dist[MAX_V];
int prevV[MAX_V], prevE[MAX_V];

void add_edge(int from, int to, int cap, int cost) {
//	cout << from << " " << to << " " << cap << " " << cost << endl;
	G[from].push_back((Edge){to, cap, cost, (int)G[to].size()});
	G[to].push_back((Edge){from, 0, -cost, (int)G[from].size()-1});
}

int min_cost_flow(int s, int t, int f) {
	int res = 0;
//	fill(h, h+V, 0);
	while ( f > 0 ) {
		priority_queue<P, vector<P>, greater<P> > Q;
		fill(dist, dist+V, inf);
		dist[s] = 0;
		Q.push( P(0, s) );
		while ( !Q.empty() ) {
			P p = Q.top(); Q.pop();
//			cout << p.first << " " << p.second << endl;
			int v = p.second;
			if (dist[v] < p.first) continue;
			for (int i = 0; i < G[v].size(); ++i) {
				Edge& e = G[v][i];
				if (dist[e.to] > dist[v]+e.cost+h[v]-h[e.to] && e.cap > 0) {
					dist[e.to] = dist[v]+e.cost+h[v]-h[e.to];
					prevV[e.to] = v;
					prevE[e.to] = i;
					Q.push( P(dist[e.to], e.to) );
				}
			}
		}
		if ( dist[t] == inf ) {
			return -1;
		}
		for (int v = 0; v < V; ++v) {
			h[v] += dist[v];
		}
		int d = f;
		for (int v = t; v != s; v = prevV[v]) {
			d = min(d, G[prevV[v]][prevE[v]].cap);
		}
		f -= d;
		res += d * h[t];
		for (int v = t; v != s; v = prevV[v]) {
			Edge &e = G[prevV[v]][prevE[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	return res;
}

signed main() {
	int A, B, K; cin >> A >> B >> K;
	vector< vector<int> > m(A, vector<int>(B, 0));
	for (int i = 0; i < A; ++i) {
		string a; cin >> a;
		for (int j = 0; j < B; ++j) {
			if (a[j] == '1') {
				m[i][j]++;
			}
		}
	}
	for (int j = 0; j < B; ++j) {
		string a; cin >> a;
		for (int i = 0; i < A; ++i) {
			if (a[i] == '1') {
				m[i][j]++;
			}
		}
	}
/*
	for (int i = 0; i < A; ++i) {
		for (int j = 0; j < B; ++j) {
			cout << m[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
*/
	int s = A + B, t = s + 1;
	V = t+1;
	for (int i = 0; i < A; ++i) {
		for (int j = 0; j < B; ++j) {
			add_edge(i, A+j, 1, m[i][j]);
		}
	}
	for (int i = 0; i < A; ++i) {
		add_edge(s, i, 1, 0);
	}
	for (int i = 0; i < B; ++i) {
		add_edge(A+i, t, 1, 0);
	}

	int cost = 0;
	int ans = 0;
	for (int i = 0; i < min(A, B); ++i) {
		int c = min_cost_flow(s, t, 1);
//		cout << c << endl;
		if (c < 0) break;
		cost += c;
		if ( cost <= K ) {
			ans = max(ans, i+1);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6740
#include <stdio.h>

void display(int n, int m) {
    int i, j;
    for(i = 0; i < n; i++) {
        if(i == 0 || i == n-1) {
            for(j = 0; j < m; j++) {
                printf("#");
            }
        } else {
            printf("#");
            for(j = 1; j < m - 1; j++) {
                printf(".");
            }
            printf("#");
        }
        printf("\n");
    }
    
}
int main() {
    int i, j, k;
    int num[300][300] = {0};
    
    i = 0;
    while(1) {
        j = 0;
        scanf("%d %d", &num[i][j], &num[i][j+1]);
        if(num[i][j] == 0 && num[i][j] == 0) break;
        i++;
    }
    
    for(k = 0; k < i; k++) {
        j = 0;
        display(num[k][j], num[k][j+1]);
        printf("\n");
    }
    
    return 0;
}



Measured memory_bytes: 2148
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    if (a+b > a+c)
    {
        cout << ((a+c > b+c) ? (b+c) : (a+c)) << endl;
    }
    else
    {
        cout << ((a+b > b+c) ? (b+c) : (a+b)) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N = int(input())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]

times = 0

for i in range(N):
    if As[i] - Bs[i] > 0:
        times += Bs[i]
    else:
        if Bs[i] - As[i] < As[i+1]:
            times += Bs[i]
            As[i+1] -= Bs[i] - As[i]
        else:
            times += As[i] + As[i+1]
            As[i+1] = 0

print(times)


Measured memory_bytes: 18624
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>

using namespace std;

int L,R;

int main()
{
	cin>>L>>R;
	long long ans=999999999;
	if(L/2019!=R/2019)
	{
		cout<<"0"<<endl;
		return 0;
	}
	else
	{
		for(long long i=L;i<=R;i++)
			for(long long j=i+1;j<=R;j++)
				ans=min(i*j%2019,ans);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,k;
ll a[200010],b[200010];
ll inf = 1e18;
int main() {
    cin >> n >> m >> k;
    ll ans = 0;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= m; i++) cin >> b[i];
    for (ll i = 1; i <= n; i++) {
        a[i] += a[i-1];
    }
    for (ll i = 1; i <= m; i++) {
        b[i] += b[i-1];
    }
    a[n+1] = inf;
    b[m+1] = inf;
    for (ll i = 0; i <= n; i++) {
        if (a[i] > k) break;
        ll lft = k - a[i];
        ans = max(ans, i + (upper_bound(b,b+m+2,lft) - b - 1));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6704
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <numeric>
using namespace std;
using Int = long long;
#define REP(i, n) for(int i = 0; i < n; i++)
#define DUMP(range) do{for(auto& x:range){cout<<x<<' ';}cout<<endl;}while(0)
int main()
{
    int N, L; cin >> N >> L;
    vector<string> S(N); for(auto&s:S)cin >> s;
    sort(S.begin(), S.end());
    for(auto&s:S)cout<<s;
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159265358979323

//int calc1(float a,float b,float c,float d,float e,float f,float *x,float *y);
//void quick(int *,long long,long long);
//int comp(char *a,char *b);

int main(){
	
	double xa,ya,xb,yb,ra,rb,kyori;
	int n;

	scanf("%d",&n);
	while(n>0){
		scanf("%lf %lf %lf %lf %lf %lf",&xa,&ya,&ra,&xb,&yb,&rb);
		kyori=sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
		if(ra>kyori+rb)
			printf("2\n");
		else if(ra+kyori<rb)
			printf("-2\n");
		else if(ra+rb>=kyori)
			printf("1\n");
		else
			printf("0\n");
		n--;
	}
	return 0;
}

Measured memory_bytes: 620
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <queue>

using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

struct Node{
    vector<int> to_right;
    vector<int> cost_right;
    ll position; // 位置
    int used; // 0: 未決定　1:決定
};
vector<Node> node(100000);

bool endFlag = false;

void dfs(vector<Node> &n, int id){

    if(endFlag) return;

    for (int i = 0; i < n[id].to_right.size(); i++){
        int next = n[id].to_right[i];
        if(n[next].used == 1){
            if(n[next].position != n[id].position + n[id].cost_right[i] ){
                endFlag = true;
            }
        }
        else{
            n[next].position = n[id].position + n[id].cost_right[i];
            n[next].used = 1;
            dfs(n, next);
        }
        if(endFlag) return;
    }

}


int main(){

    int N, M;
    cin >> N >> M;

    for(int i = 0; i < N; i++){
        node[i].position = 0;
        node[i].used = 0;
    }

    for(int i = 0; i < M; i++){
        int left, right, dist;
        cin >> left >> right >> dist;
        left --;
        right --;
        node[left].to_right.push_back(right);
        node[left].cost_right.push_back(dist);
        node[right].to_right.push_back(left);
        node[right].cost_right.push_back(-dist);
    }


    for(int i = 0; i < N; i++){
        if(node[i].used == 0){
            node[i].used = 1;
            dfs(node, i);            
        }
    }

    if(endFlag){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }

}


Measured memory_bytes: 16640
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

int main() {
    double h, a;
    cin >> h >> a;
    cout << ceil(h / a) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int a,b,c;
  int n=0;
  scanf("%d %d %d",&a,&b,&c);
  if(((a==b)&&(a!=c))||((a==c)&&(a!=b))||((b==c)&&(a!=b))){
    n=1;
  }
  if(n==0){
    printf("No");
    }
    else{
      printf("Yes");
    }
     return 0;
}
  

Measured memory_bytes: 1716
def gcd(a,b)
  a.gcd(b)
end

n,X = gets.split.map(&:to_i)
x = gets.split.map{|v| (v.to_i-X).abs}

ans = x[0]

(1..(n-1)).each do |i|
  ans = gcd(ans, x[i])
end

puts ans

Measured memory_bytes: 8452
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
long long l,x=-1,y=-1;
int main()
{
	string a;
	getline(cin,a);
	l=a.size();
	for(int i=0;i<l;i++)
	{
		if(a[i]=='C') 
		{
		x=i; 	
		}
		if(a[i]=='F') 
		{
		y=i;	
		if(x!=-1) break;
		}
	}
	if(x==-1||y==-1) 
	{
		cout<<"No";
		return 0;
	}
	if(x<y)
	{
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
	return 0;
}

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

using namespace std;

int main() {
	int a, b, c, n;
	int ans = 0;
	cin >> a >> b >> c >> n;
	for (int aa = 0; aa <= a; aa++) {
		for (int bb = 0; bb <= b; bb++) {
			for (int cc = 0; cc <= c; cc++) {
				if (500 * aa + 100 * bb + 50 * cc == n) {
					ans++;

				}

			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#define N 3005
using namespace std;
string s1,s2;
int dp[N][N],z[N][N];
char ans[N]; 
int k=0;
void getans(int i,int j){
	if(i<=0||j<=0)
		return ;
	if(z[i][j]==1){
		ans[k++]=s1[i-1];
		getans(i-1,j-1);
	}
	else if(z[i][j]==2){
		getans(i-1,j);
	}
	else if(z[i][j]==3){
		getans(i,j-1);
	} 
}
int main(){
	cin>>s1>>s2;
	int len1=s1.length();
	int len2=s2.length();
	for(int i=1;i<=len1;i++){
		for(int j=1;j<=len2;j++){
			if(s1[i-1]==s2[j-1]){
				dp[i][j]=dp[i-1][j-1]+1;
				z[i][j]=1;
			}
			else{
				if(dp[i-1][j]>=dp[i][j-1]){
					z[i][j]=2;
					dp[i][j]=dp[i-1][j];
				}
				else{
					z[i][j]=3;
					dp[i][j]=dp[i][j-1];
				}
			}
		}
	}
//	cout<<dp[len1][len2]<<endl;
	getans(len1,len2);
	for(int i=k-1;i>=0;i--){
		cout<<ans[i];
		if(i==0){
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 70784
#include <stdio.h>
#include <math.h>

int main(void){
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  if(a + b == c || b + c == a || c + a == b){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n;
    cin >> n;
    s64 c;
    cin >> c;

    vs64 x(n), y(n), v(n);
    vs64 rs(n), ls(n), rM(n + 1), lM(n + 1);
    s64 s = 0;
    rM[0] = lM[0] = 0;
    rs[0] = ls[0] = 0;
    rep (i, n)
    {
        cin >> x[i] >> v[i];
        s += v[i];
        rs[i] = s - x[i];
        rM[i + 1] = MAX(rM[i], rs[i]);
    }
    s = 0;
    rep (i, n)
    {
        y[i] = c - x[n - i - 1];
        s += v[n - i - 1];
        ls[i] = s - y[i];
        lM[i + 1] = MAX(lM[i], ls[i]);
    }

    s64 ans = 0;
    // go right at first
    rep (i, n)
    {
        s64 v1 = rs[i] - x[i] + lM[n - i - 1];
        s64 v2 = rs[i];
        ans = MAX(ans, MAX(v1, v2));
    }

    // go left
    rep (i, n)
    {
        s64 v1 = ls[i] - y[i] + rM[n - i - 1];
        s64 v2  = ls[i];
        ans = MAX(ans, MAX(v1, v2));
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 5760
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		double r = scan.nextDouble();
		
		System.out.print(String.format("%.6f", r * r * Math.PI));
		System.out.println(" "+ String.format("%.6f",2 * r * Math.PI));
		
	}
}


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

#define PrintLn(X) cout << X << endl
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;
const int md = 1000000007;

int main(void)
{
	int N;
	cin >> N;
	ll ans = 1;
	Rep(i, N){
		ans *= (i + 1);
		ans %= md;
	}
	PrintLn(ans);
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int a[110000];
int main() {
	int n,k;scanf("%d%d",&n,&k);int ans=999999999;
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	for(int i=1;i<=n-k+1;i++) {
		if(a[i]>=0)ans=min(abs(a[i+k-1]),ans);
		else if(a[i+k-1]<=0)ans=min(abs(a[i]),ans);
		else if(a[i]<0 && a[i+k-1]>0)ans=min(a[i+k-1]-a[i]+min(abs(a[i]),a[i+k-1]),ans);
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
  int N, M; cin >> N >> M;
  vector<int> S(M);
  vector<char> C(M);
  for (int i = 0; i < M; i++) cin >> S.at(i) >> C.at(i);

  for (int i = 0; i < 1000; i++) {
    string s = to_string(i);
    if (s.size() != N) continue;
    bool isMatch = true;
    for (int j = 0; j < M; j++) {
      int sj = S.at(j);
      if (sj > N) continue;
      if (s.at(sj-1) != C.at(j)) isMatch = false;
    }
    if (isMatch) { cout << i << endl; return 0; }
  }
  cout << -1 << endl;
}

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

int main() {
    while (true) {
        int n, a, b, c, x;
        cin >> n >> a >> b >> c >> x;
        if ((n | a | b | c | x) == 0) {
            break;
        }
        int* randomNums = new int [n];
        for (int i = 0; i < n; i++) {
            cin >> randomNums[i];
        }
        int reel = 0, time = 0;
        while (reel < n && time <= 10001) {
            if (randomNums[reel] == x) {
                reel++;
            }
            x = (a * x + b) % c;
            time++;
        }
        if (time <= 10001) {
            cout << time - 1 << endl;
        } else {
            cout << -1 << endl;
        }
        delete[] randomNums;
    }
}

Measured memory_bytes: 908
import sys
sys.setrecursionlimit(500*500)

N =int(input()) 
H = list(map(int, input().split())) 
  
memo = [-1]*N 
def func(n,memo): 
  if n == 0: 
    memo[0] = 0 
    return memo[n] 
  elif n == 1: 
    memo[1] = abs(H[1]-H[0]) 
    return memo[n] 
  else: 
    if memo[n] != -1: 
      return memo[n] 
    else: 
      min_c = min(func(n-1,memo)+abs(H[n]-H[n-1]), func(n-2,memo)+abs(H[n]-H[n-2])) 
      memo[n] = min_c 
    return min_c 
  
print(func(N-1,memo)) 

Measured memory_bytes: 94100
N,M=map(int,input().split())
s=[]
c=[]
for i in range(M):
    a,b=map(int,input().split())
    s.append(a)
    c.append(b)
found=False
start=pow(10,N-1)
stop=pow(10,N)
if N==1:
    start=0
for i in range(start,stop):
    i_str=str(i)
    passed=True
    for j in range(M):
        if not i_str[s[j]-1]==str(c[j]):
            passed=False
            break
    if passed:
        found=True
        print(i)
        break
if not found:
    print('-1')


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

int number(string &s, int &iter) {
	int ret = 0;
	while ('0' <= s[iter] && s[iter] <= '9') {
		ret *= 10;
		ret += s[iter] - '0';
		iter++;
	}
	return ret;
}

int dfs(string &s, int &iter, int pos) {
	int len = 0;
	int start = iter;
	
	while (iter < s.length()) {
		if ('A' <= s[iter] && s[iter] <= 'Z') {
			if (len == pos) { cout << s[iter] << endl; }
			len++;
			if (len > 1000010) len = 1000010;
			iter++;
		}
		else if ('0' <= s[iter] && s[iter] <= '9') {
			int num = number(s, iter);
			if (s[iter] == '(') {
				iter++;
				int tmpIter = iter;
				int resLen = dfs(s, iter, -1);
				if (len <= pos && pos < len + resLen * num) {
					iter = tmpIter;
					dfs(s, iter, (pos - len) % resLen);
				}
				len += resLen * num;
				if (len > 1000010) len = 1000010;
			}
			else {
				if (len <= pos && pos < len + num) {
					cout << s[iter] << endl;
				}
				len += num;
				if (len > 1000010) len = 1000010;
				iter++;
			}
		}
		else if (s[iter] == ')') {
			iter++;
			break;
		}
	}
	return len;
}


int main() {
	string s;
	int pos;
	while (cin >> s >> pos) {
		if (s == "0") break;
		int iter = 0;
		int length = dfs(s, iter, pos);
		if (length <= pos) { cout << 0 << endl; }
	}
	return 0;
}


Measured memory_bytes: 3208
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll h, n;
    cin >> h >> n;

    vl a(n);
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }

    if(sum >= h) {
        out("Yes");
    }
    else {
        out("No");
    }

    re0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

struct medicine{
	int a,b,c;
};
const int INF = 1e9;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n,ma,mb;
	cin >> n >> ma >> mb;
	vector<medicine> med(n);
	int dp[412][412];
	fill(dp[0],dp[412],INF);
	REP(i,n)cin >> med[i].a >> med[i].b >> med[i].c;
	dp[0][0] = 0;
	int ans = INF;
	REP(i,n){
		for(int j = 400;j >=0;j--){
			for(int k = 400;k >= 0;k--){
				if(dp[j][k] != INF){
					dp[j+med[i].a][k+med[i].b] = min(dp[j][k] + med[i].c,dp[j+med[i].a][k+med[i].b]);
				if((j+med[i].a)*mb == (k+med[i].b)*ma)ans = min(dp[j+med[i].a][k+med[i].b],ans);
			}
			}
		}
	}
	if(ans == INF)cout << -1 << endl;
	else cout << ans << endl;
	
  return 0;
}


Measured memory_bytes: 896
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: 0
    val matrix = Array(n){IntArray(n)}
    for (i in 0 until n) {
        val input = readLine()?.split(" ".toRegex())?.map(String::toInt) ?: return
        if (input[1] > 0) {
            input.subList(2, 2 + input[1]).forEach {
                matrix[input[0] - 1][it - 1] = 1
            }
        }
    }
    println(matrix.joinToString("\n") {
        it.joinToString(" ")
    })
}


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

#define ll long long
#define pb push_back
#define mp make_pair

void solve() {

	ll n;
	cin >> n;
	ll a[n];
	ll tot = 0;
	ll cnt[100007] = {0};
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		tot = tot + a[i];
		cnt[a[i]]++;
	}

	ll m;
	cin >> m;
	for (int i = 0; i < m; i++) {
		ll x,y;
		cin >> x >> y;
		tot = tot + (cnt[x]*(y-x));
		cnt[y] += cnt[x];
		cnt[x] = 0;
		
		cout << tot << endl;
	}






}


int main()
{

	ios::sync_with_stdio(0);
	cin.tie(0);

	ll T;
	T = 1;
	//cin >> T;
	while (T--) {
		solve();
	}




}


Measured memory_bytes: 5168
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int dp[110000][110][2];
string K;
int d;

int main() {
    cin >> K >> d;
    int n = K.size();
    dp[0][0][1] = 1;

    for (int i = 1; i<= n; i++) {
        for (int j = 0; j < d; j++) {
            int digit = K[i-1] - '0';
            for (int k = 0; k < 10; k++) {
                dp[i][j][0] += dp[i-1][((j-k)%d+d)%d][0];
                if (k < digit) {
                    dp[i][j][0] += dp[i-1][((j-k)%d+d)%d][1];
                }
                dp[i][j][0] %= MOD;
                dp[i][j][1] = dp[i-1][((j-digit)%d+d)%d][1];
            }
        }
    }
    Int ans = (dp[n][0][0] + dp[n][0][1] + MOD - 1) % MOD;
    cout << ans << endl;
}

Measured memory_bytes: 18688
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
const int MAXN=210000;
typedef long long ll;
ll mymin(ll x,ll y) {return x<y?x:y;}
ll mymax(ll x,ll y) {return x>y?x:y;}

int n;
int a[MAXN];
ll sum[MAXN];
int find2(ll d)//<=d
{
    int l=0,r=n,ans;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(sum[mid]>=d) ans=mid,r=mid-1;
        else l=mid+1;
    }
    return ans;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum[i]=sum[i-1]+a[i];
    }

    ll ans=ll(0x3f3f3f3f)*ll(0x3f3f3f3f);


    for(int mid2=1;mid2<=n;mid2++)
    {
        int tmp1=find2(sum[mid2]/2);
        for(int mid1=tmp1-1;mid1<=tmp1+1;mid1++)
        {
            if( !(1<=mid1 and mid1<mid2) ) continue;
            //1~mid1
            //mid1+1~mid2
            //mid2+1~mid3
            //mid3+1~n
            int tmp3=find2( sum[mid2]+(sum[n]-sum[mid2])/2 );
            for(int mid3=tmp3-5;mid3<=tmp3+5;mid3++)
            {
                if( !(mid2<mid3 and mid3<n) ) continue;

                ll A,B,C,D;
                A=sum[mid1];
                B=sum[mid2]-sum[mid1];
                C=sum[mid3]-sum[mid2];
                D=sum[n]-sum[mid3];

                ll mi=mymin( mymin(A,B),mymin(C,D) );
                ll mx=mymax( mymax(A,B),mymax(C,D) );
                if(mx-mi<ans) ans=mx-mi;
            }
        }
    }
    printf("%lld",ans);
}


Measured memory_bytes: 2560
s = input()
t = input()

if len(s) < len(t):
    print('UNRESTORABLE')
    exit()

s = [x for x in s[::-1]]
t = [x for x in t[::-1]]    

for i in range(len(s)-len(t)+1):
  flg = False
  cnt = 0
  for j in range(len(t)):
    if s[i+j] == '?':
      cnt += 1
      continue
    if s[i+j] == t[j]:
      flg = True
    else:
      flg = False
      break
  if flg or cnt == len(t):
    s[i:i+len(t)] = t
    flg = True
    break

if not flg:
    print('UNRESTORABLE')
    exit()

ans = ''
s = [x for x in s[::-1]]
for i in range(len(s)):
  if s[i] == '?':
    s[i] = 'a'
  ans += s[i]
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;

int main(){
    vector<int> m,f,r;
    int m1,f1,r1;
    do{
        cin>>m1>>f1>>r1;
        m.push_back(m1);
        f.push_back(f1);
        r.push_back(r1);
    }while (m1!=-1 || f1!=-1 || r1!=-1);
    int i;
    for (i=0;i<m.size()-1;i++){
        char c;
        if (m[i]==-1 || f[i]==-1){
            c='F';
        }else if (m[i]+f[i]>=80){
            c='A';
        }else if (m[i]+f[i]>=65){
            c='B';
        }else if (m[i]+f[i]>=50){
            c='C';
        }else if (m[i]+f[i]>=30){
            if (r[i]>=50){
                c='C';
            }else{
                c='D';
            }
        }else{
            c='F';
        }
        cout<<c<<endl;
    }
    return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
 
  if ( (A + B) - (C + D) == 0) {
    cout << "Balanced" << endl;
  }
  else if (A + B > C + D) {
    cout << "Left" << endl;
}
  else{
    cout << "Right" << endl;
}
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)    (x).begin(),(x).end()
# define UNIQ(c)   (c).erase(unique(ALL((c))), end((c)))
# define mp        make_pair
# define eb        emplace_back
# define REP       (i, a) for (int i = 0; i < (a); i++)
# define INIT      std::ios::sync_with_stdio(false);std::cin.tie(0);
LL x, y;

int main() {
	INIT;
	cin >> x >> y;
	LL num = x;
	int count = 0;
	while (num<=y) {
		num *= 2;
		count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    i = 1
    count = 10000000000000
    while i * i <= N:
        if N % i == 0:
            A = N / i
            B = N / A
            count = min(count, (A - 1) + (B - 1))
        i += 1
    print(int(count))


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

inline ll input() {
    ll n;
    cin >> n;
    return n;
}

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

set_random;

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
const ll MOD2 = 1e9 + 7;
const ll MOD3 = 1e9 + 9;

ll n , p[MAXN] , dp[MAXN][2];

int main() {
    fast_io;

    cin >> n;
    for(ll i = 1 ; i <= n ; i++)    cin >> p[i];

    dp[1][0] = p[1];
    dp[1][1] = -p[1];
    for(ll i = 2 ; i <= n ; i++)
    {
        dp[i][0] = max(dp[i - 1][0] + p[i] , dp[i - 1][1] - p[i]);
        dp[i][1] = max(dp[i - 1][0] - p[i] , dp[i - 1][1] + p[i]);
    }
    cout << dp[n][0] << endl;

    return 0;
}
/*
todo :
    1- set constants
    2- check TimeLimit and MemoryLimit
    3- check special test cases
    4- don't forget BS can help you that is good idea(use for loop for floats)
    5- don't forget printf and scanf can help you in your code speed
*/


Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int n;
  int k[100];
  int num;
  string s;
  string ans;
  int alp[52];
  rep(i,52){
    if(i<26) alp[i]=i+65;
    else alp[i]=i+71;
  }
  while(1){
    cin>>n;
    if(n==0) break;
    rep(i,n){
      cin>>k[i];
    }
    cin>>s;
    ans="0";
    rep(i,s.size() ){
      rep(j,52){
	if(alp[j]==s[i]) num=j;
      }
      int a=(num-k[i%n]+520)%52;
      //cout<<a<<endl;
      ans+=alp[a];
      //cout<<ans<<endl;
    }
    repi(i,1,ans.size()){
      cout<<ans[i];
    }
    cout<<endl;
  }

  return 0;
}













Measured memory_bytes: 3140
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int ans = 1;
        for(int i=2; i<=x; i++){
            int b = i * i;
            while(b <= x){
                ans = Math.max(ans, b);
                b = b*i;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 22996
#include <stdio.h>
#include <math.h>
 
int main(){
 
  int i, n, input, max, min;
 
  scanf("%d", &n);
  scanf("%d", &input);
 
  max = -1000000000;
  min = input;
  for(i = 1; i <= n-1; i++){
    scanf("%d", &input);
    max = fmax(max, input-min);
    min = fmin(min, input);
  }
  printf("%d\n", max);
 
  return 0;
}

Measured memory_bytes: 600
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int cmp(int x,int y)
{
    return x>y;
}
int main()
{
    int a[105],n,vis[105],b=0,c=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    scanf("%d",&a[i]);
    memset(vis,0,sizeof(vis));
    sort(a,a+n,cmp);
    for(int i=0;i<n;i+=2)
    b+=a[i];
    for(int i=1;i<n;i+=2)
    c+=a[i];
    printf("%d",b-c);
}

Measured memory_bytes: 128