akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

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

    ll ans = 0;
    for(int i=0;i<=1;i++){
        int mid = n/2;
        if(n%2==0) mid-=i;

        // i=0 -> 先にtail
        // i=1 -> 先にhead
        queue<ll> que1,que2;
        for(int j=n-1;j>mid;j--) que1.push(a[j]);
        for(int j=0;j<mid;j++) que2.push(a[j]);

        if(i==0) swap(que1,que2);

        vector<ll> res;
        res.emplace_back(a[mid]);

        while(!que1.empty() or !que2.empty()){
            if(!que1.empty()){
                res.push_back(que1.front());
                que1.pop();
            }
            if(!que2.empty()){
                res.push_back(que2.front());
                que2.pop();
            }
        }

        ll calc=0;
        for(int i=1;i<n;i++){
            calc += abs(res[i]-res[i-1]); 
        }
        chmax(ans,calc);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3688
#include <stdio.h>
#include <stdbool.h>
int main(void)
{
    int i, j, n; 
    char mark; 
    char marks[4]={'S', 'H', 'C', 'D'}; 
    int num; 
    bool cards[4][13]={false}; 
 
    scanf("%d ", &n); 
    for(i=0;i<n;i++){ 
        scanf("%c %d ", &mark, &num); 
        for(j=0;j<4;j++){ 
            if(mark==marks[j]){ 
                cards[j][num-1]=true; 
                break; 
            } 
        } 
    } 
    for(i=0;i<4;i++){ 
        for(j=0;j<13;j++){ 
            if(!cards[i][j]){ 
                printf("%c %d\n", marks[i], j+1); 
            } 
        } 
    } 
    return 0; 
} 



Measured memory_bytes: 2124
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

char in[20][20];
vector<int> v;
const int K=100*1000;
int dp[2][1<<20];
int M,N;
int main() {
	scanf("%d%d",&M,&N);
	int ret=1;
	for(int i=0;i<M;i++){
		scanf("%s",in[i]);
		for(int j=0;j<N;j++){
			if(in[i][j]=='?'){
				ret*=3;
				ret%=K;
			}
		}
	}
	auto cur=dp[0];
	auto nex=dp[1];
	cur[0]=1;
	for(int i=0;i<(1<<N);i++){
		bool ok=true;
		for(int j=0;j<N-1;j++){
			if(i&(1<<j)&&(i&(1<<(j+1)))){
				ok=false;
				break;
			}
		}
		if(ok){
			v.push_back(i);
			////cout << i << endl;
		}
	}
	for(int i=0;i<M;i++){
		for(int j=0;j<N;j++){
			//cout << i << ", " << j << endl;
			for(auto k:v){
				int p0=(k>>1);
				int p1=(k>>1)|(1<<(N-1));
				int sj,so,si;
				if((k&1)==0){
					sj=0;
				}
				else{
					sj=cur[p0]+cur[p1]+cur[p0|1]+cur[p1|1];
				}
				if((k&1)==1){
					so=0;
				}
				else if(j==0&&(k&2)){
					so=0;
				}
				else{
					so=cur[p0]+cur[p1];
					if(j==0){
						if((p0&1)==0){
							so+=cur[p0|1];
						}
						if((p1&1)==0){
							so+=cur[p1|1];
						}
					}
				}
				if((k&1)==1){
					si=0;
				}
				else if(p0&1){
					si=0;
				}
				else{
					si=cur[p0];
					if((p0&1)==0){
						si+=cur[p0|1];
					}
				}
				switch(in[i][j]){
					case 'J':nex[k]=sj;break;
					case 'O':nex[k]=so;break;
					case 'I':nex[k]=si;break;
					default:nex[k]=sj+so+si;break;
				}
				nex[k]%=K;
				//cout << k << ": " << nex[k] << ", " << sj << ", " << so << ", " << si << endl;
			}
			swap(nex,cur);
			//cout << endl;
		}
	}
	int ret1=0;
	for(auto k:v){
		ret1+=cur[k];
		ret1%=K;
	}
	//cout << ret1 << endl;
	printf("%d\n",(ret+K-ret1)%K);
}

Measured memory_bytes: 7828
N,M,X,Y=map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
x.sort(reverse=True)
y.sort()
if x[0] < y[0] and X < y[0] and x[0] < Y:
  print("No War")
else:
  print("War")
  

Measured memory_bytes: 2940
#include<stdio.h>
int main(){
  int n,k,i,j;
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    int r[10]={0};
    char t[10],w;
    for(i=0;i<n;i++){
      scanf("\n%c",&t[i]);
      for(j=1;j<n;j++){
	scanf("%d",&k);
	if(k==0)r[i]+=10;
	if(k==1)r[i]--;
      }
      // scanf("\n");
      //printf("%d %c",r[i],t[i]);
    }
    for(i=0;i<n;i++){
      for(j=1;i+j<n;j++){
	if(r[j-1]<r[j]){
	  k=r[j-1];
	  r[j-1]=r[j];
	  r[j]=k;
	  w=t[j-1];
	  t[j-1]=t[j];
	  t[j]=w;
	}
      }
    }
    for(i=0;i<n;i++){
      printf("%c\n",t[i]);
    }
  }
  return 0;
}

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

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M = list(map(int,input().split()))
Network = UnionFind(N)

out=0
for i in range(M):
    a,b = list(map(int,input().split()))
    Network.union(a-1,b-1)
print(-1*min(Network.parents))

Measured memory_bytes: 82644
#include<cstdio>
#define maxn 100050
using namespace std;
int a[maxn],f[maxn];
int main(){
	int n,ans=0;
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if (a[i-1]>=a[i]) f[i]=f[i-1]+1;else f[i]=0;
		if (f[i]>ans) ans=f[i];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
char c[2][3];
bool flag = 1;
int main(){
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < 3; j++){
            cin >> c[i][j];
        }
    }
    
    for(int j = 0; j < 3; j++){
        if(c[0][j] != c[1][2-j]){
            flag = 0;
        }
    }
    
    if(flag){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
}

Measured memory_bytes: 256
#include <cstdio>

const int MAX_N = 100000;
int last[1+MAX_N], next[1+2*MAX_N], mc[1+2*MAX_N], cost[1+2*MAX_N];
long long d[1+MAX_N];

inline void addM(int a, int b, int c, int id) {
  next[id] = last[a];
  last[a] = id;
  cost[id] = c;
  mc[id] = b;
}

void dfs(int nod, int papa, long long c) {
  d[nod] = c;
  for(int i = last[nod]; i != 0; i = next[i])
    if(mc[i] != papa) {
      dfs(mc[i], nod, c + cost[i]);
    }
}

int main() {
  int n, a, b, c, q, k;
  scanf("%d", &n);
  for(int i = 0; i < n - 1; ++i) {
    scanf("%d%d%d", &a, &b, &c);
    addM(a, b, c, 2 * i + 1);
    addM(b, a, c, 2 * i + 2);
  }
  scanf("%d%d", &q, &k);
  dfs(k, -1, 0);
  for(int i = 0; i < q; ++i) {
    scanf("%d%d", &a, &b);
    printf("%lld\n", d[a] + d[b]);
  }
  return 0;
}


Measured memory_bytes: 9856
#include <stdio.h>
#include <stdlib.h>

typedef struct {
  long color;
	long connected;
} S_VERTICE;

int main(void) {

  long n;
  scanf("%ld", &n);
  long **tree;
  tree = (long **)malloc(sizeof (long*) * (n+1));
  for (long i = 0; i < n+1; i++) {
    tree[i] = (long *)malloc(sizeof (long) * (n+1));
    tree[i][0] = 0;
  }
  for (long i = 1; i <= n; i++) {
    tree[0][i] = 0;
  }
	long **length;
	length = (long **)malloc(sizeof (long*) * (n+1));
  for (long i = 0; i < n+1; i++) {
    length[i] = (long *)malloc(sizeof (long) * (n+1));
  }
  long u,v,w;
  for (long i = 0; i < n-1; i++) {
    scanf("%ld %ld %ld", &u, &v, &w);
    tree[u][0]++;
    tree[u][tree[u][0]] = v;
		length[u][tree[u][0]] = w%2;
    tree[v][0]++;
    tree[v][tree[v][0]] = u;
		length[v][tree[v][0]] = w%2;
  }
  S_VERTICE vertices[n+1];
  for (long i = 1; i <= n; i++) {
    vertices[i].color = 0;
    vertices[i].connected = 0;
  }
	vertices[1].color = -1;

  long cur = 1;
	long next;
  while (1) {
    tree[0][cur]++;
    if (tree[0][cur] <= tree[cur][0]) {
			next = tree[cur][tree[0][cur]];
			if (next == vertices[cur].connected) {
	      continue;
	    }
			if (length[cur][tree[0][cur]] == 0) {
				vertices[next].color = vertices[cur].color;
			} else {
				vertices[next].color = vertices[cur].color*(-1);
			}
			vertices[next].connected = cur;
			cur = next;
    } else {
      if (cur == 1) {
        break;
      }
      cur = vertices[cur].connected;
    }
  }

	free(tree);
	free(length);

  for (long i = 1; i <= n; i++) {
		if (vertices[i].color == -1) {
			printf("0\n");
		} else {
			printf("1\n");
		}
  }

  return 0;
}


Measured memory_bytes: 807552
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    S, T = input().split()
    A, B = map(int, input().split())
    U = input()[:-1]
    if U == S:
        A -= 1
    else:
        B -= 1
    
    print(A, B)


if __name__ == '__main__':
    main()

Measured memory_bytes: 63980
#include<bits/stdc++.h>
using namespace std;
int n,h,a;
int main()
{
	scanf("%d%d",&h,&n);
	while(n--)
	{
		scanf("%d",&a);
		h-=a;
	}
	if(h<=0)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
//This is a O(n^2) implementation of the problem (Reference: Errichto's youtube video)
int main(){
    int n;
    string s;
    cin>>n>>s;
    int dp[n+1][n+1];
    int pref[n];
    //dp[i][j] means how many permutations exist with n=i and last 
    //number in the perumtation ending with j
    //The main trick in this question is that, just knowing
    //Which number do you want to place at the current position
    //and all the possible numbers you could have placed in 
    //the previous position, you can find out the number of
    //ways for the numbers in the current position using the 
    //previous ones. Okay..Okay.. I didn't mean to confuse you
    //...Let me tell this straight suppose, you know what are
    //the answers for first two positions, like in the case
    //of "3 <>", for position 1, you have 1 possibility
    //1<2 (1 possiblity for position 2), now comes the trick,
    //For position 3 1<2>1 (The question is can you place one at the end?)
    //Turns out yes, you can, if the previous position was 
    //3, but you know previous position cannot be 3 because you 
    //only had 2 spots, right? There is the catch, you add
    //the number of ways for which previous spot was 2 
    //and you can (imagine) change the above relation to 2<3<1
    //for all such possiblities, basically what I am saying is
    //for every number of ways you find after solving for some
    //i positions, you only care about the previous digit that
    //is possible and for all such ways you can guarantee that
    //you can get a permutation which ends in j.
    memset(dp,0,(n+1)*sizeof(dp[0]));
    dp[1][1] = 1;
    for(int i=2;i<=n;i++){
        memset(pref,0,4*n);
        for(int j=1;j<=(i-1);j++){
            pref[j] = (pref[j-1]+dp[i-1][j])%mod;
        }
        for(int j=1;j<=i;j++){
            int l,r;
            if(s[i-2]=='>')l=j,r=i-1;
            else l=1,r=j-1;
            if(l<=r)
                dp[i][j] = (dp[i][j]+pref[r]-pref[l-1]+mod)%mod;
        }
    }
    int ans = 0;
    for(int j=1;j<=n;j++){
        ans = (ans+dp[n][j])%mod;
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 35456
from itertools import accumulate
import bisect

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

a_acc = [0] + list(accumulate(a))
b_acc = list(accumulate(b))

ans = 0
for i in range(n + 1):
    rem = k - a_acc[i]
    if rem < 0:
        break

    j = bisect.bisect_right(b_acc, rem)
    ans = max(ans, i + j)

print(ans)

Measured memory_bytes: 48996
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = str(input().rstrip('\n'))
    t = str(input().rstrip('\n'))
    a = len(s) + len(t)
    for i in range(n):
        if s[-i-1:] == t[:i+1]:
            a = len(s) + len(t) - len(t[:i+1])
    print(a)


if __name__ == '__main__':
    slove()


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

int main(){
 	int n;
 	cin >> n;
  	vector<int> dp(3);
  	for(int day=0;day<n;day++){
  		vector<int> new_dp(3,0);
  		vector<int> c(3);
  		for(int p = 0;p<3;p++){
  			cin >> c[p];
		}
  		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				if(i!=j){
					new_dp[j] = max(new_dp[j],dp[i]+c[j]);
				}
			}
		}	
		dp = new_dp;
	}
	cout << max(dp[0],max(dp[1],dp[2]));
	
}

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

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

    vector<int> A(N);
    rep(i, N) cin >> A.at(i);
    vector<int> C(100001);

    rep(i, N)
    {
        int a = A.at(i);
        C.at(a)++;
        C.at(a + 1)++;
        if (a > 0)
        {
            C.at(a - 1)++;
        }
    }

    int ans = 0;
    rep(i, C.size())
    {
        ans = max(ans, C.at(i));
    }

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

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

n, k =map(int, input().split())
td = [list(map(int, input().split())) for _ in range(n)]
td.sort(key=lambda x: x[1], reverse=True)

base = []; other = []
val = set()
yum = 0
for t, d in td[:k]:
    yum += d
    if t in val:
        other.append(d)
    val.add(t)
other.sort(reverse=True)

kouho = []
val_tmp = val.copy()
for t, d in td[k:]:
    if t not in val_tmp:
        kouho.append(d)
        val_tmp.add(t)
kouho.sort()

v = len(val)
ans = yum + (v*v)


while len(other) > 0 and len(kouho) > 0:
    yum -= other.pop()
    yum += kouho.pop()
    v += 1
    ans = max(ans, yum+(v*v))
print(ans)



Measured memory_bytes: 36600
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long T = sc.nextLong();
        long start = 0;
        long end = 0;
        long ans = 0;
        for (int i = 0; i < n; i++) {
            long t = sc.nextLong();
            if(t <= end) end = t + T;
            else{
                ans += end - start;
                start = t;
                end = t + T;
            }
            if(i == n - 1) ans += end - start;
        }

        System.out.println(ans);
        sc.close();
    }

}


Measured memory_bytes: 61436
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#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 rep2(i, n, m) for(int i=(int)n; i<=(int)m; i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> wi;
typedef vector<ll> vl;
const ll inf=1LL << 60;
const ll MOD=1000000007;

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

  int k;
  cin >> k;
  rep(i,k)cout << "ACL";
  cout << endl;

  return 0;
}

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

using namespace std;

int k;
int g[4002][4002];


int calc(int a, int b){
	int res;
	if(a < k && b < k){
		res = g[a][b];
	}else if(a < k){
		res = g[a][b] - g[a][b - k];
	}else if(b < k){
		res = g[a][b] - g[a - k][b];
	}else{
		res = g[a][b] - g[a][b - k] - g[a - k][b] + g[a - k][b - k];
	}
	return res;
}

int main(){
	int n, k2, k4, ans = 0;
	cin >> n >> k;
	k2 = 2 * k;
	k4 = 4 * k;
	//vector<vector<int>> g(k4, vector<int>(k4));
	for(int i = 0; i < n; i++){
		int a, b;
		char c;
		cin >> a >> b >> c;
		if(c == 'W') a += k;
		a %= k2; b %= k2;
		g[a][b]++;
		g[a + k2][b]++;
		g[a][b + k2]++;
		g[a + k2][b + k2]++;
	}
	for(int i = 1; i < k4; i++){
		g[0][i] = g[0][i - 1] + g[0][i];
		g[i][0] = g[i - 1][0] + g[i][0];
	}
	for(int i = 1; i < k4; i++){
		for(int j = 1; j < k4; j++){
			g[i][j] = g[i][j] + g[i][j - 1] + g[i - 1][j] - g[i - 1][j - 1];
		}
	}
	for(int i = k - 1; i < k2 + k; i++){
		for(int j = k - 1; j < k2 + k; j++){
			ans = max(ans, calc(i, j) + calc(i + k, j + k));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 62720
a, b, c, x, y = map(int, input().split())

INF = (10**5)*a + (10**5)*b + 1
ans = INF

c = 2*c

m = max(x, y)

for num in range(m+1):
    num_x = max(0, x - num)
    num_y = max(0, y - num)
    ans = min(num_x*a + num_y*b + num*c, ans)

print(ans)


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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }

int main()
{
  int a,b;
  cin >> a >> b;

  cout << max(a+b,max(a-b,a*b)) << endl;

  return 0;
}


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

int main() {
  int N;
  vector<int> P(N), NUM(N);
  vector<string> S(N);
  cin >> N;
  for (int i=0; i<N; i++) {
    NUM.at(i) = i+1;
    cin >> S.at(i) >> P.at(i);
  }
  
  for (int i=1; i<N; i++) {
    for (int j=i; j!=0; j--) {
      if (S.at(j) < S.at(j-1) || (S.at(j) == S.at(j-1) && P.at(j) > P.at(j-1))) {
        string a;
        int b, c;
        a = S.at(j);
        S.at(j) = S.at(j-1);
        S.at(j-1) = a;
        b = P.at(j);
        P.at(j) = P.at(j-1);
        P.at(j-1) = b;
        c = NUM.at(j);
        NUM.at(j) = NUM.at(j-1);
        NUM.at(j-1) = c;
      }        
      else {
        break;
      }
    }
  }
  
  for (int i=0; i<N; i++){
    cout << NUM.at(i) << endl;
  }
        
}



Measured memory_bytes: 768
//by ciwomuli
//AK JSOI 2019
//I love wyt
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <sstream>
#define LL long long
using namespace std;
template <typename T>
inline void read(T &t)
{
    int f = 0, c = getchar();
    t = 0;
    while (!isdigit(c))
        f |= c == '-', c = getchar();
    while (isdigit(c))
        t = t * 10 + c - 48, c = getchar();
    if (f)
        t = -t;
}
template <typename T, typename... Args>
inline void read(T &t, Args &... args)
{
    read(t);
    read(args...);
}
int x[10], y[10], n;
bool used[10];
int ord[10];
int cnt;
double sum = 0;
int fact(int n){
    int ans = 1;
    for (int i = 1;i<=n;i++) ans *=i;
    return ans;
}
void work(int curr){
    if(curr == n+1) {
        double tmp = 0;
        for (int i = 1; i < n;i++){
            tmp += sqrt((x[ord[i]] - x[ord[i + 1]]) * (x[ord[i]] - x[ord[i + 1]]) + (y[ord[i]] - y[ord[i + 1]]) * (y[ord[i]] - y[ord[i + 1]]));
        }
        //tmp += sqrt((x[n] - x[1]) * (x[n] - x[1]) + (y[n] - y[1]) * (y[n] - y[1]));
        sum+=tmp;
        return;
    }
    for (int i = 1; i <= n;i++){
        if(!used[i]){
            ord[curr] = i;
            used[i] = true;
            work(curr + 1);
            used[i] = false;
        }
    }
}
int main(){
    read(n);
    for (int i = 1;i<=n;i++){
        read(x[i], y[i]);
    }
    work(1);
    printf("%.08lf", sum / fact(n));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string S;
  cin>>N>>S;
  int A[N]={0};
    for(int i=0;i<N-1;i++){
      int B[26]={0},C[26]={0},D[26];
      for(int j=0;j<i+1;j++) B[S[j]-'a']=1;
      for(int j=i+1;j<N;j++) C[S[j]-'a']=1;
      for(int j=0;j<26;j++) D[j]=B[j]*C[j];
      for(int j=0;j<26;j++) A[i]+=D[j];
    }
    sort(A,A+N);
    cout<<A[N-1]<<endl;
}

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

int main() {
    string s;cin>>s;
    int ans=0;
    int r=0;
    rep(i,3)if(s[i]=='R')++r;
    
    if(r==3 ||r==1 || r==0)ans=r;
    if(r==2 && s[1]=='R')ans=2;
    if(r==2 && s[1]!='R')ans=1;
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3620
import           Data.List
import           Control.Applicative
import           Control.Monad
import           Control.Monad.State

flags :: [Int] -> [Bool]
flags xs = map (\(a, b) -> a == b) $ zip xs [1 ..]

counts (True         : True  : xs) = 1 + counts xs
counts (True         : False : xs) = 1 + counts xs
counts (False : True : True  : xs) = 1 + counts xs
counts (False        : True  : xs) = 1 + counts xs
counts (False                : xs) = 0 + counts xs
counts [True                     ] = 1
counts []                          = 0

main = do
  n  <- readLn
  ns <- take n . map (read :: String -> Int) . words <$> getLine
  print $ counts $ flags ns



Measured memory_bytes: 32116
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    string s;cin>>s;
    ll x,y;cin>>x>>y;
    vector<ll>ff(0);
    vector<ll>tt(0);
    int f=0;
    int a=0;
    rep(i,s.size()){
        if(s[i]=='T'){
            if(ff.size()==0){
                x-=a;
                a=0;
                ff.pb(0);
            }
            if(f)tt.pb(a);
            else ff.pb(a);
            f=(1-f);
            a=0;
        }else{
            a++;
        }
    }
    if(ff.size()==0){
        x-=a;
        a=0;
        ff.pb(0);
    }
    if(f)tt.pb(a);
    else ff.pb(a);
    sort(rall(ff));
    sort(rall(tt));
    ll cntx=0;
    ll cnty=0;
    rep(i,ff.size()){
        if(cntx>=x){
            cntx-=ff[i];
        }else{
            cntx+=ff[i];
        }
    }
    rep(i,tt.size()){
        if(cnty>=y){
            cnty-=tt[i];
        }else{
            cnty+=tt[i];
        }
    }
    cout<<((cntx==x&&cnty==y)?"Yes":"No")<<endl;
}

Measured memory_bytes: 384
#include<algorithm>//everybody dies in their nightmares
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<string>
#include<vector>
#include<sstream>
#include<cmath>
#include<unordered_set>
#include<unordered_map>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const ll mod = 1e18 + 7;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);

const int N = 1e5 + 5;
int t;

int main()
{
	int n,m;
	while (cin >> n>>m)
	{
		ll sum = 0;
		if (n > 1)sum += n * (n - 1) / 2;
		if (m > 1)sum+=m*(m - 1) / 2;
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#define maxn 1000+15
using namespace std;

int main(){
	char s[20];
	scanf("%s",s);
	int flag=0;
	int flag2=0;
	int sum=0;
	int i;
	int n=strlen(s);
	if(s[0]!='A'){
			flag=1;
		}else{
		
	for(i=1;i<n;i++){
		if(s[i]>='a'&&s[i]<='z'){
			sum++;
		}else
		if(i>1&&i<n-1){
			if(s[i]=='C'){
				if(flag2==0){
					flag2=1;
				}else{
					flag=1;
					break;
				}
			}
		}

		
	}
	}
	if(flag2==0){
			flag=1;
		}
//	cout<<n<<" "<<sum<<endl;
	if(sum+2!=n){
		flag=1;
	}	
	if(flag){
		cout<<"WA"<<endl;
	}else{
		cout<<"AC"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    int n, k;
    scan(n, k);

    auto dp = new long[](2*n + 1);

    foreach (b ; 1 .. n + 1) {
        if (b <= k) continue;
        for (int r = b; r <= 2*n; r += b) {
            dp[r - (b - k)]++;
            dp[r]--;
        }
        debug {
            writeln(b, ":", dp);
        }
    }

    foreach (i ; 1 .. n + 1) {
        dp[i] += dp[i - 1];
    }

    debug {
        writeln(dp);
    }

    long ans;

    foreach (i ; 1 .. n + 1) {
        ans += dp[i];
    }

    writeln(ans);
}




void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n = 0, sum = 0, ans = 0;
	string s; cin >> s;
	for (int h = s.size() - 1; h >= 0; h--) {
		if (s[h] == 'B' && n == 1) {
			sum++; n = 0;
		}
		else if (s[h] == 'B' || n == 1) {
			sum = 0;
		}
		if (s[h] == 'A') {
			ans += sum;
		}
		if (s[h] == 'C') { n = 1; }
		else { n = 0; }
	}
	cout << ans << endl;
	cin >> n;
}

Measured memory_bytes: 640
def main():
    n = int(input())
    m = 1
    for i in range(2,int(n**0.5)+1):
        if n%i==0:
            m = i
    m_ = n//m
    print(max(len(str(m_)),len(str(m))))

if __name__ == "__main__":
    main()


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

int main() {
    int n;
    cin >> n;
    vector< int > a(n);

    for(int i = 0; i < n; i++) cin >> a[i];

    int cnt = 0;
    for(int i = 0; i < n; i++) {
        if(i + 1 != a[i] && a[a[i] - 1] == i + 1) {
            swap(a[i], a[a[i] - 1]);
            cnt++;
        }
    }

    for(int i = 1; i < n; i++) {
        if(a[i - 1] > a[i]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    if(cnt <= 1) cout << "YES" << endl;
    else cout << "NO" << endl; 
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>

#define INF 1 << 30
#define MOD 1000000007;
#define PI 3.14159265358979
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define D(x) cout << x << endl
#define d(x) cout << x
#define all(x) (x).begin(), (x).end()
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define mp(x, y) make_pair((x), (y))
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }

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

int main() { 
  string s;
  string t;
  cin >> s >> t;

  string ans = "";
  rep(i, s.size()) {
    ans += s[i];
    if (i < t.size()) {
      ans += t[i];
    }
  }

  D(ans);
  
  return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
     Scanner scan = new Scanner(System.in);
      int a = scan.nextInt();
      int b = scan.nextInt();
      int d = a / b;
      int r = a % b;
      double f = a / (double)b;
      System.out.printf(d + " " + r + " " + "%.8f",f );
     }
    }


Measured memory_bytes: 26524
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  char a;
  cin >> a;
  cout << (a > 'Z' ? 'a' : 'A');
}
#endif


Measured memory_bytes: 3644
#include <iostream>
#include <string.h>
#define ll long long
using namespace std;


void printA(int *A,int size)
{
    for(int i=0;i<size;i++)
        cout<<A[i]<<" ";
}
void scanA(int *A,int size)
{
    for(int i=0;i<size;i++)
        cin>>A[i];
}



int sum(int n);
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char a[4];
    cin>>a;
    if(a[1]=='R')
    {
        cout<<"ABC";
    }
    else
        cout<<"ARC";

}






Measured memory_bytes: 3600
function main(input) {
  const args = input.split('\n')
  const nm = args[0].split(' ')
  const n = Number(nm[0])
  const m = Number(nm[1])
  const works = args[1].split(' ').map(v => Number(v))
  const sum = works.reduce((prev, curr) => prev + curr)
  if (n < sum) {
    console.log(-1)
  } else {
    console.log(n - sum)
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 30692
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication7
{
    class Program
    {
        static void Main()
        {
            string word1 = Console.ReadLine();
            string word2 = Console.ReadLine();

            char[] c_word1 = word1.ToCharArray();
            char[] c_word2 = word2.ToCharArray();

            var result_c_word1 = word1.OrderBy(x => x).ToArray();
            var result_c_word2 = word2.OrderByDescending(x => x).ToArray();

            int result = string.Compare(new string(result_c_word1), new string(result_c_word2));

            if (result < 0) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  cout << ((b - a) % 2 == 0 ? "Alice" : "Borys") << '\n';
  return 0;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
//#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626 
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;
//https://tradingeconomics.com/forecast/stock-market

signed main() {

	fastio();
	//#define LOCAL_DEFINE	
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	string s;
	cin>>s;
	auto a=s.find('A');
	auto b=s.find('B');
	if(a!=string::npos && b!=string::npos)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

// https://github.com/FatihSevbanUyanik/Caltech-UCSD-Birds-PyTorch
// https://github.com/zctpig/Caltech-UCSD-Birds-200-2011/blob/master/%E2%80%9C%E2%80%9Cpytorch_caltech_birds_classification_ipynb%E2%80%9D%E7%9A%84%E5%89%AF%E6%9C%AC%E2%80%9D%E7%9A%84%E5%89%AF%E6%9C%AC.ipynb
// https://github.com/vinodjatav/Bird-Identification-using-ResNet50/blob/master/Bird_Identification_ResNet50_final_correct_model.ipynb
// https://github.com/AdrienBenamira/bird_classification_MVAchallenge
// https://www.kaggle.com/c/mva-recvis-2018/leaderboard
// https://github.com/Louis-Verret/mva-pixel2mesh
// https://github.com/bdvllrs/bird-classification-recvis



Measured memory_bytes: 256
N, Q = map(int, input().split())
AB = [[] for i in range(N + 1)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    AB[a].append(b)

X = [0] * (N + 1)
for _ in range(Q):
    p, x = map(int, input().split())
    X[p] += x

S = [1]
while len(S) > 0:
    p = S.pop()
    for c in AB[p]:
        X[c] += X[p]
        S.append(c)

print(" ".join(map(str, X[1:])))


Measured memory_bytes: 58964
#include <iostream>

using namespace std;

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

    bool ans = false;
    for (int i = n; i > 0; i/=10) {
        if ((i%10) == 9) {
            ans = true;
            break;
        }
    }

    cout << (ans ? "Yes" : "No") << endl;
}

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

int main(){
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
   
  if(abs(a-c) <= d){
    printf("Yes");
  }else if(abs(a-b) <= d && abs(b-c) <= d){
    printf("Yes");
  }else{
    printf("No");
  }
}

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


using namespace std;

#define ll long long
#define endl "\n"
#define YES  cout <<"YES"<<endl;
#define NO cout <<"NO"<<endl;
#define No cout <<"No"<<endl;
#define Yes cout <<"Yes"<<endl;
#define ff first
#define ss second
#define pb push_back
const ll maxn= 5e5+7;
const ll mod = 1e9+7;
ll a[maxn];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n, k;
    cin>>n>>k;
    priority_queue<ll,vector<ll>,greater<ll>>  q;
    priority_queue<ll>  q1;
   priority_queue<ll>  q2;
   ll t=1;
    for (int i=1; i<=n; i++)
    {
        cin>>a[i];
        if (a[i]>0)
        {
            q1.push(a[i]);

        }
        else
        {
            q2.push(a[i]);
            q.push(a[i]);
        }
        t=(t*a[i])%mod;
        t=(t+mod*mod)%mod;
    }
    if (n==k)
    {
        cout <<t;
        return 0;
    }
    if (q1.size()==0)
    {
        ll ans=1;
        if (k%2==0)
        {

          while (k--)
          {
           ans=ans*q.top();
           q.pop();
           ans=(ans+mod*mod)%mod;
          }
        }
        else
        {
           while (k--)
           {
               ans=ans*q2.top();
               q2.pop();
               ans=(ans+mod*mod)%mod;
           }
        }
        ans=(ans+mod*mod)%mod;
        cout <<ans;
        return 0;
    }
    ll ans=1;
    if (k%2==1)
    {
        k--;
        ans=ans*q1.top();
        q1.pop();
    }
    ans=(ans+mod*mod)%mod;
    for (int i=1;i<=k/2;i++)
    {
        ll t1=-1,t2=-1;
         vector<ll> q11;
         vector<ll> q01;
        if (q1.size()>=2)
        {
          t1=1;
          t1*=q1.top();
          q11.push_back(q1.top());
          q1.pop();
          t1*=q1.top();
          q11.pb(q1.top());
          q1.pop();
        }
        if (q.size()>=2)
        {
         t2=1;
          t2*=q.top();
          q01.push_back(q.top());
          q.pop();
          t2*=q.top();
          q01.pb(q.top());
          q.pop();
        }
       // cout <<t1<<" "<<t2<<endl;
        if (t1>t2)
        {
            //cout <<"co";
            t1%=mod;
            ans*=t1;
            for (auto h:q01)
            {
                q.push(h);
            }
        }

        else
        {
            t2%=mod;
            ans*=t2;
             for (auto h:q11)
            {
                q1.push(h);
            }
        }
        ans=(ans+mod *mod )%mod;
    }
    cout <<ans<<endl;

}


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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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






int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    double x;
    cin >> x;
    cout << fixed << setprecision(10) << 2.0*PI*x;
    return 0;
}


Measured memory_bytes: 3804
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI=3.14159265358979323846;

int main() {
    char b;
    cin >> b;

    map<char, char> m;
    m['A'] = 'T';
    m['C'] = 'G';
    m['G'] = 'C';
    m['T'] = 'A';

    cout << m[b] << endl;

    return 0;
}


Measured memory_bytes: 256
package main

import (
    . "fmt"
    "sort"
)

func main() {
    var a1, a2, a3 int
    Scanf("%d %d %d", &a1, &a2, &a3)

    var arr []int = []int{a1, a2, a3}

    sort.Sort(sort.IntSlice(arr))

    sum := 0
    for i := 1; i < 3; i++ {
        sum += arr[i] - arr[i - 1]
    }

    Println(sum)
}


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


int main() {
  int n,k;
  
  string s;
  
  cin >> n >> k >> s;
  
  s.at(k-1) = s.at(k-1)+0x20;
  
  for(int i=0; i<s.size(); i++){
    cout << s.at(i);
  }
  
  
}

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

using i64 = long long;

struct Data{
  i64 a, b;
  bool operator<(const Data &obj)const{
    return a+b < obj.a+obj.b;
  }
};

int main(){
  i64 n;
  cin >> n;
  vector<Data> v;
  for(int i=0;i<n;++i){
    i64 a, b;
    cin >> a >> b;
    v.push_back((Data){a, b});
  }
  sort(v.rbegin(), v.rend());
  i64 ans = 0;
  for(int i=0;i<n;++i){
    if(i%2){
      ans -= v[i].b;
      //cout << ans << endl;
    }else{
      ans += v[i].a;
      //cout << ans << endl;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 2420
import java.util.*;
//import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
     
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		FastReader sc=new FastReader();
// 		constructST(a,n);RMQ(n, qs, qe)
        // sieveOfEratosthenes();
//		Stack<Character> st=new Stack <> ();
		int n=sc.nextInt(),K=sc.nextInt(),i,j;
		long a[]=new long[n],dp[]=new long[n];
		Arrays.fill(dp,Integer.MAX_VALUE);
		dp[0]=0;
		for(i=0;i<n;i++)
			a[i]=sc.nextLong();
		for(i=0;i<n;i++) {
			for(int k=1;k<=K && (i-k)>=0;k++)
				dp[i]=Math.min(dp[i],dp[i-k]+Math.abs(a[i]-a[i-k]));
		}
		System.out.println(dp[n-1]);
	}
	static int lower_bound(int a[],int x){
         int n=a.length,low=0,high=n-1,res=-1;
         while(low<=high){
             int mid=(low+high)>>1;
             if(a[mid]>=x){
                res=mid;high=mid-1;
             }
             else 
                low=mid+1;
         }
         return res;
     }
      static int upper_bound(int a[],int x){
          int n=a.length,low=0,high=n-1,res=-1;
          while(low<=high){
              int mid=(low+high)>>1;
              if(a[mid]<=x){
                  res=mid;low=mid+1;
              }
              else 
                  high=mid-1;
          }
          return res;
      }
      static long modexpo(long x,long n,long m){
        if(n==0)
            return 1;
        else if(n%2==0)
            return (modexpo(((x%m)*(x%m))%m,n/2,m))%m;
        else
            return ((x%m)*((modexpo(((x%m)*(x%m))%m,(n-1)/2,m))%m))%m;
      } 
       static int gcd(int a,int b){
           if(b==0)
              return a;
           else 
              return gcd(b,a%b);
       }
       static long gcd(long a,long b){
           if(b==0)
              return a;
           else 
              return gcd(b,a%b);
       }
	 static class FastReader{
          BufferedReader in;
          StringTokenizer st;
          public FastReader(){
              in=new BufferedReader(new InputStreamReader(System.in));
          }
          String next(){
              while(st==null || !st.hasMoreElements()){
                  try{
                      st=new StringTokenizer(in.readLine());
                  }
                  catch(IOException e){
                      e.printStackTrace();
                  }
               }
               return st.nextToken();
            }
            int nextInt(){
                return Integer.parseInt(next());
            }
            long nextLong(){
                return Long.parseLong(next());
            }
            double nextDouble(){
                return Double.parseDouble(next());
            }
            String nextLine(){
            String str19 = "";
            try{
                str19 = in.readLine();
            }
            catch (IOException e){
                e.printStackTrace();
             }
            return str19;
        }
      }    
}

Measured memory_bytes: 35848
// By Debajit Chakraborty
#include<bits/stdc++.h>
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MP make_pair
#define pb push_back
#define ff first
#define ss second
#define sz(x) x.size()
#define all(c) c.begin(),c.end()
#define int long long
#define fr(i,j,x) for(int i=j;i<x;i++)
#define rep(i,j,x) for(int i=j;i<=x;i++)
#define rev(i,j,x) for(int i=j;i>=x;i--)
#define mem(x,val) memset(x,val,sizeof(x))
#define endl '\n'
#define vi vector<int>
#define pii pair<int,int>
 
const int mod=1e9+7;
const int N=2e5+10;
const int INF=1e12;



void solve(){
    int n;
    cin>>n;
    int rem=7%n,cnt=0;
    unordered_map<int,int>mp;
    mp[7%n]=1;
    while(rem!=0){
        rem=rem*10+7;
        rem%=n;
        if(mp[rem]==1){
            cout<<-1<<endl;
            return;
        }
        mp[rem]=1;
        cnt++;
    }
    cout<<cnt+1<<endl;
}


int32_t main()
{
    SPEED;
    int T=1;
    //cin>>T;
    int t1=1;
    while(true)
    {  
        //cout<<"Case #"<<t1<<": ";
        //cout<<endl;
        solve();
        t1++;
        if(t1>T)
            break;
    }
}   


Measured memory_bytes: 42620