akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k,c=0;
	cin >> n >> k;
	int a[n];
	for(int i=0;i<n;i++)
		cin >> a[i];
	for(int i=0;i<(n-1);i+=(k-1)){
		c++;
	}
	cout << c;
}

Measured memory_bytes: 640
N,M = map(int,input().split())

E = [[] for _ in range(N)]
rE = [0]*N

for _ in range(M):
  x,y = map(int,input().split())
  E[x-1].append(y-1)
  rE[y-1] += 1

memo = [0]*N

Q = [x for x in range(N) if not rE[x]]

while Q:
  v = Q.pop()
  m = memo[v]+1
  for u in E[v]:
    memo[u] = max(memo[u], m)
    rE[u] -= 1
    if not rE[u]:
      Q.append(u)

print(max(memo))

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

int main() {
    int N = 50000;
    vector<int> primes;
    vector<bool> is_prime(N,true);

    for (int j=2; j<=N; j++) {
        if(is_prime[j]){
            for (int k=2; k<=N/j;k++){
                is_prime[j*k] = false;
            }
        }
    }

    while(1){
        int n;
        cin >> n;
        int m = n/2;
        if (n == 0) break;
        int res = 0;
        for (int j=2;j<=m;j++) {
            if(is_prime[j] && is_prime[n-j]){
                res++;
            }
        }
        cout << res << endl;
    }
}


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

int main() {
    // 頂点数と辺数
    int N, M; cin >> N >> M;

    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    // BFS のためのデータ構造
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = v;
            que.push(nv);
        }
    }

    // 結果出力 (各頂点の頂点 0 からの距離を見る)
    cout<<"Yes"<<endl;
    for (int v = 1; v < N; ++v) cout <<  dist[v]+1 << endl;
}

Measured memory_bytes: 10156
#include<iostream>
#include<vector>
#include<cstring>
#include<cstdio>
#include<algorithm>

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> ii;

ll k,n,u,v,mn,f;

char str[10];

int main()
{
//     cin>>t;
//     while(t--){
//
//     }
    cin>>k>>n>>u;
    f=u;
    mn=1<<30;
    for(int i=1;i<n;i++){
        cin>>v;
        mn=min(mn,k-v+u);
        u=v;
    }
    cout<<min(mn,v-f)<<endl;
}


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

public class Main {
	static ArrayList<Integer>[] g;
	static int N;
	static int[] B;
	static int[] C;
	static long[] sum;

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			N = sc.nextInt();
			if (N == 0)
				break;
			String[] A = new String[N];
			B = new int[N];
			C = new int[N];
			String[][] D = new String[N][];
			HashMap<String, Integer> id = new HashMap<>();
			sum = new long[N];
			for (int i = 0; i < N; ++i) {
				A[i] = sc.next();
				B[i] = sc.nextInt();
				C[i] = sc.nextInt();
				D[i] = new String[C[i]];
				for (int j = 0; j < C[i]; ++j) {
					D[i][j] = sc.next();
				}
				id.put(A[i], i);
			}
			for (int i = N - 1; i >= 0; --i) {
				sum[i] = (i + 1 < N ? sum[i + 1] : 0) + B[i];
			}

			g = new ArrayList[N];
			for (int i = 0; i < N; ++i)
				g[i] = new ArrayList<>();

			for (int i = 0; i < N; ++i) {
				for (int j = 0; j < C[i]; ++j) {
					int dst = id.get(D[i][j]);
					g[i].add(dst);
					g[dst].add(i);
				}
			}
			opt = B[0];
			System.out.println(dfs(1, 1, B[0]) + B[0]);
			System.gc();
		}
	}

	static long opt;

	static long dfs(long used, int cur, long cursum) {
		if (cur >= N)
			return 0;
		if (sum[cur] + cursum < opt) {
			return 0;
		}
		long res = 0;
		boolean unadj = true;
		boolean unrestriected = true;
		for (int dst : g[cur]) {
			if (!(dst < cur && ((used >> dst) & 1) == 0)) {
				unadj = false;
			}
			if (((used >> dst) & 1) == 1) {
				unrestriected = false;
			}
		}
		if (unrestriected) {
			res = Math.max(res, dfs(used | (1L << cur), cur + 1, cursum + B[cur]) + B[cur]);
		}
		if (!unadj) {
			res = Math.max(res, dfs(used, cur + 1, cursum));
		}
		opt = Math.max(opt, cursum + res);
		return res;
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define f         first
#define s           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)



void solve(){
    long n,k;cin>>n>>k;
    long r,s,p;cin>>r>>s>>p;
    string t;cin>>t;
    map<char,char> m;
    map<char,long> l;
    m['r']='p';
    m['p']='s';
    m['s']='r';
    l['r']=r;
    l['p']=p;
    l['s']=s;

    long ans=0;
    char a[t.length()];
    for(int i=0;i<k;i++){
        for(int j=i;j<t.length();j+=k){
            if(j==i){
                a[j]=m[t[j]];
                ans+=l[a[j]];
                continue;
            }
            if(t[j-k]==t[j] && a[j-k]==m[t[j-k]]){
                if(t[j+k]==t[j]){
                    a[j]=t[j];
                }
                else{
                    a[j]=t[j+k];
                }
            }
            else{
                a[j]=m[t[j]];
                ans+=l[a[j]];
            }
        }
    }

    cout<<ans;


}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long t=1;
    //cin>>t;
    while(t--){

        solve();
    }
    return 0;
}


Measured memory_bytes: 592
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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 main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  // ll n, m;
  // cin >> n >> m;
  ll k, a, b;
  cin >> k >> a >> b;
  if(b - a > 2 && k >= a + 1 ) {
    ans += b;
    k -= (a + 1);
    ans += (k / 2) * (b - a);
    ans += k % 2;
  }
  else
    ans = 1 + k;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
N=int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

# N = 10**5
# a = [0 for i in range(N+1)]
# b = [0 for i in range(N)]

cnt = 0
for i in range(N):
    num = min(a[i], b[i])
    a[i] -= num
    b[i] -= num
    cnt += num
    num2 = min(a[i+1], b[i])
    a[i+1] -= num2
    b[i] -= num2
    cnt += num2
    # print(a,b)
print(cnt)

Measured memory_bytes: 82148
from collections import deque
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

def get_next(x, y, costs, S, cost):
    ans = list()
    if x != 0 and costs[x-1][y] == -1 and S[x-1][y] == ".":
        ans.append([x-1, y])
        costs[x-1][y] = cost + 1

    if x != H-1 and costs[x+1][y] == -1 and S[x+1][y] == ".":
        ans.append([x+1, y])
        costs[x+1][y] = cost + 1

    if y != 0 and costs[x][y-1] == -1 and S[x][y-1] == ".":
        ans.append([x, y-1])
        costs[x][y-1] = cost + 1

    if y != W-1 and costs[x][y+1] == -1 and S[x][y+1] == ".":
        ans.append([x, y+1])
        costs[x][y+1] = cost + 1

    return ans

costs = [[-1 for _ in range(W)] for _ in range(H)]
costs[0][0] = 0
q = deque()
q.append([0, 0])
while len(q) and costs[H-1][W-1] == -1:
    now = q.popleft()
    nxt = get_next(now[0], now[1], costs, S, costs[now[0]][now[1]])
    for dot in nxt:
        q.append([dot[0], dot[1]])
    
fin_cost = costs[H-1][W-1]
if fin_cost == -1:
    print(-1)
else:
    w_cnt = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] == ".":
                w_cnt += 1
    print(w_cnt - fin_cost - 1)


Measured memory_bytes: 9424
#include<stdio.h>
int main(){
  int N,M;
  scanf("%d %d", &N,&M);
  bool b[N];
  for(int i=0;i<N;i++)b[i] = false;
  b[0] = true;
  int c[N];
  for(int i=0;i<N;i++)c[i] = 1;
  for(int i=0;i<M;i++){
    int x,y;
    scanf("%d %d", &x, &y);
    x--;
    y--;
    if(b[x]) {
      if(c[x] > 1) {
        b[y] = true;
      }else{
        b[y]=true;
        b[x]=false;
      }
    }
    c[x]--;
    c[y]++;
  }
  int res= 0 ;
  for(int i=0;i<N;i++)if(b[i])res++;
  printf("%d\n",res);
}

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

int main() {
	// your code goes here
	int x, n, a;
	if(n == 0){
		cout << x << endl;
		return 0;
	}
	cin >> x >> n;
	set<int> s;
	for(int i = 0;i < n; ++i){
		cin >> a;
		s.insert(a);
	}
	int ans1 = x, ans2 = x;
	while(true){
		if(!s.count(ans1)){
			cout << ans1 << endl;
			return 0;
		}
		if(!s.count(ans2)){
			cout << ans2 << endl;
			return 0;
		}
		--ans1;
		++ans2;
	}
	return 0;
}

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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;

int N,M;
vector<pair<int,int>> G[100000];
int kyori[100000] = {0};
bool pathed[100000] = {0};
bool dfs(int now){
  pathed[now] = true;
  bool flag = true;
  for(auto n:G[now]){
    if(kyori[n.first] != 0 && kyori[n.first] != kyori[now] + n.second){
      flag = false;
    }
    kyori[n.first] = kyori[now] + n.second;
    if(pathed[n.first] == false){
      flag &= dfs(n.first);
    }
  }
  return flag;
}
int main(){
  cin>>N>>M;
  int cnt[100000] = {0};
  for(int i(0);i<M;i++){
    int a,b,l;
    cin>>a>>b>>l;
    a--;b--;
    G[a].push_back({b,l});
    cnt[b]++;
  }
  if(M==0){
    cout << "Yes" << endl;
    return 0;
  }
  bool flag(false);
  for(int i(0);i<N;i++){
    if(cnt[i] == 0 && int(G[i].size() != 0)){
      flag = true;
      if(dfs(i) == false){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 16176
from itertools import product
from collections import namedtuple
A, B, C, D, E, F = map(int, input().split())

r100 = lambda x: range(F//(100*x)+1)
cct = 0
sw = namedtuple('sw', ['suger', 'water']) #suger_water
ans = sw(0, A*100)
for a, b in product(r100(A), r100(B)):
    water = (a * A + b * B) * 100
    if water > F or water == 0:
        continue
    r = lambda x: range((F-water)//x+1)
    for c, d in product(r(C), r(D)):
        suger = c * C + d * D
        if  water + suger > F:
            continue

        if suger * 100 > water * E:
            continue
        
        if water+suger == 0:
            continue

        if cct < 100 * suger/(suger+water):
            cct = 100 * suger/(suger+water)
            ans = sw(suger, water)

print(ans.suger+ans.water, ans.suger)

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

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    bool bigB = false;
    bool bigC = false;

    int i = 0;
    while(i <= K) {
        if(B > A) {
            bigB = true;
            break;
        }
        B *= 2;
        i++;
    }
    
    while(i <= K) {
        if(C > B) {
            bigC = true;
            break;
        }
        C *= 2;
        i++;
    }

    if(bigB && bigC) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3616
def f(h,w):
  global W,H,S,A
  if h<0 or h>=H or w<0 or w>=W or S[h][w]=="#" or A[h][w]==1:
    return
  A[h][w] = 1
  f(h-1,w)
  f(h+1,w)
  f(h,w-1)
  f(h,w+1)
while True:
  W,H = map(int,input().split())
  if W+H == 0:
    break
  S = [list(input()) for h in range(H)]
  A = [[0 for w in range(W)] for h in range(H)]
  for h in range(H):
    for w in range(W):
      if S[h][w] == "@":
        f(h,w)
        break
  ans = 0
  for i in A:
    ans += sum(i)
  print(ans)


Measured memory_bytes: 5716
# coding:utf-8
n,m,qq=map(int,input().split())
dp = [[0 for i in range(n+5)] for j in range(n+5)]
for i in range(m):
    l,r=map(int,input().split())
    l-=1
    r-=1
    dp[l][r]+=1
for i in range(n):
    for j in range(n-1):
        dp[i][j+1]+=dp[i][j]
for j in range(n):
    for i in range(n-1,0,-1):
        dp[i-1][j]+=dp[i][j]
for i in range(qq):
    p,q=map(int,input().split())
    p-=1
    q-=1
    if q==n-1:
        print(dp[p][q])
    else :
     print(dp[p][q]-dp[q+1][q])


Measured memory_bytes: 9460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

// 無限大の値を定義
const long long INF = 1LL << 60;

int main(){
    int N; 
    cin >> N;
    ll h[100010];
    for (int i = 0; i < N; i++){
        cin >> h[i];
    }

    ll dp[100010];

    // DP テーブル全体を初期化．最小化問題なので INF に初期化する．
    for (int i = 0; i < 100010; i++){
        dp[i] = INF;
    }

    // 初期条件
    dp[0] = 0;

    // dp[i] の値を更新し続ける
    for (int i = 1; i < N; i++){ // 足場 1 からスタートのため
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1){
            chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
        }
    }

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

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

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

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

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

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


int main()
{
  int n; cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<vector<int>> x(62, vector<int>(2, 0));
  mint ans = 0;

  rep(i, 62) {
    ll mask = 1ll<<i;
    ll one = 0, zero = 0;
    rep(j, n) {
      if(a[j] & mask) ++one;
      else ++zero;
    }
    mint add = mask;
    add *= one;
    add *= zero;
    ans += add;
  }
  cout << ans.x << endl;
}

Measured memory_bytes: 5480
#include <stdio.h>
                                                                                                
  
int main(void){
                                                                                                
   
    int a, b, c, i;
   
      
    scanf("%d %d %d", &a, &b, &c );
   

    for( i = 1 ; a * i <= a * b ; i = i + 1 ){

        if( ( a * i ) % b == c ){

            printf("YES\n");

            return 0;

            }

        }
   

    printf("NO\n");


    return 0;
                                                          
}

Measured memory_bytes: 128
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>

using namespace std;


int main(int argc, const char * argv[]) {
    
    int n, num = 0;
    string ans = "APPROVED";
    
    cin >> n;
    
    int a[n];
    
    for(int i=0; i<n; i++)
    {
        cin >> a[i];
        
        if(a[i] % 2 == 0)
        {
            if(a[i] % 3 == 0 || a[i] % 5 == 0) ans = "APPROVED";
            else num++;
        }
    }
    
    if(num > 0) ans = "DENIED";
    
    cout << ans << endl;
    
    return 0;
}


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

const int maxn = 3005;
int N;
double p[maxn];
double dp[maxn][maxn]; //dp[i][j]

double f(int i, int j) {
    if (dp[i][j] != -1) return dp[i][j];
    if (j * 2 > N) {
        return dp[i][j] = 1;    
    }
    if (i == N + 1) {
        return dp[i][j] = 0;
    }
    return dp[i][j] = p[i] * f(i+1,j+1) + (1-p[i]) * f(i+1,j);
}
    
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N;
    for (int i = 1; i <= N; i++) cin >> p[i];
    for (int i = 1; i <= N+1; i++) {
        for (int j = 0; j <= N; j++) {
            dp[i][j] = -1;
        }
    }
    double ans = f(1,0);
    cout << fixed << setprecision(10) << ans << '\n';

    return 0;
}



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

int main() {
  
  string s; ll q;
  cin >> s >> q;
  string u;
  
  rep(i,q) {
    ll t;
    cin >> t;
    if (t==1)  swap(s,u);
    if (t==2) {
      ll f; char c;
      cin >> f >> c;
      if (f==1) u += c;
      if (f==2) s += c;
    }
  }
  
  reverse(u.begin(), u.end());
  u += s;
  cout << u << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int w, s;
    cin >> s >> w;
    cout << (w >= s ? "unsafe" : "safe") << endl;
    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		String[] temp = new String[N];
		for (int i = 0; i < M; i++) {

			int s = sc.nextInt();
			int c = sc.nextInt();

			if(temp[s-1] != null && Integer.parseInt(temp[s-1]) != c) {
				System.out.println(-1);
				return;
			}
			temp[s-1] = String.valueOf(c);
		}

//		if(M==0) {
//			if(N==1) {
//				System.out.println(0);
//			} else {
//				System.out.println(-1);
//			}
//			return;
//		}

		if(temp[0] != null && N>=2 && Integer.parseInt(temp[0]) == 0) {
			System.out.println(-1);
			return;
		}

		StringBuilder result = new StringBuilder();

		for (int i = 0; i < N; i++) {

			if(i == 0 && temp[0] == null && N != 1) {
				result.append("1");
				continue;
			}

			if(temp[i] != null) {
				result.append(temp[i]);
			} else {
				result.append("0");
			}
		}

		int resultInt = Integer.parseInt(result.toString());
		if(N ==1 && resultInt == 0) {
			System.out.println(0);
			return;
		}

		if((int)Math.pow(10, N-1) <= resultInt && (int)Math.pow(10, N) > resultInt) {
			System.out.println(Integer.parseInt(result.toString()));
		} else {
			System.out.println(-1);
		}
	}
}

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

int main(void){
  // Keyence2020 B Robot Arms
  int n, x, l, ans, cur, i;
  scanf("%d", &n);
  vector<pair<int, int>> ps(n);
  for (i = 0; i < n; i++){
    scanf("%d %d", &x, &l);
    ps[i] = {x + l, x - l};
  }

  sort(ps.begin(), ps.end());
  ans = n, cur = ps[0].first;
  for (i = 1; i < n; i++)
    if (ps[i].second < cur)
      --ans;
    else
      cur = ps[i].first;

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 4060
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define MOD 1000000007
using namespace std;

vector<pair<int,ll> >a;
vector<vector<ll> > dp;

ll solve(int id,int w,const int n){
	if(id==n)
		return 0;
	ll& ans=dp[w][id];
	if(ans!=-1)
		return ans;
	if(a[id].ff<=w){
		return ans=max(a[id].ss+solve(id+1,w-a[id].ff,n),solve(id+1,w,n));
	}
	else
		return ans=solve(id+1,w,n);
}

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);cout.tie(NULL);
	int n,w;
	cin>>n>>w;
	a.resize(n);
	dp.assign(w+1,vector<ll> (n,-1));
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i].ff>>a[i].ss;
	}
	cout<<solve(0,w,n);
	// cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
	return 0;
}

Measured memory_bytes: 82304
use proconio::input;

fn solve(n: usize, k: usize, mut p: Vec<i32>) -> i32 {
    p.sort();
    p.iter().take(k).sum::<i32>()
}

fn main() {
    input! {
        n: usize,
        k: usize,
        p: [i32; n],
    }
    let r = solve(n, k, p);
    println!("{}", r);
}


Measured memory_bytes: 2196
#include<iostream>
#include<string>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<functional>
#include<cmath>
#include<unordered_map>
#include<utility>

#define REP(i,n) for(int i=0;i<n;i++)
#define ll long long int

using namespace std;

int to_int(string s) {
  return atoi(s.c_str());
}

int map[500][500];
int p[100000];
int q[100000];

int main() {
  int m,n,Q;
  cin >> n >> m >> Q;
  REP(i,m) {
    int x,y;
    cin >> x >> y;
    for(int j = y-1; j < n; j++) {
      map[x-1][j]++;
    }
  }
  REP(i,Q) cin >> p[i] >> q[i];
  REP(i,Q) {
    int ans = 0;
    for(int j = p[i] - 1; j < q[i]; j++) {
      if(p[i] == 1) {
        ans += map[j][q[i] - 1];
      } else {
        ans += map[j][q[i] - 1] - map[j][p[i] - 2];
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

using Lint=long long;

class UnionFind
{
 public:
    vector<int> par,sz;
    UnionFind(int N):par(N),sz(N){
        for(int i=0;i<N;i++){
            par[i]=i; sz[i]=1;
        }
    }
    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x); y=find(y);
        if(x==y) return;
        if(sz[x]<sz[y]) swap(x,y);
        par[y]=x;
        sz[x]+=sz[y];
    }
    bool same(int x,int y){ return find(x)==find(y); }
    int size(int x){ return sz[find(x)]; }
    bool root(int x){ return par[x]==x; }
};

struct edge{
    int u,v,cost;
    bool operator<(const edge &e){
        return cost<e.cost;
    }
};

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

    int N; cin>>N;
    vector<edge> es;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            int c; cin>>c;
            if(i<j and c!=-1) es.push_back({i,j,c});
        }
    }
    sort(es.begin(),es.end());

    int ans=0;
    UnionFind tree(N);
    for(edge e:es){
        if(!tree.same(e.u,e.v)){
            ans+=e.cost;
            tree.unite(e.u,e.v);
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

line = input().split(" ")
n = int(line[0])
k = int(line[1])
d = set(input().split(" "))

while True:
    s = set(list(str(n)))
    r = s - d
    if len(r)==len(s):
        print(n)
        exit()
    n += 1


Measured memory_bytes: 2940
<?php

while($line = fgets(STDIN)){
	$cnt = 0;
	$n = intval($line);
	for($a = 0; $a <= 9; $a++){
		for($b = 0; $b <= 9; $b++){
			for($c = 0; $c <= 9; $c++){
				for($d = 0; $d <= 9; $d++){
					if($a + $b + $c + $d == $n){
						$cnt++;
					}
				}
			}
		}
	}
	echo $cnt."\n";
}

Measured memory_bytes: 15040
q,h,s,d = gets.chomp.split(" ").map(&:to_i)
n = gets.to_i
ans = 0

min_1 = [q*4,h*2,s].min

if d/2 < min_1
  ans += (n/2) * d
  ans += (n%2) * min_1
else
  ans += n * min_1
end

puts ans

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int main()
{
 LL n;cin>>n;
 LL a[n],i,j,k=0,l,m;
 for(i=0;i<n;i++){cin>>a[i];k+=a[i];}
 cin>>m;
 LL x,y;
 for(i=0;i<m;i++){
cin>>x>>y;
j=k-a[x-1];j+=y;
cout<<j<<endl;
 }
 return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
#define ll              long long int
#define vll             vector<ll>
#define vs              vector <string>                                    
#define mll             map<ll,ll>
#define pll             pair<ll, ll>
#define vpll            vector < pair<ll,ll> >
#define itr             vll::iterator
#define all(c)          c.begin(),c.end()
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define pb              push_back
#define mb              make_pair
#define ff              first
#define ss              second
#define max3(a,b,c)     max(max(a,b),c)                                    
#define min3(a,b,c)     min(min(a,b),c)  
#define mod             1000000007
#define inf             1000000000000000001
#define from(i, n)      for(__typeof(n) i = 0; i <  n; ++i)
#define fromj(i, j, n)  for(__typeof(n) i = j; i <  n; ++i)
#define printv(v)       from(i,v.size())cout<<v[i]<<" ";cout<<"\n";
#define w(x)            int x; cin>>x; while(x--)
 
using namespace std;
using namespace __gnu_pbds; 
 
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
}
 
bool func(const pll &a, const pll &b){
    if(a.ss==b.ss)return a.ff<b.ff;
    return a.ss < b.ss;
}
 
typedef tree<int, null_type, less<int >, rb_tree_tag, 
             tree_order_statistics_node_update> pbds; 
 
int main(){
    c_p_c();
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n;
    cin>>n;
    vector<double> v(n);
    from(i,n){
    	cin>>v[i];
    	//cout<<v[i];
    } 	
    double a[n+1][(n+1)/2 +1 ];
    from(i,n+1)a[i][0]=1;
    fromj(i,1,(n+1)/2 +1)a[0][i]=0;
    fromj(i,1,n+1){
    	fromj(j,1,(n+1)/2 + 1){
    		if(j>i)a[i][j]=0;
    		else a[i][j]=a[i-1][j-1]*v[i-1] + a[i-1][j]*(1-v[i-1]);
    	}
    }
    /*from(i,n+1){
    	from(j,(n+1)/2 + 1){
    		cout<<a[i][j]<<" ";
    	}
    	cout<<"\n";
    }*/
    cout<<ps(a[n][(n+1)/2],10);
}

Measured memory_bytes: 39000
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

typedef long long ll;

int main(){
	ll N,Y;
	cin >> N >> Y;
	Y = Y/1000;  

	int x,y,z;
	for (int yi = 0; yi <= 1 ; yi++){
		for (int zi = 0; zi <= 4; zi++){
			if((Y-yi*5-zi)%10  == 0)
			{
				x = (Y-yi*5-zi) / 10;
				y = yi;
				z = zi;
				break;
			}
		}
	}
	//cout << ":" << x << " "<< y << " " << z << endl;
	int xyz;
	int x_ans = -1,y_ans = -1,z_ans = -1;

	for (int i = 0; i <= x; i++)
	{
		xyz = i + (x-i)*2 + y + z;
		if (N - xyz >= 0)
		{
			//cout << N-xyz << endl;
			if (N == xyz)
		 	{
		 		x_ans = i;
		 		y_ans = (x-i)*2 + y;
		 		z_ans = z;
		 		break;
		 	} 

		 	else if ((N - xyz)%4 == 0)
		 	{	
		 		if((x-i)*2+ y - (N-xyz)/4 >= 0){
		 			x_ans = i;
		 			y_ans = (x-i)*2+ y - (N-xyz)/4;
		 			z_ans = z + 5*((N-xyz)/4);
		 		}
		 	}
		}
	}
	cout<< x_ans << " "
		<< y_ans << " "
		<< z_ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    sort(all(S));
    sort(all(T));
    reverse(all(T));
    if (S < T) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        System.out.println(gcd(x, y));
    }

    static int gcd(int x, int y) {
        if (x < y)
            return gcd(y, x);
        if (y == 0)
            return x;
        return gcd(y, x % y);
    }
}


Measured memory_bytes: 26148
ans = list(map(int,input().split()))
ans.sort()
count = 0
if ans[0]==ans[1] and ans[1]==ans[2]:
    pass
else:
    count += ans[2] - ans[1]
    ans[0] += count
    if ans[0] == ans[1]:
        pass
    else:
        a = ans[2] - ans[0]
        if a%2 == 0:
            count += a//2
        else:
            count += (a+1)//2 + 1
print(count)


Measured memory_bytes: 3064
let main = (standardInput) => {
    let lengthList = standardInput.split(' ');
    let varticalLength = Number.parseInt(lengthList[0]);
    let horizonLength = Number.parseInt(lengthList[1]);

    console.log(`${varticalLength * horizonLength} ${2 * (varticalLength + horizonLength)}`);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));


Measured memory_bytes: 15112
#include<iostream>
#include<math.h>
using namespace std;

int main() {
	long long  Q;
	long long a[100], b[100];
	
cin >> Q;

for (int i = 0;i < Q;i += 1) {
		cin >> a[i] >> b[i];
     }
for (int i = 0;i < Q;i += 1) {
	long long c = sqrt(a[i] * b[i]);
	if (c *c == a[i] * b[i]) {
		c-=1;
	}
	if (a[i] > b[i]) {
		swap(a[i], b[i]);
	}
	if (a[i] == b[i]|| a[i] + 1 == b[i]) {
		cout << 2 * a[i] - 2 << endl;
	}
	else if (c*(c + 1) >= a[i] * b[i]) {
		cout << 2 * c - 2 << endl;
	}

	else if (c *c < a[i] * b[i] ) {
		cout << 2 * c - 1 << endl;
	}
	


}








}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pop pop_back
#define N (ll)(2e5+5)

ll dp[102][100009];

ll knapsack(ll wts[], ll val[], ll w, ll n)
{
    if (w == 0 or n == 0)
        return 0;
    if( dp[n][w] != -1)
        return dp[n][w];
    
    if (wts[n-1] <= w)
    {
        dp[n][w] = max(val[n-1] + knapsack(wts, val, w-wts[n-1], n-1),
         knapsack(wts, val, w, n-1));
        return dp[n][w];
    }
    else
    {
        dp[n][w] = knapsack(wts, val, w, n-1);
        return dp[n][w];
    }
}

void solve()
{   
    memset(dp, -1, sizeof(dp));
    ll n, w; cin>>n>>w; ll value[n], weights[n];
    for(ll i = 0; i<n; i++)
    {
        ll wi, vi; cin>>wi>>vi;
        value[i] = vi; weights[i] = wi;
    }
    ll ans = knapsack(weights, value, w, n);
    cout<<ans<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // ll t; cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<unsigned long> a(N);
    for(auto&& i : a)cin >> i;
    unsigned long S{accumulate(begin(a), end(a), 0UL, bit_xor<>())};
    for(const auto& i : a)cout << (S ^ i) << " ";
    cout << endl;
    return 0;
}

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

#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

   int A,B,C;
   cin>>A>>B>>C;

   for(int i=1;i<B;i++){
      if((A*i)%B==C){
         cout<<"YES"<<endl;
         return 0;
      }
   }
   cout<<"NO"<<endl;
   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<utility>
#include<algorithm>
using namespace std;


int main (){
    string S;
    int flag;

    cin >> S;


    for(int i=0;i<S.length();i++){
        if(i%2 == 1){
            if(S[i] == 'R'){
                cout << "No" << endl;
                //cout << S[i] << i << endl;
                return 0;
                }
            }

        else{
            if(S[i] == 'L'){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX(x, y) (((x) > (y)) ? (x) : (y))

int main() {

	unsigned short *A, *B;//, *C;

	int n, i;
	scanf("%d", &n);

	A = (unsigned short*)malloc(sizeof(short) * n + 1);
	B = (unsigned short*)malloc(sizeof(short) * n + 1);

	for (i = 0; i < n; i++) {
		scanf("%hu", &A[i+1]);
	}

	int max = (1<<30)*-1;
	for (i = 1; i <= n; i++) max = MAX(max, A[i]);
	int C[max+1] = {0};

	for (i = 0; i < n; i++) C[A[i+1]]++;
	for (i = 1; i <= max; i++) C[i] += C[i-1];

	for (i = n; i >= 1; i--) {
		B[C[A[i]]] = A[i];
		C[A[i]]--;
	}

	printf("%d", B[1]);
	for (i = 2; i <= n; i++) {
		printf(" %d", B[i]);
	}
	printf("\n");

	free(A);
	free(B);
	return 0;
}



Measured memory_bytes: 10296
#include<iostream>
#include<string>

int N;
void dfs(std::string s, char mc) {
  if(s.size() == N) { std::cout << s << std::endl; return; }
  for(char c = 'a'; c < mc; ++c) dfs(s+c, mc);
  dfs(s+mc, mc+1);
}

int main() {
  std::cin >> N;
  dfs("", 'a');
  return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <deque>
#include <cmath>
#include <map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include "iomanip"
#include <cstdio>
#include <cstring>
#include <set>
#include <vector>
#include <fstream>
#include <algorithm>
#include <queue>
#include <cassert>
#include <stack>


using namespace std;

void print(vector<int> &b);




void print(vector<int> &b) {
    for (auto i : b) {
        cout << i << " ";
    }
    cout << endl;
}


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

    string s;
    cin >> s;
    vector<int> v(26);
    for (char c : s){
        v[c - 'a']++;
    }

    for (int c : v){
       if (c > 1){
           cout << "no";
           return 0;
       }
    }

    cout << "yes";
    return 0;
}




Measured memory_bytes: 256
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]

dp = A
cnt = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if all(dp[i][j] < dp[i][k] + dp[k][j] for k in range(N) if k != i and k != j):
            cnt += dp[i][j]
        if any(dp[i][j] > dp[i][k] + dp[k][j] for k in range(N)):
            print(-1)
            exit()

print(cnt)


Measured memory_bytes: 50268
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int a,b;
int main()
{
	cin>>a>>b;
	if(a%3==0||b%3==0||(a+b)%3==0)
	cout<<"Possible"<<endl;
	else
	cout<<"Impossible"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define frfr  freopen("input.text","r",stdin); freopen("output.text","w",stdout)
#define ll long long int
#define wh int T;cin >> T;while(T--)
#define pb push_back
#define loop(i,a,b) for (int i = a; i < n; i++)
int main(){
    
     int l,r,d;
     cin >> l >> r >> d;
     int count = 0;
     for(int i=l;i<=r;i++){
      if(i%d == 0){
       count++;
      }
     }
     cout << count << endl; 
   
  return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>

int main()
{
  int A,B;
  int ans = 0;
  std::cin >> A >> B;
  std::string S;
  for(int i = A;i <= B;i++)
  {
    S = std::to_string(i);
    if ((S[0]==S[4]) and (S[1]==S[3])) ans += 1;
  }

  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
from sys import stdin,setrecursionlimit
from itertools import groupby
setrecursionlimit(10**6) 
n,q = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n-1)]
lin = [list(map(int,stdin.readline().rstrip().split())) for _ in range(q)]
kazu = [[]for _ in range(n+1)]
point = [0]*(n+1)
for i in li:
    kazu[i[0]].append(i[1])
    kazu[i[1]].append(i[0])
for i in lin:
    point[i[0]] += i[1]
def dfs(now,before):
    for i in (kazu[now]):
        if i == before:
            continue
        point[i] += point[now]
        dfs(i,now)
dfs(1,0)
print(*point[1:])

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

const long long MOD = 1e9+7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #define int long long
    
    int n, k;
    cin >> n >> k;
    
    vector <int> prefix_sums(200005, 0);
    
    for (int i=1; i<=200003; i++){
        prefix_sums[i] = prefix_sums[i-1] + i;
        //if (prefix_sums[i] >= MOD) prefix_sums[i] -= MOD;
    }
    
    //for (int i=0; i<=100; i++) cout << prefix_sums[i] << endl;
    
    int ans = 0;
    for (int i=k; i<=n+1; i++){
        int minimum_sum = prefix_sums[i-1];
        int maximum_sum;
        if (i != n+1)
        maximum_sum = prefix_sums[n] - prefix_sums[n-i];
        else maximum_sum = prefix_sums[n];
        ans =  ans + (maximum_sum - minimum_sum + 1);
        if (ans >= MOD) ans %= MOD;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 4776
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }





using Edge = pair<int, long long>;
using Graph = vector<vector<Edge> >;

int N;
Graph G;

vector<int> dir;
void dfs(int v, int p, int c) {
    dir[v] = c;
    for (auto e : G[v]) {
        if (e.first == p) continue;
        if (e.second & 1) dfs(e.first, v, 1-c);
        else dfs(e.first, v, c);
    }
}

int main() {
    while (cin >> N) {
        G.assign(N, vector<Edge>());
        for (int i = 0; i < N-1; ++i) {
            int u, v;
            long long w;
            cin >> u >> v >> w;
            --u, --v;
            G[u].push_back(Edge(v, w));
            G[v].push_back(Edge(u, w));
        }
        dir.assign(N, 0);
        dfs(0, -1, 1);
        for (auto v : dir) cout << v << endl;
    }
}


Measured memory_bytes: 10496
use proconio::input;

fn main() {
    input! {
        x: i32,
        n: usize,
        mut p: [i32; n]
    }
    p.sort();
    if p.binary_search(&x).is_err() {
        println!("{}", x);
        return;
    }
    let mut xl = x - 1;
    let mut xr = x + 1;
    loop {
        if p.binary_search(&xl).is_err() {
            println!("{}", xl);
            break;
        }
        xl -= 1;
        if p.binary_search(&xr).is_err() {
            println!("{}", xr);
            break;
        }
        xr += 1;
    }
}


Measured memory_bytes: 2164
#include <iostream>

int main(void){
  int n, m, k;
  std::cin >> n;
  m = n; k = n;
  n /= 100;
  k /= 10;
  if(n % 10 == 1) std::cout << "9";
  else if(n % 10 == 9) std::cout << "1";
  else std::cout << n%10;
  if(k % 10 == 1) std::cout << "9";
  else if(k % 10 == 9) std::cout << "1";
  else std::cout << k%10;
  if(m % 10 == 1) std::cout << "9";
  else if(m % 10 == 9) std::cout << "1";
  else std::cout << m%10;
  std::cout << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string.h>
#include<cmath>
#include<algorithm>
#include<assert.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define mem0(s) memset(s,0,sizeof(s))
#define meminf(s) memset(s,0x3f,sizeof(s))
#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))
double pi=acos(-1);
typedef long long ll;
typedef unsigned long long ull;
inline ll lowbit(ll x){return x&(-x);}
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll max(ll a,ll b){return a>b?a:b;}
const ll INF=4223372036854775807,max_n=300005,mod=1e9+7;
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
inline ll pow(ll a,ll b,ll mod){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll x;
ll a[105];
ll b[105];
ll ans;
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		for(int j=0;j<=60;j++)
		{
			if(x&(1LL<<j))
			{
				a[j]++;
			}
			else b[j]++;
		}
	}
	for(int i=0;i<=60;i++)
	{
		if(a[i]&&b[i])
		{
			ans=(ans+(1LL<<i)%mod*a[i]%mod*b[i]%mod)%mod;
		}
	}
	cout<<(ans+mod)%mod;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        int distanceXA = Math.abs(a - x);
        int distanceXB = Math.abs(b - x);

        if (distanceXA < distanceXB) {
            System.out.println("A");
        } else {
            System.out.println("B");
        }
    }
}


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

ll isPrime(ll num){
  long long div;
  if(num==2 || num==3){
    return 1;
  }else{
    for(div=2; div*div<=num; div++){
      if(num%div==0) return 0;
    }
  }
  return 1;
}

int main() {
  ll x;
  cin >> x;
  
  while(isPrime(x)==0) x++;
  cout << x << endl;
  return 0;
}


Measured memory_bytes: 256