akhauriyash/Code-Regression huggingface dataset:
from bisect import bisect_right

n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

a_ac=[0]
for i in range(1,n+1):
  a_ac.append(a_ac[i-1]+a[i-1])

b_ac=[0]
for i in range(1,m+1):
  b_ac.append(b_ac[i-1]+b[i-1])

#print(a_ac)
#print(b_ac)

ans=0
for i in range(n+1):
  remain=k-a_ac[i]
  if remain<0:
    continue
  t_ans=i
  t_ans+=bisect_right(b_ac,remain)-1
  ans=max(ans,t_ans)

print(ans)

Measured memory_bytes: 132932
//133_c
#include <stdio.h>

typedef long long ll;
#define rep(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
ll min(ll a, ll b){if(a<b)return a;else return b;}

ll a[2020]={};

int main(void){
    ll L,R,ans=2018;
    scanf("%lld %lld",&L,&R);
    if(R-L>=2019){
        printf("0\n");
        return 0;
    }
    rep(i,L,R,1){
        rep(j,L+1,R+1,1){
            ans=min(ans,(i*j)%2019);
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1708
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

//???????????¢?´¢
//http://itpro.nikkeibp.co.jp/article/COLUMN/20120827/418468/?SS=imgview&FD=-700917643 ??????
public class Main {
	public static void main(String[] args) throws Exception{
		Queue<State> queue = new LinkedList<>();
		HashMap<Integer, Integer> map = new HashMap<>();
		int[][] firstNums = {{0,1,2,3}, {4,5,6,7}};
		State firstState = new State(firstNums, 0, 0, 0);
		map.put(firstState.hashCode(), 0);
		queue.add(firstState);

		while(!queue.isEmpty()){
			State nowState = queue.poll();
			for(State nextState : nowState.nextMove()){
				if(!map.containsKey(nextState.hashCode())){
					map.put(nextState.hashCode(), nextState.getDepth());
					queue.add(nextState);
				}
			}
		}

		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNextInt()){
				int[][] finalNums = new int[2][4];
				for(int y = 0; y < 2; y++){
					for(int x = 0; x < 4; x++){
						finalNums[y][x] = sc.nextInt();
					}
				}

				State finalState = new State(finalNums, -1, -1, -1);
				System.out.println(map.get(finalState.hashCode()));
			}
		}
	}

}

class State {

	//???????????????????????????
	private static final int[] vy = new int[]{0, 1, 0, -1};
	private static final int[] vx = new int[]{1, 0, -1, 0};

	private int[][] nums;
	private int zeroX;
	private int zeroY;
	private int hash;
	private int depth; //??¨?????±???

	public State(int[][] nums, int zeroY, int zeroX, int depth){
		this.nums = nums;
		this.zeroY = zeroY;
		this.zeroX = zeroX;
		this.depth = depth;
		this.hash = -1;
	}

	public int getDepth(){
		return depth;
	}

	public LinkedList<State> nextMove(){
		LinkedList<State> list = new LinkedList<>();
		//???????????????4??????
		for(int i = 0; i < 4; i++){
			int nextZeroY = zeroY + vy[i];
			int nextZeroX = zeroX + vx[i];
			if(nextZeroY < 0 || nextZeroY >= 2) continue;
			if(nextZeroX < 0 || nextZeroX >= 4) continue;
			int[][] nextNums = new int[2][4];
			for(int y = 0; y < 2; y++){
				for(int x = 0; x < 4; x++){
					nextNums[y][x] = nums[y][x];
				}
			}
			nextNums[nextZeroY][nextZeroX] = 0;
			nextNums[zeroY][zeroX] = nums[nextZeroY][nextZeroX];
			list.add(new State(nextNums, nextZeroY, nextZeroX, depth + 1));
		}

		return list;
	}

	@Override
	public int hashCode(){
		if(hash != -1) return hash;
		hash = 0;
		for(int y = 0; y < 2; y++){
			for(int x = 0; x < 4; x++){
				hash *= 10;
				hash += nums[y][x];
			}
		}
		return hash;
	}

}

Measured memory_bytes: 49700
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;

vector<bool> seen, done;
vector<int> hist;
int dst = -1;
void dfs(const Graph &g, int u) {
    seen[u] = true;
    hist.emplace_back(u);
    for (int v: g[u]) if (!done[v]) {
        if (seen[v]) {
            dst = v;
            return;
        }
        dfs(g, v);
        if (dst != -1) return;
    }
    hist.pop_back();
    done[u] = true;
}

int main() {
    int n, m; cin >> n >> m;
    Graph g(n);
    while (m--) {
        int a, b; cin >> a >> b; a--, b--;
        g[a].emplace_back(b);
    }
    seen.assign(n, false), done.assign(n, false);
    for (int v = 0; v < n; v++) {
        dst = -1;
        dfs(g, v);
        if (dst != -1) break;
    }
    if (dst == -1) return !(cout << -1 << endl);
    vector<int> cycle;
    while (!hist.empty()) {
        int t = hist.back(); hist.pop_back();
        cycle.push_back(t);
        if (t == dst) break;
    }
    reverse(cycle.begin(), cycle.end());
    while (true) {
        int from = -1, to = -1;
        vector<int> ord(n, -1);
        int len = cycle.size();
        for (int i = 0; i < len; i++) ord[cycle[i]] = i;
        for (int i = 0; i < len; i++) {
            for (int v: g[cycle[i]]) if (~ord[v]) {
                if (v != cycle[(i + 1) % len]) {
                    from = i, to = ord[v];
                }
            }
        }
        if (from == -1) break;
        vector<int> ncycle;
        ncycle.emplace_back(cycle[from]);
        int id = to;
        while (id != from) {
            ncycle.emplace_back(cycle[id]);
            id = (id + 1) % len;
        }
        cycle = ncycle;
    }
    cout << cycle.size() << endl;
    for (int v: cycle) cout << v + 1 << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e5+5;
int n,a[N];
char s[N];
int main()
{
    scanf("%s",s+1);
    int n=strlen(s+1);
    int tot=0,now=0;
    long long ans=0;
    for(int i=n;i>=1;i--)
    {
        if(s[i]=='>')
        {
            if(tot)
            {
                if(tot<=now) ans+=(ll)tot*(tot-1)/2;
                else ans+=(ll)tot*(tot+1)/2-now;
                now=0;
            }
            now++;
            ans+=now;
            tot=0;
        }
        else tot++;
    }
    if(tot)
    {
        if(tot<=now) ans+=(ll)tot*(tot-1)/2;
        else ans+=(ll)tot*(tot+1)/2-now;
    }
    printf("%lld\n",ans);
}


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

#define int long long
#define rep(i, a, n) for (int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort(ALL(c), greater<int>());
#define fi first
#define se second
int INF = 1e9 + 7;

typedef pair<int, int> P;
typedef vector<int> vi;

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

int n, k;
vi h;
int dp[100001] = {};

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

  cin >> n >> k;
  h.pb(0);
  rep(i, 0, n) {
    int H;
    cin >> H;
    h.pb(H);
  }

  dp[1] = 0;
  dp[2] = abs(h[2] - h[1]);
  rep(i, 3, n + 1) {
    rep(j, 1, k + 1) {
      if (i - j >= 1) {
        if (j == 1)
          dp[i] = dp[i - j] + abs(h[i] - h[i - j]);
        else
          dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 1908
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<bitset>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<map>

using namespace std;

int read()
{
	int ans=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return ans*f;
}
 
int main()
{
	printf("%d\n",read()*read());
	return 0;
} 


Measured memory_bytes: 3224
q=int(input())
s=set()
arr=[0]*(10**5+1)
for i in range(2,10**5+1):
  if arr[i]==0:
    s.add(i)
    for j in range(i,10**5+1,i):
      arr[j]+=1
cnt=[0]*(10**5+1)
for i in range(10**5+1):
  if i in s and (i+1)//2 in s:
    cnt[i]=1
for i in range(10**5):
  cnt[i+1]+=cnt[i]
for _ in range(q):
  l,r=map(int,input().split())
  print(cnt[r]-cnt[l-1])

Measured memory_bytes: 8020
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>
#define V vector<int>
#define itn int
#define tin int
#define tni int
bool dbg = false;
string S;
int s[100010];
int c[100010];
int a[2];  //even,odd
void solve()
{
    FOR(i, 0, (int)S.size())
    {
        s[i] = (S[i] == 'L');
    }
    int N = (int)S.size();
    bool flag = true;
    int t = -1;
    FOR(i, 0, N)
    {
        if (t == -1) {
            a[0] = 0;
            a[1] = 0;
            a[i % 2] = 1;
            t = -2;
            //dump(i);
            continue;
        }
        if (flag && i != N - 1) {
            if (s[i] == 0) {
                a[i % 2]++;
            } else {
                t = i - 1;
                a[i % 2]++;
                flag = false;
            }
        } else {
            if (s[i] == 1 && i != N - 1) {
                a[i % 2]++;
            } else {
                if (i == N - 1) {
                    a[i % 2]++;
                    if (t == -2) {
                        t = N - 2;
                    }
                }
                c[t] = a[t % 2];
                c[t + 1] = a[(t + 1) % 2];
                a[0] = 0;
                a[1] = 0;
                a[i % 2] = 1;
                t = -2;
                flag = true;
                if (s[i + 1] == 1) {
                    t = i;
                }
                // dump(i);
            }
        }
    }
    FOR(i, 0, N)
    {
        cout << c[i] << " ";
    }
    //dump(a[0]);
    // dump(a[1]);
    cout << endl;
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> S;
    solve();
    return 0;
}


Measured memory_bytes: 2256
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
#include <cmath>
using namespace std;
int main() {
    int ans = 0, min = INT_MAX, minIndex = 0;
    vector<int> A(5);
    for (int i = 0; i < 5; i++) {
        cin >> A[i];
        if (A[i] % 10 != 0 && A[i] % 10 < min) {
            min = A[i] % 10;
            minIndex = i;
        }
    }
    for (int i = 0; i < 5; i++) {
        if (i != minIndex) ans += (int)ceil(A[i] / 10.0) * 10;
        else ans += A[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
signed main() {
	ll n, a;
	cin >> n; double z; cin >> z; a = z * 100 + 0.5;
	cout << (ll)(n * a / 100) << endl;
	return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  string s;
  int a=1000;
  cin >> s;
  for(int i=0;i<=s.size()-3;i++){
    string t=s.substr(i,3);
    int n=abs(stoi(t)-753);
    a=min(a,n);
  }
  cout << a << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <climits>
using namespace std;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
static const int MAX=10000;

int n;
vector<pair<int,int> >A[MAX];

void dijkstra(){
  priority_queue<pair<int,int> > PQ; 
  int color[MAX],d[MAX],u;
  for(int i=0;i<n;i++){
    color[i]=WHITE;
    d[i]=INT_MAX;
  }
  d[0]=0;
  PQ.push(make_pair(0,0));
  color[0]=GRAY;

  while(!PQ.empty()){
    pair<int,int> f=PQ.top();
    PQ.pop();
    u=f.second;
    color[u]=BLACK;
    if(d[u]<f.first*(-1)) continue;

    for(int v=0;v<A[u].size();v++){
      int k=A[u][v].first;
      if(color[k]!=BLACK){
	if(d[u]+A[u][v].second<d[k]){
	  d[k]=d[u]+A[u][v].second;
	  color[k]=GRAY;
	  PQ.push(make_pair(d[k]*(-1),k));
	}
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<i<<" "<<(d[i]==INT_MAX ? -1:d[i])<<endl;
  }
}


int main(){
  int k,u,v,c;

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v>>c;
      A[u].push_back(make_pair(v,c));
    }
  }
  dijkstra();

  return 0;
}

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

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

	for(int i = 0; i < S.length() - 1; i++)
	{
		if(S.at(i) == S.at(i + 1))
		{
			cout << "Bad" << endl;
			return 0;
		}
	}

	cout << "Good" << endl;
	return 0;
}

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

#define INF 100100100
using namespace std;

int main(){
   int N;
   cin >> N;
   vector<string> W(N);
   for(int i=0;i<N;i++) cin >> W[i];
   set<string> map;
   string now = W[0];
   for(int i=1;i<N;i++){                
      if(now.back() != W[i].front()){  
         cout << "No" ;
         return 0;
      }
      if(map.find(now) != map.end()){  
         cout << "No";
         return 0;
      }
      map.insert(now);                    
      now = W[i];
   }
   if(map.find(now) != map.end()){  
      cout << "No";
      return 0;
   }
   cout << "Yes";
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;
const int tyou[7] = {0,2,4,5,7,9,11};
ll dp[4010][4010];
int pos[4010][4010];

int main() {
    int N; cin >> N;
    vector<ll> W(N + 1,0);
    rep(i,N) cin >> W[i + 1];
    rep(i,N) W[i + 1] += W[i];
    rep(i,N + 1)rep(j,N + 1) dp[i][j] = HINF;
    rep(i,N) {dp[i][i + 1] = 0;pos[i][i + 1] = i;}

    for (int length = 2;length <= N;++length) {
        for (int l = 0;l + length <= N;++l) {
            int r = length + l;
            for (int k = pos[l][r - 1];k <= pos[l + 1][r];++k) {
                if (dp[l][r] > dp[l][k] + dp[k][r] + W[r] - W[l]) {
                    dp[l][r] = dp[l][k] + dp[k][r] + W[r] - W[l];
                    pos[l][r] = k;
                }
            }
        }
    }
    ll ans = dp[0][N];
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 173708
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define FOR(I,A,B) for(int I=int(A);I<int(B);++I)

int INF = 2147483647;
struct RUQ{//平方分割 0-index
	int n,rn,bn,Q=0;
	vector<P> a,b;
	RUQ(int n_){
		n = n_;
		rn = sqrt(n);if(rn>1)rn/=2;
		bn = ceil((double)n/rn);
		a.resize(n,{2147483647,0});
		b.resize(bn,{2147483647,0});
	}
	int value(int s){
		if(a[s].second < b[s/rn].second){
			a[s] = b[s/rn];
		}
		return a[s].first;
	}
	void updete(int s,int t,int x){
		Q++;
		FOR(i,s,t+1){
			if(i%rn==0 && (i+rn-1)<=t){
				b[i/rn] = {x,Q};
				i += rn-1;
			}else{
				a[i] = {x,Q};
			}
		}
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N,Q;
	cin >> N >> Q;
	priority_queue<pair<int,P>> pq;
	vector<int> D(Q+1,INF);
	FOR(i,0,N){
		int s,t,x;
		cin >> s >> t >> x;
		pq.push({x,{s-x,t-x}});
	}
	FOR(i,0,Q){
		cin >> D[i];
	}
	RUQ ruq(Q+1);
	FOR(i,0,N){
		int s = pq.top().second.first;
		int t = pq.top().second.second;
		int x = pq.top().first;
		pq.pop();
		s = (lower_bound(D.begin(),D.end(),s)-D.begin());
		t = (lower_bound(D.begin(),D.end(),t)-D.begin());
		ruq.updete(s,t-1,x);
	}
	FOR(i,0,Q){
		int ans = ruq.value(i);
		if(ans==INF) ans = -1;
		cout << ans << '\n';
	}
}


Measured memory_bytes: 6768
fun main(args: Array<String>) {
    val (X, Y) = readLine()!!.split(" ").map {it.toLong()}
    val b = (2 * Y - X) / 3
    val a = Y - 2 * b

    if ((X + Y) % 3 != 0L || a < 0 || b < 0) {
        println(0)
        return
    }

    val MOD = 1e9.toLong() + 7
    val modComb = ModCombination(a + b, MOD)
    println(modComb[a + b, b].value)
}

class ModInt (value: Long, val mod: Long) {
    init {
        if (mod <= 0) {
            throw IllegalArgumentException("ModInt cannot be created for non-positive modulus: $mod")
        }
    }

    val value = (value % mod + mod) % mod

    private fun assertSameMod(other: ModInt) {
        if (mod != other.mod) {
            throw IllegalArgumentException(
                "You cannot operate summation, subtraction and multiplication for ModInts with different moduli: $mod, ${other.mod}"
            )
        }
    }

    operator fun unaryMinus() = ModInt(mod - value, mod)

    operator fun plus(other: ModInt): ModInt {
        assertSameMod(other)

        return ModInt((value + other.value) % mod, mod)
    }

    operator fun plus(other: Long) = plus(ModInt(other, mod))

    operator fun minus(other: ModInt): ModInt {
        assertSameMod(other)

        return plus(-other)
    }

    operator fun minus(other: Long) = minus(ModInt(other, mod))

    operator fun times(other: ModInt): ModInt {
        assertSameMod(other)

        return ModInt((value * other.value) % mod, mod)
    }

    operator fun times(other: Long) = times(ModInt(other, mod))

    fun pow(k: Long): ModInt {
        var res = 1L
        var a = value
        var l = k

        while (l > 0) {
            if ((l and 1L) == 1L) {
                res = (res * a) % mod
            }

            a = a * a % mod
            l /= 2L
        }

        return ModInt(res, mod)
    }

    /**
     * Returns an inverse element of the value.
     * To ensure `m * m.inv() = 1`, the modulus should be prime, since it uses Fermat's little theorem.
     */
    fun inv() = pow(mod - 2)

    operator fun div(other: ModInt): ModInt {
        assertSameMod(other)
        if (other.value == 0L) {
            throw ArithmeticException()
        }

        return times(other.inv())
    }

    operator fun div(other: Long) = div(ModInt(other, mod))
}

class ModCombination(val n: Long, val mod: Long) {
    private val fact = Array(n.toInt() + 1) { ModInt(1, mod) }
    private val invfact = Array(n.toInt() + 1) { ModInt(1, mod) }

    init {
        for (i in 2..n.toInt()) {
            fact[i] = fact[i - 1] * i.toLong()
            invfact[i] = fact[i].inv()
        }
    }

    operator fun get(n: Long, m: Long): ModInt {
        if (m > n) {
            return ModInt(0, mod)
        }

        return fact[n.toInt()] * invfact[m.toInt()] * invfact[(n - m).toInt()]
    }
}



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

int main() {

  int A;
  char op;
  int B;

  cin >> A >> op >> B;

  if (op == '+') {
    cout << A + B << endl;
  } else if (op == '-') {
    cout << A - B << endl;
  }

}



Measured memory_bytes: 3572
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, k, m;

    while (cin >> n >> k >> m, n || k || m) {
        vector<int> stone(n);
        int num = n;
        int idx = m - 1;

        for (int i = 0; i < n; i++)
            stone[i] = i + 1;
        stone.erase(stone.begin() + idx);
        num--;

        while (num > 1) {
            idx = (idx + k - 1) % stone.size();
            stone.erase(stone.begin() + idx);
            num--;
        }
        cout << stone[0] << endl;
    }

    return 0;
}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};

double dist(pair<int,int> a, pair<int,int> b){
  return pow((pow((a.first - b.first),2) + pow((a.second - b.second),2)),0.5);
 
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c;
  cin >> a >> b >> c;
  cout << b + min(a+b+1,c) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(void)
{
	int N;
	cin >> N;

    vector<int> mochi(101, 0);

	for (int loop = 0; loop < N; ++loop) {
		int d;
		cin >> d;
		mochi[d] = 1;
	}

	int ans = 0;
	for (int loop = 1; loop < 101; ++loop) {
		ans += mochi[loop];
	}

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


Measured memory_bytes: 3632
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
	int N;
	string S, T;

	cin >> N;
	cin >> S >> T;

	rep(i,N)
	{
		cout << S[i];
		cout << T[i];
	}

	return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n,m;
  cin >> n >> m;

  map<ll, ll> index;
  ll a, b;
  REP(i, m){
    cin >> a >> b;
    a--;
    b--;
    index[a] += 1;
    index[b] += 1;
  }


  bool flag = true;
  REP(i, n){
    if(index[i]%2 != 0)
      flag = false;
  }

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


Measured memory_bytes: 6528
#include<stdio.h>
int main()
{
	int k, a, b, flag = 0, t;
	scanf("%d%d%d", &k, &a, &b);
	t = k;
	while (k <= b)
	{
		if (k >= a && k <= b) { flag = 1;break; }
		k = k + t;
	}
	if (flag == 0) { printf("NG"); }
	else { printf("OK"); }
	return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const ll INF = numeric_limits<ll>::max();
int main()
{
    char a; cin >> a;
    if (a >= 'a' && a <= 'z' ) {
cout << "a" << endl;
    }else{
cout << "A" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner

object Main extends App { 
  val sc = new Scanner(System.in)
  val N = sc.nextInt()
  val W = sc.nextLong()
  val items = (for (i <- 1 to N) yield (sc.nextLong, sc.nextLong)).toList.sortWith(basicOrder)

  type Item  = (Long, Long) // (value, Weight)
  type Items = List[Item]

  def valuePerWeight(a:Item, b:Item):Boolean = {
    val (va,wa) = a
    val (vb,wb) = b
    va.toDouble/wa > vb.toDouble/wb
  }

  def basicOrder(a:Item, b:Item):Boolean = {
    (a, b) match {
      case ((va,wa),(vb,wb)) if va < vb => true
      case ((va,wa),(vb,wb)) if va == vb && wa < wb => true
      case _ => false
    }
  }

  type ItemCount = (Item, Int)

  def compress(al:Items):Items = {
    def count(list:Items, preItem:ItemCount, ac:List[ItemCount]):List[ItemCount] = {
      if (list.isEmpty) preItem::ac
      else preItem match {
        case (p, c) if list.head == p => count(list.tail, (p,c+1), ac)
        case _ => count(list.tail, (list.head, 1), preItem::ac) 
      }
    }

    def mkItems(t:ItemCount):List[Item] = {
      def iter(v:Long, w:Long, m:Int, s:Int, acc:List[Item]):(Int, List[Item]) = {
        if (m > 1) {
          iter(v << 1,w << 1,m >> 1, s << 1, (v, w)::acc)
        } else (s,acc)
      }
      val ((v,w),m) = t
      val (s, items) = iter(v, w, m, 1, Nil)
      val k = m - (s -1)
      if (k > 0) (v*k,w*k)::items else items
    }

    val cl = count(al, (al.head,0), Nil)
    (for (e <- cl) yield mkItems(e)).flatten.toList.sortWith(valuePerWeight)
  }

// Greedy Knapsack solver. items have to be descending by value per weight.  
  def gks(items:Items, weight:Long):Double = {
    def iter(items:Items, weight:Long, ac:Double):Double = {
      if (items.isEmpty || weight <= 0) ac
      else {
        val (v, w) = items.head
        if (weight < w) ac+v*weight.toDouble/w
        else iter(items.tail, weight -w, ac+v)    
      }
    }
    iter(items, weight, 0f)
  }

  def solver(items:Items, weight:Long):Long = {
    if (items.isEmpty || weight == 0) 0
    else {
      val (v, w)= items.head
      if (weight >= w) {
        val v0 = solver(items.tail, weight-w) + v
        if (v0 < gks(items.tail, weight)) v0 max solver(items.tail, weight)
        else v0
      }
      else solver(items.tail, weight)
    }
  }

  println(solver(compress(items), W))
}


Measured memory_bytes: 45572
#include<bits/stdc++.h>
using namespace std;
int main() {
	string s1, s2, s3; cin >> s1 >> s2 >> s3;
	string res = {};
	res.push_back(s1[0] + 'A' - 'a');
	res.push_back(s2[0] + 'A' - 'a');
	res.push_back(s3[0] + 'A' - 'a');
	cout << res << endl;
	return 0;
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define PI 3.1415926535898

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

int main() {
    int k, t;
    cin >> k >> t;
    int a[t];
    rep(i, t) cin >> a[i];

    sort(a, a + t);
    int M = a[t - 1];
    cout << max(M - 1 - (k - M), 0) << endl;

    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
#define N 100500
#define mod 1000000007
int n,nt[N],su[N],nt2[N][3],as,dp[N];
char s[N];
int main()
{
	scanf("%s",s+1);n=strlen(s+1);
	for(int i=1;i<=n;i++){su[i]=(su[i-1]+s[i]-'a'+1)%3;}
	nt[n+1]=n+1;nt2[n+1][0]=nt2[n+1][1]=nt2[n+1][2]=n+1;
	for(int i=n;i>=0;i--)
	{
		nt[i]=nt[i+1];nt2[i][0]=nt2[i+1][0];nt2[i][1]=nt2[i+1][1];nt2[i][2]=nt2[i+1][2];
		if(s[i]==s[i+1])nt[i]=i+1;
		nt2[i][su[i+1]]=i+1;
	}
	dp[0]=1;
	for(int i=0;i<=n;i++)
	{
		int tp=nt[i]-1;
		if(s[i+1]=='a')dp[nt2[tp][(2+su[i])%3]]=(dp[nt2[tp][(2+su[i])%3]]+dp[i])%mod;else dp[i+1]=(dp[i+1]+dp[i])%mod;
		if(s[i+1]=='b')dp[nt2[tp][(1+su[i])%3]]=(dp[nt2[tp][(1+su[i])%3]]+dp[i])%mod;else dp[i+1]=(dp[i+1]+dp[i])%mod;
		if(!(su[n]-su[i])%3&&i)as=(as+dp[i])%mod;
	}
	if(nt[0]==n+1)as=1;
	printf("%d\n",as);
}//

Measured memory_bytes: 2560
/* ITP1_11_A */
#include <stdio.h>

#define HEXA 6
#define ORDER_MAX_LENGTH 101
#define N_CODE 78
#define S_CODE 83
#define W_CODE 87
#define E_CODE 69

/* ?????¢????????¨????§??????? */
typedef struct {
	short top_surf;
	short front_surf;
	short right_surf;
	short left_surf;
	short back_surf;
	short bottom_surf;
} hexahedron;

/* ?§??????????????????????????????¢??° */
void init_dice(hexahedron *data);
/* ???????????????????????????????????¢??° */
void init_array_char(char array_ch[], short size);
/* ?????¢????????¶???????¨???? */
void rotate(hexahedron *dice, char rotate);
/* N?????????????????¢????????? */
void rotate_N(hexahedron *dice);
/* S?????????????????¢????????? */
void rotate_S(hexahedron *dice);
/* W?????????????????¢????????? */
void rotate_W(hexahedron *dice);
/* E?????????????????¢????????? */
void rotate_E(hexahedron *dice);

int main(void)
{
	hexahedron dice;
	init_dice(&dice);
	
	scanf("%hd", &dice.top_surf);
	scanf("%hd", &dice.front_surf);
	scanf("%hd", &dice.right_surf);
	scanf("%hd", &dice.left_surf);
	scanf("%hd", &dice.back_surf);
	scanf("%hd", &dice.bottom_surf);
	
	char order_array[ORDER_MAX_LENGTH];
	init_array_char(order_array, ORDER_MAX_LENGTH);
	
	scanf("%s", order_array);
	
	short ii;
	for( ii = 0; '\0' != order_array[ii] && '\n' != order_array[ii]; ii++ )
	{
		rotate(&dice, order_array[ii]);
	}
	
	printf("%hd\n", dice.top_surf);
	
	return 0;
}

/* ?§??????????????????????????????¢??° */
void init_dice(hexahedron *data)
{
	data->top_surf = 0;
	data->front_surf = 0;
	data->right_surf = 0;
	data->left_surf = 0;
	data->back_surf = 0;
	data->bottom_surf = 0;
}

/* ???????????????????????????????????¢??° */
void init_array_char(char array_ch[], short size)
{
	short ii;
	for( ii = 0; ii < size; ii++ )
	{
		array_ch[ii] = '\0';
	}
}

/* ?????¢????????¶???????¨???? */
void rotate(hexahedron *dice, char rotate)
{
	switch( rotate )
	{
	case N_CODE:
		rotate_N(dice);
		break;
	case S_CODE:
		rotate_S(dice);
		break;
	case W_CODE:
		rotate_W(dice);
		break;
	case E_CODE:
		rotate_E(dice);
		break;
	default:
		break;
	}
}

/* N?????????????????¢????????? */
void rotate_N(hexahedron *dice)
{
	short temp = dice->top_surf;
	dice->top_surf = dice->front_surf;
	dice->front_surf = dice->bottom_surf;
	dice->bottom_surf = dice->back_surf;
	dice->back_surf = temp;
}

/* S?????????????????¢????????? */
void rotate_S(hexahedron *dice)
{
	short temp = dice->front_surf;
	dice->front_surf = dice->top_surf;
	dice->top_surf = dice->back_surf;
	dice->back_surf = dice->bottom_surf;
	dice->bottom_surf = temp;
}

/* W?????????????????¢????????? */
void rotate_W(hexahedron *dice)
{
	short temp = dice->left_surf;
	dice->left_surf = dice->top_surf;
	dice->top_surf = dice->right_surf;
	dice->right_surf = dice->bottom_surf;
	dice->bottom_surf = temp;
}

/* E?????????????????¢????????? */
void rotate_E(hexahedron *dice)
{
	short temp = dice->right_surf;
	dice->right_surf = dice->top_surf;
	dice->top_surf = dice->left_surf;
	dice->left_surf = dice->bottom_surf;
	dice->bottom_surf = temp;
}

Measured memory_bytes: 596
import sys
n = int(input())
r = [int(input()) for x in range(n)]
max_val = sys.maxsize * -1
min_val = r[0]
for i in range(1,n):
  max_val = max(max_val, r[i] - min_val)
  min_val = min(min_val, r[i])
print(max_val)



Measured memory_bytes: 13600
N,MA,MB=map(int,input().split())
S=[list(map(int,input().split())) for i in range(N)]

DPLIST=[[10**6 for i in range(401)] for j in range(401)]
DPLIST[0][0]=0

for a,b,c in S:
    for i in range(400,a-1,-1):
        for j in range(400,b-1,-1):
            if DPLIST[i][j]>DPLIST[i-a][j-b]+c:
                DPLIST[i][j]=DPLIST[i-a][j-b]+c
                
ANS=10**6
for k in range(1,400//max(MA,MB)):
    if DPLIST[MA*k][MB*k]<ANS:
        ANS=DPLIST[MA*k][MB*k]

if ANS==10**6:
    print(-1)
else:
    print(ANS)

Measured memory_bytes: 4872
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    const int MAX_N = 1000;
    int N, M;
    ll A[MAX_N][3];
    cin >> N >> M;
    REP(i, N) {
        cin >> A[i][0] >> A[i][1] >> A[i][2];
    }
    ll res = -(1LL << 60);
    REP(i, 8) {
        vector<ll> v;
        REP(j, N) {
            ll S = 0;
            REP(k, 3) {
                if (i & 1 << k) {
                    S += A[j][k];
                } else {
                    S -= A[j][k];
                }
            }
            v.push_back(S);
        }
        SORT(v);
        REVERSE(v);
        ll S = 0;
        REP(j, M) {
            S += v[j];
        }
        amax(res, S);
    }
    cout << res << endl;
    return 0;
}


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

int main() {
  int N, bot = 1, min = -1;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a.at(i);
  for (int i = 0; i < N; i++) {
    bot = a.at(bot - 1);
    if (bot == 2) {
      min = i + 1;
      break;
    }
  }
  cout << min << endl;
}


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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

int main(){
    int A, B;
    cin >> A >> B;
    int answer = -1;
    
    REP(i,1010){
        int a = i*0.08;
        int b = i*0.10;
        
        if(a == A && b == B){
          answer = i;
          break;
        } 
        
    }
    
    if(answer == -1){
        cout << -1 << endl;
    }
    else{
    cout << answer << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007ll
#define mod1 998244353ll
#define endl "\n"
using namespace std::chrono;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    ll ar[n];
    for(ll x=0;x<n;x++){
        cin>>ar[x];
    }
    ll dp[n];
    dp[n-1]=0;
    dp[n-2]=abs(ar[n-1]-ar[n-2]);
    for(ll x=n-3;x>=0;x--){
        dp[x]=min(abs(ar[x]-ar[x+1])+dp[x+1],abs(ar[x]-ar[x+2])+dp[x+2]);
    }
    cout<<dp[0]<<endl;
    return 0;
}

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

int main()
{
  long int N, K;
  long int result;

  cin >> N >> K;
  vector<long int> H(N);

  for (long int i = 0; i < N; i++)
  {
    cin >> H.at(i);
  }

  if (H.size() < K)
  {
    K = H.size();
  }

  sort(H.begin(), H.end());
  reverse(H.begin(), H.end());

  for (long int i = 0; i < K; i++)
  {
    H.at(i) = 0;
  }

  for (long int i = 0; i < N; i++)
  {
    result += H.at(i);
  }

  cout << result << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<int,int> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n,k;

int main(){
	cin>>n>>k;
	if(k==1)cout<<0<<endl;
	else cout<<n-k<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll m = 1e9 + 7;
string s;
ll n,d;
ll a[10005];
ll dp[10005][101][2];
ll solve(ll idx,ll sum,ll flag){
    if(idx > n){
        if(sum == 0){
            return 1;
        }
        else{
            return 0;
        }
    }
    if(dp[idx][sum][flag] != -1){
        return dp[idx][sum][flag];
    }
    ll limit = 9;
    if(!flag){
        limit = a[idx];
    }
    ll ans = 0;
    for(int i=0;i<=limit;i++){
        if(i < limit || flag == 1){
            ans += solve(idx + 1,(sum + i) % d, 1);
            ans %= m;
        }
        else{
            ans += solve(idx + 1,(sum + i) % d, 0);
            ans %= m;
        }
    }
    return dp[idx][sum][flag] = ans%m;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>s;
    cin>>d;
    n = s.length();
    for(int i=0;i<=n;i++){
        for(int j=0;j<=d;j++){
            for(int k=0;k<2;k++){
                dp[i][j][k] = -1;
            }
        }
    }
    for(int i=1;i<=n;i++){
        a[i] = s[i-1] - '0';
    }
    ll ans = solve(1,0,0);
    cout<<(ans - 1 + m) % m <<"\n";
}

Measured memory_bytes: 20172
N = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            divisors.append(n//i)

    divisors.sort()
    return divisors

a = make_divisors(N)
print(a[len(a)//2-1]-1 +  a[len(a)//2]-1)

Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
int n,s[100000],q,t,c,i,j;
main(){
  for(scanf("%d",&n);i<n;scanf("%d",&s[i++]));
  for(scanf("%d",&q);j++<q;){
    scanf("%d",&t);
    binary_search(s,s+n,t)&&c++;
  }
  printf("%d\n",c);
}

Measured memory_bytes: 3500
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProconTemplate
{
    //https://atcoder.jp/contests/abc141/tasks/abc141_d
    class abc140_b
    {
        public static void Main(string[] args)
        {
            //string s = Console.ReadLine();
            string[] asInput = Console.ReadLine().Split(' ');
            int N = int.Parse(asInput[0]);
            //int M = int.Parse(asInput[1]);
            //int Q = int.Parse(asInput[2]);
            //int[] aiAns = new int[N];
            //for (int i = 0; i < Q; i++)
            //{
            //    aiAns[ int.Parse(Console.ReadLine()) - 1 ] ++;
            //}
            int[] A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int[] B = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int[] C = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            //int[] A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            int iScore = 0;
            for (int i = 0; i < N; i++)
            {
                iScore += B[i];
                if (i < N - 1 && A[i + 1] == A[i] + 1) iScore += C[A[i]-1];
            }
            Console.WriteLine(iScore);

        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <limits>
#include <queue>
#include <iomanip>
using namespace std;

using pii=pair<int,int>;
#define rip(i,n,s) (int i=(s);i<(int)(n);i++)

void dfs(vector<vector<pii>> &da,vector<long long> &dis,int no){
	int x=da[no].size();
	for rip(i,x,0){
		if(dis[da[no][i].first]<0){
			dis[da[no][i].first]=(long long)dis[no]+da[no][i].second;
			dfs(da,dis,da[no][i].first);
		}
	}
}

int main(){
	int n;
	cin >> n;
	vector<vector<pii>> da(n,vector<pii>(0));
	for(int i=0;i<n-1;i++){
		int a,b,c;
		cin >> a >> b >> c;
		da[a-1].push_back(make_pair(b-1,c));
		da[b-1].push_back(make_pair(a-1,c));
	}
	int q,k;
	cin >> q >> k;
	vector<long long> dis(n,-1);
	dis[k-1]=0;
	dfs(da,dis,k-1);
	vector<long long> ans(q);
	for rip(i,q,0){
		int x,y;
		cin >> x >> y;
		ans[i]=dis[x-1]+dis[y-1];
	}
	for rip(i,q,0){
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 15104
#include<cstdio>
#include<algorithm>
using namespace std;

const int INF = 2147483647;

int n,q,_n;
int data[262143];

void init(int n){
  _n = 1;
  while(_n<n){
    _n *= 2;
  }
  fill(data,data+2*_n-1,INF);
}

void update(int i,int x){
  i += _n-1;
  data[i] = x;
  while(i>0){
    i = (i-1)/2;
    data[i] = min(data[2*i+1],data[2*i+2]);
  }
}

int query(int a,int b,int k,int l,int r){
  if(a<=l&&r<=b+1) return data[k];
  else if(b<l||a>=r) return INF;
  else{
    int vl = query(a,b,2*k+1,l,(l+r)/2);
    int vr = query(a,b,2*k+2,(l+r)/2,r);
    return min(vl,vr);
  }
}

int main(){
  scanf("%d %d",&n,&q);
  init(n);
  for(int i=0;i<q;i++){
    int cmd,a,b;
    scanf("%d%d%d",&cmd,&a,&b);
    if(cmd==0) update(a,b);
    else if(cmd==1) printf("%d\n",query(a,b,0,0,_n));
  }
  return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n; cin >> n;
    set<char> st;

    rep(i, n){
        char c; cin >> c;
        st.insert(c);
    }
    cout << ((st.size() == 3) ? "Three" : "Four") << endl; 
}

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

int main()
{
    long n, q;
    scanf("%ld %ld", &n, &q);

    if (n >= 10)
    {
        printf("%ld\n", q);
    }
    else
    {
        printf("%ld\n", q + 100 * (10 - n));
    }

    return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.util.Map.Entry;
 
class Main {
//	 static int mod =  (int) (Math.pow(10,9)+7);
	 static int mod = 998244353;
   public static void main(String[] args) {
	   
       Scanner sc = new Scanner(System.in);
       int N = sc.nextInt();
//       int M = sc.nextInt();
       int[] a = new int[(int)N];
       for (int i=0 ; i<N; i++) {
           a[i] = sc.nextInt();
       }
       long ans=1;
       if(a[0]!=0) {
    	   System.out.println(0);
    	   return;		  
       }
       int[] cntm=new int[N];
       cntm[0]++;
       int max=0;
       for(int i=1;i<N;i++) {
    	   if(a[i]==0) {
        	   System.out.println(0);
        	   return;   		   
    	   }
    	   cntm[a[i]]++;
    	   max=Math.max(max,a[i]);
       }
       for(int i=1;i<max+1;i++) {
    	   for(int j=0;j<cntm[i];j++) {
    		   ans=(long)((ans*cntm[i-1])%mod);
    	   }
    	   
       }
       
       System.out.println(ans);
   }
      

}

Measured memory_bytes: 52088
#include<iostream>
#include<vector>
#include<string>
#include<map>
using namespace std;

int W,H;

vector<string> V;

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

int res;
typedef pair<int,int> Cor;

bool in(int y,int x){
	return !(y<0 || x<0 || y>=H || x>=W);
}
vector<vector<Cor> >Al(26);

void print(){
	cout<<endl;
	for(int y=0;y<H;y++){
		for(int x=0;x<W;x++)
			cout<<V[y][x];
		cout<<endl;
	}
}


bool kesu(int k){
	vector<vector<bool> > Check(H,vector<bool>(W,false));
	int y1=Al[k][0].first,x1=Al[k][0].second;
	int y2=Al[k][1].first,x2=Al[k][1].second;

	for(int r=0;r<4;r++){
		int y=y1+dy[r],x=x1+dx[r];
		while(in(y,x) && V[y][x]=='.'){Check[y][x]=true; y+=dy[r];x+=dx[r];}
	}

	for(int r=0;r<4;r++){
		int y=y2+dy[r],x=x2+dx[r];
		while(in(y,x) && V[y][x]=='.'){
			if(Check[y][x]){res++;V[y1][x1]=V[y2][x2]='.';return true;}
			Check[y][x]=true; y+=dy[r];x+=dx[r];
		}
	}
	return false;
}

void solve(){
	res=0;
	V.clear();
	Al.clear();
	Al.resize(26);
	for(int i=0;i<H;i++){
		string s;
		cin>>s;
		V.push_back(s);
	}

	vector<bool> ex(26,false);
	
	for(int y=0;y<H;y++){
		for(int x=0;x<W;x++){
			if(V[y][x]!='.'){
				int c=V[y][x]-'A';
				ex[c]=true;
				Al[c].push_back(make_pair(y,x));
			}
		}
	}

	bool update=true;
	while(update){
		update=false;
		for(int k=0;k<26;k++){
			if(!ex[k]) continue;
			bool kekka=kesu(k);
			ex[k]=!kekka;
			update=(update || kekka);
		}
	}
	cout<<res*2<<endl;
}

int main()
{
	while(cin>>H>>W){
		if(H==0) break;
		solve();
	}
	return 0;
}

Measured memory_bytes: 0
# coding: utf-8
n, m = map(int, input().split())
like_food = [0 for i in range(m)]
for j in range(n):
    j_data = list(map(int, input().split()))
    for k in range(j_data[0]):
        like_food[j_data[k + 1] - 1] += 1
print(like_food.count(n))


Measured memory_bytes: 2940
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)
def pow_k(x, n):

    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x
def main():  #startline-------------------------------------------
    n = int(input())
    i = 0
    ans = 0
    if n % 2 == 0:
        while 10*5 ** i <= n:
            ans += n // (10* 5**i)
            i += 1
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

Measured memory_bytes: 21388