akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
ll t1, t2, a1, a2, b1, b2;
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> t1 >> t2;
 	cin >> a1 >> a2;
 	cin >> b1 >> b2;
	ll p = a1*t1 - b1*t1, q = a2*t2 - b2*t2;
	if(p>0) p *= -1, q *= -1, swap(a1,b1), swap(a2,b2);
	if(p+q<0) cout << 0;
	else if(p+q==0) cout << "infinity";
	else 
	{
		ll ans = 2*((-p)/(p+q)) + ((-p)%(p+q) ? 0 : -1) + 1;
		cout << ans;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int rest[N];
    int a[N];
    string str[N];
    for(int i = 1; i <= N; i++){
      string s;
      int sc;
      cin >> s >> sc;
      rest[i-1] = i;
      str[i-1] = s;
      a[i-1] = sc;
    }
    for(int i = 0; i <= N-2; i++){
      for(int j = 0; j <= N-2-i; j++){
        if(str[j] > str[j+1]){
          string tmp = str[j];
          str[j] = str[j+1];
          str[j+1] = tmp;
          int tmpr = rest[j];
          rest[j] = rest[j+1];
          rest[j+1] = tmpr;
        }
        else if(str[j] == str[j+1] && a[rest[j]-1] < a[rest[j+1]-1]){
          string tmps = str[j];
          str[j] = str[j+1];
          str[j+1] = tmps;
          int tmpre = rest[j];
          rest[j] = rest[j+1];
          rest[j+1] = tmpre;
        }
      }
    }
    for(int i = 0; i <= N-1; i++){
      cout<<rest[i]<<endl;
    }
}


Measured memory_bytes: 256
import java.util.*;
import java.util.function.BiConsumer;

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];
		int[] B = new int[M];
		
		
		//部屋を結ぶ道をリストで管理
		List<Integer>[] edge = new ArrayList[N];
		for(int i = 0; i < N; i++)
		    edge[i] = new ArrayList<>();
		for (int i = 0; i < M; i++) {
		    int a = sc.nextInt()-1;
		    int b = sc.nextInt()-1;
		    edge[a].add(b);
		    edge[b].add(a);
		}

		int INF = 100000000;
		Queue<Integer> queue = new ArrayDeque<>(); //空のキューの用意
		int[] shirube = new int[N];
		//訪問済み&道標
		Arrays.fill(shirube, INF);

		//頂点vが未訪問のとき、訪問済みにしてvをキューに追加する
		//BiConsumer<T, V>は関数型
		//"->"はラムダ記法
		BiConsumer<Integer, Integer> push = (v, d) -> { 
			if (! (shirube[v]==INF)) return; //ノードに訪問済みの時は、関数を終了する

			/* 訪問済みにする操作を記述 */
			shirube[v] = d;
			queue.add(v);
		};
		//初期ノードを訪問
		push.accept(0, 0);

		//キューが空になるまで、キューから取り出し頂点と接続した頂点を訪問
		//訪問済みの場合は、push関数側が何もせずに終了する
		while(!queue.isEmpty()) {
			int v = queue.poll(); //キューから頂点取り出す

			/* 隣接する頂点にに対してpush関数を適用する　*/
			for(int i : edge[v]) {
				if(shirube[i]==INF) {
					shirube[i] = v+1;
					queue.add(i);
				}
			}

		}

		System.out.println("Yes");
		for(int i = 1; i < N; i++) {
			System.out.println(shirube[i]);
		}
		
	}
}


Measured memory_bytes: 76948
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

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

    int nr = 0;
    int nw = 0;

    vector<char> cs(N);
    for (int i = 0; i < N; i++) {
        cin >> cs[i];
        if (cs[i] == 'R') {
            nr++;
        } else {
            nw++;
        }
    }

    vector<char> expected(N);
    for (int i = 0; i < nr; i++) {
        expected[i] = 'R';
    }
    for (int i = nr; i < N; i++) {
        expected[i] = 'W';
    }

    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (cs[i] != expected[i]) {
            cnt++;
        }
    }

    // printf("cnt: %d\n", cnt);
    assert(cnt % 2 == 0);
    cout << cnt / 2 << endl;

    return 0;
}


Measured memory_bytes: 3788
#include <iostream>
#include <vector>
#include <queue>

constexpr int INF = (1 << 29);

struct State {
    int cost, x, y;
    State (int cost, int x, int y) : cost{cost}, x{x}, y{y} {}
    bool operator < (const State &s) const {
        return cost > s.cost;
    }
};

bool in_field(int x, int y, int H, int W)
{
    return (0 <= x && x < W && 0 <= y && y < H);
}

int main()
{
    int H, W;
    int sx, sy, gx, gy;
    
    std::cin >> H >> W;
    std::vector<std::string> a(H);
    for (int i = 0; i < H; i++) {
        std::cin >> a[i];
        for (int j = 0; j < W; j++) {
            if (a[i][j] == 'S') {
                sx = j; sy = i;
                a[i][j] = '.';
            } else if (a[i][j] == 'G') {
                gx = j; gy = i;
                a[i][j] = '.';
            }
        }
    }
    
    std::priority_queue<State> pq;
    pq.push(State{0, sx, sy});
    
    std::vector<std::vector<int>> d(H, std::vector<int>(W, INF));
    d[sy][sx] = 0;
    
    constexpr int dx[4] = {-1, +0, +1, +0};
    constexpr int dy[4] = {+0, -1, +0, +1};
    
    while (!pq.empty()) {
        State s = pq.top(); pq.pop();
        int x = s.x, y = s.y;
               
        if (d[y][x] < s.cost) { continue; }
        
        if (x == gx && y == gy) { break; }

        for (int i = 0; i < 4; i++) {
            int nx, ny, ncost;
            for (int j = 1; j <= 3; j++) {
                nx = x + dx[i] * j, ny = y + dy[i] * j;
                
                if (!in_field(nx, ny, H, W) || a[ny][nx] == '#') {
                    break;
                }
                
                ncost = d[y][x] + j + 2;
                if (ncost < d[ny][nx]) {
                    d[ny][nx] = ncost;
                    pq.push(State(d[ny][nx], nx, ny));
                }
            }
            
            nx = x + dx[i], ny = y + dy[i];
            if (!in_field(nx, ny, H, W) || a[ny][nx] == '#' ||
                a[ny][nx] == 'x') {
                continue;
            }
            
            ncost = d[y][x] + (a[ny][nx] == 'o' ? 1 : 2);
            if (ncost < d[ny][nx]) {
                d[ny][nx] = ncost;
                pq.push(State(d[ny][nx], nx, ny));
            }
        }
    }
    
    std::cout << d[gy][gx] << std::endl;
    
    return 0;
}

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

int main()
{
  static char s[200000];
  scanf("%s",s);
  int n=strlen(s);
  int c[26]={0};
  for(int i=0;s[i];i++){
    c[s[i]-'a']++;
  }
  sort(c,c+26);
  puts(c[25]>(n+2)/3||c[25]+c[24]>(n+2)/3+(n+1)/3?"NO":"YES");
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> b(N);
    for(int i = 0; i < N; i++){
        cin >> b[i];
        if(b[i] > i + 1){
            cout << -1 << endl;
            return 0;
        }
    }
    
    vector<int> ans(N);
    
    for(int i = 0; i < N; i++){
        int now = -1;
        for(int j = 0; j < b.size(); j++){
            if(b[j] == j + 1){
                now = j;
            }
        }
        if(now == -1){
            cout << -1 << endl;
            return 0;
        }
        
        ans[i] = now + 1;
        
        b.erase(b.begin() + now);
    }
    
    for(int i = N - 1; i >= 0; --i){
        cout << ans[i] << endl;
    }
}

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

int main() {
	vector <int> a(5);
	for (int i = 0; i < 5; ++i) {
		cin >> a[i];
	}

	int min = 9;
	int min_value;
	int min_i;
	for (int i = 0; i < 5; ++i) {
		if ((a[i] % 10) != 0 && ((a[i] % 10) <= min)) {
			min = a[i] % 10;
			min_value = a[i];
			min_i = i;
		}
	}

	int sum = 0;
	for (int i = 0; i < 5; ++i) {
		if (i != min_i) {
			if (a[i] % 10 != 0) {
				sum += ((a[i]/10)+1)*10;
			}
			else if (a[i] % 10 == 0) {
				sum += a[i];
			}
		}
		
	}

	sum += min_value;
	cout << sum << endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int x,y;
    cin >> x >> y;
    if(x < y) cout << min(y - x, 1 + abs(x + y)) << endl;
    else cout << min(x - y + 2, 1 + abs(-x - y)) << endl; 
}

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

#define DB(x) cerr << #x << " = " << (x) << " "
#define ENDL cerr << "\n"
#define FOR(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define DBA(x, a, b) { cerr << #x << " = "; for (int _ = (a); _ <= (b); _++) cerr << x[_] << ' '; ENDL }
#define DBS(x) { cerr << #x << " = "; for (auto _ : x) cerr << _ << ' '; cerr << endl; }

using namespace std;

template<typename T, typename U> static void rmin(T &x, U y) {
    if (y < x) x = y;
}
template<typename T, typename U> static void rmax(T &x, U y) {
    if (x < y) x = y;
}

#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define mid ((left + right) >> 1)
#define lson rt << 1, left, mid
#define rson rt << 1 | 1, mid + 1, right

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);
const int MOD = 1e9 + 7;

const int N = 2e5 + 10;
long long a[N];
int n;

int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    long long cur = 0;
    long long ans = (long long)1e18;
    for(int i = 0; i < n - 1; i++) {
        cur += a[i];
        ans = min(ans, abs(cur - (sum - cur)));
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1920
N=int(input())
X=list(map(int,input().split()))
minValue=-1

rangeMin=min(X)
rangeMax=max(X)+1

for i in range(rangeMin,rangeMax):
    tmp=0
    for value in X:
        tmp+=(value - i)**2
    if(minValue>tmp or minValue==-1):
        minValue=tmp


print(minValue)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
    using namespace std;
     
    int main(){
      int a,b,c;
      //string s;
      cin >> a >> b;
      //cin >> s;
      //if((a+b)%2==1)cout << 1 + (a+b)/2 << endl;
      //else cout << (a+b)/2 << endl;
      if(a*b%2==0)cout << "Even" << endl;
      else cout << "Odd" << endl;
      return 0;
    }

Measured memory_bytes: 256
S = int(input())
A = S//100
B = S%100
if 0 < A <= 12 and 0 < B <= 12:
    print("AMBIGUOUS")
elif 0 < A <= 12:
    print("MMYY")
elif 0 < B <= 12:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 9160
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    auto P = aryread();
    auto Q = aryread();
    auto I = iota(1, N + 1).array;
    long a, b;
    long i;
    do
    {
        if (P == I)
            a = i;
        if (Q == I)
            b = i;
        i++;
    }
    while (nextPermutation(I));
    writeln(abs(a - b));
}


Measured memory_bytes: 256
n=int(input())
l=sorted(list(map(int,input().split())))
ls=[]
tmp=0
for i in l:
    tmp+=i
    ls.append(tmp)
l.reverse()
ls.reverse()
l=[0]+l
ans=0
for i in range(n):
    if ls[i]*2>=l[i]:ans+=1
    else:print(ans);exit()
print(ans)

Measured memory_bytes: 14404
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 1e6;
int n, s;
V<P<int, int>> v1, v2;
void No(){
  cout << "No" << endl;
  exit(0);
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(_, 0, n){
    string t;
    cin >> t;
    int c = 0, mi = 0;
    FOR(i, 0, sz(t)){
      c += (t[i]=='(' ? 1 : -1);
      mins(mi, c);
    }
    if(mi >= 0){
      s += c;
    }else if(c >= 0){
      v1.pb(mp(mi, c));
    }else{
      v2.pb(mp(c-mi, mi));
    }
  }
  sort(all(v1), greater<P<int, int>>());
  for(auto p:v1){
    if(p.fi+s < 0) No();
    s += p.se;
  }
  sort(all(v2), greater<P<int, int>>());
  for(auto p:v2){
    if(p.se+s < 0) No();
    s += p.fi+p.se;
  }
  if(s!=0) No();
  cout << "Yes" << endl;
}

Measured memory_bytes: 7676
#include <bits/stdc++.h>
using namespace std;
int main(){
    int k,n;
    cin >> k >> n;
    int biggest =0;
    int a[n];
    for (int i = 0;i < n;i++){
        cin >> a[i];
    }
    for(int i = 0;i < n-1;i++){
        int howLong = a[i+1] - a[i];
        if(howLong > biggest) biggest = howLong;
    }
    if(a[0]+k-a[n-1] > biggest) biggest = a[0]+k-a[n-1];
    cout << k-biggest << endl;
}

Measured memory_bytes: 1024
def bsearch(a, c)
  return false if a.empty? || a.nil?

  len = a.length
  if len == 1
    a[0] == c
  else
    mid = len/2
    case
    when a[mid] == c
      true
    when a[mid] > c
      bsearch(a[0..(mid-1)], c)
    when a[mid] < c
      bsearch(a[(mid+1)..-1], c)
    end
  end
end

gets
s = gets.split.map(&:to_i)
gets
t = gets.split.map(&:to_i)
sum = 0
t.each do |c|
  sum += 1 if bsearch(s, c)
end
puts sum



Measured memory_bytes: 18296
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
 

//result = Math.pow(num1, num3)
//StringBuffer str = new StringBuffer(hoge1);
//String hoge2 = str.reverse().toString();
//map.containsKey(A)

//Map<String, Integer> map = new HashMap<String, Integer>(n);
/*for ( キーのデータ型 key : マップの名前.keySet() ) {
	データのデータ型 data = マップの名前.get( key );
	
	// keyやdataを使った処理;
}*/

//ArrayList<String> cc = new ArrayList<>(n);
//Collections.sort(list);
//Array.sort(list);
//Arrays.asList(c).contains("a")
//list.set(1,"walk");
public class Main {
	private static Scanner sc = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	//static String eikomoji[]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
	static long N;
	public static void main(String[] args) {
		long v=sc.nextLong();
		long ans=0;
		
		if(v%2==1) {
			p(0);
		}else {
			long f=2;
			for(int i=1;true;i++) {
				f*=5;
				long g=(v/f);
				if(g<1) {
					break;
				}
				ans+=g;
			}
			p(ans);
		}
		
		
	}
	static int memo[]=new int[100000];
	static int dfs(int i) {
		if(memo[i]!=0) {
			return memo[i];
		}
		if(i<=1) {
			memo[i]=1;
			return 1;
		}
		memo[i]=i*dfs(i-2);
		return memo[i];
	}
	
	
	
}


Measured memory_bytes: 22740
#include<iostream>
#include<cmath>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define llong long long
#define dotp(n) fixed << setprecision(n)

int main()
{
	int a[5];
	rep(i, 5){
		cin >> a[i];
	}
	int k;
	cin >> k;
	bool existed = false;
	for(int i = 0; i < 5; i++){
		for(int j = i+1; j < 5; j++){
			int d = abs(a[j]-a[i]);
			if(d > k)
				existed = true;
		}
	}
	cout << (existed ? ":(" : "Yay!") << endl;
	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>){
    val (H, W) = readLine()!!.split(" ").map{
        it.toInt()
    }

    var a :MutableList<String> = mutableListOf()
    for (i in 0..H-1){
        a.add(readLine()!!)
    }

    val row :MutableList<Boolean> = mutableListOf()
    val col :MutableList<Boolean> = mutableListOf()
    for (i in 0..H-1){
        row.add(false)
    }
    for (i in 0..W-1){
        col.add(false)
    }

    for (i in 0..H-1) {
        for (j in 0..W-1){
            if (a[i][j] == '#'){
                row[i] = true
                col[j] = true
            }
        }
    }

    for (i in 0..H-1){
        if(row[i]){
            for(j in 0..W-1){
                if(col[j]){
                    print(a[i][j])
                }
            }
            println()
        }
    }
}


Measured memory_bytes: 37904
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	boolean[] p = new boolean[1000000];
	putN(p);
	while(kbd.hasNext()){
	    int n = kbd.nextInt();
	    int c = 0;
	    int i;
	    for(i=0; i<=n; i++){
		if(p[i]) c++;
	    }

	    System.out.println(c);
	}
    }

    public static void putN(boolean[] p){
	int i, j;
	for(i=0; i<p.length; i++)
	    p[i] = true;
	p[0] = p[1] = false;
	for(i=2; i<p.length; i++){
	    for(j=i+i; j<p.length; j+=i){
		p[j] = false;
	    }
	}
    }
}

Measured memory_bytes: 22164
/*
Author: Sanskar Agarwal
Nick: sanskarag
Birla Institute Of Technology, Mesra
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define INF 100009
#define mod 1000000007
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define test while(t--)solve();

void solve()
{
	int a, b, c, d;
	bool flag = true;
	cin >> a >> b >> c >> d;
	int f = 0;
	while (1)
	{
		if (f == 0)
		{
			c -= b;
			if (c <= 0)
				break;
			f = 1;
		}
		else
		{
			a -= d;
			if (a <= 0)
			{
				flag = false;
				break;
			}
			f = 0;
		}
	}
	if (flag)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("../input.txt", "r", stdin);
	freopen("../output.txt", "w", stdout);
#endif
	fast
	int t;
	// cin >> t;
	t = 1;
	test
	return 0;
}

Measured memory_bytes: 3636
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    E=[[] for _ in range(n)]
    R=[[] for _ in range(n)]
    for _ in range(n-1+m):
        u,v=map(int,input().split())
        u-=1; v-=1
        E[u].append(v)
        R[v].append(u)

    # longest path
    dp=[None]*n
    def dfs(v):
        if(dp[v] is not None):
            return dp[v]
        res=0
        for nv in E[v]:
            res=max(res,dfs(nv)+1)
        dp[v]=res
        return res
    for v in range(n):
        dfs(v)

    ans=[None]*n
    root=max((dp[v],v) for v in range(n))[1]
    ans[root]=-1

    # 各頂点に対して、逆辺の dp の値の最小が親
    for v in range(n):
        if(v==root): continue
        p=min((dp[p],p) for p in R[v])[1]
        ans[v]=p

    print(*map(lambda x:int(x+1),ans),sep='\n')
resolve()

Measured memory_bytes: 158768
#include<bits/stdc++.h>
using namespace std;
const int mxn = 550;
int f[mxn] , c[mxn] , s[mxn];
int main()
{
    int n;
    cin>>n;
    for(int i = 1; i < n; i++)
    cin>>c[i]>>s[i]>>f[i];
    for(int i = 1; i < n; i++)
    {
        long long sum = 0;
        for(int j = i; j < n; j++)
        {
            if(s[j] >= sum)
            {
                sum = s[j];
            }
            else
            {
                long long tmp = sum%f[j];
                if(tmp)
                sum += f[j]-tmp;
            }
            //cout<<c[j]<<" "<<j<<endl;
            sum += c[j];
          //  cout<<sum<<endl;
        }
        cout<<sum<<endl;
    }
    cout<<0<<endl;
    return 0;
}


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

public class Main implements Runnable { //クラス名はMain1

	public static void main(String[] args) {
		Thread.setDefaultUncaughtExceptionHandler((t, e) -> System.exit(1));
		new Thread(null, new Main(), "", 1024 * 1024 * 1024).start(); //16MBスタックを確保して実行
	}

	/**
	 * for (int i = 0; i < N; i++) {}
	 * System.out.println();
	 * HashMap<Integer, Integer> hm = new HashMap<>();
	 * int[] s = new int[M];
	 * ArrayDeque<Integer> deq = new ArrayDeque<>();
	 *
	 * 文字列のSort
	 * String sorted = S.chars()
						.sorted()
						.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
						.toString();
	 */
	public void run() {
		FastScannerMainC sc = new FastScannerMainC(System.in);

		try {
			//String S = sc.nextLine().trim();
			long X = sc.nextLong();
			long Y = sc.nextLong();
			//int[] a = new int[N];
			//long l = sc.nextLong();
			//ArrayList<Integer> arr = new ArrayList<Integer>();
			//for (int i = 0; i < N; i++) {}
			//for (char i = 'a'; i <= 'z'; i++) {}

			long multiple = 2;
			long count = 1;
			long tmp = X;

			while (true) {
				tmp *= multiple;
				if (tmp > Y) {
					break;
				} else {
					count++;
				}
			}

			System.out.println(count);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}

//高速なScanner
class FastScannerMainC {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScannerMainC(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}


Measured memory_bytes: 29780
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, a, b := nextInt(), nextInt(), nextInt()
	x := nextInts(n)

	ans := 0
	for i := 0; i < n-1; i++ {
		ans += min(a*(x[i+1]-x[i]), b)
	}

	puts(ans)
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

string s;
int a[4];

int main() {
    cin >> s;
    forn(i, 4) a[i] = s[i] - '0';
    forn(mask, 16) if (!(mask & 1)) {
        int res = 0;
        forn(j, 4) if (mask & (1 << j)) {
            res -= a[j];
        } else {
            res += a[j];
        }
        if (res == 7) {
            cout << a[0];
            for (int i = 1; i < 4; ++i) if (mask & (1 << i)) {
                cout << '-' << a[i];
            } else {
                cout << '+' << a[i];
            }
            cout << "=7" << endl;
            break;
        }
    }
    return 0;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64 a,b;
  cin >> a >> b;
  int64 g = gcd(a,b);
  int64 p = 2;
  int32 ans = 1;
  while(g > p * p){
    if(g % p == 0)ans++;
    while(g % p == 0){
      g /= p;
    }
    p++;
  }
  if(g > 1)ans++;
  ANS(ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define int long long 
const int N=2e5+5;
int n,k;
vector<int>v;
int32_t main(){
	IOS;
	
	//code

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

	sort(v.begin(),v.end(), greater<int>());
	int sum=0;
	if(k>=n){
		cout<<0<<endl;
		return 0;
	}
	for(int i=k;i<n;i++){
		sum+=v[i];
	}
	cout<<sum<<endl;
	//code
	
	return 0;

}

Measured memory_bytes: 1792
coin = [1,
6,6**2,6**3,6**4,6**5,6**6,
9,9**2,9**3,9**4,9**5]
n = int(input())
inf = 10**9
dp = [inf]*(n+1)
dp[0] = 0
for c in coin:
    for yen in range(c, n+1):
        dp[yen] = min(dp[yen], dp[yen-c] + 1)
print(dp[n])


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

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<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

template<class T>
inline bool chmax(T& a, T b){if(a<b){a=b;return true;} return false;}

template<class T>
inline bool chmin(T& a, T b){if(a>b){a=b;return true;} return false;}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,a,b;
	cin >> n >> a >> b;
	if(a>b) cout << 0 << endl;
	else{
		if(n==1) cout << (a==b?1:0) << endl;
		else{
			cout << (n-2)*(b-a)+1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void) {
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	for (int i = 0; i < n - 2; ++i) {
		string tmp = s.substr(i, 3);
		if (tmp == "ABC") ++ans;
	}
	cout << ans;
	return 0;
}

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

int main(){
    long long N, A, B;
    cin >> N >> A >> B;

    long long i = N / (A + B);
    long long mod = N % (A + B);
    long long ans;
    ans = min(i * A + mod, i * A + A);
    cout << ans << endl;
}

Measured memory_bytes: 3616
#include<iostream>
using namespace std;
int main(void)
{
    int n,m,l,sum=0;
    int k,a[35];
    cin >> n >> m;
    l=n;
    int cnt[35]={0};
    while(l--){
        cin >> k;
        while(k--) {
            int t;
            cin >> t;
            cnt[t]++;
        }
    }
    for(int i=1;i<=m;i++)
        if(cnt[i]==n)
            sum++;
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
using namespace std;
typedef long long ll;

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

int main(void){
    ll a, b;
    cin >> a >> b;
    ll g;
    g = gcd(a,b);
    ll ans = 1;
    //cout << g << endl;
    ll lim = sqrt(g) + 1;
    set<ll> s;
    s.insert(1);
    bool ni;
    ll i = 2;
    ni = false;
    while(g>=i*i){
        //cout << g << " " << i << endl;
        if(g%i==0){
            g = g/i;
            if(!ni){
                s.insert(i);
            }
            ni = true;
        }else
        {
            i += 1;
            ni = false;
        }
    }
    s.insert(g);
    cout << s.size() << endl;
}

Measured memory_bytes: 256
k = int(input())

i = 0

ans = []

def rec(n):
    ans.append(n)
    if n >= 10000000000:
        return
    for j in range(-1, 2, 1):
        add = n % 10 + j
        if 0 <= add <= 9:
            rec(10 * n + add)
for i in range(1, 10):
    rec(i)
ans.sort()
print(ans[k - 1])


Measured memory_bytes: 103828
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <iomanip>

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

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s-1);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    int n; cin >> n;
    vector<ii> red, blue;
    REP(i, n) {
        int x, y; cin>>x>>y;
        red.push_back(make_pair(x,y));
    }
    REP(i, n) {
        int x, y; cin>>x>>y;
        blue.push_back(make_pair(x,y));
    }

    sort(ALL(red), [](const ii& l, const ii& r) {
        return l.second > r.second;
    });
    sort(ALL(blue), [](const ii& l, const ii& r) {
        return l.first < r.first;
    });

    int ans = 0;
    REP(i, n) {
        int x = blue[i].first, y = blue[i].second;

        REP(j, red.size()) {
            int rx = red[j].first, ry = red[j].second;
            if (x > rx && y > ry) {
                ans++;
                red.erase(red.begin()+j);
                break;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long r,c,k,x,y,v,ans;
long long m[3005][3005],f[3005][3005][5];
int main()
{
	cin>>r>>c>>k;
	for(int i=1;i<=k;++i)
	{
		cin>>x>>y>>v;
		m[x][y]=v;
	}
	for(int i=1;i<=r;++i)
	 for(int j=1;j<=c;++j)
	  for(int k=1;k<=3;++k)
	   f[i][j][k]=max(f[i-1][j][3]+m[i][j],max(f[i][j-1][k-1]+m[i][j],f[i][j-1][k])),
	   ans=max(ans,f[i][j][k]);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 425952
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	int n, p[50], ans = 0, p1;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	for (int i1 = 1; i1 < n; i1++) {
		if (p[i1 - 1]+1 == p[i1])ans++;
	}
	if (ans == n-1) {
		cout << "YES" << endl;
		return 0;
	}
	ans = 0;
	for (int j = 0; j < n; j++) {
		for (int k = j + 1; k < n; k++) {
			p1 = p[j];
			p[j] = p[k];
			p[k] = p1;
			for (int l = 1; l < n; l++) {
				if (p[l - 1]+1 == p[l])ans++;
			}
			if (ans == n-1) {
				cout << "YES" << endl;
				return 0;
			}
			ans = 0;
			p[k] = p[j];
			p[j] = p1;
		}
	}
	cout << "NO" << endl;
	return 0;
}

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

const int INF = 1 << 30;

int N, K;
int h[100010];

int dp[100200];

int main() {
    cin >> N >> K;
    for(int i = 1; i <= N; i++)
        cin >> h[i];

    for(int i = 0; i < 100200; i++)
        dp[i] = INF;

    dp[1] = 0;
    for(int i = 1; i <= N; i++)
        for(int j = 1; j <= K; j++)
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));

    cout << dp[N] << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Go_ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const ll  MAX=1e18+500;
const int sz=1e3+100;


int main()
{
    Go_
    int a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    
    int ara[3];
    for(i=0;i<3;i++) cin>>ara[i];
    sort(ara,ara+3);
    if((ara[0]==ara[1] && ara[1] != ara[2]) || (ara[1]==ara[2] && ara[1] != ara[0])) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    vl vec(n);
    REP(i,n){
        cin>>vec[i];
        vec[i]-=i+1;
    }
    sort(all(vec));
    ll ans=0;
    REP(i,n){
        ans+=abs(vec[n/2]-vec[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int x,a,b;
    scanf("%d %d %d",&x,&a,&b);
    int d,e;
    d=abs(x-a);
    e=abs(x-b);
    if(d>e)
        printf("B\n");
    else
        printf("A\n");
    return 0;

}


Measured memory_bytes: 2076
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
using namespace std;
#define MOD  1000000007

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int dp[100001] = { 0 };
bool ok[100001];
int main(){
	int n, m;
	int tmp;
	cin >> n >> m;
	for (int i = 0; i <= n; i++) ok[i] = true;
	for (int i = 0; i < m; i++) {
		cin >> tmp;
		ok[tmp] = false;
	}
	if (ok[1]) {
		dp[1] = 1;
		if (ok[2]) dp[2] = 2;
	}
	else if (ok[2]) dp[2] = 1;

	for (int i = 3; i <=n; i++) {
		dp[i] %= MOD;
		if (ok[i - 1]) dp[i] += (dp[i - 1] % MOD);
		dp[i] %= MOD;
		if (ok[i - 2]) dp[i] += (dp[i - 2] % MOD);
		dp[i] %= MOD;
	}
	dp[n] %= MOD;
	cout << dp[n] << endl;
	return 0;
}



Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int palindrome(string s1)
{int k=0,flag=1;
 int l=s1.size()-1;
 while(k<l)
 {if(s1[k]!=s1[l])
 {flag=0;
  break;}
  k++;
  l--;}
 return flag;}
int main()
{string s;
 cin>>s;
 int n=s.size();
 if(palindrome(s))
 {string s1=s.substr(0,(n-1)/2);
  int u=((n+3)/2);
  string s2=s.substr(u-1,n-u+1);
  if(palindrome(s1)&&palindrome(s2))
     cout<<"Yes";
  else
    cout<<"No";}
 else
   cout<<"No";}


Measured memory_bytes: 256
import numpy as np
import sys
i4 = np.int32
i8 = np.int64
u4 = np.uint32

if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC
    from numba import njit
    from numba.types import int64, Array, uint32
    cc = CC('my_module')

    @njit
    def factorization(N):
        p = np.zeros(N + 1, u4)
        n_max = int(np.sqrt(N)) + 1
        p[0] = 1
        p[1] = 1
        for i in range(2, n_max):
            if p[i] == 0:
                j = i
                while j <= N:
                    p[j] = i
                    j += i
        for i in range(n_max, N + 1):
            if p[i] == 0:
                p[i] = i
        return p

    @cc.export('solve', (Array(uint32, 1, 'C'),))
    def solve(A):
        a = np.sort(A)
        p_max = a[-1]
        p = factorization(p_max)
        primes_num = 0
        for i in range(p.shape[0]):
            if i == p[i]:
                primes_num += 1
        a_start = 0
        while a[a_start] == 1:
            a_start += 1
            if a_start == a.shape[0]:
                return 0
        a = a[a_start:]
        if len(a) > primes_num:
            return 1
        check = np.zeros(p_max + 1, i8)
        stack = np.empty(20, i8)
        p_stack = 0
        for d in a:
            while d > 1:
                x = p[d]
                for i in range(p_stack):
                    if stack[i] == x:
                        break
                else:
                    stack[p_stack] = x
                    p_stack += 1
                d //= x

            while p_stack > 0:
                p_stack -= 1
                check[stack[p_stack]] += 1

        if check.max() > 1:
            return 1
        else:
            return 0
    cc.compile()
    exit()


def main(in_file):
    stdin = open(in_file)
    stdin.readline()
    A = np.fromstring(stdin.readline(), u4, sep=' ')
    ans = solve(A)
    if ans:
        g = np.gcd.reduce(A)
        if g > 1:
            ans = 2
        else:
            ans = 1
    p = ['pairwise coprime', 'setwise coprime', 'not coprime']
    print(p[ans])


if __name__ == '__main__':
    from my_module import solve
    main('/dev/stdin')

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

int main(){
    int n,d,x;
    cin>>n>>d>>x;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    int ans=0;
    for(int i=0;i<n;i++){
        int b=a[i]+1;
        ans++;
        while(b<=d){
            b+=a[i];
            ans++;
        }
    }
    cout<<ans+x<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
struct Node {
  int v;
  Node(int v) : v(v) {}
  Node operator*(const Node &r) const {
    return Node(min(v, r.v));
  }
} e((1ll << 31) - 1);

struct SegmentTree {
  size_t n;
  vector<Node> seg;

  SegmentTree(size_t size) : n(1 << (32 - __builtin_clz(size - 1))), seg(2 * n, e) {}

  void update(int k, const Node &x) {
    for (k += n, seg[k] = x; k; seg[k] = seg[2 * k] * seg[2 * k + 1]) k /= 2;
  }

  Node query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return e;
    if (a <= l && r <= b) return seg[k];
    return query(a, b, 2 * k, l, (l + r) / 2) * query(a, b, 2 * k + 1, (l + r) / 2, r);
  }

  void update(int k, int x) {
    update(k, Node(x));
  }

  int query(int a, int b) {
    return query(a, b, 1, 0, n).v;
  }
};

 
int main() {
  int n, q;
  cin >> n >> q;
 
  SegmentTree seg(n);
  while (q--) {
    int c, x, y;
    cin >> c >> x >> y;
 
    if (c) {
      cout << seg.query(x, y + 1) << endl;
    } else {
      seg.update(x, y);
    }
  }
}

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

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

long long MOD = 1000000000 + 7;
long long MAX = 1000000000000000000;

int main(){
  cout << setprecision(10);
  int N;
  cin >> N;
  vector<int> v(N);
  map<int,int> flg;
  for(int i = 0; i < N; i++){
    cin >> v[i];
    v[i]--;
  }

  int ans = 0 ;
  for(int i = 0; i < N; i++){
    flg[i] = 1;
    if(flg.count(v[i]) == 0){
      if(v[v[i]] == i){
        ans++;
        flg[v[i]]++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 5376
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
using namespace std;
const int N=100000+10;
int a[N],b[N],n,m;
int main()
{

    string s,t;
    bool flag=0;
    cin>>s>>t;
    set<string >ses;
    if(s.size()<t.size()) {printf("UNRESTORABLE\n");return 0;}
    for(int i=0;i<s.size();i++){
        for(int j=0;j<t.size();j++){
            if((s[i]==t[j]||s[i]=='?')&&s.size()-i>=t.size()-j){
                string str=s;
                int l=1,r=1;
                str[i]=t[j];
                bool flag1=1,flag2=1;
                while(j-l>=0){
                    if(t[j-l]!=s[i-l]&&s[i-l]!='?') {flag1=0;break;}
                    str[i-l]=t[j-l];
                    l++;
                }
                while(j+r<t.size()){
                    if(t[j+r]!=s[i+r]&&s[i+r]!='?') {flag2=0;break;}
                    str[i+r]=t[j+r];
                    r++;
                }
                for(int k=0;k<str.size();k++)
                    if(str[k]=='?') str[k]='a';
                if(flag1&&flag2) {ses.insert(str);flag=1;}
            }
        }
    }
    if(flag) cout<<(*ses.begin())<<endl;
    else printf("UNRESTORABLE\n");
    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn max<T: std::cmp::PartialOrd>(a: T, b: T) -> T {
    if a > b {
        return a;
    } else {
        return b;
    }
}

fn main() {
    let n: usize = read();

    let mut a: Vec<Vec<u32>> = vec![vec![0; 3]; n];

    for i in 0..n {
        for j in 0..3 {
            a[i][j] = read();
        }
    }

    let mut dp = vec![vec![0; 3]; n+1];

    for i in 0..n {
        for j in 0..3 {
            for k in 0..3 {
                if j == k {
                    continue;
                }
                dp[i+1][k] = max(dp[i+1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    println!("{}", dp[n].iter().max().unwrap());
}


Measured memory_bytes: 14588
import heapq
N, K = map(int,input().split())
L1 = []
L2 = []
S = set()
val = 0

for _ in range(N):
    t, d = map(int,input().split())
    L1.append((d, t))

L1.sort(reverse = True)

for i in range(K):
    val += L1[i][0]
    if L1[i][1] in S:
        heapq.heappush(L2, L1[i][0])
    else:
        S.add(L1[i][1])

ans = val + len(S) ** 2

for i in range(K, N):
    if len(L2) == 0:
        break
    if not L1[i][1] in S:
        S.add(L1[i][1])
        val -= heapq.heappop(L2)
        val += L1[i][0]
        ans = max(ans, val + len(S) ** 2)

print(ans)

Measured memory_bytes: 19296
def judge(target):
	ACGT = ['A','C','G','T']
	for A in ACGT:
		if str(target) == A:
			return True
	return False

Inp = list(input())
max_count = 0
#リストのすべての文字で検証する
for j in range(len(Inp)):
	count = 0
	match = 1
	for i in range(j,len(Inp)):
		if judge(Inp[i]):
			count += 1
			if count >= max_count :
				max_count = count
		else:
			match = 0
			break
	if match == 0:
		continue


print(max_count)

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c;
  if (a % b != 0){
    d = (a / b) * c + c;
  }
  else {
    d = (a / b) * c;
  }
  cout << d << endl;
}

Measured memory_bytes: 3636
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.Scanner;

public class Main {

  private static final String[] WEEEK_NAME = {
      "Monday",
      "Tuesday",
      "Wednesday",
      "Thursday",
      "Friday",
      "Saturday",
      "Sunday"
  };

  public static void main(String[] args) {
    try (Scanner scanner = new Scanner(System.in)) {
      while (scanner.hasNext()) {
        final int month = scanner.nextInt();
        final int day = scanner.nextInt();
        if (month == 0 && day == 0) {
          return;
        }
        final DayOfWeek dayOfWeek = LocalDate.of(2004, month, day).getDayOfWeek();
        System.out.println(WEEEK_NAME[dayOfWeek.ordinal()]);
      }
    }
  }
}

Measured memory_bytes: 32260
#include <stdio.h>
int cnt[100001];
int main(void){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int a;
        scanf("%d",&a);
        cnt[a] += 1;
    }
    int shurui = 0;
    int over = 0;
    for(int x=0;x<=100000;x++){
        if(cnt[x] > 0){
            shurui += 1;
        }
        if(cnt[x] >= 2){
            over += cnt[x]-1;
        }
    }
    if(over%2==0){
        printf("%d\n",shurui);
    }else{
        printf("%d\n",shurui-1);
    }
    return 0;
}


Measured memory_bytes: 512