akhauriyash/Code-Regression huggingface dataset:
// https://github.com/PabloMessina/Competitive-Programming-Material/blob/master/Codejam_template.cpp
#pragma GCC optimize("Ofast") // OPTIONAL: for faster execution
#include <bits/stdc++.h>      // import everything in one shot
using namespace std;
// defines
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define invrep(i, a, b) for (int i = b - 1; i >= a; --i)
#define umap unordered_map
#define uset unordered_set
// typedefs
typedef unsigned int uint;
typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
// -------------------------------

typedef struct {
    int points;
    int cost;
    int idx;
}
triple;

int main()
{
    // OPTIONAL: for faster input/output (only if using cin/cout)
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int N, K;
    cin >> N >> K;
    vi A(N);
    rep(i, 0, N) cin >> A[i];
    vector<triple> left;
    set<int> negatives;
    int pointsSum = 0;
    rep(i, 0, N)
    {
        pointsSum += A[i];
        if (A[i] < 0)
            negatives.insert(A[i]);
        else
        {
            left.emplace_back(triple{pointsSum, i + 1, i});
            int j = 1;
            int negSum = 0;
            for (auto it = negatives.begin(); it != negatives.end(); it++)
            {
                negSum += *it;
                left.emplace_back(triple{pointsSum-negSum, i + 1 + j, i});
                j++;
            }
        }
    }

    vector<triple> right;
    negatives.clear();
    pointsSum = 0;
    invrep(i, 0, N)
    {
        pointsSum += A[i];
        if (A[i] < 0)
            negatives.insert(A[i]);
        else
        {
            right.emplace_back(triple{pointsSum, N - i, i});
            int j = 1;
            int negSum = 0;
            for (auto it = negatives.begin(); it != negatives.end(); it++)
            {
                negSum += *it;
                right.emplace_back(triple{pointsSum - negSum, N - i + j, i});
                j++;
            }
        }
    }
    int ans = 0;
    rep(pos, 0, N)
    {
        rep(moves, 1, K+1) {
            int l = 0, r = 0;
            rep(i, 0, left.size()) {
                if (left[i].idx > pos) break;
                if (left[i].cost <= moves) l = max(l, left[i].points);
            }
            rep(i, 0, right.size()) {
                if (right[i].idx <= pos) break;
                if (right[i].cost <= K - moves)r = max(r, right[i].points);
            }
            ans = max(ans, l + r);
        }
    }
    cout << ans << endl;
    // rep(i, 0, left.size())
    // {
    //     printf("%d %d %d\n", left[i].points, left[i].cost, left[i].idx);
    // }
    // printf("\n");
    // rep(i, 0, right.size())
    // {
    //     printf("%d %d %d\n", right[i].points, right[i].cost, right[i].idx);
    // }
    return 0;
}

Measured memory_bytes: 3672
import sys
import math


a,b,h,m=map(int,input().split())
mi=6*m
ho=30*h+(1/12)*mi

ang=min(abs(mi-ho),360-abs(mi-ho))

c=math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(ang)))
print(c)

Measured memory_bytes: 62164
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>

using namespace std;

int main()
{
    int n;
    long long int a[300010];
    long long int ans = 0;

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

    sort(a, a+3*n);

    for (int i = n; i < n*3; i += 2) {
        ans += a[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include<iostream>
#include<sstream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cfloat>
#include<functional>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<bitset>
#include<list>
#include<numeric>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;
typedef vector<int> Vint;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << x << "\n"
#define pri2(x, y) cout << x << " " << y << "\n"
#define pri3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << x << "\n"
#define debug2(x, y) cout << " --- " << x << " " << y << "\n"
#define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j, k;
  for(int testcase = 0;testcase < 1234567;testcase++){
    string t, p;
    cin >> t >> p;
    if(t.size() < p.size())break;
    rep(i, t.size() - p.size() + 1)if(t.substr(i, p.size()) == p)pri(i);

/*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 1196
#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>;

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " << y << endl;

  return 0;
}


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

void isort( int a[], int size ) {
  for( int i = 1; i <= size; i++ ) {
    for( int k = 0; k < size; k++ ) {
      cout << a[k] ;
      if( k < size - 1 ) {
        cout << " ";
      }
      else {
        cout << endl;
      }
    }

    int j, key = a[i];
    for( j = i - 1; j >= 0 and a[j] > key; j-- ) {
      a[j+1] = a[j];
    }
    a[j+1] = key;
  }
}

int main()
{
  int n, a[100] = { 0 };

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

  return 0;
}




Measured memory_bytes: 3104
from collections import deque

def bfs():
    q = deque()
    q.append(1)
    dist = [-1] * (n + 1)
    dist[1] = 0
    while q:
        p = q.popleft()
        for i in G[p]:
            if dist[i] == -1:
                dist[i] = dist[p] + 1
                q.append(i)
    return dist

n = int(input())
G = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)
dist = bfs()
c1, c2 = 0, 0
group1, group2 = [], []
for i in range(1, n + 1):
    if dist[i] % 2 == 1:
        c1 += 1
        group1.append(i)
    else:
        c2 += 1
        group2.append(i)
m = n // 3
ans = [0] * (n + 1)
if m >= min(c1, c2):
    l = [3 * i + 3 for i in range(m)] + [3 * (i // 2) + (i % 2) + 1 for i in range(n - m)]
    j = 0
    if c1 < c2:
        for i in group1:
            ans[i] = l[j]
            j += 1
        for i in group2:
            ans[i] = l[j]
            j += 1
    else:
        for i in group2:
            ans[i] = l[j]
            j += 1
        for i in group1:
            ans[i] = l[j]
            j += 1
else:
    j = 1
    for i in range(c1):
        if i <= (n - 1) // 3:
            ans[group1[i]] = 3 * i + 1
        else:
            ans[group1[i]] = 3 * j
            j += 1
    for i in range(c2):
        if i <= (n - 2) // 3:
            ans[group2[i]] = 3 * i + 2
        else:
            ans[group2[i]] = 3 * j
            j += 1
ans.pop(0)
print(*ans)

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

using namespace std;

using i64 = long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


signed main(){
    int n, k;
    cin >> n >> k;

    vector<int> a(n, -100), b(n, -100), c(n, -100);

    if(n % 2 == 0){
        for(int i = 0; i < n / 2; ++i){
            a[i] = k + n + i;
            b[i] = k + n - 1 - 2 * i;
        }
        for(int i = 0; i < n / 2; ++i){
            a[i + n / 2] = k + n + n / 2 + i;
            b[i + n / 2] = k + n - 2 - 2 * i;
        }
    }
    else{
        for(int i = 0; i < (n / 2); ++i){
            a[i] = k + n + i;
            b[i] = k + n - 2 - 2 * i;
        }
        for(int i = 0; i < n / 2 + 1; ++i){
            a[i + n / 2] = k + n + n / 2 + i;
            b[i + n / 2] = k + n - 1 - 2 * i;
        }
    }

    set<int> s;
    for(int i = k + 2 * n; i < k + 3 * n; ++i)
        s.emplace(i);
    for(int i = 0; i < n; ++i){
        auto it = s.lower_bound(a[i] + b[i]);
        if(it == s.end()){
            cout << -1 << endl;
            return 0;
        }
        c[i] = *it;
        s.erase(it);
    }

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

}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
const double pi=3.1415926535897932384626;
int main(){
    int n,k;
    std::cin >> n;
    std::cin >> k;
    double ans=0;
    rrep(i,1,n+1){
        double d=0;
        for (int j = i; j < k; j*=2) {
            /* code */
            d++;
        }
       // std::cout << d << std::endl;
        ans+=(1/pow(2,d));
    }
    ans/=n;
    std::cout<<keta(10) << ans << std::endl;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;


int main()
{
	int A, B, C, D;

	cin >> A >> B >> C >> D;

	if (A <= C)
	{
		if (C <= B && B <= D)
			cout << B - C << endl;
		else if (C <= B && D <= B)
			cout << D - C << endl;
		else
			cout << 0 << endl;
	}
	else
	{
		if (A <= D && B <= D)
			cout << B - A << endl;
		else if (A <= D && D <= B)
			cout << D - A << endl;
		else
			cout << 0;
	}

	return 0;
}

Measured memory_bytes: 256
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	string s,t;
	cin>>s>>t;
	sort(s.begin(),s.end());
	sort(t.rbegin(),t.rend());
	if(s<t) {
		cout<<"Yes";
	}else cout<<"No";
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3640
while 1:
    n , x = (int(a) for a in input().split())
    num = 0
    if n == 0 and x == 0:
        break
    for i in range(1 , n + 1):
        for j in range(i + 1, n + 1):
            for k in range (j + 1, n + 1):
                if i + j + k == x:
                    num = num + 1
    print(num)


Measured memory_bytes: 5596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int board[][] = new int[3][3];

		for(int i = 0; i < 3; i++){
			for(int j = 0; j < 3; j++){
				board[i][j] = sc.nextInt();
			}
		}
		int n = sc.nextInt();

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

			for(int i = 0; i < 3; i++){
				for(int j = 0; j < 3; j++){
					if(board[i][j] == tmp){
						board[i][j] = 0;
					}
				}
			}
		}

		for(int i = 0; i < 3; i++){
			if(board[i][0] + board[i][1] + board[i][2] == 0){
				System.out.println("Yes");
				return;
			}
			if(board[0][i] + board[1][i] + board[2][i] == 0){
				System.out.println("Yes");
				return;
			}
		}

		if(board[0][0] + board[1][1] + board[2][2] == 0 || board[2][0] + board[1][1] + board[0][2] == 0){
			System.out.println("Yes");
			return;
		}
		System.out.println("No");
	}

}


Measured memory_bytes: 23636
#include <cstdio>

#define MOD 1000000007
#define MAXN 1000
#define ll long long

int f[MAXN + 2];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 2; i <= n; i ++) {
        int k = i;
        for (int j = 2; k != 1; j ++) {
            while (k % j == 0) {
                f[j] ++;
                k /= j;
            }
        }
    }

    ll rez = 1;
    for (int i = 2; i <= n; i ++)
        rez = ( 1LL * rez * (f[i] + 1) ) % MOD;
    printf("%lld", rez);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, M;
bool solved[101010];
int wa[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;

	rep(i, 0, M) {
		int p; string s; cin >> p >> s;
		p--;

		if (s == "WA" and !solved[p]) wa[p]++;
		if (s == "AC") solved[p] = true;
	}

	int correct = 0, penalty = 0;
	rep(i, 0, N) if (solved[i]) {
		correct++;
		penalty += wa[i];
;	}

	cout << correct << " " << penalty << endl;
}







Measured memory_bytes: 768
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

static void counting_sort(int *a, int *b, int *c, int n, int k) {
  int i;

  for (i = 0; i < k; ++i) c[i] = 0;
  for (i = 0; i < n; ++i) ++c[a[i]];
  for (i = 1; i < k; ++i) c[i] += c[i - 1];
  for (i = n - 1; i >= 0; --i) {
    b[c[a[i]] - 1] = a[i];
    --c[a[i]];
  }
}

int main(int argc, char **argv) {
  int n, ret, i, max;
  int *a;
  int *b;
  int *c;

  ret = scanf("%d", &n);
  if (errno != 0) perror("scanf: n");
  if (ret < 1) exit(1);

  a = (int *) malloc(sizeof(int) * n);
  if (a == NULL) exit(1);

  for (i = max = 0; i < n; ++i) {
    ret = scanf("%d", &a[i]);
    if (errno != 0) perror("scanf: a[i]");
    if (ret < 1) break;
    if (a[i] > max) max = a[i];
  }

  b = (int *) malloc(sizeof(int) * n);
  if (b == NULL) {
    free(a); exit(1);
  }

  c = (int *) malloc(sizeof(int) * (max + 1));
  if (c == NULL) {
    free(a); free(b); exit(1);
  }

  counting_sort(a, b, c, n, max + 1);

  for (i = 0; i < n; ++i) {
    if (i > 0) printf(" ");
    printf("%d", b[i]);
  }
  printf("\n");

  free(a); free(b); free(c); exit(0);
}


Measured memory_bytes: 17076
#include<bits/stdc++.h>
using namespace std;
const int maxn=105;
int n,m,dx[]={1,0,-1,0},dy[]={0,1,0,-1};
char s[maxn][maxn];
bool vis[maxn][maxn];
bool match(int x,int y)
{
	if(x<0||y<0||x>=n||y>=m||vis[x][y]) return false;
	vis[x][y]=true;
	for(int i=0;i<4;i++){
		int u=x+dx[i],v=y+dy[i];
		if(u<0||v<0||u>=n||v>=m) continue;
		if(s[u][v]=='#'||vis[u][v]) continue;
		bool ok=false;
		if(s[u][v]!='.'){
			vis[u][v]=true;
			if(s[u][v]=='>') ok=match(u,v+1);
			else if(s[u][v]=='<') ok=match(u,v-1);
			else if(s[u][v]=='^') ok=match(u-1,v);
			else ok=match(u+1,v);
		}
		else ok=true;
		if(ok){
			if(i==0) s[x][y]='v',s[u][v]='^';
			else if(i==1) s[x][y]='>',s[u][v]='<';
			else if(i==2) s[x][y]='^',s[u][v]='v';
			else s[x][y]='<',s[u][v]='>';
			return true;
		}
	}
	return false;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++) scanf("%s",s[i]);
	int ans=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
   			if(s[i][j]=='.'){
				memset(vis,false,sizeof(vis));
				if(match(i,j)) ans++;
   			}
		}
	}
	printf("%d\n",ans);
	for(int i=0;i<n;i++) printf("%s\n",s[i]);
	return 0;
}

Measured memory_bytes: 3832
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{   
    int n;
    cin >> n;
    vector<i64> l(n+1);
    l[0] = 2;
    l[1] = 1;
    rep2(i,2,n+1) l[i] = l[i-1]+l[i-2]; 

    cout << l[n] << endl;
    return 0;
}

Measured memory_bytes: 256
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():

    L=list(map(int,input().split()))
    l=[0,0,0]

    for i in range(3):
        if L[i]%2!=0:
            l[i]=1
    cnt=0
    if l.count(0)==2:
        index_num = [n for n, v in enumerate(l) if v %2==0]
        for j in index_num:
            L[j]+=1
        cnt+=1
    elif l.count(0)==1:
        index_num = [n for n, v in enumerate(l) if v %2==1]
        for j in index_num:
            L[j]+=1
        cnt+=1

    L.sort()
    print(cnt+(L[-1]-L[0])//2+(L[-1]-L[1])//2)



resolve()

Measured memory_bytes: 3064
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>

#define in std::cin
#define out std::cout

int32_t N;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> N;
	int64_t sum = 0;
	int64_t i=0;
	while(N>sum)
	{
		sum += ++i;
	}
	out << i << endl;

	return 0;
}
#endif


Measured memory_bytes: 256
//#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>
#include <cstdlib>      // srand,rand


using namespace std;
#define modd 1000000007



typedef pair<long long, long long> pl;


typedef string::const_iterator State;
class ParseError {};




#define ll long long




class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};


class SegmentTree {
private:
	int n;
	vector <ll> node;

public:
	// 元の配列　v をセグメントツリーで表現する。
	SegmentTree(vector<ll> v) {
		//最下段のノード数は元配列のサイズ以上になる最小の2冪->これをnとおく。
		//セグ木全体で必要なノード数は2n-1個である。
		int sz = v.size();
		n = 1; 
		while (n < sz)n *= 2;

	}

};




long long N, M, K, a, b, c, d, e, H, W, L,T;
ll A[2][300005] = {};
ll B[300005] = {};
ll C[100][3005] = {};
bool f, ff;
string S,SS;
set <long long>sll;
pl bufpl;
vector <long long>vl[100005];
vector <long long>vll;
vector <pl>vpl;
vector <string> vs;
set<ll> llset[50];
multiset<ll> llmset;
queue<ll> ql;


struct ST
{
	ll first;
	ll second;
	ll kaisuu;
	

	bool operator<(const ST& another) const
	{
		return first < another.first;//比較
	};

};



/*vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}


ll minn, maxx;
double ansa;

ll zettai(ll aa) {

	if (aa < 0) {
		aa *= -1;
	}
	return aa;

}


bool itta[300000];

int main() {
	
	cin >> S>>SS;

	if (S.size() > SS.size()) {
		cout << "GREATER" << endl;
	}
	else if (S.size() < SS.size()) {
		cout << "LESS" << endl;
	}
	else {

		for (int i = 0; i < S.size(); i++) {
			a = S[i] - '0';
			b = SS[i] - '0';


			if (a>b) {
				cout << "GREATER" << endl;
				break;
			}
			else if (a<b) {
				cout << "LESS" << endl;
				break;
			}
			else if (i == S.size() - 1) {
				cout << "EQUAL" << endl;
			}
		}

	}

	//cout << fixed << setprecision(10) << ansa << endl;
	return 0;



}


Measured memory_bytes: 4096
#include <iostream>
using namespace std;
int main() {
    long long a , b , c;
    cin >> a >> b >> c;
    long long d = c - a - b;
    if(d > 0 && d * d > 4 * a * b){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
///
// File:  b.cpp
// Author: ymiyamoto
//
// Created on Sun Dec 17 00:51:26 2017
//

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

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

  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());

  if (s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#define MAX 100010
using namespace std;
int stones[MAX];
int memo[MAX];
int n,k;
int dfs(int index){	//´Óindex×´Ì¬ µ½ ½áÊø ÐèÒªµÄ×îÐ¡´ú¼Û 
	if(memo[index]!=-1) return memo[index];
	if(index==n-1) return 0;
	
	int res=dfs(index+1)+abs(stones[index]-stones[index+1]);
	for(int i=2;i<=k;i++){
		if(i+index<=n-1){
			res = min (res,dfs(index+i)+abs(stones[index]-stones[index+i]));
		}
	}
	memo[index]=res;
	return memo[index];
}

int main(){
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&stones[i]);
	}
	fill(memo,memo+MAX,-1);
	
	printf("%d",dfs(0));
	return 0;
} 

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

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> A(m);

    int toll = 0;
    for (int i = 0; i < m; i++) {
        cin >> A[i];
        if (A[i] < x) toll++;
    }

    cout << min(toll, m - toll) << endl;

    return 0;
}

Measured memory_bytes: 256
N = input()
l = len(N)


def func(i, flag, b, only_leading_zero):
    if i == l:
        if b == 7:
            return 1
        else:
            return 0

    sum_ = 0
    flag_temp = flag
    for n in (0, 3, 5, 7):
        if not only_leading_zero and n == 0:
            continue

        if not flag and n > int(N[i]):
            continue

        if not flag and n < int(N[i]):
            flag = True

        if n == 3:
            x = 0b001
            only_leading_zero = False
        elif n == 5:
            x = 0b010
            only_leading_zero = False
        elif n == 7:
            x = 0b100
            only_leading_zero = False
        else:
            x = 0b000

        sum_ += func(i + 1, flag, b | x, only_leading_zero)
        flag = flag_temp

    return sum_


r = func(0, False, 0, True)
print(r)


Measured memory_bytes: 9220
// #define int long long
// #define repeat(i, n) for (int i = 0; i < n; ++i)

#include <cmath> // cmath includes sqrt, abs
#include <iostream> // iostream includes cout, endl
#include <string> // string
#include <algorithm> // algorithm includes sort

// #include <bits/stdc++.h>

using namespace std;

int main() {
  bool can = true;
  // int num = 0;
  // int sum = 0;
  // string S;
  // int N;

  // int a[3];
  // int b[3];
  int c[9]; // c[3*i + j]

  // for (int i = 0; i < 3; ++i) {
  //   a[i] = -1;
  //   b[i] = -1;
  // }
  
  for (int i = 0; i < 9; ++i) {
    cin >> c[i];
  }

  for (int i1 = 0; i1 < 3; ++i1) {
    for (int i2 = i1 + 1; i2 < 3; ++i2) {
      int s = 0;
      int t = 3 * c[3 * i1 + 1] - 3 * c[3 * i2 + 1];
      // int u;
      // int v;
      for (int j = 0; j < 3; ++j) {
        s += c[3 * i1 + j] - c[3 * i2 + j];
      }
      if (s != t) {
        can = false;
      }
    }
  }
  
  // cout << sum << endl;
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i, n)  FOR(i,0,(n))
typedef pair<int, int> P;
typedef vector<int> vec;


class CGeTAC {
public:
    void solve(std::istream &in, std::ostream &out) {
      int n, q;
      string s;
      in >> n >> q >> s;
      vector<P> lr(q);
      REP(i, q) {
        int x, y;
        in >> x >> y;
        x--;
        y--;
        lr[i] = P(x, y);
      }
      vec dp(n, 0);
      FOR(i, 1, n) {
        dp[i] = dp[i - 1] + (s.substr(i - 1, 2) == "AC" ? 1 : 0);
      }
      REP(i, q) {
        out << dp[lr[i].second] - dp[lr[i].first] << endl;
      }
    }
};


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


Measured memory_bytes: 3408
def fact(x):
    res = 1
    for i in xrange(1, x + 1):
        res *= i
    return res

def comb(a, b):
    if(a < b or b < 0):return 0
    if(b == 0):return 1
    return fact(a)/fact(b)/fact(a-b)

a, b, c = map(int, raw_input().split())
c -= a * b
print comb(c + a - 1, c)

Measured memory_bytes: 4324
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
using namespace std;
typedef long long int ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define FOREQ(i, a, b) for (int i = (a); i <= (b); i++)
#define REPEQ(i, n) FOREQ(i, 0, n)

int main()
{
    int N, Min, Max;
    cin >> N >> Min >> Max;

    int sum = 0;
    int digit;
    int tmp;
    int tmpSum;
    FOREQ(i, 1, N)
    {
        tmp = i;
        tmpSum = 0;
        while (tmp > 0)
        {
            tmpSum += tmp % 10;
            tmp = tmp / 10;
        }
        if (Min <= tmpSum && tmpSum <= Max)
        {
            sum += i;
        }
    }
    cout << sum << endl;

    return 0;
}

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

#define REP(i, n) for(int i=0; i<n;i++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    int n;
    cin>>n;
    int a[n];
    REP(i, n){
        cin>>a[i];
    }
    int hantei = 0;
    int i=0;
    while(1){
        if(hantei>n){
            break;
        }
        i = a[i]-1;
        hantei++;
        if(i == 1){
            cout<<hantei<<endl;
            break;
        }
    }
    if(hantei>n){
        cout<<"-1"<<endl;
    }
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;
import java.util.Arrays;
import java.util.Calendar;

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

        String[] str = S.split("/",0);
        scan.close();
        boolean flag = false;
        
        if(Integer.compare(2019,Integer.parseInt(str[0])) == 1){
                        System.out.println(str[0]);
            flag = true;
        } else if(Integer.compare(2019,Integer.parseInt(str[0])) == 0 && Integer.compare(04,Integer.parseInt(str[1])) == 1){
            flag = true;
        }else if(Integer.compare(04,Integer.parseInt(str[1])) == 0 && Integer.compare(31,Integer.parseInt(str[2])) == 1){
            flag = true;
    }
        if(flag == true){
            System.out.println("Heisei");
        }else{
             System.out.println("TBD");
        }
    }
}

Measured memory_bytes: 21716
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return {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 (c it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(x...) " [" #x ": " << (x) << "] "

using ll = long long;

constexpr int mod = 1000 * 1000 * 1000 + 7;

void OdejmijOd(int& a, int b) { a -= b; if (a < 0) a += mod; }
int Odejmij(int a, int b) { OdejmijOd(a, b); return a; }
void DodajDo(int& a, int b) { a += b; if (a >= mod) a -= mod; }
int Dodaj(int a, int b) { DodajDo(a, b); return a; }
int Mnoz(int a, int b) { return (ll) a * b % mod; }
void MnozDo(int& a, int b) { a = Mnoz(a, b); }

constexpr int nax = 105;

pair<ll, ll> wyn = {numeric_limits<ll>::max(), numeric_limits<ll>::max()};
int n;
vector<int> graf[nax];
int stop[nax];

void Zbierz(ll naj) {
  ll ilo = 1;
  for (int i = 0; stop[i] > 0; i++) {
    naj++;
    ilo *= stop[i];
    debug() << imie(i) imie(stop[i]);
  }
  debug() << imie(naj) imie(ilo);
  wyn = min(wyn, make_pair(naj, ilo));
}

void Dawaj(int w, int o, int g) {
  stop[g] = max(stop[g], (int) graf[w].size() - 1);
  for (int x : graf[w]) {
    if (x != o) {
      Dawaj(x, w, g + 1);
    }
  }
}

void Proboj(int x) {
  debug() << "Proboj(" imie(x) ")";
  for (int i = 0; i <= n; i++) stop[i] = 0;
  stop[0] = (int) graf[x].size();
  for (int i : graf[x]) {
    Dawaj(i, x, 1);
  }
  Zbierz(1);
}

void Proboj(int a, int b) {
  debug() << "Proboj(" imie(a) imie(b) ")";
  for (int i = 0; i <= n; i++) stop[i] = 0;
  stop[0] = 2;
  Dawaj(a, b, 1);
  Dawaj(b, a, 1);
  Zbierz(0);
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    graf[a].push_back(b);
    graf[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    Proboj(i);
    for (int x : graf[i]) {
      if (i < x) Proboj(i, x);
    }
  }
  printf("%lld %lld\n", wyn.first, wyn.second);
  return 0;
}


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

int main()
{
    int n;
    cin>>n;
    int l[n];
    for(int i=0;i<n;i++)
    {
        cin>>l[i];
    }
    sort(l,l+n);
    long long int v=0;
    for(int i=0;i<n-2;i++)
    {
        for(int j=i+1;j<n-1;j++)
        {
            for(int k=j+1;k<n;k++)
            {
               int a=l[i],b=l[j],c=l[k];
                if(a<b+c&&b<c+a&&c<a+b)
                    v++;
            }
        }
    }
    cout<<v;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define r 0.01
using namespace std;
int main()
{

     ll n;
     cin>>n;
     ll a=100,c=0;
     while(a<n)
     {
         a+=a/100;
         c++;
     }
     cout<<c<<endl;
}




Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
string st,st1;
int z;
int main()
{
	st1="CODEFESTIVAL2016";
	cin>>st;
	for(int i=0;i<st.size();i++)
	  if(st[i]!=st1[i])z++;
	cout<<z<<endl;
	return 0;
}

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

unsigned long gcd(unsigned long a,unsigned long b){
	unsigned long v0,v1,v2;
	v0=a;
	v1=b;
	v2=a%b;
	while(v2!=0){
		v0=v1;
		v1=v2;
		v2=v0%v1;
	}
	return v1;
}

int main(){
	int N;
	cin>>N;
	unsigned long T[N];
	for(int i=0;i<N;++i){
		cin>>T[i];
	}
	unsigned long Tgcd=T[0],Tlcm=T[0];
	for(int i=1;i<N;++i){
		Tgcd=gcd(Tlcm,T[i]);
		Tlcm=Tlcm/Tgcd*T[i];
		//cout<<Tlcm<<endl;
	}
	cout<<Tlcm<<endl;
}


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

using namespace std;

int main(void){
	char arr[2][3];
	for(int i=0;i<2;i++){
		for(int j=0;j<3;j++){
			cin >> arr[i][j];
		}
	}
	if((arr[0][2] == arr[1][0]) && (arr[0][1] == arr[1][1]) && (arr[0][0] == arr[1][2])){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 764
from functools import reduce
import copy

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input().rstrip())
    T = list(int(_) for _ in input().split())
    M = int(input().rstrip())
    A = []
    for i in range(M):
        tmp_T = copy.copy(T)
        sum = 0
        p, x = (int(_) for _ in input().split())
        tmp_T[p-1] = x
        for j in tmp_T:
            sum+= j
        A.append(str(sum))
    print('\n'.join(A))
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
s=input()
if s== 'SUN':
  print(7)
elif s=='SAT':
  print(1)
elif s=='FRI':
  print(2)
elif s=='THU':
  print(3)
elif s=='WED':
  print(4)
elif s=='TUE':
  print(5)
elif s=='MON':
  print(6)

Measured memory_bytes: 2940
#include<stdio.h>
#include<string.h>
int s[200002],zz[200002],hh[200002];

int main()
{
	int z,a,b,i,h,cs,j,p,k;
	scanf("%d %d",&a,&b);
	
		memset(s,0,sizeof(s));
	
		z=0;cs=0;
		for(i=1;i<=a;i++)
		{
		scanf("%d",&h);
		s[h]++;
		
		if(s[h]==1){z++;zz[z]=h;}
		
		}
		
		if(z<=b)cs=0;
		else if(z==a)cs=z-b;
		else 
		{
			
			k=z-b;
			
			for(j=1;j<=z;j++)
			{
				hh[j]=s[zz[j]];
			}
			for(i=1;i<=z;i++)
			for(j=1;j<=z-i;j++)
			{
				if(hh[j]>hh[j+1])
				{
					p=hh[j];hh[j]=hh[j+1];hh[j+1]=p;
				}
			}
			for(i=1;i<=k;i++)cs+=hh[i];
			
		}
		printf("%d\n",cs);
	
}

Measured memory_bytes: 1664
#include<algorithm>//sort(all(変数),greater<型名>())で降順に、*max_element(all(変数))で最大値を獲得
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric>
// xとyのgcdは__gcd(x,y),xとyのlcmは(x*y)/__gcd、accumulate(all(変数),0)で要素の全加算
#include<queue>//priority_queue<型名> 変数
#include<set>
#include<stack>
#include<string>//変数.substr(どこから,いくつ)
#include<vector>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define rrep(i,n) for(ll i=n-1; 0<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
  string s; cin >> s;
  rep(i,s.size()) if(s[i]=='?') s[i] = 'D';
  /*
  rep(i,s.size()-1){
    if(s[i] == 'D' and s[i+1] == 'D'){
      s[i+1] = 'P';
    }
  }*/
  rep(i,s.size()) cout << s[i];
}


Measured memory_bytes: 3712
#include<stdio.h>
#include<math.h>

typedef struct {
  double x, y;
} Point;

void print(Point p){ printf("%.8f %.8f\n", p.x, p.y); }

void plot(int n, Point p1, Point p2){
  Point s, t, u;
  double th = 60.0*(acos(-1)/180.0);
  if ( n == 0 ) return;
  s.x = (2.0 * p1.x + 1.0 * p2.x)/3.0;
  s.y = (2.0 * p1.y + 1.0 * p2.y)/3.0;
  t.x = (1.0 * p1.x + 2.0 * p2.x)/3.0;
  t.y = (1.0 * p1.y + 2.0 * p2.y)/3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y ) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y ) * cos(th) + s.y;

  plot(n-1, p1, s);
  print(s);
  plot(n-1, s, u);
  print(u);
  plot(n-1, u, t);
  print(t);
  plot(n-1, t, p2);
}

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

  p1.x = 0;
  p1.y = 0;
  p2.x = 100;
  p2.y = 0;
  print(p1);
  plot(n, p1, p2);
  print(p2);

  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

int main()
{
    ll n, k;
    cin >> n >> k;

    ll resenje = 0;

    vector<ll> v(n);

    for(auto &z : v)
        cin >> z;

    for(int i = 40; i >= 0; --i)
    {
        int brojac = 0;

        for(int j = 0; j < n; ++j)
        {
            //cout << (1LL<<i) << '\n';
            if((v[j]&(1LL<<i)))
            {
                ++brojac;
            }
        }

        if(brojac * 2 < n && (resenje + (1LL<<i) <= k))
        {
            resenje += (1LL<<i);
        }
    }

    ll suma = 0;

    //cout << resenje << '\n';

    for(int i = 0; i < n; ++i)
    {
        suma += (resenje^v[i]);
    }

    cout << suma << '\n';

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<P> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n;
Graph G;
bool seen[100010];
int ans[100010];
void dfs(int v,int cur){
    seen[v]=true;
    ans[v]=cur;
    for(auto p:G[v]){
        if(seen[p.first])continue;
        dfs(p.first,(cur+p.second)%2);
    }
}
int main(){
    cin >> n;
    G.resize(n);
    rep(i,n){
        seen[i]=false;
        ans[i]=0;
    }
    rep(i,n-1){
        int u,v,w;
        cin >> u >> v >> w;
        u--;v--;
        G[u].push_back(make_pair(v,w));
        G[v].push_back(make_pair(u,w));
    }
    dfs(0,0);
    rep(i,n){
        cout<<ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long


int main() {
  string s;
  cin >> s;
  
  int ans = 0;
  
  rep(i,4) {
    if (s[i]=='+') ans++; 
    if (s[i]=='-') ans--; 
  }  
  
  cout << ans << endl;
  
}



Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int h=0, w=0;
  char s[60][60];
  int dx[4]={1, -1, 0, 0};
  int dy[4]={0, 0, 1, -1};
  int ans=1, flag=0;
  int i=0, j=0, k=0;
  int i2=0, j2=0;

  scanf("%d %d", &h, &w);

  for(i=0; i<h; i++){
    scanf("%s", &s[i]);
  }

  for(i=0; i<h; i++){
    for(j=0; j<w; j++){
      if(s[i][j]=='#'){
        flag=0;
        for(k=0; k<4; k++){
          i2=i+dx[k];
          j2=j+dy[k];
          if(i2>=0 && i2<h &&
            j2>=0 && j2<w && s[i2][j2]=='#'){
              flag=1;
            }
         }
         if(!flag)
          ans=0;
      }
    }
  }

if(ans==1)
  printf("Yes\n");
else
  printf("No\n");

  return 0;
}


Measured memory_bytes: 128
class Dice:
    def __init__(self,l):
        self.l = l
    
    def N(self):
        self.l[0], self.l[4], self.l[5], self.l[1] = self.l[1], self.l[0], self.l[4], self.l[5]
        
    def S(self):
        self.l[0], self.l[1], self.l[5], self.l[4] = self.l[4], self.l[0], self.l[1], self.l[5]
    
    def W(self):
        self.l[0], self.l[3], self.l[5], self.l[2] = self.l[2], self.l[0], self.l[3], self.l[5]
        
    def E(self):
        self.l[0], self.l[2], self.l[5], self.l[3] = self.l[3], self.l[0], self.l[2], self.l[5]
    
    def number(self, i):
        return self.l[i - 1]
    
        
dice = Dice(list(map(int, input().split())))
s = list(input())

for i in s:
    if i == "N":
        dice.N()
    elif i == "S":
        dice.S()
    elif i == "W":
        dice.W()
    elif i == "E":
        dice.E()
print(dice.number(1))    
  

Measured memory_bytes: 5608
def main():
  N, K = map(int, input().split(" "))
  X = list(map(int, input().split(" ")))
  answer = 10 ** 9 + 7
  for i in range(0, N - K + 1):
    time = X[i + K - 1] - X[i] + min(abs(X[i]), abs(X[i + K - 1]))
    answer = min(answer, time)
  print(answer)


if __name__ == "__main__":
  main()

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

using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  cin >> N;

  vector<int> C(N + 1);
  vector<long long> S(N + 1);
  vector<int> F(N + 1);

  vector<long long> ans(N + 1);

  for (int i = 1; i <= N - 1; i++) {
    cin >> C[i] >> S[i] >> F[i];
  }

  for (int i = 1; i < N; i++) {
    long long time = S[i];
    for (int j = i; j <= N - 1; j++) {
      time += C[j];
      if (j == N - 1) {
        break;
      }
      if (time < S[j + 1]) {
        time = S[j + 1];
      } else {
        time += time % F[j + 1] == 0 ? 0 : (F[j + 1] - (time % F[j + 1]));
      }
    }
    ans[i] = time;
  }
  ans[N] = 0;

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

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int cnt[(int)2e5+5];
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<n;i++)
{
int j;
scanf("%d",&j);
cnt[j]++;
}
for(int i=1;i<=n;i++) printf("%d\n",cnt[i]);
return 0;
}


Measured memory_bytes: 2456
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rep1n(i, n) for(int i=1;i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
int dn(int n, int d) {
	
	if (n%d == 0) {
		return 1 + dn(n / d, d);
	}
	else return 0;
}
bool isPrime(int n) {
	// returns whether n is prime number or not
	// n should be in range [0, lim].
	// to see detail, search "Sieve of Eratosthenes"
	static int lim = 1e5;
	static bool done = false;
	static vector<bool> isp(lim + 1, 1);
	if (!done) {
		isp[0] = isp[1] = false;
		for (int i = 2; i <= lim; i++) {
			if (isp[i]) {
				for (int j = i + i; j <= lim; j += i) {
					isp[j] = false;
				}
			}
		}
		done = true;
	}
	return isp[n];
}

int main() {

	int n;
	cin >> n;
	list<ll>a;
	rep1n(i, n) {
		if (isPrime(i)) {
			int sum = 0;
			rep1n(j, n) {
				sum += dn(j, i);
			}
			a.push_back(sum);
		}
	}
	ll ans = 1;
	for (auto v : a) {
		ans = ans*(v + 1) % 1000000007;
	}
	cout << ans;


	return 0;
}

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

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

	vector<int> SX(n), SY(n), CX(m), CY(m), ans(n);

	for(int s=0; s<n; s++) cin>>SX[s]>>SY[s];
	for(int c=0; c<m; c++) cin>>CX[c]>>CY[c];

	for(int s=0; s<n; s++){
		int mini = 1e9;
		for(int c=0; c<m; c++){
			int m  = abs(SX[s]-CX[c]) + abs(SY[s]-CY[c]);
			if(mini>m){
				mini = m;
				ans[s] = c+1;
			}
		}
	}

	for(int s=0; s<n; s++) cout<<ans[s]<<"\n";
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

vector<pair<int, int> > v[2];

bool canpair(int i, int j)
{
	return (v[0][i].first < v[1][j].first && v[0][i].second < v[1][j].second);
}

int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < n; j++){
			int a, b;
			cin >> a >> b;
			v[i].push_back(make_pair(a, b));
		}
		sort(v[i].begin(), v[i].end());
	}
	vector<bool> isused(n, false);
	int ans = 0;
	for(int i = 0; i < n; i++){
		int tmp = -1;
		for(int j = n - 1; j >= 0; j--){
			if(!isused[j] && canpair(j, i) && (tmp == -1 || v[0][tmp].second < v[0][j].second)){
				tmp = j;
			}
		}
		if(tmp >= 0){
			isused[tmp] = true;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    int sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        sum += a[i];
    }
    int ans = -1;
    int dist = sum;
    for (int i = 0; i < N; i++) {
        if (dist > abs(sum-a[i]*N)) {
            dist = abs(sum-a[i]*N);
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256