akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

const int N = 2e5;

#ifdef LOCAL
ll val[N];
#endif

struct op {
  char c; 
  int i, j, k;
};

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  #ifdef LOCAL
  val[0] = 536870912; 
  val[1] = 536870912;
  #endif
  int a = 0, b = 1;
  int ZERO = N - 1;
  int ONE = N - 2;
  int tmp = N / 2;

  vector <op> ans; 
  auto write_sum = [&] (int k, int i, int j) {
#ifdef LOCAL
    val[k] = val[i] + val[j];
#else
    ans.push_back({'+', i, j, k});
#endif
  };
  auto write_smaller = [&] (int k, int i, int j) {
#ifdef LOCAL
    val[k] = (val[i] < val[j]);
#else
    ans.push_back({'<', i, j, k});
#endif
  };

  write_sum(tmp, a, b);
  write_smaller(ONE, ZERO, tmp);
  
  auto write_and = [&] (int k, int i, int j) {
    write_sum(k, i, j);
    write_smaller(k, ONE, k);
  };
  auto clear = [&] (int k) {
    write_sum(k, ZERO, ZERO);
  };
  auto copy = [&] (int i, int j) {
    // a[i] = a[j]
    write_sum(i, j, ZERO);
  };
  auto invert = [&] (int i, int j) {
    // a[j] = a[i] ^ 1
    write_smaller(j, i, ONE);
  };  
  auto if_operator = [&] (int i, int j, int k, int K) {
    // if (a[i]) a[k] = a[j]
    // else a[k] = 0
    copy(tmp, ONE);
    clear(k);
    for (int b = 1; b < K; ++b) {
      write_sum(tmp + b, tmp + b - 1, tmp + b - 1);
    }
    int sum = tmp + K;
    int tmp_sum = tmp + K + 1;
    clear(sum);
    int fl = tmp + K + 2;
    for (int b = K - 1; b >= 0; --b) {
      write_sum(tmp_sum, sum, tmp + b);
      write_smaller(fl, j, tmp_sum);
      invert(fl, fl);
      write_and(fl, fl, i);
      for (int t = 1; t <= b; ++t) {
        write_sum(fl + t, fl + t - 1, fl + t - 1);
      }
      write_sum(k, k, fl + b);
      write_sum(sum, sum, fl + b);
    }
  };
  const int K = 30;
  int st_pw2 = 3;
  copy(st_pw2, ONE);
  for (int b = 1; b < K; ++b) {
    write_sum(st_pw2 + b, st_pw2 + b - 1, st_pw2 + b - 1);
  }
  int st_pwb = st_pw2 + K;
  copy(st_pwb, b);
  for (int b = 1; b < K; ++b) {
    write_sum(st_pwb + b, st_pwb + b - 1, st_pwb + b - 1);
  }
  int sum = st_pwb + K;
  int tmp_sum = sum + 1;
  int fl = tmp_sum + 1;
  int go = fl + 1;
  int res = 2;
  for (int b = K - 1; b >= 0; --b) {
    write_sum(tmp_sum, sum, st_pw2 + b); 
    write_smaller(fl, a, tmp_sum); 
    invert(fl, fl);
    if_operator(fl, st_pw2 + b, go, 30); 
    write_sum(sum, sum, go);
    if_operator(fl, st_pwb + b, go, 60);
    write_sum(res, res, go);
  }
#ifdef LOCAL
  cout << val[2] << endl;
#else
  cout << ans.size() << '\n';
  for (auto o : ans) {
    cout << o.c << ' ' << o.i << ' ' << o.j << ' ' << o.k << '\n';
  }
#endif
}




Measured memory_bytes: 5220
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;



int main() {
  int n;
  scanf("%d",&n);
  vi a(n);
  cin>>a;
  ll x = 0;
  ll ans = 0;
  map<ll,int> mp;
  rep(i,n) {
    mp[x]++;
    x += a[i];
    ans += mp[x];
  }
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 13568
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int d;
    cin >> d;

    while(--d >= 0){
        int h, w;
        cin >> w >> h;

        int p;
        cin >> p;
        vector<vector<bool> > matatabi(2*(h+1), vector<bool>(2*(w+1), false));
        while(--p >= 0){
            int x1, y1, x2, y2;
            cin >> x1 >> y1 >> x2 >> y2;
            matatabi[y1+y2][x1+x2] = true;
        }
        for(int i=0; i<2*(w+1); ++i)
            matatabi[2*h+1][i] = true;
        for(int i=0; i<2*(h+1); ++i)
            matatabi[i][2*w+1] = true;

        vector<vector<int> > dp(h+1, vector<int>(w+1, 0));
        dp[0][0] = 1;
        for(int y=0; y<=h; ++y){
            for(int x=0; x<=w; ++x){
                if(!matatabi[2*y+1][2*x])
                    dp[y+1][x] += dp[y][x];
                if(!matatabi[2*y][2*x+1])
                    dp[y][x+1] += dp[y][x];
            }
        }

        if(dp[h][w] == 0)
            cout << "Miserable Hokusai!" << endl;
        else
            cout << dp[h][w] << endl;
    }

    return 0;
}

Measured memory_bytes: 1224
import java.util.*;


class Main
{
    public static void main(String[] args)throws Exception
    {
        Scanner sc = new Scanner(System.in);
        Deque <String> que = new ArrayDeque <>(); 
        String []s = new String [2];  
        int n = sc.nextInt();
        int quan = sc.nextInt();
        for(int i = 0; i<n;i++) 
        {
            que.add(sc.next()+" "+sc.next());
        }
        Iterator itr = que.iterator();
        int time = 0;
        while(true)
        {
            try
            {
                s= que.getFirst().split(" ");
            }
            catch(NoSuchElementException e) 
            {
                break;
            }
            int num = Integer.parseInt(s[1]);
            if(num>quan) 
            {
                time =  quan + time;
                num = num-quan;
                que.removeFirst();
                que.add(s[0].concat(" "+ String.valueOf(num)));
            }
            else if (num<=quan)
            {
                time =  num + time;
                que.removeFirst();
                System.out.println(s[0]+" "+ time);
            }
        }
    }
}
       





Measured memory_bytes: 105128
# import itertools
# import math
# import sys
# import numpy as np

# K = int(input())
# S = input()
# n, *a = map(int, open(0))
N, M = map(int, input().split())
H = list(map(int, input().split()))
# Q = list(map(int, input().split()))
# S = input()

# d = sorted(d.items(), key=lambda x:x[0]) # keyでsort
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement([i for i in range(1, M + 1)], N))
# print(a[0][0])
# print(conditions[0])

flgs = [1] * N
for i in range(M):
    a, b = map(int, input().split())
    if H[a - 1] <= H[b - 1]:
        flgs[a - 1] = 0
    if H[a - 1] >= H[b - 1]:
        flgs[b - 1] = 0
print(sum(flgs))

Measured memory_bytes: 20060
/* ex 7_3
   アカウント名 */

#include <stdio.h>
#include <stdlib.h>


int main(void){
    int i, j, k, row, column;
    char tmp;
    char **ptr;
    scanf("%d %d\n", &row, &column);
    int row_flag[row], column_flag[column];
    ptr = (char**)calloc(row, sizeof(char*));
    if(ptr == NULL){
        exit(1);
    }
    for(i = 0; i < row; i++){
        ptr[i] = (char*)calloc(column, sizeof(char));
        if(ptr[i] == NULL){
            exit(1);
        }
    }
    for(i = 0; i < row; i++){
        row_flag[i] = 0;
    }
    for(i = 0; i < column; i++){
        column_flag[i] = 0;
    }
    for(i = 0; i < row; i++){
        for(j = 0; j < column; j++){
            scanf("%c", &ptr[i][j]);
            if(ptr[i][j] == '#'){
                row_flag[i] = 1;
                column_flag[j] = 1;
            }
        }
        scanf("%c", &tmp);
    }

    for(i = 0; i < row; i++){
        k = 0;
        for(j = 0; j < column; j++){
            if(row_flag[i] == 1 && column_flag[j] == 1){
                printf("%c", ptr[i][j]);
                k = 1;
            }
        }
        if(k == 1){
            printf("\n");
        }
    }

    return 0;
}

Measured memory_bytes: 1644
import math
import sys

sys.setrecursionlimit(1000000)
input = lambda: sys.stdin.readline().rstrip()

A = []
for _ in range(3):
    A.append(list(map(int, input().split())))

N = int(input())
b = [int(input()) for _ in range(N)]

ok = False

ok |= all(A[0][i] in b for i in range(3))
ok |= all(A[1][i] in b for i in range(3))
ok |= all(A[2][i] in b for i in range(3))
ok |= all(A[i][0] in b for i in range(3))
ok |= all(A[i][1] in b for i in range(3))
ok |= all(A[i][2] in b for i in range(3))
ok |= all(A[i][i] in b for i in range(3))
ok |= all(A[i][2 - i] in b for i in range(3))

print('Yes' if ok else 'No')


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long int;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
int main(){
    string s,t,u;
    int a,b;
    cin >> s >> t >> a >> b >> u;
    if (s == u) PRINT(a-1 << " " << b);
    else PRINT(a << " " << b-1);
}

Measured memory_bytes: 256
#ifdef __LOCAL
  #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

int main(){
  ll n,a,b,c,d; cin >> n >> a >> b >> c >> d;
  bool f=0;
  rep(i,n){
    if(i*c-(n-1-i)*d<=b-a&&b-a<=i*d-(n-1-i)*c) f=1;
  }
  if(f) cout << "YES" << endl;
  else cout << "NO" << endl;
  
}

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

int main() {
  int n,x;
  cin >> n >> x;
  ll ans = 0;
  vector<int>a(n+2);
  a[0] = a[n+1] = 0;
  for(int i = 1;i < n+1;i++) cin >> a[i];
  for(int i = 0;i < n+1;i++){
    if(a[i] > x){
      ans += a[i+1];
      a[i+1] == 0;
      ans += a[i]-x;
      a[i] = x;
    }
    else if(a[i]+a[i+1] > x){
      ans += a[i]+a[i+1]-x;
      a[i+1] = x-a[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long K = sc.nextLong();
		
		long arr[] = new long[100001];
		Arrays.fill(arr,0);
		
		for(long i=1; i<N+1; i++){
			int a = sc.nextInt();
			long b = sc.nextLong();
			arr[a]= arr[a]+b;
		}
		
		for(int i=1; i<100001; i++){
			if(K<=arr[i]){
				System.out.println(i);
				break;
			}
			else K=K-arr[i];
		}

	}
}

Measured memory_bytes: 64768
import math
H,W=map(int,input().split())

big=math.ceil(W/2)
sml=math.floor(W/2)

ans=big*math.ceil(H/2)+sml*math.floor(H/2)

if H !=1 and W!=1:
    print(int(ans))
else:
    print(1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = 4*atan(1);
typedef long long ll;
typedef pair<int,int> pii;
int n, k;
// int gcd(int a, int b) { 
//     if (a == 0) return b; 
//     return gcd(b % a, a); 
// }
ll f(ll a) {
	a %= MOD;
	if(a < 0) a += MOD;
	return a;
}
ll power(int base, int power) {
	ll prod = 1;
	ll b = base;
	while(power) {
		if (power & 1) {
			prod = f(prod*b);
		}
		b = f(b*b);
		power/=2;
	}
	return prod;
}
ll ways[100005];
void solve() {
	cin >> n >> k;
	ll sum = 0;
	for (int i = k; i > 0; i--) {
		ways[i] = power(k/i,n);
		for (int j = i * 2; j <= k; j += i) {
			ways[i] = f(ways[i]-ways[j]);
		}
		sum = f(sum + f(ways[i] * i));
	}
	printf("%lld\n",sum);
}
int main() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	// int t;
	// cin >> t;
	// for (int i = 1; i <= t; i++) { 
		// cout << "Case #" << i << ": ";
		solve();
	// }
}

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

int main(){
    int N;
    ll x;
    cin >> N >> x;
    vector<ll> a(N);
    for(int i=0; i<N; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    int ans = 0;
    ll cost = 0;
    for(int i=0; i<N; i++){
        ans++;
        cost += a[i]; 
        if(cost > x){
            ans--;
            cout << ans << endl;
            return 0;
        }
    }

    if(cost < x){
        ans--;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import collections
s = int(input())
result = [s]
tmp = s
while True:
  if collections.Counter(result).most_common()[0][1] == 2:
    break
  elif tmp%2 == 0:
    x = tmp/2
  elif tmp%2 > 0:
    x = (3*tmp) + 1
  tmp = x
  result.append(int(x))
print(len(result))

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char **argv)
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0), cout.precision(15);
    int N; // 1 20
    cin >> N;
    vector<int> V(N), C(N); // vi ci 1 50
    for(int i = 0; i < N; i++){
        cin >> V[i];
    }
    for(int i = 0; i < N; i++){
        cin >> C[i];
    }
    int res = 0; // select none
    for(int i = 0; i < N; i++){
        if(V[i] > C[i]){
            res += V[i] - C[i];
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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やllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  int N,M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  vector<P> p(M);
  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);
    p[i] = make_pair(a,b);
  }
  int ans = 0;
  for(int i=0; i<M; i++){
    vector<bool> dist(N,false);
    dist[0] = true;
    queue<int> que;
    que.push(0);
    while(que.size()){
      int v = que.front();
      que.pop();
      for(auto nv: G[v]){
        if(nv==p[i].first && v==p[i].second) continue;
        if(nv==p[i].second && v==p[i].first) continue;
        if(dist[nv]) continue;
        dist[nv] = true;
        que.push(nv);
      }
    }
    bool can = true;
    for(int i=0; i<N; i++){
      if(!dist[i]) can = false;
    }
    if(!can){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# AOJ 0096 Sum of 4 Integers II
# Python3 2018.6.15 bal4u

MAX = 1000

while True:
	try: n = int(input())
	except: break
	
	if n > 2*MAX: n = 4*MAX - n
	k = n+1
	ans = k*(k+1)*(k+2)//6
	if n > MAX:
		k = n-MAX
		ans -= 2 * k*(k+1)*(k+2)//3;
	print(ans)


Measured memory_bytes: 5596
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int pop ();
void push(int);

int stack[100];
int size=0;

int main(){
  int x;
  char s[100];
  int a,b;

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      b=pop();
      a=pop();
      push(a+b);
    } else if ( s[0] == '-' ){
      b=pop();
      a=pop();
      push(a-b);
    } else if ( s[0] == '*' ){
      b=pop();
      a=pop();
      push(a*b);
    } else {
      x = atoi(s);
      push(x);
    }
  }
  printf("%d\n",stack[0]);
  return 0;
}

int pop(){
  return stack[--size];
}

void push(int x){
  stack[size]=x;
  size++;
}

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

using namespace std;

int main(void)
{
    int N;
    cin >> N;
    int D[N][2];
    for(int i = 0; i < N; ++i)
    {
        cin >> D[i][0] >> D[i][1];
    }
    int count = 0;
    for(int i = 0; i < N; ++i)
    {
        if(D[i][0] == D[i][1])
        {
            ++count;
        }
        else
        {
            count = 0;
        }
        if(count >= 3)
        {
            break;
        }
    }
    cout << (count >= 3 ? "Yes" : "No") << endl;
    return 0;
}

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

using namespace std;

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

    int n, m;
    cin >> n >> m;
    long long ans = 1ll * n * (n - 1) / 2;
    long long a[m];

    int arr[m][2], p[n + 1];
    vector<int> c[n + 1];

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

    for (int i = 1; i <= n; i++) {
        c[i].push_back(i);
        p[i] = i;
    }

    for (int i = m - 1; i >= 0; i--) {
        a[i] = ans;

        int x, y;
        x = arr[i][0];
        y = arr[i][1];

        if (c[p[x]].size() > c[p[y]].size())
            swap(x, y);

        if (p[x] != p[y]) {
            ans -= 1ll * c[p[x]].size() * c[p[y]].size();

            vector<int> tmp, empty;
            tmp = c[p[x]];
            c[p[x]].swap(empty);

            for (int j : tmp)
                c[p[y]].push_back(j), p[j] = p[y];
        }
    }

    for (long long x : a)
        cout << x << "\n";

    return 0;
}

Measured memory_bytes: 9464
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Queue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		char[][] s = new char[n][];
		for (int i = 0; i < n; i++) {
			s[i] = br.readLine().toCharArray();
		}
		br.close();

		Obj[] arr = new Obj[n];
		int total = 0;
		for (int i = 0; i < n; i++) {
			Obj o = new Obj();
			int cnt = 0;
			for (int j = 0; j < s[i].length; j++) {
				if (s[i][j] == '(') {
					cnt++;
				} else {
					cnt--;
					o.min = Math.min(o.min, cnt);
				}
			}
			o.cnt = cnt;
			arr[i] = o;
			total += cnt;
		}
		if (total != 0) {
			System.out.println("No");
			return;
		}

		Arrays.sort(arr, (o1, o2) -> {
			if (o1.min != o2.min) {
				return o2.min - o1.min;
			}
			return o2.cnt - o1.cnt;
		});

		Queue<Obj> que = new ArrayDeque<>();
		int now = 0;
		for (Obj o : arr) {
			if (now + o.min >= 0 && o.cnt >= 0) {
				now += o.cnt;
			} else {
				que.add(o);
			}
		}

		List<Obj> list = new ArrayList<>();
		while (!que.isEmpty()) {
			Obj o = que.poll();
			if (now + o.min < 0) {
				System.out.println("No");
				return;
			}
			if (o.cnt >= 0) {
				now += o.cnt;
			} else {
				list.add(o);
			}
		}

		Collections.sort(list, (o1, o2) -> (o2.cnt - o2.min) - (o1.cnt - o1.min));
		for (Obj o : list) {
			if (now + o.min < 0) {
				System.out.println("No");
				return;
			}
			now += o.cnt;
		}
		System.out.println("Yes");
	}

	static class Obj {
		int min, cnt;
	}
}


Measured memory_bytes: 107720
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b==c+d){
     cout<<"Balanced"<<endl;
  }
  else{
     if(a+b>c+d){
        cout<<"Left"<<endl;
     }
     else{
        cout<<"Right"<<endl;
     }
  }
}



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

int main(){
  int N;
  cin >> N;
  vector<string> S(N);

  for(int i = 0; i < N; i++){
    cin >> S[i];
    if(S[i] == "Y"){ cout << "Four"; return 0; }

  }

  cout << "Three";
return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if(a <= 0 && 0 <= b) {
        cout << "Zero" << endl;
    } else if(b < 0 && (b - a) % 2 == 0) {
        cout << "Negative" << endl;
    } else {
        cout << "Positive" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, 0, n)

const int inf = 999999999;
const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	cin.tie(0);
	int N, M;
	cin >> N >> M;
	ll ans = 0;
	// 1回あたりの実行時間
	int t = 100 * (N - M) + M * 1900;
	// Mケースすべて正解する確率
	double p = 1.0/pow(2, M); // >= 1/2^5

	// 数学的な解はt/p
	cout << t / p;

	system("pause");
	return 0;
}

Measured memory_bytes: 504
import numpy as np
from numba import njit, i8
import sys
read = sys.stdin.readline
mod = 10 ** 9 + 7


@njit((i8, i8[:]), cache=True)
def main(n, a):
    s = np.zeros(n + 1, dtype=np.int64)
    for i in range(n):
        s[i + 1] = (a[i] + s[i]) % mod
    ans = 0
    for i in range(1, n):
        ans = (ans + a[i] * s[i] % mod) % mod
    print(ans)


n = int(read())
a = np.fromstring(read(), dtype=np.int64, sep=' ')
main(n, a)


Measured memory_bytes: 110580
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

class UnionFindTree
    attr_accessor:par,:rank
    def initialize(n)
      @par=Array.new(n){|i| i}
      @rank=array(n,0)
    end
    def find(x)
        return x if @par[x]==x
        @par[x]=find(@par[x])
        return @par[x]
    end

    def union(x,y)
        x=find(x)
        y=find(y)
        return if x==y
        if @rank[x]<@rank[y]
            @par[x]=y
        else
            @par[y]=x
            @rank[x]+=1 if @rank[x]==@rank[y]
        end
    end

    def same?(x,y)
        return find(x)==find(y)
    end
end
N,M=get_i
uft=UnionFindTree.new(N)
M.times do|i|
    x,y,z=get_i.map{|x| x-=1}
    uft.union(x,y) unless uft.same?(x,y)
end
group=Hash.new(0)
N.times do|i|
    group[uft.find(i)]=1
end
puts group.size

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

int main() {
  double f[101][101];
  double dp[101][101];
  int n,m;
  while (cin >> n >> m,n||m) {
    
    for ( int i = 0; i < n; i++ ) {
      for ( int j = 0; j < n; j++ ) {
	cin >> f[i][j];
      }
    }

    for ( int i = 0; i < m; i++ ) {
      for ( int j = 0; j < n; j++ ) {
	dp[i][j] = 0.0;
      }
    }

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

    for ( int i = 1; i < m; i++ ) {
      for ( int j = 0; j < n; j++ ) {
	for ( int k = 0; k < n; k++ ) {
	  dp[i][j] = max( dp[i][j], dp[i-1][k] * f[j][k] );
	}
      }
    }

    double ans = 0.0;
    for ( int i = 0; i < n; i++ ) {
      ans = max ( ans, dp[m-1][i] );
    }
      
    printf ("%.2f\n", ans );
  }
  return 0;
}

Measured memory_bytes: 1404
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<v<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

ll solve(const ll &N,ll H,const vl &a,const vl &b){
    priority_queue<P> pq;
    for(ll i=0;i<N;++i){
        pq.emplace(P(a[i],INF));
        pq.emplace(P(b[i],1));
    }
    ll ans=0;
    while(H>0){
        P x=pq.top();
        if(x.second==1){
            pq.pop();
            H-=x.first;
            ans++;
        }
        else{
            ll num=(H+x.first-1)/x.first;
            ans+=num;
            H=0;
        }
    }
    return ans;
}

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll H;
    cin >> H;
    vector<ll> a(N,0);
    vector<ll> b(N,0);
    for(ll i=0;i<N;++i)cin>>a[i]>>b[i];
    
    prt(solve(N,H,a,b))

    return 0;
}


Measured memory_bytes: 8048
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, m, k, s[11][11], buf, p[11];
string str;

int main(){
	cin >> n >> m;
	
	memset(s, sizeof(s), 0);
	for(ll i = 1; i <= m; i++){
		cin >> k;
		for(ll j = 1; j <= k; j++){
			cin >> buf;
			s[i][buf] = 1;
		}
	}
	for(ll i = 1; i <= m; i++){cin >> p[i];}
	
	ll ans = 0;
	for(ll a = 0; a < (1 << n); a++){
		bool ok = true;
		for(ll i = 1; i <= m; i++){
			ll num = 0;
			for(ll j = 1; j <= n; j++){
				if(s[i][j] == 1 && (a&(1<<j-1))){num++;}
			}
			if(num%2 != p[i]){ok = false;}
			//cout << num << endl;
		}
		if(ok){ans++;}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
template<typename T>
void print(T x) {
    cout << x << endl;
}
int main(void) {
    vector<int> x(3);
    rep(i, 3) {
        cin >> x[i];
    }
    sort(x.begin(), x.end());
    if(x[0]==x[1]&&x[1]!=x[2])
        print("Yes");
    else if(x[0]!=x[1]&&x[1]==x[2])
        print("Yes");
    else
        print("No");
}


Measured memory_bytes: 256
"""    Arnab Chanda    """

from collections import defaultdict, deque
from itertools import permutations
from sys import stdin,stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
import heapq

int_input=lambda : int(stdin.readline())
string_input=lambda : stdin.readline().split()
multi_int_input =lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input=lambda : list(map(int,stdin.readline().split()))
string_list_input=lambda: list(string_input())
MOD = pow(10,9)+7


map={
    400:8,
    600:7,
    800:6,
    1000:5,
    1200:4,
    1400:3,
    1600:2,
    1800:1,
    2000:0
}

x = int_input()

ans = 0
for items in map:
    if (x < items):
        ans = map[items]+1
        break

print(ans)

Measured memory_bytes: 9596
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, sum=0;
  cin >>N;
  vector<int> A(N+2,0), B(N+2,0);
  for(int i=1; i<=N; i++){
    int a;
    cin >>a;
    A[i]=a;
    sum+=abs(A[i-1]-A[i]);
  }
  sum+=abs(A[N]-A[N+1]);
  for(int i=1; i<=N; i++){
    if(A[i-1]<=A[i] && A[i]<=A[i+1] ||
      A[i-1]>=A[i] && A[i]>=A[i+1]) B[i]=sum;
    else B[i]=sum-min(abs(A[i-1]-A[i]),abs(A[i]-A[i+1]))*2;
  }
  for(int i=1; i<=N; i++){
    cout <<B[i] <<endl;
  }
}

Measured memory_bytes: 2048
using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;
    using System.Text.RegularExpressions;

    class Program
    {
        static void Main()
        {
            var input = System.Console.ReadLine().Split(' ');
            var n = int.Parse(input[0]);
            var k = int.Parse(input[1]);
            var p = System.Console.ReadLine().Split(' ').Select((x) => int.Parse(x)).ToArray();
            var p_min = p.OrderBy(x=> x).ToArray();
            var ans = 0;
            try
            {
                for (int i = 0; i < k; i++)
                {
                    ans += p_min[i];
                }
                Output(ans.ToString());
            }
            catch
            {
                Output(ans.ToString());
            }
        }
        private static void Output(string str)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            Console.WriteLine(str);

            Console.Out.Flush();
        }
    }


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

# 入力データ受取り時に、辞書に追加していくやり方
s_dict = {}
for i in range(n):
    s = input()    
    if s not in s_dict:
        s_dict[s] = 1
    s_dict[s] += 1

max_value = max(s_dict.values())
ans = []
for key, value in s_dict.items():
    if value == max_value:
        ans.append(key)

ans.sort()
for i in ans:
    print(i)

Measured memory_bytes: 147092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    int sum = 0;
    if (b / a >= 1) {
        sum = 1;
    }
    cout << a-1+sum << endl;
}

Measured memory_bytes: 256
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a: u64,
        b: u64,
    }

    if a * b % 2 == 0 {
        println!("No");
    } else {
        println!("Yes");
    }
}


Measured memory_bytes: 4476
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;class Program
{
	static void Main(string[] args)
	{
        //var exStdIn = new System.IO.StreamReader( "stdin.txt" );System.Console.SetIn( exStdIn );
		
		int n = int.Parse(Console.ReadLine());
		var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
		long sm = 0;
		var cnt = new int[100005];
		for (int i = 0; i < n; i++)
		{
			sm+=a[i];
			cnt[a[i]]++;
		}
		int q = int.Parse(Console.ReadLine());
		for (int i = 0; i < q; i++)
		{
			var bc = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int b = bc[0];
			int c = bc[1];
			sm+=(c-b)*cnt[b];
			cnt[c] += cnt[b];
			cnt[b] = 0;
			Console.WriteLine(sm);
		}
	}
}


Measured memory_bytes: 50872
import java.util.Scanner;


class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int  num = scanner.nextInt();//階層数
		long fin;
		
		fin =  fin(num);

		System.out.println(fin);
		
		scanner.close();
	}
	
	public static long fin(int num) {
		long Fin0 = 1,Fin1 = 1,Fin = 0;
		
		if( num == 0 ) return 0;
		if( num == 1 ) return 1;
		
		for(int i = 1; i < num; i ++) {
			Fin = Fin0 + Fin1;
			Fin0 = Fin1;
			Fin1 = Fin;
		}
		
		return Fin; 
	}
}

/* 実行時間計測用

		long start = System.currentTimeMillis();
		long end = System.currentTimeMillis();
		System.out.println((end - start)  + "ms:計測時間");
*/


Measured memory_bytes: 26284
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true) {
            int h = sc.nextInt();
            int w = sc.nextInt();
            int i, j;
            if (h == 0 && w == 0) break;
            for (i = 0; i < h; i++) {
                for (j = 0; j < w; j++) {
                    if(i == 0 || i == h-1) {
                        System.out.print("#");
                    }else{
                        if(j == 0 || j == w - 1){
                        System.out.print("#");
                        }else{
                            System.out.print(".");
                        }
                    }
                }
                System.out.print("\n");
            }
            System.out.print("\n");
        }
    }
}



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

int main(){
  ll n; cin>>n;
  vector<ll> c2,c4;
  for(int i=0; i<n; i++) {
    ll x; cin>>x;
    if(x%4==0) c4.push_back(x);
    else if(x%2==0) c2.push_back(x);
  }
  cout << (c4.size() + c2.size()/2 >= n/2 ? "Yes" : "No");
}

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

typedef string::const_iterator State;
class ParseError {};

map<char, bool> variable;

bool equation(State&);
bool formula(State&);
bool boolean(State&);

int main(void) {
    for (int i = 0; i < 11; i++) {
        variable['a'+i] = false;
    }

    string s;
    while (1) {
        getline(cin, s);
        if (s == "#") break;

        bool flag = true;
        for (unsigned int i = 0; i < 2048; i++) {
            if (!flag) break;

            unsigned int val = i;
            for (int j = 0; j < 11; j++) {
                if ((val & 1) == 0) {
                    variable['a'+j] = true;
                } else {
                    variable['a'+j] = false;
                }
                val >>= 1;
            }

            State begin = s.begin();
            if (!equation(begin)) flag = false;
        }

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

    return 0;
}

bool equation(State &begin) {
    bool left = formula(begin);
    begin++;                    // '='
    bool right = formula(begin);
    // cout << "left: " << left << ", right: " << right << endl;
    return (left == right) ? true : false;
}

bool formula(State &begin) {
    if (*begin == '(') {
        begin++;                // '('
        bool ret = formula(begin);
        if (*begin == '*') {
            begin++;
            ret = formula(begin) && ret;
        } else if (*begin == '+') {
            begin++;
            ret = formula(begin) || ret;
        } else {
            begin++;
            if (*begin == '>') {
                begin++;
                if (!ret) {
                    ret = formula(begin) || true;
                } else {
                    ret = formula(begin);
                }
            } else {
                ret = !formula(begin);
            }
        }
        begin++;                // ')'
        return ret;
    } else if (*begin == '-') {
        begin++;
        return !formula(begin);
    } else {
        return boolean(begin);
    }
}

bool boolean(State &begin) {
    if (*begin == 'T') {
        begin++;
        return true;
    } else if (*begin == 'F') {
        begin++;
        return false;
    } else {                // a~k
        bool ret = variable[*begin];
        begin++;
        return ret;
    }
}

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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  bool approved = true;

  rep(i, n) {
    int v = a[i];
    if (v % 2 == 0) {
      if (v % 3 == 0 || v % 5 == 0) {
        // 処理なし
      } else {
        approved = false;
        break;
      }
    }
  }

  cout << (approved ? "APPROVED" : "DENIED") << endl;

  return 0;
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.parents = [-1]*n
        self.rank = [0]*n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            return self.find(self.parents[x])

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1


N, M = list(map(int, input().split()))
uf = UnionFind(N)
for _ in range(M):
    x, y, z = list(map(int, input().split()))
    x -= 1
    y -= 1
    uf.union(x, y)

ct = 0
for i in range(N):
    if uf.parents[i] < 0:
        ct += 1
print(ct)


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

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

    string s; cin >> s;
    int n = s.size();
    int cnt = 0;
    REP(i, n) if (s[i] == '1') cnt++;
    cout << cnt << '\n';
    return 0;
}

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

int main() {

  int n;

  while( cin >> n ) {

    bool flag = false;

    for ( int i = 1; i <= 512; i*=2 ) {

      if ( n % (i*2) != 0 ) {
	if ( flag ) cout << " ";
	flag = true;
	cout << i;
	n -= i;
      }

    }

    cout << endl;

  }

  return 0;

}

Measured memory_bytes: 1160
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    int A, B;
    cin >> A >> B;
    if ((A + B) & 1)
    {
        cout << "IMPOSSIBLE\n";
    }
    else
    {
        cout << (A + B) / 2 << "\n";
    }

    return 0;
}



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

int main(void) {

    string s;
    cin >> s;
    int ans = 0;

    for(int i = 0; i < s.size(); i++){
        if(s[i] == '1'){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
    
}

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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }
typedef long long ll;

int main(){
  int n; cin >> n;
  vector <int> A(n);
  rep(i,n) {
    cin >> A[i];
  }
  int cnt=0;
  rep(i,A.size()) {
    int minj = i;
    for(int j=i;j<A.size();j++){
      if (A[j] < A[minj]) {
        minj = j;
      }
    }
    if(i!=minj){
      cnt++;
      swap(A[i], A[minj]);
    }
  }
  rep(i,A.size()) {
      cout << A[i] ;
      if (i != A.size()-1) {cout << " ";}
  }
  cout << endl;
  cout << cnt << endl;
}



Measured memory_bytes: 3076
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n;
bool used[100001];
int cmp[100001];
vector<int> g[100001], gr[100001];
vector<int> vs;
 
void dfs(int x){
	used[x]=1;
	for(auto y:g[x]){
		if(!used[y]) dfs(y);
	}
	vs.push_back(x);
}
 
void rdfs(int v, int k){
	used[v]=1;
	cmp[v]=k;
	for(auto y:gr[v]){
		if(!used[y]) rdfs(y, k);
	}
}
 
int scc(){
	fill(used, used+n, 0);
	vs.clear();
	for(int i=0; i<n; i++){
		if(!used[i]) dfs(i);
	}
	fill(used, used+n, 0);
	int k=0;
	for(int i=vs.size()-1; i>=0; i--){
		if(!used[vs[i]]) rdfs(vs[i], k++);
	}
	return k;
}
int main()
{
	int m; cin>>n>>m;
	for(int i=1; i<=n-1+m; i++){
		int a, b; cin>>a>>b; a--; b--;
		g[a].push_back(b); gr[b].push_back(a);
	}
	scc();
	int r;
	for(int i=0; i<n; i++) if(cmp[i]==0) r=i;
	int num[100001];
	for(int i=0; i<n; i++){
		num[cmp[i]]=i;
	}
	int d[100001];
	fill(d, d+n, -1e9);
	d[r]=0;
	for(int i=1; i<n; i++){
		for(auto y:gr[num[i]]){
			d[num[i]]=max(d[num[i]], d[y]+1);
		}
	}
	int ans[100001];
	ans[r+1]=0;
	for(int i=0; i<n; i++){
		for(auto y:g[i]){
			if(d[y]==d[i]+1){
				ans[y+1]=i+1;
			}
		}
	}
	for(int i=1; i<=n; i++) cout<<ans[i]<<endl;
	return 0;
}

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

using namespace std;
#define ll long long

ll INF = 1e18;

void getPrime(ll a, vector<ll> &res)
{
    for( ll i = 2; i*i<=a; i++)
    {
        if(a%i == 0)
        {
            res.push_back(i);
            while(a%i == 0)
            {
                a = a/i;
            }
        }
    }

    if(a>1)
        res.push_back(a);
}

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

    ll a,b;
    cin>>a>>b;

    vector<ll> temp;
    getPrime(a,temp);

    vector<ll>res;
    res.push_back(1);

    for(auto it:temp)
    {
        if(b%it == 0)
            res.push_back(it);
    }

    cout<<res.size()<<endl;

    return 0;
}


Measured memory_bytes: 256
l = list(map(int, input().split()))
g1 = [1, 3, 5, 7, 8, 10, 12]
g2 = [4, 6, 9, 11]
g3 = [2]
print('Yes' if set(l).issubset(g1) or set(l).issubset(g2) or set(l).issubset(g3) else 'No')

Measured memory_bytes: 3060
#include <iostream>

int main() {
  int a, b, c;
  std::cin >> a >> b >> c;
  int ans;
  if (a + b > b + c)
    ans = (b + c < c + a) ? b + c : c + a;
  else
    ans = (a + b < c + a) ? a + b : c + a;
  std::cout << ans << std::endl;
}


Measured memory_bytes: 256
import java.io.*
import java.util.*

fun solve(N: Int, K: Int) {
    val a = (1..N).filter { (2 * it) % K == 0 && it % K != 0 }.size.toLong()
    val b = if (N >= K) N / K else 0
    println(cubic(a) + cubic(b.toLong()))
    return
}

fun cubic(x: Long) = x * x * x


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }

    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }

    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val K = sc.next().toInt()
    solve(N, K)
}



Measured memory_bytes: 33628