akhauriyash/Code-Regression huggingface dataset:
use std::io;
use std::str;

/// Reads white-space separated tokens one at a time.
pub struct Scanner<R> {
    reader: R,
    buffer: Vec<String>,
}

impl<R: io::BufRead> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buffer: vec![],
        }
    }

    /// Use "turbofish" syntax token::<T>() to select data type of next token.
    ///
    /// # Panics
    ///
    /// Panics if there's an I/O error or if the token cannot be parsed as T.
    pub fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            self.reader.read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

fn solve<R: io::BufRead, W: io::Write>(scan: &mut Scanner<R>, out: &mut W) {
    let a: i32 = scan.token();
    let ans = a + a * a + a * a * a;
    writeln!(out, "{}", ans).ok();
}

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());
    solve(&mut scan, &mut out);
}

Measured memory_bytes: 2132
s = input()
t = input()

changes = dict()
values = set()
answer = True

for a, b in zip(s, t):
    if a in changes:
        answer &= changes[a] == b
    else:
        if b in values:
            answer = False
        else:
            changes[a] = b
            values.add(b)

print("Yes" if answer else "No")


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

int main()
{
  string S;
  cin >> S;
  
  if(S == "SSS") cout << "0" << endl;
  else if(S == "RRR") cout << "3" << endl;
  else if(S == "SRR" || S == "RRS") cout << "2" << endl;
  else cout << "1" << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const int MOD = 1000000007; 

int main() {
    ll x; cin >> x;
    vector<ll> as;
    rep(i, 201) {
        ll a = i*i;
        a *= a;
        a *= i;
        as.push_back(a);
    } 
    int ta = 0, tb = 0; 
    rep(ai, 101) {
        rep(bi, 101) {
            ll t = as[ai] + as[bi];
            if (t == x) {
                cout << ai << " " << -bi << endl;
                return 0; 
            }
        }
    }
    rep(ai, 201) {
        rep(bi, 201) {
            ll t = as[ai] - as[bi];
            if (t < 0) break;
            if (t == x) {
                cout << ai << " " << bi << endl;
                return 0; 
            }
        }
    }
    return 0;
}

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

using namespace std;

int N, M, ap[100009];
long long h[100009];
vector < pair < int, int > > v[100009];

void dfs (int nod)
{
    ap[nod] = 1;
    for (auto it : v[nod])
        if (ap[it.first] == 0)
            h[it.first] = h[nod] + it.second, dfs (it.first);
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &M);
while (M --)
{
    int x, y, d;
    scanf ("%d %d %d", &x, &y, &d);
    v[x].push_back ({y, d});
    v[y].push_back ({x, -d});
}
for (int i=1; i<=N; i++)
    if (ap[i] == 0)
        h[i] = 0, dfs (i);
for (int i=1; i<=N; i++)
    for (auto it : v[i])
        if (h[it.first] != h[i] + it.second)
        {
            printf ("No\n");
            return 0;
        }
printf ("Yes\n");
return 0;
}


Measured memory_bytes: 11776
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const ll mod=1000003;
ll pow(ll x,ll y){
  if(y==0) return 1;
  ll res=pow(x,y/2);
  res*=res;
  res%=mod;
  if(y%2==1) res*=x;
  return res%mod;
}
ll gyaku(ll x){
  return pow(x,mod-2);
}
vector<ll> frac,gfrac;
void set_frac(ll n){
  frac.push_back(1);
  gfrac.push_back(1);
  for(ll i=1;i<=n;i++){
    frac.push_back(frac[i-1]*i%mod);
    gfrac.push_back(gyaku(frac[i]));
  }
  //frac[0]=0;
  //gfrac[0]=0;
}
ll nCr(ll n,ll r){
  ll res=frac[n]*gfrac[r]%mod;
  res*=gfrac[n-r];
  return res%mod;
}
ll solve(ll x,ll d,ll n){
  ll ans=pow(d,n);
  ll X=(x*gyaku(d))%mod;
//  cout<<"X"<<X<<" "<<mod-X<<" "<<n<<endl;
  if((mod-X)<n) return 0;
//  cout<<"Y"<<endl;
  ans*=frac[(X+n-1)%mod];
  ans%=mod;
  ans*=gfrac[(X+mod-1)%mod];
  ans%=mod;
  return ans;
}
int main(){
  ll q;
  cin>>q;
  set_frac(mod+20);
  for(int i=0;i<q;i++){
    ll x,d,n;
    cin>>x>>d>>n;
    if(d==0) {
      cout<<pow(x,n)<<endl;
    }
    else cout<<solve(x,d,n)<<endl;
  }
}


Measured memory_bytes: 16980
#include<bits/stdc++.h>
#define int long long
using namespace std;
    string a[1234567];
    main(){
    int n;
    cin >> n;
    int mm , ma ,mr, mc,mh;
    mm = ma = mr = mc = mh = 0;
    for(int i = 1 ; i <= n;i++){
        cin >> a[i];
        if(a[i][0] =='M')mm++;
        if(a[i][0] =='A')ma++;
        if(a[i][0] =='R')mr++;
        if(a[i][0] =='C')mc++;
        if(a[i][0] =='H')mh++;
    }
    int d[]={mm,ma,mr,mc,mh};
    sort(d,d+5);
    int ans = 0;
    for(int i = 0 ; i < 5 ; i ++){
        for(int j = i + 1 ; j < 5;j++){
            for(int k = j + 1 ; k < 5;k++){
                ans += d[k] * d[j] * d[i];
            }
        }
    }
    cout << ans;






    }


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

const ll INF = (1LL<<59);

int main(){
    string s; cin >> s;
    int w; cin >> w;

    for(int i=0; i<s.size(); i++) if(i%w == 0) cout << s[i];
    cout << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  private static void solve(char[][] grid, int h, int w, int k) {
    int cnt = 0;
    for (int i = 0; i < (1 << h); i++) {
      for (int j = 0; j < (1 << w); j++) {
        if (check(grid, i, j, h, w, k)) {
          cnt++;
        }
      }
    }
    System.out.println(cnt);
  }

  private static boolean check(char[][] grid, int r, int c, int h, int w, int k) {
    int count = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if ((r & (1 << i)) != 0 || (c & (1 << j)) != 0) {
          continue;
        }
        if (grid[i][j] == '#') {
          count++;
        }
      }
    }
    return count == k;
  }

  public static void main(String[] args) {
    int h = scanner.nextInt();
    int w = scanner.nextInt();
    int k = scanner.nextInt();
    char[][] grid = new char[h][w];
    for (int i = 0; i < h; i++) {
      String s = scanner.next();
      for (int j = 0; j < w; j++) {
        grid[i][j] = s.charAt(j);
      }
    }
    solve(grid, h, w, k);
  }

  private static final Scanner scanner = new Scanner(System.in);
}


Measured memory_bytes: 35796
//20
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
 
using namespace std;
 
int main(){
  for(int n;cin>>n,n;){
    vector<pair<int,int> > v;
    for(int i=1;i<=n;i++){
      int c;
      cin>>c;
      if(i%2==0&&v.end()[-1].first!=c){
	if(v.size()==1){
	  v[0].first^=1;
	}else{
	  v.end()[-2].second+=v.end()[-1].second;
	  v.erase(v.end()-1);
	}
      }
      if(v.empty()||v.end()[-1].first==(c^1)){
	v.push_back(make_pair(c,1));
      }else{
	v.end()[-1].second++;
      }
    }
    int ans=0;
    for(int i=0;i<v.size();i++){
      if(v[i].first==0){
	ans+=v[i].second;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans[10] = {};

int main()
{
ll h,w,n;
cin >> h>>w>>n;
map<pair<ll,ll>,ll> m{};
rep(i, n){
    ll x,y;
    cin >> x>>y;
    rep(j,3)rep(k,3){
        if(x+j-1>1&&x+j-1<h&&y+k-1>1&&y+k-1<w)
        m[{x+j-1,y+k-1}]+=1;
    }
}
ans[0]=(h-2)*(w-2);

for (auto i = m.begin(); i != m.end(); ++i) {
    ans[i->second]++;
    ans[0]--;
}

rep(i,10)cout << ans[i] << endl;
return 0;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

const int MAX = 1e6+10;
bool isp[MAX];
LL dp[MAX];

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

  int N;
  cin >> N;
  VI xs(N);
  cin >> xs;

  fill(isp, isp+MAX, true);
  isp[0] = isp[1] = false;
  for(int i=2;i<MAX;++i)
	if(isp[i])
	  for(int j=i+i;j<MAX;j+=i)
		isp[j] = false;

  if(!isp[xs[0]]){
	cout << 0 << endl;
	return 0;
  }
  if(N == 1){
	cout << 1 << endl;
	return 0;
  }

  dp[0] = 1;
  for(int i=1;i<N;++i){
	if(isp[xs[i]]){
	  if(isp[xs[i-1]] && xs[i-1] < xs[i])
		(dp[i] += dp[i-1]) %= MOD;
	  if(i>=2 && isp[xs[i-2]] && xs[i-2] < xs[i])
		(dp[i] += dp[i-2]) %= MOD;
	}
  }

  LL ans = 0;
  if(isp[xs[N-1]]) ans += dp[N-1];
  if(isp[xs[N-2]]) ans += dp[N-2];

  cout << ans%MOD << endl;

  return 0;
}



Measured memory_bytes: 5048
#include <bits/stdc++.h>
#define int long long
#define sz(x) (int)(x.size())
using namespace std;

const int N = 20, mod = 1e9 + 7, inf = 1e18;

string A, B;
int n, dp[N][2][2];

int go(int pos, bool bigA, bool smallB){
    if(pos >= n)
        return 0;

    int &ans = dp[pos][bigA][smallB];
    if(~ans)
        return ans;
    ans = 0;
    for(int i = 0; i < 10; i++){
        if(!bigA && i < A[pos] - '0')   continue;
        if(!smallB && i > B[pos] - '0') continue;

        int get = i + go(pos + 1, bigA || (i > A[pos] - '0'), smallB || (i < B[pos] - '0'));
        ans = max(ans, get);
    }
    return ans;
}

int32_t main(){

    memset(dp, -1, sizeof(dp));
    A = "1";
    cin >> B;
    reverse(A.begin(), A.end());
    while(sz(A) < sz(B))
        A.push_back('0');
    reverse(A.begin(), A.end());
    n = sz(B);
    int ans = 0;

    for(int i = 0; i < 10; i++){
        if(i < A[0] - '0')  continue;
        if(i > B[0] - '0')  continue;

        int get = i + go(1, i > A[0] - '0', i < B[0] - '0');
        ans = max(ans, get);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
import bisect
n=int(input())
l=sorted(list(map(int,input().split())))
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        x=bisect.bisect_left(l,l[i]+l[j])-j-1
        ans+=max(0,x)
print(ans)

Measured memory_bytes: 9304
#include <iostream>

using namespace std;

int main()
{
  int exists[2019];
  int l, r, min;

  cin >> l >> r;
  for (int i = 0; i < 2019; i++) {
    exists[i] = 0;
  }
  for (int i = l; i <= r && i <= l+2019; i++) {
    exists[i%2019] = 1;
  }

  min = 2019;
  for (int i = 0; i < 2018; i++) {
    if (exists[i]) {
      for (int j = i+1; j < 2019; j++) {
        if (exists[j]) {
          int rem = (i*j) % 2019;
          if (rem < min) {
            min = rem;
          }
        }
      }
    }
  }

  cout << min << endl;
  return 0;
}


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

using namespace std;

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

	vector<int> a;
	for (int i = 0; i < N; i++)
	{
		int tmp;
		scanf("%d", &tmp);
		a.push_back(tmp);
	}

	vector<bool> ratedColors;
	for (int i = 0; i < 8; i++)
	{
		ratedColors.push_back(false);
	}
	int numRated3200 = 0;

	for (int i = 0; i < N; i++)
	{
		if (a[i] >= 1 && a[i] <= 399)
			ratedColors[0] = true;
		else if (a[i] >= 400 && a[i] <= 799)
			ratedColors[1] = true;
		else if (a[i] >= 800 && a[i] <= 1199)
			ratedColors[2] = true;
		else if (a[i] >= 1200 && a[i] <= 1599)
			ratedColors[3] = true;
		else if (a[i] >= 1600 && a[i] <= 1999)
			ratedColors[4] = true;
		else if (a[i] >= 2000 && a[i] <= 2399)
			ratedColors[5] = true;
		else if (a[i] >= 2400 && a[i] <= 2799)
			ratedColors[6] = true;
		else if (a[i] >= 2800 && a[i] <= 3199)
			ratedColors[7] = true;
		else if (a[i] >= 3200)
			numRated3200++;
	}

	int numRated = 0;
	for (int i = 0; i < 8; i++)
	{
		if (ratedColors[i])
			numRated++;
	}

	if (numRated == 0)
	{
		numRated = 1;
		numRated3200--;
	}

	printf("%d %d\n", numRated, numRated + numRated3200);
}

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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

#define _GLIBCXX_DEBUG

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int N, M, P;

const int dx[] = {1,0,0, 1,-1, 1, 1,-1, 1, 0, 0, 0, 1,-1, 1, 1},
          dy[] = {0,1,0, 1, 1,-1, 0, 0, 0, 1,-1, 1, 1, 1,-1, 1},
          dz[] = {0,0,1, 0, 0, 0, 1, 1,-1, 1, 1,-1, 1, 1, 1,-1};

int check_board(vector<vvi>& board) {
    REP(z, N) REP(y, N) REP(x, N) {
        REP(i, 16) {
            int sx = x + dx[i]*(M-1), sy = y + dy[i]*(M-1), sz = z + dz[i]*(M-1);
            if (0 <= sx && sx < N && 0 <= sy && sy < N && 0 <= sz && sz < N) {
                int black = 0, white = 0;
                REP(j, M) {
                    int sx = x + dx[i]*j, sy = y + dy[i]*j, sz = z + dz[i]*j;
                    if (board[sz][sy][sx] == 1) {
                        black++;
                    } else if (board[sz][sy][sx] == 2) {
                        white++;
                    }
                }
                if (black == M) {
                    return 1;
                } else if (white == M) {
                    return 2;
                }
            }
        }
    }
    return 0;
}

int main() {
    while (cin >> N >> M >> P, N|M|P) {
        vector<vvi> board(N, vvi(N, vi(N)));
        vector<pii> p(P);
        REP(i, P) {
            int x, y;
            cin >> x >> y;
            x--;
            y--;
            p[i] = {x, y};
        }

        REP(i, P) {
            int x = p[i].first, y = p[i].second;
            REP(z, N) {
                if (board[z][y][x] == 0) {
                    board[z][y][x] = i%2 + 1;
                    break;
                }
            }
            int retval = check_board(board);
            if (retval == 1) {
                printf("Black %d\n", i+1);
                goto END;
            } else if (retval == 2) {
                printf("White %d\n", i+1);
                goto END;
            }
        }
        printf("Draw\n");
END: {}
    }
}

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

ll arr[5];
ll n;

int main() {
	cin >> n;

	cin >> arr[0];
	ll Min = arr[0];
	for (int i = 1; i < 5; i++) {
		cin >> arr[i];
		if (Min > arr[i])
			Min = arr[i];
	}

	ll Count = 4;

	Count += n / Min;
	if (n%Min)
		Count++;

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

	return 0;
}

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

N = int(input())
x = [None] * N
y = [None] * N
h = [None] * N
for i in range(N):
    x[i], y[i], h[i] = map(int, input().split())


def distance(a,b):
    a_x = a[0]
    a_y = a[1]
    b_x = b[0]
    b_y = b[1]

    return abs(a_x - b_x) + abs(a_y - b_y)


for cx in range(101):
    for cy in range(101):
        ans = True
        c = [cx, cy]
        for i in range(N):
            if h[i] != 0:
                ch = distance(c, [x[i], y[i]]) + h[i]
                break
        # ch = distance(c, [x[0], y[0]]) + h[0]  # cx, cyを仮定するとchが定まる
        for i in range(N):
            if max([ch - distance(c, [x[i], y[i]]), 0]) != h[i]:
                ans = False
                break
        if ans:
            break
    if ans:
        break

print(" ".join(list(map(str, [cx, cy, ch]))))

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

int main() {
    int N, ans = numeric_limits<int>::min();
    string S;
    cin >> N >> S;
    int DP[N + 1][N + 1] = {};
    for (int i = N - 1; i >= 0; i--) {
        for (int j = N - 1; j >= 0; j--) {
            if (S[i] == S[j]) {
                DP[i][j] = 1 + DP[i + 1][j + 1];
            }
            ans = max(ans, min(DP[i][j], max(i, j) - min(i, j)));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 97920
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18

priority_queue<int,vector<int>,greater<int>> que;

void solve(){
	int n;
	cin >> n;
	int m=0;
	int ans;
	for(int i=0;i<n;i++){
		int a,b;
		cin >> a >> b;
		if(m<a){
			m=a;
			ans=a+b;
		}
	}
	cout << ans << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    ll n;
    cin >> n;
    ll ans = LINF;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            chmin(ans,i+n/i-2);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) {
        FastReader fs = new FastReader();
        final int inf = Integer.MAX_VALUE;
        int n = fs.nextInt();
        boolean ok = false;
        int cnt = 0;
        for (int i = 0; i < n; i ++) {
            int x = fs.nextInt();
            int y = fs.nextInt();
            if (x == y) cnt ++;
            else cnt = 0;
            if (cnt >= 3) ok = true;
        }
        if (!ok) System.out.println("No");
        else System.out.println("Yes");





    }


    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 32812
'''
Created on Mar 22, 2013

@author: wukc
'''

from sys import stdin 

def shift(s):
    return ["".join([chr(97+(ord(x)-97+t)%26) if x.islower() else x for x in s]) for t in range(26)]

target=["this","the","that"]

for s in stdin:
    for x in shift(s):
        if sum(map(x.count,target))>0:
            print(x[:-1])

Measured memory_bytes: 4232
import java.util.*;
import java.io.*;
import java.time.chrono.MinguoDate;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    static int dx[]={-1,0,1,0};
    static int dy[]={0,-1,0,1};

    public  static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // int d[]=new int[n];
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}

        
        int n=sc.nextInt();
        int e[]=new int[n];
        double d=0;
        for (int  i = 0; i < n; i++) {
			e[i]=sc.nextInt();
			d+=e[i];
		}
        d/=n;
        double min=1<<28;
        int ans=0;
        for (int  i = 0; i < n; i++) {
        	if(abs(d-e[i])<min) {
        		ans=i;
        		min = abs(d-e[i]);
        	}
		}
        


        out.println(ans);
        out.flush();
    }

    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }


    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}



//class P implements Comparable<P>{
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//    public int compareTo(P p){
//        return d-p.d; //des
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


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

int main()
{
    char c;
    cin>>c;
    string str="aiueo";
    int b=0;
    for(int i=0;i<str.size();i++){
        if(c==str.at(i)){
            cout<<"vowel";
            b=1;
            break;
        }
    }
    if(!b){
        cout<<"consonant";
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int n,k;
	long int i = 0;
	i = scanf("%d", &n);
	i = scanf("%d", &k);
        i = k;
	for(int z = 1;n>z;z++){
        i *= k-1;

}
        printf("%ld",i);
	return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
bool dis_is_int(int d,int x1[],int x2[]){
  double dis=0;
  for(int i=0;i<d;i++){
    dis+=pow(x1[i]-x2[i],2);
  }
  dis=pow(dis,0.5);
  return ceil(dis) == floor(dis);
}

int main(){
  int n,d;
  cin >> n >> d;
  int x[n][d];
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin>>x[i][j];
    }
  }
  
  int cnt=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<i;j++){
      cnt+=(dis_is_int(d,x[i],x[j]) ? 1 : 0);
    }
  }
  
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 640
/*input
200
*/
#include "bits/stdc++.h"
#define ll long long
using namespace std;
#define pb push_back
#define mod 998244353

ll mod_expo(ll b, ll p){
	ll res = 1;
	while(p) {
		if(p&1) {
			res*= b;
			res%=mod;
		}
		b*=b ;b%=mod;
		p/=2;
	}
	return res;
}
// 10813692
int main()
{
	int k;
	ll ans=0;
	cin>> k;
	for(int i=1; i<=k;i++) {
		for(int j=1;j<=k; j++) {
			for(int l=1; l<=k; l++)
				ans+= __gcd(__gcd(i,j),l);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3624
from collections import deque

def bfs(h_i, w_i):
    visit = [[0] * w for _ in range(h)]
    visit[h_i][w_i] = 1
    d = deque()
    d.append([h_i, w_i])
    distance = [[0] * w for _ in range(h)]
    while d:
        x, y = d.popleft()
        for i, j in [[0, 1], [0, -1], [1, 0], [-1, 0]]:
            if (0 <= x + i <= h - 1) & (0 <= y + j <= w - 1):
                if visit[x + i][y + j] == 0:
                    visit[x + i][y + j] = 1
                    if s[x + i][y + j] == '.':
                        distance[x + i][y + j] = distance[x][y] + 1
                        d.append([x+i, y+j])
    ans = []
    for i in distance:
        ans += i
    return max(ans)

h, w = map(int, input().split())
s = []
for _ in range(h):
    t = list(input())
    s.append(t)
dist = []
for i in range(h * w):
    h_i = i % h
    w_i = i // h
    if s[h_i][w_i] == '.':
        dist.append(bfs(h_i, w_i))
print(max(dist))

Measured memory_bytes: 3316
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<bits/stdc++.h>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<string.h>
#include<map>

using namespace std;

int main(){

    int n,k;
    cin>>n>>k;

    int arr[n];
    int dp[n];

    for(int i=0;i<n;i++) dp[i] = INT_MAX;

    for(int i=0;i<n;i++) cin>>arr[i];

    dp[0] = 0;
    
    for(int i=1;i<n;i++){
        for(int j=1;j<=k;j++){
            if(i-j>=0) { 
                dp[i] = min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j])); 
            }
        }
    }
    cout<<dp[n-1];

    return 0;

}

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

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

    int ret = INT_MAX;
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;

    for(int ab = 0; ab <= 2 * max(x, y); ab += 2){
      int cost = ab * c;
      if(x >= ab/2) cost += (x - ab/2) * a;
      if(y >= ab/2) cost += (y - ab/2) * b;
      ret = min(ret, cost);
    }
    cout << ret << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split( ))

listA = [[int(i) for i in input().split()] for i in range(n)] 

ans = 0

for a in range(1, m+1):
    ok = True
    for i in range(n):
        if a not in listA[i][1:]:
            ok = False
    if ok:
        ans += 1

print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	vi a(m),b(m);
	rep(i,m)cin>>a[i]>>b[i];
	int t=1;
	int co=0;
	while(t!=n+1){
		int ma=-1;
		rep(i,m)if(a[i]<=t&&t<=b[i])ma=max(ma,b[i]);
		if(ma==-1){
			cout<<"Impossible"<<endl;
			return 0;
		}
		rep(i,m)if(a[i]<=t&&t<=b[i]&&ma==b[i]){
			t=b[i]+1;
			co++;
			break;
		}
	}
	cout<<co<<endl;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end());
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n;
unsigned DP[5002], DP2[5002];
string s;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> s;
  DP[0] = 1;
  FOR(i, 0, n){
    FOR(j, 0, i+2) DP2[j] = (DP[max(j-1, 0)]+DP[j+1]*2) % MOD;
    swap(DP, DP2);
  }
  cout << DP[sz(s)] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long MOD=1e9+7;

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}
template<typename T> T extgcd(T a,T b,T &x,T &y){
    T d=a;
    if (b!=0){
        d=extgcd(b,a%b,y,x);
        y-=(a/b)*x;
    } else x=1,y=0;
    return d;
}
template<typename T> int digit(T n){
    string cnt=to_string(n);
    return cnt.size();
}

template<typename T> bool is_prime(T n){
    for (T i=2;i*i<=n;++i)
        if (n%i==0) return false;
    return 1<n;
}
template<typename T> vector<T> divisor(T n){
    vector<T> res;
    for (T i=1;i*i<=n;++i) if (n%i==0){
        res.emplace_back(i);
        if (i!=n/i) res.emplace_back(n/i);
    }
    return res;
}
template<typename T> map<T,int> prime_factor(T n){
    map<T,int> res;
    for (T i=2;i*i<=n;++i){
        while (n%i==0){
            ++res[i]; n/=i;
        }
    }
    if (n!=1) res[n]=1;
    return res;
}
vector<bool> prime_table(int n){
    vector<bool> prime(n+1,true);
    prime[0]=prime[1]=false;
    for (int i=2;i<=n;++i) if (prime[i]){
        for (int j=i+i;j<=n;j+=i) prime[j]=false;
    }
    return prime;
}
vector<int> primes(int n){
    vector<int> res;
    vector<bool> pt=prime_table(n);
    for (int i=2;i<=n;++i) if (pt[i]){
        res.emplace_back(i);
    }
    return res;
}

long long modpow(long long x,long long n,long long mod){
    long long res=1;
    while (n>0){
        if (n&1LL) res=res*x%mod;
        x=x*x%mod; n>>=1LL;
    }
    return res;
}
long long modinv(long long x,long long p){
    return modpow(x,p-2,p);
}

template<typename T>
T eular_phi(T n){
    T res=n;
    for (T i=2;i*i<=n;++i) if (n%i==0){
        res-=res/i;
        while (n%i==0) n/=i;
    }
    if (n!=1) res-=res/n;
    return res;
}
vector<int> eular_phi_table(int n){
    vector<int> eular(n+1);
    iota(eular.begin(),eular.end(),0);
    for (int i=2;i<=n;++i) if (eular[i]==i){
        for (int j=i;j<=n;j+=i) eular[j]-=eular[j]/i;
    }
    return eular;
};


// https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_A

void NTL_1_A(){
    int n; cin >> n;
    map<int,int> ans=prime_factor(n);
    cout << n << ':';
    for (auto p:ans){
        for (int i=0;i<p.second;++i){
            cout << ' ' << p.first;
        }
    }
    cout << '\n';
}

// https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_B

void NTL_1_B(){
    ll m,n; cin >> m >> n;
    cout << modpow(m,n,MOD) << '\n';
}

// https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_C

void NTL_1_C(){
    int n; cin >> n;
    ll ans=1;
    for (;n--;){
        ll a; cin >> a;
        ans=lcm(ans,a);
    }
    cout << ans << '\n';
}

// https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_D

void NTL_1_D(){
    int n; cin >> n;
    cout << eular_phi(n) << '\n';
}

// https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_E

void NTL_1_E(){
    int a,b,x,y; cin >> a >> b;
    extgcd(a,b,x,y);
    cout << x << ' ' << y << '\n';
}


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


Measured memory_bytes: 3212
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;
ll mod = pow(10,9) + 7;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}


int main(void){
    int n,k; cin >> n >> k;
	ll count = 1;
	count *= k;
	rep(i,n-1){
		count *= (k-1);
	}
	cout << count << endl;
}


Measured memory_bytes: 256
n=int(input())

l=[[0 for i in range(n)] for j in range(n)]##静的確保 隣接行列
d=[0 for i in range(n)]##発見
f=[0 for i in range(n)]##完了
stack=[]##スタック
check=[]

for i in range(n):
    p=[int(x) for x in input().split()]
    
    for j in range(n):
        if j+1 in p[2:]:
            l[i][j]=1
##print("---隣接行列---")
##print(l)

time=1


while len(check)<n:
    for i in range(n):
        if i+1 not in check:
            stack+=[i+1]
            d[i]=time
            break
        else: pass

    while len(stack)!=0:
        ##print("----------while---------")
        for i in range(n):
            if l[stack[-1]-1][i]==1 and not i+1 in check and i+1 not in stack and stack[-1]-1!=i:
                time+=1
                d[i]=time
                stack+=[i+1]

               ## print("stack:",stack)
               ## print("check:",check)
               ## print("d[",i,"]:",d[i])
                break
            elif i==n-1:
##最深    
                check+=[stack[-1]]
                time+=1
                f[stack.pop()-1]=time

               ## print("f[",i,"]:",f[i])
               ## print("check:",check)
    time+=1


for i in range(n):
    print(i+1,d[i],f[i])



Measured memory_bytes: 5736
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	string s;
	cin >> s;
	for (auto i : s) {
		N += (i == '1');
	}
	cout << N << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        string s = ReadLine();

        switch (s)
        {
            case "A":
                WriteLine("T");
                break;
            case "T":
                WriteLine("A");
                break;
            case "C":
                WriteLine("G");
                break;
            case "G":
                WriteLine("C");
                break;
            default:
                throw new FormatException();
        }

        ReadKey();
    }
}

static class MyUtil
{
    public static int[] ReadIntArray()
    {
        return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
    }

    /// <summary>
    /// <see cref="IEnumerable{T}"/>の各要素を並べてコンソールに出力します。各要素の間には半角スペースが一つ入ります。
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="ts"></param>
    public static void WriteToConsole<T>(this IEnumerable<T> ts)
    {
        StringBuilder stringBuilder = new StringBuilder();
        foreach (T t in ts)
        {
            stringBuilder.Append(t.ToString());
            stringBuilder.Append(" ");
        }
        stringBuilder.Remove(stringBuilder.Length - 1, 1);
        Console.WriteLine(stringBuilder.ToString());
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N, M;
int bit[10]{};
set<int> set0[10]{};
int p[10]{};
int cnt = 0;

void solve() {
  for (int i = 0; i < M; i++) {
    int sum = 0;
    for (int j = 0; j < N; j++) {
      if (bit[j] == 1 && set0[i].count(j) == 1) sum++;
    }
    if (sum % 2 != p[i]) return;
  }
  cnt++;
}

void rec(int k) {
  if (k == N) {
    solve();
    return;
  }
  rec(k + 1);
  bit[k] = 1;
  rec(k + 1);
  bit[k] = 0;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int s;
      cin >> s;
      s--;
      set0[i].insert(s);
    } 
  }
  for (int i = 0; i < M; i++) {
    cin >> p[i];
  } 
  rec(0);
  cout << cnt << "\n";
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int main() {
    int n;
    cin>>n;
    long long int a=1,b=1,c=1;
    for(int i=1;i<=n;i++){
        a=(a*10)%mod;
        b=(b*9)%mod;
        c=(c*8)%mod;
    }
    long long int ans=(a-2*b+c)%mod;
    ans=(ans+mod)%mod;
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int n;cin >> n;
	vector<int> a(n+1),b(n);
	rep(i,n+1)cin >> a[i];
	rep(i,n)cin >> b[i];
	int ret = 0;
	rep(i,n){
		int hidari = min(b[i],a[i]);
		b[i] -= hidari;
		a[i] -= hidari;
		ret += hidari;
		int migi = min(b[i],a[i+1]);
		b[i] -= migi;
		a[i+1]-= migi;
		ret+= migi;

	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 4804
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ins insert
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define rev(i,a,b) for(int i=b;i>=a;i--)
#define boost ios_base::sync_with_stdio(NULL),cin.tie(NULL),cout.tie(NULL)
#define nl '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<pii> vii;

const int N=200001;
const int MXN=1000001;
const int inf=1e9;
const ll INF=1e18;

vi g[N];
int d[N];

void dfs(int v,int p){
  d[v]=d[p]+1;
  for(int i=0;i<sz(g[v]);i++){
    int to=g[v][i];
    if(to==p)continue;
    dfs(to,v);
  }
}

int main(){
  boost;
  int n;
  cin>>n;
  for(int i=1;i<n;i++){
    int u,v;
    cin>>u>>v;
    g[u].pb(v);
    g[v].pb(u);
  }
  dfs(1,1);
  int len=0,u=0;
  for(int i=1;i<=n;i++){
    if(len<d[i]){
      len=d[i];
      u=i;
    }
    d[i]=0;
  }
  dfs(u,u);
  int D=0;
  for(int i=1;i<=n;i++){
    D=max(D,d[i]);
  }
  D--;
  if(D%3==1)cout<<"Second";
  else cout<<"First";
  return 0;
}



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

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

Measured memory_bytes: 6320
#include<stdio.h>
#include<string.h>
 
int main()
{
    char str[1005], p[1005], command[10];
    int a, b, q, tmp;
 
    scanf("%s", str);
    scanf("%d", &q);
 
    for (int i = 0; i < q; i++)
    {
        scanf("%s", command);
        scanf("%d%d", &a, &b);
        if (!strcmp(command, "print"))
        {
            for (int j = a; j <= b; j++)
                printf("%c", str[j]);
            printf("\n");
        }
        else if (!strcmp(command, "reverse"))
        {
            for (int j = 0; a + 2 * j <= b; j++)
            {
                tmp = str[a + j];
                str[a + j] = str[b - j];
                str[b - j] = tmp;
            }
        }
        else
        {
            scanf("%s", p);
            for (int j = 0; j <= b - a; j++)
                str[a + j] = p[j];
        }
    }
}


Measured memory_bytes: 2044
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)

    val x = BigInt(sc.nextBigInteger())

    var count = 0
    var now = 100L
    while (now < x) {
      count += 1
      now = now + now / 100L
    }

    println(count)
  }

  @scala.annotation.tailrec
  def gcd(a: Int, b: Int): Int = {
    if (b == 0) a else gcd(b, a % b)
  }
  def debug(args: Any*): Unit = {
    Console.err.println(args.mkString(" "))
  }
}


Measured memory_bytes: 55252
#include<iostream>
#include<vector>
#include<algorithm>
#include<bitset>
using namespace std;
int main(){
    int latte[]={
        0b0111111,0b0000110,0b1011011,0b1001111,0b1100110,
        0b1101101,0b1111101,0b0100111,0b1111111,0b1101111,
    };

    int n;
    while(cin>>n,n!=-1){
        int l=0;
        while(n--){
            int cafe;
            cin>>cafe;
            int p=l^latte[cafe];
            l=latte[cafe];
            for(int i=6;i>=0;i--){
                cout<<((p>>i)&1);
            }
            cout<<endl;
        }
    }
    return 0;
}

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

typedef long long LL;
const int N = 105;

int n, m, k, mod;
int factor[N], ifactor[N];

void reduce(int &x) { x += x >> 31 & mod; }
void up(int &a, int b, int c) { a = (a + (LL) b * c) % mod; }
int pow(int x, int y, int ans = 1) {
	for (; y; y >>= 1, x = (LL) x * x % mod)
		if (y & 1) ans = (LL) ans * x % mod;
	return ans;
}

int w[N][N * N];
void init(int n) {
	factor[0] = 1;
	for (int i = 1; i <= n; ++i)
		factor[i] = (LL) factor[i - 1] * i % mod;
	ifactor[n] = pow(factor[n], mod - 2);
	for (int i = n; i; --i)
		ifactor[i - 1] = (LL) ifactor[i] * i % mod;
	for (int i = 1; i <= k; ++i) {
		w[i][0] = 1;
		for (int j = 1; j <= n * n; ++j)
			w[i][j] = (LL) w[i][j - 1] * i % mod;
	}
}

int dp[2][N][N], trans[N][N];

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> m >> k >> mod, init(std::max(n, m));
	dp[0][0][0] = 1;
	for (int t = 1, now = 0, lst = 1; t <= k; ++t) {
		if (t > 1) {
			now ^= 1, lst ^= 1, std::memset(dp[now], 0, sizeof dp[0]);
			for (int p = 0; p <= n; ++p)
				for (int q = 0; q <= m; ++q)
					trans[p][q] = (LL) w[t - 1][p * (m - q)] * w[k - t + 1][p * q] % mod * (p & 1 ? mod - ifactor[p] : ifactor[p]) % mod;
			for (int i = 0; i <= n; ++i)
				for (int j = 0; j <= m; ++j)
					for (int k = 0; k <= n - i; ++k)
						up(dp[now][i + k][j], dp[lst][i][j], trans[k][j]);
			now ^= 1, lst ^= 1, std::memset(dp[now], 0, sizeof dp[0]);
			for (int p = 0; p <= m; ++p)
				for (int q = 0; q <= n; ++q)
					trans[p][q] = (LL) w[t - 1][p * (n - q)] * w[k - t + 1][p * q] % mod * (p & 1 ? mod - ifactor[p] : ifactor[p]) % mod;
			for (int i = 0; i <= n; ++i)
				for (int j = 0; j <= m; ++j)
					for (int k = 0; k <= m - j; ++k)
						up(dp[now][i][j + k], dp[lst][i][j], trans[k][i]);
		}
		now ^= 1, lst ^= 1, std::memset(dp[now], 0, sizeof dp[0]);
		for (int p = 0; p <= n; ++p)
			for (int q = 0; q <= m; ++q)
				trans[p][q] = (LL) w[t][p * (m - q)] * w[k - t + 1][p * q] % mod * ifactor[p] % mod;
		for (int i = 0; i <= n; ++i)
			for (int j = 0; j <= m; ++j)
				for (int k = 0; k <= n - i; ++k)
					up(dp[now][i + k][j], dp[lst][i][j], trans[k][j]);
		now ^= 1, lst ^= 1, std::memset(dp[now], 0, sizeof dp[0]);
		for (int p = 0; p <= m; ++p)
			for (int q = 0; q <= n; ++q)
				trans[p][q] = (LL) w[t][p * (n - q)] * w[k - t + 1][p * q] % mod * ifactor[p] % mod;
		for (int i = 0; i <= n; ++i)
			for (int j = 0; j <= m; ++j)
				for (int k = 0; k <= m - j; ++k)
					up(dp[now][i][j + k], dp[lst][i][j], trans[k][i]);
	}
	std::cout << (LL) dp[0][n][m] * factor[n] % mod * factor[m] % mod << std::endl;
	return 0;
}

Measured memory_bytes: 4736