akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<16,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;cin>>Q;
    map<char,int> MA;
    for(char i='0';i<='9';i++) MA[i]=int(i-'0');
    MA['a']=10;
    MA['b']=11;
    MA['c']=12;
    MA['d']=13;
    MA['e']=14;
    MA['f']=15;
    while(Q--){
        vector<unsigned int> A(9);
        for(int i=0;i<9;i++){
            string S;cin>>S;
            for(int j=0;j<S.size();j++){
                A[i]*=16;
                A[i]+=MA[S[j]];
            }
        }
        
        unsigned int ans=0;
        int kuri=0;
        
        for(int j=0;j<32;j++){
            int sum=0;
            for(int i=0;i<8;i++){
                if(A[i]&(1<<j)) sum++;
            }
            if((sum+kuri)%2){
                if(A[8]&(1<<j)) kuri=(sum+kuri)/2;
                else{
                    ans+=1<<j;
                    kuri=(8-sum+kuri)/2;
                }
            }else{
                if(A[8]&(1<<j)){
                    ans+=1<<j;
                    kuri=(8-sum+kuri)/2;
                }else kuri=(sum+kuri)/2;
            }
        }
        
        string res;
        
        for(int j=28;j>=0;j-=4){
            int a=(ans>>j)%16;
            if(a==0&&res.size()>=1) res+='0';
            else if(1<=a&&a<=9) res+=char('0'+a);
            else if(a>=10) res+=char('a'+a-10);
            
            //cout<<a<<endl;
        }
        
        if(res.size()==0) res="0";
        cout<<res<<endl;
        
    }
}





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

"""
参考：https://nuekodory.github.io/2018/06/24/AtCoder-ABC101-ARC-099-%E3%82%92-Python3-%E3%81%A7%E8%A7%A3%E3%81%8F/
　　　http://xxxasdfghjk999.hatenablog.jp/entry/2018/07/22/162323
　　　http://drken1215.hatenablog.com/entry/2018/06/24/010600
　　　http://phyllo-algo.hatenablog.com/entry/2018/06/24/160442
・事前にいくつかの範囲を調べて、候補の数がabc9999....のあたりだけだと予測しておく。
・候補の値だけに絞って最大値から下がっていく。
"""

K = int(input())

def make_snk(num):
    s = str(num)
    sm = 0
    for c in s:
        sm += int(c)
    return num / sm

snk_list = []
mn = float('inf')
suff = '999999999999'
# 後ろに付ける9の数を減らして、10^15-1から10099までを作る
for i in range(11):
    # 999～100までループ
    for j in range(999, 99, -1):
        j = int(str(j) + suff)
        num = make_snk(j)
        if num <= mn:
            snk_list.append(j)
            mn = num
    suff = suff[:-1]
# 9999以下は普通に全部やる(大した大きさじゃないので)
for i in range(9999, 0, -1):
    num = make_snk(i)
    if num <= mn:
        snk_list.append(i)
        mn = num
snk_list.reverse()
for i in range(K):
    print(snk_list[i])


Measured memory_bytes: 3188
#include <iostream>
#include <string>
using namespace std;
int main(){
  string a, b, c;
  cin >> a >> b >> c;
  if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0])cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
A, B = map(int, input().split())

if (A > 1):
    a_sum = A * (A - 1) / 2
else:
    a_sum = 0
if (B > 1):
    b_sum = B * (B - 1) / 2
else:
    b_sum = 0

ans = a_sum + b_sum
print(int(ans))

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

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

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

int n, h[100009];

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    int ans = 0, cnt = 0;
    for (int i = 0; i < n - 1; i++) {
        if (h[i] >= h[i + 1]) cnt++;
        else {
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    ans = max(ans, cnt);
    cout << ans << E;
    //system("pause");
    return 0;
}

Measured memory_bytes: 640
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, A, B): (i64, i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };

    let ans = if (A - B).abs() % 2 == 0 {
        "Alice"
    } else {
        "Borys"
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;


int main()
{
	const int MAX_N = 100000;
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	bool isLeft[MAX_N];
	for (int i = 0; i < n; i++)
		isLeft[i] = (s[i] == 'L') ? true : false;


	int happy = 0;
	for (int i = 0; i < n - 1; i++)
	{
		if (isLeft[i] == isLeft[i + 1])
			happy += 1;
	}

	int answer = min(happy + 2 * k, n -1);

	cout << answer;

	return 0;

}



Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cmath>
#include <utility>

using namespace std;

int main() {
    int n;  cin >> n;
    int *v = new int[n];
    for (int i = 0; i < n; i++)
        cin >> v[i];

    int *v_e = new int [n/2], *v_o = new int[n/2];
    for (int i = 0; i < n/2; i++) {
        v_e[i] = v[i*2];
        v_o[i] = v[i*2+1];
    }

    pair<int, int> *p_e = new pair<int,int>[100000], *p_o = new pair<int,int>[100000];
    for (int i = 0; i < 100000; i++) {
        p_e[i].first = 0;
        p_e[i].second = i+1;
        p_o[i].first = 0;
        p_o[i].second = i+1;
    }
    for (int i = 0; i < n/2; i++) {
        p_e[v_e[i]-1].first++;
        p_o[v_o[i]-1].first++;
    }

    sort(p_e, p_e+100000, greater<pair<int,int> >());
    sort(p_o, p_o+100000, greater<pair<int,int> >());

    int e_1 = p_e[0].second, e_2 = p_e[1].second, o_1 = p_o[0].second, o_2 = p_o[1].second;

    
    if (e_1 != o_1) {
        cout << n - p_e[0].first - p_o[0].first << endl;
        return 0;
    }

    else {
        cout << n - max(p_e[0].first + p_o[1].first, p_e[1].first + p_o[0].first) << endl;
        return 0; 
    }
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(){
  int n,a,b;
  int a_n,b_n;
  string state;
  cin>>n>>a>>b>>state;
  a_n=0;
  b_n=0;
  for(int i=0;i<n;i++){
    if(state[i]=='a'){
      if(a_n+b_n<a+b){
        cout<<"Yes";
        a_n++;
      }else{
        cout<<"No";
      }
      cout<<endl;
    }else if(state[i]=='b'){
      if(a_n+b_n<a+b && b_n<b){
         cout<<"Yes";           
         b_n++;
      }else{
        cout<<"No";
      }
      cout<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
}

Measured memory_bytes: 896
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		StringBuilder sb = new StringBuilder();
		Scanner scan = new Scanner(System.in);
		while(true){
		//Scanner scan = new Scanner(System.in);


		int H = scan.nextInt();
	    int W = scan.nextInt();


	    if(H == 0 && W == 0)break;
	    for(int i = 0;i < H ;i++){
	    	for(int j = 0;j < W; j++){

	    		sb.append("#");
	    		//System.out.print("#");
	    	}
	    	//System.out.println();
	    	sb.append("\n");
	    }
	    sb.append("\n");
	    //System.out.println();
	   }
		System.out.print(sb);
	}
}

Measured memory_bytes: 27488
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")

#define DEBUG(x) cout << ">> " << #x << ": " << x << endl;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f first
#define s second

const int MOD = 1000000007;
typedef long long ll;
typedef long double ld;

void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0);
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}

ll gcd(ll a, ll b) {
  if (a == 0) return b;
  return gcd(b%a, a);
}

int main() { _
  ll k; cin >> k;
  ll ans = 0;
  for (ll a = 1; a <= k; a++) {
    for (ll b = 1; b <= k; b++) {
      for (ll c = 1; c <= k; c++) {
        ans += gcd(c, gcd(a, b));
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

const int N = 100005;
bool prime[100005];
void eratosthenes(){
    rep(i,N) prime[i] = 1;
    prime[0] = prime[1] = 0;
    rep(i,N){
        if(prime[i]){
            for(int j = i + i; j < N; j+=i){
                prime[j] = 0;
            }
        }
    }
}

int main() {
  int x;
  cin >> x;
  eratosthenes();

  for(int i = x; i <= 100004; i++) {
    if(prime[i]) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 384
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18
#list(map(int, stdin.readline().rstrip().split()))
n,m,x = map(int, stdin.readline().rstrip().split())
numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
#word = [stdin.readline().rstrip() for _ in range(n)]
#number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]

rikai = [0] * m
l = [i for i in range(1,n+1)]
ans = 10**9
for i in l:
    books = list(comb(l,i))

    for j in books:
        # jを選ぶ
        pay = 0
        rikaii = rikai[:]
        for u in j:
            cost = numbers[u-1][0]
            skill = numbers[u-1][1:]
            pay += cost
            rikaii = [x + y for (x, y) in zip(rikaii, skill)]
        ok = 0
        for y in range(m):
            if rikaii[y] >= x:
                ok += 1
        if ok == m:
            ans = min(ans,pay)

if ans == 10**9:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 9380
#include <iostream>
#include <tuple>
#include <algorithm>
#include <vector>
#include <utility>

int main() {
	int a, b, c, x, y, sum_price;
	std::cin >> a >> b >> c >> x >> y;
	std::vector<std::pair<int, int>> vec;
	vec.push_back(std::make_pair(a, x));
	vec.push_back(std::make_pair(b, y));
	std::sort(vec.begin(), vec.end());
	int min_price = vec[0].first;
	int all_num = x + y;
	int all_price = a + b;
	if (c*2 <= min_price) {
		std::cout << c * 2 * ((x>y) ? x : y) << std::endl;
		return 0;
	}
	else if (c*2 <= vec[1].first) {
		sum_price = c*vec[1].second*2;
		if (vec[0].second > vec[1].second) {
			sum_price += (vec[0].first * (vec[0].second - vec[1].second));
		}
	}
	else if (a+b >= c*2) {
        auto min_num_pizza = (vec[0].second < vec[1].second) ? vec[0] : vec[1];
        sum_price = min_num_pizza.second * c * 2;
        if (min_num_pizza.second < (all_num-min_num_pizza.second)) {
            sum_price += ((all_price - min_num_pizza.first) * ((all_num-min_num_pizza.second)-min_num_pizza.second));
        }
    }
	else {
		sum_price = a*x + b * y;
	}
	std::cout << sum_price << std::endl;
	return 0;
	 
}


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

#ifdef LOCAL
#define DEBUG(...) cerr << #__VA_ARGS__ << ": ", debug(__VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename T, size_t N> ostream& operator << (ostream &os, const array<T, N> &a) {os << "("; for (int i=0; i<(int)N; i++) {if (i) os << ", "; os << a[i];} return os << ")";}
template<typename T> ostream& operator << (ostream &os, const vector<T> &v) {os << "["; for (int i=0; i<(int)v.size(); i++) {if (i) os << ", "; os << v[i];} return os << "]";}
void debug() {cerr << "\n";} template<typename T, typename... Args> void debug(T x, Args... args) {cerr << x << "; "; debug(args...);}

int dp[1000001][2];
string n;

int solve(int i, int carry) {
    if (i == n.length())
        return carry;
    if (dp[i][carry] != -1)
        return dp[i][carry];

    int digit = n[i] - '0' + carry;
    if (digit == 10)
        dp[i][carry] = solve(i + 1, 1);
    else
        dp[i][carry] = min(solve(i + 1, 0) + digit, solve(i + 1, 1) + 10 - digit);

    return dp[i][carry];
}

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

    cin >> n;

    reverse(n.begin(), n.end());
    memset(dp, -1, sizeof(dp));
    cout << solve(0, 0) << "\n";

    return 0;
}


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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if ((a == b && b == c) || (a != b && b != c && a != c)) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
 
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<vector>
using namespace std;
/*bool check(vector<int> a,vector<int> b){
	int pos=0;
	for(int i=0;i<a.size();i++){
		if(a[i]==b[pos]){
			pos++;
		}
	}
	if(b.size()==pos)
		return true;
	return false;
}*/
int main(){
	int A,B;
	while(cin>>A>>B){
		vector<int> a(A),b(B);
		for(int i=0;i<A;i++){
			cin>>a[i];
		}
		for(int i=0;i<B;i++){
			cin>>b[i];
		}
		int sum = 0,  ans = 0;
		for(int i=0;i<b.size();i++){
			sum = 0;
			int endi = 0;
			int j = i;
			//cout << "---"<<endl;
			for(; j<b.size() && endi < a.size();j++) {
				bool found = false;
				while(endi < a.size()) {
					if (b[j]==a[endi++]) {
						found = true;
						break;
					}
				}
				if (found) {
					//cout << "d" << endi<<endl;
					sum ++;
				}
			}
			//if (j != b.size()) continue;
			
			ans = max(ans, sum);
		}
		cout << ans <<endl;
	}
	return 0;
}

Measured memory_bytes: 904
#include <iostream>
#define INF 0x3f3f3f3f
using namespace std;
long long n,a[100001],dp[100001][2];
int main()
{
    //freopen("D.INP","r",stdin);
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> n;
    for (int i=1;i<=n;i++) cin >> a[i];
    dp[0][0]=0;dp[0][1]=-INF;
    for (int i=1;i<=n;i++)
    {
        dp[i][0]=max(dp[i-1][0]+a[i],dp[i-1][1]-a[i]);
        dp[i][1]=max(dp[i-1][0]-a[i],dp[i-1][1]+a[i]);
    }
    cout << dp[n][0];
}


Measured memory_bytes: 2560
#include <stdio.h>
int main() {
  int N, A[101], v;
  int i, j;
  scanf("%d", &N);
  for(i = 0; i < N; i++) scanf("%d", A+i);
  for(i = 1; i <= N; i++) {
    for(j = 0; j < N; j++) {
      if(j) printf(" ");
      printf("%d", A[j]);
    }
    puts("");
    if(i == N) break;
    v = A[i];
    j = i-1;
    while(j >= 0 && A[j] > v) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
  }
  return 0;
}

Measured memory_bytes: 616
n=int(input())
s=input()
cntW=[0]*n
cntE=[0]*n
for i in range(1,n):
  if s[i-1]=='E':
    cntE[i]=cntE[i-1]+1
  else:
    cntE[i]=cntE[i-1]
for i in range(n-2,-1,-1):
  if s[i+1]=='W':
    cntW[i]=cntW[i+1]+1
  else:
    cntW[i]=cntW[i+1]
ans=10**9
ans=min(ans,n-1-cntW[0],n-1-cntE[n-1])
for i in range(1,n-1):
  ans=min(ans,n-1-cntE[i]-cntW[i])
print(ans)

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

using namespace std;

constexpr int INF = 1e8;

int vx[]{-1,1,0,0};
int vy[]{0,0,-1,1};

int main(){
    int w,h;
    while(cin>>w>>h,w){
        vector<vector<char>>mp(w+2,vector<char>(h+2,'x'));
        pair<int,int>src;
        vector<pair<int,int>>kkk;
        for(int i=1;i<=h;++i){
            string s;
            cin>>s;
            for(int j=1;j<=w;++j){
                mp[j][i]=s[j-1];
                if(mp[j][i]=='o'){
                    src={j,i};
                }
                if(mp[j][i]=='*'){
                    kkk.emplace_back(j,i);
                }
            }
        }
        vector<vector<int>>d((w+2)*(h+2),vector<int>((w+2)*(h+2),INF));
        for(int i=1;i<=h;++i){
            for(int j=1;j<=w;++j){
                for(int k=0;k<4;++k){
                    if(mp[j+vx[k]][i+vy[k]]!='x'){
                        d[(w+2)*i+j][(w+2)*(i+vy[k])+j+vx[k]]=1;
                    }
                }
            }
        }
        int n=(w+2)*(h+2);
        for(int k=0;k<n;++k){
            for(int i=0;i<n;++i){
                for(int j=0;j<n;++j){
                    if(d[i][j]>d[i][k]+d[k][j]){   
                        d[i][j]=d[i][k]+d[k][j];                     
                    }
                }
            }
        }
        sort(kkk.begin(),kkk.end());
        int ans=INF;
        do{
            int pre=src.first+src.second*(w+2);
            int ret=0;
            for(int i=0;i<kkk.size();++i){
                if(d[pre][kkk[i].first+(w+2)*kkk[i].second]<INF){
                    ret+=d[pre][kkk[i].first+(w+2)*kkk[i].second];
                    pre=kkk[i].first+(w+2)*kkk[i].second;
                }else{
                    ret=INF;
                    break;
                }
            }
            ans=min(ans,ret);
        }while(next_permutation(kkk.begin(),kkk.end()));
        if(ans==INF)ans=-1;
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3676
f = lambda: list(map(int,input().split()))
f_ = lambda: [int(x)-1 for x in input().split()]


class UnionFind(object):
    def __init__(self, size):
        self.parent = [i for i in range(size)]
        self.rank = [0 for _ in range(size)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])

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

        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

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


n,m = f()
E = []
for _ in range(m):
    E.append(f_())

ans = 0
for edge in E:
    e = [i for i in E if not i == edge]
    u = UnionFind(n)
    for a,b in e:
        u.unite(a,b)

    f = False
    k = u.find(0)
    for i in range(n):
        if u.find(i) is not k:
            f = True
            break
    if f:
        ans += 1
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
typedef long long ll;

int main()
{
    ll ans;
    ll len;
    char str[200005];
    int cnt[256] = {};

    scanf("%s", str);

    len = strlen(str);
    
    // length - 1までの総和 n(n + 1)/2じゃないよ
    ans = len;
    ans = ans * (ans - 1) / 2 + 1;

    for (int i = 0; i < len; i++) {
        ans -= cnt[str[i]];

        cnt[str[i]]++;
    }

    printf("%lld\n", ans);

    return 0;
}


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

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

using namespace std;

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

	cout<<(a==b?"EQUAL":make_pair(a.length(),a)>make_pair(b.length(),b)?"GREATER":"LESS")<<endl;

	return 0;
}


Measured memory_bytes: 256
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let mut a: Vec<Vec<usize>> = (0..3).map(|_| (0..3).map(|_| it.next().unwrap().parse().unwrap()).collect()).collect();
    it.next();
    for s in it {
        let b: usize = s.parse().unwrap();
        for a in a.iter_mut() {
            for a in a.iter_mut() {
                if *a == b {
                    *a = 0;
                }
            }
        }
    }
    let mut bingo = false;
    bingo |= a.iter().any(|a| a.iter().all(|a| *a == 0));
    bingo |= (0..3).any(|j| (0..3).all(|i| a[i][j] == 0));
    bingo |= (0..3).all(|i| a[i][i] == 0);
    bingo |= (0..3).all(|i| a[2 - i][i] == 0);
    if bingo {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    run();
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define rep(i,a,b) for(ll i = a;i <= b;i++)
#define repv(i,a,b) for(ll i = a;i >= b;i--)
#define e endl
#define all(v) v.begin(), v.end()
typedef pair<ll,ll> pp;

int lcm(int a, int b)
{
    int lar = max(a, b);
    int small = min(a, b);
    for (int i = lar; ; i += lar) {
        if (i % small == 0)
            return i;
    }
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b) {
    return (a.second < b.second);
}

ll power(ll x, unsigned ll y, ll p)
{
    ll res = 1;     // Initialize result
  
    x = x % p; // Update x if it is more than or
                // equal to p
   
    if (x == 0) return 0; // In case x is divisible by p;
  
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;
  
        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

bool isPowerOfTwo (ll x)
{
    return x && (!(x&(x-1)));
} //cout << h[i] << " " << cnt[i] << " " << good[i] << " " << bad[i] << e;


void solve(){
    ll n; cin >> n;
    string s; cin >> s;
    ll r = 0;
    for(ll i = 0;i < s.length();i++) if(s[i] == 'R') r++;
    ll count = 0;
    for(ll i = 0;i < r;i++){
        if(s[i] == 'W') count++;
    }
    cout << count << endl;
}
        
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    //ll t; cin >> t; while(t--)
        solve();
}


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

int W,h,ans=0;
bool a[100+2][100+2],b[100+2][100+2];

bool ch(bool s,bool t){
	if(s&&!t)return true;
	if(!s&&t)return true;
	return false;
}

void w(int x,int y){
	a[x][y]=false;
	b[x][y]=true;
	if(x==0){
		if(x!=101)if(a[x+1][y])w(x+1,y);
		if(y!=101)if(a[x][y+1])w(x,y+1);
		if(y!=0){
			if(a[x][y-1])w(x,y-1);
			if(y%2==1){
				if(x!=101)if(a[x+1][y-1])w(x+1,y-1);
				if(x!=101&&y!=101)if(a[x+1][y+1])w(x+1,y+1);
			}
		}
	}
	else {
		if(a[x-1][y])w(x-1,y);
		if(x!=101)if(a[x+1][y])w(x+1,y);
		if(y!=101)if(a[x][y+1])w(x,y+1);
		if(y%2==0){
			if(y!=101)if(a[x-1][y+1])w(x-1,y+1);
			if(y!=0){
				if(a[x-1][y-1])w(x-1,y-1);
				if(a[x][y-1])w(x,y-1);
			}
		}
		else {
			if(a[x][y-1])w(x,y-1);
			if(x!=101)if(a[x+1][y-1])w(x+1,y-1);
			if(x!=101&&y!=101)if(a[x+1][y+1])w(x+1,y+1);
		}
	}
}		

int main(){
	int c;
	scanf("%d%d",&W,&h);
	for(int i=0;i<102;i++){
		for(int j=0;j<102;j++){
			b[j][i]=false;
			if(1<=i&&i<=h&&1<=j&&j<=W){
				scanf("%d",&c);
				if(c==0)a[j][i]=true;
				else a[j][i]=false;
			}
			else a[j][i]=true;
		}
	}
	w(0,0);
	for(int i=1;i<=W;i++){
		for(int j=1;j<=h;j++){
			if(j%2==0){
				if(ch(b[i-1][j-1],b[i][j])){ans++; if(i==1||j==1)ans++;}
				if(ch(b[i-1][j+1],b[i][j])){ans++; if(i==1||j==h)ans++;}
			}
			else {
				if(ch(b[i+1][j-1],b[i][j])){ans++; if(i==W||j==1)ans++;}
				if(ch(b[i+1][j+1],b[i][j])){ans++; if(i==W||j==h)ans++;}
			}
			if(ch(b[i][j+1],b[i][j])){ans++; if(j==h)ans++;}
			if(ch(b[i][j-1],b[i][j])){ans++; if(j==1)ans++;}
			if(ch(b[i+1][j],b[i][j])){ans++; if(i==W)ans++;}
			if(ch(b[i-1][j],b[i][j])){ans++; if(i==1)ans++;}
		}
	}
	printf("%d\n",ans/2);
}

Measured memory_bytes: 1980
public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = scanner.nextInt();

        long m1 = 0, m2 = 0, s1 = 0, s2 = 0;
        for (int i = 0; i < n; i++) {
            s1 += a[i];
            s2 += a[i];
            if ((i & 1) == 0) {
                if (s1 <= 0) {
                    m1 += Math.abs(s1) + 1;
                    s1 = 1;
                } if (s2 >= 0) {
                    m2 += Math.abs(s2) + 1;
                    s2 = -1;
                }
            } else {
                if (s1 >= 0) {
                    m1 += Math.abs(s1) + 1;
                    s1 = -1;
                } if (s2 <= 0) {
                    m2 += Math.abs(s2) + 1;
                    s2 = 1;
                }
            }
        }
        System.out.println(Math.min(m1, m2));
    }
}

Measured memory_bytes: 52696
#include <iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<set>
using namespace std;
#define PI acos(-1.0)
typedef long long ll;
typedef pair<int,int> P;
const int maxn=5e5+100,maxm=1e5+100,inf=0x3f3f3f3f,mod=1e9+7;
const ll INF=1e13+7;
priority_queue<P,vector<P>,greater<P> >q;
int a[100];
int main()
{
    int n,p;
    scanf("%d%d",&n,&p);
    int cou1=0;
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        a[i]=a[i]%2;
        cou1+=a[i];
    }
    int cou2=n-cou1;
    ll sum2=1;
    for(int i=1; i<=cou2; i++) sum2*=2;
    ll sum1;
    int sign=cou1,x;
    ll ans=0;
    //cout<<cou1<<" "<<cou2<<" "<<sum2<<endl;
    for(p; p<=cou1; p+=2)
    {
        if(p==0)
        {
            //cout<<p<<" "<<1<<endl;
            sum1=1,x=0;
        }
        else if(p==1)
        {
            //cout<<p<<" "<<n<<endl;
            sum1=cou1,sign--,x=1;
        }
        else
        {
            sum1=sum1*(sign)*(sign-1)/((x+1)*(x+2));
            //cout<<p<<" "<<sum1*(sign)*(sign-1)/((x+1)*(x+2))<<endl;
            sign-=2,x+=2;
        }
        ans+=sum1*sum2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rep2(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rev(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define rev2(i, a, b) for (int (i) = (a) - 1; (i) >= (b); (i)--)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pll = pair<long long, long long>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
long long TEN(int i) {return !i ? 1 : TEN(i -  1) * 10LL;}
template<class T, class U> 
bool chmin(T& a, const U& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T, class U> 
bool chmax(T& a, const U& b) {if (a < b) {a = b; return 1;} return 0;}
 
struct IoSetup {
  	IoSetup() {
    	cin.tie(nullptr);
    	ios::sync_with_stdio(false);
    	cout << fixed << setprecision(15);
  	}
} iosetup;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

int N;
string S;

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

	int ans = TEN(9);

	V<int> sumB(N + 5, 0);
	V<int> sumW(N + 5, 0);

	rep2 (i, 1, N + 1) sumB[i] += sumB[i - 1] + (S[i - 1] == '#');
	rep2 (i, 1, N + 1) sumW[i] += sumW[i - 1] + (S[i - 1] == '.');

	rep (i, N + 1) {
		chmin(ans, sumB[i] + sumW[N] - sumW[i]);
	}

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

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

cnt = 0
alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q",
            "r","s","t","u","v","w","x","y","z"]
ans = []

for i in range(10):
    n_judge = (n-1)//(26**(i+1))
    if n_judge >= 1:
        cnt += 1
        n -= 26**(i+1)
    else:
        break

for j in range(cnt+1):
    n_ = (n-1)//26**(cnt-j)
    ans.append(alphabet[n_])
    n %= 26**(cnt-j)

ans = "".join(ans)
print(ans)


Measured memory_bytes: 9216
import java.io.*;
import java.util.StringTokenizer;
    
class Main{
    
static final PrintWriter out=new PrintWriter(System.out);
 
static class binarySearchTree{
 
static class Node{
int id;
Node p;
Node l;
Node r;
int deg;
Node(int id){
this.id=id; this.p=null; this.l=null; this.r=null; this.deg=0;
}
}
 
private static Node root;
 
binarySearchTree(){
root=null;
}
 
public static void insert(int v){
if(root==null) root=new Node(v);
else __insert(new Node(v));
}
 
private static void __insert(Node z){
Node x=root;
Node y=null;
while(x!=null){
y=x;
if(z.id<x.id) x=x.l;
else x=x.r;
}
z.p=y;
if(z.id<y.id) y.l=z;
else y.r=z;
y.deg++;
}
 
public static boolean find(int v){
Node x=root;
while(x!=null){
if(x.id==v) return true;
else if(x.id>v) x=x.l;
else x=x.r;
}
return false;
}
 
public static void print(){
inorder(root);
out.println();
preorder(root);
out.println();
}
 
private static void preorder(Node now){
if(now==null) return;
out.print(" "+now.id);
preorder(now.l);
preorder(now.r);
}
  
private static void inorder(Node now){
if(now==null) return;
inorder(now.l);
out.print(" "+now.id);
inorder(now.r);
}
  
private static void postorder(Node now){
if(now==null) return;
postorder(now.l);
postorder(now.r);
out.print(" "+now.id);
}
}
 
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
binarySearchTree tree=new binarySearchTree();
int num=Integer.parseInt(br.readLine());
for(int i=0;i<num;i++){
st=new StringTokenizer(br.readLine());
String command=st.nextToken();
int n;
if("insert".equals(command)){
n=Integer.parseInt(st.nextToken());
tree.insert(n);
}
else if("find".equals(command)) {
n=Integer.parseInt(st.nextToken());
out.println((tree.find(n))?"yes":"no");
}
else tree.print();
}
out.flush();
}
}



Measured memory_bytes: 113136
#include <iostream>
using namespace std;
int main()
{
    int S,h,m,s;
    cin >> S;

    h=S/3600;
    m=S%3600/60;
    s=S%3600%60;
    
    cout << h << ":" << m << ":" << s << "\n";
    return 0; 
}


Measured memory_bytes: 3104
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
s = input()
if s == 'ABC':
    print('ARC')
else:
    print('ABC')



Measured memory_bytes: 10320
#include <bits/stdc++.h>
//Fast io
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
//Class shorthands
#define ll long long
#define db long double
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
//Function Shorthands
#define fi first
#define se second
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair
#define po pop_back
#define eb emplace_back
//Code Shorthands
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
//Constants
#define hell 1000000007
#define PI acos(-1.0)
using namespace std;
ll min(ll a, ll b){
    if(a>b) return b;
    return a;
}
ll max(ll a, ll b){
    if(a>b) return a;
    return b;
}
ll abs(ll a, ll b){
    return max(a,b)-min(a,b);
}

void solve(){
    int n;
    cin>>n;
    ll a[n][2];
    rep(i,0,n) cin>>a[i][0]>>a[i][1];
    ll ans = 0;
    for(int i: {1,-1}){
        for(int j:{1,-1}){
            ll s = a[0][0]*i + a[0][1]*j;
            for(int k=1;k<n;k++){
                ans = max(a[k][0]*i + a[k][1]*j - s, ans);
                s = min(s, a[k][0]*i + a[k][1]*j);
            }
        }
    }
    cout<<ans;
}

int main(){
    io;
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 6768
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if((b + c) - a >= 0){
    cout << (b + c) - a;
    }else{
        cout << "0";
    }
    return 0;
}

Measured memory_bytes: 3660
#include <cstdio>
#include <cstdlib>
#include <cmath>

#include <iostream>

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

const ll mod = 1000000007;

class mint{
public:
  ll x;
  mint(ll x=0) : x(x%mod){}
  mint& operator+=(const mint rhs){
    x += rhs.x;
    while(x >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint rhs){
    x -= rhs.x;
    while(x < 0) x += mod;
    return *this;
  }
  mint & operator*=(const mint rhs){
    (x *= rhs.x) %= mod;
    return *this;
  }
  mint operator+(const mint rhs) const {
    mint res(*this);
    return res += rhs;
  }
  mint operator-(const mint rhs) const {
    mint res(*this);
    return res -= rhs;
  }
  mint operator*(const mint rhs) const {
    mint res(*this);
    return res *= rhs;
  }
  friend ostream& operator<<(ostream& os,const mint rhs){
    os << rhs.x;
    return os;
  }
};

#define rep(index,num) for(int index=0;index<num;++index)

const int V = 100005;
vector<int> to[V*2];
bool visited[V*2];
vector<int> cnt;

void dfs(int v){
  if(visited[v]) return;
  visited[v] = true;
  cnt[v/V]++;
  for(int u:to[v]) dfs(u);
}

int main(){
  int n;
  std::cin >> n;
  rep(i,n){
    int x,y;
    cin >> x >> y;
    y += V;
    to[x].push_back(y);
    to[y].push_back(x);
  }
  ll ans = 0;
  rep(i,V*2){
    if(visited[i]) continue;
    cnt = vector<int>(2);
    dfs(i);
    ans += (ll)cnt[0]*cnt[1];
  }
  ans -= n;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10240
#include<stdio.h>
#define LL long long
LL GCD(LL a,LL b)
{
    return b==0?a:GCD(b,a%b);
}
int main()
{
    LL a,b;
    while(scanf("%lld%lld",&a,&b)!=EOF)
    {
        LL c=GCD(a,b);
        printf("%lld %lld\n",c,a/c*b);
    }
    return 0;
}

Measured memory_bytes: 2572
#include <cstdio>
#include <string>
#include <map>

using namespace std;

int h, w;
char str[32][32];

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

void generate(int sy, int sx, map<string, int> &rec)
{
	char tmp[2] = {0, 0};
	
	for (int i = 0; i < 8; i++){
		tmp[0] = str[sy][sx];
		string s = tmp;
		int ny = sy, nx = sx;
		while (1){
			ny = (ny + h + dy[i]) % h; nx = (nx + w + dx[i]) % w;
			if (ny == sy && nx == sx) break;
			tmp[0] = str[ny][nx];
			s += tmp;
			if (rec.count(s) > 0) rec[s] += 1;
			else rec[s] = 1;
		}
	}
}

int main()
{
	while (scanf("%d %d", &h, &w) && h){
		for (int i = 0; i < h; i++) scanf("%s", str[i]);
		map<string, int> occ;
		
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				generate(i, j, occ);
			}
		}
		
		string ans = "";
		for (map<string, int>::iterator it = occ.begin(); it != occ.end(); it++){
			if (it->second > 1 && it->first.size() >= ans.size()){
				if (it->first.size() > ans.size()) ans = it->first;
				else if (it->first.size() == ans.size() && it->first < ans) ans = it->second;
			}
		}
		
		if (ans != "") printf("%s\n", ans.c_str());
		else printf("0\n");
	}
	return (0);
}

Measured memory_bytes: 35880
import java.util.*;

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


Measured memory_bytes: 23764
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
	public static void main(String[] args) { 
		/*EZ
		 * */
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int a = I.nextInt();
		int b = I.nextInt();
		int c = I.nextInt();
		int d = I.nextInt();
		O.pln((abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d))?"Yes":"No");
	}
	public static double max(double a, double b) {return Math.max(a, b);}
	public static double min(double a, double b) {return Math.min(a, b);}
	public static long min(long a, long b) {return Math.min(a,b);}
	public static long max(long a, long b) {return Math.max(a,b);}
	public static int min(int a, int b) {return Math.min(a,b);}
	public static int max(int a, int b) {return Math.max(a,b);}
	public static long abs(long x) {return Math.abs(x);}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return max(a,b);
		return GCD(min(a,b),max(a,b)%min(a,b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
		double nextDouble() {return Double.parseDouble(next());}
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
}


Measured memory_bytes: 25572
/**
 *  author: mahfuzz
 *  created: 14.04.2020
**/

#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define trace(x) cout << #x << ':' << x << "\n"
typedef long long ll;

int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    string s; cin >> s;
    for(auto a : s){
        if(a == '7'){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
        

    return 0;
}



Measured memory_bytes: 3568
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>

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

using namespace std;
typedef long long int ll;
const int INF = 100000000;

bool Judge(string s) {
    string reverse(s.rbegin(), s.rend());
    if (s == reverse) return true;
    else return false;
}

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

    int n = s.size();
    string s1 = s.substr(0, (n - 1) / 2);
    string s2 = s.substr((n + 1) / 2, (n - 1) / 2);
    if (Judge(s) && Judge(s1) && Judge(s2)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

//試してて御免

const int cm = 1 << 17;
char ci[cm];
int cn;
inline char getcha() { 
	if (!cn) { fread(ci, 1, cm, stdin); cn = cm; }
	cn--;
	return ci[cm - cn - 1];
}

inline int getint() {
	int A = getcha() - '0';
	char C = getcha();
	while (isdigit(C)) {
		A = A * 10 + C - '0';
		C = getcha();
	}
	return A;
}


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


	int N, X;
	N = getint();
	X = getint();

	int A = 0;
	ll kotae = 0;
	rep(i, N) {
		int B = getint();
		int k = max(A + B - X, 0);
		kotae += k;
		A = B - k;
	}
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 512
import std.stdio;
import std.algorithm;

const long INF = (1 << 31) - 1;
long dp[100][100];
long[100] a, b;
void main(){
	int n;
	readf("%d\n", &n);
	for (int i = 0; i < n; i++) {
		readf("%d %d\n", &a[i], &b[i]);
		dp[i][] = INF;
		dp[i][i] = 0;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n-i; j++) {
			for (int k = j; k < j+i; k++) {
				dp[j][j+i] = min(dp[j][j+i], dp[j][k]+dp[k+1][j+i]+a[j]*b[k]*a[k+1]*b[j+i]);
			}
		}
	}
	writeln(dp[0][n-1]);
}

Measured memory_bytes: 1080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define mod (1000000007)

int64_t n,a,b;

    int64_t power(int64_t a,int64_t b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
    int64_t comb(int64_t a,int64_t b)
    {
        if(a<0||b<0||a<b)return 0;
    	int64_t x=1,y=1;
    	for(int i=1;i<=b;i++)
    	{
    		x=x*(a-i+1)%mod;
    		y=y*i%mod;
    	}
    	return x*power(y,mod-2)%mod;
    }


void solve() 
{
    cin>>n>>a>>b;
    int64_t all=power(2,n);
    int64_t ans=(all-comb(n,0)-comb(n,a)-comb(n,b))%mod;
    cout<<(ans<0?ans+mod:ans)<<endl;
}

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

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>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll a,b,cnt[5]={0};
 rep(i,0,6){
  sc(a);cnt[a]++;
 }
// rep(i,1,5)cout<<i<<" "<<cnt[i]<<endl;
 rep(i,1,5){
  if(((i==1||i==4)&&cnt[i]!=1)||((i==2||i==3)&&cnt[i]!=2)){
   pN;return 0;
  }
 }
 pY;
return 0;}


Measured memory_bytes: 3596
#include <cstdio>
#include <string>
#include <utility>
#include <set>
#include <queue>
#include <algorithm>
using namespace std;
int nxt[200000], prv[200000];
bool OK[200000];
int main() {
	int N, M, Q;
	scanf("%d %d %d", &N, &M, &Q);
	for (int i = 0; i < N; i++) {
		nxt[i] = (i + 1) % N;
		prv[i] = (i - 1 + N) % N;
	}
	int cur = 0;
	for (int i = 0; i < M; i++) {
		int a;
		scanf("%d", &a);
		if (a & 1) {
			for (int j = 0; j < a; j++) {
				cur = prv[cur];
			}
		}
		else {
			for (int j = 0; j < a; j++) {
				cur = nxt[cur];
			}
		}
		nxt[prv[cur]] = nxt[cur];
		prv[nxt[cur]] = prv[cur];
		cur = nxt[cur];
	}
	OK[cur] = 1;
	int tmp = cur;
	for (cur = nxt[cur]; cur != tmp; cur = nxt[cur]) {
		OK[cur] = 1;
	}
	for (int i = 0; i < Q; i++) {
		int q;
		scanf("%d", &q);
		printf("%d\n", OK[q]);
	}
}

Measured memory_bytes: 2600
x,y=map(int,input().split())
if (2*x-y)%3!=0 or (x-2*y)%3!=0:
  print(0)
  exit()
a=(2*x-y)//3
b=(2*y-x)//3
if a<0 or b<0:
  print(0)
  exit()
mod=10**9+7
def comb(x,y):
    s=1
    t=1
    for i in range(1,y+1):
        s=s*(x-i+1)%mod
        t=t*(i)%mod
    return (s*pow(t,mod-2,mod))%mod
print(comb(a+b,min(a,b)))

Measured memory_bytes: 3064
#include<stdio.h>
   
main()
{
    int r,c;
    scanf("%d %d",&r,&c);
       
    int calc[r+1][c+1];
    calc[r][c]=0;
       
    int i,j;
       
    for(i=0;i<r;i++){
        calc[i][c]=0;
        for(j=0;j<c;j++){
            if(i==0){
                calc[r][j]=0;
            }
            scanf(" %d",&calc[i][j]);
        }
    }
       
    for(i=0;i<=r;i++){
        for(j=0;j<=c;j++){
            if(j!=0){
                printf(" ");
            }
               
            printf("%d",calc[i][j]);
               
            if(j==c){
                printf("\n");
            }
            if(j>=0 && j<=c-1){
                calc[i][c] += calc[i][j];
                if(i!=r){
                    calc[r][j] += calc[i][j];
                }
            }
        }
           
    }
    return 0;
}


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

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

	string s;

	int res = 0;

	cin >> s;

	for(int i=0;i<4;i++)
	{
		if(s[i]=='+')
		{
			res++;
		}
		else
		{
			res--;
		}
	}

	cout << res << '\n';
	
	return 0;	
}

Measured memory_bytes: 256
import sys


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


sys.setrecursionlimit(10 ** 9)


def main():
    S = input()
    K = int(input())
    last = ""
    a = 0
    A = set(list(S))
    if len(S) == 1:
        print(K // 2)
        return

    elif len(A) == 1:
        if len(S) % 2 == 1:
            a = K % 2
            print(len(S) * (K // 2) + (len(S) // 2) * a)
        else:
            a = K % 2
            print(len(S) * (K // 2) + (len(S) // 2) * a)
    else:
        for s in S:
            if s == last:
                a += 1
                last = ""
            else:
                last = s
        if S[0] != S[-1]:
            print(a * K)
        elif len(S) == 2:
            print(a * K)
        else:
            x = 0
            y = 0
            for i in range(len(S) // 2):
                if S[i] == S[0]:
                    x += 1
            for j in range(len(S) // 2):
                if S[len(S) - j - 1] == S[-1]:
                    y += 1

            if x % 2 == 1 and y % 2 == 1:
                b = 1
            else:
                b = 0

            print(a * K + b * (K - 1))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064