akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;

int main() {
  string s;
  cin>>s;
  int n=s.size();
  bool ans=true;
  rep(i,n){
            if(i%2==0){
                if(s[i]=='R' ||s[i]=='U'||s[i]=='D'){
                  
                }
                else ans=false;
            }
            else{
              
                if(s[i]=='L' ||s[i]=='U'||s[i]=='D'){
                }
               else ans=false;
            }
    
    } 
    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
 
 
}





Measured memory_bytes: 256
n = int(input())
  
building =  [[[ 0 for i in range(10) ] for j in range(3) ] for k in range(4) ]

for i in range(n):
    b,f,r,v = [ int(s) for s in input().split() ]
    building[b-1][f-1][r-1] += v

s = ""
for b in range(4):
    for f in range(3):
        for r in range(10):
            s += ' '+str(building[b][f][r])
        s += '\n'
    if b!=3:
        s = s + '#'*20 + '\n'

print(s, end='')


Measured memory_bytes: 5612
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define ll long long int
#define sp ' '
#define intmax 2147483647
#define intmin -2147483647
#define llmax 9223372036854775807
using namespace std;

int n;
int a[100010], b[1000010], c[100010];
ll ans;

int main(){
	cin >> n;
	lp(n)
		cin >> a[i];
	lp(n)
		cin >> b[i];
	lp(n)
		cin >> c[i];
	
	a[n] = intmax;

	sort(a, a + n);
	sort(b, b + n);
	sort(c, c + n);

	ll j, k;
	j = k = 0;

	ans = 0;
	bool flag = false;

	lp(n) {
		while (a[j] < b[i]) {
			if (j == n) {
				flag = true;
				break;
			}
			j++;
		}
		j--;
		while (b[i] >= c[k]) {
			if (k == n - 1) {
				flag = true;
				break;
			}
			k++;
		}
		if (flag)break;
		ans += (j + 1)*(n - k);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define INF 1000000000000000

int main(){
  int M1,D1,M2,D2;
  cin>>M1>>D1>>M2>>D2;
  if(D1+1==D2){
    cout<<0<<endl;
  }else{
    cout<<1<<endl;
  }
}


Measured memory_bytes: 768
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
	int n, x, a[100], count = 0, m;
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	m = n;
	for (int i = 0; i < m; i++) {
		if (x >= a[i]) {
			count++;
			x -= a[i];
		}
		else {
			x = 0;
		}
	}
	if (x > 0) {
		cout << count - 1 << endl;
	}
	else {
		cout << count << endl;
	}
	return 0;
}

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

int main() {
  
  int N, K;
  cin >> N >> K;
  int a = 1;

  for (int i = 0; i < N; i++) {
    
     if (a > K) a += K;
     else a *= 2;
  }
  
  cout << a;

}


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

int main(void){
   
   int k, s;
   
   cin>>k>>s;
   
   int cnt=0;
   for(int y=0; y<=k; y++){
       for(int x=0; x<=k; x++){
           if((x+y)<=s&&s<=(k+x+y)){
               cnt++;
           }
       }
   }
   
   cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0 ; i < int(N);i++)
#define all(x) (x.begin(),x.end())
using namespace std ;
typedef long long ll;
typedef pair <int , int >pi;
typedef vector <int> vi ;
typedef vector <string> si;



int main (){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a ;
	cin >> a;
	rep(i,a) cout << "ACL";
	
	return 0 ;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const long long INF=1e18,MOD=1e9+7;
#define MAX_V 100010
int main(){
	int a,b,c;
	string s;
	cin>>a>>b;
	if(a<=5)cout<<0<<endl;
	else if(a<=12)cout<<b/2<<endl;
	else cout<<b<<endl;
	

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  if (N<=9)
    cout << N << endl;
  else if(10<=N && N<=99)
    cout << 9 << endl; 
  else if(100<=N && N<=999)
    cout << 9 + N-99 << endl;
  else if(1000<=N && N<=9999)
    cout << 9+900;
  else if(10000<=N && N<=99999)
    cout  << 9+900+N-9999 << endl;
  else
    cout << 9+900+90000 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<bitset>
#include<sstream>
#include<list>
#include<climits>

using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define nrep(i,i0,n) for(int i=(i0);i<(int)(n);++i)
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vii;
typedef long long ll;

int main(){
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	if(a>b)printf("0\n");
	else if(n==1){
		if(a==b)printf("1\n");
		else printf("0\n");
	}
	else if(n==2)printf("1\n");
	else printf("%lld\n",(ll)(b-a)*(n-2)+1);	
	return 0;
}



Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
    private static FastScanner sc = new FastScanner();
    private static long MOD = 1000000007;
    public static void main(String[] args) {
    	int N = sc.nextInt();
    	int[] C = new int[N];
    	int[] lastClrIdx = new int[200001];
    	int[] lastPairIdx = new int[N];
    	for(int i=0; i<200001; i++) {
    		lastClrIdx[i] = -1;
    	}
    	for(int i=0; i<N; i++) {
    		lastPairIdx[i] = -1;
    	}
    	for(int i=0; i<N; i++) {
    		C[i] = sc.nextInt();
    		if(lastClrIdx[C[i]] != -1) {
    			lastPairIdx[i] = lastClrIdx[C[i]];
    		}
    		lastClrIdx[C[i]] = i;
    	}
    	long[] dp = new long[N];
    	dp[0] = 1;
    	for(int i=1; i<N; i++) {
    		dp[i] = dp[i-1];
    		if(lastPairIdx[i] != -1 && i - lastPairIdx[i] != 1) {
    			dp[i] = (dp[i] + dp[lastPairIdx[i]]) % MOD;
    		}
    		//System.out.println(i + " " + dp[i]);
    	}
    	System.out.println(dp[N-1]);
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<unsigned char, unsigned char> P;
typedef vector<unsigned char> nv;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

bool calc_form(string op,nv a,nv b,nv& res){
  if(op=="/"){
    rep(i,b.size()){
      if(b[i]==0)return false;
    }
  }
  rep(i,a.size())rep(j,b.size()){
    unsigned char add;
    if(op=="+"){
      add=a[i]+b[j];
    }else if(op=="-"){
      add=a[i]-b[j];
    }else if(op=="*"){
      add=a[i]*b[j];
    }else{
      add=a[i]/b[j];
    }
    res.push_back(add);
  }
  sort(all(res));
  uni(res);
  return true;
}

int n,m;
map<string,P> h;
stack<nv> st;
vector<string> form;

int main(){
	cin.sync_with_stdio(false);
  cin>>m;
  rep(i,m){
    string name; int a,b;
    cin>>name>>a>>b;
    h[name]=P(a,b);
  }
  cin>>n;
  rep(i,n){
    string a;
    cin>>a;
    form.push_back(a);
  }
  rep(i,n){
    string a=form[i];
    if(a=="+"||a=="-"||a=="*"||a=="/"){
      nv n2=st.top(); st.pop();
      nv n1=st.top(); st.pop();
      nv tmp;
      if(!calc_form(a,n1,n2,tmp)){
        cout<<"error"<<endl;
        return 0;
      }
      st.push(tmp);
    }else if(h.count(a)){
      nv tmp;
      repl(i,h[a].fi,h[a].se+1){
        tmp.push_back(i);
      }
      st.push(tmp);
    }else{
      nv tmp;
      tmp.push_back(stoi(a));
      st.push(tmp);
    }
  }
  cout<<"correct"<<endl;
	return 0;
}

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

int main(){
  string S,T;
  cin>>S>>T;
  int N=S.length();
  rep(i,N){
    if(S==T){
      cout<<"Yes"<<endl;
      return 0;
    }
    S=S[N-1]+S.substr(0,N-1);
  }
  cout<<"No"<<endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> d(N);
    rep(i,N){
        cin >> d[i];
    }
    sort(d.begin(),d.end());
    cout << d[N/2] - d[N/2-1] << endl;
    return 0;
}

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

int compare_int(const void *a, const void *b)
{
	return *(int*)a - *(int*)b;
}


int main(void)
{
	int input[1000];
	int num, i;

	scanf("%d", &num);

	for (i = 0; i < num; i++) {
		scanf("%d", &input[i]);
	}
	
	qsort(input, num, sizeof(int), compare_int);

	printf("%d", input[num - 1] - input[0]);

	return(0);
}

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

int n;

int main()
{
    using tsii = tuple<string, int, int>;
    cin >> n;
    vector<tsii> tuples;
    for (int i = 1; i <= n; i++)
    {
        string s;
        int p;
        cin >> s;
        cin >> p;
        tuples.push_back(make_tuple(s, 100-p, i));
    }
    sort(tuples.begin(), tuples.end());
    for (auto t : tuples)
    {
        cout << get<2>(t) << endl;;
    }
}


Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split(" ")]
B = [int(i) for i in input().split(" ")]
C = [int(i) for i in input().split(" ")]

ans = 0
for i in range(N):
    ans += B[A[i]-1]
    if i > 0 and A[i] - A[i-1] == 1:
        ans += C[A[i-1]-1]
print(ans)

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r =sc.nextInt();
		int c =sc.nextInt();
		int[][] A = new int[r + 1][c + 1];
		int sum = 0;
		for(int i = 0; i < r; i++) {
			sum = 0;
			for(int j = 0; j < c; j++) {
				A[i][j] = sc.nextInt();
				sum += A[i][j];
			}
		A[i][c] = sum;
		}
		for(int j = 0; j < c + 1; j++) {
			sum = 0;
			for(int i = 0; i < r; i++) {
				sum += A[i][j];
			}
			A[r][j] = sum;
		}
		for(int i = 0; i < r + 1; i++) {
			for(int j = 0; j < c + 1; j++) {
				System.out.print(A[i][j]);
				if(j == c) { System.out.println(""); break;}
				System.out.print(" ");
			}
		}
	}
}



Measured memory_bytes: 42192
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;            //

int main(void)
{
    string odd, even;
    cin >> odd >> even;

    int diff = odd.size() - even.size();

    for (int i = 0; i < even.size(); i++)
    {
        cout << odd[i] << even[i];
    }

    if (diff != 0)
    {
        cout << odd[odd.size() - 1] << endl;
    }
    else
    {
        cout << endl;
    }

    return (0);
}

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

using namespace std;



int main() {

  string s;
  cin >> s;

  int w;
  cin >> w;

  for(int i = 0; i < s.length();) {
    cout << s[i];
    i += w;
  }
  cout << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
  
int main(){
    int n,m;
    cin>>n>>m;
    int min=0;
    int max=n;
    rep(i,m){
        int l,r;
        cin>>l>>r;
        if(l>=min)min=l;
        if(r<=max)max=r;
    }
    int ans=0;
    if(min<=max)ans=max-min+1;

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main()
{
	int H,W,i,j;
	
	while(1)
	{
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0)
		{
			break;
		}
		
		for(i = 0; i < H; i++)
		{
			for(j = 0; j < W; j++)
			{
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
	
}

Measured memory_bytes: 572
char buf[250000];sz;
char out[50505];outsz;
char tmp[10];tmpsz;
int d[5000];
long S[5001];
main()
{
	read(0,buf,250000);
	int k=0,q=0;
	for(;;)
	{
		char c=buf[sz++];
		if(c<'0')break;
		k=k*10+c-'0';
	}
	for(;;)
	{
		char c=buf[sz++];
		if(c<'0')break;
		q=q*10+c-'0';
	}
	for(int i=0;i<k;i++)
	{
		int D=0;
		for(;;)
		{
			char c=buf[sz++];
			if(c<'0')break;
			D=D*10+c-'0';
		}
		d[i]=D;
	}
	for(;q--;)
	{
		int N=0,X=0,M=0;
		for(;;)
		{
			char c=buf[sz++];
			if(c<'0')break;
			N=N*10+c-'0';
		}
		for(;;)
		{
			char c=buf[sz++];
			if(c<'0')break;
			X=X*10+c-'0';
		}
		for(;;)
		{
			char c=buf[sz++];
			if(c<'0')break;
			M=M*10+c-'0';
		}
		S[0]=0;
		for(int i=0;i<k;i++)S[i+1]=S[i]+(d[i]%M?:M);
		int ans=N-1-((N-1)/k*S[k]+S[(N-1)%k]+X)/M+X/M;
		tmpsz=10;
		do{
			tmp[--tmpsz]=ans%10+'0';
		}while(ans/=10);
		for(;tmpsz<10;)out[outsz++]=tmp[tmpsz++];
		out[outsz++]='\n';
	}
	write(1,out,outsz);
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-
S = input()

if S == "SUN":
    print(7)
elif S == "MON":
    print(6)
elif S == "TUE":
    print(5)
elif S == "WED":
    print(4)
elif S == "THU":
    print(3)
elif S == "FRI":
    print(2)
elif S == "SAT":
    print(1)

Measured memory_bytes: 3060
def main():
    a, b, q = map(int, input().split())
    INF = 10 ** 18
    s = [-INF] + [int(input()) for _ in range(a)] + [INF]
    t = [-INF] + [int(input()) for _ in range(b)] + [INF]
    x = [[int(input()), i] for i in range(q)]

    y = sorted(x, key=lambda a: a[0])
    d = [0] * q
    i, j = 0, 0
    for p in y:
        place = p[0]
        while s[i] < place:
            i += 1
        while t[j] < place:
            j += 1
        sl, sr = s[i-1], s[i]
        tl, tr = t[j-1], t[j]

        rr = abs(max(sr, tr) - place)
        ll = abs(min(sl, tl) - place)
        if sr < tr:
            rl = abs(sr - place) + abs(sr - tl)
        else:
            rl = abs(tr - place) + abs(tr - sl)
        if sl < tl:
            lr = abs(tl - place) + abs(sr - tl)
        else:
            lr = abs(sl - place) + abs(tr - sl)

        d[p[1]] = min(rr, rl, lr, ll)

    for dd in d:
        print(dd)


main()


Measured memory_bytes: 33732
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>
#include <bits/stdc++.h>

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define pi pair<int,int>
#define fi first
#define se second

#define FOR(var, to)          for (register s64 var = 0; var < (s64)to; var++)
#define FROMTO(var, from, to) for (register s64 var = from; var <= (s64)to; var++)

#define INIT(var) FOR(i,countof(var)) var[i] = 0
#define INPUT(var) FOR(i,countof(var)) var[i] = ri()

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)

#define MOD 1000000007
#define INF (1 << 30)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

using namespace std;

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

static inline s64 rs64() {
  s64 a;
  scanf("%" SCNd64, &a);
  return a;
}

static inline void wi(int a) {
  printf("%d", a);
}

static inline void wu64(u64 a) {
  printf("%" PRIu64, a);
}

static inline void ws64(s64 a) {
  printf("%" PRId64, a);
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
    int n = ri();
    string s[n];
    FOR(i,n) cin >> s[i];
    vector<int> nums(5,0);
    FOR(i,n) {
        if (s[i][0] == 'M') nums[0]++;
        if (s[i][0] == 'A') nums[1]++;
        if (s[i][0] == 'R') nums[2]++;
        if (s[i][0] == 'C') nums[3]++;
        if (s[i][0] == 'H') nums[4]++;
    }
    sort(nums.begin(), nums.end(), greater<int>());
    int num = 0;
    FOR(i,5) if (nums[i]) num++;
    s64 res = 0;
    if (num == 3) res = ((s64)nums[0])*nums[1]*nums[2];
    if (num == 4) res = ((s64)nums[0])*nums[1]*nums[2] +
                        ((s64)nums[0])*nums[1]*nums[3] +
                        ((s64)nums[0])*nums[2]*nums[3] +
                        ((s64)nums[1])*nums[2]*nums[3];
    if (num == 5) res = 
                        ((s64)nums[0])*nums[1]*nums[2] +
                        ((s64)nums[0])*nums[1]*nums[3] +
                        ((s64)nums[0])*nums[1]*nums[4] +
                        ((s64)nums[0])*nums[2]*nums[3] +
                        ((s64)nums[0])*nums[2]*nums[4] +
                        ((s64)nums[0])*nums[3]*nums[4] +
                        ((s64)nums[1])*nums[2]*nums[3] +
                        ((s64)nums[1])*nums[2]*nums[4] +
                        ((s64)nums[1])*nums[3]*nums[4] +
                        ((s64)nums[2])*nums[3]*nums[4];
                        
    cout << res << endl;
 return 0;
}


Measured memory_bytes: 6144
n = int(input())
s=0
t=0
u=0
v=0
for i in range(n):
  f = input()
  if(f=="AC"):
    s+=1
  elif(f=="WA"):
    t+=1
  elif(f=="TLE"):
    u+=1
  else:
    v+=1
    
print("AC x",s,"\nWA x",t,"\nTLE x",u,"\nRE x",v)




Measured memory_bytes: 9120
from itertools import accumulate
from collections import defaultdict
N, K = map(int, input().split())
A = list(map(int, input().split()))
A_cum = [0] + list(accumulate(A))

ans = 0
dd = defaultdict(int)
q = []
for i, a in enumerate(A_cum):
  a -= i
  a %= K
  if i-K >= 0:
    dd[q[i-K]] -= 1
  ans += dd[a]
  dd[a] += 1
  q.append(a)
print(ans)  


Measured memory_bytes: 48296
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    int main()
    {
        ios::sync_with_stdio(0);
        cin.tie(0);
        ll n,cnt;
        string s;
        cin >>n;
	    cin >> s;
        ll r=count(s.begin(),s.end(),'R');
        ll  g=count(s.begin(),s.end(),'G');
        ll  b=count(s.begin(),s.end(),'B');
        cnt=r*g*b;
        for(ll i=0;i<n;i++){
            for(ll j=i+1;j<=n;j++){
                if(j*2-i>=n)continue;
                set<char>st;
                st.insert(s[i]);
                st.insert(s[j]);
                st.insert(s[j*2-i]);
                if(st.size()==3)cnt--;
            }
        }
 
        cout << cnt << endl;
        return 0;
    }

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

int main() {
    int k;
    string s;
    cin >> k >> s;
    if(s.length() <= k) {
        cout << s << endl;
    } else {
        cout << s.substr(0, k) << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
N, K= map(int, input().split())
H = list(map(int, input().split()))

DP = [10 ** 10] * N
DP[0] = 0
DP[1] = abs(H[1] - H[0])
for i in range(2, N):
  for j in range(1, K + 1):
    if i - j >= 0:
      DP[i] = min(DP[i], DP[i - j] + abs(H[i] - H[i - j]))

#print(DP)
print(DP[-1])


Measured memory_bytes: 52448
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;

using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
#define endl        	"\n"
#define int         	long long int  
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define pll         	pair<ll,ll>
#define vec     		vector<ll>
#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod     		1000000007

ll mod_pow(ll a,ll b)
{
    ll res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    
    return res;
}

void solve()
{
	ll x,y,a,b,c;
	
	cin>>x>>y>>a>>b>>c;
	
	vector<ll> A(a),B(b),C(c);
	
	ll ans = 0;
	
	for(int i=0;i<a;i++)
	{
		cin>>A[i];
	}
	for(int i=0;i<b;i++)
	{
		cin>>B[i];
	}
	for(int i=0;i<c;i++)
	{
		cin>>C[i];
	}
	
	sort(ALL(A));
	sort(ALL(B));
	sort(ALL(C));
	
	ll l = c-1;
	
	priority_queue<ll,vector<ll>,greater<ll>> q;
	
	for(int i=a-x;i<a;i++)
	{
		ans+=A[i];
		q.push(A[i]);
	}
	
	for(int i=b-y;i<b;i++)
	{
		ans+=B[i];
		q.push(B[i]);
	}
	
	
	while(l >= 0 && !q.empty())
	{
		ll tmp = q.top();
		
		q.pop();
		
		
		if(C[l] > tmp)
		{
			ans= ans+C[l]-tmp;
			l--;
		}
		else
		{
			break;
		}
		
	}
	cout<<ans;	
}
signed main()
{
 
    fast;
 
    ll t;
    
    t=1;
    
    //cin>>t;
    
    while(t--)
    {
        solve();
    }
 
    return 0;
}


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

const int mx = 112345;

int v[mx], dp[mx];

int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    dp[i] = (!!i) * 2e9;
    for(int j = max(0, i-k); j < i; j++) {
      dp[i] = min(dp[i], dp[j] + abs(v[i]-v[j]));
    }
  }
  cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void)
{
	long int a, b;
	long int A[100];
	long int sum = 0;
	long int i;
	long int check = 0;

	scanf("%ld %ld", &a, &b);

	for (i = 0; a > i; i++) {
		scanf("%ld", &(A[i]));
		sum = sum + A[i];
	}

	for (i = 0; a > i; i++) {
		if (sum <= 4 * b * A[i]) {
			check++;
		}
	}

	if (b > check) {
		printf("No");
	}

	else {
		printf("Yes");
	}

	return 0;
}

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

int main(void) {
  int n;
  cin >> n;
  if (n == 1) {
    cout << 2 << endl;
    return 0;
  }
  if (n % 2 == 0) cout << n << endl;
  else cout << 2 * n << endl;
  return 0;
}


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

int compare(const void *a, const void *b)
{
	int A = *((int*)a);
	int B = *((int*)b);
	
	return A-B;
}


int main()
{
	//変数宣言
	int K;
	char S[1000];
	
	int i,num;
	
	scanf("%d",&K);
	scanf("%s",S);
	
	for(i=0;i<=100;i++)
	{
		if(S[i]=='\0') break;
	}
	
	if(K<i){
		for(i=0;i<K;i++)
		{
			printf("%c",S[i]);
		}
		printf("...");
	}else
	{
		printf("%s",S);
	}
	
	return 0;
}

Measured memory_bytes: 1732
import java.util.*;
import java.io.*;
class Main {
    
    public static void solve2(int[][] arr, int N){
        long ans = Long.MIN_VALUE;
        long[][] dp = new long[N][3];
        for(int i = 0; i < 3; i++){
            dp[0][i] = arr[0][i]; 
            ans = Math.max(ans,dp[0][i]);
        }

        for(int i = 1; i < dp.length; i++){
            for(int j = 0; j < dp[0].length; j++){
                long max = Long.MIN_VALUE;
                int picked = arr[i][j]; 
               for(int k = 0; k < dp[0].length; k++ ){
                    if(j != k){
                        max = Math.max(max, picked + dp[i-1][k]);
                    }
               } 
               dp[i][j] = max;
               ans = Math.max(ans,dp[i][j]);
            }
            
        }
System.out.println(ans);
    }
        public static void main(String[] args) throws Exception{
            StringTokenizer str;
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            int n = Integer.parseInt(br.readLine());
            int[][] arr = new int[n][3];
            for(int i = 0; i < arr.length; i++){
                int j = 0;
                str = new StringTokenizer(br.readLine()," ");
                while(str.hasMoreTokens()){
                    arr[i][j] = Integer.parseInt(str.nextToken());
                    j++;
                }
            }
       
        solve2(arr,n);            
    }
}

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

int main(){
  int N,K;
  cin>>N>>K;
  
  vector<int>x(N);
  int count_minus=0,count_plus=0;
  
  for(int i=0;i<N;i++){
    cin>>x.at(i);
    if(x.at(i)>=0)
      count_plus++;
    else
      count_minus++;
  }
  
  vector<int> x_minus(count_minus),x_plus(count_plus);
  
  for(int i=0;i<count_minus;i++)
    x_minus.at(count_minus-1-i)=-1*x.at(i);
  for(int i=0;i<count_plus;i++)
    x_plus.at(i)=x.at(i+count_minus);
  
  int res=999999999;
  
  for(int i=0;i<K-1;i++){
    int j=K-i-2;
    if(i>=count_minus||j>=count_plus)
      continue;
    
    int count1=2*x_minus.at(i)+x_plus.at(j);
    int count2=x_minus.at(i)+2*x_plus.at(j);
    
    res=min(res,count1);
    res=min(res,count2);
    
  }
  if(K<=count_minus)
    res=min(res,x_minus.at(K-1));
  if(K<=count_plus)
    res=min(res,x_plus.at(K-1));
  
  cout<<res;
}
  
  

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
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;
}
 
using namespace std;
//ここから

void solve(){
  ll n,k;
  cin>>n>>k;
  vector<ll>a(n);
  rep(i,n)cin>>a[i];
  vector<ll>sum(n+1);
  map<ll,ll>mp;
  rep(i,n){
    sum[i+1]=sum[i]+a[i];
  }
  ll cnt=0;
  rep(i,n){
    mp[(sum[i])%k]++;
    cnt+=mp[(sum[i+1])%k];
  }
  cout<<cnt<<endl;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


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

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

  long ct = 0;

  vector<long> p(n); 
  vector<long> pmin(n); 
  long m = 1010101;
  long tmp;
  
  for(long i=0; i<n; i++){
    cin >> tmp;
    p.at(i) = tmp;
    m = min(m, tmp);
    pmin.at(i) = m;
  }
  
  for(long i=0; i<n; i++){
    if(p.at(i)<=pmin.at(i)) ct++;
  }
  
  cout << ct << endl;
  return 0;
}


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

using namespace std;

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

    vector<int> d(n);
    for(int i=0; i<n; i++){
        cin >> d[i];
    }

    sort(d.begin(), d.end());

    int cnt = d[n/2] - d[n/2 -1];
    cout << cnt << endl;

}

Measured memory_bytes: 640
n,m=map(int,input().split())

U=10**6
mod=10**9+7

fact=[1]*(U+1)
fact_inv=[1]*(U+1)

for i in range(1,U+1):
    fact[i]=(fact[i-1]*i)%mod
fact_inv[U]=pow(fact[U],mod-2,mod)

for i in range(U,0,-1):
	fact_inv[i-1]=(fact_inv[i]*i)%mod

def comb(n,k):
    if k<0 or k>n:
        return 0
    x=fact[n]
    x*=fact_inv[k]
    x%=mod
    x*=fact_inv[n-k]
    x%=mod
    return x
def div(a,b):
    return (a*pow(b,mod-2,mod))%mod

def p(n,k):
    return div(fact[n],fact[n-k])
ans=0
for i in range(n+1):
    t=(comb(n,i)*p(m-i,n-i))%mod
    if i%2:ans=(ans-t)%mod
    else:ans=(ans+t)%mod
ans=(ans*p(m,n))%mod
print(ans)

Measured memory_bytes: 97672
import math
def kumiawase(n):
  a = 1
  b = 1
  for i in range(1, n+1):
    a = i * a
  for i in range(1, n - 2+1):
    b = i * b
  c = math.floor(a /(b * 2))
  return c
if __name__ == "__main__":
  x = input().split()
  n = int(x[0]) # 偶数
  m = int(x[1]) # 奇数
  a = kumiawase(n)
  b = kumiawase(m)
  print(a + b)

Measured memory_bytes: 3064
n = int(input())
count = 0 
s = []
h = []
c = []
d = []
for _ in range(n):
    a = [x for x in input().split()]
    if a[0 ] == "S":
        s.append(int(a[1]))
    elif a[0 ] == "H":
        h.append(int(a[1]))
    elif a[0 ] == "C":
        c.append(int(a[1]))
    else:
        d.append(int(a[1]))
for _ in range(1,14):
    if _ not in s:
        print("S", _)
for _ in range(1,14):
    if _ not in h:
        print("H", _)
for _ in range(1,14):
    if _ not in c:
        print("C", _)
for _ in range(1,14):
    if _ not in d:
        print("D", _)        


Measured memory_bytes: 5612
#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 = 1001001001;
const int mod = 1000000007;


//yet solved 2020/8/15

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

  vector<int> cum(n+2);
  // com = {0,0,1,3,...}index 1~n+1
  rep(i,n) {
    cum[i+2] = cum[i+1] + i+1;
    cum[i+2] %= mod;
  }

  int ans = 0;
  for(int i = k; i <= n+1; i++){
    int mx = cum[n+1]-cum[n+1-i];
    int mn = cum[i]-cum[0];
    ans += (mx - mn + 1 + mod)%mod;
    ans %= mod;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3984
#include <iostream>
#include <vector>
#include <map>
using namespace std;

vector<map<int, int>> graph;
vector<int> visited;
map<int, int> depths;

bool dfs(int v, int p, int d)
{
	if (1 == visited[v]) {
		return true;
	}
	visited[v] = 1;

	if (depths.find(v) != depths.end()) {
		return true;
	}
	depths[v] = d;

	for (auto n : graph[v]) {
		if (p == n.first) {
			continue;
		}
		int n_depth = d + n.second;
		if ((depths.find(n.first) != depths.end()) && (depths[n.first] != n_depth)) {
			return false;
		}
		bool result = dfs(n.first, v, n_depth);
		if (!result) {
			return false;
		}
	}
	return true;
}

int main(void)
{
	int N, M;
	cin >> N >> M;

	graph.resize(N);
	visited.resize(N);
	cerr << visited.size() << endl;

	for (int i = 0; i < M; i++) {
		int L, R, D;
		cin >> L >> R >> D;
		graph[L - 1][R - 1] = D;
		graph[R - 1][L - 1] = -D;
	}

	for (int i = 0; i < N; i++) {
		depths.clear();
		if (!dfs(i, -1, 0)) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 36224
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] n = new int[N];
    int ans = 0;
    
    for(int i = 0; i<N;i++){
    	n[i] = sc.nextInt();
    }
    for(int i = 0;i<N-1;i++){
    	if(n[i] == i+1){
    		int a = n[i];
    		n[i] = n[i+1];
    		n[i+1] = a;
    		ans++;
    	}
    }
    if(n[N-1] == N){
    	ans++;
    }
    System.out.println(ans);
   
  }
}

Measured memory_bytes: 52636
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include<string.h>
#include<limits.h>

int main(){
	int y,m,d,flag=0;
	while(scanf("%d%d%d",&y,&m,&d)!=EOF){
		
		if(y>=1989){
			if(y==1989){
				if(m>1)flag=0;
				else if(m==1){
					if(d>=8)flag=0;
					else flag=1;
				}
			}
			else flag=0;
		}
		
		else if(y>=1926){
			if(y==1926){
				if(m==12){
					if(d>=25)flag=1;
					else flag=2;
				}
				else flag=2;
			}
			else flag=1;
		}
		
		else if(y>=1912){
			if(y==1912){
				if(m>7)flag=2;
				else if(m==7){
					if(d>=30)flag=2;
					else flag=3;
				}
				else flag=3;
			}
			else flag=2;
		}
		
		else if(y>=1868){
			if(y==1868){
				if(m>9)flag=3;
				else if(m==9){
					if(d>=8)flag=3;
					else flag=4;
				}
				else flag=4;
			}
			else flag=3;
		}
		
		else flag=4;
	
	switch(flag){
		case 0:
		printf("heisei %d %d %d\n",y-1988,m,d);
		break;
		
		case 1:
		printf("showa %d %d %d\n",y-1925,m,d);
		break;
		
		case 2:
		printf("taisho %d %d %d\n",y-1911,m,d);
		break;
		
		case 3:
		printf("meiji %d %d %d\n",y-1867,m,d);
		break;
		
		case 4:
		printf("pre-meiji\n");
		break;
	}
		flag=0;
	}
return 0;
}

Measured memory_bytes: 608
from itertools import accumulate

n,c = map(int, input().split())
xv = [[0,0]]+[list(map(int, input().split())) for i in range(n)]
xv_rev = [[0,0]]+[[c-x,v] for x,v in xv][:0:-1]
cumsum = [i-x for i,(x,v) in zip(list(accumulate([v for x,v in xv])),xv)]
cumsum_rev = [i-x for i,(x,v) in zip(list(accumulate([v for x,v in xv_rev])),xv_rev)]
xv_max = [0]
xv_rev_max = [0]
now_v = 0
for k,(x,v) in enumerate(xv[:-1],1):
  xv_max.append(max(xv_max[-1], cumsum[k]))
for k,(x,v) in enumerate(xv_rev[:-1],1):
  xv_rev_max.append(max(xv_rev_max[-1], cumsum_rev[k]))
ans = 0
for i,j,(x,v) in zip(xv_max,cumsum_rev[::-1],xv_rev[::-1]):
  ans = max(ans,i+j-x)
for i,j,(x,v) in zip(xv_rev_max,cumsum[::-1],xv[::-1]):
  ans = max(ans,i+j-x)
print(ans)


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

int main()
{
    int length[100005] = {};
    int point[100005] = {};
    int N, R, L;

    set < pair < int , int > > st; //point -idx

    cin >> N >> R >> L;

    for ( int i = 0; i < N; i++ ) {
        st.insert(make_pair(0, -i));
    }
    int before = 0;
    while ( R > 0 ) {
        int d, t, x;
        cin >> d >> t >> x; --d;

        length[-(rbegin(st) -> second)] += (t - before);
        st.erase(make_pair(point[d], -d));
        point[d] += x;
        st.insert(make_pair(point[d], -d));


        R--, before = t;
    }

    length[-(rbegin(st) -> second)] += (L - before);

    int maxp = 0;
    for ( int i = 1; i < N; i++ ) {
        if ( length[i] > length[maxp] ) {
            maxp = i;
        }
    }
    cout << maxp + 1 << endl;

    return ( 0 );
}



Measured memory_bytes: 8580
w,h,x,y = gets.chomp.split(' ').map(&:to_i)
if (w.to_f)/2 == x && (h.to_f)/2 == y
  flag = 1
else
  flag = 0
end
puts (w.to_f * h / 2).to_s + " " + flag.to_s

Measured memory_bytes: 14292
#include <iostream>
using namespace std;
int main(){
 int n, x;
 int y = 0;
 while(1){
  cin >> n >> x;
  if(n == 0 && x == 0)
   break;
  for(int a=1; a<=n; a++){
   for(int b=2; b<=n; b++){
    for(int c=3; c<=n; c++){
     if(a+b+c == x && a < b && b < c)
      y++;
    }
   }
  }
  cout << y << endl;
  y = 0;
 }
 return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define reg register
#pragma GCC optimize(3)
#pragma GCC optimize("02")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#define _inline __inline__ __attribute__((always_inline))
using namespace std;
class complex{
public:
    inline char gc(){
        static const int IN_LEN=1<<18|1;
        static char buf[IN_LEN],*s,*t;
        return (s==t)&&(t=(s=buf)+fread(buf,1,IN_LEN,stdin)),s==t?-1:*s++;
    }
    template <typename _Tp> _inline complex & operator >> (_Tp &x){
        static char ch,sgn; ch=gc(),sgn=0;
        for(;!isdigit(ch);ch=gc()){if(ch==-1)return *this;sgn|=ch=='-';}
        for(x=0;isdigit(ch);ch=gc())x=x*10+(ch^'0');
        sgn&&(x=-x); return *this;
    }
}inc;
map<string,int> a;
set<string> st;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	string s;
	int maxn=-1<<30;
	int index=1;
	for(reg int i=1;i<=n;i++){
		cin>>s;
		a[s]++;
		st.insert(s);
		maxn=max(maxn,a[s]);
	}
	for(set<string>::iterator it=st.begin();it!=st.end();it++){
		string temp=*it;
		if(a[temp]==maxn) cout<<temp<<"\n";
	}
	return 0;
}


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


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define pb push_back
#define mp make_pair
#define snd second
#define fst first
#define debug printf("--%d--\n",__LINE__)
#define ll long long int

ll N, A;


int main(void){
	cin >> N >> A;
	if (N<=5) {cout << N << endl; return 0;}
	ll ans = N;
	
	for(int i=2;;i++){
		ll p = (ll)(pow(N, 1.0/i));
		ll pr = 1;
		for(int j=0;j<i;j++) pr *= p;
		if (pr<N) p++;
		
		
		pr = 1;	for(int j=0;j<i;j++) pr *= p;
		int j;
		for(j=0;j<=i;j++){
			if (pr < N) break;
			pr = pr * (p-1) / p;
		}
		//cout << p << " " << i << " " << j-1 << endl;
		
		//cout << A*(i-1) + p * i - (j-1) << endl;
		ans = min(ans, A*(i-1) + p * i - (j-1));
		
		if (p<=2) break;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 384
import scala.io.StdIn._

object Main {
  def main(args: Array[String]): Unit = {
    val genTuple = (x: List[Int]) => {
      if (x.head > x.last) (x.sum, 0)
      else if (x.head < x.last) (0, x.sum)
      else (x.head, x.last)
    }

    val eachSum = (a: (Int, Int), b: (Int, Int)) => (a._1 + b._1, a._2 + b._2)

    val readIntList = (n: Int) => {
      var list: Array[List[Int]] = Array.empty
      for (i <- 0 until n) {
        list :+= readLine.split(' ').map(_.toInt).toList
      }
      list
    }

    while (true) {
      val n = readInt
      if (n == 0) return

      val result = readIntList(n).map(genTuple).foldLeft((0, 0))(eachSum)

      println(result._1 + " " + result._2)
    }
  }
}

Measured memory_bytes: 313584
def f():
    import sys
    input = sys.stdin.readline
    n,q=[int(j) for j in input().split()]
    l=[]
    for i in range(n):
        s,t,x=[int(j) for j in input().split()]
        l.append((s-x,1,x))
        l.append((t-x,0,x))

    for i in range(q):
        d=int(input())
        l.append((d,2,i))

    l.sort()

    ans=[-1]*q
    ll=set()
    m=10**18
    p=False
    for i,j,x in l:
        if j==1:
            ll.add(x)
            if m>x:
                m=x
                p=True
        elif j==0:
            ll.remove(x)
            if x==m:
                p=False
        else:
            if not p:
                if ll:
                    p=True
                    m=min(ll)
                else:
                    m=-1
            ans[x]=m
    print('\n'.join(map(str,ans)))

f()

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

using namespace std;

int main(){
    long long N, K, Q;
    cin >> N >> K >> Q;
    long long arr[Q];
    long long cnt[N + 1] = {0};
    long long score[N + 1];
    for(long long i = 1; i <= N; i++){
        score[i] = K;
    }
    for(long long i = 0; i < Q; i++){
        cin >> arr[i];
        cnt[arr[i]]++;
    }
    for(long long i = 1; i <= N; i++){
        if(score[i] - (Q - cnt[i]) > 0){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2944
let read_lines () =
  let rec iter xs =
    try
      read_line() :: xs |> iter
    with End_of_file -> xs
  in iter []

let rec print_until n xs =
  print_int (List.hd xs);
  print_newline ();
  if n > 1 then
    print_until (n-1) (List.tl xs)
  else ()

let _ = read_lines()
        |> List.map int_of_string
        |> List.sort compare
        |> List.rev
        |> print_until 3

Measured memory_bytes: 2192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
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; }



int main(){
    ll n; cin>>n;
    vector<ll> a(n), b(n), c(n);
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    rep(i,n) cin>>c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    vector<ll> bb(n);
    rep(i,n){
        bb[i] = c.end() - upper_bound(c.begin(), c.end(), b[i]);
    }
    rep(i,n-1) bb[n-2-i]+=bb[n-1-i];
    ll res=0;
    rep(i,n){
        ll v = upper_bound(b.begin(), b.end(), a[i]) - b.begin();
        if(v==n) continue;
        else{
            res+=bb[v];
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int N,M;
bool check[8][8];


int main(){

	scanf("%d %d",&N,&M);

	for(int i = 0; i < N; i++){
		for(int k = 0; k < N; k++){

			check[i][k] = false;
		}
	}

	int from,to;

	for(int i = 0; i < M; i++){

		scanf("%d %d",&from,&to);
		from--;
		to--;

		check[from][to] = true;
		check[to][from] = true;
	}

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

	int ans = 0;
	bool FLG;

	do{

		int now = 0;
		FLG = true;

		for(int i = 0; i < vec.size(); i++){
			if(!check[now][vec[i]]){

				FLG = false;
				break;
			}
			now = vec[i];
		}

		if(FLG){

			ans++;
		}

	}while(next_permutation(vec.begin(),vec.end()));

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

	return 0;
}


Measured memory_bytes: 256
import numpy as np
from numba import jit


@jit
def myfunc(n, k, A):
    for _ in range(k):
        l = np.zeros((n + 1,), dtype=np.int64)
        for i, a in enumerate(A[:-1]):
            l[max(0, i - a)] += 1
            l[min(n, i + a + 1)] -= 1
        A = np.cumsum(l)
        if np.all(A[:-1] == n):
            break
    return A


def main():
    n, k = map(int, input().split())
    A = np.array(list(map(int, input().split())), dtype=np.int64)
    A = np.append(A, 0)
    print(*myfunc(n, k, A)[:-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 125076
#include <stdio.h>
#include <string.h>

int main(){
	char S[11],T[11],U[11];
	int A,B;
	scanf("%s%s\n",&S,&T);
	scanf("%d%d\n",&A,&B);
	scanf("%s\n",&U);
	if(strcmp(U,S) == 0 ){
		printf("%d %d\n",A-1,B);
	}else if(strcmp(U,T) == 0 ){
		printf("%d %d\n",A,B-1);
	}
	return 0;
}

Measured memory_bytes: 2120
N = int(input())
A = []
for i in range(N):
    A.append([list(map(int, input().split())) for _ in range(int(input()))])

# 引数はNが正直者か嘘つきかの組み合わせを表すリスト
# 戻り値は矛盾があるか、ないか
def check(arr):
    for idx, a in enumerate(A):
        # 嘘つきだと判断されているインデックス番号の人物は無視
        if arr[idx] == 0:
            continue
        # 一つ一つの証言をチェックする
        for x, y in a:
            if arr[x-1] != y:
                return False
    return True

all_comb = []
for i in range(2**N):
    comb = []
    for j in range(N):
        if (i >> j) & 1:
            comb.append(1)
        else:
            comb.append(0)
    all_comb.append(comb)
ret = 0
for comb in all_comb:
    if check(comb):
        ret = max(ret, sum(comb))

print(ret)


Measured memory_bytes: 51292
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

    long N = in.nextLong();
    long A = in.nextLong();
    long B = in.nextLong();

    long ans1 = (B - A) % 2 == 0 ? (B - A) / 2 : N;
    long ans2 = Math.min(B - 1, N - A);
    long ans3 = Math.min(A - 1, N - B) + 1 + (B - A) / 2;

    System.out.println(Math.min(ans1, Math.min(ans2, ans3)));
  }
}

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

#define ll long long
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int> >
#define vii vector<pair<int, int> >


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

    int x, y;
    std::cin >> x >> y;

    // 2a + 4b = y
    // a + b = x => 2a + 2b = 2x => 4a + 4b = 4x
    
    // 2b = y - 2x
    // 2a = 4x - y

    if(y - 2*x < 0 || abs((y - 2*x) % 2) == 1)
	std::cout << "No" << std::endl;
    else if(4*x - y < 0 || abs((4*x - y) % 2) == 1)
	std::cout << "No" << std::endl;
    else
	std::cout << "Yes" << std::endl;

    return 0;
}


Measured memory_bytes: 3652
import math


def get_input():
    return int(input())


def main():
    N = get_input()

    sqrt_n = int(math.sqrt(N))
    minimum = N + 1
    for p in range(1, sqrt_n + 1):
        if N % p == 0:
            q = N / p
            if p + q < minimum:
                minimum = int(p + q)

    print(minimum - 2)


main()

Measured memory_bytes: 3064
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		try (Scanner sc = new Scanner(System.in);) {

			String s = sc.next();
			String t = sc.next();

			t = t + t;
			System.out.println(t.contains(s) ? "Yes" : "No");

		}

	}
}


Measured memory_bytes: 21716
n,ma,mb = map(int, input().split())
l = []
for i in range(n):
    l.append(list(map(int,input().split())))

dp = [[[10**10 for _ in range(430)] for _ in range(430)] for _ in range(45)]

dp[0][0][0] = 0

for i in range(n):
    a=l[i][0]
    b=l[i][1]
    c=l[i][2]
    for j in range(410):
        for k in range(410):
            dp[i+1][j][k] = min(dp[i+1][j][k] ,dp[i][j][k])
            dp[i+1][j+a][k+b] =min(dp[i+1][j+a][k+b], dp[i][j][k] +c)

ans=10**10
for j in range(1,410):
    for k in range(1,410):
        if ma*k == mb*j:
            ans=min(ans,dp[n][j][k])
if ans == 10**10:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 116700
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m, n, num = 0;
	cin >> m >> n;
	for(int i = 2; i < 10; i++){
		for(int j = 2; j < 10; j++){
			if(i * 10 + j <= n && i * j <= m){
				num++;
			}
		}
	}
	cout << num;
	return 0;
}

Measured memory_bytes: 256
NUM = 1000000007

def power(m, n):
    if n == 0:
        return 1
    if n == 1:
        return m
    if n % 2 == 0:
        tmp = power(m, n/2) % NUM
        return tmp ** 2 % NUM
    if n % 2 == 1:
        tmp = power(m, n/2) % NUM
        return m * (tmp**2) % NUM

s = map(int, raw_input().split())
print "%d" % (power(s[0], s[1]) % NUM)

Measured memory_bytes: 6456
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		List<Integer> list = new ArrayList<>();
		
		list.add(1);
		list.add(2);
		list.add(3);
		
		
		list.remove(list.indexOf(scan.nextInt()));
		list.remove(list.indexOf(scan.nextInt()));
		
		System.out.println(list.get(0));
	
	}
}

Measured memory_bytes: 21972