akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
#define mst(a,x) memset(a,x,sizeof(a))
#define vector basic_string
#define fi first
#define se second
#ifndef qwq
int cansel_sync=(ios::sync_with_stdio(0),cin.tie(0),0);
#endif
//mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=200010; const double err=1e-11; typedef long long ll; const int inf=~0u>>2; const ll INF=~0ull>>2; ll read(){ll x; if(scanf("%lld",&x)==-1)exit(0); return x;} typedef double lf; typedef long double llf; const lf pi=acos(-1.0); lf readf(){lf x; if(scanf("%lf",&x)==-1)exit(0); return x;} template<typename T> T sqr(const T &x){return x*x;} typedef pair<int,int> pii; template<typename A,typename B> ostream &operator<<(ostream &o,const pair<A,B> &x){return o<<'('<<x.fi<<','<<x.se<<')';}
const int mod=(1?1000000007:998244353); ll mul(ll a,ll b,ll m=mod){return a*b%m;} ll qpow(ll a,ll b,ll m=mod){ll ans=1; for(;b;a=mul(a,a,m),b>>=1)if(b&1)ans=mul(ans,a,m); return ans;} ll getinv(ll v,ll m=mod){return qpow(v,m-2,m);}
#define int ll
string s;
int a[N],b[N];
int n,k,c;
signed main(){
	cin>>n>>k>>c;
	cin>>s;
	int cnt=0;
	for(int i=0;i<(int)s.length();i++)
	if(s[i]=='o'){
		a[i]=++cnt;
		i+=c;
	}
	if(cnt>k)exit(0);
	
	cnt=k;
	for(int i=s.length()-1;i>=0;i--)
	if(s[i]=='o'){
		b[i]=cnt--;
		i-=c;
	}
	repeat(i,0,n)if(a[i]>0 && a[i]==b[i])cout<<i+1<<endl;
	return 0;
}

Measured memory_bytes: 5012
a, b, k = map(int, input().split())
X = []
for i in range(a, min(a+k, b+1)):
    X.append(i)

for j in range(max(b-k+1, a), b+1):
    X.append(j)
X = sorted(X)
X_s = sorted(set(X), key=X.index)
for k in X_s:
    print(k)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,ll> Q;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<Q>G[200005];
bool rem[200005]={};
int sub[200005]={},n,q;
vector<P1>edge;
ll a[200005];
int make(int v,int u)
{
    int cnt=1;
    for(int i=0;i<G[v].size();i++)
    {
        int v2=G[v][i].fi;
        if(rem[v2] || v2==u) continue;
        cnt+=make(v2,v);
    }
    return sub[v]=cnt;
}
P search(int v,int u,int siz)
{
    //size and index
    P res=mp(INF,-1);
    int s=1,m=0;
    for(int i=0;i<G[v].size();i++)
    {
        int v2=G[v][i].fi;
        if(rem[v2] || v2==u) continue;
        res=min(res,search(v2,v,siz));
        m=max(m,sub[v2]);
        s+=sub[v2];
    }
    m=max(m,siz-s);
    res=min(res,mp(m,v));
    return res;
}
vector<int>L;
pair<ll,int>p;
void dfs(int v,int u,ll d)
{
    p = min(p,mp(d+a[v],v));
    for(int i=0;i<G[v].size();i++)
    {
        int v2=G[v][i].fi;
        if(rem[v2] || v2==u) continue;
        dfs(v2,v,d+G[v][i].sc);
    }
}
void dfs2(int v,int u,ll d)
{
    edge.pb(mp(d+a[v]+p.fi,mp(v,p.sc)));
    for(int i=0;i<G[v].size();i++)
    {
        int v2=G[v][i].fi;
        if(rem[v2] || v2==u) continue;
        dfs2(v2,v,d+G[v][i].sc);
    }
}
void sol(int v)
{
    make(v,-1);
    int sz = sub[v];
    int cent=search(v,-1,sub[v]).sc;
    rem[cent]=true;
    L.clear(); L.pb(cent); p = mp(a[cent],cent);
    for(int i=0;i<G[cent].size();i++){
        if(!rem[G[cent][i].fi]) dfs(G[cent][i].fi,cent,G[cent][i].sc);
    }
    edge.pb(mp(a[cent]+p.fi,mp(cent,p.sc)));
    for(int i=0;i<G[cent].size();i++){
        if(!rem[G[cent][i].fi]) dfs2(G[cent][i].fi,cent,G[cent][i].sc);
    }
    for(int i=0;i<G[cent].size();i++) if(!rem[G[cent][i].fi]) sol(G[cent][i].fi);
    rem[cent]=false;
}
struct uf{
    int par[200005];
    void init(){ rep(i,200005) par[i]=i; }
    int find(int x){ if(x==par[x]) return x; else return par[x] = find(par[x]); }
    void unite(int x,int y){
        x = find(x); y = find(y);
        if(x == y) return;
        par[x] = y;
    }
    bool same(int x,int y){ return find(x) == find(y); }
}uf;
int main(){
    scanf("%d",&n);
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    rep(i,n-1){
        int a,b; ll c; scanf("%d%d%lld",&a,&b,&c); a--; b--;
        G[a].pb(mp(b,c));
        G[b].pb(mp(a,c));
    }
    sol(0);
    ll ans = 0;
    SORT(edge); uf.init();
    rep(i,edge.size()){
        ll v = edge[i].fi; int p = edge[i].sc.fi, q = edge[i].sc.sc;
        if(uf.same(p,q)) continue;
        uf.unite(p,q); ans+=v;
    }
    cout<<ans<<endl;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> ls(n), rs(n);
    rep(i,n) cin >> ls[i] >> rs[i];
    sort(ls.begin(), ls.end());
    sort(rs.begin(), rs.end());
    int ans = 0;
    if (n&1) {
        int l = ls[n/2];
        int r = rs[n/2];
        ans = r - l + 1;
    } else {
        int l2 = ls[n/2-1] + ls[n/2];
        int r2 = rs[n/2-1] + rs[n/2];
        ans = r2 - l2 + 1;
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 4776
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time
from decimal import *


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
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 print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def main():
    A, B = MS()
    getcontext().prec = 28

    a = Decimal(A) * Decimal(B)

    print(a.quantize(Decimal('0'), rounding=ROUND_DOWN))


if __name__ == '__main__':
    main()


Measured memory_bytes: 10476
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0; i<n; i++) {
            a[i] = sc.nextInt();
        }

        int r = 0;
        long sum = a[0];
        long res = 0;
        for(int l=0; l<n; l++) {
            while(r < n - 1) {
                if(sum + a[r+1] == (sum ^ a[r+1])) {
                    sum += a[r+1];
                    r++;
                } else {
                    break;
                }
            }
            res += r - l + 1;
            if(r == l && r < n - 1) {
                r++;
                sum += a[r];
            }
            sum -= a[l];
        }
        System.out.println(res);
    }

}


Measured memory_bytes: 86612
import heapq

N,M = map(int,input().split())
s = [list(map(int, input().split())) for _ in range(N)]
jobs = [[] for _ in range(M)]

for i in s:
    if i[0] <= M:
        jobs[i[0]-1].append(-i[1])

condidate=[]
rewards=0
for k in range(M):
    for reward in jobs[k]:
        heapq.heappush(condidate, reward)
    if len(condidate) > 0:
        reward = heapq.heappop(condidate)
        rewards += -reward

print(rewards)

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

#define crap ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define CN cout<<"NO\n"
#define CY cout<<"YES\n"

using namespace std;
using ll = long long;
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
// #define MAXN 1000001 
// ll sieve[MAXN]; 
// void makesieve()
// {
//     sieve[1] = 1; 
//     for (int i = 2; i < MAXN; i++) 
//         sieve[i] = i; 
//     for (int i = 4; i < MAXN; i += 2) 
//         sieve[i] = 2; 
//     for (int i = 3; i * i < MAXN; i++) { 
//         if (sieve[i] == i) { 
//             for (int j = i * i; j < MAXN; j += i) 
//                 if (sieve[j] == j) 
//                     sieve[j] = i; 
//         } 
//     } 
// }
ll powerflow(ll x, ll n)
{
    ll res;
    if (n == 0) {
        return 1;
    }
    res = powerflow(x, n-1);             // recurse
    if(INT_MAX / res < x) {          // check for overflow
        return -1; //LONG_MAX;
    }
    return x * res;
}
ll mod=1000000007;
ll power(ll a,ll b,ll m)
{
    a%=m;b%=m;
    ll res=1;
    while(b!=0)
    {
        if(b&1)
        res=(res*a);
        b=b/2;
        a=(a*a)%mod;
    }
    return res;
}
struct compare  
 {  
   bool operator()(const int& l, const int& r)  
   {  
       return l > r;  
   }  
 };
 ll dp[2001];
ll recur(int n)
 {
    if(n==0) return 1;
    if(n<=2) return 0;
    if(dp[n]!=-1) return dp[n];
    ll ans=0;
    for(int i=3;i<=n;i++)
        ans=(ans+recur(n-i))%mod;
    return dp[n]=ans;
 
 }
void solve()
{
    ll n; cin>>n;
    if(n<3) {cout<<"0";return ;}
    rep(i,2001) dp[i]=-1;
    cout<<recur(n);
}
int main()
{
    crap;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r", stdin) ;
        freopen("output.txt","w", stdout) ;
        freopen("error.txt","w", stderr) ;
    #endif
    int t;t=1;
    //cin>>t;
    while(t--)
        {solve();}
    return 0;
}

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

int main() {
	int h, w;
	int index = 0;
	char letters[2] = {'.', '#'};
	char temp;

	while(cin >> h >> w) {
		if(h==0 && w==0) break;

		letters[0] = '.';
		letters[1] = '#';

		for(int i=0;i<h;i++) {
			temp = letters[0];
			letters [0] = letters[1];
			letters[1] = temp;

			for(int j=0;j<w;j++) {
				index = j%2;
				cout << letters[index];
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}


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

typedef long long ll;

typedef struct {
  ll A,B;
}Data;

bool operator<(const Data&l, const Data&r ) { return l.A < r.A; };

int main() {
  int N,M; cin >> N >> M;
  vector<Data> data(N);

  for ( int i = 0; i < N; i++ ) {
    cin >> data[i].A >> data[i].B;
  }
  sort(data.begin(),data.end());
  //  for ( int i = 0; i < N; i++ ) {
  //    cout << data[i].A << " " << data[i].B << endl;
  //  }

  ll cntA = 0,cntB = 0;
  for ( int i = 0; i < N; i++ ) {
    cntA += data[i].A*data[i].B;
    cntB += data[i].B;
    //    cout << cntA << endl;
    //    cout << cntB << endl;
    if ( cntB >= M ) {
      ll tmp = cntB-M;
      cntB = cntB-(cntB-M);

      cntA -= data[i].A*tmp;
      break;
    }
  }
  cout << cntA << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <cmath>
#include <cstring>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#define ll long long
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	if ((s.length() % 2 == 0) ^ (s[0] == s[s.length() - 1]))
	{
		cout << "Second" << endl;
	}
	else
	{
		cout << "First" << endl;
	}
	return 0;
}

Measured memory_bytes: 764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    public Program() { }


    Scanner cin;

    void myon()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int K = cin.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++)
        {
            A[i] = cin.nextInt();
        }
        Array.Sort(A);

        int ans = int.MaxValue;
        for (int i = 0; i <= N - K; i++)
        {
            ans = Math.Min(ans, A[i + K - 1] - A[i]);
        }
        Console.WriteLine(ans);
    }

    static void Main(string[] args)
    {
        new Program().myon();
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return next();
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}


Measured memory_bytes: 17336
#include<iostream>
#include<string>

int main()
{
    int n;
    std::cin>>n;
    int ans=0;
    std::string a,b,c;
    std::cin>>a>>b>>c;
    for(int i=0;i<n;i++){
        if(a[i]==b[i]&&b[i]==c[i])continue;
        if(a[i]!=b[i]&&b[i]!=c[i]&&c[i]!=a[i])ans += 2;
        if(a[i]==b[i]&&b[i]!=c[i])ans++;
        if(a[i]!=b[i]&&b[i]==c[i])ans++;
        if(a[i]!=b[i]&&a[i]==c[i])ans++;
    }
    std::cout<<ans<<std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
Int w,h;
Int cnt,sum,ans,tmp;
Int a[20][20];
Int us[20][20];
Int dp[20][20];
Int pn[20][20];
void inc(Int y,Int x){
  cnt+=!us[y][x];
  us[y][x]++;
}
void dec(Int y,Int x){
  us[y][x]--;
  cnt-=!us[y][x];
}
void show(){
  cout<<cnt<<" "<<sum<<":"<<tmp<<endl;
  for(Int i=0;i<h;i++)
    for(Int j=0;j<w;j++)
      cout<<us[i][j]<<" \n"[j==w-1];
  cout<<endl;
}

void dfs(Int y,Int x){
  Int ny=y+(x+1)/w,nx=(x+1)%w;
  if(ny==h||tmp+1>=ans) return;
  
  if(us[y][x]) dfs(ny,nx);
  if(!dp[y][x]) return;
  
  Int bc=cnt,k=dp[y][x];
  for(Int i=0;i<k;i++)
    for(Int j=0;j<k;j++)
      inc(y+i,x+j);

  if(bc<cnt){
    tmp++;
    if(cnt==sum) ans=min(ans,tmp);
    else if(tmp+1<ans)  dfs(ny,nx);
    tmp--;
  }
  
  for(Int i=0;i<k;i++)
    for(Int j=0;j<k;j++)
      dec(y+i,x+j);
}

signed main(){
  while(cin>>w>>h,w){
    
    cnt=sum=0;
    memset(a,0,sizeof(a));
    memset(us,0,sizeof(us));
    for(Int i=0;i<h;i++){
      for(Int j=0;j<w;j++){
	cin>>a[i][j];
	sum+=a[i][j];
	us[i][j]=!a[i][j];
      }
    }
    
    memset(dp,0,sizeof(dp));
    for(Int i=h-1;i>=0;i--)
      for(Int j=w-1;j>=0;j--)
	dp[i][j]=a[i][j]*(min({dp[i][j+1],dp[i+1][j],dp[i+1][j+1]})+1);
    
    for(Int i=h-1;i>=0;i--)
      for(Int j=w-1;j>=0;j--)
	if(dp[i][j]==dp[i+1][j+1]+1)
	  dp[i+1][j+1]=0;
    
    memset(pn,0,sizeof(pn));
    for(Int i=0;i<h;i++)
      for(Int j=0;j<w;j++)
	for(Int k=0;k<dp[i][j];k++)
	  for(Int l=0;l<dp[i][j];l++)
	    pn[i+k][j+l]++;

    Int pre=0;
    for(Int i=0;i<h;i++){
      for(Int j=0;j<w;j++){
	if(dp[i][j]&&pn[i][j]==1){
	  pre++;
	  for(Int k=0;k<dp[i][j];k++)
	    for(Int l=0;l<dp[i][j];l++)
	      inc(i+k,j+l);
	}
      }
    }

    if(0){
      cout<<pre<<" "<<sum<<endl;
      for(Int i=0;i<h;i++)
	for(Int j=0;j<w;j++)
	  cout<<dp[i][j]<<" \n"[j==w-1];
      cout<<flush;

      show();
    }

    ans=w*h*(cnt!=sum);tmp=0;
    dfs(0,0);
    
    cout<<pre+ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3032
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(){
  int n,a,b,sum=0;
  cin >> n;
  cin >> a;
  cin >> b;


  for(int i=1; i<=n; i++){
    int temp2=0;
    int temp=i;
    while(temp/10 >= 1){
      temp2 += temp%10;
      temp = (temp-temp%10)/10;
    }
    temp2 += temp;
    if(temp2>=a && temp2<=b){
       sum += i;
    }
  }

  cout << sum << endl;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
#a内部ての転倒数
c_1=0
for i in range(n):
    for j in range(i+1,n):
        if a[i]>a[j]:
            c_1+=1
ans1=c_1*k
#print(ans1)
#aとaの間の転倒数
c_2=0
for i in range(n):
    for j in range(n):
        if a[i]>a[j]:
            c_2+=1
ans2=c_2*(k*(k-1)//2)
print((ans1+ans2)%(7+10**9))

Measured memory_bytes: 9100
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
int main(){
  int n,s=0,h;
  cin >> n;
  vector<int> x(n);
  for(int i=0; i<n; i++){
    cin >> x.at(i);
    s+=x.at(i);
  }
  h=s/n;
  long long s1=0,s2=0;
  for(int i=0; i<n; i++){
    s1+=abs(x.at(i)-h)*abs(x.at(i)-h);
    s2+=abs(x.at(i)-h-1)*abs(x.at(i)-h-1);
  }
  cout << min(s1,s2) << endl;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

def solve(n:int) -> list:
    x6o2 = [(6*i+2, 6*i+4) for i in range(5000)]
    x6o3 = [(12*i+3, 12*i+9) for i in range(2500)]
    o6 = [6*i+6 for i in range(5000)]
    x6 = []
    for i in range(2500):
        x6.append(x6o3[i])
        x6.append(x6o2[2*i])
        x6.append(x6o2[2*i+1])
    
    ans = []    
    if n == 3:
        ans = [2, 5, 63]
    
    elif n <= 15000:
        idx = n//2
        for i, (mn,mx) in enumerate(x6[:idx]):
            ans.extend([mn,mx])
        if n%2:
            ans = ans + [6]
            
        
    else:
        for i, (mn,mx) in enumerate(x6):
            ans.extend([mn,mx])
        for o6i in o6[:n-15000]:
            ans.append(o6i)
        
    return ans
    
n = ni()
print(*solve(n))

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

#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef pair <int, int> PR;
typedef long long ll;
typedef unsigned long long ull;

inline void OPEN(string s){
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}

const int maxx = 2e5 + 7;
deque <ll> que[3];
vector <ll> a;
int n, ans;

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		ll x; scanf("%lld", &x);
		a.push_back(x);
	}
	sort(a.begin(), a.end());
	for(int i = 0; i < a.size(); i++) que[1].push_back(a[i]);
	for(int k = 31; k >= 0; k--) {
		ll ned = (1ll << k);
		int now = (k & 1);
		ll x = 0, y = 0;
		while(!que[now].empty()) {
			if(x == 0) {
				x = que[now].front();
				que[now].pop_front();
			}
			if(y == 0) {
				if(que[now].empty()) {
					que[!now].push_back(x);
					x = 0;
					break;
				}
				y = que[now].back();
				que[now].pop_back();
			}
			if(x + y == ned) {
				ans++;
				x = y = 0;
			}
			else if(x + y < ned) {
				que[!now].push_back(x);
				x = 0;
			}
			else if(x + y > ned) {
				que[2].push_back(y);
				y = 0;
			}
		}
		if(x != 0) que[!now].push_back(x);
		if(y != 0) que[2].push_back(y);
		while(!que[2].empty()) {
			que[!now].push_back(que[2].front());
			que[2].pop_front();
		}
	}
	printf("%d\n", ans);
}

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

int solve(vector<int> &v, int n, int k){
  ll dp[n+2][k+2];
  memset(dp, 0, sizeof dp);

  for(int j=0;j<=k;j++){
      dp[1][j]=(j>v[1])?0:1;
  }
    for(int i=2;i<=n;++i){
        for(int j=0;j<=k;++j){
            if(j==0){
                     dp[i][0]=dp[i-1][0];
            }
            else{
                dp[i][j]=  (1000000007+dp[i][j-1] + dp[i-1][j] - ((j-v[i]-1>=0)?dp[i-1][j-v[i]-1]:0))%1000000007;
            }
        }
    }
   return dp[n][k];


}
int main() {
    int n,k;
    cin>>n>>k;
    vector<int> v(n+1);
    for(int i=1;i<=n;++i){
        cin>>v[i];
    }
    cout<<solve(v,n,k);
    return 0;}

Measured memory_bytes: 83320
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,e) for(int i = (s); i < (e); i++)
#define FOE(i,s,e) for(int i = (s); i <= (e); i++)
#define FOD(i,s,e) for(int i = (s); i >= (e); i--)
#define ll long long
#define pb push_back
#define mp make_pair

int n, m, x, y, z, k, w;
int A[4005][4005];

char s[2];

void add(int x, int y, int val)
{
//	printf("(%d, %d) = %d\n", x, y, val);
	A[x][y] += val;
}

int main ()
{
	scanf("%d %d", &n, &k);
	
	FOR(i, 0, n)
	{
		scanf("%d %d %s", &x, &y, s);
		
		if (s[0] == 'W') x += k;
		
		w = min(x / k, y / k);
		x -= w * k;
		y -= w * k;
		
		if (x > y)
		{
			w = x / (2 * k);
			x -= w * (2 * k);
		}
		else
		{
			w = y / (2 * k);
			y -= w * (2 * k);
		}
		
		add(x, y, 1);
		add(x, y + k, -1);
		add(x + k, y, -1);
		add(x + k, y + k, 1);
	}

	int ans = 0;
	
	FOE(i, 0, 3 * k) FOE(j, 0, 3 * k)
	{
		if (i > 0) A[i][j] += A[i - 1][j];
	}	
	FOE(i, 0, 3 * k) FOE(j, 0, 3 * k)
	{
		if (j > 0) A[i][j] += A[i][j - 1];
	}
	
	FOR(i, 0, 3 * k) FOR(j, 0, 3 * k)
	{
		x = i; y = j;
		if (i < k && j < 2 * k) continue;
		
		if (x >= 2 * k) x -= 2 * k;
		if (x >= k && y >= k) x -= k, y -= k;
		if (y >= 2 * k) y -= 2 * k;
		
		if (x >= k) x -= k, y += k;
		
		A[x][y] += A[i][j]; 
	}
	
	//FOD(i, k - 1, 0) { FOR(j, 0, 2 * k) printf("%d ", A[i][j]); printf("\n"); }
	
	FOR(i, 0, k) FOR(j, 0, 2 * k) ans = max(ans, A[i][j]);
	
	printf("%d\n", ans);
	return 0;
}
	
	
	

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

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

    let ans = (n - 1) * (m - 1);

    println!("{}", ans);
}


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

#define rep(i,n) for (int i=0; i<(n); i++)
const int INF =1001001001;
const ll BIG = 1000000007;

int main(){
    int n;
    string s;
    cin >>n>>s;
    string si,sj,sk;
    vector<int> a(n);
    rep(i,n){
        if(s[i] == 'R') a[i] = 0;
        if(s[i] == 'G') a[i] = 1;
        if(s[i] == 'B') a[i] = 2;
    }
    vector<ll> cnt(3);
    rep(i,n) cnt[a[i]]++;
    ll ans = 1;
    rep(i,3) ans *=cnt[i];
    rep(j,n)rep(i,j){
        int k = j+(j-i);
        if(k<n){
            if(a[i]==a[j])continue;
            if(a[i]==a[k])continue;
            if(a[k]==a[j])continue;
            ans--;
        }
    }

    /*
    for(int i=0; i<n; i++) {
        si = s[i];
        for(int j=i+1; j<n; j++){
            sj = s[j];
            if(si==sj) continue;
            for(int k =j+1; k<n; k++){
                sk = s[k];
                if(si==sk || sj==sk) continue;
                if((j-i)!=(k-j)) ans++;
            }
        }
    }
    */
    cout << ans <<endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a-1)
#define trav(x, a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

ll arr[MX][3], dp[MX][3];

ll K[3][2] = {{1,2},{0,2},{0,1}};

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int N; cin >> N;

    F0R(y,N) F0R(x,3) {
        cin >> arr[y][x];
    }

    F0R(y,N){
        F0R(x,3) {
            F0R(i,2) {
                int k = K[x][i];
                dp[y][x] = max(dp[y][x],(y-1 >= 0) ? dp[y-1][k]+arr[y][x] : arr[y][x]);
            }
        }
    }

    ll res = 0;
    F0R(i,3) res = max(res,dp[N-1][i]);

    cout << res << "\n";

}


Measured memory_bytes: 8448
program Divide_the_problems
    implicit none
    integer(4):: n
    integer(4),allocatable:: d(:)

    read*, n
    allocate(d(n))
    read*, d(:)

    call merge_sort(d,1,n)
    print*, d(n/2+1)-d(n/2)
contains
    recursive subroutine merge_sort(ar, fst, lst)
        integer(4),intent(inout):: ar(:)
        integer(4),intent(in):: fst,lst
        integer(4):: mdl

        if (lst - fst < 2) then
            if (ar(fst) > ar(lst)) call swap(ar(fst),ar(lst))
            return
        end if

        mdl = (fst+lst)/2
        call merge_sort(ar,fst,mdl)
        call merge_sort(ar,mdl+1,lst)
        call merge_(ar,fst,mdl,lst)
    end subroutine

    subroutine merge_(ar,fst,mdl,lst)
        integer(4),intent(inout):: ar(:)
        integer(4),intent(in):: fst,mdl,lst
        integer(4),allocatable:: tmp(:)
        integer(4):: li,ri,ti

        allocate(tmp(lst-fst+1))

        li=fst
        ri=mdl+1
        ti=1

        do while(li <= mdl .and. ri <= lst)
            if (ar(li) <= ar(ri)) then
                tmp(ti) = ar(li)
                li=li+1
            else
                tmp(ti) = ar(ri)
                ri=ri+1
            end if
            ti=ti+1
        end do

        if (li <= mdl) then
            tmp(ti:) = ar(li:mdl)
        else
            tmp(ti:) = ar(ri:lst)
        end if

        ar(fst:lst) = tmp(:)
        deallocate(tmp)
    end subroutine


    subroutine swap(x,y)
        integer(4),intent(inout):: x,y
        integer(4):: t
        t=x
        x=y
        y=t
    end subroutine
end program Divide_the_problems

Measured memory_bytes: 1724
import sys
liquids={}
O=[]

N = int(input())
for i in range(N):
    C,D=(input().split())
    if C in liquids.keys():
        liquids[C].append(int(D))
    else:
        liquids[C]=[]
        liquids[C].append(int(D))
for i in liquids.keys():
    liquids[i]=list(set(liquids[i]))
    liquids[i].sort()

M = int(input())
if M > N:
    print("No")
    sys.exit()
for i in range(M):
    O.append(input())
    
nowdens=int(10**5+1)

for i in range(M):
    try:
        tmp=liquids[O[-(i+1)]]
        if len(tmp)==0:
            print("No")
            sys.exit()
        maxdens=tmp.pop()
        while(maxdens>=nowdens):
            if len(tmp)==0:
                print("No")
                sys.exit()
            maxdens=tmp.pop()
        nowdens=maxdens
    except KeyError:
        print("No")
        sys.exit()
    
print("Yes")


Measured memory_bytes: 41360
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;
int main() {
    ll n;
    cin >> n;
    vector<ll> a(n), ans(100010, 0);
    for(int i=0;i<n;i++) {
        cin >> a[i];
        ans[a[i]]++;
        if(a[i] < 100000)
            ans[a[i]+1]++;
        if(a[i] > 0)
            ans[a[i]-1]++;
    }
    ll ma = -1;
    for(int i=0;i<100010;i++) {
        if(ma < ans[i]) {
            ma = ans[i];
        }
    }
    cout << ma << endl;

}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
  public static void main(String... args) {
    Scanner scan = new Scanner(System.in);
    String S = scan.next();
    
    int ans = 0;
    for(int i=0,j=S.length()-1; i<=j; i++,j--) {
      if(S.charAt(i) != S.charAt(j)) ans++;
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 23380
//Name: K Cards
//Level: 2
//Category: 全探索
//Note:

/**
 * 連続K枚の積を改善するには、もっとも小さい数を取り除き、K枚に入ってないものの中でもっとも大きい数を入れれば良い。
 * オーダーは O(N^2)。
 */
#include <iostream>
#include <vector>

using namespace std;

bool solve() {
    int N, K;
    if(!(cin >> N >> K)) return false;
    if(!N && !K) return false;

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

    int c1 = 0, c2 = 0;
    for(int i = 0; i <= N-K; ++i) {
        int c1_tmp = 1;
        int min_val = 100;
        for(int k = 0; k < K; ++k) {
            c1_tmp *= cs[i+k];
            min_val = min(min_val, cs[i+k]);
        }
        c1 = max(c1, c1_tmp);

        int to_swap = 0;
        for(int j = 0; j < N; ++j) {
            if(i <= j && j < i+K) continue;
            to_swap = max(to_swap, cs[j]);
        }
        c2 = max(c2, c1_tmp / min_val * to_swap);
    }
    if(c1 <= c2) {
        cout << c2-c1 << endl;
    } else {
        cout << "NO GAME" << endl;
    }
    return true;
}

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

    while(solve()) ;
    return 0;
}

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

using namespace std;
typedef long long ll;

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

  int a, b, c;
  cin >> a >> b >> c;

  if (a != b & a != c) cout << a << "\n";
  else if (b != a && b != c) cout << b << "\n";
  else cout << c << "\n";
}


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

#define ll long long 
#define pi  pair<int,int>
#define ti  tuple<int,int,int>
#define mt  make_tuple
#define mk  make_pair
#define vi  vector<int>
#define vll vector<ll>
#define fastInOut ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pr(a) for(auto x:a) cout<<x<<" ";
#define prmap(m) for(auto x:m) cout<<x.first<<" "<<x.second<<"\n";


ll n,m;
int main() {
    fastInOut
    ll k,x;
    cin>>k>>x;
    if(x<=(k*500))
           cout<<"Yes";
    else 
          cout<<"No";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vec;
typedef vector<vec> mat;

bool gauss_jordan(const mat& A,const vec& b){
  int n=A.size();
  mat B(n,vec(n+1));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)B[i][j]=A[i][j];
  
  for(int i=0;i<n;i++)B[i][n]=b[i];
  
  for(int i=0;i<n;i++){
    int pivot=i;
    for(int j=i;j<n;j++)if(abs(B[j][i])>abs(B[pivot][i]))pivot=j;
    swap(B[i],B[pivot]);
    for(int j=0;j<n;j++)
      if(i!=j&&B[j][i])
	for(int k=i;k<=n;k++)B[j][k]=(B[j][k]+B[i][k])%2;
  }
  for(int i=0;i<n;i++)if(B[i][i]==0&&B[i][n]==1) return 0;
  return 1;
}

int h,w,d,mp[25][25];
int main(){
  while(1){
    cin>>w>>h>>d;
    if(!w&&!h&&!d)break;
    mat A(h*w,vec(h*w));
    vec B(h*w);
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)cin>>mp[i][j];
    
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	int idx=w*i+j;
	B[idx] = mp[i][j];
	for(int y=0;y<h;y++)
	  for(int x=0;x<w;x++){
	    int t = abs(i-y)+abs(j-x);
	    if(t==d||t==0)A[idx][w*y+x]=1;				
	  }
      }
    cout<<gauss_jordan(A,B)<<endl;
  }
  return 0;
}

Measured memory_bytes: 5988
#include <stdio.h>
#include <stack>
using namespace std;
const int N=1e5+10;
int main(){
    int n,q,t;
    stack<int> s[N];
    scanf("%d%d",&n,&q);
    while(q--){
        scanf("%d%d",&n,&t);
        if(n==0){
            scanf("%d",&n);
            s[t].push(n);
        }
        else if(n==1){
            if(!s[t].empty())printf("%d\n",s[t].top());
        }
        else if(!s[t].empty())s[t].pop();
    }
}


Measured memory_bytes: 70324
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long sum = 0;
        for(int i = 1; i<=n; i++) {
            if(i%3!=0 && i%5!=0) sum += i;
        }
        p(sum);
    }

    public static <T> void p(T message) {
        System.out.println(message);
    }

    public static <T> void pp(T message) {
        System.out.print(message);
    }
}

Measured memory_bytes: 35756
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#include <iomanip>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
typedef pair<double,int> pdi;
int main(){
	vector<pdi> data[4];
	int k = 0;
	for(int i =0; i< 24;i++){
		int p;
		double t;
		cin>>p>>t;
		if(i<8){
			data[k].push_back(pdi(t,p));
		}else if(i>=8&&i <16){
			if(k==0){
				k++;
			}
			data[k].push_back(pdi(t,p));
		}else if(i>=16){
			if(k==1){
				k++;
			}
			data[k].push_back(pdi(t,p));
		}
	}
	for(int k = 0;k < 3;k++){
		sort(data[k].begin(),data[k].end());
	}
	cout <<fixed<<setprecision(2);
	for(int k =0;k <3;k++){
		for(int i =0;i <2;i++){
			cout <<data[k][i].second<<" "<<data[k][i].first<<endl;
		}
		data[3].push_back(pdi(data[k][2].first,data[k][2].second));
	}
	sort(data[3].begin(),data[3].end());
	for(int i =0;i <2;i++){
		cout <<data[3][i].second<<" "<<data[3][i].first<<endl;
	}
	return 0;
}

Measured memory_bytes: 1300
#https://wakabame.hatenablog.com/entry/2020/05/24/031143

#from collections import defaultdict
#from pprint import pprint
#from collections import deque
#from collections import Counter
#from copy import deepcopy
#from itertools
#import sys 
#sys.setrecursionlimit(N) #N回まで再起を許可する。
#import numpy as np
#import math
# = map(int,input().split())

# = list(map(int,input().split()))

# = [list(map(int,input().split())) for _ in range(XXXX)]

def func(i):
    if i == 0:
        return 0
    elif i == 1:
        return d
    elif i in memo:
        return memo[i]
    else:
        min_val = int(min(
            d*i,
            d*abs(i-i//2*2) + a + func(i//2),
            d*abs(i-(i+1)//2*2) + a + func((i+1)//2),
            d*abs(i-i//3*3) + b + func(i//3),
            d*abs(i-(i+2)//3*3) + b + func((i+2)//3),
            d*abs(i-i//5*5) + c + func(i//5),
            d*abs(i-(i+4)//5*5) + c + func((i+4)//5)
        ))

    memo[i] = min_val
    return min_val



t = int(input())

nabcd = [list(map(int,input().split())) for _ in range(t)]


for i in range(t):
    n = nabcd[i][0]
    a = nabcd[i][1]
    b = nabcd[i][2]
    c = nabcd[i][3]
    d = nabcd[i][4]

    memo = {}


    print(func(n))
    #print(memo)


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

using namespace std;

int main(){
    int N;
    cin>>N;
    vector<int> a(3*N);
    for(int i = 0;i<3*N;i++){
        cin>>a[i];
    }
    sort(a.begin(), a.end());
    long int sum = 0;
    for(int j = N;j<3*N;j+=2){
        sum += a[j];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 4588
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<bitset>
#include<list>
using namespace std;

struct Info {
	int ind;
	bool jdg;
	Info(int i, bool b) {
		ind = i;
		jdg = b;
	}
};

class bfs {
public:
	bfs(vector<vector<int>>& e);
	~bfs(); 
	vector<int> main_calc();
private:
	// 最近接の部屋を探す
	void search_adj(int loc);
private:
	// edge を格納
	vector<vector<int>>& edge;
	// vertex の数
	int N;
	// vertex の道しるべと履歴状態を格納
	vector<Info> state;
	// 次に探索する部屋を格納
	vector<int> adj;
	// 履歴を格納
	vector<int> log;
};

bfs::bfs(vector<vector<int>>& e) : edge(e) {
	N = edge.size();
	state.clear();
	for (int i = 0; i < N; i++) {
		state.push_back(Info(1, false));
	}
	state[0] = Info(1, true);
	adj.clear();
	adj.push_back(0);
	log.clear();
	log.push_back(0);
}

bfs::~bfs() {
}

// 最近接の部屋を探す
void bfs::search_adj(int loc) {
	// 部屋 loc の最近接の部屋を探す
	for (int j = 0; j < edge[loc].size(); j++) {
		// まだ探索していない最近接の部屋に関して
		if (state[edge[loc][j]].jdg == false) {
			// 探索済み
			state[edge[loc][j]].jdg = true;
			// 道しるべを格納
			state[edge[loc][j]].ind = loc;
			// 次の探索の部屋として格納
			adj.push_back(edge[loc][j]);
			// 履歴を格納
			log.push_back(edge[loc][j]);
		}
	}
}

vector<int> bfs::main_calc() {

	vector<int> dum;

	// 全部の部屋を探索するまでループ
	while (log.size() < N) {
		dum = adj;
		// 探索する部屋を初期化（dumにコピーしたので）
		adj.clear();
		for (int i = 0; i < dum.size(); i++) {
			search_adj(dum[i]);
		}
	}

	// 道しるべを格納
	vector<int> ans;
	for (int i = 1; i < N; i++) {
		ans.push_back(state[i].ind + 1);
	}

	return ans;
}

int main() {

	int N;
	int M;
	cin >> N >> M;

	vector<vector<int>> edge(N, vector<int>());

	int A, B;
	for (int i = 0; i < M; i++) {
		cin >> A >> B;
		A--;
		B--;
		edge[A].push_back(B);
		edge[B].push_back(A);
	}

	bfs b(edge);

	vector<int> a = b.main_calc();

	cout << "Yes" << endl;

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

	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

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

#define INF INT_MAX/3

int n;
int a[1111];

int main(){
	cin.sync_with_stdio(false);
  while(cin>>n){
    if(n==0)break;
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    int gap=INF;
    rep(i,n-1){
      if(gap>a[i+1]-a[i]){
        gap=a[i+1]-a[i];
      }
    }
    cout<<gap<<endl;
  }
	return 0;
}

Measured memory_bytes: 3100
# coding: utf-8
def II(): return int(input())
def ILI(): return list(map(int, input().split()))


def read():
    N = input()
    return (N, )


def solve(N):
    rev = str(int("".join(reversed(N))))
    if N == rev:
        ans = "Yes"
    else:
        ans = "No"
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

#[allow(non_snake_case)]
fn main() {
    input! {
        N:usize,
        K:usize,
        A:[usize; N]
    }
    let mut c = 0;
    let mut t = 0;
    let mut v = vec![std::usize::MAX; N];
    let cycle;
    loop {
        v[t] = c;
        t = A[t] - 1;
        c += 1;
        if c == K {
            print!("{}", t + 1);
            return;
        }
        if v[t] != std::usize::MAX {
            cycle = c - v[t];
            break;
        }
    }
    dbg!(cycle, t);
    let mut k = (K - c) % cycle;
    dbg!(k);
    while k > 0 {
        t = A[t] - 1;
        k -= 1;
    }
    println!("{}", t + 1);
}


Measured memory_bytes: 5192
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,a[200010],b,c,i,j,h,sum = 0;
    cin>>h>>n;
    for(i=0;i<h;i++)
    {
        cin>>a[i];
    }
    sort(a,a+h);
    for(i=0;i<h-n;i++)
        sum+=a[i];
    cout<<sum<<endl;
    return 0;
}




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

int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; i++)
    {
        ans += (n - 1) / i;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3640
from itertools import combinations as comb
n,k=map(int,input().split())
f=lambda x,y:(min(x,y),max(x,y))
o=[tuple(map(int,input().split())) for _ in range(n)]

v=float("inf")
for (a,b) in comb(range(n),2):
  for (c,d) in comb(range(n),2):
    lx,rx=f(o[a][0],o[b][0])
    dy,uy=f(o[c][1],o[d][1])
    cnt=0
    for i in o:
      if lx<=i[0]<=rx and dy<=i[1]<=uy:
        cnt+=1
    if cnt>=k:
      v=min(v,(rx-lx)*(uy-dy))
print(v)

Measured memory_bytes: 58204
def resolve():
    x = int(input())
    l = [1]

    for i in range(2, 1001):
        j = 2
        while i ** j <= 1000:
            l.append(i ** j)
            j += 1

    l = [i for i in l if i <= x]
    ans = max(l)
    print(ans)

resolve()

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef pair<int,int> P;
int N,M,S,T;
int dp[100010][3] = {};
int inf = 1e9;
vector<vector<int>> v(100010);

int main(){
    cin >> N >> M;
    int a,b;
    for(int i=0;i<M;i++){
        cin >> a >> b;
        v[a].push_back(b);
    }
    cin >> S >> T;
    for(int i=1;i<=N;i++) for(int j=0;j<=2;j++) dp[i][j] = inf;
    dp[S][0] = 0;
    queue<P> Q;
    Q.push({S,0});
    while(!Q.empty()){
        P p = Q.front(); Q.pop();
        for(auto x:v[p.first]){
            int ne = (p.second+1)%3;
            if(dp[x][ne]==inf){
                dp[x][ne] = dp[p.first][p.second]+1;
                Q.push({x,ne});
            }
        }
    }
    cout << (dp[T][0]!=inf? dp[T][0]/3:-1) << endl;
}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
#include<math.h>
#include <stdio.h>
#include<vector>
#include<deque>
#include<stdlib.h>
#include <algorithm>
#include<set>
#include<map>
#include <limits>
#include<iomanip>
#include<string>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
#define d_5 100000
#define d9_7 1000000007
//UNION FIND
//構造体
struct Union{
  int num;
  int size;
};
Union par[d_5*5];//親の番号
//n要素で初期化
void init(int n){
  rep(i,n){
    par[i].num=i;
    par[i].size=1;
  }
}
//木の根を求める
int root(int x){
  if(par[x].num==x){
    return x;
  }else{
    return par[x].num=root(par[x].num);//経路圧縮
  }
}
//属する集合の要素数を求める
int size(int x){
  return par[root(x)].size;
}
//x,yが同じ集合に属するか否か
bool same(int x,int y){
  return (root(x)==root(y));
}
//x,yの属する集合を併合
void unite(int x,int y){
  x=root(x);
  y=root(y);
  if(x==y)return;
  par[y].size += par[x].size;
  par[x].num = y;
}
//集合の数を数える
int count(int n){
  set<int> cnt;
  //nは要素数
  rep(i,n){
    cnt.insert(root(i));
  }
  return cnt.size();
}
int main(void){
  int n,m;
  cin>>n>>m;
  vector<pair<int,int>> xy(m);
  vector<int> z(m);
  init(n);
  rep(i,m){
    cin>>xy[i].first>>xy[i].second>>z[i];
    xy[i].first--;xy[i].second--;
    z[i]%=2;
    unite(xy[i].first,xy[i].second);
  }
  cout<<count(n)<<endl;
  return 0;
}

Measured memory_bytes: 6784
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <unordered_map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;

const double EPS = 1e-9;

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

	int N;
	cin >> N;
	vector<int> A(N);
	rep(i, 0, N)cin >> A[i];

	vector<pii> DP;

	int h = -1;
	rep(i, 0, N)
	{
		if (chmax(h, A[i]))
		{
			DP.push_back(mp(A[i], i));
		}
	}

	vector<int> MC(N + 1, 0);
	vector<int> IC(N + 1, 0);

	rep(i, 0, N)
	{
		int idx = lower_bound(all(DP), mp(A[i], INF)) - DP.begin();
		MC[0]++;
		MC[idx]--;
		int d = 0;
		if (idx > 0)d = DP[idx - 1].first;
		IC[idx] += A[i] - d;
	}

	rep(i, 1, N + 1)
	{
		MC[i] += MC[i - 1];
	}

	vector<int> ANS(N, 0);
	rep(i, 0, SZ(DP))
	{
		if (DP[i].second == INF)break;
		int d = 0;
		if (i > 0)d = DP[i - 1].first;
		ANS[DP[i].second] += IC[i] + MC[i] * (DP[i].first - d);
	}

	rep(i, 0, N)
	{
		cout << ANS[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 7956