akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define  fill(st,et,val,arr) for(int i=st;i<=et;i++)arr[i]=val;
#define all(v) v.begin(),v.end()
template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}
 
const int M=1e9 + 7;
const int MAX=1e5+7;
using namespace std;
bool comp(pair<int,int> &a,pair<int,int> &b)
{
	if(a.first!=b.first)
	   return a.first<b.first;
	else
		return a.second>b.second;
}
void printQ(deque<int> q)
{
	for(int i=0;i<q.size();i++)
	{
		cout<<q[i]<<" ";
	}
	cout<<endl;
}
vector<int> g[MAX];
bool visited[MAX];
map<pair<int,int>,int> mp;
int ans1()
{
	fill(0,MAX-1,false,visited);
	visited[1]=true;
	queue<pair<int,int>> q;
	int c=1;
	q.push({1,0});
	int ans=0;
	while(!q.empty())
    {
        int currentVertex=(q.front()).first;
        int pc=(q.front()).second;
        q.pop();
        //cout<<currentVertex<<" ";
        c=1;
        for(int i=0;i<g[currentVertex].size();i++)
        {
             
            int nb=g[currentVertex][i];
            if(!visited[nb])
            {
                visited[nb]=true;
                if(c==pc)
                {   
                    c++;
                	q.push({nb,c});
                	mp[{currentVertex,nb}]=c;
                	c++;
				}else{
					q.push({nb,c});
					mp[{currentVertex,nb}]=c;
					c++;
				}
				//cout<<nb<<" ";
            }
        }
        int ans=max(ans,c);
    }
    return ans;
}
int32_t main() 
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	pair<int,int> ed[n-1];
	for(int i=0;i<n-1;i++)
	{
		int a,b;cin>>a>>b;
		ed[i]={a,b};
		g[a].pb(b);
		g[b].pb(a);
	}
	ans1();
	int ans=0;
	
	for(int i=0;i<n-1;i++)
	{
		ans=max(ans,mp[ed[i]]);
	}
	cout<<ans<<endl;
	for(int i=0;i<n-1;i++)
	{
		cout<<(mp[ed[i]])<<endl;
	}
	return 0;
}














Measured memory_bytes: 14464
#include <bits/stdc++.h>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
using namespace std;
 
const int mod = 1e9 + 7;
int n, m, p[200010],id[200010],ans;
vector <int> son[200010],f[200010],g[200010],s,tim;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int qpow(int a, int b)
{
	int x = a;  
	a = 1;
	while (b)
	{
		if (b & 1) a = 1LL * a * x % mod;
		x = 1LL * x * x % mod, b >>= 1;
	}
	return a;
}
 
void dfs(int x)
{
	int hs = -1, ID;
	for (auto y : son[x])
	{
		dfs(y);
		if ((hs < 0) || (f[id[y]].size() > f[id[hs]].size())) hs = y;
	}
	if (hs < 0)
	{
		id[x] = ++ m;
		f[m].push_back(1);
		g[m].push_back(1);
		return;
	}
	ID = id[x] = id[hs];
	for (auto y : son[x])
		if (y != hs)
		{
			int d = f[ID].size() - f[id[y]].size();
			for (int i = 0; i < (int)f[id[y]].size(); i ++)
			{
				if (tim[i + d] != x) s[i + d] = (qpow(2, g[ID][i + d]) + mod - f[ID][i + d]) % mod, tim[i + d] = x;
				f[ID][i + d] = 1LL * f[ID][i + d] * (qpow(2, g[id[y]][i]) + mod - f[id[y]][i]) % mod;
				f[ID][i + d] = (f[ID][i + d] + 1LL * s[i + d] * f[id[y]][i]) % mod;
				g[ID][i + d] += g[id[y]][i];
				s[i + d] = 1LL * s[i + d] * (qpow(2, g[id[y]][i]) + mod - f[id[y]][i]) % mod;
			}
		}
	f[id[x]].push_back(1);
	g[id[x]].push_back(1);
}
 
 
int main()
{
	scanf("%d", &n);
	s.resize(n + 1);
	tim.resize(n + 1, -1);
	rep(i, 1, n)
		p[i] = read(),
		son[p[i]].push_back(i);
	dfs(0);
	for (int i = 0; i < f[id[0]].size(); i ++)
		ans = (ans + 1LL * f[id[0]][i] * qpow(2, n + 1 - g[id[0]][i])) % mod;
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 53616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=332748118;
const int M=5e5+10;
#define inf 0x3f3f3f3f
//std::ios::sync_with_stdio(0);
int main()
{
    std::ios::sync_with_stdio(0);
     string s;
     cin>>s;
     int cnt=0;
     for(int i=0;i<s.size();i++)
     {
         cnt+=s[i]-'0';
     }
     if(cnt%9==0)
         cout<<"Yes"<<endl;
     else
        cout<<"No"<<endl;



}



Measured memory_bytes: 3780
#順列全探索の問題
#街の訪れ方はN!通りある
n=int(input())
from itertools import permutations
per=[i for i in range(n)]
per=list(permutations(per,n))

#まず累乗の関数
fac=[[0] for i in range(10)]
fac[0]=1
fac[1]=1
for i in range(2,10):
  fac[i]=i*fac[i-1]

#距離の関数
import math
def diff(a,b):
  return math.sqrt((a[0]-b[0])**2+(a[1]-b[1])**2)

#順列全探索
xy=[]
for i in range(n):
  x,y=list(map(int,input().split()))
  xy.append([x,y])

ans=0
for i in per:
  for j in range(1,n):
    ans=ans+diff(xy[i[j]],xy[i[j-1]])


print(ans/fac[n])

    

  

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

int main() {
  int n;
  cin >> n;
  vector<int> w(n);
  rep(i, n) cin >> w.at(i);
  int s = 0;
  rep(i, n) s += w.at(i);
  int num = 0;
  int q = 0;
  int mini = s;
  rep(i, n) {
    q += w.at(i);
    mini = min(mini, abs(q - (s - q)));
  }
  cout << mini << endl;
}


Measured memory_bytes: 256
import java.util.*;

import javax.print.attribute.HashAttributeSet;

import java.io.*;

public class Main {

	private static void solve(){
		//Implement solution here.
		int n = ni();
		String[] sa = new String[n];
		for(int i = 0; i < n; i++) sa[i] = next();
		int maxcnt = 0;
		Map<String,Integer> map = new HashMap<>();
		Set<String> set = new HashSet<String>();
		
		for(String s : sa) {
			if(map.containsKey(s)) {
				map.put(s, map.get(s) + 1);
			} else {
				map.put(s, 1);
			}
			
			if(map.get(s) > maxcnt) {
				maxcnt = map.get(s);
				set.clear();
				set.add(s);
			} else if(map.get(s) == maxcnt) {
				set.add(s);				
			}
		}
		Object[] result = set.toArray();
		Arrays.sort(result);
		for(Object s:result) {
			System.out.println((String)s);
		}
			
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 84912
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

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

    string s;
    cin >> s;
    ll sum = 0;
    for(auto c : s)
        sum += c - '0';

    cout << (sum % 9 ? "No\n" : "Yes\n");

    return 0;
}

Measured memory_bytes: 3768
n = int(input())
h = [int(i) for i in input().split()]

dp = [0] * n

dp[1] = abs(h[1]-h[0])

for i in range(2, n):
  dp[i] = min(dp[i-2]+abs(h[i-2]-h[i]), dp[i-1]+abs(h[i-1]-h[i]))

print(dp[n-1])

Measured memory_bytes: 13928
#include <iostream>
#include <utility>
#include <cmath>
using namespace std;

int N, i, j, a;
bool flag = false;

int main(void) {
    cin >> N;
    for (i=1; i<=N; i++) {
        cin >> a;
        if (a % 2 == 1) {
            flag = true;
            break;
        }
    }
    if (flag == true) {
         cout << "first" << endl;
    } else {
        cout << "second" << endl;
    }
    return 0;
}


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

int main() {
    int N, a, pnt = 0, ans = 0;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> a;
        if (a == pnt + 1) {
            ++pnt;
        }
        else {
            ++ans;
        }
    }
    if (pnt) cout << ans << endl;
    else cout << -1 << endl;
    
    return 0;
}

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

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

typedef long long ll;
typedef unsigned long long ull;

const int INF = 999999999;

int main(){
   string s,s2,s3;
   cin >> s>>s2>>s3;
   cout << s[0]<<s2[1]<<s3[2];
   return 0;
}

Measured memory_bytes: 256
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------
def f(n):
    if n%2==0:
        x = n//2
        if x%2==0:
            res = n
        else:
            res = n^1
    else:
        res = f(n-1)^n
    return res


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
A,B = map(int,input().split())

print(f(B)^f(A-1))

Measured memory_bytes: 3060
S=input()
ans=[0]*2#YYMM,MMYY
if 0<int(S[:2])<13:#MMYY
    ans[1]=1
if 0<int(S[2:])<13:#YYMM
    ans[0]=1
if  ans==[1,1]:
    print('AMBIGUOUS')
elif ans==[0,0]:
    print('NA')
elif ans==[1,0]:
    print('YYMM')
else:
    print('MMYY')

Measured memory_bytes: 3064
#include<iostream>
#define int long
using namespace std;
int n,a[1<<17];
main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	int l=2,r=2;
	for(int i=n-1;i>=0;i--)
	{
		if((l+a[i]-1)/a[i]*a[i]>r)
		{
			cout<<-1<<endl;
			return 0;
		}
		l=(l+a[i]-1)/a[i]*a[i];
		r=r/a[i]*a[i]+a[i]-1;
	}
	cout<<l<<" "<<r<<endl;
}

Measured memory_bytes: 1024
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

int re[333][333];

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	int h,w,t;
	cin>>h>>w>>t;
	vector<string> mp(h);
	rep(i,h) cin>>mp[i];
	int cnt=1;
	int prv=-1;
	int rem;
	rep(i,h)if(rem=count(all(mp[i]),'#')){
		rep(j,w){
			reps(k,prv,i) re[k+1][j]=cnt;
			if(mp[i][j]=='#' && --rem) ++cnt;
		}
		++cnt;
		prv=i;
	}
	reps(k,prv,h-1)rep(j,w) re[k+1][j]=re[prv][j];
	rep(i,h){ rep(j,w) cout<<re[i][j]<<" \n"[j+1==w];}
  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, L;
  cin >> N >> L;
  vector<string>S(N);
  for(int i=0; i<N; i++){
    cin >> S.at(i);
  }
  sort(S.begin(),S.end());
  for(int i=0; i<N; i++){
    cout << S.at(i);
  }
  cout << endl;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/

#include <bits/stdc++.h>
#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++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

bool ch(int y, int m, int d)
{
  if (y == 2019)
  {
    if (m < 4)
      return true;
    else if (m == 4)
      return d < 31;
    else
      return false;
  }
  else
    return y < 2019;
}
int main()
{
  string s;
  cin >> s;

  int y = stoi(s.substr(0, 4)),
      m = stoi(s.substr(5, 2)),
      d = stoi(s.substr(8, 2));

  string r = ch(y, m, d) ? "Heisei" : "TBD";

  cout << r << '\n';

  return 0;
}


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

int main() {
  int n; cin >> n;
  float sum_of_inverse = 0;
  for (int i = 0; i < n; i++) {
    int a; cin >> a;
    sum_of_inverse += 1. / a;
  }
  float ans = 1. / sum_of_inverse;
  cout << scientific << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	long long n, i, j, k, s, ss, d;
	cin >> n;
	vector<long long> a(n);
	s = 0;
	for (i = 0; i < n; i++) {
		cin >> a[i];
		s += a[i];
	}
	ss = n * (n + 1) / 2;

	bool valid = true;
	if (s % ss != 0) valid = false;
	else {
		k = s / ss;
		for (i = 0; i < n; i++) {
			d = a[(i + 1) % n] - a[i];
			if ((k - d < 0) || ((k - d) % n != 0)) valid = false;
		}
	}

	if (valid) cout << "YES\n";
	else cout << "NO\n";

	return 0;
}



Measured memory_bytes: 1656
import sys,math,collections,itertools
input = sys.stdin.readline

H,W=list(map(int,input().split()))
s = [ input().rstrip() for _ in range(H)]
dp = [[0]*W for _ in range(H)]

def isOK(start):
    q =  collections.deque([start])
    dp[start[0]][start[1]] = 1
    black,white=0,0
    while q:
        nowh,noww = q.popleft()
        if s[nowh][noww] == '.':
            target_mark = '#'
            white +=1
        else:
            target_mark = '.'
            black +=1
        if nowh >0 and s[nowh-1][noww] == target_mark and dp[nowh-1][noww]==0:
            q.append((nowh-1,noww))
            dp[nowh-1][noww]=1
        if nowh <H-1 and s[nowh+1][noww] == target_mark and dp[nowh+1][noww]==0:
            q.append((nowh+1,noww))
            dp[nowh+1][noww]=1
        if noww > 0 and s[nowh][noww-1] == target_mark and dp[nowh][noww-1]==0:
            q.append((nowh,noww-1))
            dp[nowh][noww-1]=1
        if noww < W-1 and s[nowh][noww+1] == target_mark and dp[nowh][noww+1]==0:
            q.append((nowh,noww+1))
            dp[nowh][noww+1]=1
            
    return black*white

cnt = 0

start_candi = []
end_candi = []
for ih in range(H):
    for iw in range(W):
        if s[ih][iw] == '#':
            start_candi.append((ih,iw))
        else:
            end_candi.append((ih,iw))

for ih in range(H):
    for iw in range(W):
        if dp[ih][iw] == 0:
            start = (ih,iw)
            cnt += isOK(start)
        else:
            continue

print(cnt)


Measured memory_bytes: 24196
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sort(a) sort(all(a))
using P = pair<int, int>;
using ll = long long;
using ld = long double;
int dx[4] = { 0, 1, 0,-1 };
int dy[4] = { 1, 0,-1, 0 };

signed main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans = 1;
  for (int i = 0; i < N-1; i++) {
    if (S[i]!=S[i+1]) ans++;
  }
  cout << ans << endl;
}

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

long long dp[100100][2][110];

int main()
{
    long long MOD = 1000000007;
    string K;
    int D;
    cin >> K >> D;
    int n = K.length();

    dp[0][0][0] = 1;
    for(int i=0 ; i<n ; i++)
    {
        int a = (int)K[i] - 48;
        for (int j=0 ; j<D ; j++)
        {
            for (int d=0 ; d<10 ; d++)
            {
                dp[i+1][1][(j+d)%D] += dp[i][1][j];
                dp[i+1][1][(j+d)%D] %= MOD;
            }
            for (int d=0 ; d<a ; d++)
            {
                dp[i+1][1][(j+d)%D] += dp[i][0][j];
                dp[i+1][1][(j+d)%D] %= MOD;
            }
            dp[i+1][0][(j+a)%D] += dp[i][0][j];
            dp[i+1][0][(j+a)%D] %=MOD;
        }
    }
    cout << (dp[n][1][0] + dp[n][0][0] - 1 + MOD) % MOD;
    return 0;
}

Measured memory_bytes: 18816
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

constexpr lli inf = 10000 * 10000;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
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;
}

int main(void) {

	string s;
	cin >> s;

	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}



	return 0;
}


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

int main() {
	u64 N;
	cin >> N;
	
	u64 ans = 0;
	for(u64 i=1; i<=N; i++) {
		if(i % 5 != 0 && i % 3 != 0) ans += i;
	}
	
	cout << ans;
	return 0;
}


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

int main() {

    int N,li,ri,sn;
    cin >> N;

    sn = 0;

    for(int i = 0; i < N; i++){
        cin >> li >> ri;
        sn += ri - li + 1;
    }

    cout << sn;
}

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

int main(){
  int N,M,K,l,ans[200001];
  long a[200001],b[200001];
  cin >> N >> M >> K;
  a[0]=0;
  b[0]=0;
  for(int i = 1; i < N+1; i++){
    cin >> l;
    a[i] = a[i-1]+l;
  }
  for(int i = 1; i < M+1; i++){
    cin >> l;
    b[i] = b[i-1]+l;
  }
  for(int i = 0; a[i] <= K; i++){
    for(int j = M; b[j] > K-a[i]; j--){
      M = j-1;
    }
    ans[i] = i + M;
  }
  l = 0;
  for(int i = 0; i < N+1; i++){
    if(ans[i]>=l){
      l = ans[i];
    }
  }
  cout << l <<endl;
}

Measured memory_bytes: 7476
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ld long double
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A[100001];
vll sumAs;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> N;
    ll sumA=0;
    rep(ni,N){
        cin>>ltmp;
        A[ltmp]++;
        sumA+=ltmp;
    }
    cin >> M;

    rep(qi,M){
        cin >> B;
        cin >> C;

        sumA = sumA + ( C - B ) * A[B];
        A[C] += A[B];
        A[B]=0;
        sumAs.push_back(sumA);
    }

    rep(qi,M) cout << sumAs[qi] << endl;

    

}

Measured memory_bytes: 5048
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using uInt = long long unsigned int;
using Double = long double;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
//        Int R;
//        cin >> R;
//
//        double ans = 6.28318530717958623200 * R;
//        cout << ans << endl;

//        Int N, M;
//        cin >> N >> M;
//        rep(i, 0, M) {
//            Int tmp;
//            cin >> tmp;
//            N -= tmp;
//        }
//        if (N < 0) cout << -1 << endl;
//        else cout << N << endl;


        Int N;
        cin >> N;
        vector<Int> buka(N + 1);
        rep(i, 1, N) {
            int tmp;
            cin >> tmp;
            buka[tmp]++;
        }

        rep(i, 1, N + 1) {
            cout << buka[i] << endl;
        }
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    Solve().solve();


    return 0;
}


Measured memory_bytes: 4356
//Analyzing Login/Logout Records
#include<bits/stdc++.h>
using namespace std;

int pc[1000][721], st[10000][721];

int main(){
  int N, M;
  while(cin>>N>>M, !(N==0&&M==0)){
    int r;
    memset(pc, 0, sizeof(pc)); memset(st, 0, sizeof(st));
    cin>>r;
    while(r--){
      int t, n, m, s;
      cin>>t>>n>>m>>s;
      pc[n-1][t-540]=m;
      if(s==0){
	st[m-1][t-540]=1;
	t--;
	while(true){
	  st[m-1][t-540]=1;
	  if(pc[n-1][t-540]==m || t-540==0)break;
	  t--;
	}
      }
    }
    int q;
    cin>>q;
    while(q--){
      int ts, te, m;
      cin>>ts>>te>>m;
      int cnt=0;
      bool flag=false;
      for(int i=ts-540; i<=te-540; i++){
	if(st[m-1][i]==1 && flag)
	  cnt++;
	if(st[m-1][i]==1)flag=true;
	else flag=false;
      }
      cout<<cnt<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 32148
#include<iostream>
using namespace std;
int main(){
	int t,n;
	for(int i=0;i<4;i++){
		cin >> t >> n;
		if(t == 1) t = 6000;
		if(t == 2) t = 4000;
		if(t == 3) t = 3000;
		if(t == 4) t = 2000;
       		cout << t*n << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    bool easy = true;
    rep(i, S.size()){
        if(i % 2 == 0){
            if(S[i] == 'L'){
                easy = false;
            }
        }else{
            if(S[i] == 'R'){
                easy = false;
            }
        }
    }

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

    return 0;
}

Measured memory_bytes: 3620
#include<algorithm>
#include<cstdio>
#include<set>
#include<vector>

using namespace std;

struct gra {
    int x, y;
    vector<int> to;
    bool judge = false;
};

struct ord {
    int ind, x, y;
};

const int N_MAX = 1e5;
int n;
ord o[N_MAX];
gra g[N_MAX];

void dfs(int m, set<int> &sx, set<int> &sy) {
    sx.emplace(g[m].x);
    sy.emplace(g[m].y);
    g[m].judge = true;
    for (int e : g[m].to) {
        if (g[e].judge == false) dfs(e, sx, sy);
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        g[i].x = o[i].x = x; g[i].y = o[i].y = y;
        o[i].ind = i; 
    }
    
    sort(o, o + n, [](const ord &o1, const ord &o2)->bool {
        if (o1.x < o2.x) return true;
        if (o1.x == o2.x && o1.y < o2.y) return true;
        return false;
    });    
    for (int i = 0; i < n - 1; i++) {
        if (o[i].x == o[i + 1].x) {
            g[o[i].ind].to.push_back(o[i + 1].ind);
            g[o[i + 1].ind].to.push_back(o[i].ind);
        }
    }
    
    sort(o, o + n, [](const ord &o1, const ord &o2)->bool {
        if (o1.y < o2.y) return true;
        if (o1.y == o2.y && o1.x < o2.x) return true;
        return false;
    });    
    for (int i = 0; i < n - 1; i++) {
        if (o[i].y == o[i + 1].y) {
            g[o[i].ind].to.push_back(o[i + 1].ind);
            g[o[i + 1].ind].to.push_back(o[i].ind);
        }
    }
    
    long sum = 0;
    for (int i = 0; i < n; i++) {
        set<int> s1, s2;
        if (g[i].judge == false) dfs(i, s1, s2);
        sum += static_cast<long>(s1.size()) * s2.size();
    }

    printf("%ld\n", sum - n);
    return 0;
}
     


Measured memory_bytes: 17792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) for(int i = 0; i < (a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
const int maxn = 305;

double dp[maxn][maxn][maxn];
int a[3];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	rep(i, n){
		int x;
		cin >> x;
		a[x - 1]++;
	}
	rep(k, n + 1) rep(j, n + 1) rep(i, n + 1){
		int tc = i + j + k;
		if(!tc || tc > n) continue;
		dp[i][j][k] = 1;
		if(i) dp[i][j][k] += dp[i - 1][j][k] * i / n;
		if(j) dp[i][j][k] += dp[i + 1][j - 1][k] * j / n;
		if(k) dp[i][j][k] += dp[i][j + 1][k - 1] * k / n;
		dp[i][j][k] *= (double) n / tc;
	}	
	cout << setprecision(15) << dp[a[0]][a[1]][a[2]] << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 219392
#include<stdio.h>

long long max(long long x,long long y){if(x>y){return x;}return y;}

int main(void){
	long long res=0,n,l,w[128],v[128],i,j,k,dp[128][512]={0};//dp[choose][diff]
	scanf("%lld%lld",&n,&l);
	for(i = 1;i <= n;i++){scanf("%lld%lld",&w[i],&v[i]);}
	for(i = 1;i <= n;i++){
		for(j = (i-1);j >= 0;j--){
			for(k = j*3;k >= 0;k--){
				dp[j+1][k+(w[i]-w[1])] = max(dp[j+1][k+(w[i]-w[1])],dp[j][k]+v[i]);
			}
		}
	}
	for(i = 0;i <= n;i++){
		for(j = 0;j <= 3*i;j++){
			if(w[1]*i+j <= l){res = max(res,dp[i][j]);}
		}
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
#define INF (1<<20)
int n,m;
int wa[21][21];
main(){
  cin >> n;
  cin >> m;
  for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) wa[i][j]=INF;
  for(int i=0;i<m;i++){
    int a,b,c,d;
    scanf("%d,%d,%d,%d",&a,&b,&c,&d);
    wa[a][b]=c;
    wa[b][a]=d;
  }
  for(int k=1;k<=n;k++){
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++)
	wa[i][j] = min(wa[i][j],wa[i][k]+wa[k][j]);
    }
  }
  int x1,x2,y1,y2;
  scanf("%d,%d,%d,%d",&x1,&x2,&y1,&y2);
  int res = y1 - (wa[x1][x2] + wa[x2][x1] + y2 );
  cout << res << endl;
}

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

int main(void){
  int N;
  cin>>N;
  vector<char>S(N);
  for(int i=0;i<N;i++){
    cin>>S[i];
  }
  int count=0;
  for(int i=2;i<N;i++){
    if(S[i-2]=='A'&&S[i-1]=='B'&&S[i]=='C') count++;
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    L = readline().strip()

    eq, less = 2, 1
    for d in L[1:]:
        if d == '1':
            less = (eq + 3 * less) % MOD
            eq = 2 * eq % MOD
        else:
            less = 3 * less % MOD

    print((eq + less) % MOD)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9180
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


// 2つの閉区間が交わりを持つかどうか
bool isCross(ll low1, ll up1, ll low2, ll up2) {
	if (low1 <= low2) {
		if (low2 <= up1) return true;
		else return false;
	}
	else { // low2 < low1
		if (low1 <= up2) return true;
		else return false;
	}
}


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

	ll N;
	ll A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	bool flag = false;
	N--;

	// i回引いて、N-i回足した時に実現できる値の範囲は
	// A + C*(N-i) - D*i ～ A + D*(N-i) - C*i
	for (int i = 0; i <= N && !flag; i++) {
		ll low = A + C * (N - i) - D * i;
		ll up = A + D * (N - i) - C * i;
		if (low <= B && B <= up) flag = true;
		// if (flag) cout << i << " ";
	}

	if (flag) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

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();
		int d = sc.nextInt();
		int[] p = new int[n];
		for(int i=0;i<n;i++) {
			p[i] = sc.nextInt();
		}
		int score = 0;
		for(int i=0;i<n;i++) {
			int s = p[i] - d;
			if (s > 0) {
				score+=s;
			}
		}
		if (score <= 0) {
			System.out.println("kusoge");
		}else{
			System.out.println(score);
		}
	}

}

Measured memory_bytes: 29812
S = input()
N = len(S)
l, r = 0, N - 1
num = 0
while l <= r:
    if S[l] == S[r]:
        l += 1
        r -= 1
    else:
        if S[l] == 'x':
            l += 1
            num += 1
        elif S[r] == 'x':
            r -= 1
            num += 1
        else:
            print(-1)
            exit()

print(num)



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

using namespace std;

typedef long long ll;

const int N = 1e5 + 5;
ll dp[103][N];
ll w[N], v[N];

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

	for(int i = 1; i <= n; i++)
		cin >> w[i] >> v[i];

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= W; j++){
			if(w[i] > j) 
				dp[i][j] = dp[i - 1][j];
			else
				dp[i][j] = max(dp[i - 1][j], v[i] + dp[i - 1][j - w[i]]);
		}
	}

	cout << dp[n][W] << endl;
}

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

int main(){
  
  int N, X;
  cin >> N >> X;
  
  vector<int> m(N);
  for(int i = 0; i < N; i++){
    cin >> m.at(i);
  }
  
  int s = 0;
  
  for(int i = 0; i < N; i++){
    s += m.at(i);
  }
  
  int count = N - 1;
  sort(m.begin(),m.end());
  while(X - s >= 0){
    count++;
    s += m.at(0);
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys

# import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = readline().decode('utf8').rstrip().split()

print('YES' if S.count('5') == 2 and S.count('7') == 1 else 'NO')


Measured memory_bytes: 2940
s=input()
n=len(s)-1
if n==0:
  print(s)
else:
  l=[]
  a=len(bin(1<<n))-3
  for i in range(1<<n):
    l.append(str(bin(i))[2:].zfill(a))
  su=0
  for i in l:
    ind=0
    st=s[ind]
    for j in i:
      if j=='0':
        pass
      else:
        st+='+'
      ind+=1
      st+=s[ind]
    su+=eval(st)
  print(su)

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

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

using namespace std;

using ll = long long;
using P = pair<int , int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int k, n; cin >> k >> n;
  int a[n + 1];

  rep(i, n)
    cin >> a[i];

  a[n] = k+a[0];
  int dist = 0;
  rep(i, n) {
    dist = max(dist, abs(a[i+1]-a[i]));
  }
  cout << k - dist;
}
  


Measured memory_bytes: 1024
import sys

N,M = map(int, input().split())

dp = [-1]*(N+1)
dp[0] = 1
dp[1] = 1
for i in range(M):
    num = int(input())
    dp[num] = 0

for i in range(2, N+1):
    if dp[i] == 0:
        continue
    dp[i] = dp[i-1]%1000000007 + dp[i-2]%1000000007

print(dp[N]%1000000007)

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

using namespace std;

int f(int n)
{
    int sum=0;
    for(int i=1;i<=n+1;i++)
        sum=sum+i;
    return sum;
}
int main()
{
    int a,b,s[1000],m[1000],c,r;
    while(scanf("%d %d",&a,&b)!=EOF)
    {
        c=b-a;
        s[0]=1;
        m[0]=0;
        for(int i=1;i<999;i++)
        {
            s[i]=f(i);
            m[i]=s[i]-s[i-1];
        }
        for(int i=0;i<999;i++)
        {
            if(m[i]==c)
            {
                r=s[i]-b;
            }
        }
        printf("%d\n",r);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
using namespace std;


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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

	multiset<char> S;
	string w;
	cin >> w;

	for(int i = 0; i < w.size(); i++){
		S.insert(w[i]);
	}

	int cnt = S.count(w[0]);

	bool can = 1;
	for(auto x : S){
		can &= ((S.count(x) & 1) == 0);
	}
	

	cout << (can ? "Yes" : "No") << endl;


	return 0;
}


Measured memory_bytes: 3660
import java.util.*;

public class Main {
    static Scanner scanner;

    public static void main(String[] args) {
        scanner = new Scanner(System.in);
        int ac = 0;
        int wa = 0;
        int tle = 0;
        int re = 0;
        int n = nextInt();
        for (int i = 0; i < n; i++) {
            String next = scanner.next();
            switch (next) {
                case "AC":
                    ac++;
                    break;
                case "WA":
                    wa++;
                    break;
                case "TLE":
                    tle++;
                    break;
                case "RE":
                    re++;
                    break;
            }
        }
        System.out.println(String.format("AC x %d",ac));
        System.out.println(String.format("WA x %d",wa));
        System.out.println(String.format("TLE x %d",tle));
        System.out.println(String.format("RE x %d",re));
    }

    public static void println(Object o) {
        System.out.println(o);
    }

    public static void print(Object o) {
        System.out.print(o);
    }

    public static void printf(String format, Object... o) {
        System.out.printf(format, o);
    }

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

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

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

    public static short nextShort() {
        return Short.parseShort(scanner.next());
    }

    public static float nextFloat() {
        return Float.parseFloat(scanner.next());
    }

    public static void printYes() {
        System.out.println("Yes");
    }

    public static void printYES() {
        System.out.println("YES");
    }

    public static void printNo() {
        System.out.println("No");
    }

    public static void printNO() {
        System.out.println("NO");
    }

    public static String nextLine() {
        return scanner.nextLine();
    }

    public static double distance(double x, double y, double x2, double y2) {
        return Math.sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y));
    }

    public static int MOD = 1_000_000_007;
    public static int MAX = 100000;
    public static long[] fac = new long[MAX];
    public static long[] finv = new long[MAX];
    public static long[] inv = new long[MAX];

    public static void combinit() {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    public static long combination(int n, int k) {
        if (n < k || n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }

    public static long factorial(long n) {
        return n <= 0 ? 1 : n * factorial(n - 1);
    }
}

Measured memory_bytes: 52328
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	a := scanInts(n)

	c := map[int]int{}
	for i := 0; i < n; i++ {
		c[a[i]]++
		c[a[i]-1]++
		c[a[i]+1]++
	}
	ans := 0
	for _, e := range c {
		ans = max(ans, e)
	}
	fmt.Fprintln(wr, ans)
}


Measured memory_bytes: 8852
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

#define MAX_H 50
#define MAX_W 50

/*      差分        */
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {-1, 0, 1, 0};


int main(){
    /*  グラフ構築  */

    //.をカウントする
    int cnt = 0;


    //マップ最大値
    int H, W;   cin >> H >> W;

    //スタートとゴールの座標
    int sy = 0, sx = 0, gy = H, gx = W;

    //0indexで扱うためのデクリメント
    gy--;   gx--;

    /*  文字列一列ずつを格納する    */
    vector<string> c;

    //マップの情報の入力
    for(int i = 0; i < H; i++){
        string s;   cin >> s;
        c.push_back(s);
    }

    for(int j = 0; j < H; j++){
        for(int i = 0; i < W; i++){
            if(c[j][i] == '.'){
                cnt++;
            }
        }
    }

    //マップ上の座標へのスタート地点からの最短距離を保持する
    //-1で埋める
    vector<vector<int>> dist(MAX_H, vector<int>(MAX_W, -1));

    dist[sy][sx] = 0;           //スタート地点の初期化

    //座標をペアにしてキューに突っ込む
    queue<pair<int, int>> q;
    q.push({sy, sx});


    /*      幅優先探索      */
    while(!q.empty()){
        
        //キューの最前の要素を取り出す
        pair<int, int> p = q.front();
        q.pop();

        //取り出した値を受け取る
        int y = p.first, x = p.second;


        /*      遷移        */
        for(int i = 0; i < 4; i++){
            int ny = y + dy[i];
            int nx = x + dx[i];

            //移動可能か、未探索かどうかをチェックし、遷移する
            if(ny >= 0 && ny < H && nx >= 0 && nx < W
                && dist[ny][nx] == -1 && c[ny][nx] == '.'){

                    dist[ny][nx] = dist[y][x] + 1;

                    //移動後の座標をキューに追加する
                    q.push({ny, nx});
            }
        }
    }
    
    // 出力
    if(dist[gy][gx] == -1){
        cout << -1 << endl;
    }
    else{
        cout << cnt - (dist[gy][gx] + 1)  << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
//  ©   ___MRX___

#include <bits/stdc++.h>
    using namespace std;

#define ll long long int

int main()
{
    int a, b, k, i;
    cin >> a >> b >> k;

    vector<int> vec;

    for(i = min(a, b); i > 0; i--) {
        if(a % i == 0 && b % i == 0) {
            vec.push_back(i);
        }
    }

    cout << vec[k - 1] << '\n';

    return 0;
}


Measured memory_bytes: 3560
from collections import defaultdict

class permnk_mod(object):
    # pが素数かつaとpが互いに素であるとき
    # フェルマーの小定理より以下が成り立つ.
    # 1 / a = a ** (p - 2) (mod p)
    # これを使って (1 / k!) mod p を計算する.
    def __init__(self, maxn, p):
        self.maxn = maxn
        self.p = p
        self.x = [1] # 分母にあたる数 1 / n! mod p
        self.y = [1] # 分子にあたる数. n! mod p
        for i in range(1, self.maxn + 1):
            self.x.append(self.x[-1] * pow(i, self.p - 2, self.p) % self.p)
            self.y.append(self.y[-1] * i % self.p)

    def permnk(self, n, k):
        if n < k:
            return 0
        return (self.x[n - k] * self.y[n]) % self.p

def dfs(i, V, E, k):
    MOD = 10 ** 9 + 7
    p = permnk_mod(k - 1, MOD)
    ans = k
    V[i] = 1
    S = [i]
    while(len(S) > 0):
        vi = S.pop()
        for j in E[vi]:
            if V[j] == 0:
                V[j] = 1
                S.append(j)
        if vi == i:
            ans *= p.permnk(k - 1, len(E[vi]))
        elif len(E[vi]) > 1:
            ans *= p.permnk(k - 2, len(E[vi]) - 1)
        ans %= MOD
    return ans

n, k = map(int, input().split())
E = defaultdict(list)
for i in range(n - 1):
    a, b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)
V = [0] * (n + 1)
ans = dfs(1, V, E, k)
print(ans)


Measured memory_bytes: 37544
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		int g,r;

		Scanner scan = new Scanner(System.in);

		while(true)
		{
			g = scan.nextInt();
			r = scan.nextInt();

			if( (g|r) == 0) break;

			for(int i=0; i<g; i++)
			{
				for(int j=0; j<r; j++)
				{
					if(i==0 || i==(g-1) )//Line0 or LastLine
					{
						System.out.print("#");
					}
					else
					{
						if(j==0 || j==(r-1) ) System.out.print("#");
						else System.out.print(".");
					}
				}

				System.out.println();
			}

			System.out.println();

		}

		scan.close();

	}
}

Measured memory_bytes: 32308
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        ArrayList<Integer> nums = new ArrayList<Integer>();
        nums.add(1);
        for (int i = 2;i <= 31;++i){
            int k = i * i;
            while (k <= 1000){
                nums.add(k);
                k *= i;
            }
        }
        int max = 1;
        for (int i = 0;i < nums.size();++i){
            int o = nums.get(i);
            if(o <= x&&o > max){
                max = o;
            }
        }
        System.out.println(max);





    }

}

Measured memory_bytes: 22868
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
using namespace std;

class dice{
public:
	int a[6];
	int b;
	void moveN(){
		b = a[0];
		a[0] = a[1];
		a[1] = a[5];
		a[5] = a[4];
		a[4] = b;
	}
	void moveS(){
		b = a[0];
		a[0] = a[4];
		a[4] = a[5];
		a[5] = a[1];
		a[1] = b;
	}
	void moveE(){
		b = a[0];
		a[0] = a[3];
		a[3] = a[5];
		a[5] = a[2];
		a[2] = b;

	}
	void moveW(){
		b = a[0];
		a[0] = a[2];
		a[2] = a[5];
		a[5] = a[3];
		a[3] = b;
	}
};

int main(){
	dice c;
	int d, e, f;
	for (int i = 0; i < 6; i++){
		cin >> c.a[i];
	}

	cin >> d;
	for (int i = 0; i < d; i++){
		cin >> e >> f;

		if (c.a[2] == f){
			c.moveW();
		}
		if (c.a[3] == f){
			c.moveE();
		}
		while (1){
			c.moveN();
			if (c.a[1] == f)break;
		}
		while (1){
			c.moveE();
			if (c.a[0] == e)break;
		}


		cout << c.a[2] << endl;
	}

	return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int n;
int a[1030][1030];
int encode(int x,int y){
	if(x>y) swap(x,y);
	return (n*2LL-x)*(x-1LL)/2LL+(y-x);
}
int dp[1000100];
vector<int> ga[1000100];
int vis[1000100];
int path(int x){
	if(vis[x]==1){
		cout<<"-1"<<endl;
		exit(0);
	}
	if(dp[x]!=-1)
		return dp[x];
	dp[x]=0;
	vis[x]=1;
	for(int y:ga[x])
		dp[x]=max(dp[x],path(y));
	dp[x]++;
	vis[x]=2;
	return dp[x];
}
int main(){
	#ifdef FILIN
		#ifndef LOCAL
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n-1;j++){
			cin>>a[i][j];
		}
		for(int j=1;j<=n-2;j++){
			ga[encode(i,a[i][j])].push_back(encode(i,a[i][j+1]));
		}
	}
	int res=0;
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=n*(n-1)/2;i++){
		res=max(res,path(i));
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 51072
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d",&a,&b);
    c=a+b;
    if(a%3==0){
        printf("Possible");
    }
    else if(b%3==0){
        printf("Possible");
    }

    else if(c%3==0){
        printf("Possible");
    }
    else {
        printf("Impossible");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define rep1(i,n) for (int i=1; i<=(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;

void solve() {
  int n, t; cin >> n >> t;
  Graph G(n, vi(2));
  rep(i,n) rep(j,2) cin >> G[i][j];
  sort(all(G));

  Graph dp(n+1, vi(t+1, 0));
  rep(i,n) {
    dp[i+1] = dp[i];
    int a = G[i][0], b = G[i][1];
    if (a < t) dp[i+1][a] = max(dp[i+1][a], b);
    else dp[i+1][t] = max(dp[i+1][t], b);

    rep1(j,t-1) {
      if (dp[i][j] == 0) continue;

      if (j+a < t) dp[i+1][j+a] = max(dp[i+1][j+a], dp[i][j] + b);
      else dp[i+1][t] = max(dp[i+1][t], dp[i][j] + b);
    }
  }

  cout << *max_element(all(dp[n])) << endl;
  return;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  solve();
  return 0;
}


Measured memory_bytes: 35712