akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e9) + 1;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
#define scn(n) scanf("%d", &n)
#define scns(s) scanf("%s", &s)
#define pri(n) printf("%d", n)
#define priln(n) printf("%d\n", n)
#define pris(s) printf("%s", s)
#define prisln(s) printf("%s\n", s)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
  int n;
  scn(n);

  int a[n];
  rep(i, n) scn(a[i]);

  int ans = INF;
  reps(i, 100) {
    int sum = 0;
    rep(j, n) {
      sum += abs(a[j] - i) * abs(a[j] - i);
    }
    chmin(ans, sum);
  }
  pri(ans);
  return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair
int N;
LL A[200000];
LL B[200000];
int main(){
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> A[i];
		B[i] = A[i];
	}
	sort(B, B+N);
	
	for(int i=0; i<N; i++){
		if(A[i] == B[N-1]) cout << B[N-2] << endl;
		else cout << B[N-1] << endl;
	}
	
}


Measured memory_bytes: 4736
# coding: utf-8

def main():
    N = input()
    X = list(map(int, input().split()))
    ans = 1000001

    for i in range(1, 101):
        tmp = sum([(x - i) ** 2 for x in X])
        if tmp < ans:
            ans = tmp

    print(ans)

if __name__ == "__main__":
    main()


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

int main()
{
    int A[3][3];
    for (int i = 0; i < 3; ++i){
        cin >> A[i][0] >> A[i][1] >> A[i][2];
    }

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

    for (int I = 0; I < N; ++I){
        for (int i = 0; i < 3; ++i){
            for (int j = 0; j < 3; ++j){
                if(A[i][j] == B[I]){
                    A[i][j] = 0;
                }
            }
        }
    }

    if( (A[0][0] == 0 and A[0][1] == 0 and A[0][2] ==0) or
        (A[1][0] == 0 and A[1][1] == 0 and A[1][2] ==0) or
        (A[2][0] == 0 and A[2][1] == 0 and A[2][2] ==0) or
        (A[0][0] == 0 and A[1][0] == 0 and A[2][0] ==0) or
        (A[0][1] == 0 and A[1][1] == 0 and A[2][1] ==0) or
        (A[0][2] == 0 and A[1][2] == 0 and A[2][2] ==0) or
        (A[0][0] == 0 and A[1][1] == 0 and A[2][2] ==0) or
        (A[0][2] == 0 and A[1][1] == 0 and A[2][0] ==0)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define cy cout<<"Yes"
#define cn cout<<"No"
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7
#define LINF 1e18+10  
using ll = long long; 

using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
using Ps=pair<int,string>;

using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvl =vector<vector<ll>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}

//const ll mod=998244353;
const ll mod=1e9+7;
const ll MAX=300000;

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

int main(){

    int k;
    cin>>k;
    int a=7;
    vi check(k);
    bool ans=true;
    int b=a%k;
    int cnt=0;
    while(1){
        cnt++;
        if(b==0)break;
        if(check[b]==1){
            ans=false;
            break;
        }
        check[b]=1;
        b=b*10+7;
        b%=k;
    }
    if(ans)cout<<cnt<<endl;
    else cout<<-1<<endl;
    return 0;

}

Measured memory_bytes: 7132
N, M = map(int, input().split())
shops = [tuple(map(int, input().split())) for _ in range(N)]
shops.sort()
cost = 0
for shop in shops:
    value, amount = shop
    if amount < M:
        cost += value * amount
        M -= amount
    else:
        cost += value * M
        break
print(cost)


Measured memory_bytes: 17004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
}

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
}

int n;
void solve(int i,int j,string s){
  if(i==n) {
    cout<<s<<endl;
    return;
  }
  for(int k=0;k<=j;k++){
    char u=k+'a';
    solve(i+1,j,s+u);
  }
  char u=j+1+'a';
  if(i!=0) solve(i+1,j+1,s+u);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int i,j;
  cin>>n;
  solve(0,0,"");
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    cin >> n;
    if(n%10==3){
        cout << "bon" << endl;
    } else if(n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8){
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b) {if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b) {if(a<b) a=b;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int n = s.length();
    int k; cin >> k;
    REP(i,n) {
        if(s[i]=='a') continue;
        if(k-('z'-s[i])>0) {
            k -= ('z'-s[i])+1;
            s[i]='a';
        }
    }
    k %= 26;
    while(k>0) {
        if(s[n-1]=='z' && k-1>0) s[n-1]='a';
        else ++s[n-1];
        --k;
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 592
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

int D;
int c[32];
int s[512][32];
int ans[512];

void inp(){
    cin>>D;
    for(int i=1;i<=26;i++){
        cin>>c[i];
    }
    for(int i=1;i<=D;i++){
        for(int j=1;j<=26;j++){
            cin>>s[i][j];
        }
    }
}

void ans_inp(){
    for(int i=1;i<=D;i++){
        cin>>ans[i];
    }
}

void ans_ran(){
    for(int i=1;i<=D;i++){
        ans[i]=rand()%26+1;
    }
}

int man_calc(bool disp){
    int l[32]={0};
    int man=0;
    for(int i=1;i<=D;i++){
        int n=ans[i];
        l[n]=i;
        man+=s[i][n];
        for(int j=1;j<=26;j++){
            man-=c[j]*(i-l[j]);
        }
        if(disp) cout<<man<<endl;
    }
    return man;
}

void ans_disp(){
    for(int i=1;i<=D;i++){
        cout<<ans[i]<<endl;
    }
}

int change_ans(int i,int n,bool f){
    int ret=0;
    if(f){
        int fr=ans[i];
        ret+=s[i][n];
        ret-=s[i][fr];

        //cout<<ret<<endl;
        int fl=0;
        for(int j=1;j<=i-1;j++){
            if(ans[j]==fr) fl=0;
            else fl++;
        }
        for(int j=i;j<=D;j++){
            if(ans[j]==fr&&j!=i) break;
            ret-=c[fr]*(fl+1);
        }
        //cout<<ret<<endl;
        int tl=0;
        for(int j=1;j<=i-1;j++){
            if(ans[j]==n) tl=0;
            else tl++;
        }
        for(int j=i;j<=D;j++){
            if(ans[j]==n) break;
            ret+=c[n]*(tl+1);
        }
        //cout<<ret<<endl;
    }
    ans[i]=n;
    //cout<<ret<<endl;
    return ret;
}

void solve_C(){
    int M;
    cin>>M;
    int man=man_calc(false);
    //cout<<man<<endl;
    for(int i=0;i<M;i++){
        int from,to;
        cin>>from>>to;
        int cng=change_ans(from,to,true);
        man+=cng;
        cout<<man<<endl;
    }
}

void random_solve(){
    int seed=1234;
    int cnt=1000000;
    srand(seed);
    ans_ran();
    int bc=D/2,bt=13;
    for(int i=0;i<=cnt;i++){
        int ci=bc+rand()%3-1;
        if(ci<=0) ci+=D;
        ci%=D;
        bc=ci;
        int tn=bt+rand()%3-1;
        if(tn<=0) tn+=26;
        tn%=26;
        bt=tn;
        int fn=ans[ci];
        if(tn==fn){
            tn=(tn+1)%26;
        }
        //cout<<ci<<","<<bt<<endl;
        int cng=change_ans(ci,tn,true);
        if(cng<0){
            change_ans(ci,fn,false);
        }
    }
    ans_disp();
    //cout<<man_calc(false)<<endl;
}

signed main(){
    inp();
    //ans_inp();
    //solve_C();
    random_solve();
    return 0;
}



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

int main() {
  long n, k;

  cin >> n >> k;

  vector<long> array(1e5 + 1);

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

  for (int i = 1; i <= 1e5 + 1; i++) {
    if (k <= array[i]) {
      cout << i;
      break;
    }
    k -= array[i];
  }

  return 0;
}

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

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

int main() {
    int n; cin >> n;
    vector<int> v(n), c(n);
    rep(i, n) cin >> v[i];
    rep(i, n) cin >> c[i];

    int ans = 0;
    rep(i, n) ans += max(v[i]-c[i], 0);

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


Measured memory_bytes: 256
// Nihesh Anderson - knandy

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

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll MOD=1000000007;

#define fast_cin() ios_base::sync_with_stdio(false)
#define pb push_back
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define debug1(x) cerr << x << endl;
#define debug2(x,y) cerr << x << " " << y << endl;
#define debug3(x,y,z) cerr << x << " " << y << " " << z << endl;
#define FOR(i, a, b) for (ll i=a; i<(b); i++)
#define FORR(i, a, b) for (ll i=a; i>=(b); i--)
ll INF = 2000000000000000001;
double EPS = 1e-9;
ll nextll(){ll inp; cin>>inp; return inp;}
string nextStr(){string inp; cin>>inp; return inp;}
double nextDouble(){double inp; cin>>inp; return inp;}
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{ll res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(ll* a, ll* b){shuffle(a,b,grndm);}

int main(){
	fast_cin();
	ll n;
	cin>>n;
	ll prev=-1, cur;
	ll count = 0,ans=0;
	FOR(i,0,n){
		cin>>cur;
		if(cur == prev){
			count++;
		}
		else{
			prev=cur;
			ans+=(count/2);
			count=1;
		}
	}
	ans+=(count/2);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
            
            using namespace std;
             
            int main(){
                int a,b,c,d,t;
                cin >> a >> b >> c >> d;
                t = min(b,d) - max(a,c);
                if(t<0){t = 0;}
                cout << t << endl;
                 
                return 0;
            }

Measured memory_bytes: 256
<?php
$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
//list($N,$K) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));

if ($N>=30) {
  printf("Yes\n");
}
else {
  printf("No\n");
}


Measured memory_bytes: 16240
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll  long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
const int INF=1e5+5;
int main(){
ios_base::sync_with_stdio(0);
ll int t,i,j,n,k,m,x,y,flag=0,sum=0,ans=0;
//cin>>t;
t=1;
while(t--){
string a,b;
cin>>a;
cin>>b;
int ans=INT_MAX;
    n=a.length();
    m=b.length();
fo(i,n-m+1){
   int cnt=0;
    fo(j,b.length()){
        if(a[i+j]!=b[j])cnt++;
    }
    ans=min(ans,cnt);
}
cout<<ans;
}
return 0;
}
int mpow(int base, int exp) {
    base %= mod;
    int result = 1;
    while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
    }
    return result;
}


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

if N >= 2 and M >= 2:
    ans = (N-2)*(M-2)
elif N == 1 and M >= 2:
    ans = M-2
elif N >= 2 and M == 1:
    ans = N-2
else:
    ans = 1

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#include <queue>
#include <string.h>
#include <bitset>
#define ll long long int
#define ld long double
#define rep(i,n) for(int i = 0;i < n;i++)
#define rep1(i,n) for(int i = 1;i < n;i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "
#define all(x) x.begin(),x.end()
#define allr(x) x.begin(),x.end(),greater<int>()
#define P pair<ll,ll>
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1ll << 60
#define PI 3.14159265359

using namespace std;

int main(){
	int n,m;
	cin >> n >> m;
	cout << n*m << endl;
	return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ll long long
#define lb(x) ((x)&(-x))
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define de(x) cout<<x<<" x"<<endl
#define LCAFA rep(i,1,20)rep(j,1,n+1)fa[j][i]=fa[fa[j][i-1]][i-1]
#define all(x) x.begin(),x.end()
#define ls(x) x<<1
#define rs(x) x<<1|1
using namespace std;
const int N=2e5+9;
const ll mod=998244353;
int deg[N],cnt[2];
vi g[N];
int num[3][N],p[N],pos[3];
void dfs(int u,int f){
	deg[u]=deg[f]^1;
	cnt[deg[u]]++;
	for(auto v:g[u]){
		if(v==f)continue;
		dfs(v,u);
	} 
}
int main(){
	int n;
	scanf("%d",&n);
	rep(i,1,n){
		int u,v;
		scanf("%d%d",&u,&v);
		g[u].pb(v);g[v].pb(u);
	} 
	dfs(1,0);
	rep(i,1,n+1){
		int m=i%3;
		num[m][++num[m][0]]=i;
	}
	if(cnt[0]<cnt[1]){
		if(cnt[0]<num[2][0]){
			rep(i,1,n+1)if(!deg[i])p[i]=num[0][++pos[0]];
			rep(i,1,n+1){
				if(!p[i]){
					rep(j,0,3){
						if(pos[j]<num[j][0]){
							p[i]=num[j][++pos[j]];
							break;
						}
					}
				}
			}
		}
		else{
		//	cout<<"ok\n";
			rep(i,1,n+1){
				if(!deg[i]){
					if(pos[2]<num[2][0])p[i]=num[2][++pos[2]];
					else p[i]=num[0][++pos[0]];
				}
				else{
					if(pos[1]<num[1][0])p[i]=num[1][++pos[1]];
					else p[i]=num[0][++pos[0]];
				}
			}
		} 
	}
	else{
		if(cnt[1]<num[2][0]){
			rep(i,1,n+1)if(deg[i])p[i]=num[0][++pos[0]];
			rep(i,1,n+1){
				if(!p[i]){
					rep(j,0,3){
						if(pos[j]<num[j][0]){
							p[i]=num[j][++pos[j]];
							break;
						}
					}
				}
			}
		}
		else{
			rep(i,1,n+1){
				if(deg[i]){
					if(pos[2]<num[2][0])p[i]=num[2][++pos[2]];
					else p[i]=num[0][++pos[0]];
				}
				else{
					if(pos[1]<num[1][0])p[i]=num[1][++pos[1]];
					else p[i]=num[0][++pos[0]];
				}
			}
		} 
	}
	rep(i,1,n+1)printf("%d ",p[i]);
}


Measured memory_bytes: 20480
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define _GLIBCXX_DEBUG
const int MOD = 1000000007;

int main() {
  ll x;
  cin >> x;
  ll ans = x/11*2;
  if (x%11!=0) {
    if (x%11<7) ans++;
    else ans += 2LL;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int a,b,c,d,e;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	if(a==0)
	{
		printf("1\n");
	}
	else if(b==0)
	printf("2\n");
	else if(c==0)
	printf("3\n");
	else if(d==0)
	printf("4\n");
	
	else
	{
		printf("5\n");
	}
	return 0;
}

Measured memory_bytes: 1648
#include <iostream>
using namespace std;
int main()
{
    int n, m, total = 0, t[100], p, x;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> t[i];
        total += t[i];
    }
    cin >> m;
    for(int i = 0; i < m; i++){
        cin >> p >> x;
        cout << total - t[p-1]   + x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define forx(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define caseout(i, x) cout << "Case #" << i << ": " << x << endl;

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

    int n;
    string s;
    cin >> n >> s;

    vector<ll> a(26);

    rep(i, n) a[s[i] - 'a']++;
    ll ans = 1, mod = 1e9 + 7;

    rep(i, 26){
        ans *= a[i] + 1;
        ans %= mod;
    }
    cout << ans - 1 << endl;

    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
using namespace std;

long long x[100011];
long long  v[100011];
long long vsum[100010];
long long rsum[100010];
long long lsum[100010];

int main(int argc, const char * argv[]) {
  
   int  n;
    long long ans= 0,c;
    scanf("%d %lld",&n,&c);
    
    
    for(int i=1;i<=n;i++){
        scanf("%lld %lld",&x[i],&v[i]);
        vsum[i] = vsum[i-1] + v[i];
    }
    ans = max(ans,vsum[n]-c);
    
   
    for(int i=1;i<=n;i++) rsum[i] = max(rsum[i-1],vsum[i] - 2*x[i]);
    for(int i=1;i<=n;i++) lsum[i] = max(lsum[i-1],(vsum[n]-vsum[n-i]) - (c-x[n-i+1]));
    for(int i=0;i<=n;i++) ans = max(ans, rsum[i]+lsum[n-i]);
    
    for(int i=1;i<=n;i++) rsum[i] = max(rsum[i-1],vsum[i] - x[i]);
    for(int i=1;i<=n;i++) lsum[i] = max(lsum[i-1],(vsum[n]-vsum[n-i]) - 2*(c-x[n-i+1]));
    for(int i=0;i<=n;i++) ans = max(ans, rsum[i]+lsum[n-i]);
    
    printf("%lld\n",ans);
    
    return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stdio.h>
#include <stdlib.h>

using namespace std;
//DP用
template<class T> inline bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF = 1LL << 60;

int main() {
    int n,x;
    cin >> n >> x;
    int l[n];
    for(int i = 0; i < n; i++) {
        cin >> l[i];
    }
    int d = 0;
    int count = 1;
    for(int i = 0; i < n;) {
        d += l[i];
        if(d <= x) {
            i++;
            count++;
        }else {
            break;
        }
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	int[] tmp = ReadIntArray();
	int n = tmp[0], w = tmp[1];

	int[] weight = new int[n];
	int[] v = new int[n];
	
	for (int i = 0; i < n; i++)
	{
	    tmp = ReadIntArray();
	    weight[i] = tmp[0];  v[i] = tmp[1];
	}
	
	long[,] dp = new long[n+1, w+1];

	// DP loop
	for (int i = 0; i < n; i++)
	{
	    for (int ww = 0; ww <= w; ww++)
	    {
		// when choosing the item #i
		if (ww  >= weight[i])
		    dp[i+1, ww] =
			Math.Max(dp[i+1, ww], dp[i, ww - weight[i]] + v[i]);

		// when not choosing it
		dp[i+1, ww] = Math.Max(dp[i+1, ww], dp[i,ww]);
		
	    }
       
	}

	WriteLine(dp[n, w]);
    }
}


Measured memory_bytes: 89056
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define INF 1LL<<60
#define pi 3.14159265358979323846
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}

int main(){
    int n;cin>>n;
    string s,t;cin>>s>>t;

    int ans=2*n;
    for(int i=0;i<n;i++){
        bool same=true;
        if(s[i]==t[0]){
            for(int k=0;k<n-i;k++){
                if(s[i+k]==t[k]){ans--;}
                else{same=false;}
            }
            if(!same){ans=2*n;}
            else{cout<<ans<<endl;return 0;}
        }
    }

    cout<<2*n<<endl;

    return 0;
}

Measured memory_bytes: 256
import numpy as np
import bisect

N = int(input())
A = np.array(list(map(int, input().split())))
s = sum(A)
cum = A.cumsum()
index = bisect.bisect_left(cum, s / 2)
if index == 0:
    answer = abs(s - 2 * A[0])
else:
    answer = min(abs(s - 2 * cum[index-1]), abs(s - 2 * cum[index]))
print(answer)

Measured memory_bytes: 34192
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
const int INF = (int)1 << 50;

main() {
  int N, M;
  cin >> N >> M;
  const int NMAX = 1000;
  const int MMAX = 2000;
  int a[MMAX], b[MMAX], c[MMAX];
  for (int i = 0; i < M; ++i) {
    cin >> a[i] >> b[i] >> c[i];
    --a[i];
    --b[i];
    c[i] *= -1;
  }
  int d[NMAX];
  for (int i = 0; i < N; ++i) d[i] = INF;
  d[0] = 0;
  for (int loop = 0; loop < N - 1; ++loop) {
    for (int i = 0; i < M; ++i) {
      if (d[a[i]] == INF) continue;
      if (d[b[i]] > d[a[i]] + c[i]) {
          d[b[i]] = d[a[i]] + c[i];
      }
    }
  }
  int ans = d[N - 1];
  bool neg[NMAX];
  for (int i = 0; i < N; ++i) neg[i] = false;
  for (int loop = 0; loop < N; ++loop) {
    for (int i = 0; i < M; ++i) {
      if (d[a[i]] == INF) continue;
      if (d[b[i]] > d[a[i]] + c[i]) {
        d[b[i]] = d[a[i]] + c[i];
        neg[b[i]] = true;
      }
      if (neg[a[i]] == true) neg[b[i]] = true;
    }
  }
  if (neg[N - 1])
    cout << "inf" << endl;
  else
    cout << -ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define LOOP(i,x,n) for(int i=(x);i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e10;

using namespace std;
template<typename T> void cmax(T &a, T b) {a = max(a, b);}

signed main(){
  int d,n;
  while(cin>>d>>n,d){
    bool flag=false;
    vector<int> a(n),e(n),r(n);
    REP(i,n){
      cin>>a[i]>>e[i]>>r[i];
      if(r[i]==0)flag=true;
    }
    if(flag==false){
      cout<<"NA"<<endl;

    }else{
      int dp[301][301]={};
      int used[301][301]={};

      REP(i,n){
        if(r[i]==0){
          cmax(dp[0][e[i]],a[i]);
          //dp[0][e[i]]=a[i];
          used[0][e[i]]=1;
        }
      }

      REP(i,201){
        REP(j,101){
          if(used[i][j]){
            REP(k,n){
              if(j-r[k]>=0){
              used[i+1][j+e[k]>=100?100:j+e[k]]=1;
              cmax(dp[i+1][j+e[k]>=100?100:j+e[k]],dp[i][j]+a[k]);
              }
            }
          }
        }
      }
      // REP(i,30)cout<<i<<' ';
      // cout<<endl;
      // REP(i,15){
      //   REP(j,101){
      //     cout<<dp[i][j]<<' ';
      //   }
      //   cout<<endl;
      // }cout<<endl;
      bool f=false;
      REP(i,201){
        REP(j,101){
          if(dp[i][j]>=d){
            cout<<i+1<<endl;
            f=true;
            break;
          }
        }
        if(f)break;
      }
      if(f==false){
        cout<<"NA"<<endl;
      }
    }
  }

  return 0;
}



Measured memory_bytes: 4508
// clang-format

#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;

using lli = long long int;

void solve(long long n) {
  lli ans = 0;
  for(int i = 1;i<n;i++){
    if(i<n-i)ans++;
  }
  cout << ans << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 
#endif

#define df(b, e) ((b) > (e))
#define fore(i, b, e) for (auto i = (b) - df(b, e); i != e - df(b, e); i += 1 - 2 * df(b, e))
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define f first
#define s second
#define pb push_back

using lli = long long;
using ld = long double;
using ii = pair<int, int>;
using vi = vector<int>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#ifdef LOCAL
const int N = 20;
#else
const int N = 1e5 + 5;
#endif

int mod = 2;

struct Modular {
  int v;
  Modular(lli x = 0) : v(x % mod) {}
  Modular operator + (const Modular &m) const { return Modular(v + m.v); }
  Modular operator - (const Modular &m) const { return Modular(v - m.v + mod); }
  Modular operator * (const Modular &m) const { return Modular(1LL * v * m.v); }
  void operator += (const Modular &m) { *this = *this + m; }
  void operator -= (const Modular &m) { *this = *this - m; }
  void operator *= (const Modular &m) { *this = *this * m; }
  friend ostream & operator << (ostream &os, const Modular &m) { return os << m.v; }
};

using mint = Modular;
vi graph[N];
mint dp[N], ans[N];
int n;

void dfs1(int u, int p = 0) {
  dp[u] = mint(1);
  for (int v : graph[u]) 
    if (v != p) {
      dfs1(v, u);
      dp[u] *= (dp[v] + mint(1));
    }
} 

void dfs2(int u, int p = 0) {
  vector<mint> pref, suf;
  fore (it, 0, 2) {
    pref.pb(mint(1));
    for (int v : graph[u]) 
      pref.pb(pref.back() * (dp[v] + mint(1)));
    swap(pref, suf);
    reverse(all(graph[u]));
  }
  ans[u] = pref.back();
  reverse(all(suf));

  auto without = [&](int i) -> mint {
    return pref[i] * suf[i + 1];
  };

  debug(u, pref, suf);

  for (auto &v : graph[u]) 
    if (v != p) {
      int i = &v - &graph[u][0];
      // re-root
      debug(i, v, graph[u][i]);
      dp[u] = without(i);
      debug(dp[u]);
      dfs2(v, u);
      // undo
      dp[u] = pref.back();
    }
}

int main() {
  cin.tie(0)->sync_with_stdio(0), cout.tie(0);

  cin >> n >> mod;
  fore (i, 0, n - 1) {
    int u, v;
    cin >> u >> v;
    graph[u].pb(v);
    graph[v].pb(u);
  }

  dfs1(1, 0);
  dfs2(1, 0);

  fore (u, 1, n + 1) 
    cout << ans[u] << '\n';

  return 0;
}

Measured memory_bytes: 25556
#include <cstdio>
const int mod = 1000000007;
int a[21];
int dp[1<<21], bc[1<<21];
int main(){
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) {
			int x;
			scanf("%d", &x);
			a[i] |= x << j;
		}
	for (int i = 1; i < 1 << 21; i++)
		bc[i] = bc[i&(i-1)] + 1;
	int m = (1 << n) - 1;
	dp[0] = 1;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < 1 << n; j++) {
			if (bc[j] != i) continue;
			int k = (j ^ m) & a[i];
			for (int l = k; l; l &= l - 1) {
				int nl = l & (l - 1), t = nl ^ l;
				dp[j|t] += dp[j];
				if (dp[j|t] >= mod) dp[j|t] -= mod;
			}
		}
	printf("%d\n", dp[m]);
	return 0;
}


Measured memory_bytes: 18068
#include<bits/stdc++.h>
#define pb push_back
#define boostup ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int ll;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
using namespace std;
vector <ll> adj[1000000+5];
int main()
{
    ll n,m;
    cin>>n>>m;
    ll i,j;
    ll h[n+1];
    for(i=1;i<=n;i++)
    {
        cin>>h[i];
    }
    for(i=1;i<=n;i++)
    {
        adj[i].pb(i);
    }
    map<pair<ll,ll>,ll> mp;
    for(i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        if(mp[make_pair(x,y)]==1)
        {
            continue;
        }
        adj[x].pb(y);
        adj[y].pb(x);
        mp[make_pair(x,y)]++;
    }
    // for(i=1;i<=n;i++)
    // {
    //     //f=0;
        
    //     for(j=0;j<adj[i].size();j++)
    //     {
    //       cout<<adj[i][j]<<" ";
    //     }
    //     cout<<"\n";
    // }
    ll f=0;
    ll cnt=0;
    ll flag=0;
    for(i=1;i<=n;i++)
    {
        f=0;
        //adj[i].erase( unique( adj[i].begin(), adj[i].end() ), adj[i].end() );
        for(j=1;j<adj[i].size();j++)
        {
            //cout<<adj[i][j]<<" ";
            flag=1;
            if(h[adj[i][0]]<=h[adj[i][j]])
            {
                f=1;
                break;
            }
            else
            {
                //cout<<adj[i][j]<<" ";
            }
        }
        //cout<<endl;
        if(!f)
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 39156
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

n = int(input())
a = [ int(x) for x in input().split() ]

left = [0] * (n+1)
for i, item in enumerate(a):
    left[i+1] = gcd( left[i], item )

right = [0] * (n+1)

for i in range(n-1, -1, -1):
    right[i] = gcd(right[i+1], a[i])

ans = -1

for i in range(n):
    t = gcd(left[i], right[i+1])
    ans = max(ans, t)

print(ans)


Measured memory_bytes: 14436
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end
n, m = gets_i_list
ac, wa = 0, 0
acs = {}
was = {}
m.times do
  pn, s = gets.chomp.split(" ")
  if acs[pn].nil?
    if s == "AC"
      ac += 1
      wa += was[pn].to_i
      acs[pn] = true
    elsif s == "WA"
      was[pn] = was[pn].to_i + 1
    end
  end
end

puts [ac, wa].join(" ")

Measured memory_bytes: 26848
import java.util.Scanner;

/**
 * 
 */

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		StringBuilder sb = new StringBuilder();
		Scanner as = new Scanner(System.in);
		Sort sort = new Sort();
		
		int cnt = 0;
		int m = 0;
		int h = 0;
		int n = 0;
		int j = 0;
		int G[];
		int A[];
		
		n = Integer.parseInt(as.next());
		
		A = new int[n];
		
		for(int i=0;i<n;i++){
			
			A[i] = Integer.parseInt(as.next());
			
		}
		
		h = (n/2);
		
		if(h == 0){
			
			G = new int[h+1];
			
		}
		else{
			
			G = new int[h];
			
		}
			
			
		G[0] = 1;
		
		for(int i=1;i<h;i=i*3+1){
			
			G[j] = i;
			j++;
			
		}
		
		if(j == 0){
			
			m = 1;
			j = 1;
			
		}
		else{
			
			m = j;
			
		}
		
		for(int i=0;i<=m-1;i++){
			
			ReturnValues value = sort.insertionSort(A, n, G[j-i-1]);
			cnt += value.count;
			A = value.A;
			
		}
		
		sb.append(m);
		System.out.println(sb.toString());
		sb.setLength(0);
		for(int i=0;i<m;i++){
			
			if(i == m-1){
				
				sb.append(G[j-i-1]);
				
			}
			else{
			
				sb.append(G[j-i-1]).append(' ');
			
			}
		}
		
		System.out.println(sb.toString());
		sb.setLength(0);
		sb.append(cnt);
		System.out.println(sb.toString());
		sb.setLength(0);
		for(int i=0;i<n;i++){
			
			sb.append(A[i]);
			System.out.println(sb.toString());
			sb.setLength(0);
			
		}

	}

}

class Sort{
	
	public static ReturnValues insertionSort(int[] A,int n, int g){
		
		int v = 0;
		int j = 0;
		int count = 0;
		
		for(int i=g;i<=n-1;i++){
			
			v = A[i];
			j = i - g;
			
			while(j >= 0 && A[j] > v){
				
				A[j + g] = A[j];
				j = j - g;
				count++;
				
			}
		
			A[j + g] = v;
			
		}
		
		ReturnValues value = new ReturnValues();
		value.A = A;
		value.count += count;
		
		return value;
		
	}
	
}

class ReturnValues{
	
	public int count;
	public int A[];
	
}

Measured memory_bytes: 179844
import java.util.Scanner;

public class Main {

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

	    int x=gi();
	    int a=gi();
	    int b=gi();



        //System.out.println(c);
        if (b-a<=0) {
        	System.out.print("delicious");
        }else if (b-a>x){
            System.out.print("dangerous");
        } else {
        	System.out.print("safe");
        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
}

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

using namespace std;

int main(void){
	int n = 0;
	string s;
	cin >> n >> s;

	int cnt_r = 0;
	int cnt_b = 0;

	for(int i=0;i<n;i++){
		if(s.at(i)=='R'){
			cnt_r++;
		}else{
			cnt_b++;
		}
	}
	if(cnt_r > cnt_b){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <queue>
#include <map>
#include <set>
using namespace std;
 
typedef pair<int, int> pii;
const int MAXN = 1e5 + 10;
 
int N;
int fa[MAXN];
set<int> Adj[MAXN];
queue<pii> dualEdges;
map<pii, int> edgeCnt;
 
int find(int x)
{
	if (x == fa[x])
		return x;
	return fa[x] = find(fa[x]);
}
 
inline void addEdge(int u, int v)
{
	Adj[u].insert(v), Adj[v].insert(u);
	if (u > v)
		swap(u, v);
	if (++edgeCnt[make_pair(u, v)] == 2)
		dualEdges.emplace(u, v);
}
 
int main()
{
	int u, v;
	cin >> N;
 
	for (int i = 1; i <= 2 * N - 2; i++)
		cin >> u >> v, addEdge(u, v);
	iota(&fa[0], &fa[N + 1], 0);
 
	for (int i = 1; i < N; i++)
	{
		int x = 0, y = 0;
		do
		{
			if (dualEdges.empty())
			{
				puts("NO");
				return 0;
			}
			tie(x, y) = dualEdges.front();
			dualEdges.pop();
			x = find(x), y = find(y);
		} while (x == y);
 
		if (Adj[x].size() > Adj[y].size())
			swap(x, y);
		fa[x] = y, Adj[x].erase(y), Adj[y].erase(x);
		edgeCnt.erase(make_pair(min(x, y), max(x, y)));
 
		for(int z : Adj[x])
		{
			z = find(z);
			edgeCnt[make_pair(min(x, z), max(x, z))]--;
			if(z == y)
				continue;
			Adj[z].erase(x);
			addEdge(y, z);
		}
	}
 
	puts("YES");
 
	return 0;
}

Measured memory_bytes: 39168
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    string a,b;
    cin>>a>>b;
    if(SZ(a)<SZ(b)) {
        cout<<"LESS"<<endl;
        return 0;
    }
    else if(SZ(a)>SZ(b)) {
        cout<<"GREATER"<<endl;
        return 0;
    }
    else {
        REP(i,SZ(a)) {
            if(a[i]<b[i]) {
                cout<<"LESS"<<endl;
                return 0;
            }
            else if(a[i]>b[i]){
                cout<<"GREATER"<<endl;
                return 0;
            }
        }
    }
    cout<<"EQUAL"<<endl;
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
ps = []
while price = gets do
    ps.push(price.to_i)
end

ps = ps.sort.reverse
max = ps[0]
ps.delete_at(0)
waribiki = max/2
sum = 0
ps.each do |p|
    sum = sum + p
end

puts sum + waribiki

Measured memory_bytes: 1788
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
const long long mod = 1000000007;


int main() {
	int T1, T2;
	long long A1, A2;
	long long B1, B2;
	scanf("%d %d", &T1, &T2);
	scanf("%lld %lld", &A1, &A2);
	scanf("%lld %lld", &B1, &B2);
	A1 *= T1;
	B1 *= T1;
	A2 *= T2;
	B2 *= T2;
	if (A1 + A2 < B1 + B2) {
		long long t = A1;
		A1 = B1;
		B1 = t;
		t = A2;
		A2 = B2;
		B2 = t;
	}
	if (A1 + A2 == B1 + B2) {
		printf("infinity");
	}
	else if(B1<A1){
		printf("0");
	}
	else {
		long long res = (A1 - B1) / (B1 + B2 - A1 - A2)*2+1;
      if((A1 - B1) % (B1 + B2 - A1 - A2)==0)res--;
		printf("%lld", res);
	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//pow(x,n)
//cout << fixed << setprecision(桁数);

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    ///aを選んだ場合、総和はa*xで表される(xは１以上の整数)
    int amari=a%b;
    for(int i=2; ;++i){
        if((a*i)%b==amari){
            cout << "NO" << endl;
            return 0;
        }
        if((a*i)%b==c){
            cout << "YES" << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
def bubble_sort(array):
    count = 0
    A = array[:]
    for i in range(len(A)):
        for j in range(1, len(A) - i):
            if int(A[j - 1]) > int(A[j]):
                count += 1
                A[j - 1], A[j] = A[j], A[j - 1]
    return A, count

_, array = input(), input().split()

result, count = bubble_sort(array)

print(' '.join(result))
print(count)


Measured memory_bytes: 5600
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int A = sc.nextInt();
			int B = sc.nextInt();
			int C = sc.nextInt();
			int D = sc.nextInt();
			int result1 = A * B;
			int result2 = C * D;
			System.out.println(result1 > result2 ? result1 : result2);

		}
	}
}


Measured memory_bytes: 9680
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
	int N, T, A;
	cin >> N >> T >> A;
	
	int ans = 1;
	int h1;
	cin >> h1;
	double d = abs(A - (T - 0.006 * h1));
	for(int i = 1; i < N; i++)
	{
		int h2;
		cin >> h2;
		double td = abs(A - (T - 0.006 * h2));
		if(td < d)
		{
			ans = i + 1;
			d = td;
		}			
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n, k[100], f1, f2, in, ik, s[100];
	while(scanf("%d %d",&in, &ik) && in > 0 && ik > 0)
	{
		for(f1 = 0; f1 < ik; f1++)
		{
			k[f1] = 0;
			scanf("%d",&s[f1]);
		}
		for(f1 = 0; f1 < in; f1++)
		{
			for(f2 = 0; f2 < ik; f2++)
			{
				scanf("%d",&n);
				k[f2] += n;
			}
		}
		for(f1 = 0; f1 < ik; f1++)
		{
			if(k[f1] > s[f1])
				break;
		}
		if(f1 == ik)
			printf("Yes\n");
		else
			printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 380
#include<bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;
//printf("%.10f\n", n);

ll test[1234][1234];
signed main() {
	vector<vector<ll>> abc(27, vector<ll>(2));
	ll D, c, s; cin >> D;
	for (int h = 1; h <= 26; h++) {
		cin >> abc[h][0]; abc[h][1] = h;
	}
	sort(abc.begin() + 1, abc.end());
	for (int i = 0; i < D; i++) {
		for (int h = 0; h < 26; h++) {
			cin >> test[i][h];
		}
	}
	vector<ll> ng;
	for (int h = 0; h < D - 26; h++) {
		if (h % 26 == 0) { ng.clear(); }
		ll a = 0, ans1 = 0, ans2 = 0;
		for (int i = 0; i < 26; i++) {
			if (a != ng.size() && i == ng[a]) { a++; continue; }
			if (ans1 < test[h][i]) {
				ans1 = test[h][i]; ans2 = i;
			}
		}
		cout << ans2 + 1 << endl; ng.push_back(ans2);
		sort(ng.begin(), ng.end());
	}
	for (int h = 1; h <= 26; h++) {
		cout << abc[h][1] << endl;
	}
	return 0;
}

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

int calc(vector<int>&a){
    int n=a.size();
    if(n<=1)return 0;
    vector<int>b(a.begin(),a.begin()+n/2);
    vector<int>c(a.begin()+n/2,a.end());
    int ret=calc(b)+calc(c);

    int bi=0,ci=0;
    for(int i=0;i<a.size();i++){
        if(bi<b.size()&&(ci==c.size()||b[bi]<=c[ci])){
            a[i]=b[bi++];
        }
        else{
            ret+=n/2-bi;
            a[i]=c[ci++];
        }
    }
    return ret;
}

int main(){
    int N;
    while(cin>>N,N){
        vector<int>a(N);
        for(int i=0;i<N;i++)cin>>a[i];
        cout<<calc(a)<<endl;
    }
    return 0;
}

Measured memory_bytes: 1220
import sys
input = sys.stdin.readline
INF = 10**13


def main():
    N = int(input())
    T = [[int(i) for i in input().split()] for j in range(N)]
    X_dist = [[0]*N for _ in range(1 << N)]
    Y_dist = [[0]*N for _ in range(1 << N)]

    for bit in range(1 << N):
        cur_x = [0]
        cur_y = [0]
        for i in range(N):
            if bit & (1 << i):
                cur_x.append(T[i][0])
                cur_y.append(T[i][1])
        for i, (x, y, p) in enumerate(T):
            X_dist[bit][i] = p*min(abs(cx - x) for cx in cur_x)
            Y_dist[bit][i] = p*min(abs(cy - y) for cy in cur_y)

    answer = [INF] * (N+1)
    count = 0
    for i in range(1 << N):
        cnt = bin(i).count("1")
        j = i
        while j >= 0:
            j &= i
            cost = 0
            for k in range(N):
                count += 1
                if not((i >> k) & 1):
                    cost += min(X_dist[j][k], Y_dist[i - j][k])
            answer[cnt] = min(answer[cnt], cost)
            j -= 1

    for ans in answer:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 88720
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  int n;
  cin>>n;
  vector<int> C(n);
  cin>>C;

  vector<int> cnt(n,0);

  int Q;
  cin>>Q;

  int ans = -1;
  while(Q--){
    int t,x,d;
    cin>>t>>x>>d; x--;
    if(t == 1){
      cnt[x] += d;
      if(ans == -1 && cnt[x] > C[x]) ans = x;
    }
    if(t == 2){
      cnt[x] -= d;
      if(ans == -1 && cnt[x] < 0) ans = x;
    }
    
  }

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



Measured memory_bytes: 3120
#include <atcoder/lazysegtree>
#include <atcoder/modint>
#include <cstdio>
 
using namespace std;
using namespace atcoder;
 
using mint = modint998244353;

const int N=200005;
const mint in = mint(9).inv();
const mint minus_=mint(1);

mint A[N];

struct S {
    mint a;
    int size;
};
 
struct F {
    mint d;
    int time;
};
 
S op(S l, S r) { 
    return S{l.a*A[r.size] + r.a, l.size + r.size}; 
}
 
S e() { return S{0, 0}; }
 
S mapping(F l, S r) { 
    if(l.time==-1)
        return r;

    mint nw = (A[r.size]-minus_)*in*l.d;
    return S{nw,r.size}; 
}
 
F composition(F l, F r) {
     return l.time > r.time ? l : r; 
}
 
F id() { return F{0, -1}; }
 
int main() {
    int n, q;
    scanf("%d %d", &n, &q);
    
    vector<S> a(n);
    A[0]=mint(1);
    mint aa=mint(10);

    for (int i = 0; i < n; i++) {
        a[i] = S{1, 1};
        A[i+1]=aa*A[i];
    }
 
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);
    
    //std::cout << seg.prod(1,n).a.val() << std::endl;
    for (int i = 0; i < q; i++) {
        int l, r, d;
        scanf("%d %d %d", &l, &r, &d);
        l--;
        r--;
        r++;
        seg.apply(l, r, F{mint(d), i});
        
        printf("%d\n", seg.prod(0,n).a.val());
    }
}

Measured memory_bytes: 11316
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int N=1e3+5,mod=1e9+7;
char G[N][N];
int dp[N][N];
int main(){
    int n,m;scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%s",G[i]+1);
    dp[1][1]=1;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(i==1&&j==1) continue;
            if(G[i][j]=='#') continue;
            dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
        }
    }
    printf("%d",dp[n][m]);
}


Measured memory_bytes: 5120