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

int main() {
  int N, X, a, b, c, d, e, f, g, h, j;
  cin >> N;
  
  a=N/100000000;
  b=(N-a*100000000)/10000000;
  c=(N-a*100000000-b*10000000)/1000000;
  d=(N-a*100000000-b*10000000-c*1000000)/100000;
  e=(N-a*100000000-b*10000000-c*1000000-d*100000)/10000;
  f=(N-a*100000000-b*10000000-c*1000000-d*100000-e*10000)/1000;
  g=(N-a*100000000-b*10000000-c*1000000-d*100000-e*10000-f*1000)/100;
  h=(N-a*100000000-b*10000000-c*1000000-d*100000-e*10000-f*1000-g*100)/10;
  j=N-a*100000000-b*10000000-c*1000000-d*100000-e*10000-f*1000-g*100-h*10;
  
  X=a+b+c+d+e+f+g+h+j;
  
  if (N%X==0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>

#define REP(i,n) for(int i=0; i<n; i++)
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
 
#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9

using namespace std;
typedef long long ll;

int main(){
	bool furui[102];
	vector<int> primes;
	
	REP(i,102) furui[i] = true;
	furui[0] = false;
	furui[1] = false;
	for (int i=2; i<=102; i++){
		if (furui[i]){
			primes.push_back(i);
			for (int j=2; i*j<=102; j++){
				furui[i*j] = false;
			}
		}
	}
	
	const int len = primes.size();
	vector<int> countprimes(len);
	REP(i,len){
		countprimes[i] = 0;
	}
	
	int n, ans=0;
	
	cin >> n;
	
	for (int i=2; i<=n; i++){
		REP(j,len){
			if (i%primes[j]==0){
				int p = primes[j];
				for (int k=1; k<8; k++){
					if (i%(int)(pow(p,k))==0){
						countprimes[j] += 1; 
					}
				}
			}
		}
	}
	
	// REP(i,len){
	// 	cout << countprimes[i] << " ";
	// }
	// cout << endl;
	
	int x, y;
	
	// x: 4以上, y: 2以上
	REP(i,len){
		if (countprimes[i]>=2){
			y++;
			if (countprimes[i]>=4){
				x++;
			}
		}
	}
	
	if (x>=2 && y>=3){
		ans += ((x)*(x-1)/2)*(y-2);
	}
	
	// x: 24以上, y: 2以上
	x=0; y=0;
	REP(i,len){
		if (countprimes[i]>=2){
			y++;
			if (countprimes[i]>=24){
				x++;
			}
		}
	}
	
	if (x>=1 && y>=1){
		ans += x*(y-1);
	}
	// debug(ans)
	
	// x: 14以上, y: 4以上
	x=0; y=0;
	REP(i,len){
		if (countprimes[i]>=4){
			y++;
			if (countprimes[i]>=14){
				x++;
			}
		}
	}
	
	if (x>=1 && y>=1){
		ans += x*(y-1);
	}
	// debug(ans)
	
	// x: 74以上
	x=0;
	REP(i,len){
		if (countprimes[i]>=74){
			x++;
		}
	}
	
	ans += x;
		
	cout << ans << endl;
	
	return 0;
}


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

void funcB() {
  std::string s, t;
  std::cin >> s >> t;
  int diff = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != t[i]) diff++;
  }
  std::cout << diff;

}

int main(void) {
  funcB();
  return 0;
}

Measured memory_bytes: 3480
import math

n, d = map(int, input().split())

points = [0]*n
for i in range(0, n):
    points[i] = list(map(int, input().split()))

# とりあえず距離を計算
cnt = 0

for p_i in points:
    for p_j in points:
        
        # 同じ点は見ない
        if p_i == p_j:
            continue
        
        # 距離を計算
        dist = 0
        for d_i in range(0, d):
            dist += (p_i[d_i] - p_j[d_i]) * (p_i[d_i] - p_j[d_i])
        dist = math.sqrt(dist)
        
#         print("----------")
#         print(p_i)
#         print(p_j)
#         print(dist)
        
        # もし整数ならカウント
        if dist == int(dist):
            cnt += 1
        
print(int(cnt /2))                


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

int main()
{
	int N,i;
	string str;
	cin>>str>>N;
	for(i=0;i<N;i++){
		if(str.at(i)!='1'){
			break;
		}
	}
	if(i==N){
		cout<<1;
	}else{
		cout<<str.at(i);
	}
}


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

int main(){
  int n, i, j, x, bv, ans = 0;
  bool c;
  vector<int> a, b[MAXV];
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &x);
    a.push_back(x);
  }
  for(i = 0; i < n; i++){
    scanf("%d", &bv);
    for(j = 0; j < MAXV;j++) b[j].push_back(bv&((1<<j+1)-1));
  }
  for(j = 0; j < MAXV; j++){
    sort(b[j].begin(), b[j].end());
    c = false;
    for(i = 0; i < n; i++){
      x = a[i]&((1<<j+1)-1);
      vector<int>::iterator it1 = lower_bound(b[j].begin(), b[j].end(), (1<<j)-x);
      vector<int>::iterator it2 = lower_bound(b[j].begin(), b[j].end(), 2*(1<<j)-x);
      vector<int>::iterator it3 = lower_bound(b[j].begin(), b[j].end(), 3*(1<<j)-x);
      c ^= (it2 - it1 + b[j].end() - it3)&1;
    }
    if(c) ans += 1<<j;
    printf("\n");
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 32884
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] values = new int[w];
		for(int i=0; i<values.length; i++){
			values[i] = i+1;
		}
		for(int i=0; i<n; i++){
			String str = sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0])-1;
			int b = Integer.parseInt(ab[1])-1;
			int abefore=values[a];
			values[a]=values[b];
			values[b]=abefore;
		}
		for(int i=0; i<values.length; i++){
			System.out.println(values[i]);
		}
	}
}

Measured memory_bytes: 25872
dic={2:1,3:2,4:3,5:4,6:5,7:6,8:7,9:8,10:9,11:10,12:11,13:12,1:13}
a,b=map(int,input().split())
if dic[a]>dic[b]:
    print("Alice")
elif dic[a]<dic[b]:
    print("Bob")
else:
    print("Draw")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define mod 1000000007
#define bitcount __builtin_popcountll
#define ll long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define mp make_pair
int main()
{
	int i,j,k;
	int n;
	sd(n);
	int x=n;
	int temp=0;
	while(n!=0)
	{
		temp+=(n%10);
		n/=10;
	}
	printf("%s\n",x%temp==0 ? "Yes" : "No" );
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define ll long long
#define cpp boost::multiprecision::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
int mod = 1'000'000'000 + 7;
const double PI = 3.1415926535897932384626433832795;
void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}
string S;
int x[100010];
ll memo[100010][13];
ll solve (ll k, int a) {
	if (k == -1) {
		return (a == 5);
	}
	if (memo[k][a] != -1) return memo[k][a];
	ll res = 0;
	if (S[k] == '?') {
		for (int i = 0; i <= 9; i++) {
			res += solve(k-1, (a + x[k]*i) % 13);
		}
	}
	else {
		res = solve(k-1, (a + x[k]*(S[k]-'0'))%13);
	}
	res %= mod;
	return memo[k][a] = res;
}
int main() {
	COME_LET_THE_GAMES_BEGIN();
	cin >> S;
	x[S.length() - 1] = 1;
	for (int i = S.length() - 2; i >= 0; i--) {
		x[i] = x[i + 1] * 10;
		x[i] %= 13;
	}
	for (int i = 0; i < 100010; i++) for (int j = 0; j < 13; j++) memo[i][j] = -1;
	cout << solve(S.length()-1, 0) << endl;
}

Measured memory_bytes: 17232
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;

long long s[51];
long long sum = 0;
long long C[51][51]; 
void init(){
	C[1][0] = C[1][1] = 1;
	for(int i = 2;i<=50;i++){
		C[i][0] = 1;
		for(int j = 1;j<=i;j++){
			C[i][j] = C[i-1][j]+C[i-1][j-1];
		}
	}
}

int main(){
	int n,a,b;
	
	init();
	cin >> n >> a >> b;
	for(int i = 0;i < n;i++){
		cin >> s[i];
	}
	if(a>b){
		cout << "0.000000\n0";
		return 0;
	}
	sort(s,s+n);
	int i;
	for(i = n-1;i>n-1-a;i--){
		sum+=s[i];
	}
	cout << fixed << setprecision(6) << sum*1.0/a << endl;
	if(a==n){
		cout << "1" << endl;
		return 0;
	}
	if(s[n-a]>s[n-a-1]){
		cout << "1" << endl;
		return 0;
	}
	int cnts = 0,cntm = 0;
	for(int i = n-a;i < n;i++){
		if(s[i]==s[n-a]) cntm++;
	}
	for(int i = n-a-1;i>=0;i--){
		if(s[i]==s[n-a]) cnts++;
	}
	cnts+=cntm;
	long long ans = 0;
	if(s[n-a]==s[n-1]){
		for(int i = a;i<=b;i++){
			if(i<=cnts) ans+=C[cnts][i];
			else break;
		}
	}
	else{
		ans+=C[cnts][cntm];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int n,i,r=0;
	int p[51];
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&p[i]);
		if(p[i]!=i){
			r++;
		}
	}
	printf(r==0||r==2?"YES":"NO");
	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


void solve(){
    int a,b;
    cin >> a >> b;
    if(a>b) cout << a-1 << endl;
    else cout << a << endl;
}

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


Measured memory_bytes: 256
import sys

n, m = map(int, sys.stdin.readline().split())
ab = map(int, sys.stdin.read().split())
ab = zip(*[ab] * 2)
graph = [[] for _ in range(n)]
for a, b in ab:
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

def main():

    cnt = 0
    stack = [(0, set())]
    while stack:
        v, visited = stack.pop()
        visited.add(v)
        if len(visited) == n: 
            cnt += 1
            continue
        for u in graph[v]:
            if u in visited:
                continue
            stack.append((u, visited.copy()))

    return cnt

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 200010
ll cnt[10][10];
int main(){
    rep(i,10)rep(j,10)cnt[i][j]=0;
    ll n; cin>>n;
    for(int i=1;i<=n;i++){
	ll x=i;
	ll a=x%10;
	while(x>=10){
	    x/=10;
	}
	ll b=x;
	cnt[a][b]++;
    }
    ll ans=0;
    rep(i,10)rep(j,10){
	ans+=cnt[i][j]*cnt[j][i];
    }
    cout<<ans<<endl;
}




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

using namespace std;
int main(){
    string S;
    string dream[5],dreamer[7],erase[5],eraser[6];
    dream[0]='m';dream[1]='a';dream[2]='e';dream[3]='r';dream[4]='d';
    dreamer[0]='r';dreamer[1]='e';dreamer[2]='m';dreamer[3]='a';dreamer[4]='e';dreamer[5]='r';dreamer[6]='d';
    erase[0]='e';erase[1]='s';erase[2]='a';erase[3]='r';erase[4]='e';
    eraser[0]='r';eraser[1]='e';eraser[2]='s';eraser[3]='a';eraser[4]='r';eraser[5]='e';
    cin >> S;
    reverse(S.begin(), S.end());
    int i=0;
    bool flag;
    while (i<=S.size()){
        if('m' == S[i] && 'a' == S[i+1] && 'e' == S[i+2] && 'r' == S[i+3] && 'd' == S[i+4]) i+=5;
        else if('r' == S[i] && 'e' == S[i+1]  && 'm' == S[i+2] && 'a' == S[i+3] && 'e' == S[i+4] && 'r' == S[i+5] && 'd' == S[i+6]) i+=7;
        else if('e' == S[i] && 's' == S[i+1] && 'a' == S[i+2] && 'r' == S[i+3] && 'e' == S[i+4]) i+=5;
        else if('r' == S[i] && 'e' == S[i+1] && 's' == S[i+2] && 'a' == S[i+3] && 'r' == S[i+4] && 'e' == S[i+5]) i+=6;
        else if(i==S.size()) {
            flag = true;
            break;
        }
        else{
            flag = false;
            break;
        }
    }
    if(flag) cout << "YES" << "\n";
    else cout << "NO" << "\n";
    return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;

namespace AtCoderTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Read());

            if (n % 1000 != 0)
                Console.WriteLine(1000 - n % 1000);
            else
                Console.WriteLine(0);
        }


        private static string Read() => Console.ReadLine();
        private static List<string> SplitRead(char delimiter = ' ')
        {
            var splitWord = new List<string>();
            var start = 0;
            var str = Console.ReadLine();

            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == delimiter)
                {
                    splitWord.Add(str[start..i]);
                    start = i + 1;
                }
            }
            return splitWord;
        }
    }
}


Measured memory_bytes: 17384
#include<iostream>
#include<cctype>
#include<cstring>
using namespace std;

string toUpper(string s){
    string t = s;
    for(int i = 0; i < s.size(); i++){
        t[i] = toupper(s[i]);
    }
    return t;
}

int main(){
    string target, source;
    cin >> target;
    target = toUpper(target);
    int count = 0;
    
    while(1){
        cin >> source;
        if(source == "END_OF_TEXT") break;
        source = toUpper(source);
        if(target == source) count += 1;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <stack>

int main(){
    using namespace std;

    int count = 0;
    cin >> count;

    stack<int> numberStack;
    for( int i = count; i > 0; --i ){
        int num = 0;
        cin >> num;
        numberStack.push( num );
    }

    while( numberStack.size() != 0 ){
        int num = numberStack.top();
        numberStack.pop();
        cout << num;
        if( numberStack.size() == 0 ){ break; }
        cout << " ";
    }

    cout << endl;
   
    return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
const int N=1e3+5;
int n,k,a[N],i,j,xb,z;
long long b[N*N/2],ans,s,x;
int main(){
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;++i)scanf("%d",a+i);
	for(i=1;i<=n;++i)for(j=i,s=0;j<=n;++j)b[++xb]=s+=a[j];
	for(i=60;i>=0;--i){
		z=0;x=ans|(1ll<<i);
		for(j=1;j<=xb;++j)if((b[j]&x)==x)++z;
		if(z>=k)ans=x;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4224
// g++ -std=gnu++1y -O2 main.cpp

#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <string>
#include <utility>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <climits>

using namespace std;

template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (b < a)
	{
		a = b;
		return 1;
	}
	return 0;
}

int main()
{
	int N;
	string S;
	int Q;

	cin >> N;
	cin >> S;
	cin >> Q;

	vector<set<int>> table('z' - 'a' + 1);

	for (int i = 0; i < S.size(); i++)
	{
		table[S[i] - 'a'].insert(i);
	}

	for (int i = 0; i < Q; i++)
	{
		int q;
		cin >> q;
		if (q == 1)
		{
			int iq;
			char cq;
			cin >> iq >> cq;
			char c = S[iq - 1];
			table[c - 'a'].erase(iq - 1);
			table[cq - 'a'].insert(iq - 1);
			S[iq - 1] = cq;
		}
		else
		{
			int lq, rq;
			cin >> lq >> rq;

			int count = 0;
			// cout << S << endl;
			for (int j = 0; j <= 'z' - 'a'; j++)
			{
				// cout << static_cast<char>('a' + j) << ": ";
				// for (set<int>::iterator itr = table[j].begin(); itr != table[j].end(); itr++)
				// {
				// 	cout << (*itr) << ' ';
				// }
				// cout << endl;

				set<int>::iterator itr = table[j].lower_bound(lq - 1);
				if (itr != table[j].end()) 
				{
					// cout << static_cast<char>('a' + j) << *itr << endl;
					if (*itr <= rq - 1)
						count++;
				}
			}
			cout << count << endl;
		}
	}
}

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

using namespace std;
#define int long long
typedef pair <int, int> ii;

const int N = 705;
int n, m, mark[N];
bool mat[N][N], dp[N][N];

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

	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		for (int j = i + 1; j <= n; ++j)
			mat[i][j] = mat[j][i] = 1;
	}
	for (int i = 1; i <= m; ++i) {
		int u, v;
		cin >> u >> v;
		mat[u][v] = mat[v][u] = 0;
	}
	// for (int i = 1; i <= n; ++i) {
	// 	for (int j = i + 1; j <= n; ++j) if (mat[i][j])
	// 		cerr << i << ' ' << j << endl;
	// }
	vector <ii> comp; comp.clear();
	int cc = 0; comp.push_back({0, 0});
	for (int i = 1; i <= n; ++i) if (!mark[i]) {
		queue <int> q; ++cc;
		while (!q.empty()) q.pop();
		q.push(i);
		mark[i] = 1;
		vector <int> V; V.clear();
		while (!q.empty()) {
			int u = q.front(); q.pop();
			V.push_back(u);
			for (int v = 1; v <= n; ++v) if (mat[u][v]) {
				if (!mark[v]) {
					q.push(v);
					mark[v] = ((mark[u] - 1) ^ 1) + 1;
				} else {
					if (mark[v] != ((mark[u] - 1) ^ 1) + 1) {
						cerr << v << endl;
						cout << -1 << endl;
						return 0;
					}
				}
			}
		}
		int p1, p2; p1 = p2 = 0;
		for (int u : V) {
			if (mark[u] == 1) p1++;
			else if (mark[u] == 2) p2++;
		}
		comp.push_back({p1, p2});
	}
	dp[0][0] = 1;
	for (int i = 1; i <= cc; ++i) {
		for (int j = 0; j <= n; ++j) if (dp[i - 1][j]) {
			dp[i][j + comp[i].first] = dp[i][j + comp[i].second] = 1;
		}
	}
	int res = (int)1e9;
	for (int i = 1; i <= n; ++i) if (dp[cc][i]) {
		res = min(res, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
lli mod=1000000007;

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    set<string>s;
    lli n;
    cin>>n;
    for(lli i=0;i<n;++i){
    	string str;
    	cin>>str;
    	s.insert(str);
    }
    cout<<s.size()<<endl;
}

Measured memory_bytes: 19124
#include <stdio.h>

int main(void){

    int X, X2, sum = 0;

    scanf("%d", &X);
    X2 = X;

    while(X > 0){
        sum += X % 10;
        X /= 10;
    }

    if(X2 % sum == 0){
        puts("Yes");
    } else { puts("No"); }

    return 0;
}

Measured memory_bytes: 128
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,k = iim()
l = [True]*n
for i in range(k):
    d = ii()
    A = iil()
    for item in A:
        if l[item-1] == True:
            l[item-1] = False

print(l.count(True))

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int> d(N);
  for(int i=0; i<N; i++) {
    cin >> d.at(i);
  }
  

  int res = 0;
    for(int i=0; i<N; i++) {
        for(int j=i; j<N; j++) {
          if(i != j) res += d.at(i)*d.at(j);
        }
    }
  
  cout << res << endl;

}

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

#define ll long long 

ll dp[401][401];

ll prefix[401];

ll v[401];

ll solve( int i, int j){

    if(i>=j){
        return 0;

    }
    
  

    if(dp[i][j]!=-1){
        return dp[i][j];

    }


    ll ans=LLONG_MAX;
    ll s;
     if(i>0){
        s=prefix[j]-prefix[i-1];

    }else{
        s=prefix[j];

    }

    for(int k=i;k<j;k++){

        ll left;
        ll right;
        if(dp[i][k]!=-1){
            left=dp[i][k];

        }else{
            left=solve(i,k);
            dp[i][k]=left;

        }

        if(dp[k+1][j]!=-1){
            right=dp[k+1][j];
            
        }else{
            right=solve(k+1,j);
            dp[k+1][j]=right;

        }


        ll temp=s+left+right;

        ans=min(ans,temp);

    }


    return dp[i][j]=ans;



}

int main(){
    
   int n;
   cin>>n;
   
   
   memset(dp,-1,sizeof(dp));

   

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

   prefix[0]=v[0];

   for(int i=1;i<n;i++){
       prefix[i]=prefix[i-1]+v[i];

   }
 


   cout<<solve(0,n-1);



}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int a[n];
	std::map<int, int> count;
	for (auto &i : a) i = ri(), count[i]++;
	int64_t all = 0;
	for (auto i : count) all += (int64_t) (i.second - 1) * i.second / 2;
	for (auto i : a) {
		int64_t res = all;
		res -= (int64_t) (count[i] - 1) * count[i] / 2;
		res += (int64_t) (count[i] - 2) * (count[i] - 1) / 2;
		printf("%" PRId64 "\n", res);
	}
	return 0;
}


Measured memory_bytes: 8320
#include<stdio.h>

int main(){
  int A[100];
  int N,key,i,j,k;

  scanf("%d", &N);
  for(i = 0 ; i < N ; i ++){
    scanf("%d", &A[i]);
  }
  
  for( i = 0 ; i < N ; i ++){
    key = A[i];
    j = i-1;
    while(j >= 0 && A[j] > key){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;
    
    for(k = 0 ; k < N ; k++){
      printf("%d", A[k]);
      if( k == N-1){
	printf("\n");
	break;
      }
      printf(" ");
    }
  }
  return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 

int islands_war(int n, vector<int> a, vector<int> b) {
  int m = a.size();

  vector<pair<int, int>> ab;

  for (int i=0;i<m;i++) {
    ab.push_back(make_pair(a[i], b[i]));
  }
  sort(ab.begin(), ab.end(), sortbysec);
  
  int ans = 1;
  int cut = ab[0].second -1;
  //cout << "cut:" <<  cut << " m: " << m  << endl;
  for(int i=1;i<m;i++) {
    // cout << "(" << ab[i].first << ", " << ab[i].second << ")" << endl;
    if(ab[i].first<=cut) {
      continue;
    }
    // ab[i] > cut;
    ans++;
    cut = ab[i].second-1;
    // cout << "==>" << cut << endl;
  }
  
  return ans;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a, b;
  for(int i=0;i<m;i++) {
    int aa, bb;
    cin >> aa >> bb;
    a.push_back(aa);
    b.push_back(bb);
  }
  cout << islands_war(n, a, b);
}


Measured memory_bytes: 2932
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7; constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int N;
vi A;

int main() {
    cin >> N;
    A.resize(N);
    rep(i, N) cin >> A[i];

    int abs_max = 0;
    int i_absmax = 0;
    rep(i, N) {
        if (abs(A[i]) > abs_max) {
            abs_max = abs(A[i]);
            i_absmax = i;
        }
    }

    vector<pair<int, int>> ans;
    if (A[i_absmax] > 0) {
        ans.emplace_back(i_absmax + 1, 1);
        ans.emplace_back(i_absmax + 1, 1);

        rep(i, 1, N) {
            if (A[i] >= 0) {
                ans.emplace_back(i, i + 1);
            }
            else {
                ans.emplace_back(i, i + 1);
                ans.emplace_back(i, i + 1);
            }
        }
    }
    else if (A[i_absmax] < 0) {
        ans.emplace_back(i_absmax + 1, N);
        ans.emplace_back(i_absmax + 1, N);

        for (int i = N - 2; i >= 0; --i) {
            if (A[i] <= 0) {
                ans.emplace_back(i + 2, i + 1);
            }
            else {
                ans.emplace_back(i + 2, i + 1);
                ans.emplace_back(i + 2, i + 1);
            }
        }
    }

    write(ans.size());
    rep(i, ans.size()) {
        cout << ans[i].first << " " << ans[i].second << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI=3.14159265358979323846;

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main() {
    long long N, M;
    cin >> N >> M;

    vector<pair<int, int>> edges(M);
    for (int i = 0; i < M; i++) {
        cin >> edges[i].first >> edges[i].second;
        --(edges[i].first);
        --(edges[i].second);
    }

    UnionFind uf(N);

    vector<long long> ans(M);
    ans[M - 1] = N * (N - 1) / 2;
    for (int i = M - 1; i >= 1; i--) {
        const pair<int, int>& e = edges[i];
        if (uf.same(e.first, e.second)) {
            ans[i - 1] = ans[i];
        } else {
            ans[i - 1] = ans[i] - static_cast<long long>(uf.size(e.first)) * static_cast<long long>(uf.size(e.second));
        }
        uf.unite(e.first, e.second);
    }

    for (int i = 0; i < M; i++) {
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3328
import java.io.*;

class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
int count;
char[][] map;
while(true){
map=new char[12][12];
for(int i=0;i<12;i++){
line=br.readLine();
for(int j=0;j<12;j++){
map[i][j]=line.charAt(j);
}
}
count=0;
for(int i=0;i<12;i++){
for(int j=0;j<12;j++){
if(map[i][j]=='1'){
dfs(i,j,map);
count++;
}
}
}
System.out.println(count);
line=br.readLine();
if(line==null){
break;
}
else{
continue;
}
}
}
private static void dfs(int x,int y,char[][] map){
int nx,ny;
map[x][y]='0';
int[] dx={-1,0,1,0};
int[] dy={0,-1,0,1};
for(int i=0;i<4;i++){
nx=x+dx[i];
ny=y+dy[i];
if(nx>=0&&nx<12&&ny>=0&&ny<12&&map[nx][ny]=='1'){
dfs(nx,ny,map);
}
}
return;
}
}

Measured memory_bytes: 16896
N = int(input())


def extract_first(i):
    return str(i)[0]

def extract_last(i):
    return str(i)[-1]

def get_key(first, last):
    return "{}-{}".format(first, last)

combi_map = {}
for i in range(0, 10):
    for j in range(0,10):
        combi_map[get_key(i, j)] = 0


for i in range(1, N+1):
    first = extract_first(i)
    last = extract_last(i)
    combi_map[get_key(first, last)] += 1

ans = 0
for i in range(1, 10):
    for j in range(i, 10):
        if i == j:
            ans += combi_map[get_key(i, j)] * combi_map[get_key(j, i)]
        else:
            ans += combi_map[get_key(i, j)] * combi_map[get_key(j, i)] * 2
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>

#define sp ' '
#define endl '\n'
#define Endl '\n'
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define FOR(YY, yy) for(int yy = 0; yy < YY; ++yy)

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector< pair<int, int> > vii;
typedef vector< pair< int, pair<int, int> > > vpip;
typedef pair<int, int> ii;

const int MOD = 1e9 + 7;
const int INF = 2e9;

const int N = 10e6;

vi lp(N+1, 0);
vi pr;

void sieve(void)
{
    for(int i = 2; i <= N; ++i)
    {
        if(lp[i] == 0)
        {
            lp[i] = i;
            pr.pb(i);
        }
        for(int j = 0; j < (int)pr.size() and pr[j] <= lp[i] and i*pr[j] <= N; ++j)
            lp[i*pr[j]] = pr[j];
    }
    return;
}

int main(int argc, char **argv)
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    //sieve();

    ull n; cin >> n;

    ull sq = sqrtl(n);
    if(sq*sq == n){ cout << 2*(sq-1); return 0; }

    for(ull i = sq; i >= 1; --i)
    {
        if(n % i == 0){ cout << (i-1) + (n/i-1) << endl; return 0; }
    }

    return 0;
}

//cikisir



Measured memory_bytes: 39296
// #define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using V = vector<int>;
using VV = vector<V>;

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 A = (1<<2) | (1<<3) | (1<<5) | (1<<7);
//~ for (int bit=A; ; bit=(bit-1)&A){
//~ if (!bit) break;
//~ }
int next_combination(int sub) {
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}
//~ int n=5;
//~ int k=3; // nCkの組み合わせ、ただしk=0には対応してない
//~ int bit=(1<<k)-1; // 1000 -> 0111
//~ for(; bit < (1<<n); bit=nex_combination(bit){
//~ }
bool isPrime(int a) {
    if (a == 2) return true;
    if (a <= 1 || a % 2 == 0) return false;

    for (int i = 3; i * i <= a; i += 2) {
        if (a % i == 0) return false;
    }
    return true;
}
//~ vector<int> a = {1, 14, 32, 51, 51, 51, 243, 419, 750, 910};
vector<int> aaa;
// index が条件を満たすかどうか
bool isOK(int index, int key) {
    if (aaa[index] >= key)
        return true;
    else
        return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
    int ng = -1;  //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok =
        (int)aaa
            .size();  // 「index =
                      // a.size()-1」が条件を満たさないこともあるので、初期値は
                      // a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key))
            ok = mid;
        else
            ng = mid;
    }
    return ok;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//~ int v[100100];
//~ int INF = 1 << 30;
//~ vector<vector<int>> dp(310, vector<int>(310));
//~ ll dp[110][100100];
//~ vector<int> dp(100100, 0));

//~ int seen[110];
//~ int ans[110][2];
//~ ll MOD = 1e9 + 7;

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

    vector<int> a(n + 1);
    rep2(i, 1, n + 1) { cin >> a[i]; }

    int ans = 0;
    int cnt = 0;
    int p;

    stack<int> st;
    st.push(1);
    while (!st.empty()) {
        p = st.top();
        st.pop();
        ans++;
        cnt++;
        if (a[p] == 2) break;
        if (cnt > n) break;

        st.push(a[p]);
    }

    if (a[p] == 2)
        cout << ans << endl;
    else
        cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 3744
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::pair<double, double> pdd;
using namespace std;


#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loope(i,a,b) for(ll i=a;i<=b;i++)
#define test() ull testcase;cin>>testcase;while(testcase--)
#define pb push_back
#define mp make_pair
#define nl cout<<"\n"
#define prime 1000000007
#define debug(x) cout<<(#x)<<" : "<<x,nl
#define debug2(x,y) cout<<(#x)<<" : "<<x<<" "<<(#y)<<" : "<<y,nl
#define debug3(x,y,z) cout<<(#x)<<" : "<<x<<" "<<(#y)<<" : "<<y<<" "<<(#z)<<" : "<<z,nl
#define f first
#define s second
#define oa(a,n) loop(i,0,n)cout<<a[i]<<" ";nl;
#define ov(a) loop(i,0,a.size()) cout<<a[i]<<" ";nl;
#define MOD(a) (((a%prime)+prime)%prime)


int main()
{

    vector <pair <string,ll> > v;
    map <ll,ll> m;

    ll n,i;

    cin >> n;

    loop(i,1,n+1)
    {
        string s;
        ll u;
        cin >> s >> u;
        v.pb(mp(s,u));
        m[u] = i;
    }


    sort(v.begin(),v.end());

    string s1 = v[0].first;

    vector <ll> v1;

    // loop(i,0,v.size())
    //     cout << v[i].first << " " << v[i].second << endl;

    loop(i,0,n)
    {
        if(s1==v[i].first)
        {
            v1.pb(v[i].second);
            //cout << s1 << " " << m[v[i].second] << endl;
        }
        else
        {
            sort(v1.begin(),v1.end(),greater<ll>());
            for(ll j=0;j<v1.size();j++)
                cout << m[v1[j]] << endl;
            v1.clear();   
            v1.pb(v[i].second);
            s1=v[i].first;
        }
    }
    sort(v1.begin(),v1.end(),greater<ll>());
    for(ll j=0;j<v1.size();j++)
        cout << m[v1[j]] << endl;
}

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

int main(){
    string a,b;
    getline(cin, a);
    for(int i=0;i<a.size();i++){
        if(islower(a[i])){
            b += toupper(a[i]);
        }
        else if(isupper(a[i])){
            b += tolower(a[i]);
        }
        else{
            b += a[i];
        }
    }
    cout<<b<<endl;
    return 0;
}

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

//降順
int des(const void *a, const void *b)
{
  return *(long *)b - *(long *)a;
}

int main() {
  int N, W;
  cin >> N >> W;
  long vl[4][N], w_s, w, v, csum[4][N+1], ans = 0, sumv = 0, sumw = 0;
  int cnt[4] = {1, 0, 0, 0};
  cin >> w_s >> vl[0][0];
  for (int i=1; i<N; i++) {
    cin >> w >> v;
    vl[w-w_s][cnt[w-w_s]] = v;
    cnt[w-w_s]++;
  }
  for (int i=0; i<4; i++) {
    if (cnt[i] == 0)
      continue;
    qsort(vl[i], cnt[i], sizeof(long), des);
  }
  for (int i=0; i<4; i++) {
    csum[i][0] = 0;
    for (int j=0; j<cnt[i]; j++)
      csum[i][j+1] = csum[i][j] + vl[i][j];
  }
  for (int i0=0; i0<=cnt[0]; i0++) {
    sumv = 0;
    for (int i1=0; i1<=cnt[1]; i1++) {
      for (int i2=0; i2<=cnt[2]; i2++) {
        for (int i3=0; i3<=cnt[3]; i3++) {
          sumw = w_s*i0 + (w_s+1)*i1 + (w_s+2)*i2 + (w_s+3)*i3;
          if (sumw > W)
            break;
          sumv = csum[0][i0] + csum[1][i1] + csum[2][i2] + csum[3][i3];
          ans = max(ans, sumv);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define sz(a) ((int)a.size())
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define forse(i,s,e) for(int i=(int)s;i<(int)e;i++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

using dbl=double;
using ll=long long;
using pii=pair<int, int>;
using pll=pair<ll, ll>;

dbl PI=3.141592653589793;


void solve(){
	int n,m;ll k;
	cin >> n >> m >> k;
	vector<ll> a(n),b(m);
	forn(i,n) cin >> a[n-1-i];
	forn(i,m) cin >> b[m-1-i];
	for(int i=n-1;i>0;i--) a[i-1]+=a[i];
	for(int i=m-1;i>0;i--) b[i-1]+=b[i];
	int i=n-1,j=0,out=0;
	for(int i=m-1;i>=0;i--) if(b[i]<=k) out=m-i;
	for(;i>=0;i--){
		ll tem=k-a[i];
		if(tem<0) break;
		while(j<m&&b[j]>tem) j++;
		out=max(out,n-i+m-j);
	}
	cout << out;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); 
	int T=1;
//	cin >> T;
	for(int c=1;c<=T;c++){
		solve();
	}
}


Measured memory_bytes: 6364
#include <cstdio>
#include <vector>
#define pb push_back
long long ans;
int mx[200005], sec[200005], sz[200005], mn[200005];
std::vector<int> adj[200005];
char col[200005];
void init(int u, int fa = -1)
{
	mn[u] = 1e9;
	if (col[u] == '1')
	{
		mn[u] = 0;
		sz[u] = 1;
	}
	for (int v : adj[u])
	{
		if (v == fa)
			continue;
		init(v, u);
		if (mx[v] + 1 > mx[u])
		{
			sec[u] = mx[u];
			mx[u] = mx[v] + 1;
		}
		else if (mx[v] + 1 > sec[u])
			sec[u] = mx[v] + 1;
		if (sz[v])
			mn[u] = std::min(mn[u], mx[v] + 1);
		sz[u] += sz[v];
	}
}
void calc(int u, int fa = -1)
{
	if (~fa)
	{
		int x = mx[fa] == mx[u] + 1 ? sec[fa] : mx[fa];
		if (x + 1 > mx[u])
		{
			sec[u] = mx[u];
			mx[u] = x + 1;
		}
		else if (x + 1 > sec[u])
			sec[u] = x + 1;
		if (sz[u] != sz[0])
			mn[u] = std::min(mn[u], x + 1);
	}
	for (int v : adj[u])
	{
		if (v != fa)
			calc(v, u);
	}
	ans += std::max(0, std::min(sec[u] + 1, mx[u] - 1) - mn[u] + 1);
}
int main()
{
	// freopen("AGC008-F.in", "r", stdin);
	int n;
	scanf("%d", &n);
	for (int i = 1; i < n; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		adj[--u].pb(--v);
		adj[v].pb(u);
	}
	scanf("%s", col);
	init(0);
	calc(0);
	printf("%lld\n", ans + 1);
	return 0;
}


Measured memory_bytes: 24064
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    long long x, y;
    cin >> x >> y;

    if(abs(x - y) <= 1)
        cout << "Brown" << endl;
    else
        cout << "Alice" << endl;

    return 0;
}


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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

int main(void)
{
    double l;
    cin >> l;
    
    l /= 3.0;
    printf("%.10f\n", l*l*l);
    return 0;
    
}
/** tcoder **/


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

int main(){
    string s;
    cin >> s;
    int cnt = 0, cnts = 0, maxcnt = 0;
    for(int i=0; i<s.size(); i++){
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
            cnt++;
        }else{
            if(maxcnt < cnt) maxcnt = cnt;
            cnt = 0;
        }
    }

    if(maxcnt > cnt) cout << maxcnt << endl;
    else cout << cnt << endl; 
}

Measured memory_bytes: 256
n=int(input())

dic=dict()
for i in range(n):
  s=input()
  if s not in dic:
    dic[s]=1
  else:
    dic[s]+=1
a=(max(dic, key=dic.get))
b=dic[a]
keys = [k for k, v in dic.items() if v == b]
keys.sort()

for i in range(len(keys)):
  print(keys[i])

Measured memory_bytes: 32096
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  string s;
  cin>>s;
  long long num = 0;
  int n = s.size();
  REP(i, n) num += s[i] - '0';
  if(num % 9 == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
 
int main() {
  long long A,B,C,D;
    cin >> A >> B >> C >> D;
  long long g = __gcd(C,D);
  long long l = C*D/g;
  long long s_C = (A-1)/C;
  long long n_C = B/C;//ほんまか？
    long long ans1 = n_C - s_C;//2
  long long s_D = (A-1)/D;
  long long n_D = B/D;//ほんまか？
    long long ans2 = n_D - s_D;//2
  long long s_l = (A-1)/l;
  long long n_l = B/l;//ほんまか？
    long long ans3 = n_l - s_l;//2
  cout << B-A+1-(ans1+ans2-ans3) << endl;
}
  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  int x;
  cin >> x;
  if(x>=30) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3644
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;

public class Main {
  public static void main(String[] args) throws IOException{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    String[] a_str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int m = Integer.parseInt(str[1]);
    Integer[] a = new Integer[n];
    int sum = 0;

    for(int i = 0; i < n; i++) {
      a[i] = Integer.parseInt(a_str[i]);
      sum += a[i];
    }
    
    Arrays.sort(a, Comparator.reverseOrder());
    System.out.println(a[m-1] * 4 * m >= sum?"Yes":"No");
  }
}

Measured memory_bytes: 32612
#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)
typedef long long ll;
#define MAX 10e10
int main(){

	int n;
	cin >> n;

	ll sum = 0;
	int minus = 0;
	// 絶対値最小
	ll mi = MAX;
	rep(i,n) {
		ll a;
		cin >> a;
		if (a<0) {
			minus++;
		}
		a = abs(a);
		mi = min(mi, a);
		sum += a;
	}

	if (minus%2) {
		sum -= mi*2;
	}

	cout << sum << endl;
}


Measured memory_bytes: 256
import math

def lcm(c,d): return c*d // math.gcd(c,d)

a, b, c, d = map(int, input().split())

q11 = (a-1)//c
q12 = (a-1)//d

q21 = b//c
q22 = b//d

q3 = (a-1)//lcm(c,d)
q4 = b//lcm(c,d)
print(b-(a-1) - (q21-q11) - (q22-q12) + (q4-q3))

Measured memory_bytes: 9212
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using itn = int;

int main(void){
    int n,k;
    cin >> n >> k;
    
    long long p[n],c[n];
    for(int i = 0;i < n;i++)cin >> p[i];
    for(int i = 0;i < n;i++)cin >> c[i];
    
    for(int i = 0;i < n;i++)p[i]--;
    
    long long ans = -1e18;
    if(k <= 4*n){
        for(int i = 0;i < n;i++){
            int now = p[i];
            long long score = 0;
            
            for(int j = 0;j < k;j++){
                now = p[now];
                score += c[now];
                ans = max(ans,score);
            }
        }
    } else {
        for(int i = 0;i < n;i++){
            int now = p[i],syuuki = 0,memo = now;
            long long score = 0;
            
            for(int j = 0;j < 2*n;j++){
                if(j > 0 && memo == now)break;
                now = p[now];
                score += c[now];
                ans = max(ans,score);
                syuuki++;
            }
            
            score = score * ((k / syuuki) - 1);
            now = p[i];
            ans = max(ans,score);
            long long score2 = 0;
            
            for(int j = 0;j < (k % syuuki) + syuuki;j++){
                now = p[now];
                score2 += c[now];
                ans = max(ans,score + score2);
            }
        }
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll A[200100];
ll B[200100];
int main(){
    int N;
    cin >> N;
    REP(i,N){
        ll a;
        cin >> a;
        A[i] = a;
    }
    REP(i,N){
        ll b;
        cin >> b;
        B[i] = b;
    }


    vector<ll> tmpA(N);
    vector<ll> tmpB(N);
    ll ans = 0;
    for(int k = 0; k < 30; k++){
        ll T = 1 << k;
        for(int i = 0; i < N; i++){
            tmpA[i] = A[i] & (2*T-1);
            tmpB[i] = B[i] & (2*T-1);
        }
        sort(tmpB.begin(), tmpB.end());

        ll num = 0;
        for(int i = 0; i < N; i++){
            ll a = tmpA[i];
            num += lower_bound(tmpB.begin(), tmpB.end(), 2*T-a) - lower_bound(tmpB.begin(), tmpB.end(), T-a);
            num += lower_bound(tmpB.begin(), tmpB.end(), 4*T-a) - lower_bound(tmpB.begin(), tmpB.end(), 3*T-a);
        }

        if(num%2){
            ans += T;
        }
    }

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


Measured memory_bytes: 6528
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define chmax(x,y) x = max(x,y)

 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
typedef vector<LL> VL;
typedef vector<vector<long long>> VVLL;
const int MOD = 1e9+7;
const int INF = 1e9;
const LL LINF = 1e18;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}

int main() {
    LL x;
    cin >> x;
    LL ans = 0;
    ans = (x/500) * 1000;
    // cout << ans << endl;
    x %= 500;
    ans += (x/5) * 5;
    // cout << (x/5) * 5 << endl;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    char s[n+1],t[n+1];
    cin>>s>>t;
    for(int i=0;i<n;i++)
        cout<<s[i]<<t[i];
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
ll llmax = LLONG_MAX;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}
void sorti(vi &a) {sort(a.begin(), a.end());}
void sortll(vll &a) {sort(a.begin(), a.end());}
void sorts(vs &a) {sort(a.begin(), a.end());}

int main() {
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;
  if (s == u) cout << a - 1 << " " << b << endl;
  else cout << a << " " << b - 1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long n,m;
    cin >> n >> m;
    long x[n];
    long y[n];
    long z[n];

    long ans = 0;

    for(int i=0;i<n;i++)cin >> x[i] >> y[i] >> z[i];
    for(int k=0;k<8;k++){
        long xsig = 1;
        long ysig = 1;
        long zsig = 1;
        if(k&1)xsig=-1;
        if(k&2)ysig = -1;
        if(k&4)zsig = -1;

        vector<vector<long> >dp(n+1,vector<long>(m+1,-999999999999999));
        for(int i=0;i<=n;i++)dp[i][0] = 0;

        for(long i=0;i<n;i++){
            long tmp = x[i]*xsig + y[i]*ysig + z[i]*zsig;
            for(int j=0;j<min(m,i+1);j++){
                dp[i+1][j+1] = max(dp[i][j+1],dp[i][j]+tmp);
            }
        }
        ans = max(ans,dp[n][m]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 11212
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < b; i++)
typedef long long ll;
typedef pair<int,int> pii;

const ll MOD = 1e9 + 7;

int main(){
    ll N; cin >> N;
    vector<ll> A(N);
    ll mp[3] = {0};
    ll ans = 1;
    rep(i, 0, N) cin >> A[i];

    rep(i, 0, N){
        int cnt = 0;
        rep(j, 0, 3){
            if(mp[j] == A[i]) cnt++;
        }
        ans = (ans * cnt ) % MOD;
        rep(j,0,3){
            if(mp[j] == A[i]){
                mp[j]++;
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024