akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main(){
  int n,m;
  while(cin >> n,n){
    map<string,string>mm;
    map<string,int>mm2;
    string ans;
    for(int i=0; i<n; i++){
      string in,in2;
    cin >> in >> in2;
    mm[in] = in2;
    mm2[in] = 1;
    }
    
    cin >> m;
    for(int i=0; i<m; i++){
      string in;
      cin >> in;
      if(mm2[in]) ans += mm[in];
      else ans += in;
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
 int N,R;
  cin >> N >> R;
  int naibu;
  if (N<10){
    naibu = R + 100*(10-N);
  }
  else {
    naibu = R;
  }
      cout <<  naibu;
}

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

#define ll long long int
#define pb                 push_back
#define T int time;        scanf("%d", &time); while(time--)
#define all(x)             x.begin(), x.end()
#define fill(a, b)         memset(a, b, sizeof(a))
#define mp                 make_pair
#define fst                first
#define snd                second
#define filein             freopen("input.txt", "r", stdin);
#define fileout            freopen("output.txt", "w", stdout);
int main(){
     int a,b;
	 ll t;ll x,c=0,cc=0;
	 cin>>t;
	 for(ll i=0; i<t; i++){
	 	
	 	cin>>x;
	 	if(x%2==0)c++;
	 	if((x%3==0 || x%5==0) and x%2==0)cc++;
	 }
	 if(c==cc)cout<<"APPROVED"<<endl;
	 else cout<<"DENIED"<<endl;



}



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

int main(){
  int X,N;
  cin >> X >> N;
  vector<int> P(N);
  for(int i=0;i<N;i++){
    cin >> P.at(i);
  }
  int i=0;
  while(true){
    int A=X-i,B=X+i;
    bool a=false,b=false;
    for(int j=0;j<N;j++){
      if(P.at(j)==A){
        a=true;
      }
      if(P.at(j)==B){
        b=true;
      }
    }
    if(!a){
      cout << A << endl;
      return 0;
    }
    if(!b){
      cout << B << endl;
      return 0;
    }
    i++;
  }
}
      

Measured memory_bytes: 3632
N, M = map(int, input().split())
edge = [[] for  _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    edge[a].append([1, b])
    edge[b].append([1, a])


used = [False] * N
d = [0] * N
now_list = [(0,0,-1)]
next_list = set()
while len(now_list) > 0:
    for _ in range(len(now_list)):
        c, v, pv = now_list.pop()
        if used[v]: continue
        d[v] = pv
        used[v] = True
        for nc, nv in edge[v]:
            if used[nv]: continue
            if v == nv: continue
            next_list.add((nc+c, nv, v))
    now_list = list(next_list)
    next_list = set()

judge = all(d[i] > -1 for i in range(1,N))
if judge:
    print("Yes")
    for i in d[1:]:
        print(i+1)
else:
    print("No")


Measured memory_bytes: 163632
X, N = map(int, input().split())
p = list(map(int, input().split()))
p.sort()

if N == 0:
    print(X)
    exit()

if X not in p:
    print(X)    
else:
    i = 1
    while p[p.index(X)] + i in p:
        i += 1
    up = p[p.index(X)] + i
    
    i = 1
    while p[p.index(X)] - i in p:
        i += 1
    down = p[p.index(X)] - i

    if abs(down-X) <= abs(up-X):
        print(down)
    else:
        print(up)

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

using namespace std;

typedef long long ll;

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if (abs(a - b) % 2 == 0) {
        cout << abs(a - b) / 2;
    } else {
        cout << min(a, n - b + 1) + (b - a - 1) / 2;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
typedef long long ll;
typedef double dd;
#define pb push_back
#define mp make_pair
#define endl "\n"
#define M 1000000007
#define pi acos(-1)
/*ll power(ll a,ll b)
{
    ll res = 1;
    while(b > 0)
    {
        if(b & 1)
            res = (res*a)%M;
        a = (a*a)%M;
        b = b >> 1;
    }
    return res;
}*/
/*ll modinv(ll a)
{
   return power(a,M - 2); 
}*/
/*vector<ll> primes(ll n)
{
    bool *sieve = new bool[n + 1];
    ll i,j;
    vector<ll> v;
    for(i = 3; i <= n; i+=2)
        sieve[i] = true;
    sieve[2] = true;
    for(i = 3; i*i <= n; i+=2)
    {
        if(sieve[i])
            for(j = i*i; j <= n; j+=i)
                sieve[j] = false;
    }
    if(n >= 2)
    {
        v.pb(2);
        for(i = 3; i <= n; i+=2)
        {
            if(sieve[i])
                v.pb(i);
        }
    }
    return v;
}*/

/*class graph{
public:
    vector<ll> *g;
    ll n;
    graph(ll v)
    {
        n = v + 1;
        g = new vector<ll> [n];
    }
    void addegde(ll f,ll s)
    {
        g[f].pb(s);
        g[s].pb(f);
    }
    void dfs(bool *visited,ll sv)
    {
        visited[sv] = true;
        for(auto x: g[sv])
        {
            if(!visited[x])
            {
                dfs(visited,x);
            }
        }
    }
    void bfs(ll sv){
       queue<ll> q;
       bool visited[n] = {};
       q.push(sv);
       visited[sv] = true;
       while(!q.empty())
       {
           ll node = q.front();
           q.pop();
           for(auto x : g[node])
           {
               if(!visited[x])
               {
                   visited[x] = true;
                   q.push(x);
               }
           }
       }
    }
};*/
int main()
{
    fast;
    ll n,k,i;
    cin >> n >> k;
    ll a[n + 1];
    dd expec[1001] = {},ans = 0,sum[n + 1] = {};
    for(i = 1; i <= 1000; i++)
        expec[i] = (i*(i + 1))/(2.0*i);
    for(i = 1; i <= n; i++)
        cin >> a[i];
    for(i = 1; i <= n; i++)
        sum[i] = sum[i - 1] + expec[a[i]];
    for(i = k; i <= n; i++)
        if(sum[i] - sum[i - k] > ans)
            ans = sum[i] - sum[i - k];
    cout<<setprecision(12)<<fixed<<ans<<endl;
    return 0;
}



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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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

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

    int A, B, C, D; cin >> A >> B >> C >> D;
    cout << max(A*B, C*D) << endl;
}

Measured memory_bytes: 3636
const main = (input) => {
  input = input.trim().split('\n')
  const [N, M, K] = input[0].split(' ').map(BigInt)
  const booksA = input[1].split(' ').map(BigInt)
  const booksB = input[2].split(' ').map(BigInt)

  let currentSum = 0n
  const maxB = []
  for (let i = 0; i < booksB.length; i++) {
    currentSum += booksB[i]
    maxB.push(booksB[i])

    if (currentSum > K) {
      currentSum -= maxB.pop()
      break
    }
  }

  let ans = maxB.length

  let A_sum = 0n
  const Alist = []
  for (let i = 0; i < booksA.length; i++) {
    A_sum += booksA[i]
    Alist.push(booksA[i])

    while (A_sum + currentSum > K && maxB.length) currentSum -= maxB.pop()
    if (A_sum + currentSum > K) break

    ans = Math.max(ans, Alist.length + maxB.length)
  }

  return console.log(ans)
}


process.env.MYTEST ? test() : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

int main()
{
	int64_t n, k, mod = 1000000007;
	cin >> n >> k;
	vector<int64_t> as(n);
	for (auto &&a : as)
	{
		cin >> a;
	}

	auto pow_mod = [](int64_t a, int64_t n, int64_t mod) {
		int64_t r = 1;
		for (; n; n >>= 1)
		{
			if (n & 1)
			{
				(r *= a) %= mod;
			}
			(a *= a) %= mod;
		}
		return r;
	};

	int64_t ans = 0;

	for (int64_t i = 0; i < n; i++)
	{
		int64_t lc = 0, ac = 0;

		for (int64_t j = 0; j < n; j++)
		{
			if (as[i] < as[j])
			{
				if (j < i)
				{
					lc++;
				}
				ac++;
			}
		}

		(ans += (lc * k % mod + ac * k % mod * (k - 1) % mod * pow_mod(2, mod - 2, mod) % mod) % mod) %= mod;
	}

	cout << ans << endl;

	return 0;
}

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

using ll=long long; 

void solve(){
	int n;
	cin>>n;
	double t,a;
	cin>>t>>a;
	vector<double> h(n);
	for(int i=0; i<n; i++)cin>>h[i];
	double minv=1000000;
	int mini=-1;
	for(int i=0; i<n; i++){
		double tmp=t-h[i]*0.006;
		double z=fabs(a-tmp);
		//cout<<z<<endl;
		if(minv>z){
			minv=z;
			mini=i;
		}
	}
	cout<<mini+1<<endl;

}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), p = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int[] m = new int[p]; long ans = 0;
		if(p==2||p==5) {
			for (int i = 0; i < n; i++) {
				if((s[i]-'0')%p==0) ans += i+1;
			}
		}else {
			int u = 0;
			long dig = 1;
			m[0] = 1;
			for (int i = n-1; i >= 0; i--) {
				u += (s[i]-'0')*dig;
				u %= p;
				ans += m[u];
				m[u]++;
				dig *= 10;
				dig %= p;
			}
		}
		System.out.println(ans);
		sc.close();
	}
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)

int main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  ll ans;
  if(a>=b && a>=c)ans=b+c+a*pow(2,k);
   else if(c>=b && c>=a)ans=b+a+c*pow(2,k);
   else if(b>=a && b>=c)ans=c+a+b*pow(2,k);
  cout << ans << endl;
}
  
      
    


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010
#define lb lower_bound 

double dp[3100][3100]={0};

int main()
{
  int N;cin>>N;
  vector<double> p(N);
  for (int i=0;i<N;i++)
    cin>>p[i];
  
  //dp[i][j]=i番目まででj個コインが表になる確率
  dp[0][0]=1;
  for (int i=0;i<N;i++)
  {
    for (int j=0;j<=i;j++)
    {
      dp[i+1][j+1]+=dp[i][j]*p[i];
      dp[i+1][j]+=dp[i][j]*(1-p[i]);
    }
  }
  double ans=0.0;
  for (int j=N/2+1;j<=N;j++)
     ans += dp[N][j];
  
  cout << fixed << setprecision(15) << ans << endl;
}

Measured memory_bytes: 72320
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define ull unsigned long long
#define INF 987654321

int ac, wa, tle, re;

int main() {
    ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0); 
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (s == "AC") ac++;
        if (s == "WA") wa++;
        if (s == "TLE") tle++;
        if (s == "RE") re++;
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  double r; cin >> r;
  cout << 2 * r * acos(-1) << endl;
}

Measured memory_bytes: 3760
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const double EPS = 1E-10;

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




int main(){
    int N; std::cin >> N;
    std::vector<std::pair<long long, int>> A(N);
    for(int i(0); i < N; ++i){
        std::cin >> A[i].first;
        A[i].second = i+1;
    }
    std::sort(A.rbegin(), A.rend());
    //dp[i][j] := i人配置、左側はj人
    std::vector<std::vector<long long>> dp(N+1, std::vector<long long>(N+1, 0));
    for(int i(1); i <= N; ++i){
        for(int j(0); j <= i; ++j){
            if(j) dp[i][j] = dp[i-1][j-1] + A[i-1].first*(A[i-1].second - j);
            if(j != i)chmax(dp[i][j], dp[i-1][j] + A[i-1].first*(N-i+j+1 - A[i-1].second));
        }
    }
    long long ans(0);
    for(int i(0); i <= N; ++i) chmax(ans, dp[N][i]);
    std::cout << *std::max_element(dp[N].begin(), dp[N].end()) << std::endl;
    return 0;
}


Measured memory_bytes: 34672
#include <stdio.h>
int g[101][101];
int H,W,N,x,k,i,j;
int main()
{
    while(scanf("%d%d%d",&H,&W,&N)!=EOF)
    {
        k=-1;
        for(i=1;i<=N;i++)
        {
            scanf("%d",&x);
            while(x--) k++,g[(k/H)&1?(H-1-(k%H)):k%H][k/H]=i;
        }
        for(i=0;i<H;i++)
        {
            for(j=0;j<W;j++)
            {
                if(j) printf(" ");
                printf("%d",g[i][j]);
            }
            printf("\n");
        }
    }
    return 0;
}


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

int main(void) {
  int input, i, A, B, C, dir;
  bool flag = false;
  int a[N];
  for(i = 0; i < N; i++) {
    cin >> input;
    a[i] = input;
  }
  A = a[0];
  B = a[1];
  C = a[2];

  if(A < B) dir = 1;
  else dir = -1;

  for(i = A; i != B; i += dir) {
    if(i == C) {
      flag = true;
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;

  //for(i = 0; i < N; i++)
  //cout << a[i] << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=200000000000000;
double pi=3.141592653589793;

const int MOD = 1000000007;

long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	return gcd(a%b,b);
}

long long lcm(long long a,long long b){
	return a/gcd(a,b)*b;
}
long myPow(long long x, long long n, long long m=MOD){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

ll N,M;
vector<ll>A(106);

void batten(ll i,ll k){
	if(i==N)return;
	if((A[i]%k)>(A[i+1]%k)){
		swap(A[i],A[i+1]);
		batten(i+1,k);
		return;
	}else{
		batten(i+1,k);
		return;
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll N;
	cin>>N;
	vector<pair<ll,bool>>D(N);
	for(int i=0;i<N;i++){
		ll d;
		cin>>d;
		D[i]=make_pair(d,true);
	}
	sort(D.begin(),D.end());
	ll M;
	cin>>M;
	vector<bool>boolT(M,false);
	for(int i=0;i<M;i++){
		ll T;
		cin>>T;
		if(!binary_search(D.begin(),D.end(),make_pair(T,true))){
			cout<<"NO"<<endl;
			return 0;
		}
		ll index=lower_bound(D.begin(),D.end(),make_pair(T,true))-D.begin();
		D[index].second=false;
		//cout<<T<<endl;
	}
	cout<<"YES"<<endl;
}



Measured memory_bytes: 3456
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1001001001
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
    ll n,x,t;cin>>n>>x>>t;
    if(n%x==0) cout << n/x*t <<endl;
    else cout << (n/x+1)*t << endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};
  

int main()
{
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> c(h);
  rep(i, h) cin >> c[i];
  int ans = 0;
  for(int bit1 = 0; bit1 < 1<<h; ++bit1) {
    for(int bit2 = 0; bit2 < 1<<w; ++bit2) {
      int count = 0;
      rep(i, h) rep(j, w) {
        if(bit1 & 1<<i || bit2 & 1<<j) continue;
        if(c[i][j] == '#') ++count;
      }
      if(count == k) ++ans;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
#include <functional>
#include <queue>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}


int main(){
    int R,C,k ;
    cin >> R >> C >> k ;
    vector<vector<int> > maze(R,vector<int>(C,0)) ;
    int r,c,v ;
    for (int i = 0; i < k; i++)
    {
        cin >> r >> c >> v ;
        maze.at(r-1).at(c-1) = v ;
    }
    vector<vector<vector<int64_t> > > table(R,vector<vector<int64_t> >(C,vector<int64_t>(4,0))) ;
    for (int i = 0; i < R; i++)
    {
        for (int j = 0; j < C; j++)
        {
            if (i == 0 & j == 0)
            {
                table.at(i).at(j).at(1) = maze.at(i).at(j) ;
            }else if (i == 0)
            {
                table.at(i).at(j).at(1) = max(table.at(i).at(j-1).at(0) + maze.at(i).at(j),table.at(i).at(j-1).at(1)) ;
                table.at(i).at(j).at(2) = max(table.at(i).at(j-1).at(1) + maze.at(i).at(j),table.at(i).at(j-1).at(2)) ;
                table.at(i).at(j).at(3) = max(table.at(i).at(j-1).at(2) + maze.at(i).at(j),table.at(i).at(j-1).at(3)) ;
            }else if (j == 0)
            {
                table.at(i).at(j).at(0) = max(table.at(i-1).at(j).at(0),max(table.at(i-1).at(j).at(1),max(table.at(i-1).at(j).at(2),table.at(i-1).at(j).at(3)))) ;
                table.at(i).at(j).at(1) = table.at(i).at(j).at(0) + maze.at(i).at(j) ;
            }else
            {
                table.at(i).at(j).at(0) = max(table.at(i-1).at(j).at(0), max(table.at(i-1).at(j).at(0), max(table.at(i-1).at(j).at(1), max(table.at(i-1).at(j).at(2),table.at(i-1).at(j).at(3))))) ;
                table.at(i).at(j).at(1) = max(table.at(i).at(j).at(0) + maze.at(i).at(j), max(table.at(i).at(j-1).at(0) + maze.at(i).at(j),table.at(i).at(j-1).at(1))) ;
                table.at(i).at(j).at(2) = max(table.at(i).at(j-1).at(2),table.at(i).at(j-1).at(1) + maze.at(i).at(j) ) ;
                table.at(i).at(j).at(3) = max(table.at(i).at(j-1).at(3),table.at(i).at(j-1).at(2) + maze.at(i).at(j) ) ;
            }
            
            
            

            
            
            
        }
        
    }
    
    cout << max(table.at(R-1).at(C-1).at(0), max(table.at(R-1).at(C-1).at(1), max(table.at(R-1).at(C-1).at(2),table.at(R-1).at(C-1).at(3)))) << endl ;
}

Measured memory_bytes: 670956
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

typedef struct {
	int64_t A;
	int64_t B;
} _happy;

int compare_f(const void *a, const void *b) {
	const _happy * const aP = (_happy *)a;
	const _happy * const bP = (_happy *)b;

	const int64_t aSum = aP->A + aP->B;
	const int64_t bSum = bP->A + bP->B;

	int ret = 0;

	if (aSum < bSum) {
		ret = 1;
	}
	else {
		ret = -1;
	}

	return ret;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

static _happy happy[100000];
static struct {
	size_t num;
	struct {
		size_t count;
		int64_t sum;
	} div[100000];
}divInfo;

int main(void) {
	size_t N;

	scanf("%zu\n", &N);
	for (size_t idx = 0; idx < N; idx++) {
		scanf("%"PRId64 "%"PRId64, &(happy[idx].A), &(happy[idx].B));
		if (idx < N - 1) {
			scanf("\n");
		}
	}

	qsort(happy, N, sizeof(_happy), compare_f);

	int64_t sum[2] = { 0,0 };

	for (size_t idx = 0; idx < N; idx++) {
		sum[idx % 2] += (idx % 2 == 0) ? happy[idx].A : happy[idx].B;
	}

	printf("%"PRId64"\n", sum[0] - sum[1]);

	return 0;
}


Measured memory_bytes: 3324
# -*- coding:utf-8 -*-

def solve():
    X, Y = list(map(int, input().split()))

    for kame in range(0, X+1):
        turu = X - kame

        if kame*4 + turu*2 == Y:
            print("Yes")
            return
    print("No")


if __name__ == "__main__":
    solve()


Measured memory_bytes: 9160
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <map>
#include <vector>
#include <time.h>
#include <stdarg.h>
#include <algorithm>
#include <iostream>

using namespace std;

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

  vector<vector<pair<int, int>>> data(n + 1, vector<pair<int, int>>());
  for (int i=1; i<=n; i++) {
    int count;
    cin>>count;
    for (int j = 0; j<count; j++) {
      int x, y;
      cin>>x>>y;
      data[i].push_back({x, y});
    }
  }

  int top = (1<<n);
  int ans = 0;
  for (int i=0; i<top; i++) {
    map<int, bool> valid;
    int tot = 0;
    for (int j=1; j<=n; j++)
      if (i & (1<<(j-1))) {
        valid[j] = true;
        tot++;
      }
    if (tot < ans) continue;

    for (int p = 1; p<=n; p++) {
      if (!valid[p]) continue;

      for (auto e : data[p]) {
        if (e.second == 1 && !valid[e.first]) {
          tot = 0;
          break;
        }

        if (e.second == 0 && valid[e.first]) {
          tot = 0;
          break;
        }
      }

      if (tot == 0) break;
    }

    if (tot > ans) ans = tot;
  }

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



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

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

int main()
{
    int N;
    cin >> N;
    vector<int> B(N-1);
    rep(i,N-1) cin >> B[i];
    ll ans = 0;
    bool flag = false;
    int tmp;
    ans += B[0];
    for(int i = 1;i < N-1;i++)
    {
        ans += min(B[i-1],B[i]);
    }
    ans += B[N-2];
    cout << ans << endl;
}


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

using namespace std;
 int main(){
    vector<int> a(3);
    for(int i=0;i<3;i++){
        cin>>a[i];
    }
    
    sort(a.begin(),a.end());
    for(int i=0;i<3;i++){
        cout<<a[i];
        if(i<2){cout<<" ";}
        else{cout<<endl;}
        
    }
    
    
 }
 


Measured memory_bytes: 3136
//ABC129D
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int h, w;
	cin >> h >> w;
	bool wall[h][w];
	pair<int, int> m[h][w];
	for (int y = 0; y < h; y++) {
		string s;
		cin >> s;
		int count = 0;
		int last_x = 0;
		for (int x = 0; x < s.size(); x++) {
			if (s[x] == '#') {
				wall[y][x] = true;
				for (int tmp = last_x; tmp < x; tmp++) {
					m[y][tmp].first = count;
				}
				m[y][x].first = 0;
				count = 0;
				last_x = x+1;
			} else {
				count++;
				wall[y][x] = false;
			}
		}
		for (int tmp = last_x; tmp < w; tmp++) {
			m[y][tmp].first = count;
		}
	}
	for (int x = 0; x < w; x++) {
		int count = 0;
		int last_y = 0;
		for (int y = 0; y < h; y++) {
			if (wall[y][x]) {
				for (int tmp = last_y; tmp < y; tmp++) {
					m[tmp][x].second = count;
				}
				m[y][x].second = 0;
				count = 0;
				last_y = y+1;
			} else {
				count++;
			}
		}
		for (int tmp = last_y; tmp < h; tmp++) {
			m[tmp][x].second = count;
		}
	}

	int ans = 0;
	for (int y = 0; y < h; y++) {
		for (int x = 0; x < w; x++) {
			int tmp = m[y][x].first + m[y][x].second - 1;
			if (ans < tmp) {
				ans = tmp;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

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


/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 10000000000;
/****** define constant end ********/
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll bfs(ll sx, ll sy, ll gx, ll gy, ll h, ll w, vector< vector<string> > s){
    ll d[25][25];
    queue<P> que;
    REP(i, h){
        REP(j, w){
            d[i][j] = INF;
        }
    }
    que.push(P(sx, sy));
    d[sx][sy] = 0;
    while (que.size()){
        P p = que.front(); que.pop();
        if(p.first == gx && p.second == gy) break;
        REP(i, 4){
            ll nx = p.first + dx[i], ny = p.second + dy[i];
            if(0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] != "#" && d[nx][ny] ==INF){
                que.push(P(nx, ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    return d[gx][gy];
}


/****** define variable start ******/
ll h ,w;
/******* define variable end *******/
ll solve(){
    cin >> h >> w;
    vector< vector<string> > s(h, vector<string>(w));
    REP(i, h){
        string tmp;
        cin >> tmp;
        REP(j, w){
            s[i][j] = tmp.substr(j, 1);
        }
    }
    ll ans = 0;
    REP(i, h){
        REP(j, w){
            if(s[i][j] == "."){
                for(ll k = i; k < h; k++){
                    REP(l, w){
                        if(s[i][j] == "." && s[k][l] == "."){
                            ll tmp = bfs(i, j, k, l, h, w, s);
                            if(tmp > ans){
                                ans = tmp;
                            }
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
    
    return 0;
}
int main(){
    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */
    return (int)end_solve;
}


Measured memory_bytes: 256
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  P = list(map(int, input().split()))
  for i in range(n+1):
    if x-i not in P:
      print(x-i)
      break
    elif x+i not in P:
      print(x+i)
      break
    else:
      pass


Measured memory_bytes: 9164
#include<iostream>
#include<cmath>

using namespace std;

int main() {
  int n;
  cin >> n;
  int ans = 10000000;
  for (int i = 1; i <= n / 2; i++) {
    int a = i;
    int b = n - i;
    int tmp = 0;
    while (a) {
      tmp += a % 10;
      a = a / 10;
    }
    while (b) {
      tmp += b % 10;
      b = b / 10;
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
inline int Rand(){return rand()*32768+rand();}
string s;
int suf[1000005],pref[1000005],h[1000005];
int solve(int x){
	string ss=s;
	int add=0,sum=0;
	for(int i=0;i<s.size();i++){
		if(s[i]!='?'){
			sum+=(s[i]=='1'?1:-1);
			continue;
		}
		if(add+suf[i]<=x-2){
			add+=2;s[i]='1';
		}else s[i]='0';
		sum-=1;
	}
	pref[0]=s[0]=='1'?1:-1;
	for(int i=1;i<s.size();i++)pref[i]=pref[i-1]+(s[i]=='1'?1:-1);
	int mx=max(0,*max_element(pref,pref+s.size())),mn=min(0,*min_element(pref,pref+s.size()));
	s=ss;
//	cerr<<x<<" "<<mx<<" "<<mn<<endl;
	return mx-mn;
}
int main(){
	cin>>s;
	int f=0,g=0; 
	for(int i=0;i<s.size();i++)f+=(s[i]=='1'?1:-1),h[i]=f,g=max(g,f);
	int cur=0;suf[s.size()]=-inf;
	for(int i=s.size()-1;i>=0;i--){
		suf[i]=max(suf[i+1],h[i]);
	}
	cout<<min(solve(g),solve(g+1))<<endl;
	return 0;
}

Measured memory_bytes: 17176
import itertools
n=int(input())
a=list(map(int,input().split()))
li=list(itertools.accumulate(a))
ans=float("inf")
#print(li)

for i in range(n-1):
    l=li[i]
    r=li[-1]-li[i]
    #print(l,r)
    ans=min(ans,abs(l-r))

print(ans)


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

#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int main(){
  string s;
  cin>>s;
  int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';
  for(int i=-1;i<2;i++){
    for(int j=-1;j<2;j++){
      for(int k=-1;k<2;k++){
        if(i==0 || j==0 || k==0){
          continue;
        }
        int ans=a+(i*b)+(j*c)+(k*d);
        if(ans==7){
          i++,j++,k++;
          cout<<a<<(i?'+':'-')<<b<<(j?'+':'-')<<c<<(k?'+':'-')<<d<<"=7"<<endl;
          return 0;
        }
      }
    }
  }
}


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

using namespace std;

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

	int n;
	cin >> n;

	vector<int> v(n);
	vector<int> dp(n, INT_MAX);

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

	dp[0] = 0;
	for (int i = 0; i < n - 1; i++)
	{
		if (i + 1 < n)
		{
			dp[i + 1] = min(dp[i + 1], dp[i] + abs(v[i + 1] - v[i]));
		}
		if (i + 2 < n)
		{
			dp[i + 2] = min(dp[i + 2], dp[i] + abs(v[i + 2] - v[i]));
		}
	}

	cout << dp[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
  int tho, han, han5, a, b, x;

  while(1){
    scanf("%d%d", &a, &b);
    
    if(a == 0 && b == 0) break;

    x = b - a;
    tho = 0;
    han = 0;
    han5 = 0;
    
    
    if(x >= 1000){
      tho = x / 1000;
      x %= 1000;  
    }
    
    
    if(x >= 500){
      han5 = x / 500;
      x %= 500; 
    }
    
    if(x >= 100){
      han = x / 100;
      x %= 100;  
    }
    
    printf("%d %d %d\n", han, han5, tho);
    
  }
  
  return 0;
  
}

Measured memory_bytes: 600
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
const long long INF = 1LL << 60;

int main() {
	ll A, B, C, D;
	cin >> A >> B >> C >> D;

	ll divc = 0, divd = 0, divcd = 0;
	divc = B / C - (A - 1) / C;
	divd= B / D - (A - 1) / D;

	ll c = C, d = D;
	if (c > d) {
		swap(c, d);
	}
	ll amari = d % c;
	while (amari != 0) {
		d = c;
		c = amari;
		amari = d % c;
	}

	ll lcm = C * D / c;
	divcd = B / lcm - (A - 1) / lcm;
	ll ans = B - A + 1 - divc - divd + divcd;

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using std::cout;
using std::endl;
using std::cin;

int main()
{
    // int n;
    // while (cin >> n) {
    //     cout << n*n*n << endl;
    // }
    int n;
    while (scanf("%d", &n) == 1) {
        printf("%d\n", n * n * n);
    }

    return 0;
}



Measured memory_bytes: 3188
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;

int main(){
	int n;
	cin>>n;
	vector<int> a(n);
	vector<int> b(n);
	rep(i,n){
		int num;
		cin>>num;
		a[i] = num;
		b[i] = num;
	}
	sort(b.begin(),b.end());
	int count = 0;
	rep(i,n){
		if( a[i] != b[i]) count++;
	}
	if( count <= 2){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}


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

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

  int cnt_divisors = 0;
  for (int i = a; i <= b; i++) {
    if (c % i == 0) cnt_divisors++;
  }

  cout << cnt_divisors << endl;
  return 0;
}


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

Measured memory_bytes: 3060
while True:
    c=input()
    
    if c=="-":
        break
        
    cards=list(c)
    m=int(input())
    
    for i in range(m):
        h=int(input())
        for i in range(h):
            s=cards.pop(0)
            cards+=s
    print("".join(cards))

Measured memory_bytes: 7636
#include <bits/stdc++.h>
#define REP(i, N) for (ll i = 0; i < (N); i++)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;

ll bin_search_TLE(const ll N, ll A[]) {
  const ll N_BIT = 20;
  ll b[N_BIT][N + 1];
  // bitごとの累積和
  REP(j, N_BIT) REP(i, N + 1) b[j][i] = 0;
  REP(j, N_BIT) {
    REP(i, N) {
      ll x = (A[i] >> j) & 1;
      b[j][i + 1] = x + b[j][i];
    }
  }

  ll INF = 1 << 30;
  ll ans = 0;
  REP(i, N) {
    ll tmp = INF;
    REP(j, N_BIT) {
      // 累積和の調整
      // i = 1のとき i = 0まで累積和 + 1がi = 1以降では許容される
      ll a = 1 + b[j][i];
      // 0 to N - 1ではなく、0 to Nなので - 1 と i + 1以降なので - i
      ll x = upper_bound(b[j], b[j] + N + 1, a) - b[j];
      tmp = min(tmp, x - 1 - i);
    }
    ans += tmp;
  }
  return ans;
}

int main() {
  ll N;
  cin >> N;
  ll A[N];
  REP(i, N) cin >> A[i];

  ll ans = bin_search_TLE(N, A);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 33024
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    tmp = 1
    th = 10 ** 18
    if 0 in A:
        return 0
    for a in A:
        tmp *= a
        if tmp > th:
            return -1
    return tmp


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, A))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


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

int main(){
    int n;
    cin >> n;
    vector<int> r(n);
    for(int i = 0;i < n;i++){
        cin >> r[i];
    }
    
    int maxv = r[1] - r[0];
    int minv = r[0];
    for(int i = 1;i < n;i++){
        maxv = max(maxv, r[i] - minv);
        minv = min(minv, r[i]);
    }
    cout << maxv << endl;
}


Measured memory_bytes: 3536
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#include <string>
using namespace std;
#define N 100009
#define ll long long

int main(){
    int n;
    cin>>n;
    string a,b;
    cin>>a>>b;
    for (int i=0; i<n; i++){
        cout<<a[i]<<b[i];
    }
    cout<<endl;
}

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

#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define nl "\n"
#define sp " "
#define int long long
#define PI 3.141592653589793
#define scanstr(s) cin>>ws; getline(cin,s);

int32_t main()
{
	FastIO;
    int n,k;
    cin>>n>>k;
    int ans=0;
    while(n) n/=k, ans++;
    cout<<ans;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vvll nei(n);
    REP(i,n-1){
        ll a,b;
        cin >> a >> b;
        a--; b--;
        nei[a].pb(b);
        nei[b].pb(a);
    }
    if(n==1){
        cout << "First" << endl;
        return 0;
    }else if(n==2){
        return 0;
    }
    vll dep(n);
    dep[0]=0;
    stack<ll> st;
    st.push(0);
    vll par(n);
    par[0]=-1;
    ll v = 0;
    while(!st.empty()){
        ll now = st.top();
        st.pop();
        for(ll i:nei[now]){
            if(i!=par[now]){
                dep[i]=dep[now]+1;
                par[i] = now;
                st.push(i);
                if(dep[i]>dep[v]) v = i;
            }
        }
    }
    dep = vll(n,0);
    dep[v]=0;
    st.push(v);
    par = vll(n,0);
    par[0]=-1;
    ll u = v;
    while(!st.empty()){
        ll now = st.top();
        st.pop();
        for(ll i:nei[now]){
            if(i!=par[now]){
                dep[i]=dep[now]+1;
                par[i] = now;
                st.push(i);
                if(dep[i]>dep[u]) u = i;
            }
        }
    }
    ll l = dep[u];
    if(l%3==1){
        cout << "Second" << endl;
    }else{
        cout << "First" << endl;
    }
    return 0;
}

Measured memory_bytes: 19056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll n, m, t, a[100005];
vector< ll > adj[100005];
#define ari for( int i = 0 ; i < n ; i++ ) cin >> a[i];
#define ginp for( int i = 0 ; i < m ; i++ ){ int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u);}
#define pb push_back
#define ss second
#define ff first
#define fs first.second
#define fff first.first
#define sss second.second
#define sf second.first
#define mp make_pair

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

	cin >> n;
	ari
	int aa = 0;
	int bb = abs(a[1] - a[0]);
	int cc = min(bb + abs(a[2] - a[1]), abs(a[2] - a[0]));
	if(n == 1){
		cout << aa << endl;
		return 0;
	}
	if(n == 2){
		cout << bb << endl;
		return 0;
	}
	if(n == 3){
		cout << cc << endl;
		return 0;
	}
	int temp;

	for(int i = 3; i < n; i++){
		//cout << aa << " " << bb << " " << cc << endl;
		//temp = cc;
		aa = bb;
		bb = cc;
		cc = min(bb + abs(a[i] - a[i-1]), aa + abs(a[i] - a[i-2]));
	}
	cout << cc << endl;
	
	return(0);
}

Measured memory_bytes: 6700
#include<stdio.h>

void PrintArray(int a[], int N) {
	int i;
	for (i = 0; i < N; i++) {
		printf("%d", a[i]);
		if (!(i - N + 1)) break;
		printf(" ");
	}
	printf("\n");
}

void InsertSort(int a[], int N) {
	int buff, key, j;
	for (key = 1; key < N; key++) {
		buff = a[key];
		j = key - 1;
		while ((j >= 0) && (a[j] > buff)) {
			a[j + 1] = a[j];
			j--;
		}
		a[j+1] = buff;
		PrintArray(a, N);
	}

}

int main() {
	int a[100], N;
	scanf("%d", &N);
	for (int i = 0; i < N; i++)scanf("%d", &a[i]);
	PrintArray(a, N);
	InsertSort(a, N);


	return 0;
}


Measured memory_bytes: 2684
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int a[200005];
map<int,int> m;
signed main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	int n,k;
	cin>>n>>k;
	FOR(i,1,n)cin>>a[i],a[i]+=a[i-1];
	int ans=0;
	m[0]=1;
	FOR(i,1,n){
		if(i>=k){
			m[(a[i-k]-(i-k)+k)%k]--;
		}
		ans=ans+m[(a[i]-i+k)%k];
		m[(a[i]-i+k)%k]++;
	}
	cout<<ans;
	return 0;
}




Measured memory_bytes: 14336
#include<bits/stdc++.h>
#define ll      long long
#define pii     pair<int, int>
#define f       first
#define s       second
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d ", a)
#define pfl(a) printf("%lld\n", a)
#define Case(a) printf("Case %d: ", a)

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

    ll pre = n;

    if(min(n%k, abs(n%k - k)) < n )
        n = min(n%k, abs(n%k - k));

    cout<<n;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
ll mod = 1e9+7;
ll dp[2][110][10100]; //ギリギリ攻めてるか　あまり　すでに見た桁数

int main(){
    string s;
    cin >> s;
    int d;
    cin >> d;
    dp[1][0][0] = 1;
    rep(i,s.length()){
        rep(j,d){
            rep(k,10){
                if(k==s[i]-'0'){
                    dp[1][(j+k)%d][i+1] += dp[1][j][i];
                    dp[1][(j+k) % d][i + 1] %= mod;
                }
                if(k<s[i]-'0'){
                    dp[0][(j+k)%d][i+1] += dp[1][j][i];
                    dp[0][(j+k) % d][i + 1]%=mod;
                }
                dp[0][(j+ k) % d][i + 1]+=dp[0][j][i];
                dp[0][(j+ k) % d][i + 1] %= mod;
            }
        }
    }
    cout << (dp[1][0][s.length()]+dp[0][0][s.length()]-1+mod)%mod << endl;
    return 0;
}

Measured memory_bytes: 16896
#include<stdio.h>

int main(void){

  int n;


int x;


int i;


long long sum;


int min,max;


scanf("%d",&n);


sum = 0;


min = 1000000;


max = -1000000;


for(i = 0;i<n;i++){


    scanf("%d",&x);


    sum+=x;


    if(x<min){


      min=x;


    }


    if(x>max){


      max=x;


    }


  }


  printf("%d %d %lld\n",min,max,sum);


return 0;


}

Measured memory_bytes: 600
#include <iostream>

using namespace std;

typedef long long ll;

int N;
ll d[50];
ll score;

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> d[i];
    score = 0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            score += d[i] * d[j];
        }
    }
    cout << score << endl;
    return 0;
}

Measured memory_bytes: 256
d=int(input())
C=[int(i) for i in input().split()]
s=[[int(i) for i in input().split()] for q in range(d)]

sco=0
L=[0 for i in range(26)]

for q in range(d):
    t=int(input())-1
    sco+=s[q][t]
    
    
    L[t]=q+1
    for i in range(26):
        if L[i]!=-1:
            sco-=C[i]*(q+1-L[i])
    
    print(sco)

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


int main(){

int n,k;
cin>>n>>k;
int p=k-(n-1);
int q=k;
for(int i=1;i<abs(n);i++)
{cout<<p++<<" ";}
//cout<<k;
for(int i=1;i<=abs(n);i++)
{cout<<q++<<" ";}

return 0;
}


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

int main() {
  int n,l; cin >>n >>l;
  int pie = 0;
  for (int i=0; i<n; i++){
    pie += l + i;
  }
  int sub = 0;
  int ans = 0;
  if (l>=0) ans = pie - l;
  else if (l+(n-1)>=0) ans = pie;
  else ans = pie - (l+n-1);
  
  cout <<ans;
  cout <<endl;
}


Measured memory_bytes: 256
while (True):
    s = list(map(int, input().strip().split(' ')))

    if s[0] == 0 and s[1] == 0:
        break
    else:
        for i in range(s[0]):
            for j in range(s[1]):
                if j % 2 == 0 and i % 2 == 0:
                    print("#", end="")
                elif j % 2 == 1 and i % 2 == 0:
                    print(".", end="")
                elif j % 2 == 0 and i % 2 == 1:
                    print(".",end="")
                else:
                    print("#", end="")
            print()
    print()


Measured memory_bytes: 7004
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int a=0;
  int b=0;
  int n=s.size();
  for(int i=0;i<n;i++){
    if(i%2==0){
      if(s[i]=='0')a++;
    }
    else{
      if(s[i]=='1')a++;
    }
  }
  for(int i=0;i<n;i++){
    if(i%2==0){
      if(s[i]=='1')b++;
    }
    else{
      if(s[i]=='0')b++;
    }
  }
  cout<<min(a,b)<<endl;
}

Measured memory_bytes: 512
import collections as c

N = int(input())
a = [int(i) for i in input().split()]

d = c.Counter()
for i in a:
    d[i] += 1

ans = 0
for k, v in d.items():
    if v >= k:
        ans += v - k
    else:
        ans += v

print (ans)

Measured memory_bytes: 18676
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{
	int n;
	
	std::cin >> n;
	
	std::vector<int> a(n);
	
	long long int sum = 0LL;
	for(int i = 0; i < n; i++)
	{
		std::cin >> a[i];
		sum += a[i];
	}
	
	int min = *std::min_element(a.begin(), a.end());
	int max = *std::max_element(a.begin(), a.end());

	std::cout << min << " " << max << " " << sum << std::endl;
	
	return 0;
}


Measured memory_bytes: 3140
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	long long x;
	scanf("%lld",&x);
	long long y=(x+1)/2;
	double ans=(double)y/(double)x;
	printf("%0.10lf",ans);
	return 0;
}

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

static class Factrial
{
    static void Main()
    {
        var f = Enumerable.Range( 1, int.Parse( Console.ReadLine() ) )
            .Select( x => (long)x )
            .Aggregate( (x, y) => x * y );
        Console.WriteLine( f );
    }
}

Measured memory_bytes: 5812