akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
 
using namespace std;
 
// Competetive Template:
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
// Debugging :
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ba  back
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp make_pair 
#define mt make_tuple
#define fi first
#define se second
#define gcd __gcd
#define maxe *max_element
#define mine *min_element
#define deb debug
 
#define forz(i,n) for(long long int i=0;i<n;i++)
#define rep(i,k,n) for (lli i = k; i <= n; i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)
 
typedef pair <lli,lli> pll;
 
 
lli countGreater(lli arr[], lli n, lli k) 
{ 
    lli l = 0; 
    lli r = n - 1; 
  
    // Stores the index of the left most element 
    // from the array which is greater than k 
    lli leftGreater = n; 
  
    // Finds number of elements greater than k 
    while (l <= r) { 
        lli m = l + (r - l) / 2; 
  
        // If mid element is greater than 
        // k update leftGreater and r 
        if (arr[m] > k) { 
            leftGreater = m; 
            r = m - 1; 
        } 
  
        // If mid element is less than 
        // or equal to k update l 
        else
            l = m + 1; 
    } 
  
    // Return the count of elements greater than k 
    return (n - leftGreater); 
}
 
bool is_palin(string input)
{
if (input == string(input.rbegin(), input.rend())) 
    return true;
return false;
}
void solve()
{
    lli s,w;cin>>s>>w;
    if(w>=s)
    {
        cout<<"unsafe"<<endl;
        return;
    }
    else
    {
        cout<<"safe"<<endl;
    }
}
 
int main()
{
    kira; 
 
    lli t=1; //cin>>t;
    while(t--)
    {
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;
const int INF = LLONG_MAX;

int mod_pow(int x, int n) {
    int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

const int MAXN = 3000010;
int fact[MAXN], inv[MAXN];

void init_fact() {
    fact[0] = 1;
    for(int i=1; i<MAXN; i++) {
        fact[i] = (fact[i-1] * i) % MOD;
    }

    inv[MAXN - 1] = mod_pow(fact[MAXN - 1], MOD-2);
    for(int i=MAXN - 2; i>=0; i--) {
        inv[i] = (inv[i+1] * (i+1)) % MOD;
    }
}

int comb(int n, int r) {
    if(r < 0 || n < r) return 0;
    return fact[n] * inv[n-r] % MOD * inv[r] % MOD;
}

map<int, int> prime_factors(int n) {
    map<int, int> res;
    if(n == 1) { // n=1 の素因数分解は n^1
        res[n] = 1;
        return res;
    }
    for(int i = 2, _n = n; i*i <= _n; ++i) {
        while(n % i == 0) {
            ++res[i]; // 素数i^{res[i]}
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}


signed main(){
    
    init_fact();
    int n, m; cin >> n >> m;
    int ans = 1LL;
    map<int, int> res = prime_factors(m);
    for(map<int, int>::iterator it = res.begin(), end = res.end(); it != end; ++it) {
        ans = ans * comb(n - 1 + it->second, it->second);
        ans %= MOD;
    }

    if(m == 1) cout << 1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 47104
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n,k;
    cin >> n >> k;
    int cnt = 0;
    while(n){
        n /= k;
        cnt++;
    }
    cout << cnt << endl;
}

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

#define FOR(i, s, e)   for(int i = (s); i < (e); i++)
#define FOR64(i, s, e) for(ll  i = (s); i < (e); i++)
#define ALL(x)         (x).begin(), (x).end()
#define SORT(b, e)     sort((b), (e))
#define REV(b, e)      reverse((b), (e))
#define VSORT(v)       sort((v).begin(), (v).end())
#define VREV(v)        reverse((v).begin(), (v).end())
#define pb(a)          push_back(a)
#define INF            999999999

typedef long long ll;

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

	cout << (N - i + 1) << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

class UnionFind {
public:
	vector < ll > par;
	vector < ll > siz;
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1) {
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1);
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	ll root(ll x) {
		while (par[x] != x) {
			x = par[x] = par[par[x]];
		}
		return x;
	}
	bool unite(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}
	bool same(ll x, ll y) {
		return root(x) == root(y);
	}
	ll size(ll x) {
		return siz[root(x)];
	}
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    rep(i, m){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }
    ll ans = 0;
    rep(i, m){
        UnionFind uf(n);
        rep(j, m){
            if(j == i)continue;
            uf.unite(a[j], b[j]);
        }
        if(!uf.same(a[i], b[i]))ans++;
    }
    cout << ans << endl;
}   


Measured memory_bytes: 256
//F5で実行 Shift+F5で停止
//F9でブレークポイント
#include<cmath>
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
//Shift+PageUpで上部の大半を選択できる
// 1e18 = 10の18乗

int N;

int l[(1000 * 1000)+1];
int L[(1000 * 1000) + 1];
int found[(1000 * 1000) + 1];

void _main(){
	set<int> st;

	cin >> N;
	rep(i,0,N) {
		cin >> L[i];
		st.insert(L[i]); // setに入れて重複を削除
	}

	// setから配列に戻す
	/*
	int cnt = 0;
	for (auto x : st) {
		L[cnt] = x;
		cnt++;
	}
	*/

	int ans = 0;

	for (int i = 0; i < N;i++) {
		for (int j = i + 1; j < N;j++) {
			for (int k = j + 1; k < N; k++) {
				if (L[i] != L[j] && L[j] != L[k] && L[k] != L[i]) {
					int Len = L[i] + L[j] + L[k];
					int maxLen = max(L[i], max(L[j], L[k]));
					int leftLen = Len - maxLen;

					if (maxLen < leftLen) {
						ans++;
					}
				}
			}
		}
	}

	cout << ans;
}

Measured memory_bytes: 3616
fun main(args: Array<String>) {
    val a = readLine()!!.toInt()
    val b = readLine()!!.toInt()
    val c = readLine()!!.toInt()
    val x = readLine()!!.toInt()
    var count = 0
    for (i in 0..a) {
        if (i * 500 > x) continue
        for (j in 0..b) {
            if (i * 500 + j * 100 > x) continue
            val sa = x - (i * 500 + j * 100)
            if (sa == 0) {
                count++
            } else if (sa / 50 <= c) {
                count++
            }
        }
    }
    println(count)
}


Measured memory_bytes: 31616
#include<cstdio>
#include<cstring>
#include<iostream>
#include<stdlib.h>
#include<ctime>
#include<string>
#include<cmath>
#include<algorithm>
#include<complex>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LL long long
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef pair<int,int> pa;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
char s[666],S[666];
int n,m,rp,ans;
char C;
bool check(int m){
	FOR(i,1,m)
		if (s[i]!=C) return 0;
	return 1;
}
int main(){
	scanf("%s",S+1);
	n=strlen(S+1);
	ans=n+n;
	FOR(c,'a','z'){
		FOR(i,1,n) s[i]=S[i];
		C=c;
		int rp=0,m=n;
		while (!check(m)){
			++rp;
			FOR(i,1,m-1)
				if (s[i+1]==c) s[i]=c;
			--m;
		}
		ans=min(ans,rp);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include "math.h"


int main(int argc, char *argv[]){

  int i;
  char S[101];
  int l;
  int x=0;

  scanf("%s", S);

  l = strlen(S);

  for(i=0; i<=l-1; i++){
    if(i%2 == 1){
      if(S[i] == 'L' || S[i] == 'U' || S[i] == 'D'){
        x = x;
      }else{
        x++;
      }
    }else if(i%2 == 0){
      if(S[i] == 'R' || S[i] == 'U' || S[i] == 'D'){
        x = x;
      }else{
        x++;
      }
    }
  }

  if(x == 0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 128
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,p[100005],P,ans;
ll a[100005],A[100005];
bool b[100005];
map<ll,int> m;
void mul(ll &x,ll y){
    if(x>10000000000ll/y)x=0;
    x*=y;
    if(x>10000000000ll)x=0;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%lld",a+i);
    for(int i=2;i<=100000;++i){
        if(b[i]) continue;
        if(i<=2154)p[++P]=i;
        for(int j=i*2;j<=100000;j+=i)b[j]=1;
    }
    for(int i=1;i<=n;++i){
        for(int j=1;j<=P;++j){
            ll o=p[j];
            o=o*o*o;
            while(a[i]%o==0)a[i]/=o;
        }
        ll _=1,t=a[i];
        if(t==1){
            ans=1;
            continue;
        }
        for(int j=1;j<=P;++j){
            ll o=p[j];
            if(t%o) continue;
            if(t%(o*o)==0)t/=o*o,mul(_,o);
            else t/=o,mul(_,o),mul(_,o);
        }
        if(t>1){
            double d=t*1.0+10.0;
            d=sqrt(d);
            ll o=d;
            while(o*o>t)--o;
            if(o*o==t&&!b[o])mul(_,o);
            else mul(_,t),mul(_,t);
        }
        A[i]=_;
        ++m[a[i]];
    }
    for(int i=1;i<=n;++i){
        if(a[i]==1) continue;
        ans+=max(m[a[i]],m[A[i]]);
        m[a[i]]=0;
        m[A[i]]=0;
    }
    printf("%d\n",ans);
    //system("pause");
    return 0;
}


Measured memory_bytes: 12160
import collections
N = int(input())
a = list(map(int, input().split()))

table = collections.defaultdict(int)
m = 0
for i in range(N):
    table[a[i]] += 1
    if a[i] == m or a[i] == m+1:
        m = a[i]
if m == 0:
    print(-1)
else:
    print(N - m)


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    i64 x,y,z,k; cin >> x >> y >> z >> k;
    vl a(x), b(y), c(z);
    rep(i,x) cin >> a[i];
    rep(i,y) cin >> b[i];
    rep(i,z) cin >> c[i];

    /**
     * A+Bを全列挙
     * A+B, C, をsort
     * 上から見ていく
     */

    vl ab;
    rep(i,x)rep(j,y) {
        ab.push_back(a[i] + b[j]);
    }

    sort(ab.rbegin(), ab.rend());
    sort(c.rbegin(), c.rend());

    vl AB;
    rep(i,min(u32(3001), ab.size())) AB.push_back(ab[i]);

    maxheap<i64> abc;
    for(auto p : AB) {
        for(auto q : c) {
            abc.push(p+q);
        }
    }

    rep(i,k) {
        cout << abc.top() << '\n';
        abc.pop();
    }


    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807



int n,a[100000],aMax,ans[2],memo;
double tmp=INF;

main() {
    cin >> n;
    rep(i,n) {
        cin >> a[i];
        if (aMax < a[i]) aMax = a[i],ans[0] = a[i],memo = i;
    }
    rep(i,n) {
        if (memo == i) continue;
        if (tmp > abs((double)aMax/a[i]-2)) {
            tmp = abs((double)aMax/a[i]-2);
            ans[1] = a[i];
        }
    }
    cout << ans[0] << " " << ans[1] << endl;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();

		int t = c/b;
		if ( c%b!=0 ) t++;

		int u = a/d;
		if ( a%d!=0 ) u++;

		if ( t<=u ) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int solve(vector<tuple<int,int,int,int>>& vt, int n, int m, int i, int mn, vecint& v) {
  if (i == n) {
    int score = 0;
    for (auto [a,b,c,d]:vt) {
      if (v[b] - v[a] == c) score += d;
    }
    return score;
  } else {
    int mx = 0;
    FOR(j,mn,m+1) {
      auto nx = v;
      nx.push_back(j);
      mx = max(mx, solve(vt, n, m, i+1, j, nx));
    }
    return mx;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,m,q;
  cin>>n>>m>>q;
  vector<tuple<int,int,int,int>> vt;
  REP(i,q) {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    --a;--b;
    vt.emplace_back(a,b,c,d);
  }
  vecint v;
  cout<<solve(vt,n,m,0,1,v)<<endl;
  return 0;
}


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

int main()
{
    long long n;
    int k;
    cin>>n>>k;
    for(int i=0;i<k;++i){
        int a,b;
        cin>>a>>b;
        int m[4]={a,b,n-a+1,n-b+1};
        sort(m,m+4);
        if(m[0]%3==1)cout<<1<<endl;
        else if(m[0]%3==2)cout<<2<<endl;
        else cout<<3<<endl;
    }
    return 0;
}

Measured memory_bytes: 1184
n = int(input())
A = [int(_) for _ in input().split()]

for i in range(n):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(' '.join(map(str, A)))



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

const int INF = 1000000007;

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

struct edge{
    int to;
    int cost;
    edge(){}
    ~edge(){}
    edge(int a, int b): to(a), cost(b){}
};

struct state{
    int pos;
    int cost;
    state(){}
    ~state(){}
    state(int a, int b): pos(a), cost(b){}
    bool operator <(const state& b) const {
        return cost > b.cost;
    }
};

typedef vector<vector<edge> > graph;

vector<int> d;

void dijkstra(int src, graph& G){
    d.resize(G.size());
    fill(d.begin(), d.end(), INF);
    d[src] = 0;
    priority_queue<state> que;
    que.push(state(src, 0));
    while(!que.empty()){
        state s = que.top(); que.pop();
        int pos = s.pos;
        if(d[pos] < s.cost) continue;
        for(int i = 0; i < G[pos].size(); i++){
            int nxt = G[pos][i].to, e_cost = G[pos][i].cost;
            if(s.cost + e_cost < d[nxt]){
                d[nxt] = s.cost + e_cost;
                que.push(state(nxt, d[nxt]));
            }
        }
    }
}

int main(){
    int V, E, r;
    scanf("%d%d%d", &V, &E, &r);
    graph G(V);
    for(int i = 0; i < E; i++){
        int s, t, d;
        scanf("%d%d%d", &s, &t, &d);
        G[s].push_back(edge(t, d));
    }
    dijkstra(r, G);
    for(int i = 0; i < G.size(); i++){
        if(d[i] == INF){
            puts("INF");
        }else{
            printf("%d\n", d[i]);
        }
    }
    
    return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
    int N;
    cin >> N;
    vector<int> arr;
    int cur;
    for (int i = 0; i < N; i++) {
        cin >> cur;
        arr.push_back(cur);
    }

    int64_t ans = 0;
    for (int j = 0; j < N; j++) {
        ans += arr[j] - 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
char c,s[15];
int main()
{
    int t=0;
    while(scanf("%c",&c) && c!='\n')
    {
        if(c=='B' && t!=0)
            s[--t]='\0';
        else if(c=='B' && t==0)
            continue;
        else
            s[t++]=c;
    }
    printf("%s",s);
    return 0;
}


Measured memory_bytes: 128
d[5000],c;main(w,n,i,C,W,b){for(;scanf("%d%d",&w,&n),w;printf("Case %d:\n%d\n%d\n",++c,d[w],b))for(bzero(d,w*5);n--;)for(i=w,scanf("%d,%d",&C,&W);i>=W;i--)d[i]=fmax(d[i],d[i-W]+C),b=d[i]-d[w]?b:i;}

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

using namespace std;

const int MaxN = 2000005;
const long long Mod = 1000000007;

int n, k;
string s;

long long Power(long long a, long long b)
{
    long long Resuft = 1;
    while (b)
    {
        if (b & 1)
        {
            Resuft = Resuft * a % Mod;
        }
        b /= 2;
        a = a * a % Mod;
    }
    return Resuft;
}

long long fct[MaxN], ifct[MaxN];

void Init()
{
    fct[0] = 1;
    for (int i = 1; i < MaxN; i++)
    {
        fct[i] = (fct[i - 1] * i) % Mod;
    }
    ifct[MaxN - 1] = Power(fct[MaxN - 1], Mod - 2);
    for (int i = MaxN - 2; i >= 0; i--)
    {
        ifct[i] = (ifct[i + 1] * (i + 1)) % Mod;
    }
}

long long C(int n, int k)
{
    return (((fct[n] * ifct[k]) % Mod) * ifct[n - k]) % Mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> k >> s;
    n = s.size();
    long long Ans = 0;
    Init();
    for (int i = 0; i <= k; i++)
    {
        Ans = (Ans + Power(25, k - i) * Power(26, i) % Mod * C(k - i + n - 1, n - 1)) % Mod;
    }
    cout << Ans;
    return 0;
}

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

bool grid[1000][1000];
int num[1001][1001],i,j,h,w,n,t;

int main(){
  while(scanf("%d%d%d",&h,&w,&n) && (h||w||n)){
    for(i=0;i<h;i++)
      for(j=0;j<w;j++){
	scanf("%d",&t);
	grid[i][j] = t?true:false;
	num[i][j] = 0;
      }

    num[0][0] = n-1;
    for(i=0;i<h;i++)
      for(j=0;j<w;j++){
	int N=num[i][j];
	if(grid[i][j]){
	  num[i+1][j] += N/2;
	  num[i][j+1] += N-N/2;
	}else{
	  num[i][j+1] += N/2;
	  num[i+1][j] += N-N/2;
	}
	if(N&1)grid[i][j] = !grid[i][j];
      }

    i=j=0;
    while(i<h && j<w)grid[i][j]?j++:i++;
    printf("%d %d\n",i+1,j+1);
  }
}

Measured memory_bytes: 5656
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int a,b,c,d,n,k;
    cin>>n>>k;
    int ara[n];
    for(int i=0;i<n;i++)  cin>>ara[i];
    sort(ara,ara+n);

    n-=k;
    long long sum=0;
    for(int i=0;i<n;i++) sum+=ara[i];
    cout<<sum<<endl;
}


Measured memory_bytes: 1024
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


class CmbMod:
    def __init__(self, n, p):
        """
        二項係数nCr(n個の区別できるものからr個のものを選ぶ組み合わせの数)をpで割った余りを求める
        """
        self.n = n
        self.p = p
        self.fact = [1, 1]
        self.factinv = [1, 1]
        self.inv = [0, 1]

    def cmb_mod(self, n, r):
        """
        二項係数nCr(mod p)をO(r)にて計算。nが大きいがrは小さい時に使用。
        """
        numer, denom = 1, 1
        for i in range(r):
            numer = (numer * (n - i)) % self.p
            denom = (denom * (i + 1)) % self.p
        return (numer * pow(denom, self.p - 2, self.p)) % self.p

    def prep(self):
        """
        二項係数nCr(mod p)をO(1)で求める為の前処理をO(N)にて実行。
        """
        for i in range(2, self.n + 1):
            self.fact.append((self.fact[-1] * i) % self.p)
            self.inv.append((-self.inv[self.p % i] * (self.p // i)) % self.p)
            self.factinv.append((self.factinv[-1] * self.inv[-1]) % self.p)

    def cmb_mod_with_prep(self, n, r):
        """
        二項係数nCr(mod p)をO(1)で求める。事前にprepを実行する事。
        """
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return self.fact[n] * self.factinv[r] * self.factinv[n - r] % self.p


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    D = Counter(A)
    dup = 0
    for k, v in D.items():
        if v == 2:
            dup = k
            break

    flg = 1
    right, left = 0, 0
    for i in range(n + 1):
        if flg and A[i] == dup:
            left = i
            flg ^= 1
        elif A[i] == dup:
            right = i
            break

    remain = n - (right - left)
    cmb = CmbMod(n + 1, mod)
    cmb.prep()
    for i in range(1, n + 2):
        res = cmb.cmb_mod_with_prep(n + 1, i) - cmb.cmb_mod_with_prep(remain, i - 1)
        print(res % mod)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 28244
h, w = gets.split.map(&:to_i)
while h != 0 || w != 0 do
for b in 1..w do
	print "#"
end
puts
	for a in 3..h do
		print "#"
		for b in 3..w do
			print "."
		end
		print "#"
		puts
	end
	for b in 1..w do
	print "#"
end
puts
puts
h, w = gets.split.map(&:to_i)
end

Measured memory_bytes: 8804
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; ++i)
#define RREP(i, n) for (int i = n; 0 <= i; --i)
#define FOR(i, start, end) for (int i = start; i < end; ++i)
#define RFOR(i, start, end) for (int i = start; end <= i; --i)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
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; }


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

    ll N; cin >> N;
    cout << ((N-1)/2) << '\n';
}



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

struct Node{
    int key;
    Node *parent,*left,*right;
};
Node *root,*NIL;

Node *treeMinimum(Node *x){
    while(x->left!=NIL)
        x=x->left;
    return x;    
}

Node *find(Node *u,int k){
    while(u!=NIL&&k!=u->key){
        if(u->key>k)
            u=u->left;
        else
            u=u->right;
    }
    return u;
    
}

Node *treeSuccessor(Node *x){
    if(x->right!=NIL)return treeMinimum(x->right);
    Node *y=x->parent;
    while(y!=NIL&&x==y->right){
        x=y;
        y=y->parent;
    }
    return y;
}

void treeDelete(Node *z){
    Node *y;
    Node *x;

    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 insert(int k){
    Node *y=NIL;
    Node *x=root;
    Node *z;

    z=(Node *)malloc(sizeof(Node));
    z->key=k;
    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;
    }
}
void inorder(Node *u){
    if(u==NIL)return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node *u){
    if(u==NIL)return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
    int n,x;
    char com[7];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>com;
        if(com[0]=='i'){
            cin>>x;
            insert(x);
        }else if(com[0]=='f'){
            cin>>x;
            Node *t=find(root,x);
            if(t!=NIL)printf("yes\n");
            else printf("no\n");
        }else if(com[0]=='p'){
            inorder(root);
            putchar('\n');
            preorder(root);
            putchar('\n');
        }else if(com[0]=='d'){
            cin>>x;
            treeDelete(find(root,x));
        }   
    }   
    return 0;
        
}  



Measured memory_bytes: 21936
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)


int main(){
  ll n;
  cin >> n;
  ll h[n];
  ll dp[n+10];
  rep(i,n+10)dp[i]=0;
  rep(i,n){
    cin >> h[i];
  }
  dp[1]=abs(h[1]-h[0]);
  rep(i,n){
    if(i>1)dp[i]=min((dp[i-1]+abs(h[i]-h[i-1]))
    ,dp[i-2]+abs(h[i]-h[i-2]));
  }
  cout << dp[n-1] << endl;
}


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

#include <atcoder/all>

using namespace std;
using namespace atcoder;

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

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

    int N, Q;
    cin >> N >> Q;
    dsu uf(N);
    rep(i, Q) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t == 0) {
            uf.merge(u, v);
        } else {
            int ans = uf.same(u, v);
            cout << ans << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 3944
a, b, x = map(int, input().split())

# 0~a-1でいくつあるか
if a == 0:
    count_a = 0
else:
    count_a = (a-1) // x + 1


# 0~bでいくつあるか
count_b = b // x + 1

print(count_b - count_a)


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

int main() {
  int i, j, cnt, max;
  string s;
  cin >> s;
  max = INT_MIN;
  for (i = 0; i < s.length(); i++) {
    cnt = 0;
    for (j = i; j < s.length(); j++) {
      if (s[j] == 'A' || s[j] == 'T' || s[j] == 'G' || s[j] == 'C')
        cnt++;
      else
        break;
    }
    if (cnt > max) max = cnt;
  }

  cout << max << endl;
}

Measured memory_bytes: 3624
x_1, y_1, x_2, y_2 = map(int, input().split())
x_3 = x_2 - y_2 + y_1
y_3 = y_2 + x_2 - x_1
x_4 = x_3 - x_2 + x_1
y_4 = y_3 - y_2 + y_1
print(x_3, y_3, x_4, y_4)


Measured memory_bytes: 2940
from collections import deque
n, m = map(int, input().split())
edges = [[]*n for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)
#print(edges)
d = deque()
d.append(0)
visited = [False]*n
visited[0] = True
from_0 = [0]*n
while d:
    x = d.popleft()
    for child in edges[x]:
        if visited[child]:
            continue
        else:
            visited[child] = True
            d.append(child)
            from_0[child] = from_0[x] + 1
#print(from_0)
if from_0[n-1] == 2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")



Measured memory_bytes: 45156
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    cout<<s1[0]<<s2[0]<<s3[0]<<Endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------




Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

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



int main() {
  int a, b;
  cin >> a >> b;

  int ans = 0;
  for(int i = a; i <= b; i++) {
    string s = to_string(i);
    if(s[0] == s[4] && s[1] == s[3]) ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import itertools
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, A, B, C = list(map(int, sys.stdin.readline().split()))
L = [int(sys.stdin.readline()) for _ in range(N)]

L = np.array(L)

# 全部試す
choosing = np.array(list(itertools.product([0, 1, 2, 3], repeat=N)))
# 0: 選ばない
# 1: 竹 A にする
# 2: 竹 B にする
# 3: 竹 C にする
a = choosing == 1
b = choosing == 2
c = choosing == 3
acnt = a.sum(axis=1)
bcnt = b.sum(axis=1)
ccnt = c.sum(axis=1)
ans = abs(np.dot(a, L) - A) + (acnt - 1) * 10
ans += abs(np.dot(b, L) - B) + (bcnt - 1) * 10
ans += abs(np.dot(c, L) - C) + (ccnt - 1) * 10
print(ans[(acnt > 0) & (bcnt > 0) & (ccnt > 0)].min())


Measured memory_bytes: 25316
/*
 
dunjen_master
 
*/
 
 

 
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
 
using namespace std;
 
const int MAX_N = int(1e6) + 10;
const long long int MOD=1e9+7;
const long long int INF=1e18;
 
typedef long long int ll;
typedef unsigned long long int llu;
 
 
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

inline ll mul(ll a,ll b){

    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll c=a*b;
    c=(c+MOD)%MOD;
    return c;
}
inline ll add(ll a,ll b){
    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll ans=(a+b);
    ans=(ans+MOD)%MOD;
    return ans;
}
ll power(ll a,ll b,ll c=0){
    ll ans=1;
    while(b){
        if(b&1){
            ans=mul(ans,a);
        }
        a=mul(a,a);
        b=b/2;
    }
    return ans;
}

  

 
#define all(x) (x).begin(),(x).end()

/* ordered_set A;
   A.insert(x);
   A.erase(x);
   A.order_of_key(x) // no of elements less than (<) x
   *A.find_by_order(k-1) // kth smallest element
*/






int main(){
 

  
  
  ll n,m;
  cin>>n>>m;
  vector<ll>v(m);
  ll sum=0;
  for(int i=0;i<m;i++){
    cin>>v[i];
    sum+=v[i];
  }
  if(sum<=n){
    cout<<n-sum<<endl;
  }else{
    cout<<"-1"<<"\n";
  }
  
  
  
  return 0;
  }
  


   

    


    


    
    
    
    
 
    


Measured memory_bytes: 3672
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int ans;

vector<int> split(string s){
	int n=0;
	vector<int> vc;

	for(int i=0 ; i < s.size() ; i++ ){
		char c = s[i];
		if( c == ' ' ){
			vc.push_back( n );
			n = 0;
		}else if( c >= '0' && c <= '9' ){
			n *= 10;
			n += c - '0';
			if( i == s.size()-1 )
				vc.push_back( n );
		}
	}
	return vc;
}

void solve(const vector<int>& a,int i,int p){
	if( p > 21 ){
		return;
	}
	if( i == a.size() ){
		ans = max( ans , p );
		return;
	}

	if( a[i] == 1 ){
		solve( a , i+1 , p+1  );
		solve( a , i+1 , p+11 );
	}else if( a[i] >= 10 ){
		solve( a , i+1 , p+10 );
	}else{
		solve( a , i+1 , p+a[i] );
	}
}

int main(){
	string s;
	while( getline(cin,s) ){
		vector<int> a = split(s);
		if( a.size() == 1 && a[0] == 0 ) break;

		ans = 0;
		solve( a , 0 , 0 );
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
from fractions import gcd

n, m = map(int, input().split())

s = input()
t = input()


l = (n * m) // gcd(n, m)

p = l // n
q = l // m
r = (p * q) // gcd(p, q)

ans = l

for i in range(l//r):
    if s[r//p*i] != t[r//q*i]:
        ans = -1
        break

print(ans)

Measured memory_bytes: 5688
#define _GLIBCXX_DEBUG
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;

int P[10010];
void init(int n){
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);//代表元を求める
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対set,グラフ？

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

int main(){
    string s;
    int k=0, l=0;
    cin >> s;
    char a[4];
    rep(i,s.size()){
        a[i]=s[i];
    }
    if(a[0]!=a[1]){
        if((a[2]==a[0]&&a[3]==a[1])||(a[2]==a[1]&&a[3]==a[0])){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }else{
        if(a[2]==a[3]&&a[0]!=a[2]){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <limits.h>
#include <assert.h>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long int
#define db double
#define ldb long double
#define MOD 1000000007
#define FI first
#define SE second
#define INF INT_MAX
#define NINF INT_MIN
#define L_INF LLONG_MAX
#define L_NINF LLONG_MIN
#define gc getchar
#define sz size


void fsscan()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void scan(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}

int main()
{
    //Write Your Code Here
    int n;
    cin>>n;
    int a[n-1][3];
    for(int i=0;i<n-1;i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    for(int i=0;i<n-1;i++)
    {
        int s=0;
        s+=a[i][1];
        s+=a[i][0];
        for(int j=i+1;j<n-1;j++)
        {
            if(s<a[j][1])
            {
                s=a[j][1];
            }
            if(s%a[j][2]!=0)
            {
                s+=a[j][2]-s%a[j][2];
            }
            s+=a[j][0];
        }
        cout<<s<<endl;
    }
    cout<<"0";
    return 0;
}



Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

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


int main(void) {

	while (1) {
		int n;
		int count = -1;
		int f, t;

		int dp[51][51] = {};
		int time[51][31] = {};

		cin >> n;
		if (n == 0) {
			break;
		}
		FOR(i, 1, n) {
			cin >> f;
			FOR(j, 1, f) {
				cin >> t;
				time[i][t] = 1;
			}
		}
		
		FOR(i, 1, n) {
			dp[i][i] = 1;
		}

		FOR(i, 1, 30) {
			int maps[51] = {};
			FOR(j, 1, n) {
				if (time[j][i] == 1) {
					FOR(k, 1, n) {
						if (dp[j][k] == 1) {
							maps[k] = 1;
						}
					}
				}
			}
			
			FOR(j, 1, n) {
				if (time[j][i] == 1) {
					FOR(k, 1, n) {
						dp[j][k] = maps[k];
					}
				}
			}

			FOR(j, 1, n) {
				FOR(k, 1, n) {
					if (dp[j][k] != 1) {
						break;
					}
					if (k == n) {
						count = i;
						break;
					}
				}
				if (count != -1) {
					break;
				}
			}

			if (count != -1) {
				break;
			}
		}

		cout << count << endl;


	}

	
	return 0;
}


Measured memory_bytes: 3052
import java.util.*;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		int A, B, C, D;
		Scanner sc = new Scanner(System.in);
		A = sc.nextInt();
		B = sc.nextInt();
		C = sc.nextInt();
		D = sc.nextInt();
		
		//if(!(A*B==C*D)){
			if(A*B>C*D){
				System.out.println(A*B);
			}else{
				System.out.println(C*D);
			}
		//}else{
		//	System.out.println(A*B);
		//}
	}
}

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

int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    if(k <= a){
        ans = k;
    }
    else if(k <= a + b){
        ans = a;
    }
    else{
        ans = a - (k - (a + b));
    }

    cout << ans << endl;
    
}

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

int main(){
    int N,R;
    cin >> N >> R;
    int ans = 0;
    if ( N < 10 ){
        ans = R + 100 * ( 10 - N );
    } else {
        ans = R;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define eb emplace_back
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }
void ok() { cerr << "ok" << endl; }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll n, k;
    cin >> n >> k;
    n %= k;
    cout << min(n, k - n) << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc142d()
}

fun abc142d() {
    val (a, b) = readLine()!!.split(" ").map { it.toLong() }

    val apf = primeFactorization(a).keys
    val bpf = primeFactorization(b).keys

    val answer = apf.intersect(bpf)

    println(answer.size + 1)
}

//素因数分解
fun primeFactorization(n: Long): Map<Long, Long> {
    val factors = mutableMapOf<Long, Long>()
    var temp = n
    var i = 2L
    while (i * i <= temp) {
        while (temp % i == 0L) {
            factors[i] = (factors[i] ?: 0) + 1
            temp /= i
        }
        i++
    }
    // 残った数=素数が1以上の場合、それも含めるように
    if (temp > 1) factors[temp] = 1
    return factors
}


Measured memory_bytes: 38064