akhauriyash/Code-Regression huggingface dataset:
#ifdef MY_LOCAL
#define MY_NAMESPACE(ns) namespace ns {
#define MY_NAMESPACE_    }
#define MY_DEBUG(s)      s
#else
#define MY_NAMESPACE(ns) 
#define MY_NAMESPACE_    
#define MY_DEBUG(s)      
#endif

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

#define EPS (1e-7)
#define IINF ((int)1e9)


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

	int n;
	cin >> n;
	int total = 0;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		total ^= a[i];
	}

	for (int i = 0; i < n; i++)
	{
		int this_res = 0;
		this_res = total ^ a[i];
		if (i != 0)
			cout << " ";
		cout << this_res;
	}
	cout << "\n";
	return 0;
}
MY_NAMESPACE_

Measured memory_bytes: 3904
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    cin >> n;

    int x[n], y[n];
    int mod = -1;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        if (mod == -1) {
            mod = (abs(x[i]) + abs(y[i])) % 2;
        } else if (mod != (abs(x[i]) + abs(y[i])) % 2) {
            mod = -2;
        }
    }

    if (mod == -2) {
        cout << -1 << "\n";
        return 0;
    }

    vector <int> D;
    if (mod == 0) D.push_back(1);
    for (int i = 30; i >= 0; i--) D.push_back(1 << i);

    cout << D.size() << "\n";
    for (int d : D) cout << d << " ";
    cout << "\n";

    for (int i = 0; i < n; i++) {
        int u = x[i] + y[i];
        int v = x[i] - y[i];

        for (int d : D) {
            if (u >= 0 && v >= 0) {
                cout << 'R';
                u -= d; v -= d;
            } else if (u >= 0 && v < 0) {
                cout << 'U';
                u -= d; v += d;
            } else if (u < 0 && v >= 0) {
                cout << 'D';
                u += d; v -= d;
            } else {
                cout << 'L';
                u += d; v += d;
            }
        }

        cout << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
def main():

    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**5)
    from collections import deque


    N = int(input())
    edges = []
    ad = [[] for _ in range(N)]
    for _ in range(N-1):
        a,b = map(int,input().split())
        a -= 1; b -= 1
        ad[a].append(b)
        ad[b].append(a)
        edges.append((a,b))

    C = deque(sorted(map(int,input().split()), reverse=True))

    nodes = [-1]*N

    def dfs(v=0,pv=-1):
        for nv in ad[v]:
            if nv == pv:
                continue
            dfs(nv,v)
        nodes[v] = C.pop()

    dfs()
    ans = 0

    for a,b in edges:
        ans += min(nodes[a],nodes[b])

    print(ans)
    print(*nodes)


if __name__ == "__main__":
    main()

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

int main() {
    string S;
    cin >> S;
    int n = S.size() / 2;
    int ans = 0;
    rep(i, n) {
        if (S[i] != S[S.size()-i-1]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var H, W int64
	fmt.Scanf("%d %d", &H, &W)
	if H > 1 && W > 1 {
		fmt.Printf("%d\n", (H*W+1)/2)
	} else {
		fmt.Println("1")
	}
}

Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, m;
    cin >> n >> m;
    yukari<pair<int, int>> g(n);
    for (int i = 0; i < m; i++)
    {
        int s, t;
        cin >> s >> t;
        s--, t--;
        g[s].push_back(make_pair(t, 1));
    }
    akari<double> dp(n);
    akari<int> heavy(n), vst(n);
    auto calc = [&](auto &&calc, akari<double> &dp, int s = 0) -> double {
        if (vst[s])
        {
            return dp[s];
        }
        double res = 0, maxi = 0;
        int cnt = 0;
        vst[s] = 1;
        for (auto np : g[s])
        {
            if (!np.second)
            {
                continue;
            }
            cnt++;
            double w = calc(calc, dp, np.first) + 1;
            if (maxi < w)
            {
                maxi = w;
                heavy[s] = np.first;
            }
            res += w;
        }
        if (cnt)
        {
            res /= cnt;
        }
        else if (s != n - 1)
        {
            res = n + 1;
        }
        return dp[s] = res;
    };
    double ans = calc(calc, dp);
    for (int s = 0; s < n - 1; s++)
    {
        akari<double> dp2(n);
        fill(vst.begin(), vst.end(), 0);
        for (auto &p : g[s])
        {
            if (p.first == heavy[s])
            {
                p.second = 0;
                ans = min(ans, calc(calc, dp2));
                p.second = 1;
                break;
            }
        }
    }
    cout << setprecision(15) << ans << endl;
}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 2560
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double c = sc.nextDouble();
        double S, L, h;
        S = 0.5 * a * b * Math.sin(Math.PI * c / 180);
        double d = Math.sqrt( a * a + b * b - 2 * a * b * Math.cos(Math.PI * c / 180));
        System.out.printf("%.10f\n", S);
        System.out.printf("%.10f\n", a + b + d);
        System.out.printf("%.10f\n", 2 * S / a);
        sc.close();
    }
}




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

using namespace std;
using ll = long long;

//constructor: LCA(n, graph);
class LCA {
private:
    int n;                      //number of vertex
    int D = 30;                 //hight
    vector<int> depth;          //depth from root
    vector<vector<int>> hen;    //tree
    vector<vector<int>> par;    //doubling array

    void dfs(int v, int p, int dep) {
        par[v][0] = p;
        depth[v] = dep; 
        for(auto i : hen[v]) {
            if(i == p)continue;
            dfs(i, v, dep + 1);
        }
    }

public:

    LCA(const int& n, const vector<vector<int>>& hen):n(n), hen(hen) {
        par.resize(n, vector<int>(D + 1));
        depth.resize(n);


        dfs(0, -1, 0);
        for(int i = 0; i < D; i++) {
            for(int j = 0; j < n; j++) {
                if(par[j][i] == -1)par[j][i + 1] = -1;
                else par[j][i + 1] = par[par[j][i]][i];
            }
        }
    }

    //go back to root
    int back(int v, int dist) {
        for(int i = 0; i < D; i++)if((1 << i) & dist) {
            if(v == -1)return v;
            v = par[v][i];
        }
        return v;
    }

    //u-v path distance
    int dist(int u, int v) {
        int ret = 0;
        if(depth[u] > depth[v])swap(u, v);
        ret = depth[v] - depth[u];
        v = back(v, ret);
        if(u == v)return ret;
        int lef = 0, rig = n;
        while(rig - lef > 1) {
            int mid =(rig + lef) / 2;
            (back(u, mid) == back(v, mid) ? rig : lef) = mid;
        }
        return rig * 2 + ret;
    }

    //get LCA
    int get(int u, int v) {
        int ret = 0;
        if(depth[u] > depth[v])swap(u, v);
        ret = depth[v] - depth[u];
        v = back(v, ret);
        if(u == v)return v;

        int lef = 0, rig = n;
        while(rig - lef > 1) {
            int mid = (rig + lef) / 2;
            (back(u, mid) == back(v, mid) ? rig : lef) = mid;
        }
        return back(v, rig);
    }

    //print parents
    void print(int i) {
        cerr << "[";
        for(int j = 0; j < n; j++)cerr << par[j][i] << (j == n - 1 ? "" : ",");
        cerr << "]";
    }

};

int main()
{
    int n; cin >> n;
    vector<vector<int>> hen(n);
    for(int i = 0; i < n; i++) {
        int t; cin >> t;
        for(int j = 0; j < t; j++) {
            int p; cin >> p;
            hen[i].push_back(p);
            hen[p].push_back(i);
        }
    }
    LCA lca(n, hen);
    int q; cin >> q;
    for(int i = 0; i < q; i++) {
        int u, v; cin >> u >> v;
        cout << lca.get(u, v) << endl;
    }
}


Measured memory_bytes: 33420
from collections import Counter
h, w, n = map(int, input().split())
c = Counter([])

for i in range(n):
    a, b = map(int, input().split())
    a-=1; b-=1

    for i in range(-2, 1):
        for j in range(-2, 1):
            if 0<=a+i<h-2 and 0<=b+j<w-2:
                c[(a+i, b+j)]+=1

ans = [0] * 10
total = 0
for k, v in c.items():
    ans[v]+=1
    total+=1
ans[0]=(h-2)*(w-2) - total


for a in ans:
    print(a) 
    



Measured memory_bytes: 164400
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }

using ll = long long;
const ll mod = LLONG_MAX;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b)cout<<c<<endl;
  else if(a==c)cout<<b<<endl;
  else cout<<a<<endl;

}


Measured memory_bytes: 256
n = int(input())
bucket = [0]*(101)

d = [0]*(n)
for i in range(n):
    d[i] = int(input())

for i in range(n):
    bucket[d[i]] += 1

counter = 0

for num in bucket:
    if num > 0:
        counter+=1

print(counter)


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;  
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MAX = 8010;

int main() {
  string s;
  int x, y;
  cin >> s >> x >> y;
  vector<int> xnum, ynum;
  bool flag = 1;
  int cnt = 0;
  rep(i, s.size()) {
    if (s[i] == 'F')
      cnt++;
    if (s[i] == 'T' || i+1 == s.size()) {
      if (flag)
        xnum.push_back(cnt);
      else
        ynum.push_back(cnt);
      cnt = 0;
      flag ^= 1;
    }
  }
  vector<vector<bool>> xdp(xnum.size()+1, vector<bool>(MAX*2));
  xdp[0][MAX] = true;
  rep(i, xnum.size()) rep(j, MAX*2) {
    if (xdp[i][j]) {
      xdp[i+1][j+xnum[i]] = true;
      if (i)
        xdp[i+1][j-xnum[i]] = true;
    }
  }
  vector<vector<bool>> ydp(ynum.size()+1, vector<bool>(MAX*2));
  ydp[0][MAX] = true;
  rep(i, ynum.size()) rep(j, MAX*2) {
    if (ydp[i][j]) {
      ydp[i+1][j+ynum[i]] = true;
      ydp[i+1][j-ynum[i]] = true;
    }
  }
  if (xdp[xnum.size()][x+MAX] && ydp[ynum.size()][y+MAX])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 16256
N, C = map(int, input().split())
INF = 10**20
rightSushi = [tuple(map(int, input().split())) for _ in range(N)]
leftSushi = [(C - x, v) for x, v in rightSushi[:: -1]]

def calc(sushi):
    ret = [-INF] * (N + 1)
    ret[0] = 0
    vSum = 0
    for i, (x, v) in enumerate(sushi, start=1):
        vSum += v
        ret[i] = max(vSum - x, ret[i - 1])
    return ret

leftV = calc(leftSushi)
rightV = calc(rightSushi)

ans = 0
vSum = 0
for right, (x, v) in enumerate(rightSushi, start=1):
    vSum += v
    ans = max(
        ans,
        vSum - x,
        vSum - x * 2 + leftV[N - right]
    )

vSum = 0
for left, (x, v) in enumerate(leftSushi, start=1):
    vSum += v
    ans = max(
        ans,
        vSum - x,
        vSum - x * 2 + rightV[N - left]
    )

print(ans)

Measured memory_bytes: 34660
"""a = int(input())

import itertools
a_list = [i for i in range(3,a+1)]
#print(a_list)

for i in itertools.combinations_with_replacement(a_list,len(a_list)):
    if(sum(i) == a):
        print(sum(i))
        """

MOD = 10**9 + 7
S = int(input())

dp = [1] * 2001
dp[0] = dp[1] = dp[2] = 0
"""
for i in range(S+1):
    for j in range(3, i):
        dp[i] += dp[i-j]
    print(i,dp[0:S+1])

"""

for i in range(3,S+1):
    for l in range(i+1-3):
        dp[i] += dp[l]

    #print(i,dp[0:i+1])

      

print(dp[S] % MOD)



Measured memory_bytes: 9232
module subprogram
	implicit none
contains
subroutine heapsort(n,array)
  implicit none
  integer,intent(in) :: n
  integer,intent(inout) :: array(1:n)
  
  integer ::i,k,j,l
  double precision :: t
  
  if(n.le.0)then
     write(6,*)"Error, at heapsort"; stop
  endif
  if(n.eq.1)return

  l=n/2+1
  k=n
  do while(k.ne.1)
     if(l.gt.1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k.eq.1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j.le.k)
        if(j.lt.k)then
           if(array(j).lt.array(j+1))j=j+1
        endif
        if (t.lt.array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo

  return
end subroutine heapsort

end module subprogram

program main
	use subprogram
	implicit none
    integer N, i, l
	integer(8) S
	integer, allocatable :: A(:)
	read(*, *) N
	allocate(A(1:N))
	read(*, *) A(1:N)
	do i = 1, N
		A(i) = A(i) - i
	end do
	call heapsort(N,A)
	if(mod(N, 2) == 0) then
		l = A(N/2)
		do i = 1, N
			A(i) = A(i) - l
		end do
		S = 0
		do i = 1, N
			S = S + abs(A(i))
		end do
		write(*, *) S
	else
		l = A((N+1)/2)
		do i = 1, N
			A(i) = A(i) - l
		end do
		S = 0
		do i = 1, N
			S = S + abs(A(i))
		end do
		write(*, *) S
	end if
end program main

Measured memory_bytes: 1536
n = input()

if len(n) == 1:
    print(int(n))
elif len(n) == 2:
    print(9)
elif len(n) == 3:
    print(9 + int(n) - 100 + 1)
elif len(n) == 4:
    print(9 + 900)
elif len(n) == 5:
    print(909 + int(n) - 10000 + 1)
elif len(n) == 6:
    print(909 + 90000)


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

#define MAX_A   10000

int main() {
    int n;
    cin >>n;
    vector<int> C(MAX_A+1, 0);
    vector<int> A(n, 0);
    for (int i=0; i<n; i++) {
        cin >>A.at(i);
        C.at(A.at(i))++;
    }
    for (int i=1; i<=MAX_A; i++)
        C.at(i) +=C.at(i-1);
    vector<int> B(n+1, 0);
    for (int i=0; i<n; i++) {
        B.at(C.at(A.at(i)))=A.at(i);
        C.at(A.at(i))--;
    }
    for (int i=1; i<=n; i++)
        if (i==1)
            cout <<B.at(i);
        else
            cout <<' ' <<B.at(i);
    cout <<endl;
    return 0;
}


Measured memory_bytes: 18300
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n;
  cin>>n;
  vector<int> h(n);
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  int num=-999;
  for(int i=0;i<n;i++){
    if(num<=h[i]-1){
      num=h[i]-1;
    }else if(num<=h[i]){
      num=h[i];
    }else{
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Main{
    public static void main(String[] args) throws Exception {
        int[] x = new int[10001];
        String[] z = new String[3001];
        String str;
        int a=0,b=0,c=1,i=0;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));    
        for (i=1;c!=0;i++) {
            str = br.readLine();
            z = str.split(" ");
            a = Integer.parseInt(z[0]);
            b = Integer.parseInt(z[1]);
            if (a>b) {
                c=a;
                a=b;
                b=c;
            }
            c=a+b;
            x[i]=a;
            i++;
            x[i]=b;
        }
        i--;
        i--;
        i--;
        while(i>0){
            c++;
            System.out.print(x[c]);
            System.out.print(" ");
            c++;
            System.out.println(x[c]);
            i--;
            i--;
        }
    }
}


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

int main() {
  vector<int> N(3);
    for(int i=0;i<3;i++)
      cin>>N.at(i);
  sort(N.begin(),N.end());
  int ans=N.at(0)+N.at(1)+N.at(2)*10;
  cout<<ans<<endl;
}


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

int main(){
  int n;
  cin >> n;
  int ans=0;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    if(i%2==0) ans+=a%2;
  }
  cout << ans << endl;
}

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

int main(){
  int n; cin >> n;
  vector<int> a(n);
  int s = 1000000010, t;
  for (int i = 0; i < n; i++){
    cin >> a.at(i);
    if (abs(a.at(i)) < s){
      s = abs(a.at(i));
      t = i;
    }
  }
  int mins = 0;
  for (int i = 0; i < n; i++){
    if (a.at(i) < 0) mins++;
  }
  mins %= 2;

  int64_t ans = 0;
  for (int i = 0; i < n; i++){
    if (mins == 1 && i == t) ans += (-1) * abs(a.at(i));
    else ans += abs(a.at(i));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    string s, t;
    cin >> s >> t;
    int ans = t.size();
    rep(i,s.size()){
        int diff = 0;
        bool f = true;
        rep(j,t.size()){
            if(i + j >= s.size()){
                f = false;
                break;
            }
            if(s[i+j] != t[j]){
                diff++;
            }
        }
        if(f){
            ans = min(ans, diff);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3608
#include<stdio.h>
int main(void){
int a,b;
  scanf("%d%d",&a,&b);
  if(a>b){
for(int i=0;i<a;i++){
printf("%d",b);
}
  }
    else {
      for(int i=0;i<b;i++){
printf("%d",a);
}
    }
      return 0;
    }

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int gcd(int a, int b){
  if (a%b==0){
    return(b);
  }
  else{
    return(gcd(b,a%b));
  }
}


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 2020; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j]);
//       }
//     }
//   }
//   return 0;
// }


int factorial(int n){
  if(n == 0) return 1;
  return n*factorial(n-1);
}

int divisor(int a){
  int cnt = 0;
  for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
  return cnt;
}

int comb(int n, int k){
  return factorial(n) / (factorial(n-k)*factorial(k));
}

int answer(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}






int main(){
  int N;
  cin >> N;
  vector<vector<int>> to(N),cost(N);
  rep(i,N-1){
    int a,b,c;
    cin >> a >> b >> c;
    a--;b--;
    to[a].push_back(b);cost[a].push_back(c);
    to[b].push_back(a);cost[b].push_back(c);
  }
  
  vector<int> ans(N,-1);
  queue<int> q;
  ans[0] = 0;
  q.push(0);
  while(!q.empty()){
    int v = q.front();
    q.pop();
    rep(i,to[v].size()){
      int u = to[v][i];
      int c = cost[v][i];
      if(ans[u] != -1) continue;
      ans[u] = (ans[v] + c) %2;
      q.push(u);
    }
  }
  rep(i,N) cout << ans[i] << endl;

  
  return 0;
}







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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

// ex2だとまず先頭1文字だけを見るとb<aが確定
// 上2つはokだけど下2つでprefixの条件を破ってるからダメ
// こんな感じで条件を全部列挙して矛盾があったらno
// ex4の条件は b<c(1個目と2個目より) と c<b(3個目と4個目) で矛盾してるからダメ
// a<bならa->bに辺をつなげるとかして出来たグラフに閉路があれば矛盾してるとわかる

int n;
string s[500];
vi e[26];
bool vis[26], hei;

void rec(int v, int p) {
	vis[v] = 1;
	rep(i,e[v].size()) {
		if (e[v][i]==p) hei = 1;
		else if (!vis[e[v][i]]) rec(e[v][i],p);
	}
}

signed main() {
	while (1) {
		cin >> n;
		if (n==0) break;
		rep(i,26) e[i].clear();
		bool dame = 0;
		rep(i,n) {
			cin >> s[i];
			rep(j,i) if (s[j].size()>s[i].size() && s[j].substr(0,s[i].size())==s[i]) dame = 1; // prefix
		}
		if (dame) {
			cout << "no" << ln;
			continue;
		}
		// 条件追加
		rep(i,n) reps(j,i+1,n) {
			if (s[j].size()>=s[i].size() && s[j].substr(0,s[i].size())==s[i]) continue; // prefix
			rep(k,min(s[i].size(),s[j].size())) if (s[i][k]!=s[j][k]) {
				e[s[i][k]-'a'].pb(s[j][k]-'a');
				break;
			}
		}
		// 閉路検出
		hei = 0;
		rep(i,26) zero(vis), rec(i,i);
		cout << (hei ? "no" : "yes") << ln;
	}
}


Measured memory_bytes: 8396
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var nm = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var acNum = 0;
            var waNum = 0;
            var ac = new bool[nm[0]];
            var wa = new int[nm[0]];
            for (var i = 0; i < nm[1]; i++)
            {
                var ps = Console.ReadLine().Trim().Split(' ');
                var issue = int.Parse(ps[0]) - 1;
                var res = ps[1];
                if (ac[issue]) continue;
                if (res.Equals("AC"))
                {
                    ac[issue] = true;
                    acNum++;
                    waNum += wa[issue];
                }
                else
                {
                    wa[issue]++;
                }
            }
            Console.WriteLine($"{acNum} {waNum}");
        }
    }
}


Measured memory_bytes: 17740
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll A, B, N;
    cin >> A >> B >> N;

    ll i;
    if (B == 1) {
        cout << 0 << "\n";
    } else {
        ll i;
        if (B-1 <= N) i = B-1;
        else i = N;
        cout << (A*i)/B - A*(i/B) << "\n";
    }
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll s,w;


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>s>>w;
    if(s<=w){
        print("unsafe");
    }else{
        print("safe");
    }
    return 0;
}

Measured memory_bytes: 3656
import java.util.*;
 
 
import java.io.*;
 
public class Main {
	private static void solve(){
		//Implement solution here.
		char[] s = next().toCharArray();
		char[] t = next().toCharArray();
		int result = 0;
		for(int i = 0; i < 3; i++) {
			if(s[i] == t[i]) {
				result++;
			}
		}
		System.out.println(result);
		
	}
 
	//Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
		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: 21204
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    a,v=MI()
    b,w=MI()
    t=II()
    if v<=w:ans="NO"
    elif abs(a-b)<=t*(v-w):ans="YES"
    else:ans="NO"
    print(ans)

main()

Measured memory_bytes: 9212
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner();
        int N = in.nextInt();

        String sn = Integer.toString(N);

        int length = sn.length();
        int sum = 0;

        for (int i = 0; i < length; i++)
        {
            char digit = sn.charAt(i);
            int idigit = Character.getNumericValue(digit);
            sum += idigit;
        }
        if (N%sum == 0)
        {
            System.out.println("Yes");
        }
        else
            {
                System.out.println("No");
            }


    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

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

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

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

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

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


Measured memory_bytes: 21332
N = int(input())
A = list(map(int, input().split()))
A.sort()
if A[1] >= 0:
	print(sum(A) - 2 * A[0])
	y = A[0]
	for i in range(N - 2):
		print(y, A[i + 1])
		y -= A[i + 1]
	print(A[-1], y)
elif A[-1] < 0:
	print(-sum(A) + 2 * A[-1])
	y = A[-1]
	for i in range(N - 1):
		print(y, A[i])
		y -= A[i]
else:
	n = len([i for i in A if i < 0])
	print(-sum(A[:n]) + sum(A[n:]))
	y = A[0]
	for i in range(N - n - 1):
		print(y, A[-i - 2])
		y -= A[-i - 2]
	print(A[-1], y)
	y = A[-1] - y
	for i in range(n - 1):
		print(y, A[i + 1])
		y -= A[i + 1]

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

int main()
{
	while (true)
	{
		int I[21];
		int a, L;
		cin >> a >> L;
		I[0] = a;
		if (a == 0 && L == 0)break;
		for (int cnt = 1; cnt < 21; cnt++)
		{	
			bool end = false;
			int n = 1;
			int Max = 0;
			int Min = 0;
			for (int m = 1; m < L; m++)n = n * 10;
			int m1 = n;
			int m2 = n;
			int* pt;
			pt = new int[L];
			for (int l = 0; l < L; l++,n=n/10)
			{
				pt[l] = int(a / n);
				if (pt[l] != 0)a = a-(int(a/n)*n);
			}
			sort(pt,&pt[L]);
			for (int n = 0; n < L; n++)
			{
				if (pt[n] != 0)
				{
					Min +=pt[n] * m1;
				}
				m1 = m1 / 10;
			}
			reverse(pt, &pt[L]);
			for (int n = 0; n < L; n++)
			{
				if (pt[n] != 0)
				{
					Max += pt[n] * m2;
				}
				m2 = m2 / 10;
			}
			I[cnt] = Max - Min;
			for (int i = 0; i < cnt; i++)
			{
				if (I[cnt] == I[i])
				{
					cout << i << " " << I[cnt] << " " << cnt - i << endl;
					end = true;
					break;
				}
			}
			if (end==true)break;
			a = I[cnt];
		}//for
	}//while
	return 0;
}

Measured memory_bytes: 3076
#include<stdio.h>
int main()
{
    int i;
    char a[4];
    scanf("%s",a);
    for( i=0;i<3;i++)
    {
        //printf("%d\n",i);

        if(a[i]==a[i+1])
            break;
    }
    //printf("%d\n",i);
    if(i==3)
        printf("Good");
    else
        printf("Bad");
    return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();

		int[] arr = new int[n];
		int[] cnt = new int[n];
		for(int i = 0; i < n; ++i) {
			arr[i] = in.nextInt();
			while(arr[i] % 2 == 0) {
				++cnt[i];
				arr[i] /= 2;
			}
		}


		int ans = cnt[0];
		for(int i = 0; i< n; ++i)
			ans = Math.min(ans, cnt[i]);

		System.out.println(ans);
	}
}


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

int main()
{
	int n, time, c[100], t[100], min = 1001;

	cin >> n >> time;

	for (int i = 0; i < n; i++) {
		cin >> c[i] >> t[i];
		if (time >= t[i] && min > c[i]) {
			min = c[i];
		}
	}

	if (min != 1001)
		cout << min << endl;
	else
		cout << "TLE" << endl;

	return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for ai in range(a + 1):
    for bi in range(b + 1):
        for ci in range(c + 1):
            if (500 * ai + 100 * bi + 50 * ci == x):
                cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <typeinfo>
#define _USE_MATH_DEFINES
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

bool linearSearch(int S[], int BANPEI, int t) {
    int j = 0;
    while (S[j] != t) {
        j++;
        if (S[j] == BANPEI) {
            return false;
        }
    }
    return true;
}

int main(){
    int n, q, c;
    cin >> n;
    int S[n+1];
    for (int i = 0; i < n; i++) {
        cin >> S[i];
    }
    // 番兵値
    int BANPEI = 10010;
    S[n] = BANPEI;

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

    // counter
    c = 0;
    for (int i = 0; i < q; i++) {
        bool found = linearSearch(S, BANPEI, T[i]);
        if (found) {
            c++;
        }
    }
    cout << c << endl;

    return 0;
}



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

using namespace std;

int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++) {
    vec.at(i) = i + 1;
  }
  
  int count;
  
  for (int i = 0; i < N; i++) {
    int a = vec.at(i);
    if (a < 10) {
      count++;
    }
    else if (a > 99 && a < 1000) {
      count++;
    }
    else if (a > 9999 && a < 100000) {
      count++;
    }
  }
  cout << count << endl;
}

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

int main(){
	int l[10], v0, v1;
	string in;
	while( cin >> in ){
		sscanf( in.c_str(), "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&v0,&v1 );
		int sum=0;
		for( int i=0; i<10; i++ ){
			sum += l[i];
		}
		double t = (double)sum / (double)(v0+v1);
		double len = t * v0;
		int i=0;
		for(; i<10; i++ ){
			len -= l[i];
			if( len <= 0.0 )	break;
		}
		cout << i+1 << endl;
	}
	return 0;
}

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

typedef unsigned long long ull;

int main()
{
	int N, M, L, R;
	int mn = -1, mx = 1000001;
	scanf("%d%d", &N, &M);
	for (int i = 0; i < M; ++i) {
		scanf("%d%d", &L, &R);
		mx = min(mx, R);
		mn = max(mn, L);
	}
  	int ans = mx - mn + 1;
	printf("%d", ans >= 0 ? ans : 0);
}

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

fn parse_line<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn parse_pair<T: FromStr, U: FromStr>() -> (T, U) {
    let line = parse_line::<String>();
    let mut iter = line.split_whitespace();
    (
        iter.next().unwrap().parse().ok().unwrap(),
        iter.next().unwrap().parse().ok().unwrap(),
    )
}

fn println<T: ToString>(s: T) {
    println!("{}", s.to_string());
}

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

fn main() {
    let (l, r) = parse_pair::<usize, usize>();

    const DIVISOR: usize = 2019;

    let i_range = (l..r).take(DIVISOR);
    let mut min_mod = DIVISOR - 1;

    'outer: for i in i_range {
        let j_range = (i + 1..r + 1).take(DIVISOR);
        for j in j_range {
            let cur_mod = (i * j) % DIVISOR;
            if cur_mod < min_mod {
                min_mod = cur_mod;
                if min_mod == 0 {
                    break 'outer;
                }
            }
        }
    }

    println(min_mod);
}


Measured memory_bytes: 4352
N = int(input())
d = {}
for i in range(N):
    A, B = map(int, input().split())
    if d.get(B) is None:
        d[B] = [A]
    else:
        d[B].append(A)

ans = 1
works = 0

for k in sorted(d):
    if works + sum(d[k]) > k:
        ans = 0
        break
    works += sum(d[k])
if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 47868
#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-1; i >= 0; i--)
#define all(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
const int mod = 1e9+7;

int main() {
    int n;
    cin >> n;
    int p[n];
    rep(i, n) {
        cin >> p[i];
        p[i]--;
    }
    int cnt = 0;
    rep(i, n) {
        if (p[i] == i) {
            if (i == n - 1) {
                swap(p[i], p[i - 1]);
                cnt++;
            } else {
                swap(p[i], p[i + 1]);
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3956
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
typedef long long ll;
using namespace std;

void solve(void)
{
	ll x;
	cin>>x;
	if(x==1)
		cout<<0<<endl;
	else
		cout<<1<<endl;
}

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll testcase;
	//cin>>testcase;
	//while(testcase--)
	{
		solve();
	}
	return 0;
}


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

using namespace std;

int gcd(int a, int b){
	return b == 0 ? a : gcd(b, a % b);
}

queue <int> A, B, C, D;
vector <int> ans;
int n;

void res(){
	ans.clear();
	while(!A.empty()) A.pop();
	while(!B.empty()) B.pop();
	while(!C.empty()) C.pop();
	while(!D.empty()) D.pop();
}

int main(){
	cin >> n;
	if(n == 3){
		cout << "2 5 63\n";
		return 0;
	}
	for(int i = 2; i <= 30000; ++i){
		if(i % 3 == 0){
			if(i % 2 == 1) A.push(i);
			else B.push(i);
		}
		if(i % 2 == 1) continue;
		if(i % 3 == 1) C.push(i);
		if(i % 3 == 2) D.push(i);
	}
	ans.push_back(A.front()); A.pop();
	ans.push_back(A.front()); A.pop();
	n -= 2;
	while(n > 1 && !C.empty()){
		ans.push_back(C.front()); C.pop();
		ans.push_back(D.front()); D.pop();
		n -= 2;
	}
	while(n > 1 && !A.empty()){
		ans.push_back(A.front()); A.pop();
		ans.push_back(A.front()); A.pop();
		n -= 2;
	}
	while(n > 0 && !B.empty()){
		ans.push_back(B.front()); B.pop();
		n -= 1;
	}
	for(auto u : ans) printf("%d ", u);
	printf("\n");
	assert(n == 0);
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define PI 3.141592653589793
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  if(K <= A) cout << K << endl;
  else if(K <= A+B) cout << A << endl;
  else cout << A - (K - A - B) << endl;
}

Measured memory_bytes: 3636
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		while(true){
			String in=br.readLine();
			String[] s=in.split(" ");
			int a=Integer.parseInt(s[0]);
			String op=s[1];
			int b=Integer.parseInt(s[2]);
			switch(op){
			case "+":System.out.println(a+b);break;
			case "-":System.out.println(a-b);break;
			case "*":System.out.println(a*b);break;
			case "/":System.out.println(a/b);break;
			case "?":return;
			}
		}
	}
}


Measured memory_bytes: 26292
def prime(n):
	prime = [2,3,5]
	for i in range(6,n+1):
		check = True
		for k in range(2,int(i**0.5)+1):
			if i%k == 0:
				check = False
				break
		if check:
			prime.append(i)
	return prime

prime = prime(100000)
data = dict()
for i in range(1,100001):
	data[i] = 0
for k in range(len(prime)):
	data[prime[k]] = 1

anotherdata = dict()
for i in range(0,100001):
	anotherdata[i] = 0
counter = 1
for k in range(1,len(prime)):
	if data[(prime[k]+1)/2] == 1:
		anotherdata[prime[k]] = counter
		counter += 1
anotherdata[1] = 0
anotherdata[2] = 0
for e in range(3,100001):
	if anotherdata[e] == 0:
		anotherdata[e] = anotherdata[e-1]

q = int(input())
for i in range(q):
	l,r = map(int,input().split())
	print(anotherdata[r]-anotherdata[l-1])

Measured memory_bytes: 27672
#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 pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;
 
const ll INF=(1ll<<31)-1;
int a[100001];
int b[1005];
int main(){
    int n,q;
    cin>>n>>q;
    int sqn=sqrt(n);
    int bn=(n+sqn-1)/sqn;
    rep(i,n) a[i]=0;
    rep(i,bn) b[i]=0;
    int com;
    rep(i,q){
        cin>>com;
        if(com==0){
            int k,x;
            cin>>k>>x;
            --k;
            a[k]+=x;
            int cur=k/sqn; 
            b[cur]+=x;
        }
        if(com==1){
            //[s,t)
            int s,t;
            cin>>s>>t;
            --s;
            int ans=0;
            rep(j,bn+1){
                int l=j*sqn,r=(j+1)*sqn;
                if(r<=s||t<=l) continue;
                if(s<=l&&r<=t) ans+=b[j];
                else{
                    FOR(k,max(s,l),min(t,r)){
                        ans+=a[k];
                    }
                }
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3480
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  int n;
  cin >> n >> s >> t;
  int i,j;
  int chk=0;
  int len = s.length()+t.length();
  for(i=0;i<s.length()&&chk==0;i++){
    if(s[i]==t[0]){
      chk=1;
      for(j=1;j<s.length()-i;j++){
        if(s[i+j]!=t[j])chk=0;
      }
    }
    if(chk==1){
      len -= (s.length()-i);
    }
  }

cout << len;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>

#define N 100000

using namespace std;

struct Process{char name[10]; int time;};

Process Queue[N];
int head = 0, tail = 0;

void push(Process data){
    Queue[tail % N] = data;

    ++tail;
}

Process pop(){
    Process ret;
    ret = Queue[head % N];

    ++head;

    return ret;
}

int main(){
    int time_sum=0;

    int n, q;

    cin >> n >> q;

    Process tmp;
    for (int i = 0; i < n; ++i) {
        cin >> tmp.name >> tmp.time;

        if (tmp.time > q){
            time_sum += q;
            tmp.time -= q;
            push(tmp);
        }else{
            time_sum += tmp.time;
            printf("%s %d\n", tmp.name, time_sum);
        }
    }

    while (head != tail){
        tmp = pop();

        if (tmp.time > q){
            time_sum += q;
            tmp.time -= q;
            push(tmp);
        }else{
            time_sum += tmp.time;
            printf("%s %d\n", tmp.name, time_sum);
        }
    }
}

Measured memory_bytes: 4636
n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
x = a[0]
result = [abs(sum_a-2*x)]
for i in range(1, n-1):
    x += a[i]
    result.append(abs(sum_a-2*x))
print(min(result))

Measured memory_bytes: 24812
using System;
using System.Linq;

namespace AGC005
{
    class A
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int delete_count = 0;
            int s = 0;

            for (int i = 0; i < S.Length; i++)
            {
                if (S[i] == 'S') s++;
                else
                {
                    if (0 < s) { delete_count++; s--; }
                }
            }

            Console.WriteLine(S.Length - 2 * delete_count);
        }
    }
}

Measured memory_bytes: 11616