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

int main() {
   int K,S;
   cin >> K >> S;
   int count=0;
   for (int i=0; i<=K; i++) {
       for (int j=0; j<=K; j++) {
           if (S-i-j>=0 && S-i-j<=K) count++;
       }
   }
   cout << count << endl;
}

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

const long long MOD = 1000000007;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;
typedef long long ll;

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

    set<char> D;
    for(int i=0;i<K;i++){
        int d;
        cin >> d;
        D.insert(d+'0');
    }


    while(1){
        string str;
        stringstream ss;
        ss << N;
        ss >> str;
        bool able = true;
        for(int i=0;i<str.size();i++){
            if(D.count(str[i]) > 0){
                able = false;
                break;
            }
        }
        if(able) break;
        N++;
    }
    cout << N << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
int main(){
    int n;
    cin >> n;
    map<string, vector<P>> m;
    for(int i=0;i<n;i++) {
        string s;
        int p;
        cin >> s >> p;
        m[s].push_back(P(p,i+1));
    }
    for(auto v : m){
        sort(v.second.begin(),v.second.end());
        reverse(v.second.begin(),v.second.end());
        for(P p:v.second){
            cout << p.second << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;



int main() {
	while(1) {
		int N; cin >> N;
		if (!N)break;
		vector<pair<string, long double>>pls;
		for (int i = 0; i < N; ++i) {
			string st;
			int p, a, b, c, d, e, f, s, m; cin >> st>>p >> a >> b >> c >> d >> e >> f >> s >> m;
			int initime = a + b + c;
			int rooptime = d + e;
			int money = m*s*f-p;
			long double eff = static_cast<long double>(money) / static_cast<long double>(initime + rooptime*(m));
			pls.push_back(make_pair(st, eff));
		}
		sort(pls.begin(), pls.end(), [](const pair<string, long double>&l, const pair<string, long double>&r) {return abs(l.second-r.second)<1e-44?l.first<r.first:l.second > r.second; });
		for (int i = 0; i < pls.size(); ++i) {
			cout << pls[i].first << endl;
		}
		cout << "#" << endl;
	}
	return 0;
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);
    int M,K;
    cin >> M >> K;
    int mx = (1<<M) - 1;
    if(M==1&&K==0){
        cout << "0 0 1 1" << endl;
        return 0;
    }
    if(M==1&&K==1){
        cout << -1 << endl;
        return 0;
    }
    if(K>mx){
        cout << -1 << endl;
        return 0;
    }
    for(int i=0;i<=mx;i++){
        if(i==K)continue;
        cout << i << " ";
    }
    cout << K <<" ";
    for(int i=mx;i>=0;i--){
        if(i==K)continue;
        cout << i << " ";
    }
    cout << K << endl;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

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

	bool v[4] = { false, false, false, false };
	char c;
	for (int i = 0; i < N; i++) {
		cin >> c;
		switch (c) {
			case 'P':
				v[0] = true;
				break;
			case 'W':
				v[1] = true;
				break;
			case 'G':
				v[2] = true;
				break;
			case 'Y':
				v[3] = true;
				break;
		}
	}

	int num = 0;
	for (int i = 0; i < 4; i++) {
		if (v[i]) {
			++num;
		}
	}

	string s = (num == 3) ? "Three": "Four";
	cout << s << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    while(cin >> N >> M && N){
        vec<int> mi(N),ma(N);
        for(int i=0;i<M;i++){
            int s,k;
            cin >> s >> k;
            for(int j=0;j<k;j++){
                int c;
                cin >> c;
                c--;
                ma[c] += s;
                if(k==1) mi[c] += s;
            }
        }
        vec<int> L(N+1,1e9),R(N+1,1e9);
        for(int i=0;i<N;i++) L[i+1] = min(L[i],mi[i]);
        for(int i=N-1;i>=0;i--) R[i] = min(R[i+1],mi[i]);
        int ans = 0;
        for(int i=0;i<N;i++){
            int now = min(L[i],R[i+1]);
            ans = max(ans,max(0,ma[i]-now));
        }
        cout << ans+1 << "\n";
    }
}



Measured memory_bytes: 3276
#include<stdio.h>
#include<string.h> 
int main()
{
	int n, r;
	scanf("%d", &n);
	char s[n];
	char t[n];
	
	scanf("%s %s", s, t);
	
	
	for(r=0; r<n; r++){
		printf("%c%c", s[r], t[r]);
	}

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  string s;
  string str;
  for (int i = 0; i < n; i++) {
    cin >> s;
    str.push_back(s.at(0));
  }
  cout << "AC x " << count(str.cbegin(), str.cend(), 'A') << endl;
  cout << "WA x " << count(str.cbegin(), str.cend(), 'W') << endl;
  cout << "TLE x " << count(str.cbegin(), str.cend(), 'T') << endl;
  cout << "RE x " << count(str.cbegin(), str.cend(), 'R') << endl;
} 



Measured memory_bytes: 3764
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int t=1;
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			boolean[][][] c = new boolean[7][7][7];
			for(int z=1;z<=5;z++){
				for(int i=1;i<=5;i++){
					char[] aa = sc.next().toCharArray();
					for(int j=1;j<=5;j++){
						if(aa[j-1]=='1') c[z][i][j] = true;
					}
				}
			}
			
			int an = sc.nextInt();
			ArrayList<Integer> a = new ArrayList<Integer>();
			for(int i=0;i<an;i++) a.add(sc.nextInt());
			int bn = sc.nextInt();
			ArrayList<Integer> b = new ArrayList<Integer>();
			for(int i=0;i<bn;i++) b.add(sc.nextInt());
			
			int cnt;
			for(int nn=0;nn<n;nn++){
				boolean[][][] temp = new boolean[7][7][7];
				for(int z=1;z<=5;z++){
					for(int i=1;i<=5;i++){
						for(int j=1;j<=5;j++){
							cnt = 0;
							for(int p=-1;p<=1;p++){
								for(int q=-1;q<=1;q++){
									for(int r=-1;r<=1;r++){
										if(p==0 && q==0 && r==0) continue;
										if(c[z+p][i+q][j+r]==true) cnt++;
									}
								}
							}
							if(c[z][i][j]==false && a.contains(cnt)==true){
								temp[z][i][j] = true;
							}else if(c[z][i][j]==true && b.contains(cnt)==false){
								temp[z][i][j] = false;
							}else{
								temp[z][i][j] = c[z][i][j];
							}
						}
					}
				}
				for(int z=1;z<=5;z++){
					for(int i=1;i<=5;i++){
						for(int j=1;j<=5;j++){
							c[z][i][j] = temp[z][i][j];
						}
					}
				}
			}
			
			if(t!=1) System.out.println();
			System.out.println("Case " + t + ":");
			for(int z=1;z<=5;z++){
				for(int i=1;i<=5;i++){
					for(int j=1;j<=5;j++){
						if(c[z][i][j]==true) System.out.print(1);
						else System.out.print(0);
					}
					System.out.println();
				}
				if(z!=5) System.out.println();
			}
			t++;
		}
	}

}

Measured memory_bytes: 39916
mod=10**9+7
n=int(input())
dp=[[0]*64 for _ in range(n+1)]
dp[0][0]=1
#3前、2前,1前,今の文字
#t=0,a=1,g=2,c=3
ban_list=[]
for i in range(256):
	p=[i//64%4,i//16%4,i//4%4,i%4]
	if p[1:]==[1,2,3] or p[1:]==[1,3,2] or p[1:]==[2,1,3]\
	or (p[:2]==[1,2] and p[3]==3) or (p[0]==1 and p[2:]==[2,3]):
		ban_list.append(i)
for i in range(n):
	for j in range(4):
		for k in range(64):
			three=k*4%64+j
			four=k*4+j
			if four not in ban_list:
				dp[i+1][three]+=dp[i][k]
				dp[i+1][three]%=mod
ans=0
for x in dp[-1]:
	ans+=x
	ans%=mod
print(ans)

Measured memory_bytes: 9152
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

// CHECK THE LIMITS
typedef long long ll;

static const int NMAX = 1e5;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int a,b,c;
    cin >> a >> b >> c;
    cout << max(c - (a-b),0);


    return 0;
}

Measured memory_bytes: 256
#include"iostream"
#include"vector"
using namespace std;
int main()
{
  vector<int> branch;
  int n;
  cin>>n;
  for(int i=0;i<n;i++)
    {
      int num;
      cin>>num;
      branch.push_back(num);
    }
  for(int i=0;i<branch.size();i++)
    {
      cout<<"node "<<i+1<<": key = "<<branch[i]<<", ";
      if(i>0)
        {
          cout<<"parent key = "<<branch[(i+1)/2-1]<<", ";
        }
      if(i*2+1<n)
        {
          cout<<"left key = "<<branch[i*2+1]<<", ";
        }
      if(i*2+2<n)
        {
          cout<<"right key = "<<branch[i*2+2]<<", ";
        }
      cout<<endl;
    }
  return 0;
}


Measured memory_bytes: 3092
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <vector>
using namespace std;
const int N=1005;
char a[N];
int main ()
{
	scanf("%s",&a);
	int len=strlen(a);
	for(int i=0;i<len;i++){
		if(a[i]=='C')
		    for(int j=i+1;j<len;j++)
		        if(a[j]=='F'){
		        	printf("Yes\n");
		        	return 0;
				}
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 256
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;
import std.bigint;


void main()
{
  double w, h;
  long x, y;
  readf("%s %s %s %s\n", &w, &h, &x, &y);
  int n;
  if (2 * x == w && 2 * y == h) n++;
  writefln("%.12f %s", w * h / 2, n);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
void knapsack(int n,ll W,ll *w,ll *v )
{
  ll m=0;
  for(int i=0;i<n;i++)
  {
    m+=v[i];
  }
  ll dp[n][m+1];
  ll max=1e9+5;
  for(int i=0;i<=m;i++)
  {
    if(i==v[0])
    {
      dp[0][i]=w[0];

    }
    else
    {
      dp[0][i]=max;
    }
  //  cout<<dp[0][i]<<"   ";
  }
  dp[0][0]=0;
  //cout<<endl;
/*  for(int i=1;i<n;i++)
  {
    for(int j=0;j<=m;j++)
    {
      if(j>=v[i])
      {
        dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
      }
      else
      {
        dp[i][j]=dp[i-1][j];
      }
    }
  }*/
  for(int i = 1; i < n; i++){
        for(int j = 0; j <= m; j++){
            dp[i][j] = dp[i-1][j];
            int left = j - v[i];
            if(left >= 0){
                dp[i][j] = min(dp[i][j], dp[i-1][left]+w[i]);
            }
          //  cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
  ll ansj=0;
  for(int i=0;i<=m;i++)
  {
    if(dp[n-1][i]<=W)
    {
      if(i>ansj)
        ansj=i;

    }
  }
  cout<<ansj<<endl;

}
int main()
{
  int n;
  ll W;
  cin>>n>>W;
  ll w[n],v[n];
  for(int i=0;i<n;i++)
  {
    cin>>w[i]>>v[i];
  }
  knapsack(n,W,w,v);
}


Measured memory_bytes: 78336
#include <iostream>
#include <vector>
#include <algorithm>
#define MOD (1000000007l)

using namespace std;

// a 散歩領域に含まれ、始点が左、終点が右
// b 散歩領域に含まれ、始点も終点も左
// c 散歩領域に含まれ、始点も終点も右

// d 散歩領域に含まれず、まだ散歩を開始していない
// e 散歩領域に含まれず、すでに散歩を終了している

long L;
vector<long> Avec;

vector<long> a;
vector<long> b;
vector<long> c;
vector<long> d;
vector<long> e;

int main(void) {
  cin >> L;
  for (long i = 0; i < L; i++) {
    long tmp;
    cin >> tmp;
    Avec.push_back(tmp);
  }
  a.push_back(Avec[0] == 0 ? 1 : (Avec[0] + 1) % 2);
  b.push_back(Avec[0] == 0 ? 2 : Avec[0] % 2);
  c.push_back(Avec[0] == 0 ? 2 : Avec[0] % 2);
  d.push_back(Avec[0]);
  e.push_back(Avec[0]);
  for (long i = 1; i < L; i++) {
    long next_a = min(min(a[i-1], c[i-1]), d[i-1]) + (Avec[i] == 0 ? 1 : (Avec[i] + 1) % 2);
    a.push_back(next_a);
    long next_b = min(min(min(a[i-1], b[i-1]), c[i-1]), d[i-1]) + (Avec[i] == 0 ? 2 : Avec[i] % 2);
    b.push_back(next_b);
    long next_c = min(c[i-1], d[i-1]) + (Avec[i] == 0 ? 2 : Avec[i] % 2);
    c.push_back(next_c);
    long next_d = d[i-1] + Avec[i];
    d.push_back(next_d);
    long next_e = min(min(min(min(a[i-1], b[i-1]), c[i-1]), d[i-1]), e[i-1]) + Avec[i];
    e.push_back(next_e);
  }

  long ans = min(min(min(min(a[L-1], b[L-1]), c[L-1]), d[L-1]), e[L-1]);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 12656
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
 
class Main{
public static void main(String[] args) throws IOException{
final int[] alphas={1,3,5,7,9,11,15,17,19,21,23,25};
final int[] betas={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25};
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> array=new ArrayList<String>();
HashMap<Character,Character> dic=new HashMap<Character,Character>();
int ga;
int gb;
String line;
int n=Integer.parseInt(br.readLine());
while(n-->0){
ga=0;
gb=0;
line=br.readLine();
char[] chararray=line.toCharArray();
for(String s : line.split(" ")){
if(s.length()==4){
array.add(s);
}
}
outside: for(int p=0;p<array.size();p++){
         char[] uc=array.get(p).toCharArray();
         for(int a=0;a<alphas.length;a++){
         for(int b=0;b<betas.length;b++){
         char ct=(char)((alphas[a]*('t'-97)+betas[b])%26+97);
         char ch=(char)((alphas[a]*('h'-97)+betas[b])%26+97);
         char ci=(char)((alphas[a]*('i'-97)+betas[b])%26+97);
         char cs=(char)((alphas[a]*('s'-97)+betas[b])%26+97);
         char ca=(char)(betas[b]%26+97);
         if(uc[0]==ct&&uc[1]==ch){
         if((uc[2]==ci&&uc[3]==cs)||(uc[2]==ca&&uc[3]==ct)){
         ga=alphas[a];
         gb=betas[b];
         break outside;
         }
         }
         }
         }
         }
for(int i=0;i<26;i++){
char nc=(char)((ga*i+gb)%26+97);
char c=(char)(i+97);
dic.put(nc,c);
}
for(int i=0;i<chararray.length;i++){
if(chararray[i]>='a'&&chararray[i]<='z'){
chararray[i]=dic.get(chararray[i]);
}
}
System.out.println(chararray);
array.clear();
dic.clear();
}
}
}

Measured memory_bytes: 17808
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main(){
  int n,k;cin>>n>>k;
  string s;cin>>s;
  int count=0;
  int now=1;
  vector<int> Nums;
  int i,j;

  for(i=0;i<n;i++){
    if(s[i]-'0'==now) count++;
    else{
      Nums.push_back(count);
      now=1-now;
      count=1;
    }
  }

  if(count!=0) Nums.push_back(count);
  //cout<<Nums.size()<<endl;
  /*for(i=0;i<Nums.size();i++){
    cout<<Nums.at(i);
  }*/
  //cout<<endl;
  int add=2*k+1;
  int ans=0;

  for(i=0;i<Nums.size();i+=2){
    int tmp=0;

    int left=i;
    int right=min(i+add,(int)Nums.size());
    for(j=left;j<right;j++){
      tmp+=Nums[j];
    }
    //cout<<tmp<<endl;
    ans=max(ans,tmp);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VS = vector<string>;
using graph = vector<vector<int>>;
int main()
{
string s;
bool a=true;
cin>>s;
int str=s.length();
for (int i = 0; i < str; i++)
{
   for (int j = 0; j < str; j++)
   {
       if (s.at(i)==s.at(j)&&i!=j)
       {
        a=false;
       }
     
   }
    
}
if (a==true)
{
    cout<<"yes"<<endl;
}
else
{
    cout<<"no"<<endl;
}

    return 0;
}

Measured memory_bytes: 256
import sys

a, b = map(int, sys.stdin.readline().split())
s = sys.stdin.readline().rstrip()

def main():
    return 'Yes' if s[a] == '-' and not '-' in set(s[:a] + s[a+1:]) else 'No'

if __name__ == '__main__':
    ans = main()
    print(ans)

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

int main(){
  int N,j=0;
  string S;
  cin>>N>>S;
  for(int i=0;i<N-2;i++)
    if(S.at(i)=='A' && S.at(i+1)=='B' && S.at(i+2)=='C')
      j++;
  cout<<j<<endl;
}

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

using namespace std; 

#define nl "\n"
#define sp " "
#define pb push_back
#define int long long
#define hashset unordered_set
#define llMin LLONG_MIN
#define llMax LLONG_MAX

signed main(){
    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);
    string s; cin >> s;
    int best = 0, counter = 0;
    for (int i = 0; i < s.size(); i++){
        if (s[i] == 'R'){
            counter++;
        }
        else {
            best = max(best, counter);
            counter = 0;
        }
    }
    best = max(best, counter); cout << best;
}

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

char w[105];
int cnt[26];

int main(){

	scanf("%s",w);

	int len=strlen(w);

	int i;

	for(i=0;i<len;i++){
	cnt[w[i]-'a']++;
	}

	int ans=1;
	for(i=0;i<26;i++){
		if(cnt[i]%2==1){ans=0;}
	}
	if(ans==1){printf("Yes\n");}
	else{printf("No\n");}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int X, A, B; cin >> X >> A >> B;
    if (A-B >= 0) cout << "delicious" << endl;
    else if ((X+A) < B) cout << "dangerous" << endl;
    else cout << "safe" << endl;
}

Measured memory_bytes: 256
def debug_print_joined(l):
    for col in l:
        print("".join(col))


def solve(): # Picture Frame
    H, W = list(map(int, input().split(" ")))
    A = []
    for _ in range(H):
        A.append(list(input()))

    for i in range(H):
        A[i].insert(0, "#")
        A[i].append("#")

    A.insert(0, ["#" for _ in range(W + 2)])
    A.append(["#" for _ in range(W + 2)])

    debug_print_joined(A)


solve()

Measured memory_bytes: 3064
N = int(input())
A = input().split(' ')
for i in range(N):
  A[i] = int(A[i])
cnt = 0
for i in range(N):
  if A[i]<0:
    cnt += 1
if cnt%2==0:
  rlt = 0
  for i in range(N):
    rlt += abs(A[i])
else:
  sml = 0
  for i in range(N-1):
    if abs(A[sml])>abs(A[i+1]):
      sml = i+1
  rlt = 0
  for i in range(N):
      if i != sml:
        rlt += abs(A[i])
      else:
        rlt += -(abs(A[i]))
print(rlt)

Measured memory_bytes: 11540
#include <cstdio>
using namespace std;
int main(){
    unsigned int a,b;
    scanf("%d %d",&a,&b);
    if(a%2==0 && b%2==0){
        printf("Even");
    }
    else if(a%2==0 && !(b%2==0)){
        printf("Even");
    }
    else if(!(a%2==0) && b%2==0){
        printf("Even");
    }
    else{
        printf("Odd");
    }
    return 0;
}


Measured memory_bytes: 128
//C - Sum of product of pairs
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>

#define LL long long
#define Lowbit(X) (X&(-X))
#define Lson (X<<1)
#define Rson (X<<1|1)
#define Cl(X,Y) memset((X),(Y),sizeof(X))
#define FOR(i,A,B) for(LL i=A;i<=B;i++)
#define BOR(i,A,B) for(LL i=A;i>=B;i--)
#define FOR_SIDE(i,A) for(LL i=Head[A];i;i=Next[i])
#define INF 0x7fffffff
#define MOD 1000000007
using namespace std;
const LL MAXN=2e5+10;

LL Num[MAXN],Total,Ans,Pre[MAXN];

inline void File() {
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
}

int main() {
    //File();
	scanf("%lld",&Total);
	FOR(i,1,Total) {
		scanf("%lld",&Num[i]);
		Pre[i]=(Pre[i-1]+Num[i])%MOD;
	}
	FOR(i,1,Total-1) 
		(Ans+=(Num[i]*(Pre[Total]-Pre[i])%MOD)%MOD)%=MOD;
	cout<<(Ans%MOD+MOD)%MOD<<endl;
    //fclose(stdin); fclose(stdout);
    //system("pause");
    return 0;
}


Measured memory_bytes: 6884
#include<bits/stdc++.h>
 using namespace std;
  int main()
  {
      int x,d;
       cin>>x>>d;
      vector<double>v;
      for(int i=0; i<x; i++)
      {
           int a, b;
            cin>>a>>b;
             double q= sqrt(pow(a,2)+pow(b,2));
             v.push_back(q);
      }
       int count=0;
       for(int i=0; i<v.size(); i++)
       {
            if(v[i]<=d)
            count++;
       }
        cout<<count<<endl;
       
  }

Measured memory_bytes: 5372
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int a,b;
	cin>>a>>b;
	if (a<=0&&b>=0) puts("Zero");
	else if (a<0&&b<0&&(b-a)%2==0) puts("Negative");
	else puts("Positive");
	return 0;
} 

Measured memory_bytes: 256
n = int(input())
t = [0] * (n+1)
x = [0] * (n+1)
y = [0] * (n+1)

result = "Yes"

for i in range(1, n+1):
    t[i], x[i], y[i] = map(int, input().split())

for i in range(n + 1):
    if i == 0:
        continue
    time = t[i] - t[i-1]
    kyori = abs(x[i] - x[i-1]) + abs(y[i] - y[i-1])
    if time < kyori:
        result = "No"
        break
    elif t[i] % 2 != (x[i] + y[i]) % 2:
        result = "No"
        break

print(result)


Measured memory_bytes: 11636
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;

void main(){
	while(true) {
		auto nm = readInts();
		auto N = nm[0];
		auto M = nm[1];
		if((N|M) == 0) return;

		auto r = readInt();
		auto login = new short[][](M, 721);
		for(int i; i < r; ++i) {
			auto tnms = readInts();
			auto t = tnms[0]-540;
			auto n = tnms[1];
			auto m = tnms[2]-1;
			auto s = tnms[3];
			if(s == 1) {
				++login[m][t];
			} else {
				--login[m][t];
			}
		}
		for(int i; i < M; ++i) {
			for(int j = 1; j < login[i].length; ++j) {
				login[i][j] += login[i][j-1]; 
			}
		}
		auto q = readInt();
		for(int i; i < q; ++i) {
			auto sem = readInts();
			auto ts = sem[0]-540;
			auto te = sem[1]-540;
			auto m = sem[2]-1;
			writeln(login[m][ts..te].filter!(a => a > 0).array.length);
		}
	}
}

Measured memory_bytes: 52536
/* competitive programming circle traP */
/* template */
#include <stdio.h>

int main(){
  // initialize
  int dp[31];
  dp[0] = 1;
  dp[1] = 1;
  dp[2] = 2;
  for(int n=3;n<=30;n++){
    dp[n] = dp[n-1];
    dp[n] += dp[n-2];
    dp[n] += dp[n-3];
  }
  for(int n=0;n<=30;n++){
    dp[n] = (dp[n]+3650-1)/3650;
  }
  // in/out
  while(true){
    int n;
    scanf("%d",&n);
    if(n==0)break;
    printf("%d\n",dp[n]);
  }
  return 0;
}

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

S = input()
N = len(S)

# dp[i] := i文字目までをS=Tとすることができるか
dp = [0] * (N + 9)
dp[0] = 1
for i in range(N):
    if dp[i]:
        if S[i:i+5] == 'dream':
            dp[i+5] = 1
        if S[i:i+7] == 'dreamer':
            dp[i+7] = 1
        if S[i:i+5] == 'erase':
            dp[i+5] = 1
        if S[i:i+6] == 'eraser':
            dp[i+6] = 1
if dp[N]:
    YES()
else:
    NO()


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

int main() {
  int N;
  cin >> N;
  vector<long double>x(N);
  vector<long double>y(N);
  long double sum = 0, num;
  for (int i = 0; i < N; i++) {
    cin >> x.at(i) >> y.at(i);
  }
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      num = (x.at(i) - x.at(j)) * (x.at(i) - x.at(j)) + (y.at(i) - y.at(j)) * (y.at(i) - y.at(j));
      sum += sqrtl(num);
    }
  }
  cout << fixed;
  cout << setprecision(6) << sum * 2 / N;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

int n;
ll X[100100], Y[100100];
ll f(ll n) {
    ll t = n;
    while(n) {t--; n&=n-1;}
    return t;
}
int comb(ll n, ll r) {
    if (r<0||r>n) return 0;
    return !(f(n)-f(r)-f(n-r));
}

const ll M = 1LL<<57;

int cal(ll x) {
    int i, t = 0;
    for (i=0;i<n;i++) t ^= comb(Y[i]+M*2-1,x-X[i]);
    return t;
}

int main() {
    int i;

    scanf("%d",&n);
    for (i=0;i<n;i++) scanf("%lld%lld",&X[i],&Y[i]);
    ll s = -M, e = M;
    while(s<=e) {
        ll m = (s+e)/2;
        if (cal(m)) e = m-1;
        else s = m+1;
    }
    printf("%lld\n",s);

    return 0;
}


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

typedef long long ll;

ll n;
vector<ll> bit(200010,0);
void init() {
    fill(bit.begin(),bit.end(),0);
}
void add(ll a, ll w) {
	for (ll x = a;x <= n+n+1;x += x&-x) bit[x] += w;
}
ll sum(ll a) {
	ll ret = 0;
	for (ll x = a;x > 0;x -= x&-x) ret += bit[x];
	return ret;
}

int main() {
    cin >> n;
    vector<ll> a(n,0),sums(n+1,0);
    for (ll i = 0;i < n;++i) cin >> a[i];

    ll min = 0,max = *max_element(a.begin(),a.end())+1;

    while (1) {
        ll mid = min+(max-min)/2;
        for (ll i = 0;i < n;++i) sums[i+1] = (mid > a[i]) ? -1 : 1;
        for (ll i = 0;i < n;++i) sums[i+1] += sums[i];

        init();
        ll ret = 0;
        for (ll i = n;i >= 0;--i) {
            ret += n-i-sum(sums[i]+n);
            add(sums[i]+n+1,1);
        }
        //cout << min << " " << max << " " << mid << " " << ret << "\n";
        if (ret < (1+n*(n+1)/2)/2) max = mid;
        else if (min == mid) break;
        else min = mid;
    }
    cout << min << endl;
}

Measured memory_bytes: 3456
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")

// #pragma GCC optimize("O3")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  string s;
  cin >> s;
  int ans = 0;
  int c = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == 'R')
      c++;
    else
      c = 0;
    ans = max(ans, c);
  }
  cout << ans << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    REP(i,N) cin >> S[i];
    map<string,int> mp;
    int maxi = 0;
    REP(i,N) {
        if ( mp.count(S[i]) == 0) {
            mp[S[i]] = 1;
        } else {
            mp[S[i]]++;
        }
        chmax(maxi,mp[S[i]]);
    }

    vector<string> ans;
    for (auto & itr : mp) {
        if (itr.second == maxi) {
            ans.push_back(itr.first);
        }
    }

    sort(ALL(ans));

    REP(i,ans.size()) {
        cout << ans[i] << endl;
    }





    return 0;
}


Measured memory_bytes: 29940
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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 <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

signed main() {
  ll K, X;
  cin >> K >> X;
  if (500 * K >= X) {
    COUT("Yes");
  } else {
    COUT("No");
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
struct item{
	ll wt;
	ll val;
};
ll dp[105][100005];
ll knapsack(ll wt,ll n,vector<item> &things){
	if(wt == 0 || n == 0){
		return 0;
	}
	if(dp[n][wt]!=-1){
		return dp[n][wt];
	}
	ll ans1 = knapsack(wt,n-1,things);
	ll ans2 = INT_MIN;
	if(things[n-1].wt<=wt){
		ans2 = things[n-1].val+knapsack(wt-things[n-1].wt,n-1,things);
	}
	return dp[n][wt] = max(ans1,ans2);
}
int main(int argc,char const* argv[]){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	ll n,w;
	cin>>n>>w;
	vector<item> things(n);
	for(int i=0;i<n;i++){
		cin>>things[i].wt>>things[i].val;
	}
	memset(dp,-1,sizeof(dp));
	cout<<knapsack(w,n,things)<<endl;
	return 0;
}

Measured memory_bytes: 85668
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fi first
#define se second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>
 
using std::cin;
using std::cout;
using std::endl;
 
typedef long long ll;
typedef unsigned long long ull;
 
const int N = 100000 + 5;
const int M = 1000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int LOG = 40;
const ull BASE = 19260817;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
// const double PI = acos(-1);
const double PI = 3.14159;

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
 
template<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

namespace Comb{
const int N = 10 + 5;
inline void exgcd(ll a, ll b, ll &g, ll &x, ll &y) {
    if (!b) g = a, x = 1, y = 0;
    else exgcd(b, a % b, g, y, x), y -= x * (a / b);
}
 
inline ll inv(ll a) {
    ll g, res, tmp;
    exgcd(a, MOD, g, res, tmp);
    return ((res % MOD) + MOD) % MOD;
}
 
ll f[N], invFact[N];
 
inline void prepare() {
    f[0] = 1;
    int n = 200000;
    for (int i = 1; i <= n; i++) f[i] = f[i - 1] * i % MOD;
    invFact[n] = inv(f[n]);
    for (int i = n - 1; i >= 1; i--) invFact[i] = invFact[i + 1] * (i + 1) % MOD;
}
 
inline ll C(int n, int m) {
    if (!m) return 1;
    if (n == m) return 1;
    if (m > n) return 0;
    if (m < 0) return 0;
    return f[n] * invFact[m] % MOD * invFact[n - m] % MOD;
}
}

int n;
std::set< String > set;

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        String tmp;
        cin >> tmp;
        set.insert(tmp);
    }
    // printf("%d\n", (int)set.size());
    puts(set.size() == 3 ? "Three" : "Four");
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int X = scanner.nextInt();
		int t = scanner.nextInt();
		int result = 0;

		if (X > t) {
			result = X - t;
		}
		System.out.println(result);
	}

}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1000000007;
const long long 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;
}

int main()
{
    int n; cin >> n;
    
    bool is_ap = true;
    for(int i=0;i<n;i++){
        int a; cin >> a;
        if(a%2)continue;
        if(a%3 && a%5){
            is_ap = false;
            break;
        }
    }
    cout << (is_ap? "APPROVED":"DENIED")<< endl;
}
    

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

public class Main{
  public static void main(String args[]){
      String str ;
      BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
       try {
            str = reader.readLine();
            reader.close();
         	String[] astr = str.split(" ");
      long n = Long.parseLong(astr[0]);
      long k = Long.parseLong(astr[1]);
      double result = 0;
      for(long i = 1; i <= n; i++){
          long p = 0, a = i;	
          while(a < k){
              a = a * 2;
              p++;
          }
          double tmp = 0.5;
          for(long j = 1; j < p; j++){
              tmp = tmp * 0.5;
          }
        if(p != 0)
          result = result + tmp;
        else
          result = result + 1;
      }
      result = result / n;
      System.out.print(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
  }
}


Measured memory_bytes: 21460
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

N = int(input())

count = 0
for i in range(105, N+1, 2):
    div_i = make_divisors(i)
    if len(div_i) == 8:
        count += 1

print(count)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void){
  int N,M,A[10000],i,j;
  
  scanf("%d %d", &N,&M);
  for(i=0;i<M;i++){
    scanf("%d", &A[i]);
  }
  
  for(j=0;j<M;j++){
    N=N-A[j];
    if(N<0){
      printf("-1");
      break;
    }
  }
  if(N>=0){
    printf("%d", N);
  }
  return 0;
}

Measured memory_bytes: 1740
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var t=sc.S;
		var m=sc.I;
		var a=sc.Ia;
		var ans=new long[m];
		for(int i = 0;i<m;i++) {
			var h=new long[3];
			for(int j = 0;j<n;j++) {
				if(t[j]=='D'){
					h[0]++;
				}
				else if(t[j]=='M'){
					h[1]++;
					h[2]+=h[0];
				}
				else if(t[j]=='C'){
					ans[i]+=h[2];
				}
				if(j>=a[i]-1){
					if(t[j-a[i]+1]=='D'){
						h[0]--;
						h[2]-=h[1];
					}
					else if(t[j-a[i]+1]=='M'){
						h[1]--;
					}
				}
			}
		}
		Console.WriteLine("{0}",String.Join("\n",ans));
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 16992
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

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

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> A(N-1);
  rep(i, N-1) cin >> A[i];
  vector<int> answer(N, 0);
  rep(i, N-1) {
    ++answer[A[i]-1];
  }
  rep(i, N) {
    cout << answer[i] << '\n';
  }
}


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

using namespace std;
long long int N, A[200000], B[200000], C[200000];

int main()
{
    scanf("%d", &N);
    for(int i = 0;i < N;i++)
        scanf("%lld", &A[i]);
    for(int i = 0;i < N;i++)
        scanf("%lld", &B[i]);
    for(int i = 0;i < N;i++)
        scanf("%lld", &C[i]);

    sort(A, A+N);
    sort(B, B+N);
    sort(C, C+N);
    long long int ans = 0;
    for(int ib = 0;ib < N;ib++){
        auto lb = lower_bound(A, A+N, B[ib]), ub = upper_bound(C, C+N, B[ib]);
        ans += (lb - A) * ((C + N) - ub);
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main(){
    
    int N; cin >> N;
    int data[N],list[N];
    for(int i=0;i<N;i++){int a;cin >> a; data[i] = a; list[i] = a;}
    sort(data,data+N);
    int l,r;
    l = data[(N-1)/2];
    r = data[N/2];
    for(int i=0;i<N;i++){
        if(list[i] <= l) cout << r <<endl;
        else cout << l << endl;
    }
}

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

void topological_sort(vector<vector<int>> &adj, stack<int> &sorted, vector<int> &visited, int i){
    visited[i] = 1;
    for(int j = 0 ; j < adj[i].size() ; j++){
        if(!visited[adj[i][j]])topological_sort(adj, sorted,  visited, adj[i][j]);
    }
    sorted.push(i);
}

int main() {
    int n, m;
    cin>>n>>m;
    vector<int> t;
    vector<vector<int>> adj(n + 1, t);
	for(int i = 0 ; i < m ; i++){
	    int x,y;
	    cin>>x>>y;
	    adj[x].push_back(y);
	}
	vector<int> visited(n+1, 0);
	stack<int> sorted;
	
	for(int i = 1 ; i <= n ; i++){
	    if(visited[i] == 0)topological_sort(adj, sorted, visited, i);
	}
	int d[n+1] = {0};
	int ans = 0;
	while(!sorted.empty()){
	    int x = sorted.top();
	    sorted.pop();
	    for(int i = 0 ; i < adj[x].size() ; i++){
	        d[adj[x][i]] = max(d[adj[x][i]], d[x] + 1);
	    }
	}
	for(int i = 1 ; i <= n ; i++){
	    ans = max(ans, d[i]);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 9216
local mod = 1000000007
local function badd(x, y) return (x + y) % mod end
local function bsub(x, y) return y <= x and x - y or x + mod - y end
local n, k = io.read("*n", "*n")
local dp1, dp2 = {1}, {0}
for i = 2, k + 1 do
  dp1[i] = 0
  dp2[i] = 0
end
for i = 1, n do
  local src = i % 2 == 1 and dp1 or dp2
  local dst = i % 2 == 1 and dp2 or dp1
  for j = 1, k + 1 do
    dst[j] = 0
  end
  local a = io.read("*n") + 1
  local sum = 0
  for j = 1, k + 1 do
    sum = badd(sum, src[j])
    if a < j then
      sum = bsub(sum, src[j - a])
    end
    dst[j] = badd(dst[j], sum)
  end
end
local ret = n % 2 == 1 and dp2 or dp1
print(ret[k + 1])


Measured memory_bytes: 2560
module Main where

import Data.List
import Control.Monad
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust, catMaybes)
import qualified Data.Vector as V


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = do
    strs <- BC.words  <$> BC.getLine
    let bcList = catMaybes $ (BC.readInt <$> strs)
    pure $ fst <$> bcList

onOffLists :: Int -> Int -> [[Int]]
onOffLists i m = if i == m then [[0], [1]] else
    let
        prevLists = onOffLists (i + 1) m
    in
        [(1:), (0:)] <*> prevLists

checkVector :: [([Int], Int)] -> V.Vector Int -> Bool
checkVector ss v = all checker ss where
    checker (s,p) = ((foldr (\si acc -> (v V.! (si - 1) ) + acc ) 0 s) `mod` 2) == p

main = do
    [r, g, b, n] <- readInts
    let maxR =  n `div` r
    let ans = foldr (\rNum acc ->
            acc + foldr (\gNum acc -> 
                if (n - rNum * r - gNum * g) `mod` b == 0 then 1 + acc else 0 + acc
                ) 0 [0..(n - rNum * r) `div` g]
            ) 0 [0..maxR]
    print ans



Measured memory_bytes: 1276
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <assert.h>
#define BUF_SIZE 30

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

struct list {
    struct list *next;
    int v;
};
#define VERTEX_MAX 200000
struct list *create_graph(int size) {
    struct list *graph = malloc(sizeof(struct list)*size);
    int i;
    for(i = 0; i < size; i++) {
        graph[i].next = &graph[i];
    }
    return graph;
}

// be careful, multiply by 2 because execute insert() twice
struct list pool[VERTEX_MAX*2];
int idx = 0;

struct list *get_list(void) {
    assert(idx+1 < VERTEX_MAX*2);
    return &pool[idx++];
}

void insert(struct list *graph, int size, int src, int dst) {
    assert(src < size);
    assert(dst < size);
    struct list *head = &graph[src];
    struct list *elem = get_list();
    elem->v = dst;
    elem->next = head->next;
    head->next = elem;
}

int stack[VERTEX_MAX+1];
int pos;

void push(int node) {
    stack[pos++] = node;
    return;
}

int is_empty(void) {
    return !pos;
}

int pop(void) {
    assert(pos >= 1);
    return stack[--pos];
}

int peek(void) {
    assert(pos >= 1);
    return stack[pos-1];
}

// 1-indexed
int dfs(struct list *graph, int *profit, int *ans, int size) {
    int start = 1;
    static char checked[VERTEX_MAX+1];
    static struct list *cache[VERTEX_MAX+1] = {0};
    push(start);
    checked[start] = 1;
    ans[start] = profit[start];
    while(!is_empty()) {
        int v = peek();
        struct list *head = &graph[v];
        struct list *elem = (cache[v] != NULL) ? cache[v] : head->next;
        int flag = 0;
        for(; elem != head; elem = elem->next) {
            int nv = elem->v;
            if(!checked[nv]) {
                // calc ans
                ans[nv] = profit[nv] + ans[v];
                push(nv);
                checked[nv] = 1;
                cache[v] = elem;
                flag = 1; break;
            }
        }
        if(!flag) pop();
    }
    return 0;
}

int main(void) {
    int vs, queries;
    get_int2(&vs, &queries);

    struct list* graph = create_graph(vs+1);
    int i;
    for(i = 0; i < vs-1; i++) {
        int v1, v2;
        get_int2(&v1, &v2);
        insert(graph, vs+1,v1, v2);
        insert(graph, vs+1,v2, v1);
    }

    // vertex is 1-indexed.
    int map[VERTEX_MAX+1] = {0};
    for(i = 0; i < queries; i++) {
        int v, point;
        get_int2(&v, &point);
        map[v] += point;
    }
    int sum[VERTEX_MAX+1] = {0};
    if(dfs(graph, map, sum, vs) == -1) return 0;

    // presentation
    for(i = 1; i <= vs; i++) {
        int end = (i == vs);
        printf("%d%c", sum[i], end ? '\n' : ' ');
    }

    return 0;
}

Measured memory_bytes: 15744
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[11];
    cin>>s;
    int l=strlen(s);
    int mx=10000;
    for(int i=0;i<l-2;i++)
    {
        int x=(s[i]-'0')*100;
        int y=(s[i+1]-'0')*10;
        int z=(s[i+2]-'0');
        int ans=753-(x+y+z);
        if(abs(ans)<mx)
        {
            mx=abs(ans);
        }
    }
    cout<<mx<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
x = list(map(int, input().split()))
 
n = len(x)
 
sum_a = 0
sum_b = 0
 
for xi in x:
  sum_a += (xi*xi)
  sum_b += xi

p = int(sum_b/n+0.5)
ans = sum_a - 2*sum_b*p+n*p*p

min_ans = 10**9
if ans > min_ans:
    ans = min_ans
print(int(ans))

Measured memory_bytes: 3064