akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#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--)
#define mp make_pair
#define fi first
#define sc second
char s[100];
ll n;
bool bit[20];

ll dfs(ll i){
	if(i == n - 1) {
		ll ret = 0;
		ll a = s[0];
		REP(j,n - 1) {
			if(bit[j]) {
				ret += a;
				a = s[j + 1];
			}else {
				a *= 10;
				a += s[j + 1];
			}
		}
		return ret + a;
	}

	bit[i] = 1;
	ll ret = dfs(i + 1);
	bit[i] = 0;
	ret += dfs(i + 1);
	return ret;
}
int main(){
	cin >> s;
	n = strlen(s);
	REP(i,n)
		s[i] -= '0';

	cout << dfs(0) << endl;
	return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a,b,c,d,k,x=0;
    cin>>a>>b>>c>>d>>k;
    if(d>b)
    {
    	d-=b;
    	b=0;
    	x+=(c-a)*60;
    	x+=d;
    	x-=k;
	}
	else if(b>d)
	{
		b-=d;
		d=0;
		x=60-b;
		c--;
		x+=(c-a)*60;
		x-=k;
	}
	else
	{
		x+=(c-a)*60;
		x-=k;
	}
	cout<<x<<endl;
	return 0;
}



Measured memory_bytes: 3576
# ABC155 B

n = int(input())
A = list(map(int, input().split()))
res = 0

for num in A:
    if num % 2 == 0:
        if (num % 3 == 0) or (num % 5 == 0):
            pass
        else:
            res += 1

if res == 0:
    print('APPROVED')
else:
    print('DENIED')

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

#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
	int n;
	cin>>n;
	int h[n];
	rep(i, n){
		cin>>h[i];
	}
	vector<int> a;
	int b=0;
	rep(i, n){
		if(i == n - 1){
			a.push_back(b);
			break;
		}
		if(max(h[i],h[i+1])==h[i+1] && h[i] != h[i + 1]){
			a.push_back(b);
			b=0;
		}
		else
			b++;
	}
	sort(a.begin(), a.end(), greater<int>());
	cout<<a[0]<<endl;
	return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
int maksi=-1,u,mini=1001,n;
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&u);
        maksi=max(u,maksi);
        mini=min(u,mini);
    }
    printf("%d",maksi-mini);
    return 0;
}


Measured memory_bytes: 256
// ABC137D.cpp :
// priority_queueを使う
#include <iostream>
#include <vector>
#include <queue>
using ll = long long;
#define rep( i, n ) for ( ll i = 0; i < (ll)( n ); ++i )
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> jobs(m);
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        if (a > m) continue; // 支払日が遅いバイトはしない
        jobs.at(m - a).push_back(b);
    }
    priority_queue<int> q;
    ll ans = 0;
    for (int i = m - 1; i >= 0; i--) {
        for (int x : jobs.at(i)) {
            q.push(x);
        }
        if (!q.empty()) {
            ans += q.top(); q.pop();
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8156
N, K = map(int, input().split())    
if N % K == 0:                      ##N/Kの余りが0だった時
    print(0)
else:                               ##それ以外は
    N = N % K                       ##NにN/Kの余りを代入
    if abs(N - K) < N:           ##N-Kの絶対値がNより小さいなら
        N = abs(N - K)              ##NはN-Kの絶対値
        print(N)
    else:
        print(N)

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import defaultdict
mod = 10**9+7

N = int(input())
xy = [list(map(int, input().split())) for i in range(N)]
cnt = defaultdict(int)
for i in range(N):
    for j in range(i+1, N):
        a, b = xy[j][0]-xy[i][0], xy[j][1]-xy[i][1]
        cnt[(a, b)] += 1
        cnt[(-a, -b)] += 1
if N == 1:
    print(1)
else:
    print(N-max(cnt.values()))


Measured memory_bytes: 3828
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>

#define int long long
#define pb push_back
#define pf push_front
#define st first
#define nd second
#define sz(x) ((int)x.size())
#define ins insert
#define fastio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define lowbit(x) ((x)&(-x))
#define pi acos(-1.0)
using namespace std;

const int maxn=1e6+10;
const int maxe=1e6+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;

inline int read(){
    int x=0; bool flag=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
    while(ch>='0'&&ch<='9') {x=(x<<1)+(x<<3)+ch-'0'; ch=getchar();}
    if(flag) return x;
    return ~(x-1);
}
inline void write(int x){
    if(x<0) {x=~(x-1); putchar('-');}
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

int gcd(int a,int b){
    return b==0?a:gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/(gcd(a,b));
}

int a[maxn],num[maxn]={};
main(){
    fastio;
    int n=read();
    for(int i=1;i<=n;++i)a[i]=read();
    int g=0;
    for(int i=1;i<=n;++i){
        g=gcd(g,a[i]);
        for(int j=2;j*j<=a[i];++j){
            if(a[i]%j==0){
                num[j]++;
                while(a[i]%j==0)a[i]/=j;
            }
        }
        num[a[i]]++;
    }
    if(g>1)cout<<"not coprime"<<endl;
    else {
        for(int i=2;i<maxn;++i)if(num[i]>1){
            cout<<"setwise coprime"<<endl;
            return 0;
        }
        cout<<"pairwise coprime"<<endl;
    }
}


Measured memory_bytes: 19148
#include <cstdio>
#include <cstring>

using namespace std;

char A[100],B[100],C[100];

int main()
{
    //freopen("file.in","r",stdin);
    //freopen("file.out","w",stdout);
    scanf("%s%s%s",A,B,C);
    int l1=strlen(A),l2=strlen(B),l3=strlen(C);
    if(A[l1-1]==B[0] && B[l2-1]==C[0]) printf("YES");
    else printf("NO");
    return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();

            if (S.Length == 1)
            {
                Console.WriteLine(0);
                return;
            }

            var numEven = S.Length / 2;
            var numOdd = numEven;
            if (S.Length % 2 != 0)
            {
                numEven++;
            }

            var numEvenWhite = 0;
            var numOddWhite = 0;

            for (int i = 0; i < S.Length; i++)
            {
                var isEven = (i % 2 == 0) ? true : false;
                var isWhite = (S[i] == '1') ? true : false;

                if (isEven)
                {
                    if (isWhite)
                    {
                        numEvenWhite++;
                    }
                }
                else
                {
                    if (isWhite)
                    {
                        numOddWhite++;
                    }
                }
            }

            var cost1 = (numEven - numEvenWhite) + numOddWhite;
            var cost2 = (numOdd - numOddWhite) + numEvenWhite;

            Console.WriteLine(Math.Min(cost1, cost2));
        }
    }
}


Measured memory_bytes: 13140
program prob4
    implicit none
    integer :: tmp, N, i, ans
    integer, allocatable :: a(:)
    read(*,*) N
    allocate(a(N))
    read(*,*) a
    ans = 0
    do i = 1, N-1
        if(i == a(i))then
            tmp = a(i+1)
            a(i+1) = i
            a(i) = tmp
            ans = ans + 1
        end if
    end do
    if(N == a(N))then
        ans = ans + 1
    end if
    write(*,*) ans

    deallocate(a)

    stop
contains
end program prob4

Measured memory_bytes: 3428
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(b-a == c-b) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
function main()
  
  (N,M) = map(x -> parse(Int,x), split(readline()))
  
  a = zeros(Int,M)
  b = zeros(Int,M)
  c = zeros(Int,M)
  
  ans = 0
  
  d = ones(Int,N,N)*1000000
  
  for i in 1:N
    d[i,i] = 0
  end
  
  for i in 1:M
    (a[i],b[i],c[i]) = map(x -> parse(Int,x), split(readline()))
  end
  
  for i in 1:M
    
    d[a[i],b[i]] = min(d[a[i],b[i]], c[i])
    d[b[i],a[i]] = min(d[b[i],a[i]], c[i])
    
  end
  
  for k in 1:N, i in 1:N, j in 1:N
    
    d[i,j] = min(d[i,j], d[i,k]+d[k,j])
    
  end
  
  for i in 1:M
    
    count = 0
    
    for j in 1:N
    
      if d[j,a[i]] + c[i] == d[j,b[i]]
      
        count += 1
      
      end
    
    end
    
    if count > 0
      
      ans += 1
      count = 0
      
    end
    
  end
  
  println(M-ans)
  
  
end

main()

Measured memory_bytes: 156436
import java.util.*;

public class Main{
  public static final int N = 13;
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    boolean[] cards = new boolean[N*4+1];
    int n = sc.nextInt(),num,i;
    String s;
    for(i = 1;i <= N*4;i++)cards[i] = false;
    for(i = 0;i < n;i++){
      s = sc.next();
      num = sc.nextInt();
      if(s.equals("S"))cards[num] = true;
      if(s.equals("H"))cards[N+num] = true;
      if(s.equals("C"))cards[N*2+num] = true;
      if(s.equals("D"))cards[N*3+num] = true;
    }
    for(i = 1;i <= N;i++){
      if(!cards[i])System.out.println("S " + i);
    }
    for(;i <= N*2;i++){
      if(!cards[i])System.out.println("H " + (i-N));
    }
    for(;i <= N*3;i++){
      if(!cards[i])System.out.println("C " + (i-N*2));
    }
    for(;i <= N*4;i++){
      if(!cards[i])System.out.println("D " + (i-N*3));
    }
    sc.close();
  }
}


Measured memory_bytes: 26328
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int main() {
    while(1){     
    	int i,n;
        int v;
        double avg, dev, sum = 0.0, sum2 = 0.0;
     	cin >> n;
     	if(n==0)break;
        for (i = 0; i < n; i++) {
           cin>> v;
           sum  += v;
           sum2 += v*v;
        }
        avg = sum/n;
        dev = sqrt(sum2/n - avg*avg);
        printf("%.10f\n", dev);
    }

}         // ??????=3.375, ?¨??????????=0.540

Measured memory_bytes: 3152
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
temp=[0]*n
for i in range(0,n):
  temp[i]=i+1
from itertools import permutations
templ=list(permutations(temp,n))#長さnのtmpの順列リストを取る　どうやら昇順で取ってくれるらし
     
for i in range(0,len(templ)):
  if templ[i]==p:
    a=i#大きさの差を取るので，ずれは問題なし
  if templ[i]==q:
    b=i
print(abs(a-b))

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0, max_h = 0;
    rep(i, n) {
        int h; cin >> h;
        if (max_h <= h) max_h = h, ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <queue>
#include <set>
#include <vector>

using namespace std;

int H, W, N;
int sh, sw;

int L, R, U, D;

void cnt(char c) {
  if (c == 'L') {
    L--;
  } else if (c == 'R') {
    R++;
  } else if (c == 'U') {
    U--;
  } else {
    D++;
  }
}

void hoge(char c) {
  if (c == 'L') {
    R--;
  } else if (c == 'R') {
    L++;
  } else if (c == 'U') {
    D--;
  } else {
    U++;
  }
}

bool check() {
  if (L < 1) {
    return true;
  } else if (R > W) {
    return true;
  } else if (U < 1) {
    return true;
  } else if (D > H) {
    return true;
  }
  return false;
}

void marume() {
  if (L > W) {
    L = W;
  }
  if (R < 1) {
    R = 1;
  }
  if (U > H) {
    U = H;
  }
  if (D < 1) {
    D = 1;
  }
}

int main() {
  cin >> H >> W >> N;
  cin >> sh >> sw;

  L = sw;
  R = sw;
  U = sh;
  D = sh;

  string a, b;
  cin >> a >> b;

  for (int i = 0; i < N; i++) {
    cnt(a[i]);
    if (check()) {
      cout << "NO" << endl;
      return 0;
    }
    hoge(b[i]);
    marume();
  }
  cout << "YES" << endl;

  return 0;
}


Measured memory_bytes: 776
def f():
    N, M = map(int, input().split())
    if N == 0:
        return -1
    A = [0] * M
    for i in range(N):
        T = [int(i) for i in map(int, input().split())]
        for j in range(M):
            if T[j] == 1:
                A[j] += 1

    B = sorted([(v, i + 1) for i, v in enumerate(A)], key=lambda t:(t[0], -t[1]), reverse=True)
    print(' '.join([str(t[1]) for t in B]))
    return 1


def main():
    while True:
        ret = f()
        if ret == -1:
            return


if __name__ == '__main__':
    main()





Measured memory_bytes: 5624
let readCharArray () = stdin.ReadLine().ToCharArray()
let choice ok ng bool = if bool then ok else ng

let isPalindrome (chars: char []) =
    chars
    |> System.String
    |> (=)
    <| (chars |> Array.rev |> System.String)

readCharArray ()
|> fun x ->
    let num =
        x
        |> Array.length
        |> fun a -> (a - 1) / 2

    let a = x |> isPalindrome
    let b = x |> Array.take num |> isPalindrome

    let c =
        x |> Array.rev |> Array.take num |> isPalindrome

    a && b && c
|> choice "Yes" "No"
|> printfn "%s"


Measured memory_bytes: 29580
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

int main() {
  int64_t X, K, D;
  cin >> X >> K >> D;

  X = abs(X);
  int64_t a = X / D;
  if (a >= K) {
    cout << X - K * D << endl;
  } else {
    cout << abs(X % D - (K - a) % 2 * D) << endl;
  }
  return 0;
}

Measured memory_bytes: 3620
n, m, x = map(int, input().split())
A = list(map(int, input().split()))
cost = 0
for i in range(x, n+1):
  if A.count(i) > 0:
    cost += 1
cost_nomal = cost
cost = 0 
for i in range(1, x+1):
  if A.count(i) > 0:
    cost += 1
cost_reverse = cost

print(min(cost_nomal,cost_reverse))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vvi g;
vl two;

void dfs(int v,deque<vl> &dp,deque<ll> &dis){
	int mx=0;
	for(auto u:g[v]){
		deque<ll> dis1;
		deque<vl> dp1;
		dfs(u,dp1,dis1);
		if(dp.size()<dp1.size()){
			swap(dp,dp1);
			swap(dis,dis1);
		}
		int m=dp1.size();
		mx=max(mx,m);
		for(int i=0;i<m;i++){
			vl tmp(3);
			for(int j=0;j<3;j++) for(int k=0;k<3;k++){
				(tmp[min(j+k,2)]+=dp[i][j]*dp1[i][k])%=mod;
			}
			dp[i]=tmp;
			dis[i]+=dis1[i];
		}
	}
	for(int i=0;i<mx;i++){
		(dp[i][0]+=dp[i][2])%=mod;
		dp[i][2]=0;
	}
	vl tmp(3);
	tmp[0]=tmp[1]=1;
	dp.push_front(tmp);
	dis.push_front(1);
}

int main(){
	cin>>n;
	two=vl(n+2);
	g=vvi(n+1);
	two[0]++;
	for(int i=1;i<n+2;i++) two[i]=two[i-1]*2%mod;
	for(int i=1;i<=n;i++){
		int v;
		cin>>v;
		g[v].push_back(i);
	}
	deque<ll> dis;
	deque<vl> dp;
	dfs(0,dp,dis);
	ll t=0,m=dp.size();
	for(int i=0;i<m;i++) (t+=dp[i][1]*two[n+1-dis[i]])%=mod;
	cout<<t<<endl;
}

Measured memory_bytes: 322176
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll x; cin >> x;
    if(x>=400 && x<=599) cout << "8" << endl;
    else if(x>=600 && x<=799) cout << "7" << endl;
    else if(x>=800 && x<=999) cout << "6" << endl;
    else if(x>=1000 && x<=1199) cout << "5" << endl;
    else if(x>=1200 && x<=1399) cout << "4" << endl;
    else if(x>=1400 && x<=1599) cout << "3" << endl;
    else if(x>=1600 && x<=1799) cout << "2" << endl;
    else if(x>=1800 && x<=1999) cout << "1" << endl;
}

Measured memory_bytes: 3632
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                String s = sc.next();
                sc.close();
                char[] a = new char[s.length()];
                for(int i = 0 ; i < s.length() ; i++){
                        a[i] = s.charAt(i);
                }
                Arrays.sort(a);
                char pct = 'a';
                boolean ebishu = true;
                for(int i = 0 ; i < 26 && ebishu ; i++){
                        if(i != 0) pct++;
                        boolean bool = true;
                        for(int j = 0 ; j < s.length() && ebishu ; j++){
                                if(s.charAt(j) == pct) bool = false;
                        }
                        if(bool){
                                System.out.println(pct);
                                ebishu = false;
                        }
                }
                if(ebishu) System.out.println("None");
        }
}//0=48
//鶏になれ

Measured memory_bytes: 39564
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int main(){
  ll n,m; cin >> n >> m;
  vector<vector<ll> > v(n);
  vector<ll> p(m), y(m);
  rep(i,0,m){
    cin >> p[i] >> y[i];
    p[i]--;
    v[p[i]].pb(y[i]);
  }
  rep(i,0,n){
    sort(all(v[i]));
  }
  rep(i,0,m){
    auto ite = lower_bound(all(v[p[i]]), y[i]) - v[p[i]].begin();
    printf("%06lld%06ld\n", p[i]+1, ite+1);
  }
  return 0;
}


Measured memory_bytes: 8576
N = int(input())
x = list(map(int,input().split()))
count =[]
for i in range(100):
    HP = 0
    for j in range(N):
        a = (x[j]-(i+1))**2
        #print(x[j])
        HP +=a
 #   print(HP)
    count.append(HP)
   # print(HP)
print(min(count))
#消費体力を計算する

#前回と比較する
#前回より大きければ、記録する


Measured memory_bytes: 3060
import java.awt.*;
import java.util.*;
public class Main{
	static Scanner s=new Scanner(System.in);
	static int g(){return Integer.parseInt(s.next());}
	public static void main(String[]$){
		Point st=new Point(g(),g()),go=new Point(g(),g());
		if(st.y>go.y){
			Point buf=go;
			go=st;
			st=buf;
		}
		Comparator<Point>c=Comparator.comparingDouble(Point::getX);
		TreeSet<Point>p=new TreeSet<>(st.x<go.x?c:c.reversed());
		for(int i=g();i>0;--i){
			int x=g(),y=g();
			if(st.y<=y&&y<=go.y)
				p.add(new Point(x,y));
		}
		int v=lis(p.subSet(st,true,go,true));
		System.out.println(
				(Math.abs(st.x-go.x)+Math.abs(st.y-go.y))*100L
				+v*-20
				+(v==Math.min(go.y-st.y,Math.abs(go.x-st.x))+1?
						v+1:v)
						*5*Math.PI
				);
	}
	static int lis(NavigableSet<Point>p){
		ArrayList<Integer>l=new ArrayList<>();
		l.add(Integer.MIN_VALUE);
		while(!p.isEmpty()){
			int y=p.pollFirst().y;
			if(l.get(l.size()-1)<y)
				l.add(y);
			else {
				int v=Collections.binarySearch(l,y);
				if(v<0)
					l.set(~v,y);
			}
		}
		return l.size()-1;
	}
}

Measured memory_bytes: 92180
x,y=map(int,input().split())
if y>2*x or x>2*y:
    print(0)
    exit()
if not (x+y)%3==0:
    print(0)
    exit()
m=(x+y)//3
k=x-m
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7
N = 3*10**6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
print(cmb(m,k,mod))

Measured memory_bytes: 270996
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=300;
int n;
char ans[maxn];
char s[30];
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	printf("? ");
	for (int i=1;i<=n;i++) printf("%d ",i);
	printf("\n");
	fflush(stdout);
	scanf("%s",s+1);
	bool x=(s[1]=='R');
	int l=1,r=n+1,mid;
	while (l+1<r) {
		mid=(l+r)/2;
		printf("? ");
		for (int i=1;i<=n;i++) printf("%d ",i+mid-1);
		printf("\n");
		fflush(stdout);
		scanf("%s",s+1);
		if (x==(s[1]=='R')) l=mid;
		else r=mid;
	}
	for (int i=1;i<=n*2;i++) {
		printf("? ");
		if (r<=i&&i<=r+n-2) {
			for (int j=1;j<r-1;j++) printf("%d ",j);
			for (int j=r+n;j<=n*2;j++) printf("%d ",j);
			printf("%d\n",i);
			fflush(stdout);
		} else {
			for (int j=r;j<=r+n-2;j++) printf("%d ",j);
			printf("%d\n",i);
			fflush(stdout);
		}
		scanf("%s",s+1);
		ans[i]=s[1];
	}
	printf("! ");
	for (int i=1;i<=n*2;i++) printf("%c",ans[i]);
	printf("\n");
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 724
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<stdbool.h>
#include<string.h>

#define M 10000

  
  int top;
  int S[M];

  
bool isEnpty(int *S){
  if(top == 0) return true;
  else return false;
}

void push(int *S,int x){
  top = top + 1;
  S[top] = x;

}
  

int pop(int *S){
 
  if(isEnpty(S) == true) printf("underflow\n");
  else top =top - 1;
 
  return S[top + 1];
 
}
   
 
 
int main(){

  char p[M];
  int i,j,k,a,b;
 
  S[0] = '0';

  while(scanf("%s",p) != EOF){

    if(p[0] == ' ') continue;
    
    if(p[0] == '+'){

      a = pop(S);
      b = pop(S);
      push(S,b+a);
    }

   
    else if(p[0] == '-'){

      a = pop(S);
      b = pop(S);
      push(S,b-a);
    }
    else if(p[0] == '*'){
   
      a = pop(S);
      b = pop(S);
      push(S,b*a);
    }
    else {

      push(S, atoi(p));
    }

  }


  
  printf("%d\n",S[top]);
 
   
  return 0;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=100005;
//i_am_noob
int n,l,ans=0;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n >> l;
	rep(n) ans+=l+i;
	if(l>0) print1(ans-l);
	else if(l+n-1<0) print1(ans-l-n+1);
	else print1(ans);
	return 0;
}


Measured memory_bytes: 256
def ma():
  n,m=map(int,input().split())
  ans=0
  e=[ ]
  for i in range(m):
    e.append(set(list(map(int,input().split()))[1:]))
  f=list(map(int,input().split()))
  for i in range(2**n):
    l=set()
    for a,b in zip(range(1,n+1),bin(i)[2:].zfill(n)) :
      if b=="1":l.add(a)
    for j in range(1,m+1):
      if int(len(e[j-1]&l)%2!=f[j-1]):break
    else:ans+=1
  print(ans)

if __name__=="__main__":
  ma()

Measured memory_bytes: 41840
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, A[112345];
LL ans;

int main()
{
	in >> N;
	rep(i, N) { in >> A[i]; }

	std::sort(A, A + N);
	LL cou = 1;
	rep(i, N)
	{
		if (A[i] == A[i + 1]) { ++cou; }
		else
		{
			if (cou % 2LL == 1LL) { ++ans; }
			cou = 1;
		}
	}

	out << ans << std::endl;
	return 0;
}

Measured memory_bytes: 1024
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right,bisect
n,m,k=map(int,stdin.readline().split())
a=list(map(int,stdin.readline().split()))
b=list(map(int,stdin.readline().split()))
prea=[]
ans=0
for i in a:
    ans+=i 
    prea.append(ans)
final=bisect(prea,k)
temp=0
for i in range(m):
    temp+=b[i]
    if(temp>k):
        break
    temp2=bisect(prea,k-temp)
    final=max(final,temp2+i+1)
print(final)

Measured memory_bytes: 41924
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;

void DFS(int v, int from, const vector<vi>& g, vi& parent) {
  parent[v] = from;
  for (int to : g[v]) if (to != from) DFS(to, v, g, parent);
}

int main()
{
  int n;
  cin >> n;
  vector<vi> g(n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vi parent(n);
  DFS(0, -1, g, parent);
  ll result = 0;
  for (ll len = 1; len <= n; ++len) result += len * (n - len + 1);
  for (int i = 0; i < n; ++i) {
    ll p = parent[i] + 1;
    ll q = i + 1;
    if (p > q) swap(p, q);
    result -= p * (n - q + 1);
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 27480
use std::cmp::min;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|i| i.parse().ok().unwrap())
        .collect()
}

fn shortest(i: i32, j: i32, x: i32, y: i32) -> usize {
    let mut short = min((i-j).abs(), (i-x).abs() + 1 + (y-j).abs());
    
    short = min(short, (i-y).abs()+1+(j-x).abs());
    (short as usize)
}

fn solve() {
    let input = read_vec::<i32>();
    let n = input[0];
    let x = input[1] - 1;
    let y = input[2] - 1;

    let mut len = vec![0; (n - 1) as usize];

    for i in 0..n {
        for j in i+1..n {
            let index = shortest(i,j,x,y) - 1;
            len[index] += 1;
        }
    }


    for i in len.iter() {
        println!("{}", i);
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(32*1024*1024)
        .name("solve".into())
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}

Measured memory_bytes: 8572
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {

    vector<bool> is_square(100000, false);
    for (ll i = 0; i * i < 100000; i++) {
        is_square[i * i] = true;
    }
    
    ll n, d; cin >> n >> d;
    vector<vector<ll>> x(n, vector<ll>(d));
    REP(i, n) REP(j, d) {
        cin >> x[i][j];
    }

    ll ans = 0;
    RANGE(i, 0, n-1) RANGE(j, i+1, n-1) {

        ll d2 = 0;
        REP(k, d) {
            ll dxi = x[i][k] - x[j][k];
            d2 += dxi * dxi;
        }
        ans += is_square[d2];

    }
    cout << ans << endl;


    
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
using namespace std;

#define ll long long
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define mem(a,b) memset(a,b,sizeof(a))
#define cpy(a,b) memcpy(a,b,sizeof(b))
#pragma comment(linker, "/STACK:102400000,102400000")
inline void read(int &x){x=0; char ch=getchar();while(ch<'0') ch=getchar();while(ch>='0'){x=x*10+ch-48; ch=getchar();}}

int n,a[100100],b[100100];
ll sum;
//sum=k*n*(n+1)/2
//d[i]=(1-n)x+k-x -> k-d[i]=nx

int main()
{
    scanf("%d",&n);
    //sum=0;
    for(int i=0;i<n;++i) { scanf("%d",a+i);sum+=a[i]; }
    for(int i=0;i<n;++i) b[i]=a[i]-(i==0?a[n-1]:a[i-1]);
    ll ret=1LL*n*(n+1)/2;
    if(sum%ret) {puts("NO");return 0;}
    int k=sum/ret;
    bool flag=0;
    for(int i=0;i<n;++i)
    {
        if(b[i]>k) { flag=1;break; }
        if((k-b[i])%n==0) continue; else { flag=1;break; }
    }
    if(flag) puts("NO");else puts("YES");
    return 0;
}


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

int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    int A,B,C,K,max=0;

    cin>>A>>B>>C>>K;

    if(K>=A){
        K-=A;
        max+=A;
        if(K>=B){
            K-=B;
            max-=K;
        }
    }
    else{
        max=K;
    }

    cout<<max<<endl;

    return 0;
}

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

#define IOS cin.tie(0);ios_base::sync_with_stdio(false)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vs      vector<string>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)    for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 200;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//

signed main(){
    SCIN(s);
    int cur1=0,cur2=0;
    rep(i,s.size()){
        if(i%2==0&&s[i]=='0')cur1++;
        else if(i%2==1&&s[i]=='1')cur1++;
    }
    rep(i,s.size()){
        if(i%2==0&&s[i]=='1')cur2++;
        else if(i%2==1&&s[i]=='0')cur2++;
    }
    printf("%d\n",min(cur1,cur2));

    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

long long mod = 1000000007;

int n, q, l, r;
string s;
int dp[1<<20];

int main() {
  //freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);

  cin >> n >> q >> s;
  // update dp
  for (size_t i = 2; i <= n; i++) {
    if(s[i-2] == 'A' and s[i-1] == 'C') {
      dp[i] = dp[i-1] + 1;
    } else {
      dp[i] = dp[i-1];
    }
  }

  while (q--) {
    cin >> l >> r;
    cout << dp[r]-dp[l] << endl;
  }

  return 0;
}


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

void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  if (n % 2 != 0) cout << "No" << endl;
  else {
    string firstS = s.substr(0, s.size() / 2);
    string secondS = s.substr(s.size() / 2);
    if (firstS == secondS) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

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


Measured memory_bytes: 256
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;
import java.util.TreeMap;


public class Main {
	
	public static void main(String[] args) throws IOException {
		Main m = new Main();
		m.input();
		m.solve();
		m.output();
	}
	/*
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	/*/
	InputUtil in = new InputUtil();
	PrintWriter out = new PrintWriter(System.out);
	//*/
	int N = 0;
	int[] A = null;
	int[] B = null;
	int[] C = null;
	long[] Cn = null;
	long ans = 0;
	List<TreeMap<Integer,Integer>> mapList = null;
	
	public void input() throws IOException {
		/*
		S = br.readLine();
		/*/
		N = in.nextInt();
		A = in.nextInt(new int[N]);
		B = in.nextInt(new int[N]);
		C = in.nextInt(new int[N]);
		Cn = new long[N];
		//*/
	}

	public void solve() throws IOException {
		Arrays.sort(A);
		Arrays.sort(B);
		Arrays.sort(C);
		
		solveSub();
		
	}
	
	private void solveSub() {
		int pA = 0; 
		int pB = 0;
		int pC = 0;
		for(;pC < N; pC++){
			if(pC>0) Cn[pC] = Cn[pC-1];
			for(;pB < N && B[pB] < C[pC]; pB++){
				for(;pA < N && A[pA] < B[pB]; pA++);
				Cn[pC] += pA;
			}
			ans += Cn[pC];
		}
	}
	
	
	public void output() {
		out.println(ans);
		out.flush();
		
	}
}


//*
class InputUtil {
	//Static Fields
	private static final int BUFSIZ = 100000;
	
	//Fields
	protected InputStream in;
	private byte[] buf = null;
	private int ptr = 0;
	private int max = -1;
	private DataInputStream dis = null;
	//Constructors
	public InputUtil() {this(System.in,BUFSIZ);}
	public InputUtil(InputStream in, int bufsiz) {
		initBuf(bufsiz);
		initIn(in);
	}
	
	//Methods
	//Initializer
	protected void initIn(InputStream in) {dis = new DataInputStream(this.in = in);}
	protected void initBuf(int bufsiz) {buf = new byte[bufsiz];}
	
	//buffer operation
	private void next() throws IOException {ptr++; readBuf();}
	private void readBuf() throws IOException {
		if(ptr >= max && dis.available()>0) {
			if(max>0) Arrays.fill(buf,0,max,(byte)0);
			max = dis.read(buf);
			ptr = 0;
		}
	}
	
	//Number Input Reader/Parser
	private boolean isNum(byte b) {return '0' <= b && b <= '9'; }
	private boolean isMinus(byte b) {return b=='-'; }

	private int _nextInt() throws IOException {
		int sign = 1;
		int res = 0;
		byte c;
		while (!isNum(c=buf[ptr]) && !isMinus(c)) 
			next();
		if (isMinus(buf[ptr])) {
			sign = -1;
			next();
		}
		while (isNum(c=buf[ptr])) {
			res *= 10;
			res += c - '0' ;
			next();
		}
		next();
		return sign * res;
	}
	
	public int nextInt() throws IOException {
		readBuf();
		return _nextInt();
	}

	public int[] nextInt(int[] result) throws IOException {
		readBuf();
		for(int i=0; i<result.length; i++) {
			result[i] = _nextInt();
		}
		return result;
	}
	
	//Close 
	public void close() throws IOException {
		if(!this.in.equals(System.in)) 
			this.in.close();
	}
}
//*/


Measured memory_bytes: 26780
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;

int asort(const void *a, const void *b){
  int A = *(int *)a, B = *(int *)b;
  if(A > B) return  1;
  if(A < B) return -1;
  return 0;
}

int dsort(const void *a, const void *b){
  int A = *(int *)a, B = *(int *)b;
  if(A < B) return  1;
  if(A > B) return -1;
  return 0;
}

typedef struct {
  char name[20];
  int time;
} Process;

int
main(int argc, char *argv[])
{
  int n, q;
  scanf("%d %d", &n, &q);
  Process p[100000];
  rep(i, n) scanf("%s %d", p[i].name, &p[i].time);

  int que[1000000] = {};
  rep(i, n) que[i] = i;
  int f = 0; int t = n; int T = 0;
  while(f < t) {
    if(p[que[f]].time > q) {
      p[que[f]].time -= q;
      que[t] = que[f];
      f++; t++;
      T += q;
    } else {
      T += p[que[f]].time;
      printf("%s %d\n", p[que[f]].name, T);
      f++;
    }
  }
  
  return 0;
}
      
  
  
  



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

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;
typedef pair<int, int> P;

#define MAX 100005
#define INF INT_MAX

class Tree
{
    vector<int> rank, id; 
public:
    Tree(int n) : rank(n), id(n) {
        rep(i,n) id[i] = i;
    }
    int getId(int n) {
        if (n != id[n]) id[n] = getId(id[n]);
        return id[n];
    }
    void uniteTree(int u, int v) {
        u = getId(u);
        v = getId(v);
        if (rank[u] > rank[v]) swap(u,v);
        if (rank[u] == rank[v]) rank[v]++;
        id[u] = v;
    }

};

struct Edge
{
    int u, v;
    int cost;
    bool operator<(const Edge& e) const { return this->cost < e.cost; }
};

int main(int, char**)
{
    int n;
    cin >> n;

    vector<Edge> E;
    int tmp;
    rep(i,n) rep(j,n) {
        cin >> tmp;
        if (i >= j) continue;
        if (tmp == -1) continue;
        E.push_back({i,j,tmp});
    }

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

    Tree tree(n);
    ll ans = 0;
    rep(i,E.size()) {
        int u = E[i].u;
        int v = E[i].v;
        if (tree.getId(u) != tree.getId(v)) {
            tree.uniteTree(u,v);
            ans += E[i].cost;
        }
    }

    cout << ans << endl;

    return 0;
}



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

int main() {
  ios::sync_with_stdio(0); cin.tie(NULL);
  int n;
  cin >> n;
  int arr[2 * n];
  for (int i = 0; i < 2 * n; ++i) {
    cin >> arr[i];
  }
  sort(arr, arr + 2 * n);
  int ans = 0;
  for (int i = 2 * n - 1; i > 0; i -= 2) {
    ans += min(arr[i], arr[i - 1]);
  }
  cout << ans << '\n';
  return 0;
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N; cin >> N;
    string ans="";
    while(N>0){
        ans+='a'+(--N)%26;
        N/=26;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << '\n';
}

Measured memory_bytes: 3644
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
/*メンチン待ちクイズ*/
void solve(){
    int n;
    cin >> n;
    vector<vector<int> >data(n, vector<int>(2));
    for(int i = 0; i < n; i++){
        cin >> data.at(i).at(0) >> data.at(i).at(1);
    }//入力甘露ゆ
    vector<vector<double> >length(n, vector<double>(n));
    double total = 0;
for(int i = 0; i < n; i++){
    for(int j = i + 1; j < n; j++){//常にi < j
        length.at(i).at(j) = sqrt((data.at(i).at(0) - data.at(j).at(0)) * (data.at(i).at(0) - data.at(j).at(0)) + ((data.at(i).at(1) - data.at(j).at(1)) * (data.at(i).at(1) - data.at(j).at(1))));
        total += length.at(i).at(j);
    }
}//距離入力完了
double ans = 0;
ans = total * 2 / n; 
cout << fixed << setprecision(10);
cout << ans << endl;
}
int main(){
    solve();
    return 0;
}


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

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

i64 n, a, b, c;
vector<string> ss;
vector<char> ans;
map<tuple<i64, i64, i64, i64>, i64> dp;

bool dfs(i64 depth, i64 x, i64 y, i64 z) {
    if (dp.find({ depth, x, y, z }) != dp.end()) return dp[{ depth, x, y, z }];
    if (x < 0 || y < 0 || z < 0) return false;
    if (depth == n) return true;

    i64 na, nb, nc;
    if (ss[depth] == "AB") {
        na = x + 1, nb = y - 1, nc = z;
        ans.push_back('A');
    } else if (ss[depth] == "AC") {
        na = x + 1, nb = y, nc = z - 1;
        ans.push_back('A');
    } else {
        na = x, nb = y + 1, nc = z - 1;
        ans.push_back('B');
    }

    if (dfs(depth + 1, na, nb, nc)) return true;
    ans.pop_back();

    if (ss[depth] == "AB") {
        na = x - 1, nb = y + 1, nc = z;
        ans.push_back('B');
    } else if (ss[depth] == "AC") {
        na = x - 1, nb = y, nc = z + 1;
        ans.push_back('C');
    } else {
        na = x, nb = y - 1, nc = z + 1;
        ans.push_back('C');
    }

    if (dfs(depth + 1, na, nb, nc)) return true;
    ans.pop_back();

    return dp[{ depth, x, y, z }] = false;
}

void solve() {
    cin >> n >> a >> b >> c;
    ss.resize(n);
    for (auto& e : ss) cin >> e;

    if (dfs(0, a, b, c)) {
        cout << "Yes" << endl;
        for (auto& e : ans) cout << e << endl;
    } else {
        cout << "No" << endl;
    }
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 22752
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N; cin >> N;
  if(N % 2 == 1) { cout << "0"; return 0;}
  ll a = 1, ans = 0;
  while(1){
    ll tmp = 2*pow(5,a); 
    if(tmp > N) break;
    ans += N/tmp;
    a++;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int n,a[3][100010];
int need_swap[2],real_swap[2];
int num[100010],id[100010];
int tree[100010];
void add(int _id,int x){for(;_id<=n;_id+=_id&-_id) tree[_id]+=x;}
int query(int _id){int re=0;for(;_id;_id-=_id&-_id) re+=tree[_id];return re;}
int main()
{
    scanf("%d",&n);
    for (int j=0;j<3;j++)
    for (int i=1;i<=n;i++) 
        scanf("%d",&a[j][i]);
    for (int i=1;i<=n;i++)
    for (int j=0;j<3;j++)
    {
        if ((a[0][i]^i)&1) { printf("No");return 0;}
        if (a[0][i]==a[1][i]+1&&a[1][i]==a[2][i]+1&&a[2][i]%3!=0) 
        {
            need_swap[i&1]++;num[i]=a[2][i]/3+1;id[num[i]]=i;continue;
        }
        if (a[0][i]==a[1][i]-1&&a[1][i]==a[2][i]-1&&a[0][i]%3!=0) 
        {
            num[i]=a[0][i]/3+1;id[num[i]]=i;continue;
        }
        printf("No");return 0;
    }
    int cnt;
    for (int i=1;i<=n;i+=2)
    {
        cnt=id[i]+2*(i/2-query(id[i]));
        real_swap[0]+=abs(i-cnt)/2;
        add(id[i],1);
    }
    memset(tree,0,sizeof(tree));
    for (int i=2;i<=n;i+=2)
    {
        cnt=id[i]+2*(i/2-1-query(id[i]));
        real_swap[1]+=abs(i-cnt)/2;
        add(id[i],1);
    }
    real_swap[0]%=2;real_swap[1]%=2;need_swap[0]%=2;need_swap[1]%=2;
    if (real_swap[0]!=need_swap[0]||real_swap[1]!=need_swap[1]) printf("No");
    else printf("Yes");
}

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

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
const int INF = 1<<30;

int main(){
  int n;cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int ans=1;
  int pos=0;
  while(pos<n){
    int t=pos+1;
    while(t<n&&a[t]==a[pos])t++;
    if(t==n){break;}
    bool inc=(a[pos]<a[t]);
    pos=t;
    t=0;
    while(pos+t+1<n && 
          (a[pos+t]<a[pos+t+1]==inc || a[pos+t]==a[pos+t+1]))t++;
    if(pos+t+1==n){break;}
    pos+=t+1;
    ans++;
  }
  cout<<ans<<endl;
}


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

using namespace std;

void solve()
{
	int a, b, s, t;
	cin >> a >> b >> s >> t;
	int x = a%s, y = b%t;
	cout << x*b + y*a - x*y << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}



Measured memory_bytes: 3104