akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
typedef struct pair
  {
      long long used;
      long long flag;
   } pair;

long long gcd(long long a,long long b){
    if(a<b){
        long long tmp=a;
        a=b;
        b=tmp;
    }
    long long r=a%b;
    while(r){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}
int compare(const void *a,const void *b){
    if(*(long long *)a>*(long long *)b)return 1;
    return -1;
}
#define NUM 1000000
pair prime[NUM+5];
int main(int argv,char* argc[]){
    long long n;
    scanf("%lld",&n);
    long long a[n];
    for(long long i=0;i<n;i++){
        scanf("%lld",&a[i]);
        
    }
    long long sq_num = (long long)sqrt(NUM);
    

     for (long long i=0;i<=NUM+4;i++){
        prime[i].flag=1;
        prime[i].used=0;
    }
    
    prime[0].flag=0;
    prime[1].flag=1;
   
    for(long long i=2;i<=sq_num+3;i++){
        if (prime[i].flag==1){
            for(long long j=i;j*i<=NUM;j++){
                prime[i*j].flag=i;
            }
        }
    }
    prime[1].used=0;
    int flag=0;
    long long g=a[0];
    for(long long i=0;i<n;i++){
        if(prime[a[i]].flag>1){
            long long cpy=a[i];
            long long array[100]={0},z=0;
            while(prime[cpy].flag!=1){
                if(array[z]!=prime[cpy].flag){
                    array[z]=prime[cpy].flag;
                    z++;
                }
                cpy/=prime[cpy].flag;
            }
                array[z]=cpy;
                z++;
            qsort(array,z,sizeof(long long),compare);
            for(int j=0;j<z;j++){
                if(array[j]==array[j+1]){
                    continue;
                }
                prime[array[j]].used++;
            }
        }else{
            prime[a[i]].used++;
        }
        g=gcd(g,a[i]);
        //printf("%d\n",g);
    }
    if(g!=1){
        printf("not coprime");
        return 0;
    }
    for(int i=2;i<=1000000;i++){
        if(prime[i].used>1){
            flag=1;
        }
    }
    if(flag==1&&g==1){
        printf("setwise coprime");
        return 0;
    }
    printf("pairwise coprime");
    
    return 0;
}


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

int main() {
	int a, b, ans = 0;
	cin >> a >> b;
	if ( a < b ) swap(a, b);
	ans += a;
	a--;
	if ( a < b ) swap(a, b);
	ans += a;
	cout << ans;
}


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

int main(){
    int num[300000]={};
    for(int i=6;i<300000;i++){
        if(num[i]==1) continue;
        if(i%7==1 || i%7==6) for(int j=i+i;j<300000;j+=i)num[j]=1;
        else num[i]=1;
    }
    int N;
    while(1){
        cin>>N;
        int tmp=N;
        if(N==1) break;
        vector<int> ans;
        for(int i=6;i<300000;i++){
            if(num[i]==1) continue;
            if(N%i==0){
                ans.push_back(i);
            }
            if(N<i) break;
        }
        
        cout<<tmp<<": ";
        for(int i=0;i<ans.size();i++){
            cout<<ans[i];
            if(i!=ans.size()-1) cout<<" ";
        }
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 4320
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

// ?§?????????¨????????¨???????????????????¨???????????§???????
struct Edge {
    int from, to, cost;
    Edge(int s, int d) : to(s), cost(d) {}
    Edge(int f, int s, int d) : from(f), to(s), cost(d) {}

    bool operator<(const Edge &e) const {
        return cost < e.cost;
    }
    bool operator>(const Edge &e) const {
        return cost > e.cost;
    }
};

// 1??????????????????????????????????????±????????????????????????????????? vector
// Edges????????????????????????????????????????????°??????????????????
typedef vector<Edge> Edges;

// ???????????±??????????????? vector
// Graph??????????????????????????°?????????????????§??? V ??§?????????
typedef vector<Edges> Graph;

void getDeepest(pii &n, Graph &G, int p, int prev, int cost) {
    int ok = true;
    for(auto x : G[p]) {
        if(x.to != prev) {
            ok = false;
            getDeepest(n, G, x.to, p, cost+x.cost);
        }
    }
    if(ok && n.sc < cost) {
        n.fr = p;
        n.sc = cost;
    }
}

signed main() {
    int n, s, t, w; cin >> n;
    Graph G(n);
    rep(i,0,n-1) {
        cin >> s >> t >> w;
        G[s].pb(Edge(t, w));
        G[t].pb(Edge(s, w));
    }

    pii p = pii(0, 0), r = pii(0, 0);
    getDeepest(p, G, 0, -1, 0);
    getDeepest(r, G, p.fr, -1, 0);
    cout << r.sc << endl;
    return 0;
}

Measured memory_bytes: 19040
#include <iostream>
#include <set>

using namespace std;

int a, b, c;

int main(void)
{
	cin >> a >> b >> c;
	
	set<int> s;
	s.insert(a);
	s.insert(b);
	s.insert(c);
	
	cout << s.size() << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    if(s.size()<t.size()){
        for(int i=0;i<s.size();i++){
            if(s.at(i)<t.at(i)){
                cout<<"Yes"<<endl;
                return 0;
            }
            else if(s.at(i)>t.at(i)){
                cout<<"No"<<endl;
                return 0;
            }
            if(i==s.size()-1){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    for(int i=0;i<t.size();i++){
        if(s.at(i)<t.at(i)){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
     cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
  int n, x, y;
  int min_ans;
  
  cin >> n >> x >> y;
  
  if(x + y - n >= 0) min_ans = x + y - n;
  else min_ans = 0;
  
  cout << min(x, y) << " " << min_ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
DATA = """
141421 35623
""".split("\n")

def get_debug_line():
	for i in DATA:
		yield i

if 1:
	get_line = input
else:
	get_line = get_debug_line().__next__
	get_line()

MOD = 10**9 + 7

N, M = [int(i) for i in get_line().strip().split(" ")]

minV = (0 + M-1) * M // 2
maxV = (N-M+1 + N) * M // 2
#print (minV, maxV)
#0, 1, 2, 3
count = 0
for i in range(M, N+2):
    count += (maxV - minV + 1)
    #print (i, N+1, minV, maxV)
    minV += i
    maxV += (N-i)
print (count%MOD)


Measured memory_bytes: 9188
def bfs(k):
    flag=[-1]*(n+1)
    que=[k]
    flag[k]=0
    cnt=1
    while que:
        h=[]
        for uu in que:
            for vv in data[uu]:
                if flag[vv]==-1:
                    flag[vv]=cnt
                    h.append(vv)
        que=h
        cnt+=1
    return flag

n,u,v=map(int,input().split())
data=[[] for i in range(n+1)]
for _ in range(n-1):
    a,b=map(int,input().split())
    data[a].append(b)
    data[b].append(a)
T=bfs(u)
A=bfs(v)
ans=0
for i in range(1,n+1):
    if T[i]<A[i]:
        ans=max(ans,A[i]-1)
print(ans)

Measured memory_bytes: 65260
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define wuyt main
typedef long long ll;
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
//#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
if(c == '-')Nig = -1,c = getchar();
while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
return Nig*x;}
#define read read()
const ll inf = 1e15;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
#define start int wuyt()
#define end return 0
start{
    int num[4];
    cin>>num[1]>>num[2]>>num[3];
    sort(num+1,num+4);
    cout<<num[3]*10+num[2]+num[1]<<endl;
	end;
}


Measured memory_bytes: 256
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + end + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw "ArrayIndexOutOfBoundsException ‚There is no more input";}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var list = getDivisorList(N);
  if(list.length % 2 == 1){
    myout((list[Math.floor(list.length / 2)] - 1) * 2);
  }else{
    myout(list[(list.length / 2) - 1] + list[(list.length / 2)] - 2);
  }
}
function getDivisorList(val){
  var list = [];
  for(var i = 1; i * i <= val; i++){
    if(val % i == 0){
      list.push(i);
      if(i * i != val){
        list.push(val / i);
      }
    }
  }
  list.sort(function(a,b){ return a - b; });
  return list;
}

Measured memory_bytes: 35072
#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define vii vector<int>
#define vll vector<long long int>
#define sii set<int>
#define sll set<long long int>
#define usi unordered_set<int, custom_hash>
#define usl unordered_set<long long int, custom_hash>
#define mii map<int, int>
#define mll map<long long int, long long int>
#define umi unordered_map<int, int, custom_hash>
#define uml unordered_map<long long int, long long int, custom_hash>
#define ski stack<int>
#define skl stack<long long int>
#define all(v) v.begin(),v.end()
using namespace std;
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);
    }
};


const int N=2e5+1;
const int mod=998244353;
ll a[N], b[N], c[N];


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif
    
    int n;
    cin>>n;
    ll x=0, y=0, z=0, xx, yy, zz;
    for(int i=0;i<n;++i){
        cin>>xx>>yy>>zz;
        ll tx=x, ty=y, tz=z;
        x=xx+max(ty, tz);
        y=yy+max(tz, tx);
        z=zz+max(tx, ty);
    }
    
    cout<<max(x, max(y, z))<<endl;

}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int h = Integer.parseInt(scan.next());
        int w = Integer.parseInt(scan.next());
        int k = Integer.parseInt(scan.next());
        int[][] c = new int[h][w];
        for (int i = 0; i < h; i++) {
            String[] s = scan.next().split("");
            for (int j = 0; j < w; j++) {
                if (s[j].equals(".")) {
                    c[i][j] = 0;
                } else {
                    c[i][j] = 1;
                }
            }
        }
        scan.close();

        long ans = 0;
        for (int i = 0; i < (1 << h); i++) {
            Set<Integer> iSet = new HashSet<Integer>();
            for (int a = 0; a < h; a++) {
                if ((i & (1 << a)) != 0) {
                    iSet.add(a);
                }
            }

            for (int j = 0; j < (1 << w); j++) {
                Set<Integer> jSet = new HashSet<Integer>();
                for (int a = 0; a < w; a++) {
                    if ((j & (1 << a)) != 0) {
                        jSet.add(a);
                    }
                }

                int black = 0;
                for (int a = 0; a < h; a++) {
                    if (iSet.contains(a)) {
                        continue;
                    }
                    for (int b = 0; b < w; b++) {
                        if (jSet.contains(b)) {
                            continue;
                        }
                        black += c[a][b];
                    }
                }

                if (black == k) {
                    ans++;
                }
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 39336
"""#################################################################
【ABC091】
B - Two Colors Card Game
#################################################################"""

#インポート
import sys

#入力用
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))  #リスト(int型)
def MI(): return map(int, sys.stdin.readline().rstrip().split())        #多変数(int型)
def II(): return int(sys.stdin.readline().rstrip())                     # 1変数(int型)
def S(): return sys.stdin.readline().rstrip()                           #文字列(str型)

N = II()
s = [S() for _ in range(N)]
M = II()
t = [S() for _ in range(M)]
max = 0
for x in set(s):
    a = s.count(x)
    b = t.count(x)
    if max < a - b:
        max = a - b
print(max)


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

n = int(input())
an = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]

ls = [0 for _ in range(10**5 + 1)]
ans = 0
for a in an:
  ls[a] += 1
  ans += a
for b, c in bc:
  x = ls[b]
  ls[c] += x
  ls[b] = 0
  ans = ans - x * b + x * c
  print(ans)
  


Measured memory_bytes: 31956
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <regex>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

char next(char a) {
    if (a == 'z') return 'a';
    return char(a + 1);
}

int toa(char a) {
    return 'z' - a + 1;
}

int main() {
    string s;
    long k;
    cin >> s >> k;
    
    if (k > 26 * s.size()) {
        REP(i,s.size() - 1) {
            if (s[i] == 'a') continue;
            k -= toa(s[i]);
            s[i] = 'a';
        }
        k %= 26;
        REP(i,k) {
            s[s.size() - 1] = next(s.back());
        }
        cout << s << endl;
        return 0;
    }
    REP(i,s.size() - 1) {
        if (s[i] == 'a') continue;
        if (k - toa(s[i]) >= 0) {
            k -= toa(s[i]);
            s[i] = 'a';
        }
    }
    REP(i,k) {
        s[s.size() - 1] = next(s.back());
    }
    cout << s << endl;
}


Measured memory_bytes: 512
#include<stdio.h>
int main(){
  int a , b , c , d;
  scanf("%d %d %d %d", &a , &b , &c ,&d);
  long long ac , ad , bc , bd;
  ac = (long long)a * (long long)c;
  ad = (long long)a * (long long)d;
  bc = (long long)b * (long long)c;
  bd = (long long)b * (long long)d;
  long long max = ac;
  if(max < ad)
    max = ad;
  if(max < bc)
    max = bc;
  if(max < bd)
    max = bd;
  printf("%lld\n",max);
  return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

ll d[13][100001]={};

int main() {
	string s;
	cin>>s;
	int n;
	n=s.size();
	if(s[0]=='0')d[0][0]=1;
	if(s[0]=='1')d[1][0]=1;
	if(s[0]=='2')d[2][0]=1;
	if(s[0]=='3')d[3][0]=1;
	if(s[0]=='4')d[4][0]=1;
	if(s[0]=='5')d[5][0]=1;
	if(s[0]=='6')d[6][0]=1;
	if(s[0]=='7')d[7][0]=1;
	if(s[0]=='8')d[8][0]=1;
	if(s[0]=='9')d[9][0]=1;
	if(s[0]=='?'){
		rep(i,10)d[i][0]=1;
	}

	rep(i,n-1){
		int d2=0;
		if(s[i+1]=='0')d2=0;
		if(s[i+1]=='1')d2=1;
		if(s[i+1]=='2')d2=2;
		if(s[i+1]=='3')d2=3;
		if(s[i+1]=='4')d2=4;
		if(s[i+1]=='5')d2=5;
		if(s[i+1]=='6')d2=6;
		if(s[i+1]=='7')d2=7;
		if(s[i+1]=='8')d2=8;
		if(s[i+1]=='9')d2=9;
		if(s[i+1]=='?'){
			rep(j,13){
				rep(k,10){
					int j2=(j*10+k)%13;
					d[j2][i+1]+=d[j][i];
				}
			}
		}else{
			rep(j,13){
				int j2=(j*10+d2)%13;
				d[j2][i+1]+=d[j][i];
			}
		}
		
		rep(j,13)d[j][i+1]%=1000000007;
	}
	cout<<d[5][n-1]<<endl;
	return 0;
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  vector< vector<int> > a(h, vector<int>(w));
  for (auto&& v : a) {
    for (auto&& e : v) {
      cin >> e;
    }
  }
  vector< vector<int> > b(h, vector<int>(w));
  for (auto&& v : b) {
    for (auto&& e : v) {
      cin >> e;
    }
  }
  vector< vector< bitset<20000> > > dp(h, vector< bitset<20000> >(w));
  dp[0][0][10000 + a[0][0] - b[0][0]] = 1;
  dp[0][0][10000 + b[0][0] - a[0][0]] = 1;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (i + 1 < h) {
        int d = abs(a[i + 1][j] - b[i + 1][j]);
        dp[i + 1][j] |= dp[i][j] << d;
        dp[i + 1][j] |= dp[i][j] >> d;
      }
      if (j + 1 < w) {
        int d = abs(a[i][j + 1] - b[i][j + 1]);
        dp[i][j + 1] |= dp[i][j] << d;
        dp[i][j + 1] |= dp[i][j] >> d;
      }
    }
  }
  for (int x = 0; ; ++x) {
    if (dp.back().back()[10000 + x] or dp.back().back()[10000 - x]) {
      cout << x << '\n';
      return 0;
    }
  }
}


Measured memory_bytes: 16256
program sample
    implicit none
    character(10)::s,ans
    integer(8) :: i,j,m,n
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) s
    n=len_trim(s)
    ans=''
    m=0
    do i=1,n
        if(s(i:i) .eq. '0')then
            ans=ans(1:m)//'0'
            m=m+1
        elseif(s(i:i) .eq. '1')then
            ans=ans(1:m)//'1'
            m=m+1
        else
            m=m-1
            if(m<=0)then
                m=0
                ans=''
            else
                ans=ans(1:m)
            end if
        endif
    end do
            

  
    write(*,*) ans
  
    stop
end program sample
  



Measured memory_bytes: 2796
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	immutable MAX = 1000000;

	bool p[MAX];
	p[] = 1;
	p[0..1] = 0;
	foreach (i; 2..sqrt(MAX*1.0).ceil.to!int) {
		if (p[i]) {
			foreach (j; iota(i*2, MAX, i))
				p[j] = 0;
		}
	}

	foreach (line; stdin.byLine) {
		auto n = line.chomp.to!int;
		foreach_reverse (i; 2..n) {
			if (p[i]) {
				write(i, " ");
				break;
			}
		}
		foreach (i; n+1..MAX) {
			if (p[i]) {
				writeln(i);
				break;
			}
		}
	}
}

Measured memory_bytes: 2040
#include<iostream>
using namespace std;
int main() {
	int a, b, s, f, N, ans;
	cin >> a >> b;
	cin >> N;
	ans = 0;
	for (int i = 1; i <= N; i++) {
		cin >> s >> f;
		if (s <= a && a < f || s < b&&b <= f || a <= s && b >= f) {
			ans = 1;

		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3112
N = int(input())
B = list(map(int,input().split()))
A = [0]*(N+1)
A[0] = B[0]
A[N-1] = B[-1]

for i in range(N-2) :
    A[i+1] = min(B[i],B[i+1])

print(sum(A))



Measured memory_bytes: 3060
import java.util.*;

public class Main{
	public static void main(String args[]){
    	
      Scanner scan = new Scanner(System.in);
      int N = scan.nextInt();
      int K = scan.nextInt();
      double M = K/2;
      int sum = 0;
      for(int i=0;i<N;i++){
      	int a = scan.nextInt(); 
   		if(a > M){
        	sum = sum + 2 * (K - a);
        }else{
          	sum = sum + 2 * a;
        }   	
      }
      System.out.println(sum);
    }
}

Measured memory_bytes: 35660
n,h = map(int,input().split())
A = []
B = []
for i in range(n):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
A.sort(reverse=True)
B.sort(reverse=True)
B = [ i for i in B if i > A[0] ]
ans = 0
for i in B:
    ans += 1
    h -= i
    if h <= 0:
        break
if h > 0:
    if h % A[0] == 0:
        ans += (h // A[0])
    else:
        ans += (h // A[0]) + 1
print(ans)


Measured memory_bytes: 17780
// #include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,x,n) for(int i=x;i<n;i++)
#define breps(i,x,n) for(int i=x;i>=n;i--)
#define exrep(x,vec) for(auto&& x : vec);
#define PI 3.14159265358979323846264338327950288
const int MOD{ int(1e9 + 7) };	// = 1000000007
const int inf{ 2100000000 };	// = 2100000000 (MAX:2147483647)
typedef long long ll;
using namespace std;

/**
* ------------- ここからコード -------------
*/

ll ANS = -1, KK = -1, cnt = 0;
set<ll> s;
void modmod(ll x) {
	if (x % KK == 0) {
		ANS = cnt + 1;
		return;
	}
	
	x = x % KK;
	s.insert(x);
	cnt++;
	if (s.size() != cnt) return;
	
	modmod(x * 10 + 7);
}

int main(void) {

	ll K; cin >> K;
	ll ans = 0;

	KK = K;
	modmod(7);
	ans = ANS;

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


Measured memory_bytes: 81664
import bisect

A,B,Q = list(map(int,input().split()))
INF = 10 ** 18
shrine_list = [-INF] + [int(input()) for _ in range(A)] + [INF]
temple_list = [-INF] + [int(input()) for _ in range(B)] + [INF]
question_list = [int(input()) for _ in range(Q)]
for i in range(Q):
    x = question_list[i]
    index_s = bisect.bisect_right(shrine_list,x)
    index_t = bisect.bisect_right(temple_list,x)
    most_east_shrine = shrine_list[index_s - 1]
    most_east_temple = temple_list[index_t - 1]
    most_west_shrine = shrine_list[index_s]
    most_west_temple = temple_list[index_t]
    likelyhood_list = []
    likelyhood_list.append(abs(x - most_east_shrine) + abs(most_east_shrine - most_east_temple))
    likelyhood_list.append(abs(x - most_east_temple) + abs(most_east_shrine - most_east_temple))
    likelyhood_list.append(abs(x - most_east_shrine) + abs(most_east_shrine - most_west_temple))
    likelyhood_list.append(abs(x - most_west_temple) + abs(most_east_shrine - most_west_temple))
    likelyhood_list.append(abs(x - most_west_shrine) + abs(most_west_shrine - most_east_temple))
    likelyhood_list.append(abs(x - most_east_temple) + abs(most_west_shrine - most_east_temple))
    likelyhood_list.append(abs(x - most_west_shrine) + abs(most_west_shrine - most_west_temple))
    likelyhood_list.append(abs(x - most_west_temple) + abs(most_west_shrine - most_west_temple))
    print(min(likelyhood_list))


Measured memory_bytes: 17292
N, M = map(int, input().split())
G = [[] for _ in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

for i in range(N):
    print(len(G[i]))



Measured memory_bytes: 3064
require 'set'

n, m, tax = gets.strip.split.map(&:to_i)
abc = readlines.map {|line| line.strip.split.map(&:to_i) }
abc = abc.map {|a, b, c| [a, b, -1*(c-tax)] }

# get adjuscent list
graph = Array.new(n+1) { [] }
r_graph = Array.new(n+1) { [] }
abc.each do |a, b, c|
  graph[a] << b
  r_graph[b] << a
end

# build from_1 from_n
def reachable(s, g)
  q=[s]
  visited = Set.new(q)
  until q.empty?
    from = q.shift
#    next if visited.include?(from)
    visited.add(from)
    g[from].each do |to|
      next if visited.include?(to)
      visited.add(to)
      q.push(to)
    end
  end

  visited
end

from_1 = reachable(1, graph)
from_n = reachable(n, r_graph)
av = from_1 & from_n
edges=abc.select {|a, b, c| av.include?(a) && av.include?(b) }

#p av
#p edges

# b-f method
updated = false
INF= 10**12
dist = Array.new(n+1, INF)
dist[1]=0
n.times do
  updated = false
  edges.each do |a, b, c|
    next if dist[a]==INF || dist[b] <= dist[a] + c

    dist[b] = dist[a] + c
    updated = true
  end
  break unless updated
end

if updated
  p -1
  exit
end

# answer
p [0, -dist[n]].max




Measured memory_bytes: 5500
from functools import reduce
from fractions import gcd

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers)
mod = 10**9 + 7
n = int(input())
As = list(map(int, input().split()))

lcm = lcm_list(As)
b = [lcm//As[i] for i in range(n)]

print(sum(b) % mod)

Measured memory_bytes: 264668
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int N;
vector<double> score;

bool input() {
  cin >>N;
  if (N == 0) return false;
  score.assign(N, 0);
  rep(i, N) cin >>score[i];
  return true;
}

void solve(){
  double sum = 0, sum2 = 0;
  // 二乗の平均引く平均の二乗
  rep(i, N){
    sum += score[i];
    sum2 += score[i] * score[i];
  }
  sum2 /= N;
  sum /= N;
  double res = sqrt(sum2 - sum*sum);
  cout <<fixed <<setprecision(12) <<res <<endl;
}

int main() {
  while (input()) solve();
}


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

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

  int kaisu = 0;
  int ans = 1;
  for (int num=1; num<N+1; num++) {
    int tmp = num;
    int a = 0;
    while (1) {
      if (tmp%2 == 0) {
        tmp /= 2;
        a++;
      }
      else break;
    }
    if (kaisu < a) {
      kaisu = a;
      ans = num;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
use List::Util 'min';

while(<>){
	chomp;
	$n = $_ if($. == 1);
	@a = split(/ /, $_) if($. == 2);
}
unshift(@a, "0");

$r = 0;
for $i (1 .. $n){
	if($i == 1){
		$r += $a[$i];
	}elsif($i == $n){
		$r += $a[$i - 1];
	}else{
		$r += min($a[$i], $a[$i - 1]);
	}
}

printf "$r\n";


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();
			String chr[] = in.split(" ");

			 System.out.println(chr[1]+chr[0]);
		}
	}
}

Measured memory_bytes: 25280
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int l, a, b, c, d;
    l = sc.nextInt(); a = sc.nextInt(); b = sc.nextInt();
    c = sc.nextInt(); d = sc.nextInt();
    if(a % c == 0)a /= c;
    else a = a / c + 1;
    if(b % d == 0)b /= d;
    else b = b / d + 1;
    if(a > b)b = a;
    out.println(l - b);

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 26260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f;
typedef vector<ll> vll;
typedef pair<ll, ll> Pll;

const int MAXN = 100000 + 10;

ll N, W;

int main() {
    cin >> N >> W;
    vll weight(N + 1);
    vll value(N + 1);
    for (int i = 1; i <= N; ++i) {
        cin >> weight[i] >> value[i];
    }
    vector<vector<ll>> dp(N + 1, vector<ll>(W + 1));
    for (int i = 1; i <= N; ++i) {
        for (int j = 0; j <= W; ++j) {
            if (j < weight[i]) {
                dp[i][j] = dp[i - 1][j];
            } else {
                dp[i][j] = max(dp[i - 1][j - weight[i]] + value[i], dp[i - 1][j]);
            }
        }
    }
    cout << dp[N][W] << endl;
    return 0;
}

Measured memory_bytes: 80256
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
#define dump(a) cout << (a) << endl;
typedef long long ll;
ll mod = 1e9+7;
ll MOD = 998244353;

ll n, a, b;
ll h[100005];

bool enough(ll x) {
    ll cnt = 0;
    for (int i = 0; i < n; i++) {
        //h[i] -= b*x;
        if (h[i]-b*x > 0) {
            cnt += (h[i]-b*x) / (a-b);
            if ((h[i]-b*x) % (a-b) != 0) cnt++;
        }
    }

    //if (x == 4) dump(cnt);
    return cnt <= x;
}

int main() {
    cin >> n >> a >> b;
    for (int i = 0; i < n; i++) cin >> h[i];
    sort(h, h+n);
    ll l = -1;
    ll r = h[n-1] / b;
    if (h[n-1] % b != 0) r++;
    while (abs(r-l) > 1) {
        ll m = (l+r)/2;
        if (enough(m)) {
            r = m;
        }
        else {
            l = m;
        }
    }
    dump(r);
    return 0;  
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val p = (1..n).map { val a = (readLine()!!.split(" ").map { it.toInt() }); Point(it-1, a[0], a[1]) }

    val xy = Array(100001) { mutableListOf<Int>() }
    val yx = Array(100001) { mutableListOf<Int>() }
    val uf = UnionFind(n)
    p.forEach {
        xy[it.x].add(it.id)
        yx[it.y].add(it.id)
    }

    xy.filter { it.size>=2 }.forEach { it.reduce{ a,b -> uf.unite(a,b); b } }
    yx.filter { it.size>=2 }.forEach { it.reduce{ a,b -> uf.unite(a,b); b } }

    val sum = p.groupBy { uf.find(it.id) }.map { it.value }.map {
        val x = it.distinctBy { it.x }.size
        val y = it.distinctBy { it.y }.size
        1L *x * y
    }.sum()

    println(sum-n)

}

data class Point(val id: Int, val x: Int, val y: Int) 

class UnionFind(N: Int) {
    private val parent = IntArray(N) { it }
    val roots = (0..N-1).toList().toMutableSet()
    private val rank = IntArray(N) { 0 }
    private val size = IntArray(N) { 1 }
    private var numTree = N

    fun size() = numTree
    fun find(x: Int): Int = if (parent[x] == x) x else { parent[x] = find(parent[x]); parent[x] }

    fun same(x: Int, y: Int) = find(x) == find(y)
    fun sizeOf(x: Int) = size[find(x)]
    fun unite(x: Int, y: Int) {
        val rx = find(x)
        val ry = find(y)
        if (rx == ry) return else numTree--

        if (rank[rx] < rank[ry]) {
            parent[rx] = ry
            roots.remove(rx)
            size[ry] += size[rx]
        } else {
            parent[ry] = rx
            roots.remove(ry)
            size[rx] += size[ry]
            if (rank[rx] == rank[ry]) rank[rx]++
        }
    }
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int ans = 0, N;
int V[100], C[100];
void solve(int i, int sum) {
    if (i >= N) {
        ans = max(ans, sum);
        return;
    }
    solve(i + 1, sum + V[i] - C[i]);
    solve(i + 1, sum);
    return;
};

int main() {
    cin >> N;
    rep(i, N) cin >> V[i];
    rep(i, N) cin >> C[i];

    solve(0, 0);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std ;

int main(){
	string s ; cin >> s ;
	long long ans = 0 ;
	int cnt = 0 ;
	int n = s.size() ;
	reverse(s.begin(),s.end()) ;
	for(int i=0;i<n;i++){
		if(s.at(i)=='B'){
			ans += cnt ;
		}else{
		    cnt++ ;
		}
	}
	cout << ans << endl ;
}



Measured memory_bytes: 640
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

const int MAX_N = 200050;
int N, Q;
long long S[MAX_N], T[MAX_N], X[MAX_N];
long long D[MAX_N];
long long ret[MAX_N];

std::set<long long> st;
std::unordered_map<long long, int> mp;

int main(int argc, char **argv) {
    std::cin >> N >> Q;

    for (int i = 1; i <= N; i++) {
        std::cin >> S[i] >> T[i] >> X[i];
    }

    for (int i = 1; i <= Q; i++) {
        std::cin >> D[i];
    }

    for (int i = 1; i <= Q; i++) {
        st.insert(D[i]);
        mp[D[i]] = i;
        ret[i] = -1;
    }

    std::vector<int> vec;
    for (int i = 1; i <= N; i++) {
        vec.push_back(i);
    }

    std::sort(vec.begin(), vec.end(),
        [](const int a, const int b) { return X[a] < X[b]; }
    );

    for (int i : vec) {
        long long begin = S[i] - X[i];
        long long end = T[i] - X[i] - 1;
        std::vector<long long> del;
        for (auto itr = st.lower_bound(begin); itr != st.upper_bound(end); ++itr) {
            del.push_back(*itr);
        }
        //std::cout << "check:" << i << " " << begin << " " << end << " " << X[i] << std::endl; 
        for (long long d : del) {
            //std::cout << d << " " << mp[d] << std::endl;
            ret[mp[d]] = X[i];
            st.erase(d);
        }
        //std::cout << std::endl;
    }

    for (int i = 1; i <= Q; i++) {
        std::cout << ret[i] << std::endl;
    }

    return 0;
}

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

typedef long long ll;
const int INF = 1e8;
// const ll INF = 1LL << 60;
typedef pair<int, int> P;

ll N;
vector<ll> A;
int main() {
    cin >> N;

    A.resize(N);
    rep(i, N) cin >> A[i];

    map<ll, ll> mp;;
    rep(i, N) {
        mp[A[i]]++;
    }
    map<ll, ll> comb;
    ll sum_ans = 0;
    for (auto iter = mp.begin(); iter != mp.end(); iter++) {
        // cout << iter->first << " " << iter->second << endl; 
        if (iter->second >= 2) {
            comb[iter->first] = iter->second * (iter->second - 1) / 2;
            sum_ans += comb[iter->first];
        } 
    }

    for (int i = 0; i < N; i++) {
        ll tmp = sum_ans;
        // cout << tmp << endl;
        // 計算ずみのを引く
        ll target = comb[A[i]];
        tmp -= target;
        ll num = mp[A[i]];
        num--;
        if (num >= 2) {
            tmp += num * (num - 1) / 2;
        }

        // 1こ減らして計算し直す 
        cout << tmp << endl;
    }
}

Measured memory_bytes: 18944
#include<bits/stdc++.h>
	#include<ext/pb_ds/assoc_container.hpp>
	#include<ext/pb_ds/tree_policy.hpp>
	#define pi 3.141592653589793238
	#define int long long
	using namespace __gnu_pbds;
	using namespace std;
	template <typename T>
	using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

	map<int,int>dis;

	map<int,vector<pair<int,int> > >mm;
	void bfs(int ver)
	{
		priority_queue<pair<int,int> ,vector<pair<int,int> >,greater<pair<int,int>> >qq;
		qq.push({0,ver});
		while (!qq.empty())
		{
			pair<int,int>pp=qq.top();
			qq.pop();
			for(auto i:mm[pp.second])
			{
				if(dis[i.first]>pp.first+i.second)
				{
					dis[i.first]=pp.first+i.second;
					qq.push({dis[i.first],i.first});
				}
			}
		}	
	}

	signed main()
	{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);  
	cout.tie(0);   

	#ifndef ONLINE_JUDGE
		if(fopen("INPUT.txt","r"))
		{
		freopen ("INPUT.txt" , "r" , stdin);
		freopen ("OUTPUT.txt" , "w" , stdout);
		}
	#endif  

		int x,y;
		cin>>x>>y;
		mm[x].push_back({-x,1});
		mm[-x].push_back({x,1});
		mm[y].push_back({-y,1});
		mm[-y].push_back({y,1});
		int arr[4];
		arr[0]=x;
		arr[1]=-x;
		arr[2]=-y;
		arr[3]=y;
		for(int i=0;i<4;i++)
		{
			dis[arr[i]]=1e17;
			for(int j=0;j<4;j++)
			{
				if(arr[j]>arr[i])
					mm[arr[i]].push_back({arr[j],arr[j]-arr[i]});
			}
		}
		dis[x]=0;
		bfs(x);
		cout<<dis[y];

	}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll a[20001];
ll b[20001];
int p[20001];
int diff[20001];
vector<int> G[20001];
vector<int> vs;
bool used[20001];

void dfs(int v){
	used[v]=true;
	for(int i=0;i<n;i++){
		if(!used[G[v][i]]){
			dfs(G[v][i]);
		}
	}
	vs.push_back(v);
}

int num[20001];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&p[i]);
		p[i]--;
		num[p[i]]=i+1;
	}
	for(int i=0;i<n;i++){
		a[i]=(ll)i*n+1;
		b[i]=(ll)n*(n-i)+num[i];
	}
	for(int i=0;i<n;i++){
		printf("%lld%c",a[i],i==n-1?'\n':' ');
	}
	for(int i=0;i<n;i++){
		printf("%lld%c",b[i],i==n-1?'\n':' ');
	}
	return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<string.h>
#include<queue>
using namespace std;
typedef pair<int,int>P;

int main(){
    int a,b;cin>>a>>b;
    cout<<max(max(a+b,a-b),a*b)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef tree<int,null_type,less<int >,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v);
#ifndef ONLINE_JUDGE
#define debug(a) cout<<#a<<" --> "<<(a)<<"\n";
#define debug2(a) cout<<#a<<" --> "<<(a)<<" ";
#define HERE cout<<"here - "<<__LINE__<<"\n";
#else
#define debug(a)
#define debug2(a)
#define HERE
#endif
const ll mod = 998244353  ;
const int N = 1e5+5;

void TEST_CASES(int cas)
{
    string s;
    cin>>s;
    string t;
    for(int i=0;i<3;i++)
        t+=s[i];
    cout<<t<<endl;
}


/*

*/

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t=1,cas=0;
    //scanf("%d",&t);
    while(t--)
    {
        TEST_CASES(++cas);
    }

    return 0;
}



//os.order_of_key(v): returns how many elements strictly less than v
//os.find_by_order()

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v)
{
    for(auto i:v)
    {
        os<<"Key : "<<i.first<<" , Value : "<<i.second<<endl;
    }
    return os;
}


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

using namespace std;

#define vi vector<int>
#define pb push_back
#define lli long long int
#define INF 100000001
#define all(c) (c.begin(),c.end())
#define sz(x) c.size()


void solve() {
	int n;
	cin >> n;
	string s;
	int ac = 0, tle = 0, we = 0, re = 0;
	while (n--) {
		cin >> s;
		if (s == "AC")ac++;
		else if (s == "TLE")tle++;
		else if (s == "WA")we++;
		else re++;
	}
	cout << "AC x " << ac << endl;
	cout << "WA x " << we << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;
}

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

#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);

	freopen("output.txt", "w", stdout);
#endif
	// int t; cin >> t;
	// while (t--) {
	solve();

	// }



	return 0;

}

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

int main(){
	int x, y;
	cin >> x >> y;
	if (x < y) {
		int dum = x;
		x = y;
		y = dum;
	}
	int div;
	while(1){
		div = x % y;
		if (div == 0) break;
		x = y;
		y = div;
	}
	cout << y << endl;
}


Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値

int main() {
    // input
    ll N;
    cin >> N;
    string ans = "";
    
    // calculation
    while(N != 0) {
        if (N%2 != 0) {
            --N;
            ans = "1" + ans;
        } else {
            ans = "0" + ans;
        }
        N /= -2;
    }
    if (ans == "") ans = "0";
    
    cout << ans << "\n";
    
    return 0;
}

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

num = int(input())
val_list = [int(i) for i in input().split()]

val_list.sort()

init_1 = val_list.pop(0)
init_2 = val_list.pop(0)

rtn = (init_1 + init_2)/2

for i in val_list:
  rtn = (rtn + i)/2

print(rtn)

Measured memory_bytes: 3060
def main(k, s):
    if k == n:
        return sum(d * (s[b] - s[a] == c) for a, b, c, d in abcd)
    return max(main(k + 1, s + [ai]) for ai in range(s[-1], m + 1))

if __name__ == '__main__':
    n, m, q = map(int, input().split())
    abcd = [[int(i) for i in input().split()] for _ in range(q)]
    print(main(0, [1]))

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

char s[200010];
int main()
{
	cin >> s;
	int start=-1, end=-1;
	bool flag = false;
	int len = strlen(s);
	for(int i = 0;i < len;i++)
	{
		if(s[i] == 'C' && flag != true)
		{
			start = i;
			flag = true;
		}
		if(s[i] == 'F')
		{
		    end = i;
		}
	}
	if(start > end||start==-1||end==-1)
	{
	    cout << "No"<<endl;
	}
	else
	{
	    cout << "Yes"<<endl;
	}
	return 0;	
} 

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int n, q; cin >> n >> q;
    queue<pair<string, int>> RR;
    rep(i,n){
        string name; int time;
        cin >> name >> time;
        RR.push(make_pair(name, time));
    }
    int sum = 0;
    while(!RR.empty()){
        auto task = RR.front(); RR.pop();
        if(task.second <= q){
            sum += task.second;
            cout << task.first << " " << sum << endl;
        }else{
            sum += q;
            RR.push(make_pair(task.first, task.second-q));
        }
    }
}


Measured memory_bytes: 6296
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
	vector<string> w = {"MON", "TUE", "WED", "THU", "FRI", "SAT","SUN"};
 
	string s;
	cin >> s;
 
	if (s == "SUN"){
		cout << 7 << endl;
		return 0;
	}
 
	int pos = 0;
	for(int i = 0; i < w.size(); i++){
		if (w[i] == s){
			pos = i;
		}
	}
	cout << w.size() - pos - 1  << endl;
	return 0;
}

Measured memory_bytes: 888