akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;
int flag = 0;
int flag2 = 0;

void Transplant(Node u, Node v){
  if(u->parent == NIL){
    root = v;
  }else if(u == u->parent->left){
    u->parent->left = v;
  }else{
    u->parent->right = v;
  }
  if(v != NIL){
    v->parent = u->parent;
  }
}

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){

  if(u == NIL || k == u->key){
    return u;
  }
  if(k < u->key){
    return treeSearch(u->left, k);
  }else {
    return treeSearch(u->right, k);
  }

}

Node treeSuccessor(Node x){

  Node y;
  if(x->right != NIL){
    return treeMinimum(x->right);
  }
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left == NIL){
    Transplant(z, z->right);
  }else if(z->right == NIL){
    Transplant(z, z->left);
  }else {
    y = treeMinimum(z->right);
    if(y->parent != z){
      Transplant(y, y->right);
      y->right = z->right;
      y->right->parent = y;
    }
    Transplant(z, y);
    y->left = z->left;
    y->left->parent = y;
  }

}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }else {
      x = x->right;
    }
  }
  z->parent = y;
  
  if(y == NIL){
    root = z;
  }else if(z->key < y->key){
    y->left = z;
  }else {
    y->right = z;
  }
}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
  }
  
}
void preorder(Node u){
  if(u != NIL){
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
  }
  

}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20456
def main():
    N = int(input())
    S = list(map(int, input().split()))
    S = sorted(S, reverse=True)
    a = []
    b = []

    flg = 0
    for s in S:
        if flg == 0:
            a.append(s)
            flg = 1
        else:
            b.append(s)
            flg = 0

    print (sum(a) - sum(b))

if __name__ == "__main__":
    # global stime
    # stime = time.clock()
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mmax = 1e5*2;
ll N, K;
ll A[mmax];
const ll MAX = ll(1e18) + 1;

bool clear(ll l, ll r) {
    ll mid = (l+r) / 2;
    ll t = 0;
    for (ll i = 0; i < N; ++i) {
        if (A[i] < 0) {
            ll lp = -1, rp = N;
            while (lp+1 < rp) {
                ll c = (lp + rp) / 2;
                if (A[c] * A[i] < mid) {
                    rp = c;
                } else {
                    lp = c;
                }
            }
            t += N - rp;
        } else {
            ll lp = -1, rp = N;
            while (lp+1 < rp) {
                ll c = (lp + rp) / 2;
                if (A[c] * A[i] < mid) {
                    lp = c;
                } else {
                    rp = c;
                }
            }
            t += rp;
        }
        if (A[i]*A[i] < mid) t--;
    }
    t /= 2;
    return t < K;
}

void solve() {
    cin >> N >> K;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    sort(A, A + N);
    ll l = -MAX, r = MAX;
    while (l + 1 < r) {
        ll mid = (l+r) / 2;
        if (clear(l, r)) {
            l = mid;
        } else {
            r = mid;
        }
    }
    cout << l << endl;
}

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


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

int main(){
  int N;
  cin >> N;
  N += 1;

  int64_t ans = 0;
  int count = 0;

/* 全部違う */
  for(int i=1; i<N; i++){
    for(int j=i+1; j<N; j++){
      for(int k=j+1; k<N; k++){
        bool check = true;
        for(int l=i; l>=1; l--){
          if(i%l==0&&j%l==0 && k%l==0 && check) {
            ans+=l*6;
            check = false;

        }
      }
    }
  }
}

/* 2つ同じ、1つ違う */
for(int i=1; i<N; i++){
  for(int j=i+1; j<N; j++){
    bool check = true;
      for(int l=i; l>=1; l--){
        if(i%l==0 && j%l==0 && check) {
          ans+=l*6;
          check = false;
          
      }
    }
  }
}

/* 全部同じ */
for(int i=1; i<N; i++){
  ans+=i; 
}

  cout << ans;

}

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

int main() {

 string str;
 cin>>str;
 int counta=0,countb=0;
 for(int i=0;i<str.size();i++){
     if(str[i]=='A')counta++;
     else countb++;

 }

if(counta==0 || countb==0 || counta==3 || counta==3){cout<<"No";}
else {cout<<"Yes";}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAXN 10000010
string s;
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	long long i,yaz=0,dp=0;
	cin>>s;
	for(i=0;i<s.size();i++)
	{
		if(s[i]=='A')
			dp++;
		else if(s[i]=='B' && s[i+1]=='C')
		{
			yaz+=dp;
			i++;
		}
		else dp=0;
	}
	cout<<yaz<<endl;
	return 0;
}

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

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

    double sum=0;
    for(int i=1;i<=n;i++){
        int tmp=i;
        int r=0;//何回表で勝ちか
        while(1){
            if(tmp>=k)break;
            tmp*=2;
            r++;
        }
        sum+=pow(0.5,r);
    }

    cout<<fixed<<setprecision(15)<<sum/n<<endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
*P, = map(int, input().split())
*C, = map(int, input().split())
ans = -float("inf")

for pos in range(N):
    used = [-1] * N
    cost = [0] * (N+1)

    for k in range(N+1):
        if k:
            cost[k] = cost[k-1] + C[pos]
        if used[pos] >= 0:
            loop_size = k-used[pos]
            break
        used[pos] = k
        pos = P[pos] - 1
    if cost[loop_size] <= 0:
        ans = max(ans, max(cost[1:K+1]))
    else:
        a, b = divmod(K, loop_size)
        v1 = cost[loop_size] * (a-1) + max(cost[:K+1])
        v2 = cost[loop_size] * a + max(cost[:b+1])
        ans = max(ans, max(v1, v2) if a else v2)

print(ans)


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

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s1, s2;
cin >> s1 >> s2;

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

if (s1 == s2) cout << "YES\n";
else cout << "NO\n";

return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<map>
#include<string>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<typeinfo>
#include<queue>
#include<iomanip>
using namespace std;
int main() {
	static const double pi = 3.141592653589793;
	int A,B,H,M;
	double dist;
	cin >> A >> B >> H >> M;
	double H_rad,M_rad;
	M_rad= (double)M * pi / (double)30;
	H_rad = ((double)5*(double)H + ((double)M / (double)12)) * pi / (double)30;
	dist = (A * A + B * B - 2 * A * B * cos(abs(M_rad - H_rad)));
	cout << std::fixed << std::setprecision(15) <<sqrt(dist);
}


Measured memory_bytes: 4232
// think twice code once
// Start:
// End  :
#include <bits/stdc++.h>
using namespace std;

#define rep(i, x, y) for(int i = (x), _ = (y); i <= _; ++ i)
#define per(i, x, y) for(int i = (x), _ = (y); i >= _; -- i)
#define dprintf(...) fprintf(stderr, __VA_ARGS__)
#define disp(x) cout << #x << " = " << x << "; "

typedef long long LL;

template <class T> bool chkmin(T& a, T b) { return a > b ? a = b, true : false; }
template <class T> bool chkmax(T& a, T b) { return a < b ? a = b, true : false; }

template <class T> void read(T& a) {
	char c = getchar(); T f = 1; a = 0;
	for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) a = a * 10 + c - '0';
	a *= f;
}

template <class T> void write(T a) {
	static int stk[60]; 
	int tp = 0;
	if(a < 0) putchar('-'), a = -a;
	do {
		stk[++ tp] = a % 10;
		a /= 10;
	}while(a);
	
	while(tp) putchar(stk[tp--] + '0');
}

const int maxN = 1e5 + 5, mo = 1e9 + 7;

int N;
int cnt[maxN];

int pow_mod(int x, int t) {
	int ret = 1;
	while(t) {
		if(t & 1) ret = (LL) ret * x % mo;
		x = (LL) x * x % mo; t >>= 1;
	}
	return ret;
}

int main() {
#ifdef Leeson
	freopen("tmp.in", "r", stdin);
	freopen("tmp.out", "w", stdout);
#endif

	read(N);
	rep(i, 1, N) {
		int a;
		read(a);
		cnt[a] ++;
	}

	if(cnt[0] == 2) {
		puts("0");
		return 0;
	}
	rep(i, 1, N) {
		if(cnt[i] != 0 && cnt[i] != 2) {
			puts("0");
			return 0;
		}
	}

	cout << pow_mod(2, N / 2) << endl;

	return 0;
}


Measured memory_bytes: 640
input_str = STDIN.gets
n = input_str.to_i

$result = []
$result[0] = 1
$result[1] = 1
# for num in 2..n do
#   result[num] = result[num - 1] + result[num - 2]
# end
for i in 0..n do
  $result[i] = 0
end

$result[0] = 1
$result[1] = 1

def fib num
  if $result[num] != 0
    return $result[num]
  end
  a = fib num - 1
  b = fib num - 2
  $result[num] = a + b

  return $result[num]
end

fib n
puts $result[n]



Measured memory_bytes: 6872
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int R = sc.nextInt();
    
        if(R<1200){
            System.out.println("ABC");
        }else if(1200<=R && R<2800){
            System.out.println("ARC");
        } else {
          System.out.println("AGC");
        }
    }
}


Measured memory_bytes: 35756
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			long k = sc.nextLong();

			Map<Integer, Integer> map = new TreeMap<Integer, Integer>();

			for (int i = 0; i < n; i++) {
				int a = sc.nextInt();
				int b = sc.nextInt();

				if (map.get(a) == null) {
					map.put(a, b);
				} else {
					map.put(a, map.get(a) + b);
				}
			}

			TreeSet<Integer> set = new TreeSet<Integer>(map.keySet());
			for (int i : map.keySet()) {
				k -= map.get(i);
				if (k <= 0) {
					System.out.println(i);
					return;
				}
			}
			System.out.println(set.last());
		}
	}
}

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

using namespace std;

#define ll long long int
#define MOD 1000000007

int main()
{
     ll i,j,k,n,m,flag=0;
     cin>>n;
     ll a[n];
     for(i=0;i<n;i++){
         cin>>a[i];
         if(a[i]%2==0&&((a[i]%3==0)||(a[i]%5==0))){
             continue;
         }
         else if(a[i]%2==0){
             flag=1;
         }
     }
     if(flag==1){
         cout<<"DENIED"<<endl;
     }
     else{
         cout<<"APPROVED";
     }
     
     
     
     
    // cout<<"YES"<<endl;
    //cout<<"NO"<<endl;
    
    
    
      return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
bre = 0
while True:
	for s in range(n):
		if a[s] % 2 != 0:
			bre += 1
		a[s] = a[s] // 2
	if bre != 0:
		break
	ans += 1
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define fd(i,a,b)for(int i=b,_e=a;i>=_e;--i)
#define ll long long
using namespace std;
const int N=505;
int n,mo,ans,f[N][N],s;
struct nod{
	int i,l,r;
}a[N];
bool cmp(nod x,nod y){
	if(x.i<n){
		if(y.i<n)return x.l<y.l||x.l==y.l&&x.r<y.r;
		return x.l<=y.r;
	}
	if(y.i<n)return x.r<y.l;
	return x.r<y.r;
}
int sqrt1(int n){
	int a=sqrt(n);
	for(;a*a<=n;)++a;
	for(;a*a>n;)--a;
	return a;
}
int sqrt2(int n){
	int a=sqrt(n);
	for(;a*a<n;)++a;
	for(;a*a>=n;)--a;
	return a;
}
int main(){
	cin>>n>>mo;
	fo(i,0,n-1)a[i]=(nod){i,sqrt2(n*n-i*i),sqrt1(n*n*4-i*i)};
	fo(i,n,n*2-1)a[i]=(nod){i,0,sqrt1(n*n*4-i*i)};
	a[0].r=n*2-1;
	sort(a,a+n*2,cmp);
	fo(k,0,n){
		memset(f,0,sizeof f);
		f[0][0]=1;
		s=0;
		fo(i,0,n*2-1)
			if(a[i].i>=n){
				fo(j,0,min(s,k))
					if(a[i].r+1>=(i-s+j))
						f[i+1][j]=(ll)f[i][j]*(a[i].r+1-(i-s+j))%mo;
			}else{
				fo(j,0,min(s,k)){
					if(a[i].l+1>=(i-s+j))
						f[i+1][j+1]=(ll)f[i][j]*(a[i].l+1-(i-s+j))%mo;
					if(a[i].r+1>=(n+s+k-j))
						f[i+1][j]=((ll)f[i][j]*(a[i].r+1-(n+s+k-j))+f[i+1][j])%mo;
				}
				++s;
			}
		ans=(ans+f[n*2][k]*(k&1?-1:1))%mo;
	}
	cout<<(ans+mo)%mo;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> b(n);
    vector<int> ans;
    rep(i,n) cin >> b[i];
    bool ok=true;
    rep(i,n){
        if(b[i]>i+1) ok=false;
    }
    if(ok){
        int cnt=n-1;
        while(1){
            for(int i=cnt;0<=i;--i){
                if(b[i]==i+1){
                    ans.push_back(b[i]);
                    b.erase(b.begin()+i);
                    --cnt;
                    break;
                }
            }
            if(b.empty()) break;
        }
        reverse(ans.begin(),ans.end());
        rep(i,n){
            cout << ans[i] << "\n";
        }
        return 0;
    }else{
        cout << -1 << "\n";
        return 0;
    }
}   

Measured memory_bytes: 3644
#include <cstdio>
#include <iostream>
#include <string.h>
#include <cstdlib>


#define STACK_MAX 300
using namespace std;
struct Stack {
    int s[STACK_MAX] = {};
    int top = 0;
    void init() {
        top = 0;
    }
    bool isEmpty() {
        return (top == 0);
    }
    bool isFull() {
        return (top >= STACK_MAX-1);
    }
    void push(int x) {
        if(isFull()) {
            cerr << "stack over flow" << endl;
            exit(-1);
        }
        top++;
        s[top] = x;
    }
    int pop() {
        if(isEmpty()) {
            cerr << "stack under flow" << endl;
            exit(-1);
        }
        top--;
        return s[top+1];
    }
    
};
int add(int a, int b) {
    return a+b;
}
int sub(int a, int b) {
    return a-b;
}
int mul(int a,int b) {
    return a*b;
}
int main() {
    char str[100];
    Stack s;
    s.init();
    while(scanf("%s", str) != EOF) {
        if(strcmp("+", str) == 0) {
            int a = s.pop();
            int b = s.pop();
            s.push(add(a, b));
        }else if(strcmp("-", str) == 0) {
            int b = s.pop();
            int a = s.pop();
            s.push(sub(a, b));
        }else if(strcmp("*", str) == 0) {
            int a = s.pop();
            int b = s.pop();
            s.push(mul(a, b));
        }else {
            int x = atoi(str);
            s.push(x);
        }
    }
    printf("%d\n", s.pop());
}


Measured memory_bytes: 3228
// Author: Jashan Bansal
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second	
#define mp make_pair
#define int long long
#define ll long long
#define pii pair<int,int>
#define all(arr) arr.begin(), arr.end()
#define sz(arr) ((long long)arr.size())
// const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
#define log1(x) cout << x << '\n'
#define log2(x,y) cout << x << " " << y <<'\n'
#define log3(x,y,z) cout << x <<" " << y <<" " << z << '\n'
#define logarr(arr,n) for(int __=0; __ < n; __++)	cout << arr[__] << " "; cout << '\n'

int powm(int a, int b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}


void solve() {
	int o,t,m,k; cin >> o >> t >> m >> k;

	int ans = 0;

	if(k > o){
		k-= o;
		ans += o;
	}
	else{
		cout << ans+k;
		return;
	}

	if(k > t){
		k-= t;
	}
	else{
		cout << ans;
		return;
	}

	cout << ans - k;

}
 
signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t=1;
	// cin>>t;
	while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 3584
object Main {
    def main(args: Array[String]) = {
        val sc = new java.util.Scanner(System.in)
        val s = sc.next
        println(calc(s))
    }
    def calc(s: String) : String = {
        val alphabet = "abcdefghijklmnopqrstuvwxyz"
        val ret = alphabet.filter(x => !s.contains(x))
        if (ret.length > 0) ret(0).toString else "None"
    }
}

Measured memory_bytes: 29764
S = list(input())
T = list(input())

answer = 'Yes'
for s in sorted(map(chr,range(97,123))):
    if S.count(s) >= 2:
        l1 = [i for i, x in enumerate(S) if x == s]
        for x in l1:
            if T[x] != T[l1[0]]:
                answer = 'No'
    if T.count(s) >= 2:
        l2 = [i for i, x in enumerate(T) if x == s]
        for x in l2:
            if S[x] != S[l2[0]]:
                answer = 'No'
print(answer)

Measured memory_bytes: 18424
ABCD = input()
for i in ('-1','+1'):
    for j in ('-1','+1'):
        for k in ('-1','+1'):
            if int(ABCD[0]) + (int(i)) * int(ABCD[1]) + (int(j)) * int(ABCD[2]) + + (int(k)) * int(ABCD[3]) == 7:
                print(ABCD[0]+i[0]+ABCD[1]+j[0]+ABCD[2]+k[0]+ABCD[3]+'=7')
                exit()


Measured memory_bytes: 62008
void main() {
  problem();
}

void problem() {
  auto a = scan!long;

  long solve() {
    return a + a*a + a*a*a;
  }

  solve().writeln;
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

// -----------------------------------------------


Measured memory_bytes: 2668
from collections import defaultdict

n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
dic = defaultdict(lambda: 0)
ans = "YES"
for i in d:
  dic[i] += 1
for i in t:
  dic[i] -= 1
  if dic[i] == -1:
    ans = "NO"
    break
print(ans)

Measured memory_bytes: 41692
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	
	
	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		sc.close();

		int s = 0;
		int n = N;
		while(n != 0) {
			s += n%10;
			n /= 10; 
		}
		
		if(N%s == 0) {
			out.println("Yes");
		}else {
			out.println("No");
		}
		
	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


Measured memory_bytes: 23252
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int N,M,P,X[101];

int main(){
	while(cin>>N>>M>>P&&N){
		int sum=0;
		rep(i,N){cin>>X[i+1];sum+=X[i+1];}
		if(!X[M]){cout<<"0"<<endl;continue;}
		cout<<sum*(100-P)/X[M]<<endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// 端点を間違えないように気をつけること!
#define FOR(i, m, n) for (ll i = (ll)(m); i <= (ll)(n); i++)
#define RFOR(i, m, n) for (ll i = (ll)(m); i >= (ll)(n); i--)
// 割り算をするときは自作関数syou,amariを使うこと!

// FRAC

// gcd(a,b)=aとbの最大公約数.正の値を返す.両方0のときは0.計算量O(loga or logb).
// std::absを使う.
ll gcd(ll a, ll b)
{
    a = abs(a);
    b = abs(b);
    if (a == 0)
    {
        return b;
    }
    else
    {
        return gcd(b % a, a);
    }
}

// x:分母,y:分子
struct frac
{
    ll x;
    ll y;
};

// tasufrac(p,q)=p+q.足した後に約分する.
// gcdを使う.
frac tasufrac(frac p, frac q)
{
    ll x = p.x * q.x;
    ll y = p.y * q.x + p.x * q.y;
    ll g = gcd(x, y);
    return {x / g, y / g};
}

// hikufrac(p,q)=p-q.引いた後に約分する.
// gcdを使う.
frac hikufrac(frac p, frac q)
{
    ll x = p.x * q.x;
    ll y = p.y * q.x - p.x * q.y;
    ll g = gcd(x, y);
    return {x / g, y / g};
}

// kakerufrac(p,q)=pq.掛けた後に約分する.
// gcdを使う.
frac kakerufrac(frac p, frac q)
{
    ll x = p.x * q.x;
    ll y = p.y * q.y;
    ll g = gcd(x, y);
    return {x / g, y / g};
}

// warufrac(p,q)=p/q.割った後に約分する.
// gcdを使う.
frac warufrac(frac p, frac q)
{
    ll x = p.x * q.y;
    ll y = p.y * q.x;
    ll g = gcd(x, y);
    return {x / g, y / g};
}

// FRAC終わり

int main()
{
    ll N;
    cin >> N;
    frac f;
    bool found = false;
    FOR(i, 1, 3500)
    {
        FOR(j, i, 3500)
        {
            f = hikufrac({N, 4}, tasufrac({i, 1}, {j, 1}));
            if (f.y == 1 && f.x > 0)
            {
                found = true;
                cout << i << " " << j << " " << f.x << endl;
                break;
            }
        }
        if (found)
            break;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define VAR(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}
// }}} End Header

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

    VAR(i64, x, y);
    if (abs(x - y) <= 1) {
        print("Brown");
    } else {
        print("Alice");
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>

using namespace std;


int main(){

    int n,m;
    cin >> n >> m;

    vector<vector<int>> vec(m);

    for(int i = 0; i < m; i++){
        int k; 
        cin >> k;
        vec[i].resize(k);
        for(int j = 0; j < k; j++){
            cin >> vec[i][j];
            vec[i][j]--;
        }
    }

    vector<int> p(m);
    for(int i = 0; i < m; i++) cin >> p[i];


    int ans = 0;
    for(int mask = 0; mask < (1 << n); mask++){
        bool ok = true;
        for(int i = 0; i < m; i++){
            int cnt = 0;
            for(int id : vec[i]){
                if((mask >> id) & 1){
                    cnt++;
                }
            }
            cnt %= 2;
            if(cnt != p[i]){
                ok = false;
            }
        }
        if(ok){
            ans++;
        }
    }

    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 888
N,M = list(map(int,input().split()))
from collections import defaultdict
q = defaultdict(set)
for i in range(M):
  s,c = list(map(int,input().split()))
  q[s] |= {c}
  
for i in range(10**N):
  if len(str(i)) != N:
    continue
  else:
    for key,value in q.items():
      v = list(value)[0]
      if len(value) > 1 :
        break
      elif str(i)[key-1] != str(v):
        break
    else:
      print(i)
      break
else:
  print(-1)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define int long long
const int MOD=1e9+7;
using pii=std::pair<int,int>;
using namespace std;

int a, b, n;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> a >> b >> n;
    int x = min(b - 1, n);
    int ans = (a * x) / b - a * (x / b);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <algorithm>
using namespace std;

const int M=1e5+5;
struct Node
{
	int id,a;
	void read(int i)
	{
		id=i;
		scanf("%d",&a);
	}
	bool operator<(const Node &B) const
	{
		return a<B.a;
	}
}node[M];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		node[i].read(i);
	sort(node+1,node+n+1);
	for(int i=1;i<=n;i++)
		printf("%d%c",node[i].id,i==n?'\n':' ');
}

Measured memory_bytes: 1536
H,W=map(int,input().split())
a=[0]*H
for i in range(H):
  a[i]=list(map(int,input().split()))
  
move_even = [ (0,1) ,(1,0) ]
move_odd  = [ (0,-1),(1,0) ]
cnt=0
ans_list=[]

for i in range(H):
  if i%2==0:  #偶数列は左から
    for j in range(W):
      for move in move_even:
        p = i+move[0]
        q = j+move[1]
        if 0<=p<=H-1 and 0<=q<=W-1:
          if a[i][j]%2==1:
            a[i][j] += -1
            a[p][q] +=  1
            ans_list.append([i+1,j+1,p+1,q+1])
            cnt+=1
            break                
  else: #奇数列は右から
    for j in range(W-1,-1,-1):
      for move in move_odd:
        p = i+move[0]
        q = j+move[1]
        if 0<=p<=H-1 and 0<=q<=W-1:
          if a[i][j]%2==1:
            a[i][j] += -1
            a[p][q] +=  1
            ans_list.append([i+1,j+1,p+1,q+1])
            cnt +=1
            break         
print(cnt)
for queue in ans_list:
  print(*queue)

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

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

ll gcd(ll a,ll b){
  if(a%b == 0) return b;
  else return gcd(b,a%b);
}

bool sss(vector<int> p,vector<int> q){
  bool flag = true;
  for(int i=0;i<p.size();i++){
    if(p[i] != q[i]){
      flag = false;
    }
  }
  return flag;
}

int main(){
  int n;
  cin >> n;
  vector<int> p,q;
  int temp;
  for(int i=0;i<n;i++){
    cin >> temp;
    p.push_back(temp);
  }
  for(int i=0;i<n;i++){
    cin >> temp;
    q.push_back(temp);
  }
  int ans = 0;
  bool flag = true;
  for(int i=0;i<n;i++){
    if(p[i] == q[i]) continue;
    if(p[i] < q[i]) break;
    else{
      flag = false;
      break;
    }
  }

  if(flag){
    while(true){
      if(sss(p,q)){
        cout << ans << endl;
        return 0;
      }
      else{
        next_permutation(p.begin(),p.end());
        ans++;
      }
    }
  }
  else{
    while(true){
      if(sss(p,q)){
        cout << ans << endl;
        return 0;
      }
      else{
        next_permutation(q.begin(),q.end());
        ans++;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int nax = 1e5 + 1;
vector<vector<int>> g(nax,vector<int>());

vector<int> dp(nax,-1);

int dfs(int v){
    if (dp[v] != -1) return dp[v];
    int res = 0;
    for (auto nv:g[v]){
        res = max(res,dfs(nv) + 1);
    }
    dp[v] = res;
    return res;
}

int main(){
    int n,m;
    cin >> n >> m;
    
    for(int i = 0; i < m; i++) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
    }
    
    int ans = 0;
    for (int v = 0; v < n;v++){
        if (dp[v] == -1){
            dp[v] = dfs(v);
            ans = max(ans,dp[v]);
        }
    }
    
    cout << ans;
    
}

Measured memory_bytes: 8192
if __name__ == '__main__':
    A, B, C, X, Y = map(int, input().split())
    min_cost = 2*max(X, Y)*C
    for c in range(0, 2*pow(10, 5)+2, 2):
        a = X-c//2
        b = Y-c//2
        if a>=0 and b>=0:
            cost = A*a+b*B+C*c
            min_cost = min(cost, min_cost)
    print(min_cost)

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

double f(double K, double i, int n) {
    if(K <= i) {
        return n;
    }
    n++;
    f(K, i * 2, n);
}

int main() {
    double N;
    double K;
    cin >> N >> K;
    double ans;
    for(double i = N; i >= 1; i--) {
        double tmp;
        double cl = f(K, i, 0);
        tmp = (1.0 / N) * pow(1.0 / 2.0, cl);
        ans += tmp;
    }

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


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) begin(a),end(a)
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
#define MAX (int)1e6 + 5

int N, A, B;
int t[MAX];


signed main() {
	cout << setprecision(20) << fixed;
	cin >> N >> A >> B;
	int cnt = 0;
	rep(i, N) {
		cin >> t[i];
		if (t[i] < A) cnt++;
		else if (t[i] >= B) cnt++;
	}
	cout << cnt << endl;
}


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

long n, a, b, c, d, e;
long long minutes = 4;

int main() {
    std::cin >> n >> a >> b >> c >> d >> e;
    long long x = std::min({a, b, c, d, e});
    minutes += std::ceil(((double)n) / x);
    std::cout << minutes << std::endl;

}


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

int main(){
  int n; 
  cin >> n;
  int ans = 0;
  for(int i = 1; i <= n; i++){
    if( 1 <= i && i <= 9 ) ans++;
    else if(100 <= i && i <= 999) ans++;
    else if(10000 <= i && i <= 99999) ans++;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 100010;

int n;LL c;
LL d[maxn],v[maxn];
LL mmax[maxn],maxx[maxn];
LL sum1[maxn],sum2[maxn];

int main() {
    scanf("%d%lld",&n,&c);
    for(int i=1;i<=n;i++) scanf("%lld%lld",&d[i],&v[i]);
    for(int i=n;i>=1;i--) sum2[i] = sum2[i+1]+v[i];
    for(int i=1;i<=n;i++) sum1[i] = sum1[i-1]+v[i];

    LL ans = 0;
    for(int i=n;i>=1;i--) {
        mmax[i] = max(mmax[i+1],sum2[i]-(c-d[i]));
        ans = max(ans,mmax[i]);
        //printf("%lld ",mmax[i]);
    }//puts("");

    for(int i=1;i<=n;i++)  {
        maxx[i] = max(maxx[i-1],sum1[i]-d[i]);
        ans = max(ans,maxx[i]);
    }

    for(int i=1;i<=n;i++) {
        ans = max(ans,sum1[i]-2*d[i]+mmax[i+1]);
    }
    for(int i=n;i>=1;i--) {
        ans = max(ans,sum2[i]-2*(c-d[i])+maxx[i-1]);
    }

    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 4992
#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 <cstdlib>
#include <iomanip>
#define rep(i,x) for(ll i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
using graph = vector<vector<ll>>;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}/*フィボナッチテンプレ
ll memo[50];
ll fibo(ll n) {
    if (memo[n] != 0)return memo[n];
    if (n <= 1)return memo[n] = n;
    else return memo[n] = fibo(n - 1) + fibo(n - 2);
}
*/
int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> height(N);
    graph road(N);
    ll a, b;
    rep(i, N)cin >> height[i];
    rep(i, M) {
        cin >> a >> b;
        road[a - 1].push_back(b - 1);
        road[b - 1].push_back(a - 1);
    }
    ll ans = 0;
    rep(i, N) {
        bool ok = true;
        for (auto x : road[i]) {
            if (height[i] <= height[x])ok = false;
        }
        if (ok)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9808
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using tllll=tuple<ll,ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    while(cin>>n>>m, n){
        vector<vector<tllll>> edge(n);
        rep(i,m){
            ll s,t,d,c;
            cin>>s>>t>>d>>c;
            s--; t--;
            edge[s].emplace_back(d,c,s,t);
            edge[t].emplace_back(d,c,t,s);
        }
        vl dist(n,LINF);
        dist[0] = 0;
        priority_queue<tllll, vector<tllll>, greater<tllll>> q;
        for(auto&e:edge[0]){
            q.push(e);
        }
        ll ans=0;
        while(!q.empty()){
            ll d,c,s,t;
            tie(d,c,s,t) = q.top();
            q.pop();
            if(dist[t]!=LINF)continue;
            dist[t]=d;
            ans+=c;
            for(auto e:edge[t]){
                get<0>(e) += d;
                q.push(e);
            }
        }
        puta(ans);
    }
    return 0;
}


Measured memory_bytes: 6720
n,m = map(int, input().split()) 

ans = 1

for i in range(1, int(m ** 0.5)+1):
  if m % i == 0:
    if i >= n:
      ans = max(ans, m // i)
    elif m // i >= n:
      ans = max(ans, i)
      
      
print(ans)

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
	int debt = 100000;
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		debt += (int)(debt*0.05);
		if (debt % 1000 != 0)
			debt = debt/1000*1000+1000;
	}
	printf("%d\n", debt);
}

Measured memory_bytes: 0
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}
char a[8];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    scanf("%s", a);
    printf(a[2] == a[3] && a[4] == a[5] ? "Yes\n" : "No\n");

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void swap(int *i, int *j)
{
	*i += *j;
	*j = *i - *j;
	*i -= *j;
}

int main(void)
{
	int score[100];
	int i, j;
	int a, b, c, d;
	int n;
	int no[100];
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		score[i] = no[i] = 0;
	}
	
	for (i = 0; i < n * (n - 1) / 2; i++){
		scanf("%d %d %d %d", &a, &b, &c, &d);
		
		if (c == d){
			score[a - 1]++;
			score[b - 1]++;
		}
		else if (c < d){
			score[b - 1] += 3;
		}
		else {
			score[a - 1] += 3;
		}
		no[a - 1] = score[a - 1];
		no[b - 1] = score[b - 1];
	}
	
	for (i = 0; i < n; i++){
		for (j = i + 1; j < n; j++){
			if (score[i] < score[j]){
				swap(&score[i], &score[j]);
			}
		}
	}
	/*
	for (i = n - 1; i >= 0; i--){
		if (score[i] == score[i - 1]){
			score[i] = -1;
		}
	}
	*/
	for (i = 0; i < n; i++){
		for (j = 0; j < n; j++){
			if (no[i] == score[j]){
				printf("%d\n", j + 1);
				break;
			}
		}
	}
	
	return (0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    int h[100000][3];
    for(int i=0;i<N;i++)
        for(int j=0;j<3;j++)
            cin >> h[i][j];
    
    // dp[i][d]:i日目にd(A, B, Cのどれか)をした後の幸福度の総和の最大値
    int dp[100000][3];
    // 1日目
    for(int i=0;i<3;i++)
        dp[0][i] = h[0][i];
    // 2~N日目
    for(int i=1;i<N;i++){
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + h[i][0];
        dp[i][1] = max(dp[i-1][2], dp[i-1][0]) + h[i][1];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + h[i][2];
    }

    cout <<  max({ dp[N-1][0], dp[N-1][1], dp[N-1][2] }) << endl;

    return 0;
}


Measured memory_bytes: 2560
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
cnt = 0
for i in range(n):
    a = list(map(int,input().split()))
    t = c
    for j in range(m):
        t+= a[j]*b[j]
    if t>0:
        cnt+=1
print(cnt)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll long long
//#define int long long
#define pb push_back
#define x first
#define ld long double
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) a.begin(),a.end()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector <int> a(n);
    for (auto &i : a) cin >> i;
    sort(all(a));
    ll ans = 0;
    for (int i = 0; i < k; i++) ans += a[i];
    cout << ans << '\n';
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
using mat = vector<vector<ll>>;

inline void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//ll pas[5001][5002];

signed main(){
	IOS();
	ll n;
	cin >> n;
	vector<ll> a(n), b;
	for (int i = 0;i < n;++i) {
		cin >> a[i];
	}
	b = a;
	sort(a.begin(), a.end());
	ll cnt = 0;
	for (int i = 0;i < n;i += 2){
		ll t = lower_bound(a.begin(), a.end(),b[i]) - a.begin();
		if(t % 2)cnt++;
	}
	cout << cnt << endl;
	
}

Measured memory_bytes: 1792
while True:
	try:
		temp = [int(x) for x in raw_input().split()]
		m = max(temp)
		n = min(temp)

		while True:
			if n == 0:
				print m, (temp[0]*temp[1])/m
				break
			else:
				temp2 = n
				n = m % n
				m = temp2

	except:
		break

Measured memory_bytes: 4208
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main(void) {

    int n; cin >> n;
    string s, t; cin >> s >> t;

    int ans;
    for (int i = 0; i <= n; ++i) {
        bool ok = true;
        for (int j = 0; j < n - i; ++j) {
            if (s[i+j] != t[j]) ok = false;
        }
        if (ok) {
            ans = n + i;
            break;
        }
    }
    out(ans);




    return 0;
}









Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;
int main(){

int X,A;

cin >> X >> A;

if(X<A){
  cout << 0 << endl;
}

else{
  cout << 10 << endl;
}

}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
	long long k,a,b,i,j;
	cin>>k;
	cin>>a>>b;
	for (i=a;i<=b;i++)
	{
		if (i%k==0)
		{
			cout<<"OK"<<endl;
			return 0;
		}
	} 
	cout<<"NG"<<endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
// #define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair<int,int>
// #define pii pair< int, pi >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
using namespace std::chrono;

string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
vector<vector<int>> vis;
int h,w,ch,cw,dh,dw;
int X[]={1,0,0,-1};
int Y[]={0,1,-1,0};
bool safe(int x,int y){
  return x>=0 && x<h && y>=0 && y<w;
}
void solve(){
	int h,w,m;
	cin>>h>>w>>m;
	vector<pii> v1(m);
	map<int,int> r,c;
	map<pii,int> mp;
	set<pii,greater<pii>> st;
	map<int,set<int>> mp2;
	rep(i,0,m){
		cin>>v1[i].f>>v1[i].s;
		r[v1[i].f]++;
		c[v1[i].s]++;
		mp2[v1[i].f].insert(v1[i].s);
		mp[{v1[i].f,v1[i].s}]++;
	}
	int mx1=0,mx2=0;
	for(auto i:r){
		mx1=max(i.second,mx1);
	}
	for(auto i:c){
		mx2=max(i.second,mx2);
	}
	vector<int> r1; set<int> c1;
	for(auto i:r){
		if(i.s==mx1) r1.push_back(i.f);
	}
	for(auto i:c){
		if(i.s==mx2) c1.insert(i.f);
	}
	int ans=mx1+mx2-1;
	rep(i,0,r1.size()){
		int cnt=0;
		set<int> st2=mp2[r1[i]];
		for(auto j:st2) if(c1.find(j)!=c1.end()) cnt++;
		if(cnt!=c1.size()){
			cout<<ans+1<<endl;
			return;
		}
	}
	cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 109888
# a = list(map(int, input().split()))　:スペース区切り入力

s = input()
t = input()

x = len(s)
y = len(t)

p = []
q = []

for i in range(x):
    p.append(ord(s[i]))

for j in range(y):
    q.append(ord(t[j]))

p.sort()
q.sort(reverse=True)

if p < q:
    print("Yes")
else:
    print("No")

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

int main(){

	long long int i = 0, x = 0, money = 100;
    cin >> x;
    
    while(1){
    	
        money = money * 1.01;
        i++;
        
        if(money >= x){
        	cout << i;
            break;
        }
    }
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

int main()
{
    fastread();

    ll n,m;

    cin>>n>>m;
    ll a,b;
    cin>>a>>b;


    for(ll i=0;i<m-1;i++)
    {
        ll a1,b1;

        cin>>a1>>b1;

        a=max(a,a1);
        b=min(b,b1);
    }

    cout<<max(b-a+1,0ll)<<endl;


}


Measured memory_bytes: 3604