akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

#define int long long

const int N = 51;

int used[N];
vector<int> g[N];

int h[N];
int p[N];
int lca[N][N];
vector<int> sub[N];

void dfs(int cur, int ch, int pr) {
    used[cur] = 1;
    h[cur] = ch;
    p[cur] = pr;
    lca[cur][cur] = cur;
    sub[cur].push_back(cur);
    for (auto t : g[cur]) {
        if (!used[t]) {
            dfs(t, ch + 1, cur);
            for (auto x : sub[t]) {
                for (auto y : sub[cur]) {
                    lca[x][y] = cur;
                    lca[y][x] = cur;
                }
            }
            for (auto x : sub[t]) {
                sub[cur].push_back(x);
            }
        }
    }
}

int n;

int solve(vector<pair<int, int>> tk) {
    vector<int> vl(n);
    auto appl = [&](int v, int h) {
        // cerr << v + 1 << ' ' << h << endl;
        for (int i = 0; i < h; i++) {
            vl[v] = 1;
            v = p[v];
        }
    };
    for (auto t : tk) {
        int x, y;
        tie(x, y) = t;
        // cerr << "hr " << x + 1 << ' ' << y + 1 << ' ' << lca[x][y] + 1 << endl;
        appl(x, h[x] - h[lca[x][y]]);
        appl(y, h[y] - h[lca[x][y]]);
    }
    int ans = 1;
    for (int i = 1; i < n; i++) {
        if (!vl[i]) {
            ans *= 2;
        }
    }
    return ans;
}

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

    cin >> n;
    for (int i = 1; i < n; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(0, 0, -1);
    int m;
    cin >> m;
    vector<pair<int, int>> bn(m);
    for (auto &t : bn) {
        cin >> t.first >> t.second;
        t.first--;
        t.second--;
    }
    int ans = 0;
    for (int mask = 0; mask < (1 << m); mask++) {
        vector<pair<int, int>> nb;
        for (int i = 0; i < m; i++) {
            if ((mask >> i) & 1) nb.push_back(bn[i]);
        }
        int c = -1;
        if (__builtin_popcount(mask) & 1) c = 1;
        ans -= c * solve(nb);
        // cerr << mask << ' ' << solve(nb) << endl;
    }
    cout << ans << endl;
}   


Measured memory_bytes: 384
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int x=0,i,a[6];
	for(i=0;i<6;i++) scanf("%d",&a[i]);
	sort(a,a+4,greater<int>());
	for(i=0;i<3;i++) x=x+a[i];
	if(a[4]<a[5]) x=x+a[5];
	else x=x+a[4];
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 2772
s = input()

st = 0
ed = 0
sl = len(s)
for i in range(sl):
    if s[i] == "A":
        st = i
        break
for i in reversed(range(sl)):
    if s[i] == "Z":
        ed = i
        break
print(sl - st - (sl-ed) + 1)

Measured memory_bytes: 3512
#include <stdio.h>
#include <string.h>
char t[3000000];
int q[99999];

int main(void){
	int l, r, n, g, b, c, x, y, i, c1, c2;
	char s[20];
	for(; scanf("%s", s ), *s - '0';){
		memset( t, 0, 700000 );
		*q = 0;
		for( n = 0; s[n]; n++ ){
			*q |= ( s[n] == 'b' ? 2 : s[n] == 'g' ) << ( 2 * n );
		}
		n *= 2;
		g = 0x55555 & ( 1 << n ) - 1;
		b = 0xAAAAA & ( 1 << n ) - 1;

		q[1] = -1;
		l = c = 0;
		r = 2;
		for(; r - l > 1; ){
			x = q[l++];
			if( !x || x == g || x == b ){ ++r;	break;	}
			if( x == -1 ){	++c;	q[r++] = -1;	}
			else{
				c1 = x & 3;
				for( i = 2; i < n; i += 2 ){
					c2 = x >> i & 3;
					if( c1 != c2 ){
						y = x & ~( 15 << i - 2 );
						y |= ( 3 - c1 - c2 ) * 5 << i - 2;
						if( !t[y] ){
							t[y] = 1;
							q[r++] = y;
						}
					}
					c1 = c2;
				}
			}
		}
		if( r - l > 1 ){	printf("%d\n", c );	}
		else{	puts("NA");	}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
const ll INF=1e15+7;
const ll N = 1002;
ll a,b,c,ans=0,m,mn=0,m1=0;

int main(){
	cin>>a>>b>>c;
	m=max(a,b);
	m=max(m,c);

	ans+=(m-a)/2;
	if(m%2==a%2)a=m;
	else a=m-1;

	ans+=(m-b)/2;
	if(m%2==b%2)b=m;
	else b=m-1;

	ans+=(m-c)/2;
	if(m%2==c%2)c=m;
	else c=m-1;	

	if(a==b && c==b){
		cout<<ans<<endl;
		return 0;
	}
	if(a==m){
		mn++;
	}else{
		m1++;
	}
	if(b==m){
		mn++;
	}else{
		m1++;
	}
	if(c==m){
		mn++;
	}else{
		m1++;
	}
	if(mn==2){
		cout<<ans+2<<endl;
		return 0;
	}else{
		cout<<ans+1<<endl;
		return 0;
	}

	return 0;
}


Measured memory_bytes: 256
n = int(input())
list = []
list1 = []
for i in range(1, n+1):
    if i%5==0 and i%3==0:
        list.append('FizzBuzz')
    elif i%3==0:
        list.append('Fizz')
    elif i%5==0:
        list.append('Buzz')
    else:
        list.append(i)
for j in list:
    if isinstance(j, int):
        list1.append(j)
print(sum(list1))

Measured memory_bytes: 37732
def main():
    N = int(input())
    S = [int(input()) for _ in range(N)]
    S.sort()
    score = sum(S)
    if score % 10 != 0:
        print(score)
    else:
        find = False
        for i in range(N):
            if (score - S[i]) % 10 != 0:
                score -= S[i]
                find = True
                break
        if find:
            print(score)
        else:
            print(0)
main()

Measured memory_bytes: 3060
import heapq
def dijkstra_heap(s,g):
    used = [True] * n #True:未確定
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,[e[0],e[1]])
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        if v==g:
            return minedge[0]
        kai=minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+kai,e[1]])                   
    return -1

################################
n,m = map(int,input().split()) #n:頂点数　w:辺の数

edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
pp=[]
for i in range(m):
    x,y,z = map(int,input().split())
    edge[x-1].append([z,y-1])
    edge[y-1].append([z,x-1])
    pp.append([x-1,y-1,z])
ans=0
for i in range(m):
    if pp[i][2]>dijkstra_heap(pp[i][0],pp[i][1]):
        ans+=1
print(ans)


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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n+1);
  rep(i,k) {
    int d;
    cin >> d;
    rep(j,d) {
      int v;
      cin >> v;
      a[v]++;
    }
  }
  int ans = 0;
  for(int i = 1; i <= n; i++) {
    if(a[i] == 0) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
function Main(input) {
    input = input.split("\n");
    ans = 0;
    alp = "abcdefghijklmnopqrstuvwxyz";
    for (i = 1; i < input[1].length; i++) {
        cnt = 0;
        sub1 = input[1].substring(0, i);
        sub2 = input[1].substring(i);
        for (j = 0; j < alp.length; j++)
            if (sub1.indexOf(alp[j]) != -1 && sub2.indexOf(alp[j]) != -1) cnt++;
        ans = Math.max(ans, cnt);
    }
    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

long long int llabs(long long int Num){
    if(0 <= Num){
        return Num;
    }else{
        return -Num;
    }
}

int main(void){
    long long int A,B;
    unsigned long long int tmpA,tmpB;
    cin >> A >> B;


    for(long long int i=0; i<=1000000000; i++){
        if(llabs(A - i) == llabs(B - i)){
            cout << i <<endl;
            return 0;
        }
    }

    cout << "IMPOSSIBLE" <<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n],b[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i]>>b[i];
  }
  double sum=0;
  for(int i=0;i<n-1;i++)
  {
    for(int j=i+1;j<n;j++)
    {
      sum+=(sqrt((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])));
    }
  }
  sum=(sum/n);
  sum*=2;
  cout<<fixed<<setprecision(9)<<sum;
 return 0; 
}

Measured memory_bytes: 256
#include<iostream>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<algorithm>
    #include<string>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    using namespace std;
    #define INF 10000000;
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)

    int main(){
     int n,k,ans;
     cin >> n >> k;
     vector<int> a(n);
     vector<int> buc(n);

     rep(i,n){
       cin >> a[i];
     }

     rep(i,n){
       buc[a[i]]++;
     }

     sort(buc.begin(),buc.end(),greater<int>());
     
	ans = n;
    rep(i,k){
      ans -= buc[i];
    }
    cout << ans <<endl;
    }
    

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using ll = long long;
#define vc vector
using namespace std;
int main() {
  int N,a[100001];
  cin>>N;
  for (int i(1);i<=N;i++) cin>>a[i];
  int now(1);
  int cnt(0);
  int next(0);
  for (int i(0);i<N;i++){
    next=a[now];
    cnt+=1;
    if (next==2){
      cout << cnt <<endl;
      return 0;
    }
    now=next;
  }
  cout << "-1" <<endl;
  return 0;
}



Measured memory_bytes: 640
import java.io.*;
import java.util.*;
public class Main {
	static long MOD = 2 << 29;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		char[] in = sc.next().toCharArray();
		boolean ok = false;
		IN:for(int i = 0; i < in.length; i++) {
			if(in[i] == 'C') {
				for(int j = i + 1; j < in.length; j++) {
					if(in[j] == 'F') {
						ok = true;
						break IN;
					}
				}
			}
		}
		if(ok) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
	
	
	
	
}
 
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        if (!hasNext()) throw new NoSuchElementException();
        int n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}

Measured memory_bytes: 8148
def insert(string, hash_list):
    hali = hash_list
    if string not in hali:
        hali[string] = 1
    return hali
 
 
def find(string, hash_list):
    hali = hash_list
    return string in hali
 
 
 
n = int(input())
words = {}
operate = [list(input().split()) for i in range(n)]
 
for i in operate:
    if i[0] == "insert":
        insert(i[1], words)
    elif i[0] == "find":
        if find(i[1], words):
            print("yes")
        else:
            print("no")


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

int main()
{
    long long n, m;
    cin>>n>>m;
    long long w = min(n, m/2);
    long long p = max(m-n*2, 0LL);
    cout<<w+p/4LL<<endl;
    return 0;
} 

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

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

    int left = N % 10; // 1桁目の数字

    if(left == 3) {
        cout << "bon" << endl;
    } else if(left == 0 || left == 1 || left == 6 || left == 8) {
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }

    return 0;
}

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

using namespace std;

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

	vector<string> ans;

	function<void(int, int, string)> dfs = [&] (int d, int p, string s) {
		if(d == n) {
			ans.emplace_back(s);
			return;
		}

		for(int i = 0; i <= p + 1; ++i) {
			dfs(d + 1, max(p, i), s + (char)('a' + i));
		}

	};

	dfs(1, 0, "a");

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

	for(auto& s : ans) {
		cout << s << '\n';
	}
	return 0;
}

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

//a^n (mod m)
const long long mod = 13;
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//mod mでの a の逆元を求める
long long modinv(long long a) {
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod; 
    if (u < 0) u += mod;
    return u;
}

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

    ll md=1e9+7;

    int n=s.size();
    ll dp[n+1][13]={};
    dp[0][0]=1;
    ll p[111111]={};

    for(int i=0;i<n;i++){
        p[i] = modpow(10,i);
    }

    reverse(s.begin(),s.end());

    for(int i=0;i<n;i++){
        for(int j=0;j<13;j++){
            if(s[i]=='?'){
                for(int k=0;k<=9;k++){
                    dp[i+1][j] += dp[i][(1300000000 + j - k*p[i])%13];
                    dp[i+1][j]%=md;
                }
            }
            else {
                dp[i+1][j] += dp[i][(1300000000 + j - (ll)(s[i]-'0')*p[i])%13];
                dp[i+1][j]%=md;
            }
        }
    }
    cout<<dp[n][5]<<endl;
}

Measured memory_bytes: 11472
#include<bits/stdc++.h>
#define  ll  long long int

using namespace std;


int main()
{


  ll a,b,k,i,j,p,x,y,z;

  cin>>a>>b>>k;

  if(k>=a)
  {
    x=k-a;
    a=0;
    if(x>=b)
    {
      b=0;
    }
    else
    {
      b=b-x;
    }
  }
  else
  {
    a=a-k;

  }

  cout<<a<<" "<<b<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back

int main() {
    string s;
    cin>>s;
    ll sum=0;
    for(ll i=0;i<s.size();i++) {
        ll x=s[i]-'0';
        sum+=x;
    }
    if(sum%9==0) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 3748
d = {1: 1, 2: 2, 3: 1, 4: 3, 5: 1, 6: 3, 7: 1, 8: 1, 9: 3, 10: 1, 11: 3, 12: 1}
x, y = map(int, input().split())

if d[x] == d[y]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
N,W = [int(i) for i in input().split()]
dp = [0 for i in range(W+1)] # dp[i] is the the max value you have achieve with weight i
for i in range(N):
  w,value = [int(i) for i in input().split()]
  for weight in range(W-w, -1, -1): # range of kanpsack weight in which i can push the current item
    dp[weight + w] = max(dp[weight + w], dp[weight] + value)
print("%s" % dp[W])

Measured memory_bytes: 45424
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<iomanip>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<vector>

using namespace std;

#define LL long long

int n,S[10001],q,C=0;

int main() {
	cin>>n;
	for(int i=0;i<n;i++)cin>>S[i];
	cin>>q;
	for(int i=0;i<q;i++){
		int T;
		cin>>T;
		for(int j=0;j<n;j++){
			if(T==S[j]){
				C++;
				break;
			}
		}
	}
	cout<<C<<endl;
	return 0;
}




Measured memory_bytes: 3120
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 100009 /// Still trying to be normal
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e9 + 15;
ll dp[102][100002];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    memset(dp,0,sizeof dp);
    ll n,w;
    cin>>n>>w;
    pii vet[n+2];
    rep(i,1,n+1){
        ll a,b;
        cin>>a>>b;
        vet[i]=make_pair(a,b);
    }
    rep(i,1,n+1){
        for(int j=w;j>=0;j--){
            if(w-j>=vet[i].F){
                dp[i][j]=max(dp[i-1][j],dp[i-1][j+vet[i].F]+vet[i].S);
                // cout<<i<<" "<<j<<" "<<dp[i][j]<<'\n';
            }
            else dp[i][j]=dp[i-1][j];
        }
    }
    ll ans=-1;
    rep(i,0,w+1){
        ans=max(ans,dp[n][i]);
    }
    cout<<ans<<'\n';
    return 0;   
}

Measured memory_bytes: 80000
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
const int N = 2e5 + 10;
 
int main(){
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n, 0), h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  for (int i = 1; i < n; i++) {
    if (h[i] <= h[i - 1]) {
      a[i] = a[i - 1] + 1;
    }
  }
  cout << *max_element(a.begin(), a.end()) << endl;
  return 0;
}

Measured memory_bytes: 1024
x,y = gets.strip.split(" ").map(&:to_i)
count = "-1 -1 -1"
(0..x).each do |n|
    (0..(x-n)).each do |m|
        l = x - n - m
        count = "#{n} #{m} #{l}" if 10000 * n + 5000 * m + 1000 * l == y
    end
end
print count

Measured memory_bytes: 1916
#include<stdio.h>
#define MAX 100005

typedef struct { 
    int p;
    int l;
    int r;
} Node;

Node np[MAX]; 
int i;

void Preorder(int i){

    printf(" %d",i);
    if(i != -1){
        if(np[i].l != -1) {
            Preorder(np[i].l);
        }
        if(np[i].r != -1){
            Preorder(np[i].r);
        }
    }
}

void Inorder(int i){

    if(i != -1){
        if(np[i].l != -1){
            Inorder(np[i].l);
        }
        printf(" %d",i);

        if(np[i].r != -1){
            Inorder(np[i].r);
        }
    }
}

void Postorder(int i){

    if(i != -1){
        if(np[i].l != -1) Postorder(np[i].l);
        if(np[i].r != -1) Postorder(np[i].r);
    }
    printf(" %d",i);
}

int main(){

    int n;
    int key, c1, c2;

    scanf("%d", &n);

    for(i = 0; i < n; i++){
        np[i].p = np[i].l = np[i].r = -1;
    }

    for(i = 0; i < n; i++){
        scanf("%d%d%d", &key, &c1, &c2);

        np[c1].p = key;
        np[c2].p = key;
        np[key].l = c1;
        np[key].r = c2;
    }

    for(i = 0; i < n; i++){
        if(np[i].p == -1) break;
    }

    printf("Preorder\n");
    Preorder(i);
    printf("\n");

    printf("Inorder\n");
    Inorder(i);
    printf("\n");

    printf("Postorder\n");
    Postorder(i);
    printf("\n");

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<tuple<string, int, int>> vec(n);
  rep(i, n) {
    string s;
    int x = i + 1, p;
    cin >> s >> p;
    tuple<string, int, int> tpl(s, -1 * p, x);
    vec.at(i) = tpl;
  }
  sort(vec.begin(), vec.end());
  for (tuple tpl : vec) {
    int a = get<2>(tpl);
    cout << a << endl;
  }    
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    rep(i,n){
        cin >>a[i];
    }
    rep(i,n){
        cin >> b[i];
    }
    rep(i,n){
        cin >> c[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    ll ans = 0;
    rep(i,n){
        int val = b[i];
        ll cnt_a = lower_bound(a.begin(),a.end(),val) - a.begin();
        ll cnt_c = c.end()- upper_bound(c.begin(),c.end(),val);
        ans+=cnt_a*cnt_c;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
using System;
using static System.Console;

namespace abc158
{
    class Program
    {
        static void Main()
        {
            var nab = ReadLine().Split(' ');
            var n = long.Parse(nab[0]);
            var a = long.Parse(nab[1]);
            var b = long.Parse(nab[2]);
            var repeats = n / (a + b);
            var rest = n % (a + b);
            WriteLine(a * repeats + Math.Min(rest, a));
        }
    }
}


Measured memory_bytes: 27524
#pragma GCC optimize(3)
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0xff,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

int n;
int h[100010];
int dp[100010];
int cost(int i,int j){
	return abs(h[i]-h[j]);
}
int main(int argc,char** argv){
	cin>>n;
	rep(i,n){
		cin>>h[i];
	}
	dp[0]=0;
	dp[1]=cost(0,1);
	for(int i=2;i<n;i++){
		dp[i]=min(dp[i-1]+cost(i-1,i),dp[i-2]+cost(i-2,i));
	}
	cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main() {

	int n;
	scanf("%d", &n);
	char arr[5];
	
	int sumA = 0, sumW = 0, sumT = 0, sumR = 0;
	for(int i = 0; i<n; i++){
		scanf("%s", arr);
		if(arr[0]=='A'){
			sumA++;
		}
		else if(arr[0]=='W'){
			sumW++;
		}
		else if(arr[0]=='T'){
			sumT++;
		}
		else if(arr[0]=='R'){
			sumR++;
		}
	}

	printf("AC x %d\n", sumA);
	printf("WA x %d\n", sumW);
	printf("TLE x %d\n", sumT);
	printf("RE x %d\n", sumR);

    return 0;
}

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

typedef long long  LL;
const double pi=acos(-1);
struct point{int x,y;}a[105];
int n;
double b[205];

void work()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++)
		scanf("%d %d",&a[i].x,&a[i].y);
	for (int i=1,tot,win; i<=n; i++)
		{
			tot=0,win=0;
			for (int j=1; j<=n; j++)
				if (i!=j)
					{
						double r=atan2(a[j].y-a[i].y,a[j].x-a[i].x);
						b[++tot]=r,b[++tot]=r+2*pi;
					}
			sort(b+1,b+tot+1);
			for (int j=2; j<=tot; j++)
				if (b[j]-b[j-1]>pi)
					{
						printf("%.10lf\n",(b[j]-b[j-1]-pi)/2/pi),win=1;
						break;
					}
			if (!win)  printf("%.10lf\n",0.0);
		}
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String S = sc.next(); //計算回数

		if(S.charAt(S.length()-1)=='s'){
			System.out.println(S.substring(0, S.length())+"es");
		}else{
			System.out.println(S.substring(0, S.length())+"s");
		}
	}
}


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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#ifdef MAROON_LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

ll read(){
	ll i;
	scanf("%" SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

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

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

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

signed main(){
	string s=readString();
	if(int(s.size())<26){
		vi used(26,0);
		for(auto c:s)
			used[c-'a']=1;
		REP(i,26)if(!used[i]){
			cout<<s<<char('a'+i)<<endl;
			return 0;
		}
	}else{
		string t=s;
		if(next_permutation(ALL(t))){
			REP(i,26){
				cout<<t[i];
				if(t[i]!=s[i])break;
			}
			cout<<endl;
		}else{
			cout<<-1<<endl;
		}
	}
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
long long modpow(long long a, long long b){
  long long ans = 1;
  while (b > 0){
    if (b % 2 == 1){
      ans *= a;
      ans %= MOD;
    }
    a *= a;
    a %= MOD;
    b /= 2;
  }
  return ans;
}
long long modinv(long long a){
  return modpow(a, MOD - 2);
}
vector<long long> mf = {1};
long long modfact(int n){
  if (mf.size() > n){
    return mf[n];
  } else {
    for (int i = mf.size(); i <= n; i++){
      long long next = mf.back() * i % MOD;
      mf.push_back(next);
    }
    return mf[n];
  }
}
long long modbinom(int n, int k){
  if (n < 0 || k < 0 || k > n){
    return 0;
  }
  return modfact(n) * modinv(modfact(k)) % MOD * modinv(modfact(n - k)) % MOD;
}
int main(){
  int K, N;
  cin >> K >> N;
  int M = (K + 1) / 2;
  vector<long long> tmp(M, 0);
  for (int i = 1; i <= M; i++){
    for (int j = 0; j <= i; j++){
      long long d = 1;
      d *= modbinom(K - i - j - 1 + N, N);
      d *= modbinom(i, j);
      d %= MOD;
      d *= modpow(2, i - j);
      d %= MOD;
      if (j % 2 == 0){
        tmp[i - 1] += d;
      } else {
        tmp[i - 1] += MOD - d;
      }
      tmp[i - 1] %= MOD;
    }
  }
  vector<long long> ans(2 * K - 1);
  for (int i = 0; i < K; i++){
    ans[i] = tmp[i / 2];
  }
  for (int i = K; i < 2 * K - 1; i++){
    ans[i] = ans[2 * K - 2 - i];
  }
  for (int i = 0; i < 2 * K - 1; i++){
    cout << ans[i] << endl;
  }
}

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

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

	if (N * 2 < K) {
		cout << 0 << endl;
		return 0;
	}

	ll x = N / K;

	ll res = 0;
	for (int i = 1; i <= N; i++) {
		if (i + N < K) continue;

		ll a = i % K;
		ll b = (K - a) % K;
		if (b > N) continue;

		if (a == 0) {
			res += (x * x);
			continue;
		}

		if ((b * 2 + K) % K == 0) {
			ll y = x;
			if ((x * K + b) <= N) y++;

			res += (y * y);

			if ((b * 2) < K) res--;
		}
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const int INF = (1 << 30);
const ll INFL = (1LL << 62);
const ll MOD = 1000000007;
template <class T>
bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T>
ll mod_pow(ll a, ll n, T mod) {
    mod = (ll)mod;
    ll res = 1, p = a % mod;
    while (n) {
        if (n & 1) res = res * p % mod;
        p = p * p % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<string> A(H);
    rep(i, H) cin >> A[i];
    int prev_index = -1;
    rep(i, W) {
        if (A[0][i] == '#') {
            prev_index = i;
        } else {
            break;
        }
    }
    if (prev_index == -1) {
        cout << "Impossible" << endl;
        return 0;
    }
    for (int i = 1; i < H; i++) {
        int now_index = -1;
        rep(j, prev_index) {
            if (A[i][j] == '#') {
                cout << "Impossible" << endl;
                return 0;
            }
        }
        for (int j = prev_index; j < W; j++) {
            if (A[i][j] == '#')
                now_index = j;
            else
                break;
        }
        for (int j = now_index + 1; j < W; j++) {
            if (A[i][j] == '#') {
                cout << "Impossible" << endl;
                return 0;
            }
        }
        if (now_index >= prev_index) {
            prev_index = now_index;
        } else {
            cout << "Impossible" << endl;
            return 0;
        }
    }
    cout << "Possible" << endl;

    return 0;
}

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

int main() {
int N;
  int64_t ans=0;
  map<int64_t, int64_t> kosuu;
  cin >> N;
  vector<int64_t> kazu(N);
  for(int i = 0; i < N; i++){
  	cin >> kazu[i];
    if(kosuu.count(kazu[i])){
    	kosuu[kazu[i]] = kosuu[kazu[i]] + 1;      	
    }
    else{
    	kosuu[kazu[i]] = 1;
    }
    ans += kazu[i];
  }

  int64_t a,b,c,Q;
  cin >> Q;
  for(int i = 0; i < Q; i++){
  	cin >> a >> b;
    c = b-a;
    if(kosuu.count(a)){
    	ans = ans + kosuu[a] * c;
      if(kosuu.count(b)){
      	kosuu[b] = kosuu[b] + kosuu[a];
      }
      else{
      	kosuu[b] = kosuu[a];
      }
      kosuu[a] = 0;
    }
    cout << ans << endl;
  }


}

Measured memory_bytes: 8988
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX + 1];
  int n,i,j;
  scanf("%d",&n);

  A = malloc(sizeof(short) * n + 1);
  B = malloc(sizeof(short) * n + 1);

  for(i = 0; i <= VMAX; i++)
    C[i] = 0;

  for(i = 0; i < n; i++){
    scanf("%hu", &A[i+1]);
    C[A[i+1]]++;
  }

  for(i = 1; i <= VMAX; i++)
    C[i] = C[i] + C[i-1];

  for(j = 1; j <= n; j++){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i = 1; i <= n; i++){
    if(i > 1)
      printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
  
  return 0;
}



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

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

int main(){
  int n;
  cin >> n;
  priority_queue<int> data;
  for(int i = 0; i < n; i++){
    int x; 
    cin >> x;
    data.push(x);
  }
  int answer = 0;
  for(int i = 0; i < n; i++){
    if(i == 0){
      answer += data.top() / 2;
      data.pop();
    }
    else{
      answer += data.top();
      data.pop();
    }
  }
  cout << answer << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> l = new ArrayList<>();

        while(sc.hasNextInt()) {
            l.add(sc.nextInt());
        }

        Collections.sort(l, Collections.reverseOrder());
        l.stream().limit(3).forEach(System.out::println);
    }
}

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

int main(){
    int n;
    list<int> V;
    cin >> n;
    string com_s;
    int com_n;
    rep(i, n){
        cin >> com_s;
        if(com_s == "delete"){
            cin >> com_n;
            auto itr = find(V.begin(), V.end(), com_n);
            if (itr != V.end()){
                V.erase(itr);
            }
        }else if (com_s == "insert"){
             cin >> com_n;
             V.insert(V.begin(), com_n);
        }else if (com_s == "deleteFirst"){
            V.pop_front();
        }else if (com_s == "deleteLast"){
            V.pop_back();
        }
    }
    
    if (V.size() >= 1){
        for(auto itr = V.begin(); itr != --V.end(); ++itr){
            cout << *itr << " ";
        }
        cout << V.back() << endl;
    }else{
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 34312
while 1:
    n=int(input())
    if n==0:break
    l=d=mi=cl=cm=cd=0
    for i in range(n):
        t,M=input().split()
        M=int(M)
        h,m=map(int,t.split(":"))
        if m>M:M+=60
        a=M-m<=8
        if 11<=h<15:cl+=1;l+=a
        elif 18<=h<21:cd+=1;d+=a
        elif 21<=h or h< 2:cm+=1;mi+=a
    print('lunch', l*100//cl if cl else 'no guest')
    print('dinner', d*100//cd if cd else 'no guest')
    print('midnight', mi*100//cm if cm else 'no guest')

Measured memory_bytes: 7548
using System;
using System.Linq;

namespace abc140_b
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var arrayA = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            var arrayB = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            var arrayC = Console.ReadLine().Split(' ').Select(int.Parse).ToList();

            var sum = 0;
            var prev = -10;
            
            foreach (var a in arrayA)
            {
                var index = a - 1;
                var b = arrayB[index];
                var c = 0;
                if (index == prev + 1)
                {
                    c = arrayC[index - 1];
                }

                sum += b + c;
                prev = index;
            }
            
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13396
from collections import Counter
n = int(input())
def prime_decomposition(n, table):
    i = 2
    while i * i <= n:
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
table = []
for j in range(2,n+1):
  prime_decomposition(j, table)
c = Counter(table).values()
cc = Counter(c)
count_2 = cc[2] + cc[3]
count_4 = 0
for i in range(4,14):
  count_4+=cc[i]
count_14 = 0
for i in range(14,24):
  count_14+=cc[i]
count_24 = 0
for i in range(24,74):
  count_24+=cc[i]
count_74 = 0
for i in range(74,101):
  count_74+=cc[i]
count_24 += count_74
count_14 += count_24
count_4 += count_14
count_2 += count_4
print(count_74+count_24*max([0,count_2-1])+count_14*max(count_4-1,0)+max([count_2-2,0])*max([count_4-1,0])*count_4//2)

Measured memory_bytes: 3436
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN   
#define linf LLONG_MAX
#define lninf LLONG_MIN   
const ll mod=998244353;
const int N=2e5+4;

int main()                  
{
	string s,t; cin>>s>>t; 

	int n=(int)s.size(),m=(int)t.size();

	int ans=inf;

	for(int i=0;i+m-1<n;i++)
	{
		int here = 0;

		for(int j=0;j<m;j++)
		if(s[i+j]!=t[j])
		here++;

		ans=min(ans,here);
	}

	pri(ans);
 
  	return 0;
}

Measured memory_bytes: 3724
import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		ArrayList<Double> x = new ArrayList<Double>();
		ArrayList<Double> y = new ArrayList<Double>();
		while(sc.hasNext()) {
			String[] tmp = sc.next().split(",");
			double xt = (Double.parseDouble(tmp[0]));
			double yt = (Double.parseDouble(tmp[1]));
			x.add(xt);
			y.add(yt);
		}
		x.add(x.get(0));
		y.add(y.get(0));
		double S = 0;
		for(int i = 0; i < x.size()-1; i++) {
			S += (x.get(i) - x.get(i+1))*(y.get(i) + y.get(i+1));
		}
		S /=2;
		out.println(Math.abs(S));
		out.flush();

	}
}
//------------------------------//
//-----------//
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    
    public int nextInt() {
    	return (int)nextLong();
    }
    

}

Measured memory_bytes: 16996
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll l, r, d; cin >> l >> r >> d;
    ll ans = 0;
    for(ll i = l; i <= r; i++){
        if(i % d == 0){
            ans++;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 3632
#include <stdio.h>

int main(void)
{
	int n;
	int m;
	int in, out;
	int max;
	
	scanf("%d %d", &n, &m);
	for (max = m; n--;){
		scanf("%d %d", &in, &out);
		if (m < 0){
			max = 0;
			continue;
		}
		
		m += in;
		m -= out;
		
		if (max < m){
			max = m;
		}
	}
	
	printf("%d\n", max);
	
	return (0);
}

Measured memory_bytes: 592
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

#a,bの最大公約数
def gcd(a,b):
    while b:
        a,b = b,a%b
    return a
#a,bの最小公倍数
def lcm(a,b):
    return a*b//gcd(a,b)

N,M = map(int,readline().split())
A = list(map(int,readline().split()))

B = [A[i]//2 for i in range(N)]
ans = 1

dev_c = 0
while A[0]%2 != 1:
    A[0] = A[0]//2
    dev_c += 1
#print(dev_c)

for i in range(1,N):
    dev_c2 = 0
    while A[i]%2 != 1:
        A[i] = A[i]//2
        dev_c2 += 1
    if dev_c != dev_c2:
        ans = 0
        break

l = B[0]
if ans == 1:
    for i in range(N):
        l = lcm(l,B[i])

#print(l)

if ans != 0:
    ans = (M//l+1)//2

print(ans)

Measured memory_bytes: 12972
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mat vector<vector<int>>
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<n;i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll


int max1(auto a){auto ans=a[0];for(auto i:a)if(i>ans)ans=i;return ans;}
auto min(auto a){auto ans=a[0];for(auto i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cerr<<i<<' ';cerr<<'\n';}

int n;
vector<vector<int>> conn;
vector<int> comp;

int f(int start)
{
	comp[start]=0;
	queue<int> q;
	q.push(start);
	while(q.size())
	{
		int node=q.front();
		q.pop();
		for(int i:conn[node])
		{
			if(comp[i]==-1)
			{
				comp[i]=comp[node]+1;
				q.push(i);
			}
			else if(comp[i]!=comp[node]-1 && comp[i]!=comp[node]+1)
			{
				return -1;
			}
		}
	}
	return max1(comp)+1;
}


signed main()
{
	fio
	cin>>n;
	conn.resize(n);
	fo(i,n)
	{
		string s;
		cin>>s;
		fo(j,n)
		{
			if(s[j]=='1')
			{
				conn[i].pb(j);
			}
		}
	}
	// comp=vector<int>(n,-1);
	// cout<<f(0)<<endl;
	// return 0;
	int ans=-1;
	fo(i,n)
	{
		comp=vector<int>(n,-1);
		ans=max(ans,f(i));
	}
	cout<<ans<<'\n';
	printclock;
}

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

int n,last[200010];
long long ans=0;

int main(){
	scanf("%d",&n);
	int bound=0;
	memset(last,-1,sizeof(last));
	for(int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		for(int j=0;j<20;j++){
			if(x&(1<<j)){
				bound=max(bound,last[j]+1);
				last[j]=i;
			}
		}
		ans+=i-bound+1;
	}
	printf("%lld\n",ans);
	return 0;
} 


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
    int n = 0;

    int leaver[4][3][10] = {};

    int b = 0;
    int f = 0;
    int r = 0;
    int v = 0;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> b;
        cin >> f;
        cin >> r;
        cin >> v;
        leaver[b - 1][f - 1][r - 1] += v;
    }

    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 10; k++) {
                cout << " " << leaver[i][j][k];
            }
            cout << "\n";
        }
        if (!(i == 3)) {
            cout << "####################\n";
        }
    }


}

Measured memory_bytes: 3080