akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define pb push_back
 
#define limit (int) (2e5 + 5)
#define mod (int) 1000000007

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
using ld = long double;

int main()
{
    // ios_base::sync_with_stdio(false);cin.tie(NULL);
    int a;
    cin >> a;

    cout << (a + a*a + a*a*a);
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  long long T[N];
  for(int i=0; i<N; i++)
    cin >> T[i];
  //ここまで入力

  //T0]からT[N-1]までの最小公倍数を取ればよい
  long long ans = T[0];
  long long gcd;
  for(int i=1; i<N; i++){
    gcd = __gcd(ans, T[i]);
    //オーバーフローを見越して，計算順序を工夫する
    ans = ans/gcd*T[i];
  }
  
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
local n = io.read("*n")
local sum = 0
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
  sum = sum + a[i]
end
local c = 1
local cval = math.abs(sum - a[1] * n)
for i = 2, n do
  if math.abs(sum - a[i] * n) < cval then
    c = i
    cval = math.abs(sum - a[i] * n)
  end
end
print(c - 1)


Measured memory_bytes: 508
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N, M;
ll U[1000], D[1000], X[1000];
ll Y[1000], L[1000], R[1000];

vector<ll> zY, zX;
int tate[4000][4000] ={};
int yoko[4000][4000] ={};

bool canEnter[4000][4000];
queue<pair<int, int>> que;

signed main(){
    cin >> N >> M;
    rep(i, N){
        cin >> U[i] >> D[i] >> X[i];
        zY.pb(U[i]); zY.pb(D[i]);
        zX.pb(X[i]);
    }
    rep(i, M){
        cin >> Y[i] >> L[i] >> R[i];
        zX.pb(L[i]); zX.pb(R[i]);
        zY.pb(Y[i]);
    }
    sort(all(zX));
    zX.erase(unique(all(zX)), zX.end());
    sort(all(zY));
    zY.erase(unique(all(zY)), zY.end());

    rep(i, N){
        tate[lower_bound(all(zX), X[i])-zX.begin()][lower_bound(all(zY), U[i])-zY.begin()]++;
        tate[lower_bound(all(zX), X[i])-zX.begin()][lower_bound(all(zY), D[i])-zY.begin()]--;
    }
    rep(i, zX.size()){
        rep(j, zY.size()-1){
            tate[i][j+1] += tate[i][j];
        }
    }
    rep(i, M){
        yoko[lower_bound(all(zY), Y[i])-zY.begin()][lower_bound(all(zX), L[i])-zX.begin()]++;
        yoko[lower_bound(all(zY), Y[i])-zY.begin()][lower_bound(all(zX), R[i])-zX.begin()]--;
    }
    rep(i, zY.size()){
        rep(j, zX.size()-1){
            yoko[i][j+1] += yoko[i][j];
        }
    }

    int x = lower_bound(all(zX), 0) - zX.begin();
    int y = lower_bound(all(zY), 0) - zY.begin();
    canEnter[x][y] = true;
    que.push({ x,y });
    while(!que.empty()){
        int x = que.front().first;
        int y = que.front().second;
        que.pop();
        if(x == 0 || y == 0 || x == zX.size() || y == zY.size()){
            cout << "INF" << endl;
            return 0;
        }
        if(!tate[x-1][y-1] && !canEnter[x-1][y]){
            canEnter[x-1][y] = true;
            que.push({ x-1,y });
        }
        if(!tate[x][y-1] && !canEnter[x+1][y]){
            canEnter[x+1][y] = true;
            que.push({ x+1,y });
        }
        if(!yoko[y-1][x-1] && !canEnter[x][y-1]){
            canEnter[x][y-1] = true;
            que.push({ x,y-1 });
        }
        if(!yoko[y][x-1] && !canEnter[x][y+1]){
            canEnter[x][y+1] = true;
            que.push({ x,y+1 });
        }
    }

    ll ans = 0;
    rep(i, zX.size()-1){
        rep(j, zY.size()-1){
            if(canEnter[i+1][j+1]){
                ans += (zX[i+1]-zX[i]) * (zY[j+1]-zY[j]);
            }
        }
    }
    cout << ans << endl;
}

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

#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef pair<ll,ll> pll;

int n;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    clock_t ck;
    ck = clock();
    cin >> n;
    cout << (n >= 30 ? "Yes" : "No") << '\n';
    ck = clock()-ck;
    cerr << "It took " << 1.0*ck/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

Measured memory_bytes: 3800
import math

def main():
    n, d, *x = map(int, open(0).read().split())

    cnt = 0
    for i in range(n-1):
        for j in range(i+1, n):
            y = x[i*d:(i+1)*d]
            z = x[j*d:(j+1)*d]
            dist = 0
            for cur_y, cur_z in zip(y, z):
                dist += (cur_y - cur_z) ** 2
            dist = math.sqrt(dist)
            if dist == int(dist):
                cnt += 1

    ans = cnt
    print(ans)
    return()

if __name__ == '__main__':
    main()


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

typedef long long ll;

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

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

    ll ttl = 0;
    rep(i, m) ttl += b[i];

    int j = m;
    int ans = 0;
    // iはAから選ぶ冊の数、つまり0-n
    rep(i, n+1){
        while(j > 0 && ttl > k){
            --j;
            ttl -= b[j];
        }
        // bの中に、一つ引く、Kより小さい時、
        // もしjが０になった時、ttlはｋより大きい場合は
        // このb[j]は条件を満たさないので、breakします
        if(ttl > k) break;
        // でなければ、この状況は条件を満たす
        // それで、もしansより大きい場合は、i✛ｊに変更
        ans = max(ans, i+j);
        // stackoverflowを避ける
        if(i == n) break;
        // 次のloopでaの一冊を既に読んだ、最初は0冊です
        ttl += a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6428
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static final PrintStream so = System.out;
    static final Scanner sc = new Scanner(System.in);
    
    public static void main(String[] args) {
        char[] x = nsToChars();
        int len = x.length;
        
        int countST = 0;
        int countS = 0;
        for (int i = 0; i < len; i++) {
            if (x[i] == 'S') {
                countS++;
                
            } else if (countS > 0) {
                countS--;
                countST++;
            }
        }
        so.println(len - countST*2);
    } 

    static int ni() {
        return sc.nextInt();
    }
    
    static long nl() {
        return sc.nextLong();
    }

    static char[] nsToChars() {
        return sc.next().toCharArray();
    }
}


Measured memory_bytes: 26500
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(){
	
	string a,b,c;
	string d="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
	
	map<string,char> D;
	D["101"] = ' ';
	D["000000"] = '\'';
	D["000011"] = ','; 
	D["10010001"] = '-'; 
	D["010001"] = '.';
	D["000001"] = '?'; 
	D["100101"] = 'A'; 
	D["10011010"] = 'B'; 
	D["0101"] = 'C';
	D["0001"] = 'D'; 
	D["110"] = 'E'; 
	D["01001"] = 'F'; 
	D["10011011"] = 'G';
	D["010000"] = 'H'; 
	D["0111"] = 'I'; 
	D["10011000"] = 'J'; 
	D["0110"] = 'K';
	D["00100"] = 'L'; 
	D["10011001"] = 'M'; 
	D["10011110"] = 'N';
	D["00101"] = 'O';
	D["111"] = 'P'; 
	D["10011111"] = 'Q'; 
	D["1000"] = 'R'; 
	D["00110"] = 'S'; 
	D["00111"] = 'T'; 
	D["10011100"] = 'U';  
	D["10011101"] = 'V'; 
	D["000010"] = 'W'; 
	D["10010010"] = 'X'; 
	D["10010011"] = 'Y'; 
	D["10010000"] = 'Z';
	
	
	while(getline(cin,a)){
		b=c="";
		for(int i=0;i<a.size();i++){
			for(int j=0,k=1;k && j<32;j++){
				if(a[i]==d[j]){
					k=0;
					for(int l=16;l>=1;l/=2){
						if(j>=l)b+='1',j-=l;
						else b+='0';
					}
				}
			}
		}
		for(int i=0;i<b.size();i++){
			a="";
			for(int j=i;j<b.size();j++){
				a+=b[j];
				i=j;
				if(D[a]!=0){
					c+=D[a];
					break;
				}
			}
		}
		cout<<c<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 1200
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

int main() {

    int a, p;
    cin >> a >> p;

    int s;
    s = a*3 + p;

    cout << s/2 << endl;

}

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



#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"



using namespace std;
//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; }
template<class T> inline bool chmin(T a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;
typedef long long int ll ;


#define INF 2000000000

int main() {
 
    int n, m;
    cin >> n >> m;
    vector<int> s(m);
    vector<char> c(m);
    rep(i, m){
        cin >> s[i] >> c[i];
    }
 
    bool ok = true;
    rep(i, 1000){
        string tmp = to_string(i);
        if(tmp.size() != n) continue;
        //cout << tmp << endl;
        ok = true;
        rep(j, m){
            if(tmp[s[j]-1] != c[j]){
                ok = false;
            }
        }
        if(ok) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
 
    return 0;
}


Measured memory_bytes: 256
// Scc Puzzle

#include<bits/stdc++.h>

int main() {
    int64_t N = 0;
    int64_t M = 0;

    std::cin >> N >> M;
    std::cout << (std::min(N, M >> 1) + std::max(int64_t(0), (M - (N << 1)) >> 2)) << std::endl;

    return 0;
}


Measured memory_bytes: 256
N, W = list(map(int, input().split()))

val, wt = [], []
for _ in range(N):
    res = list(map(int, input().split()))
    val.append(res[1])
    wt.append(res[0])

dp = [[0 for _ in range(W + 1)] for _ in range(N+1)]
for n in range(N + 1):
    for w in range(W + 1):
        if n == 0 or w == 0:
            dp[n][w] = 0
        elif wt[n-1] > w:
            # If weight is bigger than knapsack capacity - this item can't be included
            dp[n][w] = dp[n - 1][w]
        else:
            # If this item can be included - decide to include it or not
            dp[n][w] = max(val[n-1] + dp[n-1][w - wt[n-1]], dp[n-1][w])  
            # first term - include, second term - not
            
print(dp[N][W])

Measured memory_bytes: 217988
#include<iostream>
#include<vector>
#include<set>
#include<climits>
#include<cfloat>
#include<cmath>
#include<algorithm>
 
 
using namespace std;
 
double EPS = 1e-10;
 
 
double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}
 
struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}
 
  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }
 
  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }
 
  bool operator == ( const point &p ) const {
    return abs(x-p.x) < EPS && abs(y-p.y) < EPS;
  }
};
 
bool cmp_x(const point& p, const point& q){
  if(p.x != q.x)return p.x<q.x;
  return p.y < q.y;
}
 

vector<point>N;

bool Binary_search(point x){
  int l=0,r=N.size(),mid=(l+r)/2;
 
  while(r-l>1){
    if(N[mid]==x)return true;
 
    if(x.x < N[mid].x ||(N[mid].x==x.x && x.y < N[mid].y))r=mid;
    else l=mid;
 
    mid=(l+r)/2;
  }
 
  if(N[mid]==x)return true;
  return false;
}
 
point solve(vector<point> M){
 
  for(int i=0; i< N.size(); i++){
    int j=1;
    for(; j< M.size(); j++){
      point t=N[i]+M[j]-M[0];
      if(!Binary_search(t))break;  
    }
    if(j==M.size())return N[i]-M[0];
  }
  return M[0];
}
 
int main(void){
  int n,m;
  point in;
  vector<point>M;
 
  while(cin >> m,m){
    M.clear();
    N.clear();   
 
    for(int i=0; i< m; i++){
      cin >> in.x >> in.y;
      M.push_back(in);
    }
     
    cin >> n;
 
    for(int i=0; i< n; i++){
      cin >> in.x >> in.y;
      N.push_back(in);
    }
 
    sort(N.begin(),N.end(),cmp_x);
 
    point res=solve(M);
 
    cout << res.x <<" "<< res.y << endl;
 
  }
 
  return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }

  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
  ll N; cin >> N;
  ll ans = 0;
  vector<ll> d = divisor(N);
  for(int i = 0; i < d.size(); ++i) {
    if(d[i] - 1 < 1) continue;
    if(N / (d[i] - 1) == N % (d[i] - 1)) ans += (d[i] - 1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3608
n = int(raw_input())
l = map(int, raw_input().split())
sp = 0
p = 0
sm = 0
m = 0
pflg = True
for i in l:
    sp += i
    if pflg and sp <= 0:
        p += abs(sp) + 1
        sp = 1
    elif not pflg and sp >= 0:
        p += abs(sp) + 1
        sp = -1
    sm += i
    if pflg and sm >= 0:
        m += abs(sm) + 1
        sm = -1
    elif not pflg and sm <= 0:
        m += abs(sm) + 1
        sm = 1
    pflg = not pflg
print min(p,m)


Measured memory_bytes: 11248
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class SearchString
    {
        readonly int MOD = 1000000007;
        readonly int C1 = 401;
        readonly int C2 = 397;

        readonly string[] txt, pat;
        readonly int H, W, R, C;

        public SearchString(string[] txt, int h, int w, string[] pat, int r, int c)
        {
            this.txt = txt; H = h; W = w;
            this.pat = pat; R = r; C = c;
        }

        public void PrintIndex()
        {
            if (H < R || W < C) return;

            long[,] txtTable = GenHash(txt, H, W);
            long[,] patTable = GenHash(pat, R, C);

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i <= H - R; i++)
            {
                for (int j = 0; j <= W - C; j++)
                {
                    if (txtTable[i, j] == patTable[0, 0]) sb.AppendLine(i + " " + j);
                }
            }
            Console.Write(sb);
        }

        private long[,] GenHash(string[] v, int h, int w)
        {
            long[,] h1 = new long[h, w];
            long[,] h2 = new long[h, w];

            long cn1 = 1, cn2 = 1;

            for (int i = 0; i < C; i++) cn1 = (cn1 * C1) % MOD;
            for (int i = 0; i < R; i++) cn2 = (cn2 * C2) % MOD;

            for (int i = 0; i < h; i++)
            {
                long hs = 0;

                for (int j = 0; j < C; j++) hs = (hs * C1 + v[i][j]) % MOD;

                for (int j = 0; j <= w - C; j++)
                {
                    h1[i, j] = hs;

                    if (j + C < w) hs = (hs * C1 - v[i][j] * cn1 + v[i][j + C]) % MOD;

                    hs = (hs < 0) ? hs + MOD : hs;
                }
            }

            for (int i = 0; i < w; i++)
            {
                long hs = 0;

                for (int j = 0; j < R; j++) hs = (hs * C2 + h1[j, i]) % MOD;

                for (int j = 0; j <= h - R; j++)
                {
                    h2[j, i] = hs;

                    if (j + R < h) hs = (hs * C2 - h1[j, i] * cn2 + h1[j + R, i]) % MOD;

                    hs = (hs < 0) ? hs + MOD : hs;
                }
            }
            return h2;
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int H = input[0];
            int W = input[1];

            string[] text = new string[H];
            for (int i = 0; i < H; i++) text[i] = Console.ReadLine();

            input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int R = input[0];
            int C = input[1];

            string[] pattarn = new string[R];
            for (int i = 0; i < R; i++) pattarn[i] = Console.ReadLine();

            SearchString SS = new SearchString(text, H, W, pattarn, R, C);

            SS.PrintIndex();
        }
    }
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int a, b, c, x, ans;
int main() {
    cin >> a >> b >> c >> x;
    for (int i = 0; i <= a; ++i) {
        for (int j = 0; j <= b; ++j) {
            for (int k = 0; k <= c; ++k) {
                int sum = 500 * i + 100 * j + 50 * k;
                if (sum == x)
                    ++ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
#define int long long
 
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, x, y;
  cin >> n >> x >> y;
  int from = min(x, y);
  int to = max(x, y);
  vector<int> ans(n);
  for(int a = 1; a <= n; a++) {
    for(int b = a+1; b <= n; b++) {
      int dist = b-a;
      int pos = abs(a-x) + abs(b-y) + 1;
      ans[min(dist, pos)]++;
    }
  }
  for(int k = 1; k < n; k++) {
    cout << ans[k] << '\n';
  }
  return 0;
}


Measured memory_bytes: 3644
mod=10**9+7
n,k=map(int,input().split())
ans=(n+1)*(n+k+1)*(n-k+2)//2-(n+1)*(n+2)*(2*n+3)//6+k*(k-1)*(2*k-1)//6+(n-k+2)
ans%=mod
print(ans)

Measured memory_bytes: 61740
from collections import Counter

N,K=map(int,input().split())
P = [input() for _ in range(N)]

c = Counter([P[i][0] for i in range(N)])

ans = 0
while True:
  mc = c.most_common()
  if len(mc)<K:break
  if mc[K-1][1] == 0: break
  mc = mc[:K]
  for k,v in mc:
    c[k] -= 1
  ans += 1
  
print(ans)

Measured memory_bytes: 10140
# who says a pun?

# 今日の精進問題第三問目ｎ

n = int(input())
s = list(input())
# dp[L][K]=一番目は左からL番目、二番目は左からK番目からスタートするとした時の共通文字列の中で長さが最大のもの
dp = [[0 for i in range(n + 2)] for j in range(n + 2)]
# もしi>=jであるならば答えは当然ゼロ
# 0<i<jである時だけで考える
for j in range(n, 1, -1):
    # j=n,n-1,,,,,,,,2の値をとる
    for i in range(1, j):

        if s[i - 1] == s[j - 1]:
            dp[i][j] = dp[i + 1][j + 1] + 1
        else:
            dp[i][j] = 0
ans = 0
for j in range(2, n + 1):
    for i in range(1, j):
        ans = max(ans, min(dp[i][j],j-i))
print(ans)


Measured memory_bytes: 247176
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main() {
	double pi = atan(1) * 4;
 int A;
 cin >> A;
 int B;
 cin >> B;
 int H;
 cin >> H;
 int M;
 cin >> M;

 double e = abs(30*H-5.5*M);

 e = e*pi/180;


 double f = sqrt(A*A + B*B - 2*A*B*cos(e));

 printf("%.20lf", f);

  return 0;
}

Measured memory_bytes: 4188
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
    cin >> n;
    long long cnt = 0;
    vector<long long> march(5, 0);
    for(int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        if(s.at(0) == 'M') march.at(0)++;
        else if(s.at(0) == 'A') march.at(1)++;
        else if(s.at(0) == 'R') march.at(2)++;
        else if(s.at(0) == 'C') march.at(3)++;
        else if(s.at(0) == 'H') march.at(4)++;
    }

    for(int bit = 0; bit < (1<<5); ++bit) {
        int truth = 0;
        for(int i = 0; i < 5; ++i) {
            if(bit&(1<<i)) truth++;
        }
        if(truth == 3) {
            long long subcnt = 1;
            for(int i = 0; i < 5; ++i) {
                if(bit&(1<<i)) {
                    subcnt *= march.at(i);
                }
            }
            cnt += subcnt;
        }
    }

    cout << cnt << endl;
}

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

int N, A[1 << 18], B[1 << 18], dist[1 << 18];
vector<int> G[1 << 18];

void dfs(int pos, int dep) {
	if (dist[pos] != (1 << 30)) return;
	dist[pos] = dep;
	for (int i = 0; i < G[pos].size(); i++) dfs(G[pos][i], dep + 1);
}

int diameter() {
	for (int i = 1; i <= N; i++) dist[i] = (1 << 30);
	dfs(1, 0);
	int maxn = -1, maxid = -1;
	for (int i = 1; i <= N; i++) { if (maxn < dist[i]) { maxn = dist[i]; maxid = i; } }

	for (int i = 1; i <= N; i++) dist[i] = (1 << 30);
	dfs(maxid, 0);
	int ret = 0;
	for (int i = 1; i <= N; i++) ret = max(ret, dist[i]);
	return ret;
}

int main() {
	cin >> N;
	for (int i = 1; i <= N - 1; i++) {
		cin >> A[i] >> B[i];
		G[A[i]].push_back(B[i]);
		G[B[i]].push_back(A[i]);
	}
	int dst = diameter();
	if (dst % 3 == 1) cout << "Second" << endl;
	else cout << "First" << endl;
	return 0;
}

Measured memory_bytes: 24832
use std::io::*;
use std::str::FromStr;

fn main() {
    let h: usize = read();
    let w: usize = read();
    let s: Vec<Vec<char>> = (0..h).map(|_| read::<String>().chars().collect()).collect();
    let mo = 10_i64.pow(9) + 7;

    let mut dp: Vec<Vec<i64>> = vec![vec![0; w+1]; h+1];
    dp[0][0] = 1;
    for i in 0..h {
        for j in 0..w {
            if i + 1 < h && s[i+1][j] == '.' {
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= mo;
            }
            if j + 1 < w && s[i][j+1] == '.' {
                dp[i][j+1] += dp[i][j];
                dp[i][j+1] %= mo;
            }
        }
    }
    println!("{}", (dp[h-2][w-1] + dp[h-1][w-2]) % mo);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 16636
#include<iostream>
#include<algorithm>
using namespace std;
struct State{char x[35][35];};
int H,W,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};State S;char f[5]="NESW";
int solve(State V,int depth){
	if(depth==31)return 99999999;
	bool OK=true;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(V.x[i][j]>='A' && V.x[i][j]<='W')OK=false;
		}
	}
	if(OK==true)return depth;
	vector<int>G[30][30];
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(V.x[i][j]<'A' || V.x[i][j]>'W')continue;
			
			int dr=0;for(int k=0;k<4;k++){if(V.x[i][j]==f[k])dr=k;}
			for(int k=dr+5;k>=dr-2;k--){
				int ex=i+dx[k%4],ey=j+dy[k%4];
				if(V.x[ex][ey]=='X' || V.x[ex][ey]=='.'){
					V.x[i][j]=f[k%4];
					G[ex][ey].push_back((11-k)%4);break;
				}
			}
		}
	}
	State I=V;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(G[i][j].size()>=1){
				sort(G[i][j].begin(),G[i][j].end());
				int J=(11-G[i][j][0])%4;
				int fx=i-dx[J],fy=j-dy[J];
				if(I.x[i][j]!='X'){I.x[i][j]=I.x[fx][fy];}
				I.x[fx][fy]='.';
			}
		}
	}
	return solve(I,depth+1);
}
int main(){
	while(true){
		cin>>W>>H;if(W==0 && H==0)break;
		for(int i=0;i<H;i++){for(int j=0;j<W;j++)cin>>S.x[i][j];}
		int ans=solve(S,0);
		if(ans>180)cout<<"NA"<<endl;else cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3692
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static final Scanner sc  = new Scanner(System.in);
    static final int     MOD = (int) 1E9 + 7;

    public static void main(String[] args) {
        int N = nint();
        long[] h = nlongs(N, 1, 0);
        long[] cost = new long[N+1];
        cost[1] = 0;
        cost[2] = cost[1] + cost(h, 2, 1);
        
        for (int n = 3; n <= N; n++) {
            cost[n] = min(cost[n-1] + cost(h, n, n-1),
                          cost[n-2] + cost(h, n, n-2));
        }
        
        System.out.println(cost[N]);
    }
    
    static long cost(long[] h, int from, int to) {
        return abs(h[to] - h[from]);
    }

    private static int nint() {
        return sc.nextInt();
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0, 0);
    }

    private static long[] nlongs(int n, int padL, int padR) {
        long[] a = new long[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nlong();
        return a;
    }

    private static double ndouble() {
        return sc.nextDouble();
    }

    private static double[] ndoubles(int n) {
        return ndoubles(n, 0, 0);
    }

    private static double[] ndoubles(int n, int padL, int padR) {
        double[] d = new double[n + padL + padR];
        for (int i = 0; i < n; i++) {
            d[padL + i] = ndouble();
        }
        return d;
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nchars() {
        return sc.next().toCharArray();
    }

    private static char[] nchars(int padL, int padR) {
        char[] temp = sc.next().toCharArray();
        char[] ret = new char[temp.length + padL + padR];
        System.arraycopy(temp, 0, ret, padL, temp.length);
        return ret;
    }

    private static char[][] nchars2(int h, int w) {
        return nchars2(h, w, 0, 0);
    }

    private static char[][] nchars2(int h, int w, int padLU, int padRD) {
        char[][] a2 = new char[h + padLU + padRD][w + padLU + padRD];
        for (int i = 0; i < h; i++)
            System.arraycopy(nchars(), 0, a2[padLU + i], padLU, w);
        return a2;
    }

    private static long min(long... ls) {
        return Arrays.stream(ls).min().getAsLong();
    }

    private static long max(long... ls) {
        return Arrays.stream(ls).max().getAsLong();
    }

    private static long abs(long a) {
        return Math.abs(a);
    }
}


Measured memory_bytes: 64080
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
int a[105];
int main()
{
	int n,m,ans = 0,sum = 0;
	scanf("%d%d",&n,&m);
	if(m <= n && m <= 50 && m >= 1 && n <= 50 && n >= 1){
		for(int i = 1; i <= n; i++)
			scanf("%d",&a[i]);
		sort(a+1,a+n+1);
		for(int i = n; i >= 1; i--){
			ans += a[i];
			sum++;
			if(sum == m) break;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String,
    }
    let mut s = s.chars().collect::<Vec<_>>();
    s.sort();
    if s[0] == s[1] && s[2] == s[3] && s[0] != s[2] {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
N = int(input())
E = [[] for _ in range(N)]

#辺の定義
#辺E(u,v)の重みがw
l = []
for i in range(N-1):
  u,v = map(int,input().split())
  u -= 1
  v -= 1
  E[u].append(v)
  E[v].append(u)
  l.append((u,v))

#各頂点が白(0)か黒(1)か
color = [-1 for _ in range(N)]
ans= {}
#dfsで色を塗っていく
#頂点の数をN、辺の数をMとすると、O(N+M)で解ける
stack = [0]
color[0] = 0
while stack:
  u = stack.pop()
  i = 1
  for v in E[u]:
    if color[v] == -1:
      stack.append(v)
      color[v] = i
      if color[v] == color[u]:
      	color[v] += 1
      	i += 1
      tmp = [u,v]
      tmp.sort()
      ans[tuple(tmp)] = color[v]
      i += 1
#各頂点の色を出力
print(max(color))
for a,b in l:
  print(ans[(a,b)])


Measured memory_bytes: 44108
/*input
a
z
*/

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main()
{
  string s, t;
  cin >> s >> t;
  int n = s.length();
  int m = t.length();

  int dp[n + 1][m + 1];
  int last[n + 1][m + 1];
  memset(dp, 0, sizeof(dp));
  memset(last, 0, sizeof(last));
  // dp[0][0] = 1;

  for(int i = 1; i <= n; i ++) {
  	for(int j = 1; j <= m; j ++) {
  		if(s[i - 1] == t[j - 1]) {
  			dp[i][j] = 1 + dp[i - 1][j - 1];
  		} else {
  			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
  		}
  	}
  }

  string ans = "";
  int i = n, j = m;
  while(i > 0 and j > 0) {
  	if(s[i - 1] == t[j - 1]) {
  		ans += s[i - 1];
  		i --, j --;
  	} else if(dp[i - 1][j] > dp[i][j - 1]){
  		i --;
  	} else {
  		j --;
  	}
  }
  reverse(ans.begin(), ans.end());
  cout << ans;
  return 0;
}

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

using namespace std;

bool isSame(int a[], int c[], int n) {
    for(int i = 0; i < n; i++){
        if(a[i] != c[i])
        return false;
    }
    return true;
}

int main() {
    int n;
    cin>>n;
    int a[n+1], b[n+1], c[n+1];
    for(int i = 0; i < n; i++)
        cin>>a[i];
    for(int i = 0; i < n; i++)
        cin>>b[i];
    for(int i = 1; i <= n; i++)
    {
        c[i-1] = i;
    }
    int a1 = -1, a2 = -1, i = 1;
    do {
        if(isSame(a, c, n)){
            a1 = i;
        }
        if(isSame(b, c, n)) {
            a2 = i;
        }
        i++;
    }while(next_permutation(c, c + n));
    cout<<abs(a1-a2);
  return 0;
}

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


#define fun(a,b,c) a*a + b*b + c*c + a*b + b*c + c*a

int main()
{
	//freopen("in.txt","r",stdin);

	int n;
	cin>>n;
	


	for(int m=1;m<=n;m++)
	{
        int i=1,j=1,k=1;

        bool chk=false;
        int cnt=0;

		for( i=1;i<=m;i++)
		{
			if(fun(i,j,k)>m) break;
			if(chk==true) break;

			for( j=1;j<=m;j++)
			{
				if(fun(i,j,k)>m) break; 
				if(chk==true) break;

				for( k=1;k<=m;k++)
				{
					if(fun(i,j,k)>m)
						break;
					 else if(fun(i,j,k)==m)
					 {
						cnt++;
					 }
					 
				}
				k=1;

			}
			j=1;
		}
		cout<<cnt<<endl;

	}



	//cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3592
# coding: utf-8
#-------------------------------------------------------------------
#-------------------------------------------------------------------
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")
#-------------------------------------------------------------------
import math
def prm(n, r):
	#return math.factorial(n)//math.factorial(n-r)
	if n-r<0:
		return 0
	else:
		return math.factorial(n)//math.factorial(n-r)

def cmb(n, r):
	return prm(n, r)//math.factorial(r)
#-------------------------------------------------------------------
def v(k):
	#p("B-1, k-1, cmb", B-1, k-1, cmb(B-1, k-1))
	p("R, k, cmb(R, k)",R, k, cmb(R, k))
#-------------------------------------------------------------------
MOD = 10**9+7
#-------------------------------------------------------------------


N, K = map(int, input().split())			# "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7

B=K
R=N-K


def calc(i):
	r = cmb(R+1, i)
	b = cmb(B-1, i-1)
	return (r * b) % MOD

for i in range(1,K+1):
	print( calc(i) )




Measured memory_bytes: 3444
N = int(input())
A = list(map(int, input().split()))

bit_index = [-1] * 20
cnt = 0
pos = -1
for i in range(N):
    a = A[i]
    for j in range(20):
        if (a >> j) & 1:
            pos = max(pos, bit_index[j])
            bit_index[j] = i
    cnt += i - pos
print(cnt)


Measured memory_bytes: 77772
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int k, x;
  cin >> k >> x;

  if (500 * k >= x) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3608
#include<iostream>
using namespace std;
int n,m;long k;
int x[1<<17],d[1<<17];
int t[1<<17],s[1<<17],b[1<<17];
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x[i];
		if(i)d[i-1]=x[i]-x[i-1];
	}
	for(int i=0;i<n-1;i++)s[i]=t[i]=i;
	cin>>m>>k;
	for(int i=0;i<m;i++)
	{
		int a;cin>>a;
		t[a-2]^=t[a-1]^=t[a-2]^=t[a-1];
	}
	while(k)
	{
		if(k&1)
		{
			for(int i=0;i<n-1;i++)s[i]=t[s[i]];
		}
		for(int i=0;i<n-1;i++)b[i]=t[t[i]];
		for(int i=0;i<n-1;i++)t[i]=b[i];
		k>>=1;
	}
	long now=x[0];
	cout<<now<<endl;
	for(int i=0;i<n-1;i++)
	{
		now+=d[s[i]];
		cout<<now<<endl;
	}
}

Measured memory_bytes: 3200
N = int(input())
A, B = [], []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a + b)
    B.append(b)

A.sort(reverse=True)
print(sum([ab for i, ab in enumerate(A) if i % 2 == 0]) - sum(B))


Measured memory_bytes: 11652
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int n;
  cin>>n;
  vin a(n);
  rep(i,0,n){
   cin>>a[i]; 
  }
  sort(all(a));
  reverse(all(a));
  int k=a[0];
  int ans=inf;
  int s=-1;
  rep(i,1,n){
    if(abs(a[i]-k/2)<ans){
       s=a[i];
      ans=abs(a[i]-(k+1)/2);
    }
  }
  cout<<k<<" " <<  s <<endl;
}









Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <list>
#include <chrono>
#include <thread>
#include <thread>
#include <fstream>

using namespace std;

//const bool debug = false;

#ifndef M_PI
    const double M_PI = acos(-1.0);
#endif // M_PI

#define y1 roman_kaban
#define rank oryshych_konb
#define ull unsigned long long
//#define ll long long
const int mod = int(1e9) + 7;
//const int inf = 1e7;
//const long long infLL = 1e16;
//const int MX2 = 10100500; //  e7
//const long long INF = 1e18 + 0.5;
const int MX = 200500; //       e5
//const int SZ = 122;

long long a[MX];

int main()
{
    //epic(); return 0;
    ios_base::sync_with_stdio(false);
    //freopen("/Users/ozzy/Documents/in.txt","r", stdin);
    int n;
    cin >> n;
    long long s = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        s += a[i];
    }

    long long s2 = 0;
    long long ans = 1e18;
    for(int i = 0; i < n - 1; i ++){
        s2 += a[i];
        s -= a[i];
        long long z = s - s2;
        if(z < 0) z *= -1;
        if(z < ans) ans = z;
    }
    cout << ans <<endl;

    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a; cin >> a;
    cout << 24 + (24 - a) << endl;
}


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

int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n;cin>>n;ll arr[n],a,b;
    for(ll i=0;i<n;i++){
        cin>>a>>b;
        arr[i]=a-b;
    }
    for(ll i=0;i<=n-3;i++){
        if(arr[i]==0&&arr[i+1]==0&&arr[i+2]==0)
        {
            cout<<"Yes";return 0;
        }
    }
    cout<<"No";
}


Measured memory_bytes: 3640
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
#define int long long


signed main(void){
  int n,n1,n2;
  n1=0;n2=0;
  int a;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a;
    if(a%2)n1++;
    else n2++;
  }
  n2 += n1/2;
  n1 %= 2;
  if(n2>=1)n2=1;

  if(n1 && n2)cout << "NO\r\n";
  else cout << "YES\r\n";

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <vector>

typedef long long ll;

using namespace std;


int n,a[6001];
ll memo[4000+1][4000+1];

ll dfs(int l,int r){
  ll x=0,y=0;

  if(r-l+2>=n) return 0LL;

  if(memo[l+n][r+n]) return memo[l+n][r+n];

  if(a[l+n-1]>a[n+r+1])
    x=max(dfs(l-2,r)+(ll)a[n+l-2],dfs(l-1,r+1)+(ll)a[n+r+1]);
  else
    y=max(dfs(l-1,r+1)+(ll)a[n+l-1],dfs(l,r+2)+(ll)a[n+r+2]);

  return memo[l+n][r+n]=max(x,y);
}

int main(){
  ll ans=0;

  scanf("%d",&n);

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

  for(int i=0;i<n;i++){
      ans=max(ans,dfs(i,i)+(ll)a[i]);
  }

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

  return 0;
}

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

int main() {

	int n, k, r, s, p; cin >> n >> k >> r >> s >> p;
	string t; cin >> t;	
	vector<char> result(n, 'e');	
	int ans = 0;	
	for (int i = 0; i < t.size(); i++) {		
		if (i <= k - 1) { // k回目まで
			if (t[i] == 'r') {
				ans += p;
				result[i] = 'p';
			}
			if (t[i] == 's') {
				ans += r;
				result[i] = 'r';
			}
			if (t[i] == 'p') {
				ans += s;
				result[i] = 's';
			}
		}
		else  {  // k < i
			if (t[i] == t[i - k]) {
				if (t[i] == 'r') {
					if (result[i - k] == 'p') {}
					else {
						ans += p;
						result[i] = 'p';
					}
				}
				else if (t[i] == 's') {
					if (result[i - k] == 'r') {}
					else {
						ans += r;
						result[i] = 'r';
					}
				}
				else if (t[i] == 'p') {
					if (result[i - k] == 's') {}
					else {
						ans += s;
						result[i] = 's';
					}
				}
			}
			else { // k回前と違えばなんでも出せる
				if (t[i] == 'r') {
					ans += p;
					result[i] = 'p';
				}
				if (t[i] == 's') {
					ans += r;
					result[i] = 'r';
				}
				if (t[i] == 'p') {
					ans += s;
					result[i] = 's';
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();

		int d = Math.max(a, Math.max(b, c));
		if (d == a) {
			for(int i = 0;i < k; i++) {
				d *= 2;
			}
			System.out.println(d + b + c);
		}else if (d == b) {
			for(int i = 0;i < k; i++) {
				d *= 2;
			}
			System.out.println(d + a + c);
		}else {
			for(int i = 0;i < k; i++) {
				d *= 2;
			}
			System.out.println(d + a + b);
		}
	}
}


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

int top1=0, top2=0, top3=0;
int S1[20000], S2[20000], S3[20000];

void push1(int x){top1++;S1[top1] = x;}
int pop1(){top1--;return S1[top1+1];}

void push2(int x){top2++;S2[top2] = x;}
int pop2(){top2--;return S2[top2+1];}

void push3(int x){top3++;S3[top3] = x;}
int pop3(){top3--;return S3[top3+1];}


int main(void)
{
	char s[20000];
	int i=0, j=0, sum=0;
	int k=0;
	scanf("%s", s);
	
	while(s[i] == '\\' || s[i] == '_' || s[i] == '/'){
		if(s[i] == '\\' ) push1(i);
		else if(s[i] == '/' && top1 != 0){
			j = pop1();
			k = i - j;
			sum += k;
			while(top2 != 0 && j < S2[top2]){
				pop2();
				k += pop3();
			}
			push2(j);
			push3(k);
		}
		i++;
	}
	
	printf("%d\n", sum);
	printf("%d", top3);
	
	for(i = 1; top3 != 0; i++){
		pop3();
		printf(" %d", S3[i]);
	}
	printf("\n");
	return 0;
}



Measured memory_bytes: 2104
H, W = map(int, input().split())
s = [""] * H
for h in range(H):
  s[h] = input()

INF = float('inf')
dp = [[[INF, s[h][w]] for w in range(W)] for h in range(H)]

def update_dp_1(c, dp):
  if dp[1] == ".":
    if c == ".":
      res = [dp[0], "."]
    else:  # c == "#"
      res = [dp[0]+1, "#"]
  else:  # dp[1] == "#"
    if c == ".":
      res = [dp[0], "."]
    else:  # c == "#"
      res = [dp[0], "#"]
  return res

def update_dp_2(c, dp_a, dp_b):
  a = update_dp_1(c, dp_a)
  b = update_dp_1(c, dp_b)
  if a[0] < b[0]:
    return a
  else:
    return b

if s[0][0] == ".":
  dp[0][0] = [0, "."]
else:  #  == "#"
  dp[0][0] = [1, "#"]

for h in range(H):
  if h != 0:
    dp[h][0] = update_dp_1(dp[h][0][1], dp[h-1][0])
  for w in range(1, W):
    if h == 0:
      dp[h][w] = update_dp_1(dp[h][w][1], dp[h][w-1])
    else:
      dp[h][w] = update_dp_2(dp[h][w][1], dp[h-1][w], dp[h][w-1])

print(dp[H-1][W-1][0])


Measured memory_bytes: 4084
#include<iostream>
#include<cstdio>
using namespace std;
double S,L,r;
int main(){
	cin>>r;
	S=r*r*3.14159265358979323846264338;
	L=2.0*r*3.14159265358979323846264338;
	printf("%f %f",S,L);
	return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define ll  long long
#define ull unsigned long long  
using namespace std;
#define  inf 1e9+18
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define  f1(i,n) for(i=1;i<=n;i++)
#define f0(i,n)  for(i=0;i<n;i++)
#define w(x)   while(x--)
const int maxn=105;
#define  pq priority_queue
#define  ff first
#define  ss second 
#define pb  push_back
#define lb lower_bound
#define ub upper_bound
#define pie 3.14159265359
#define mod 1000000007
ll dp[3005][3005];

ll stones(ll a[],ll sta ,ll end,ll id)
{
   if(sta>=end)
   return 0;	
if(dp[sta][end]!=-1)
	return dp[sta][end];
ll ans=0;
if(id)
 ans=max(a[sta]+stones(a,sta+1,end,0),a[end-1]+stones(a,sta,end-1,0));
else
 ans=min(stones(a,sta+1,end,1),stones(a,sta,end-1,1));
dp[sta][end]=ans;
return ans;
  
}
int main()
{    fastio;
	ll int n,sum=0;
	cin>>n;
	ll int a[n];
	for(int i=0;i<n;i++)
   {
   	cin>>a[i];
   	sum+=a[i];
   }
  memset(dp,-1,sizeof(dp));
ll k=stones(a,0,n,1);
	cout<<2*k-sum;
}

Measured memory_bytes: 70912
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef         long double      dl;
typedef		vector<ll>      vll;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define		ss              ' '
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
typedef     pair <int, int>   pii;
typedef     pair <ll, ll>      pll;
int main()
{
 //O_O ;
   ll t,h,w,n,temp,temp2;
   cin>>h>>w>>n;
   if(h<w)
    swap(h,w);
   // cout<<h<<nn<<w;
   temp=n/h;
   temp2=n%h;
   if(temp2)
    cout<<temp+1<<nn;
   else
    cout<<temp<<nn;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
#define L 2003
#define N 4000006
#define LL long long
#define mod 1000000007
#define rep(i,j,k) for(i=j;i<=k;++i)
#define down(i,j,k) for(i=j;i>=k;--i)
int n,m,i,j,k,s1,s2;
int fac[N],inv[N],dp[L][L];
int quick_mi(int a,int b){
	int sum=1;
	for(;b;b>>=1,a=(a*1LL*a)%mod)
	if(b&1) sum=(sum*1LL*a)%mod;
	return sum;
}
int C(int n,int m){
	if(m>n) return 0;
	return (((fac[n]*1LL*inv[m])%mod)*1LL*inv[n-m])%mod;
}
int main(){
// 	freopen("in.txt","r",stdin);
	scanf("%d%d",&n,&m);
	if(m==1) {printf("1\n"); return 0;}
	fac[0]=1; k=n*m;
	rep(i,1,k) fac[i]=(fac[i-1]*1LL*i)%mod;
	inv[k]=quick_mi(fac[k],mod-2);
	down(i,k-1,0) inv[i]=(inv[i+1]*1LL*(i+1))%mod;
	dp[0][0]=1;
	rep(i,0,n)
	 rep(j,i,n)
	 if(i||j){
	 	if(i) dp[i][j]=dp[i-1][j];
		dp[i][j]+=(dp[i][j-1]*1LL*C(m-2+i+((j-1)*(m-1)),m-2))%mod;
	 	dp[i][j]%=mod;
	 }
	int ans=(dp[n][n]*1LL*fac[n])%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 47104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int x; cin>>x;
    if(x<1200)cout<<"ABC"<<endl;
    else cout<<"ARC"<<endl;
}


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

int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
int findGCD(int arr[], int n)
{
    int result = arr[0];
    for (int i = 1; i < n; i++)
    {
        result = gcd(arr[i], result);

        if(result == 1)
        {
           return 1;
        }
    }
    return result;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,sum=0;
    cin>>n;
    int a[3];
    for(int i=1;i<=n;i++)
    {
        a[0]=i;
        for(int j=1;j<=n;j++)
        {
            a[1]=j;
            for(int k=1;k<=n;k++)
            {
                a[2]=k;
               sum+=findGCD(a,3);
            }
        }
    }
  cout<<sum;
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll par[200010];
ll len[200010];
void init(ll n){
    for(int i=0;i<n;i++){
        par[i]=i;
        len[i]=0;
    }
}
ll root(ll n){
    if(par[n]==n)return n;
    return par[n]=root(par[n]);
}
void unit(ll a,ll b){
    a=root(a);
    b=root(b);
    if(a==b)return;
    if(len[a]<len[b]){
        par[a]=b;
    }
    else{
        par[b]=a;
        if(len[a]==len[b])len[a]++;
    }
}
int main(){
    int n,m;cin>>n>>m;
    init(n+1);
    rep(i,0,m){
        int x,y,z;cin>>x>>y>>z;
        unit(x,y);
    }
    set<int> st;
    rep(i,1,n+1){
        int u=root(i);
        st.insert(u);
    }
    int ans=st.size();
    cout<<ans<<endl;
}


Measured memory_bytes: 6528