akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<algorithm>
using namespace std;
int c[1000],d[1000];
int dp[1001][1001];
int main(){
	int a,b;
	int now=0;
	while(scanf("%d",&a),a){
		scanf("%d",&b);
		for(int i=0;i<b;i++){
			scanf("%d,%d",c+i,d+i);
		}
		for(int i=0;i<=b;i++)
			for(int j=0;j<=a;j++)
				dp[i][j]=-99999999;
		for(int i=0;i<=a;i++)dp[0][i]=0;
		for(int i=1;i<=b;i++){
			for(int j=0;j<=a;j++){
				if(j>=d[i-1])dp[i][j]=max(dp[i-1][j],dp[i-1][j-d[i-1]]+c[i-1]);
				else dp[i][j]=dp[i-1][j];
			}
		}
		int weight=0;
		int ans=0;
		for(int i=0;i<=a;i++){
			if(weight<dp[b][i]){
				weight=dp[b][i];
				ans=i;
			}
		}
		printf("Case %d:\n%d\n%d\n",++now,weight,ans);
	}
}

Measured memory_bytes: 0
fun main(args : Array<String>) {
    val N = readLine()!!.toInt()
    val L = readLine()!!.split(" ").map { it.toInt() }.toIntArray()

    L.sort()


    var answer = 0
    for (i in 0 until N - 2) {
        for (j in i + 1 until N - 1) {
            val a = L[i]
            val b = L[j]
            val lower = Math.max(a - b, b - a)
            val upper = a + b
            val lowerIndex = Math.max(lowerBound(L, lower + 1), j + 1)
            val upperIndex = Math.min(lowerBound(L, upper), N)
            if (upperIndex > lowerIndex) {
                answer += (upperIndex - lowerIndex)
            }
        }
    }

    println(answer)
}

fun lowerBound(sortedList: IntArray, key: Int) : Int {
    var ng = - 1 // left
    var ok = sortedList.size  // right

    fun isOk(mid: Int) : Boolean {
        return sortedList.get(mid) >= key
    }

    while (Math.abs(ok - ng) > 1) {
        var mid = (ok + ng) / 2
        if (isOk(mid)) {
            ok = mid
        } else {
            ng = mid
        }
    }
    return ok
}

Measured memory_bytes: 40432
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {

  int n;
  cin >> n;
  vec1 t(n);
  vec1 a(n);
  for(int i = 0; i < n; i++) {
    cin >> t.at(i);
    a.at(i) = t.at(i);
  }
  int m;
  cin >> m;
  int ans = 0;
  for(int i = 0; i < m; i++) {
    int p, x;
    cin >> p >> x;
    t.at(p-1) = x;
    for(int j = 0; j < n; j++) {
      ans = ans + t.at(j);
    }
    cout << ans << endl;
    ans = 0;
    t.at(p-1) = a.at(p-1);
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		if(a % 2 == 0) {
			System.out.println(a);
		}else {
			System.out.println(a*2);
		}
	}

}

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

int n, fin = 0;
int ten[9] = {0};
int memo[30] = {0}, chmemo[30] = {0};
bool used[10] = {0}, chused[10] = {0};
vector<string> s;

int solve(int now, int nowid, int nowsum);
bool ch(int sum);
void resetmemo();

int main() {
  ten[0] = 1;
  for(int i = 1; i < 9; ++i) ten[i] = ten[i - 1] * 10;
  while(1) {
    cin >> n;
    if(n == 0) break;
    s.resize(n);
    fin = 0;
    for(int i = 0; i < 26; ++i) memo[i] = -1;
    for(int i = 0; i < n; ++i) {
      cin >> s[i];
      reverse(s[i].begin(), s[i].end());
      if(i < n - 1) fin = max((int)s[i].size(), fin);
    }
    cout << solve(0, 0, 0) << endl;
  }
  return 0;
}

int solve(int now, int nowid, int nowsum) {
  if(now == fin) return ch(nowsum);
  int ans = 0;
  while(nowid < n - 1) {
    if(s[nowid].size() > now) {
      if(memo[s[nowid][now] - 'A'] != -1)
        nowsum += ten[now] * memo[s[nowid][now] - 'A'];
      else
        break;
    }
    ++nowid;
  }
  if(nowid == n - 1) {
    if(now + 1 > s[n - 1].size()) return 0;
    if(memo[s[n - 1][now] - 'A'] != -1 &&
       (nowsum / ten[now]) % 10 !=
           memo[s[n - 1][now] - 'A'])
      return 0;
    if(memo[s[n - 1][now] - 'A'] == -1) {
      if(used[(nowsum / ten[now]) % 10]) return 0;
      memo[s[n - 1][now] - 'A'] = (nowsum / ten[now]) % 10;
      used[(nowsum / ten[now]) % 10] = 1;
      ans += solve(now + 1, 0, nowsum);
      used[(nowsum / ten[now]) % 10] = 0;
      memo[s[n - 1][now] - 'A'] = -1;
      return ans;
    }
    ans += solve(now + 1, 0, nowsum);
  }
  else {
    for(int i = 0; i < 10; ++i)
      if(!used[i]) {
        used[i] = 1;
        memo[s[nowid][now] - 'A'] = i;
        ans += solve(now, nowid + 1, nowsum + i * ten[now]);
        used[i] = 0;
      }
    memo[s[nowid][now] - 'A'] = -1;
  }
  return ans;
}

bool ch(int sum) {
  for(int i = 0; i < 10; ++i) chused[i] = used[i];
  for(int i = 0; i < 26; ++i) chmemo[i] = memo[i];
  for(int i = 0; i < s[n - 1].size(); ++i) {
    if(chmemo[s[n - 1][i] - 'A'] != -1) {
      if(sum % 10 != chmemo[s[n - 1][i] - 'A']) return 0;
    }
    else {
      if(chused[sum % 10]) return 0;
      chmemo[s[n - 1][i] - 'A'] = sum % 10;
      chused[sum % 10] = 1;
    }
    sum /= 10;
  }
  if(sum != 0) return 0;
  for(int i = 0; i < n; ++i)
    if(s[i].size() != 1 &&
       chmemo[s[i][s[i].size() - 1] - 'A'] == 0)
      return 0;
  return 1;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
    using namespace std;
    using LL = long long;

    const int N = 234567;

    vector <int> G[N];
    int d[N], f[N], n, x, y;

    void dfs(int u, int p, int d[]) {
      for (auto v : G[u])
        if (v != p) {
          d[v] = d[u] + 1;
          dfs(v, u, d);
        }
    }

    int main() {
      cin >> n >> x >> y;
      for (int i = 1; i < n; i ++) {
        int u, v;
        scanf("%d %d", &u, &v);
        G[u].push_back(v); G[v].push_back(u);
      }
      dfs(y, 0, f);
      dfs(x, 0, d);
      int ans = 0;
      for (int i = 1; i <= n; i ++) {
        if (f[i] > d[i]) ans = max(ans, f[i]);
      }
      cout << ans-1 << endl;
      return 0;
    }


Measured memory_bytes: 14848
#include <iostream>
#include <deque>

using namespace std;

bool equ(deque <char> deq,string s)
{
    string c;
    for (int i=0;i<deq.size();i++)
        c+=deq[i];
    return c==s;

}


int main()
{
    deque <char> deq;
    string s,t;
    cin>>s>>t;
    for (int i=0;i<s.size();i++)
        deq.push_back(s[i]);
    for (int i=0;i<s.size();i++){
        if (equ(deq,t)){
            cout<<"Yes";
            return 0;
        }
        char c=deq[deq.size()-1];
        deq.pop_back();
        deq.push_front(c);
    }
    cout<<"No";

    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

int find(int v, vector<int>& p){
    if(p[v] == -1){
        return v;
    }
    p[v] = find(p[v], p);
    return p[v];
}

void unite(int u, int v, vector<int>& p){
    int u_root = find(u, p);
    int v_root = find(v, p);

    if(u_root == v_root){
        return;
    }
    p[u_root] = v_root;
}

signed main(){
    int w, h;
    cin >> w >> h;
    vector<tuple<int, int, int>> edge;
    rep(i, w){
        int p;
        cin >> p;
        edge.emplace_back(p, i, 0);
    }
    rep(i, h){
        int q;
        cin >> q;
        edge.emplace_back(q, i, 1);
    }
    sort(edge.begin(), edge.end());

    vector<int> parent(w + h + 2, -1);
    int ans = 0;
    int a = w+1;
    int b = h+1;
    rep(i, w+h){
        if(get<2>(edge[i]) == 0){
            int ww = get<1>(edge[i]);
            int u = find(ww, parent);
            int v = find(ww+1, parent);

            unite(u, v, parent);
            ans += get<0>(edge[i]) * b;
            a--;
        }else{
            int hh = get<1>(edge[i]);
            int u = find(w+1 + hh, parent);
            int v = find(w+1 + hh+1, parent);

            unite(u, v, parent);
            ans += get<0>(edge[i]) * a;
            b--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8176
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    public struct Pair<T> { public T x, y; public Pair(T x, T y) { this.x = x; this.y = y; } }
    public static void Solve()
    {
        int N = NextInt();
        int X = NextInt();
        int[] L = LineInt();
        int x = 0;
        int ans = 1;
        for (int i = 0; i < N; i++) {
            x += L[i];
            if (x <= X) ans++;
            else break;
        }
        Console.WriteLine(ans);
    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}


public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


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

struct UnionFind{

    vector<int> r;
    vector<int> count;

    UnionFind(int N):r(N),count(N){
        for(int i=0;i<N;i++){
            r.at(i)=i;
            count.at(i)=1;
        };
    }

    int root(int x){
        return r.at(x)==x?x:r.at(x)=root(r.at(x));
    }

    void unite(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y)return;
        r.at(y)=x;
        count.at(x)+=count.at(y);
        count.at(y)=0;
    }
};

int main(){
    int n,m;
    cin>>n>>m;
    UnionFind UF(n);
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        x--;y--;
        UF.unite(x,y);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        ans=max(UF.count.at(i),ans);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4768
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

using combi = pair<ll,vector<ll>>;

int main(){
    ll X,Y,Z,K;
    cin >> X >> Y >> Z >> K;
    vector<vector<ll>> vec_XYZ(3);
    vector<ll> limit;
    limit.push_back(X);
    limit.push_back(Y);
    limit.push_back(Z);


    ll cur;
    REP(i,0,3){
        REP(j,0,limit[i]){
            cin >> cur;
            vec_XYZ[i].push_back(cur);
        }
        sort(ALL(vec_XYZ[i]),greater<ll>());
    }
    
    priority_queue<combi> pri_qeu;
    set<combi> collision;
    combi c;
    c.second={0,0,0};
    c.first=vec_XYZ[0][0]+vec_XYZ[1][0]+vec_XYZ[2][0];
    pri_qeu.push(c);
    collision.insert(c);

    REP(i,0,K){
        c=pri_qeu.top(); pri_qeu.pop();
        P(c.first);

        REP(j,0,3){
            combi c_next;
            if(c.second[j]+1<limit[j]){
                c_next.second=c.second; c_next.second[j]++;
                c_next.first=c.first-vec_XYZ[j][c.second[j]]+vec_XYZ[j][c.second[j]+1];
            }
            if(!collision.count(c_next)){
                //for(auto a:c_next.second)cout << a << " "; cout<<endl;
                collision.insert(c_next); pri_qeu.push(c_next);
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;
const long long int MOD=1e9+7;

int main(){
  long long n, mn=1e15;
  cin >> n;
  for(long long i=1;i*i<=n;i++){
    if(n%i==0){
      mn = min(mn, (i-1)+(n/i-1));
    }
  }
  cout << mn << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;

int main() {
	int N;
	cin >> N;
	int n = -1;
	for (int i = 1; i <= N; i++) {
		if (N == i*(i + 1) / 2)n = i;
	}
	if (n == -1) {
		cout << "No" << endl;
		return 0;
	}
	vector<vector<int>> ans(n + 1, vector<int>(n));
	for (int i = 0; i < n; i++) ans[0][i] = i + 1;
	for (int i = 1; i < n; i++)for (int j = 0; j < n - i; j++) ans[i][i + j] += ans[i - 1][i + j] + n - i;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < i+1; j++) {
			ans[i + 1][j] = ans[j][i];
		}
	}
	cout << "Yes" << endl;
	cout << n+1 << endl;
	for (int i = 0; i < n+1; i++) {
		cout << n << " ";
		for (int j = 0; j < n; j++) {
			cout << ans[i][j];
			if (j != N - 1)cout << " ";
		}
		cout << endl;
	}
	return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64 N, M;
  cin >> N >> M;
  vector<int64> A(N), Asum(N+1, 0);
  REP(i, N) {
    cin >> A[i];
  }

  sort(all(A));
  REP(i, N) {
    Asum[i+1] += Asum[i] + A[i];
  }
  int64 l = 0, r = 212345, m;

  auto calc = [&](int64 x) {
    int64 sum = 0;
    REP(i, N) {
      int64 cnt = A.end() - lower_bound(all(A), x-A[i]);
      sum += cnt;
    }
    return sum;
  };

  auto ok = [&](int64 x) {
    return calc(x) >= M;
  };

  auto calc_sum = [&](int64 x) {
    int64 ret = 0;
    REP(i, N) {
      int64 idx = lower_bound(all(A), x-A[i]) - A.begin();
      ret += (N-idx) * A[i] + Asum[N] - Asum[idx];
    }
    return ret;
  };

  while (r - l > 1) {
    m = (l + r) >> 1;
    if (ok(m)) {
      l = m;
    } else {
      r = m;
    }
  }
  int64 cnt = calc(l);
  int64 res = calc_sum(l);
  if (cnt > M) {
    res -= l * (cnt - M);
  }
  cout << res << endl;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
using namespace std;
long long Mod = 998244353, F[1001000], InvF[1001000], S, S2, S3;
long long Pow(long long a, long long b){
    long long r = 1;
    while(b){
        if(b&1)r=r*a%Mod;
        a=a*a%Mod;b>>=1;
    }
    return r;
}
long long Inv(long long a){return Pow(a,Mod-2);}
long long Get(int a, int b){
    return F[a+b] * InvF[a] % Mod * InvF[b] % Mod;
}
int n, m;
int main(){
    int i;
    F[0]=1;
    for(i=1;i<=1000000;i++)F[i]=F[i-1]*i%Mod;
    InvF[1000000] = Inv(F[1000000]);
    for(i=1000000;i>=1;i--)InvF[i-1] = InvF[i] * i % Mod;
    scanf("%d%d",&n,&m);
    if(n > m) swap(n,m);
    S = m * Get(n,m) % Mod;
    for(i=0;i<n;i++){
        S = (S + Mod - Get(i, m-n+i) * Get(n-i, n-i-1) % Mod * (n-i-1) % Mod) % Mod;
        S = (S + Get(i, m-n+i+1) * Get(n-i-1, n-i-1) % Mod * (n-i-1) % Mod) % Mod;
        
        S3 = (S3 + Get(i, m-n+i) * Get(n-i, n-i-1) % Mod * (n-i) % Mod) % Mod;
        S3 = (S3 + Mod - Get(i, m-n+i+1) * Get(n-i-1, n-i-1) % Mod * (n-i-1) % Mod) % Mod;
    }
    S=(S+S3)%Mod;
    printf("%lld\n",S * Inv(Get(n,m))%Mod);
}

Measured memory_bytes: 15744
import sys
input = sys.stdin.readline

n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
cnt = 0
for i in range(n):
    x -= a[i]
    cnt += 1
    if x < 0:
        cnt -= 1
        break
if x > 0:
    cnt -= 1
print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define pi pair<int, int>

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	long long n, a, b;
	cin >> n >> a >> b;
	if(a < b) swap(a, b);
	
	if((a - b) % 2 == 0){
		cout << (a - b) / 2 << endl;
	}else if(a - b == 1){
		cout << min(n - b, a - 1) << endl;
	}else{
		cout << (min(b, n - a + 1) + (a - b) / 2) << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi x(n),y(n),h(n);
    rep(i,n){
        cin >> x[i] >> y[i] >> h[i];
    }
    rep(i,101){
        rep(j,101){
            bool flag = true;
            ll hh = -1;
            rep(k,n){
                if(h[k] == 0) continue;
                if(hh < 0){
                    hh = abs(x[k]-i)+abs(y[k]-j)+h[k];
                }else if(hh != abs(x[k]-i)+abs(y[k]-j)+h[k]){
                    flag = false;
                    break;
                }
            }
            if(flag){
                rep(k,n){
                    if(h[k] > 0) continue;
                    if(hh-abs(x[k]-i)-abs(y[k]-j) > 0){
                        flag = false;
                        break;
                    }
                }
                if(flag){
                    cout << i << " " << j << " " << hh << "\n";
                    return 0;
                }
            }
        }
    }
    return 0;
}


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

string my_pair(string S) {
  if (S == "A") return "T";
  if (S == "T") return "A";
  if (S == "C") return "G";
  if (S == "G") return "C";
}

int main(){
  string T;
  cin >> T;
  
  cout << my_pair(T) << endl;

}


Measured memory_bytes: 256
package main

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

type Node struct {
	Value int
	Left *Node
	Right *Node
	Parent *Node
}

func main() {
	var n int
	fmt.Scan(&n)

	var root *Node

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	wr := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		sc.Scan()
		command := sc.Text()
		switch command {
		case "print":
			printInorder(wr, root)
			wr.WriteString("\n")
			printPreorder(wr, root)
			wr.WriteString("\n")
		case "insert":
			sc.Scan()
			k, _ := strconv.Atoi(sc.Text())
			root = insert(root, k)
		case "find":
			sc.Scan()
			k, _ := strconv.Atoi(sc.Text())
			if find(root, k) == nil {
				wr.WriteString("no\n")
			} else {
				wr.WriteString("yes\n")
			}
		case "delete":
			sc.Scan()
			k, _ := strconv.Atoi(sc.Text())
			delete(root, k)
			
		default:
			panic("undefined command")
		}
	}
	wr.Flush()
}

func printPreorder(wr *bufio.Writer, node *Node) {
	if node == nil {
		return
	}
	wr.WriteString(" ")
	wr.WriteString(strconv.Itoa(node.Value))
	printPreorder(wr, node.Left)
	printPreorder(wr, node.Right)
}

func printInorder(wr *bufio.Writer, node *Node) {
	if node == nil {
		return
	}
	printInorder(wr, node.Left)
	wr.WriteString(" ")
	wr.WriteString(strconv.Itoa(node.Value))
	printInorder(wr, node.Right)
}

func insert(root *Node, k int) *Node {
	z := &Node{k, nil, nil, nil}
	if root == nil {
		return z
	}
	
	var x, y *Node
	x = root
	for x != nil {
		y = x
		if k < x.Value {
			x = x.Left
		} else {
			x = x.Right
		}
	}

	z.Parent = y
	if k < y.Value {
		y.Left = z
	} else {
		y.Right = z
	}
	return root
}

func find(node *Node, k int) *Node {
	if node == nil {
		return nil
	} else if node.Value == k {
		return node
	} else if k < node.Value {
		return find(node.Left, k)
	} else {
		return find(node.Right, k)
	}
}

func delete(root *Node, k int) {
	node := find(root, k)
	if node == nil {
		return
	}
	if node.Left == nil && node.Right == nil {
		p := node.Parent
		if p.Left == node {
			p.Left = nil
		} else {
			p.Right = nil
		}
	} else if node.Left == nil {
		p := node.Parent
		c := node.Right
		if p.Left == node {
			p.Left = c
		} else {
			p.Right = c
		}
		c.Parent = p
	} else if node.Right == nil {
		p := node.Parent
		c := node.Left
		if p.Left == node {
			p.Left = c
		} else {
			p.Right = c
		}
		c.Parent = p
	} else {
		y := node.Right
		for y.Left != nil {
			y = y.Left
		}
		node.Value = y.Value
		// yを削除
		if y.Right == nil {
			if y.Parent.Left == y {
				y.Parent.Left = nil
			} else {
				y.Parent.Right = nil
			}
		} else {
			if y.Parent.Left == y {
				y.Parent.Left = y.Right
			} else {
				y.Parent.Right = y.Right
			}
			y.Right.Parent = y.Parent
		}
	}
}



Measured memory_bytes: 22240
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long ll;

int main()
{
    ll n;
    cin>>n;
    if(n%2)
    {
        printf("%lld",n/2);
    }
    else
        printf("%lld",n/2-1);
    return 0;
}
/*
5
5
1 5 4 2 3
1 2 5 4 3
*/



Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int h,w;
    cin >> h >> w;
    vector<string> v(100);
    rep(i,h){
        cin >> v[i];
    }
    vector<bool> vertical(h,false);
    vector<bool> side(w,false);
    rep(i,h){
        rep(j,w){
            if(v[i][j]=='#'){
                vertical[i] = true;
                side[j] = true;
            }
        }
    }
    rep(i,h){
        if(vertical[i]){
            rep(j,w){
                if(side[j]){
                    cout << v[i][j];
                }
            }
            cout << endl;
        }
    }


    return 0;
}

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

int main () {

    int N;
    scanf("%d", &N);

    int A[N];
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }

    long long sum = 0LL, ans = 0LL;
    for (int i = 0; i < N; i++) {
        if (A[i] == 0) {
            ans += sum / 2;
            sum = 0LL;
        } else {
            sum += A[i];
        }
    }
    ans += sum / 2;
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 640
S = str(input())
L = len(S)

lst = []
for i in range(2**(L-1)):
    lst.append(bin(i))
    lst[i] = lst[i][2:]
    lst[i] = lst[i].zfill(L-1)

res = []

for j in lst:
    lst_s = list(S)
    for k in range(L-1):
        if j[k] == "0":
            lst_s[k+1] = lst_s[k] + lst_s[k+1]
            lst_s[k] = "0"
        else:
            pass
    for l in range(L):
        lst_s[l] = int(lst_s[l])
    res.append(sum(lst_s))

print(sum(res))

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

void solve(int n, vector<vector<pair<int, int>>> &g, vector<int> &ans, int now = 0, int par = -1, int col = 0)
{
	int nc = 1;
	for (auto &&p : g[now])
	{
		if (p.first == par)
		{
			continue;
		}

		if (nc == col)
		{
			nc++;
		}
		ans[p.second] = nc++;

		solve(n, g, ans, p.first, now, ans[p.second]);
	}
}

int main()
{
	int n;
	cin >> n;
	vector<int> as(n - 1), bs(n - 1);
	for (int i = 0; i < n - 1; i++)
	{
		cin >> as[i] >> bs[i];
		as[i]--;
		bs[i]--;
	}

	vector<vector<pair<int, int>>> g(n);
	for (int i = 0; i < n - 1; i++)
	{
		g[as[i]].emplace_back(bs[i], i);
		g[bs[i]].emplace_back(as[i], i);
	}

	vector<int> deg(n);
	for (int i = 0; i < n - 1; i++)
	{
		deg[as[i]]++;
		deg[bs[i]]++;
	}

	vector<int> ans(n - 1, 0);

	solve(n, g, ans);

	cout << *max_element(deg.begin(), deg.end()) << endl;
	for (auto &&c : ans)
	{
		cout << c << endl;
	}

	return 0;
}

Measured memory_bytes: 8960
#include<stdio.h>
int main()
{
    long int a,b,c,co=0;
    while(scanf("%ld%ld",&a,&b)!=EOF)
    {
        c=a+b;
         co=0;

        while(c>0)
        {
             c=c/10;
            co++;
        }
      printf("%ld\n",co);
    }
    return 0;
}

Measured memory_bytes: 600
object Main{
  def main(args: Array[String]){
      	val ct1 = io.StdIn.readLine
    	val ct = io.StdIn.readLine().split(" ").map(_ .toInt)
    val mx = ct.max
		val ret = if((ct.sum - mx) > mx){
        "Yes"
        }else{
          "No"
        }
      println(ret);
  }
}

Measured memory_bytes: 25548
#include <bits/stdc++.h>
using namespace std;
#define fast_io cin.tie(0);ios_base::sync_with_stdio(0);
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cout << endl; }
void show() { cout << endl; }
void pret() { cout << endl; exit(0);}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cout << " " << to_string(H); debug_out(T...);}
template <typename Head, typename... Tail> void show(Head H, Tail... T) {cout <<H<<" "; show(T...);}
template <typename Head, typename... Tail> void pret(Head H, Tail... T) {cout <<H<<" "; pret(T...);}
#define pr(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
#define int ll
typedef long double ld;
#define disp(x) cout<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(int)b;i++)
#define fo(i,a,b) for(int i=a;i<=(int)b;i++)
#define rf(i,a,b) for(int i=a;i>=(int)b;i--)
#define mp make_pair
#define pb emplace_back
#define F first
#define S second
#define endl '\n'
//cout.setf(ios::fixed);cout.precision(18)
const int MOD = 1e9+7;
const int N = 300000+10;

int32_t main(){
	fast_io;
	int n, k;
	cin >> n >> k;
	int a[n + 1];
	a[0] = 0;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
		a[i]--;
	}
	map<int, int> m;
	m[0] = 1;
	int ans = 0;
	for (int i = 1; i <= n; ++i)
	{
		if(i) a[i] += a[i - 1];
		a[i] %= k;
		if(i - k >= 0) m[a[i - k]]--;
		// show(a[i], m[a[i]]);
		ans += m[a[i]];
		m[a[i]]++;
	}
	show(ans);
	return 0;
}

Measured memory_bytes: 17616
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

int main(){
	int N,M;
	cin>>N>>M;
	map <long,int>arr;
	vector<long>arr1;
	long tmp;
	for(int i=0;i<N;++i){
		cin>>tmp;
		if (arr[tmp]==0){
			arr1.push_back(tmp);
		}
		arr[tmp]++;
	}
	int tmp1;
	for(int i=0;i<M;++i){
		cin>>tmp1>>tmp;
		if (arr[tmp]==0){
			arr1.push_back(tmp);
		}
		arr[tmp]+=tmp1;
	}
	sort(arr1.begin(),arr1.end(),greater<long>());
	long ans = 0;
	for(int i=0;i<arr1.size();++i){
		/*
		cout<<arr1[i]<<endl;
		cout<<arr[arr1[i]]<<endl;
		cout<<endl;
		*/
		if(N<=arr[arr1[i]]){
			ans+=arr1[i]*N;
			break;
		}
		else{
			ans+=arr1[i]*arr[arr1[i]];
			N-=arr[arr1[i]];
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 14320
/***
 ** " I have not failed. I've just found 10,000 ways that won't work. "
 **     -- Thomas Edison
***/

/**
  *  Author: dhruv_gheewala
  *  Problem: Lunlun Number
  *  Date:   06.04.2020
  *  Time:   14:25:58
**/

#if __has_include("debug.h")
    #include "debug.h"
#else
    #include<bits/stdc++.h>
    using namespace std;

    #define p(str) 7
    #define o(str) 42
    #define fundri 108
    #define d(...) 1729
#endif


typedef unsigned int ui;
typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

const bool testcases = 0;
#define ff first
#define ss second
#define endl '\n'
#define all(s) s.begin(),s.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define test int T = 1;if(testcases)cin >> T;for(int tc = 1 ; tc <= T ; tc++)
#define make_unique(vec) sort(all(vec));vec.erase(unique(all(vec)),vec.end())
#define sort_by(cont,expr) sort(all(cont),[&](const auto &lhs,const auto &rhs){return expr;})

ll seed;mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l=0,int r=INT_MAX){return uniform_int_distribution<int>(l,r)(rng);}

template<typename T>bool isPrime(T n){for(T i=2;i*i<=n;i++)if(n%i==0)return 0;return 1;}
template<typename T>inline bool in_range(T a,T l,T r){return (a>=l&&a<=r);}

template<typename T,typename U>inline istream& operator >>(istream& in,pair<T,U> &a)
{in>>a.ff>>a.ss;return in;}
template<typename T>inline istream& operator >>(istream& in,vector<T> &a)
{for(auto &x : a)in>>x;return in;}
template<typename TAIL>inline void inp(TAIL& T){cin>>T;}
template<typename HEAD,typename... TAIL>inline void inp(HEAD &H,TAIL&... T){cin>>H;inp(T...);}

int main(int argc, char **argv)
{
    std::chrono::time_point<std::chrono::high_resolution_clock> start_time, end_time;
    start_time = std::chrono::high_resolution_clock::now();

    #ifdef DHRUV_GHEEWALA
        freopen("INPUT.txt","r",stdin);
        freopen("OUTPUT.txt","w",stdout);
        freopen("DEBUG.txt","a",stderr);
    #endif
    
    fast;
    int k;
    test
    {
        cin >> k;
        queue<ll> q;
        for(int i = 1 ; i < 10 ; i++)
        	q.push(i);
        while(k > 1)
        {
        	ll fir = q.front();
        	q.pop();
        	int rem = fir % 10;
            if(rem != 0)
                q.push(fir * 10 + rem - 1);
            q.push(fir * 10 + rem);
            if(rem != 9)
                q.push(fir * 10 + rem + 1);
        	k--;
        }
        cout << q.front() << endl;
        fundri;
    }

    end_time = std::chrono::high_resolution_clock::now();
    ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
    o("\n\n");
    if(elapsed_time<10000)
        o("Elapsed Time: "<<elapsed_time<<" ms\n");
    else
        o("Elapsed Time: "<<elapsed_time/1000<<" s\n");

    return 0;
}

Measured memory_bytes: 1792
#2
n,m,x,y = map(int,input().split())
listx = [int(i) for i in input().split()]
listy = [int(i) for i in input().split()]
listx.append(x)
listy.append(y)
maxx = max(listx)
miny = min(listy)
if (miny > maxx):
    print("No War")
else:
    print("War")

Measured memory_bytes: 38256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

const int LEN = 1000010;

struct pp{
    string name;
    int time;
};

vector<pp> Q(LEN);
int head = 0, tail = 0;

bool isEmpty(){
    return tail == head;
}

void enqueue(pp x){
    Q[tail] = x;
    if(tail + 1 == LEN) tail = 0;
    else tail++;
}

pp dequeue(){
    pp x = Q[head];
    if(head + 1 == LEN) head = 0;
    else head++;
    return x;
}

int main(){
    int n, q;
    cin >> n >> q;
    rep(i, n){
        pp tmp;
        cin >> tmp.name >> tmp.time;
        enqueue(tmp);
    }
    int t = 0;
    while(!isEmpty()){
        pp h = dequeue();
        if(h.time <= q){
            t += h.time;
            cout << h.name << ' ' << t << endl;
        }
        else {
            t += q;
            h.time -= q;
            enqueue(h);
        }
    }
}


Measured memory_bytes: 20756
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;

deque<long long int> dq;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,i;
	cin >> n;
	string s;
	int value;
	deque<long long int>::iterator it = dq.begin();
	for(i=0;i<n;++i){
		cin >> s;
		if(s=="insert"){
			cin >> value;
			dq.push_front(value);
		} else if (s=="delete"){
			cin >> value;
			deque<long long int>::iterator itr = dq.begin();
			while(itr!=dq.end()){
				if(*itr==value){
					dq.erase(itr);
					break;
				}
				itr++;
			}
		} else if (s=="deleteFirst"){
			dq.pop_front();
		} else if (s=="deleteLast"){
			dq.pop_back();
		}
	}
	int cnt=0;

	for(it=dq.begin();it!=dq.end();++it){
		cnt++;
	}
	for(i=0 ; i<cnt-1 ; ++i){
		cout << dq[i] << " ";
	}
	cout << dq[i];
	cout << endl;
	return 0; 
}

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

using namespace std;

#define INF 1001000100010001000
#define int long long 
#define rep(i, N) for (int i = 0; i < N; i++)
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define vi vector<int>
#define vvi vector< vi >


signed main()
{
    int n;
    cin >> n;

    vi data(n);
    rep(i, n) cin >> data[i];

    int ans = 0, pos = -1, cnt = 0;
    bool state = data[0] < data[1];
    rep(i, n-1) {
        if (data[i] != data[i+1]) {
            state = data[i] < data[i+1];
            cnt = 2;
            pos = i+1;
            break;
        }
    }
    if (pos == -1) {
        cout << 1 << endl;
        return 0;
    }

    for (int i = pos+1; i < n; i++) {
        if (data[i-1] == data[i]) {
            ;
        } else if (state == (data[i-1] < data[i])) {
            cnt++;
        } else {
            state = !state;
            ans = max(cnt, ans);
            cnt = 2;
        }
    }

    ans = max(ans, cnt);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3576
a=sorted(list(map(int,[input()for i in range(5)])),key=lambda x:x%10)
if ''.join([str(i)[-1]for i in a])=='00000':print(sum(a));quit()
while str(a[0])[-1]=='0':
  a+=[a[0]]
  del a[0]
print(sum([a[0]]+[10*(0--i//10)for i in a[1:]]))

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
  char n[2];
  string ans="No";
  cin >> n[0] >>n[1];
  if(n[0]=='9'||n[1]=='9'){
    ans="Yes";
  }

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


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;
const ll MOD = 1e9+7;
const ll INF = 1e18;


#define PB push_back
#define MP make_pair
#define F first
#define S second

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
  	ll n;
  	cin >> n;
	set<string> ss;
  	for(ll i=0;i<n;i++){
    	string tmp;
      	cin >> tmp;
      	ss.insert(tmp);
    }
  	cout << ss.size() << endl;
}

Measured memory_bytes: 19228
x, n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(n):
    if p[i] - x >= 0:
        p[i] = 2 * (p[i] - x)
    else:
        p[i] = (x - p[i]) * 2 - 1
p = sorted(p)
i = 0
while i in p:
    i += 1
if i % 2 == 0:
    j = round(i / 2) + x
else:
    j = x - round((i + 1) / 2)
print(j)

Measured memory_bytes: 9092
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main ()
{
	int a,b,c,d,e,ss;
	
	cin>>a>>b>>c>>d>>e;
	if(a<40)a=40;
	if(b<40)b=40;
	if(c<40)c=40;
	if(d<40)d=40;
	if(e<40)e=40;
	ss=(a+b+c+d+e)/5;
	
	cout<<ss<<endl;
	
	
	
return 0;	
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;cin>>a>>b>>c>>d;
  string ans="Balanced";
  if(a+b<c+d)ans="Right";
  if(a+b>c+d)ans="Left";
  cout << ans << endl;
}

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

import sys
import os
import math

def second_to_str(second):
    T = second // 3600
    second -= 3600 * T

    H = second // 60
    second -= 60 * H

    S = second
    return "{:02d}:{:02d}:{:02d}".format(T, H, S)

for s in sys.stdin:
    T, H, S = map(int, s.split())
    if T == H == S == -1:
        break

    past_second = T * 3600 + H * 60 + S

    rest_second = 120 * 60 * 1 - past_second
    rest_second_3x = rest_second * 3

    print(second_to_str(rest_second))
    print(second_to_str(rest_second_3x))

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

int main(void){
  int i,j,l;
  char str[105],s[105],t[105],*p,buff;
  
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  strcpy(s,p);
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  strcpy(t,p);
  
  l=strlen(s);
  
  if(strcmp(s,t)==0){
    printf("Yes\n");
    return 0;
  }
  
  for(i=1;i<l;i++){
    buff=s[l-1];
    for(j=l-1;j>0;j--){
      s[j]=s[j-1];
    }
    s[0]=buff;
    if(strcmp(s,t)==0){
      printf("Yes\n");
      return 0;
    }
  }
  
  if(i==l){
    printf("No\n");
    return 0;
  }
  
}

Measured memory_bytes: 128
n = int(input())
D = list(map(int, input().split()))

kaihuku =0

for i in range(n-1):
    #1つめのたこ焼きを選ぶ
    first = D.pop(0)
    #2つ目のたこ焼きを選ぶ
    for j in range(len(D)):
        kaihuku += first*D[j]
print(kaihuku)

    


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

using namespace std;

typedef long long ll;

const int INF = 1e9;

class Die {
public:
  Die(vector<int> numbers) {
    vertical_ = vector<int>(4);
    horizontal_ = vector<int>(4);
    vertical_[0] = numbers[0];
    vertical_[1] = numbers[4];
    vertical_[2] = numbers[5];
    vertical_[3] = numbers[1];
    horizontal_[0] = numbers[0];
    horizontal_[1] = numbers[2];
    horizontal_[2] = numbers[5];
    horizontal_[3] = numbers[3];
  }

  int get_top() const { return vertical_[0]; }
  int get_right() const { return horizontal_[1]; }
  int get_front() const { return vertical_[3]; }
  void rotate_north()
  {
    rotate(vertical_.rbegin(), vertical_.rbegin() + 1, vertical_.rend());
    update(vertical_, horizontal_);
  }
  void rotate_south()
  {
    rotate(vertical_.begin(), vertical_.begin() + 1, vertical_.end());
    update(vertical_, horizontal_);
  }
  void rotate_east()
  {
    rotate(horizontal_.rbegin(), horizontal_.rbegin() + 1, horizontal_.rend());
    update(horizontal_, vertical_);
  }
  void rotate_west()
  {
    rotate(horizontal_.begin(), horizontal_.begin() + 1, horizontal_.end());
    update(horizontal_, vertical_);
  }

  int find_right(int top, int front)
  {
    if (find(horizontal_.begin(), horizontal_.end(), front) != horizontal_.end()) {
      while (get_top() != front) {
        rotate_east();
      }
    }
    while (get_front() != front) {
      rotate_north();
    }

    while (get_top() != top) {
      rotate_east();
    }
    return get_right();
  }

  bool operator==(const Die& rhs) const
  {
    Die d1 = rhs;
    for (int i = 0; i < 4; ++i) {
      Die d2 = d1;
      for (int j = 0; j < 4; ++j) {
        Die d3 = d2;
        for (int k = 0; k < 4; ++k) {
          Die d4 = d3;
          for (int l = 0; l < 4; ++l) {
            if (vertical_ == d4.vertical_ && horizontal_ == d4.horizontal_) {
              return true;
            }
            d4.rotate_west();
          }
          d3.rotate_south();
        }
        d2.rotate_east();
      }
      d1.rotate_north();
    }
    return false;
  }

  string dump() const
  {
    stringstream ss1, ss2;
    for (int i = 0; i < 4; ++i) {
      ss1 << vertical_[i] << ",";
      ss2 << horizontal_[i] << ",";
    }
    return ss1.str() + "|" + ss2.str();
  }

private:
  vector<int> vertical_, horizontal_;

  void update(vector<int>& from, vector<int>& to)
  {
    to[0] = from[0]; to[2] = from[2];
  }

};

int main()
{
  vector<int> nums1(6), nums2(6);
  for (int i = 0; i < 6; ++i) {
    fscanf(stdin, "%d", &nums1[i]);
  }
  for (int i = 0; i < 6; ++i) {
    fscanf(stdin, "%d", &nums2[i]);
  }
  Die d1(nums1), d2(nums2);
  string ans = d1 == d2 ? "Yes" : "No";
  fprintf(stdout, "%s\n", ans.c_str());
  return 0;
}

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

int pwr(int n){
  int s = 1;
  for (int i = 0; i < n; i++) {
    s = s * 10;
  }
  if (n == 0){
    return 1;
  }
  else {
    return s;
  }
  
}


int main() {
  int N, C=0, S = 30;
  cin >> N;

  for (int i = 0; i < 10; i++) {
    C = C + (N / pwr(i)) % 10;
  }
  if (N % C == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  bool F=false;
  cin>>N;
  vector<long long>vec(N);
  for(int X=0;X<N;X++){
    cin>>vec[X];
    if(vec[X]%2==1){
      F=true;
    }
  }
  if(F==true){
    cout<<"first"<<endl;
  }
  else{
    cout<<"second"<<endl;
  }
}

Measured memory_bytes: 3992
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int[] W = new int[N];

		for (int i = 0; i < N; i++) {
			W[i] = sc.nextInt();
		}

		int ans = Integer.MAX_VALUE;

		for (int i = 0; i < N - 1; i++) {
			int s1 = 0;
			int s2 = 0;

			for (int j = 0; j <= i; j++) {
				s1 += W[j];
			}

			for (int j = i + 1; j < N; j++) {
				s2 += W[j];
			}

			int a = Math.abs(s1 - s2);

			ans = Math.min(ans, a);
		}

		out.println(ans);

		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


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

using namespace std;
typedef long long ll;

int main(){
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  
  int ret = 0;
  if (K <= A){
    ret = K;
  }else if (K <= A+ B){
    ret = A;
  }else{
    ret = 2 * A + B - K;
  }
  
  cout << ret << endl;
  return 0;
}

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

void solve(vector<vector<LL>>& V,LL L,LL R,LL idx){
  if(R-L<=2){
    if(R-L==2){
      V[L][L+1]=idx;
      V[L+1][L]=idx;
    }
    return;
  }
  LL half = (L+R)/2;
  FOR(i,L,half){
    FOR(j,half,R){
      V[i][j]=idx;
      V[j][i]=idx;
    }
  }
  solve(V,L,half,idx+1);
  solve(V,half,R,idx+1);
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  LL N;
  cin>>N;
  
  vector<vector<LL>> V(N,vector<LL>(N,0));
  
  solve(V,0,N,1);
  
  FOR(i,0,N-1){
    FOR(j,i+1,N){
      cout<<V[i][j];
      if(j!=N-1){
        cout<<" ";
      }
    }
    cout<<endl;
  }
}


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

#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

inline void Main() {
  // code
  int n,a,b;
  cin>>n>>a>>b;
  cout<<min(b,n*a)<<endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
A.sort()
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########
import bisect as bi
Q=deque(A)
rui=[pow(2,i) for i in range(31)]
ans=0
C=Counter(A)
# N={ i:0 for i in C.keys() }
while Q:
    k=Q.pop()
    if C[k]==0:continue
    for r2 in rui:
        if r2>2*k:break
        if C.get(r2-k,None)==None:continue
        if r2-k==k: 
            if C[k]<=1:continue
        if C[r2-k]==0: continue
        C[r2-k]-=1;C[k]-=1;ans+=1

print(ans)


Measured memory_bytes: 126608
# h,n,*a=map(int,open(0).read().split())

# h = int(input())
n, k = [int(x) for x in input().split()]
# k = int(input())

# ヨコ
h = [int(x) for x in input().split()]

# タテ
# m = [int(input()) for _ in range(N)]
if n <= k:
  print(0)
  exit()

h = sorted(h)

h = h[:n-k]
print(sum(h))

Measured memory_bytes: 26764
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int x[n] = {};
    int y[n] = {};
    for(int i=0; i<n; i++){
        cin >> x[i] >> y[i];
    }
    
    vector<int> v(n);
    iota(v.begin(), v.end(), 0);
    long long count = 0;
    double sum = 0;
    do{
        for(int k=0; k<n-1; k++){
            int i = v[k];
            int j = v[k+1];
            sum += sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
        }
        count++;
    }while(next_permutation(v.begin(), v.end()));
    
    cout << fixed << setprecision(10) << sum/(double)count << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

ll N;
map<ll, ll> mp;
ll pow2[61];

signed main(){
    cin >> N;
    unsigned long long a;
    REP(i, N){
        cin >> a;
        REP(j, 61){
            if(a == 0) continue;
            if(a % 2 == 1) mp[j]++;
            a /= 2;
        }
    }
    pow2[0] = 1;
    REP(i, 60) pow2[i + 1] = (pow2[i] * 2) % MOD;
    ll ans = 0;
    REP(i, 61){
        ll k = mp[i] * (N - mp[i]) % MOD;
        ans = (ans + k * pow2[i] % MOD) % MOD;
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 3596