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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for(int p=2;p<1000001;p++)
        if(prime[p])
            primes.pb(p);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int t=1;
	//cin>>t;
	//SieveOfEratosthenes(1000000);
    while(t--){
        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
            cin>>a[i];
        int dp[n];
        dp[0]=0,dp[1]=abs(a[1]-a[0]);
        for(int i=2;i<n;i++)
            dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
        cout<<dp[n-1];
    }
}

Measured memory_bytes: 4408
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int d[]= new int[N];
    int sum = 0;
    
    for(int i = 0; i<N; i++){
      d[i]=sc.nextInt();
      sum += d[i];
    }
    
    int ans = 0;
    for(int i = 0; i<N; i++){
      ans += d[i]*(sum-d[i]);
    }
    
    System.out.println(ans/2);
  }
}

Measured memory_bytes: 35860
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    int a, b;
    cin >> a >> b;
    if(a-b >= 0) cout << a-b << endl;
    else cout << 0 << endl;
    return 0;
}

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

int calc(int x){
  int ret = 0;
  while(x % 100 == 0){
    x /= 100;
    ret++;
  }
  return ret;
}

int main(){
  int D , N ;
  cin >> D >> N;
  int cnt =0,val =0;
  while(cnt < N){
    ++val;
    if(calc(val) == D) ++cnt;
  }
  cout << val << endl;
  return 0;
}


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

struct lunch{
    string name;
    int omosa,genkai;
    };
lunch a[10];
signed main(){
    int b;
    while(cin>>b,b){
	for(int c=0;c<b;c++){
	    string d;int e,f;cin>>d>>e>>f;
	    a[c]={d,e,f};
	    }
	    vector<int>c;
	    for(int i=0;i<b;i++){c.push_back(i);}
	    int MIN=1<<29;
	    do{
		int sum=0;
		bool S=true;
		for(int i=b-1;i>=0;i--){
		    if(sum>a[c[i]].genkai)S=false;
		    sum+=a[c[i]].omosa;
		    }
		 if(S){
		     int zyuusin=0;
		     for(int i=0;i<b;i++){
			 zyuusin+=(i+1)*a[c[i]].omosa;
			 }
			 MIN=min(MIN,zyuusin);
		     }   
		}while(next_permutation(c.begin(),c.end()));
		do{
		int sum=0;
		bool S=true;
		for(int i=b-1;i>=0;i--){
		    if(sum>a[c[i]].genkai)S=false;
		    sum+=a[c[i]].omosa;
		    }
		 if(S){
		     int zyuusin=0;
		     for(int i=0;i<b;i++){
			 zyuusin+=(i+1)*a[c[i]].omosa;
			 }
			 if(zyuusin==MIN){
			     for(int i=0;i<b;i++){
				 cout<<a[c[i]].name<<endl;
				 }
			     }
		     }   
		}while(next_permutation(c.begin(),c.end()));
	}
    }

Measured memory_bytes: 3152
from heapq import heappush,heappop

N,M = (int(i) for i in input().split())
a = [0] *N
b = [0] *N
T = []
list = [[] for i in range(M+1)]

for i in range(N):
    a[i],b[i] = map(int,input().split())
    if a[i] <= M:
        list[a[i]].append(b[i])

k = 0
ans = 0
for j in range(1,M+1):
    for i in list[j]:
        heappush(T,-1 * i)
    if T != []:
        ans += -1 * heappop(T)

print(ans)


Measured memory_bytes: 23132
#include<bits/stdc++.h>
using namespace std;
long long int v[101], w[101];

int main(){
      int n, W;
      cin>>n>>W;
      long long int sum=0;
      for(int i=0; i<n; i++)
            {cin>>w[i+1]>>v[i+1];sum+=v[i+1];}

      vector<vector<long long int>>dp(n+1, vector<long long int>(sum+1, INT_MAX));

      for(int i=0; i<=sum; i++)dp[0][i]=1e9;
      for(int i=0; i<=n; i++)dp[i][0]=0;
      int ans=0;

      for(int i=1; i<=n; i++)
      {
            for(int v1=1; v1<=sum; v1++){
                  dp[i][v1]=dp[i-1][v1];
                  if(v[i]<=v1)
                  dp[i][v1]=min(dp[i][v1], (dp[i-1][v1-v[i]]+w[i]));
                  //cout<<i<<' '<<v1<<' '<<dp[i][v1]<<'\n';
                  if(dp[i][v1]<=W)ans=max(ans, v1);
            }
      }
      
      cout<<ans;
}

Measured memory_bytes: 83144
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
A.sort()

M = A[N-1]
K = [False]*(M+1)
ans = 0
for i in range(N-1):
    a = A[i]
    if K[a]:
        continue
    if A[i+1] != a:
        ans += 1
    for i in range(a, M+1, a):
        K[i] = True
if not K[ A[N-1] ]:
    ans += 1
print(ans)


Measured memory_bytes: 106316
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

template<typename T>
vector<T> smallest_prime_factors(T n) {

    vector<T> spf(n + 1);
    for (int i = 0; i <= n; i++) spf[i] = i;


    for (T i = 2; i * i <= n; i++) {

        // 素数だったら
        if (spf[i] == i) {

            for (T j = i * i; j <= n; j += i) {

                // iを持つ整数かつまだ素数が決まっていないなら
                if (spf[j] == j) {
                    spf[j] = i;
                }
            }
        }
    }

    return spf;
}


int gcd(int a,int b) {
  return (a%b==0)?b:gcd(b,a%b);
}

//nの素因数を列挙
template<typename T=int>
vector<T> factolization(T x, vector<T> &spf) {
    vector<T> ret;
    while (x != 1) {
        ret.push_back(spf[x]);
        x /= spf[x];
    }
    sort(ret.begin(), ret.end());
    return ret;
}


bool flag=true;

int main()
{
  int n;
  cin>>n;
  vector<int> a(n);
  for(auto&& e: a) 
  {
    cin>>e;
  }
  auto spf=smallest_prime_factors(1000000+10);
  vector<bool> divisor(1000000+15,false);
  //pairwize coprimeかどうか判定
  for (int i = 0; i < n; ++i)
  {
    //a[i]の素因数を列挙
    vector<int> tmp=factolization(a[i],spf);
    for(const auto& e: tmp) 
    {
      if(divisor[e]) flag=false;
    }
    for(const auto& e: tmp) 
    {
      divisor[e]=true;
    }
  }
  if (flag) {
    cout<<"pairwise coprime"<<endl;
    return 0;
  }

  //setwise coprimeかどうか判定
  int tmp=a[0];
  for (int i = 1; i < n; ++i)
  {
    tmp=gcd(tmp,a[i]);
  }
  if (tmp==1) cout<<"setwise coprime"<<endl;
  else cout<<"not coprime"<<endl;
}

Measured memory_bytes: 11148
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 505;
int mo,n,l[N],r[N],s[N],qz[N],sz,dp[N][N];
bool cmp(int x, int y){
	int tx=l[x]==0?r[x]:l[x]-1;
	int ty=l[y]==0?r[y]:l[y]-1;
	if(tx!=ty)return tx<ty;
	return x>y;
}
int main() {
	read(n);read(mo);
	rep(i,0,n*2-1){
		rep(j,0,2*n-1)if(i*i+j*j>=n*n&&i*i+j*j<=4*n*n)r[i]=j;
		per(j,2*n-1,0)if(i*i+j*j>=n*n&&i*i+j*j<=4*n*n)l[i]=j;
	//	printf("%d:%d %d\n",i,l[i],r[i]);
	}
	rep(i,0,2*n-1)s[++sz]=i;
	sort(s+1,s+sz+1,cmp);
	int tot=0,res=0;rep(i,0,2*n-1)tot+=l[i]>0;
	rep(i,1,sz)qz[i]=(i-1>=0?qz[i-1]:0)+(l[s[i]]==0);
//	rep(i,1,sz)
	rep(t,0,tot){
		memset(dp,0,sizeof(dp));dp[0][0]=1;
		rep(i,0,sz-1)rep(j,0,min(i,t))if(dp[i][j]){
			if(l[s[i+1]]==0)dp[i+1][j]=(dp[i+1][j]+1LL*dp[i][j]*(r[s[i+1]]+1-qz[i]-j))%mo;
			else{
				dp[i+1][j+1]=(dp[i+1][j+1]+1LL*dp[i][j]*(l[s[i+1]]-qz[i]-j))%mo;
				dp[i+1][j]=(dp[i+1][j]+1LL*dp[i][j]*(r[s[i+1]]+1-(2*n-1-(s[i+1]-(t-j)))))%mo;
			}
		}
		res=(res+1LL*(t&1?-1:1)*dp[sz][t])%mo;
	//	cerr<<t<<' '<<dp[sz][t]<<endl;
	}
	printf("%d\n",(res+mo)%mo);
	return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
ll fin(ll a,ll n,ll m){
    if(n==0)
        return 1;
    ll k = fin(a,n/2,m);
    k %= m;
    k *= k;
    k %= m;
    if(n&1)
        k*=a;
    return k%m;
}
ll solve(string s,ll a){
    int n=s.size();
    ll ans=0;
    for(int i=0;i<n;i++){
        if(s[n-1-i]=='1'){
            ans += fin(2,i,a);
            ans %= a;
        }
    }
    return ans;
}

int main() {
    ll t,n,k,k1,k2,a1=0,a2=0,a3=0,a4=0,a5=0;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<n;i++)
        if(s[i]=='1')
            a1++;
    //k = solve(s,a1);
    if(n>a1)
        k1 = solve(s,a1+1);
    if(a1>1)
        k2 = solve(s,a1-1);
    for(int i=0;i<n;i++){
        ll ans,fl=0;
        if(s[i]=='0'){
            ans = k1;
            ans += fin(2,n-1-i,a1+1);
            ans %= (a1+1);
            if(ans<0)
                ans+=(a1+1);
        }else{
            if(a1==1)
                fl=1;
            else{
                ans = k2;
                ans -= fin(2,n-i-1,a1-1);
                ans %= (a1-1);
                if(ans<0)
                    ans+=(a1-1);
            }
        }
        if(fl)
            cout<<0<<endl;
        else{
            ll c=1,p=0;
            while(ans){
                //cout<<ans<<" ";
                p=0;
                for(int i=0;i<32;i++)
                    if(ans&(1<<i))
                        p++;
                ans %= p;
                c++;
            }
            cout<<c<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3920
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

int n,m;
vvi G;
vi d;
void dfs(int a,int p){
	rep(i,G[a].size())if(G[a][i]-p){
		d[G[a][i]]+=d[a];
		dfs(G[a][i],a);
	}
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin>>n>>m;
	G=vvi(n);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	d=vi(n);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--;
		d[a]+=b;
	}
	dfs(0,-1);
	show1d(d);
}


Measured memory_bytes: 24320
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int isprime(int n){
    int count =0;
    for(int i=2;i<=sqrt(n);i++)
    if(n%i==0)count++;
    if(count)return 0;
    return 1;
}
int main()
{
   ll a,v,b,w,t;
   cin>>a>>v>>b>>w>>t;
   if(a>b){
       if(b-w*t>=a-v*t)cout<<"YES"<<endl;
       else cout<<"NO"<<endl;
   }
   else{
   if(a+v*t>=b+w*t)cout<<"YES"<<endl;
   else cout<<"NO";}
}
 
 


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define forab(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using ui = unsigned int;
const ll infll = (ll)(1e18) + 10;
const int inf = int(1e9) + 10;
const int maxn = int(1e5) + 10;
const int mod = int(1e9) + 7;

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int h, w;
    cin >> h >> w;
    vector<vector<char>> grid(h, vector<char>(w));
    vector<vector<int>> dp(h, vector<int>(w));
    forn(i, h) forn(j, w) cin >> grid[i][j];
    dp[0][0] = 1;
    auto add = [](int &a, int b) {
        a = (a + b) % mod;
    };
    auto valid = [=](int x, int y) {
        return 0 <= x && x < h &&
                0 <= y && y < w &&
                grid[x][y] == '.';
    };
    forn(i, h) {
        forn(j, w) {
            if (i == 0 && j == 0) {
                continue;
            }
            add(dp[i][j], valid(i - 1, j) ? dp[i - 1][j] : 0);
            add(dp[i][j], valid(i, j - 1) ? dp[i][j - 1] : 0);
        }
    }
    cout << dp[h - 1][w - 1] << "\n";
    return 0;
}

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

bool isEven(int e){
    return e%2==0? true: false;
}

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int childrenAt[n] = {0};
    int ppl = 0;
    int indexOfL;
    int x, y;
    int i, j;

    for (i = 0; i < n; ++i){
        if (s[i] == 'R') {
            ppl++;
            if (s[i+1] == 'L') {
                if(isEven(ppl)){
                    x = ppl / 2;
                    y = ppl / 2;
                } else {
                    x = (ppl+1) / 2;
                    y = (ppl-1) / 2;
                }
                childrenAt[i] += x;
                childrenAt[i+1] += y;
                ppl = 0;
                indexOfL = i+1;
            }
        } else {
            ppl++;
            if (s[i+1] == 'R' || s[i+1] == '\0') {
                if(isEven(ppl)){
                    x = ppl / 2;
                    y = ppl / 2;
                } else {
                    x = (ppl+1) / 2;
                    y = (ppl-1) / 2;
                }
                childrenAt[indexOfL] += x;
                childrenAt[indexOfL-1] += y;
                ppl = 0;
            }
        }
    }

    for(j = 0; j < n; ++j)
        cout << childrenAt[j] << ' ';
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
typedef long long int ll;

ll mod=1e9+7;

ll mod_pow(ll a,ll b){
    a%=mod;
    if(b==0)return 1;
    if(b==1)return a;
    ll res=mod_pow(a,b/2)%mod;
    res*=res; res%=mod;
    if(b%2)res*=a;
    return res%mod;
}

struct perm{
private:
    int sz;
    vector<ll> p,invp;
public:
    perm(int n){
        sz=n+1;
        p.resize(sz),invp.resize(sz);
        p[0]=1;
        for(int i=1;i<=sz-1;i++){
            p[i]=p[i-1]*i%mod;
        }
        invp[sz-1]=mod_pow(p[sz-1],mod-2);
        for(int i=sz-2;i>=0;i--){
            invp[i]=invp[i+1]*(i+1)%mod;
        }
    }
    ll comb(ll x,ll y){
        if(x<y||y<0)return 0;
        return (p[x]*invp[x-y]%mod)*invp[y]%mod;
    }
};
perm p(1<<22);

ll dp[2020][2020];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    if(k==1){
        cout << 1 << endl;
        return 0;
    }
    dp[0][1]=1;
    for(int i=2;i<=n;i++){
        dp[0][i]=dp[0][i-1]*p.comb(i*(k-1)-1,k-2)%mod;
    }
    for(int i=1;i<=n;i++){
        dp[i][i]=dp[i-1][i];
        for(int j=i+1;j<=n;j++){
            dp[i][j]=(dp[i-1][j]+dp[i][j-1]*p.comb(j*(k-1)+i-1,k-2))%mod;
        }
    }
    ll res=dp[n][n];
    for(ll i=1;i<=n;i++){
        (res*=i)%=mod;
    }
    cout << res << endl;
}


Measured memory_bytes: 96768
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int X; cin >> X;
	int ans = 1;
	FOR(b,2,X+1){
		int power = b * b;
		for(int p=2;;++p){
			if(power > X) break;
			ans = max(ans, power);
			power *= b;
		}
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
pair<int, int> p;
int main(){
    int n, x, y; cin >> n >> x >> y; x--; y--;
    vector<vector<int>> g(n);
    for(int i=0; i+1<n; ++i){
        g[i].push_back(i+1);
        g[i+1].push_back(i);
    }
    g[x].push_back(y); 
    g[y].push_back(x);
    
    queue<int> que;
    vector<int> res(n, 0);
    for(int i=0; i<n; ++i){
        vector<int> dist(n, -1); dist[i] = 0;
        que.push(i); 
        while(!que.empty()){
            int v = que.front(); que.pop();// cout << "v:" << v << ",";
            
            for(auto nv : g[v]){
              	if(dist[nv]!=-1){continue;}
                que.push(nv);
                dist[nv] = dist[v] + 1;
            }
        } /*for(int j=0; j<n; ++j){
            cout << dist[j] << ",";
        } cout << endl;*/
        for(int j=0; j<n; ++j){
            int d = dist[j];
            res[d]++;
        }
    }
    for(int i=1; i<n; ++i){cout << res[i]/2 << endl;}
    return 0;
}

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

const int MAXN = 1e5+5;

ll n, x[MAXN], m, k, a[MAXN];
ll p[MAXN], q[MAXN], d[MAXN];
bool vis[MAXN];

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

    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> x[i];

    for (int i = 0; i < n-1; ++i)
        d[i] = x[i+1] - x[i];

    for (int i = 0; i < n-1; ++i)
        p[i] = i;

    cin >> m >> k;

    for (int i = 0; i < m; ++i) {
        int y; cin >> y;
        swap(p[y-2], p[y-1]);
    }

    for (int i = 0; i < n-1; ++i) {
        if (vis[i])
            continue;
        vector<int> v;
        int j = i;
        while (true) {
            v.push_back(j);
            j = p[j];
            if (j == i)
                break;
        }
        int s = v.size();
        for (int a = 0; a < s; ++a) {
            p[v[a]] = v[(a+k)%s];
            vis[v[a]] = 1;
        }
    }

    ll part = x[0];
    cout << x[0] << "\n";
    for (int i = 0; i < n-1; ++i) {
        part += d[p[i]];
        cout << part << "\n";
    }
}

Measured memory_bytes: 3824
#include <cstdio>
#include <algorithm>
#define int long long

int n,head[2001],nxt[4001],b[4001],k,sum[2001],size[2001];
void push(int s,int t){
	nxt[++k]=head[s];
	head[s]=k;
	b[k]=t;
}
char str[2001];
void dfs(int x,int f){
	sum[x]=0;
	size[x]=(str[x]-'0');
	for(int i=head[x];i;i=nxt[i])
		if(b[i]!=f){
			dfs(b[i],x);
			sum[x]+=sum[b[i]]+size[b[i]];
			size[x]+=size[b[i]];
		}
}
int get(int x,int f){
	int mx=0;
	for(int i=head[x];i;i=nxt[i])
		if(b[i]!=f&&sum[b[i]]>=sum[mx])mx=b[i];
	if(!mx)return 0;
	int k=get(mx,x)+(size[mx]<<1ll)+sum[mx]-sum[x];
	if(k<=0)return sum[x]&1;
	return k;
}
signed main(){
	scanf("%lld",&n);
	scanf("%s",str+1);
	for(int i=1,u,v;i<n;i++){
		scanf("%lld%lld",&u,&v);
		push(u,v);
		push(v,u);
	}
	int ans=n*n+1;
	for(int i=1;i<=n;i++){
		dfs(i,0);
		int mx=0,tot=sum[i];
		if(get(i,0)==0)ans=std::min(ans,tot>>1ll);
	}
	printf("%lld\n",ans==n*n+1?-1:ans);
}

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

int main()
{
    long long n, k;
    std::cin >> n >> k;

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

    long long p = 0;
    const int mod = 1000000007;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            if (a[i] > a[j]) {
                p++;
                p %= mod;
            }
        }
    }

    p *= k;
    p %= mod;

    long long q = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (a[i] > a[j]) {
                q++;
                q %= mod;
            }
        }
    }

    q *= ((k * (k - 1) / 2) % mod);
    long long ans = p + q;
    ans %= mod;
    std::cout << ans << std::endl;
}


Measured memory_bytes: 384
N,D = map(int, input().split())
xy = [map(int, input().split()) for _ in range(N)]
x, y = [list(i) for i in zip(*xy)]


count = 0
for j in range(0,N):
    if (x[j]**2 + y[j]**2)**0.5 <= D:
        count = count +1
    else:
        pass

print(count)

Measured memory_bytes: 116736
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 100005
#define ll signed long long int
using namespace std;

ll ans = 0, a, b, c[MAXX] ,n , t, k= 0, m, x;
signed main()
{
    FAST;
    cin >> n >> m;
    if(500*n >= m){
    	cout << "Yes";
    	return 0;
    	
	}
	cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
using namespace std;

int main() {
	int n; long long a[200000] = {};
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i >= 1) a[i] += a[i - 1];
	}
	long long s = a[n - 1], m = abs(a[n - 1] - 2*a[0]);
	for (int i = 1; i < n-1; i++) {
		m = min(abs(s - 2*a[i]), m);

	}
	cout << m << endl;
}

Measured memory_bytes: 1792
/* author   : mpily :-()
title : Competing1.cpp
time :Sun Jan 19 14:54:36 2020

*/
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
#define F first 
#define S second 
#define MAX 1000009 
  
typedef long long ll;  
  
int prime[MAX]; 
unordered_map<int, int> max_map; 
long long power(long long a, long long b){
if(b == 1){
	return a%mod;
}
else{
	long long temp = power(a,b/2);
	temp*=temp;
	temp%=mod;
	if(b%2){
		temp*=a;
		temp%=mod;
	}		
	return temp;
}
}
void sieve() 
{ 
    prime[0] = prime[1] = 1; 
    for (int i = 2; i < MAX; i++) { 
        if (prime[i] == 0) { 
            for (int j = i * 2; j < MAX; j += i) { 
                if (prime[j] == 0) { 
                    prime[j] = i; 
                } 
            } 
            prime[i] = i; 
        } 
    } 
} 
  
// Function to return the LCM modulo M 
ll lcmModuloM(vector<int>& ar) 
{ 
    int n = ar.size();
    for (int i = 0; i < n; i++) { 
        int num = ar[i]; 
        unordered_map<int, int> temp; 
  
        // Temp stores mapping of prime factor to 
        // its power for the current element 
        while (num > 1) { 
  
            // Factor is the smallest prime factor of num 
            int factor = prime[num]; 
  	    //cout<<factor<<"is a factor of "<<ar[i]<<"\n";
            // Increase count of factor in temp 
            temp[factor]++; 
  
            // Reduce num by its prime factor 
            num /= factor; 
        } 
  
        for (auto it : temp) { 
  
            // Store the highest power of every prime 
            // found till now in a new map max_map 
            max_map[it.first] = max(max_map[it.first], it.second); 
        }
    } 
    ll ans = 1; 
    for (auto it : max_map) { 
  
        // LCM is product of primes to their highest powers modulo M 
        ans = (ans * power(it.F, it.S)) % mod; 
    } 
  
    return ans; 
} 
int main(){
	sieve();
	int n;
	cin>>n;
	vector<int>arr(n);
	for(int i = 0; i < n; i++)cin>>arr[i];
	long long lcm = lcmModuloM(arr);
	//cout<<"here at least";
	long long ans = 0;
	for(auto a : arr){
		long long toadd = lcm*power(a,mod-2);
		toadd%=mod;
		ans+=toadd;
		ans%=mod;
	}
	cout<<ans<<"\n";
	return 0;
}


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

int main(){
  int N,M;
  cin >> N >> M;
  vector<pair<int,int> > v(M);
  int cuta=0;
  int cutb=N+1;
  int ans=0;
  rep(i,M){
    cin >> v.at(i).first >> v.at(i).second;
  }
  sort(v.begin(),v.end());
  rep(i,M){
    if(cuta<v.at(i).first)
      cuta=v.at(i).first;
    if(v.at(i).second<cutb)
      cutb=v.at(i).second;
    else if (cutb<=v.at(i).first||v.at(i).second<=cuta){
      ans++;
      cuta=v.at(i).first;
      cutb=v.at(i).second;
    }
  }
  ans++;
  cout << ans << endl;
    
}

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


void solve(long long X){
    int ans = 0;
    if (X < 600) {ans = 8;}
    else if (X < 800) {ans = 7;}
    else if (X < 1000) {ans = 6;}
    else if (X < 1200) {ans = 5;}
    else if (X < 1400) {ans = 4;}
    else if (X < 1600) {ans = 3;}
    else if (X < 1800) {ans = 2;}
    else {ans = 1;}
    cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define all(v) (v.begin(),v.end())
#define ff first
#define ss second
const ll maxn=1e6+10;
const ll mod=1e9+7;
 
 
 
 
int main() {
  	fast;
  	ll n,w;
  	cin>>n>>w;
  	ll we[n],co[n];
  	for(ll i=0;i<n;i++){
  		cin>>we[i]>>co[i];
	  }
  		
	vector<ll> dp(maxn+3,INT_MAX);
	//dp[j] = min(dp[j] (j>=co[i]) ? we[i]+dp[j-co[i]] : INT_MAX) //dp[val] represents min weight we can get at value val.
	dp[0]=0;
	for(ll i=0;i<n;++i){
		for(ll j=maxn;j>=co[i];--j){
			dp[j]=min(dp[j],dp[j-co[i]]+we[i]);
		}
	}
	ll ans=0;

	for(ll i= 0; i<=maxn ;++i){
		
		if(dp[i]<=w)
			ans=i;
	}
  	cout<<ans;
  	
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double d;
typedef vector<ll> v;
typedef pair<ll,ll> p;
ll mod=1000000007;

void solve(){
	ll n;
	cin>>n;
	if(n%1000==0){
		cout<<"0"<<endl;
	}else{
		n%=1000;
		cout<<1000-n<<endl;
	}
}


int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	int test=1;
	//cin>>test;
	while(test--){
		solve();
	}
}

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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<(int)n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

int32_t main(){
   fast;
   int k,a,b;
   cin >> k >> a >> b;
   int tot = b/k - (a-1)/k;
   if(tot) cout << "OK";
   else  cout << "NG";
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    string s; cin >> s;

    int alphabets[26] = {};
    REP(i, 0, s.size()) alphabets[s[i] - 'a']++;

    REP(i, 0, 26) {
        if (alphabets[i] == 0) {
            cout << s << (char)('a' + i) << endl;
            return 0;
        }
    }

    string t = s;
    next_permutation(t.begin(), t.end());
    if (t < s) {
        cout << -1 << endl;
        return 0;
    }

    string ans = "";
    REP(i, 0, 26) {
        ans += t[i];
        if (s[i] != t[i]) break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
public static void main(String[] args){
	try{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String[] str = br.readLine().split(" ");
	List<Integer> num = new ArrayList<Integer>();
	
		for(int i = 0; i < str.length; i++){
		num.add(Integer.parseInt(str[i]));
		}
	
	Collections.sort(num);
	
		for(int n = 0; n < num.size(); n++){
			if(n != num.size()-1){
			System.out.print(num.get(n) + " ");
			}else{
			System.out.println(num.get(n));
			}
		}

	}catch(IOException e){
	System.out.println(e);
	}
}	
}

Measured memory_bytes: 16964
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << "=" << x << ","
#define de(x) cout << #x << "=" << x << endl
#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 all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define lowbit(x) x&(-x)
const int N = 20000;
const int M = 1e9+7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
	ll b;
	cin>>b;
    ll a=100,ans=0;
	while (a<b){
		a+=a/100;
		ans++;
	}
	cout<<ans;
}


Measured memory_bytes: 3612
kousyas = [[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]]

n = int(input())
for _ in range(n):
    b, f, r, v = map(int, input().split())
    kousyas[b-1][f-1][r-1] += v

for j, kousya in enumerate(kousyas):
    for f in kousya:
        for i, r in enumerate(f):
            if i == 9:
                print(f' {r}')
            else:
                print(f' {r}', end='')
    if j <= 2:
        print('#' * 20)



Measured memory_bytes: 5644
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>

#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=s;i--)
#define rep_re(i,s,n)for(int i = n;i>=s;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;

ll v[100001];
vector<pair<ll, ll>> e[100001];
ll n, m;

void dfs(ll i, ll x) {
	v[i] = x;

	rep(p, 0, e[i].size()) {
		if (v[e[i][p].first]) {
			if (v[i] + e[i][p].second != v[e[i][p].first]) {
				cout << "No";
				exit(0);
			}
		}
		else {
			dfs(e[i][p].first, v[i] + e[i][p].second);
		}
	}
}

int main() {
	cin >> n >> m;
	rep(i, 0, m) {
		ll l, r, d; cin >> l >> r >> d;
		e[l].push_back({ r,d });
		e[r].push_back({ l,-d });
	}

	repe(i, 1, n) {
		if (!v[i]) {
			dfs(i, INF);
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 16512
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i,n) for(int i = 0; i < (n); i++)
#define PB push_back
#define ALL(c) c.begin(),c.end()
#define LLINF 1000000000000000000LL

using namespace std;
typedef long long ll;

ll lrev[120000], rrev[120000];
int main()
{
  int N, K;
  cin >> N >> K;
  vector<ll> l, r;

  r.PB(0);
  REP(i, N) {
    ll x; cin >> x;
    if (x > 0) r.PB(x);
    else l.PB(-x);
  }
  l.PB(0);
  reverse(ALL(l));

  REP(i, 110000) lrev[i + 1] = rrev[i + 1] = LLINF;
  REP(i, l.size() - 1) lrev[i + 1] = 2*l[i + 1];
  REP(i, r.size() - 1) rrev[i + 1] = 2*r[i + 1];

  ll ans = LLINF;
  for (int i = 1; i < l.size(); i++) {
    if (i > K) break;
    if (rrev[K - i] != LLINF) ans = min(ans, l[i] + rrev[K - i]);
  }
  for (int i = 1; i < r.size(); i++) {
    if (i > K) break;
    if (lrev[K - i] != LLINF) ans = min(ans, r[i] + lrev[K - i]);
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>


#define fs first
#define sc second

using namespace std;

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

bool judge_prime(int x){
    for(int i = 2; i * i <= x; i++){
        if(x % i == 0){
            return false;
        }
    }
    return true;
}


int main(){
    int N;
    cin >> N;
    vector<int> prime_numbers;

    for(int i = 2; i <= 55555; i++){
        if(judge_prime(i)){
            prime_numbers.push_back(i);
        }
    }

    int count = 0;
    for(auto p: prime_numbers){
        if(N == 0){
            break;
        }
        if(p % 5 == 1){
            N--;
            cout << p << " ";
        }
    }
    cout << endl;


    return 0;

}


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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

typedef long long ll;
typedef pair<int,int> pii;

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 109, M = 509, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;


int fr[N];

int main(){
    init();

    ll n, k;   cin >> n >> k;
    pii a[n];
    for(int i = 0;i < n;i++)    cin >> a[i].F >> a[i].S;

    sort(a, a + n);

    for(int i = 0;i < n;i++){
        k -= a[i].S;
        if(k <= 0) return cout << a[i].F, 0;
    }
}

Measured memory_bytes: 1024
A = input()
if A[-1]== "2" or A[-1]== "4" or A[-1]== "5" or  A[-1]== "7" or A[-1]== "9":
    print("hon")
elif A[-1]== "0" or A[-1]== "1" or A[-1]== "6" or A[-1]== "8":
    print("pon")
else:
    print("bon")

Measured memory_bytes: 9140
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
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);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int X;
  cin>>X;

  Int num = 100;
  Int ans = 0;
  while(num < X) num = num * 1.01, ans++;
  cout<<ans<<endl;

  return 0;
}


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

using namespace std;
using ll = long long;

ll solve(vector<ll> &vx, ll offset, ll n, ll sum,
         vector<vector<vector<ll>>> &memo) {
  if (offset == vx.size()) {
    return sum == 0 && n == 0;
  }

  if (n < 0 || sum < 0) {
    return 0;
  }

  if (memo[offset][n][sum] == -1) {
    memo[offset][n][sum] = solve(vx, offset + 1, n, sum, memo) +
                           solve(vx, offset + 1, n - 1, sum - vx[offset], memo);
  }

  return memo[offset][n][sum];
}

int main(int argc, const char *argv[]) {
  int n, a;
  cin >> n >> a;

  vector<ll> vx(n);
  for (int i = 0; i < n; ++i) {
    cin >> vx[i];
  }

  vector<vector<vector<ll>>> memo(
      60, vector<vector<ll>>(60, vector<ll>(60 * 60, -1)));
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += solve(vx, 0, i, a * i, memo);
  }

  cout << ans << '\n';
}

Measured memory_bytes: 106484
#include<stdio.h>
int check_10(int s[],int n){ //配点が全て10の倍数かチェック
    int count = 0;
    for(int i = 0; i < n; i++){
        if(s[i] % 10 != 0) count++;
    }
    if(count == 0) return 1;
    else return 0;
}

int main(){
    int n,i,j,tmp;
    int s[100];
    int tmp_sum = 0;
    
    
    scanf("%d",&n);
    for(i = 0; i < n; i++) scanf("%d",&s[i]);
    for(i = 0; i < n; i++) tmp_sum += s[i];
    if(check_10(s,n) == 1){
        printf("0\n");
        //printf("all score 10 times\n");
        return 0;
    }
    
    for(i = 0; i < n-1; i++){ //昇順ソート
        for(j = i+1; j < n; j++){
            if(s[i] > s[j]){
                tmp = s[i];
                s[i] = s[j];
                s[j] = tmp;
            }
        }
    }
    
    if(tmp_sum % 10 != 0){ //全ての配点の合計が10の倍数でない時
        printf("%d\n",tmp_sum);
        return 0;
    }
    
    for(i = 0; i < n; i++){
        if(s[i] % 10 != 0){
            tmp_sum -= s[i];
            break;
        }
    }
    printf("%d\n",tmp_sum);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define ll long long

int main()
{
	ll Q, H, S, D, N;
	cin >> Q >> H >> S >> D >> N;

	ll ppl = Q * 4; // price per litle
	if (ppl > H * 2) ppl = H * 2;
	if (ppl > S) ppl = S;

	ll ans = 0;
	if (ppl * 2 > D) ans += (N / 2 * D);
	else ans += (N / 2 * ppl * 2);
	if (N % 2 != 0) ans += ppl;

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

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

int main(){
  int a,b,i,j,k,c=0;
  cin>>a>>b;
  for(i=0;i<=a;i++){
    for(j=0;j<=a;j++){
      c+=(0<=b-i-j&&b-i-j<=a);
    }
  }
  cout<<c<<endl;
}


Measured memory_bytes: 256
#キーエンス2019
#C:ExamandWizard
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
if sum(A)<sum(B):
    print(-1)
    exit()
data=[]
need=0
ans=0
for i in range(N):
    if A[i]>B[i]:
        data.append(A[i]-B[i])
    elif A[i]<B[i]:
        need+=B[i]-A[i]
        ans+=1
data.sort()
while need>0:
    ans+=1
    need-=data.pop()
print(ans)
#notsub

Measured memory_bytes: 18836
import bisect


n, m = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)

ruiseki = [0]*(n+1)
for i in range(n):
    ruiseki[i+1] = ruiseki[i] + a[i]

def solve(min_power):
    ans = 0
    for pos in range(n):
        tmp = min_power - a[pos]
        next_pos = max(bisect.bisect_left(a, tmp), pos)
        times = n - pos - (next_pos - pos)
        if times == n - pos:
            ans += 2 * (times - 1) + 1 
        else:
            ans += 2 * times
    if ans >= m:
        return True
    else:
        return False

ok = 0
ng = 2*10**5 + 1
while abs(ok - ng) > 1:
    mid =  (ok + ng) // 2 
    if solve(mid):
        ok = mid
    else:
        ng = mid

cnt = 0
ans = 0

for pos in range(n):
    tmp = ok - a[pos]
    next_pos = max(bisect.bisect_left(a, tmp), pos)
    times = n - pos - (next_pos - pos)
    if times == n - pos:
        cnt += 2 * (times - 1) + 1 
        ans += 2 * (ruiseki[n] - ruiseki[n-times+1] + (times-1)*a[pos]) + 2*a[pos]
    else:
        cnt += 2 * times
        ans += 2 * (ruiseki[n] - ruiseki[n-times] + times*a[pos])

print(ans - (cnt-m)*ok)

Measured memory_bytes: 57784
#include <stdio.h>

int main(){
    char name[100];
    scanf("%[^\n]", name);
    
    for(int i= 0; name[i] != ','; i++){
        printf("%c", name[i]);
    }
    printf(" ");
    for( int j = 6; name[j] != ','; j++){
        printf("%c", name[j]);
    }
    printf(" ");
    for(int k = 14; name[k] != '\0'; k++){
        printf("%c", name[k]);
    }

    return 0;
}

Measured memory_bytes: 1596
#include <iostream>

using namespace std;

int main(void){
	while(1){
		int t, d, l; cin >> t >> d >> l;
		if(!t && !d && !l) break;

		int ans = 0, last_time = 0;
		for(int i=0; i<t; i++){
			int x; cin >> x;
			if(x >= l) last_time = d;
			if(last_time > 0){
				ans++;
				last_time--;
			}
		}
		if(ans != 0) ans--;
		cout << ans << endl;
	}
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

const int mod=1000000007;
inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}
int mpow(int n,int m){
    int ret=1;
    while(m){
        if(m&1)ret=ret*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ret;
}
const int FACT_SIZE=1111111;
int fact[FACT_SIZE];
int inv[FACT_SIZE];
struct fact_exec{
    fact_exec(){
        fact[0]=1;
        for(int i=1;i<FACT_SIZE;i++)fact[i]=fact[i-1]*i%mod;
        inv[FACT_SIZE-1]=mpow(fact[FACT_SIZE-1],mod-2);
        for(int i=FACT_SIZE-2;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
    }
}factexec;
int nCk(int n,int k){
    return fact[n]*inv[k]%mod*inv[n-k]%mod;
}
int nPk(int n,int k){
    return fact[n]*inv[n-k]%mod;
}

int acc[2222][2222];

signed main(){
    for(int i=0;i<2222;i++){
        for(int j=0;j<=i;j++){
            acc[i][j]=nCk(i,j);
            if(j)add(acc[i][j],acc[i][j-1]);
        }
    }
    int A,B;
    cin>>A>>B;



    int ans=0;
    for(int b=0;b<B;b++){
        int sum=0;
        for(int a=0;a+b<=A;a++){
            if(a==0)sum++;
            else if(b){
                int k=min(b-1,a);
                add(sum,acc[b-1][k]);
            }
            add(ans,nCk(a+b-a+B-1-b,B-1-b)*sum%mod);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 54784
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e7;
const int inf=1e9;
int main(){
	string s;cin>>s;
	if(s[2]==s[3] && s[4]==s[5]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

const INF: usize = 1 << 50;

fn main() {
    input! {
    d: usize,
    n: usize,
    }

    if n == 100 {
        println!("{}", 100_i32.pow(d as u32) * 101 as i32);
    } else {
        println!("{}", 100_i32.pow(d as u32) * n as i32);
    }
}


Measured memory_bytes: 4352
from collections import deque
import sys
readline = sys.stdin.readline
N, Q = map(int, readline().split())
G = [[] for i in range(N)]
C = [0] * N
for i in range(N-1):
    a, b = map(int, readline().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
for i in range(Q):
    p, x = map(int, readline().split())
    C[p-1] += x
used = [0]*N
used[0] = 1
que = deque([0])
while que:
    v = que.popleft()
    c = C[v]
    for w in G[v]:
        if used[w]:
            continue
        used[w] = 1
        C[w] += c
        que.append(w)
print(*C)

Measured memory_bytes: 93972
N=int(input())
LIST=[0]
for i in range(30):
    LIST.append(LIST[-1]+pow(26,i+1))

for i in range(29):
    if N<=LIST[i]:
        LEN=i
        break

for k in range(LEN):
    N-=pow(26,k)

ANS=[]
for i in range(LEN):
    ANS.append(N%26)
    N//=26

#print(ANS)

print("".join([chr(a+97) for a in ANS][::-1]))


Measured memory_bytes: 9192
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations,permutations
from copy import deepcopy
import sys
sys.setrecursionlimit(4100000)



if __name__ == '__main__':
    S = input()
    mid = len(S)//2

    cnt = 0
    for i in range(mid):
        if S[i] != S[-i-1]:
            cnt += 1
    print(cnt)

Measured memory_bytes: 10100
#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MAX max<ll>
#define MIN min<ll>
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
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; }
ll devc(ll x, ll y) { return (x + y - 1) / y; }

vector<ll> ans;

void func(string x, bool s, bool f, bool t){
    if(len(x) >= 10) return;
    if(x != "" and s and f and t) ans.pb(stoi(x));
    func(x + "7", true, f, t);
    func(x + "5", s, true, t);
    func(x + "3", s, f, true);
}

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

    ll N;
    cin >> N;
    func("", false, false, false);

    ll s = 0;
    for(auto a : ans) s += a <= N;
    print(s);

    return 0;
}

Measured memory_bytes: 640