akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i) = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  int n;cin>>n;
  ll ans = 0;
  rep(i,n+1){
    if(i%3 != 0 && i%5 != 0)ans+=i;
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 3568
#include<cstdio>
#include<vector>
#include<algorithm>
#include<list>
#include<iostream>
#include<map>
#include<queue>
#include<set>
using namespace std;
typedef pair<int,int>pii;
#define F first
#define S second
int main(){
    map<char,int>c;c['o']=0,c['x']=1;
    string str;
    cin>>str;
    int cnt=1;
    list<pii>L;
    int sum[2]={0};
    for(int i=1;i<str.length();i++){
        if(str[i]==str[i-1])cnt++;
        else{
            sum[c[str[i-1]]]+=cnt;
            L.push_back(pii(c[str[i-1]],cnt));
            cnt=1;
        }
    }
    L.push_back(pii(c[str[str.length()-1]],cnt));
    sum[c[str[str.length()-1]]]+=cnt;

    for(int i=0;sum[0]&&sum[1];i++){
        int p=i&1;
        if(L.front().F!=p){
            int val=L.front().S+1;
            sum[p]+=val;
            sum[1-p]-=val-1;
            L.pop_front();
            val+=L.front().S;
            L.pop_front();
            L.push_front(pii(p,val));

        }
        else if(L.back().F!=p){
            int val=L.back().S+1;
            sum[p]+=val;
            sum[1-p]-=val-1;
            L.pop_back();
            val+=L.back().S;
            L.pop_back();
            L.push_back(pii(p,val));
        }
    }
    cout<<(L.front().F==0?'o':'x')<<endl;
    return 0;
}

Measured memory_bytes: 1180
from collections import deque, defaultdict
import sys
input=sys.stdin.readline


def solve():
    H, W, K = map(int, input().split())
    y1, x1, y2, x2 = map(int, input().split())
    l = [input() for _ in range(H)]
    INF = 10**12

    x1 -= 1
    y1 -= 1
    x2 -= 1
    y2 -= 1

    ddy = [0, 0, -1, 1]
    ddx = [-1, 1, 0, 0]

    dist = defaultdict(lambda :INF)
    dist[(y1, x1)] = 0
    q = deque([(y1, x1)])

    while q:
        y, x = q.popleft()
        for dy, dx in zip(ddy, ddx):
            for j in range(1, K+1):
                ny, nx = y+dy*j, x+dx*j
                if (not (0<=ny<H and 0<=nx<W)) or l[ny][nx]=="@" or dist[(ny, nx)] < dist[(y, x)] + 1:
                    break
                if dist[(ny, nx)] > dist[(y, x)] + 1:
                    dist[(ny, nx)] = dist[(y, x)] + 1
                    q.append((ny, nx))
                else:
                    continue

    ans = dist[(y2, x2)]
    print(ans if ans!=INF else -1)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 188384
S = input()[::-1]
P = 13
qs = [0]*13
tmp = 1
rest = 0
for i, s in enumerate(S):
    if s == '?':
        qs[tmp] += 1
    else:
        rest = (rest + int(s) * tmp) % P
    tmp = (tmp * 10) % P

dp = [0] * 13
dp[rest] = 1
for i, cnt in enumerate(qs):
    for _ in range(cnt):
        dp_new = [0]*13
        for j in range(10):
            tmp = (i * j) % P
            for k in range(P):
                dp_new[(k + tmp) % P] = (dp_new[(k + tmp) % P] + dp[k])%int(1e9+7)
        dp = dp_new
print(dp[5]%int(1e9+7))


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

int main() {
  int n,ac,wa,tle,re;
  cin >> n;
  ac=0;
  wa=0;
  tle=0;
  re=0;
  for(int i=0;i<n;i++){
    string s;
    cin >> s;
    if(s == "AC")
      ac++;
    else if(s == "WA")
      wa++;
    else if(s == "TLE")
      tle++;
    else
      re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

Measured memory_bytes: 3592
def f(S):
    sets = {}
    for s in S:
        sets[s] = sets.setdefault(s, 0) + 1
    return sets
S = input()
T = input()
setS = f(S)
setT = f(T)

for k, v in setS.items():
    if setT.setdefault(k, 0) != v:
        print("No")
        break
else:
    N = len(S)
    for n in range(N):
        if S == T:
            print("Yes")
            break
        S = S[N-1] + S[0:N-1]
    else:
        print("No")

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

int main() {
    int N, M, C;
    cin >> N >> M >> C;
    vector<int> B;
    for(int i=0;i<M;i++) {
        int b;
        cin >> b;
        B.push_back(b);
    }
    int c=0;
    for(int i=0; i<N;i++) {
        int ans =0;
        for(int j=0; j<M;j++) {
            int tt;
            cin >>tt;
            ans+=B[j]*tt;
        }
        ans+=C;
        if(ans>0)
            c++;
    }
    cout << c;
}


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

#define debug(n) cerr << #n << ':' << n << endl;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;

int main(){
  int n, k; cin >> n >> k;
  vector<int> a(n);
  for(int&e:a)cin >> e;
  int sum = 0;
  for(int e:a)sum += e;
  vector<int> dlist;
  for(int i = 1; i * i <= sum; ++i){    
    if(sum % i == 0){
      dlist.push_back(i);
      dlist.push_back(sum / i);
    }
  }

  int ans = 0;
  for(int d:dlist){
    vector<int> v = a;
    for(int&e:v)e %= d;
    sort(v.begin(), v.end());
    int vsum = 0;
    for(int&e:v)vsum += e;
    int cnt = 0;
    int mid = vsum / d;
    for(int i = v.size()-mid; i < v.size(); ++i)cnt+=d-v[i];
    if(cnt <= k)ans = max(ans, d);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define hello777 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#include <string>
#define pie 3.14159265358979323846
constexpr int MOD = 1e9+7;
const int N= 50000;
using namespace std;


//ll gcd(int a, int b)
//{ 
//    if (a == 0) 
//        return b;  
//    return gcd(b % a, a);  
// } 
// 
//ll lcm(int a, int b)  
// {  
//    return a/gcd(a, b) *b;  
// }
//  
//int prime(int n)
//{
//	rep(i,2,n+1)
//	{
//		if(n%i==0)return i;
//	}
//	
//}


void solve() 
{
  ll x,k,d,n,m,ans;
    cin>>x>>k>>d;
    x=abs(x);
    n=(x/d);
    if(n>=k)
        cout<<x-k*d<<endl;
    else
    {
        m=k-n;
        if(m%2)
        {
            ans=(x%d);
            abs(ans-d)<=ans+d?ans=abs(ans-d):ans=ans+d;
            cout<<ans<<endl;
        }
        else
            cout<<x%d<<endl;
    }
}

int main()
{
	hello777;
	int q=1;
//    cin>>q;
    while(q--)
    {   
      solve();
    }
}

Measured memory_bytes: 3620
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define REP_AB(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll K, X;
    in >> K >> X;
    //vector<ll> X(N)

    REP_AB(i, X-K+1, X+K){
        /*
        if(i==1000001){
            break;
        }else if(i<-1000001){
            i=-1000000;
        }
        */
        out << i << " ";
    }

}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
using namespace std;
int main(){
 int x,n;
 scanf("%d%d",&x,&n);
 int a,min=0,i;
 bool flag[1000]={0}; 
 
 for(i=0;i<n;i++){
  scanf(" %d",&a);
  flag[a]=1;
 }
 
 int compare,tmp=1000;
 for(i=0;i<=200;i++){
  compare=abs(x-i);
  if(tmp>compare&&!flag[i]){
   min=i;
   tmp=compare;
  }
 }
 printf("%d\n",min);
return 0;}

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

using namespace std;

main(){
  int n;
  while(cin >> n){
    for(int i=0;i<n;i++){
      string hito;
      string data;
      cin >> hito;
      cin >> data;
      for(int j=hito.size()-1;j>=0;j--){
	//cout << data << endl;
	if(hito[j]=='J'){
	  string tmp=data;
	  data="";
	  data+=tmp[tmp.size()-1];
	  for(int k=0;k<tmp.size()-1;k++){
	    data+=tmp[k];
	  }
	}else if(hito[j]=='C'){
	  string tmp=data;
	  data="";
	  for(int k=1;k<tmp.size();k++){
	    data+=tmp[k];
	  }
	  data+=tmp[0];
	}else if(hito[j]=='E'){
	  string left="", right="";
	  if(data.size()%2==0){
	    for(int k=0;k<data.size()/2;k++){
	      left+=data[k];
	      right+=data[k+data.size()/2];
	    }
	  }else{
	    for(int k=0;k<data.size()/2;k++){
	      left+=data[k];
	      right+=data[k+data.size()/2+1];
	    }
	    right+=data[data.size()/2];
	  }
	  data="";
	  data+=right;
	  data+=left;
	}else if(hito[j]=='A'){
	   string tmp=data;
	  for(int k=0;k<tmp.size();k++){
	    data[k]=tmp[tmp.size()-1-k];
	  }
	}else if(hito[j]=='P'){
	  for(int k=0;k<data.size();k++){
	    if(data[k]>='0' && data[k]<='9'){
	      if(data[k]=='0') data[k]='9';
	      else data[k]=data[k]-1;
	    }
	  }
	}else if(hito[j]=='M'){
	  for(int k=0;k<data.size();k++){
	    if(data[k]>='0' && data[k]<='9'){
	      if(data[k]=='9') data[k]='0';
	      else data[k]=data[k]+1;
	    }
	  }
	}
      }
      cout << data << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<math.h>
#include<string.h>

int main()
{
	int S;
	scanf("%d", &S);
	
	char A[S];
	scanf("%s", A);
	
	int r;
	int c=1;
	for(r=0; r<S-1; r++){
		if(A[r]!=A[r+1]) c++;
	}		
	
	printf("%d", c);


	return 0;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<x<<endl
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
typedef vector<int> vi;

string a;

int main(void){
    cin>>a;
    if(a=="A")p('T');
    else if(a=="G")p('C');
    else if(a=="C")p('G');
    else if(a=="T")p('A');
    return 0;
}



Measured memory_bytes: 256
def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))
MOD = 10 ** 9 + 7


H, W = MI()
C = [input() for _ in range(H)]
for i in range(H):
    print(C[i])
    print(C[i])


Measured memory_bytes: 38288
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  vector<int> cnt(n, 1);
  vector<bool> in(n); in[0] = true;
  rep(i, m) {
    int x, y; cin >> x >> y;
    x--; y--;
    if(in[x]) {
      if(cnt[x] == 1) {
        in[x] = false;
        in[y] = true;
      } else {
        in[y] = true;
      }
    }
    cnt[x]--;
    cnt[y]++;
  }
  cout << accumulate(all(in), 0) << "\n";
  return 0;
}


Measured memory_bytes: 3680
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
	
#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int n, r;
	while (~scanf("%d%d", &n, &r))
	{
		deque<int> C;
		rep (i, n)
			C.push_back(i);
		while (r--)
		{
			int c;
			scanf("%d", &c);
			deque<int> A, B;
			rep (i, n / 2)
			{
				B.push_back(C.front());
				C.pop_front();
			}
			while (!C.empty())
			{
				A.push_back(C.front());
				C.pop_front();
			}

			while (!A.empty())
			{
				for (int i = 0; i < c && !A.empty(); ++i)
				{
					C.push_back(A.front());
					A.pop_front();
				}
				for (int i = 0; i < c && !B.empty(); ++i)
				{
					C.push_back(B.front());
					B.pop_front();
				}
			}
		}
		printf("%d\n", C.back());
	}
}

Measured memory_bytes: 0
import heapq

N,M=map(int,input().split())
A=list(map(int,input().split()))
A=list(map(lambda x: x*(-1),A))

heapq.heapify(A)
for i in range(M):
    temp=heapq.heappop(A)
    heapq.heappush(A,temp//2+temp%2)
    
print(-sum(A))

Measured memory_bytes: 14180
package main

import (
	"fmt"
)

func main() {
	var n, x, m int
	fmt.Scan(&n, &x, &m)
	mp := make(map[int]int)
	var sum, cnt int
	ns := make([]int, 0)
	for {
		if idx, ok := mp[x]; ok {
			loop := len(ns) - idx
			ln := (n - idx) / loop

			var lsum int
			for i := idx; i < len(ns); i++ {
				lsum += ns[i]
			}
			ans := ln * lsum
			for i := 0; i < idx; i++ {
				ans += ns[i]
			}
			for i := idx; i < ((n-idx)%loop)+idx; i++ {
				ans += ns[i]
			}
			fmt.Println(ans)
			return
		}
		sum += x
		mp[x] = cnt
		ns = append(ns, x)
		x = (x * x) % m
		if x == 0 {
			fmt.Println(sum)
			return
		}
		cnt++
	}

	fmt.Println(n)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 6696
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vll vector<ll>
#define pb push_back
#define x first
#define y second

struct data
{
	int len,i_,j_;
	char c;
};

data max_of(data a, data b)
{
	return a.len>b.len ? a : b;
}

int main()
{
	string s,t;
	cin>>s;
	cin>>t;
	vector<vector<data> > dp(s.length()+1,vector<data> (t.length()+1,{0,-1,-1,'\0'}));int i,j;
	for(i=1;i<=s.length();i++)
	{
		for(j=1;j<=t.length();j++)
		{
			if(s[i-1] == t[j-1])
				{
					dp[i][j].len=dp[i-1][j-1].len+1;
					dp[i][j].i_ = i-1;
					dp[i][j].j_ = j-1;
					dp[i][j].c = s[i-1];
				}
			else
				dp[i][j]=max_of(dp[i-1][j],dp[i][j-1]);

			//cout<<i<<' '<<j<<' '<<dp[i][j].c<<' '<<dp[i][j].i_<<' '<<dp[i][j].j_<<'\n';
		}
	}
	data ans =dp[s.length()][t.length()];
	string r;
	while(ans.i_>=0 && ans.j_>=0)
	{
		r += ans.c;
		ans=dp[ans.i_][ans.j_];
	}
	reverse(r.begin(),r.end());
	cout<<r;
}

Measured memory_bytes: 141184
import sys

def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())

    num = (N-1) * (N-2) // 2
    if K > num:
        print(-1)
        exit()

    edges = [(1, i) for i in range(2, N+1)]
    for j in range(2, N):
        for k in range(j+1, N+1):
            if num == K:
                break
            edges.append((j, k))
            num -= 1

    print(len(edges))
    for a, b in edges:
        print(a, b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3992
n = int(input());

a = [int(i) for i in input().split()];
b = [int(0) for i in range(n)];

for i in a:
  b[i - 1] += 1;

#print(a);
#print(b);

sum = 0;
for i in b:
  sum += i * (i - 1) // 2;
#print(sum);
for i in a:
  print(sum - b[i - 1] + 1);


Measured memory_bytes: 26268
N, W = list(map(int, input().split()))
WE = []
V = []
INF = float('inf')
for i in range(N):
    w, v = list(map(int, input().split()))
    WE.append(w)
    V.append(v)

MAX_V = (10 ** 3) * 100 + 1

# DP[i+1][j]: i番目までの品物から価値の総和がjとなるように選んだときの、重さの総和の最小値
DP = []
for i in range(N+1):
    a = [INF] * (MAX_V + 1)
    DP.append(a)

DP[0][0] = 0

for i in range(N):
    for j in range(MAX_V):
        if j < V[i]:  # 作りたい価値の総和よりも、価値が大きい
            DP[i+1][j] = DP[i][j]
        else:
            DP[i+1][j] = min(DP[i][j], DP[i][j-V[i]] + WE[i])

r = 0
for i in range(MAX_V+1):
    if DP[N][i] <= W:
        r = i

print(r)

# for i in range(N+1):
    # print(DP[i][:20])

Measured memory_bytes: 311448
/*
  AOJ 1241
  Title:Lagrange's Four-Square Theorem
  @kankichi573
*/
#include <stdio.h>


int solve(int n,int c,int low)
{
  int i,ret;
  ret=0;
  for(i=low;i*i<=n;i++)
    {
      if(n==i*i)
	ret++;
      else if(c<4)
	ret+=solve(n-i*i,c+1,i);
    }
  return(ret);
}
main()
{
  int n,ret;
  while(scanf("%d",&n) && n)
    {
      ret=solve(n,1,1);
      printf("%d\n",ret);
    }
  return(0);
}

Measured memory_bytes: 600
import bisect
n= int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for i in range(n):
    x = bisect.bisect_left(a,b[i])
    y = bisect.bisect_right(c,b[i])
    ans += x*(n-y)
print(ans)

Measured memory_bytes: 23360
// C - Low Elements
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
template<class T> T in(){T x;cin>>x;return x;}

int main(){
	int N = in<int>();
	int ans=0, minP = INT_MAX;
	rp(i,0,N){
		int p = in<int>();
		if(minP >= p){ minP = p; ans++; }
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
N = int(input())
num = [int(i) for i in input().split()]
count = 0
for i in range(N):
    if i == 0:
        continue
    else:
        if num[i] < num[i-1]:
            count += num[i-1] - num[i]
            num[i] = num[i-1]
print(int(count))

Measured memory_bytes: 32320
#include <cstdio>
#include <algorithm>

typedef long long lli;

lli df(lli x, lli y) {
  if (x % y == 0) return -1;
  return x;
}

int main() {
  long long X, Y;
  scanf("%lld%lld", &X, &Y);
  printf("%lld\n", df(X, Y));
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
   long long n,a,x,ans=0;
   cin>>n>>a;
   while(--n)
   {
       cin>>x;
       if(x<a)ans+=a-x;
       else a=x;
   }
   cout<<ans<<endl;
   return 0;
}


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const int INF = 1000000000;

ll V[500][500];
vector<Pii> E[500][500];

struct State{
    int y,x,length;
    State(int y, int x, int length): y(y), x(x), length(length){};

    bool operator>(const State& s) const{
        return length > s.length;
    }
};

int main(){
    int R,C,ax,ay,bx,by;
    cin >> R >> C >> ay >> ax >> by >> bx;

    queue<State> que;
    que.push(State(ay, ax, 0));
    int dist[500][500];
	ll count[500][500];
    fill_n(dist[0], 500*500, INF);
	fill_n(count[0], 500*500, 0);
    dist[ay][ax] = 0;
	count[ay][ax] = 1;
	auto update = [&](int y, int x, int d, ll c){
		if(dist[y][x] < d){ return; }
		if(dist[y][x] > d){
			que.push(State(y, x, d));
			count[y][x] = 0;
		}
		dist[y][x] = d;
		count[y][x] = (count[y][x] + c) % MOD;
	};
    while(!que.empty()){
        State now = que.front(); que.pop();
        //printf("(%d, %d) length:%d, count:%lld\n", now.y, now.x, now.length, count[now.y][now.x]);

        if(now.y != 0){
			update(now.y-1, now.x, now.length + 1, count[now.y][now.x]);
			update(0, now.x, now.length + 1, count[now.y][now.x]);
        }
        if(now.y != R-1){
			update(now.y+1, now.x, now.length + 1, count[now.y][now.x]);
			update(R-1, now.x, now.length + 1, count[now.y][now.x]);
        }

        if(now.x != 0){
			update(now.y, now.x-1, now.length + 1, count[now.y][now.x]);
			update(now.y, 0, now.length + 1, count[now.y][now.x]);
        }
        if(now.x != C-1){
			update(now.y, now.x+1, now.length + 1, count[now.y][now.x]);
			update(now.y, C-1, now.length + 1, count[now.y][now.x]);
        }
    }

    cout << dist[by][bx] << " " << count[by][bx] << endl;
    return 0;
}



Measured memory_bytes: 11952
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

const int NIL=-1;

struct Node{int parent,left,right;};
Node T[10004];
int n,D[10004],H[10004];

void setDepth(int u,int d) {
    if(u==NIL) return;
    D[u]=d;
    setDepth(T[u].left,d+1);
    setDepth(T[u].right,d+1);
}

int setHeight(int u) {
    int h1=0,h2=0;
    if(T[u].left!=NIL) h1=setHeight(T[u].left)+1;
    if(T[u].right!=NIL) h2=setHeight(T[u].right)+1;

    return H[u]=max(h1,h2);
}

int getSibling(int u) {
    if(T[u].parent==NIL) return NIL;
    if(T[T[u].parent].left!=u && T[T[u].parent].left!=NIL) return T[T[u].parent].left;
    if(T[T[u].parent].right!=u && T[T[u].parent].right!=NIL) return T[T[u].parent].right;
    return NIL;
}

void print(int u) {
    printf("node %d: ",u);
    printf("parent = %d, ",T[u].parent);
    printf("sibling = %d, ",getSibling(u));
    int deg=0;
    if(T[u].left!=NIL) deg++;
    if(T[u].right!=NIL) deg++;
    printf("degree = %d, ",deg);
    printf("depth = %d, ",D[u]);
    printf("height = %d, ",H[u]);

    if(T[u].parent == NIL) {
        printf("root\n");
    }
    else if(T[u].left==NIL&&T[u].right==NIL) {
        printf("leaf\n");
    }
    else {
        printf("internal node\n");
    }

}

int main() {
    int v,l,r;
    int root=0;
    cin>>n;
    rep(i,n) T[i].parent=NIL;
    rep(i,n) {
        cin>>v>>l>>r;
        T[v].left=l;
        T[v].right=r;
        if(l!=NIL) T[l].parent=v;
        if(r!=NIL) T[r].parent=v;
    }
    rep(i,n) if(T[i].parent==NIL) root=i;
    setDepth(root,0);
    setHeight(root);
    rep(i,n) print(i);
    return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

set<int> s;

int main(){
    int N;
    cin >> N;
    REP(i, N){
        int tmp;
        cin >> tmp;
        if(s.count(tmp)){
            s.erase(tmp);
        }else{
            s.insert(tmp);
        }       
    }

    cout << s.size() << endl;
}


Measured memory_bytes: 4864
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Main {
  public static void main(String[] args) {
    Main m = new Main();
    m.run();
  }
  private void run() {
    int n = 0;
    long s = 0L;
    FordFulkerson ff = null;
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
      n = Integer.parseInt(br.readLine());
      long[] a = Arrays.stream(br.readLine().split("\\s+"))
        .mapToLong(Long::parseLong).toArray();
      ff = new FordFulkerson(n+2);
      for (int i=1;i<n+1;i++) {
        if (a[i-1] > 0) {
          s += a[i-1];
          ff.addEdge(i,n+1,a[i-1]);
        } else {
          ff.addEdge(0,i,-a[i-1]);
        }
        for (int j=2*i;j<n+1;j+=i) {
          ff.addEdge(i,j,1000000000000000L);
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    System.out.println(s-ff.execute(0,n+1));
  }
  private class FordFulkerson {
    private List<Edge>[] graph;
    private boolean[] used;
    FordFulkerson(int n) {
      graph = new List[n];
      for (int i=0;i<n;i++) graph[i] = new ArrayList<>();
      used = new boolean[n];
    }
    private void addEdge(int fm,int to,long cp) {
      graph[fm].add(new Edge(to,cp,graph[to].size()));
      graph[to].add(new Edge(fm,0,graph[fm].size()-1));
    }
    private long execute(int s,int t) {
      for (long flow=0;;) {
        Arrays.fill(used,false);
        long f = dfs(s,t,100000000000000L);
        if (f == 0) return flow;
        flow += f;
      }
    }
    private long dfs(int v,int t,long f) {
      if (v == t) return f;
      used[v] = true;
      for (int i=0;i<graph[v].size();i++) {
        Edge e = graph[v].get(i);
        if(used[e.to] || e.cp <= 0) continue;
        long d = dfs(e.to,t,Math.min(f,e.cp));
        if (d > 0) {
          e.cp -= d;
          graph[e.to].get(e.rv).cp += d;
          return d;
        }
      }
      return 0;
    }
  }
  private class Edge {
    private int to;
    private long cp;
    private int rv;
    Edge(int to,long cp,int rv) {
      this.to = to;
      this.cp = cp;
      this.rv = rv;
    }
  }
}

Measured memory_bytes: 26836
#include"bits/stdc++.h"
using namespace std;

void Main() {
  int n;
  cin >> n;
  unordered_map<string, long long> cnt;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    cnt[s]++;
  }

  long long ans = 0;
  for (auto it: cnt) {
    long long tmp = it.second;
    ans += tmp * (tmp - 1) / 2;
  }
  cout << ans << endl;
}

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

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

int main() {
  int N,L;
  cin>>N>>L;
  vector<string> v(N);
  for(int i=0;i<N;i++)cin>>v.at(i);
  sort(v.begin(),v.end());
  for(int i=0;i<N;i++)cout<<v.at(i);
  cout<<endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
const int haha=15000;
long long int n, W, best, w[10005], v[100005], dp[110][100005];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> W;
    for(long long int i=1;i<=n;i++){
        cin >> w[i] >> v[i];
    }
    for(long long int i=0;i<=n;i++){
        for(long long int j=0;j<=W;j++){
            if(i==0 or j==0){
                dp[i][j]=0;
            }
            else{
                best=dp[i-1][j];
                if(j>=w[i]){
                    best=max(best, dp[i-1][j-w[i]]+v[i]);
                }
                dp[i][j]=best;
            }
        }
    }
    cout << dp[n][W] << endl;
}

Measured memory_bytes: 82176
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func floatSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	h, w := iScan(), iScan()
	s := SScan(h)
	g := make([][]int, h*w)
	for i, _ := range g {
		g[i] = make([]int, h*w)
		for j, _ := range g[i] {
			if i != j {
				g[i][j] = mod
			}
		}
	}
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if string(s[i][j]) == "." {
				if i+1 < h {
					if string(s[i+1][j]) != "#" {
						g[i*w+j][(i+1)*w+j] = 1
					}
				}
				if i > 0 {
					if string(s[i-1][j]) != "#" {
						g[i*w+j][(i-1)*w+j] = 1
					}
				}
				if j+1 < w {
					if string(s[i][j+1]) != "#" {
						g[i*w+j][i*w+j+1] = 1
					}
				}
				if j > 0 {
					if string(s[i][j-1]) != "#" {
						g[i*w+j][i*w+j-1] = 1
					}
				}
			}
		}
	}
	for k := 0; k < h*w; k++ {
		for i := 0; i < h*w; i++ {
			for j := 0; j < h*w; j++ {
				g[i][j] = smaller(g[i][j], g[i][k]+g[j][k])
			}
		}
	}
	ans := 0
	for i, _ := range g {
		for j, _ := range g[i] {
			if g[i][j] < mod {
				ans = larger(ans, g[i][j])
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 3144
import java.util.*;
public class Main { 

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int cnt = 0;
        for(int i = 0; i < n; i++) {
            if(sc.nextInt() >= k)
                cnt++;
        }

        System.out.println(cnt);
    }

}

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

int main()
{
    set<string> dict;
    int n;
    
    cin>>n;
    for(int i = 0;i < n;i++)
    {
        string cmd, w;
        cin>>cmd>>w;
        if(!cmd.compare("insert"))
        {
            dict.insert(w);
        }
        else if(!cmd.compare("delete"))
        {
            set<string>::iterator iter = dict.find(w);
            if(iter != dict.end())
            {
                dict.erase(iter);
            }
        }
        else if(!cmd.compare("find"))
        {
            set<string>::iterator iter = dict.find(w);
            if(iter != dict.end())
            {
                cout<<"yes"<<endl;
            }
            else
                cout<<"no"<<endl;
        }
    }
}


Measured memory_bytes: 32136
#include <iostream>
#include <vector>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

bool is_prime(int n) {
	if (n < 2) {
			return false;
	}
	if (n==2||n==3) {
		return true;
	}
	for (int i = 3; i < n; i = i+2) {
		if (n%i==0) {
			return false;
		}
	}
	return true;
}

int main(void) {
	int N = 1300000;

	std::vector<bool> prime(N);
	for (int i = 0; i < N+2; i++) {
		prime[i] = true;
	}
	prime[0] = false;
	prime[1] = false;
	for (int i = 2; i <= sqrt(N); i++) {
		if (is_prime(i)) {
			for (int j = 2; i*j < N+2; j++) {
				prime[i*j] = false;
			}
		}
	}

	int n;
	cin >> n;

	while (n != 0) {
		int pa = 0;
		int pb = 0;
		bool afind = false;
		bool bfind = false;
		for (int i = n; !(afind) && i < N+2; i++) {
			if (prime[i]) {
				pa = i;
				afind = true;
			}
		}
		for (int i = n; !(bfind) && i > 0; i--) {
			if (prime[i]) {
				pb = i;
				bfind = true;
			}
		}
		cout << (pa - pb) << endl;
		cin >> n;
	}

	return 0;
}

Measured memory_bytes: 2996
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int dp[110][10010]={}; //[v][w]

int main() { 
  double n,k;
  cin>>n>>k;
  
  double init=1/n,sum=0;
  int j=0;
  for(int i=1;i<=n;i++){
      j=0;
      while(k>i*pow(2,j)){
          j++;
      }
      //cout<<j<<endl;
      //cout<<init<<endl;
      sum+=init*(1/(pow(2,j)));
  }

  cout<<fixed<<setprecision(20)<<sum<<endl;

}



Measured memory_bytes: 512
use proconio::input;

fn main() {
    input! {
        n: usize,
        mut a: [i64; n],
    }

    a.sort();
    a.reverse();
    let mut sum = a[0];
    let mut t = n - 2;
    for i in 1..n {
        let lim = 2;
        for _ in 0..lim {
            if t > 0 {
                sum += a[i];
                t -= 1;
            }
        }
    }
    println!("{}", sum);
}



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

int main(void) {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	
	string n ;
	cin>>n;
	bool ans = false;
	for (auto &ch: n) {
		if (ch == '7')
			ans = true;
	}

	cout<<(ans ? "Yes": "No")<<"\n";

	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
using namespace std;
const int maxn = 1e5+100;
const int MOD = 1e9+7;
const double Pi = 3.141592654;
typedef long long ll;
typedef unsigned long long ull;


int main()
{
    int n;
    cin >> n;
    int a[maxn];
    int vis[maxn];
    int st;
    ll ans = 1;
    memset(vis, 0, sizeof(vis));
    for(int i=1 ; i<=n ; ++i)
    {
        cin >> a[i];
        vis[a[i]] ++;
    }
    if(!(n%2))//even
    {
        if(vis[0])
        {
            cout << 0 << endl;
            return 0;
        }
        for(int i=1 ; i<=n ; i+=2)
        {
            ans = (ans%MOD)*2%MOD;
            if(vis[i] != 2)
        {
            cout << 0 << endl;
            return 0;
        }
        }
    }
    else
    {
        if(vis[0] != 1)
        {
            cout << 0 << endl;
            return 0;
        }
        for(int i=2 ; i<=n ; i+=2)
        {
            ans = (ans%MOD)*2%MOD;
            if(vis[i] != 2)
        {
            cout << 0 << endl;
            return 0;
        }
        }
    }
    cout << ans << endl;

}

//9(4(7(1)(2))(3(6)(8)))(5(10)(11(12)))


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

using namespace std;

void solve() {
    string s;
    cin >> s;
    int i = s.size() - 1;
    string t;
    while(i >= 0) {
        t.push_back(s[i]);
        if (t == "maerd" || t == "remaerd" || t == "esare" || t ==  "resare")
            t.clear();
        --i;
    }
    if (t.empty())
        cout << "YES";
    else
        cout << "NO";

}

int main() {

    solve();
    return 0;
}


Measured memory_bytes: 3192
n,m = gets.chomp.split(" ").map{|e|e.to_i}
a = gets.chomp.split(" ").map{|e|e.to_i}
sum = 0

for i in a do
	sum += i
end

b = a.sort!.reverse![m-1]

if b < sum/4.0/m then
	print("No")
else
	print("Yes")
end

Measured memory_bytes: 3836
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define MOD 998244353 

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

ll power(ll a, ll n, ll m)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=(ans*a)%m;
        n>>=1;
        a=(a*a)%m;
    }
    return ans;
}

int main()
{
    IOS;
    int n;
    cin>>n;
    int a[n];
    repf(i,0,n) cin>>a[i];
    int c=0;
    repf(i,0,n)
    {
        if(a[i]==c+1)
        {
            c++;
        }
    }
    int rem=n-c;
    if(rem>n-1) cout<<-1<<endl;
    else cout<<rem<<endl;
}  

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    string s;
    cin >> n >> s;

    for (int i=0; i<(int)s.length(); i++)
        cout << (char) (((int) (s[i] - 'A') + n) % 26 + 'A');
    cout << "\n";

    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
using namespace std;

int main() {
	string s;
	cin >> s;
	int q;
	cin >> q;
	/*
	bool ans = true;
	
	for (int i = 0; i < q; i++) {
		int t;
		cin >> t;
		if (ans) {
			if (t == 1) ans = false;
			else if (t == 2) {
				int f;
				string c;
				cin >> f;
				cin >> c;
				add(s, f, c);
			}
		}
		else if (!ans) {
			if (t == 1) ans = true;
			else if (t == 2) {
				int f;
				string c;
				cin >> f;
				cin >> c;
				add(s, f, c);
			}
		}
		// cout << s <<ans<< endl;
	}

	if (ans) cout << s << endl;
	else if (!ans) {
		int num = s.size();
		vector<char> str(num);
		for (int i = 0; i < num; i++) {
			str.at(i) = s.at(i);
		}
		reverse(str.begin(), str.end());
		for (int i = 0; i < num; i++) {
			cout << str.at(i);
		}
		cout << endl;
	}
	*/
	int num = s.size();
	deque<char> str;
	for (int i = 0; i < num; i++) {
		str.push_back(s.at(i));
	}
	bool ans = true;

	for (int i = 0; i < q; i++) {
		int t;
		cin >> t;
		if (ans) {
			if (t == 1) ans = false;
			else if (t == 2) {
				int f;
				char c;
				cin >> f;
				cin >> c;
				if (f == 1) str.push_front(c);
				else if (f == 2) str.push_back(c);
			}
		}
		else if (!ans) {
			if (t == 1) ans = true;
			else if (t == 2) {
				int f;
				char c;
				cin >> f;
				cin >> c;
				if (f == 2) str.push_front(c);
				else if (f == 1) str.push_back(c);
			}
		}
	}

	if (!ans) reverse(str.begin(), str.end());
	int num_str = str.size();
	for (int i = 0; i < num_str; i++) {
		cout << str.at(i);
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 960
#include<bits/stdc++.h>
#define len (2*L)
#define rep(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long ll;
const int sz=3e5+7;
int n;
ll x[sz];
bool del[sz];
ll ans;
ll L,t[sz];
stack<int>q[2];
struct node{
	int left,right;
}c[sz];
int main(){
	scanf("%d%lld",&n,&L);
	rep(i,1,n) scanf("%lld",&x[i]);
	rep(i,1,n){
		scanf("%lld",&t[i]);
		ans+=(t[i]-1)/len;
		t[i]=(t[i]-1)%len+1;
	}
	rep(i,1,n){
		c[i].left=t[i]>2*(L-x[i]);
		c[i].right=t[i]>2*x[i];
		if(c[i].left==1&&c[i].right==1){
			del[i]=1;
			ans++;
		}
	}
	rep(i,1,n-1){
		if(del[i]) continue;
		if(c[i].left==0&&c[i].right==1){
			if(!q[1].empty()){
				del[q[1].top()]=1;
				del[i]=1;
				q[1].pop();
				ans++;
			}
			else if(!q[0].empty()){
				del[q[0].top()]=1;
				del[i]=1;
				q[0].pop();
				ans++;
			}
		}
		else if(c[i].right==0) q[c[i].left].push(i);
	}
	while(!q[0].empty()) q[0].pop();
	while(!q[1].empty()) q[1].pop();
	rep(i,1,n-1){
        if(del[i]==1||(c[i].left==0&&c[i].right==1)) continue;
        if(c[i].left==0){
            if(!q[1].empty()){
                del[i]=1;
                del[q[1].top()]=1;
                q[1].pop();
                ans++;
            }
            else if(!q[0].empty()){
                del[i]=1;
                del[q[0].top()]=1;
                q[0].pop();
                ans++;
            }
            else q[0].push(i);
        }
        else q[1].push(i);
	}
	if(c[n].left==0&&del[n]==0){
        rep(i,1,n-1)
        if(del[i]==0&&c[i].right==0){
            del[i]=1;
            del[n-1]=1;
            ans++;
            break;
        }
    }
	rep(i,1,n) if(!del[i]) ans++;
	ans++;
	if(!del[n]&&((c[n].left!=1)||(c[n].right!=0))) ans--;
	printf("%lld",len*ans);
}

Measured memory_bytes: 8832
#include<stdio.h>

int selectionsort(int A[], int N){
    int i, j, t, sw=0, minj;
    
    for(i=0; i<N-1; i++){
        minj = i;
        for(j=i;j<N;j++){
            if(A[j]<A[minj]) minj=j;
        }
        t=A[i];
        A[i] = A[minj];
        A[minj]=t;
        if(i!=minj) sw++;
    }
    return sw;
}

int main(){
    int A[100], N, i, sw;
    
    scanf("%d", &N);
    for(i=0; i<N; i++) scanf("%d", &A[i]);
    
    sw=selectionsort(A,N);
    
    for(i=0; i<N; i++){
        if(i>0) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
    printf("%d\n", sw);
    
    return 0;
}


Measured memory_bytes: 2148
#include<stdio.h>

int main(void){
    int n;
    scanf("%d",&n);
    int i, j;
    int ans;
    int w[n], t=1;
    int s1, s2, b=100, a;
    for(i=0;i<n;i++){
        scanf("%d",&w[i]);
    }
    for(j=0;j<n;j++){
        s1 = 0;
        s2 = 0;
        for(i=0;i<=t;i++){
            s1 = s1 + w[i];
        }
        for(i=t+1;i<n;i++){
            s2 = s2 + w[i];
        }
        if(s1-s2 >= 0){
            a = s1 - s2;
        }
        else{
            a = s2 -s1;
        }
        if(a < b){
            ans = a;
            b = a;
        }
        t++;
    }
    printf("%d\n",ans);
    return 0;
    
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
    ll a,b;cin >> a >> b;
    ll count = 0;
    ll ans = b;
    if(a==b){
        cout << b << endl;
        return 0;
    }
    if(b-a == 1){
        cout << (a^b) << endl;
        return 0;
    }
    if(a%2 == 0){
        if((b-a+1) %2 == 0){
            count = (b-a+1)/2;
            if(count%2 == 0){
                ans = 0;
            }
            else{
                ans = 1;
            }
        }
        else{
            count = (b-a)/2;
            if(count %2 == 0){
                ans = 0^ans;
            }
            else{
                ans = 1^ans;
            }
        }
    }
    else{
        if((b-a+1)%2 == 0){
            count = (b-a-1)/2;
            if(count%2 == 0){
                ans = a^0^b;
            }
            else{
                ans = a^1^b;
            }
        }
        else{
            count = (b-a)/2;
            if(count %2 == 0){
                
                ans = a^0;
            }
            else{
                ans = a^1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

	int a, b, c;
	int price;
	int x;
	int count = 0;
	int i, j, k;

	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);

	scanf("%d", &x);

	for ( i = 0; i <= a; i++)
	{
		for ( j = 0; j <= b ; j++)
		{
			for ( k = 0; k <= c; k++)
			{
				price = 500 * i + 100 * j + 50 * k;
				if (price == x) count++;
			}
		}
	}

	printf("%d", count);

	return 0;
}

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

public class Main{

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

    void run(){
      Scanner sc=new Scanner(System.in);
      int N=sc.nextInt();
      int[][] A=new int[N][3];
      long[][] dp=new long[N][3];
      for(int i=0;i<N;++i){
          for(int j=0;j<3;++j){
	          A[i][j]=sc.nextInt();
          }
      }
      for(int i=0;i<N;++i){
          for(int pre=0;pre<3;++pre){
    	      for(int ne=0;ne<3;++ne){
              	if(pre==ne)continue;
            	  dp[i][ne]=Math.max(dp[i][ne],(i>0?dp[i-1][pre]:0)+A[i][ne]);
        	  }
          }
      }
      long ans=0;
      for(int i=0;i<3;++i){
          ans=Math.max(ans,dp[N-1][i]);
      }
      System.out.println(ans);
    }
}


Measured memory_bytes: 102584
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

ll n, h, max_a = 0;
vector<ll> a, b;

void solve() {
    sort(b.begin(), b.end(), greater<>());
    ll ans = 0;
    each(i, b) {
        if (i >= max_a) {
            h -= i;
            ans++;
            if (h <= 0) break;
        }
    }
   
    if (h > 0) ans += (h % max_a == 0 ? h / max_a : (h / max_a + 1));
    cout << ans << endl;
}

int main() {
    cin >> n >> h;
    a.resize(n);
    b.resize(n);
    rep(i, n) {
        cin >> a[i] >> b[i];
        max_a = max(a[i], max_a);
    }
    solve();
    return 0;
}

Measured memory_bytes: 1792