akhauriyash/Code-Regression huggingface dataset:
def f(n):
    l = []
    for i in range(n):
        l.append(i)
        l = l[::-1]
    return l

def index(N):
    if N % 2 == 0:
        L = list(range(1, N, 2)[::-1])
        L.extend(range(0, N, 2))
    else:
        L = list(range(2, N, 2)[::-1])
        L.append(0)
        L.extend(range(1, N-1, 2))
    return L

def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    print(*[A[i] for i in index(N)])
main()


Measured memory_bytes: 26180
import Data.List (sort)

main :: IO ()
main = do
  [r,g,b,n] <- map (read :: String -> Int) . words <$> getLine
  print $ ans n r g b

ans :: Int -> Int -> Int -> Int -> Int
ans n a b c = let k = div n a in foldl func 0 [0..k] where
  func acc l = acc + split (n-a*l) b c

split :: Int -> Int -> Int -> Int
split n a b = let k = div n a in foldl func 0 [0..k] where
  func acc l = if (n-a*l) `mod` b == 0 then acc + 1 else acc

Measured memory_bytes: 636
#include<iostream>
#include<cstdlib>

#include<cmath>
#include<map>
#include<string>
#include<vector>
#include<algorithm> 

using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) std::cout << (j ? s1 : s2) << endl;
# define YES(j) std::cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define rep(n,i) for(i = 0 ; i < n ; i++)

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

    int i = 2;
    while(1){
        if(s.substr(0,(s.size()-i)/2) == s.substr((s.size()-i)/2,(s.size()-i)/2)){
            cout << s.size()-i << endl;
            return 0;
        } 
        i += 2;
    }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
A = int(input())
B = int(input())
C = int(input())
X = int(input())
Ans = 0
for i in range(0,A+1):
  for j in range(0,B+1):
    for k  in range(0,C+1):
      if 500*i + 100*j + 50*k == X:
        Ans += 1
print(Ans)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-

from functools import reduce

N = int(input())
aN = list(map(int, input().split()))

def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a
def lcm_base(x, y):
    return (x * y) // gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def f(num, aN):
    sum1 = 0
    for i in range(len(aN)):
        sum1 += num % aN[i]
    return sum1

# リストの最小公倍数-1を関数fの引数にする
lcm = lcm_list(aN)
print(f(lcm-1, aN))

Measured memory_bytes: 3812
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc;// = new Scanner(System.in);
        sc = new Scanner(System.in);
        int count = 0;
        while(true) {
            int n = sc.nextInt();
            int x = sc.nextInt();
            if (n == 0 && x == 0) break;
            for (int a = 1; a <= n; a++) {
                for (int b = a + 1; b <= n; b++) {
                    for (int c = b + 1; c <= n; c++) {
                        if (a + b + c == x) {
                            count++;
                            break;
                        }
                    }
                }
            }
            System.out.println(count);
            count = 0;
            sc.nextLine();
        }
    }
}


Measured memory_bytes: 26868
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long ans = 0;
		ans += x / 500 * 1000;
		x %= 500;
		ans += x / 5 * 5;
		System.out.println(ans);

	}

}


Measured memory_bytes: 21716
package main
     
import "fmt"

func main() {
	var n, m int
    fmt.Scan(&n, &m)
    s := make([]int, m, m)
    c := make([]int, m, m)
    for i := 0; i < m; i++ {
        fmt.Scan(&s[i], &c[i])
    }

    num := make([]int, n, n) 
    if n > 1 { num[0] = 1 }

    dupl := make([]int, n, n)
    for i := range s {
        if dupl[s[i]-1] == 1 && num[s[i]-1] != c[i] {
            fmt.Println("-1")
            return
        } 
        num[s[i]-1] = c[i]
        dupl[s[i]-1] = 1
    }
    
    if num[0] == 0 && len(num) > 1 {
        fmt.Println("-1")
        return 
    }

    ans := ""
    for _, v := range num {
        ans += fmt.Sprintf("%d", v)
    }
    fmt.Println(ans)
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int a[100005];

int main() {
    int n;
    cin>> n;
    int tmp;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &tmp);
        a[tmp] = i;
    }
    for (int i = 1; i <= n; i++) {
        printf("%d ", a[i]);
    }
}


Measured memory_bytes: 4152
n, m, X, Y = map(int, input().split())

x = list(map(int, input().split())) + [X]
y = list(map(int, input().split())) + [Y]

#print(x)
#print(y)

x_max = max(x)
y_min = min(y)

if x_max >= y_min:
    ans = True
else:
    ans = False

if ans:
    print("War")
else:
    print("No War")


Measured memory_bytes: 3060
def resolve():
    '''
    code here
    '''
    K = int(input())

    is_not_found = True
    memo = [0 for _ in range(K)]

    i=7%K
    res = 1
    if i == 0:
        is_not_found = False

    while is_not_found and memo[i] == 0:
        memo[i] += 1
        if i == 0:
            is_not_found = False
        else:
            res += 1
            i = (i * 10 + 7) % K

    print(res) if is_not_found == False else print(-1)


if __name__ == "__main__":
    resolve()


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

using namespace std;

typedef long long ll;

int main(){
        ll N, K;
        cin>>N>>K;
        vector <ll> a(N), b(N);
        for(int i=0;i<N;i++){
                cin>>a[i]>>b[i];
        }
        ll ret=0;
        //最初にK自身を見る。
        for(ll i=0;i<N;i++){
                bool flag=true;
                for(ll j=0;j<30;j++){
                        //見ているビットa[i]==1 K==0のとき
                        if((a[i]>>j)&1&&!((K>>j)&1)){
                                flag=false;
                                break;
                        }
                }
                if(flag){
                        ret+=b[i];
                }
        }
        //cout<<ret<<endl;
        ll ans=ret;
        for(ll i=0;i<30;i++){
                //見ているビットが1であったなら
                // kの上位ibit目が1 → そこを0にしてそこより下位のbitを1に
                if(K>>i&1){
                        //見ているKのビットを0にしたものをcに代入
                        //~ビットごとの反転
                        ll c=K&~(1LL<<i);
                        //cout<<K<<":"<<c<<endl;
                        //見ているビット以下をすべて1にする。
                        c|=(1LL<<i)-1;
                        ll ret2=0;
                        // a[j]でbitが立っていてcでbitが立っていない → だめ
                        for(ll j=0;j<N;j++){
                                bool flag=true;
                                for(ll l=0;l<30;l++){
                                        if((a[j]>>l)&1&&!((c>>l)&1)){
                                                flag=false;
                                                break;
                                        }
                                }
                                if(flag){
                                        ret2+=b[j];
                                }
                        }
                        //cout<<ret2<<endl;
                        ans=max(ans, ret2);
                }
        }
        cout<<ans<<endl;
        return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int ch=0,a=0;
    for(int i=0;i<n;++i){
      string s; cin>>s;
      if(s=="lu" || s=="ru"){
        if(ch==1) a++, ch=0;
        else ch=1;
      }else if(s=="ld" || s=="rd"){
        if(ch==-1) a++, ch=0;
        else ch=-1;
      }
    }
    cout<<a<<endl;
  }
  return 0;
}

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
int main(){
  int exp[10001], n, i, j, mod[10001], a[10001], c, count[6000], h, d;

  for(i = 1; i < 10001; ++i) exp[i] = i * i;

  while(scanf("%d", &n) && n){
    memset(count , 0, sizeof(count));
    for(i = 1; i < n; ++i) mod[i] = exp[i] % n;
    c = 0;
    for(i = 1; i < n; ++i){
      for(j = 0; j < c; ++j)
	if(mod[i] == a[j]) break;
      if(j == c) a[c++] = mod[i];
    }
    h = (n - 1) / 2;
    for(i = 0; i < c; ++i){
      for(j = 0; j < c; ++j){
	if(a[i] != a[j]){
	  d = a[i] - a[j];
	  if(d < 0) d += n;
	  if(d > h) d = n - d;
	  count[d]++;
	}
      }
    }

    for(i = 1; i <= h; ++i) printf("%d\n", count[i]);  
  }
  return 0;
}

Measured memory_bytes: 732
#include <bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 5010, mod = 1e9 + 7 ;
int head[maxn], to[maxn * 2], nxt[maxn * 2], tot = 1 ;
int g[maxn] ;
int sz[maxn], f[maxn][maxn], tmp[maxn] ;
void addEdge (int u, int v) {
    to[++ tot] = v; nxt[tot] = head[u]; head[u] = tot ;
}
void dfs (int v, int fa) {
    f[v][1] = 1; sz[v] = 1 ;
    for (int i = head[v]; i; i = nxt[i]) {
        if (to[i] == fa) continue ;
        dfs (to[i], v) ;
        for (int j = 0; j <= sz[v] + sz[to[i]]; j ++) tmp[j] = 0 ;
        for (int j = 1; j <= sz[v]; j ++)
            for (int k = 0; k <= sz[to[i]]; k ++)
                tmp[j + k] = (tmp[j + k] + 1ll * f[v][j] * f[to[i]][k] % mod) % mod ;
        for (int j = 1; j <= sz[v] + sz[to[i]]; j ++) f[v][j] = tmp[j] ;
        sz[v] += sz[to[i]] ;
    }
    for (int i = 2; i <= sz[v]; i += 2) f[v][0] = (f[v][0] - 1ll * f[v][i] * g[i] % mod + mod) % mod ;
}
int main() {
    int n ;
    scanf("%d", &n) ;
    for (int i = 1; i < n; i ++) {
        int u, v ;
        scanf("%d%d", &u, &v) ;
        addEdge (u, v); addEdge (v, u) ;
    }
    g[0] = 1 ;
    for (int i = 2; i <= n; i += 2) g[i] = 1ll * g[i - 2] * (i - 1) % mod ;
    dfs (1, 0) ;
    printf("%d\n", mod - f[1][0]) ;
    return 0 ;
}


Measured memory_bytes: 97280
V,E = map(int, input().split())
adj = [[] for _ in range(V)]
for _ in range(E):
    s,t = map(int, input().split())
    adj[s].append(t)

color = [0 for _ in range(V)]
topo = []

def topo_dfs(s):
    color[s] = 1
    if adj[s]:
        for next in adj[s]:
            if color[next] == 0:
                topo_dfs(next)
    topo.append(s)
    return

for i in range(V):
    if color[i] == 0:
        topo_dfs(i)
print("\n".join(map(str, topo[::-1])))

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)

#define INF 987654321
#define IINF 2987654321987654321
#define MOD 1000000007

struct SegmentTree {
	int n;
	vector<ll> st;

	void init(int sz) {
		n = 1;
		while(n < sz) n <<= 1;
		st.assign(2*n, 0LL);
	}

	void reset() {
		fill(st.begin(), st.end(), 0LL);
	}

	void update(ll p, ll val) {
		p += n-1;
		st[p] += val;
		for(p >>= 1; p; p >>= 1)
			st[p] = st[2*p] + st[2*p+1];
	}

	ll rangeSum(int l, int r) {
		ll sum = 0;
		for(l += n-1, r += n-1; l <= r; l >>= 1, r >>= 1) {
			if(l&1) sum += st[l++];
			if(!(r&1)) sum += st[r--];
		}
		return sum;
	}
} tree;


const int MAXN = 1e5 + 50;
ll n, m, a[MAXN];
void readInput() {
	scanf("%lld", &n);
	for(int i = 1; i <= n; i++)
		scanf("%lld", &a[i]);
	tree.init(2*n+1);
	m = n*(n+1)/2;
}

bool check(ll x) {
	tree.reset();
	ll sum = n+1, cnt = 0;
	tree.update(sum, 1);
	for(int i = 1; i <= n; i++) {
		sum += (a[i] >= x) ? 1 : -1;
		cnt += tree.rangeSum(1, sum);
		tree.update(sum, 1);
	}
	return cnt >= (m - (m/2+1) + 1);
}

void solve() {
	ll low = 1, high = 1000000000LL, res = -1;
	while(low <= high) {
		ll mid = (low + high) / 2;
		if(check(mid)) {
			res = mid;
			low = mid+1;
		} else {
			high = mid-1;
		}
	}
	printf("%lld\n", res);
}

int main() {
	readInput();
	solve();
}	

Measured memory_bytes: 5120
#include<stdio.h>

void explode(char map[8][8],int x,int y){
  if( 1<=x && x<=8 &&
      1<=y && y<=8 &&
      map[y-1][x-1]=='1'){
    map[y-1][x-1]='0';

    explode(map,x-3,y);
    explode(map,x-2,y);
    explode(map,x-1,y);

    explode(map,x+1,y);
    explode(map,x+2,y);
    explode(map,x+3,y);

    explode(map,x,y-3);
    explode(map,x,y-2);
    explode(map,x,y-1);

    explode(map,x,y+1);
    explode(map,x,y+2);
    explode(map,x,y+3);
  }
  return;
}

int main(void){
  int i,j,k,n;
  char map[8][8];
  int x,y;
  char hoge;

  scanf("%d",&n);
  scanf("%c",&hoge);
  scanf("%c",&hoge);

  for(i=0;i<n;i++){
    for(j=0;j<8;j++){
      for(k=0;k<8;k++)
        scanf("%c",&map[j][k]);
      scanf("%c",&hoge);
    }
    scanf("%d%d",&x,&y);

    explode(map,x,y);
    
    printf("Data %d:\n",i+1);
    for(j=0;j<8;j++){
      for(k=0;k<8;k++)
        printf("%c",map[j][k]);
      printf("%c",hoge);
    }

    if(i!=n-1){
      scanf("%c",&hoge);
      scanf("%c",&hoge);
    }
  }

  return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

ll n, m;
ll wMax = -1;
ll wMin = INF64;
vector<ll> v, w;

void solve2() {
	vector<vector<ll>> dp(n + 1, vector<ll>(m + 1));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= m; j++) {
			if (j >= w[i]) {
				dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
			} else {
				dp[i + 1][j] = dp[i][j];
			}
		}
	}

	cout << dp[n][m] << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;

	v.resize(n);
	w.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i] >> w[i];
		wMax = max(wMax, w[i]);
	}

	solve2();
	//if (n <= 30) {

	//} else if (wMax <= 1000) {
	//	solve2();
	//} else {

	//}
	return 0;
}



Measured memory_bytes: 10716
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(X: int, Y: int):
    ans = False
    
    for a in range(0, 101):
        for b in range(0,101):
            if X == a +b and Y==2*a+4*b:
                ans = True
    if ans:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(X, Y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9136
import java.util.Scanner;

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

		System.out.print((A - K) < 0 ? "0" : (A - K));
		System.out.print(" ");
		if (A - K < 0) {
			System.out.println((B - (K - A)) < 0 ? "0" : (B - (K - A)));
		} else {
			System.out.println(B);
		}
	}
}

Measured memory_bytes: 22732
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

int main(){
  ll n,k,ans=0;cin>>n>>k;
  vll p(n);
  rep(i,0,n){
    cin>>p[i];
  }
  sort(p.begin(),p.end());
  rep(i,0,k){
    ans+=p[i];
  }
  cout<<ans<<endl;
}




Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<string> S(N);
    int AC=0;
    int WA=0;
    int TLE=0;
    int RE=0;
    for (int i=0;i<N;i++){
        cin >> S.at(i);
        if (S.at(i)=="AC") {AC++;}
        if (S.at(i)=="WA") {WA++;}
        if (S.at(i)=="TLE") {TLE++;}
        if (S.at(i)=="RE") {RE++;}
    }// Your code here!
    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE << endl;
}


Measured memory_bytes: 6360
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    int m, f, r;

    while (true) {
      m = scanner.nextInt();
      f = scanner.nextInt();
      r = scanner.nextInt();
      if (m == -1 && f == -1 && r == -1) break;

      if (m == -1 || f == -1) System.out.println("F");
      else if (m + f >= 80) System.out.println("A");
      else if (m + f >= 65) System.out.println("B");
      else if (m + f >= 50 || (m + f >= 30 && r >= 50)) System.out.println("C");
      else if (m + f >= 30) System.out.println("D");
      else System.out.println("F");
    }
  }
}


Measured memory_bytes: 26356
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) int __VA_ARGS__; in(__VA_ARGS__)
//オーバーフロー対策
#define INL(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
#pragma endregion RegionDefs

void solve()
{
    IN(n);
    set<int> v;
    rep(i, 10)
    {
        rep(j, 10)
        {
            v.insert(i * j);
        }
    }
    cout << (v.find(n) == v.end() ? "No" : "Yes") << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

struct HLD {
  vector<int> label, parent, head;

  HLD(const vector<vector<int>> &g) : label(g.size()), parent(g.size()), head(g.size()) {
    const int n = g.size();
    vector<int> size(n, 1);
    auto dfs = [&](auto dfs, int u, int p) -> void {
      for (int v : g[u]) if (v != p) {
        dfs(dfs, v, u);
        size[u] += size[v];
      }
    };
    dfs(dfs, 0, -1);
    int k = 0;
    auto dfs2 = [&](auto dfs, int u, int p, int h) -> void {
      label[u] = k++;
      head[u] = h;
      parent[u] = p;
      for (int v : g[u]) if (v != p && size[v] * 2 >  size[u]) dfs(dfs, v, u, h);
      for (int v : g[u]) if (v != p && size[v] * 2 <= size[u]) dfs(dfs, v, u, v);
    };
    dfs2(dfs2, 0, -1, 0);
  }

  int lca(int u, int v) {
    for (;;) {
      if (label[u] > label[v]) swap(u, v);
      if (head[u] == head[v]) return u;
      v = parent[head[v]];
    }
  }
};

#define getchar getchar_unlocked
#define putchar putchar_unlocked

int i32() {
  int n, c;
  while ((c = getchar()) < '0') if (c == EOF) return -1;
  n = c - '0';
  while ((c = getchar()) >= '0') n = n * 10 + c - '0';
  return n;
}

void print(int n) {
  int res[11], i = 0;
  do { res[i++] = n % 10, n /= 10; } while (n);
  while (i) putchar(res[--i] + '0');
  putchar('\n');
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n = i32();
  int q = i32();
  vector<vector<int>> g(n);
  struct edge {
    int v, c, w;
  };
  vector<vector<edge>> g2(n);
  rep(i, n-1) {
    int u = i32() - 1;
    int v = i32() - 1;
    int c = i32();
    int w = i32();
    g[u].push_back(v);
    g[v].push_back(u);
    g2[u].push_back((edge){v, c, w});
    g2[v].push_back((edge){u, c, w});
  }
  HLD hld(g);
  vector<ll> ans(q);
  struct query {
    int x, y;
    int coeff;
    int i;
  };
  vector<vector<query>> qs(n);
  rep(i, q) {
    int x = i32();
    int y = i32();
    int u = i32() - 1;
    int v = i32() - 1;
    qs[u].push_back((query){x, y, 1, i});
    qs[v].push_back((query){x, y, 1, i});
    qs[hld.lca(u, v)].push_back((query){x, y, -2, i});
  }
  ll dist = 0;
  vector<ll> distc(n);
  vector<ll> cnt(n);
  auto dfs = [&](auto dfs, int u, int p) -> void {
    for (query q : qs[u]) {
      ans[q.i] += q.coeff * (dist - distc[q.x] + cnt[q.x] * q.y);
    }
    for (edge e : g2[u]) {
      if (e.v == p) continue;
      distc[e.c] += e.w;
      cnt[e.c]++;
      dist += e.w;
      dfs(dfs, e.v, u);
      dist -= e.w;
      cnt[e.c]--;
      distc[e.c] -= e.w;
    }
  };
  dfs(dfs, 0, -1);
  rep(i, q) {
    print(ans[i]);
  }
}


Measured memory_bytes: 53236
//1%

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / __gcd(a, b) * b
#define range(a) (a).begin(),(a).end()
const int inf = 2147483647;

int main (){
    ll X;cin>>X;
    ll XX = 100;
    ll i;
    for(i = 0;XX<X;i++){
        XX += XX * 0.01;
    }
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	int a[n],dp[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		dp[i]=INT_MAX;
	}
	dp[n-1]=0;
	for(int i=n-2;i>=0;i--){
		for(int j=1;j<=k;j++)
		{
		if(i+j<n){
			dp[i]=min(dp[i],(abs(a[i+j]-a[i])+dp[i+j]));
		}
		}}
	cout<<dp[0];
return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 5, mod = 1e9 + 7, inf = 0x3f3f3f3f;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int n, x;
    cin >> n >> x;
    int ans = 1, sum = 0, t;

    for (int i = 0; i < n; ++i){
        cin >> t;
        sum += t;
        if (sum <= x) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N=sc.nextInt(),K=sc.nextInt(),d=1;
		while(true) {
			if(N<K) break;
			N/=K;
			d++;
		}
		System.out.println(d);
	}
}


Measured memory_bytes: 35592
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i64,
        b: i64,
        c: i64,
        d: i64,
        e: i64,
    }
    let mut arr = [
        (a % 10, a),
        (b % 10, b),
        (c % 10, c),
        (d % 10, d),
        (e % 10, e),
    ];
    for item in arr.iter_mut() {
        if item.0 == 0 {
            item.0 += 10;
        }
    }
    arr.sort();
    let mut ans = 0;
    for item in arr.iter().skip(1) {
        ans += if item.0 == 0 {
            item.1
        } else {
            item.1 - item.0 + 10
        };
    }
    ans += arr[0].1;
    println!("{}", ans);
}


Measured memory_bytes: 4352
from collections import deque

N,M = map(int,input().split())

data = [[] for _ in range(N)]

for i in range(M):
    a,b = map(lambda x:int(x)-1,input().split())
    data[a].append(b)
    data[b].append(a)

q = deque([(0,0)])
ans = [-1]*N

#print(data)

while q:
    x = q.popleft()
    for y in data[x[1]]:
        if y == x[0]:
            continue
        if ans[y] == -1:
            ans[y] = x[1]
            q.append((x[1],y))
    #print(x,q,ans)

if -1 in ans[1:]:
    print('No')
else:
    print('Yes')
    for i in range(1,N):
        print(ans[i]+1)


Measured memory_bytes: 98520
import sys
from collections import Counter


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

class UnionFind():
    def __init__(self, n):
        self.n = n                              # 要素数(初期頂点数)
        self.root = [i for i in range(n)]       # 根
        self.rank = [0] * n                     # 深さ
        self.sizes = [1] * n                     # 要素数(木)

    def find(self, x):                          # 根を返す
        if self.root[x] == x:
            return x
        self.root[x] = self.find(self.root[x])  # 経路圧縮
        return self.root[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:         # 浅い方を深い方につなげる
            self.root[x] = y
            self.sizes[y] += self.sizes[x]
        else:
            self.root[y] = x
            self.sizes[x] += self.sizes[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):                       # 同じ集合かどうかの真偽を返す
        return self.find(x) == self.find(y)

    def roots(self):
        return {i for i, num in enumerate(self.root) if i == num}

    def size(self, x):
        return self.sizes[self.find(x)]

n, m = inintm()

uf = UnionFind(n)

for i in range(m):
    a, b = inintm()
    uf.unite(a-1, b-1)

ans = 0

r = uf.roots()

for i in r:
    if uf.size(i) > ans:
        ans = uf.size(i)

print(ans)


Measured memory_bytes: 37352
//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define file_input
//#define multitest
//#define measure_time
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<v32>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c)
{
	cout << "{ ";
	for (const auto &v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

ll get_power(ll n, ll i)
{
	ll ans = 0, j = i;
	while (n / i > 0)
	{
		ans += (n / i);
		i *= j;
	}
	return ans;
}

void solve()
{
	ll n;
	cin >> n;
	if (n & 1)
	{
		cout << 0 << ln;
		return;
	}
	ll five = get_power(n / 2, 5);
	cout << five << ln;
	return;
}

int main()
{
	FASTIO;
#ifdef file_input
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	clock_t start, stop;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
#ifdef measure_time
	start = clock();
#endif
	for (int tc = 1; tc < t + 1; tc++)
		solve();
#ifdef measure_time
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; } value
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  if(n<2) cout << n << endl;
  else if(n<4) cout << 2 << endl;
  else if(n<8) cout << 4 << endl;
  else if(n<16) cout << 8 << endl;
  else if(n<32) cout << 16 << endl;
  else if(n<64) cout << 32 << endl;
  else cout << 64 << endl;
}

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

string s;
int ans = 1e9;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> s;
	for(int i=0; i<s.size()-2; ++i){
		int t = stoi(s.substr(i, 3));
		ans = min(ans, abs(753-t));
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
n = int(input())
l = [int(ln) for ln in input().split()]
ans = 0
if len(l) >= 3:
  for i in range(n-2):
    li = l[i]
    for j in range(i+1, n-1):
      lj = l[j]
      if not (li == lj):
        for k in range(j+1, n):
          lk = l[k]
          if not(li == lk) and not(lj ==lk):
            if (li + lj > lk) and (lj + lk > li) and (lk + li > lj):
              ans += 1
print(ans)


Measured memory_bytes: 68292
import java.util.*;
public class Main {
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String T = sc.next();
    int count = 0;
    for (int i=0; i<S.length(); i++) {
      if (S.charAt(i) != T.charAt(i))
        count++;
    }
    System.out.println(count);
  }
}

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

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define all(box) box.begin(), box.end()

using namespace std;

using P = pair<int,int>;
using ll = long long;

const long long INF = LLONG_MAX/3;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
inline void Yes (bool condition) { if(condition) { cout << "Yes" << endl; } else { cout << "No" << endl;} }

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[b]+=siz[a];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

const int MOD=998244353;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
	if(COMinited==false){
		fac[0] = fac[1] = 1;
    	finv[0] = finv[1] = 1;
    	inv[1] = 1;
    	for (int i = 2; i < MAX; i++){
        	fac[i] = fac[i - 1] * i % MOD;
        	inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        	finv[i] = finv[i - 1] * inv[i] % MOD;
    	}
		COMinited=true;
	}
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};
signed main(){
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	priority_queue<P> pq;
	rep(i,a){
		int s;
		cin>>s;
		pq.push(P(s,1));
	}
	rep(i,b){
		int s;
		cin>>s;
		pq.push(P(s,2));
	}
	rep(i,c){
		int s;
		cin>>s;
		pq.push(P(s,3));
	}
	int ca=0,cb=0,cc=0;
	int ret=0;
	while(true){
		P s=pq.top();
		//cout<<s.first<<endl;
		pq.pop();
		if(s.second==1&&ca<x){
			ca++;
			ret+=s.first;
		}
		else if(s.second==2&&cb<y){
			cb++;
			ret+=s.first;
		}
		else if(s.second==3){
			cc++;
			ret+=s.first;
		}
		if(ca+cb+cc==x+y)break;
	}
	cout<<ret<<endl;
}

Measured memory_bytes: 10604
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace ConsoleApp1
{
    public class Program
    {
        static void Main(string[] args)
        {
            var s1 = ReadLine();
            var s2 = ReadLine();


            var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);
            WriteLine(Hoge(s2));
            Out.Flush();
        }

        public static long Hoge(string s2)
        {
            var a = s2.Split(' ').Select(int.Parse);
            return Fuga(a).Sum();
        }

        private static IEnumerable<int> Fuga(IEnumerable<int> i)
        {
            foreach (var item in i)
            {
                var a = true;
                var b = item;
                var c = 0;

                while (a)
                {
                    if (b % 2 == 0)
                    {
                        c += 1;
                        b = b / 2;
                    }
                    else
                    {
                        a = false;
                    }
                }

                yield return c;
            }
        }


    }




}

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

namespace ABC120A
{
    class Program
    {
        static void Main(string[] args)
        {
            int A, B, C;

            int x;
            var word = Console.ReadLine().Split(' ');

            A = int.Parse(word[0]);
            B = int.Parse(word[1]);
            C = int.Parse(word[2]);

            if (B / A >= C)
                Console.WriteLine(C);
            if (B / A < C)
                Console.WriteLine(B / A);

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

const int MOD = 1e9 + 7;

int64 frac(int n) {
    int64 res = 1;
    for (int i=1; i<=n; i++) {
        res *= i;
        res %= MOD;
    }
    return res;
}

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

    int64 ans = frac(n);
    ans *= frac(m);

    cerr << "ans : " << ans << endl;

    if (n == m) {
        ans *= 2;
    } else if (abs(n-m) > 1) {
        ans = 0;
    }

    ans %= MOD;
    cout << ans << endl;
}

Measured memory_bytes: 256
import itertools
h, w = map(int, input().split())
L = [ [ [i, j] for j in range(w) ][::(-1)**i] for i in range(h) ]
L = list(itertools.chain(*L))
A = [ list(map(int, input().split())) for _ in range(h) ]
ans = 0
Q = []
for i in range(h*w-1):
  nh, nw = L[i]
  if A[nh][nw]%2:
    nnh, nnw = L[i+1][0], L[i+1][1]
    A[nnh][nnw] += 1
    Q.append([nh+1, nw+1, nnh+1, nnw+1])
    ans += 1
print(ans)
for i in Q:
  print(*i, sep=" ")

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int n;
    cin >> n;
    map<string, int> mp;
    rep(i, n) {
        string s;
        cin >> s;
        mp[s]++;
    }
    int mx = 0;
    for (auto x : mp) mx = max(mx, x.second);
    for (auto x : mp) {
        if (x.second == mx) cout << x.first << endl;
        else continue;
    }
    return 0;
}



Measured memory_bytes: 25216
from sys import stdin
input=lambda : stdin.readline().strip()
from math import ceil,sqrt,factorial,gcd
from collections import deque
n,k=map(int,input().split())
l=list(map(int,input().split()))
z=[float("infinity") for i in range(n)]
z[0]=0
for i in range(n):
	for j in range(1,k+1):
		if i+j<n:
			z[i+j]=min(z[i+j],z[i]+abs(l[i]-l[i+j]))
		else:
			break
print(z[-1])


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

void displayVector(std::vector<int> a, int n){
    for(int i = 0; i < n; i++){
        std::cout << a[i];
        if(i != n-1){
            std::cout << " ";
        }
    }
    std::cout << std::endl;
}

int bubbleSort(std::vector<int>& a, int n){
    bool flag = true;
    int tmp;
    int cnt = 0;
    //displayVector(a, n);
    while(flag){
        flag = false;
        for(int j = n-1; j > 0; --j){
            if(a[j] < a[j-1]){
                tmp = a[j-1];
                a[j-1] = a[j];
                a[j] = tmp;
                cnt++;
                flag = true;
            }
        }
        //displayVector(a, n);
    }
    return cnt;
}

int main(void){
    int n;
    scanf("%d", &n);
    std::vector<int> a(n);
    for(int i = 0; i < n; ++i){
        scanf("%d", &a[i]);
    }
    
    int cnt = bubbleSort(a, n);
    displayVector(a, n);
    std::cout << cnt << std::endl;
    return 0;
}


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

int main() {
	// your code goes here
	int m,n,x,y;
	while(true){
	
	cin >> m;
	if(m==0)
	break;
	cin >> n;
	for(int i=0;i<n;i++){
	cin >> x >> y;
	m-=y-x;
	}
	if(m>0)
	cout << m << endl;
	else 
	cout << "OK" << endl; 

	}
		return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

template<class T>
inline void read(T& x) {
  T s = 0, base = 1;
  char c;
  while (!isdigit(c=getchar())) if (c == '-') base = -base;
  while (isdigit(c)) {
    s = s * 10 + (c^48);
    c = getchar();
  }
  x = base * s;
}

int A[3];

int main() {
  REP(i,3) read(A[i]);

  int minval = 10000000;
  REP(i,3) {
    REP(j,3) {
      if (i != j) {
        int cost1 = abs(A[j] - A[i]);
        REP(k,3) {
          if (k != i && k != j) {
            int cost2 = abs(A[k] - A[j]);
            if (cost1 + cost2 < minval) minval = cost1 + cost2;
          }
        }
      }
    }
  }
  
  printf("%d\n", minval);
  return 0;
}


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

int main() {
  cout << setprecision(15);
  int n;
  cin >> n;
  vector<double> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < n-1; ++i) {
    v[i+1] = (v[i+1] + v[i])/2.0;
  }
  cout << v[n-1] << endl;
  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    bool fin = true;
    vector<int> v(n);
    rep(i, n)
    {
        cin >> v.at(i);
    }
    rep(i, n)
    {
        if ((v.at(i) % 2) == 0)
        {
            if ((v.at(i) % 3) == 0 || (v.at(i) % 5) == 0)
            {
                fin = true;
            }
            else
            {
                fin = false;
              break;
            }
        }
    }
    if (fin)
    {
        cout << "APPROVED" << endl;
    }
    else
    {
        cout << "DENIED" << endl;
    }
}

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

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> L(M),R(M);
  for(int i=0;i<M;i++){
    cin>>L.at(i)>>R.at(i);
  }
  sort(L.begin(),L.end());
  sort(R.begin(),R.end());
  if(R.at(0)-L.at(M-1)<0){
    cout<<0<<endl;
  }else{
    cout<<R.at(0)-L.at(M-1)+1<<endl;
  }
}


Measured memory_bytes: 1024
s = input()
t = input()
times = len(s) - len(t) + 1
ans = len(t)
if t in s:
  ans = 0
else:
  for i in range(times):
    ans_tmp = 0
    for j in range(len(t)):
      if t[j] != s[i+j]:
        ans_tmp += 1
    if ans_tmp <= ans:
      ans = ans_tmp
print(ans)

Measured memory_bytes: 67540
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<map>

using namespace std;

int main(){
	int n,k,p;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d %d",&k,&p);
		if(k<=p)
		printf("%d\n",k);
		else{
			if(k%p==0)
			printf("%d\n",p);
			else
			printf("%d\n",k%p);
		}
	}
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int tot,id,n,q,dis[N],dep[N],root[N],head[N],nex[N<<1],to[N<<1],c[N<<1],wi[N<<1];
int fa[N][20],lg[N];
struct node
{
    int tot,sum,l,r;
}t[N*40];
void add(int u,int v,int x,int y)
{
    to[++tot]=v;nex[tot]=head[u];head[u]=tot;c[tot]=x;wi[tot]=y;
}
int build(int l,int r,int k)
{
    int p=++id;
    if(l==r) return p;
    int m=l+r>>1;
    t[p].l=build(l,m,k<<1);
    t[p].r=build(m+1,r,k<<1|1);
    return p;
}
int update(int l,int r,int k,int x,int v,int pre)
{
    int p=++id;
    //if(l==r) cout<<p<<endl;
    if(l==r) {t[p].sum=t[pre].sum+v;t[p].tot=t[pre].tot+1;return p;}
    int m=l+r>>1;
    if(x<=m)
    {
        t[p].r=t[pre].r;
        t[p].l=update(l,m,k<<1,x,v,t[pre].l);
    }
    else
    {
        t[p].l=t[pre].l;
        t[p].r=update(m+1,r,k<<1|1,x,v,t[pre].r);
    }
    return p;
}
pair<int,int> query(int l,int r,int k,int x,int now,int pre)
{
    //if(l==r) cout<<now<<' '<<pre<<endl;
    if(l==r) return {t[now].tot-t[pre].tot,t[now].sum-t[pre].sum};
    int m=l+r>>1;
    if(x<=m) return query(l,m,k<<1,x,t[now].l,t[pre].l);
    return query(m+1,r,k<<1|1,x,t[now].r,t[pre].r);
}
void dfs(int u,int p)
{
    dep[u]=dep[p]+1;
    fa[u][0]=p;
    for(int i=1;1<<i<dep[u];i++)
        fa[u][i]=fa[fa[u][i-1]][i-1];
    for(int i=head[u];i;i=nex[i])
    {
        int v=to[i];
        if(v==p) continue;
        root[v]=update(1,n-1,1,c[i],wi[i],root[u]);
        dis[v]=dis[u]+wi[i];
        dfs(v,u);
    }
}
int LCA(int u,int v)
{
    if(dep[u]<dep[v]) swap(u,v);
    while(dep[u]>dep[v])
        u=fa[u][lg[dep[u]-dep[v]]-1];
    if(u==v) return u;
    for(int k=lg[dep[u]]-1;k>=0;k--)
        if(fa[u][k]!=fa[v][k])
            u=fa[u][k],v=fa[v][k];
    return fa[u][0];
}
int main()
{
    scanf("%d%d",&n,&q);
    for(int i=1;i<n;i++)
    {
        int u,v,x,y;
        scanf("%d%d%d%d",&u,&v,&x,&y);
        add(u,v,x,y);
        add(v,u,x,y);
    }
    for(int i=1;i<=n;i++)
        lg[i]=lg[i-1]+(1<<lg[i-1]==i);
    root[1]=build(1,n-1,1);
    dfs(1,0);
    while(q--)
    {
        int x,y,u,v;
        scanf("%d%d%d%d",&x,&y,&u,&v);
        int lca=LCA(u,v);
        if(dep[u]>dep[v]) swap(u,v);
        if(lca==u)
        {
            int ans=dis[v]-dis[u];
            pair<int,int>t=query(1,n-1,1,x,root[v],root[u]);
            ans=ans-t.second+t.first*y;
            printf("%d\n",ans);
        }
        else
        {
            int ans=dis[v]-dis[lca]+dis[u]-dis[lca];
            pair<int,int>t1=query(1,n-1,1,x,root[v],root[lca]),t2=query(1,n-1,1,x,root[u],root[lca]);
            ans=ans-t1.second+t1.first*y-t2.second+t2.first*y;
            printf("%d\n",ans);
        }
    }
}


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

int main(int argc, char const *argv[])
{
	// freopen("in", "r", stdin);
	int n; cin >> n;
	int a[n + 2];
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	a[n + 1] = 1e9 + 1;
	int mx = 0;
	int cur = 1;
	while(cur <= n) {
		int now = cur;
		while(a[now] >= a[now + 1]) now++;
		mx = max(mx, now - cur);
		cur = now + 1;
	}
	cout << mx << endl;
	return 0;
}

Measured memory_bytes: 640
n = input()

if len(n) == 1:
    print(n)
elif len(n) == 2:
    print(9)
elif len(n) == 3:
    print(9+(int(n)-100+1))
elif len(n) == 4:
    print(909)
elif len(n) == 5:
    print(9+900+(int(n)-10000+1))
elif len(n) == 6:
    print(90909)


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

int main() {
	while (1) {
		int m, f, r;
		cin >> m >> f >> r;
		char grade;
		if (m + f == -2)
			break;
		if (m == -1 || f == -1)
			grade ='F';
		else if (m + f >= 80)
			grade = 'A';
		else if (m + f >= 65)
			grade = 'B';
		else if (m + f >= 50) 
			grade = 'C';
		else if (m + f >= 30) {
			if (r >= 50)
				grade = 'C';
			else
				grade = 'D';
		}
		else if (m + f < 30)
			grade = 'F';
		cout << grade << endl;
	}
}



Measured memory_bytes: 3112