akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
using namespace std;

#define LL long long
#define DB double
#define MOD 1000000007
#define MAXN 300000
#define mem(x,v) memset(x,v,sizeof(x))

LL read(){
    LL x=0,F=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*F;
}

char s[MAXN+5];
int len;
int dp[MAXN+5][8];
int ch[8][2]={{2, 1},{4, 3},{6, 5},{3, 3},{7, 1},{2, 1},{2, 2},{4, 4}};
void upd(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}

int main(){
    scanf("%s",s+1);
    len=strlen(s+1);
    dp[0][0]=1;
    for(int i=1;i<=len;i++)
        for(int j=0;j<8;j++){
            if(s[i]!='1')upd(dp[i][ch[j][0]],dp[i-1][j]);
            if(s[i]!='0')upd(dp[i][ch[j][1]],dp[i-1][j]);
        }
    upd(dp[len][1],dp[len][3]);
    printf("%d",dp[len][1]);
}


Measured memory_bytes: 9856
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define per(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define enter cout << endl
#define siz(x) ((int)x.size())
typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi ;
typedef pair <int, int> pii ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 100010 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const int MOD = 1000000007 ;
void print(int x) { cout << x << endl ; exit(0) ; }
void PRINT(string x) { cout << x << endl ; exit(0) ; }
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }

int a[N] ;

signed main(){
	rep(i, 1, 4) scanf("%d", &a[i]) ;
	sort(a + 1, a + 5) ;
	if (a[1] == 1 && a[2] == 4 && a[3] == 7 && a[4] == 9) puts("YES") ;
	else puts("NO") ;

	return 0 ;
}

/*
写代码时请注意：
	1.ll？数组大小，边界？数据范围？
	2.精度？
	3.特判？
	4.至少做一些
思考提醒：
	1.最大值最小->二分？
	2.可以贪心么？不行dp可以么
	3.可以优化么
	4.维护区间用什么数据结构？
	5.统计方案是用dp？模了么？
*/


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    cin>>a>>b;
    if(a>0||a==0){cout<<"1"<<endl;}
    if(a<0&&-b==a){cout<<"0"<<endl;}
    else if(a<0){cout<<"-1"<<endl;}
}
    



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

#define REP(i, x) for (int i = 0, i##_len = (int)(x); i < i##_len; i++)
#define REP1(i, x) for (int i = 1, i##_len = (int)(x); i <= i##_len; i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
const int MOD = (int)1e9 + 7;
const int INF = 1145141919;
using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using l_l = pair<ll, ll>;
using d_d = pair<double, double>;
using vint = vector<int>;
using vll = vector<ll>;
using vbool = vector<bool>;

int n, q;
vector<vint> tonaris;
vint parent;
vint ps;

// void rec(int now) {
//     for (int tonari : tonaris[now]) {
//         if (tonari != parent[now]) {
//             ps[tonari] += ps[now];
//             parent[tonari] = now;
//             rec(tonari);
//         }
//     }
// }

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

    tonaris = vector<vint>(n + 1);
    parent = vint(n + 1);
    ps = vint(n + 1);

    REP(_, n - 1) {
        int a, b;
        cin >> a >> b;
        tonaris[a].pb(b);
        tonaris[b].pb(a);
    }

    REP(_, q) {
        int p, x;
        cin >> p >> x;
        ps[p] += x;
    }

    // rec(1);

    stack<int> stk;
    stk.push(1);
    // seen[1] = true;
    vbool seen(n + 1);
    while (!stk.empty()) {
        int now = stk.top();
        stk.pop();
        // seen[now] = true;
        for (int tonari : tonaris[now]) {
            // if(seen[tonari])
            if (tonari != parent[now]) {
                ps[tonari] += ps[now];
                parent[tonari] = now;
                stk.push(tonari);
            }
        }
    }

    REP1(i, n) {
        if (i > 1)
            cout << " ";
        cout << ps[i];
    }
}

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

int main() {
    int64_t N,M;
    cin >> N >> M;
    vector<int64_t> X(M);
    for ( int64_t i = 0; i < M; ++i){
        cin >> X[i];
    }
    sort(X.begin(),X.end());
    vector<int64_t> DX(M-1);
    for ( int64_t i = 0; i < M-1; ++i){
        DX[i] = X[i+1] - X[i];
    }
    
    sort(DX.begin(),DX.end());
    
    int64_t res = 0;
    for ( int64_t i = 0; i < M-N; ++i){
        res = res + DX[i];
    }
    cout << res << endl;
    
    
    return 0;
}


Measured memory_bytes: 4704
S = input()

S = S[::-1]

T = [0]
t = 0
a = 1
for i in range(len(S)):
    t += int(S[i])*a
    t %= 2019
    a *= 10
    a %= 2019
    T.append(t)
from collections import Counter
c = Counter(T)
num = 0
for key in c:
    num +=(c[key]*(c[key]-1))//2

print(num)

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

namespace ABC073A
{
    class Program
    {
        static void Main(string[] args)
        {
            String n;
            n = Console.ReadLine();

            if (n[0] == '9' || n[1] == '9')
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<i64> a(n);
	for(int i = 0; i < n; i++) scanf("%lld", &a[i]);
	
	i64 ans = 0;
	for(int d = 1; d < n; d++) {
		i64 sum = 0, tmp = 0, count = 1;
		std::set<int> st;
		for(int i = 0, j = n - 1; i < n and j > 0; i += d, j -= d) {
			sum += a[i];
			tmp += a[j];
			count += 2;
			
			if(st.count(i) or st.count(j) or i == j) break;
			st.insert(i); st.insert(j);
			
			i64 A = n - i - 1;
			i64 B = A - d;
			if(B <= 0) continue;
			ans = std::max(ans, sum + tmp);
		}
	}
	
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 5760
//3/4/20 20:45
//nifty 8083.80

#include <bits/stdc++.h>
using namespace std;

#define ll          long long
#define ull         unsigned long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define Mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)      (a).rbegin(),(a).rend()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define INF         numeric_limits<ll>::max();
#define NINF        numeric_limits<ll>::min();
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))




void solve(){
    vector<ll> ans={1,2,3,4,5,6,7,8,9};
    int i=0;
    while(ans.size()<1e5+10){
        ll cur=ans[i];
        i++;
        if(cur%10>0){
            ans.pb(cur*10+cur%10-1);
        }
        ans.pb(cur*10+cur%10);
        if(cur%10<9){
            ans.pb(cur*10+cur%10+1);
        }
    }
    int k;
    cin>>k;
    cout<<ans[k-1];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 1592
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
  fio();
  LL n; cin>>n;
  vector<LL> v(n);
  LL su = 0;
  map<LL,LL> m;
  forn(i,n) {
  	cin>>v[i];
  	su+=v[i];
  	m[v[i]]++;
  }
  LL q;cin>>q;
  while(q--){
  	LL b,c; cin>>b>>c;
  	su-=m[b]*(b-c);
  	m[c] += m[b];
  	m[b] = 0;
  	cout<<su<<endl;
  }
  return 0;
}

Measured memory_bytes: 9964
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random
def I():
    return int(input())
def MI():
    return map(int,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 show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
#ts=time.time()
#sys.setrecursionlimit(10**6)
#input=sys.stdin.readline
show_flg=False
#=True

inf=float('inf')
n=I()
s=[[inf]*n for _ in range(n)]
g=[[] for i in range(n)]
for r in range(n):
    ri=list(input())
    for c in range(n):
        if ri[c]=='1':
            s[r][c]=1
            g[r].append((c,1))

def wf(d):
    n=len(d)
    for k in range(n):#       // 経由する頂点
        for i in range(n):#    // 始点
            for j in range(n):#  // 終点
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d

d=wf(s)
diam=-1
bg=0
ed=n-1
for r in range(n):
    for i,dist in enumerate(d[r]):
        if i==r:
            continue
        if diam<dist:
            diam=dist
            bg=r
            ed=i

v=[-1]*(n)

def bfs(x):
    p=deque()
    p.append(x)
    v[x]=0
    while p:
        c=p.popleft()
        for i,d in g[c]:
            if v[i]==-1:
                p.append(i)
                v[i]=v[c]+d
    return

bfs(bg)

for i in range(n):
    for nb,d in g[i]:
        if abs(v[nb]-v[i])!=1:
            print(-1)
            exit()

print(diam+1)
exit()

Measured memory_bytes: 57052
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
char a[200007];
LL sum,cnt[60],l;
void rds()
{
	l=0;
	char c=getchar();
	while((c<'A'||c>'Z')&&(c<'a'||c>'z'))c=getchar();
	while((c>='A'&&c<='Z')||(c>='a'&&c<='z'))
	{
		if(c>='A'&&c<='Z')cnt[c-'A'+1]++;
		else cnt[c-'a'+31]++;
		a[++l]=c;c=getchar();
	}
	return;
}
int main()
{
	rds();
	sum=l*(l-1)/2+1;
	for(int i=1;i<=56;i++)if(cnt[i])sum-=(cnt[i]*(cnt[i]-1)/2);
	printf("%lld",sum);
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int64 N, K;
    cin >> N >> K;
    vector<int64> A(N), B(2*N);
    REP(i, N) {
        cin >> A[i];
        B[i] = B[i+N] = A[i];
    }
    auto nxt = make_v<PLL>(N, 100);
    fill_v<PLL>(nxt, PLL(-1, -1));
    vector<int64> memo(212345, INF);

    for (int64 i = 2*N-1; i >= 0; i--) {
        if (memo[A[i%N]] != INF) {
            int64 nn = (memo[A[i%N]]+1)%N;
            nxt[i%N][0] = PLL(nn, (i%N == N-1 && nn == 0 ? 2 : nn-1 <= i));
        }
        memo[A[i%N]] = i%N;
    }
//    REP(i, N) {
//        cout << nxt[i%N][0].fs << " ";
//    }
//    cout << endl;

    REP(i, 99) {
        REP(j, N) {
            int64 a1, b1, a2, b2;
            tie(a1, b1) = nxt[j][i];
            if (a1 == -1) continue;
            tie(a2, b2) = nxt[a1][i];
            if (a2 == -1) continue;
            if (b1 + b2 <= K) {
                nxt[j][i + 1] = PLL(a2, b1 + b2);
            } else {
                nxt[j][i + 1] = PLL(-1 ,-1);
            }
        }
    }
    int64 nl = 0, np = 0; // num of loop, now position
    for (int64 i = 99; i >= 0; i--) {
        int64 a1, b1;
        tie(a1, b1) = nxt[np][i];
        if (a1 < 0 || nl + b1 >= K) continue;
        nl += b1;
        np = a1;
    }
    deque<int64> dq;
    map<int64, int64> cnt;
//    cout << nl << endl;
    FOR(i, np, (K-nl)*N) {
        if (cnt[A[i%N]] == 0) {
            cnt[A[i%N]]++;
            dq.push_back(A[i%N]);
        } else {
            while (cnt[A[i%N]] != 0) {
                cnt[dq.back()]--;
                dq.pop_back();
            }
        }
    }
    REP(i, dq.size()) {
        cout << dq[i] << " ";
    }
    cout << endl;
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	ll a, b;

	cin >> a >> b;

	cout << (a + b) % 24 << endl;
}

Measured memory_bytes: 256
fac=[1]*505050
inv=[1]*505050
finv=[1]*505050
mod=1000000007
for i in range(2,500010):
  fac[i]=fac[i-1]*i%mod
  inv[i]=-inv[mod%i]*(mod//i)%mod
  finv[i]=finv[i-1]*inv[i]%mod

def C(n,r):
  if n<0 or r<0 or n<r: return 0
  return fac[n]*finv[n-r]*finv[r]%mod

N,M=map(int,input().split())
ans=0
for i in range(N+1):
  ans+=C(N,i)*fac[M]%mod*finv[M-i]%mod*((fac[M-i]*finv[M-N])**2%mod)*(1 if i%2==0 else -1)%mod
  ans%=mod
print(ans%mod)


Measured memory_bytes: 102784
N = int(input())
A = list(map(int, input().split()))
total = sum(A)
from collections import defaultdict
d = defaultdict(lambda: 0)
for a in A:
    d[a] += 1
Q = int(input())
ans = []
for i in range(Q):
    x,y = map(int, input().split())
    total += y*d[x]-x*d[x]
    d[y] += d[x]
    d[x] = 0
    ans.append(total)
print(*ans, sep='\n')



Measured memory_bytes: 97728
import math

n = [[]]
a, b = input("").split(" ")
a = int(a)
b = int(b)
for i in range(a):
    tmp = input("").split(" ")
    for j in range(b):
        tmp[j] = int(tmp[j])
    n.append(tmp)
n.remove(n[0])
rep = 0
for i in range(a):
    for j in range(a-i-1):
        ans = 0
        for s in range(b):
            p = (n[i][s] - n[j+i+1][s])
            ans += (n[i][s] - n[j+i+1][s])**2
        ans = math.sqrt(ans)
        intans = int(ans)
        if ans - intans == 0:
            rep+=1
print(rep)

Measured memory_bytes: 3064
// ooooo      ooo                     
// `888b.     `8'                     
//  8 `88b.    8   .ooooo.   .oooo.   
//  8   `88b.  8  d88' `88b `P  )88b  
//  8     `88b.8  888   888  .oP"888  
//  8       `888  888   888 d8(  888  
// o8o        `8  `Y8bod8P' `Y888""8o 
// C++ Conpetitive Programming Template 
// Ver 2.0 (codename: Noa)
// Last Modified : 2019-06-07
// Created       : 2019-05-25
// Auther        : shirataki3
#include <bits/stdc++.h>
using namespace std;
// typename alias
template <class T> using vec = vector<T>;
template <class T, class U> using vep = vec<pair<T,U> >;
template <class T> using PQ = priority_queue<T>;
using ll = long long;
using vll = vec<ll>;
using pll = pair<ll, ll>;
using vpll = vec<pll>;
using str = string;
// あくまのちから
//#define int ll

// const
static const long long INF = 1LL<<59;
static const long long MOD = (ll)1e9+7;
static const double PI = 3.14159265358979323846;

// accelerate stdin, stdout
#define endl "\n"
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
// repeat macro
#define FOR(i, a, b) for(ll (i)=(a);(i)<=(b);i++)
#define rFOR(i, a, b) for(ll (i)=(b);(i)>=(a);i--)
#define REP(i, n) for(ll i=0;i<n;i++)
// vector macro
#define WHOLE(v) (v).begin(), (v).end()
#define ASC(v) sort(WHOLE(v))
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse(WHOLE(v))
#define FOLDL(src, dst, lambda) partial_sum(WHOLE(src), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum(WHOLE(src), (dst).begin(), lambda);INV(dst)
#define CUMSUML(src, dst) FOLDL(src, dst, [](auto a, auto b) {return a+b;})
#define CUMSUMR(src, dst) FOLDR(src, dst, [](auto a, auto b) {return a+b;})
#define ACCUM(v, d0, lambda) accumulate(WHOLE(v), d0, lambda)
#define SUM(v, d0) ACCUM(v, d0, [](auto a, auto b) {return a+b;})
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);v.erase(unique(v.begin(), v.end()), v.end())

// io helper
template <typename T>void debug(T t) {cerr << t << endl;}
template <typename T, typename ...Args>void debug(T t, Args ...args) {cerr << t << " ";debug(args...);}
template <typename T>void out(T t) {cout << t << endl;}
template <typename T, typename ...Args>void out(T t, Args ...args) {cout << t << " ";out(args...);}
template <typename T>istream& operator>>(istream &is, vec<T> &v) {for(auto &a:v) is >> a; return is;}
template <typename T>ostream& operator<<(ostream &os, vec<T> &v) {os << "[";REP(i, v.size() - 1) os << v[i] <<", "; os << v[v.size()-1]<<"]";return os;}
template <typename T, typename U>ostream& operator<<(ostream &os, pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")";return os;}
template <typename T, typename U>ostream& operator<<(ostream &os, map<T, U> &mp) {os << "{ ";for(auto &p:mp) os << p.first << ": " << p.second << ", "; os << "}";return os;}

void solve() {
    ll N, X;
    cin >> N >> X;
    vll L(N);
    cin >> L;
    ll ans = 1, d = 0;
    REP(i, N) {
        d += L[i];
        if(d <= X) {
            ans++;
        }
    }
    out(ans);
}

signed main() {
    fast_io;
    cout << setprecision(20) << fixed;
    solve();
    return 0;
}

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

using namespace std;
const long long INF = 1LL <<60;

int main(void){
  long long N,rst;
  cin >>N;
  map<long long,long long> a;
  long long b[N];
  int i,j;
  rst=0;
  long long tmp=0,cnt=0;
  
  for(i=0;i<N;i++){
    cin>>tmp;
    if(a[i+tmp]){
      a[i+tmp]+=1;
    }
    else{
      a[i+tmp]=1;
    }
    b[i]=i-tmp;
    //cout<<i<<" "<<i-tmp<<endl;
  }
  for(i=0;i<N;i++){
    if(a[b[i]]>0){
      //cout<<i<<" "<<b[i]<<" "<<a[b[i]]<<endl;
	  rst+=a[b[i]];
    }
  }
  //cout<<a.size()<<" "<<b.size()<<endl;


  cout<<rst<<endl;
  
  return 0;
}

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

#define pii pair<int,int>
#define piiii pair<pii,pii>

int main() {
  int n;
  while(cin >> n, n) {
    vector<piiii> v;
    for (int i=0; i<n;i++) {
      int id, u, a,p;
      cin >>id>>u>>a>>p;
      piiii x = make_pair(pii(11-a,p) ,pii(id, u));
      v.push_back(x);
    }
    sort(v.begin(), v.end());
    vector<int> t(1001,0);
    int m=0;
    for(int i=0; i<v.size(); i++) {
      pii pis = v[i].second;
      int id = pis.first;
      int u = pis.second;

      if (m<10&&t[u]<3 || m<20&&t[u]<2 || m<26&&t[u]==0) {
        cout << id << endl;
        m++;
        t[u]++;
      }
    }
  }
}

Measured memory_bytes: 0
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9
def dfs(cur, a, b, c):
	if cur == N:
		return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
	ret0 = dfs(cur + 1, a, b, c)
	ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
	ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
	ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
	return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))


Measured memory_bytes: 43996
/*
*/
#include<iostream>
#include<queue>
using namespace std;

int main()
{
  // 標準入力
  int N,K;
  cin >> N >> K;

  int p[N];
  int s = 0;
  int mx=0; 
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    //期待値は、出目の数＋１÷２、÷２は最後に持っていく
    p[i]++;
  }
  queue<int> q;
  for (int i = 0; i < N; i++) {
    s += p[i];
    q.push(p[i]);
    if (q.size() > K) {
      s -= q.front();
      q.pop();
    }
    if (q.size() == K) {
      mx = max(s, mx);
    }
  }
  
  double ans = mx;
  ans /= 2;

  printf("%.10f\n",ans);

  return 0;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int N; cin >> N;
    bool is_four = false;
    for (int i = 0; i < N; i++) {
        char ch;
        cin >> ch;
        if (ch == 'Y') is_four = true;
    }

    cout << (is_four ? "Four" : "Three") << endl;

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n, k := nextInt(), nextInt()
	as := make([]int, n)
	for i := 0; i < n; i++ {
		as[i] = nextInt()
	}

	fmt.Println((n-2)/(k-1)+1)
}

Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
	int n;
	ll m;
	while( cin >> n >> m, n || m ){
		vector<ll> vp(n+1);
		vp[0] = 0;
		for( int i = 0; i < n; i++ ){
			cin >> vp[i+1];
		}
		vector<ll> points;
		for( int i = 0; i <= n; i++ ){
			for( int j = i; j <= n; j++ ){
				points.push_back(vp[i]+vp[j]);
			}
		}
		sort(points.begin(), points.end());

		ll ans = 0;
		for( int i = 1; i < points.size(); i++ ){
			if( m < points[i] || points[i] == points[i-1] ) continue;
			ll diff = m - points[i];
			int left = 0, right = points.size()-1;
			while( 1 ){
				ll next = (left + right) / 2;
				if( next == left || next == right ){
					if( points[next] <= diff ) ans = max(ans, points[i] + points[next] );
					break;
				}
				if( points[next] == diff ){
					ans = points[i] + points[next];
					break;
				}else if( points[next] < diff ){
					left = next;
				}else{
					right = next;
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 9196
import java.io.*
import java.util.*

fun solve(a: Long, b: Long){
    val ans = a - 1 + if(b >= a) 1 else 0
    println(ans)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val a = sc.next().toLong()
    val b = sc.next().toLong()
    solve(a, b)
}



Measured memory_bytes: 29488
#include<stdio.h>

int main(){
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i=0; i<n; i++) {
    scanf("%d", &a[i]);
  }
  int cnt = 0;
  int b = 1;
  while (b==1) {
    for (int i=0; i<n; i++) {
      if (a[i]%2==0) {
        a[i] /= 2;
      } else {
        b = 0;
        break;
      }
    }
    if (b==1)
      cnt++;
  }
  
  printf("%d\n", cnt);

  return 0;
}

Measured memory_bytes: 128
N = gets.to_i
T = [0]; X = [0]; Y = [0]
N.times do
  s, t, u = gets.split.map(&:to_i)
  T << s; X << t; Y << u
end
# p plans
# binding.pry
0.upto(N-1) do |i|
  distload = (X[i+1] - X[i]).abs + (Y[i+1] - Y[i]).abs
  disttime = T[i+1] - T[i]
  if distload > disttime || (disttime - distload).odd?
    puts 'No'
    exit
  end
end
puts 'Yes'

Measured memory_bytes: 4252
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

int main(){
  ll n,k;
  cin >> n >> k;
  ll a,b;
  vector<ll> graph[n+1];
  for(int i=0;i<n-1;i++){
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  ll color[n+1];
  for(int i=0;i<n+1;i++){
    color[i] = 0;
  }
  queue<ll> q;
  q.push(1);
  ll ans = k;
  color[1] = 1;
  while(!q.empty()){
    ll now = q.front();
    q.pop();
    ll temp;
    ll c_num = k-2;
    if(now == 1) c_num += 1;
    for(int i=0;i<graph[now].size();i++){
      temp = graph[now][i];
      if(color[temp] == 0){
        color[temp] = 1;
        q.push(temp);
        ans *= c_num;
        c_num -= 1;
        ans %= MOD;
      }
    }
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 8052
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int ar[n],x=0;
    for(int i=0;i<n;i++)
    {
        cin>>ar[i];
        x^=ar[i];
    }
    for(int i=0;i<n;i++)
    {
        cout<<(x^ar[i])<<" ";
    }
}

Measured memory_bytes: 5100
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
using namespace std;
typedef pair<long long, long long> P;
int main(){
    int N, M;
    cin >> N >> M;
    vector<P> C(N);
    for(int i = 0; i < N; i++) {
        long long a, b;
        cin >> a >> b;
        C[i] = P(a, b);
    }
    sort(C.begin(), C.end());
    int j = 0;
    priority_queue<long long> q;
    long long ans = 0;
    for(int i = 1; i <= M; i++){
        while(C[j].first == i && j < N){
            q.push(C[j].second);
            j++;
        }
        if(!q.empty()) {
            ans += q.top();
            q.pop();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5824
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long H,W,c,ans=0;
    cin>>H>>W;
    if(H==1||W==1)
        cout<<1;
    else
        cout<<(H*W+1)/2;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n%2==0){
			System.out.println(n/2);
		}else{
			System.out.println((n+1)/2);
		}
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define be(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};

int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        if(n==0)return 0;
        vector<int>a(n);
        int maxx=0;
        REP(i,n)cin>>a[i];
        REP(i,n-1)
            rep(j,i+1,n)
            {
                int mix=a[i]+a[j];
                if(mix>m)continue;
                //if(mix==m){cout<<m<<endl;}
                maxx=max(mix,maxx);
            }
        if(maxx==0)cout<<"NONE"<<endl;
        else cout<<maxx<<endl;
    }
}


Measured memory_bytes: 3100
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <stack>

using namespace std;

int main() 
{
	stack <int> s;
	int n;
	while (cin >> n)
	{
		if (n == 0)
		{
			cout << s.top() << endl;
			s.pop();
		}
		else
			s.push(n);
	}
	return 0;
}


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

using namespace std;

#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()

typedef long long ll;
typedef long double ld;

void solve();

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	int t = 1;
	// cin >> t;
	while (t--) { 
		solve();
	}
	return 0;
}
int n;	
void solve() {
	cin >> n;
	cout << (n + 1) / 2;
}	
	

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int)(N);i++)
#define p(s) cout<<(s)<<endl
#define ck(n,a,b) (a<=(n)&&(n)<=b)
using namespace std;

string s,ans;
stack<int> st;
void bng(unsigned int pos,int diff){
	if(pos==s.size()) return;
	if(ck(s[pos],'A','Z')){
		ans+=(char) (s[pos]-'A'+diff)%26 + 'A';
		diff=0;
	}else if(s[pos]=='+'){
		diff++;
	}else if(s[pos]=='-'){
		diff--;
	}else if(s[pos]=='['){
		st.push(ans.size());
	}else if(s[pos]==']'){
		reverse(ans.begin()+st.top(),ans.end());
		st.pop();
	}else if(s[pos]=='?'){
		ans+='A';
		diff=0;
	}
	bng(pos+1,(diff+26)%26);
}

int main(){
	while(cin>>s){
		if(s==".") break;
		ans="";
		bng(0,0);
		p(ans);
	}
	return 0;
}

Measured memory_bytes: 3140
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
 
#define MAX 100005
#define NIL -1
 
typedef struct node{int p,l,r;}Node;
Node T[MAX];
int D[MAX];
 
void print(int u )
{
    int i,c;
    printf("node %d: parent = %d, depth = %d, ",u,T[u].p,D[u]);
    if(T[u].p==NIL)printf("root, ");
    else if(T[u].l==NIL)printf("leaf, ");
    else printf("internal node, ");
    printf("[");
    for(i=0,c=T[u].l;c!=NIL;c=T[c].r,i++)
    {
        if(i)printf(", ");
        printf("%d",c);
    }
    printf("]\n");
}
 
void rec(int u,int p)
{
    D[u]=p;
    if(T[u].l != NIL)rec(T[u].l,p+1);
    if(T[u].r != NIL)rec(T[u].r,p);
}
 
int main()
{
    int n,l,root,i, v,d,c,j;
    scanf("%d",&n);
    for(i=0;i<n;i++)T[i].p=T[i].l=T[i].r=NIL;
 
    for( i=0;i<n;i++)
    {
        scanf("%d%d",&v,&d);
        for(j=0;j<d;j++)
        {
            scanf("%d",&c);
            if(j==0)T[v].l=c;
            else T[l].r=c;
            l=c;
            T[c].p=v;
        }
    }
    for( i=0;i<n;i++)
    {
        if(T[i].p==NIL)root=i;
    }
    rec(root,0);
    for( i=0;i<n;i++)print(i);
}


Measured memory_bytes: 3296
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var N = Input.NextInt();
            var list = Input.IntList().Select(x => x / 400).ToList();

            var count = list.Distinct().Count(x => x < 8);
            var pro = list.Count(x => x >= 8);

            if(count == 0) {
                Console.WriteLine($"1 {pro}");
            } else {
                Console.WriteLine($"{count} {count + pro}");
            }
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 13404
class String
  alias nya <=>

  def <=> other
    self.size == other.size ? self.nya(other) : self.size <=> other.size
  end
end

product = Hash.new(0)
gets.to_i.times do
  name, num = gets.split
  product[name] += num.to_i
end
arr = product.sort
arr.each do |item|
  puts "#{item[0]} #{item[1]}"
end

Measured memory_bytes: 6112
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        String s = sc.next(), t = sc.next(), ans = "No";
        char[] ss = new char[s.length()];
        char[] tt = new char[t.length()];
        for(int i = 0; i < s.length(); i++)
            ss[i] = s.charAt(i);
        for(int i = 0; i < t.length(); i++)
            tt[i] = t.charAt(i);
        Arrays.sort(ss);
        Arrays.sort(tt);
        String news = "", newt = "";
        for(int i = 0; i < s.length(); i++)
            news += ss[i];
        for(int i = 0; i < t.length(); i++)
            newt += tt[t.length()-1-i];
        if(news.compareTo(newt) < 0) ans = "Yes";
        System.out.println(ans);
    }
}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
set<int> t[15];
bool f[1010];
int main() {
	memset(f,0,sizeof(f));
	int n;string s;
	cin>>n>>s;
	for(int i=0;i<s.size();i++)
		t[s[i]-'0'].insert(i);
	for(int i=0;i<s.size();i++) {
		t[s[i]-'0'].erase(i);
		for(int j=0;j<10;j++) {
			if(t[j].empty()) continue;
			for(int k=0;k<10;k++) {
				if(t[k].empty()) continue;
				if(*t[j].begin()<*t[k].rbegin())
					f[(s[i]-'0')*100+j*10+k]=true;
			}
		}
	}
	int cnt=0;
	for(int i=0;i<1000;i++) 
		if(f[i]) cnt++;
	printf("%d",cnt);
	return 0;
}

Measured memory_bytes: 1792
N, M, Q = map(int, input().split())
MAX = 0
Query = []
for i in range(Q):
  Query.append(list(map(int, input().split())))

for A_9 in range(1,M + 1):
  for A_8 in range(1,A_9 + 1):
    for A_7 in range(1,A_8 + 1):
      for A_6 in range(1,A_7 + 1):
        for A_5 in range(1,A_6 + 1):
          for A_4 in range(1,A_5 + 1):
            for A_3 in range(1,A_4 + 1):
              for A_2 in range(1,A_3 + 1):
                for A_1 in range(1,A_2 + 1):
                  A = [A_1,A_2,A_3,A_4,A_5,A_6,A_7,A_8,A_9,M]
                  d = 0
                  for i in range(Q):
                    a = Query[i][0] - 1
                    b = Query[i][1] - 1
                    if A[b] - A[a] == Query[i][2]:
                      d += Query[i][3]
                      if d > MAX:
                        MAX = d         
      
      
           
print(MAX)

Measured memory_bytes: 9012
# init
ROOMS=10
FLOORS=3
BUILDINGS=4
rooms = [[[0 for i in range(ROOMS)] for j in range(FLOORS)] for k in range(BUILDINGS)]

# input
n = int(input())

# check inputs
for loop in range(n):
    b, f, r, v = map(int, input().split())
    
    rooms[b-1][f-1][r-1] += v
    
    if rooms[b-1][f-1][r-1] < 0:
        rooms[b-1][f-1][r-1] = 0

for i in range(BUILDINGS):
    for j in range(FLOORS):
        for k in range(ROOMS):
            print(" {0}".format(rooms[i][j][k]), end="")
        print()
    if i<BUILDINGS-1:
        print('#'*20)



Measured memory_bytes: 5624
N = int(input())
A = [tuple(map(int,input().split())) for i in range(N)]
D = 0
for Cx in range(101):
    for Cy in range(101):
        H = 0
        F = 1
        for i in A:
            if H < 1:
                if i[2] == 0:
                    continue
                H = i[2] + abs(i[0]-Cx) + abs(i[1]-Cy)
            elif i[2] == max(H-abs(i[0]-Cx)-abs(i[1]-Cy),0):
                continue
            else:
                F = 0
                break
        for i in A:
            if not (i[2] == max(H-abs(i[0]-Cx)-abs(i[1]-Cy),0)):
                F = 0
                break
        if F == 1 and H >= 1 and D == 0:
            D = 1
            print(Cx,Cy,H)
            


Measured memory_bytes: 3064
import java.util.Scanner;

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

        int A;
        int B;

        A=sc.nextInt();
        B=sc.nextInt();

        if (A==2)
            if (B==1)
                System.out.println(3);
            else
                System.out.println(1);
        else
            if (A==1)
                if (B==2)
                    System.out.println(3);
                else
                    System.out.println(2);

            else
                if (B==2)
                    System.out.println(1);
                else
                    System.out.println(2);
    }
}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  bool x;
  
  for(int i=0;i<N;i++){
  string op;
    cin>>op;
    if(op=="Y"){
      x=1;
      break;
    }
    x=0;
  }
  if(x==1){
  cout<<"Four"<<endl;
  }
  if(x==0){
  cout<<"Three"<<endl;
  }

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cassert>
 
using namespace std;
 
#define sz(x) (int)(x.size())
#define fi(a, b) for(int i=a;i<b;++i)
#define fj(a, b) for(int j=a;j<b;++j)
#define fk(a, b) for(int k=a;k<b;++k)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
////////////////

int const N = 1e5 + 41;
int const INF = 1e9 + 41;

int n;
int a[N], d[N][2];

void solve(){
	cin  >> n;
	fi(1, n+1){
		cin >> a[i];
	}
	fi(0, N) fj(0, 2) d[i][j] = INF;
	d[1][0] = d[1][1] = 1;
	fi(2, n+1){
		d[i][0] = d[i][1] = (1 + min(d[i-1][0], d[i-1][1]));
		if(a[i-1] <= a[i]) d[i][1] = min(d[i-1][1], d[i][1]);
		if(a[i-1] >= a[i]) d[i][0] = min(d[i-1][0], d[i][0]);
	}
	
	int ans = min(d[n][1], d[n][0]);
	cout << ans << endl;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();

	return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>

// +, -, *, /, sqrt, >, >=, <, <=, ==
template<typename T>
class Point2 {
public:
  Point2() {}
  Point2(T x_, T y_) : x(x_), y(y_) {}
  Point2 operator * (T b) { return Point2<T>(x*b, y*b); };
  Point2 operator / (T b) { return Point2<T>(x/b, y/b); };
  T x, y;
};

class Mean_ {
public:
  template<typename T>
  Point2<T> operator() (Point2<T> a, Point2<T> b) {
    return Point2<T>((a.x + b.x) / 2.0, (a.y + b.y) / 2.0);
  }
};
Mean_ Mean;

class Distance_ {
public:
  template<typename T>
  T operator () (Point2<T> a, Point2<T> b) {
    T dx = a.x - b.x;
    T dy = a.y - b.y;
    return sqrt(dx * dx + dy * dy);
  }
};
Distance_ Distance;

class Heron_ {
public:
  template<typename T>
  T operator () (T a, T b, T c) {
    T s = (a + b + c) / 2.0;
    return sqrt(s*(s-a)*(s-b)*(s-c));
  }
};
Heron_ Heron;

class CenterCoord_ {
public:
  template<typename T>
  bool check(Point2<T> a, Point2<T> b, T r) {
    T dist = Distance(a, b);
    if( dist >= r * 2.0 ) return false;
    return true;
  }
  template<typename T>
  std::pair<Point2<T>, Point2<T> > operator () (Point2<T> a, Point2<T> b, T r) {
    T dist = Distance(a, b);
    assert( dist < 2.0 );
    auto t1 = Mean(a, b);
    auto t2 = Point2<T>((a.x - b.x) / dist, (a.y - b.y) / dist);
    T h = 2 * Heron(r, r, dist) / dist;
    auto t3 = t2 * h;
    auto c1 = Point2<T>(t1.x + t3.y, t1.y - t3.x);
    auto c2 = Point2<T>(t1.x - t3.y, t1.y + t3.x);
    return std::pair<Point2<T>, Point2<T> >(c1, c2);
  }
};
CenterCoord_ CenterCoord;

class InCircle_ {
public:
  template<typename T>
  bool operator () (Point2<T> center, T r, Point2<T> target) {
    return Distance(center, target) <= r;
  }
};
InCircle_ InCircle;

int n;
Point2<double> p[512];

void init() {
  for(int i = 0; i < (int)512; ++i) {
    p[i].x = p[i].y = 0.0;
  }
} 


class solve_ {
public:
  int operator() (void) {
    int res = 1;
    for(int i = 0; i < (int)n; ++i) {
      for(int j = 0; j < (int)i; ++j) {
        res = std::max(res, CountPoints(i, j));
      }
    }
    return res;
  }
  int CountPoints(int i, int j) {
    if( not CenterCoord.check(p[i], p[j], 1.0) ) return 0;
    auto c12 = CenterCoord(p[i], p[j], 1.0);
    auto c1 = c12.first;
    auto c2 = c12.second;
    int count1 = 0;
    int count2 = 0;
    for(int k = 0; k < (int)n; ++k) {
      if( k == i or k == j ) continue;
      if( InCircle(c1, 1.0, p[k]) ) {
        count1 += 1;
      }
      if( InCircle(c2, 1.0, p[k]) ) {
        count2 += 1;
      }
    }
    int res = std::max(count1, count2) + 2;
    return res;
  }
};
solve_ solve;

int main() {
  for(;;) {
    init();
    scanf("%d", &n);
    if( n == 0 ) break;
    for(int i = 0; i < (int)n; ++i) {
      scanf("%lf %lf", &p[i].x, &p[i].y);
    }
    printf("%d\n", solve());
  }
  return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>
inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    ll a,b;cin>>a>>b;
    if(a>b){
        cout<<a-1<<endl;
    }else{
        cout<<a<<endl;
    }

    return 0;
}

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

int main(){
	int n, m;
	cin >> n >> m;
	
	pair<int, int> a[n];
	for(int i = 0; i<n; i++){
		int x, y;
		cin >> x >> y;
		a[i] = {y, x};
	}
	
	sort(a, a + n);
	reverse(a, a + n);
	
	set<int> days;
	for(int i = 0; i<=m; i++) days.insert(-i);
	
	long long ans = 0;
	
	for(int i = 0; i<n; i++){
		auto it = days.lower_bound(-(m - a[i].second));
		if(it == days.end()) continue;
		days.erase(*it);
		ans += a[i].first;
	}
	
	cout << ans << endl;
}


Measured memory_bytes: 5760
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int n;
int a[123456],vt[123456];
bool PP(int i,int j){
    return a[i]<a[j];
}
int main(){
    cin>>n;
    for (int i=1; i<=n; i++){
        cin>>a[i];
        vt[i]=i;
    }
    sort(vt+1,vt+1+n,PP);
    for (int i=1; i<=n; i++)
        cout<<vt[i]<<" ";
    return 0;
}

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

#define ONLINE_JUDGE

#define V vector
#define P pair

using LL = long long;
#define FOR(i, x, y) \
    for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) \
    for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifndef ONLINE_JUDGE
#define dbg(x...)                             \
    do {                                      \
        cerr << "\033[32;1m" << #x << " -> "; \
        err(x);                               \
    } while (0)
void err() { cerr << "\033[39;0m" << endl; }
template <template <typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) {
    for (auto v : a) cerr << v << ' ';
    err(x...);
}
template <typename T, typename... A>
void err(T a, A... x) {
    cerr << a << ' ';
    err(x...);
}
#else
#define dbg(...)
#endif
#define sz(x) (int)x.size()

LL bin(LL a, LL b, LL p) {
    LL res = 1;
    a = (a % p + p) % p;
    for (; b; b >>= 1, a = a * a % p)
        if (b & 1) res = res * a % p;

    return res;
}

const int N = 200000+50;
char s[N];
LL ex_gcd(LL a, LL b, LL &x, LL &y) {
    if (b == 0) { x = 1; y = 0; return a; }
    LL ret = ex_gcd(b, a % b, y, x);
    y -= a / b * x;
    return ret;
}

LL get_inv(LL a, LL M) {
    static LL x, y;
    assert(ex_gcd(a, M, x, y) == 1);
    return (x % M + M) % M;
}
LL len[N];

void solve() {
    len[0] = 1;
    const LL x = get_inv(10, 2019);
    for (int i=1; i<N; ++i) {
        len[i] = len[i-1] * x % 2019;
    }
    map<int, int> mp;
    mp[0]++;
    scanf("%s", s);
    int n = strlen(s);
    int now = 0;
    dbg(x);
    LL ans = 0;
    for (int i=0; i<n; ++i) {
        now = (now * 10 + s[i] - '0') % 2019;
        
        LL tar = now * len[i] % 2019;
        dbg(i, now, tar);
        ans += mp[tar];
        mp[tar]++;
    }
    printf("%lld\n", ans);
}

int main() {

    // int t;
    // cin >> t;
    // while (t--) solve();

    solve();

    return 0;
}

Measured memory_bytes: 5516
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) rep(i,0,n)
 
int main()
{
  long long int N; cin >> N;
  long long int out = (N-1)*N / 2;
  cout << out << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N,M;
int A[3001];
int B[3001];
string S;
int l[3001];
int r[3001];

void maxS(){
	REP(i,M){
		int c=0;
		for(int j=l[i];j<=r[i];j++){
			if(A[j]==1){
				c++;
				A[j]=0;
			}
		}
		REP(j,c){
			A[r[i]-j]=1;
		}
	}
}

void minS(){
	REP(i,M){
		int c=0;
		for(int j=l[i];j<=r[i];j++){
			if(B[j]==1){
				c++;
				B[j]=0;
			}
		}
		REP(j,c){
			B[l[i]+j]=1;
		}
	}
}

LL dp[3011];
LL nxt[3011];
LL MOD=1e9+7;

int main(){
	cin>>N>>M>>S;
	REP(i,N){
		if(S[i]=='0'){
			A[i]=0;
			B[i]=0;
		}else{
			A[i]=1;
			B[i]=1;
		}
	}
	REP(i,M){
		cin>>l[i]>>r[i];
		l[i]--;
		r[i]--;
	}
	maxS();
	minS();
	REP(i,N){
		if(i==0)continue;
		A[i]=A[i]+A[i-1];
		B[i]=B[i]+B[i-1];
	}
	REP(i,3002){
		dp[i]=0;
	}
	
	/*REP(i,N){
		cout<<A[i]<<" ";
	}
	cout<<endl;
		REP(i,N){
		cout<<B[i]<<" ";
	}
	cout<<endl;*/
	dp[0]=1;
	REP(k,N){
		REP(i,3002){
			nxt[i]=0;
		}
		REP(i,3001){
			if((i>=A[k])&&(i<=B[k])){
				nxt[i]+=dp[i];
				nxt[i]%=MOD;
			}
			if(((i+1)>=A[k])&&((i+1)<=B[k])){
				nxt[i+1]+=dp[i];
				nxt[i+1]%=MOD;
			}
		}
		REP(i,3002){
			dp[i]=nxt[i];
		}
		/*cout<<"test"<<endl;
		REP(i,5){
			cout<<dp[i]<<endl;
		}*/
	}
	LL ans=0;
	REP(i,3002){
		ans+=dp[i];
		ans%=MOD;
	}
	cout<<ans<<endl;
	
	return(0);
}

Measured memory_bytes: 384