akhauriyash/Code-Regression huggingface dataset:
//by szh
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define fi first
#define SZ(x) (int((x).size()))
#define se second
#define ll long long
#define pq priority_queue
#define MP make_pair
#define pii pair<int,int>
#define mod 998244353
#define debug(x) cerr<<#x<<"="<<x<<'\n'

const int maxn=2e5+10;

int n,q;
int a[maxn];
int tmp[maxn];
ll ans=0ll;

int p0w(int base,int p) {
	int res=1;
	while (p) {
		if (p%2==1) res=res*base%q;
		base=base*base%q;
		p/=2;
	}
	return res;
}

void solve() {
	ll ans=0;
	for (int i=1;i<=n;i++) {
		char c;
		scanf("%c",&c);
		if (q==2&&(c=='0'||c=='2'||c=='4'||c=='6'||c=='8')) ans+=(ll)i;
		if (q==5&&(c=='0'||c=='5')) ans+=(ll)i;
	}
	printf("%lld",ans);
	exit(0);
}

int main(){
	scanf("%d %d\n",&n,&q);
	if (q==2||q==5) solve();
	tmp[0]=1;
	for (int i=1;i<maxn;i++) tmp[i]=tmp[i-1]*10%q;
	a[0]++;
	int lst=0;
	for (int i=1;i<=n;i++) {
		char c;
		scanf("%c",&c);
		int cur=(lst*10+(int)(c-'0'))%q;
//		debug(cur);
		int x=(ll)cur*p0w(tmp[i],q-2)%q;
		ans+=(ll)a[x];
		a[x]++;
//		debug(ans);
		lst=cur;
	}
	printf("%lld",ans);
	return 0;
}

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

using namespace std;

#define INF 2e18


int main()
{
    //freopen("in.txt", "r", stdin);
    long double x;
    cin >> x;
    long double ans = 100;
    long double cur = 1.01;
    for(int n = 1; ;n++){
        ans = ans*cur;
        ans = (long long int) ans;
        if(ans >= x){
            cout << n << endl;
            return 0;
        }
    }
}



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

int main(){
    long long int H, W;
    cin >> H >> W;
    long long int count;
    if(H == 1 || W == 1) count = 1;
    else if(H*W %2 == 0 ) count = H*W/2;
    else count = H*W/2 +1;
    cout << count << endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

a,b = map(int,input().split())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
    
print(len(set(prime_factorize(a)) & set(prime_factorize(b))) +1)


Measured memory_bytes: 38384
import sys
from functools import lru_cache
from collections import defaultdict
from collections import deque
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
n,a,b,c=reads()
lsAB=deque()
lsBC=deque()
lsAC=deque()
dic=defaultdict(int)
k=-1
lsS=[]
for i in range(n):
  s=input()
  lsS.append(s)
  if "AB" in s:
    lsAB.append(i)
    a-=1
    b-=1
  if "BC" in s:
    lsBC.append(i)
    b-=1
    c-=1
  if "AC" in s:
    lsAC.append(i)
    c-=1
    a-=1
  if a<0:
    a+=2
    try:
      hoge=lsAB[0]
    except:hoge=inf
    try:
      hoge2=lsAC[0]
    except:hoge2=inf   
    #print(hoge,hoge2)
    if min(hoge,hoge2)>i:
      print("No")
      exit()
    if hoge<hoge2:
        dic[hoge]=0
        lsAB.popleft()
    else:
        dic[hoge2]=0
        lsAC.popleft()
  if b<0:
    b+=2
    try:
      hoge=lsAB[0]
    except:hoge=inf   
    try:
      hoge2=lsBC[0]
    except:hoge2=inf   
    if min(hoge,hoge2)>i:
      print("No")
      exit()
    if hoge<hoge2:
        dic[hoge]=1
        lsAB.popleft()
    else:
        dic[hoge2]=0
        lsBC.popleft()
  if c<0:
    c+=2
    try:
      hoge=lsBC[0]
    except:hoge=inf
    try:
      hoge2=lsAC[0]
    except:hoge2=inf   
    #print(hoge,hoge2)
    if min(hoge,hoge2)>i:
      print("No")
      exit()
    if hoge<hoge2:
        dic[hoge]=1
        lsBC.popleft()
    else:
        dic[hoge2]=1
        lsAC.popleft()
print("Yes")
for i in range(n):
  print(lsS[i][dic[i]])


Measured memory_bytes: 92024
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   string s, t;
   cin >> s >> t;
   sort(s.begin(), s.end());
   sort(t.begin(), t.end(), greater<char>());
   if (s < t)
      cout << "Yes" << endl;
   else
      cout << "No" << endl;
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    scanf("%d",&n);
    int s=0,m=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&k);
        s+=k;
        m=max(m,k);
    }
    s-=m;
    s+=m/2;
    printf("%d\n",s);
}


Measured memory_bytes: 256
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    class UnionFind(object):
        def __init__(self, n=1):
            # 木の親要素を管理するリストparをつくります。
            # par[x] == xの場合には、そのノードが根であることを示します。
            # 初期状態では一切グループ化されていないので、すべてのノードが根になりますね。
            self.par = [i for i in range(n)]
            # 木の高さを持っておき、あとで低い方を高い方につなげる。初期状態は0
            self.rank = [0 for _ in range(n)]
            self.size = [1 for _ in range(n)]

        def find(self, x):
            """
            x が属するグループを探索：
            ある２つの要素が属する木の根が同じかどうかをチェックすればよい。
            つまり、親の親の親の・・・と根にたどり着くまで走査すればよい。
            再帰。
            """
            # 根ならその番号を返す
            if self.par[x] == x:
                return x
            # 根でないなら、親の要素で再検索
            else:
                # 一度見た値については根に直接繋いで経路圧縮
                # 親を書き換えるということ
                self.par[x] = self.find(self.par[x])
                return self.par[x]

        def union(self, x, y):
            """
            x と y のグループを結合
            """
            # 根を探す
            x = self.find(x)
            y = self.find(y)
            # 小さい木に結合して経路圧縮
            if x != y:
                if self.rank[x] < self.rank[y]:
                    x, y = y, x
                # 同じ長さの場合rankが1増える
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1
                # 低い方の木の根を高い方の根とする
                self.par[y] = x
                self.size[x] += self.size[y]

        def is_same(self, x, y):
            """
            x と y が同じグループか否か
            """
            return self.find(x) == self.find(y)

        def get_size(self, x):
            """
            x が属するグループの要素数
            """
            x = self.find(x)
            return self.size[x]

    N, Q = map(int, input().split())
    uf = UnionFind(N)  # ノード数Nでクラス継承

    A, B = [0] * Q, [0] * Q
    for i in range(Q):
        A[i], B[i] = map(int, input().split())

    ans = [0]*Q
    cnt = Q*(Q-1)//2
    for i in reversed(range(Q)):
        sizea = uf.get_size(A[i]-1)
        sizeb = uf.get_size(B[i]-1)
        if uf.is_same(A[i]-1,B[i]-1):
            ans[i]=0
        else:

            ans[i] = sizea*sizeb
        uf.union(A[i]-1, B[i]-1)

    
    from itertools import accumulate
    
    
    ans = [0] + ans
    # 累積和を格納したリスト．A[l:r]の総和はB[r] - B[l]
    ans = list(accumulate(ans))
    for i in range(1,len(ans)):
        print(ans[i])
    
resolve()

Measured memory_bytes: 113452
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define numrep(i,n) for(int i=1;i<=n;i++)
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)
#define ll int64_t
#define all(v) v.begin(), v.end()

const int MOD = 1000000007;

int main() {

int N; cin >> N ;

vector<int> A(N); rep(i,N) cin >> A[i];

map<int,int> M;

rep(i,N) M[A[i]]++;

stack<int> S;

for(auto p : M){
  int key=p.first;
  int value=p.second;
  while(value>=2){
    S.push(key);
    value-=2;
  }
}

ll ans;

if(S.size()<=1) ans=0;

else{
int x=S.top();
S.pop();
int y=S.top();

ans=(ll)x*y;
}

cout << ans << endl;

return 0;
}

Measured memory_bytes: 5376
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int x = sc.nextInt();
    int[] c = new int[n];
    int[][] a = new int[n][m];
    for (int i = 0; i < n; i++) {
      c[i] = sc.nextInt();
      for (int j = 0; j < m; j++) {
        a[i][j] = sc.nextInt();
      }
    }
    boolean find = false;
    int min = Integer.MAX_VALUE;
    for (int i = 0; i < (1 << n); i++) {
      int[] sum = new int[m];
      int total = 0;
      for (int j = 0; j < n; j++) {
        if ((i & (1 << j)) == 0) continue;
        total += c[j];
        for (int k = 0; k < m; k++) {
          sum[k] += a[j][k];
        }
      }
      boolean ok = true;
      for (int s : sum) {
        if (s < x) {
          ok = false;
          break;
        }
      }
      if (ok && min > total) {
        min = total;
        find = true;
      }
    }
    System.out.println(find ? min : -1);
  }
}

Measured memory_bytes: 26824
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int inf = 1000000;
        int n = scanner.nextInt();
        int ma = scanner.nextInt();
        int mb = scanner.nextInt();

        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            b[i] = scanner.nextInt();
            c[i] = scanner.nextInt();
        }

        int[][][] dp = new int[41][401][401];
        Arrays.stream(dp).forEach(a1 -> Arrays.stream(a1).forEach(a2 -> Arrays.fill(a2, inf)));
        dp[0][0][0] = 0;

        for (int i = 0; i < n; i++) {
            for (int ca = 0; ca <= 400; ca++) {
                for (int cb = 0; cb <= 400; cb++) {
                    if (dp[i][ca][cb] != inf) {
                        dp[i + 1][ca][cb] = Math.min(dp[i + 1][ca][cb], dp[i][ca][cb]);
                        dp[i + 1][ca + a[i]][cb + b[i]] = Math.min(dp[i + 1][ca + a[i]][cb + b[i]], dp[i][ca][cb] + c[i]);
                    }
                }
            }
        }

        int ans = inf;
        for (int ca = 1; ca <= 400; ca++)
            for (int cb = 1; cb <= 400; cb++)
                if (ca * mb == cb * ma)
                    ans = Math.min(ans, dp[n][ca][cb]);

        System.out.println(ans == inf ? -1 : ans);
    }
}

Measured memory_bytes: 56140
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
struct process {
	char name[101];
	int time;
};
queue<process> qq;
int main() {
	int n,q;
	scanf("%d%d",&n,&q);
	process a;
	for (int i=0; i<n; i++) {
		cin >> a.name >> a.time;
		qq.push(a);
	}
	int cnt=0;
	while (!qq.empty()) {
		process t=qq.front();
		if (t.time<=q)  {
			cnt+=t.time;
			cout << t.name << " " << cnt << endl;
			qq.pop();
		}
		else {
			t.time-=q;
			qq.pop();
			qq.push(t); 
			cnt+=q;
		}
	}
	return 0;
}


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

int main(){
  int k;
  cin >> k;
  int a,b;
  a = k/2;
  b = k-a;
  cout << a*b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >>c;
  
  if(a == 5){
    if(b == 5){
    	if(c == 7){
          cout << "YES";
          return 0;
        }
  	}if(b == 7){
      if(c == 5){
        cout << "YES";
        return 0;
      }
  	}
  }if(a == 7){
      if(b == 5){
    	if(c == 5){
          cout << "YES";
          return 0;
        }
      }
    }
    cout << "NO";
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

ll dp[110][100005];

int main(){
    int N,K; cin>>N>>K;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) {
        cin>>a[i];
    }
    memset(dp,0, sizeof(dp));
    dp[0][0]=1;
    for (int i = 1; i <= N; ++i) {
        for(int j=0;j<=K;++j){
            if(j==0) dp[i][j]=dp[i-1][j];
            else if(j-1-a[i-1]>=0) (dp[i][j]=dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1-a[i-1]]+MOD)%=MOD;
            else (dp[i][j]=dp[i][j-1]+dp[i-1][j])%=MOD;
        }
    }
    cout<<dp[N][K]<<endl;
    return 0;
}

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

using namespace std;

struct shop {
    int p, c;
    bool operator<(const shop &o) const {
        return p < o.p;
    }
};

// struct shop_cmp {
    // bool operator()(const shop &o) const {
    //     return p < o.p;
    // }
// };



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

    vector<shop> shops;
    shops.reserve(n);
    for (int i = 0; i < n; ++i) {
        int p, c;
        cin >> p >> c;
        shops.push_back({p, c});
    }
    sort(shops.begin(), shops.end());
    long long ans = 0;
    int got = 0;
    for (auto &sh : shops) {
        if (got + sh.c >= m) {
            ans += (long long)(m - got) * sh.p;
            break;
        }
        ans += (long long)sh.c * sh.p;
        got += sh.c;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
  string S, s = "";
  cin >> S;
  for (int i = 0; i < S.size(); i++)
    s += "9";
  while (stoll(s) > stoll(S))
  {
    int in = s.at(0) - '1';
    s.replace(0, 1, to_string(in));
  }
  int64_t ans = 0;
  for (int i = 0; i < s.size(); i++)
  {
    ans += s.at(i) - '0';
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        if(N <= 999){
            System.out.println("ABC");
        }else{
            System.out.println("ABD");
        }
    }
}


Measured memory_bytes: 35708
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  string s,n,final;
  int o,c=0,lim;
  cin>>lim;
  for(int j = 0 ; j < lim ; j++){
    cin>>s>>n;
      reverse(s.begin(),s.end());
    reverse(n.begin(),n.end());
    for(int i = 0; i < s.size() || i<n.size() || c;i++){
      o = (s.size() > i ? s[i]-'0' : 0) +(n.size() > i ? n[i]-'0' : 0) + c;
      
      //   o = (s[i]-'0')+(n[i]-'0')+c;
      c = o / 10;
      o %= 10;
      final.append(1,o+'0');
    }
    reverse(final.begin(),final.end());
    if(final.size()>80) cout<<"overflow"<<endl;
    else cout<<final<<endl;
    final.clear();
  }
}
  

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int t,d,l,x;
    while (cin>>t>>d>>l) {
        if (t==0&&d==0&&l==0) {
            break;
        }
        int start,flag=0,count=d,ans=0;
        for (int i=1;i<=t;i++) {
            cin>>x;
            if (flag==0) {
                if (x>=l) {
                    start=i;
                    flag=1;
                }
            } else {
                if (x<l) {
                    count--;
                    if (count==0) {
                        ans+=(i-start);
                        count=d;
                        flag=0;
                    }
                } else {
                    count=d;
                }
                if (i==t) {
                    ans+=i-start;
                }
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3032
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define EPS 1e-8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define MOD 100000
typedef long long ll;
typedef pair < int , int > Pii;
int main(){
	int n;
	scanf("%d",&n);
	int num[128];
	ll dp[101][21]={{0}};
	rep(i,n){
		scanf("%d",&num[i]);
	}
	dp[1][num[0]] = 1;
	reps(i,1,n-1){
		rep(j,21){
			if(dp[i][j] > 0){
				if(j+num[i] >= 0 && j+num[i] < 21)dp[i+1][j+num[i]] += dp[i][j];
				if(j-num[i] >= 0 && j-num[i] < 21)dp[i+1][j-num[i]] += dp[i][j];
			}
		}
	}
	/*reps(i,1,n){
		rep(j,21){
			printf("%d ",dp[i][j]);
		}
		puts("");
	}*/
	printf("%lld\n",dp[n-1][num[n-1]]);
	return 0;
}

Measured memory_bytes: 1212
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define fst first
#define snd second
using ll = long long;
using I = pair<int, int>;
const ll INF = 1ll << 60;

int main() {
  int N, M, R;
  while (cin >> N >> M >> R) {
    vector<int> r(R);
    for (int i = 0; i < R; i++) cin >> r[i], --r[i];
    vector<vector<ll>> dist(N, vector<ll>(N, INF));
    for (int i = 0; i < N; i++) dist[i][i] = 0;
    for (int i = 0; i < M; i++) {
      int A, B, C;
      cin >> A >> B >> C;
      --A;
      --B;
      dist[A][B] = C;
      dist[B][A] = C;
    }
    for (int k = 0; k < N; k++) {
      for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
          dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
        }
      }
    }
    vector<vector<ll>> dp(1 << R, vector<ll>(R, INF));
    for (int i = 0; i < R; i++) dp[1 << i][i] = 0;
    for (int S = 0; S < 1 << R; S++) {
      for (int i = 0; i < R; i++) {
        if ((S >> i) & 1) {
          for (int j = 0; j < R; j++) {
            if ((S >> j) & 1) continue;
            dp[S | (1 << j)][j] =
                min(dp[S | (1 << j)][j], dp[S][i] + dist[r[i]][r[j]]);
          }
        }
      }
    }
    ll res = INF;
    for (int i = 0; i < R; i++) res = min(res, dp[(1 << R) - 1][i]);
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();

		int[] D = new int[N+1];
		int[] L = new int[N+1];
		D[0] = 0;
		for(int i=0;i<N;i++) {
			L[i] = sc.nextInt();
			D[i+1] = D[i] + L[i];
		}
		Arrays.sort(D);

		int ans = 0;
		for(int i=0;i<N+1;i++) {
			if(D[i] > X) {
				System.out.println(ans);
				return;
			}else {
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22996
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void) {

    ll x; cin >> x;
    ll i = 100, cnt = 0;
    while (i < x) {
        i *= 1.01;
        cnt++;
    }
    cout << cnt << endl;


    return 0;
}

Measured memory_bytes: 3636
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

use std::cmp::max;

fn main() {
    input!{
        n: usize,
        mut v: [[i64; 3]; n]
    }
    v.sort_by_key(|x| x[0] + x[1]);
    let mut tab: Vec<Vec<i64>> = vec![vec![-1; 20001]; n + 1];
    tab[0][0] = 0;
    for i in 0..n {
        for j in 0..v[i][1] as usize + 1 {
            if tab[i][j] >= 0 {
                tab[i + 1][j + v[i][0] as usize] = max(tab[i][j + v[i][0] as usize], tab[i][j] + v[i][2]);
            }
        }
        for j in 0..20001 {
            tab[i + 1][j] = max(tab[i + 1][j], tab[i][j]);
        }
    }
    println!("{}", *tab[n].iter().max().unwrap());
}


Measured memory_bytes: 174332
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

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

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

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

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

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

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	a := readInt()
	b := readInt()
	c := readInt()
	count := make([]int, 10)
	count[a]++
	count[b]++
	count[c]++
	if count[5] == 2 && count[7] == 1 {
		println("YES")
	} else {
		println("NO")
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define N 101
using namespace std;
int n,A[N];

void sort(){
  for(int i=0;i<n;i++)cout<<(i? " ":"")<<A[i];cout<<endl;    
  for(int i=1;i<n;i++){
    int v = A[i];
    int j = i -1;
    while(j>=0&&A[j]>v) A[j+1]=A[j--];
    A[j+1] = v;
    for(int i=0;i<n;i++)cout<<(i? " ":"")<<A[i];cout<<endl;    
  }
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++) cin>>A[i];
  sort();
  return 0;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,a,ans=0;
	cin>>n>>m;
	
	for(int i=1;i<=m;i++){
	    cin>>a;
	    ans+=a;
	}
	    
    if(n>=ans)
    	cout<<n-ans;
	else
	    cout<<"-1";
	
	return 0;
}

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

int main(){
  int S,Ss;
  int h;
  int m;
  int s;
  cin>>S;
  h=S/3600;
  Ss=S%3600;
  m=Ss/60;
  s=Ss%60;
  cout<<h<<":"<<m<<":"<<s<<endl;
}

Measured memory_bytes: 1164
class disjoint_set:
    def __init__(self,num):

        self.array=[0]+[[i,0] for i in range(1,num+1)]  # our set
    
    def union(self,a,b):
        
        ''' a and b are the vertices that we want to connect them to each other '''
        
        a=self.find(a) # finds the ancestor of a
        b=self.find(b) # finds the ancestor of b
    
        if a==b:
            # if the ancestors of a and b are the same , do nothing
            return False
    

        # connecting two graph components to each other

        if self.array[a][1] > self.array[b][1] :
            self.array[b][0]=a
        
        elif self.array[a][1] < self.array[b][1] :
            self.array[a][0]=b

        else:
            self.array[a][0]=b
            self.array[b][1]+=1
        return True
            
    def find(self,a):
        p=[]
        while self.array[a][0]!=a :
            p.append(a)
            a=self.array[a][0]
        for i in p:
            self.array[i][0]=a
        return a

##############################3
n,m=map(int,input().split())
dset=disjoint_set(n)
for _ in range(m):
    a,b=map(int,input().split())
    dset.union(a,b)

ans=set()
for i in range(1,n+1) :
    ans.add(dset.find(i))

print(len(ans)-1)

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,k; cin>>n>>k;
  
  double ans=0;
  reps(i,n){
    double x=1;
    ll now=i;
    while(now<k){
      x/=2.0;
      now*=2;
    }
    ans+=x*(1.0/n);
  }
  cout<<std::setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 3816
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int k,t;
  cin>>k>>t;
  std::vector<int> a(t);
  for(auto&& e: a) {
    cin>>e;
  }
  int sum=accumulate(a.begin(), a.end(),0);
  int m=*max_element(a.begin(), a.end());
  sum-=m;
  m--;
  cout<<max(0,m-sum);

}

Measured memory_bytes: 256
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-26 16:43:07
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod)
{
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod)
{
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod)
{
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l)
{
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    int cnt[9] = {0};
    for (int i = 0; i < n; i++) {
        int in = a[i]/400;
        if (in < 8) cnt[in]++;
        else cnt[8]++;
    }

    int min = 0;
    for (int i = 0; i < 8; i++) {
        if (cnt[i] > 0) min++;
    }

    int max = min + cnt[8];

    if (min == 0) min = 1;

    cout << min << " " << max << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=(1e5+10);
int n,a[maxn],dp[maxn],mx=0;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=n-1;i>=0;i--)
	{
		if(i==n-1)
			dp[i]=0;
		else
			dp[i]=(a[i+1]>a[i]?0:dp[i+1]+1);
		mx=max(mx,dp[i]);
	}
	cout<<mx<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define maxn 210
#define maxm 10000010
const int lim=1e7;
template <typename T>inline T read()
{
    register T sum=0;
    register char cc=getchar();
    int sym=1;
    while(cc!='-'&&(cc>'9'||cc<'0'))cc=getchar();
    if(cc=='-')sym=-1,cc=getchar();
    sum=sum*10+cc-'0';
    cc=getchar();
    while(cc>='0'&&cc<='9')sum=sum*10+cc-'0',cc=getchar();
    return sym*sum;
}
template <typename T>inline T read(T &a)
{
    a=read<T>();
    return a;
}
template <typename T,typename... Others> inline void read(T& a, Others&... b)
{
    a=read(a);
	read(b...);
}
struct Edge
{
	int v;
	Edge *next;
	Edge(int a=0,Edge *b=NULL)
	{
		v=a;
		next=b;
	}
}*head[maxn];
int n,mx,tim,cnt,cnt1,cnt2,ans,maxflow,a[maxm];
int L[maxn],R[maxn],p[maxm],vis[maxn],flg[maxm],match[maxn];
bool Match(int k)
{
	for(Edge *i=head[k];i!=NULL;i=i->next)
	{
		if(vis[i->v]==tim)
			continue;
		vis[i->v]=tim;
		if(!match[i->v]||Match(match[i->v]))
		{
			match[i->v]=k;
			return true;
		}
	}
	return false;
}
void init()
{
	flg[0]=flg[1]=true;
	for(int i=2;i<=lim;i++)
	{
		if(!flg[i])
			p[++cnt]=i;
		for(int j=1;j<=cnt&&p[j]*i<=lim;j++)
		{
			flg[i*p[j]]=true;
			if(i%p[j]==0)
				break;
		}
	}
}
int main()
{
	init();
	read(n);
	for(int i=1;i<=n;i++)
	{
		int x;
		read(x);
		a[x]+=1;
		mx=max(mx,x);
	}
	for(int i=1;i<=mx+1;i++)
	{
		if(a[i]!=a[i-1])
		{
			if(i&1)
				L[++cnt1]=i;
			else
				R[++cnt2]=i;
		}
	}
	for(int i=1;i<=cnt1;i++)
		for(int j=1;j<=cnt2;j++)
			if(!flg[abs(L[i]-R[j])])
				head[i]=new Edge(j,head[i]);
	for(int i=1;i<=cnt1;i++)
	{
		tim+=1;
		maxflow+=Match(i);
	}
	ans=maxflow;
	ans+=(cnt1-maxflow)/2*2+(cnt2-maxflow)/2*2;
	ans+=((cnt1-maxflow)&1)*3;
	printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 82304
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut a: Vec<u8> = vec![];
    let mut bubble_count: u16 = 0;
    let mut bubble_flag: bool = true;
    for _ in 0..n {
        let number: u8 = read();
        a.push(number);
    }

    while bubble_flag {
        bubble_flag = false;
        for index in (1..n).rev() {
            if a[index] < a[index - 1] {
                bubble_flag = true;
                bubble_count += 1;
                a.swap(index, index - 1);
            }
        }
    }

    for (index, number) in a.iter().enumerate() {
        if index != a.len() - 1 {
            print!("{} ", number);
        } else {
            println!("{}", number);
        }
    }
    println!("{}", bubble_count);
}



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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct Vertex {
    vector<ll> node;
    ll cost = 0;
    ll child = 0;
};

Vertex V[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    REP(i, M) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        V[b].node.push_back(a);
        V[a].child++;
    }

    queue<pll> q;
    REP(i, N) {
        if (V[i].child == 0)
            q.push(pll(i, 0));
    }
    ll ans = 0;
    while (!q.empty()) {
        pll t = q.front();
        q.pop();
        ans = std::max(ans, t.second);
        ll cost = t.second + 1;
        for (auto &n : V[t.first].node) {
            V[n].cost = std::max(V[n].cost, cost);
            if (--V[n].child > 0)
                continue;
            q.push(pll(n, V[n].cost));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7296
#include <stdio.h>
int main(void){
    // Your code here!
    int num;
    int v[50];
    int c[50];
    int ans=0;
    
    scanf("%d",&num);
    for(int i=0; i<num; i++){
        scanf("%d",&v[i]);
    }
    for(int i=0; i<num; i++){
        scanf("%d",&c[i]);
    }
    
    for(int i=0; i<num; i++){
        if(v[i]-c[i] > 0){
            ans += v[i]-c[i];
        }
    }
    
    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
int main()
{   char s[101],key[8]="keyence";
    scanf("%s",s);
    int h=0,t=0;
    for(int i=0;i<7;i++){
        if(s[i]==key[i]){
            h++;
        }else{
            break;
        }
    }
    for(int i=0;i<7;i++){
        if(s[strlen(s)-(1+i)]==key[6-i]){
            t++;
        }else{
            break;
        }
    }
    if(h+t>=7)
    printf("YES");
    else printf("NO");

    return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class C
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = Scanner.Scan<int>();
            var P = Scanner.ScanEnumerable<int>().ToArray();
            var answer = 0;
            var min = (int)1e9;
            for (var i = 0; i < N; i++)
            {
                if (min <= P[i]) continue;
                min = P[i];
                answer++;
            }
            Console.WriteLine(answer);
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 47748
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  string ans = "";
  string s;

  cin >> s;

  int slen = s.size();
  for(int i = 0; i < slen; i++){
    if(s[i] == 'B'){
      if(ans==""){
        continue;
      }else{
        ans.pop_back();
      }
    }else if(s[i] == '0'){
      ans.push_back('0');
    }else if(s[i] == '1'){
      ans.push_back('1');
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
def call(n)   
  for i in 1..n do
        if i%3==0
            print " ",i
        else
            x = i
            while x > 0 do
                if x%10==3
                    print " ",i
                    break
                end
                x /= 10
            end
        end
    end
    puts
end

n = gets.to_i
call(n)

Measured memory_bytes: 8736
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <typeinfo>

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<string> S(n);
  for(int i=0;i<n;i++)  cin >> S.at(i);

  vector<char> abc(26);
  for(int i=0;i<26;i++){
    int count=50;
    for(int j=0;j<n;j++){
      int x=0;
      for(int k=0;k<S.at(j).size();k++){
        if(S.at(j).at(k)-'a'==i)  x++;
      }
      count=min(count,x);
    }
    abc.at(i)=count;
  }

  for(int i=0;i<26;i++){
    for(int j=0;j<abc.at(i);j++){
      printf("%c",i+'a');
    }
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
    int main(void)
    {
      int i,K,X;
      int num;
      scanf("%d%d",&K,&X);
      num=2*K-1;
      for(i=0;i<num;i++){
        printf("%d ",X-K+1+i);
      }
      return 0;
    }

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define DUMP(v) for(auto& x : v) cerr << x << " "; cerr << endl;
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);


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

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

  vector<ll> x(n);
  rep(i, n) cin >> x[i];

  ll ans = 0;
  for (int i = 0; i < n-1; i++) {
    ans += min((x[i+1] - x[i]) * a, b);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	string s;
	cin >> s;
	rep(i,0,sz(s)) {
		int ch = (s[i] - 'A' + n) % 26;
		cout << (char)(ch + 'A');
	}
	cout << endl;

	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = ll(1e9 + 7);
ll dp[70][2][2];
int a[70];

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

	ll N;
	cin >> N;
	for(int i = 0; i < 64; i++) {
		a[i] = N >> i & 1;
	}

	dp[0][0][0] = 1;
	for(int i = 0; i < 64; i++) {
		for(int j = 0; j < 2; j++) {
			for(int k = 0; k < 2; k++) {
				if(dp[i][j][k] == 0) continue;
				int u[3] = { 0, 0, 1 }, v[3] = { 0, 1, 1 };
				for(int l = 0; l < 3; l++) {
					int sum = j + u[l] + v[l];
					int nj = sum / 2;
					int nk = (sum % 2) > a[i] || k && (sum % 2) >= a[i];
					dp[i + 1][nj][nk] += dp[i][j][k];
					dp[i + 1][nj][nk] %= MOD;
				}
			}
		}
	}

	cout << dp[64][0][0] << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

ll N, gA, gB, sA, sB, bA, bB;

int main() {
    cin >> N >> gA >> sA >> bA >> gB >> sB >> bB;

    vll dp_AB(N + 1);
    rep(n, 1, N + 1) {
        dp_AB[n] = n;
        if (n >= gA) dp_AB[n] = max(dp_AB[n], dp_AB[n - gA] + gB);
        if (n >= sA) dp_AB[n] = max(dp_AB[n], dp_AB[n - sA] + sB);
        if (n >= bA) dp_AB[n] = max(dp_AB[n], dp_AB[n - bA] + bB);
    }
    ll N_B = dp_AB[N];

    vll dp_BC(N_B + 1);
    rep(n, 1, N_B + 1) {
        dp_BC[n] = n;
        if (n >= gB) dp_BC[n] = max(dp_BC[n], dp_BC[n - gB] + gA);
        if (n >= sB) dp_BC[n] = max(dp_BC[n], dp_BC[n - sB] + sA);
        if (n >= bB) dp_BC[n] = max(dp_BC[n], dp_BC[n - bB] + bA);
    }

    write(dp_BC[N_B]);
}

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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int D;
    cin >> D;
    vector<int> c(26);
    for (int i=0;i<26;i++) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(26));
    for (int i=0;i<D;i++){
        for (int j=0;j<26;j++){
            cin >> s[i][j];
        }
    }
    vector<int> t(D);
    //初期t[i]の決定
    for (int i=0;i<D;i++) {
        t[i] = i % 26;
    }

    ll oldsum = 0;
    vector<int> ans = t;
    for (int m=0;m<100000;m++){
        //ここでt[i]を更新していく
        int dd = rand()%365;
        int qq = rand()%26;
        int oldval = t[dd];
        t[dd] = qq;
        //=======================
        ll sum = 0;
        vector<int> last(26);
        for (ll i=0;i<D;i++){
            sum += s[i][t[i]];
            last[t[i]] = i+1;
            for (int j=0;j<26;j++){
                sum -= c[j]*(i+1-last[j]);
            }
        }
        if (sum > oldsum) {
            oldsum = sum;
            ans[dd] = qq;
        } else {
            t[dd] = oldval;
        }
    }
    for (int i=0;i<D;i++){
        cout << ans[i]+1 << "\n";
    }
}

Measured memory_bytes: 3708
N = int(input())
S = input()

r = S.count("R")
g = S.count("G")
b = S.count("B")

ans = r * g * b
for i in range(1, N):
    if 2 * i + 1 > N:
        break
    for x in range(N):
        if x + 2 * i + 1 > N:
            break
        if S[x] != S[x+i] and S[x] != S[x+(2*i)] and S[x+i] != S[x+(2*i)]:
            ans -= 1

print(ans)



Measured memory_bytes: 9204
#include <iostream>
#include <vector>
#include <limits.h>
#include <string>

using namespace std;

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

	cin >> n;
	string wk;
	for (int i = 0; i < n; i++) {
		cin >> wk;

		a.push_back(wk);

	}

	bool flg = true;

	for (int i = 0; i < a.size() - 1; i++) {
		for (int j = i+1; j < a.size(); j++) {
			if (a[i] == a[j]) {
				flg = false;
				break;
			}
		}

		if (a[i][a[i].size() - 1] != a[i + 1][0])flg = false;

		if (!flg)break;


	}

	if (flg) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}





	return 0;





}



Measured memory_bytes: 256
#include <cstdio>
#define rg register
using namespace std;
typedef long long ll;
template <typename Tp> inline int getmin(Tp &x,Tp y){return y<x?x=y,1:0;}
template <typename Tp> inline int getmax(Tp &x,Tp y){return y>x?x=y,1:0;}
template <typename Tp> inline void read(Tp &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    if(f) x=-x;
}
ll n,x,d;
ll calc(ll n,ll x)
{
	if(n%x==0) return n/x*x*2-x;
	return calc(x,n%x)+n/x*x*2;
}
int main()
{
	read(n);read(x);
	printf("%lld\n",n+calc(n-x,x));
	return 0;
}

Measured memory_bytes: 128