akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

const int MAX_N = 200000;

int f[MAX_N + 3], g[MAX_N + 3], h[MAX_N + 3];
char s[MAX_N + 3];

inline int modPow(int a, int b, int c) {
  int ret = 1;
  for (; b; b >>= 1, a = static_cast<long long>(a) * a % c)
    if (b & 1) ret = static_cast<long long>(ret) * a % c;
  return ret;
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  int n, ones = 0;
  std::cin >> n >> (s + 1);

  for (int i = 1; i <= n; ++i) ones += s[i] == '1';
  for (int i = 1; i <= ones + 1; ++i) f[i] = f[i % __builtin_popcount(i)] + 1;
  if (ones == 1) {
    for (int i = 1; i <= n; ++i) {
      if (s[i] == '1') {
        std::cout << "0\n";
      } else {
        s[i] = '1';
        std::cout << static_cast<int>(s[n] == '1') + 1 << '\n';
        s[i] = '0';
      }
    }
    return 0;
  }
  for (int i = n; i; --i) {
    if (s[i] == '1') {
      g[i] = (g[i + 1] + modPow(2, n - i, ones + 1)) % (ones + 1);
      h[i] = (h[i + 1] + modPow(2, n - i, ones - 1)) % (ones - 1);
    } else {
      g[i] = g[i + 1];
      h[i] = h[i + 1];
    }
  }
  int tmp[2]{0, 0};
  for (int i = 1; i <= n; ++i) {
    if (s[i] == '1') {
      std::cout << f[(tmp[1] + h[i + 1]) % (ones - 1)] + 1 << '\n';
    } else {
      std::cout
          << f[(tmp[0] + g[i + 1] + modPow(2, n - i, ones + 1)) % (ones + 1)] +
                 1
          << '\n';
    }
    if (s[i] == '1') {
      tmp[0] = (tmp[0] + modPow(2, n - i, ones + 1)) % (ones + 1);
      tmp[1] = (tmp[1] + modPow(2, n - i, ones - 1)) % (ones - 1);
    }
  }
}

Measured memory_bytes: 5804
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    if((a+b)%2==1){
        cout << (a+b)/2 + 1 << endl;
    }else{
        cout << (a+b)/2 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
ll powMod(ll x, ll k, ll m) {//x^k (mod n)
	if (k == 0)     return 1;
	if (k % 2 == 0) return powMod(x*x % m, k/2, m);
	else            return x*powMod(x, k-1, m) % m;
}
int N;

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a!=c)cout<<1<<endl;
	else cout<<0<<endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;++i)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;

int main(){
  string s;cin>>s;
  string t;int l = 999;
  for(int i=0;i<s.size()-2;i++){
    t = s.substr(i,3);
    l = min(l,abs(753-stoi(t)));
  }
  cout << l << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

ll N,a,b,c,d;
map<ll,ll> cnt;

ll f(ll n) {
  if(n==0) return 0;
  if(cnt.count(n)) return cnt[n];
  ll res=inf;
  if(n*d>0) res=min(res,n*d);
  res=min(res,f(n/2)+a+d*abs(n/2*2-n));
  res=min(res,f(n/3)+b+d*abs(n/3*3-n));
  res=min(res,f(n/5)+c+d*abs(n/5*5-n));
  if((n+1)/2<n) res=min(res,f((n+1)/2)+a+d*abs((n+1)/2*2-n));
  if((n+2)/3<n)res=min(res,f((n+2)/3)+b+d*abs((n+2)/3*3-n));
  if((n+4)/5<n)res=min(res,f((n+4)/5)+c+d*abs((n+4)/5*5-n));
  if(n-1>0) res=min(res,f((n-1)/2)+a+d*abs((n-1)/2*2-n));
  if(n-2>0) res=min(res,f((n-2)/3)+b+d*abs((n-2)/3*3-n));
  if(n-4>0) res=min(res,f((n-4)/5)+c+d*abs((n-4)/5*5-n));
  cnt[n]=res;
  return res;
}

int main() {
  ll t;
  cin >> t;
  while(t--) {
    cnt.clear();
    cin >> N >> a >> b >> c >> d;
    cout << f(N) << endl;
  }
}

Measured memory_bytes: 4780
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int l;
#define fastIO              ios::sync_with_stdio(false), cin.tie(0)
#define pf                  push_front
#define pb                  push_back
#define popb                pop_back()
#define popf                pop_front()
#define loop(i,n)           for(int i=0;i<n;i++)
#define lop(i,n)           for(int i=1;i<n;i++)
#define loops(i,x,n)        for(int i=x;i<n;i++)
#define loopr(i,n)          for(int i=n-1;i>=0;i--)
#define loopt(i,n)          for(int i=0;i<=n;i++)
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define vc vector
#define vll vector<long long>
#define pll pair<long long,long long>
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define INT_BITS 32
#define  st                  l t; cin>>t;
#define  sn                  l n; cin>>n;
#define  unordered_map<l,l>  u;
#define MOD1 1000000007
char c[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
l gcd(l a,l b)
{
    return b==0?a:gcd(b,a%b);
}
int maxSubArray(vector<int>& nums) {
        int msf = INT_MIN,meh = 0;
        for(int i=0;i<nums.size();i++)
        {
            meh = meh + nums[i];
            if(meh<nums[i])
                meh = nums[i];
            if(msf<meh)
                msf = meh;
        }
        return msf;
}
l binaryToDecimal(l n)
{
    l num = n;
    l dec_value = 0;
    l base = 1;

    l temp = num;
    while (temp) {
        l last_digit = temp % 10;
        temp = temp / 10;

        dec_value += last_digit * base;

        base = base * 2;
    }

    return dec_value;
}
/*void bt(int s,int e,int *tree,int ind )
{
    if(s==e)
    {}
}*/
l sum(l a,l b)
{
    return a+b;
}
l frog(l h[],l n,l k)
{
   l dp[n];
   dp[0] = 0;
   for(l i=1;i<n;i++)
   {
       l ans = INT_MAX;
       for(l j=0;j<k;j++){
           l a;
           if((i-j)-1>=0){
        a = dp[(i-j)-1] + abs(h[i]-h[(i-j)-1]);
           }
       dp[i] = min(a,ans);
       ans = min(a,ans);
       }
   }
return dp[n-1];
}
int main()
{
    fastIO;
    l  n,k;
    cin>>n>>k;
    l a[n];
    l h[n];
    for(l i=0;i<n;i++)
    cin>>h[i];
    cout<<frog(h,n,k)<<"\n";

    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int k = sc.nextInt();
		long sum = 0;
		for(int i = 1; i < k+1; i++) {
			for (int m = 1; m < k+1; m++) {
				for(int l = 1; l <k+1; l++) {
					sum +=yu(yu(i,m),l);
				}
			}
		}
		System.out.println(sum);
		
	}
	static int yu(int a, int b) {
		int c;
		while(true) {
			if(b==0) {
				a =0;
				break;
			}
			c = a%b;
			a = b;
			b = c;
			if(c == 0) {
				break;
			}
			
		
		}
		return a;
	}
	
}


Measured memory_bytes: 27112
c(int*a,int*b){return*a-*b;}
char buf[10101];
L[2000];
N,i,j,k,s;
sz;
main()
{
	read(0,buf,10101);
	for(;;)
	{
		k=buf[sz++];
		if(k<'0')break;
		N=N*10+k-'0';
	}
	for(i=0;i<N;i++)
	{
		for(;;)
		{
			k=buf[sz++];
			if(k<'0')break;
			L[i]=L[i]*10+k-'0';
		}
	}
	qsort(L,N,4,c);
	for(i=0;i<N;i++)
	{
		for(j=k=i+1;j<N;j++)
		{
			while(k<N&&L[k]<L[i]+L[j])k++;
			s+=k-j-1;
		}
	}
	printf("%d",s);
}

Measured memory_bytes: 252
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 ln         PIC X(15).
01 A          PIC 9(10).
01 B          PIC 9(10).
01 C          PIC 9(10).
01 D          PIC 9(10).
01 TK         PIC 9(10).
01 AO         PIC 9(10).

PROCEDURE DIVISION.
  ACCEPT ln.
  UNSTRING ln DELIMITED BY SPACE INTO A B C D.
  COMPUTE TK = (C + B - 1) / B
  COMPUTE AO = (A + D - 1) / D
  IF TK <= AO
    DISPLAY "Yes"
  ELSE
    DISPLAY "No"
  END-IF.
  STOP RUN.


Measured memory_bytes: 3940
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int compw(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}

uint32_t nextpint(void){ char c=getchar(); while(c<'0'||'9'<c) c=getchar(); uint_fast32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return x; }

int min2(const int a, const int b){return a>b?b:a;}

char s[100][101];
int d[100][100];
int main(int argc, char *argv[], char *envp[]){
	int h=nextpint();
	int w=nextpint();
	for(int i=0; i<h; i++){
		scanf("%s", s[i]);
	}
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(i!=0 && j!=0){
				int a=d[i][j-1]+(s[i][j]=='#'&&s[i][j-1]=='.');
				int b=d[i-1][j]+(s[i][j]=='#'&&s[i-1][j]=='.');
				d[i][j]=min2(a, b);
			}else if(i!=0){
				d[i][j]=d[i-1][j]+(s[i][j]=='#'&&s[i-1][j]=='.');
			}else if(j!=0){
				d[i][j]=d[i][j-1]+(s[i][j]=='#'&&s[i][j-1]=='.');
			}else{
				d[i][j]=(s[i][j]=='#');
			}
		}
	}
	printf("%d\n", d[h-1][w-1]);
}


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

main(){

int S, a, b, h, m, s;

scanf("%d",&S);

a = S % 3600;
h = (S - a) / 3600;

s = a % 60;
m = (a - b) / 60;

printf("%d:%d:%d\n",h,m,s);

return 0;

}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll a[300005],b[300005][69];
int main(){
    int n;
    cin>>n;

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

    ll ans=0;
    for(int i=0;i<=64;i++){
        b[n][i]=0;
    }

    for(ll i=n-1;i>=0;i--){
        for(ll j=0;j<64;j++){
            if((a[i]&(1ll<<j))!=0){
                b[i][j]=b[i+1][j]+1;
            }
            else{
                b[i][j]=b[i+1][j];
            }
        }
    }

    for(ll i=0;i<n-1;i++){
        for(ll j=0;j<64;j++){
            //cout<<(1ll<<j)<<" "<<b[i+1][j]<<" "<<i<<" "<<j<<" "<<ans<<endl;
            ll x=(1ll<<j);
            if((x&a[i])!=0){
                ans+=(((x%hell)*((n-1-i-b[i+1][j])%hell)))%hell;
            }
            else{
                ans+=(((x%hell)*((b[i+1][j])%hell)))%hell;
            }
            ans=ans%hell;
            if(ans<0)
                ans+=hell;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 164352
import sys,os,math
from collections import Counter, defaultdict, deque
import bisect
from sys import stdin, stdout
from itertools import repeat


# sys.stdin = open('input')
# n, k = map(int, raw_input().split())
# da = map(int, raw_input().split())
# db = map(int, raw_input().split())


def solve():

    pass

def main():
    a, b = map(int, raw_input().split())
    def gcd(a, b):
        if b:
            return gcd(b, a%b)
        return a

    def div(n):
        c = 0
        for i in range(2, int(math.sqrt(n)+1)):
            if n%i==0:
                c += 1
                while n%i==0:
                    n /= i
        if n>1:
            c+=1
        return c+1
    print div(gcd(a,b))





main()


Measured memory_bytes: 29036
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int a, b, c, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> a >> b >> c >> k;

  ll ans = 0;

  while(a >= b) {
    b *= 2;
    ans++;
  }

  while(b >= c) {
    c *= 2;
    ans++;
  }

  cout << (ans <= k ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3608
import sys
import math
import functools
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def lcm(a, b):
    return a * b // gcd (a, b)
def lcm_n(nums):
    return functools.reduce(lcm, nums)
def count_div2(x):
    c = 0
    while x%2 == 0:
        c += 1
        x //= 2
    return c
n, m = na()
a = na()
div2 = count_div2(a[0])
if any([count_div2(ai) != div2 for ai in a]):
    print(0)
else:
    r = lcm_n(a)//2
    b = m//r
    print((b+1)//2)


Measured memory_bytes: 14860
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char a;
	cin>>a;
	if (a=='A') cout<<'T';
	if (a=='T') cout<<'A';
	if (a=='G') cout<<'C';
	if (a=='C') cout<<'G'; 
	return 0;
}

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

using namespace std;

int val[20];

int main(){
    int n,w;

    while(cin >> n >> w){
        if((n|w) == 0) break;
        int maxh=0, maxw = 0, tmp;
        double ret=0;
        memset(val, 0, sizeof(val));

        for(int i=0;i<n;i++){
            cin >> tmp;
            val[tmp/w]++;
            maxw = max(maxw, tmp/w);
            maxh = max(maxh, val[tmp/w]);
        }
        maxw++;
        for(int i=0;i<maxw;i++){
            ret += ((double)(maxw-i-1)/(maxw-1)) * ((double)val[i] / maxh);
        }
        printf("%.7f\n", ret+0.01);
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{
    ll t=1,i,j,a,b,n,x,y,m;
    //cin>>t;
    while(t--)
    {
       double p,q,r,ans;
       cin>>p>>q>>r;
       ans=p/r;
       if(ans<=q)
        cout<<"Yes"<<endl;
       else
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3712
N=int(input())
H=[int(s) for s in input().split(" ")]

#左右差のリストを作成。(+1,-1),(-1,+1)の区間は直せる

List=[]
for i in range(N-1):
    List.append(H[i+1]-H[i])

count=0
for i in range(len(List)):
    count+=List[i]
        
    if count>=1:
        count=0
    if count<=-2:
        count=-2
        break

print("Yes" if count>=-1 else "No")

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

int main()
{
	int i,N,t=0,x=0,y=0;scanf("%d",&N);
	for(i=1;i<=N;i++)
	{
		int lat=t,lax=x,lay=y;
		scanf("%d%d%d",&t,&x,&y);
		int v=t-lat-abs(x-lax)-abs(y-lay);
		if(v<0||v&1) {puts("No");return 0;}
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 256
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;
	vector<int> p(n), q(n), base; fore(e, p) cin >> e; fore(e, q) cin >> e;
	forl(i, 1, n+1) base.push_back(i);
	int counter = 1, made = 0, qc = -1, pc = -1;
	while(true) {
		if(q == base) { made++; qc = counter; }
		if(p == base) { made++; pc = counter; }
		if(made == 2) break;
		counter++; next_permutation(base.begin(), base.end());
	}
	println(abs(qc-pc));
}


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

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

int main(){
    int N, a[110000];
    int tmp=0, sum=0, ans=0;

    scanf("%d", &N);
    for(int i=0; i<N; i++){
        scanf("%d", &a[i]);
    }

    qsort(a, N, sizeof(int), acs);
    a[N]=1000000001;
    ans = N;
    for(int i=0; i<=N; i++){
        if(tmp == a[i]){
            sum++;
        }else{
            if(tmp>sum){
                ans = ans-sum;
            }else if(tmp<sum){
                ans = ans-(sum-tmp);
            }
            tmp = a[i];
            sum = 1;
        }
    }
    printf("%d", N-ans);

    return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
#define MAX_N 200000

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, P> pii;
typedef vector<int> vi;
typedef queue<int> qi;

struct segtree{
  int N;
  P dat[2 * MAX_N - 1];
  segtree(){}
  segtree(int n){
    N = 1;
    while(n > N) N *= 2;

    rep(i, 2 * N - 1) dat[i] = MP(-10000000, -10000000);
    for(int i = N - 1; i < 2 * N - 1; i++) dat[i] = MP(0, -1 * (i - N + 1));
  }

  void update(int k, int a){
    k += N - 1;
    dat[k].F += a;
    while(k > 0){
      k = (k - 1) / 2;
      dat[k] = max(dat[k*2+1], dat[2*k+2]);
    }
  }

  P query(int a, int b){ return query(a, b, 0, 0, N); }
  P query(int a, int b, int k, int l, int r){
    if(r <= a || b <= l) return P(-10000000, -10000000);

    if(a <= l && r <= b) return dat[k];
    else{
      P vl = query(a, b, 2*k+1, l, (l+r)/2);
      P vr = query(a, b, 2*k+2, (l+r)/2, r);
      return max(vl, vr);
    }
  }
};

int res[MAX_N];

int main(){
  int N, R, L;
  scanf("%d%d%d", &N, &R, &L);
  segtree seg(N);
  rep(i, N) seg.update(i, 0);

  int time = 0;
  rep(i, R){
    int d, t, x;
    scanf("%d%d%d", &d, &t, &x); d--;
    P s = seg.query(0, N);
    res[-s.second] += t - time;
    seg.update(d, x);
    time = t;
  }
  P s = seg.query(0, N);
  res[-s.second] += L - time;

  int ans = 0;
  rep(i, N) if(res[ans] < res[i]) ans = i;

  printf("%d\n", ans+1);
  return 0;
}

Measured memory_bytes: 7832
n=int(input())
L=list(map(int, input().split()))
a=max(L)
b=a
c=0
for i in range(n):
	if b>=abs(L[i]-a/2) and L[i]!=a:
		b=abs(L[i]-a/2)
		c=L[i]


print(a,c)


Measured memory_bytes: 20056
/*     ####   ####  #               ####  #        ##   #    # #    # ###### #####
      #      #    # #              #      #       #  #  ##  ## ##  ## #      #    #
       ####  #    # #               ####  #      #    # # ## # # ## # #####  #    #
           # #  # # #                   # #      ###### #    # #    # #      #####
      #    # #   #  #              #    # #      #    # #    # #    # #      #   #
       ####   ### # ###### #######  ####  ###### #    # #    # #    # ###### #    #
*/
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef vector<long long> VLL;
typedef vector<string> VS;
typedef vector<pair<LL, LL> > VP;
 
 
#define For(in) for (LLi i = 0; i < (n); i++)
#define FOR(in) for(LLi i=1; i <= (n); i++)
#define pb push_back
#define sr(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end());
#define exit(); return 0;
#define no "NO"
#define yes "YES"
#define con continue;
 

 
 
int main()
{
	
	long long a,b,c,d;
	//cin>>a;
	string s;
	cin>>s;
	long long x,y=0;
	for(int i=0; i<s.size(); i++)
	{
		if(s[i]=='A')
		{
			x=i;
			break;
		}
	}
	for(int i=s.size()-1; i>=0; --i)
	{
		if(s[i]=='Z')
		{
			y=i;
			break;
		}
	}
	
	cout<<y-x+1<<endl;
			
			
    exit()
 
 
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 810114514
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define int long long 

signed main(){
    int s[3];
    int K;
    REP(i,3){cin >> s[i];}
    cin >> K;
    sort(s,s+3);
    REP(i,K){
        s[2]*=2;
    }
    cout << s[0]+s[1]+s[2] << endl;
	return 0;
}

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

using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main(){
    int a,b;
    cin>>a>>b;
    if(a<=b)cout<<a<<endl;
    else cout<<a-1<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;cin >> s >> t;
  int n = s.size(),m = t.size(),i,j,dp[n+1][m+1] = {};
  for(i=1;i<=n;i++){
    for(j=1;j<=m;j++){
      if(s[i-1]==t[j-1]) dp[i][j] = dp[i-1][j-1]+1;
      else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
    }
  }
  string ans = "";i = n;j = m;
  while(i>0 && j>0){
    if(dp[i][j] == dp[i-1][j]) i--;
    else if(dp[i][j] == dp[i][j-1]) j--;
    else{
      i--;j--;ans += s.substr(i,1);
    }
  }
  reverse(ans.begin(),ans.end());
  cout << ans << "\n";
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define endl '\n'
#define modulo 1000000007
#define int int64_t
//#pragma GCC optimize("trapv")
#define float double
#define PI acos(-1);
#define sinDegrees(x) sin((x) * PI / 180.0)
#define tanDegrees(x) tan((x) * PI / 180.0)
#define atanDegrees(x) atan(x)* 180.0 / PI
using namespace std;
int power(int x,int y,int m)
{
int temp;
if(y == 0)
return 1;
temp = (power(x, y/2,m))%m;
if (y%2 == 0)
return ((temp%m)*temp);
else
return ((x*temp%m)*temp%m)%m;
}
int inv(int x)
{
return (power(x,modulo-2,modulo))%modulo;
}
bool comp(int a,int b)
{
return a<b;
}
///Solution created by:Ahmadsm2005
int32_t main()
{
//freopen("output.txt","w", stdout);
//freopen("output.txt","r", stdin);
//iostream::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
vector<string>a(3);
cin>>a[0]>>a[1]>>a[2];
reverse(a[0].begin(),a[0].end()),reverse(a[1].begin(),a[1].end()),reverse(a[2].begin(),a[2].end());
int ptr=0;
while(1){
if(!a[ptr].size()){
cout<<(char)('A'+ptr);
exit(0);
}
int buff=(a[ptr][a[ptr].size()-1]-'a');
a[ptr].pop_back();
ptr=buff;
}
return 0;
}


Measured memory_bytes: 256
/**************************************************************************
Coded by: Saba Karimi(_VINTAGE)
Institution: AIT PUNE
***************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
#define F first 
#define S second
/**************************************************************************/
signed main() 
{
    fast;
    string s,t;
    cin>>s>>t;
    int a[26]={};
    int b[26]={};
    for(int i=0;i<s.size();i++)
    {
        a[s[i]-'a']++;
        b[t[i]-'a']++;
    }
    multiset<int> st1,st2;
    for(int i=0;i<26;i++)
    {
        st1.insert(a[i]);
        st2.insert(b[i]);
    }
    if(st1 == st2)
        cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 916
def main():
    from collections import deque
    n, *a = map(int, open(0).read().split())
    a = deque(a)

    tar = 1
    gab = 0
    while a:
        i = a.popleft()
        if i != tar:
            gab += 1
        else:
            tar += 1

    if gab == n:
        print(-1)
    else:
        print(gab)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24900
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int> a(n),b(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
  b=a;
    sort(a.begin(),a.end());
    int m1=a[n-1],m2=a[n-2];
    for(int i=0;i<n;i++){
    if(b[i]==m1)cout<<m2<<endl;
    else cout<<m1<<endl;
    }
    return 0;
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
const int INF = 1e9;
const long long LINF = 1e18;
const double EPS = 1e-8;
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef pair<string, int> Psi;
typedef pair<ll, ll> Pll;
int main(){

	string a;
	cin >> a;
	rep(i,a.size()){
		cout << a[i];
		if(i == 3){
			cout << " ";
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
using namespace std;
int a, b, c, d, n, ans;
int ar[234567];
string s;
bool b1, b2;
signed main() {
	cin >> n;
	for1(i, n) {
		cin >> ar[i];
		if (i > 1 && ar[i] > ar[i - 1]) {
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3948
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

vector<set<int>> mm;
vector<set<int>> km;

vector<bool> seen;
vector<int> group_memo;
vector<int> group_size;
int group_id = 0;

void rec(int person)
{
  seen[person] = true;
  group_memo[person] = group_id;
  group_size[group_id]++;
  for (auto next : mm[person])
  {
    if (seen[next] == false) rec(next);
  }
  return;
}

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

  mm.assign(n + 1, set<int>());
  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    mm[a].insert(b);
    mm[b].insert(a);
  }

  km.assign(n + 1, set<int>());
  for (int i = 0; i < k; i++)
  {
    int c, d;
    cin >> c >> d;
    km[c].insert(d);
    km[d].insert(c);
  }

  group_memo.assign(n + 1, -1);
  group_size.assign(n + 1, 0);
  seen.assign(n + 1, false);

  for (int i = 1; i <= n; i++)
  {
    if (seen[i] == false)
    {
      rec(i);
    }
    group_id++;
  }

  for (int i = 1; i <= n; i++)
  {
    if (group_memo[i] == -1)
    {
      cout << 0 << endl;
      continue;
    }

    int ans = group_size[group_memo[i]] - 1;
    for (auto m : mm[i])
    {
      if (group_memo[m] == group_memo[i]) ans--;
    }
    for (auto k : km[i])
    {
      if (group_memo[k] == group_memo[i]) ans--;
    }
    cout << ans << endl;
  }

  return 0;
}

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

int main(){

  int r, g, b, tmp;

  cin >> r >> g >> b;

  tmp = r * 100 + g * 10 + b;

  if(tmp % 4 == 0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}


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

#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

const int N = 1004;
const int M = 1e9+7;
string s[N];
int dp[N][N];
int n;
int m;


void solve()
{
  cin >> n >> m;
    
  f(i,n) cin >> s[i];
    
  dp[0][1] = 1; 
    
  for(int i=1;i<=n;i++) 
  {
   for(int j=1;j<=m;j++)
       if(s[i-1][j-1] == '.')
          dp[i][j] = (dp[i-1][j] + dp[i][j-1])%M;
  }
    
  cout << dp[n][m];   
}

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

Measured memory_bytes: 9216
var  a,b,c,d:longint;
     s:string;
begin
  readln(s);
  a:=ord(s[1])-ord('0');
  b:=ord(s[2])-ord('0');
  c:=ord(s[3])-ord('0');
  d:=ord(s[4])-ord('0');
  if a+b+c+d=7 then
  begin
    writeln(a,'+',b,'+',c,'+',d,'=7');
    halt;
  end;
  if a+b+c-d=7 then
  begin
    writeln(a,'+',b,'+',c,'-',d,'=7');
    halt;
  end;
  if a+b-c+d=7 then
  begin
    writeln(a,'+',b,'-',c,'+',d,'=7');
    halt;
  end;
  if a+b-c-d=7 then
  begin
    writeln(a,'+',b,'-',c,'-',d,'=7');
    halt;
  end;
  if a-b+c+d=7 then
  begin
    writeln(a,'-',b,'+',c,'+',d,'=7');
    halt;
  end;
  if a-b+c-d=7 then
  begin
    writeln(a,'-',b,'+',c,'-',d,'=7');
    halt;
  end;
  if a-b-c+d=7 then
  begin
    writeln(a,'-',b,'-',c,'+',d,'=7');
    halt;
  end;
  if a-b-c-d=7 then
  begin
    writeln(a,'-',b,'-',c,'-',d,'=7');
    halt;
  end;
end.

Measured memory_bytes: 128
x,n=map(int,input().split())
if n == 0:
  print(x)
else:
  list=list(map(int,input().split()))
  if not(x in list):
    print(x)
  else:
    i=1
    while i<1000:
      if not((x-i) in list):
        print(x-i)
        break
      if not((x+i) in list):
        print(x+i)
        break
      i+=1

Measured memory_bytes: 9208
/**
*	  Name: Ajay
*	  Institute: IIITH 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define ll long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vii vector<ppi>
#define vll vector<ll>
#define mp make_pair
#define fi first
#define se second
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void input()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}

int main()
{      
  fastio();
  ll n;
  cin>>n;
  ll ans=0;
  ll f=-1,s=-1;
  for(ll i=2;i*i<=n;i++){
  	if(n%i==0){
  		if(f<i){
  			f=i;
  			s=n/i;
  		}
  	}
  }
  if(f==-1)
  	cout<<n-1;
  else
  	cout<<f+s-2;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

class UnionFind {
    int n;
    vector<int> uni;
public:
    explicit UnionFind(int n) : uni(static_cast<u32>(n), -1) , n(n){};

    int root(int a){
        if (uni[a] < 0) return a;
        else return (uni[a] = root(uni[a]));
    }

    bool unite(int a, int b) {
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b);
        uni[a] += uni[b];
        uni[b] = a;
        return true;
    }

    int size(int i){ return -uni[root(i)]; }
    bool same(int a, int b) { return root(a) == root(b); }
};

int main() {
    int n;
    array<int, 4> di{0, 0, -1, 1}, dj{1, -1, 0, 0};
    while(cin >> n, n){
        map<pair<int, int>, int> s;
        int cnt = 1;
        for (int i = 0; i < n; ++i) {
            int x, y; char c;
            scanf("%d %d %c", &x, &y, &c);
            if(c == 'x'){
                s[{x, y}] = cnt;
                s[{x+1, y}] = cnt++;
            }else {
                s[{x, y}] = cnt;
                s[{x, y+1}] = cnt++;
            }
        }
        UnionFind uf(cnt*2);
        for (auto &&x : s) {
            int i, j; tie(i, j) = x.first;
            int p = x.second;
            for (int k = 0; k < 4; ++k) {
                if(s.count({i+di[k], j+dj[k]})) {
                    int q = s[{i+di[k], j+dj[k]}];
                    if(p == q) continue;
                    uf.unite(p, q+cnt);
                    uf.unite(q, p+cnt);
                }
            }
        }
        int ok = 1;
        for (int i = 1; i < cnt; ++i) {
            if(uf.same(i, i+cnt)){
                ok = 0;
                break;
            }
        }
        puts(ok ? "Yes" : "No");
    }
    return 0;
}


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

#define fs first
#define sc second
#define mp make_pair
#define pb emplace_back
#define sz(s) ((int) s.size ())
#define all(s) s.begin (), s.end ()

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef unsigned long long ull;

const ll linf = (ll) 1e18;

const int pw = 997;
const int N = 59;
const int inf = (int) 1e9;
const int mod = (int) 1e9 + 7;

const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;

char a[N][N];
char b[N][N];

inline void prepare () {

}
inline void solve () {
        int n, m; cin >> n >> m;
        for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                        cin >> a[i][j];
                }
        }
        for (int i = 0; i < m; i++) {
                for (int j = 0; j < m; j++) {
                        cin >> b[i][j];
                }
        }
        for (int i = 0; i < n - m + 1; i++) {
                for (int j = 0; j < n - m + 1; j++) {
                        bool bad = 0;
                        for (int k = i; k < i + m; k++) {
                                for (int l = j; l < j + m; l++) {
                                        if (a[k][l] != b[k - i][l - j]) {
                                                bad = 1;
                                                break;
                                        }
                                }
                                if (bad) {
                                        break;
                                }
                        }
                        if (!bad) {
                                puts ("Yes");
                                return;
                        }
                }
        }
        puts ("No");
}
int main () {
        #ifdef FSTREAM
                #define name ""
                freopen (name".in", "r", stdin);
                freopen (name".out", "w", stdout);
        #endif // FSTREAM
        int tests = 1;
        prepare ();
	while (tests--) {
                solve ();
        }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define last Last
#define int long long
const int N=1e6+5;
int n;
char a[N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
signed main()
{
	scanf("%s",a+1);
	n=strlen(a+1);
	for(int i=1;i<=n;i++)
		if(i%2==1)
		{
			if(a[i]=='L'){puts("No");return 0;}
		}
		else{
			if(a[i]=='R'){puts("No");return 0;}
		}
	puts("Yes");
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
int main() {
  string s;cin>>s;
  int ans=0;
  REP(i,s.size()/2){
    if(s[i]!=s[s.size()-1-i]){
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {
        int n = sc.nextInt();
        int m = sc.nextInt();

        List<Integer>[] list = new ArrayList[m+1];

        for (int i=0; i<m+1; i++) {
            list[i] = new ArrayList<>();
        }

        for (int i=0; i<n; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            if (a<=m) {
                list[a].add(b);
            }
        }

        PriorityQueue<Node> pq = new PriorityQueue<>();

        long ans = 0;

        for (int i=1; i<=m; i++) {
            List<Integer> tmpL = list[i];
            for (int t: tmpL) {
                Node node = new Node(t);
                pq.add(node);
            }
            if (!pq.isEmpty()) {
                ans += pq.poll().money;
            }

        }

        System.out.println(ans);

    }

    class Node implements Comparable<Node> {
        int money;
        public Node(int m) {
            this.money = m;
        }

        public int compareTo(Node nd) {
            if (this.money<nd.money) return 1;
            if (nd.money<this.money) return -1;
            return 0;
        }
    }

}


Measured memory_bytes: 99512
#include <stdio.h>

#define MAX_HEIGHT 30
#define MAX_WIDTH  10

typedef unsigned char U1;
typedef signed   char S1;
typedef signed   int  S4;

/* 番号の組み合わせ毎に、入れ替え可能ならば入れ替え可能位置、そうでなければ0,0を入れる */
/* [0]：段 [1]：列 */
U1 irekae[MAX_WIDTH+1][MAX_WIDTH+1][2];

int main(){
    S4 n,m,atari,d;        /* 入力：各値 */
    S1 amida[MAX_WIDTH+2]; /* 入力：あみだくじの横線情報 両端に番兵0を固定で入れるため幅は+2 */
    S4 keika[MAX_WIDTH+1];   /* あみだくじ辿り中の番号の位置 インデックス0を使わないため幅を+1 */
    S4 i,j,tmp;            /* 計算時一時変数 */
    U1 tate,yoko;          /* 出力時一時変数 */

    while( (scanf("%d",&n)>0) && (n>0) ){
        /* 入力 */
        scanf("%d",&m);
        scanf("%d",&atari);
        scanf("%d",&d);

        /* 入れ替え可能位置情報の初期化 */
        /* i,j：縦線の番号 */
        for( i=1; i<=n; i++ ){
            for( j=1; j<=n; j++ ){
                irekae[i][j][0] = 0U;
                irekae[i][j][1] = 0U;
            }
        }

        /* あみだくじ初期位置設定 */
        for( i=1; i<=n; i++ ){
            keika[i]=i;
        }

        /* 左端を番兵0とする */
        amida[0]='0';
        /* 各段の情報を読み込みながら、あみだをたどりつつ、入れ替え可能な番号の組み合わせ・位置を記憶 */
        /* i：段目 , j：縦線の番号 */
        for( i=1; i<=d; i++){
            /* 読み込み後、右端を番兵0にする */
            scanf("%s",&amida[1]);
            amida[n]='0';
            for( j=1; j<=n-1; j++ ){
                /* 横線があれば入れ替える */
                if( amida[j]=='1' ){
                    tmp        = keika[j];
                    keika[j]   = keika[j+1];
                    keika[j+1] = tmp;
                }else{
                    /* 横線を追加可能な場合、入れ替え可能位置情報として記憶 */
                    if( (amida[j-1]=='0') && (amida[j+1]=='0') ){
                        /* 先に見つけた情報が優先なので、すでに記憶済みならば何もしない */
                        if(irekae[keika[j]][keika[j+1]][0]==0){
                            irekae[keika[j]][keika[j+1]][0]=i;
                            irekae[keika[j]][keika[j+1]][1]=j;

                            irekae[keika[j+1]][keika[j]][0]=i;
                            irekae[keika[j+1]][keika[j]][1]=j;
                        }
                    }
                }
            }
        }

        /* 出力 */
        tate = irekae[m][keika[atari]][0];
        yoko = irekae[m][keika[atari]][1];

        if(m==keika[atari]){
            /* 何もしなくても当たり */
            printf("0\n");
        }else{
            if(tate==0){
                /* 記憶されてなければたどり着けない */
                printf("1\n");
            }else{
                printf("%d %d\n",tate,yoko);
            }
        }
    }

    return 0;
}



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

int main()
{
	long long N;
	scanf("%lld", &N);
	
	int i, count = 0, digit[10] = {7, 5, 3}, flag[3];
	long long n = 357;
	while (n <= N) {
		count++;
		while (1) {
			for (i = 0; digit[i] == 7; i++);
			if (digit[i] == 0) {
				for (; i >= 2; i--) digit[i] = 3;
				digit[1] = 5;
				digit[0] = 7;
				break;
			} else {
				for (digit[i--] += 2; i >= 0; i--) digit[i] = 3;
				for (i = 0; i < 3; i++) flag[i] = 0;
				for (i = 0; digit[i] > 0; i++) flag[(digit[i]-3)/2] = 1;
				if (flag[0] == 1 && flag[1] == 1 && flag[2] == 1) break;
			}
		}
		for (i = 9, n = 0; i >= 0; i--) n = n * 10 + digit[i];
	}
	
	printf("%d\n", count);
	fflush(stdout);
	return 0;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */
int main(){
    double n, m, d; cin >> n >> m >> d;
    double res = 2 * (n - d) / n * (m - 1) / n;
    if(d == 0) res = (n - d) / n * (m - 1) / n;
    setpre(10); out(res);
}

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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  
  if(((a-b)<=d && (a-b)>=(-1)*d && (b-c)<=d && (b-c)>=(-1)*d) || (a-c)<=d && (a-c)>=(-1)*d ){
    cout << "Yes" << endl;  
  }
  else{
    cout << "No" << endl;
  }

 
}

  

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

N, D = map(int, readline().split())

A = list(map(int, readline().split())) + [0]

reach = [None]*(N+2)
reach[-1] = D
for i in range(N+1):
    r = reach[i-1]
    a = A[i]
    reach[i] = min(r, abs(r-a))

putter = [0]*(N+2)
for i in range(N, -1, -1):
    p = putter[i+1]
    a = A[i]
    if 2*p+1 >= a:
        p += a
    putter[i] = p

res = ['NO']*N
for i in range(N):
    if reach[i-1] > putter[i+1]:
        res[i] = 'YES'

Q = int(readline())
print('\n'.join(res[int(i)-1] for i in readline().split()))

    

Measured memory_bytes: 138800
rank = ['heavy','light heavy','middle','light middle','welter','light welter','light','feather','bantam','fly','light fly']
lwgt=[91.00,81.00,75.00,69.00,64.00,60.00,57.00,54.00,51.00,48.00,0.0]
while True:
    try:
        wgt = float(input().strip())
        for i in range(len(lwgt)):
            if  wgt > lwgt[i]:
                print(rank[i])
                break
        
    except EOFError:
        break

Measured memory_bytes: 7424
let sorts s b =
  let s2l s =
    let len = String.length s in
    let rec f i l =
      if i >= len then
        let ls = List.sort Char.compare l in
        if b then List.rev ls else ls
      else f (i + 1) (s.[i] :: l)
    in
    f 0 []
  in
  let rec cl2s tmp = function
    | [] -> tmp
    | c :: t -> cl2s (Char.escaped c ^ tmp) t
  in
  s2l s |> cl2s ""


let f s t =
  let s' = sorts s true and t' = sorts t false in
  if s' < t' then "Yes" else "No"


let () = Scanf.scanf "%s\n%s" f |> print_endline

Measured memory_bytes: 512
ss = gets().split(" ")
s = gets().split(" ")
n = ss[0].to_i
m = ss[1].to_i
x = ss[2].to_i

countL = 0
countR = 0

for i in 0..m-1
	s[i] = s[i].to_i
	if s[i] < x
		countL += 1
	elsif s[i] > x
		countR += 1
	end
end

if countL < countR
	puts(countL)
else
	puts(countR)
end

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

using namespace std;
using vi = vector<int>;

#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ITER(it,v) for(auto it=v.begin();it!=v.end();++it)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

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

  string S; cin >> S;

  if (S.length() == 26) {
    vi v;
    for (int i = S.length() - 1; i >= 0; --i) {
      ITER(it2, v) {
        if (*it2 > S[i]) {
          OUT(S.substr(0, i) << (char)*it2);
          return 0;
        }
      }
      v.push_back(S[i]);
    }
    OUT(-1);
  } else {
    string sorted = S;
    sort(ALL(sorted));
    REP(i, 26) {
      if (binary_search(ALL(sorted), (char)i+'a'))
        continue;
      OUT(S << (char)(i + 'a'));
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
import collections
n =int(input())
ss = []
ans = []
for i in range(n):
    ss.append(input())
a = collections.Counter(ss)

m = max(a.values())

for i,s in a.items():

    if s == m:
        ans.append(i)
ans = sorted(ans)

for i in ans:
    print(i)


Measured memory_bytes: 35572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  ll ans=0;
  for(int i=0;i<n;i++){
    cin >> v[i];
    ans += v[i];
  }
  int count = 0;
  sort(v.begin(), v.end());
  for(int i=0;i<n;i++){
    if (ans % 10 == 0){
      ll ans2 = ans - v[i];
      if (ans2 % 10 == 0){
        count++;
        continue;
      }else{
        ans = ans2;
        break;
      }
    }else{
      break;
    }
  }
  if (count == n){
    cout << 0 << endl;
  }else{
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

char g[55][55];
vector<P> dir = { {1,0},{-1,0},{0,1},{0,-1} };

int main() {
  int h,w; cin>>h>>w;
  REP(i,h) REP(j,w) { cin >> g[i+1][j+1]; }

  for (int i = 1; i<=h; i++) {
    for (int j = 1; j<=w; j++) {
      if (g[i][j] != '#') continue;
      int ok = 0;
      for (auto x: dir) {
        ok = ok || g[i+x.first][j+x.second] == '#';
      }
      if (!ok) { COUT("No"); return 0; }
    }
  }
  COUT("Yes");
  return 0;
}

Measured memory_bytes: 256
M = int(1e+9 + 7)


def main():
  input()
  s = list(map(int, input().split()))
  t = list(map(int, input().split()))
  z = [0] * len(t)

  for v in s:
    c = 0

    for i, w in enumerate(t):
      y = z[i]

      if v == w:
        z[i] = (z[i] + c + 1) % M

      c = (c + y) % M

  y = 0

  for v in z:
    y = (y + v) % M

  y = (y + 1) % M

  print(y)


if __name__ == '__main__':
  main()


Measured memory_bytes: 41196
#include <iostream>
using namespace std;
int n,m;
int deg[50];
int main(){
  cin >> n >> m;
  while(m--){
    int a,b;
    cin >> a >> b;
    a--;b--;
    deg[a]++;
    deg[b]++;
  }
  for(int i=0;i<n;++i)
    cout << deg[i] << endl;
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 256