akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {

    private int N;
    private int M;
    private int Q;
    private int[][] B;

    public Main(FastScanner in, PrintWriter out) {
        N = in.nextInt();
        M = in.nextInt();
        Q = in.nextInt();
        B = new int[Q][4];
        for (int i = 0; i < Q; i++) {
            int a = in.nextInt() - 1;
            int b = in.nextInt() - 1;
            int c = in.nextInt();
            int d = in.nextInt();
            B[i][0] = a;
            B[i][1] = b;
            B[i][2] = c;
            B[i][3] = d;
        }

        out.println(dfs(1, new ArrayList<>()));
    }

    private int dfs(int i, List<Integer> A) {
        if (A.size() == N) {
            int res = 0;
            for (int[] q : B) {
                if (A.get(q[1]) - A.get(q[0]) == q[2])
                    res += q[3];
            }
            return res;
        }
        int res = 0;
        for (int j = i; j <= M; j++) {
            A.add(j);
            res = Math.max(res, dfs(j, A));
            A.remove(A.size() - 1);
        }
        return res;
    }

    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        // Scanner in = new Scanner(
                // new BufferedReader(new InputStreamReader(System.in)));
        FastScanner in = new FastScanner(System.in);

        Main sol = new Main(in, out);

        out.close();
    }
}


class FastScanner{
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

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

    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++];
    }

    boolean isSpaceChar(int c)
    {
        return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
    }

    boolean isEndline(int c)
    {
        return c=='\n'||c=='\r'||c==-1;
    }

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

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

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

    String next(){
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isSpaceChar(c));
        return res.toString();
    }

    String nextLine(){
        int c = read();
        while (isEndline(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isEndline(c));
        return res.toString();
    }
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

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

struct Edge {
	int t, p;
	Edge(int _t, int _p) : t(_t), p(_p) {}
};

int N, C[1010];
vector< vector<Edge> > edges;

int dfs(int v, int prev, int c_cost) {
	if (C[v] > 0) return c_cost;
	
	int e_size = size_of(edges[v]);
	int sum_cost = 0;
	for_(i,0,e_size) {
		Edge e = edges[v][i];
		if (e.t == prev) continue;
		sum_cost += dfs(e.t, v, e.p);
	}
	
	return min(c_cost, sum_cost);
}

void solve() {
	cout << dfs(0, -1, (int)1e9) << endl;
}

int main() {
	cin >> N;
	for_(i,1,N) cin >> C[i];
	edges.assign(N, vector<Edge>());
	for_(i,0,N - 1) {
		int u, v, p; cin >> u >> v >> p;
		edges[u].push_back(Edge(v, p));
		edges[v].push_back(Edge(u, p));
	}
	solve();
	return 0;
}

Measured memory_bytes: 1260
#include <iostream>
#include <algorithm>
#include <cstring>
#define MAX 1000000
using namespace std;

int tetra[200];
int dp[MAX];
int dp2[MAX];

int main(void){
	int n;
	memset(dp,MAX,sizeof(dp));
	memset(dp2,MAX,sizeof(dp2));
	dp[0]=dp2[0]=0;
	for(int i=1;i<200;i++)
		tetra[i]=i*(i+1)*(i+2)/6;
	for(int i=1;i<200;i++){
		for(int j=0;j<MAX;j++){
			if(j+tetra[i]>=MAX)
				continue;
			dp[j+tetra[i]]=min(dp[j+tetra[i]],dp[j]+1);
			if(tetra[i]%2)
				dp2[j+tetra[i]]=min(dp2[j+tetra[i]],dp2[j]+1);
		}
	}
	while(cin >>n,n)
		cout << dp[n] <<" " << dp2[n] << endl;
	return 0;
}

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

int n, m, h;

int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	while (cin >> n >> m >> h) {
		int res = 0;
		while (h > 0) {
			h -= max(n,m);
			res++;
		}
		cout << res << '\n';
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define fi first
#define se second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

vector<ll> g[MAX];
ll N, M;
ll Q;
ll v[MAX], d[MAX], c[MAX];
ll dp[MAX][11], clr[MAX];


void coloring(ll v, ll d, ll c) {
    if(dp[v][d]==1) return;
    dp[v][d]=1;
    if(d==0) {
        clr[v]=c;
        return;
    }
    
    coloring(v, d-1, c);
    for(auto u: g[v])
        coloring(u, d-1, c);
}

int main(void) {
    cin >> N >> M;
    ll i;
    
    for(i=0; i<M; i++) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    
    cin >> Q;
    for(i=0; i<Q; i++) {
        cin >> v[i] >> d[i] >> c[i];
        v[i]--;
    }
    
    for(i=Q-1; i>=0; i--)
        coloring(v[i], d[i], c[i]);
    
    for(i=0; i<N; i++)
        pt(clr[i]);
}



Measured memory_bytes: 18804
N = int(input())
A = list(map(int, input().split()))
cnt=0
A_ = []
for i in range(N):
    val = A[i]
    if A[i]<0:
        cnt+=1
        val*=-1
    A_.append(val)
if cnt%2==0:
    print(sum(A_))
else:
    print(sum(A_)-min(A_)*2)

Measured memory_bytes: 65284
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

string S;
vector<vector<int>> v(400010);
int N,M,visited[400010] = {0};

void dfs(int n){
	visited[n] = -1;
	for(int i=0;i<v[n].size();i++){
		if(visited[v[n][i]]==-1){
			cout << "Yes" << endl;
			exit(0);
		}
		else if(visited[v[n][i]]==0) dfs(v[n][i]);
	}
	visited[n] = 1;
}

int main(){
	cin  >> N >> M >> S;
	int a,b;
	for(int i=0;i<M;i++){
		cin >> a >> b;
		if(S[a-1]==S[b-1]){
			v[a].push_back(b+N);
			v[b].push_back(a+N);
		}else{
			v[a+N].push_back(b);
			v[b+N].push_back(a);
		}
	}
	for(int i=1;i<=N;i++){
		if(visited[i]==0) dfs(i);
	}
	cout << "No" << endl;
}

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

int main() {
	string s;
	cin >> s;
	for(int i = 0; i < s.size(); i += 2) cout << s[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(auto i = (N) - 1; i >= 0; i -= 1)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define rand mtrand
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cout << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,...) do { cout << #v << " = "; array_out(v , ##__VA_ARGS__);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
#endif
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = 0x1FFFFFFFFFFFFFFFLL;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}

using P = pair<int,int>;
random_device seed_gen; mt19937_64 mtrand(seed_gen());
constexpr int MOD = 1000000007;
//////////////////////////////////////////

int main(){
  ini(N); ins(A,B,C);
  set<P> s;
  rep(i,N){
    s.emplace(i , A[i]);
    s.emplace(i , B[i]);
    s.emplace(i , C[i]);
  }
  out(s.size() - N);
}

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

int main(void){
	int x[N],y[N],num=0;
	while(1){
		cin>>x[num]>>y[num];
		if(x[num]==0&&y[num]==0)break;
		num++;
	}
	for(int i=0;i<num;i++){
		if(x[i]<=y[i])cout<<x[i]<<" "<<y[i]<<endl;
		else cout<<y[i]<<" "<<x[i]<<endl;
	}
}


Measured memory_bytes: 3024
T=str(input())
ans=""
pre=False
for i in range(len(T)):
    if T[i]=="D":
        ans+=T[i]
        pre=False
    elif T[i]=="P":
        ans+=T[i]
        pre=True
    else:
        if pre==True:
            ans+="D"
            pre=False
        else:
            ans+="D"
print(ans)


Measured memory_bytes: 9460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(int I = int((B)-1); I >= int(A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl

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

	ll N , M;
	cin >> N >> M;
	vector<ll> A(N),B(M),acount,bcount;
	FOR(i,0,N)cin >> A[i];
	FOR(i,0,M)cin >> B[i];
	SORT(A);acount=A;REV(A);
	SORT(B);bcount=B;REV(B);

	ll ans = 1;
	FORR(i,1,N*M+1){
		ll k,l,x,y,z;
		k = NUM(acount,i);
		l = NUM(bcount,i);
		x = POSL(acount,i);
		y = POSL(bcount,i);
		x = N - x;//i以上Aの数
		y = M - y;//i以上Bの数
		z = N*M - i;//今までに入れた
		if(k*l>=2){
			cout << 0 << endl;
			return 0;
		}else if(k*l==1){

		}else if(k==0&&l==0){
			ans *= x*y - z;
			ans %= MOD;
			if(ans<0)ans += MOD;
		}else if(l==1){
			ans *= x;
			ans %= MOD;
		}else if(k==1){
			ans *= y;
			ans %= MOD;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int A,B,C,D;
  cin >> A >> B >> C >> D;
int TA,AO,x,y;
  AO =C/B;
  TA =A/D;
  if(C%B!=0){
    AO=AO+1;
  }
  if(A%D!=0){
    TA=TA+1;
  }
  
  if(AO<=TA){
    cout << "Yes";
  }else{
    cout << "No";
  }
}


Measured memory_bytes: 3636
#include <stdio.h>

int main()
{
	int a = 0; char s[111]; scanf ("%s", s);
	int l = 0; while (s[l]) l++;

	for (int i = 0, j = l - 1; i < j; i++, j--) if (s[i] != s[j]) a++;
	printf ("%d\n", a);
	return 0;
}

Measured memory_bytes: 128
import sys
input=lambda: sys.stdin.readline().rstrip()
x,k,d=map(int,input().split())
if k%2==1:
  if x>0:
    x-=d
  else:
    x+=d
  k-=1

a=x%(2*d)
b=a-2*d
ans=abs(abs(x)-k*d)
if abs(x-a)//d<=k:
  ans=min(ans,abs(a))
if abs(x-b)//d<=k:
  ans=min(ans,abs(b))
print(ans)


Measured memory_bytes: 9116
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String S = br.readLine();
	String T = br.readLine();
	int result = 0;
	for (int i = 0; i < 3; i++) {
	    if (S.charAt(i) == T.charAt(i))
		result++;
	}
	System.out.println(result);
    }
}


Measured memory_bytes: 23252
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.StringTokenizer;

public class Main  implements Runnable {
    public static void main(String[] args) {
        new Thread(null, new Main(), "", 64 * 1024 * 1024).start();
    }

    public void run() {
    	FastScanner sc = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(System.out);
		//long n = Long.parseLong(sc.next());
		int n = Integer.parseInt(sc.next());
		char[] c0 = sc.next().toCharArray();
		char[] c1 = sc.next().toCharArray();
		int p = 0;
		long ans = 1;
		int pre = 0;
		if(c0[p] == c1[p])
		{
			ans *= 3;
			pre = 1;
			p++;
		}
		else {
			ans *= 6;
			pre = 2;
			p+=2;
		}
		while(p < n)
		{
			if(c0[p] == c1[p])
			{
				if(pre == 1)
				{
					ans *= 2;
				} else {
					ans *= 1;
				}
				pre = 1;
				p++;
			}
			else {
				if(pre == 1)
				{
					ans *= 2;
				} else {
					ans *= 3;
				}
				pre = 2;
				p+=2;
			}
			ans %= 1000000007;
		}
		out.println(ans);
		out.flush();
    }

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;
        public FastScanner(String in) {
        	StringReader sr = new StringReader(in);
            reader = new BufferedReader(new BufferedReader(sr));
            tokenizer = null;
        }
        public FastScanner(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();
        }
    }
}

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

using namespace std;

vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

bool used[1005000];

int main() {
	int n; cin >> n;
	vector<int> a(n);
	for (auto& e : a) cin >> e;
	sort(a.begin(), a.end());
    a.push_back(1e7);
    int ans = 0;
	for (int i = 0; i < n; ++i) {
        if (a[i] != a[i + 1]) {
            auto tmp = divisor(a[i]);
            bool f = true;
            for (auto& x : tmp) {
                if (used[x]) {
                    f = false;
                    break;
                }
            }
            if (f) ++ans;
        }
        used[a[i]] = true;
	}
    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5060
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
int main(){
 int H,W;
	while(1){
		cin>>H>>W;
		if(W==0){
			break;
		}
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				cout<<"#";
			}
			cout<<endl;
		}
		cout<<endl;
	}
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
vector<bool> bs(2);
void f(int n)
  {if (n <= 1) return;
  bs.resize(n + 1, true);
  for (int i = 2; i * i <= n; ++i)
    if (bs[i]) for (int j = i + i; j <= n; j += i) bs[j] = false;}
int main()
  {int N; cin >> N;
  f(55555);
  int c = 0;
  for (int j = 2; j <= 55555 and c < N; ++j)
    if (bs[j] and j % 5 == 1) {++c; cout << j << (c == N ? "\n" : " ");}}

Measured memory_bytes: 3644
#import <stdio.h>
#import <limits.h>
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
typedef long long INT;
int main(){
    int n,a;
    scanf("%d",&n);
    int S=0,T=0;
    int min = INT_MAX;
    int max = -INT_MAX;
    for(int i=0;i<n;i++){
        scanf("%d",&a);
        S+=a*a;
        T+=a;
        min=MIN(min,a);
        max=MAX(max,a);
    }
    INT result=LONG_MAX;
    for(int x=min;x<=max;x++){
        result=MIN(result,S-2*x*T+x*x*n);
    }
    printf("%lld",result);
}


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

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

#include<algorithm>

using namespace std;
typedef long long ll;

int main() {
  ll A,B;
  cin >> A >> B;
  ll ret = 0;
  REP(i,100){
    if((i * (A-1) + 1) >= B){
      ret = i;
      break;
    }
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
//coded b vishal mourya - the legendary coder
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define f(a,b) for(ll i = a ; i < b ; i++ )
#define fj(a,b) for(ll j = a ; j < b ; j++ )
#define fk(a,b) for(ll k = a ; k < b ; k++ )
#define fasthoja ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

int main(void){
    fasthoja;
    ll n; cin >> n;
    ll k; cin >> k;
    vec v(n);
    f(0,n) cin >> v[i];
    
    sort( v.rbegin() , v.rend() );
    
    if( k >= n ) cout << "0\n";
    else {
    	ll cnt = 0;
    	for( ll i = k ; i < v.size() ; i++ ) cnt += v[i];
    	cout << cnt << "\n";
	}

 return 0;
}


Measured memory_bytes: 4680
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i];
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
auto __fast_io__ = (ios_base::sync_with_stdio(false), cin.tie(nullptr)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
////@formatter:on
//endregion


int32_t main() {
    make(int, n, k);
    makev(a, n);
    for(int i = 0; i < n; ++i){
        a[i]--;
    }
    VI was(n);
    int st = 0;
    while (k > 0 && !was[st]) {
        was[st] = 1;
        st = a[st];
        k--;
    }
    if (k == 0) {
        cout << st + 1;
        return 0;
    }
    was.assign(n, 0);
    int sz = 0;
    while(k > 0 && !was[st]){
        was[st] = 1;
        st = a[st];
        k--;
        sz++;
    }
    k %= sz;
    while(k > 0){
        st = a[st];
        k--;
    }
    cout << st + 1;

    return 0;
}

Measured memory_bytes: 6392
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	final int X = sc.nextInt();
    int X2 = X;
    int A = sc.nextInt();
    int B = sc.nextInt();
      while(X2 <= 1000){
        if(X2 >= A && X2 <= B){
          System.out.println("OK");
          return;
        }
        X2 += X;
        
      }
      System.out.println("NG");
	}
}


Measured memory_bytes: 35600
#[test]
fn test_solve() {
    assert_eq!(solve("1\n3 7\n"), "2\n");
    assert_eq!(solve("4\n13 13\n7 11\n7 11\n2017 2017\n"), "1\n0\n0\n1\n");
    assert_eq!(
        solve("6\n1 53\n13 91\n37 55\n19 51\n73 91\n13 49\n"),
        "4\n4\n1\n1\n1\n2\n"
    );
}
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    const MAX: usize = 50_000;

    let ipm = is_prime_table(2 * MAX);
    let sum: Vec<_> = (0..MAX + 1)
        .scan(0, |pre, i| {
            if i != 0 {
                *pre += (ipm[2 * i - 1] && ipm[i]) as usize;
            }
            Some(*pre)
        })
        .collect();

    let mut ret = String::new();
    use std::fmt::Write;
    let q: usize = sc.read();
    for _ in 0..q {
        let l: usize = sc.read();
        let r: usize = sc.read();
        let (l, r) = (l >> 1, r >> 1);
        writeln!(&mut ret, "{}", sum[r + 1] - sum[l]).unwrap();
    }
    ret
}
fn is_prime_table(n: usize) -> Vec<bool> {
    let mut ipm = vec![true; n + 1];
    ipm[0] = false;
    ipm[1] = false;
    let nsr = (n as f64).sqrt() as usize;
    for p in 2..nsr + 1 {
        if ipm[p] {
            let mut mpp = 2 * p;
            while mpp <= n {
                ipm[mpp] = false;
                mpp += p;
            }
        }
    }
    ipm
}
fn main() {
    let mut buf = String::new();
    use std::io::{Read, Write};
    std::io::stdin().read_to_string(&mut buf).unwrap();
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}


Measured memory_bytes: 6780
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    public static void Main()
    {
        string s = NextString();
        bool c = false;
        for (int i = 0; i < s.Length; i++) {
            if (s[i] == 'C') c = true;
            if (c && s[i] == 'F') { Console.WriteLine("Yes"); return; }
        }
        Console.WriteLine("No");
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   for(int i=0;i<(n);++i)
#define SORT(c)    sort((c).begin(),(c).end())
#define CLR(a)     memset((&a), 0 ,sizeof(a))//clear memory
#define dump(x)    cerr << #x << " = " << (x) << endl;//debug
#define debug(x)   cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define EPS        1e-10//sample:if((double)>=(double)+EPS)
//cin,cout release
//std::cin.tie(0);
//ios::sync_with_stdio(false);

using namespace std;

struct node {
  int key;
  node *parent,*right, *left;
};
typedef node* nodep;
nodep root,NIL;
void insert(int key){
  nodep y=NIL,x=root,z=(nodep)malloc(sizeof(node));
  z->key=key;
  z->left=NIL;
  z->right=NIL;
  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL)root=z;
  else{
    if(z->key<y->key)y->left=z;
    else y->right=z;
    }
}
nodep find(nodep d,int key){
  while(d!=NIL&&d->key!=key){
    if(key<d->key)d=d->left;
    else d=d->right;
  }
  return d;
}
void del(nodep u,int key){
  dump(u->key);
  dump(u->parent->key);
  if(u==NIL)return;
  else if(u->parent==NIL)cout<<"$";
  else if(u->left==NIL&&u->right==NIL){
    if(u->parent->left->key==key)u->parent->left=NIL;
    else if(u->parent->right->key==key)u->parent->right=NIL;
  }
  else if(u->left==NIL&&u->right!=NIL){
    if(u->parent->left->key==key)u->parent->left=u;
    else if(u->parent->right->key==key)u->parent->right=u;
  }
  else if(u->left!=NIL&&u->right==NIL){
    if(u->parent->left->key==key)u->parent->left=u;
    else if(u->parent->right->key==key)u->parent->right=u;
  }
  else{
    if(u->parent->left->key==key)u->parent->left=u;
    else if(u->parent->right->key==key)u->parent->right=u;
  }cout<<"#delfinished"<<endl;
}
nodep treeMinimum(nodep x){
  while(x->left!=NIL)x=x->left;
  return x;
}
nodep treesuccessor(nodep x){
  if(x->right!=NIL)return treeMinimum(x->right);
  nodep y=x->parent;
  while(y!=NIL&&x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}
void treeDelete(nodep z){
  nodep x,y;
  if(z->left==NIL||z->right==NIL)y=z;
  else y=treesuccessor(z);
  if(y->left!=NIL)x=y->left;
  else x=y->right;
  if(x!=NIL)x->parent=y->parent;
  if(y->parent==NIL)root=x;
  else{
    if(y==y->parent->left)y->parent->left=x;
    else y->parent->right=x;
  }
  if(y!=z)z->key=y->key;
  free(y);
}
void inorder(nodep u){
  if(u==NIL)return;
  inorder(u->left);
  cout<<" "<<u->key;
  inorder(u->right);
}
void preorder(nodep u){
  if(u==NIL)return;
  cout<<" "<<u->key;
  preorder(u->left);
  preorder(u->right);
}
int main(){
  string buf;
  int a,n;
  cin>>n;
  rep(i,n){
    cin>>buf;
    if(buf[0]=='i'){
      cin>>a;
      insert(a);
    }
    else if(buf[0]=='f'){
      cin>>a;
      if(find(root,a)==NIL)cout<<"no"<<endl;
      else cout<<"yes"<<endl;
    }
    else if(buf[0]=='d'){
      cin>>a;
      treeDelete(find(root,a));
    }
    else{
      inorder(root);
      cout<<endl;
      preorder(root);
      cout<<endl;
    }
  }
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    int n,m;cin>>n>>m;
    int a,b;cin>>a>>b;
    cout<<m*n-(m*a+b*n)+a*b<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{
	ll a,b;
	cin>>a>>b;
	cout<<a*b<<endl;
	return 0;
}




Measured memory_bytes: 3672
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const int maxn=4005,maxa=2e5+5;
const ll mod=1e9+7;

int a[maxa],b[maxa],n,mx;
ll dp[maxn][maxn],inv[maxn<<1],fac[maxn<<1];

inline ll C(int n,int m)
{
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for(int i=2;i<=8000;++i) fac[i]=i*fac[i-1]%mod,inv[i]=mod-mod/i*inv[mod%i]%mod;
	for(int i=1;i<=8000;++i) inv[i]=inv[i-1]*inv[i]%mod;
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i]>>b[i];
		mx=max(mx,a[i]);
		mx=max(mx,b[i]);
	}
	++mx;
	for(int i=1;i<=n;++i)
		dp[-a[i]+mx][-b[i]+mx]++;
	for(int i=1;i<=2*mx;++i)
		for(int j=1;j<=2*mx;++j)
			dp[i][j]=(dp[i][j]+dp[i-1][j])%mod,dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
	ll ans=0;
	for(int i=1;i<=n;++i)
		ans=(ans+dp[a[i]+mx][b[i]+mx])%mod,ans=(ans-C(2*a[i]+2*b[i],2*a[i])+mod)%mod;
	printf("%lld\n",ans*inv[2]%mod);
	return 0;
}

Measured memory_bytes: 130628
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

const static int MAX_N = 100000;

int main()
{
  int DP[MAX_N + 1];
  int N;

  cin >> N;
  for (int i = 0; i <= N; ++i)
  {
    DP[i] = i;
  }

  int A[2] = {6,9};
  for (int ai = 0; ai < 2; ++ai)
  {
    int exp = 1;
    while (true)
    {
      int cur = pow(A[ai], exp);
      if (cur > N) break;
      for (int i = cur; i <= N; ++i)
      {
        DP[i] = min(DP[i], DP[i - cur] + 1);
      }
      ++exp;
    }
  }

  cout << DP[N] << endl;
  
  return 0;
}


Measured memory_bytes: 640
# coding: utf-8
# Your code here!


nums=list(map(int,input().split()))
n = nums[0]
y = nums[1]

lower = max(0, int((y-10000*n)/4000))
upper = min(n, int((y-1000*n)/4000))

for b in range(lower, upper + 1):
    a = (y - 1000*n - b*4000) / 9000
    if a.is_integer():
        c = n - b - a
        if c >= 0:
            print(int(a), int(b), int(c))
            exit()

print(-1, -1, -1)














Measured memory_bytes: 38768
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long lo;
typedef pair< lo,lo > PII;
 
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(lo i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
 
const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 100005;
const lo mod = 1000000007;
 
lo n,m,b[li],a[li],k,flag,t,dp[103][li];
lo cev;
string s;
vector<lo> v;
 
main(void){
	scanf("%lld %lld",&n,&k);
	FOR{
		scanf("%lld %lld",&b[i],&a[i]);
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<=100000;j++)dp[i][j]=inf;
	}
	FOR{
		dp[i][a[i]]=b[i];
	}
	FOR{
		for(int j=li-5;j>=0;j--){
			if(j-a[i]<0){dp[i][j]=dp[i-1][j];}
			else dp[i][j]=min(min(dp[i-1][j],dp[i][j]),(dp[i-1][j-a[i]])+b[i]);
		}
	}
	lo mx=0;
	//~ cout<<dp[3][90]<<endl;
	for(int i=li-5;i>=0;i--){
		//~ if(dp[n][i]!=inf)cout<<i<<endl;
		if(dp[n][i]!=inf && dp[n][i]<=k){mx=i;break;}
	}
	printf("%lld\n",mx);
	return 0;
}


Measured memory_bytes: 82176
#include <stdio.h>
int main(){
  int a1[3][10],a2[3][10],a3[3][10],a4[3][10],n,b,f,r,v,i,j,k;
 
  for(i=0;i<3;i++)for(j=0;j<10;j++){
      a1[i][j]=0;
      a2[i][j]=0;
      a3[i][j]=0;
      a4[i][j]=0;
    }

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d %d %d %d",&b,&f,&r,&v);
    if(b==1) a1[f-1][r-1]+=v;
    else if(b==2) a2[f-1][r-1]+=v;
    else if(b==3) a3[f-1][r-1]+=v;
    else if(b==4) a4[f-1][r-1]+=v;
  }
  for(k=0;k<4;k++){
    for(i=0;i<3;i++){
      for(j=0;j<10;j++){
	if(k==0) printf(" %d",a1[i][j]);
	else if(k==1) printf(" %d",a2[i][j]);
	else if(k==2) printf(" %d",a3[i][j]); 
	else if(k==3) printf(" %d",a4[i][j]);
      }
      printf("\n");
    }
    if(k!=(4-1)){
      for(j=0;j<20;j++) printf("#");
      printf("\n");
    }
  }

  return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef vector<pll> vll;
typedef vector<vl> vvl;

#define fori(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i >= 0; i--)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define trav(x, a) for (auto &x : a)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define endl '\n'
#define sz(a) (int)(a).size()
#define fi first
#define se second

clock_t time_p = clock();
void time_taken()
{
    time_p = clock() - time_p;
    cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}

const ll mod = 1e9 + 7;
const ll INF = 1e18;

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

    int a, b, c, k;
    cin >> a >> b >> c >> k;

    fori(i, k + 1)
    {
        fori(j, k - i + 1)
        {
            fori(l, k - i - j + 1)
            {
                int A = (a << i);
                int B = (b << j);
                int C = (c << l);
                if (B > A and C > B)
                {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;

    time_taken();
    return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long double pi = acos(-1.0); 
typedef long long ll;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;
	int q;
	cin >> q;
	deque<char> deq;
	for(int i = 0; i < (int)s.size(); i++)  {
		deq.push_back(s[i]);
	}
	bool rev = true;
	for(int i = 0; i < q; i++) {
		int t;
		cin >> t;
		if(t == 1) {
			if(rev) {
				rev = false;
			}else {
				rev = true;
			}
		}else if(t == 2) {
			int f;
			char c;
			cin >> f >> c;
			if((f == 1 && rev) || (f == 2 && !rev)) {
				deq.push_front(c);
			}else {
				deq.push_back(c);
			}
		}
	}
	if(rev) {
		for(int i = 0; i < (int)deq.size(); i++) {
			if(i != (int)deq.size() - 1) {
				cout << deq[i];
			}else {
				cout << deq[i] << endl;
			}
		}
	}else {
		for(int i = (int)deq.size() - 1; i >= 0; i--) {
			if(i != 0) {
				cout << deq[i];
			}else {
				cout << deq[i] << endl;
			}
		}
	}
}

Measured memory_bytes: 976
import sys
from bisect import bisect_left
input = sys.stdin.readline

N,Q = map(int, input().split())
STX = [list(map(int, input().split())) for _ in range(N)]
D = [int(input()) for _ in range(Q)]

STX = sorted(STX, key=lambda x: x[2])

MASK = [-1]*Q
ANS = [-1]*Q

for (s,t,x) in STX:
  s2 = (s - x)
  t2 = (t - x)

  start = bisect_left(D, s2)
  end = bisect_left(D, t2, lo=start)

  #print(start, end, DI)
  while (start < end):
    if (-1 == MASK[start]):
      ANS[start] = x
      MASK[start] = end
      start += 1
    else:
      start = MASK[start]


print(*ANS, sep='\n')


Measured memory_bytes: 77288
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
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;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int n;
vector<lint> a;

vector<lint> solve(){
    lint dp[n+1][16];
    rep(j, 16) dp[n-1][j] = j*2;
    vector<lint> R(n+1, INF);
    R[n] = R[n-1] = 0;
    rrep(i, n-1)rep(j, 16){
        int k = 0; lint t = a[i+1];
        while((a[i] << 2*j) > t){
            t *= 4;
            ++k;
        }
        if(k <= 15) dp[i][j] = dp[i+1][k] + j*2;
        else dp[i][j] = dp[i+1][15] + (n-i-1)*(k-15)*2 + j*2;
        chmin(R[i], dp[i][j]);
    }
    return R;
}

int main(){
    scanf("%d", &n);
    a.resize(n);
    rep(i, n) scanf("%lld", &a[i]);

    auto R = solve();
    reverse(a.begin(), a.end());
    auto L = solve();
    reverse(L.begin(), L.end());

    lint ans = INF;
    rep(i, n+1) chmin(ans, L[i] + R[i] + i);
    printf("%lld\n", ans);
}

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

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

int main() {
    int a,b;
    cin >> a >> b;
    ll g = gcd(a,b);
    cout << g *(a/g) * (b/g);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------


int main(){
ll a,b,x;
cin>>a>>b>>x;
if(a>x){
    cout<<"NO"<<endl;
}
else if(x-a<=b){
    cout<<"YES"<<endl;
}else{
    cout<<"NO"<<endl;
}
}









Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mkp make_pair
#define rep(i,s,f) for(i=s;i<f;i++)
#define db cout<<'h'<<'i'<<endl 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 100005
#define lg 18
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;

    cin>>n>>t;
    cout<<n/(2*t+1) +(n%(2*t+1)!=0);  

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#define mod 998244353
using namespace std;
int fac[1000006], inv[1000006];
int fpw(int x, int y){
	int ans = 1;
	for (int i = 1; i <= y; i <<= 1, x = 1LL * x * x % mod)
		if (y & i)
			ans = 1LL * ans * x % mod;
	return ans;
}
int C(int n, int m){
	return 1LL * fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int main(){
	int n, a, b;
	long long k;
	cin >> n >> a >> b >> k;
	fac[0] = 1;
	for (int i = 1; i <= n; ++ i)
		fac[i] = 1LL * fac[i - 1] * i % mod;
	inv[n] = fpw(fac[n], mod - 2);
	for (int i = n - 1; i >= 0; -- i)
		inv[i] = 1LL * inv[i + 1] * (i + 1) % mod;
	int ans = 0;
	for (int i = 0; i <= min(1LL * n, k / a); ++ i)
		if ((k - i * a) % b == 0 && (k - i * a) / b <= n)
			ans = (ans + 1LL * C(n, i) * C(n, (k - i * a) / b) % mod) % mod;
	cout << ans << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

struct tw{
  ll w,s,v;
};
bool operator<(const tw& a,const tw& b){
  return a.s+a.w < b.s+b.w;
}

ll n;
vector<tw> ts;
ll dp[2][20001];

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

  cin>>n;
  rep(i,n){
    ll w,s,v;
    cin>>w>>s>>v;

    ts.push_back((tw){w,s,v});
  }
  sort(all(ts));

  int crt=0,nxt=1;
  rep(i,2)rep(j,20001)dp[i][j]=-INF;
  dp[0][0]=0;
  rep(i,n){
    rep(j,20001)dp[nxt][j]=-INF;
    rep(j,20001){
      if(j<=ts[i].s&&j+ts[i].w<=20000)maxch(dp[nxt][j+ts[i].w],dp[crt][j]+ts[i].v);
      maxch(dp[nxt][j],dp[crt][j]);
    }
    swap(crt,nxt);
  }
  ll res=0;
  rep(i,20001)maxch(res,dp[crt][i]);
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 640
#!/usr/bin/env python3
import sys
from itertools import chain


def solve(N: int, S: str, T: str):
    answer = "".join([st[0] + st[1] for st in zip(S, T)])
    return answer


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    answer = solve(N, S, T)
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9068
/*
** BFS
*/

# include <cstdio>
# include <cstring>
# include <queue>
using namespace std;

const int MAX = 100 + 2;
int n, g[MAX][MAX], d[MAX], c[MAX];

void init() {
    scanf("%d", &n);
    memset(g, 0, sizeof(g));
    memset(c, 0, sizeof(c));

    int u, v, k;
    for (int i = 1; i <= n; i++) {
        d[i] = -1;
        scanf("%d%d", &u, &k);
        while (k--) {
            scanf("%d", &v);
            g[u][v] = 1;
        }
    }
}

void bfs() {
    queue<int> q;
    q.push(1);
    c[1] = 1;
    d[1] = 0;

    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int i = 1; i <= n; i++) {
            if (g[v][i] == 1 && c[i] == 0) {
                q.push(i);
                c[i] = 1;
                d[i] = d[v] + 1;
            }
        }
    }
}

void solve() {
    init();
    bfs();
    for (int i = 1; i <= n; i++) {
        printf("%d %d\n", i, d[i]);
    }
}

int main() {
    // freopen("infile", "r", stdin);
    // freopen("outfile", "w", stdout);
    solve();
    return 0;
}


Measured memory_bytes: 2800
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
LL h, w, n = 0, m, ans[12] = {}, d[100] = {}, a[10][10] = {}, f[200][200] = {}, sum = 0;
int flag = 0;
string str;
int main(){
	cin >> str;
	for (int i = 0; i < str.size(); i++) {
		sum += str[i] - '0';
		n += (str[i] - '0')*pow(10, str.size()-i-1);
	}
	cout << (n%sum == 0 ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256