akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



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

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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string a,b,c;
  cin>>a>>b>>c;
  string res="";
  res+=(a[0]+'A'-'a');
  res+=(b[0]+'A'-'a');
  res+=(c[0]+'A'-'a');
  cout<<res<<endl;
  
  

  return 0;

}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque

S = input().rstrip()
S = deque(S)
Q = int(input())
Que = (input().rstrip() for _ in range(Q))

flag = 0 #0:そのまま 1:反転
for elem in Que:
  if elem[0] == '1':
    flag ^= 1
  else:
    s = int(elem[2])
    if s == 1 and flag == 0:
      S.appendleft(elem[4])
    elif s == 2 and flag == 0:
      S.append(elem[4])
    elif s == 1 and flag == 1:
      S.append(elem[4])
    else:
      S.appendleft(elem[4])

if flag == 1:
  S.reverse()
print(''.join(S))

Measured memory_bytes: 8428
n = int(input())
H = [int(i) for i in input().split()]

garden = [0] * n
ans,i = 0,0

while H != garden:
    
    if H[i] != garden[i]:
        
        while 1:
            if n == i or H[i] == garden[i]:
                ans += 1
                break
            else:
                garden[i] += 1
            i += 1
    
    else: i += 1
    if n <= i: i = 0
    #print(garden)

print(ans)



Measured memory_bytes: 3060
#include<stdio.h>

int main()
{
    int a,b,c,d;

    scanf(" %d %d %d %d",&a,&b,&c,&d);
    if(a-c>=-d&&a-c<=d||a-b>=-d&&a-b<=d&&c-b>=-d&&c-b<=d)
        printf("Yes ");
    else
        printf("No ");

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int distance(int a, int b, int c, int d) {
    return abs(a-c) + abs(b-d);
}
int main() {
    int n, m;
    cin >> n >> m;
    int a[n], b[n], c[m], d[m];
    for (int i=0; i<n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i=0; i<m; i++) {
        cin >> c[i] >> d[i];
    }
    int point[n], min;
    for (int i=0; i<n; i++) {
        min = distance(a[i], b[i], c[0], d[0]);
        point[i] = 1;
        for (int j=1; j<m; j++) {
            if (distance(a[i], b[i], c[j], d[j]) < min) {
                point[i] = j+1;
                min = distance(a[i], b[i], c[j], d[j]);
            }
        }
        cout << point[i] << endl;
    }
}

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

#define PI 3.14159265

int main()
{
        double a, b, c;
        double s, l, h;
        cin >> a >> b >> c;
        s = 0.5*a*b*sin(c*PI/180);
        l = a + b + sqrt(a*a+b*b-2*a*b*cos(c*PI/180));
        h = b * sin(c*PI/180);
        printf("%.8lf\n%.8lf\n%.8lf\n", s, l, h);        

        return 0;
}

Measured memory_bytes: 1264
/******************************************
* AUTHOR : HRITIK AGGARWAL *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define F first
#define S second
ll po(ll a, ll x,ll m){ if(x==0){return 1;}ll ans=1;ll k=1;  while(k<=x) {if(x&k){ans=((ans*a)%m);} k<<=1; a*=a; a%=m; }return ans; }
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int a,b;
	cin>>a>>b;
	if(b==1){
		cout<<"0"<<"\n";
		return 0;
	}
	int ans=1;
	int temp=a;
	while(temp<b){
		ans++;
		temp+=a-1;
	}
	cout<<ans<<"\n";
return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(read())
	a := make([]int, n)
	cnt := 0
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(read())
		if i >= 2 {
			if (a[i-1]-a[i])*(a[i-2]-a[i-1]) >= 0 {
				cnt++
			}
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 640
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A, B, C = map(int, readline().split())
    if C < A - B:
        print(0)
    else:
        print(C - A + B)
    
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9124
a = []
while True:
    d = list(map(int,input().split()))
    if d == [-1,-1,-1]:
        break
    a.append(d)

def Point2Grade(d):
    m,f,r = d
    if (m==-1)|(f==-1):
        return 'F'
    elif m+f >= 80:
        return 'A'
    elif m+f >= 65:
        return 'B'
    elif m+f >= 50:
        return 'C'
    elif m+f >= 30:
        if r >=50: return 'C'
        else: return 'D'
    else: return 'F'

for x in a:
    print(Point2Grade(x))

Measured memory_bytes: 7712
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))

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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
    SS(string,s)
    set<char>S;
    rep(i,3)S.insert(s[i]);
    Yes(S.size()==2);
}

Measured memory_bytes: 256
//標準関数をすべてインクルードする。
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

const int_least64_t INF = 10000000;

int main(){
    //cin coutを高速化
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);

    int a, b, k;
    cin >> k >> a >> b;
    int rem = 0;
    for(int i = 1; i * k <= b; i++){
        if(a <= i * k && i * k <= b){
            rem = 1;
        }
    }
    if (rem == 1) cout << "OK" << endl;
    else cout << "NG" << endl;
    return 0;
}



Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <atcoder/all>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
using namespace atcoder;

struct UF {
	int par[100000];
	UF() { int i; rep(i, 100000) par[i] = i; }
	int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); }
	void unit(int x, int y) { x = root(x); y = root(y); par[x] = y; }
	bool same(int x, int y) { return root(x) == root(y); }
};

int n, m;
int a, b;
UF uf;

signed main() {
	int i;

	cin >> n >> m;
	
	int ans = n - 1;
	rep(i, m) {
		cin >> a >> b;
		a--; b--;
		if (uf.same(a, b) == false) {
			uf.unit(a, b);
			ans--;
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3976
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
D,X = map(int,input().split())
A = [int(input()) for _ in range(N)]

chocos = []
for i in range(N):
    chocos.append((D-1)//A[i] + 1)

ans = sum(chocos)+X

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 2940
// The very basic /////////////////////////////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define ALL_H 1

// Print elements of containers using << operator /////////////////////////////
// pair
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
  return s << "(" << p.first << ", " << p.second << ")";}
// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  for (auto &elem : v) {
    s << elem;
    if (&elem != &v.back()) s << " ";
  }
  return s;
}
// 2 dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  for (auto &elem : vv) {
    s << elem;
    if (&elem != &vv.back()) s << endl;
  }
  return s;
}
// map
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
  s << "{" << endl;
  for (auto &elem: m) {
    s << " " << elem.first << " : " << elem.second << endl;
  }
  s << "}";
  return s;
}
//set
template<typename T> ostream& operator<<(ostream& s, const set<T>& m) {
  s << "{ ";
  for (auto &elem: m) {
    s << elem << " ";
  }
  s << "}";
  return s;
}

// Convenient macros //////////////////////////////////////////////////////////

// types
#define ll long long
#define ld long double
#define int ll
#define Pi pair<int, int>
#define Graph vector<vector<int>>
#define WeightGraph vector<vector<Pi>>

// other
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

#define MOD 1000000007
#define INF LLONG_MAX/1000

// update max or min //////////////////////////////////////////////////////////

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; }

// gcd
int gcd(int a,int b){return b?gcd(b,a%b):a;}

// direction
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};


// Debug it by D(x) ///////////////////////////////////////////////////////////
#define DEBUG 1
#if DEBUG
#define D(x) x
#else
#define D(x)
#endif

///////////////////////////////////////////////////////////////////////////////
//                             Start Coding Here                             //
///////////////////////////////////////////////////////////////////////////////

signed main() {
  int N; cin >> N;
  vector<Pi> X;
  rep(i, N) {
    int x, l; cin >> x >> l;
    X.push_back(make_pair(x-l, x+l));
  }
  auto sortbysec = [&](const Pi &l, const Pi &r) {
                     return (l.second < r.second);
                   };
  sort(all(X), sortbysec);
  int ans = 0;
  int now = -INF;
  for (int i = 0; i < N;){
    while (i < N && now > X[i].first) {
      i++;
    }
    if (i >= N) {
      break;
    }
    now = X[i].second;
    ans++;
    i++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2420
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    from collections import defaultdict
    #nの素因数分解，[[a1,b1],[a2,b2]...]   aがb個,
    def factorization(n):
        if n==1:
            return [[1,0]]
        arr = []
        temp = n
        for i in range(2, int(-(-n**0.5//1))+1):
            if temp%i==0:
                cnt=0
                while temp%i==0:
                    cnt+=1
                    temp //= i
                arr.append([i, cnt])

        if temp!=1:
            arr.append([temp, 1])

        if arr==[]:
            arr.append([n, 1])

        return arr
    
    lcm_dd = defaultdict(int)
    
    N=I()
    A=LI()
    for i in range(N):
        a=A[i]
        arr=factorization(a)
        for v in arr:
            p,cnt=v
            lcm_dd[p]=max(lcm_dd[p],cnt)
            
    lcm=1
    for k,v in lcm_dd.items():
        temp=pow(k,v,mod)
        lcm=(lcm*temp)%mod
        
    ans=0
    for i in range(N):
        temp=(lcm*pow(A[i],mod-2,mod))%mod
        ans=(ans+temp)%mod
        
    print(ans%mod)
        
    


main()


Measured memory_bytes: 75656
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n,tmp,ans=0;
    cin>>n;
    int l[n];
    for(int i=0;i<n;i++)cin>>l[i];
    while(1){
        int count=0;
        for(int i=0;i<n-1;i++){
            if(l[i]<l[i+1]){
                tmp=l[i];
                l[i]=l[i+1];
                l[i+1]=tmp;
                count++;
            }
        }
        if(count==0)break;
    }
    for(int i=1;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            for(int k=i-1;k>=0;k--){
                if(l[k]<l[i]+l[j])ans++;
                else break;
            }
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
s = input()
n = len(s)
St = []
St2 = []
h = 0
area = 0

for i in range(n):
    if s[i] == "\\":
        St.append(i)
        h -= 1
    elif s[i] == "/":
        h += 1
        if St:
            left = St.pop()
            area += i - left
            
            area2 = 0
            while St2:
                left2 = St2.pop()
                j = left2[0]
                if left < left2[0]:
                    area_add = left2[1]
                    area2 += area_add
                else:
                    St2.append(left2)
                    break
            St2.append([left, area2 + i-left])


print(area)
ans = [t[1] for t in St2]
if St2:
    print(len(St2), end = " ")
    print(*ans)

else:
    print(0)



Measured memory_bytes: 6516
#include<bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define endl "\n"
#define pb push_back
#define se second
#define fi first
#define int long long 
#define pi pair<int,int>
#define vpi vector<pi>
#define vvi vector<vpi>
#define For(i,n) for(int i=0;i<n;i++)
#define pie =3.14159265358979323846264338327950;
const int mod= 1e9+7;

int32_t main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
	int n;
	cin>>n;
	int ac= 0;
	int wa=0;
	int tle=0;
	int re=0;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		if(s=="AC")ac++;
		else if(s=="WA") wa++;
		else if(s=="TLE") tle++;
		else re++;
	}
	cout<<"AC x "<<ac<<endl;
	cout<<"WA x "<<wa<<endl;
	cout<<"TLE x "<<tle<<endl;
	cout<<"RE x "<<re<<endl;
	return 0;
}


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

class Lazysegtree:
    #RUQ
    def __init__(self, A, intv, initialize = True, segf = min):
        #区間は 1-indexed で管理
        self.N = len(A)
        self.N0 = 2**(self.N-1).bit_length()
        self.intv = intv
        self.segf = segf
        self.lazy = [None]*(2*self.N0)
        if initialize:
            self.data = [intv]*self.N0 + A + [intv]*(self.N0 - self.N)
            for i in range(self.N0-1, -1, -1):
                self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) 
        else:
            self.data = [intv]*(2*self.N0)

    def _ascend(self, k):
        k = k >> 1
        c = k.bit_length()
        for j in range(c):
            idx = k >> j
            self.data[idx] = self.segf(self.data[2*idx], self.data[2*idx+1])
            
    def _descend(self, k):
        k = k >> 1
        idx = 1
        c = k.bit_length()
        for j in range(1, c+1):
            idx = k >> (c - j)
            if self.lazy[idx] is None:
                continue
            self.data[2*idx] = self.data[2*idx+1] = self.lazy[2*idx] \
            = self.lazy[2*idx+1] = self.lazy[idx] 
            self.lazy[idx] = None
            
            
    def query(self, l, r):
        L = l+self.N0
        R = r+self.N0
        self._descend(L//(L & -L))
        self._descend(R//(R & -R)-1)
        
        s = self.intv                                                                   

        while L < R:
            if R & 1:
                R -= 1
                s = self.segf(s, self.data[R])
            if L & 1:
                s = self.segf(s, self.data[L])
                L += 1
            L >>= 1
            R >>= 1
        return s
    
    def update(self, l, r, x):
        L = l+self.N0
        R = r+self.N0

        Li = L//(L & -L)
        Ri = R//(R & -R)
        self._descend(Li)
        self._descend(Ri-1)
        
        while L < R :
            if R & 1:
                R -= 1
                self.data[R] = x
                self.lazy[R] = x
            if L & 1:
                self.data[L] = x
                self.lazy[L] = x
                L += 1
            L >>= 1
            R >>= 1
        
        self._ascend(Li)
        self._ascend(Ri-1)

inf = 10**19
N, A, B = map(int, readline().split())
S = [-inf] + [int(readline()) for _ in range(N)]

MOD = 10**9+7
dpa = Lazysegtree([1] + [0]*N, 0, initialize = True, segf = lambda x, y: (x+y)%MOD)
dpb = Lazysegtree([1] + [0]*N, 0, initialize = True, segf = lambda x, y: (x+y)%MOD)

for i in range(1, N+1):
    oka = 0
    ng = i
    while abs(oka-ng) > 1:
        med = (oka+ng)//2
        if S[i] - S[med] >= A:
            oka = med
        else:
            ng = med

    okb = 0
    ng = i
    while abs(okb-ng) > 1:
        med = (okb+ng)//2
        if S[i] - S[med] >= B:
            okb = med
        else:
            ng = med
    
    tb = dpa.query(0, okb+1)
    dpa.update(i-1, i, dpb.query(0, oka+1))
    dpb.update(i-1, i, tb)
    if S[i] - S[i-1] < A:
        dpa.update(0, i-1, 0)
    if S[i] - S[i-1] < B:
        dpb.update(0, i-1, 0)
print((dpa.query(0, N+1) + dpb.query(0, N+1)) % MOD)


Measured memory_bytes: 87260
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define pi 3.14159265358979323846264338327950L
using namespace std;

int main() {
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  if (B!=0) {
    if (A!=0) {
      for (int i=0; i<B; i++) {
        for (int j=0; j<A; j++) {
          cout << "0";
        }
        for (int j=A; j<W; j++) {
          cout << "1";
        }
        cout << endl;
      }
      for (int i=B; i<H; i++) {
        for (int j=0; j<A; j++) {
          cout << "1";
        }
        for (int j=A; j<W; j++) {
          cout << "0";
        }
        cout << endl;
      }
    }
    else {
      for (int i=0; i<B; i++) {
        for (int i=0; i<W; i++) {
          cout << "1";
        }
        cout << endl;
      }
      for (int i=B; i<H; i++) {
        for (int i=0; i<W; i++) {
          cout << "0";
        }
        cout << endl;
      }
    }
  }
  else {
    if (A!=0) {
      for (int i=0; i<H; i++) {
        for (int j=0; j<A; j++) {
          cout << "1";
        }
        for (int j=A; j<W; j++) {
          cout << "0";
        }
        cout << endl;
      }
    }
    else {
      for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
          cout << "0";
        }
        cout << endl;
      }
    }
  }
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#include <numeric>
// #define int long long
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;

long double calc_length(int xi, int xj, int yi, int yj){
    long double lenlen = (xi - xj)*(xi - xj) + (yi - yj)*(yi  - yj);
    return sqrt(lenlen);
}

signed main() {
    int n;
    cin >> n;
    vi x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];

    long double sum_of_len = 0;
    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            sum_of_len += calc_length(x[i], x[j], y[i], y[j]);
        }
    }
    cout << fixed;
    cout << setprecision(7) << sum_of_len*2.0000000 / (long double)n << endl;
}

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


int main() {
    int64_t A,B,N;
    cin>>A>>B>>N;
    int64_t x=B-1;
    if(x>N){
        x=N;
    }
    int64_t ans;
    int64_t fl1;
    int64_t fl2;
    fl1=A*x/B;
    fl2=x/B;
    ans=fl1-A*fl2;
    cout<<ans<<endl;

}

Measured memory_bytes: 3624
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9 + 7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4] ={ 1,0,-1,0 };
int dy[4] ={ 0,1,0,-1 };

int N;
string S;

inline vector<int> Z_algorithm(string S) {
	vector<int> Z(S.size());
	Z[0] = S.size();
	int i = 1, j = 0;
	while(i < S.size()){
		while(i + j < S.size() && S[j] == S[i + j]) j++;
		Z[i] = j;

		if(j == 0){
			i++;
			continue;
		}
		int k = 1;
		while(k < j && k + Z[k] < j){
			Z[i + k] = Z[k];
			k++;
		}
		i += k;
		j -= k;
	}
	return Z;
}

signed main() {
	cin >> N >> S;
	ll ans = 0;
	rep(i, N) {
		string T = S.substr(i, N - i);
		vector<int> v = Z_algorithm(T);
		for(int j = 1; j < v.size(); j++) {
			if(v[j] <= j) ans = max(ans, (ll)v[j]);
		}
	}
	cout << ans << endl;
}


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

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

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

    int ans = 0;
    for (int i=0; i<N-1; ) {
        if (v[i] == i+1) {
            swap(v[i], v[i+1]);
            ans++;
            i += 2;
        } else {
            i += 1;
        }
    }
    if (v[N-1] == N) ans++;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main()
{
  int n,X,Y,W,H,N,x,y,ans;
  cin>>n;
  while(n-->0){
    cin>>X>>Y>>W>>H>>N;
    ans=0;
    for(int i=0;i<N;i++){
      cin>>x>>y;
      if(X<=x & x<=X+W & Y<=y & y<=Y+H)ans++;
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    a+=b,c+=d;
    if(a==c){
        cout1("Balanced")
    }else if(a>c){
        cout1("Left")
    }else{
        cout1("Right")
    }
}

Measured memory_bytes: 256
package main

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

func main() {
	var wg sync.WaitGroup
	wg.Add(1)
	go func() {
		defer wg.Done()
		b := bufio.NewScanner(os.Stdin)
		b.Split(bufio.ScanWords)
		b.Scan()
		A, _ := strconv.Atoi(b.Text())
		b.Scan()
		B, _ := strconv.Atoi(b.Text())
		if B%A == 0 {
			fmt.Println(A + B)
		} else {
			fmt.Println(B - A)
		}
	}()
	wg.Wait()
}


Measured memory_bytes: 640
import math

N, D = map(int, input().split())
X_list = [0] * N
for i in range(N):
    X_list[i] = list(map(int, input().split()))

ans = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0
        for d in range(D):
            dist += (X_list[i][d] - X_list[j][d]) ** 2
        dist = dist ** (1/2)
        if dist - math.floor(dist) == 0:
            ans += 1
print(ans)


Measured memory_bytes: 38384
A,B,C = map(int,input().split())
count=0
if A==B==C and A%2==0 :
    print(-1)
elif A==B==C and A%2==1 :
    print(0)
else :
    while True :
        if A%2 != 0 or B%2 != 0 or C%2 != 0 :
            print(count)
            break
        elif A==B and B==C :
            print(-1)
            break
        else :
            count += 1
            dA=A
            dB=B
            dC=C
            A=dB/2+dC/2
            B=dA/2+dC/2
            C=dA/2+dB/2

Measured memory_bytes: 9272
import collections
n = int(input())
s = [input() for _ in range(n)]
c = collections.Counter(s)
C = c.most_common()
most_count = C[0][1]
answer = []

for i in range(len(C)):
  if most_count == C[i][1]:
    answer.append(C[i][0])

answer.sort()
for i in answer:
    print(i)

Measured memory_bytes: 47640
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
ll mlen=0,N,dp[3001][3001];
P memo[3000][3001];
char memoc[3000][3001];
string res="";
int main()
{
  string s,t;
  cin >> s >> t;
  REP(i,3001)REP(j,3001)dp[i][j] = 0;
  REP(i,3001)REP(j,3001)memoc[i][j] = 0;
  for(int i=0;i<s.size();i++)
    for(int j=0;j<t.size();j++){
      if(s[i] == t[j]){
        dp[i+1][j+1] = dp[i][j] + 1;
        memo[i+1][j+1] = P(i,j);
        memoc[i+1][j+1] = s[i];
      }else{
        if(dp[i+1][j] > dp[i][j+1]){
          dp[i+1][j+1] = dp[i+1][j];
          memo[i+1][j+1] = P(i+1,j);
        }else{
          dp[i+1][j+1] = dp[i][j+1];
          memo[i+1][j+1] = P(i,j+1);
        }
      }
    }
  int a=s.size(),b=t.size();
  while(a != 0 && b != 0){
    if(memoc[a][b] != 0)
      res = memoc[a][b] + res;
    P p = memo[a][b];
    a = p.first;
    b = p.second;
  }
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 220160
from collections import defaultdict
from heapq import heappush, heappop

def main():
    #Read stdin
    fl = input().split(" ")
    V = int(fl[0])
    E = int(fl[1])
    R = int(fl[2])
    #Adjacency list
    G = defaultdict(list)
    for i in range(int(E)):
        s, t, w = [int(x) for x in input().split(" ")]
        G[s].append((t,w))

    #initialized
    d = {}
    INF = float('inf')
    #INF = 10001
    for i in range(V):
        d[i] = INF
    d[R] = 0
    q = [R]
    while q:
        u = heappop(q)
        for v in G[u]:
            if d[v[0]] > d[u] + v[1]:
                d[v[0]] = d[u] + v[1]
                heappush(q, v[0])

    for k in d.keys():
        if d[k] == float('inf'):
            print("INF")
        else:
            print(d[k])

if __name__ == '__main__':
    main()

Measured memory_bytes: 111972
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;

int main(){
	int k, x;
	cin >> k >> x;

	if (x - k + 1 < -1000000){
		cout << -1000000;
		for(int i = -999999; i < x + k; i++) {
			cout << " " << i;
		}
	} else if (x + k - 1 > 1000000){
		cout << x - k + 1;
		for(int i = x - k + 2; i < 1000001; i++) {
			cout << " " << i;
		}
	} else {
		cout << x - k + 1;
		for(int i = x - k + 2; i < x + k; i++) {
			cout << " " << i;
		}
	}

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll mod=INF;


int main() {
    ll n;
    cin >> n;
    ll e=26;
    string s;
    while(true){
      int u=n%e;
      char y='a'+u-1;
      if (u!=0) s.push_back(y);
      if (u==0) {
        s.push_back('z');
        n--;
      }
      n/=e;
      if (n==0) break; 
    }
    reverse(all(s));
    cout << s << endl;
}


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

int main() {

	int N;
	std::cin >> N;

	std::vector<std::vector<int>> a(3, std::vector<int>(N + 1));
	for (int i = 1; i < 3; i++) {
		for (int j = 1; j <= N; j++)std::cin >> a[i][j];
	}

	int ans = 0;
	for (int j = 1; j <= N; j++) {
		int res = 0;
		
		//上側の和
		for (int k = 1; k <= j; k++)res += a[1][k];

		//下側の和
		for (int k = j; k <= N; k++)res += a[2][k];

		ans = std::max(ans, res);

	}
	std::cout << ans << std::endl;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int N;
    cin >> N;
    if (N >= 1 && N <= 10000 && N % 1000 == 0) {
        cout << "0";
    } else {
        int res;
        res = 1000 - (N % 1000);
        cout << res;
    }
    return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1001001001001001001;
const ll mod = 1000000007;
const int MAX = 1000100;

ll modpow(ll a, ll p){
    ll ret = 1; 
    while(p){
        if(p & 1) ret = ret * a % mod;
        a = a * a % mod;
        p >>= 1;
    }
    return ret;
}

ll gcd(ll a, ll b){ return (b == 0 ? a : gcd(b, a % b));}

int main(){
    int n; cin >> n;
    ll ans = 1;
    ll cnt = 0;
    map<pair<ll, ll>, pair<ll, ll>> mp;
    for(int i = 0; i < n; i++){
        ll a, b; cin >> a >> b;
        if(a == 0 && b == 0){
            cnt++;
        }
        else if(a == 0){
            mp[{0, 1}].first++;
        }
        else if(b == 0){
            mp[{0, 1}].second++;
        }
        else{
            ll g = gcd(a, b);
            a /= g;
            b /= g;
            //cout << a << " " << b << endl;
            if(b < 0){
                a = -a; b = -b;
            }
            if(a > 0){
                mp[{a, b}].first++;   
                //cout << a << " " << b << endl;
            }
            else{
                mp[{b, -a}].second++;
                //cout << b << " " << -a << endl;
            }
        }
    }
    for(auto p : mp){
        ll a = p.second.first, b = p.second.second;
        //cout << a << " " << b << " " << modpow(2, a) + modpow(2, b) << endl;
        ans *= (modpow(2, a) + modpow(2, b) - 1) % mod;
        ans %= mod;
        //cout << ans << endl;
    }
    cout << (ans + cnt + mod - 1) % mod<< endl;
}

Measured memory_bytes: 19176
//
// Created on 2020/04/13.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;

int d_cnt(int x){
    int i = 0;
    while(x > 0){
        x /=10;
        i ++;
    }
    return i;
}

int main() {
    int ans = 0;
    int n;
    cin>>n;

    for (int i = 1; i <= n; ++i) {
        if(d_cnt(i) % 2 == 1) ans++;
    }

    cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
  string S; 
  int counter=0;
  int tmp=0; 
  
  getline(cin,S);

  for(int i=0; i <(int)S.length(); i++){
    if(S[i]=='T'){
      if(tmp == 0){
	counter++;
	if(counter == (int)(S.length()/2)){
	  cout << counter*2 <<endl;
	  return 0;
	}
      }else{
	tmp--;
      }
    }else{
      tmp++;
    }
  }
  if(tmp!=counter)
    cout << "ERROR" << endl;

  cout << counter*2 <<endl;
  
  return 0;
}
  


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define all(v) (v).begin(),(v).end()
#define chmax(a, b) a = max((a),(b))
#define chmin(a, b) a = min((a),(b))
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;



int main(){
    int n;
    cin>>n;
    vll table(n);
    rep(i,n)cin>>table[i];

    ll sum=0;
    rep(i,n){
        sum=sum^table[i];
    }
    if(sum==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

#define rep(i, b, e) for(int (i) = (b); (i) < (e); (i)++)

int main() {

  int A, B, T;
  cin >> A >> B >> T;

  int ans = (int)((float)T+0.5)/A * B;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <string> 
#include <vector> 
using namespace std;

int main(){
	int t[100];
	cin >> t[1] >> t[2] >> t[3];
	if(t[1] == 1 and t[2] == 1){
		cout << "Open" << endl;
	}else if(t[3] == 1){
		cout << "Open" << endl;
	}else{
		cout << "Close" << endl;
	}
}

	

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{

    public static void Main()
    {
        int[] box = SpIntRead(' ');
        int N = box[0];
        int lim_T = box[1];
        int c = int.MaxValue;
        string ans = "";
        for (int i = 0; i < N; i++) {
            box = SpIntRead(' ');
            if (lim_T >= box[1]) {
                if (c > box[0]) {
                    c = box[0];
                    ans = c.ToString();
                }
            }
        }
        if (ans == "") Console.WriteLine("TLE");
        else Console.WriteLine(ans);
    }

}


public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static long LCM(long a, long b)
    {
        long c = a * b;
        if (a < b) Swap(ref a, ref b);
        long d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int intRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
    public static int[] SpIntRead(char c)
    {
        return Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
    }
    public static string ToConvertBit(int N, int e)
    {
        string ret = "";
        int r = 0;
        while (N != 0)
        {
            r = N % e;
            ret += r.ToString();
            N -= r;
            N /= e;
        }
        ret = strReverce(ret);
        return ret;
    }

}


Measured memory_bytes: 13268
#include <stdio.h>

int main (int argc, char *argv[])
{
	int d;
	
	scanf("%d", &d);
	if ( d == 22 ) printf("Christmas Eve Eve Eve"); else
	if ( d == 23 ) printf("Christmas Eve Eve"); else 
	if ( d == 24 ) printf("Christmas Eve"); else
	if ( d == 25 ) printf("Christmas"); 
	
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<map>

int main() {
	int n,count=0;
	std::cin >> n;

	std::multimap<int, int> mp;

	for (int i = 0; i < n; i++) {
		int a, b;
		std::cin >> a >> b;
		mp.insert(std::pair<int, int>(b,a));
	}

	for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
		count += itr->second;

		if (count > itr->first) {
			std::cout <<"No" << std::endl;
			return 0;
		}
	}

	std::cout << "Yes" << std::endl;
	return 0;
}

Measured memory_bytes: 9600
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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; }

int N;

int main(){
    cin>>N;
    out(N/3);
}


Measured memory_bytes: 256
unittest
{
	assert( [ "atcoderregularcontest" ].parse.expand.solve == "b" );
	assert( [ "abcdefghijklmnopqrstuvwxyz" ].parse.expand.solve == "None" );
	assert( [ "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg" ].parse.expand.solve == "d" );

	assert( [ "acb" ].parse.expand.solve == "d" );		// 追加ケース
	assert( [ "abcdefghijklmnopqrstuvwxy" ].parse.expand.solve == "z" );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.strip.to!( dchar[] );
	return tuple( s );
}

auto solve( dchar[] s )
{
	auto t = s.sort().uniq;
	for( dchar c = 'a'; c <= 'z'; c++ )
	{
		if( t.empty || t.front != c ) return c.to!( string );
		t.popFront;
	}
	return "None";
}


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

typedef long long ll;

ll gcd( ll x, ll y );
ll lcm( ll x, ll y );

int main()
{
    int d;
    string str;

    scanf("%d", &d );

    if ( d == 25 ) str = "Christmas";
    if ( d == 24 ) str = "Christmas Eve";
    if ( d == 23 ) str = "Christmas Eve Eve";
    if ( d == 22 ) str = "Christmas Eve Eve Eve";

    cout << str << endl;

    return 0;
}

ll gcd( ll x, ll y )
{
    if ( y == 0 ) return x;
    return gcd( y, x % y );
}

ll lcm( ll x, ll y )
{
    return x / gcd( x, y ) * y;
}



Measured memory_bytes: 256
s = list(input())
if len(s) < 2:
    print("D")
    exit()
for i in range(len(s)):
    if s[i] =="?":
        if i == 0:
            if s[1]=="D" or s[1]=="?":
                s[i] ="D"
            else:
                s[i] ="D"
        else:
            if s[i-1] =="P":
                s[i]= "D"
            else:
                if i == len(s)-1:
                    s[i] ="D"
                else:
                    if s[i+1] =="?" or "D":
                        s[i]="D"
                    else:
                        s[i]= "D"
print(''.join(s))
            

Measured memory_bytes: 10856
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define N 200
using namespace std;

int m,n,ans,dp[2][N][N][N];
char mm[N][N];
bool now,cur;

inline void Max(int &u,int v){if(v>u) u=v;}
int main()
{
    int i,j,p,q,l,r,mid;
    cin>>m>>n;
    for(i=1;i<=m;i++) scanf("%s",mm[i]+1);
    now=1;
    for(q=1;q<=m;q++)
    {
	for(p=q;p>=1;p--)
	{
	    for(i=n;i>=1;i--)
	    {
		if(p==q)
		{
		    if(i==n) dp[now][p][q][i]=n+1;
		    if(mm[p][i]==mm[p][i+1]) dp[now][p][q][i]=dp[now][p][q][i+1];
		    else dp[now][p][q][i]=i+1;
		}
		else
		{
		    if(mm[q-1][i]==mm[q][i]) dp[now][p][q][i]=min(dp[now][p][q-1][i],dp[now][q][q][i]);
		    else dp[now][p][q][i]=i;
		}
	    }
	}
    }
    for(ans=0;;ans++)
    {
	if(dp[now][1][m][1]==n+1)
	{
	    cout<<ans;
	    return 0;
	}
	swap(now,cur);
	for(p=1;p<=m;p++)
	{
	    for(q=p;q<=m;q++)
	    {
		for(i=1;i<=n;i++)
		{
		    if(dp[cur][p][q][i]==n+1) dp[now][p][q][i]=n+1;
		    else dp[now][p][q][i]=dp[cur][p][q][dp[cur][p][q][i]];
		    for(l=p,r=q;l<r;)
		    {
			mid=((l+r)>>1);
			Max(dp[now][p][q][i],min(dp[cur][p][mid][i],dp[cur][mid+1][q][i]));
			if(dp[cur][p][mid][i]>dp[cur][mid+1][q][i]) l=mid+1;
			else r=mid;
		    }
		}
	    }
	}
    }
}


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

typedef long long ll;

struct C{
    ll k, l;
};

vector<C> a, b;

int main()
{
    int tt, T;
    scanf("%d", &T);
    for(tt=1; tt<=T; ++tt){
        int n;
        scanf("%d", &n);
        a.clear(); b.clear();
        ll ans = 0;
        for(int i=0; i<n; ++i){
            ll x, y, z;
            scanf("%lld%lld%lld", &x, &y, &z);
            if(x==n || y==z){ ans += y; continue; }
            ll t = min(y,z);
            ans += t; y -= t; z -= t;
            if(z==0) a.push_back({x,y});
            else b.push_back({n-x,z});
        }
        sort(a.begin(), a.end(), [&](C &a, C &b)->bool{return a.k<b.k;});
        sort(b.begin(), b.end(), [&](C &a, C &b)->bool{return a.k<b.k;});
        priority_queue<ll,vector<ll>,greater<ll>> q;
        for(auto c : a){
            if(q.size() >= c.k){
                if(q.top() >= c.l) continue;
                else q.pop();
            }
            q.push(c.l);
        }
        while(!q.empty()){ ans += q.top(); q.pop(); }
        for(auto c : b){
            if(q.size() >= c.k){
                if(q.top() >= c.l) continue;
                else q.pop();
            }
            q.push(c.l);
        }
        while(!q.empty()){ ans += q.top(); q.pop(); }
        printf("%lld\n", ans);
    }
}

Measured memory_bytes: 8244
#include"bits/stdc++.h"
using namespace std;
#define MOD 1000000007
long long int ppow(long long int i, long long int j) {
	long long int res = 1LL;
	while (j) {
		if ((j & 1LL)) {
			res *= i;
			if (res >= MOD) {
				res %= MOD;
			}
		}
		j >>= 1;
		i *= i;
		if (i >= MOD) {
			i %= MOD;
		}
	}
	return res;
}
long long int gcd(long long int a, long long int b) {
	if (a > b) {
		swap(a, b);
	}
	while (a) {
		swap(a, b);
		a %= b;
	}
	return b;
}
long long int lcm(long long int a, long long int b) {
	return a / gcd(a, b)*b;
}
int n;
int m;
#define MAX 100002
vector<int> v[MAX];
bool f[MAX];

queue<int> q;
int bc[MAX];
int mx[MAX];
vector<pair<int, int> > ed;
int ans[MAX];
int main() {
	cin >> n>>m;
	for (int i = 1; i < n+m; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		b--;
		ed.push_back(make_pair(a, b));
		v[a].push_back(b);
		f[b] = true;
		bc[b]++;
	}
	for (int i = 0; i < n; i++) {
		if (f[i] == false) {
			q.push(i);
			while (!q.empty()) {
				int b = q.front();
				q.pop();
				for (int go : v[b]) {
					mx[go] = max(mx[go], mx[b] + 1);
					bc[go]--;
					if (bc[go] == 0) {
						q.push(go);
					}
				}
			}
			for (int i = 0; i < ed.size(); i++) {
				if (mx[ed[i].first] + 1 == mx[ed[i].second]) {
					ans[ed[i].second] = ed[i].first + 1;
				}
			}
			ans[i] = 0;
			for (int i = 0; i < n; i++) {
				printf("%d\n", ans[i]);
			}
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 8308
#include<iostream>
using namespace std;
int main()
{
    long long n[205],m;
    int t,i,flag;
    while(cin>>t)
    {
        flag=0;m=1000000000;
        for(i = 1; i<=t; i++)
        {
            cin>>n[i];
            if(n[i]%2==1) flag=1;
        }
        if(!flag)
        {
            long long sum,res=1000000000;
            for(i = 1;i<=t;i++)
           {
               sum=0;
                while(n[i]&&n[i]%2==0)
            {
                n[i]/=2;
                sum++;
            }
           // cout<<sum<<endl;
            res=min(sum,res);
           }
            cout<<res<<endl;
        }
        else
            cout<<'0'<<endl;
    }
}


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


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a + b > c + d){
    cout << "Left" << endl;
  }
  if (a + b < c + d){
    cout << "Right" << endl;
  }
    if (a + b == c + d){
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int ret;
  if(a*b>c*d){
    ret=a*b;
  }else{
    ret=c*d;
  }
  cout<<ret;
  return 0;
}

Measured memory_bytes: 256
N,M,L = map(int,input().split())

A = [list(map(int,input().split())) for i in range(N)] #N*M配列の取得
B = [list(map(int,input().split())) for i in range(M)] #M*L配列の取得
ANS = [[0]*L for i in range(N)] #N*L


for x in range(N):
    for y in range(L):
        for z in range(M):
            ANS[x][y] += B[z][y]*A[x][z]

for row in range(N):
    print("%d"%ANS[row][0],end = "")
    for col in range(1,L):
        print(" %d"%(ANS[row][col]),end = "")
    print()



Measured memory_bytes: 7052
#include <stdio.h>

int era_num;

char *era(int y, int m, int d)
{
	if (y <= 1868 && m <= 9 && d <= 7){
		era_num = -1;
		return "pre-meiji";
	}
	else if (y <= 1912){
		if (y < 1912 || m < 7 || d <= 29){
			era_num = 1867;
			return "meiji";
		}
		else {
			era_num = 1911;
			return "taisho";
		}
	}
	else if (y <= 1926){
		if (y < 1926 || m < 12 || d <= 24){
			era_num = 1911;
			return "taisho";
		}
		else {
			era_num = 1925;
			return "showa";
		}
	}
	else if (y <= 1989){
		if (y < 1989 || (m == 1 && d <= 7)){
			era_num = 1925;
			return "showa";
		}
		else {
			era_num = 1988;
			return "heisei";
		}
	}
	else {
		era_num = 1988;
		return "heisei";
	}
}

int main(void)
{
	int y, m, d;
	//const char *era[] = {"meiji", "taisho", "showa", "heisei"};
	//const int minus[] = {1867, 1911, 1925, 1988};
	
	while (scanf("%d %d %d", &y, &m, &d) != EOF){
		char *str = era(y, m, d);
		printf("%s", str);
		if (era_num != -1){
			printf(" %d %d %d", y - era_num, m, d);
		}
		puts("");
	}
	
	return 0;
}

Measured memory_bytes: 608
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N;
	static double P, DP[3010][3010] = {}, count = 0.0;
	DP[0][0] = 1.0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> P;
		for (int j = 0; j <= i; j++) {
			DP[i + 1][j] += DP[i][j] * P;
			DP[i + 1][j + 1] += DP[i][j] * (1 - P);
		}
	}
	for (int i = 0; i <= N / 2; i++) {
		count += DP[N][i];
	}
	printf("%.10f", count);
}

Measured memory_bytes: 69120