akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#define rep(i,n) for(int i = 0; i < (n); i++) 
using namespace std;
using ll = long long;

int main() {
    
    int a,b,c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b;
	return 0;
}


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

int a,b,c;

int main() {

	cin >> a >> b >> c;
  	if(a <= c&&c <= b || b <= c && c <= a)
    	cout <<"Yes"<<endl;
 	else 	
		cout<<"No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 1014159
#define  vi vector<int>
#define  v  vector


int n;
vi adj[N];
int k;
int dp[N][4];

inline int mul(int a,int b){return (a*1ll*b)%MOD;}
inline int add(int a,int b){a+=b;if(a>=MOD)a-=MOD;return a;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,MOD-2);}


int dfs(int u,int p)
{
    dp[u][0] = 1;
    int x  = 0;
    forn(i,1,2)x+=dp[u][i];
    int sum = (k-x);
    if(sum <= 0)
    {
        cout<<0;nl;
        
        exit(0);
    }
    int ans = 1;
    for(auto v : adj[u])
    {
        if(v == p)continue;
        dp[v][2]=dp[u][1];
        dp[v][1]=dp[u][0];
        ans=mul(ans,dfs(v,u));
        dp[u][1]+=dp[v][0];
        dp[u][2]+=dp[v][1]-1;
        
    }
    return mul(sum,(max(ans,1LL)));
}


signed solve()
{
    cin>>n>>k;
    forn(i,1,n-1)
    {
        int a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    cout<<dfs(1,0)<<"\n";
    
   
}


signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }



    return 0;

}

//       g++ -g c.cpp ; ./a.exe

Measured memory_bytes: 40448
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef pair<ll , ll> pii;
typedef long double DB;

const ll N = 100100;
const ll MOD = 1000*1000*1000LL + 7 , INF = MOD*N;


vector <pii> adj1[N];
vector <int> q , par[N] , adj2[2][N];
set <pii> s;

ll num[2][N] , d[2][N] , ans;
int n , m , b , e , deg[N];


void Dijkstra(int st , bool f){

	for(int i = 0 ; i < n ; i++){
	   if(i != st)
		  d[f][i] = INF;
	   s.insert({d[f][i] , i});
	}   

	while(s.size()){

		int v = (*s.begin()).S;
		s.erase(s.begin());

		for(auto u : adj1[v]){
		   ll c = d[f][v] + u.S;
		   if(c < d[f][u.F]){
			  s.erase({d[f][u.F] , u.F});
			  d[f][u.F] = c;
			  s.insert({c , u.F});
		   }
		}

	}

	return;

}


void tsort(int st , bool f){
	
	for(int i = 0 ; i < n ; i++)
	   deg[i] = adj2[1-f][i].size();

	
	num[f][st] = 1;
	q.pb(st);

	int pt1 = 0 , pt2 = 1;

	while(pt1 < pt2){
		
	   for(int u : adj2[f][q[pt1]]){
		  deg[u]--;
		  if(!deg[u])
			 q.pb(u) , pt2++;
	   }

	   pt1++;
	}

	for(int v : q)
	   for(int u : adj2[f][v])
		  num[f][u] = (num[f][u] + num[f][v]) % MOD;
	
	q.clear();
	return;
}


int main(){

	ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	
	int u , v , w;

	cin >> n >> m >> b >> e;
	b-- , e--;	

	for(int i = 0 ; i < m ; i++){
	   cin >> u >> v >> w;

	   adj1[--u].pb({--v , w});
	   adj1[v].pb({u , w});
	}

	Dijkstra(b , 0);
	Dijkstra(e , 1);	

	for(int i = 0 ; i < n ; i++){
	   for(auto u : adj1[i]){
		  if(d[0][i] + d[1][u.F] + u.S == d[0][e]){
			 adj2[0][i].pb(u.F);
			 adj2[1][u.F].pb(i);
		  }
	   }
	}

	tsort(b , 0);
	tsort(e , 1);

	ans = num[0][e] * num[0][e] % MOD;
	DB x = (DB) d[0][e]/2;

	for(int i = 0 ; i < n ; i++){
	   for(int u : adj2[0][i]){
		  ll y = num[1][u] , z = num[0][i];
		  if((DB) d[0][u] > x && (DB) d[0][i] < x)
			 ans -= (y*y % MOD)*(z*z % MOD) %MOD;
		  
		  ans = (ans + MOD) % MOD;
	   }
	   
	   if((DB) d[0][i] == x && d[1][i] == x){
		  ll z = num[0][i] , y = num[1][i];
	   	  ans -= (z*z % MOD)*(y*y % MOD) % MOD;
	   }

	   ans = (ans + MOD) % MOD;
	}

	cout << ans << endl;

}

Measured memory_bytes: 29952
'''
https://beta.atcoder.jp/contests/abc104/submissions/2954675
https://beta.atcoder.jp/contests/abc104/submissions/2953603
'''
D, G = map(int, input().split())
p = []
c = []
for i in range(D):
    x, y = map(int, input().split())
    p.append(x)
    c.append(y)

ans = max(p) * D
for i in range(1 << D):
    cnt = 0
    score = 0
    rest_max = -1
    for j in range(D):
        if i >> j & 1:
            score += c[j]
            score += p[j] * (j + 1) * 100
            cnt += p[j]
        else:
            rest_max = j
    if score < G:
        g = (rest_max + 1) * 100
        need = (G - score + g - 1) // g#Gを超えるのに必要な問題数
        if need >= p[rest_max]:
            continue#iで表されるコンプリートボーナス取得計画では、G以上を達成できない
        cnt += need
    ans = min(ans, cnt)
print(ans)

'''
G-score mod g: 剰余0～(g-1)
これに(g-1)を加えると
剰余は(g-1), g, ..., (2g-2) = (g+g-2)まで
元の剰余が0だった場合以外は、剰余をgで割ると1.xになるので、
整数部分を取れば、切り上げになっている
'''

Measured memory_bytes: 3064
def main():
    L, R = map(int, input().split())
    minCount = float('inf')

    for i in range(L, R+1):
        for j in range(i+1, R+1):
            ans = i * j % 2019
            minCount = min(minCount, ans)
            if ans == 0:
                print(0)
                return
    print(minCount)

if __name__ == "__main__":
     main()

Measured memory_bytes: 38896
#include<stdio.h>

int main(int argc, char const *argv[])
{
    int y = 0;
    int m = 0;
    int d = 0;
    int hot = 0;

    scanf("%d/%d/%d", &y, &m, &d);

    if(m > 4){
        hot = 1;
    }

    if(hot == 1){
        printf("TBD\n");
    }else{
        printf("Heisei\n");
    }

    return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		
		for(int i = 0; i < n; i++){
			
						
			String[] tmpArray = br.readLine().split(" ");
			int y = Integer.parseInt(tmpArray[0]);
			int m = Integer.parseInt(tmpArray[1]);
			int d = Integer.parseInt(tmpArray[2]);
			
			int day = 0;
			while(true){
				boolean addMonth = false;
				//??§???????????????
				if(d == 20){
					d = 1;
					addMonth = true;
				}
				//?°????????????????
				else if(d == 19 && y%3 != 0 && m%2 == 0){
					d = 1;
					addMonth = true;
				}
				else {
					d++;
				}
				
				if(addMonth){
					if(m == 10){
						m = 1;
						y++;
					}
					else {
						m++;
					}
				}
				
				day++;
				//System.out.println("day "+ day);
				
				if(y == 1000 && m == 1 && d == 1){
					System.out.println(day);
					break;
				}
			}
		}
	}

}

Measured memory_bytes: 24768
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check(int n) {
    for(int i=2;i*i<=n;++i) {
        if(n%i==0)
        return false;
    }
    return true;
}


// bool cmp(pair<int,int>p,pair<int,int>q) {
//     // return p.first>q.first;//descending by first
//     // return p.first<q.first;//ascending by first
//     // return p.second>q.second;//descending by second
//     return p.second<q.second;//ascending by second
// }

bool cmp(int p,int q) {
    return p>q;//descending
    // return p<q;//ascending
}


int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }

    return 0;
}
int clue() {

    lli a,b;
    cin>>a>>b;
    lli p=a+b;
    if(p%2==0) {
        cout<<p/2<<endl;
    }
    else
    {
        cout<<"IMPOSSIBLE"<<endl;
    }
    
    // ()?cout<<"Yes"<<endl:cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Test int T;cin>>T;while(T--)
#define ls lower_bound
#define up upper_bound
#define bs binary_search
#define S second
#define F first
#define vi vector<int>  
#define pii pair<int,int>
#define vpii vector<pii>
#define vvi vector<vi>
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define m_n(v) *min_element(all(v))
#define m_x(v) *max_element(all(v))
#define ___(a) for(auto &i:a) cin>>i
#define __(a)  for(auto i:a) cout<<i<<" "
#define nl cout<<"\n";
#define momo(k) memset(k,0,sizeof(k))
#define momi(k) memset(k,-1,sizeof(k))
/* 
#include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
*/
int power(int x, int y,int mod){
    int res = 1;
    while (y)
    {
        if (y & 1)
        res = (res*x)%mod;
        y = y>>1;
        x = (x*x)%mod;
    }
    return res;
}
int modInverse(int a, int m){
    int m0 = m;
    int y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;

    return x;
}
int binomial(int n,int k){
    int res = 1;
    if ( k > n - k )
        k = n - k;

    for (int i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }

    return res;
}

// vector<int> prime;
// void sieve(){
//     bool arr[300000]={0};
//     prime.pb(2);
//     for(int i=3;i<300000;i+=2){
//         if(arr[i])continue;
//         for(int j=i*i;j<300000;j+=i) arr[j]=1;
//         prime.pb(i);
//     }
// }
// const int N=1e18+2;
const int mod = 1e9+7;
const int N = 3e3+2;
int n;
double p[N];

// void solve(){
//     double dp[n+1][n+1];
//     memset(dp,0.0,sizeof(dp));
//     dp[0][0] = 1;
//     for(int i=1;i<=n;i++){
//         for(int j=0;j<=n;j++){
//             if(j == 0) dp[i][j] = (1-p[i])*dp[i-1][j];
//             else dp[i][j] = p[i]*dp[i-1][j-1] + (1-p[i])*dp[i-1][j];
//         }
//     }
//     double ans = 0.0;
//     for(int i=(n+1)/2;i<=n;i++){
//         ans += dp[n][i];
//     }
//     cout<<ans;
// }

int32_t main() {
    IOS;
    cout<<fixed<<setprecision(10);
    cin>>n;
    memset(p,0.0,sizeof(p));
    for(int i=1;i<=n;i++){
        cin>>p[i];
    }
    double dp[n+1];
    memset(dp,0.0,sizeof(dp));
    dp[0] = 1;
    for(int i=1;i<=n;i++){
        for(int j=i;j>=0;j--){
            if(j == 0) dp[j] = (1-p[i])*dp[j];
            else dp[j] = (1-p[i])*dp[j] + p[i]*dp[j-1];
        }
    }
    double ans = 0;
    for(int i=(n+1)/2;i<=n;i++){
        ans += dp[i];
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3780
N = int(input())
G = [input().split() for _ in range(N)]

taro, hanako = 0, 0
for g in G:
	if g[0] < g[1]:
		hanako += 3
	elif g[0] > g[1]:
		taro += 3
	else:
		hanako += 1
		taro += 1
print(taro, hanako)



Measured memory_bytes: 5716
x,y,z,k=map(int, input().split())
a=sorted(list(map(int, input().split())),reverse=True)
b=sorted(list(map(int, input().split())),reverse=True)
c=sorted(list(map(int, input().split())),reverse=True)

from heapq import heapify,heappop,heappush
q=[]
heappush(q,(-a[0]-b[0]-c[0],(0,0,0)))
used={(0,0,0):True}
for i in range(k):
    if q[0][1][0]+1<x and (q[0][1][0]+1,q[0][1][1],q[0][1][2]) not in used:
        heappush(q,(-a[q[0][1][0]+1]-b[q[0][1][1]]-c[q[0][1][2]],(q[0][1][0]+1,q[0][1][1],q[0][1][2])))
        used[(q[0][1][0]+1,q[0][1][1],q[0][1][2])]=True
    if q[0][1][1]+1<y and (q[0][1][0],q[0][1][1]+1,q[0][1][2]) not in used:
        heappush(q,(-a[q[0][1][0]]-b[q[0][1][1]+1]-c[q[0][1][2]],(q[0][1][0],q[0][1][1]+1,q[0][1][2])))
        used[(q[0][1][0],q[0][1][1]+1,q[0][1][2])]=True
    if q[0][1][2]+1<z and (q[0][1][0],q[0][1][1],q[0][1][2]+1) not in used:
        heappush(q,(-a[q[0][1][0]]-b[q[0][1][1]]-c[q[0][1][2]+1],(q[0][1][0],q[0][1][1],q[0][1][2]+1)))
        used[(q[0][1][0],q[0][1][1],q[0][1][2]+1)]=True
    print(-heappop(q)[0])


Measured memory_bytes: 5020
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using Int = int64_t;
const Int INF = 1<<30;
const Int MOD = (Int)1e9 + 7;
const Int MAX_N = (Int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(Int i = 0; i < (Int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

Int func(Int n)
{
    Int res = 0;
    for(Int x = 1; x <= sqrt(n); x++)
    {
        if(x * x > n) break;
        for(Int y = 1; y <= sqrt(n); y++)
        {
            if(x * x + y * y > n) break;
            for(Int z = 1; z <= sqrt(n); z++)
            {
                Int tmp = x * x + y * y + z * z + x * y + y * z + z * x;
                if(tmp > n) break;
                if(tmp == n) res++;
            }
        }
    }
    return res;
}

void solve()
{
    Int n; cin >> n;
    for(Int i = 1; i <= n; i++)
    {
        cout << func(i) << "\n";
    }
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll t[222222];
int main(){
    int n,b,i,j,k,x,y;
    cin>>n>>x>>y;
    for(i=1;i<n;i++){
        for(j=i+1;j<=n;j++){
            int mi=j-i;
            mi=min(mi,abs(i-x)+abs(j-y)+1);
            t[mi]++;
        }
    }
    for(i=1;i<n;i++)cout<<t[i]<<endl;
}


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

int m,n,b[501],r[501];
vector<int> G[1000];
int match[1000];
bool used[1000];

bool dfs(int v){
	used[v]=1;
	rep(i,G[v].size()){
		int u=G[v][i],w=match[u];
		if(w<0||!used[w]&&dfs(w)){
			match[v]=u,match[u]=v;
			return 1;
		}
	}
	return 0;
}

void solve(){
	rep(i,n) cin>>b[i];
	rep(i,m) cin>>r[i];
	rep(i,1000)G[i].clear();
	rep(i,n) rep(j,m){
		int a=b[i],c=r[j];
		while(c){
			a%=c;
			swap(a,c);
		}
		if(a!=1)G[i].push_back(j+n),G[n+j].push_back(i);
	}
	int res=0;
	memset(match,-1,sizeof(match));
	rep(v,m+n){
		if(match[v]<0){
			memset(used,0,sizeof(used));
			if(dfs(v)) res++;
		}
	}
	cout<<res<<endl;
}

int main(){
	while(cin>>n>>m,n||m)solve();
}

Measured memory_bytes: 3380
import collections
K = int(input())

que = collections.deque()
for i in range(1, 10, 1):
    que.append(i)
cnt = 0
for i in range(K):
    x = que.popleft()
    cnt += 1
    if cnt == K:
        print(x)
        exit()
    if x%10 == 0:
        que.append(10*x+0)
        que.append(10*x+1)
    elif x%10 == 9:
        que.append(10*x+8)
        que.append(10*x+9)
    else:
        que.append(10*x+(x%10)-1)
        que.append(10*x+(x%10)+0)
        que.append(10*x+(x%10)+1)



Measured memory_bytes: 18856
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 112000000012345678L

long d[300][300];

int main(){
  int n;
  cin>>n;
  rep(i,n) rep(j,n) cin>>d[i][j];

  long ans = 0;
  rep(i,n)rep(j,i){
    bool dup = false;
    rep(k,n)if(k!=i && j!=k){
      if(d[i][k]+d[k][j] < d[i][j]){
        cout << -1 << endl;
        return 0;
      }
      if(d[i][k]+d[k][j] == d[i][j]) dup = true;
    }
    if(!dup) ans += d[i][j];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 1e9 + 7
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.begin(), v.end(), greater<ll>()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;
using namespace std;
int main() {
    string ss, tt;
    cin >> ss;
    cin >> tt;
    int ct = 0;
    for(int i = 0; i < 3; ++i) if(ss[i] == tt[i]) ++ct;
    cout << ct;
}


Measured memory_bytes: 256
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

mod util {
    #[allow(dead_code)]
    pub fn chmin<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x > y && {
            *x = y;
            true
        }
    }

    #[allow(dead_code)]
    pub fn chmax<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x < y && {
            *x = y;
            true
        }
    }

    /// 整数除算切り上げ
    #[allow(dead_code)]
    pub fn roundup(a: i64, b: i64) -> i64 {
        (a + b - 1) / b
    }

    #[allow(dead_code)]
    pub fn ctoi(c: char) -> i64 {
        c as i64 - 48
    }
}

#[allow(unused_imports)]
use util::*;

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque};

fn main() {
    input! {
        n:usize,
        mut s:chars
    }
    s.push('#');

    let mut ans = 0;
    for i in 0..n {
        if s[i] != s[i + 1] {
            ans += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <stdlib.h>
#include <cmath>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;

const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
    ll X,Y;
    cin>>X>>Y;
    ll ans=0;
    if((X+Y)%3==0 && 2*X>=Y && 2*Y>=X){
        ll S=(X+Y)/3;
        ll a=(S-abs(X-Y))/2;
        //cout<<S<<' '<<a<<endl;
        COMinit();
        ans=COM(S,a);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 16768
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

class Procon {
    static void Main (string[] agrs) {
        long N = Long();
        long K = Long();

        long tmp1 = N / K;
        long tmp2 = 0;
        if (K % 2 == 0 && N >= K / 2) {
            tmp2 = (N - K / 2) / K + 1;
        }

        Dbg(tmp1 * tmp1 * tmp1 + tmp2* tmp2* tmp2);
    }

    static string String () => Scanner.nextString ();
    static int Int () => int.Parse (Scanner.nextString ());
    static long Long () => long.Parse (Scanner.nextString ());
    static double Double () => double.Parse (Scanner.nextString ());
    static char[] Chars () => String ().ToCharArray ();
    static string[] Strings () => Console.ReadLine ().Split (' ');
    static int[] Ints () => Strings ().Select (v => int.Parse (v)).ToArray ();
    static long[] Longs () => Strings ().Select (v => long.Parse (v)).ToArray ();
    static double[] Doubles () => Strings ().Select (v => double.Parse (v)).ToArray ();
    const int M = 1000000007;
    static void Dbg (object a) => Console.WriteLine (a);
    static void Dbg (params object[] a) => Console.WriteLine (string.Join (" ", a));
    static void Dbgs<T> (IEnumerable<T> a, string split = " ") => Console.WriteLine (string.Join (split, a));
    static T Max<T> (params T[] a) => a.Max ();
    static T Min<T> (params T[] a) => a.Min ();
}

class PriorityQueue<T> where T : IComparable<T> {
    public T[] heap;
    public int size;
    public int sign;
    public PriorityQueue (int N, bool descend = false) {
        heap = new T[N];
        if (descend) sign = -1;
    }
    public int Compare (T x, T y) {
        return x.CompareTo (y) * sign;
    }
    public void Push (T x) {
        int i = size++;
        while (i > 0) {
            int p = (i - 1) / 2;
            if (Compare (x, heap[p]) >= 0) {
                break;
            }
            heap[i] = heap[p];
            i = p;
        }
        heap[i] = x;
    }
    public T Pop () {
        T ret = heap[0];
        T x = heap[--size];
        int i = 0;
        while (i * 2 + 1 < size) {
            int a = i * 2 + 1;
            int b = i * 2 + 2;
            if (b < size && Compare (heap[a], heap[b]) > 0) {
                a = b;
            }
            if (Compare (heap[a], x) >= 0) {
                break;
            }
            heap[i] = heap[a];
            i = a;
        }
        heap[i] = x;
        return ret;
    }
    public int Count () {
        return size;
    }
}

class Scanner {
    static string[] s = new string[0];
    static int i = 0;
    static int max_i = 0;
    static public string nextString () {
        if (i >= s.Length) {
            s = Console.ReadLine ().Split (' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0) {
                return "";
            }
            return s[i++];
        }
        return s[i++];
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cstdint>
#include <vector>
#include <algorithm>
using namespace std;
static const long long MOD = 1000000007LL;
typedef long long ll;
#define REP(i,n) for(int i = 0; i < (int)(n); i++)

int main()
{
	int n;
	cin>>n;
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		string s= to_string(i);
		if(s.length()%2!=0)
			cnt++;
	}
	cout<<cnt<<endl;


	return 0;
}


Measured memory_bytes: 256
N,W = map(int,input().split())
w = [0]*(N+1)
v = [0]*(N+1)
for i in range(1,N+1): w[i],v[i] = map(int,input().split())

dp = [[0]*(N+1) for _ in range(W+1)]
for i in range(1,W+1):
    for j in range(1,N+1):
        if i < w[j]: dp[i][j] = dp[i][j-1]
        else: dp[i][j] = max(dp[i][j-1],dp[i-w[j]][j-1]+v[j])
print(dp[W][N])

Measured memory_bytes: 131036
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

X = int(sys.stdin.buffer.readline())
a = X // 500
b = (X % 500) // 5
print( a * 1000 + b * 5)


Measured memory_bytes: 25172
//#pragma GCC optimize("trapv")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace __gnu_pbds;
//using namespace __gnu_cxx;
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
const int maxn = 3e5 + 33, mlg = 18, mod = 1e9 + 7;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	int ans = 0;
	cin >> s;
	int n = s.size();
	for(int i = 0; n-i-1>=i; i++) {
		ans += s[i]!=s[n-i-1];
	}
	cout << ans;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main(void){
    int path[3][2];
    int i;
    int count[5]={0};
    for(i=0;i<3;i++){
        scanf("%d %d",&path[i][0],&path[i][1]);
        count[path[i][0]-1]++;
        count[path[i][1]-1]++;
    }
    for(i=0;i<4;i++){
        if(count[i]==2){
            count[4]++;
        }
    }
    if(count[4]==2){
        printf("YES");
    }
    else{
        printf("NO");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main() {
	int x[5];
	int a;
	cin >> a;
	x[0] = a / 100;
	x[1] = (a / 10) % 10;
	x[2] = a % 10;
	for (int i = 0; i < 3; i++) {
		if (x[i] == 1)x[i] = 9;
		else if (x[i] == 9)x[i] = 1;
	}
	cout << x[0] << x[1] << x[2] << endl;





	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  cout << fixed << setprecision(20);
  int n;
  cin >> n;
  vector<double> x(n);
  for (int i = 0; i < n; i++){
    cin >> x[i];
  }
  vector<double> y(n);
  for (int i = 0; i < n; i++){
    cin >> y[i];
  }
  double d1 = 0, d2 = 0, d3 = 0, di = 0;
  for (int i = 0; i < n; i++){
    d1 += abs(x[i] - y[i]);
    d2 += pow(abs(x[i] - y[i]), 2);
    d3 += pow(abs(x[i] - y[i]), 3);
    di = max(di, abs(x[i] - y[i]));
  }
  d2 = pow(d2, (double)1 / 2);
  d3 = pow(d3, (double)1 / 3);
  cout << d1 << endl;
  cout << d2 << endl;
  cout << d3 << endl;
  cout << di << endl;
}


Measured memory_bytes: 3480
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'

const ll m = 1e9+7;
void solve(){ 
  ll n, k;
  cin >> n >> k;
  vector<int> a(n);
  forn(i,n) cin >> a[i];
  ll ans = 0;
  forn(i,n) {
    ll cnt = 0;
    rep(j,0,i){
      if (a[i] < a[j]) cnt++;
    }
    ans += cnt * k;
    ans %= m;
  }
  sort(rall(a));
  k--;
  ll t = (k * (k + 1ll) / 2ll) % m;
  forn(i,n) {
    ll cnt = 0;
    rep(j,i+1,n){
      if (a[i] > a[j]) cnt++;
    }
    ans += (cnt * t) % m;
    ans %= m;
  }
  cout << ans % m << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 



9 8 7 10 5 6 3 4 2 1 * 9 8 7 10 5 6 3 4 2 1 * 9 8 7 10 5 6 3 4 2 1

 */

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

int find(int64_t H, int64_t W){
  int64_t h_side = (H * W + 3 * H - 1) / (3 * H);
  int64_t h_max = 100000000;
  for(int64_t i = h_side - 1; i <= h_side; i++){
    int64_t h1 = i*H;
    int64_t h2 = min((W - i) * ((H + 1) / 2), H * ((W - i + 1) / 2)); 
    int64_t h3 = W * H - h1 - h2;
    h_max = min(max(h1, max(h2, h3)) - min(h1, min(h2, h3)), h_max);
  }
  return h_max;
}

int main(){
  int64_t H, W;
  cin >> H >> W;
  if(H%3 == 0 || W%3 == 0) cout << 0 << endl;
  else{
    int64_t ans = min(find(H, W), find(W, H));
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b>c+d)
    cout<<"Left"<<endl;
  else if(a+b==c+d)
    cout<<"Balanced"<<endl;
  else
    cout<<"Right"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<unordered_set>
#include<unordered_map>
#define ll long long 
#define lowbit(x) (x)&(-x)
using namespace std;
const int maxn = 2e5 + 100;
const ll mod = 998244353;
ll d[maxn];

//线段树
class SEGEMENT_TREE
{
public:
	ll a[maxn];
	struct node
	{
		int L; int R; ll sum; ll flag;
	};
	node tree[maxn << 2];

	//如果某项不需要，为节省事件开销可以注释掉
	void push_down(int x)
	{
		if (tree[x].flag == 0) return;
		tree[x << 1].flag = tree[x].flag; tree[x << 1 | 1].flag = tree[x].flag;
		tree[x << 1].sum = ((d[tree[x << 1].R] - d[tree[x << 1].L - 1]) % mod + mod) % mod * tree[x].flag;
		tree[x << 1].sum %= mod;
		tree[x << 1 | 1].sum = ((d[tree[x << 1 | 1].R] - d[tree[x << 1 | 1].L - 1]) % mod + mod) % mod * tree[x].flag;
		tree[x << 1 | 1].sum %= mod;
		tree[x].flag = 0;
	}

	void push_up(int x)
	{
		tree[x].sum = (tree[x << 1].sum + tree[x << 1 | 1].sum) % mod;
	}

	//最大值和最小值的初值根据实际情况初始化
	//也可以根据初始数组a来进行建树
	void init(int L, int R, int x)
	{
		tree[x].L = L; tree[x].R = R;
		if (tree[x].L == tree[x].R)
		{
			tree[x].sum = ((d[tree[x].R] - d[tree[x].L - 1]) % mod + mod) % mod;
			tree[x].flag = 0;
			return;
		}
		int mid = (L + R) >> 1;
		init(L, mid, x << 1); init(mid + 1, R, x << 1 | 1);
		push_up(x);
	}

	//给l，r区间修改K
	void update(int l, int r, int x, ll K)
	{
		if (l <= tree[x].L && tree[x].R <= r)
		{
			tree[x].sum = ((d[tree[x].R] - d[tree[x].L - 1]) % mod + mod) % mod * K;
			tree[x].sum %= mod;

			tree[x].flag = K;
			return;
		}
		int mid = (tree[x].L + tree[x].R) >> 1;
		push_down(x);
		if (l <= mid) update(l, r, x << 1, K);
		if (mid < r) update(l, r, x << 1 | 1, K);
		push_up(x);
	}
};
//线段树
SEGEMENT_TREE T;

int main()
{
	ios::sync_with_stdio(false);
	int N; cin >> N; int Q; cin >> Q;
	d[1] = 1; d[0] = 0;
	for (int i = 2; i <= N; i++) d[i] = (d[i - 1] * 10) % mod;
	for (int i = 2; i <= N; i++) d[i] = (d[i - 1] + d[i]) % mod;

	T.init(1, N, 1);
	while (Q--)
	{
		int L; int R; ll D; cin >> L >> R >> D;
		//int t = L; L = R; R = t; 
		L = N - L + 1; R = N - R + 1;
		T.update(R, L, 1, D);
		cout << T.tree[1].sum << endl;
	}
	return 0;
}

Measured memory_bytes: 17504
#include<cstdio>
#include<cstring>
#include<algorithm>
typedef long long LL;
using namespace std;
#define max_n 100005

int a[max_n];

int main()
{
	int n,k=1,ans,i;
	bool flag,res=false;
	scanf("%d",&n);
	scanf("%d",&a[0]);
	if(n==1)
	{
		printf("1\n");
		return 0;
	}
	ans=a[0];
	for(i=1;i<n;i++)
	{
		scanf("%d",&a[i]);
//		for(;i<n;i++)
//		{
//			scanf("%d",&a[i]);
//			
//		}
		if(!res)
		{
			if(a[i]>ans)
			{
				flag=true;
				res=true;
				ans=a[i];
			}
			else if(a[i]<ans)
			{
				flag=false;
				res=true;
				ans=a[i];
			}
		}
		else
		{
			if(flag)
			{
				if(a[i]>=ans)
					ans=a[i];
				else
				{
					k++;
					ans=a[i];
					res=false;
				}
			}
			else
			{
				if(a[i]<=ans)
					ans=a[i];
				else
				{
					k++;
					ans=a[i];
					res=false;
				}
			}
		}
	}
	printf("%d\n",k);
	return 0;
}

Measured memory_bytes: 640
while True:
    m, f, r = map(int, input().split())
    if m == f == r== -1:
        break
    s = m + f
    if m == -1 or f == -1:
        print("F")
    elif s >= 80:
        print("A")
    elif s >= 65:
        print("B")
    elif s >= 50:
        print("C")
    elif s >= 30:
        if r >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")
    




Measured memory_bytes: 5592
n = int(input())
sum = 0
a_list = list(map(int, input().split()))
num = [0] * (10 ** 5 + 1)
for i in range(n):
    num[a_list[i]] += 1
    sum += a_list[i]

q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    sum += (c - b) * num[b]
    num[c] += num[b]
    num[b] = 0
    print(sum)

Measured memory_bytes: 21104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
typedef vector<vector<ll>> Graph;
typedef vector<pii> vpii;

int main() {
  ll N,X; cin>>N>>X;
  ll a=X,b=N-X,c=N;
  while(1) {
    if(a<b) swap(a,b);
    if(a%b==0) {
      c+=((a/b)*2-1)*b;
      cout<<c<<endl;
      return 0;
    }
    c+=(a/b)*b*2;
    a%=b;
  }
}


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

const int maxn = 1e5 + 5;

int N;
int Ans;
int A[maxn];
int F[maxn];

int main(){
        scanf("%d", &N);
        for(reg int i = 1; i <= N; i ++) scanf("%d", &A[i]);
        for(reg int i = 1; i <= N; i ++){
                F[i] = 1;
                if(i != 1 && A[i] <= A[i-1]) F[i] += F[i-1];
                Ans = std::max(Ans, F[i]);
        }
        printf("%d\n", Ans-1);
        return 0;
}


Measured memory_bytes: 1024
import itertools
import collections
import math

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

def cmb(n,r):
    if n < 0 or r < 0 or n-r < 0:
        return 0
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

sumA = list(itertools.accumulate(A))
sumA = [0]+[i % M for i in sumA] 
c = collections.Counter(sumA)
lsA = c.most_common()
ans = 0

for i in lsA:
    ans += cmb(i[1],2)

print(ans)

Measured memory_bytes: 19492
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>

using namespace std;
typedef long long ll;

const char EMPTY = '.';

int main(){
    ll h, w;
    scanf("%lld %lld\n", &h, &w);
    vector<string> map(h);
    for(int i = 0; i < h; ++i){
        getline(cin, map.at(i));
    }

    vector<vector<ll>> cemp_h(h);
    for(int i = 0; i < h; ++i){ cemp_h.at(i).resize(w); }
    for(int i = 0; i < h; ++i){
        vector<ll> cempl(w, 0);
        cempl.at(0) = (map.at(i).at(0) == EMPTY);
        for(int j = 1; j < w; ++j){
            if(map.at(i).at(j) == EMPTY){
                cempl.at(j) = cempl.at(j - 1) + 1;
            }
        }
        vector<ll> cempr(w, 0);
        cempr.at(w - 1) = (map.at(i).at(w - 1) == EMPTY);
        for(int j = w - 2; j >= 0; --j){
            if(map.at(i).at(j) == EMPTY){
                cempr.at(j) = cempr.at(j + 1) + 1;
            }
        }
        for(int j = 0; j < w; ++j){
            cemp_h.at(i).at(j) = max(0LL, cempl.at(j) + cempr.at(j) - 1);
        }
    }

    vector<vector<ll>> cemp_v(h);
    for(int i = 0; i < h; ++i){ cemp_v.at(i).resize(w); }
    for(int j = 0; j < w; ++j){
        vector<ll> cempu(h, 0);
        cempu.at(0) = (map.at(0).at(j) == EMPTY);
        for(int i = 1; i < h; ++i){
            if(map.at(i).at(j) == EMPTY){
                cempu.at(i) = cempu.at(i - 1) + 1;
            }
        }
        vector<ll> cempd(h, 0);
        cempd.at(h - 1) = (map.at(h - 1).at(j) == EMPTY);
        for(int i = h - 2; i >= 0; --i){
            if(map.at(i).at(j) == EMPTY){
                cempd.at(i) = cempd.at(i + 1) + 1;
            }
        }
        for(int i = 0; i < h; ++i){
            cemp_v.at(i).at(j) = max(0LL, cempu.at(i) + cempd.at(i) - 1);
        }
    }

    ll ans = 0;
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            ans = max(ans, cemp_h.at(i).at(j) + cemp_v.at(i).at(j) - 1);
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main()
{
    int i,j,h,w,ans = 0;
    char a;
    cin >> h >> w;
    for(i = 0; i < h; i ++)
    {
        getchar();
        for(j = 0; j < w; j ++)
        {
            cin >> a;
            if(a == '#') ans ++;
        }
    }
    if(ans == h + w - 1) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}

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

int mulp(ll a, ll b) {
    const ll p = 1000000007;
    ll ans = ((a%p) * (b%p))%p;
    return ans;
}

int main() {
    const ll p = 1000000007;
    int n,k;cin>>n>>k;
    vector<int> a(n,0);for(auto &aa:a)cin>>aa;
    ll at=0,t=0;
    for (int i=0;i<n;i++) {
        for (int j=0;j<n;j++) {
            if ((i!=j) and (a[i] > a[j])) at++;
            if ((i<j) and (a[i] > a[j])) t++;
        }
    }
    ll c,d;
    if (k%2==0) {c=k/2;d=k-1;}
    else {c=k;d=(k-1)/2;}
    cout << (mulp(mulp(c,d),at)+mulp(k,t))%p << endl;
    return 0;
}

Measured memory_bytes: 256
//Link : https://atcoder.jp/contests/agc013/tasks/agc013_b
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define N 100005

vector<int> adj[N];

int ret[N];
int pos = 0;
bool vis[N];
void dfs(int node,bool isRoot) {
  bool isEndNode = true;
  vis[node] = true;
  int cc = 1;
  ret[pos++] = node;
  if(isRoot) {
    cc = 2;
  }
  for(int i=0;i<(int)adj[node].size()&& cc>0;++i) {
    int ch = adj[node][i];
    if(vis[ch]) {
      continue;
    }
    dfs(ch,0);
    --cc;
    if(isRoot) {
      reverse(ret,ret+pos);
    }
  }
}
void solve() {
  int n,m; scanf("%d %d ", &n,&m);
  for(int i=0;i<m;++i) {
    int a,b;scanf("%d %d ", &a,&b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(1,1);
  printf("%d\n", pos);
  for(int i=0;i<pos;++i) {
    printf("%d ", ret[i]);
  }
  putchar('\n');
}
int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}


Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD=1000000007;

int main() {
    int N; cin>>N;
    int ans=0;
    vector<int> A(N+2,0);
    for(int i=1;i<=N;i++){
        cin>>A[i];
    }
    for(int i=1;i<=N+1;i++){
        ans+=abs(A[i-1]-A[i]);
    }
    for(int i=1;i<=N;i++){
        int a=ans;
        a=ans-(abs(A[i-1]-A[i])+abs(A[i]-A[i+1]))+abs(A[i-1]-A[i+1]);
        cout<<a<<endl;
    }
    return 0;
}

Measured memory_bytes: 1664
import sys
from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
 
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

n = int(ri())
s  = set([i**5 for i in range(1001)])
f,l = -1,-1
sign = 1
for i in s:
    if n+i in s:
        f = i
        l = n+i
        break
    if n-i in s:
        sign = -1
        f = i
        l = n-i
        break
print(int(pow(l,1/5)),int(sign*pow(f,1/5)))

Measured memory_bytes: 63264
#include <iostream>

using namespace std;

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

    if(a < b)
    {
        cout << "a < b" << endl;
    }
    else if(a > b)
    {
        cout << "a > b" << endl;
    }
    else
    {
        cout << "a == b"<< endl;
    }

    return 0;
}

Measured memory_bytes: 1156
from collections import deque
while 1:
    n = input()
    if n == 0:
        break
    P = map(int, raw_input().split())
    D = map(int, raw_input().split())
    U = [0]*n
    G = [[] for i in xrange(n)]
    for i in xrange(1, n):
        G[i].append((P[i-1]-1, D[i-1], i-1))
        G[P[i-1]-1].append((i, D[i-1], i-1))
    sum_D = sum(D)
    sum_path = sum_D
    for i in xrange(n):
        if len(G[i]) == 1:
            to, cost, r = G[i][0]
            if U[r] == 0:
                sum_path -= cost
                U[r] = 1
    def find(s):
        deq = deque()
        dist = [None]*n
        deq.append(s)
        dist[s] = 0
        while deq:
            v = deq.popleft()
            for t, c, r in G[v]:
                if dist[t] is None:
                    deq.append(t)
                    dist[t] = dist[v] + c
        ma = -1; result = None
        for i in xrange(n):
            if ma < dist[i] and len(G[i]) > 1:
                result = i
                ma = dist[i]
        return (result, ma)
    u = find(0)[0]
    if u is None:
        cost = 0
    else:
        v, cost = find(u)
    print sum_D + sum_path*2 - cost

Measured memory_bytes: 7120