akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static Scanner sc = new Scanner(System.in);
	//A
	/*
	public static void main(String[] args){
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();

		if((Math.abs(b - a )<=d && Math.abs(c-b)<= d)||Math.abs(c-a) <= d)
			System.out.println("Yes");
		else
			System.out.println("No");
	}*/

	//B
	public static void main(String[] args){
		int X = sc.nextInt();
		int i = 2;
		int ans = 0;
		if(X == 1){
			System.out.println("1");
		}else{
			while(i*i <= X){
				int tmp = i*i;
				while(tmp <= X){
					tmp*=i;
				}
				tmp /= i;
				if(tmp > ans)
				ans = tmp;
				i++;
			}
			System.out.println(ans);
		}
	}

}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    string str;
    cin >> n >> str;

    for (int i = 0; i < str.size(); i++) {
        int slide = (str[i] - 'A' + n) % 26;
        putchar('A' + slide);
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
    int X, Y;
    double x, y;

    scanf("%d %d",&X,&Y);
    x=2*X-0.5*Y;
    y=-X+0.5*Y;

    if(x<0||y<0||ceil(x)!=floor(x)){
      printf("No");
    }else{
      printf("Yes");
    }

return 0;
}

Measured memory_bytes: 2172
S = str(input())
S_len = len(S)

A = ('01' * 10**5)[:S_len]
B = ('10' * 10**5)[:S_len]
#print(B)

result_A = sum([a == s for a, s in zip(A, S)])
result_B = sum([b == s for b, s in zip(B, S)])
print(min([result_A, result_B]))


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

using namespace std;

int main()
{
    int t,c1=0,c2=0,c3=0,c4=0;
    cin>>t;
     while(t--)
      {string s;
       cin>>s;
       if(s=="AC")
        {c1++;
        }
       else if(s=="WA")
        {c2++;
        }
       else if(s=="TLE")
        {c3++;
        }
       else
        {c4++;
        }
      }
      cout<<"AC"<<" "<<"x"<<" "<<c1<<endl;
      cout<<"WA"<<" "<<"x"<<" "<<c2<<endl;
      cout<<"TLE"<<" "<<"x"<<" "<<c3<<endl;
      cout<<"RE"<<" "<<"x"<<" "<<c4<<endl;

    return 0;
}


Measured memory_bytes: 3632
N = int(input())
points = [tuple(map(int, input().split())) for i in range(N)]
points = [(0,0,0)] + points
for idx in range(1,N + 1):
  time_diff = points[idx][0] - points[idx-1][0]
  x_diff = abs(points[idx][1] - points[idx-1][1])
  y_diff = abs(points[idx][2] - points[idx-1][2])
  
  if (time_diff < x_diff + y_diff) or (time_diff - x_diff - y_diff) % 2 == 1:
    print('No')
    exit()
    
print('Yes')

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

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

int main() {
    int n,x;cin>>n>>x;
    int ans = 1;
    int t = 0;
    rep(i,n){
        int tmp;cin>>tmp;
        t+=tmp;
        if(t<=x)++ans;
        else break;
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3516
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
  int n;
  scanf("%d", &n);
  vector<int> v;
for(int i=0;i<2*n;i++){
  int t;
  scanf("%d", &t);
  v.push_back(t);
 }
 sort(v.begin(),v.end());
 int ans=0;
 for(int i=0;i<n;i++){
   ans += v[2*i];
}
 printf("%d\n",ans);

}


Measured memory_bytes: 256
// String Transformation

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>

using namespace std;

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

    vector<int> s_count(26);
    vector<int> t_count(26);
    for (int i = 0; i < 26; i++) {
        s_count[i] = 0;
        t_count[i] = 0;
    }

    for (int i = 0; i < s.size(); i++) {
        s_count[s[i] - 'a']++;
        t_count[t[i] - 'a']++;
    }

    sort(s_count.begin(), s_count.end());
    sort(t_count.begin(), t_count.end());

    for (int i = 0; i < 26; i++) {
        if (s_count[i] != t_count[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 776
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <iomanip>
#include <type_traits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//constexpr long long MOD = 1e9 + 7;
//constexpr long long MAX = 1000000;

//long long MOD = 998244353;
constexpr ll INF = 1e17;
constexpr double PI = 3.141592653589793;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

ll h, w;
vector<ll> dx = { -1, 0, 1, 0 };
vector<ll> dy = { 0, -1, 0, 1 };


bool isInField(ll x, ll y) {
    bool f = x >= 0 && x < w && y >= 0 && y < h;
    return f;
}

bool compare_first(pair<ll, ll> x, pair<ll, ll> y)
{
    if (x.first != y.first) {
        return x.first < y.first;
    }
    else {
        return x.second < y.second;
    }
}

bool compare_second(pair<ll, ll> x, pair<ll, ll> y)
{
    if (x.second != y.second) {
        return x.second < y.second;
    }
    else {
        return x.first < y.first;
    }
}

struct {
    bool operator()(pair<string, int> x, pair<string, int> y) const
    {
        return x.second <= y.second && x.first < y.first;
    }
} compare_map;

const ll MAX = 500000000;
const ll MOD = 1000000007;

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

    string s;
    cin >> s;
    int q;
    cin >> q;

    string before;
    string after;

    bool isReversed = false;
    for (int i = 0; i < q; i++)
    {
        int t;
        cin >> t;
        if (t == 1) {
            isReversed = isReversed ? false : true;
            continue;
        }
        // t : 2
        int f;
        char c;
        cin >> f >> c;

        if (!isReversed && f == 1) {
            before += c;
        }
        if (isReversed && f == 1) {
            after += c;
        }
        if (!isReversed && f == 2) {
            after += c;
        }
        if (isReversed && f == 2) {
            before += c;
        }
    }

    if (isReversed) {
        reverse(after.begin(), after.end());
        reverse(s.begin(), s.end());
        after += s;
        after += before;
        cout << after << "\n";
    }
    else {
        reverse(before.begin(), before.end());
        before += s;
        before += after;
        cout << before << "\n";
    }

    return 0;
}



Measured memory_bytes: 1300
#include<stdio.h>
int main()
{
	int A,B,C;
	 1<=A<=10;
	 1<=B<=10;
	 1<=C<=10;
	char YES,NO;
	scanf("%d %d %d",&A,&B,&C);
	if(A==5&&B==5&&C==7)
	{
	printf("%s","YES");
	}
	else if(A==5&&B==7&&C==5)
	{
	printf("%s","YES");
	}
	else if(A==7&&B==5&&C==5)
	{
	printf("%s","YES");
	}
	else
	{
	printf("%s","NO");
	}
	return 0;
} 

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;

int main(void){
	int n,a[101],m=0;
	rep(i,1,101){
		a[i]=0;
	}
	while( cin >> n ){
		a[n]++;
	}
	rep(i,1,101){
		if(m < a[i]){
			m=a[i];
		}
	}
	rep(i,1,101){
		if(m == a[i]){
			cout << i << "\n";
		}
	}
	return 0;
}

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

int main() {
  
  int A,B,C,tmp;
  cin >> A >> B >> C  ;  
  
  tmp = B;
  B = A;
  A = C;
  C = tmp;
  
  cout << A << " " << B << " " << C <<endl; 
  
//  for(int i=0;i<;i++){
//  }
  
//  cout <<   << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int p[5010];
ll s[5010];
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	rep(i,0,n)scanf("%d",p+i),p[i]--;
	rep(i,0,n)scanf("%lld",s+i);
	
	ll ans=-INF;
	rep(i,0,n){
		ll score[5010];
		ll pp[5010];
		score[0]=0;
		pp[0]=i;
		int pos=i;
		int cnt=0;
		do{
			pos=p[pos];
			cnt++;
			pp[cnt]=pos;
			score[cnt]=score[cnt-1]+s[pos];
		}while(pos!=i);
		ll tempans=-INF;
		if(score[cnt]>0){
			//最後の1周だけ全探索
			int aaa=max(0,k-cnt);
			ll temp=score[cnt]*(aaa/cnt)+score[aaa%cnt];
			int num=min(k,cnt);
			int crr=pp[aaa%cnt];
			tempans=temp;
			rep(j,0,num){
				crr=p[crr];
				temp+=s[crr];
				tempans=max(tempans,temp);
			}
		}else{
			//最初の1周だけ全探索
			ll temp=0;
			int num=min(k,cnt);
			int crr=i;
			tempans=-INF;
			rep(j,0,num){
				crr=p[crr];
				temp+=s[crr];
				tempans=max(tempans,temp);
			}
		}
		//printf("%lld\n",tempans);
		ans=max(ans,tempans);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 1872
#include <iostream>
#include <cstdio>
#include <vector>
#include <valarray>
#include <cassert>

using namespace std;
typedef long long ll;

int n;
int g[55][9][9];
int dp[55][55][9];
int used[55][55][9];

int solve(int u, int m, int b = 0) {
	if (u == n) return 0;
	if (used[u][m][b]) return dp[u][m][b];
	used[u][m][b] = true;
	int res = -1000000;
	for (int i = 0; i <= min(8, m); i++) {
		res = max(res, solve(u+1, m-i, i) + g[u][i][b]);
	}
	return dp[u][m][b] = res;
}

int main() {
	int m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		for (int j = 0; j <= 8; j++) {
			for (int k = 0; k <= 8; k++) {
				g[i][j][k] = c;
				for (int x = 0; x <= j; x++) {
					for (int y = 0; y <= k; y++) {
						if (!x && !y) continue;
						if (x + y > 8) continue;
						int res = x*a + y*b;
						g[i][j][k] = max(g[i][j][k], res);
					}
				}
			}
		}
	}
	cout << solve(0, m) << endl;
	return 0;
}

Measured memory_bytes: 1376
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
int main(){
	int N, M; cin >> N >> M;
	vector<int> P(100000), Y(100000);
	V2(V, 100001, 0);
	REP(i, M){
		cin >> P[i] >> Y[i];
		V[P[i]].push_back(Y[i]); 
	}
	REP(i, N) sort(V[i+1].begin(), V[i+1].end());	
	REP(i, M) printf("%012lld\n", (ll)P[i]*1000000 + int(lower_bound(V[P[i]].begin(), V[P[i]].end(), Y[i]) - V[P[i]].begin()) + 1);
}


Measured memory_bytes: 7808
#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 sum = 0;
  for (int i = 0; i < n; i ++)
    for (int j = i + 1; j < n; j ++)
      sum += d.at(i) * d.at(j);
    
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
//Md Fahad
// CSE 18

#include<bits/stdc++.h>


using  namespace  std;

#define PI              acos(-1.0)
#define lcm(a,b)        (a * (b / __gcd(a,b)))
#define en '\n'

#define READ_IN freopen("Input.txt","r",stdin);
#define READ_OUT freopen("Output.txt","w",stdout);
#define Infi                0x3f3f3f3f

const int fx[] = {+1,-1,+0,+0};                         // 4 X directions
const int fy[] = {+0,+0,+1,-1};                         // 4 Y directions
const int fx8[] = {+0,+0,+1,-1,-1,+1,-1,+1};            // King X Moves
const int fy8[] = {-1,+1,+0,+0,+1,+1,-1,-1};            // King Y Moves
const int kx[] = {-2, -2, -1, -1,  1,  1,  2,  2};      // Knight X Moves
const int ky[] = {-1,  1, -2,  2, -2,  2, -1,  1};      // Knight Y Moves



int  Set    (int N,int pos) {return N=N | (1<<pos);}    /// turn a bit on
int  reset  (int N,int pos) {return N= N & ~(1<<pos);}  /// turn a bit off
bool check  (int N,int pos) {return (bool)(N & (1<<pos));} /// check, if a bit is on or not

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define trace(x...)
#endif


typedef long long int           ll;
typedef unsigned long long int  llu;


int main(void)
{
    //READ_IN;

    int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int k;
    cin >> k;

    cout << a[k-1] << endl;


    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>
int main()
{
    int n;
    scanf("%d", &n);
    int *a = malloc(sizeof(int)*n+1);
    int *b = malloc(sizeof(int)*n+1);
    int *c = malloc(sizeof(int)*n);
    a[0]=-1; b[0]=0; c[0]=0;
    for(int i=1; i<=n; i++)
        scanf("%d", &a[i]);
    for(int i=1; i<=n; i++)
        scanf("%d", &b[i]);
    for(int i=1; i<=n-1; i++)
        scanf("%d", &c[i]);
    int points = 0;
    for(int i =1; i<=n; i++)
    {
        points += b[a[i]];
        if((a[i]+1==a[i+1]) && i!=n)
            points+=c[a[i]];
    }
    printf("%d\n", points);
    free(a); free(b); free(c);
    return 0;
}

Measured memory_bytes: 128
K, S = map(int, input().strip().split(' '))
cnt = 0
if S < K:
	for X in range(0, S+1):
		cnt += (S-X+1)
else:
	for X in range(0, K+1):
		if (S-X) <= (2*K):
			if (S-X) < K:
				cnt += (S-X+1)
			elif (S-X) > K:
				Z = S-X-K
				cnt += (K-Z+1)
			else:
				cnt += (K+1)
 
print(cnt)

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

int main() {
  for(string s; cin >> s && s != "0"; ) {
    int num[2][11] = {};
    int res = 0;
    num[0][0] = 1;
    for(int i = 0, now = 0; i < s.size(); ++i) {
      now = (now * 10 + s[i] - '0') % 11;
      res += num[i&1][now];
      if(i+1 == s.size() || s[i+1] != '0') num[i&1][now] += 1;
      for(int j = 0; j < 11; ++j) num[(i+1)&1][j*10%11] = num[i&1][j];
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1316
import java.util.Scanner;
import java.util.Arrays;
/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		try {
		    Scanner sc = new Scanner(System.in);
		    int t,n,i,k;
		    String s = sc.nextLine();
		    if(s.charAt(s.length()-1) == 's')
		     s=s+"es";
		     else
		     s=s+"s";
		     System.out.println(s);
		} catch(Exception e) {
		}
	}
}


Measured memory_bytes: 38592
from fractions import gcd

A,B = map(int, input().split())

num_gcd = gcd(A,B)

ans = [1]
number = num_gcd

if number%2==0:
  ans.append(2)
  number = number//2
  while number%2==0:
    number = number//2 

f=3
while f*f <= number:
  if number%f==0:
    ans.append(f)
    number = number//f
    while number%f==0:
      number = number//f 
  else:
    f += 2
if number!=1:
  ans.append(number)

print(len(ans))

Measured memory_bytes: 64108
#include<iostream>
#include<string>
using namespace std;
int main(){
	string str;
	string order;
	string p;
	char temp;
	int n=0;
	int a,b;
	
	cin>>str;
	cin>>n;
	for(int i=0;i<n;i++){
		cin >> order >> a >> b;
		if(order == "print"){
   			cout << str.substr(a, b-a+1) << endl;
  		} 
		else if(order == "reverse") {
   			while(a < b){
    				temp = str[a];
    				str[a] = str[b];
    				str[b] = temp;
    				a++;
    				b--;
   			}
  		} 
  		else if(order == "replace"){
   			cin >> p; 
   			str = str.replace(a, b-a+1, p);
  		}
	}
	}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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; }

template<class T> inline auto __lcm(T& a, T& b) 
{ return a * b / __gcd(a, b); }

template<typename T> void remove(std::vector<T>& vector, unsigned int index)
{ vector.erase(vector.begin() + index); }


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

  vector<int> v;
  rep1(i, 10) {
    rep1(j, 10) {
      v.push_back(i * j);
    }
  }

  rep(i, v.size()) {
    if (v[i] == N) {
      yes;
      return 0;
    }
  }
  no;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct _I { _I() {cin.tie(0);ios::sync_with_stdio(false);}} __I;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

int main()
{
    int H, W, D; cin >>H>>W>>D;
    vpii x2p(H*W+1);
    rep(i, H) {
        rep(j, W) {
            int A; cin >> A;
            x2p[A] = make_pair(i, j);
        }
    }

    vi cost(H*W+1, 0); // 前のマス(x-D)からあるマス(x)に移動するのに必要な累積コスト(魔力)
    rep1(x, H*W+1) {
        if (x-D >= 1) {
            cost[x] = cost[x-D] + abs(x2p[x].first - x2p[x-D].first) + abs(x2p[x].second - x2p[x-D].second);
        }
    }

    int Q; cin >> Q;
    rep(i, Q) {
        int L, R; cin >> L >> R;
        cout << (cost[R] - cost[L]) << endl;
    }
}


Measured memory_bytes: 2176
#include <stdio.h>
#include <string.h>

int main(void)
{
        int a;
        char s[10], t[10] = "2019/04/30";

        scanf("%s", s);

        a = strcmp(s, t);

        if(a<0) printf("Heisei\n");
        else printf("TBD\n");

        return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

const int INF = int(1e9 + 7);
typedef long long       ll;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
    {
    	if (s[i] == '1') s[i] = '9';
    	else s[i] = '1';
    }
    cout << s << '\n';
    return 0;
}
// PLUS ULTRA!

Measured memory_bytes: 256
import sys
#import time
#import copy
from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import itertools
#input = sys.stdin.readline
sys.setrecursionlimit(10**6)
 
def ri():
    return list(map(int, input().split()))
def rs():
    return list(input().strip())

n,m = ri()
edge=[[] for _ in range(n)]
for i in range(m):
    a, b = ri()
    a+=-1
    b+=-1
    edge[a].append(b)
    edge[b].append(a)

visited=[0]*n
dis = [0]*n
ans=[0]*n
def bfs(now, p=-1):
    q = deque([])
    q.append((now, p, -1))
    while len(q):
        now, p, d = q.popleft()
        dis[now] = d+1
        visited[now]=1
        ans[now]=p+1
        
        for e in edge[now]:
            if visited[e]==1:
                continue
            if e==now:
                continue
            q.append((e, now, dis[now]))
            visited[e]=1
        
        
        
        
bfs(0)
flag=True
for i in range(n):
    if visited[i]==0:
        flag=False
if flag:
    print("Yes")
    for i in range(1,n):
        print(ans[i])
else:
    print("No")

Measured memory_bytes: 104592
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define int long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
int mod = 1e9+7;

int32_t main(){
	#ifndef ONLINE_JUDGE
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif

	int n;
	cin>>n;
	int ans = 1000 - n%1000;
	if(ans == 1000)
		ans = 0;

	cout<<ans<<"\n";	
	return 0;
}

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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(v) (v).begin(), (v).end()
#define sp cout << fixed << setprecision(10)
typedef pair<int, int> P;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

    int n, k;
    cin >> n >> k;
    int h[n];
    rep(i, n) cin >> h[i];

    sort(h, h + n);

    ll sum = 0;
    rep(i, n - k) sum += (ll)h[i];

    cout << sum << endl;

    return 0;
}

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

public class Main {

    private static int ans = Integer.MAX_VALUE;
    private static int[] values;
    private static int a;
    private static int b;
    private static int c;

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

        int N = in.nextInt();
        a = in.nextInt();
        b = in.nextInt();
        c = in.nextInt();
        values = new int[N];
        for (int i = 0; i < N; i++) {
            values[i] = in.nextInt();
        }

        char[] patterns = new char[N];
        dfs(N, 0, patterns);

        System.out.println(ans);
    }

    private static void dfs(int depth, int currentDepth, char[] patterns) {
        if (depth == currentDepth) {
            ans = Math.min(ans, calcMp(a, b, c, patterns));
            return;
        }

        char[] patternA = patterns.clone();
        patternA[currentDepth] = 'A';
        dfs(depth, currentDepth + 1, patternA);

        char[] patternB = patterns.clone();
        patternB[currentDepth] = 'B';
        dfs(depth, currentDepth + 1, patternB);

        char[] patternC = patterns.clone();
        patternC[currentDepth] = 'C';
        dfs(depth, currentDepth + 1, patternC);

        char[] patternD = patterns.clone();
        patternD[currentDepth] = 'D';
        dfs(depth, currentDepth + 1, patternD);
    }

    private static int calcMp(int a, int b, int c, char[] patterns) {
        int numOfA = 0;
        int numOfB = 0;
        int numOfC = 0;

        int totalA = 0;
        int totalB = 0;
        int totalC = 0;

        for (int i = 0; i < patterns.length; i++) {
            if (patterns[i] == 'A') {
                numOfA++;
                totalA += values[i];
            }
            if (patterns[i] == 'B') {
                numOfB++;
                totalB += values[i];
            }
            if (patterns[i] == 'C') {
                numOfC++;
                totalC += values[i];
            }
        }

        if (numOfA == 0 || numOfB == 0 || numOfC == 0) {
            return Integer.MAX_VALUE;
        }

        int appendMp = ((numOfA - 1 ) * 10) + ((numOfB - 1) * 10) + ((numOfC - 1) * 10);
        int strechMp = Math.abs(a - totalA) + Math.abs(b - totalB) + Math.abs(c - totalC);

        return appendMp + strechMp;
    }
}


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

#define ll long long 

int main() {
    ios::sync_with_stdio(0); 

    int x; int y;
    cin >> x >> y;
    int mn = 2 * x;
    int mx = 4 * x;
    if (y % 2 == 0 && y >= mn && y <= mx) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0; 
}



Measured memory_bytes: 3536
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include<ctype.h>

int main() {

    char s[4];
    scanf("%s", s);
    
    int num=0;
    
    for(int i=0;i<4;i++){
        if(s[i]=='+'){
            num++;
        }else{
            num--;
        }
    }

    printf("%d",num);


    return 0;

}


Measured memory_bytes: 128
#include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
  int main() {
    int rep=0;
    int pos=1;
    char tab[5];
    int occ[26]={0};
    scanf("%s",tab);
    for (int i = 0; i <4; i++) {
    occ[tab[i]-'A']++;
    }
    for (int i = 0; i < 26; i++) {
      if (occ[i]!=0) {
        rep++;
      }
    }
    if (rep!=2) {
      printf("No\n");
    }
    else
    printf("Yes\n");
    return 0;
  }


Measured memory_bytes: 128
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

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

a = []
for i in range(N):
    a.append( (A[i], i+1) )

a.sort()
for (x, y) in a:
    print(str(y)+" ", end="")

print("")

Measured memory_bytes: 18444
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a+b+c>=22)
    {
        printf("bust");

    }
    else
    {
        printf("win");
    }
    return 0;
}


Measured memory_bytes: 128
class UF:
    def __init__(self, N):
        self.uf = [-1]*N
        self.n = N

    def find(self, x):
        if self.uf[x]<0: return x
        self.uf[x] = self.find(self.uf[x])
        return self.uf[x]

    def size(self, x):
        return -self.uf[self.find(x)]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x==y: return
        if self.size(x) > self.size(y): x, y = y, x
        self.uf[y] += self.uf[x]
        self.uf[x] = y
        self.n -= 1

N, M = map(int, input().split())
uf = UF(N)
for _ in range(M):
    A, B = map(int, input().split())
    uf.union(A-1, B-1)

print(max([uf.size(x) for x in range(N)]))


Measured memory_bytes: 19792
//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

typedef long long ll;
const int INF=1<<30;

const int maxn=50+10;
const int maxm=100+10;

int first[maxn],nxt[maxm],ecnt;
struct Edge{int u,v;Edge(int u=0,int v=0):u(u),v(v){}}e[maxm];
void add_edge(int u,int v){
	nxt[ecnt]=first[u];first[u]=ecnt;e[ecnt++]=Edge(u,v);
	nxt[ecnt]=first[v];first[v]=ecnt;e[ecnt++]=Edge(v,u);
}

int d[maxn];
int bit(int x){return 1<<x;}

int dep[maxn],fa[maxn];
void dfs(int u,int pre)
{
	dep[u]=dep[pre]+1;fa[u]=pre;
	for(int i=first[u];i!=-1;i=nxt[i])
	{
		int v=e[i].v;
		if(v==pre) 	continue;
		dfs(v,u);
	}
}

int LCA(int a,int b){
	if(dep[a]>dep[b]) swap(a,b);
	while(dep[a] < dep[b]) b=fa[b];	
	while(a!=b) a=fa[a],b=fa[b];
	return a;
}

struct LIM{
	int a,b,lca;	
	void input(){cin>>a>>b;lca=LCA(a,b);}
}lim[maxn];
int tag=0;
int dfs2(int u)
{
	int ret=d[u];
	for(int i=first[u];i!=-1;i=nxt[i])
	{
		int v=e[i].v;
		if(v==fa[u]) continue;
		int t=dfs2(v);
		if(t>0) ++tag;	
		ret+=t;
	}
	return ret;
}

int main()
{
	int n;cin>>n;
	rep(i,1,n) first[i]=-1;
	rep(i,1,n-1){
		int u,v;cin>>u>>v;
		add_edge(u,v);	
	}
	int m;cin>>m;
	dfs(1,1);
	rep(i,1,m) lim[i].input();	
	
	ll ans=1ll<<(n-1);
	for(int S=1;S<(1<<m);++S)
	{
		int v=1;
		rep(i,1,n) d[i]=0;
		for(int i=1;i<=m;++i) if(bit(i-1)&S){
			v*=-1;
			++d[lim[i].a];
			++d[lim[i].b];
			d[lim[i].lca]-=2;			
		}
		tag=0;
		dfs2(1);
		ans+=v*(1ll<<(n-1-tag));
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void) {
  int k;
  char s[101] = {0};
  scanf("%d", &k);
  scanf("%s", s);
  int len = strlen(s);
  if(len > k) {
    for(int i = 0;i < k;i++) {
      printf("%c", s[i]);
    }
    puts("...");
  } else {
    for(int i = 0;i < len;i++) {
      printf("%c", s[i]);
    }
    puts("");
  }
  return 0;
}
    

Measured memory_bytes: 2092
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=100000 +117;
const int MM=100000 +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n;
struct node{
	LL a,b;
}a[NN]={};;
int orda[NN]={};
int ordb[NN]={};
int rka[NN]={};
int rkb[NN]={};
bool acmp(int x,int y){
	return a[x].a<a[y].a;
}
bool kcmp(int x,int y){
	return a[x].b>a[y].b;
}
int main(){
	//open();
	n=read();
	for(int i=1;i<=n;++i){
		a[i].a=read();
		a[i].b=read();
		orda[i]=ordb[i]=i;
	}
	sort(orda+1,orda+1+n,acmp);
	sort(ordb+1,ordb+1+n,kcmp);
	int posa=0;
	int posb=n+1;
	LL ans=0;
	for(int i=1;i<=n;++i){
		if(a[orda[i]].a<a[ordb[i]].b)posa=i;
		if(a[orda[i]].a>a[ordb[i]].b)posb=min(i,posb);
		ans+=min(a[orda[i]].a,a[ordb[i]].b);
	}
	if(posa==0||posb==n+1){
		ans+=0;
	}
	else{
		for(int i=1;i<=n;++i){
			rka[orda[i]]=i;
			rkb[ordb[i]]=i;
		}
		bool fl=0;
		for(int i=1;i<=n;++i){
			if(!((rka[i]<=posa&&rkb[i]<=posa)||(rka[i]>=posb&&rkb[i]>=posb))){
				fl=1;
			}
		}
		if(!fl){
			int up=0;
			if(a[ordb[posa]].b<a[orda[posa+1]].a)up=ordb[posa];
			else up=orda[posa+1];
			int down=0;
			if(a[orda[posa]].a>a[ordb[posa+1]].b)down=orda[posa];
			else down=ordb[posa+1];
			if(up!=down){
				ans+=min(a[ordb[posa]].b,a[orda[posa+1]].a)-max(a[orda[posa]].a,a[ordb[posa+1]].b);
			}

			else{
				if(a[ordb[posa]].b<a[orda[posa+1]].a)up=posa;
				else up=posa+1;
				int down=0;
				if(a[orda[posa]].a>a[ordb[posa+1]].b)down=posa;
				else down=posa+1;
				LL res1=1e9+1,res2=0;
				for(int i=1;i<=n;++i){
					if(i!=up)res1=min(res1,max(a[orda[i]].a,a[ordb[i]].b));
					if(i!=down)res2=max(res2,min(a[orda[i]].a,a[ordb[i]].b));
				}
				res1=res1-max(a[orda[posa]].a,a[ordb[posa+1]].b);
				res2=min(a[ordb[posa]].b,a[orda[posa+1]].a)-res2;
				ans+=min(res1,res2);
			}
		}
	}
	printf("%lld\n",ans);
	close();
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int N; cin >>N;
  map<int,int> fact;
  for (int i=2; i<=N; i++){
    int tmp = i;
    for (int factor=2; factor<100; factor++){
      while (tmp % factor == 0){
        fact[factor]++;
        tmp /= factor;
      }
      if (tmp == 1) break;
    }
  }
  // factにはN!の素因数が全て入っている
  // 約数が75個：3*5*5 or 3*25 or 5*15 or 75
  // 乃ち、素因数分解したときの素因数の指数が
  // 2,4,4 or 2,24 or 4,14 or 74
  map<int,int> exponent;
  // 指数が2, 4, 14, 24, 74個あるものの個数を格納
  for (auto p : fact){
    int k = p.first;
    int v = p.second;
    if (v >= 2) exponent[2]++;
    if (v >= 4) exponent[4]++;
    if (v >= 14) exponent[14]++;
    if (v >= 24) exponent[24]++;
    if (v >= 74) exponent[74]++;
  }
  int res = 0;
  // 指数が74単独のヤツ
  res += exponent[74];
  // 指数が4, 14のヤツ
  res += exponent[14] * (exponent[4]-1);
  // 指数が2, 24のやつ
  res += exponent[24] * (exponent[2]-1);
  // 指数が2, 4, 4のやつ
  res += exponent[4] * (exponent[4] - 1) / 2 * (exponent[2] - 2);
  cout <<res <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<string> s(n);
  for(int i=0;i<n;i++){
    cin>>s[i];
  }
  int a,b,c,d;
  a=0;
  b=0;
  c=0;
  d=0;
  for(int i=0;i<n;i++){
    if(s[i]=="P"){
       a++;
       break;
    }
  }
   for(int i=0;i<n;i++){
    if(s[i]=="W"){
       b++;
       break;
    }
  }
   for(int i=0;i<n;i++){
    if(s[i]=="G"){
       c++;
       break;
    }
  }
   for(int i=0;i<n;i++){
    if(s[i]=="Y"){
       d++;
       break;
    }
  }
  if(a+b+c+d==3){
    cout<<"Three";
  }
  else{
    cout<<"Four";
  }
       
}

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

int main()
{
  int a[5];
  for (int i = 0; i < 5; i++)
  {
    cin >> a[i];
  }
  int lastIndex = 0;
  int min = 10;
  for (int i = 0; i < 5; i++)
  {
    if (a[i] % 10 != 0)
      if (a[i] % 10 < min)
      {
        lastIndex = i;
        min = a[i] % 10;
      }
  }
  int time = 0;
  for (int i = 0; i < 5; i++)
  {
    if (i == lastIndex) continue;
    if (a[i] % 10 == 0)
    {
      time += a[i];
    }
    else
    {
      time += a[i];
      time += 10 - a[i] % 10;
    }
  }
  
  time += a[lastIndex];
  cout << time << endl;
  return 0;
}


Measured memory_bytes: 256
// トポロジカルソート : 深さ優先探索
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<list>

using namespace std;

const int MAX = 10000;

// 各辺のつながりを格納する動的配列
vector<int> G[MAX];
// 訪問情報を保持する配列
bool V[MAX];
// トポロジカルソートの結果を格納するリスト
list<int> out;

int N;

void dfs(int u);

int main(void)
{

    int s, t, M;

    cin >> N >> M;

    for(int i = 0; i < N; i++)
    {
        // 配列の初期化
        V[i] = false;
    }

    for(int i = 0; i < M; i++)
    {
        cin >> s >> t;

        // 各辺のつながりを記憶する
        G[s].push_back(t);
    }

    for(int i = 0; i < N; i++)
    {
        if( !V[i] )
        {
            // 頂点を順番に訪れる
            dfs(i);
        }
    }

    // 結果の表示
    // トポロジカルソートの結果の表示
    for(list<int>::iterator it = out.begin(); it != out.end(); it++)
    {
        cout << *it << endl;
    }

    return 0;
}

// トポロジカルソートを実施するためのメソッド
// u : 訪問する頂点
void dfs(int u)
{
    // 訪問情報を記録
    V[u] = true;

    for(unsigned int i = 0; i < G[u].size(); i++ )
    {
        // 接続先の頂点No.の格納
        int v = G[u][i];

        if( !V[v] )
        {
            // 接続している頂点を順番に訪れる
            dfs(v);
        }
    }

    // 入力辺が無くなった頂点をトポロジカルキューに追加する
    out.push_front(u);

}



Measured memory_bytes: 3996
import sys
sys.setrecursionlimit(10**5+1)

def cur(p):
    for i in x[p]:
        if rank[i]==-1:
            rank[i]=rank[p]+1
            par[i]=p
            cur(i)

def cur2(p):
    if spar[p]==-1:
        spar[p]=cur2(par[p])
    return spar[p]




n,u,v=map(int,input().split())
u,v=u-1,v-1
x=[[] for i in range(n)]

for i in range(n-1):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    x[a].append(b)
    x[b].append(a)

rank=[-1 for i in range(n)]
rank[u]=0
par=[-1 for i in range(n)]

cur(u)

spar=[-1 for i in range(n)]
i=v
while i!=u:
    spar[i]=i
    i=par[i]
spar[u]=u


for p in range(n):
    cur2(p)

ans=rank[v]-1
for i in range(n):
    z=rank[v]-rank[spar[i]]*2
    if z>0:
        ans=max(ans,rank[i]+z-1)
print(ans)

Measured memory_bytes: 92124
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            string szLine = Console.ReadLine();
            szLine = Console.ReadLine();
            bool[] eArr = new bool[szLine.Length];
            for(int i=0;i<szLine.Length;++i)
            {
                eArr[i] = szLine[i] == 'E';
            }

            int[] w_totalArr = new int[eArr.Length];// leaderの西側のwの総数 累積和
            int[] e_totalArr = new int[eArr.Length];// leaderの東側のeの総数　累積和
            
            for(int leader=1; leader<eArr.Length;++leader)
            {

                w_totalArr[leader] = w_totalArr[leader - 1] + (eArr[leader - 1] ? 0 : 1);
                int idx = eArr.Length - 1 - leader;
                e_totalArr[idx] = e_totalArr[idx + 1] + (eArr[idx + 1] ? 1 : 0);


            }

            int min_ = int.MaxValue;

            for( int i=0; i<eArr.Length;++i)
            {
                int total = w_totalArr[i] + e_totalArr[i];
                if( total < min_)
                {
                    min_ = total;
                }
            }

            Console.WriteLine(min_);
        }
    }
}


Measured memory_bytes: 14688
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

loop_count = 0
loop = [0] * N
i = 1
town = A[0] - 1
loop[0] = i
if N > K:
    for _ in range(K - 1):
        town = A[town] - 1
    print(town + 1)
else:
    while True:
        if loop[town] == 0:
            i += 1
            loop[town] = i
            town = A[town] - 1
        else:
            break
    loop_size = i - loop[town] + 1
    
    if loop_size != 0:
        K = (K - i) % loop_size
    
    for _ in range(K):
        town = A[town] - 1
    
    print(town + 1)


Measured memory_bytes: 92460
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;




int main(){
    
    string s;
    string t;
    cin >> s >> t;
    if (s.size() < 1 || s.size() > 10){
        cout << "No"; 
    }
    else{
        if (s.size() != t.size() - 1 || t.substr(0,s.size()) != s){
            cout << "No";
        }
        else{
            bool ok = true;
            for(auto e:t){
                int i = e - 'a';
                if (i < 0 || i > 26){
                    cout << "No";
                    ok = false;
                    break;
                }
            }
            if (ok) cout << "Yes";
        }
    }
}










Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

#define _ { \
	ios_base::sync_with_stdio(false); \
    cin.tie(NULL); \
}

int main(){
   _;
   string s;cin>>s;
   string wow="";
   int q;cin>>q;
   int yay=0;
   for(int i=0;i<q;i++){
       int a;cin>>a;
       if(a==1){
           yay++;
       }
       else {
           int b;cin>>b;char c;cin>>c;
           if(b==1&&yay%2==0)wow+=c;
           else if(b==1)s+=c;
           else if(yay%2==0)s+=c;
           else wow+=c;
       }
   }
  if(yay%2==0)cout<<string(wow.rbegin(),wow.rend())<<s;
  else cout<<string(s.rbegin(),s.rend())<<wow;
}

Measured memory_bytes: 1108
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
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(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
int main()
{
  ll n; cin >> n;
  ll res = n;
  rep(i,n-1) {
    ll u,v; cin >> u >> v;
    if(u > v) swap(u, v);
    res += (i + 1) * (n - i);
    res -= u * (n - v + 1);
  }
  cout << res << "\n";
  return 0;
}


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

int main(){
    int N, X, cnt=0;
    cin >> N >> X;
    vector<int> m(N);
    for(int i=0; i<N;i++){
        cin >> m[i];
    }
    sort(m.begin(), m.end());
    int sum = accumulate(m.begin(), m.end(),0);
    X -= sum;
    cnt+=N;
    while(X>=0){
        X-=m[0];
        cnt++;
    }
    cnt--;
    cout << cnt;
}

Measured memory_bytes: 256
from collections import deque

h, w = map(int, input().split())
field = [input() for i in range(h)]
todo = deque([[0, 0]])
seen = [[-1]*w for _ in range(h)]
seen[0][0] = 0
dy = [1, -1, 0, 0]
dx = [0, 0, 1, -1]

count_black = 0
for line in field:
    count_black += line.count('#')

while todo:
    y, x = todo.popleft()

    for i in range(4):
        ny, nx = y + dy[i], x + dx[i]

        if ny < 0 or h <= ny or nx < 0 or w <= nx:
            continue
        elif field[ny][nx] == '#' or seen[ny][nx] >= 0:
            continue
        else:
            seen[ny][nx] = seen[y][x] + 1
            todo.append([ny, nx])

goal = seen[h-1][w-1]

if goal == -1:
    print(-1)
else:
    ans = h * w - count_black - goal - 1
    print(ans)


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

int main()
{
    int a, x = 0, y = 0;
    for (int i = 0; i < 3; i++)
    {
        cin >> a;
        if (a == 5)
            x++;
        else if (a == 7)
            y++;
    }
    if (x == 2 && y == 1)
        cout << "YES";
    else
        cout << "NO";
}

Measured memory_bytes: 3500
n = int(input())
a = list(map(int, input().split()))

cnt = 0

flag = True

while flag == True:
    for i in range(n):
        if a[i]%2:
            flag = False
            cnt -= 1
            break
        a[i] = a[i]//2
    cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x/10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x%mod;
	while(m){
		if(m&1) res=(1ll*res*bas)%mod;
		bas=(1ll*bas*bas)%mod,m>>=1;
	}
	return res%mod;
}
const int MAXN = 2e5+5,mod = 1e9+7;
int n,val[MAXN],pre[MAXN],dp[MAXN];
it add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n),dp[0]=1;
	for(ri i=1;i<=n;++i) read(val[i]);
	for(ri i=1;i<=n;++i){
		dp[i]=dp[i-1];
		if(val[i]==val[i-1]) continue;
		if(pre[val[i]]) dp[i]=add(dp[i],dp[pre[val[i]]]);
		pre[val[i]]=i;
	}
	print(dp[n]);
	return 0;
}

Measured memory_bytes: 2560