akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace __gnu_pbds;
typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
/* Precode Start Here *\
     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}
/* Precode Ends */
#define mod 1000000007
ll A[5000001],vis[5001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
priority_queue<ll> pq;
priority_queue<ll, vector<ll>, std::greater<ll> > first;
ll po(ll a,ll n)
{
    ll ans=1;
    for(int i=1; i<=n; i++)
        ans*=a;
    return ans;
}

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

     string s;
     cin>>s;
     if(s[s.size()-1]=='s')
        s+="es";
     else
        s+='s';
     cout<<s<<endl;

    return 0;
}


Measured memory_bytes: 3652
# https://atcoder.jp/contests/abc128/tasks/abc128_b

Res = Struct.new(:no, :city, :score)

N = gets.to_i
Rs = []
1.upto(N) do |i|
  s1, s2 = gets.chomp.split
  Rs.push(Res.new(i, s1, s2.to_i))
end

Rs.sort_by { |r| [r.city, -r.score] }.each { |r| puts r.no }


Measured memory_bytes: 1788
// B - String Rotation
#include <bits/stdc++.h>
using namespace std;

int main(){
	string S,T; cin>>S>>T;
	int N = S.size();
	bool ans;
	for(int i=0; i<N; ++i){
		ans = true;
		for(int s=i, t=0; t<N; ++t, s=(s+1)%N)
			if(S[s] != T[t]){ ans = false; break; }
		if(ans) break;
	}
	cout<< (ans? "Yes":"No") <<endl;
}

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

int main() {
	string n;
	cin>>n;
	string tmp1, tmp2;
	tmp1=n;
	tmp1[1]=n[0];
	tmp1[2]=n[0];

	tmp2=n;
	tmp2[0] = n[0]+1;
	tmp2[1] = n[0]+1;
	tmp2[2] = n[0]+1;

	if (tmp1 >= n) {
		cout << tmp1 <<endl;
	} else {
		cout << tmp2 <<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	
	vector<int> A(3 * N);
	REP(i, 3 * N) scanf("%d", &A[i]), --A[i];
	
	int base = 0;
	vector<vector<int>> dp(N + 1, vector<int>(N + 1, -INF));
	
	auto update = [&](int i, int j, int x) {
		chmax(dp[i][j], x);
		chmax(dp[j][i], x);
		chmax(dp[N][j], x);
		chmax(dp[j][N], x);
		chmax(dp[i][N], x);
		chmax(dp[N][i], x);
		chmax(dp[N][N], x);
	};
	
	update(A[0], A[1], 0);
	
	struct Data { int i, j, x; };
	
	REP(t, N - 1) {
		int idx = t * 3 + 2;
		if (A[idx] == A[idx + 1] && A[idx + 1] == A[idx + 2]) { ++base; continue; }
		
		vector<Data> upd;
		FOR(s, 1, 7) {
			vector<int> v, ev;
			REP(i, 3) {
				if (s >> i & 1) v.emplace_back(A[idx + i]);
				else ev.emplace_back(A[idx + i]);
			}
			
			if (v.size() == 1) {
				upd.emplace_back(Data{ev[0], ev[1], dp[N][N]});
				if (dp[v[0]][v[0]] != -INF) upd.emplace_back(Data{ev[0], ev[1], dp[v[0]][v[0]] + 1});
			}
			else {
				REP(j, N) upd.emplace_back(Data{ev[0], j, dp[N][j]});
				if (v[0] == v[1]) REP(j, N) if (dp[j][v[0]] != -INF) upd.emplace_back(Data{ev[0], j, dp[j][v[0]] + 1});
			}
		}
		
		for (auto &&cur : upd) update(cur.i, cur.j, cur.x);
	}
	int ans = -INF;
	REP(i, N) REP(j, N) chmax(ans, dp[i][j]);
	chmax(ans, dp[A.back()][A.back()] + 1);
	ans += base;
	cout << ans << endl;
	return 0;
}


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

// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4765
const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(100005);

mint f(int n, int k) {
  if (n < 0) return 0;
  // nPk = nCk * k!
  mint res = comb(n,k);
  res *= comb.fact[k];
  return res;
}

int k;
mint ans;
vector<int> to[100005];
void dfs(int v, int p=-1) {
  for (int u : to[v]) {
    if (u == p) continue;
    dfs(u,v);
  }
  int nk = (p==-1) ? k : k-2;
  int c = (p==-1) ? to[v].size()+1 : to[v].size()-1;
  ans *= f(nk,c);
}

int main() {
  int n;
  cin >> n >> k;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans = 1;
  dfs(0);
  cout<<ans.x<<endl;
  return 0;
}


Measured memory_bytes: 10752
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

int main()
{
	int X,Y,Z;
	cin>>X>>Y>>Z;
	cout<<Z<<" "<<X<<" "<<Y<<endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int g = sc.nextInt();
		int b = sc.nextInt();
        int check = 10*g + b;
      
        if(check%4 == 0){
          System.out.println("YES");
        }else{
          System.out.println("NO");
        }
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main(void)
{
	char str[17]= {};
	char cmp[]= "CODEFESTIVAL2016";
	int count= 0;

	cin>>str;
	for(int i= 0; i < 16; i++)
		if(str[i] != cmp[i])
			count++;

	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
xy_list = []
for i in range(n):
    xy_list.append(list(map(int, input().split())))

import itertools
import math
comb = list(itertools.permutations(xy_list))
ans = 0
for s in comb:
    ans_tmp = 0
    #print(ans)
    for zyun in range(len(s)-1):
        ans_tmp += math.sqrt((s[zyun][0] - s[zyun+1][0])**2 + (s[zyun][1] - s[zyun+1][1])**2)
    ans += ans_tmp
print(round(ans/len(comb), 12))

Measured memory_bytes: 7972
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
const int INF=1e+9;
const ll INFLL=1e+17;
char a,b;
char solve(){
  if(a=='H'){
    if(b=='H'){
      return 'H';
    }
    else{
      return 'D';
    }
  }
  else{
    if(b=='H'){
      return 'D';
    }
    else{
      return 'H';
    }
  }
}
int main(){
  cin>>a>>b;
  prin(solve());
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
    int a,b,c,total = 0,count[2000],counter = 0,sum = 0;
    cin >> a >> b >> c;
    sum = a;
    count[0] = sum % b;
    for(;;)
    {
        if(sum % b == c){cout << "YES" << endl; return 0;}
        else
        {
            for(int i = 0;i < counter;i++)
            {
                if(count[i] == sum % b)
                {
                    cout << "NO" << endl;
                    return 0;
                }
            }
            sum += a;
            counter++;
            count[counter] = sum % b;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#define FILEIO(a) freopen(a".in", "r", stdin); freopen(a".out", "w", stdout);
#include <cstdio>
#include <algorithm>
#include <numeric>

typedef long long ll;

const int MaxN = 100005;

inline int div_ceil(ll a, int b) {
	return (a + b - 1) / b;
}

int n, W;
struct node {
	int b, l, r; ll val;
	
	node() = default;
	node(int b, int l, int r): b(b), l(l), r(r) {
		val = (ll)r * (W - b) + (ll)l * b;
	}
	
	inline int calc(ll s) const {
		if (s >= val) return W;
		ll tmp = s - (ll)b * l;
		return tmp > 0 ? b + div_ceil(tmp, r) : div_ceil(s, l);
	}
} dat[MaxN];

ll solve() {
	scanf("%d%d", &n, &W);
	
	ll sum = 0;
	for (int i = 0; i < n; ++i) {
		int b, l, r;
		scanf("%d%d%d", &b, &l, &r);
		dat[i] = node(b, l, r);
		sum -= (ll)l * b;
	}
	
	std::sort(dat, dat + n, [](const node &a, const node &b) {
		return a.val > b.val;
	});
	
	for (int i = 0; i < n; ++i) {
		ll val = dat[i].val;
		if (sum + val >= 0) {
			int res = W;
			for (int j = 0; j < i; ++j) {
				res = std::min(res, dat[j].calc(-sum + dat[j].val - val));
			}
			for (int j = i; j < n; ++j) {
				res = std::min(res, dat[j].calc(-sum));
			}
			return (ll)i * W + res;
		}
		sum += val;
	}
	
	return (ll)n * W;
}

int main() {
	printf("%lld\n", solve());
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
using namespace std;
void func(int,int);

int H, W;

int main() {
	
	for (;;) {
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		else {
			func(H, W);
		}
	}

}

void func(int H,int W) {
	int i, j;
	for (i = 0;i < H;i++) {
		for (j = 0;j < W;j++)
			if (i == 0 || i == H - 1 || j == 0 || j == W - 1) {
				cout << '#';
			}
			else {
				cout << '.';
			}
		cout << endl;
	}
	cout << endl;
}


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;


int main(){
	int n,r;
	while(cin>>n>>r,n){
		string s="";
		for(int i=n;i>=1;i--){
			char c=50+i;
			s+=c;
		}
		for(int i=0;i<r;i++){
			int p,c;
			cin>>p>>c;
			string a=s.substr(0,p-1);
			s.erase(0,p-1);
			string b=s.substr(0,c);
			s.erase(0,c);
			s=b+a+s;
			
		}
		cout<<(int)s[0]-50<<endl;
	}
	return 0;
}


Measured memory_bytes: 1232
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    s = input().rstrip()
    print(s[:-8])

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
/*
 *  I wish I could travel by the road that crosses baby's mind,
 *  and out beyond all bounds;
 *  Where messengers run errands for no cause
 *  between the kingdoms of kings of no history;
 *  Where Reason makes kites of her laws and flies them,
 *  and Truth sets Fact free from its fetters.
 *                                           Rabindranath Tagore
 */

#include <bits/stdc++.h>
using namespace std;

#ifndef ORZ_EVERYBODY_BUT_ME
#define ORZ_EVERYBODY_BUT_ME
#endif

#ifndef SOCIALISM
#define SOCIALISM
#endif

unsigned long long operator "" _love(unsigned long long literal) {
    return literal;
}

int main() {
    int n, d; double m;
    cin >> n >> m >> d;
    printf("%.10lf\n", (m - 1) * (d ? 2 : 1) * (n - d) / n / n);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <climits>
#define LL long long
const double pi=acos(-1.0);
using namespace std;
const int maxm = 20;
const double eps = 1e-6;
int cmp(const void *a,const void *b)
{
    return *(int*)b-*(int*)a;
}
int main()
{
    int a[10];
   for(int i=0;i<10;i++)
    scanf("%d",&a[i]);
   qsort(a,10,sizeof(int),cmp);
   printf("%d\n%d\n%d\n",a[0],a[1],a[2]);
   return 0;
}

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

int main()
{
	int A,B;
  cin >> A;
  cin >> B;
  if ((A != 1 && B != 1))
      { cout << 1 << endl;
       return (0);
      }

  if ((A != 2 && B != 2))
      {cout << 2 << endl;

      	return (0);
      }

  if ((A != 3 && B != 3))
      {cout << 3 << endl;
   			return (0);
      }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define P pair<ll,ll> 
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;cin>>s;
  ll k,pos=0,l=s.length();cin>>k;
  lvector v(l,0);
  rep(i,l) v[i]=26-(s[i]-'a');
  while(pos<l&&k>0) {
    if(s[pos]=='a') {pos++;continue;} 
    if(v[pos]>k) pos++;
    else {
       s[pos]='a';
       k-=v[pos],pos++;
    }
  }
  if(k>0) s[l-1]+=(k%26);
  print(s);
  return 0;
}

Measured memory_bytes: 1360
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int n = stdIn.nextInt();
			if(n == 0) {
				break;
			}
			int[][] a = new int[n][4];
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < 4; j++) {
					a[i][j] = stdIn.nextInt();
				}
			}
			int p = stdIn.nextInt();
			int q = stdIn.nextInt();
			int r = stdIn.nextInt();
			int c = stdIn.nextInt();
			
			int[] ok = new int[n];
			int okp = 0;
			
			for(int i = 0; i < n; i++) {
				int cal = 0;
				cal += a[i][1]*4;
				cal += a[i][2]*9;
				cal += a[i][3]*4;
				if(cal <= c && a[i][1] <= p &&  a[i][2] <= q && a[i][3] <= r)  {
					ok[okp++] = a[i][0];
				}
			}
			if(okp == 0) {
				System.out.println("NA");
			}
			else {
				for(int i = 0; i < okp; i++) {
					System.out.println(ok[i]);
				}
			}
		}
	}

}

Measured memory_bytes: 64864
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

ll n;
ll a[100010];
ll ans1,ans2;
int main(){
	scanf("%lld\n",&n);
	rep(i,0,n)scanf("%lld\n",a+i);
	//最初を負
	ll s=0;
	rep(i,0,n){
		s+=a[i];
		if(i%2){
			//sを正
			ans1+=max(1-s,0);
			s=max(1,s);
		}else{
			//sを負
			ans1+=max(s+1,0);
			s=min(-1,s);
		}
	}

	//最初を正
	s=0;
	rep(i,0,n){
		s+=a[i];
		if(i%2==0){
			//sを正
			ans2+=max(1-s,0);
			s=max(1,s);
		}else{
			//sを負
			ans2+=max(s+1,0);
			s=min(-1,s);
		}
	}
	printf("%lld\n",min(ans1,ans2));
}

Measured memory_bytes: 896
from heapq import heappop, heappush


class Medians:
    def __init__(self):
        self.left = []
        self.right = []
        self.size_l = 0
        self.size_r = 0
        self.sum_l = 0
        self.sum_r = 0

    def add(self, n):
        if self.size_l > self.size_r:
            t = -self.left[0]
            if n >= t:
                heappush(self.right, n)
                self.sum_r += n
            else:
                heappop(self.left)
                self.sum_l -= t
                heappush(self.left, -n)
                self.sum_l += n
                heappush(self.right, t)
                self.sum_r += t
            self.size_r += 1
        else:
            if not self.size_l:
                heappush(self.left, -n)
                self.sum_l += n
            else:
                t = self.right[0]
                if n <= t:
                    heappush(self.left, -n)
                    self.sum_l += n
                else:
                    heappop(self.right)
                    self.sum_r -= t
                    heappush(self.right, n)
                    self.sum_r += n
                    heappush(self.left, -t)
                    self.sum_l += t
            self.size_l += 1
    
    def get(self):
        return -self.left[0]


def solve():
    Q = int(input())
    s = 0
    med = Medians()
    for _ in range(Q):
        q, *l, = map(int, input().split())
        if q == 1:
            a, b = l
            s += b
            med.add(a)
        else:
            m = med.get()
            d1 = med.size_l - med.size_r
            d2 = med.sum_r - med.sum_l
            print(m, m*d1+d2+s)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 84452
#include<stdio.h>
int main(){
  int n,d[300010],a,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    if(i%2==0)d[(n+i+1-n%2)/2]=a;//,printf("%d\n",(n+i+1-n%2)/2);
    else      d[(n-i-1    )/2]=a;//,printf("%d\n",(n-i-1    )/2);
  }
  for(i=0;i<n;i++){
    if(i)printf(" ");
    printf("%d",n%2?d[n-i-1]:d[i]);
  }
  printf("\n");
  return 0;
}


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

int main(int argc, char const *argv[]) {
 // ifstream cin("in.txt");
  ios::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  vector<int> w(n);
  for (auto &e : w)
    cin >> e;
  int left = *max_element(w.begin(), w.end()),
      right = accumulate(w.begin(), w.end(), 0), p = right;
  while (left <= right) {
    int middle = (left + right) / 2;
    bool flag = true;
    int cnt = 1, cur = middle;
    for (auto e : w) {
      if (e <= cur) {
        cur -= e;
      } else {
        cnt++;
        cur = middle - e;
      }
      if (cnt > k) {
        flag = true;
        break;
      }
    }
    if (cnt > k) {
      flag = false;
    }
    if (flag) {
      p = min(middle, p);
      right = middle - 1;
    } else {
      left = middle + 1;
    }
   // cout << flag << " " << middle << " [" << left << "," << right << "]"
    //     << endl;
  }
  cout << p << endl;
  return 0;
}



Measured memory_bytes: 3360
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    int cnt = 0;
    rep(i, 40){
        if(a%2==1 || b%2==1 || c%2==1){
            cout << cnt << endl;
            return 0;
        }
        ll d, e, f;
        d = (a + b) / 2;
        e = (b + c) / 2;
        f = (c + a) / 2;
        a = d; b = e; c = f;
        cnt++;
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3672
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

n, m = map(int, input().split())
a = list(map(int, input().split()))
l = a[0] // 2
for i in range(n):
    a[i] //= 2
    l = lcm(l, a[i])
c = 0
while True:
    for i in range(n):
        if a[i] % 2 == 1:
            c += 1
        else:
            a[i] //= 2
    if not c == 0:
        break
print(((m // l) + 1) // 2 if c == n else 0)

Measured memory_bytes: 15060
#include <iostream>

int main(){
  int N;
  std::cin >> N;
  bool isSeven = false;
  if(N%10==7){ isSeven = true; }
  N = N/10;
  if(N%10==7){ isSeven = true; }
  N = N/10;
  if(N%10==7){ isSeven = true; }
  if(isSeven){
    std::cout << "Yes" << std::endl;
  }else{
    std::cout << "No" << std::endl;
  }

  return 0;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int c[4][4];

void solve() {
   bool right = true;
   for (int i=0;i<3;i++) {
     for (int j=0;j<3;j++) {
       if (i == j) {
         continue;
       }
       for (int k=0;k<3;k++) {
         for (int l=0;l<3;l++) {
           if (k == l) {
             continue;
           }
           right &= (c[i][k] - c[i][l] == c[j][k] - c[j][l]);
         }
       }
     }
   }
   if (right) {
     cout << "Yes" << endl;
   } else {
     cout << "No" << endl;
   }
}

int main() {
  for (int i=0;i<3;i++) {
    for (int j=0;j<3;j++) {
      cin >> c[i][j];
    }
  }
  solve();
}


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

#define ll long long

#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define fill0(ar) fill((ar), 0)
#define debug(x) cout<<#x<<": "<<x<<endl

#define ld double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<int> vi;

#define INF 1000000000000000000

string s,t;
ll dp[3001][3001];
pair<char, pair<ll, ll> > p[3001][3001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> s;
    cin >> t;

    ll n = s.length();
    ll m = t.length();

    fr(i,1,n)
    {
        fr(j,1,m)
        {
            if(s[i-1]==t[j-1])
            {
                dp[i][j] = dp[i-1][j-1] + 1;
                p[i][j] = mp(s[i-1], mp(i-1,j-1));
            }
            else
            {
                if(dp[i-1][j]>dp[i][j-1])
                {
                    dp[i][j] = dp[i-1][j];
                    p[i][j] = mp('0', mp(i-1,j));
                }
                else
                {
                    dp[i][j] = dp[i][j-1];
                    p[i][j] = mp('0', mp(i,j-1));
                }
            }
        }
    }

    ll x = n;
    ll y = m;
    ll p1 = dp[n][m]-1;
    char ans[dp[n][m]];
    bool hu = 1;

    while(hu)
    {
        if(x==0 || y==0)
            hu = 0;
        if(p[x][y].ff!='0')
        {
            ans[p1] = p[x][y].ff;
            p1--;
        }
        ll x1 = p[x][y].ss.ff;
        ll y1 = p[x][y].ss.ss;
        x = x1;
        y = y1;
    }

    rep(i,dp[n][m])
    {
        cout << ans[i];
    }
    cout << endl;
}

Measured memory_bytes: 281600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
#include <bits/stdc++.h>
using namespace std;
  int N;
  cin >> N;
   int sum;
  vector<int> v(N); // N個の価値データ
  vector<int> c(N); // N個の支払いデータ
 
  // 数学の点数データを受け取る
  for (int i = 0; i < N; i++) {
    cin >> v.at(i);
  }
 
  // 英語の点数データを受け取る
  for (int i = 0; i < N; i++) {
    cin >> c.at(i);
  }
 
  // 合計点を出力
  for (int i = 0; i < N; i++) {
  if((v.at(i) - c.at(i))>0)
    sum += (v.at(i) - c.at(i));
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#define rep(i, n) for(int (i) = 1; (i) <= (n); (i)++)
//#define rep(i, n) for(int (i) = 0, TmP = (n); (i) < (int)TmP ; ++(i))
//#define int long long
#define asort(v, n) sort((v), (v + n)) //Using array
#define vsort(v) sort((v).begin(), (v).end()) // Using vector
#define vint vector<int>

using namespace std;

signed main(){
  int n;
  long long sum = 0;
  cin >> n;
  rep(i, n){
    if(i % 3 != 0 && i % 5 != 0)sum += i;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3636
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v) {std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

constexpr int MAX_N = 32800;

int main() {

    vector<int> squares;
    for (int i = 1; i * i <= MAX_N; i++) squares.push_back(i * i);

    vector<vector<vector<int >>> dp(2, vector<vector<int>>(6, vector<int>(MAX_N, 0)));
    //dp[i+1][j][k]
    //0-index i番目までの品物をj個使用して、合計がkになる通り数
    dp[0][0][0] = 1;

    for (int i = 0; i < squares.size(); i++) {
        for (int j = 0; j < 5; j++) {
            for (int k = 0; k < MAX_N - 3; k++) {
                if (k + squares[i] < MAX_N - 2) {
                    dp[i % 2][j + 1][k + squares[i]] += dp[i % 2][j][k];
                }
                dp[(i + 1) % 2][j][k] += dp[i % 2][j][k];
            }
        }
        dp[i % 2] = vector<vector<int>>(6, vector<int>(MAX_N, 0));
    }

//    vector<vector<vector<int >>> dp(squares.size() + 1, vector<vector<int>>(6, vector<int>(MAX_N, 0)));
//    //dp[i+1][j][k]
//    //0-index i番目までの品物をj個使用して、合計がkになる通り数
//    dp[0][0][0] = 1;
//
//    for (int i = 0; i < squares.size(); i++) {
//        for (int j = 0; j < 5; j++) {
//            for (int k = 0; k < MAX_N - 3; k++) {
//                if (k + squares[i] < MAX_N - 2) {
//                    dp[i][j + 1][k + squares[i]] += dp[i][j][k];
//                }
//                dp[i + 1][j][k] += dp[i][j][k];
//            }
//        }
//    }

    while (true) {
        int d;
        cin >> d;

        if (d == 0) break;

        int ans = 0;
        for (int i = 0; i < 5; i++) ans += dp[squares.size() % 2][i][d];
        cout << ans << endl;

    }


    return 0;
}





























Measured memory_bytes: 5044
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;
using LLI = long long int;

int main(void) {
	LLI N, H, MAX, pos, res = 0;
	cin >> N >> H;
	vector<LLI>a(N);
	vector<LLI>b(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i] >> b[i];
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	MAX = a[N - 1];
	pos = N - 1;
	while (1) {
		if (pos >= 0 && MAX < b[pos]) {
			H -= b[pos];
			pos--;
			res++;
		}
		else {
			break;
		}
		if (H <= 0) {
			break;
		}
	}
	if (H > 0) {
		if (H % MAX != 0) {
			res++;
		}
		res += H / MAX;
	}

	cout << res << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
 
using namespace std;
using std::cout;
using ll =long long;
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int ab(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
int main(){
  int age,A,B;
  cin>> age>>A>>B;
  if(age==1){
    cout<<"Hello World"<<endl;
  }
  else{
    cout<<A+B<<endl;
  }

}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7
INF = 10  ** 7
def main():
    n,a,b = map(int,input().split())
    m = n//2
    Chemical = [tuple(map(int,input().split())) for _ in range(n)]
    Chemical1 = Chemical[:m]
    Chemical2 = Chemical[m:]
    Sum1 = [[INF] * 405 for _ in range(405)]
    Sum2 = [[INF] * 405 for _ in range(405)]
    for bit in range(1<<m):
        cost,v1,v2 = 0,0,0
        for i in range(m):
            if (bit>>i)&1:
                d,e,f = Chemical1[i]
                v1 += d
                v2 += e
                cost += f
        Sum1[v1][v2] = min(Sum1[v1][v2],cost)
    
    for bit in range(1<<(n - m)):
        cost,v1,v2 = 0,0,0
        for i in range(n - m):
            if (bit>>i)&1:
                d,e,f = Chemical2[i]
                v1 += d
                v2 += e
                cost += f
        Sum2[v1][v2] = min(Sum2[v1][v2],cost)
    
    ans = INF
    for i in range(405):
        for j in range(405):
            if Sum1[i][j] != INF:
                C = Sum1[i][j]
                k = max((i + a - 1)//a,(j + b - 1)//b,1)
                while k * a - i < 405 and k*b - j < 405:
                    if Sum2[k*a - i][k*b - j] != INF:
                        ans = min(ans,Sum2[k*a - i][k*b - j] + C)
                    k += 1
    print(ans if ans != INF else -1)
if __name__ == '__main__':
    main()

Measured memory_bytes: 49372
#include <iostream>
#include <bitset>
#include <utility>

using namespace std;

#define int long long

signed main()
{
    int A, B;
    cin >> A >> B;

    /*
    int n = 0;
    for (int i = A; i <= B; i++)
    {
        n = n ^ i;
        //cout << bitset<5>(n) << " " << bitset<5>(i) << endl;
    }
    cout << n << endl;
    */

    // use piriodicity
    // count how many times 1 will appear in ndigits
    int ans = 0;
    // consider i digit
    // i digit has 1<<i period
    // 1 << (i-1) & A means a cycle in the period of A
    // i = 1 is exception
    ans += ((B + 1) / 2 - A / 2) % 2;
    for (int i = 2; i <= 50; i++)
    {
        int a = A & ((1ll << i) - 1);
        int b = B & ((1ll << i) - 1);
        int none = 0;

        a++;
        b++;

        none += min(1ll << (i - 1), (1ll << i) - a + 1);

        none += max(0ll, b - (1ll << (i - 1)));

        //cout << max(0ll, b - (1ll << (i - 1))) << endl;

        if (none % 2 == 1)
        {
            ans |= (1ll << (i - 1));
        }
        //cout << none << " " << ans << endl;
    }

    cout << ans << endl;
}

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

int main(int argc, char **argv)
{
    int n;
    std::cin >> n;

    long long b[100002];

    for (int i = 0; i < n; i++) std::cin >> b[i];

    int c = 0;
    for (int i = 0; i < n; i++) if (b[i] < 0) c ^= 1;
    long long m = 0;
    if (c) {
        m = 2000000000LL;
        for (int i = 0; i < n; i++) {
            m = std::min(m, std::abs(b[i]));
        }
    }
    long long s = 0;
    for (int i = 0; i < n; i++) s += std::abs(b[i]);
    s -= m * 2LL;

    std::cout << s << std::endl;

    return 0;
}

Measured memory_bytes: 1024
def get_num(n, x):
    ans = 0
    for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1):
        for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3 + 1) / 2 - 1, -1):
            for n1 in xrange(min(n2 - 1, x - n3 - n2), 0, -1):
                if n1 + n2 + n3 == x:
                    ans += 1
                    break
    return ans


while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        print(0)
    else:
        print(get_num(n, x))

Measured memory_bytes: 6368
#include<iostream>
#include<bits/stdc++.h>
#include<climits>

#define forn(x,n,s) for(int i = x; i < n; i += s )
#define forr(x,n,s) for(int i = x; i>=n; i -= s)

using namespace std;

void go(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  #ifndef ONLINE_JUDGE
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
  #endif
}

int main(){
    go();

    // code here
    int n,m;cin>>n>>m;
    unordered_map<int,vector<int>> List;
    forn(0,m,1){
        int a1,a2;cin>>a1>>a2;
        List[a1].push_back(a2);
        List[a2].push_back(a1);
    }
    unordered_set<int> visited;
    stack<int> st;
    int ans = 0;
    for(int i = 1;i<=n;i++){
        if(visited.find(i)==visited.end()){
            int cnt = 0;
            st.push(i);
            visited.insert(i);
            while(!st.empty()){
                cnt++;
                int pnt = st.top();
                st.pop();
                for(auto nei:List[pnt]){
                    if(visited.find(nei)==visited.end()){
                        visited.insert(nei);
                        st.push(nei);
                    }
                }
            }
            ans = max(ans,cnt);
        }
    }
    cout<<ans;

}






Measured memory_bytes: 29428
using System;

class Program
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine();
        for (int i = s.Length - 1; i >= 0; i--)
        {
            if (m1(s.Substring(0, i)))
            {
                Console.WriteLine(i);
                return;
            }
        }
    }

    static bool m1(string s)
    {
        return s.Substring(s.Length / 2) == s.Substring(0, s.Length / 2);
    }
}


Measured memory_bytes: 11092
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

N = INT()
i = 1
while N > 26**i:
	N -= 26**i
	i += 1

ans = ""
N -= 1
for j in range(i-1, -1, -1):
	ans += ascii_lowercase[N//(26**j)]
	N %= 26**j

print(ans)

Measured memory_bytes: 10052
s=input()
while len(s)>7:
    if s[-5:]=='erase' or s[-5:]=='dream':
        s=s[:-5]
    elif s[-6:]=='eraser':
        s=s[:-6]
    elif s[-7:]=='dreamer':
        s=s[:-7]
    else:
        break
if s=='' or s=='dreamer' or s=='eraser' or s=='erase' or s=='dream':
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define  ll  long long int
#define  sz  200010

using namespace std;

ll num[sz];
ll mn=LONG_LONG_MAX;

int main()
{

    ll n,i,j,k,c,s,d,p,m,x,y,a,b;


    cin>>a>>b;
    d=b/a;

     c=0;

    while(d>=1)
    {
        d=d/2;
        c++;
    }

    cout<<c<<endl;


    return 0;
}


Measured memory_bytes: 256
import sys
import math

#https://atcoder.jp/contests/agc008/submissions/15248942
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

S = input()
T = input()

ans = 0
for i in range(len(S)):
    for j in range(i+1,len(S)+1):
        if (j-i) == len(T):
            match = 0
            for k,l in enumerate(range(i,j)):
                if S[l] == T[k]:
                    match += 1
            ans = max(ans,match)

print(len(T)-ans)



Measured memory_bytes: 9152
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	map<int, int> m;
	rep(i, n){
		int a; cin >> a;
		m[a]++;
	}
	int ans = 0;
	for(auto i : m){
		if(i.first <= i.second) ans += i.second - i.first;
		else ans += i.second;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 4736
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = 1e18;
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;
    vector<int> A(N); REP(i, 0, N) cin >> A[i];
    
    vector<int> diff(N-1);
    REP(i,0,N-1){
        diff[i] = A[i + 1] - A[i];
    }
    ll sum = 0;
    REP(i,0,N-1){
        int v = diff[i];
        if (v < 0){
            sum += -1 * v;
            if (i != N-2) diff[i + 1] += v;
        }
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 4860
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int val = sc.nextInt();
        int h = val / 3600;
        int m = val % 3600 / 60;
        int s = val % 60;
        System.out.println(h + ":" + m + ":" + s);
    }
}


Measured memory_bytes: 26332
a = int(input())
b = [input() for _ in range(a) ]
c = int(input())
d = [input() for _ in range(c) ]

bb = set(b)
dd = set(d)
s = max(b.count(i) -d.count(i)  for i in bb)
print(s if s > 0 else 0)

Measured memory_bytes: 62392
n = int(input())
ans = []
A = list(map(int,input().split()))
A2 = [[0,i+1] for i in range(n)]

for i in range(n):
	A2[i][0] = A[i]
#print(A2)
A2 = sorted(A2,key = lambda x:x[0])

for i in range(n):
	ans.append(A2[i][1])
print(*ans)


Measured memory_bytes: 23648
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let (n, m): (usize, usize) = read();
    let a: Vec<usize> = readnc();

    let mut partial_sum = vec![0; n+1];
    for i in 0..n {
        partial_sum[i+1] = partial_sum[i] + a[i];
    }
    let mut mod_count: HashMap<usize, i64> = HashMap::new();
    for i in 0..n+1 {
        let modm = partial_sum[i]%m;
        let cnt = *mod_count.get(&modm).unwrap_or(&0);
        mod_count.insert(modm, cnt+1);
    }

    let mut ans: i64 = 0;
    for i in (1..n+1).rev() {
        let modm = partial_sum[i] % m;
        let cnt = *mod_count.get(&modm).unwrap_or(&0);
        mod_count.insert(modm, cnt-1);
        ans += cnt-1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 14588
#include <stdio.h>
#include <string.h>
int main(){
  char txt[201],txt2[101],word[101];
int i=0,j=0,res=0,k=0,n=0;

 scanf("%s",txt);
 scanf("%s",word);
  strcpy(txt2,txt);
 strcat(txt,txt2);
 for(i=0;i<201;i++){
   for(j=0;j<101;j++){
     if(word[j]=='\0'){
       res=1;
       break;
     }
     else if(word[j]==txt[i+j])continue;
     else break;
   }
 }

 if(res==1){
   printf("Yes\n");
 }
 else if(res==0){
   printf("No\n");
 }
 return 0;
}

Measured memory_bytes: 532
// ABC 089 B- Hina Arare
// repの練習

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

int main() {
  int N, a = 0;
  string S;
  cin >> N;

  rep(i, N) { // main関数内で書くときはrep(カウント変数名,回数)
    cin >> S;
    if (S == "Y") {
      cout << "Four" << endl; // Y がきたときのみ
      break;
    }
    a++; // ループ数をカウントしておけば、数が一致することでThree判定できる
  }
  if (a == N) {
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 3624
def solve(x, n, p):
    S = set(p)
    for d in range(n+1):
        for y in [x-d, x+d]:
            if not y in S:
                return y

x, n = map(int, input().split())
p = list(map(int, input().split()))
print(solve(x, n, p))

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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

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

vector<int> h;
int N, A, B;

bool enough(ll T) {
    ll addd = 0;
    REP(i, N) {
        if (h[i] - T * B > 0) {
            ll tmp = h[i] - T * B;
            addd += tmp / (A-B);
            if (tmp%(A-B)) addd++;
        }
    }
    return T >= addd;
}

int main(){
    ios::sync_with_stdio(false);
    cin >> N >> A >> B;
    h = vector<int>(N);
    
    REP(i, N) {
        cin >> h[i];
    }
    
    ll lb = 0, ub = INF;
    while(ub - lb > 1) {
        ll mid = (ub + lb) / 2;
        if (!enough(mid)) {
            lb = mid;
        } else {
            ub = mid;
        }
    }
    cout << lb+1 << endl;
    
    return 0;
}


Measured memory_bytes: 768
'use strict';
function Main(input) {
    const tmp = input.split(' ');
    let five = 0;
    let seven = 0;
    for (let i = 0; i < tmp.length; i++) {
        if (tmp[i] == 5) {
            five++;
        } else if (tmp[i] == 7) {
            seven++;
        }
    }
    if (five == 2 && seven == 1) {
        console.log("YES");
    } else {
        console.log("NO");
    }
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 9420
#include <cstdio>
#include <stdlib.h>

#include <iostream>
#include <chrono>


#define N 10000

#if _DEBUG
typedef long lli;
#else
typedef long long int  lli;
#endif

lli a[N*N];
lli b[N*N];
lli c[N*N];

int n,m,l;

void mult() {
    lli register t;
    for(int i=0; i<n; i++)
        for(int j=0; j<l; j++)
        {
            t = 0;
            for(int k=0; k<m; k++)
                t += a[i*N + k] * b[k*N + j];
            c[i*N + j] = t;
        }
}

int main(void) {
#if _DEBUG
    for(n=2; n<N; n*=2) {
        m=l=n;
#else
        scanf("%d%d%d", &n, &m, &l);
#endif


#if _DEBUG
        for(int i=0; i<n; i++)
            for(int j=0; j<m; j++)
                a[i*N + j] = rand();
        for(int i=0; i<m; i++)
            for(int j=0; j<l; j++)
                b[i*N + j] = rand();
#else
        for(int i=0; i<n; i++)
            for(int j=0; j<m; j++)
                scanf("%lld", &a[i*N + j]);
        for(int i=0; i<m; i++)
            for(int j=0; j<l; j++)
                scanf("%lld", &b[i*N + j]);
#endif
        for(int i=0; i<n; i++)
            for(int j=0; j<l; j++)
                c[i*N + j] = 0;

        auto start = std::chrono::system_clock::now();
        mult();
        auto end = std::chrono::system_clock::now();

#if _DEBUG
        auto dur = end-start;
        auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(dur).count();
        std::cout << n << " : " << msec << " milli sec" << std::endl;
    }
#else
    for(int i=0; i<n; i++) {
        for(int j=0; j<l-1; j++)
            printf("%lld ", c[i*N + j]);
        printf("%lld", c[i*N + l-1]);
        printf("\n");
    }
#endif
    return 0;
}

Measured memory_bytes: 4596