akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;

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

	int d, g, p[10], c[10];
	cin >> d >> g;
	for(int i = 0;i < d;i++) cin >> p[i] >> c[i];

	int ans = 2000000000;
	for(int i = 0;i < pow(2, d);i++){
		int a = i;
		int pts = 0, cnt = 0;
		bool used[10] = {0};
		for(int j = 0;j < d;j++){
			if(a % 2 != 0){
				pts += 100*(j+1)*p[j] + c[j];
				cnt += p[j];
				used[j] = 1;
			}
			a /= 2;
		}

		if(pts >= g){
			if(ans > cnt) ans = cnt;
		} else {
			for(int j = d-1;j >= 0;j--){
				if(used[j]) continue;
				if(pts + 100*(j+1)*(p[j]-1) < g){
					pts += 100*(j+1)*(p[j]-1);
					cnt += p[j];
					continue;
				} else {
					while(pts < g){
						pts += 100*(j+1);
						cnt++;
					}
					break;
				}
			}
			if(ans > cnt) ans = cnt;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int h=sc.nextInt();
        int w=sc.nextInt();
        boolean[][]nums=new boolean[h+1][w+1];
        String tmp;
        for(int i=0;i<h;i++){
            tmp=sc.next();
            for(int j=0;j<w;j++){
                nums[i][j]=tmp.charAt(j)=='.';
            }
        }
        int[][] hs=new int[h+1][w];
        int[][] ws=new int[h][w+1];
        int begin;
        int length;
        for(int i=0;i<h;i++){
            begin=-1;
            length=0;
            for(int j=0;j<w+1;j++){
                if(nums[i][j]){
                    if(begin==-1)begin=j;
                    length++;
                }else{
                    for(int k=begin;k<begin+length;k++){
                        ws[i][k]=length;
                    }
                    begin=-1;
                    length=0;
                }
            }
        }
        for(int i=0;i<w;i++){
            begin=-1;
            length=0;
            for(int j=0;j<h+1;j++){
                if(nums[j][i]){
                    if(begin==-1)begin=j;
                    length++;
                }else{
                    for(int k=begin;k<begin+length;k++){
                        hs[k][i]=length;
                    }
                    begin=-1;
                    length=0;
                }
            }
        }
        int ans=0;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                ans=Math.max(hs[i][j]+ws[i][j],ans);
            }
        }
        System.out.println(ans-1);
    }
}

Measured memory_bytes: 82352
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N,K,ans=0;
  string S;
  cin>>N>>K>>S;
  for(int i=1;i<N;i++)
    if(S[i-1]!=S[i])
      ans++;
  ans-=K*2;
  cout<<N-max(0LL,ans)-1<<endl;
}

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

struct P
{
    int x,y;

    bool operator<(const P &a)const{
        if(x!=a.x) return x>a.x;
        return y<a.y;
    }
};


vector<int> v[11111];
vector<int> v1;
//bitset<4001000> b;
int i,n,m,k,a,d,b,c;
int e;
int o[11112];
int l[11111];
int j[11131];

int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
int px[10]={-1,1,1,-1,1,1,-1,-1},py[10]={1,1,-1,-1,1,-1,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[1];
stack<int> s;
//set<int> se[33],s1;

//priority_queue<P> q[2];
queue<int> q;
string r,r1;

//char r1[110],r[331];
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
map<int,int> p;
//v.resize(unique(v.begin(),v.end())-v.begin());

bool as(P a,P b)
{
    //if(a.x!=b.x)
    return a.x<b.x;

}


//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//rng();



int main()
{
    scanf("%d",&a);
    for(int t=1;t<a;t++)
    {
        scanf("%d %d",&n,&m);
        v[n].push_back(m);
        v[m].push_back(n);
    }
    for(int t=1;t<=a;x+=o[t],t++)
        scanf("%d",&o[t]);
    sort(o+1,o+a+1);
    x-=o[a];
    printf("%lld\n",x);
    for(int t=1;t<=a;t++)
    if(v[t].size()==1)
        q.push(t);
    for(;q.size();q.pop())
    {
        for(int h=0;h<v[q.front()].size();h++)
        {
            l[v[q.front()][h]]++;
            if(v[v[q.front()][h]].size()-l[v[q.front()][h]]==1)
            {
                q.push(v[q.front()][h]);
            }
        }
        d++;
        j[q.front()]=o[d];
    }
    for(int t=1;t<=a;t++)
        printf("%d ",j[t]);
}




Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

using namespace std;
typedef long long int64;

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  
  int n;
  string s;
  cin>>n>>s;
  
  for(int i=0;i<s.size();i++){
    for(int j=0;j<n;j++){
      s[i]++;
      if(s[i]>'Z') s[i]='A';
    }
  }
  
  cout<<s<<endl;



  return 0;
}

Measured memory_bytes: 256
import math

n,d = map(int,input().split())
x_inputs = [[int(j) for j in input().split()]for i in range(n)]

ans = 0
for i in range(n):
    for j in range(i+1,n):
        dist = math.sqrt(sum([(i-j)**2 for i,j in zip(x_inputs[i],x_inputs[j])]))
        #print(i,j,dist)
        if dist%1==0 and dist>0:
            ans+=1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  string s;
  cin>>s;
  vector<int> tmp(3);
  for (char i = 'a'; i <= 'c' ; ++i)
  {
    for(auto&& e: s) {
      if(e==i) tmp[i-'a']++;
    }
  }
  int all=s.size()/3;
  int amari=s.size()%3;
  for(auto&& e: tmp) {
    if(e<all) {
      cout<<"NO";
      return 0;
    }
    e-=all;
  }
  set<int> st;
  for (int i = 0; i < 3; ++i)
  {
    if(tmp[i]>0) st.insert(i);
  }
  if(st.size()!=amari){
    cout<<"NO";
    return 0;
  }
  cout<<"YES";
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>

using namespace std;

const double eps = 1e-10;

class Vector
{
public:
  double x;
  double y;

  Vector(){}
  Vector( double x, double y ) : x(x), y(y) {}

  Vector operator + ( const Vector v ) { return Vector( x + v.x, y + v.y ); }
  Vector operator - ( const Vector v ) { return Vector( x - v.x, y - v.y ); }
  Vector operator * ( const double k ) { return Vector( x * k, y * k ); }
  Vector operator / ( const double k ) { return Vector( x / k, y / k ); }
  bool operator < ( const Vector &v ) const { return x * x + y * y < v.x * v.x + v.y * v.y; }

  double abs() { return sqrt( norm() ); }
  double norm() { return x * x + y * y; }

  static double dot( Vector v1, Vector v2 ) { return v1.x * v2.x + v1.y * v2.y; }
  static double cross( Vector v1, Vector v2 ) { return v1.x * v2.y - v1.y * v2.x; }
};

int main()
{
  double x1, y1, x2, y2;

  cin >> x1 >> y1 >> x2 >> y2;

  Vector p1( x1, y1 );
  Vector p2( x2, y2 );

  Vector a = p2 - p1;

  int q;
  cin >> q;

  double x, y;

  for ( auto i = 0; i < q; ++i )
    {
      cin >> x >> y;
      Vector b = Vector( x, y ) - p1;
      
      Vector pr = a * Vector::dot( a, b ) / a.norm();

      Vector rf = pr * 2 - b + p1;

      cout << fixed << setprecision(10) << rf.x << " " << rf.y << endl;
    }
  
  return 0;
}

Measured memory_bytes: 1296
import heapq
import sys
sys.setrecursionlimit(10 ** 7)

class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]
		self.count = 0

#	def find(self, x):
#		while self.table[x] >= 0:
#			x = self.table[x]
#		return x

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

	def union(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
			elif self.table[s1] < self.table[s2]:
				self.table[s1] = s2
			else:
				self.table[s1] = s2
				self.table[s2] -= 1

			self.count += 1
			return True
		return False

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

vx = sorted(x, key=lambda x: x[1])
vy = sorted(y, key=lambda x: x[1])

edges = []
uf = UnionFind(n)

for i in range(n - 1):
	if vx[i][1] == vx[i + 1][1]:
		uf.union(vx[i][0], vx[i + 1][0])
	else:
		heapq.heappush(edges, (vx[i + 1][1] - vx[i][1], vx[i][0], vx[i + 1][0]))

	if vy[i][1] == vy[i + 1][1]:
		uf.union(vy[i][0], vy[i + 1][0])
	else:
		heapq.heappush(edges, (vy[i + 1][1] - vy[i][1], vy[i][0], vy[i + 1][0]))


#edges = sorted(edges, key=lambda x: x[2], reverse=True)
#print(edges)

ans = 0

while edges != []:
	e = heapq.heappop(edges)
	if uf.union(e[1], e[2]):
		ans += e[0]
	if uf.count == n - 1:
		break

print(ans)

Measured memory_bytes: 82352
N, M = map(int, input().split())
A = list(map(int, input().split()))
F = 0
trigger = 1 / (4 * M)
 
for i in range(len(A)):
    if A[i]/sum(A) < trigger:
        F = F + 1
        
if N - F >= M:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define rep(i, n)           for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b)        for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a)           for (auto &i : a)
#define ALL(obj)            begin(obj), end(obj)
#define MAX(x)              *max_element(ALL(x))
#define MIN(x)              *min_element(ALL(x))
#define SUM(x)              accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = (int)(1e9 + 7);
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int a, int b) {                                                             //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}

#define MAX_ 2000000
int inv_list[MAX_]; //inv_list[i-1] = inverse of i
int fac[MAX_];
int finv[MAX_];
void nCk_init() {
  inv_list[0] = fac[0] = finv[0] = 1;
  for (int i = 0; i < MAX_ - 1; i++) {
    inv_list[i + 1] = MOD - ((inv_list[(MOD % (i + 2)) - 1] * (MOD / (i + 2))) % MOD);
    fac[i + 1]      = (fac[i] * (i + 2)) % MOD;
    finv[i + 1]     = (finv[i] * inv_list[i + 1]) % MOD;
  }
}
int nCk(int n, int k) {
  if (n == k or k == 0) return 1;
  return (fac[n - 1] * ((finv[k - 1] * finv[n - k - 1]) % MOD)) % MOD;
}

class FStrivore {
public:
  static void solve(istream &cin, ostream &cout) {
    int K;
    string S;
    cin >> K >> S;
    nCk_init();
    int ans = 0;
    rep(i, K + 1) {
      ans += mod(nCk(S.size() + i - 1, S.size() - 1) * bpm(25, i), MOD) * bpm(26, K - i);
      ans = mod(ans, MOD);
    }
    cout << ans << endl;
  }
};


signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  FStrivore solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

using namespace std;

long long gcd(vector<long long> &a) {

	//ユークリッドの互除法で最大公約数を求める
	//多変数の場合

	long long x = a[0];
	long long y = a[1];
	for (long long i = 1; i < (long long)a.size(); i++) {
		y = a[i];
		if (x < y) { swap(x, y); }
		while (x%y != 0) {
			long long r;
			r = x % y;
			if (r == 0) { 
				break;
			}
			else {
				x = y;
				y = r;
			}
		}
		x = y;
	}
	return y;
}


int main() {

	long long n, xx;
	cin >> n >> xx;

	if (n == 1) {
		long long yy;
		cin >> yy;
		cout << abs(yy-xx) << endl;
	}
	else {
		vector<long long> x(n, (long long)0);
		for (long long i = 0; i < n; i++) {
			cin >> x[i];
			x[i] = (long long)abs(x[i] - xx);
		}

		cout << gcd(x) << endl;
	}
}


Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <iterator>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <cmath>

#define YESNO(x) x ? printf("YES") : printf("NO")
#define YesNo(x) x ? printf("Yes") : printf("No")
#define scani(x) scanf("%d", &x)
#define printi(x) printf("%d", x)

using namespace std;

//ABC087C - Candies
int Main() {
	int ans;
	int n;
	vector<vector<int>> a;

	scani(n);
	a.resize(2);
	for (auto& col : a) {
		col.resize(n);
		for (auto& x : col)
			scani(x);
	}

	//check
	for (int branch = 0; branch < n; branch++) {
		//1try
		int y = 0;
		int score = 0;
		for (int x = 0; x < n || y == 0; x++) {
			score += a[y][x];
			if (x == branch) {
				y++;
				score += a[y][x];
			}
		}
		ans = max(score, ans);
	}

	cout << ans;

	return 0;
}

int main()
{
	Main();
	return 0;
}

Measured memory_bytes: 256
//%std
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out = 0, fh = 1;
	char jp = getchar();
	while ((jp > '9' || jp < '0') && jp != '-')
		jp = getchar();
	if (jp == '-')
		fh = -1, jp = getchar();
	while (jp >= '0' && jp <= '9')
		out = out * 10 + jp - '0', jp = getchar();
	return out * fh;
}
int main()
{
	int S = read(), W = read();
	puts(W >= S ? "unsafe" : "safe");
	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 100000
#define  MOD  998244353
const int mod=1e9+7;
#define tezz std::ios::sync_with_stdio(false);std::cin.tie(NULL);std::cout.tie(NULL);
#define ull unsigned long long
#define pb push_back
#define vll vector<ll>
int main(){
        long long int s,w;
        cin>>s>>w;
        if(s<=w) cout<<"unsafe\n";
        else cout<<"safe\n";
        return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
char c[4];
signed main(){
    cin>>c[0]>>c[1]>>c[2]>>c[3];
    sort(c,c+4);
    if(c[0]==c[1]&&c[2]==c[3]&&c[1]!=c[2])puts("Yes");
    else puts("No");
    return 0;
}



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

using namespace std;

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

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

	return 0;
}


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

#define ll long long

int main(){

    int N;
    int i,j,k,l;
    int count=0,count_n=0,count_m=0;
    bool flag = false;
    int ans=0;
    string S;
    int max=0;

    cin >> N;
    cin >> S;

    for(i=1;i<N;i++){

    vector<int> s_ascii(26);

        for(j=0;j<i;j++){
            if(s_ascii.at( (int)S.at(j)-'a') != 1 ) s_ascii.at( (int)S.at(j)-'a' ) = 1;
        }

        for(k=i;k<N;k++){

            if( s_ascii.at( (int)S.at(k) - 'a' ) ){
                s_ascii.at( (int)S.at(k) - 'a' ) = 0;
                count ++;
            }
        }

        if(max < count)max = count;
        count = 0;

    }

    cout << max << endl;
    
    return 0;

}

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

int main()
{
  int n, h;
  cin >> n >> h;
  vector<int> a(n), b(n);
  for (auto i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  int max_swing = *max_element(begin(a), end(a));
  sort(begin(b), end(b), greater<>());
  int count = 0;
  for (auto&& e : b) {
    if (e > max_swing) {
      count++;
      h -= e;
      if (h <= 0) break;
    }
  }
  if (h > 0) {
    count += h / max_swing;
    if (h % max_swing != 0) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main(){
char c[12];
int a,b;
cin>>a>>b>>c;
int count=0;
for(int i=0;i<a;i++){
if(c[i]<=57 && c[i]>=48) count++;
}
if(c[a]=='-') count++;
for(int i=0;i<b;i++){
if(c[i+a+1]<=57 && c[i+a+1]>=48) count++;
}
if(count==a+b+1) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{
    int time;
    int min_time = 0;
    int min_amari = 10;
    bool flag = false;
    for(int i=0; i<5; i++){
        scanf("%d", &time);
        int amari = time % 10;
        min_time += (amari == 0) ? time : time + 10 - amari; 
        if(amari != 0 && amari < min_amari){
            flag = true;
            min_amari = amari;
        }
    }
    min_time += (flag == true) ? min_amari - 10 : 0;
    printf("%d\n", min_time);
    return 0;
}


Measured memory_bytes: 128
n,w=map(int,input().split())
P=[]
for _ in range(n):
  iw,iv=map(int,input().split())
  P.append([iw,iv])
INF=float('inf')

dp=[[0 for i in range(w+1)] for j in range(n+1)]

for i in range(1,n+1):
  for j in range(1,w+1):
    if j-P[i-1][0]>=0:
      dp[i][j]=max(dp[i-1][j],dp[i-1][j-P[i-1][0]]+P[i-1][1])
    else:
      dp[i][j]=dp[i-1][j]
print(dp[n][w])

Measured memory_bytes: 217780
def main():
    n = int(input())
    m = []

    for _ in range(n):
        row = [int(s) for s in input().split()]
        m.append(row)
    
    print(solve(m))

def solve(m):
    dp = [0, 0, 0]

    for row in m:
        dp = [
            max(dp[1], dp[2]) + row[0],
            max(dp[0], dp[2]) + row[1],
            max(dp[0], dp[1]) + row[2],
        ]
    
    return max(dp)

main()


Measured memory_bytes: 24304
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string a, b, c;
  	cin >> a >> b >> c;
  	if ((a[a.size() - 1] == b[0]) && (b[b.size() - 1] == c[0])){
    	cout << "YES";
    } else {
    	cout << "NO";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<pair<int,int>> a(n);
  for (int i; i<n; i++){
    int num;
    cin >> num;
    a[i] = make_pair(num,i);
  }
  sort(a.begin(),a.end());
  for (int i; i<n; i++){
    cout << a[i].second + 1 << endl;
  }
}

Measured memory_bytes: 1664
N=int(input())
n=list(map(int,input().split()))
if N >= 2:
    a=sorted(n)
    if (a[N-1]-a[0])%2 == 0:
        print((a[N-1]-a[0])//2)
    else:
        print((a[N-1]-a[0]+1)//2)
elif N == 1:
    print(0)


Measured memory_bytes: 5620
<?php

$cnt = 1;
$base;
$num;
while ( ! feof(STDIN) ) {
  $line = trim(fgets(STDIN));

  if ($cnt == 1) {
      $base = split(" ",$line);
      $cnt++;
  } else {
      $num = split(" ",$line);
      break;
  }
}
rsort($num);

$sum = 0;
for ($i = 0; $i < $base[1]; $i++) {
    $sum += $num[$i];
}
echo $sum;
?>

Measured memory_bytes: 3700
import java.io.*;
import java.util.*;

public class Main {
	public static void main (String [] args){
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		int c = a * b;
		if(c % 2 == 0)
			System.out.println("Even");
		else
			System.out.println("Odd");
	}
}

Measured memory_bytes: 20820
using System;
using System.Linq;
public class Hello{
    public static void Main(){
        var n = int.Parse(Console.ReadLine());
        var array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var memo = new int[100002];
        var max = 0;
        var dx = new int[]{-1,0,1};
        for(var i = 0;i < n;i++){
            for(var j = 0;j < 3;j++){
                if(array[i] + dx[j] > 0) memo[array[i] + dx[j]]++; 
            }
        }
        
        Console.WriteLine(memo.Max());
        
    }
}


Measured memory_bytes: 18528
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int N, K;
	cin >> N >> K;
	K--;

	vector<int> height(N, 0);

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

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

	int min_value = height.back();

	for (int i = 0; i < N - K; i++)
	{
		int min_idx = i;
		int max_idx = i + K;

		min_value = min(min_value, height[max_idx] - height[min_idx]);
	}

	cout << min_value;
	
	return 0;
}


Measured memory_bytes: 3692
#include <iostream>
#include <vector>
#include <queue>
#include <string>

using namespace std;

struct Tag {
    int to;
    string str;

    Tag() {}
    Tag(int to, const string &str) : to(to), str(str) {}
};

struct Queue_Tag {
    string str;
    int pos;

    Queue_Tag() {}
    Queue_Tag(const string &str, int pos) : str(str), pos(pos) {}

    bool operator < (const Queue_Tag &other) const {
        return str > other.str;
    }
};

int main() {
    while(true) {
        int N, A, S, G;
        cin >> N >> A >> S >> G;
        if(!N && !A && !S && !G) break;

        vector<vector<Tag> > v(N);
        for(int i = 0; i < A; ++i) {
            Tag t;
            int x;
            cin >> x >> t.to >> t.str;
            v[x].push_back(t);
        }

        vector<vector<string> > dp(N, vector<string>(6*2*N+1));
        vector<vector<int> > visited(N, vector<int>(6*2*N+1, 0));
        dp[S][0] = "";

        priority_queue<Queue_Tag> q;
        q.push(Queue_Tag("", S));
        while(!q.empty()) {
            const Queue_Tag qt = q.top();
            q.pop();

            if(visited[qt.pos][qt.str.size()]) continue;
            visited[qt.pos][qt.str.size()] = 1;
            dp[qt.pos][qt.str.size()] = qt.str;

            for(int i = 0; i < v[qt.pos].size(); ++i) {
                const Tag &t = v[qt.pos][i];
                const string next = qt.str + t.str;
                if(next.size() > 6*2*N) continue;
                if(visited[t.to][next.size()]) continue;
                q.push(Queue_Tag(next, t.to));
            }
        }

        string ans = "NO";
        bool loop = false;
        bool found = false;
        for(int i = 0; i <= 6*2*N; ++i) {
            if(visited[G][i]) {
                if(i >= 6*N && found && dp[G][i] < ans) loop = true;
                if(found) ans = min(ans, dp[G][i]);
                else ans = dp[G][i];
                //cout << ans << endl;
                found = true;
            }
        }

        if(loop) cout << "NO" << endl;
        else cout << ans << endl;
    }

    return 0;
}

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

int main()
{
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    vector<int> copy(n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    copy = a;
    sort(copy.begin(), copy.end());
     reverse(copy.begin(), copy.end());

    for (int i = 0; i < n; i++)
    {
        if (a[i] == copy[0])
        {
            // printf("%d\n", copy[1]);
            cout<<copy[1]<<endl;
        }
        else
        {
            // printf("%d\n", copy[0]);
                      cout<<copy[0]<<endl;
        }
    }
}

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

int main()
{
	long long n, m;
	cin >> n >> m;
	vector<long long> av(n);
	long long sum = 0;
	for (auto& i : av) {
		cin >> i;
		sum += i;
		i *= 4 * m;
	}
	sort(av.rbegin(), av.rend());
	long long i = 0;
	for (; i < n; ++i) {
		if (av[i] < sum) {
			break;
		}
	}

	if (m <= i) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
while True:
    m, n_min, n_max = map(int, input().split())
    if m == 0:
        break
    gap_max = 0
    ans = 0
    pre = int(input())
    for i in range(1, m):
        next = int(input())
        if n_min <= i and n_max >= i:
            tmp = pre - next
            if tmp >= gap_max:
                gap_max = tmp
                ans = i
        pre = next
    print(ans)



Measured memory_bytes: 5616
#include <stdio.h>
#define MAX 100
#define INF (1<<22)

int G[MAX][MAX];
void SSSP(int);

int main(){
  int n,i,j,id,k,c,v;

  scanf("%d",&n);
  for(i = 0;i < n;i++){
    for(j = 0;j < n;j++){
      G[i][j] = INF;
    }
  }
  for(i = 0;i < n;i++){
    scanf("%d%d",&id,&k);
    for(j = 0;j < k;j++){
      scanf("%d%d",&v,&c);
      G[id][v] = c;
    }
  }
  /* //sita iranai kamo
  for(i = 0;i < k;i++) {
    for(j = 0;j < k;j++) {
      if(G[i][j] == 0) G[i][j] = INF;
    }
  }
  //*/
  SSSP(n);

  return 0;
}

void SSSP(int n){
  int i,j,hen,min,color[MAX],parent[MAX],weight[MAX];
  
  for(i = 0;i < n;i++){
    color[i] = 0;
    //  parent[i] = -1;
    weight[i] = INF;
  }
  weight[0] = 0;
  color[0] = 1;

  while(1){
    min = INF;
    hen = -1;
    for(i = 0;i < n;i++){
      if(color[i] != 2 && weight[i] < min){
        min = weight[i];
        hen = i;
      }
    }
    if(hen <= -1) break;
    color[hen] = 2;
    for(i = 0;i < n;i++){
      if(color[i] != 2 && G[hen][i] != INF){
        if(weight[i] > G[hen][i] + weight[hen]){
          color[i] = 1;
	  weight[i] = weight[hen] + G[hen][i];
        }
      }
    }
  }
  for(i = 0;i < n;i++){
    printf("%d ",i);
    if(weight[i] != INF) printf("%d\n",weight[i]);
    else printf("-1\n");
  }
}



Measured memory_bytes: 2104
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll N = 3;
  vector<vector<ll>> as(N, vector<ll>(N));
  for (auto i = 0; i < N; i++) {
    for (auto j = 0; j < N; j++) cin >> as[i][j];
  }

  bool correct = true;
  for (auto i = 0; i < N; i++) {
    for (auto j = i + 1; j < N; j++) {
      ll d0 = as[i][0] - as[j][0];
      ll d1 = as[i][1] - as[j][1];
      ll d2 = as[i][2] - as[j][2];

      ll d3 = as[0][i] - as[0][j];
      ll d4 = as[1][i] - as[1][j];
      ll d5 = as[2][i] - as[2][j];

      if (!(d0 == d1 && d0 == d2 && d3 == d4 && d3 == d5)) correct = false;
    }
  }

  cout << (correct ? "Yes" : "No") << endl;

  return 0;
}


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

int main(){
  string S, T, U;
  int A, B;
  
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  
  if(U==S){
    A--;
  }
  else{
    B--;
  }
  cout << A << ' ' << B << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define all(v) v.begin(),v.end()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, greater_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;

int sub[200001], cnt[200001], c[200001];
vi adj[200001], comp[200001];

int dfs(int node, int par) {
	sub[node] = 1;
	for (auto next : adj[node])
		if (next != par)
			sub[node] += dfs(next, node);
	return sub[node];
}

void dfs2(int node, int par) {
	int temp = cnt[c[node]];
	for (auto next : adj[node])
		if (next != par) {
			cnt[c[node]] = sub[next];
			dfs2(next, node);
			if (cnt[c[node]] > 0)
				comp[c[node]].pb(cnt[c[node]]);
		}
	cnt[c[node]] = temp - sub[node];
}

int main() {
	fast_io;
	int n;
	cin >> n;
	for (int i = 1;i <= n;i++)
		cin >> c[i];
	for (int i = 1;i < n;i++) {
		int u, v;
		cin >> u >> v;
		adj[v].pb(u);
		adj[u].pb(v);
	}
	dfs(1, 0);
	for (int i = 1;i <= n;i++)
		cnt[i] = n;
	dfs2(1, 0);
	for (int i = 1;i <= n;i++)
		if (cnt[i] > 0)
			comp[i].pb(cnt[i]);
	for (int i = 1;i <= n;i++) {
		ll ans = 1LL * n * (n + 1) / 2;
		for (ll x : comp[i])
			ans -= x * (x + 1) / 2;
		cout << ans << '\n';
	}
}


Measured memory_bytes: 43524
#include<iostream>
using namespace std;
long n,x;
long city[100001];
long maxDivisor(long a,long b){
	if(a<b){
		int c= a;
		a=b;
		b=c;
	}
	while(true){
		int c = a%b;
		if(c==0){
			return b;
		}	
		a=b;
		b=c;	 
	}
	
}

int allDivisor(long result){
	for(int i=0;i<=n;i++){
		if(city[i] /result*result !=city[i]){
			return 0;
		}
	}
	return 1;
}

int main(){
	
	
	
	long min1,min2;
	cin>>n>>x;
	city[0]=x;
	min1 = x;
	min2 = 1000000001;
	for(int i=1;i<=n;i++){
		cin>>city[i];
		if(min1>city[i]){
			min2 = min1;
			min1 = city[i];
			
		}else if(min2>city[i]){
			min2 = city[i];
		}
	}
	for(int i=0;i<=n;i++){
		city[i] -= min1;
	//	cout << city[i]<<"\t";
	}
	
	//cout<<"\n";
	
	//long min = min2-min1;
	long result =  min2-min1;
	//cout <<min1<<"\t"<<min2<<endl;
	for(int i=0;i<=n;i++){
		if(city[i] == 0){
			continue;
		}
		result =  maxDivisor(result,city[i]);
		if(result ==1 ){
			cout << 1;
			return 0;
		}
		if(allDivisor(result)){
			cout<<result;
			return 0;
		}
	} 
	/** 
	for(long i =1 ;i<=min/2;i++){
		int canDivide = 1;
		if(min/i*i != min){
			continue;
		}
		int result = min / i;
		for(int j=0;j<=n;j++){
			if(city[j]/result*result != city[j] ){
				canDivide = 0;
				//cout << city[j]<<"can divide by"<<result<<endl;
				break;
			}
		} 
		if(canDivide){
			cout <<result;
			return 0;
		}
	}
	cout<<1;
	*/
	
}

Measured memory_bytes: 1024
def resolve():
    N,W = map(int,input().split())
    weights = [0]
    values  = [0]
    for i in range(N):
        w,v = map(int,input().split())
        weights.append(w)
        values.append(v)

    min_costs = [[0 for i in range(W+1)] for i in range(N+1)]

    for ni in range(1,len(min_costs)):
        for wi in range(1,len(min_costs[ni])):
            if wi < weights[ni]:
                min_costs[ni][wi] = min_costs[ni -1][wi]
            else:
                min_costs[ni][wi] = max(min_costs[ni -1][wi],min_costs[ni -1][wi-weights[ni]] + values[ni])

    print(min_costs[-1][-1])
    
resolve()

Measured memory_bytes: 171400
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>
#include<numeric>
#include<stdlib.h>

using namespace std;

int main()
{

  int N;
  cin >> N;

  int ans = 0;
  for(int i=1; i<=N; i++){
    ans += i;
  }

  cout << ans << endl;

}


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

int main() {
    long long n, ret = 0, t;
    std::cin >> n;

    std::vector<std::pair<long long, long long>> a(n);

    for (long long i = 0; i < n; i++) {
        std::cin >> t;
        a[i] = std::make_pair(i + 1, t);
    }
    std::sort(a.begin(), a.end(), [](auto& l, auto& r) { return l.second < r.second; });

    for (long long i = 0; i < n; i++) {
        if ((a[i].first % 2) != ((i+1) % 2)) ret++;
    }

    std::cout << ret / 2 << std::endl;

    return 0;
}

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
typedef long long ll;
int main() {
  ll a,b,A,B,t,T,sa,sb,ans=0;
  string word;
  bool flag;
  cin>>a>>b>>A;
  if(a+b+A<22)cout<<"win"<<endl;
  else cout<<"bust"<<endl;
  //vector<vector<int>> sss(h,vector<int>(w));
  //vector<int> a(k),b(k);
  //char x;
}

Measured memory_bytes: 256
k, a, b = list(map(int, input().split()))

if a + 2 <= b and k + 3 > a:
    k -= a - 1
    n = k // 2
    x = (b - a) * n + a
    y = k % 2
    print(x + y)

else:
    print(1 + k)
    


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define sf scanf
#define pf printf
#define pi acos(-1)
#define time_save ios_base::sync_with_stdio(false); cin.tie(NULL);
int main()
{
    time_save;
    int a,b;
    while(cin>>a>>b)
    {
        string aa="",bb="";
        for(int i=0;i<a;i++)
            bb+=(b+'0');
        for(int i=0;i<b;i++)
            aa+=(a+'0');
        if(aa<=bb)
            cout<<aa<<endl;
        else
            cout<<bb<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;
using ll = long long;

const ll MOD = 1000000007;
const ll INF = 1e18;
const double pi = acos(-1);
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};


#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()


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

 


void solve(){
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    map<string,int> poll = {};
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        if(poll.count(s)) {
            poll[s]++;
        }else{
            poll.emplace(s,0);
        }
    }
    int maxnum = -1;
    for (auto itr = poll.begin(); itr != poll.end(); itr++) {
        maxnum = max(maxnum,itr->second);
    }
    for (auto itr = poll.begin(); itr != poll.end(); itr++) {
        if(itr->second == maxnum) cout << itr->first << endl;
    }
    
}



signed main() {
    solve();
    return 0;
}



Measured memory_bytes: 23808
#include <stdio.h>


int main(void){
	int N,M,i,a[50],b[50];
	int cnt[50];

	scanf("%d %d",&N,&M);
	for(i=0;i<N;i++){
		cnt[i] = 0;
	}
	for(i=0;i<M;i++){
		scanf("%d %d",&a[i],&b[i]);
	}
	for(i=0;i<M;i++){
		cnt[a[i]-1]++;
		cnt[b[i]-1]++;
	}
	
	for(i=0;i<N;i++){
		printf("%d\n",cnt[i]);
	}

}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		sc.close();

		if (s.equals(t.substring(0, t.length() - 1))) {
			System.out.print("Yes");
		} else {
			System.out.print("No");
		}
	}
}


Measured memory_bytes: 26968
use std::io;
use std::cmp;


fn main() {
    let n = read_one::<usize>();
    let mut an = vec![0; n];
    for i in 0..n { an[i] = read_one::<usize>(); }
    let mut cnt: usize = an[0] / 2;
    an[0] = an[0] % 2;
    for i in 1..n {
        let d = cmp::min(an[i - 1], an[i]);
        cnt += d + (an[i] - d) / 2;
        an[i] = (an[i] - d) % 2;
    }

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


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
n = gets.to_i
a = gets.split.map(&:to_i)

left_gcd = Array.new(n + 1, 0)
right_gcd = Array.new(n + 1, 0)

(0..n - 1).each do |i|
    left_gcd[i + 1] = left_gcd[i].gcd(a[i])
end

(n - 1).downto(0) do |i|
    right_gcd[i] = right_gcd[i + 1].gcd(a[i])
end

ans = 0
(0..n - 1).each do |i|
    left = left_gcd[i]
    right = right_gcd[i + 1]
    ans = [ans, left.gcd(right)].max
end

puts ans

Measured memory_bytes: 14348
# ABC043D - アンバランス / Unbalanced (ARC059D)
def main():
    # more than half -> 2/3 in a 3-length partial string
    S = input().rstrip()
    N = len(S)
    if N == 2:  # e.g. "aa", "ab"
        ans = (1, 2) if S[0] == S[1] else (-1, -1)
        print(*ans)
        return
    for i in range(N - 2):
        if len(set(S[i : i + 3])) == 2:
            print(i + 1, i + 3)
            return
    print(-1, -1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector> // vectorを使うためにインクルードする
using namespace std;

int main() {
	int n;
	
	scanf("%d", &n);

	vector<int> vc;
	int max=0;
	int maxindex=0;
	int sum = 0;

	for (int i = 0; i <n ;i++) {
		int k;
		scanf("%d",&k);
		vc.push_back(k);
		if (max < k) {
			max = k;
			maxindex = i;
		}
	}

	for (int i = 0; i < n; i++) {
		if (i != maxindex) {
			sum += vc[i];
		}
	}
	if (sum > max) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#!/usr/bin/env python
import itertools

N, K = map(int, input().split())
div = []
rest = []
for n in range(1, N+1):
    if K % 2 == 1:
        if n % K  == 0:
            div.append(n)
    else:
        if n % K  == 0:
            div.append(n)
        elif n % K == K/2:
            rest.append(n)

D = len(div)**3
R = len(rest)**3

print(D+R)


Measured memory_bytes: 11064
#include<iostream>
const int MAX_NUM =100000001;
using namespace std;

int main()
{
    int N,K,S;cin >> N >> K >> S;
    if(K==0)
    {
        for(int i=0;i<N;++i)
        {
            if(i==0) cout << MAX_NUM;
            else cout << " " << MAX_NUM;
        }
        cout<<endl;
        return 0;
    }
    cout << S;
    for(int i=2;i<=K;++i) cout<< " " << S ;

    for(int j=K+1;j<=N;++j) cout <<" "<< MAX_NUM;

    cout << endl;
    return 0;
}

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n){
    cin >> a[i];
  }

  vector<ll> ans(n, 0);
  for(int i = 0; i < n; ++i){
    if(i & 1){
      ans[0] -= a[i];
    }
    else{
      ans[0] += a[i];
    }
  }

  for(int i = 1; i < n; ++i){
    ans[i] = 2 * a[i - 1] - ans[i - 1];
  }

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


Measured memory_bytes: 2944
def judge(x):
    if x == 1:
        return True
    i = 2
    while i**2 <= x:
        if x % i == 0:
            return False
        i += 1
    return True


n = int(input())

ans = 0
for i in range(n):
    x = int(input())
    ans += 1 if judge(x) else 0

print(ans)



Measured memory_bytes: 5608
#全体に同じものを足すときは累積和を考えたい

N,Q = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N-1)]
PX = [list(map(int,input().split())) for _ in range(Q)]

graph = [[] for _ in range(N+1)]

for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)
#どちらが親か分からないがとりあえずつながっている
#どちらが親かは後で判断

counter = [0 for _ in range(N+1)]
#counter[i]:i番目の頂点のカウンター
parent = [None for _ in range(N+1)]

for p,x in PX:
    counter[p] += x

def dfs(graph,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)

dfs(graph,counter,1)

ans = " ".join(map(str,counter[1:]))
print(ans)


Measured memory_bytes: 153328
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s , t = "SS";
    cin >> n >> s;
    s += s[0];
    for ( int j = 0 ; j < 4 ; j++ ) {
        if ( j == 0 ) t = "SS";
        else if ( j == 1 ) t = "SW";
        else if ( j == 2 ) t = "WS";
        else t = "WW";
        for ( int i = 2 ; i <= n + 1 ; i++ ) {
            if ( t[i - 1] == 'S' ) {
                if ( s[i - 1] == 'o' ) {
                    if ( t[i - 2] == 'S' ) t += 'S';
                    else t += 'W';
                } else {
                    if ( t[i - 2] == 'S' ) t += 'W';
                    else t += 'S';
                }
            } else {
                if ( s[i - 1] == 'o' ) {
                    if ( t[i - 2] == 'S' ) t += 'W';
                    else t += 'S';
                } else {
                    if ( t[i - 2] == 'S' ) t += 'S';
                    else t += 'W';
                }
            }
        }
        if ( t[0] == t[n] && t[1] == t[n + 1] ) {
            for ( int i = 0 ; i < n ; i++ ) cout << t[i];
            return 0;
        }
    }
    cout << -1;
}

Measured memory_bytes: 720
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
//
#define int long long
#define ALL(x) (x).begin(), (x).end()
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))
// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((a) >> (b)) & 1
#define bitcount(a) __builtin_popcountll((a))
//
typedef long long lint;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;
//
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
//
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

int N, M;
int d[51][51];
bool used[51];

void dfs(int s) {
  used[s] = true;
  for (int i = 0; i < N; i++) {
    if (used[i] || d[s][i] == 0) {
      continue;
    }
    dfs(i);
  }
}

bool check() {
  for (int i = 0; i < N; i++) {
    if (used[i] == false) {
      return true;
    }
  }
  return false;
}

signed main() {
  cin >> N >> M;
  m0(d);
  vector<P> edge[51];
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    d[a][b] = d[b][a] = 1;
    edge[i].push_back(make_pair(a, b));
  }

  int ans = 0;
  for (int i = 0; i < M; i++) {
    P p = edge[i].front();
    int a = p.first, b = p.second;
    d[a][b] = d[b][a] = 0;

    m0(used);
    dfs(0);
    if (check()) {
      ans++;
    }

    d[a][b] = d[b][a] = 1;
  }

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


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

// 標準入力取込
let gInput = '';
process.stdin.on('data', (chunk) => (gInput += chunk));
process.stdin.on('end', () => main(gInput.split(/\r?\n/)));

// 解答
function main(inputs: string[]): void {
  const num = BigInt(inputs[0].split(' ')[0]);
  let sum: BigInt = BigInt(0);

  for (let i: number = 1; i <= num; i++) {
    if (i % 15 !== 0 && i % 3 !== 0 && i % 5 !== 0) {
      sum += BigInt(i);
    }
  }

  console.log(Number(sum));
}


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

int main(){
	int N, i;
	scanf("%d", &N);
	string S, T;
	cin >> S;
	cin >> T;
	for(i = 0; i < N; i++){
		printf("%c%c", S[i], T[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
count = 0


for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if l[i] != l[j] and l[i] != l[k] and l[j] != l[k] and abs(l[i]-l[j]) < l[k] < l[i]+l[j]:
                count = count + 1

print(count)


Measured memory_bytes: 9100
#define rep(i,n) for (int i = 0; i < n; i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;
struct edge {
	int from, to, cost;
};


int main() {
	int n; string s; cin >> n >> s;
	vector<int> a(n + 1, 0);
	rep(i, n) {
		a[i + 1] = a[i] + (s[i] == 'W' ? 0 : 1);
	}
	ll ans = INF;
	rep(i, n + 1) {
		ll l = i, r = 0;
		if (i != 0) {
			l -= a[i] - a[0];
		}
		if (i != n) {
			r = a[n] - a[i];
		}
		ans = min(ans, l + r);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1796
#include <stdio.h>

#define N 100

int n,count=0;
int sel[N];


void Select(){
	int i,minj,j,tmp;
	for(i = 0;i < n -1; i++){
		minj = i;
		for(j = i+1; j< n;j ++){
			if(sel[j] < sel[minj]){
				minj = j;
			}
		}
		if(minj != i){
			tmp = sel[minj];
			sel[minj] = sel[i];
			sel[i] = tmp;
			count++;
		}
	}

}

void print(){
	int i;
	for(i = 0;i < n-1; i++){
		printf("%d ",sel[i]);
	}
	printf("%d\n",sel[i]);
	printf("%d\n",count);
}

int main(){
	int i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&sel[i]);
	}
	Select();
	print();
	return 0;
}

Measured memory_bytes: 2732
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  const int INF = 1 << 28;

  int n;
  while (~scanf("%d", &n)) {
    int m;
    scanf("%d", &m);

    vector<vector<int> > cost(n, vector<int>(n, INF));
    for (int i = 0; i < m; ++i) {
      int a1, b1, c1, d1;
      scanf("%d,%d,%d,%d", &a1, &b1, &c1, &d1);
      --a1;
      --b1;
      cost[a1][b1] = c1;
      cost[b1][a1] = d1;
    }

    for (int k = 0; k < n; ++k) {
      for (int i = 0; i < n; ++i) {
	for (int j = 0; j < n; ++j)
	  cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
      }
    }

    int x1, x2, y1, y2;
    scanf("%d,%d,%d,%d", &x1, &x2, &y1, &y2);

    printf("%d\n", y1-y2-cost[x1-1][x2-1]-cost[x2-1][x1-1]);

  }
  return 0;
}

Measured memory_bytes: 0