akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

#define N 8
#define NOT_FREE 0
#define FREE 1

int board[N][N];

// row:-  col:|  pos:/  neg:\

int row(int i){
    for(int j = 0; j < N; j++){
        if(board[i][j] == NOT_FREE){
            return NOT_FREE;
        }
    }
    return FREE;
}

int col(int i){
    for(int j = 0; j < N; j++){
        if(board[j][i] == NOT_FREE){
            return NOT_FREE;
        }
    }
    return FREE;
}

int pos(int i){
    if(i >= N-1){
        for(int j = N-1; i-j < N; j--){
            //printf("%d,%d\n", j, i-j);
            if(board[j][i-j] == NOT_FREE){
                return NOT_FREE;
            }
        }
    }else{
        for(int j = i; j >= 0; j--){
            //printf("%d,%d\n", j, i-j);
            if(board[j][i-j] == NOT_FREE){
                return NOT_FREE;
            }
        }
    }
    return FREE;
}

int neg(int i){
    if(i >= N-1){
        for(int j = N-1; 2*(N-1)-i >= 0; j--){
            //printf("%d,%d\n", j, 2*(N-1)-i);
            if(board[j][2*(N-1)-i] == NOT_FREE){
                return NOT_FREE;
            }
            i++;
        }
    }else{
        int k = 0;
        for(int j = i+1; j > 0; j--){
            //printf("%d,%d\n", j-1, N-1-k);
            if(board[j-1][N-1-k] == NOT_FREE){
                return NOT_FREE;
            }
            k++;
        }
    }
    
    return FREE;
}

//-------//------//

void init(){
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            board[i][j] = FREE;
        }
    }
}

void PrintBoard(){
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            printf("%c", board[i][j] == FREE ? '.' : 'Q');
        }
        printf("\n");
    }
}

void PutQueen(int i){
    
    if(i == N){
        PrintBoard();
        return;
    }
    
    if(row(i) == NOT_FREE){
        PutQueen(i+1);
    }else{
    
    for(int j = 0; j < N; j++){
        if(row(i) == NOT_FREE || col(j) == NOT_FREE || pos(i+j) == NOT_FREE || neg(i-j+(N-1)) == NOT_FREE){
            continue;
        }
        // j行にqueenを置いてみる
        board[i][j] = NOT_FREE;
        //printf("put on (%d, %d)\n", i, j);
        PutQueen(i+1); // 次の列へ
        // ここに戻ってきたら置いたqueenを取る
        board[i][j] = FREE;
        //printf("  take out (%d, %d)\n", i, j);
    }
    }
}

int main(){
    int n, y, x;
    scanf("%d", &n);
    
    init();
    
    for(int i = 0; i < n; i++){
        scanf("%d %d", &y, &x);
        board[y][x] = NOT_FREE;
    }
    
#ifdef D
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            //printf("%d ", row(i));
            printf("%d ", col(j));
            //printf("%d ", pos(i+j));
            //printf("%d ", neg(i-j+N-1));
        }
        printf("\n");
    }
#else
    
    PutQueen(0);
#endif
    
    return 0;
}



Measured memory_bytes: 2692
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
 
int main(){
    int n;
    cin>>n;
    int ans=0;
    REP(i, 1, n+1)
        if(i%2==1) ans += 1;
    cout << ans/float(n) << endl;
    
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque

readline = sys.stdin.readline

ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))

def solve():
  n, m = nm()
  G = [list() for _ in range(n)]
  for _ in range(m):
    a, b = nm()
    a -= 1; b -= 1
    G[a].append(b)
    G[b].append(a)
  Q = int(input())
  color = [0]*n
  dist = [-1]*n
  queries = [tuple(nm()) for _ in range(Q)][::-1]
  for v, d, c in queries:
    v -= 1
    q = deque()
    q.append((v, d))
    while q:
      v, d = q.popleft()
      if dist[v] >= d:
        continue
      dist[v] = d
      if not color[v]: color[v] = c
      for x in G[v]:
        if d - 1 > dist[x]:
          q.append((x, d-1))
  print(*color, sep='\n')
  return

solve()


Measured memory_bytes: 43916
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()


using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

#define debug(x) cout << #x " = " << (x) << endl

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

template <typename T>
void do_uniq(vector<T> vec) {
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

#define solvsh
//#define multi
#ifdef solvsh

#define LOG(FMT...) fprintf(stderr, FMT)

const int MAXN = 1e3 + 20;
const int INF = 1e9;

ll mod = 1e9 + 7;

ll ml(ll a, ll b){
    return(a * b) % mod;
}

ll add(ll a, ll b) {
    return (a + b) % mod;
}

void solve() {

    int answr = 0;

    string s,t;
    cin >> s >> t;

    for (int i = 0; i < s.size(); ++ i){
        if (s[i] != t[i]) ++answr;
    }


    cout << answr;
}


#else

void solve() {

}

#endif


void multisolve() {
    int t;
    cin >> t;

    int i = 1;
    while (t--) {
//        cout << "Mission #" << (i++) << ": \n";

        solve();
//        cout << "\n";
    }
}



#define int int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);

#ifdef multi
//    gen();

//    doo();

    multisolve();
#else
    solve();
    //    gen();
#endif

}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    int ans = n;
    for(int i = 0; i < n; i++){
        int k;
        cin >> k;
        const int X = sqrt(1 + 2LL * k) / 2;
        for(int x = 1, mod = 3; x <= X; x++, mod += 2){
            if(k % mod == x){
                ans--;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second > b.second; }

int main() {
    int n;
    cin >> n;
    int odds=0;
    rep(i,n)if((i+1)%2!=0)odds++;
    cout<<fixed<<setprecision(10)<<(double)odds/n<<endl;
}

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

int main(){
    int a,b,K; cin >> a >> b >> K;
    vector <int> A(100);
    vector <int> B(100);
    vector <int> C(100);
    
    int j=0;
    rep(i,a){
        if (a%i==0){
            A[j]=i;
            j++;
            
        }
    }
    
    int J=0;
    rep(i,b){
        if (b%i==0){
            B[J]=i;
            J++;
        }
    }
    
    
    int k=0;
    for (int i=0; i<j; i++){
        for (int j=0; j<J; j++){
            if (A[i]==B[j]){
                C[k]=A[i];
                k++;
                break;
            }
        }
        
    }
    cout << C[(k-1)-(K-1)];
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 1000;

int main() {
	int n;cin>>n;
	int x[N],y[N];
	rep(i,n) {cin>>x[i]>>y[i];}
	bool odd;
	if(abs(x[0]+y[0])%2==1) odd=true;
	else odd=false;
	rep(i,n) if((abs(x[i]+y[i])%2==1)!=odd) {cout<<-1<<endl;return 0;}
	int d[40],m=31;
	for(int i=0;i<=30;i++) d[i]=1<<(30-i);
	if(!odd) {m++;d[31]=1;}
	string w[N];
	rep(i,n){
		for(int j=0;j<m;j++){
			if(y[i]>=-x[i]&&y[i]<x[i]) {w[i]+='R';x[i]-=d[j];}
			else if(y[i]>=x[i]&&y[i]>-x[i]) {w[i]+='U';y[i]-=d[j];}
			else if(y[i]<=-x[i]&&y[i]>x[i]) {w[i]+='L';x[i]+=d[j];}
			else {w[i]+='D';y[i]+=d[j];}
		}
	}
	cout<<m<<endl;
	rep(i,m-1) cout<<d[i]<<' ';
	cout<<d[m-1]<<endl;
	rep(i,n) cout<<w[i]<<endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
  int N;
  cin >> N;
  vector<ll>cat(N);
  for (int i = 0; i < N; i ++) cin >> cat[i];
  sort(cat.begin(), cat.end());
  reverse(cat.begin(), cat.end());
  int fl = 0;
  int cp = 1;
  ll ans = 0;
  for (int i = 1; i < N; i ++) {
    if (cp == 0) {
      ans += cat[fl];
      cp ++;
    }
    else {
      ans += cat[fl];
      cp = 0;
      fl ++;
    }
    //cout << 'r' << endl;
    //cout << ans << endl;
  }
  cout << ans << endl;
}



Measured memory_bytes: 4844
// Why am I so dumb? :c
#include<bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int MAXN = (int)2e5 + 5;

int l[MAXN], r[MAXN];

int arr[MAXN], n;

ll ans;

void solve() {
    scanf("%d", &n);

    for (int i = 1; i <= n; ++i) {
        scanf("%d", &arr[i]);
    }

    stack<int> S;

    for (int i = 1; i <= n; ++i) {
        while (!S.empty() && arr[S.top()] > arr[i]) {
            S.pop();
        }

        l[i] = (S.empty() ? 0 : S.top()) + 1;
        S.push(i);
    }

    while (!S.empty()) {
        S.pop();
    }

    for (int i = n; i > 0; --i) {
        while (!S.empty() && arr[S.top()] > arr[i]) {
            S.pop();
        }

        r[i] = (S.empty() ? n + 1 : S.top()) - 1;
        S.push(i);
    }

    for (int i = 1; i <= n; ++i) {
        ans += (i - l[i] + 1ll) * (r[i] - i + 1ll) * arr[i];
    }

    printf("%lld\n", ans);
}

int main() {
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <cstdint>
#include <queue>
using namespace std;

int main() {
  uint64_t K;
  cin >> K;
  
  queue<uint64_t> Q({1, 2, 3, 4, 5, 6, 7, 8, 9});

  uint64_t q;
  for(int i = 0; i < K; ++i) {
    q = Q.front(); Q.pop();

    if((q % 10) != 0) Q.push(10 * q + (q % 10) - 1);
    Q.push(10 * q + (q % 10));
    if((q % 10) != 9) Q.push(10 * q + (q % 10) + 1);
  }

  cout << q << endl;
  
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <queue>
#define to first
#define cost second
const int inf=1e9+7;
using namespace std;
int main(){

  int n,tmp,r=0,flag[100]={},v=0;
  cin>>n;
  vector <pair<int,int> > gl[n];
  priority_queue <pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > >q;
  //for(int i=1;i<n;i++) mincost[i]=inf;                                                                                                                                                       

  for(int i=0;i<n;i++) for(int j=0;j<n&&cin>>tmp;j++) if(tmp!=-1) gl[i].push_back(make_pair(j,tmp));
  int now=0;
  for(int j=0;j<n-1;j++){
    for(int i=0;i<gl[now].size();i++) if(!flag[gl[now][i].to]) q.push(make_pair(gl[now][i].cost,gl[now][i].to));
    flag[now]=1;
    // cout<<now<<" "<<q.top().first<<endl;                                                                                                                                                    
    for(;flag[q.top().second];) q.pop();
    if(q.empty()) break;
    r+=q.top().first;
    now=q.top().second;
    q.pop();
  }
  cout<<r<<endl;
  return 0;

}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int a,b,ans;
  cin>>a>>b;
  if(a>0&&b>0) cout<<"Positive"<<endl;
  else if(a<=0&&0<=b) cout<<"Zero"<<endl;
  else{
    if(a<0&&b>0) ans=0-a;
    else if(a<0&&b<0) ans=b-a;
    
    if((ans+1)%2==0) cout<<"Positive"<<endl;
    else cout<<"Negative"<<endl;
  }
}


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

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))

#define INF 1000000000

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int gcd(int a, int b)
{
	if (a < b)
		swap(&a, &b);

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

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

int main()
{
	long long int H;
	int N;
	int M;
	int K;
	int L;
	int A[200000];
	long long int ans = 0;
	int flag = 0;
	long long int count = 0;

	scanf("%lld", &H);

	long long int tmp=1;

	while (1)
	{
		if (H == 1)
			break;

		//count++;

		if (H > 1)
		{
			H = H / 2;
			count += tmp;
		}
		tmp *= 2;

		//printf("%d\n", count);

	}
	H = H / 2;
	count += tmp;
	
	printf("%lld\n", count);
}

Measured memory_bytes: 256
object Main extends App{
    def readLine() = io.StdIn.readLine()
    
    val h = readLine().toInt
    val w = readLine().toInt
    val n = readLine().toInt
    
    val answer = math.ceil(n.toDouble / math.max(h, w).toDouble)
    
    println(answer.toInt)
}


Measured memory_bytes: 25416
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int N, A, B;

int main()
{
	in >> N >> A >> B;
	out << std::min(A*N, B) << std::endl;
	return 0;
}

Measured memory_bytes: 256
a = [input().split() for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
total = []
 
for i in range(n):
  for k in range(3):
    for j in range(3):
      if b[i] == int(a[k][j]):
          total.append(k * 3 + j)
          
if 0 in total and 1 in total and 2 in total: 
  print("Yes")
elif 3 in total and 4 in total and 5 in total: 
  print("Yes")
elif 6 in total and 7 in total and 8 in total: 
  print("Yes")
elif 0 in total and 3 in total and 6 in total: 
  print("Yes")
elif 1 in total and 4 in total and 7 in total: 
  print("Yes")
elif 2 in total and 5 in total and 8 in total: 
  print("Yes")
elif 0 in total and 4 in total and 8 in total: 
  print("Yes")
elif 2 in total and 4 in total and 6 in total: 
  print("Yes")
else:
  print("No")

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

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

/*
 string -> int : stoi(S);
 int -> string : to_string(N);
 Sのn文字以降をm文字取り出す : S.substr(n,m)

 int: -2,147,483,648 ～ 2,147,483,647 (2×10^9)
 ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 (9×10^18)

*/

int main() {

 int n,k, count=0, ans=0,Max=-2147483648;
 
 cin >> n >> k;
 vector<ll> v(n);
 rep(i,n){
   cin >> v[i];
 }

 int m = min(n,k);

 for (int i = 0; i <= m; i++){
   for(int l = 0; i+l<= m; l++){
     vector<ll> get;
     rep(a,i){
       get.push_back(v[a]);
     }
     rep(a,l){
       get.push_back(v[n-1-a]);
     }

     sort( get.begin(), get.end());
     int bb = get.size();
     int aa = min(bb,k-i-l);
     ll ss = max(aa,0);
     rep(b,ss){
       if(get[b]<0) get[b]=0;
       else break;
     }
     count=0;
     rep(a,get.size()){
       count+=get[a];
     }
     Max = max(Max,count);
   }
 }
 cout << Max << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define OK 1
#define NG -1

typedef struct
{
	int iTop;
	int iNorth;
	int iEast;
	int iSouth;
	int iWest;
	int iBottom;
}DICE;

void vdDiceRoll(DICE* stDice, char chOrder);
void vdDiceRollRight(DICE* stDice);
int iCheck2Dice(DICE stDice1, DICE stDice2);
int iCheck2DiceRound(DICE stDice1, DICE stDice2);

#define DICE_NUM 2

// 2つのダイスの目が与えられ、それらが同じさいころかどうか判定
int main()
{
	DICE stDice[DICE_NUM];
	int iInputQuestionNum;
	int iQTop, iQSouth;

	int iCnt;

	// さいころの目を入力
	for (iCnt = 0; iCnt < DICE_NUM; iCnt++)
	{
		scanf("%d", &stDice[iCnt].iTop);
		scanf("%d", &stDice[iCnt].iSouth);
		scanf("%d", &stDice[iCnt].iEast);
		scanf("%d", &stDice[iCnt].iWest);
		scanf("%d", &stDice[iCnt].iNorth);
		scanf("%d", &stDice[iCnt].iBottom);
	}

	if (iCheck2Dice(stDice[0], stDice[1]) == OK)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}

	return 0;
}

// chOrderの方角にダイスを転がす
void vdDiceRoll(DICE* stDice, char chOrder)
{
	int iTopTmp = stDice->iTop;	// Top退避用
	switch (chOrder)
	{
	case 'N':
		stDice->iTop = stDice->iSouth;
		stDice->iSouth = stDice->iBottom;
		stDice->iBottom = stDice->iNorth;
		stDice->iNorth = iTopTmp;
		break;
	case 'E':
		stDice->iTop = stDice->iWest;
		stDice->iWest = stDice->iBottom;
		stDice->iBottom = stDice->iEast;
		stDice->iEast = iTopTmp;
		break;
	case 'S':
		stDice->iTop = stDice->iNorth;
		stDice->iNorth = stDice->iBottom;
		stDice->iBottom = stDice->iSouth;
		stDice->iSouth = iTopTmp;
		break;
	case 'W':
		stDice->iTop = stDice->iEast;
		stDice->iEast = stDice->iBottom;
		stDice->iBottom = stDice->iWest;
		stDice->iWest = iTopTmp;
		break;
	default:
		// 上記以外は何もしない
		break;
	}

	return;
}

// 上面から見て時計回りにダイスを回転
void vdDiceRollRight(DICE* stDice)
{
	int iSouthTmp = stDice->iSouth;

	stDice->iSouth = stDice->iEast;
	stDice->iEast = stDice->iNorth;
	stDice->iNorth = stDice->iWest;
	stDice->iWest = iSouthTmp;
	return;
}

// stDice1とstDice2が同じダイスかどうか判定
// 出力：同じダイスならOK、異なるダイスならNG
int iCheck2Dice(DICE stDice1, DICE stDice2)
{
	int iCnt;

	// 6面すべてを上にしてチェック
	//横回転
	for (iCnt = 0; iCnt < 4; iCnt++)
	{
		if (iCheck2DiceRound(stDice1, stDice2) == OK)
		{
			return OK;
		}
		vdDiceRoll(&stDice2, 'E');
	}
	// 縦回転
	for (iCnt = 0; iCnt < 3; iCnt++)
	{
		vdDiceRoll(&stDice2, 'N');
		// 上の横回転時にチェック済みの状態なのでそれ以外が上なら
		if (iCnt != 1) {
			if (iCheck2DiceRound(stDice1, stDice2) == OK)
			{
				return OK;
			}
		}
	}

	return NG;
}

// stDice2の上面を固定して1回転させたときにstDice1と同じさいころになるかチェック
// 出力：持っているならOK、もっていないならNGを返す
int iCheck2DiceRound(DICE stDice1, DICE stDice2)
{
	int iCnt;

	// 上面固定一回転してチェック
	for (iCnt = 0; iCnt < 4; iCnt++)
	{
		if (stDice1.iTop == stDice2.iTop &&
			stDice1.iEast == stDice2.iEast &&
			stDice1.iWest == stDice2.iWest &&
			stDice1.iNorth == stDice2.iNorth &&
			stDice1.iSouth == stDice2.iSouth &&
			stDice1.iBottom == stDice2.iBottom
			)
		{
			return OK;
		}
		// 上面固定で時計回り90度回転
		vdDiceRollRight(&stDice2);
	}

	return NG;
}


Measured memory_bytes: 2104
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<math.h>

#define DIV 1000000007
using namespace std;
using ll = long long;

int main(void) {
    int N, A;
    cin >> N >> A;
 
    vector<ll> x(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }

    ll dp[51][51][2501];
    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = 0; k <= 2500; k++) {
                dp[i + 1][j][k] += dp[i][j][k];
                
                if (k + x[i] <= 2500) {
                    dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
                }
            }
        }
    }

   
    ll ans = 0;
    for (int j = 1; j <= N; j++) {
        ans += dp[N][j][j * A];      
    }

    cout << ans << endl;
}

Measured memory_bytes: 51072
let popcnt x =
  let x = (x land 0x5555555555555555) + ((x lsr 1) land 0x5555555555555555) in
  let x = (x land 0x3333333333333333) + ((x lsr 2) land 0x3333333333333333) in
  let x = (x land 0x0f0f0f0f0f0f0f0f) + ((x lsr 4) land 0x0f0f0f0f0f0f0f0f) in
  let x = (x land 0x00ff00ff00ff00ff) + ((x lsr 8) land 0x00ff00ff00ff00ff) in
  let x = (x land 0x0000ffff0000ffff) + ((x lsr 16) land 0x0000ffff0000ffff) in
  (x land 0x00000000ffffffff) + ((x lsr 32) land 0x00000000ffffffff)

let log2 x =
  let x = x lor (x lsr 1) in
  let x = x lor (x lsr 2) in
  let x = x lor (x lsr 4) in
  let x = x lor (x lsr 8) in
  let x = x lor (x lsr 16) in
  let x = x lor (x lsr 32) in
  popcnt x

let () = Scanf.scanf "%d\n" @@ fun l ->
  let n = log2 l in
  let es = List.concat @@ List.concat @@
    [ Array.to_list (Array.init (n - 1) @@ fun i -> [(i + 1, i + 2, 0); (i + 1, i + 2, 1 lsl i)]);
      Array.to_list (Array.init (n - 1) (fun i ->
        if l land (1 lsl i) = 0 then []
        else [(i + 1, n, l lxor (l land ((1 lsl (i + 1)) - 1)))])) ] in
  Printf.printf "%d %d\n" n (List.length es);
  List.iter (fun (u, v, w) -> Printf.printf "%d %d %d\n" u v w) es



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

using ll = long long;
#define int long long
using P = pair<int, int>;
/***** MAIN *****/
signed main() {
  int n, m, x;
  cin >> n >> m >> x;
  int prices[n];
  int books[n][m];
  for(int i = 0; i < n; ++i) {
    cin >> prices[i];
    for(int j = 0; j < m; ++j) {
      cin >> books[i][j];
    }
  }
  int ans = LLONG_MAX;
  for(int bits = 1; bits < (1<<n); ++bits) {
    int price = 0;
    vector<int> keiken(m,0);  // m個のアルゴリズムの経験値
    // n冊の本を買うかどうか判断するループ
    for(int book_i = 0; book_i < n; ++book_i) {
      // ビットが立っていたら買う
      if((bits>>book_i)&1) {
        price += prices[book_i];
        // その本で得られる経験値を加算
        for(int algo_i = 0; algo_i < m; ++algo_i) {
          keiken[algo_i] += books[book_i][algo_i];
        }
      }
    }

    // このビット列で表現される本で最低経験値xを達成できるか？
    bool satisfied = true;
    for(int algo_i = 0; algo_i < m; ++algo_i) {
      if(keiken[algo_i] < x) {
        satisfied = false;
        break;
      }
    }
    // 達成できるなら最安値を更新
    if(satisfied) {
      ans = min(ans, price);
    }
  }

  if(ans == LLONG_MAX) {
    cout << -1;
  } else {
    cout << ans;
  }
  cout << "\n";
  return 0;
}
/***** MAIN *****/


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

int main() {
    // Input
    int n, l, amin, ssum, smin, wnum, ans;
    cin >> n >> l;

    // Init
    amin = 999;
    ssum = 0;

    // Search abs min
    for(int i = 0; i < n; i++){
        wnum = abs(l + i);
        ssum += l + i;
        if (amin > wnum){
            amin = wnum;
            smin = l + i;
        }
    }
    ans = ssum - smin;
    
    // Output
    cout << ans << endl;
}


Measured memory_bytes: 256
arr = Array.new(26, 0)
ch = [*('a'..'z')]

while true
s = gets
break if s == nil
len = s.chomp.length

for i in 1..len
al = s[i-1].downcase.ord - "a".ord
next if al < 0 || al > 25
arr[al] += 1
end
end

for i in 0..25
 puts ch[i] + " : " + arr[i].to_s

end



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

typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  for (int i = 0; i < n; i++) {
    cin >> l[i];
  }
  vector<int> sl = l;
  sort(sl.begin(), sl.end());
  for (int i = 0; i < n; i++) {
    if (l[i] == sl[n - 1]) {
      cout << sl[n - 2] << endl;
    } else {
      cout << sl[n - 1] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};



int main(){
    int A,B;cin >> A >> B;
    if(A < B)swap(A,B);
    if((A-B)%2 == 1){
        cout<<"IMPOSSIBLE"<<endl;
    }else{
        cout<<(A+B)/2<<endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
long long a[200005],f[200005],s[200005];
int main()
{
    long long n,i,ans=0,j;
    memset(f,0,sizeof(f));
    scanf("%lld",&n);
    for(i=0;i<n;i++)
        scanf("%lld",&a[i]);
    s[0]=0;
    for(i=0;i<n;i++)
    {
        if((a[i]^s[0])==(s[0]+a[i]))
            {f[0]++;s[0]^=a[i];}
        else break;
    }
    ans=f[0];
    for(i=1;i<n;i++)
    {
        f[i]=max((long long)0,min(f[i-1]-1,n-i));
        s[i]=s[i-1]^a[i-1];
        for(j=i+f[i-1]-1;j<n;j++)
        {
            if((a[j]^s[i])==(s[i]+a[j]))
            {
                f[i]++;
                s[i]^=a[j];
            }
            else break;
        }
        ans+=f[i];
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 4992
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll n,k,r,s,p;cin>>n>>k>>r>>s>>p;

  string t;cin>>t;
  ll ans=0;
  map<char,char>mp_win,mp_ww;

  mp_win['r']='p';
  mp_win['s']='r';
  mp_win['p']='s';

  string ok="";
  rep(i,0,t.length()){
    if(i-k>=0){
      if(t[i]==t[i-k]){
        if(ok[i-k]=='0')ok+=mp_win[t[i]];
        else ok+='0';
      }else{
        ok+=mp_win[t[i]];
      }
    }else{
      ok+=mp_win[t[i]];
    }
  }
  rep(i,0,ok.length()){
    if(ok[i]=='r')ans+=r;
    else if(ok[i]=='s')ans+=s;
    else if(ok[i]=='p')ans+=p;
    // else if(ok[i]=='0')
  }
  // out(ok);
  out(ans);

  return 0;
}


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

using namespace std;
using ll = long long;

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back
#define MOD 1000000007
#define M 1000000

vector<ll> fac(M), finv(M), inv(M);

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < M; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    
    ll X, Y;
    cin >> X >> Y;

    ll cnt = 0;
    ll m, n;
    m = 2 * Y - X;
    n = 2 * X - Y;

    COMinit();

    ll c = 0;
    if((m >= 0) && (m % 3 == 0) && (n >= 0) && (n % 3 == 0) && ((m + n) % 3 == 0)){
        c = COM((m+n)/3, m/3);
    }

    _PR(c);

    return 0;
}

/*



*/

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

int main() {
    long long n,m;
    long long mod = pow(10,9) + 7;
    cin >> n >> m;
    long long ans=0;
    for (int i = m; i < n+2; i++) { 
        ans+=i*(n-i+1);
        ans++;
        ans%=mod;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDD pair<double,double>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=200000+10;
const ll mod=1e9+7;
int main()
{
	int n,k,i,x,ans,now;
	while(~scanf("%d%d",&n,&k))
	{
		map<int,int> mp;
		map<int,int> ::iterator it;
		for(i=0;i<n;i++)
		{
			scanf("%d",&x);
			mp[x]++;
		}
		vector<PII > res;
		for(it=mp.begin();it!=mp.end();it++)
		{
			res.pb(MP(it->se,it->fi));
		}
		if(sz(res)<=k)
		{
			puts("0");
			continue;
		}
		sort(all(res));
		ans=0;
		now=sz(res);
		for(i=0;i<sz(res);i++)
		{
			ans+=res[i].fi;
			now--;
			if(now<=k) break;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 11768
// C++ includes
#include <bits/stdc++.h>
// 俳句
using namespace std;

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b)  for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

int main(void){
    ll n,a,b;
    cin >> n >> a >> b;


    cout << min(n*a,b) << endl;
}

Measured memory_bytes: 256
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    h, w, k = map(int, input().split())
    c = [input() for i in range(h)]
    ans = []
    def dfs1(i, a):
        if i == h:
            dfs2(0, [0]*w, a)
            return
        dfs1(i+1, a)
        a[i] = 1
        dfs1(i+1, a)
        a[i] = 0

    def dfs2(i, b, a):
        if i == w:
            cnt = 0
            for i in range(h):
                for j in range(w):
                    if a[i] != 0 and b[j] != 0 and c[i][j] == '#':
                        cnt += 1
            if cnt == k:
                ans.append(1)
            return
        dfs2(i+1, b, a)
        b[i] = 1
        dfs2(i+1, b, a)
        b[i] = 0

    dfs1(0, [0] * h)
    print(len(ans))
main()

Measured memory_bytes: 9476
#include <bits/stdc++.h>
using namespace std;
double n;
vector<int> x(10, 0);
vector<int> y(10, 0);

double len(int i, int j) {
    double dx = x.at(i) - x.at(j);
    double dy = y.at(i) - y.at(j);
    return sqrt(dx*dx+dy*dy);
}

int main() {
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> x.at(i) >> y.at(i);
    }

    double sum = 0.0;
    double total = 1.0;
    vector<int> p(n);
    for(int i = 0; i < n; ++i) {
        p.at(i) = i+1;
        total *= i+1;
    }

    do {
        for(int i = 0; i < n-1; ++i) {
            sum += len(p.at(i+1), p.at(i));
        }
    } while(next_permutation(p.begin(), p.end()));

    double ans = sum / total;

    printf("%.14f\n", ans);
}

Measured memory_bytes: 256
# ちーともわからんので解説見た
# ら、悔しさあふれる感じ
# NGになる文字の並びは限定される。3文字のものは"ACG" "GAC", 4文字のものは"AxGC", "AGxC"
# ここで, "AAGC"とか"AGCC"なんてのを考え出すと「すでに"AGC"が含まれとるやんけ」->（だから何？）みたいなよくわからん思考に陥ってしまった
# （いまみてるのとそれ以前の3つを保存して探索すると結局かぶらず全探索できるので考えなくていい）

# n = input()

# なんで？？？？？？？？？？？
# これが無限ループになるの？？？？？？？？？？？？？？？？
# は？？？？？？？？？？？？？？？？？？？？？？？？？？？
# def f(i, s):
#     if i == n:
#         return 1
#     # print("now s : {}".format(s))
#     ret = 0
#     for c in "ACGT":
#         print(s + c)
#         is_include = True if "AGC" in s + c else False
#         if is_include:
#             continue
#         ret += f(i + 1, s[1:] + c)
#     return ret
# print(f(0, "xxx"))
# coding: utf-8
# Your code here!

n = int(input())
memo = {}


def f(i, s):
    if (i, s) in memo:
        return memo[(i, s)]
    if i == n:
        return 1
    ret = 0
    for c in "AGCT":
        flag = False
        for j in range(4):
            t = list(s + c)
            if j >= 1:
                t[j], t[j - 1] = t[j - 1], t[j]
            if "AGC" in "".join(t):
                flag = True
        if not flag:
            ret += f(i + 1, s[1:] + c)
            ret %= 10 ** 9 + 7
    memo[(i, s)] = ret
    return ret


print(f(0, "TTT"))


Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
x,y
DFSで全探索かな
でもどうやって･･･。
..
..
2通り

...
...
...
6通り

1 1 1 1 1
1 2 3 4 5
1 3 6 1015
1 4 102035
1 5 153570
なんだっけこれ
2C1,4C2,6C3,8C4,10C5通りか
160C80は全探索無理か
159個の数字、選択をして偏りをなくす取り方も

可能性網羅のDPか
おさえるのは差だけ

1024MBって、ぎりぎりか
bfsかな
6500*160通りくらい
push_backのほうがいいかな
setでいれる？

座標は{x,y}
配列はDP[y][x]
まじややこしい
これ不慣れ。永遠に。

TLEなんかい
なんでだ
そんなに多くないと思うんだが
used判定必要だた
必要パターンまで消えてるな

自分のマスから見て左上と上で見ていくか
がんばって書いたBFS･･･。

forでもTLEだな
H+W)^2*2*6400
160*160*2*6400
6400をへらす。

setが重いのかなーーーーー
わかんねーーーー
setやめよう
*/

ll H,W;
vector<vector<ll>> A(100,vector<ll>(100,0));
vector<vector<vector<bool>>> DP(100,vector<vector<bool>>(100,vector<bool>(6500,false)));
ll vx[2]={-1,0};
ll vy[2]={0,-1};

int main(){
  cin>>H>>W;
  for(ll i=0; i<H; i++) for(ll j=0; j<W; j++) cin>>A[i][j];
  for(ll i=0; i<H; i++) for(ll j=0; j<W; j++){
    ll b; cin>>b;
    A[i][j]=abs(A[i][j]-b);
  }
  DP[0][0][A[0][0]]=true;
  ll end=H+W-2;
  for(ll d=1; d<=end; d++){//距離
    for(ll x=max(0LL,d-H); x<=min(d,W-1); x++){
      ll y=d-x;
      for(ll i=0; i<2; i++){
        ll nx=x+vx[i];
        ll ny=y+vy[i];
        if(nx<0 || ny<0) continue; 
        ll m=A[y][x];
        for(ll j=0; j<=6400; j++){
          if(DP[ny][nx][j]){
            DP[y][x][abs(j-m)]=true;
            DP[y][x][j+m]=true;
          }
        }
      }
    }
  }
  for(ll i=0; i<=6400; i++){
    if(DP[H-1][W-1][i]){
      cout<<i<<endl;
      break;
    }
  }
}

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

int main()
{
    int a,b,n,m[200001];
    cin>>a>>b;
    int max=0;
    for(int i=0;i<b;i++){
        cin>>n;
        m[i]=n;
        max+=n;
    }
    int now=max;
    for(int i=b;i<a;i++){
        cin>>m[i];
        now+=m[i];
        now-=m[i-b];
        if(now>max)
            max=now;
    }
    double v=(max+b)*1.0/2;
    cout<<fixed<<setprecision(12)<<v;

    return 0;
}


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

int main() {
  ll n;
  string s,ans="Yes";
  cin >> n >> s;
  if (n%2==1) cout << "No" << endl;
  else{
  	rep(i,n/2){
			if(s.at(i)!=s.at(n/2+i)) ans="No";
    }    
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i,s,p,l,k,sum;
    cin>>k;

        s=k/500;
        //cout<<s<<endl;
        k=k%500;
        //cout<<k<<endl;
        l=k/5;
        //cout<<l<<endl;
        k=k%5;
        //cout<<k<<endl;
        sum=(s*500*2)+(l*5);
       // cout<<sum<<endl;

    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a); i > (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod1=1000000007;
ll mod2=67280421310721;
ll mod3=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b%2==1)
		{
			res*=a;
			res%=mod3;
		}
		a*=a;
		a%=mod3;
		b>>=1;
	}
	return res;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		int n;
		cin>>n;
		while(n)
		{
			if(n%10==7)
			{
				cout<<"Yes";
				return 0;
			}
			n/=10;
		}
		cout<<"No";
	}
	return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define pb                push_back
#define int               long long
#define M                 1000000007
#define MM                998244353
#define fr                first
#define sc                second
#define vc                vector
#define pii               pair<int,int>
#define msi               map<string,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define piii              pair<int,pii>

	signed main() {
	
		   int t=1;
		  //cin>>t;
		   while(t--)
		   {
		   		
		   	int n,k,w,mx=0,sum=0,xx=0;
		             string s;

		        cin>>n;
	int a[n],ii[n],b[n],c[n],p[n],q[n];
   for(int i=1;i<=n;i++)
   if(i%3!=0&&i%5!=0)sum+=i;
cout<<sum<<endl;
}
 
	} 

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("First");}else{puts("Second");}
const int MX = 200005;

vi to[MX];

P dfs(int v, int d=1, int p=-1) {
  P res(d,v);
  for (int u : to[v]) {
    if (u == p) continue;
    maxs(res,dfs(u,d+1,v));
  }
  return res;
}

int main() {
  int n;
  scanf("%d",&n);
  rep(i,n-1) {
    int a,b;
    scanf("%d%d",&a,&b);
    --a; --b;
    to[a].pb(b);
    to[b].pb(a);
  }
  int v = dfs(0).se;
  int l = dfs(v).fi;
  if (l%3 != 2) yn;
  return 0;
}






















Measured memory_bytes: 26752
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.MArray as MA
import Control.Monad.ST

modN = 1000000007


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

pow :: Int -> Int -> Int -> Int
pow base 1 modNum = base `mod` modNum
pow base time modNum
    | odd time = let 
        a = pow base (time `div` 2) modNum `mod` modNum
        in
        a * a * base `mod` modNum
    | otherwise = let
        a = pow base (time `div` 2) modNum `mod` modNum
        in
        a * a `mod` modNum

combi :: Integral a => a -> a -> a
combi n k
    | k > n = 0
    | n == k = 1
    | k > (n - k) = combi n (n - k)
    | otherwise = product [n, (n - 1)..(n - k + 1)] `div` product [1..k]

solve :: Int -> [Int] -> [Int]
solve n as = let
    arr = M.fromList $ zip [1..] as
    numMap =  foldr (M.alter $ \case
                        Nothing -> Just 1
                        Just x -> Just $ x + 1
                    ) M.empty as
    (combiMap, total) = foldl' (\(b, tot) a -> case M.lookup a numMap of
                                    Nothing  -> (b, tot)
                                    Just x -> let ansx = combi x 2
                                        in
                                        (M.insert a ansx b, tot + ansx)
                    ) (M.empty, 0) [1..n]
    ans x = let
        num = arr M.! x
        counter = numMap M.! num
        combiNum = combiMap M.! num
        in
            total - combiNum + combi (counter - 1) 2
    in
    ans <$> [1..n]


main :: IO ()
main = do
    n <- readInt
    as <- readInts
    forM_ (solve n as) print




Measured memory_bytes: 97916
#include "bits/stdc++.h"
using namespace std;

int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)cin >> A[i];

    int total = accumulate(A.begin(), A.end(), 0);

    if (total >= H)cout << "Yes";
    else cout << "No";
}

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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for(int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  int cnt = 0;
  for(int i = 0; i < N; i++) {
    if(S.at(i) == "AC") {
      cnt++;
    }
  }
  cout << "AC x ";
  cout << cnt << endl;
  cnt = 0;
  for(int i = 0; i < N; i++) {
    if(S.at(i) == "WA") {
      cnt++;
    }
  }
  cout << "WA x ";
  cout << cnt << endl;
  cnt = 0;
  for(int i = 0; i < N; i++) {
    if(S.at(i) == "TLE") {
      cnt++;
    }
  }
  cout << "TLE x ";
  cout << cnt << endl;
  cnt = 0;
  for(int i = 0; i < N; i++) {
    if(S.at(i) == "RE") {
      cnt++;
    }
  }
  cout << "RE x ";
  cout << cnt << endl;
}


Measured memory_bytes: 6428
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    String[] card;
    int i;
    int[] a, buba, sela;
    char[] c, bubc, selc;

    n = sc.nextInt();
    card = new String[n];
    a = new int[n];
    buba = new int[n];
    sela = new int[n];
    c = new char[n];
    bubc = new char[n];
    selc = new char[n];

    for(i = 0;i < n;i++){
      card[i] = sc.next();
      c[i] = card[i].charAt(1);
      a[i] = c[i] - '0';
      buba[i] = a[i];
      sela[i] = a[i];
      c[i] = card[i].charAt(0);
      bubc[i] = c[i];
      selc[i] = c[i];
    }

    bubblesort(buba, bubc, n);
    System.out.println("Stable");
    selectionsort(sela, selc, n);
    for(i = 0;i < n;i++){
      if(selc[i] != bubc[i]){
        break;
      }
    }
    if(i < n){
      System.out.println("Not stable");
    }else{
      System.out.println("Stable");
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }

  private static void bubblesort(int[] buba, char[] bubc, int n){
    int i, j, tmp;
    char ctmp;

    for(i = 0;i < n - 1;i++){
      for(j = 0;j < n - 1 - i;j++){
        if(buba[j] > buba[j + 1]){
          tmp = buba[j];
          buba[j] = buba[j + 1];
          buba[j + 1] = tmp;
          ctmp = bubc[j];
          bubc[j] = bubc[j + 1];
          bubc[j + 1] = ctmp;
        }
      }
    }

    for(i = 0;i < n - 1;i++){
      System.out.print(bubc[i] + "" + buba[i] + " ");
    }
    System.out.println(bubc[n - 1] + "" + buba[n - 1]);

    return;
  }

  private static void selectionsort(int[] sela, char[] selc, int n){
    int i, j, tmp, min;
    char ctmp;

    for(i = 0;i < n - 1;i++){
      min = i;
      for(j = i + 1;j < n;j++){
        if(sela[min] > sela[j])min = j;
      }
      if(min != i){
        tmp = sela[min];
        sela[min] = sela[i];
        sela[i] = tmp;
        ctmp = selc[min];
        selc[min] = selc[i];
        selc[i] = ctmp;
      }
    }

    for(i = 0;i < n - 1;i++){
      System.out.print(selc[i] + "" + sela[i] + " ");
    }
    System.out.println(selc[n - 1] + "" + sela[n - 1]);

    return;
  }
}

Measured memory_bytes: 17324
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
	int n,limit,diff_min,A,B;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		int array[n];

		for(int i=0; i < n; i++){
			scanf("%d",&array[i]);
		}

		diff_min = 2147483647;
		limit = pow(2,n);

		for(int i=0; i < limit; i++){
			A = 0,B=0;
			for(int k=0; k < n; k++){
				if((i & (1 << k))){
					A += array[k];
				}else{
					B += array[k];
				}
			}
			if(diff_min > abs(A-B)){
				diff_min = abs(A-B);
			}
		}

		printf("%d\n",diff_min);

	}

    return 0;
}

Measured memory_bytes: 2696
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
using namespace std;
 
int main() {
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll ans;
  ans=max(a*c,a*d);
  ans=max(b*d,ans);
  ans=max(ans,b*c);
  cout<<ans<<endl;
}


Measured memory_bytes: 3616
package main

import "fmt"


var n, a, b int
var hs [100010]int

func isEnough(k int) bool {
	rest := k
	for i := 0; i < n; i++ {
		h := hs[i] - b*k
		if h > 0 {
			rest -= (h+(a-b)-1) / (a-b)
		}
	}
	return rest >= 0
}

func main() {
	fmt.Scan(&n, &a, &b)
	for i := 0; i < n; i++ {
		fmt.Scan(&hs[i])
	}

	left := 0 // ng
	right := 1000000000 // ok
	for left + 1 < right {
		md := (left + right) / 2
		if isEnough(md) {
			right = md
		} else {
			left = md
		}
	}

	fmt.Printf("%d\n", right)
}


Measured memory_bytes: 6272
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = 1e9 + 7;

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

	ll index = -1;
	rep(i, 0, s.size()) {
		bool match = true;
		if (i > s.size() - t.size()) {
			break;
		}
		ll ti = i;
		ll minex = MAX_L;
		ll ex = 0;
		rep(j, 0, t.size()) {
			if (s[ti] == '?') ex++;

			match &= (s[ti] == '?' || s[ti] == t[j]);
			ti++;
		}
		if (match) {
			if (minex >= ex) {
				minex = ex;
				index = i;
			}
		}
	}

	if (index == -1) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}

	ll i = 0;
	while (i < s.size()) {
		if (i == index) {
			cout << t;
			i += t.size();
		}
		else {
			if (s[i] == '?')cout << 'a';
			else cout << s[i];

			i++;
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256