akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int h=sc.nextInt();
        int w=sc.nextInt();
        char[][] f=new char[h][w];
        for (int i = 0; i < h; i++) {
            String t=sc.next();
            for (int j = 0; j < w; j++) {
                f[i][j]=t.charAt(j);
            }
        }
        long ans=0;
        int[] dx={-1,0,1,0};
        int[] dy={0,-1,0,1};
        int[][] node=new int[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if(node[i][j]==0) {
                    Queue<Point> q = new ArrayDeque<>();
                    if(f[i][j]=='#'){
                        q.add(new Point(i, j));
                        node[i][j]++;
                    }
                    long tempW = 0, tempB = 0;
                    while (!q.isEmpty()) {
                        Point p = q.poll();
                        if (f[p.x][p.y] == '.') tempW++;
                        else tempB++;
                        for (int k = 0; k < 4; k++) {
                            int x = p.x + dx[k];
                            int y = p.y + dy[k];
                            if (0 <= x && x < h && 0 <= y && y < w) {
                                if (node[x][y] == 0 && f[p.x][p.y] != f[x][y]) {
                                    q.add(new Point(x, y));
                                    node[x][y]++;
                                }
                            }
                        }
                    }
                    ans += tempB * tempW;
                }
            }
        }
        out.println(ans);
    }
}


Measured memory_bytes: 46640
#include<iostream>
using namespace std;
main()
{
    int n,m;cin>>n>>m;
    int a[n+1];
    for(int i=0;i<=n;i++)a[i]=0;
    for(int i=0;i<m;i++)
    {
        int s,t;cin>>s>>t;
        a[--s]++,a[t]--;
    }
    for(int i=0;i<n;i++)a[i+1]+=a[i];
    int ret=0;
    for(int i=0;i<=n;i++)ret+=a[i]==m;
    printf( "%d\n",ret);

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N,M;
    cin >> N >> M;
    vector<vector<ll>> jobs(M+1);
    for(int i=0;i<N;i++){
        int a,b;
        cin >> a >> b;
        if(a>M)continue;
        jobs[a].push_back(b);
    }
    priority_queue<int> q;
    ll ans = 0;
    for(int i=0;i<=M;i++){
        for(int b:jobs[i]){
            q.push(b);
        }
        if(!q.empty()){
            ans += q.top();
            q.pop();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5632
from collections import Counter
n,k=map(int, input().split())
a=list(map(int, input().split()))
b=Counter(a)
count=0
now=0
for i in sorted(b):
    count+=now*b[i]
    now+=b[i]
count*=(k-1)*k//2
c=[]
count2=0
import bisect
for i in a[::-1]:
    count2+=bisect.bisect_left(c,i)
    bisect.insort(c, i)
count2*=k
print((count+count2)%(10**9+7))

Measured memory_bytes: 3572
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>

#define INF_LL 9000000000000000000
#define INF 2000000000

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

struct edge{int to, cost; };

int main(void){
	int a[200];
	int tmp[200];
	int n, m;
	cin >> n >> m;
	REP(i, 2*n){
		a[i] = i+1;
	}
	REP(t, m){
		int k;
		cin >> k;
		if(k == 0){
			REP(i, 2*n){
				int index = (i*2)%(2*n);
				if(i >= n) index++;
				tmp[index] = a[i];
			}
			REP(i, 2*n){
				a[i] = tmp[i];
			}
		}else{
			REP(i, k){
				tmp[2*n-k+i] = a[i];
			}
			FOR(i, k, 2*n){
				tmp[i-k] = a[i];
			}
			REP(i, 2*n){
				a[i] = tmp[i];
			}
		}
	}
	REP(i, 2*n){
		cout << a[i] << endl;
	}
}

Measured memory_bytes: 3096
import java.util.*

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    val aas = scan.nextLine().split(" ").map{ it.trim().toString() }.toTypedArray()
    val aai = scan.nextLine().split(" ").map { it.trim().toInt() }.toTypedArray()
    val q = scan.nextLine().toString()

    if(q==aas[0])
        aai[0]--;
    else
        aai[1]--;

    var a=aai[0];
    var b=aai[1];
    print("$a $b")
}


Measured memory_bytes: 36084
X,K,D = list(map(int,input().split()))
X = abs(X)
count = K
x = X
mx = X//D

if mx<=K:
    x = X-(mx-1)*D
    count -= mx-1
else:
    x = X-(K-1)*D
    count -= K-1

ans = abs(x)
while x>0 and count>0:
    x -= D
    count -= 1
    if abs(x)<ans and count%2==0:
        ans = abs(x)

print(ans)

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

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

    int ramen_nedan = 700;
    for(int i=0; i < 3; i++){
        if(S[i] == 'o') ramen_nedan += 100;
    }
    cout << ramen_nedan << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ll long long

int main(void){
	int x=0;
	int ans=0;
	int n;
	char str[101];
	scanf("%d",&n);
	scanf("%s",str);
	for(int i=0;i<n;i++){
	    if(str[i]=='I') x++;
	    else x--;
	    ans = MAX(ans,x);
	}
	printf("%d\n",ans);
    return 0;
}

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

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        String s[]=bu.readLine().split(" ");
        int n=Integer.parseInt(s[0]),i,a[]=new int[n+1];
        long k=Long.parseLong(s[1]);
        s=bu.readLine().split(" ");
        int pos=1,l=1;
        for(i=0;i<n;i++)
            a[i+1]=Integer.parseInt(s[i]);
        ArrayList<Integer> path=new ArrayList<>();
        HashMap<Integer,Integer> hm=new HashMap<>();
        path.add(1);
        hm.put(1,1);
        while(true)
        {
            pos=a[pos];
            if(hm.get(pos)==null)
            {
                path.add(pos);
                hm.put(pos,path.size());
            }
            else {l=hm.get(pos); break;}
        }
        if(k<path.size()) {System.out.print(a[path.get((int)(k-1))]); return;}
        l--;
        k-=l;
        k%=(path.size()-l);
        k--;
        if(k==-1) k=path.size()-l-1;
        System.out.print(a[path.get((int)(l+k))]);
    }
}


Measured memory_bytes: 71192
#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>

#define MAX 10000
#define INFTY 1<<30 // 2^30
#define N 3
#define N2 9  // N * N
#define REP(i,n) for(int i=0;i<n;i++)

/*
priority_queue<> pq
 push()  pop() size()  top()
map<>
 find() begin() end() insert(map<>::value_type())
pair<>
sort(.begin(), .end())
sort(arr, arr+N)
sort(a, a+N, greater<int>())
binary_search(vc.begin(), vc.end(), x)  //binary_search???true, false?????????
vector<int>::iterator lit = lower_bound(vc.begin(), vc.end(), x);
  lower_bound?????????????????????"??\???"????????????????????????????????????????????¬???????????????
vector<int>::iterator uit = upper_bound(vc.begin(), vc.end(), x);
  upper_bound????????????????????????"?¶???????"?????????????????????????????????????????¬???????????????
*/


using namespace std;

typedef long long llong;

struct Puzzle
{
  int f[N2];
  int space;
  string path;

  bool operator < (const Puzzle &p) const
  {
    for(int i = 0; i < N2; i++)
    {
      if(f[i] == p.f[i]) continue;
      return f[i] > p.f[i];
    }
    return false;
  }
};
/*
  1 3 2       1 2 3
  4 5 6   <   4 5 6
  7 8 9       7 8 9
  : true
  1 2 3       1 3 2
  4 5 6   <   4 5 6
  7 8 9       7 8 9
  : false
  ??¨??¨??????
  : false
*/

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const char dir[4] = {'u', 'l', 'd', 'r'};

bool isTarget(Puzzle p)
{
  for(int i = 0; i< N2; i++)
    if(p.f[i] != (i + 1)) return false;
  return true;
}

string bfs(Puzzle s)
{
  queue<Puzzle> Q;
  map<Puzzle, bool> V;
  Puzzle u, v;
  s.path = "";
  Q.push(s);
  V[s] = true;

  while(!Q.empty())
  {
    u = Q.front(); Q.pop();
    if(isTarget(u)) return u.path;
    int sx = u.space / N;
    int sy = u.space % N;
    for(int r = 0; r < 4; r++)
    {
      int tx = sx + dx[r];
      int ty = sy + dy[r];
      if(tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
      v = u;
      swap(v.f[u.space], v.f[tx*N+ty]);
      v.space = tx*N+ty;
      if(!V[v])
      {
        V[v] = true;
        v.path += dir[r];
        Q.push(v);
      }
    }
  }
  return "unsolvable";
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // FROM HERE
  Puzzle in;
  for(int i = 0; i < N2; i++)
  {
    cin >> in.f[i];
    if(in.f[i] == 0)
    {
      in.f[i] = N2;
      in.space = i;
    }
  }
  string ans = bfs(in);
  cout << ans.size() << endl; 
  //cerr << bfs(in) << endl;
  // END
  return 0;
}

Measured memory_bytes: 28664
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] attendA = new int[3];
		int[] leavA = new int[3];
		
		int[] attendB = new int[3];
		int[] leavB = new int[3];
		
		int[] attendC = new int[3];
		int[] leavC = new int[3];
		
		for(int i = 0; i < 3; i++) {
			attendA[i] = sc.nextInt();
		}
		
		for(int i = 0; i < 3; i++) {
			leavA[i] = sc.nextInt();
		}
		
		for(int i = 0; i < 3; i++) {
			attendB[i] = sc.nextInt();
		}
		
		for(int i = 0; i < 3; i++) {
			leavB[i] = sc.nextInt();
		}
		
		for(int i = 0; i < 3; i++) {
			attendC[i] = sc.nextInt();
		}
		
		for(int i = 0; i < 3; i++) {
			leavC[i] = sc.nextInt();
		}
		
		attendA[0]*=3600;
		attendB[0]*=3600;
		attendC[0]*=3600;
		
		leavA[0]*=3600;
		leavB[0]*=3600;
		leavC[0]*=3600;
		
		attendA[1]*=60;
		attendB[1]*=60;
		attendC[1]*=60;
		
		leavA[1]*=60;
		leavB[1]*=60;
		leavC[1]*=60;
		
		int atdSumA = 0;
		int atdSumB = 0;
		int atdSumC = 0;
		
		for(int i = 0; i < 3; i++) {
			atdSumA+=attendA[i];
			atdSumB+=attendB[i];
			atdSumC+=attendC[i];
		}
		
		int lvSumA = 0;
		int lvSumB = 0;
		int lvSumC = 0;
		
		for(int i = 0; i < 3; i++) {
			lvSumA+=leavA[i];
			lvSumB+=leavB[i];
			lvSumC+=leavC[i];
		}
		
		int subA = lvSumA - atdSumA;
		int subB = lvSumB - atdSumB;
		int subC = lvSumC - atdSumC;
		
		int[] inA = new int[]{0, 0, 0};
		int[] inB = new int[]{0, 0, 0};
		int[] inC = new int[]{0, 0, 0};
		
		while(subA > 0) {
			if(subA >= 3600) {
				subA-=3600;
				inA[0]++;
			} else if(subA >= 60) {
				subA-=60;
				inA[1]++;
			} else {
				subA--;
				inA[2]++;
			}
		}
		
		while(subB > 0) {
			if(subB >= 3600) {
				subB-=3600;
				inB[0]++;
			} else if(subB >= 60) {
				subB-=60;
				inB[1]++;
			} else {
				subB--;
				inB[2]++;
			}
		}
		
		while(subC > 0) {
			if(subC >= 3600) {
				subC-=3600;
				inC[0]++;
			} else if(subC >= 60) {
				subC-=60;
				inC[1]++;
			} else {
				subC--;
				inC[2]++;
			}
		}
		
		for(int i = 0; i < 3; i++) {
			if(i == 2) {
				System.out.print(inA[i]);
			} else {
				System.out.print(inA[i] + " ");
			}
		}
		
		System.out.println();
		
		for(int i = 0; i < 3; i++) {
			if(i == 2) {
				System.out.print(inB[i]);
			} else {
				System.out.print(inB[i] + " ");
			}
		}
		
		System.out.println();
		
		for(int i = 0; i < 3; i++) {
			if(i == 2) {
				System.out.print(inC[i]);
			} else {
				System.out.print(inC[i] + " ");
			}
		}
		
		System.out.println();
	}
}

Measured memory_bytes: 26088
A,B,C=map(int,input().split())
#755の時の検証
if 7==A: 
    if 5==B:
        if 5==C:
            print("YES")
        else:
            print("NO")
    elif 5==C:
        if 5==B:
            print("YES")
        else:
            print("NO")
    else:
        print("NO")
#575の時の検証
elif 7==B: 
    if 5==A:
        if 5==C:
            print("YES")
        else:
            print("NO")
    elif 5==C:
        if 5==A:
            print("YES")
        else:
            print("NO")
    else:
        print("NO")
#557の時の検証
elif 7==C: 
    if 5==B:
        if 5==A:
            print("YES")
        else:
            print("NO")
    elif 5==A:
        if 5==B:
            print("YES")
        else:
            print("NO")
    else:
        print("NO")

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

struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))
//#define int long long

signed main(){
    int n; cin >> n;
    vector<bitset<10>> f(n);
    vector<vector<int>> p(n,vector<int>(11));
    rep(i,n){
        string s = "";
        rep(j,10){
            char c; cin >> c;
            s.push_back(c);
        }
        f[i] = bitset<10>(s);
    }
    rep(i,n)rep(j,11) cin >> p[i][j];
    
    bitset<10> b;
    int ans = INT_MIN;
    reps(i, 1, (1 << 10) -1){
        b = i;
        int x = 0;
        rep(j,n){
            bitset<10> t = b & f[j];
            x += p[j][t.count()];
        }
        ans = max(ans, x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n-1],
    }
    let mut b = vec![0 as usize; n];
    for i in 0..a.len() {
        b[a[i] - 1] += 1;
    }
    for i in 0..b.len() {
        println!("{}", b[i]);
    }
}


Measured memory_bytes: 6236
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
 
int main()
{
  int n,x,t;
  cin >> n >> x >> t;
  int ans;
  if(n%x == 0) ans = n / x *t;
  else ans = (n/x +1) * t;
 
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;
import java.util.Arrays;

class Main{
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		
		while(true){
			int h = scanner.nextInt();
			int w = scanner.nextInt();
			
			if(h == 0 && w == 0){
				break;
			}

			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					sb.append("#");
				}
				sb.append("\n");
			}
			sb.append("\n");
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 27584
#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
bool canleft[N][N], canright[N][N];
int n, K;
int a[N];
bool can[N];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n >> K;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	canleft[0][0] = 1;
	for(int i = 1; i <= n - 1; i++){
		for(int j = 0; j < N; j++){
			canleft[i][j] = canleft[i - 1][j];
			if(j >= a[i])
				canleft[i][j] |= canleft[i - 1][j - a[i]];
		}
	}
	canright[n + 1][0] = 1;
	for(int i = n; i >= 2; i--){
		for(int j = 0; j < N; j++){
			canright[i][j] = canright[i + 1][j];
			if(j >= a[i])
				canright[i][j] |= canright[i + 1][j - a[i]];
		}
	}
	int cnt = 0;
	for(int i = 1; i <= n; i++){
		bool nece = false;
		vector<int> A, B;
		for(int j = 0; j < N; j++)
			if(canleft[i - 1][j]) A.push_back(j);
		for(int j = 0; j < N; j++)
			if(canright[i + 1][j]) B.push_back(j);
		for(int val : A){
			int tmp = K - a[i] - val;
			vector<int>::iterator it = lower_bound(B.begin(), B.end(), tmp);
			if(it != B.end()){
				if((*it) + val < K)
					nece = true;
			}
		}
		if(!nece) cnt++;
	}
	cout << cnt << "\n";
	return 0;
}


Measured memory_bytes: 49408
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int m=sc.nextInt();
    int[][] a=new int[m][];
    for(int i=0;i<m;i++){
      int k=sc.nextInt();
      a[i]=new int[k];
      for(int j=0;j<k;j++){
        a[i][j]=sc.nextInt()-1;
      }
    }
    int[] p=new int[m];
    for(int i=0;i<m;i++){
      p[i]=sc.nextInt();
    }
    int ans=0;
    Deque<E> dq=new ArrayDeque<>();
    dq.add(new E(n));
    while(!dq.isEmpty()){
      E here=dq.pollFirst();
      if(here.fixed<n){
        dq.add(here.nT());
        dq.add(here.nF());
        continue;
      }
//      System.err.println(Arrays.toString(here.sw));
      boolean flag=true;
      for(int i=0;i<m;i++){
        int cnt=0;
        for(int j=0;j<a[i].length;j++){
          cnt+=here.sw[a[i][j]]?1:0;
        }
        if((cnt&1)!=p[i]){
          flag=false;
          break;
        }
      }
      if(flag){
        ans++;
      }
    }
    System.out.println(ans);
  }
  static class E{
    boolean[] sw;
    int fixed=0;
    E(int n){
      sw=new boolean[n];
    }
    E nT(){
      E res=new E(sw.length);
      for(int i=0;i<fixed;i++){
        res.sw[i]=sw[i];
      }
      res.sw[fixed]=true;
      res.fixed=fixed+1;
      return res;
    }
    E nF(){
      E res=new E(sw.length);
      for(int i=0;i<fixed;i++){
        res.sw[i]=sw[i];
      }
      res.fixed=fixed+1;
      return res;
    }
  }
}

Measured memory_bytes: 22608
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int b[100005];



int getp(int x)
{
    if(b[x]==x)return x;
    else
    {
        int p=getp(b[x]);
        b[x]=p;
        return p;
    }

}
bool can(int x,int y)
{
    if(getp(x)==getp(y))return true;
    else return false;
}
void seti(int x,int y)
{
    if(x==y)return;
    if(x>y)
    {
        x=x^y;
        y=x^y;
        x=x^y;
    }
    int px=getp(x);
    int py=getp(y);
    if(px!=py)
    {
        int t=px<py?px:py;
        b[px]=b[py]=t;
    }
    else return;


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

    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i+1]);
        b[i+1]=i+1;
    }
    for(int i=0; i<m; i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        seti(x,y);
    }
    int res=0;
    for(int i=1; i<=n; i++)
    {
        if(a[i]==i)res++;
        else if(can(a[i],i))res++;
    }
    printf("%d",res);


}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <unordered_map>
#include <queue>
#define MOD 1000000007
#define REP(i,st,num)for(int i=(st);i<(num);++i)
#define ll long long
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    ll N,M,A[100001],s[100001],ans=0;
    cin>>N>>M;
    REP(i,0,N) {
        cin>>A[i];
    }
    s[0]=0;
    unordered_map<ll, ll> mp;
    mp[0]=1;
    REP(i,0,N) {
        s[i+1]=(A[i]+s[i])%M;
    }
    REP(i,1,N+1) {
        mp[s[i]]++;
        ans+=mp[s[i]]-1;
    }
    cout<<ans;
    // 4 1 5
    // logMA[i]
    // 0 1 1
    // 0 1 2
    return 0;
}

Measured memory_bytes: 5260
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}



void getCost(int parent,int node,vi &cost,vvi &child,QP &q) {
  cout << parent + cost[node] << endl;
  int c = parent + cost[node];
  rep(i,sz(child[node])) {
    q.push(make_pair(c,child[node][i]));
  }
}
  
int main() {
  int N,q;
  cin >> N >>q;
  vvi child(N);
  rep(i,N-1) {
    int a,b;
    cin >> a >> b;
    child[a-1].push_back(b-1);
  }
  rep(i,N) {
    sort(rng(child[i]));
  }
  vi cost(q,0);
  rep(i,q) {
    int p,x;
    cin >> p >> x;
    cost[p-1] += x;
  }
  vi ans(N);
  QP p;
  p.push(make_pair(0,0));
  while(!p.empty()) {
    P pai = p.front();
    p.pop();
    int parent = pai.first;
    int node = pai.second;
    ans[node] = parent + cost[node];
    int c = parent + cost[node];
    rep(i,sz(child[node])) {
      p.push(make_pair(c,child[node][i]));
    }
  }
  cout << ans[0];
  srep(i,1,N) {
    cout << " " << ans[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 14848
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG=20;

ll n, m, k, u, v, x, y, t, a, b, ans=1;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>m;
	if (n==1) kill(m)
	for (ll p=2; p*p<=m; p++) if (m%p==0){
		int t=0;
		while (m%p==0){
			m/=p;
			t++;
			if (t==n){
				t=0;
				ans*=p;
			}
		}
	}
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#define V(time) (9.8*time)
#define YT(height) (sqrt(height/4.9)) 
using namespace std;
int main(){
  double broken;
  while(cin>>broken){
    double hv[1000]={};
    for(int i=1;i<1000;i++)
      hv[i]=V(YT((i-1)*5));
    for(int i=1;i<1000;i++){
      if(hv[i]>=broken){
	cout<<i<<endl;
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3112
# -*- coding: utf-8 -*-
h, w = map(int, input().split())
a = []
a = [[True] * (w + 2)]
for i in range(h):
    a.append([True] + [x == '#' for x in input()] + [True])
a.append([True] * (w + 2))
q = []

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if a[i][j]:
            q.append((i, j))

count = 0
while True:
    qq = []
    for i, j in q:
        if not a[i-1][j]:
            a[i-1][j] = True
            qq.append((i - 1, j))
        if not a[i+1][j]:
            a[i+1][j] = True
            qq.append((i + 1, j))
        if not a[i][j-1]:
            a[i][j-1] = True
            qq.append((i, j - 1))
        if not a[i][j+1]:
            a[i][j+1] = True
            qq.append((i, j + 1))
    q = qq
    if len(q) <= 0:
        break
    count += 1

print(count)


Measured memory_bytes: 108028
#include<math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define ull unsigned long long
#define py printf("Yes\n")
#define pn printf("No\n")
#define in cin>>
using namespace std;
int INF = 1001001001;
const int MOD=1e9+7;
int main(void) {
  int n,k;
  int x[100];
  in n>>k;
  rep(i,n)
  {
    in x[i];
  }
  int ans=0;
  rep(i,n)
  {
    int tmp = min(x[i],k-x[i]);
    ans+=tmp;
  }
  cout<<ans*2<<endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

typedef long long ll;

int main() {
    ll n;
    scanf("%lld", &n);
    vector<ll> a(n), b(n), c(n);
    for (ll i = 0; i < n; ++i) scanf("%lld", a.begin() + i);
    for (ll i = 0; i < n; ++i) scanf("%lld", b.begin() + i);
    for (ll i = 0; i < n; ++i) scanf("%lld", c.begin() + i);
    sort(a.begin(), a.end());
    sort(c.begin(), c.end());
    printf("%lld\n", accumulate(b.begin(), b.end(), 0LL, [a, c](ll init, ll i){ return init += (lower_bound(a.begin(), a.end(), i) - a.begin()) * (c.end() - upper_bound(c.begin(), c.end(), i)); }));
    return 0;
}


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

char t[100001];
char tt[100001];

int main() {
	int		a,b,c,i,j,k,n,m,x,y,r,s,p;
	long long	ans = 0;

	
	cin >> n;
	cin >> k;
	cin >> r;
	cin >> s;
	cin >> p;
	scanf("%s", t);
	

	for(i=0;i<n;i++) {
		if (i>=k) {
			if (t[i] == 'r') {
				if (tt[i-k] == 'p') { tt[i] = 'P'; continue; }
				else { ans += p; tt[i] = 'p'; continue; }
			}
			if (t[i] == 's') {
				if (tt[i-k] == 'r') { tt[i] = 'R'; continue; }
				else { ans += r; tt[i] = 'r'; continue; }
			}
			if (t[i] == 'p') {
				if (tt[i-k] == 's') { tt[i] = 'S'; continue; }
				else { ans += s; tt[i] = 's'; continue; }
			}
		} else {
			if (t[i] == 'r') { ans += p; tt[i] = 'p'; }
			if (t[i] == 's') { ans += r; tt[i] = 'r'; }
			if (t[i] == 'p') { ans += s; tt[i] = 's'; }
		}
		//cout << ans << endl;
	}
	
	cout << ans << endl;

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;long long q[33][305],A=0,all;int p[7],a[7],n,c,g;
inline void S(){int i,j,k,t=(1<<(n-1))-1,o,l;for(i=0;i<g;i++){if(i%n==0)continue;o=p[i%n];l=min(g,a[o]*n+i);o=1<<(o-1);for(j=t;j>=0;j--)if(!(o&j))for(k=g;k>=i;k--)q[j|o][max(k,l)]+=q[j][k];}A+=q[t][g];}
main(){int i,N=0;scanf("%d%d",&n,&c);g=n*c;for(i=1;i<=n;i++)scanf("%d",&a[i]);sort(a+1,a+n+1);for(i=1;i<=n-1;i++)p[i]=i;do{memset(q,0,sizeof(q));q[0][a[n]*n]=1;S();N++;}while(next_permutation(p+1,p+n));double R=1.0/N;for(i=1;i<=n-1;i++)R*=(1.0/c);printf ("%.12lf\n",R*A);}

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

int debug = 1;


int main(){
    ll a,b,n,x;
    ll ans;
    cin >> a >>b>>n;

    if( b== 1){
        ans = 0;
    }else if(a ==1){
        ans = 0;
    }else{
        if(n<b-1){
            x=n;
            ans = floor(a*x/b)-a*floor(x/b);
        }else {
            x=b-1;
            ans = floor(a*x/b)-a*floor(x/b);
        }
    }

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

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

int N, K, height[100005];
int dp[100005];

int diff(int x, int y) {
	if (x>y) {
		return x-y;
	}
	return y-x;
}

int solve(int i) {
	if (i >= N) {
		return -1;
	}
	
	if (dp[i] != INT_MAX) {
		return dp[i];
	}
	
	for(int j=i+1;j<=K+i;j++) {
		if (j<N) {
			dp[i] = min(dp[i], diff(height[j], height[i]) + solve(j));
		}
	}
	
	return dp[i];
}


int main() {
	for(int i=0;i<100005;i++) {
		dp[i] = INT_MAX;
	}
	cin>>N>>K;
	for(int i=0;i<N;i++) {
		cin>>height[i];
	}
	
	dp[N-1] = 0;
	if (N>1) {
		dp[N-2] = diff(height[N-1], height[N-2]);
	}
	
	cout<<solve(0);
}

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

namespace ConsoleApp2
{

    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = input[0];
            int B = input[1];
            int C = input[2];

            int x = A - B;
            int y = C - x;
            if(y<0)
                Console.WriteLine(0);
            else
            Console.WriteLine(y);
        }
    }
}

Measured memory_bytes: 28284
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
    ll n, k; cin >> n >> k;
    vector<ll> a(n);
    vector<ll> f(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> f[i];
    sort(a.begin(), a.end());
    sort(f.rbegin(), f.rend());
    // binary search
    ll l = 0, r = 1e12;
    while (l < r) {
        ll mid = l + (r-l)/2;   // total cost
        ll need = 0;
        rep(i, n) need += max(0ll, a[i]-mid/f[i]);
        if (need <= k) r = mid;
        else l = mid + 1;
    }
    cout << l << endl;
    return 0;
}

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

using namespace std;

using ll=long long;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
constexpr int mo = 1e9+7;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    cin>>n;
    vector<pair<string,int>> v(n);
    for(auto &a : v) cin>>a.first >> a.second;
    string x;cin>>x;
    int sum = 0;
    bool ok = false;
    for(int i=0;i<n;++i){
        if(ok)sum += v[i].second;
        if(v[i].first == x){
            ok = true;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>

typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;

ll partition(pair<char,ll> A[], ll p, ll r){
    ll x = A[r].second;
    ll i = p-1;
    for(ll j = p; j < r;j++){
        if(A[j].second <= x){
            i = i+1;
            swap(A[i],A[j]);
        }
    }
    swap(A[i+1],A[r]);
    return i+1;
}

void quickSort(pair<char,ll> A[], ll p, ll r){
    if(p < r){
        ll q = partition(A, p, r);
        quickSort(A,p,q-1);
        quickSort(A,q+1,r);
    }
}

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

    ll n;
    cin >> n;
    pair<char,ll> A[n];
    map<ll,list<char> > a;
    for(int i = 0; i < n;i++){
        cin >> A[i].first >> A[i].second;
        a[A[i].second].push_back(A[i].first);
    }

    quickSort(A,0,n-1);

    bool isStable = true;

    for(int i = 0; i < n;i++){
        if(A[i].first != a[A[i].second].front()){
            isStable = false;
            break;
        }
        a[A[i].second].pop_front();
    }
    
    if(isStable) cout << "Stable" << endl;
    else cout << "Not stable" << endl;
    for(int i = 0; i < n;i++){
        cout << A[i].first <<  " " << A[i].second << endl;
    }


    return 0;
}


Measured memory_bytes: 9384
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1000+5,dx[]={0,0,1},dy[]={0,1,0},dz[]={1,0,0};
bool cmp(ll x,ll y)//从大到小
{
    return x>y;
}
struct P{
    int x,y,z;
    ll w;
    P(){};
    P(int a,int b,int c,ll ww)
    {
        x=a;y=b;z=c;w=ww;
    }
    friend bool operator<(const P &p1,const P &p2)//从大到小
    {
        return p1.w<p2.w;
    }
};
priority_queue<P>q;
ll a[N],b[N],c[N];
int k;
map<ll,int>mmp;
ll zh(int x,int y,int z)//将x,y,z转换成一个长整型，用来映射
{
    return x*100000000+y*10000+z;
}
int x,y,z;
 
void bfs()
{
    mmp[0]=1;
    q.push(P(0,0,0,a[0]+b[0]+c[0]));
    while(!q.empty()&&k)
    {
        P p=q.top();
        q.pop();
        k--;
        printf("%lld\n",p.w);
        for(int i=0;i<3;i++)
        {
            int nx=p.x+dx[i],ny=p.y+dy[i],nz=p.z+dz[i];
            if(nx<x&&ny<y&&nz<z&&!mmp[zh(nx,ny,nz)])
            {
                mmp[zh(nx,ny,nz)]=1;
                q.push(P(nx,ny,nz,a[nx]+b[ny]+c[nz]));
            }
        }
    }
    while(!q.empty()){
        q.pop();
    }
 
}
int main()
{
 
    scanf("%d%d%d%d",&x,&y,&z,&k);
    for(int i=0;i<x;i++)
    {
        scanf("%lld",&a[i]);
    }
    for(int i=0;i<y;i++)
    {
        scanf("%lld",&b[i]);
    }
    for(int i=0;i<z;i++)
    {
        scanf("%lld",&c[i]);
    }
    sort(a,a+x,cmp);
    sort(b,b+y,cmp);
    sort(c,c+z,cmp);
    bfs();
    return 0;
}


Measured memory_bytes: 768
#include<string>
#include<sstream>
#include<iostream>
using namespace std;
int main(){
	for(int m,n;cin>>m>>n,m;){
		static bool flg[1000];
		static int bef[1000],nxt[1000];
		for(int i=0;i<m;i++)	flg[i]=true,bef[i]=(i+m-1)%m,nxt[i]=(i+1)%m;
		int pos=0,num=m;
		for(int i=1;i<=n;i++){
			string s;	cin>>s;
			if(num==1)	continue;
			bool ok=1;
			if(i%15==0){	if(s!="FizzBuzz")	ok=0;	}
			else if(i%3==0){	if(s!="Fizz")	ok=0;	}
			else if(i%5==0){	if(s!="Buzz")	ok=0;	}
			else{
				stringstream ss;	ss<<i;
				if(s!=ss.str())	ok=0;
			}
			if(!ok){
				flg[pos]=0;
				int tmpb=bef[pos],tmpn=nxt[pos];
				bef[tmpn]=tmpb;
				nxt[tmpb]=tmpn;
				num--;
			}pos=nxt[pos];
		}
		for(int i=0,j=0;i<m;i++)if(flg[i])	cout<<(j++?" ":"")<<i+1;
		cout<<endl;
	}
}


Measured memory_bytes: 3028
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>

template <class Tp>
class prefix_accumulator {
  std::vector<size_t> lsuf, pf;
  std::vector<Tp> c;

  void precalc() {
    size_t n = c.size()-1;
    std::vector<size_t> msf(n+1);
    size_t f0 = 1;
    size_t f1 = 1;
    pf[1] = 1;
    for (size_t i = 1; i <= n; ++i) {
      if (i == f1) {
        std::swap(f0 += f1, f1);
        if (f1 <= n) pf[f1] = f0;
      }
      msf[i] = f0;
      lsuf[i] = (i > msf[i])? lsuf[i-msf[i]] : i;
    }
    return;

    for (size_t i = 1; i <= n; ++i)
      fprintf(stderr, "%zu: %zu/%zu\n", i, msf[i], lsuf[i]);
  }

public:
  prefix_accumulator(size_t n): lsuf(n+1), pf(n+1), c(n+1) {
    precalc();
  }

  void update(size_t i, Tp x) {
    // a[i] += x;
    ++i;
    while (i < c.size()) {
      c[i] += x;
      i += pf[lsuf[i]];
    }
  }

  Tp accumulate(size_t i) const {
    // a[0] + ... + a[i-1]
    Tp res = 0;
    while (i > 0) {
      res += c[i];
      i -= lsuf[i];
    }
    return res;
  }
};

int main() {
  size_t n, q;
  scanf("%zu %zu", &n, &q);

  prefix_accumulator<int> pa(n);
  for (size_t i = 0; i < q; ++i) {
    int t;
    scanf("%d", &t);

    if (t == 0) {
      // add(i, x)
      size_t j;
      int x;
      scanf("%zu %d", &j, &x);
      --j;
      pa.update(j, x);
    } else if (t == 1) {
      // getSum(s, t);
      size_t s, t;
      scanf("%zu %zu", &s, &t);
      --s;
      --t;
      int sum = pa.accumulate(t+1);
      sum -= pa.accumulate(s);
      printf("%d\n", sum);
    }
  }
}


Measured memory_bytes: 4972
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define W(x) cout<<x<<endl;
#define Debug(x) cout<<"#DEBUG "<<x<<endl;

using namespace std;
int main()
{
    int n;
    cin>>n;
    long long a[n+1];
    long long x;
    a[0]=0;
    rep(i,n)
    {
        cin>>x;
        a[i+1]=a[i]+x;
    }
    sort(a,a+(n+1));
    long long ans=0,cnt=0;
    rep(i,n)
    {
        if(a[i]==a[i+1])
        {
            cnt++;
        }
        else
        {
            ans+=(cnt*(cnt+1)/2);
            cnt=0;
        }
    }
    ans+=(cnt*(cnt+1)/2);
    W(ans);
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;
int main() {
    fast();
    // ll t;
    // cin>>t;
    // while(t--)			
    // {
        
    // }
    ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    ll temp1=x%d;
    ll temp2=d-temp1;
    if((x-temp1)/d==k)
    cout<<temp1;
    else if((x-temp1)/d>k)
    cout<<x-k*d;
    else
    {
        ll ans=1e18;
        ll mv=(x-temp1)/d;
        if(mv%2==0&&k%2==0)
        cout<<temp1;
        else if(mv%2==0&&k%2==1)
        cout<<temp2;
        else if(mv%2==1&&k%2==1)
        cout<<temp1;
        else
        cout<<temp2;
    }
    
}

Measured memory_bytes: 3640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "KharYusuf", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastReader in = new FastReader(inputStream);
            PrintWriter out = new PrintWriter(outputStream);
            APayment solver = new APayment();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class APayment {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            w.println((1000 - s.nextInt() % 1000) % 1000);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 25616
#include <iostream>
#include <algorithm>

std::uint64_t solve(std::uint64_t n, std::uint64_t t, std::uint64_t rest = 0, std::uint64_t prev = 0, std::uint64_t total = 0) {
    if (n == 0) return total + rest;
    std::uint64_t ti;
    std::cin >> ti;
    auto delta = ti - prev;
    auto time = std::min(rest, delta);
    total += time;
    rest -= time;
    prev = ti;
    return solve(n-1, t, t, prev, total);
}

int main() {
    std::uint64_t n, t;
    std::cin >> n >> t;
    std::uint64_t result = solve(n, t);
    std::cout << result << std::endl;
}


Measured memory_bytes: 12800
#include <stdio.h>

int main(void) {

  int n,m;
  scanf("%d %d", &n, &m);
  int x[m],y[m];
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &x[i], &y[i]);
  }
  int box[n];
  for (int i = 0; i < n; i++) {
    box[i] = 1;
  }
  int red[n];
  red[0] = 1;
  for (int i = 1; i < n; i++) {
    red[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    if (red[x[i]-1] == 1) {
      if (box[x[i]-1] == 1) {
        red[x[i]-1] = 0;
      }
      red[y[i]-1] = 1;
    }
    box[x[i]-1]--;
    box[y[i]-1]++;
  }
  int answer = 0;
  for (int i = 0; i < n; i++) {
    if (red[i] == 1) {
      answer++;
    }
  }
  printf("%d\n", answer);

  return 0;
}

Measured memory_bytes: 1664
import numpy as np
A = []
for i in range(3):
    A.append(list(map(int, input().split())))
A = np.array(A)

N = int(input())

for n in range(N):
    called_num = int(input())
    exist_list = [called_num in A[i] for i in range(3)]
    if True in exist_list:
        called_row = exist_list.index(True)
        A[called_row] = [0 if x==called_num else x for x in A[called_row]]
        
sum_row = np.sum(A, axis=1)
sum_col = np.sum(A, axis=0)
sum_diag1 = np.diag(A).sum()
sum_diag2 = A[0][2] + A[1][1] + A[2][0] #良い実装が思いつかなかった

if 0 in sum_row or 0 in sum_col or 0 in [sum_diag1, sum_diag2]: #書き方イマイチ
    print('Yes')
else:
    print('No')

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

int main() {
  int n;
  cin>>n;
  vector<int> color;
  color.assign(n,-1);

  int u0,v0,w0;
  cin>>u0>>v0>>w0;
  u0-=1;
  v0-=1;
  if(w0%2==0){
    color[u0]=0;
    color[v0]=0;
  }else{
    color[u0]=0;
    color[v0]=1;
  }

  int u,v,w;
  queue<vector<int>> q;
  for(int i=0;i<n-2;i++){
    cin>>u>>v>>w;
    q.push({u,v,w});
  }
  while(!q.empty()){
    u=q.front()[0];
    v=q.front()[1];
    w=q.front()[2];
    q.pop();
    u-=1;
    v-=1;
    if(color[u]==-1 && color[v]==-1){
      q.push({u+1,v+1,w});
    }else{
      if(w%2==0){
        if(color[u]!=-1 && color[v]==-1) color[v]=color[u];
        else if (color[u]==-1 && color[v]!=-1) color[u]=color[v];
      }else{
        if (color[u]!=-1 && color[v]==-1) color[v]=(color[u]+1)%2;
        else if (color[u]==-1 && color[v]!=-1) color[u]=(color[v]+1)%2;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<color[i]<<endl;
  }
}

Measured memory_bytes: 9744
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define FOR(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define ALL(n) (n).begin(), (n).end()
#define pb push_back

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> mat;

const ll MAX_V = 100000;
const ll INF = 1e9;
const ll MOD = 998244353;

int main(){
    int r, D, base; cin >> r >> D >> base;
    REP(i, 10){
        int ans = r*base - D;
        base = ans;
        cout << ans << endl;
    }
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

inline int topbit(unsigned long long x){
    return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
    return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
    return __builtin_parity(x);
}


signed main(){
    int N;cin>>N;
    vint P(N),Q(N);
    rep(i,N)cin>>P[i];
    rep(i,N)cin>>Q[i];

    vint v(N);iota(all(v),1);
    int cur=0;
    int a,b;
    do{
        if(v==P)a=cur;
        if(v==Q)b=cur;
        cur++;

    }while(next_permutation(all(v)));
    cout<<abs(a-b)<<endl;
    return 0;
}

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

int main(){
    int a,b,c,x;
    cin>>a>>b>>c>>x;
    int ans=0;
    int num1=min(x/500,a);
    int num2=min(x/100,b);
    int num3=min(x/50,c);

    for(int h=num1;h>=0;h--){
        for(int i=num2;i>=0;i--){
            for(int j=num3;j>=0;j--){
                if(x==500*h+100*i+50*j) ans++;
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

const ll INF = 1e18;

ll dp[200005][4];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n+1)rep(j,n%2+2) dp[i][j] = -INF;
    dp[0][0] = 0;
    rep(i,n){
        rep(j,n%2+2){
            chmax(dp[i+1][j+1], dp[i][j]);
            ll tmp = dp[i][j];
            if((i+j)%2 == 0) tmp += a[i];
            chmax(dp[i+1][j], tmp);
        }
    }
    ll ans = dp[n][n%2+1];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int n; cin >> n;
    map<int, int> mp;
    int ans = 0;
    rep(i, n) {
        int a; cin >> a;
        mp[a]++; ans++;
        if(mp[a]==2) {
            ans-=2;
            mp[a] = 0;
        }
    }
    cout << ans;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<v<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll X;
    cin >> X;
    ll Y;
    cin >> Y;
    if(abs(X-Y)<=1)prt("Brown")
    else prt("Alice")

    return 0;
}


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

int main(){
    int n, s = 0;
    cin >> n;
    int a[100] = {};
    
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int j = 0; j < n; j++){
        int minj = j;
        for(int k = j; k < n; k++){
            if (a[minj] > a[k]) minj = k;
        }
        swap(a[minj], a[j]);
        if (minj != j) s++; 
    }
    for(int i = 0; i < n; i++){
        cout << a[i];
        if (i != n-1) cout << " ";
    }
    cout << "\n";
    cout << s << endl;

    return 0;
}



Measured memory_bytes: 3100
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

int main() {
	int N; cin >> N;
	int K; cin >> K;
	map<char, bool> mp;
	for (int i = 0; i < K; ++i) {
		char a; cin >> a;
		mp[a] = true;
	}

	for (int i = N; i < N * 100; ++i) {
		string s = to_string(i);
		bool flags = 0;
		for (int j = 0; j < s.length(); ++j) {
			if (mp[s[s.length() - j - 1]] == 1) {
				flags = 1;
				break;
			}
		}
		if (!flags) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3696