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

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

		long HOGE = 998244353;

		long n = sc.nextLong();

		long[] counter = new long[200000];

		long max = 0;

		long ans = 1;

		for (long i = 0; i < n; i++) {
			int tmp = sc.nextInt();

			if (i == 0 && tmp != 0) ans = 0;

			if (tmp > max)
				max = tmp;

			counter[tmp]++;
		}

		long before = counter[0];

		for (int i = 0; i < max + 1; i++) {
			if (counter[0] != 1) {
				ans = 0;
				break;
			}
			if (counter[i] == 0) {
				ans = 0;
				break;
			}
			//			System.out.println("b" + before + "c" + counter[i]);
			//			System.out.println(ans);

			for(int j = 0; j < counter[i]; j++) {
				ans = before * ans % HOGE;
			}


			before = counter[i];
		}
		System.out.println(ans);

	}
}


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

using namespace std;

int main(){
    int N;
    while(cin >> N){
        vector<int> a(N);
        for(auto& t : a){ cin >> t; --t; }
        int res = 0;
        for(int i=0;i<N;i++){
            if(i == a[a[i]]) ++res;
        }
        cout << (res/2) << endl;
    }
}

Measured memory_bytes: 640
#include <stdio.h>

int main()
{
    int A[100][100];
    int b[100];
    long long ans;
    int i, j, n, m;

    scanf("%d %d", &n, &m);
    for(i = 0; i < n; i++) {
        for(j = 0; j < m; j++) {
            scanf("%d", &A[i][j]);
        }
    }
    for(i = 0; i < m; i++) {
        scanf("%d", &b[i]);
    }
    for(i = 0; i < n; i++) {
        ans = 0;
        for(j = 0; j < m; j++) {
            ans += A[i][j] * b[j];
        }
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 2040
#include<iostream>
using namespace std;
int main()
{
	int a,b[2];
	cin >> a;
	if (a % 2 == 0) {
		cin >> b[0] >> b[1];
		cout << b[0] + b[1];
	}
	else {
		cout << "Hello World" << endl;
	}
	return 0;
}

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

using namespace std;
using ll = long long;


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

    int n = a.length();
    ll count = 0;

    for (int i = 0; i < n; i++){
        if (a[i] != b[i]) count ++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pbs(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1000000007;

const ll INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

int main(){
	int n;cin>>n;
	int ans=0;
	reps(i,n){
		int a;cin>>a;
		if(i%2==1 && a%2==1)ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
constexpr int INF = 1000000000000000000LL;
template<typename A, typename B> void cmax(A &a, const B &b) {
  if (a < b) a = b;
}
template<typename A, typename B> void cmin(A &a, const B &b) {
  if (a > b) a = b;
}

int MAX_V;

int N, W;
int v[50], w[50], m[50];

int solve() {
  int X = 1000, S = N * X * MAX_V;

  vector<int> dp(S + 1, INF);
  dp[0] = 0;
  rep(i, N) {
    int t = min(m[i], X);
    m[i] -= t;
    for (int k = 0; t; k++) {
      int c = min(t, 1LL << k);
      t -= c;
      for (int j = S; j - v[i] * c >= 0; j--) cmin(dp[j], dp[j - v[i] * c] + w[i] * c);
    }
  }

  vector<int> ord(N);
  iota(all(ord), 0);
  sort(all(ord), [&](int i, int j) { return v[i] * w[j] > v[j] * w[i]; });
  int ans = 0;
  for (int j = 0; j <= S; j++) {
    if (W < dp[j]) continue;
    int lim = W - dp[j];
    int s = j;
    rep(i, N) {
      int k = ord[i];
      int c = min(m[k], lim / w[k]);
      lim -= w[k] * c;
      s += v[k] * c;
    }
    cmax(ans, s);
  }
  return ans;
}

main() {
  cin >> N >> W;
  rep(i, N) cin >> v[i] >> w[i] >> m[i];
  MAX_V = *max_element(v, v + N);
  cout << solve() << endl;
}



Measured memory_bytes: 22288
s = input()
q = int(input())
r = 0
qn = []*3
left =''
right = ''

for i in range(q):
    qn = input().split()
    if qn[0] == '1':
        r += 1
    elif qn[0] == '2':
        if qn[1] == '1' and r%2 == 0:
            left = qn[2] + left
        elif qn[1] == '1' and r%2 == 1:
            right += qn[2]
        elif qn[1] == '2' and r % 2 == 0:
            right += qn[2]
        elif qn[1] == '2' and r % 2 == 1:
            left = qn[2] + left

ans = left + s + right

if r%2 == 1:
    ans = ans[::-1]

print(ans)

Measured memory_bytes: 4448
# = int(input())
H, M, h, m, K = map(int, input().split())
# = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]

count = 0

count += m-M
count += (h-H)*60
count -= K

print(count) 


Measured memory_bytes: 9176
t=int(input())
if(t>=400 and t<=599):
    print(8)
elif(t>=600 and t<=799):
    print(7)
elif(t>=800 and t<=999):
    print(6)
elif(t>=1000 and t<=1199):
    print(5)
elif(t>=1200 and t<=1399):
    print(4)
elif(t>=1400 and t<=1599):
    print(3)   
elif(t>=1600 and t<=1799):
    print(2)
elif(t>=1800 and t<=1999):
    print(1)    

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

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second

typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

const int MOD = 1e9+7;

int main(){ _

	int h, w; cin >> h >> w;
	vector<vector<char>> grid(h, vector<char>(w));

	for(auto& v : grid) for(auto& c : v) cin >> c;

	vector<int> memo(w);
	memo[0] = 1;
	for(int i=0; i<h; i++) {
		for(int j=0; j<w; j++) {
			if(grid[i][j] == '#') memo[j] = 0;
			else memo[j] = (j ? (memo[j]+memo[j-1])%MOD : memo[j]);
		}	
	}
	
	cout << memo[w-1] << endl;

	return 0;
}


Measured memory_bytes: 4256
using System;
using System.Linq;

namespace Hoge
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x));
            var five = input.Count(x => x == 5) == 2;
            var seven = input.Any(x => x == 7);

            var output = five && seven ? "YES" : "NO";
            Console.WriteLine(output);
        }
    }
}


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

int main(void){
    int N;
    int ans = -1;
    string s, t;
    cin >> N >> s >> t;
    for(int sb = 0; sb < N; sb++){
        bool flg = true;
        for(int si = sb; si < N; si++){
            int ti = si - sb;
            if(s[si] != t[ti]) flg = false;
        }
        if(flg){
            cout << sb + N << endl;
            break;
        }
        if(sb == N-1)
            cout << s.length() + t.length() << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 int m[3][3];
int mark[3][3];
void search(int x)
{
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
      if(m[i][j]==x and !mark[i][j]){mark[i][j]=1;return;}
}
int main()
{
 
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
    {
      cin>>m[i][j];
    }
  int n;cin>>n;
  int x;
  for(int i=0;i<n;i++)
  {
    cin>>x;
    search(x);
  }
  bool ans=false;
  for(int i=0;i<3;i++)
  {
    if(mark[i][0]+mark[i][1]+mark[i][2]==3)ans=true;
    if(mark[0][i]+mark[1][i]+mark[2][i]==3)ans=true;
  }
  if(mark[0][0]+mark[1][1]+mark[2][2]==3)ans=true;
  if(mark[0][2]+mark[1][1]+mark[2][0]==3)ans=true;
  if(ans)cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
long modPow(long a, long x, long p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}

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

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

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

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
int main() {
  int n,a,b;
  cin >> n >> a >> b;
  int ans;
  ans = (modPow(2,n,1000000007) -1 -modBinomial(n,a,1000000007) -modBinomial(n,b,1000000007))%1000000007;
  if (ans < 0){
  ans+=1000000007;}
  cout << ans << endl;
}

Measured memory_bytes: 256
import math
X,K,D=map(int,input().split())
count=0
#Xが初期値
#Dが移動量（+or-）
#K回移動後の最小の座標
#X/D＞Kの場合、K*D＋Xが答え

Y = 0
#X>0 D>0 の場合
if X / D > K and X / D > 0:
    Y = abs(X - D * K)
elif abs(X / D) > K and X / D < 0:
    Y = abs(X + D * K)
else:
    #X/D<Kの場合、X mod D
    L = abs(X) % D
    M = math.floor(abs(X) / D)
    if (K - M) % 2 == 0:
        Y = L
    else:
        Y=abs(L-D)

print(Y)

Measured memory_bytes: 62132
import java.util.Scanner;


public class Main 
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		for(; scanner.hasNext();)
		{
			double v = scanner.nextDouble();
			
			double y = v*v / 19.6;
			int n = 0;
			for(; 5*(n-1)<y; n++);
			
			System.out.println(n);
		}
	}
}

Measured memory_bytes: 27536
#include <bits/stdc++.h> 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
typedef long long ll;
using namespace std;
int main(){
  int x;
  cin>>x;
  cout<<x*x<<endl;
}

Measured memory_bytes: 256
import bisect
N = int(input())
L = list(map(int, input().split()))
L = sorted(L)


res = 0
for i in range(N):
    a = L[i]
    for j in range(i + 1, N):
        b = L[j]
        k = bisect.bisect_left(L, a + b)
        res += max(k - (j + 1), 0)
        # print(a, b, k, k - (j + 1))

print(res)

Measured memory_bytes: 45488
#include <stdio.h>

int main(){
  int N;
  int A[100];
  int num = 0,count = 0;
  int i,j,minj = 0;

  scanf("%d",&N);
  for(i=0;i<N;i++)scanf("%d",&A[i]);
  
  for(i=0;i<N;i++){
    minj = i;
    for(j=i;j<N;j++){
      if(A[j]<A[minj])minj = j;
    }
    if(minj!=i){
      num = A[i];
      A[i] = A[minj];
      A[minj] = num;
      count++;
    }
  }
  
  for(i=0;i<N-1;i++)printf("%d ",A[i]);
  printf("%d\n",A[i]);
  
  printf("%d\n",count);
  
  return 0;
}



Measured memory_bytes: 2048
#include "bits/stdc++.h"
using namespace std;
using ld = long double;
const ld eps = 1e-9;


int main() {
	int N; cin >> N;
	vector<bitset<3>>flags(N);
	for (int i = 0; i < 3; ++i) {
		int K; cin >> K;
		while (K--) {
			int a; cin >> a; a--;
			flags[a][i] = true;
		}
	}
	int ans=count_if(flags.begin(),flags.end(),
		[](const bitset<3>&bs) {
		int n = bs.to_ulong();
		return n == 4 || n==6 || n==7;
	});
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3084
while True:
    n,x = (int(i) for i in input().split())
    if n == 0 and x == 0:
        break

    c = 0
    for i in range(1, n + 1):
        for j in range(1, i):
            for k in range(1, j):
                if i + j + k == x:
                    c += 1
    print(c)


Measured memory_bytes: 5604
#include <stdio.h>
#include <stdlib.h>
#include "string.h"

int main(void)
{
  char S[100];
  scanf("%s", &S);
  for (size_t i = 0; i < strlen(S); i++) {
    if ( i % 2 == 0) {
      if (S[i] == 'L') {
        printf("No\n" );
        return 0;
      }
    }else{
      if ( S[i] == 'R') {
        printf("No\n");
        return 0;
      }
    }
  }

  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int f[15], n, k, x;
int main(){
	cin>>n>>k;
	for(int i=1;i<=k;i++) {
		scanf("%d", &x);
		f[x]=1;
	}
	for(int i=n;;i++){
		int ok=1, j=i;
		while(j){
			if(f[j%10]){
				ok=0;
				break;
			}
			j/=10;
		}
		if(ok){
			cout<<i;
			return 0;
		}
	}
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdlib>
#include <math.h>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrep1(i,a,b) for(long i=(a);i<=(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define X first
#define Y second
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define vpl vector<pair<long, long> >
#define vppl vector<pair<long, pair<long, long> > >

const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;

int printYes() {
    cout << "Yes" << endl;
    return 0;
}

int printNo() {
    cout << "No" << endl;
    return 0;
}

int ans;

int printAns() {
    cout << ans << endl;
    return 0;
}


int pow(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow(x - 1) * 2;
	}
}

int main(int argc, char const *argv[])
{
    string a;
    cin >> a;
    string y,m,d;
    y = a.substr(0,4);
    m = a.substr(5, 2);
    d = a.substr(8,2);
    if(stoi(y) > 2019) {
        cout << "TBD";
    } else if (stoi(y) == 2019)
    {
        if (stoi(m) > 4) {
            cout << "TBD";
        } else if (stoi(m) == 4 && stoi(d) >
         30)
        {
            cout << "TBD";
        }else{
        
        cout << "Heisei";

        }
    } else
    {
        cout << "Heisei";
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,m,f[2505];
int p;
struct node{int from,to,val;}e[5005];
int main(){
	cin>>n>>m>>p;
	memset(f,0x7f,sizeof(f));
	for(int i=1,a,b,c;i<=m;i++){
		cin>>a>>b>>c;
		e[i]=((node){a,b,p-c});
	}
	f[1]=0;
	for(int i=1;i<=n<<1;i++){
		for(int j=1;j<=m;j++){
			int a=e[j].from,b=e[j].to,c=e[j].val;
			if(f[a]==9187201950435737471)continue;
			if(f[b]>f[a]+c*1ll)f[b]=i<n?f[a]+c:-1e18;
		}
	}
	if(f[n]==-1e18)cout<<-1;
	else cout<<(f[n]<0?-f[n]:0);
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

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

  rep(i,3){
    if(s[i]=='7'){
      cout << "Yes"<< endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


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

const int nmax = 50;

int main(){
	int n, p;
	int kouho[nmax];
	while(cin >> n >> p){
		if(n == 0 && p == 0) break;
		for(int i = 0; i < n; i++){
			kouho[i] = 0;
		}
		int num = p;
		int place = 0;
		while(true){
			if(num){
				kouho[place]++;
				if(kouho[place] == p) break;
				num--;
			}else{
				num += kouho[place];
				kouho[place] = 0;
			}
			place++;
			if(place == n) place = 0;
		}
		cout << place << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;
import java.lang.Math;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
  		
      	int n = sc.nextInt();
      	int m = sc.nextInt();
      	int as[] = new int[n];
      	int bs[] = new int[n];
      	int cs[] = new int[m];
      	int ds[] = new int[m];
      	int ans[] = new int[n];
      	int min;
      	int istack;
      	
      	for(int i = 0;i < n;i++){
          as[i] = sc.nextInt();
          bs[i] = sc.nextInt();
        }
      	for(int i = 0;i < m;i++){
          cs[i] = sc.nextInt();
          ds[i] = sc.nextInt();
        }
      	for(int i = 0;i < n;i++){
          min = Math.abs(as[i]-cs[0]) + Math.abs(bs[i]-ds[0]);
          ans[i] = 0;
          for(int j = 1;j < m;j++){
          	istack = Math.abs(as[i]-cs[j]) + Math.abs(bs[i]-ds[j]);
            if(istack < min){
              min = istack;
              ans[i] = j;
            }
          }
        }
      	
      	for(int i = 0;i < n;i++) System.out.println(ans[i] + 1);
        
	}
}


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

def Main(N, V):
    dp = [[0 for _ in range(3)] for _ in range(N+1)]
    for i in range(N):
        for j in range(3):
            for k in range(3):
                if(j != k):
                    dp[i+1][j] = max(dp[i+1][j], dp[i][k] + V[i][j])
    return max(dp[N])

def main():
    N = int(input())
    V = []
    for i in range(N):
        V.append(list(map(int, input().split())))
    print(Main(N, V))

if __name__ == '__main__':
    main()

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

int main() {
	int S,h,m,s;
	cin>>S;
	h=S/3600;
	m=(S%3600)/60;
	s=(S%3600)%60;
	cout<<h<< ":" <<m<< ":"<<s<<endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3092
n = int(input())
a = list(map(int, input().split()))
b = []
if n % 2 == 0:
    for i in range(n // 2):
        b.append(a[- 2 * i - 1])
    for i in range(n // 2):
        b.append(a[2 * i])
else:
    for i in range(n // 2 + 1):
        b.append(a[- 2 * i - 1])
    for i in range(n // 2):
        b.append(a[2 * i + 1])
print(*b)

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

int main(){
	int money = 100000;
	int n;

	cin >> n;
	for(int i=0 ; i<n ; i++){
		money *= 1.05;
		if(money%1000 != 0){
			money += 1000 - (money%1000);
		}
	}
	cout << money << endl;
} 

Measured memory_bytes: 3000
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define piii pair<int, pii >
#define ppp pair<pii, pii >
#define F first
#define S second
#define pb push_back
#define pp pop_back

const int P = 1000000007;

using namespace std;



int main(){

	int a, b, c;
	cin >> a >> b >> c;
	cout << c << ' ' << a << ' ' << b << endl;

	return 0;
}


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

int main(void){
 
  int H,W;
  
  cin >> H >> W;
  
  //周囲8マスをしらべるための配列を作成
  const int dh[] = { -1, -1, -1, 0, 0,  1, 1, 1};
  const int dw[] = { -1,  0,  1,-1, 1, -1, 0, 1};
  
  string S[H];
  
  for(int i = 0; i < H; ++i) cin >> S[i];
  
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      if(S[i][j] == '.'){
        int count = 0;
        //'.'の周り8マスに'#'が何個あるか調べる
        for(int k = 0; k < 8; ++k){
          int h = i + dh[k];
          int w = j + dw[k];
          //存在しないマスを見ていないか確認した後、'#'の判定をする
          if((h >= 0 && h < H && w >= 0 && w < W )
             && S[h][w] == '#') count++;
        }   
        //intの数値をcharに変換
        S[i][j] = '0' + count;
      } 
    }
  }
  
  for(int i = 0; i < H; i++) cout << S[i] << endl;
  
  return 0;
}


Measured memory_bytes: 256
/*---> 31 October 2019 <--- > 23:42:59 <---*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//boot#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
//template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=1e5+5;

int32_t main(){__
	int n;
	cin>>n;
	vi a(n),b(n),c(n-1);
	int ans=0;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		cin>>b[i],ans+=b[i];
	for(int i=0;i<n-1;i++)
		cin>>c[i];
	for(int i=1;i<n;i++){
		if(a[i]==a[i-1]+1)
			ans+=c[a[i-1]-1];
	}
	cout<<ans<<"\n";
return 0;
}

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

struct node{int to, cost;};
vector<vector<node>> G(2e6);
vector<int> ans(1e5, -1);
int N;


void dfs(int v) {
    while(!G[v].empty()) {
        node tmp;
        tmp = G[v].back();
        G[v].pop_back();
        if (ans[tmp.to] > -1) continue;
 
        if ( tmp.cost % 2 == 0 ) {
            ans[tmp.to] = ans[v];
        } else {
            ans[tmp.to] = 1- ans[v];
        }
        dfs(tmp.to);
    }
    return ;
}

int main() {
 
    cin >> N;

    for(int i=0; i<N-1; i++){
        int a, b, w;
        node tmp;
        cin >> a >>  b >> w;
        a--;
        b--;
        tmp.to = b;
        tmp.cost = w;
        G[a].push_back(tmp);
        tmp.to = a;
        G[b].push_back(tmp);
    }
    ans[0] = 0;
    dfs(0);
 
    for (int i = 0; i < N; i++) {
        cout << ans[i] << "\n";
    }
}


Measured memory_bytes: 52096
n = int(input())
a_list = list(map(int, input().split(' ')))

def count_manipulation(a_list, start):
    assert start in (0, 1)
    sum = 0
    count = 0
    for i, a in enumerate(a_list):
        sum += a
        if i % 2 == start:
            if sum > 0:
                continue
            else:
                diff = 1 - sum
                count += diff
                sum += diff
        else:
            if sum < 0:
                continue
            else:
                diff = sum - (-1)
                count += diff
                sum -= diff
    return count

count_plus = count_manipulation(a_list, 0)
count_minus = count_manipulation(a_list, 1)
print(min(count_plus, count_minus))


Measured memory_bytes: 58384
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var hw = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			int h = hw[0];
			int w = hw[1];

			int n = 10;
			var d = new int[n, n];
			for (int i = 0; i < n; i++) {
				var temp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
				for (int j = 0; j < n; j++) {
					d[i, j] = temp[j];
				}
			}

			for (int k = 0; k < n; k++) {
				for (int i = 0; i < n; i++) {
					for (int j = 0; j < n; j++) {
						d[i, j] = Math.Min(
							d[i, j],
							d[i, k] + d[k, j]);
					}
				}
			}

			var mins = new int[n];
			for (int i = 0; i < n; i++) {
				mins[i] = d[i, 1];
			}

			long ans = 0;
			for (int i = 0; i < h; i++) {
				var temp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
				for (int j = 0; j < w; j++) {
					if (temp[j] == -1) {
						continue;
					}

					ans += mins[temp[j]];
				}
			}

			Console.WriteLine(ans);
		}
	}
}

Measured memory_bytes: 15444
n = int(input())
s = input()
s = list(map(lambda x:1 if x=="o" else -1,list(s)))
flag = False
for start in [[1,1], [1,-1], [-1, 1], [-1, -1]]:
    circle = start + [0]*(n-2)
    for i in range(1,n-1):
        circle[i+1] = circle[i]*s[i]*circle[i-1]
    # 最後があっているかどうかの確認
    if circle[-2] == circle[-1]*s[-1]*circle[0] and circle[-1] == circle[0]*s[0]*circle[1]:
        flag = True
        break
if flag:
    ans = ""
    for i in circle:
        if i == 1:
            ans += "S"
        else:
            ans += "W"
    print(ans)
else:
    print(-1)

Measured memory_bytes: 6244
# solution

import io
import math

nim,mike = map(int,input().split())

array = [list(map(int,input().split())) for l in range(10)]

are = []

counter = 0

for _ in range(nim):
    are.extend(list(map(int,input().split())))

for k in range(10):
    for i in range(10):
        for j in range(10):
            if array[i][j] > array[i][k]+array[k][j]:
                array[i][j] = array[i][k]+array[k][j]

for sa in are:
    if sa != -1:
        counter += array[sa][1]

print(counter)

Measured memory_bytes: 3508
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

N,X =[int(x) for x in input().split()]

Llist = [int(x) for x in input().split()]

count = 1
pos = 0
for i in Llist:
    pos += i
    if pos > X:
        print(count)
        break
    count += 1

if count == N+1:
    print(count)
        




Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int sum[100000000];
int num[100000000];
bool fib(int n)
{
    if (n <= 1)
        return n;
    return fib(n-1) + fib(n-2);
}
long long int modpow(long long int x,long long int n,long long int m)
{
    if(n==0)
        return 1%m;
    long long int u=modpow(x,n/2,m);
    u=(u*u)%m;
    if(n%2==1)
    {
        u=(u*x)%m;
    }
    return u;
}
void build(int at,int L,int R)
{
    sum[at]=0;
    if(L==R)
    {
        sum[at] = num[L];
        return;
    }
    int mid=(L+R)/2;
    build(at*2,L,mid);
    build(at*2+1,mid+1,R);
    sum[at]=sum[at*2]+sum[at*2+1];
}
int query(int at,int L,int R,int l,int r)
{
    if(r<L || R<l)
        return 0;
    if(l<=L && R<=r)
        return sum[at];
    int mid=(L+R)/2;
    int x=query(at*2,L,mid,l,r);
    int y=query(at*2+1,mid+1,R,l,r);
    return x+y;
}


int main()
{
  string s;
  cin>>s;
  set<char>ar;
  ar.insert(s[0]);
  ar.insert(s[1]);
  ar.insert(s[2]);
  if(ar.count('7')==1)
  {
      cout<<"Yes"<<endl;
  }
  else cout<<"No"<<endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
using namespace std;
 
int dp[3001][3001];     // large for stack
int flag[3001][3001];

int main()
{
    string s,t;
    cin >> s >> t;
    for(int i=0; i<s.size(); i++){
        for(int j=0; j<t.size(); j++){
            if (s[i] == t[j]){
                dp[i+1][j+1] = dp[i][j] + 1;
                flag[i+1][j+1] = 0;
            }else if(dp[i+1][j] < dp[i][j+1]){
                dp[i+1][j+1] = dp[i][j+1];
                flag[i+1][j+1] = 1;
            }else{ 
                dp[i+1][j+1] = dp[i+1][j];
                flag[i+1][j+1] = -1;
            }
        }
    }    
    
    string ans = "";
    int si = s.size();
    int ti = t.size();
    
    while(si > 0 && ti > 0){
        if(flag[si][ti] == 0){
            ans += s[si-1];
            si--;
            ti--;
        }else if(flag[si][ti] == 1){
            si--;
        }else{
            ti--;
        }
    }
    
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t x,i;
  bool f;
  cin>>x;
  vector<int64_t> p;
  p.push_back(2);
  for(i=3;i<=100003;i+=2){
    f=true;
    for(auto j:p){
      if(i%j==0){
        f=false;
        break;
      }
    }
    if(f==true) {
      p.push_back(i);
      if(x<=i) break;
    }
  }
  if(x==2) cout<<x<<endl;
  else cout<<i<<endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

ll h, w;
int n;
int a[100010], b[100010];
unordered_set<P, pairhash> memo;

int count(int x, int y) {
    int res = 0;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            res += memo.count(make_pair(x+i, y+j));
        }
    }
    return res;
}

void solve() {
    ll res[10];
    memset(res, 0, sizeof(res));
    res[0] = (h - 2) * (w - 2);

    for (int i = 0; i < n; i++) {
        for (int dx = -2; dx <= 0; dx++) {
            for (int dy = -2; dy <= 0; dy++) {
                int X = a[i] + dx, Y = b[i] + dy;
                if (0 <= X && X < h-2 && 0 <= Y && Y < w-2) {
                    int c = count(X, Y);
                    res[c]--;
                    res[c+1]++;
                }
            }
        }
        memo.insert(make_pair(a[i], b[i]));
    }
    
    for (int i = 0; i < 10; i++)
        cout << res[i] << endl;
}

void input() {
    cin >> h >> w >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
}

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

    input();
    solve();
}


Measured memory_bytes: 5156
import itertools

A = []
A1 = [int(i) for i in input().split()]
A.append(A1)
A2 = [int(i) for i in input().split()]
A.append(A2)
A3 = [int(i) for i in input().split()]
A.append(A3)

f = [[0] * 3 for i in range(3)]

#print(A)


N = int(input ())
b = [input().split() for i in range(N)]
b= list(itertools.chain.from_iterable(b))
b = list(map(int, b))

for i in range(3):
    for j in range(3):
        for x in b:
            if A[i][j] == x:
                f[i][j] = 1
s = 0

for i in range(3):
    if sum(f[i]) == 3:
        s = 1
    if f[0][0] + f[1][1] + f[2][2] == 3:
        s = 1
    if f[0][2] + f[1][1] + f[2][0] == 3:
        s = 1
    for j in range(3):
        if f[0][j] + f[1][j] + f[2][j] == 3:
            s = 1
        
                
        
if s == 1:
    print("Yes")
else:
    print("No")




Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; ll k; cin >> n >> k;
  vector<int> P(n);
  rep(i, n) {
    cin >> P[i];
    P[i]--;
  }
  vector<ll> C(n); rep(i, n) cin >> C[i];
  vector<bool> vis(n);
  vector<vector<int>> path;
  auto dfs = [&](auto dfs, int cur) {
               if(vis[cur]) return;
               vis[cur] = true;
               path.back().push_back(cur);
               dfs(dfs, P[cur]);
             };
  rep(i, n) {
    if(!vis[i]) {
      path.push_back(vector<int>());
      dfs(dfs, i);
    }
  }
  auto func = [&](vector<int>& path) {
                int n = path.size();
                ll sum = 0;
                rep(i, n) sum += C[path[i]];
                vector<vector<ll>> mx(n, vector<ll>(2*n+1));
                rep(i, n) rep(j, 2*n) {
                  mx[i][j+1] = mx[i][j] + C[path[(i+j)%n]];
                }
                if(sum < 0 || k < n) {
                  ll ans = -longinf;
                  rep(i, n) REP(j, 1, min(k+1, (ll)n+1)) {
                    ans = max(mx[i][j], ans);
                  }
                  return ans;
                } else {
                  ll ans = -longinf;
                  rep(i, n) rep(j, k%n+n+1) {
                    ans = max(mx[i][j], ans);
                  }
                  ans += sum * (k/n-1);
                  return ans;
                }
              };
  ll ans = -longinf;
  for(auto& ele: path) {
    ans = max(func(ele), ans);
  }
  cout << ans << endk;
  return 0;
}


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

int main()
{
    int n,i,j;
    cin >> n;
    int arr[n];
    
    for (i=0 ;i< n; i++){
        cin >> arr[i];
    }
    
    int ans=100000000;
    
    for(int i = 1; i <= 100; i++) {
    int cost = 0;
    for (j=0;j<n ;j++)
        cost += (arr[j] - i) * (arr[j] - i);
    ans = min(ans, cost);
}

    
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
from collections import deque

n=int(input())
A=deque(list(map(int,input().split())))

while len(A)>1:
    a=A.popleft()
    for _ in range(len(A)):
        aa=A.popleft()
        if aa%a>0:
            A.append(aa%a)
    A.append(a)

print(A[0])

Measured memory_bytes: 96152
#include <bits/stdc++.h>
#define forn(i,b) for(int i=0 ; i< b ;i++)
#define for1(i,b) for(int i=1 ; i<=b ;i++)
#define reps(i,a,b) for(int i=a ; i< b.length() ;i++)
typedef long long ll;
#define MOD 1000000007

using namespace std;




int main()
{
  int a,b;
  cin >> a >> b ;
  if (a>9 || b>9)cout << "-1";
  else
    cout << a*b ;


  return 0 ;
}


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

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

// Graph
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  for (auto &it : p)
    cin >> it;
  sort(p.begin(), p.end());
  int ans = 0;
  for (int i = 0; i < K; i++)
    ans += p[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3648
N, K = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(N)]
cds = [K]
b = 0
for i in range(30)[::-1]:
    if K&(1<<i):
        cds.append(b + (1<<i) - 1)
        b += (1<<i)

ans = 0
for k in cds:
    buf = 0
    for i, j in l:
        if i|k==k:
            buf += j
    ans = max(ans, buf)
print(ans)


Measured memory_bytes: 22556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b,c;
    cin >> a >> b >> c;
    int maxnum = max(max(a,b), c);
    int tmp = 3 * maxnum - (a+b+c);
    if (tmp%2 == 0)
    {
        cout << tmp / 2 << endl;
    }
    else
    {
        cout << (tmp+3)/2 << endl;
    }
    
}


Measured memory_bytes: 256
s = list(input())
count = 0
check = 1
tmp = '0'
for i in s:
    if check == 1:
        if tmp == i:
            tmp = i
            check = 2
        else:
            tmp = i
            check = 1
            count += 1
    elif check == 2:
        tmp = '0'
        check = 1
        count += 1
print(count)

Measured memory_bytes: 4840
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
  bool error[10][10];
  int puzzle[10][10];
  
  int T;
  cin >> T;
  while(T--){
    for(int i = 0 ; i < 9 ; i++){
      for(int j = 0 ; j < 9 ; j++){
	cin >> puzzle[i][j];
      }
    }
    
    memset(error, 0, sizeof(error));
    int check1[10];
    int check2[10];
    
    for(int i = 0 ; i < 9 ; i++){
      memset(check1, 0, sizeof(check1));
      memset(check2, 0, sizeof(check2));
      for(int j = 0 ; j < 9 ; j++){
	check1[puzzle[i][j]]++;
	check2[puzzle[j][i]]++;
	
	if(check1[puzzle[i][j]] >= 2){
	  for(int k = 0 ; k < 9 ; k++){
	    if(puzzle[i][k] == puzzle[i][j]) error[i][k] = true;
	  }
	}
	
	if(check2[puzzle[j][i]] >= 2){
	  for(int k = 0 ; k < 9 ; k++){
	    if(puzzle[k][i] == puzzle[j][i]) error[k][i] = true;
	  }
	}
	
      }
    }

    for(int k = 0 ; k < 9 ; k+=3){
      for(int l = 0 ; l < 9 ; l+=3){
	memset(check1, 0, sizeof(check1));
	memset(check2, 0, sizeof(check2));
	for(int i = k ; i < k+3 ; i++){
	  for(int j = l ; j < l+3 ; j++){
	    check1[puzzle[i][j]]++;
	    if(check1[puzzle[i][j]] >= 2){
	      for(int _i = k ; _i < k+3 ; _i++){
		for(int _j = l ; _j < l+3 ; _j++){
		  if(puzzle[i][j] == puzzle[_i][_j]) error[_i][_j] = true;
		}
	      }
	    }
	  }
	}
      }
    }
    
    for(int i = 0 ; i < 9 ; i++){
      for(int j = 0 ; j < 9 ; j++){
	cout << ((error[i][j]) ? '*' : ' ') << puzzle[i][j];
      }
      cout << endl;
    }
    if(T)cout << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import numpy as np
h,w = map(int, input().split())
a = [list(input()) for i in range(h)]
a = np.array(a)
for hi in range(h):
    for wi in range(w):
        c = 0
        if a[hi][wi] == "#":
            print('#',end='')
        else:
            print(np.count_nonzero(a[max(0,hi-1):hi+2,max(0,wi-1):wi+2] == "#"),end='',)
    print()

Measured memory_bytes: 12880
#include <algorithm>
#include <bitset>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
inline char tc() {
    static char fl[100], *A = fl, *B = fl;
    return A == B && (B = (A = fl) + fread(fl, 1, 100, stdin), A == B) ? EOF
                                                                       : *A++;
}
inline int intread() {
    int a = 0;
    static char c;
    c = tc();
    while (c & 16) a = a * 10 + c - 48, c = tc();
    return a;
}
inline ll llread() {
    ll a = 0;
    static char c;
    c = tc();
    while (c & 16) a = a * 10 + c - 48, c = tc();
    return a;
}

static const int buf_size = 4096;
static int write_pos      = 0;
static char write_buf[buf_size];

inline void writeChar(ll x) {
    if (write_pos == buf_size)
        fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
    write_buf[write_pos++] = x;
}
inline void write(ll x, char end) {
    char s[24];
    int n = 0;
    while (x || !n) s[n++] = '0' + x % 10, x /= 10;
    while (n--) writeChar(s[n]);
    if (end) writeChar(end);
}
struct Flusher {
    ~Flusher() {
        if (write_pos) fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
    }
} flusher;

int X, Y, Z, K;
ll A[1000], B[1000], C[1000], ABC[1000000];
int main() {
    X = intread(), Y = intread(), Z = intread(), K = intread();
    rep(i, X) A[i] = llread();
    rep(i, Y) B[i] = llread();
    rep(i, Z) C[i] = llread();
    sort(A, A + X, greater<ll>());
    sort(B, B + Y, greater<ll>());
    sort(C, C + Z, greater<ll>());
    int cnt = 0;
    rep(a, X) {
        rep(b, Y) {
            if ((a + 1) * (b + 1) > K) break;
            rep(c, Z) {
                if ((a + 1) * (b + 1) * (c + 1) > K) break;
                ABC[cnt++] = (A[a] + B[b] + C[c]);
            }
        }
    }
    sort(ABC, ABC + cnt, greater<ll>());
    rep(i, K) { write(ABC[i], '\n'); }
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
using namespace std;

int main(){
    int N;
    cin >> N;
    vi(a,N);
    rep(i,N) cin >> a.at(i);
    srt(a);
    long long ans = 4000000;
    rng(i, a.at(0), a.at(N-1)+1){
        long long sum=0;
        rep(j,N){
            sum += pow(a.at(j)-i,2);
        }
        ans = min(sum,ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
#define N 100'000
ll cnt[N+1] = {};
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    ll k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        cnt[a] += b;
    }
    ll seen = 0;
    for(int i = 1; i <= N; i++) {
        seen += cnt[i];
        if(seen >= k) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
        long long int n; cin >> n;
        string s = "abcdefghijklmnopqrstuvwxyz";
        vector<long long int> v;
        while (n > 0){
            n--;
            v.push_back(n%26);
            n /= 26;
        }
        for (long long int x = v.size()-1; x >= 0; --x){
            cout << s[v[x]];
        }
    return 0;
}



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

using namespace std;

int main(){

	int A,B;
	cin >> A >>B;

	if( A%3==0 || B%3==0 || (A+B)%3==0 ){
		cout <<"Possible" <<endl;
	}

	else{
		cout <<"Impossible" <<endl;
	}
}

Measured memory_bytes: 3516
#include<bits/stdc++.h>
using namespace std;
#define gc getchar
#define gcu getchar_unlocked
#define pc(x) putchar(x);
#define pcu(x) putchar_unlocked(x);
#define ll long long int
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

ll gcd(ll a, ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}

void readint(ll &x)
    {
        bool neg=false;
        ll c;
        x =0;
        c=gc();
        if(c=='-')
        {
            neg = true;
            c=gc();
        }
        for(;(c>47 && c<58);c=gc())
            x = (x<<1) + (x<<3) +c -48;
        if(neg)
            x *=-1;
    }

inline void writeInt (ll n)
{
    ll N = n, rev, count = 0;
    rev = N;
    if (N == 0) { pc('0'); pc('\n'); return ;}
    if (N*(-1)>0){pc('-');rev=rev*(-1);N=N*(-1);}
    while ((rev % 10) == 0) { count++; rev /= 10;}
    rev = 0;
    while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10;}
    while (rev != 0) { pc(rev % 10 + '0'); rev /= 10;}
    while (count--) pc('0');
}
int main()
{
  SPEED;
  ll n,k;
   cin>>n>>k;
   char a[n+1];
   cin>>a;
   a[k-1]=a[k-1]+32;
   cout<<a;


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	if (a > 0){
		cout << (b - a) * e;
	}
	else{
		cout << (0 - a) * c + d + b * e;
	}
	cout << endl;
}

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

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

    int c=a+b, d=a*b, e=a-b;

    if(c>d && c>e)
        cout<<c;
    else if(d>c && d>e)
        cout<<d;
    else
        cout<<e;


}


Measured memory_bytes: 256
N = int(input())
P = [int(i) for i in input().split()]

count = 0
for i in range(N):
  if P[i] == i+1:
    if i+1 != N:
      P[i],P[i+1] = P[i+1],P[i]
    else:
      P[i],P[i-1] = P[i-1],P[i]
    count += 1
print(count)



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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

ll kai(ll i)
{
    if(i == 2) return 1;
    else return kai(i-1) + i - 1;
}

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

    vector<string> s(N);
    rep(i,N) cin >> s[i];
    rep(i,N) sort(all(s[i]));
    sort(all(s));
    ll ans = 0;
    ll tmp = 0;

    rep(i,N-1)
    {
        if(s[i] == s[i+1])tmp++;
        else
        {
            if(tmp != 0)ans += kai(tmp+1);
            tmp = 0;
        }
    }
    if(tmp != 0)
    {
        ans += kai(tmp+1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int R, G; cin >> R >> G;
  auto ans = G*2 - R;
  cout << ans << CRLF;
  
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Product
            var line = ReadLine();
            int a = line[0];
            int b = line[1];

            if (a * b % 2 == 0)
            {
                Console.WriteLine("Even");
            }
            else
            {
                Console.WriteLine("Odd");
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 11220