akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <algorithm>

long long int MOD = 1e9 + 7;

int main(){
  // read problem
  long long int N, tmp;
  std::string S;
  std::cin >> S;
  N = S.length();
  
  //std::cerr << "length of S: " << N << std::endl << "S: " << std::endl << S << std::endl;
  
  // solve problem
  // make mod table
  std::vector<long long int> mod13(N);
  mod13[0] = 1;
  for(long long int i = 1; i < N; i++){
    mod13[i] = (mod13[i-1] * 10)%13;
  }
  
  // dp
  std::vector<std::vector<long long int> > dp(N);
  for(long long int i = 0; i < N; i++){
    for(long long int j = 0; j < 13; j++){
      dp[i].push_back(0);
    }
  }
  
  // determine dp[0][~]
  if(S[0] == '?'){
    for(long long int i = 0; i <= 9; i++){
      dp[0][(mod13[N-1]*i)%13]++;
    }
  }
  else{
    dp[0][(mod13[N-1]*(S[0]-'0'))%13]++;
  }
  
  // determine dp[i][j]
  for(long long int i = 1; i < N; i++){
    if(S[i] == '?'){
      for(long long int j = 0; j <= 9; j++){
        tmp = (mod13[N-1-i]*j)%13;
        for(long long int k = 0; k < 13; k++){
          dp[i][k] += dp[i-1][(k-tmp+13)%13];
          dp[i][k] = (dp[i][k] + MOD)%MOD;
        }
      }
    }
    else{
      tmp = (mod13[N-1-i]*(S[i]-'0'))%13;
      for(long long int k = 0; k < 13; k++){
        dp[i][k] += dp[i-1][(k-tmp+13)%13];
        dp[i][k] = (dp[i][k] + MOD)%MOD;
      }
    }
  }
  
  /*
  std::cerr << "result of dp:" << std::endl;
  for(long long int i = 0; i < N; i++){
    for(long long int j = 0; j < 13; j++){
      std::cerr << dp[i][j] << " ";
    }std::cerr << std::endl;
  }std::cerr << std::endl;*/
  
  std::cerr << "Answer:" << std::endl;
  std::cout << dp[N-1][5] << std::endl;
  
  return 0;
}


Measured memory_bytes: 17536
N = int(input())
T, A = list(map(int, input().split()))
H = list(map(int, input().split()))
t = 1_000_000
res = 0
for i in range(N):
    _t = abs(A - (T - H[i] * 0.006))
    if _t < t:
        res = i
        t = _t
print(res + 1)


Measured memory_bytes: 9124
#include<cstdio>
#include<algorithm>
struct node{
	int l,r;
	bool operator<(node b)const{
		return r-l<b.r-b.l;
	}
}a[500100];
int tree[2001000],n,m;
void pushdown(int t){
	tree[t*2]+=tree[t];
	tree[t*2+1]+=tree[t];
	tree[t]=0;
}
void modify(int t,int l,int r,int L,int R){
	if(L>r||l>R)return;
	if(L<=l&&r<=R){
		tree[t]++;
		return;
	}
	pushdown(t);
	int mid=(l+r)/2;
	modify(t*2,l,mid,L,R);
	modify(t*2+1,mid+1,r,L,R);
}
int query(int t,int l,int r,int pos){
	if(l==r)return tree[t];
	int mid=(l+r)/2;
	pushdown(t);
	if(pos<=mid)return query(t*2,l,mid,pos);
	return query(t*2+1,mid+1,r,pos);
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&a[i].l,&a[i].r);
	std::sort(a+1,a+n+1);
	int now=1;
	for(int i=1;i<=m;i++){
		while(a[now].r-a[now].l+1<i&&now<=n){
			modify(1,1,m,a[now].l,a[now].r);
			now++;
		}
		int res=0;
		for(int j=i;j<=m;j+=i)
			res+=query(1,1,m,j);
		printf("%d\n",res+n-now+1);
	}
	return 0;
}

Measured memory_bytes: 6016
#include <stdio.h>
#include <string.h>
 int main(void) {
    int i,j,q,a,b;
    char str[1000],v[1000],p[1000],c[100];
    scanf("%s %d",str,&q);
    for(i=0;i<q;i++){
        scanf("%s %d %d",c,&a,&b);
        if(strcmp(c,"print")==0){
            for(j=a;j<=b;j++){
                printf("%c",str[j]);
            }
            printf("\n");
        }
        else if(strcmp(c,"reverse")==0){
            strcpy(v,str);
            for(j=a;j<=b;j++){
                str[j]=v[b-(j-a)];
            }
        }
        else{
            scanf("%s",p);
            for(j=a;j<=b;j++){
                str[j]=p[j-a];
            }
        }
    }
    return 0;
}



Measured memory_bytes: 2084
n, m, l = list(map(int, input().split(' ')))
A = []
B = []
for i in range(n):
    A.append(list(map(int, input().split(' '))))
for i in range(m):
    B.append(list(map(int, input().split(' '))))
C = []
for i in range(n):
    C.append([0] * l)
for i in range(n):
    for j in range(l):
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]
for a in C:
    print(*a)


Measured memory_bytes: 7044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int ans = max(A * B, C * D);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;

public class Main {

    public static void main(String[] args) throws IOException {
        InputStreamReader inputReader = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(inputReader);

        final int column = Integer.parseInt(reader.readLine());
        NumberList list = new NumberList(column);

        final int row = Integer.parseInt(reader.readLine());
        for (int i = 0; i < row; i++) {
            final String line = reader.readLine();
            final StringTokenizer tokenizer = new StringTokenizer(line, ",");

            final int a = Integer.parseInt(tokenizer.nextToken());
            final int b = Integer.parseInt(tokenizer.nextToken());

            list.swap(a - 1, b - 1);
        }

        StringBuilder builder = new StringBuilder();
        List<Integer> resultList = list.getList();
        for (int value : resultList) {
            builder.append(String.format("%d\n", value));
        }
        System.out.print(builder);
    }

}

class NumberList {

    private List<Integer> list;

    public NumberList(int size) {
        list = new ArrayList<>();
        for (int i = 1; i <= size; i++) {
            list.add(i);
        }
    }

    public void swap(int index1, int index2) {
        int tmp = list.get(index1);
        list.set(index1, list.get(index2));
        list.set(index2, tmp);
    }

    public List<Integer> getList() {
        return list;
    }

}

Measured memory_bytes: 24376
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
int main()
{
	fast;
	ll a,b,t,ti,sum=0;
	cin>>a>>b>>t;
	t++;
	ti=a;
	while(ti<t)
		sum+=b,ti+=a;
	cout<<sum;
	return 0;
}


Measured memory_bytes: 3556
def readln():
    return list(map(int, input().split()))


A, B = readln()


A_isodd = []  # 奇数の桁は1
B_isodd = []  # 奇数の桁は1
# 1の偶奇
tmp = (A) % 4
if (tmp == 2)or(tmp == 3):
    A_isodd.append(1)
else:
    A_isodd.append(0)
tmp = (B+1) % 4
if (tmp == 2)or(tmp == 3):
    B_isodd.append(1)
else:
    B_isodd.append(0)


for i in range(1, 40):  # 各桁につい
    tmp = (A) % 2 ** (i + 1)
    if (tmp > 2 ** (i)) and (tmp % 2 == 1):
        A_isodd.append(1)
    else:
        A_isodd.append(0)
    tmp = (B + 1) % 2 ** (i + 1)
    if (tmp > 2 ** (i)) and (tmp % 2 == 1):
        B_isodd.append(1)
    else:
        B_isodd.append(0)

# print(A_isodd)
# print(B_isodd)

ans = []
for a, b in zip(A_isodd, B_isodd):
    if a == b:
        ans.append(0)
    else:
        ans.append(1)

ans_print = 0
for i, a in enumerate(ans):
    ans_print += 2 ** i if a == 1 else 0

print(ans_print)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int count_1=0,count_2=0,count_3=0;
  int i;
  for(i=0;i<3;i++){
    if(s.at(i)=='a'){
      count_1++;
    }
    if(s.at(i)=='b'){
      count_2++;
    }
    if(s.at(i)=='c'){
      count_3++;
    }
  }
  if(count_1==count_2 && count_1==count_3){
	cout << "Yes";
  }else{
    cout << "No";
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer n = scanner.nextInt();
        Integer d = scanner.nextInt();
        
        int result = 1;
        while(true) {
          if(result * (2 * d +1) >= n) {
            System.out.println(result);
            return;
          }
          result++;
        }
    }
    
}


Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

typedef long long ll;

using namespace std;

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

    vector<int> v(N);
    iota(v.begin(), v.end(), 1);
    vector<int> P(N);
    int i;
    for(i = 0; i < N ; ++i){
        cin >> P[i];
    }
    vector<int> Q(N);
    for (i = 0; i < N; ++i){
        cin >> Q[i];
    }

    int count = 1;
    int a = 1;
    int b = 1;
    do {
        if (P == v) {
            a = count;
        }
        if ( Q == v){
            b = count;
        }
        count++;
    } while(next_permutation(v.begin(), v.end()));

    cout << abs(a-b) << endl;
}


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

using namespace std;

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

	int n;
	long long k;
	cin >> n >> k;

	vector<int> a(n * 2);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	for(int i = 0; i < n; ++i) {
		a[i + n] = a[i];
	}

	map<int, int> pos;
	vector<int> nxt(n * 2 + 1, -1);
	vector<int> pre(n * 2 + 1, -1);
	for(int i = n * 2 - 1; i >= 0; --i) {
		if(pos.count(a[i])) {
			nxt[i] = pos[a[i]] + 1;
			pre[pos[a[i]] + 1] = i;
			pos[a[i]] = i;
		} else {
			nxt[i] = -1;
			pos[a[i]] = i;
		}
	} 

	vector<int> to(n * 2 + 1, -1);
	function<void(int)> dfs = [&] (int cur) {
		if(nxt[cur] == -1) {
			to[cur] = cur - n;
			return;
		}
		if(to[cur] != -1) {
			return;
		}
		dfs(nxt[cur]);
		to[cur] = to[nxt[cur]];
	};

	for(int i = 0; i < n; ++i) {
		dfs(i);
	}
	
	to[n] = 0;

	vector<vector<int> > jump(n + 1, vector<int> (62, -1));
	for(int i = 0; i <= n; ++i) {
		jump[i][0] = to[i];}

	for(int j = 0; j < 61; ++j) {
		for(int i = 0; i <= n; ++i) {
			jump[i][j + 1] = jump[jump[i][j]][j];
		}
	}

	int cur = 0;

	k -= 1;

	for(int i = 62; i >= 0; --i) {
		if(k >> i & 1) {
			cur = jump[cur][i];
		}
	}

	vector<int> ans;
	map<int, bool> vis;
	for(int i = cur; i < n; ++i) {
		if(vis[a[i]]) {
			while(ans.back() != a[i]) {
				vis[ans.back()] = false;
				ans.pop_back();
			}
			ans.pop_back();
			vis[a[i]] = false;
		} else {
			vis[a[i]] = true;
			ans.emplace_back(a[i]);
		}
	}

	for(int i : ans) {
		cout << i << ' ';
	}
	cout << '\n';

	return 0;
}


Measured memory_bytes: 82036
N,M=map(int,input().split())
List = []
for i in range (M):
  List.append(list(map(int, input().split())))
resList = [0]*N
for i in range(M):
  resList[List[i][0]-1] +=1
  if List[i][1]<N:
    resList[List[i][1]] +=-1
for j in range(1,N):
  resList[j] = resList[j] + resList[j-1]
print(resList.count(M))

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

using namespace std;

void solve() {
    int n; cin >> n;
    if(n == 1){
        cout << "Hello World" << endl;
    } else {
        int a, b;
        cin >> a >> b;
        cout << a+b << endl;
    }
}

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

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

int main(){
    int n, d, cnt;
    cin >> n >> d;
    int x[n][d];
    double gap;
    cnt = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < d; j++){
            cin >> x[i][j];
        }
    }

    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            gap = 0.0;
            for(int k = 0; k < d; k++){
                gap += (double)abs(x[i][k]-x[j][k]) * abs(x[i][k]-x[j][k]);
            }
            gap = sqrt(gap);
            if(gap == (int)gap) cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
inline int read(){
	int sum(0);
	char ch(getchar());
	for(;ch<'0'||ch>'9';ch=getchar());
	for(;ch>='0'&&ch<='9';sum=sum*10+(ch^48),ch=getchar());
	return sum;
}
struct edge{
	int e;
	bool can;
	edge *n,*rev;
}*pre[55];
inline void insert(int s,int e){
	edge *tp1(new edge),*tp2(new edge);
	tp1->rev=tp2,tp2->rev=tp1;
	tp1->e=e;tp2->e=s;
	tp1->n=pre[s],tp2->n=pre[e];
	pre[s]=tp1,pre[e]=tp2;
	tp1->can=tp2->can=true;
}
int n,m;
int ans;
bool vis[55];
inline void dfs(int u){
	vis[u]=1;
	for(edge *i=pre[u];i;i=i->n)
		if(i->can){
			int e(i->e);
			if(vis[e])continue;
			dfs(e);
		}
}
int main(){
	n=read(),m=read();
	for(int i=1;i<=m;++i){
		int x(read()),y(read());
		insert(x,y);
	}
	for(int i=1;i<=n;++i){
		for(edge *j=pre[i];j;j=j->n){
			j->can=false;
			j->rev->can=false;
			memset(vis,0,sizeof(vis));
			dfs(1);
			for(int k=1;k<=n;++k)
				if(!vis[k]){
					++ans;
					break;
				}
			j->can=true;
			j->rev->can=true;
		}
	}
	printf("%d",ans>>1);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main () {

    vector<vector<int> > c(3, vector<int>(3, 0));
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> c[i][j];
        }
    }

    vector<int> a(3,0);
    vector<int> b(3,0);
    for (int i = 0; i < 3; i++) {
        b[i] = c[0][i] - a[0];
    }
    for (int i = 1; i < 3; i++) {
        a[i] = c[i][0] - b[0];
    }

    bool ans = true;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            if(a[i] + b[j] != c[i][j]) {
                ans = false;
            } 
        }
    }

    if(ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    } 

    return 0;
}

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

int main()
{
  string a,s,d;
  cin >> a>>s>>d;
  int j = a.size();
  if(a[j-1] ==s[0]&&d[0]==s[s.size()-1])
    cout << "YES" << endl;
    else
      cout << "NO" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;
 
signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  vector<pii> ans;
  int x, y, a, b, c, p;
  cin >> x >> y >> a >> b >> c;
  rep(i, a){
    cin >> p;
    ans.pu(mp(p, 1));
  }
  rep(i, b){
    cin >> p;
    ans.pu(mp(p, 2));
  }
  rep(i, c){
    cin >> p;
    ans.pu(mp(p, 3));
  }
  sort(all(ans), greater<pii>());
  int i = 0, na = 0, su = 0, sum = 0;
  lol nasu = 0;
  while(na + su + sum != x + y){
    if(ans[i].se == 1){
      if(na != x){
	nasu += ans[i].fi;
	na ++;
      }
    }
    if(ans[i].se == 2){
      if(su != y){
	nasu += ans[i].fi;
	su ++;
      }
    }
    if(ans[i].se == 3){
      nasu += ans[i].fi;
      sum ++;
    }
    i ++;
  }
  cout << nasu << '\n';
  return 0;
}


Measured memory_bytes: 6512
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let mut c = vec![0; 9];
    for i in 0..3 {
        let v = read_vec::<i64>();
        for j in 0..3 {
            c[i * 3 + j] = v[j];
        }
    }
    if c[0] - c[1] == c[3] - c[4]
        && c[0] - c[1] == c[6] - c[7]
        && c[1] - c[2] == c[4] - c[5]
        && c[1] - c[2] == c[7] - c[8]
        && c[3] - c[0] == c[4] - c[1]
        && c[3] - c[0] == c[5] - c[2]
        && c[6] - c[3] == c[7] - c[4]
        && c[6] - c[3] == c[8] - c[5]
    {
        println!("Yes");
    } else {
        println!("No");
    }
}

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

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


Measured memory_bytes: 4352
package main

import "fmt"

var N int
var A [][]int

func main() {
	fmt.Scanf("%d", &N)

	A = MakeMatrix(2, N+1)

	for i := 0; i < 2; i++ {
		for j := 1; j <= N; j++ {
			fmt.Scanf("%d", &A[i][j])
		}
	}

	for i := 0; i < 2; i++ {
		for j := 0; j <= N; j++ {
			if j != N {
				A[i][j+1] += A[i][j]
			}
		}
	}

	max := 0
	for j := 1; j <= N; j++ {
		tmp := (A[0][j] - A[0][0]) + (A[1][N] - A[1][j-1])
		max = Max(tmp, max)
	}

	fmt.Println(max)
}

// Library

func MakeMatrix(w, h int) [][]int {
	m := make([][]int, w)
	for x := 0; x < w; x++ {
		m[x] = make([]int, h)
	}

	return m
}

func Max(x, y int) int {
	if x > y {
		return x
	}
	return y
}


Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))
out = [0] * n

x = 0
for i in range(n):
    if i % 2 == 1:
        x -= a[i]
    else:
        x += a[i]
out[0] = x / 2

for i in range(n - 1):
    out[i + 1] = a[i] - out[i]

for i in range(n):
    print(int(2 * out[i]), end=' ')


Measured memory_bytes: 68196
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	string S;
	scan(N>>S);
	int ans=1;
	rep(i,N-1){
		if(S[i]!=S[i+1]) ans++;
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include<algorithm>
#include<deque>
#include<string>
using namespace std;

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)

int main(void){
  string s;
  cin>>s;
  int cond=0,cond1=0,cond2=0;

  if(s.at(0)=='A')cond=1;

  for(int i=2;i<s.size()-1;i++){
    if(s.at(i)=='C')cond1++;
  }

  int x;
  r(i,s.size()){
    x=s.at(i);
    
    if(x-90<=0)cond2++;
  }

  if(cond==1&&cond1==1&cond2==2)cout<<"AC"<<endl;
  else cout<<"WA"<<endl;





return 0;}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

#define INF 1000000000

using namespace std;

vector<vector<pair<int, long long>>> g;
vector<bool> visited;
vector<long long> dist;
queue<int> q;

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

    g = vector<vector<pair<int, long long>>>(N);
    visited = vector<bool>(N, false);
    dist = vector<long long>(N, INF);

    REP(i, M) {
        int s, t;
        cin >> s >> t;

        s--;
        t--;

        int w;
        cin >> w;

        g[s].emplace_back(t, w);
        g[t].emplace_back(s, -w);
    }

    REP(i, N) {
        if (visited[i] == false) {
            q.push(i);

            while (!q.empty()) {
                int p = q.front();
                q.pop();

                for (auto& e : g[p]) {
                    long long next_dist = dist[p] + e.second;
                    if (visited[e.first]) {
                        if (dist[e.first] != next_dist) {
                            cout << "No" << endl;
                            return 0;
                        }
                    } else {
                        dist[e.first] = next_dist;
                        visited[e.first] = true;
                        q.push(e.first);
                    }
                }
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}


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

int n;
int color[200000];
vector<vector<pair<int,int>>> v(200000);
//memset(color,-1,sizeof(color));

void dfs(int n, int pre, int c){
    for(auto x:v[n]){
        
        if(x.first==pre) continue;
        if(x.second%2==0) color[x.first]=c;
        else color[x.first]=1-c;
        dfs(x.first,n,color[x.first]);
    }
}

int main(){
    
    cin >> n;
    
    
    rep(i,n-1){
        int uu,vv,ww;
        cin >> uu >> vv >> ww;
        v[uu-1].push_back(make_pair(vv-1,ww));
        v[vv-1].push_back(make_pair(uu-1,ww));
    }
    color[0]=0;
    dfs(0,-1,0);

    rep(i,n) cout << color[i] << endl;
    
}

Measured memory_bytes: 11520
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

template<class T = int>
class Dinic {
  struct edge {
    int to;
    T cap;
    int rev;
  };
  vector<vector<edge>> graph;
  vector<int> level;
  vector<int> iter;

  void bfs(int s) {
    level.assign(level.size(), -1);
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()) {
      int v = que.front();
      que.pop();
      for(const edge &e: graph[v]) {
        if(e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          que.push(e.to);
        }
      }
    }
  }

  T dfs(int v, int t, T f) {
    if(v == t) return f;
    for(int &i = iter[v]; i < (int)graph[v].size(); i++) {
      edge &e = graph[v][i];
      if(e.cap > 0 && level[v] < level[e.to]) {
        T new_f = f < 0 ? e.cap : min(f, e.cap);
        int d = dfs(e.to, t, new_f);
        if(d > 0) {
          e.cap -= d;
          graph[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

public:
  Dinic(int n) : graph(n), level(n), iter(n) {}

  void add_edge(int from, int to, T cap) {
    graph[from].push_back({to, cap, (int)graph[to].size()});
    graph[to].push_back({from, 0, (int)graph[from].size() - 1});
  }

  T max_flow(int s, int t) {
    T flow = 0;
    while(true) {
      bfs(s);
      if(level[t] < 0) return flow;
      iter.assign(iter.size(), 0);
      T f;
      while((f = dfs(s, t, -1)) > 0) {
        flow += f;
      }
    }
  }
};

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<PI> red(n);
  vector<PI> blue(n);
  FOR(r,red) {
    cin >> r.first >> r.second;
  }
  FOR(b,blue) {
    cin >> b.first >> b.second;
  }
  Dinic<int> g(2 * n + 2);
  REP(i,0,n) {
    g.add_edge(2 * n, i, 1);
  }
  REP(i,n,2*n) {
    g.add_edge(i, 2 * n + 1, 1);
  }
  REP(r,0,n) {
    REP(b,0,n) {
      if(red[r].first < blue[b].first && red[r].second < blue[b].second) {
        g.add_edge(r, b + n, 1);
      }
    }
  }
  cout << g.max_flow(2 * n, 2 * n + 1) << endl;
  
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x <= 1) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
int n,x,y;
int cnt[maxn];
int main(){
 	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> x >> y;
	for(int i = 1;i <= n;i++){
		for(int j = i + 1;j <= n;j++){
			int d = min(abs(j-i),abs(x-i)+1+abs(j-y));
			cnt[d]++;
		} 
	}
	for(int i = 1;i < n;i++) cout << cnt[i] << endl;
	return 0;
}
//do smt instead of nothing! never give up!
//take care of long long!
//take care of upper or lower case e.g "yes" or "YES"?
//boundary condition! e.g. n = 0?
//brute force is always the first choice!
// print the ans to look for patterns in the data!

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<double>a(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    double ans=0;
    for(int i=0;i<n;i++){
        ans+=1/a[i];
    }
    ans=1/ans;
    cout<<ans;
}


Measured memory_bytes: 256
#[allow(dead_code)]
fn main() {
    let nn = i::u();
    let kk = i::u();
    let tt:Vec<usize> = i::uv(nn);
    let mut kakovec:Vec<i64> = vec![0; nn+1];
    let mut vec= Vec::new();
    let mut px:usize=1;
    vec.push(1);
    kakovec[px]=0;
    for  yy in 1..(kk+1) {
        px=tt[px-1];
        if (kakovec[px]!=0){
            //loop
            let mut loosu=(yy as i64)-kakovec[px];
            let mut nokori = (kk as i64 - yy as i64 ) % loosu;
            let mut zan =nokori+kakovec[px];
            println!("{}",vec[zan as usize]);
            return;
        }else{
            vec.push(px);
            kakovec[px]=yy as i64;
        }
    }
    //ループなし
    println!("{}",px);
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}

Measured memory_bytes: 6252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }




int main() {
  double t,x;
  cin >> t >> x;

  cout << t/x << endl;


}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define repi(i,a,b) for(ll i=a; i<=(b); ++i)
#define rrep(i,n) for(ll i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
using Edge = pair<ll,ll>;
using Graph = vector<vector<Edge>>;
typedef pair<ll,ll> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}

ll solve(ll N, string S){
    set<ll> ans;
    rep(i,1000){
        ll a = i/100;
        ll b = (i-a*100)/10;
        ll c = (i-a*100-b*10);

        ll flag = 3;
        rrep(i,N){
            if(flag == 3 && S[i] - '0' == c){
                flag--; continue;
            }
            if(flag == 2 && S[i] - '0' == b){
                flag--; continue;
            }
            if(flag == 1 && S[i] - '0' == a){
                flag--; continue;
            }
        }
        if(flag == 0) ans.insert(100*a+10*b+c);
    }
    return sz(ans);
}

int main(){
    ll N; cin >> N;
    string S; cin >> S;
    pr(solve(N,S));
    return 0;
}

Measured memory_bytes: 384
using System;
 
namespace AtCoder
{
    class ABC117A
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' '); 
            float t = int.Parse(input[0]);
            float x = int.Parse(input[1]);
 
            Console.WriteLine(t / x);
        }      
    }
}

Measured memory_bytes: 13140
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  ll N;
  cin >> N;
  cin >> S;
  ll r = 0;
  ll b = 0;
  REP(i, S.size()) {
    if (S[i] == 'R')
      r++;
    else
      b++;
  }
  if (r > b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  int s1, s2, s3;
  cin >> a;
  s1 = a/100;
  s2 = (a - s1*100)/10;
  s3 = (a - s1*100 - s2*10);
  cout << s1 + s2 + s3 << endl;
}

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

int main(){
    int n;
    cin >> n;
    int a[100];
    int A=0,B=0;
    for(int i=0;i<n;i++)cin >> a[i];
    sort(a,a+n);
    reverse(a,a+n);
    for(int i=0;i<n;i++){
        if(i%2==0)A+=a[i];
        else B+=a[i];
    }
    cout << A-B << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vl l(n),r(n);
    rep(i,n){
        cin >> l[i] >> r[i];
    }
    multiset<ll> lv={l[0]}, rv={l[0]};
    ll ans = 0, lsum = 0, rsum = 0;
    rep(i,n-1){
        lsum += r[i+1]-l[i+1];
        rsum += r[i] - l[i];
        if(l[i+1] < *(--lv.end()) - lsum){
            ans += *(--lv.end()) - lsum - l[i+1];
            rv.insert(*(--lv.end())-lsum-rsum);
            lv.erase((--lv.end()));
            lv.insert(l[i+1]+lsum), lv.insert(l[i+1]+lsum);
        }else if(l[i+1] > *(rv.begin()) + rsum){
            ans += l[i+1] - *(rv.begin()) - rsum;
            lv.insert(*rv.begin()+rsum+lsum);
            rv.erase(rv.begin());
            rv.insert(l[i+1]-rsum), rv.insert(l[i+1]-rsum);
        }else{
            lv.insert(l[i+1]+lsum), rv.insert(l[i+1]-rsum);
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 11264
program prob5
    implicit none
    character(105) :: s
    integer :: n
    integer :: m, i, tmp, q, w

    read(*,*) n,s

    m = 0
    tmp = 0
    q = 0
    w = 0
    do i = 1, n
        if(s(i:i) == '(') then
            tmp = tmp + 1
            q = q + 1
        else
            tmp = tmp - 1
            w = w + 1
        end if
        m = min(m, tmp)
    end do
    
    do i = 1, -m
        write(*,'(a)',advance='no') '('
    end do

    q = q - m
    write(*,'(a)',advance='no') trim(adjustl(s))
    do i = 1, q - w
        write(*,'(a)',advance='no') ')'
    end do
    write(*,*) 


    stop
contains
end program prob5

Measured memory_bytes: 2900
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
#define INF 1000000000
typedef long long int ll;
typedef pair<ll,ll> P;
template <typename T> std::string tostr(const T& t){std::ostringstream os; os<<t; return os.str();}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
 
int main(){ 
    int n,k,l;
    cin>>n>>k>>l;
    vector<vector<int>> v1(n+100);
    vector<vector<int>> v2(n+100);
    for(int i=0;i<k;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        v1[a].push_back(b);v1[b].push_back(a);
    }
    for(int i=0;i<l;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        v2[a].push_back(b);v2[b].push_back(a);
    }
    vector<int> visit1(n+100,0),visit2(n+100,0);
    //BFS×2
    int cnt1=1,cnt2=1;
    for(int i=0;i<n;i++){
        if(visit1[i]!=0){
            continue;
        }
        queue<int> q;
        q.push(i);
        visit1[i]=cnt1;
        while(q.empty()!=1){
            int tmp=q.front(); 
            q.pop();
            for(int j=0;j<v1[tmp].size();j++){
                if(visit1[v1[tmp][j]]==0){
                    q.push(v1[tmp][j]);
                    visit1[v1[tmp][j]]=cnt1;
                }
            }
        }
        cnt1++;
    }
    for(int i=0;i<n;i++){
        if(visit2[i]!=0){
            continue;
        }
        queue<int> q;
        q.push(i);
        visit2[i]=cnt2;
        while(q.empty()!=1){
            int tmp=q.front(); 
            q.pop(); 
            for(int j=0;j<v2[tmp].size();j++){
                if(visit2[v2[tmp][j]]==0){
                    q.push(v2[tmp][j]);
                    visit2[v2[tmp][j]]=cnt2;
                }
            }
        }
        cnt2++;
    }
    map<P,int> mp;
    for(int i=0;i<n;i++){
        mp[{visit1[i],visit2[i]}]++;
    }
    for(int i=0;i<n;i++){
        cout<<mp[{visit1[i],visit2[i]}];
        if(i==n-1) {
            cout<<endl;
        }else{
            cout<<' ';
        }
    }
    return 0;
}

Measured memory_bytes: 27812
n = int(input())
csf = []
for i in range(n - 1):
    csf.append(list(map(int, input().split())))

for i in range(n):
    AnsSec = 0
    Now_Station = i
    while Now_Station < n - 1:
        if AnsSec > csf[Now_Station][1]:
            if AnsSec % csf[Now_Station][2] != 0:
                AnsSec += csf[Now_Station][2] - (AnsSec % csf[Now_Station][2])
        else:
            AnsSec += csf[Now_Station][1] - AnsSec
        AnsSec += csf[Now_Station][0]
        Now_Station += 1
    print(AnsSec)


Measured memory_bytes: 3316
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int N = scanner.nextInt();
        int[][] dp = new int[N+1][3];
        for(int i = 1; i <= N; i++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int c = scanner.nextInt();
            dp[i][0] = Math.max(dp[i-1][1], dp[i-1][2])+a;
            dp[i][1] = Math.max(dp[i-1][0], dp[i-1][2])+b;
            dp[i][2] = Math.max(dp[i-1][1], dp[i-1][0])+c;
        }
        out.println(Math.max(Math.max(dp[N][0], dp[N][1]), dp[N][2]));
        out.flush();
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        
        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
}


Measured memory_bytes: 46592
import java.util.*;
 
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int taka = sc.nextInt();
    int flag1 = 0;
    int flag2 = 0;
    
    if(taka < 1200){
      System.out.print("ABC");
      flag1 = 1;
    }else if(taka < 2800){
      System.out.print("ARC");
      flag2 = 1;
    }
    
    if(flag1 == 0 && flag2 == 0){
      System.out.print("AGC");
    }
  }
}

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

ll N, M, AI, BI, indeg[100005], dp[100005];
vector<ll> G[100005];
queue<ll> Q;

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

	cin >> N >> M;
	for (ll i = 0; i < M; i++) {
		cin >> AI >> BI;
		indeg[BI]++;
		G[AI].push_back(BI);
	}

	for (ll i = 1; i <= N; i++) {
		if (indeg[i] == 0) {
			Q.push(i);
		}
	}

	ll ans = 0;
	while (!Q.empty()) {
		ll f = Q.front(); Q.pop();
		for (ll i = 0; i < G[f].size(); i++) {
			indeg[G[f][i]]--;
			dp[G[f][i]] = max(dp[G[f][i]], dp[f]+1);
			ans = max(ans, dp[G[f][i]]);
			if (indeg[G[f][i]] == 0) {
				Q.push(G[f][i]);
			}
		}
	}

	cout << ans << "\n";

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)
#define All(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define End '\n'
#define Out(x) cout<<(x)<<End
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

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

    ll a, b;
    int k;

    cin >> a >> b >> k;

    while (k) {
        if (a % 2 == 1) a--;

        b += a / 2;
        a /= 2;

        k--;

        if (k <= 0) break;

        if (b % 2 == 1) b--;

        a += b / 2;
        b /= 2;

        k--;
    }

    cout << a << " " << b << End;

    return 0;
}


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

#define MAX 100000

int N;
long long a[MAX * 3];

long long sumL[MAX + 1];
long long sumR[MAX + 1];
priority_queue< long long, vector< long long >, greater< long long > > queL;
priority_queue< long long, vector< long long > > queR;


int main()
{
	cin >> N;
	for( int i = 0; i < N * 3; i++ ) {
		cin >> a[i];
	}

	for( int i = 0; i < N; i++ ) {
		queL.push( a[i] );
		sumL[0] += a[i];
	}
	for( int i = 0; i < N; i++ ) {
		int n = N + i;
		queL.push( a[n] );
		long long s = queL.top();
		queL.pop();
		sumL[i + 1] = sumL[i] + a[n] - s;
	}
	for( int i = 0; i < N; i++ ) {
		int n = N * 2 + i;
		queR.push( a[n] );
		sumR[0] += a[n];
	}
	for( int i = 0; i < N; i++ ) {
		int n = N * 2 - i - 1;
		queR.push( a[n] );
		long long s = queR.top();
		queR.pop();
		sumR[i + 1] = sumR[i] + a[n] - s;
	}
	reverse( sumR, sumR + N + 1 );
	long long ans = INT64_MIN;
	for( int i = 0; i < N + 1; i++ ) {
		ans = max( ans, sumL[i] - sumR[i] );
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5876
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using ld = long double;
int n;
ld dp[305][305][305];

ld memo_rec(int One, int Two, int Three){
    if(dp[One][Two][Three] != -1)   return dp[One][Two][Three];
    if(One + Two + Three == 0)  return dp[One][Two][Three] = 0.0;
    
    ld res = n;
    if(One > 0) res += memo_rec(One - 1, Two, Three) * One;
    if(Two > 0) res += memo_rec(One + 1, Two - 1, Three) * Two;
    if(Three > 0)   res += memo_rec(One, Two + 1, Three - 1) * Three;
    res *= 1.0 / (One + Two + Three);

    return dp[One][Two][Three] = res;
}

int main(){
    cin >> n;
    vector<int> cnt(4, 0);
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        ++cnt[a];
    }
    
    for(int i = 0; i <= 300; ++i){
        for(int j = 0; j <= 300; ++j){
            for(int k = 0; k <= 300; ++k){
                dp[i][j][k] = -1;
            }
        }
    }

    cout << fixed << setprecision(15);
    cout << memo_rec(cnt[1], cnt[2], cnt[3]) << endl;
}

Measured memory_bytes: 438528