akhauriyash/Code-Regression huggingface dataset:
x,y=map(int,input().split())

mod=10**9+7
n=10**6
f=[1,1]
g=[1,1]
h=[0,1]

for i in range(2,n+1):
  f.append(f[-1]*i%mod)
  h.append((-h[mod%i]*(mod//i))%mod)
  g.append(g[-1]*h[i]%mod)
  
def cmb(n,r):
  p=f[n]*g[r]*g[n-r]%mod
  return p

if x==y:
  if x%3==0:
    print(cmb((x+y)//3,x//3))
  else:
    print(0)
elif x>y:
  if 2*y-x>=0 and (2*y-x)%3==0:
    print(cmb((x+y)//3,(2*y-x)//3))
  else:
    print(0)
else:
  if 2*x-y>=0 and (2*x-y)%3==0:
    print(cmb((x+y)//3,(2*x-y)//3))
  else:
    print(0)

Measured memory_bytes: 122176
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var m = int.Parse(line[1]);
            if (n == 0 && m == 0) break;
             line = Console.ReadLine().Trim().Split(' ');
            var p = Array.ConvertAll(line, int.Parse);
            Array.Sort(p);
            Console.WriteLine(p[0] == 1? 0:n/2d);
        }
    }
}



Measured memory_bytes: 15984
typedef long long ll;
#include <bits/stdc++.h>

using namespace std;

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

string s;
ll a[4];

int main() {
    std::cin >> s;
    for (int i = 0; i < 4; i++) {
        a[i] = s[i] - '0';
    }
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                ll res = a[0];
                string ans = to_string(a[0]);
                if(i==0){
                    res+=a[1];
                    ans += "+"+to_string(a[1]);
                }else{
                    res-=a[1];
                    ans += "-"+to_string(a[1]);
                }
                if(j==0){
                    res+=a[2];
                    ans += "+"+to_string(a[2]);
                }else{
                    res-=a[2];
                    ans += "-"+to_string(a[2]);
                }
                if(k==0){
                    res+=a[3];
                    ans += "+"+to_string(a[3]);
                }else{
                    res-=a[3];
                    ans += "-"+to_string(a[3]);
                }
                if(res==7){
                    ans += "=7";
                    std::cout << ans << std::endl;
                    return 0;
                }
            }
        }
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define reg register
#define rep(i, a, b) for (reg int i = (a), i##end = (b); i <= i##end; ++i)
#define dep(i, a, b) for (reg int i = (a), i##end = (b); i >= i##end; --i)

template <typename _typer> inline _typer read() {
	_typer init = 0;
	char ch = getchar(), k = 0;
	for ( ; !isdigit(ch); ch = getchar()) k = (ch == '-');
	for ( ; isdigit(ch); ch = getchar())
		init = (init << 3) + (init << 1) + (ch ^ 48);
	return k ? -init : init;
}
const ll N = 100005, INF = 1e9;

/*******************************************************************************
 *
 *
 *
 ******************************************************************************/

int n;
ll A[N], X[N], S;

int main() {
	n = read<int>();
	rep (i, 1, n) {
		A[i] = read<ll>();
		S += A[i];
	}
	X[n] = S;
	for (reg int i = 1; i <= n - 2; i += 2)
		X[n] -= 2 * A[i];
	X[1] = 2 * A[n] - X[n];
	cout << X[1] ;
	rep (i, 1, n - 2) {
		X[i + 1] = 2 * A[i] - X[i];
		cout << " " << X[i + 1] ;
	}
	cout << " " << X[n] << endl;
	return 0;
}



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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int N=read();
	int i=0;
	while(true){
		i++;
		int rem=N%3;
		N=N/3;
		if(rem!=0) N+=1;
		if(N==1) break;
	}
	
	cout << i << endl;
}

Measured memory_bytes: 3216
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int main() {
	while (cin >> n, n) {
		vector<int> p(n + 1), t(n + 1);
		for (int i = 0; i < n; i++) cin >> p[i + 1] >> t[i + 1];
		vector<vector<int> > dp(n + 1, vector<int>(4, 999999999));
		dp[0][0] = 0;
		for (int i = 1; i <= n; i++) {
			bool flag1 = false;
			for (int j = 1; j <= 3; j++) {
				int d1 = p[i - 1] + p[i];
				int t1 = p[i - 1] * (j + 1) + p[i];
				if(t[i] - t[i - 1] >= t1) dp[i][1] = min(dp[i][1], dp[i - 1][j] + d1);
			}
			for (int j = 0; j <= 2; j++) {
				int d1 = abs(p[i - 1] - p[i]);
				int t1 = d1 * (j + 1);
				if (t[i] - t[i - 1] >= t1) dp[i][j + 1] = min(dp[i][j + 1], dp[i - 1][j] + d1);
			}
		}
		int ret = 999999999;
		for (int i = 1; i <= 3; i++) ret = min(ret, dp[n][i] + p[n]);
		if (ret != 999999999) {
			cout << "OK " << ret << endl;
		}
		else {
			int res = 0;
			for (int i = 1; i <= n; i++) {
				if (dp[i][1] == 999999999 && dp[i][2] == 999999999 && dp[i][3] == 999999999) {
					res = i;
					break;
				}
			}
			cout << "NG " << res << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3132
#include "bits/stdc++.h"
#define REP(i,n) for(int i=0;i< (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) std::sort(v, v+n);
#define VSORT(v) std::sort(v.begin(), v.end());
#define VRSORT(v) std::sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


static ll Sum[3][31] = {};


int main() {
	ll n,c;
	static ll d[1010][1010];
	static ll ci[1010][1010];
	ll x = LINF;

	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin >> n>> c;
	for (int i = 1; i <= c;i++) {
		for (int k = 1; k <= c;k++) {

			cin >> d[i][k];

		}
	}

	for (int i = 1; i <= n; i++) {
		for (int k = 1; k <= n; k++) {
			cin >> ci[i][k];
		}
	}

		//色をきめる
	for (int i = 1; i <= c;i++) {
		//タイルを決める
		for (int j = 1; j <= n; j++) {
			for (int k = 1; k <= n; k++) {
				Sum[(j + k) % 3][i] += d[ci[j][k]][i];
			}
		}

	}

	//全色の組み合わせを総当りする
	//iは0組の色
	for (int i = 1; i <= c; i++) {
		//jは1組の色
		for (int j = 1; j <= c; j++ ) {
			if (i == j) continue;

			//kは2組の色
			for (int k = 1; k <= c; k++) {
				//もし同じ色が合ったら避ける
				if (k == j||k==i)continue;

				x = min(x, Sum[0][i] + Sum[1][j]+Sum[2][k]);

			}
		}
	}

	cout << x << endl;

	return 0;
}


Measured memory_bytes: 8448
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
k = ii()
x = iil()
ans = 0
for i in x:
    ans += min(i, k-i)
print(ans*2)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
int main (){
  int a=0,b=0;
  string S;
  cin>>S;
  int N=S.length();
  rep(i,N){
    if(S[i]=='0') a++;
    else b++;
  }
  cout<<min(a,b)*2;
}


Measured memory_bytes: 512
#include <string>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stdlib.h>
#include <algorithm>
#include <list>
#include <math.h>
#include<string.h>
#define reps(i,j,k) for(int i=(j);i<(k);i++)
#define rep(i,j) reps(i,0,j)

//	rep(i,10)cout << i << endl;
using namespace std;

int main(void){
	int n,r,g,b;
	cin >> r >> g >> b >> n ;
	int ans = 0;
	for(int i=0;i*r<=n;i++){
		for(int j=0;i*r + j*g<=n;j++){
			if((n-i*r-j*g)%b == 0){
				ans++;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    string s;
    getline(cin, s);
    for (int i=0;i<s.size();i++) {
        if ('a' <= s[i] && s[i] <= 'z') s[i] += 'A' - 'a';
        else if ('A' <= s[i] && s[i] <= 'Z') s[i] += 'a' - 'A';
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3216
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
	    int S = scan.nextInt();
		int h = S / 3600;
		int m = (S % 3600) / 60;
		int s = (S % 3600) % 60;
		
		System.out.println(h + ":" + m + ":" + s);
	}

}

Measured memory_bytes: 26204
#include <iostream>
#include <string.h>
using namespace std;

#define MOD 1000000007
int h, w, k;
long long d[8];
long long d2[8];

int fib[] = { 1, 1, 2, 3, 5, 8, 13, 21};

int main(void) {
	cin >> h >> w >> k;
	d[0] = 1;
	for (int i = 1; i < w; i++) {
		d[i] = 0;
	}

	long long *ct = d;
	long long *ct2 = d2;
	for (int s = 0; s < h; s++) {
		memset(ct2, 0, sizeof(d));
		for (int i = 0; i < w; i++) {
			if (ct[i] == 0) {
				continue;
			}
			if (i == 0) {
				ct2[0] += ct[0] * fib[w - 1];
				if (w > 1) {
					ct2[1] += ct[0] * fib[w - 2];
				}
			} else if (i == w - 1) {
				ct2[w - 1] += ct[w - 1] * fib[w - 1];
				if (w > 1) {
					ct2[w - 2] += ct[w - 1] * fib[w - 2];
				}
			} else {
				ct2[i - 1] += ct[i] * fib[i - 1] * fib[w - i - 1];
				ct2[i] += ct[i] * fib[i] * fib[w - i - 1];
				ct2[i + 1] += ct[i] * fib[i] * fib[w - i - 2];
			}
			for (int j = 0; j < w; j++) {
				ct2[j] = ct2[j] % MOD;
			}
		}
		long long *tmp = ct;
		ct = ct2;
		ct2 = tmp;
	}
	cout << ct[k - 1] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; int d[11], n, m, i, a, b, sum, e;
int main(){
	while(true) {
		memset(d,0,sizeof(d));sum=0;
		cin>>n>>m;if(!n){break;}
		for(i=0;i<n;i++){
			cin>>a>>b;
			d[b]+=a;
		}
		for(i=10;i>=0;i--){
			e=min(d[i],m);
			m-=e;
			sum+=i*(d[i]-e);
		}
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    for (char c = 'a'; c <= 'z'; ++c)
        if (find(all(s), c) == s.end())
            return cout << c, 0;
    cout << "None";
}


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

int main(void){
 int n;
 cin>>n;
 int a[109];
 for(int i=0;i<n;i++){
     cin>>a[i];
 }
 sort(a,a+n,greater<int>());
 int ans=0;
 for(int i=0;i<n;i++){
     ans+=a[i]*(i&1?-1:1);
 }
 cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n;
    cin >> n;
    ll ans = 1;
    for(int i=1; i<=n; i++){
        ans *= i;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);

	string S;
	cin >> S;
	if (S == "Sunny") cout << "Cloudy" << endl;
	else if (S == "Cloudy") cout << "Rainy" << endl;
	else cout << "Sunny" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
typedef long long int ll;
#define pb push_back
#define endl        '\n'
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);
   ll N;
   string s;
   cin>>N>>s;
   int ans=0;
   for(int i=1;i<N;i++)
   {
       if(s[i]!=s[i-1]) ans++;
   }
cout<<ans+1;
}

Measured memory_bytes: 512
/*
  Id: ak260901
  Task: a
  Lang: C++
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

int n, k;

int main() {
  scanf("%d%d", &n, &k);
  if(k == 1) puts("0");
  else printf("%d\n", n - k);
  return 0;
}


Measured memory_bytes: 256
var
a,b,c:longint;
function max(x,y:longint):longint;
 begin
  if x>y then exit(x) else exit(y);
 end;
begin
readln(a,b,c);
if (a>b)and(a>c) then begin a:=a*10;writeln(a+b+c);exit; end;
if (b>a)and(b>c) then begin b:=b*10; writeln(b+a+c);exit;end;
if (c>a)and(c>b) then begin c:=c*10; writeln(a+b+c);exit;end;
if (a=b)and(a>c) then begin a:=a*10;writeln(a+b+c);exit; end;
if (a=c)and(a>b) then begin a:=a*10;writeln(a+b+c);exit; end;
if (c=b)and(b>a) then begin b:=b*10;writeln(a+b+c);exit; end;
writeln(a*10+b+c);
end.

Measured memory_bytes: 128
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, k: usize, mut h:  [usize; n]);
    h.sort();
    println!(
        "{}",
        h.iter().take(if n > k { n - k } else { 0 }).sum::<usize>()
    );
}


Measured memory_bytes: 6212
use whiteread::parse_line;

fn main() {
    let x: u32 = parse_line().unwrap();
    let mut ans: u32 = 1;

    for i in 2..=((x as f64).sqrt().floor()) as u32 {
        let mut k = 2;
        let exp = loop {
            if i.pow(k) > x {
                break k - 1;
            }
            k += 1;
        };
        ans = ans.max(i.pow(exp));
    }
    println!("{}", ans);
}


Measured memory_bytes: 2652
package main

import (
	"fmt"
)

func solve() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	ans := 0
	if a < b+c {
		ans = (b + c) - a
	} else {
		ans = 0
	}

	fmt.Println(ans)
}

func main() {
	solve()
}


Measured memory_bytes: 512
from collections import defaultdict


def main():
    N, M = list(map(int, input().split()))
    adj_from = defaultdict(list)
    adj_to = defaultdict(list)
    for _ in range(M):
        s, t = list(map(lambda x: int(x) - 1, input().split()))
        adj_from[t].append(s)
        adj_to[s].append(t)
    # prob[s][t]: 邪魔がない場合に枝s->tを通る確率
    prob = [[0] * N for _ in range(N)]
    for t in adj_to[0]:
        prob[0][t] = 1 / len(adj_to[0])
    for s in range(1, N - 1):
        # node 's' に入ってくる確率を均等に分配
        prob_sum = sum([prob[n][s] for n in adj_from[s]])
        for t in adj_to[s]:
            prob[s][t] += prob_sum / len(adj_to[s])
    # expect[s][t]: 邪魔がなく、かつ枝s->tからカウントを始めた場合に通る枝本数の期待値
    expect = [[0] * N for _ in range(N)]
    for s in adj_from[N - 1]:
        expect[s][N - 1] = 1
    for t in range(N - 2, 0, -1):
        # node 't' から出ていく時の本数を、node 't' に入ってくるところに反映
        e = sum([expect[t][n] for n in adj_to[t]]) / len(adj_to[t])
        for s in adj_from[t]:
            expect[s][t] += e + 1
    # 邪魔なしの場合の枝本数の期待値
    expect_all = sum([p * e for p, e in zip(prob[0], expect[0])])
    # 各edgeをふさいだ場合の枝本数の変化量の最小値を求める
    diff_min = 0  # ふさげない場合 / ふさぐと不利になる場合はふさがないので変化量0
    for s in range(N - 1):
        if len(adj_to[s]) <= 1:
            continue
        s_prob = 1 if s == 0 else sum([prob[n][s] for n in adj_from[s]])
        # expect[s][t] が最も大きいtを選んでふさぐのが良い
        expect_max, target = 0, None
        for t in adj_to[s]:
            if expect[s][t] > expect_max:
                expect_max = expect[s][t]
                target = t
        # 枝s->targetをふさいだ時の枝の期待値の変化量
        d = - prob[s][target] * expect[s][target]
        for t in adj_to[s]:
            if t == target:
                continue
            d += ((s_prob / (len(adj_to[s]) - 1)) - prob[s][t]) * expect[s][t]
        diff_min = min(diff_min, d)
    # 答え
    print(expect_all + diff_min)


if __name__ == '__main__':
    main()

Measured memory_bytes: 105848
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
tmp = -2
for i in range(N):
    if A[i]-1 == tmp + 1:
        ans += B[A[i]-1] + C[A[i]-2]
    else:
        ans += B[A[i]-1]
    tmp = A[i]-1
print(ans)

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

int main(){
  int n,a,b;
  cin >> n >> a >>b;
  bool can = false;
  for(int i = a; i<=b; i++){
    if(i%n==0) can = true;
  }
  if(can) cout << "OK" << endl;
  else cout << "NG" << endl;
  return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>

using namespace std;

int dfs(vector<vector<pair<int,int>>> &graph, vector<pair<int,int>> &res, int v, int &count, int from, vector<int> &low, vector<int> &pre){
	pre[v] = count++;
	low[v] = pre[v];
	
	for(pair<int,int> next : graph[v]){
		if(pre[next.first] == -1){
			
			low[v] = min(low[v], dfs(graph, res, next.first, count, v, low, pre));
			if(low[next.first] == pre[next.first]){
				if(v < next.first) res.push_back(make_pair(v, next.first));
				else res.push_back(make_pair(next.first, v));
			}
		} else {
			if(from == next.first){
				continue;
			}
			low[v] = min(low[v], pre[next.first]);
		}
	}
	
	return low[v];
}

vector<pair<int,int>> bridges(vector<vector<pair<int,int>>> & graph, int V){
	vector<pair<int,int>> res;
	
	if(V > 0){
		vector<int> low(V, -1);
		vector<int> pre(V, -1);
		int count = 0;
		dfs(graph, res, 0, count, -1, low, pre);
	}
	
	return res;
}


signed main(){
	
	int V, E;
	vector<vector<pair<int,int>>> G;
	vector<pair<int,int>> b;
	set<int> s;
	
	cin>>V>>E;
	
	G.resize(V);
	
	for(int i = 0; i < E; i++){
		int s, t;
		
		cin>>s>>t;
		
		G[s].push_back({t, 1});
		G[t].push_back({s, 1});
	}
	
	b = bridges(G, V);
	
	sort(b.begin(), b.end());
	
	for(int i = 0; i < b.size(); i++){
		cout<<b[i].first<<" "<<b[i].second<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 5948
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] h = new int[n];
		Arrays.setAll(h, i -> sc.nextInt());
		
		int[] dp = new int[n];
		dp[0] = 0;
		dp[1] = Math.abs(h[0] - h[1]);
		
		for (int i = 2; i < n; i++) {
			dp[i] = dp[i - 1] + Math.abs(h[i - 1] - h[i]);
			for (int j = 2; i - j >= 0 && j <= k; j++) {
				dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(h[i - j] - h[i]));
			}
		}
		
//		System.out.println(Arrays.toString(h));
//		System.out.println(Arrays.toString(dp));
		
		System.out.println(dp[n - 1]);
				
		sc.close();
	}
 
}
 

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

int main() {
	
	//vector<int> a(n);
	//cout << "test" << endl;

	cin.tie(0);
	ios::sync_with_stdio(false);
	
	//string ans="YES";


	int n;
	cin >> n;
	
	int ans=0;
	
	
	vector<int> a(n);
	
	rep(i,n) cin >> a[i];
	
	for(int i=1;i<n-1;i++){
		int c=0;//count
		if(a[i]<a[i-1]) c++;
		if(a[i]<a[i+1]) c++;
		if(c==1) ans++;
	}
		
	
	cout << ans << "\n";
	
	
	return 0;

    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int h,w;
    cin>>h>>w;
    char p[h+2][w+2];
    int jg[h+2][w+2]={0};
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            cin>>p[i][j];
            if(p[i][j]=='#')
            {
                jg[i-1][j-1]++;
                jg[i][j-1]++;
                jg[i+1][j-1]++;
                jg[i-1][j]++;
                jg[i+1][j]++;
                jg[i-1][j+1]++;
                jg[i][j+1]++;
                jg[i+1][j+1]++;
            }
        }
    }
        for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(p[i][j]=='#')
            {
              cout<<"#";
            }
            else
            {
                cout<<jg[i][j];
            }
        }
        cout<<endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(void){
  int t,h,y,w=0;
  while(1){
    scanf("%d%d",&h,&w);
    if(h==0&&w==0)break;
    for(t=0;t<h;t++){
       if((t+2)%2==0){
	for(y=0;y<w;y++){
	  if((y+2)%2>0){
	    printf(".");
	  }else{
	    printf("#");
	  }
	}
      }
       else if((t+2)%2>0){
	for(y=0;y<w;y++){
	  if((y+2)%2>0){
	    printf("#");
	  }else{
	    printf(".");
	  }
	}
	}
       puts("");
    }
    puts("");
  }  
  return 0;
}



Measured memory_bytes: 2092
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int a,b;
  cin>>a>>b;
  if(a==b){
    rep(i,a){
      cout<<a<<flush;
    }
  }else{
  int c=max(a,b);
  int d=min(a,b);
    rep(i,c){
      cout<<d<<flush;
    }
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
vector<int> edges[400000];
int vis[400000];
int ncc = 0;
void dfs(int a){
	if(vis[a]) return;
	vis[a] = 1;
	for(int c = 0; c < edges[a].size(); c++) dfs(edges[a][c]);
}
int main(){
	for(int i = 0; i < 400000; i++) vis[i] = 0;
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < n; i++){
		int z = 0;
		cin >> z;
		for(int j = 0; j < z; j++){
			int x;
			cin >> x;
			edges[i].push_back(x+n-1);
			edges[x+n-1].push_back(i);
		}
	}
	for(int i = 0; i < m+n; i++) vis[i] = 0;
	dfs(0);
	for(int i = 0; i < n; i++){
		if(!vis[i]){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;

}


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

//#define DEBUG 1
#define REP(i,n) for(int i=1;i<=n;i++)
int n;
int d[114514];
int dp[114514][3];

int main(){
	cin >> n;
	REP(i, n){
		cin >> d[i];
		if (d[i - 1] == d[i]){
			dp[i][0] = 1;
			dp[i][1] = dp[i - 1][0] + 1;
			dp[i][2] = dp[i - 1][1] + 1;
		}
		else{
			dp[i][0] = dp[i - 1][0] + 1;
			dp[i][1] = dp[i - 1][1] + 1;
			dp[i][2] = dp[i - 1][2] + 1;
		}
	}
	int m = 0;
#ifdef DEBUG
	REP(i, n)cout << d[i] << " ";
	cout << endl;
	REP(j, 3){
		REP(i, n)cout << dp[i][j - 1] << " ";
		cout << endl;
	}
#endif
	REP(i, n)REP(j, 3)m = max(m, dp[i][j - 1]);
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 4612
#!/usr/bin/env python3
import sys
from bisect import bisect_right, bisect_left


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    ans  = 0
    A.sort()
    B.sort()
    C.sort()
    for i in range(N):
        ai = bisect_left(A, B[i])
        ci = bisect_right(C, B[i])
        ans += (ai) * (N-ci)

    print(ans)

    return


# Generated by 1.1.5 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()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 24188
#include<stdio.h>
int main()
{
    int a,b,n,s=0,c=0;
    scanf("%d%d",&a,&b);
    while(a--)
    {
        scanf("%d",&n);
        s+=n;
        if(s<=b)
            c++;
    }
    printf("%d\n",c+1);
    return 0;
}


Measured memory_bytes: 128
n,a,b,c=map(int,input().split())

xs=[int(input()) for _ in range(n)]

inf = 10**9

def solve(aa, bb, cc, xs):
    if not xs:
        if min(aa,bb,cc) == 0:
           return inf
        else:
            return abs(a-aa) + abs(b-bb) + abs(c-cc) - 30

    x, *rest = xs
    res0 = solve(aa, bb, cc,     rest)
    res1 = solve(aa + x, bb, cc, rest) + 10
    res2 = solve(aa, bb + x, cc, rest) + 10
    res3 = solve(aa, bb, cc + x, rest) + 10

    return min(res0, res1, res2, res3)

print(solve(0,0,0,xs))

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if (a + b > c + d) {
    cout << "Left" << endl;
  }
  else if (a + b < c + d) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  } 
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    lint n, T;
    cin >> n >> T;

    vector<lint> t(n);
    rep(i, n){
        cin >> t[i];
    }

    lint ans = T;
    REP(i, 1, n){
        ans += min(T, t[i] - t[i - 1]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(){
    int n[200][2] = {}, i = 0, a, sum, digit;
    
    while (scanf("%d %d", &n[i][0], &n[i][1]) != EOF) {
        i++;
    }
    
    for (a = 0; a < i; a++) {
        sum = n[a][0] + n[a][1];
        digit = 0;
        while (sum != 0) {
            sum = sum / 10;
            digit++;
        }
        printf("%d\n", digit);
    }
    return 0;
}

Measured memory_bytes: 600
/***************************************************
 * Problem Name : B - Guidebook.cpp
 * Problem Link : https://atcoder.jp/contests/abc128/tasks/abc128_b
 * OJ           : AtCoder
 * Verdict      : Trying
 * Date         : 2019-05-27
 * Problem Type :
 * Author Name  : Saikat Sharma
 * University   : CSE, MBSTU
 ***************************************************/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<cstring>
#include<string>
#include<sstream>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdlib>
#include<deque>
#include<stack>
#include<map>
#include<set>
#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define __FileRead freopen ("input.txt", "r", stdin);
#define __FileWrite freopen ("output.txt", "w", stdout);
#define SET(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define pll pair <ll, ll>
#define debug cout <<"#########\n";
#define nl cout << "\n";
#define sp cout << " ";
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pf(n) scanf("%d", n)
#define pfl(n) scanf("%lld", n)
#define all(v) v.begin(), v.end()
#define Pow2(x) ((x)*(x))
#define Mod(x, m) ((((x) % (m)) + (m)) % (m))
#define Max3(a, b, c) max(a, max(b, c))
#define Min3(a, b, c) min(a, min(b, c))
#define pb push_back
#define mk make_pair
#define MAX 100005
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
std::string NumberToString ( T Number ) {
    std::ostringstream ss;
    ss << Number;
    return ss.str();
}
ll lcm (ll a, ll b) {
    return a * b / __gcd (a, b);
}
/************************************ Code Start Here ******************************************************/
int main () {
    __FastIO;
    //~ vector<string>res;
    map < string, int > mp;
    int n;
    cin >> n;
    int k = 1;
    vector<pii>vec[MAX];
    set<string>res;

    for (int i = 1; i <= n; i++) {
        string str;
        int p;
        cin >> str >> p;

        if (mp[str] == 0) {
            mp[str] = k++;
        }

        vec[mp[str]].pb (pii (p, i) );
        res.insert (str);
    }

    for (int i = 1; i < k; i++) {
        sort (all (vec[i]) );
        reverse (all (vec[i]) );
    }

    //~ sort (all (res) );
    for (auto it = res.begin(); it != res.end(); it++) {
        string str = *it;

        for (int i = 0; i < (int) vec[mp[str]].size(); i++) {
            //~ pii top = vec[mp[str]]
            cout << vec[mp[str]][i].second << "\n";
        }
    }

    return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine().replace("\n", "");
        sc.close();

        int count = 0;
        String sign = "CODEFESTIVAL2016";
        for(int i = 0; i < s.length(); i++) {
            if (s.charAt(i) != sign.charAt(i)) count++;
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 24916
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

ll Pow(ll n, ll k) {
	ll ans = 1, a = n % MOD;
	while (k > 0) {
		if (k & 1) {
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		k >>= 1;
	}
	return ans;
}

int main(void) {
	int num, m, i, a, b, ans = 0;
	cin >> num >> m;
	vector<map<int, int>> d(num);
	rep(i, m) {
		cin >> a >> b;
		a--;
		d[a][b] = 0;
	}
	rep(i, num) {
		if (d[i].size() == 0) {
			if (i == 0 && num > 1)
				ans = Pow(10, num - 1);
		}
		else if (d[i].size() == 1) {
			if (i == 0 && num > 1 && (*d[0].begin()).first == 0) {
				ans = -1;
				break;
			}
			ans += (*d[i].begin()).first * Pow(10, num - i - 1);
		}
		else {
			ans = -1;
			break;
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import heapq

n = int(input())
al = list(map(int, input().split()))

q = []
heapq.heapify(q)
s = 0
for i in range(n):
    heapq.heappush(q, al[i])
    s += al[i]

red = [s]
for i in range(n,2*n):
    a = heapq.heappushpop(q, al[i])
    s = s - a + al[i]
    red.append(s)

q = []
heapq.heapify(q)
s = 0
for i in range(2*n,3*n):
    heapq.heappush(q, -al[i])
    s += al[i]

blue = [s]
for i in range(2*n-1,n-1,-1):
    a = heapq.heappushpop(q, -al[i])
    s = s + a + al[i]
    blue.append(s)

# print(red)
# print(blue)
res = red[0] - blue[-1]
for i in range(n+1):
    res = max(res, red[i] - blue[-1-i])

print(res)

Measured memory_bytes: 39260
x, n = map(int, input().split())
t = list(map(int, input().split()))

if(x not in t):print(x);exit()
down = x-1
up = x+1
while(True):
    if down not in t:print(down);exit()
    if up   not in t:print(up);exit()
    down-=1
    up+=1

Measured memory_bytes: 61876
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long[] max = new long[3*N];
		var SH = new SkewHeap<long>();
		long tot = 0;
		for(int i=0;i<N;i++){
			SH.Push(A[i]);
			tot += A[i];
		}
		max[N-1] = tot;
		
		for(int i=N;i<2*N;i++){
			tot += A[i];
			SH.Push(A[i]);
			var mm = SH.Top; SH.Pop();
			tot -= mm;
			max[i] = tot;
		}
		
		long[] min = new long[3*N];
		SH = new SkewHeap<long>();
		tot = 0;
		for(int i=3*N-1;i>=2*N;i--){
			SH.Push(-A[i]);
			tot += A[i];
		}
		min[2*N] = tot;
		for(int i=2*N-1;i>=N;i--){
			tot += A[i];
			SH.Push(-A[i]);
			var mm = SH.Top; SH.Pop();
			tot -= -mm;
			min[i] = tot;
		}
		
		long ans = long.MinValue;
		for(int i=N-1;i<2*N;i++){
			ans = Math.Max(ans,max[i] - min[i+1]);
		}
		
		Console.WriteLine(ans);
		
	}
	
	
	int N;
	long[] A;
	public Sol(){
		N = ri();
		A = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


class SkewHeap<T> where T:IComparable<T>{
	public int Count{
		get{return cnt;}
		private set{cnt=value;}
	}
	
	public SkewHeap(){
		root=null;
		this.Count=0;
	}
	
	public void Push(T v){
		NodeSH<T> p=new NodeSH<T>(v);
		root=NodeSH<T>.Meld(root,p);
		this.Count++;
	}
	
	public void Pop(){
		if(root==null)return;
		root=NodeSH<T>.Meld(root.L,root.R);
		this.Count--;
	}
	
	public T Top{
		get{return root.Val;}
	}
	
	int cnt;
	NodeSH<T> root;
	
	class NodeSH<S> where S : IComparable<S> {
		public NodeSH<S> L, R;
		public S Val;

		public NodeSH(S v){
			Val = v;
			L = null; R = null;
		}
		public static NodeSH<S> Meld(NodeSH<S> a, NodeSH<S> b){
			if(a == null)return b;
			if (b == null) return a;
			if (a.Val.CompareTo(b.Val) > 0) swap(ref a, ref b);
			a.R = Meld(a.R, b);
			swap(ref a.L, ref a.R);
			return a;
		}

		static void swap<U>(ref U x, ref U y) {
			U t = x; x = y; y = t;
		}
	}
}



Measured memory_bytes: 48096
#include <iostream>
#include <vector>
#include <queue>
using namespace  std;

const int nIMPOS = -1;
struct StDist
{
  int m_nDist;
  int m_nFromMeTo;

  StDist(int nDist) : m_nDist(nDist), m_nFromMeTo(0)
  { }
};

void fnInput(vector<vector<int>>& rvvnAdjcy, vector<StDist>& rvoDist)
{
  int nxSiz;
  cin >> nxSiz;

  rvvnAdjcy.resize(nxSiz + 1, vector<int>(nxSiz + 1, 0));
  for (int i = 0; i < nxSiz; ++i)
  {
    int nx, nySiz;
    cin >> nx >> nySiz;
    for (int j = 0; j < nySiz; ++j)
    {
      int ny;
      cin >> ny;
      rvvnAdjcy[nx][ny] = 1;
    }
  }
  StDist oDist(nIMPOS);
  rvoDist.resize(nxSiz + 1, oDist);
}

void fnBreadthFirstSearch(const vector<vector<int>>& cnrvvnAdjcy, 
                          queue<int>& rqnBFSrch, vector<StDist>& rvoDist)
{
  while (rqnBFSrch.size())
  {
    int nx = rqnBFSrch.front(); rqnBFSrch.pop();
    if (rvoDist[nx].m_nDist == nIMPOS)  continue;

    for (int ny = 1; ny < cnrvvnAdjcy[nx].size(); ++ny)
    {
      if (cnrvvnAdjcy[nx][ny] == 1  &&
          rvoDist[nx].m_nFromMeTo == 0)
      {
        int nDist = rvoDist[nx].m_nDist + 1;
        if (rvoDist[ny].m_nDist == nIMPOS)
          rvoDist[ny].m_nDist = nDist;
        else
          rvoDist[ny].m_nDist = min(rvoDist[ny].m_nDist, nDist);

        rqnBFSrch.push(ny);
      }
    }
    rvoDist[nx].m_nFromMeTo = 1;
  }
}

void fnResult(const vector<StDist>& cnrvoDist)
{
  for (int i = 1; i < cnrvoDist.size(); ++i)
    cout << i <<  " " << cnrvoDist[i].m_nDist << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnAdjcy;
  queue<int>  qnBFSrch;
  vector<StDist> voDist;

  fnInput(vvnAdjcy, voDist);

  voDist[1].m_nDist = 0;
  qnBFSrch.push(1);
  fnBreadthFirstSearch(vvnAdjcy, qnBFSrch, voDist);
  fnResult(voDist);

  return 0;
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int H, W, K;
  int total, total2, origin = 0, count = 0;
  cin >> H >> W >> K;

  int buf;

  vector<vector <char>> c(H, vector<char>(W, 'a'));
  vector<vector <char>> cop1(H, vector<char>(W, 'a'));
  vector<vector <char>> cop2(H, vector<char>(W, 'a'));

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> c.at(i).at(j);
      if(c.at(i).at(j) == '#'){
        origin++;
      }
    }
  }

  string s;

  int limitH = pow(2, H);
  int limitW = pow(2, W);



  for(int i = 0; i < limitH; i++){ // 何行目を選ぶか

    buf = i;

    for(int k = 0; k < H; k++){ // 初期化
      for(int l = 0; l < W; l++){
        cop1.at(k).at(l) = c.at(k).at(l);
      }
    }

    total = origin;

    for(int k = 0; k < H; k++){ // 赤に塗る & 数チェック
      if(buf % 2 == 1){
        for(int l = 0; l < W; l++){
          if(cop1.at(k).at(l) == '#'){
            total--;
          }
          cop1.at(k).at(l) = '+';
        }
      }
      buf = buf / 2;
    }

    /*for(int k = 0; k < H; k++){ // 数チェック
      for(int l = 0; l < W; l+){
        if(cop.at(l).at(k) = '#'){}
          total++;
        }
      }
    }*/

    if(total < K){ // これ以上進んでも仕方がない
      continue;
    }

    for(int j = 0; j < limitW; j++){

      buf = j;

      for(int k = 0; k < H; k++){ // 初期化
        for(int l = 0; l < W; l++){
          cop2.at(k).at(l) = cop1.at(k).at(l);
        }
      }

      total2 = total;
      
      for(int k = 0; k < W; k++){ // 赤に塗る & 数チェック

        if(buf % 2 == 1){
          for(int l = 0; l < H; l++){
            if(cop2.at(l).at(k) == '#'){
              total2--;
            }
            cop2.at(l).at(k) = '+';
          }
        }
        buf = buf / 2;
      }

      if(total2 == K){
        count++;
        /*cout << i << "," << j << endl;
        for(int k = 0; k < H; k++){ // 初期化
          for(int l = 0; l < W; l++){
            cout << cop2.at(k).at(l);
          }
          cout << endl;
        }*/
      }

    }
  
  }  

  cout << count << endl;

}

Measured memory_bytes: 4124
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    List<Integer> list = new ArrayList();
    int n = s.nextInt();
    int m = s.nextInt();
    int sum = 0;
    boolean coosable = true;
    for(int i = 0; i < n; i++){
      int value = s.nextInt();
      list.add(value);
      sum = sum + value;
    }
    Collections.sort(list);
    Collections.reverse(list);
    for(int i = 0; i < m; i++){
      if(list.get(i) < Math.ceil((double)sum / (4 * m))){
        coosable = false;
      }
    }
    if(coosable){
      System.out.println("Yes");
    } else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21972
#include<stdio.h>

int A[1000000],n;

int binarySearch(int key){
    int left = 0;
    int right = n;
    int mid;

    while(left < right){
        mid = (left + right)/2;
        if(key == A[mid]){
            return 1;
        }
        if(key > A[mid]){
            left = mid + 1;
        }
        if(key < A[mid]){
            right = mid;
        }
    }
    return 0;
}

int main(){
    int i,q,k,sum = 0;

    scanf("%d",&n);
    for(i = 0;i < n; i++){
        scanf("%d",&A[i]);
    }
    scanf("%d",&q);
    for(i = 0; i < q; i++){
        scanf("%d",&k);
        if(binarySearch(k))sum++;
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define ll long long int
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
using namespace std;
ll ans[101][100001];
int main() {
	IOS;
	ll n,k,x,sum=0;
	ll const num=1000000007;
	cin>>n>>k;
	for(ll i=0;i<=n;i++)ans[i][0]=1;
	for(ll i=1;i<=n;i++){
		cin>>x;
		sum=0;
		for(ll j=0;j<=k;j++){
			if(j<=x){
				sum+=ans[i-1][j]%num;
				sum%=num;
				ans[i][j]=sum%num;
			}
			else{
				sum+=ans[i-1][j]%num;
				sum%=num;
				sum=(sum-ans[i-1][j-x-1]%num+num)%num;
				
				ans[i][j]=sum%num;
			}
		}
	}
	cout<<ans[n][k];
}


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

// 辺を表す構造体
struct edge{
    int from, to;
    long long cost;
};

// v:=頂点数 es:=辺の集合 cost:=始点からの最短経路のコストを格納する配列
// s:=始点(指定しなければ頂点0) g:=終点(指定しなければ頂点v-1)
// 始点から到達可能で、かつ終点へ到達可能な負閉路が検出された場合falseを、それ以外の場合trueを返す
bool bellman_ford(int v, const vector<edge>& es, vector<long long>& cost, int s = 0, int g = -1){
    if(g == -1){
        g = v - 1;
    }

    const long long INF = 1LL << 61;

    cost.resize(v);
    fill(cost.begin(), cost.end(), INF);
    cost[s] = 0;

    for(int i = 0 ; i < v * 2 ; ++i){
        for(auto& e : es){
            if(cost[e.from] < INF && cost[e.from] + e.cost < cost[e.to]){
                cost[e.to] = cost[e.from] + e.cost;
                if(i >= v - 1 && e.to == g){
                    return false;
                }else if(i >= v - 1){
                    cost[e.to] = -INF;
                }
            }
        }
    }

    return true;
}

#include<iostream>

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

    vector<edge> es;
    for(int i = 0 ; i < m ; ++i){
        int a, b;
        long long c;
        cin >> a >> b >> c;
        es.push_back({a - 1, b - 1, p - c});
    }

    vector<long long> cost;
    if(bellman_ford(n, es, cost)){
        cout << max(-cost[n - 1], 0LL) << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int n,m,cnt[150000],loc[150000];
vector<P> s[200000];
int main(void){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        s[a].push_back(P(b,c));
        s[b].push_back(P(a,c*-1));
    }
    for(int i=0;i<n;i++){
        if(!cnt[i]){
            loc[i]=0;
            cnt[i]=1;
            queue<int> que;
            que.push(i);
            while(!que.empty()){
                int q=que.front();
                que.pop();
                for(auto p:s[q]){
                    if(cnt[p.first]){
                        if(loc[q]+p.second!=loc[p.first]){cout<<"No"<<endl;return 0;}
                    }
                    else{
                        loc[p.first]=loc[q]+p.second;
                        cnt[p.first]=1;
                        que.push(p.first);
                    }
                }
            }
        }
    }
    cout<<"Yes"<<endl;
}


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

int main()
{
	long long int i,n,x,y;
	cin>>n;
	vector<long long int>a(n),b(n);
	
	
	for(i=0;i<n;i++)
		{
			cin>>x>>y;
			a[i]=x+y;
			b[i]=x-y;
			
		}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	cout<<max((a[n-1]-a[0]),(b[n-1]-b[0]))<<endl;
}

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

int main() {
	int N;
	vector<int>b;
	int a[100];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		b.push_back(a[i]);
	}
	sort(b.begin(), b.end());
	double res = ((double)b[0] + (double)b[1])/2;
	for (int k = 0; k < N - 2; k++) {
		res = (res + (double)b[k+2])/2;
	}
	cout << res << endl;
}

Measured memory_bytes: 764
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<functional>
#include<cmath>
#include<vector>
#include<assert.h>
//using namespace std;
using std::min;
using std::max;
using std::swap;
using std::sort;
using std::reverse;
using std::random_shuffle;
using std::lower_bound;
using std::upper_bound;
using std::unique;
using std::vector;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
void open(const char *s){
#ifndef ONLINE_JUDGE
    char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
void open2(const char *s){
#ifdef DEBUG
    char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
int rd(){int s=0,c,b=0;while(((c=getchar())<'0'||c>'9')&&c!='-');if(c=='-'){c=getchar();b=1;}do{s=s*10+c-'0';}while((c=getchar())>='0'&&c<='9');return b?-s:s;}
void put(int x){if(!x){putchar('0');return;}static int c[20];int t=0;while(x){c[++t]=x%10;x/=10;}while(t)putchar(c[t--]+'0');}
int upmin(int &a,int b){if(b<a){a=b;return 1;}return 0;}
int upmax(int &a,int b){if(b>a){a=b;return 1;}return 0;}
const int N=3010;
const ll p=1000000007;
ll fp(ll a,ll b)
{
    ll s=1;
    for(;b;b>>=1,a=a*a%p)
        if(b&1)
            s=s*a%p;
    return s;
}
const ll inv2=fp(2,p-2);
int a[N];
int n,q;
ll f[N][N];
int main()
{
    open2("d");
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            if(a[i]<a[j])
                f[i][j]=1;
    int x,y;
    for(int i=1;i<=q;i++)
    {
        scanf("%d%d",&x,&y);
        f[x][y]=f[y][x]=(f[x][y]+f[y][x])*inv2%p;
        for(int j=1;j<=n;j++)
            if(j!=x&&j!=y)
            {
                f[x][j]=f[y][j]=(f[x][j]+f[y][j])*inv2%p;
                f[j][x]=f[j][y]=(f[j][x]+f[j][y])*inv2%p;
            }
    }
    ll ans=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<i;j++)
            ans=(ans+f[i][j])%p;
    ans=ans*fp(2,q)%p;
    ans=(ans%p+p)%p;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;
 
template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
    is>>p.first>>p.second;
    return is;
}

template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}


signed main(){
    ll d,t,s;cin>>d>>t>>s;
    if(s*t>=d) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

using namespace std;


// Bismilahir Rahmanir Rahim


typedef unsigned int ui;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef short int si;
typedef unsigned short int usi;
typedef pair <int, int> pii;


#define CASE false
#define TEST false
#define BUFFER true
#define TIME false
#define DEBUG true
#define SET_GEN false
#define _ << " " <<
#define __ << "\n"
#define ff first
#define ss second
#define RANGE(a, b) (rand() % (b-a+1) + a)


const double pi = acos(-1.);
const double eps = 1e-7;
const int high = 2e9;
const int inf = 2147483647;
const int _inf = -2147483648;
const lli INF = 1e18;
const int mod = 1e9+7;


void delay(int sec); // DEBUG


void solution(void)
{	
	ulli n, w;
	
	cin >> n >> w;
	const int maxn = n*1000;
	const ulli nf = 1e18;
	
	vector <ulli> dp(maxn+1, nf);
	dp[0] = 0;
	
	
	for(int i = 0; i < n; ++i) {
		ulli weight, val;
		cin >> weight >> val;
		
		for(int j = maxn-val; j >= 0; --j) {
			dp[j+val] = min(dp[j+val], dp[j] + weight);
		}	
	}
	
	int ans;
	
	for(int i = 0; i <= maxn; ++i) {
		if (dp[i] <= w) ans = i;
	}
	
	cout << ans __;
	

    return ;
}

int main(int argc, char *arv[])
{
    #if BUFFER
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #endif

    #if SET_GEN
    srand((unsigned int) time(0));
    #endif

    int t = 1;

    #if CASE
    int cnt = 1;
    #endif

    #if TEST
    cin >> t;
    #endif

    #if TIME
    clock_t start_time, end_time;
    double time_elapsed;
    #endif


    while(t--) {

        #if TIME
        start_time = clock();
        #endif

        #if CASE
        cout << "Case " << cnt++ << ": ";
        #endif

        solution();

        #if TIME
        end_time = clock();

        time_elapsed = (double) (end_time - start_time) / CLOCKS_PER_SEC;

        cout << "\nRuntime: " << fixed << setprecision(7) << time_elapsed << "\n";
        #endif
    }


    return 0;
}

void delay(int sec)
{
    int mili_sec = 1000 * sec;

    clock_t start_time = clock();

    while (clock() < start_time + mili_sec);

    return ;
}


Measured memory_bytes: 3980