akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/


int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    vector<string> s(n);
    rep(i, n) {
        cin >> s[i] >> p[i];
    }
    vector<string> name(0);
    rep(i, n) {
        int flag = 0;
        rep(j, name.size()) {
            if (s[i] == name[j]) {
                flag = 1;
                break;
            }
        }
        if (flag == 0)
           name.emplace_back(s[i]);
        
    }
    sort(name.begin(), name.end());
    
    rep(i, name.size()) {
        vector<int> num(0);
        rep(j, n) {
            if (name[i] == s[j]) {
                num.push_back(j);
            }
        }
        vector<int> pla(0);
        rep(j, num.size()) {
            pla.emplace_back(p[num[j]]);
        }
        while (num.size()) {
            int max = -1;
            int ind;
            int k_ind;
            rep(k, pla.size()) {
                if (max < pla[k]) {
                    ind = num[k] + 1;
                    max = pla[k];
                    k_ind = k;
                }
            }
            cout << ind << endl;
            num.erase(num.begin() + k_ind);
            pla.erase(pla.begin() + k_ind);
        }
    }
    
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

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

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

int main(){
    int K;
    cin >> K;
    
    int64_t res = 0;
    for ( int a = 1; a <= K; ++a){
        for ( int b = 1; b <= K; ++b){
            for ( int c = 1; c <= K; ++c){
                res += gcd(a,gcd(b,c));
            }
        }
    }
    cout << res << endl;
    
    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
  int n=0;
  int m=100000;
  cin>>n;
  for(int i=0;i<n;i++){
	  m=m*1.05;
	  if(m%1000!=0){
		  m=m+999;
		  m=m/1000;
		  m=m*1000;
	  }
  }
  cout<<m<<endl;

  return 0;
}

Measured memory_bytes: 3076
using AtCoderBeginnerContest152.Questions;
using AtCoderBeginnerContest152.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest152.Questions
{
    public class QuestionC : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadInt();
            var p = inputStream.ReadIntArray();

            int count = 0;
            int min = p[0];
            foreach (var pi in p)
            {
                if (pi <= min)
                {
                    count++;
                }
                min = Math.Min(min, pi);
            }

            yield return count;
        }
    }
}


namespace AtCoderBeginnerContest152
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionC();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest152.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest152.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 35676
N = int(input())
A = list(map(int, input().split()))
ans = 0

#最大公約数
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

#最小公倍数
def lcm(x, y):
    return x * y // gcd(x, y)

lcm_A = lcm(A[0], A[1])
for a in A[2:]:
    lcm_A = lcm(lcm_A, a)

for a in A:
    ans += (lcm_A-1) % a

print(ans)


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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i) cin >> a[i];
	int ans = 0;
	while(true){
		bool odd = false;
		for(int i = 0; i < n; ++i){
			if(a[i]%2 != 0) odd = true;
		}
		if(odd) break;
		for(int i = 0; i < n; ++i) a[i] /= 2;
	++ans;
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,x,ans=0;
	cin>>n>>x;
	vector<ll>v(n);
	for(ll i=0;i<n;i++){
		cin>>v.at(i);
	}
	sort(v.begin(),v.end());
	for(ll i=0;i<n;i++){
		if(i==n-1){
			if(x==v.at(i)){
				ans++;
			}
		}else if(x-v.at(i)>=0){
			x-=v.at(i);
			ans++;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

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

__attribute__ ((constructor))
void init() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
}

struct UnionFind{
  vector<int> d;
  UnionFind(int n) : d(n,-1) {}
  //根なら、-サイズを格納それ以外は、親を格納
  int find(int x){
    if(d[x] < 0) return x;
    return d[x] = find(d[x]); //経路縮約
  }
  bool unite(int x,int y){
    //二つ頂点を持ってくる
    x = find(x);
    y = find(y);
    if(x == y) return false;//根が一致するなら何もしない
    if(d[x] > d[y]) swap(x,y);
    //ex:d[x]=-5,d[y]=-2
    //小さい方が、大きい方に引っ付く
    d[x] += d[y];//この場合、yがxにくっつく
    d[y] = x;
    return true;
  }
  bool same(int x,int y) {return find(x) == find(y);}
  int size(int x) {return -d[find(x)];}
};

signed main(){
  int n,q;
  cin >> n >> q;
  UnionFind uf(n);
  vector<int> ans;
  rep(i,q){
    int t,u,v;
    cin >> t >> u >> v;
    if(t == 0) uf.unite(u,v);
    if(t == 1){
      if(uf.same(u,v)) ans.push_back(1);
      else ans.push_back(0);
    }
  }
  for(auto u : ans) cout << u << endl;
  return 0;
}

Measured memory_bytes: 4280
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9 + 7, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}



signed main(){
	int N,K;
	cin>>N>>K;
	vector<int> a(N); for(auto& e:a)cin >> e;
	int init = 0;
	REP(i,N){
		FOR(j,i+1,N){
			if(a[i]>a[j])init++;
		}
	}
	int cnt = 0;
	REP(i,N){
		REP(j,N){
			if(a[i]>a[j])cnt++;
		}
	}
	int ans = 0;
	ans = init * K + K * (K-1) / 2 % MOD * cnt;
	cout<<ans%MOD<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, m, t[100007];
pair<int, int>p[300007];
int read()
{
	int num = 0;
	char c = getchar();
	while (c < '0' || c>'9')c = getchar();
	while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
	return num;
}
int cmp(pair<int, int>a, pair<int, int>b)
{
	return a.second - a.first < b.second - b.first;
}
int add(int x, int v)
{
	while (x <= m)t[x] += v, x += x & -x;
	return 0;
}
int ask(int x)
{
	int res = 0;
	while (x)res += t[x], x -= x & -x;
	return res;
}
int main()
{
	n = read();
	m = read();
	for (int i = 1; i <= n; i++)
	{
		p[i].first = read();
		p[i].second = read();
	}
	sort(p + 1, p + n + 1, cmp);
	int pos = 1;
	for (int i = 1; i <= m; i++)
	{
		while (pos <= n && p[pos].second - p[pos].first + 1 < i)
		{
			add(p[pos].first, 1);
			add(p[pos].second + 1, -1);
			pos++;
		}
		int res = n - (pos - 1);
		for (int j = 1; i * j <= m; j++)
			res += ask(i * j);
		printf("%d\n", res);
	}
	return 0;
}

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

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #define int long long int
    string s;
    int c=0,flag=0;
    cin>>s;
    if(s.size()%2!=0){cout<<"No"<<endl;return 0;}
    for(int i=0;i<s.size()-1;i+=2)
    {
        if(s[i]=='h' && s[i+1]=='i')flag=1;
        else {flag=0;break;}
    }
    if(flag==1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

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

    int r; cin >> r;
    cout << r*r << endl;
    

    return 0;
}

Measured memory_bytes: 256
/*
auth - @sportykush
*/

#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
// using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;

//#define mp make_pair
#define bug(v)                    cerr<<#v<<" = "<<(v)<<endl;
#define bug2(v1,v2)               cerr<<#v1<<" = "<<(v1)<< ' ' << #v2<<" = "<<(v2)<<endl;
#define ERASE(x)                  x.erase(unique(x.begin(),x.end()),x.end())
#define pb                        emplace_back
#define vii                       vector<int>
#define vll                       vector<ll>
#define vpll                      vector< pair <ll,ll> >
#define pll                       pair <ll,ll>
#define pii                       pair <int,int>
#define pq                        priority_queue< int >
#define khtm                      "\n"
#define F                         first
#define S                         second
#define fr(i,a,n)                 for(i=a;i<n;i++)
#define mem(arr,l)                memset(arr,l,sizeof arr)
#define ALL(x)                    x.begin(), x.end()
#define frr(i,a,n)                for(i=n-1;i>=a;i--)
#define fast                      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define testcase                  ll T; cin>>T; while(T--)


const double pi = 3.14159265359;
const int MAX = 1e6 +2;
const ll inf =  1e18;
const int N = 1010;
//const ll mod = 998244353 ;
const ll mod = 1000000007;
inline ll add(ll a,ll b){a+=b;if(a>=mod)a-=mod;return a;}
inline ll mul(ll a,ll b){return (((a+mod)%mod)*(b+mod)%mod)%mod;}
inline ll power(ll a,ll b){ll rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline ll modInverse(ll n, ll p){ return power(n, p-2)%p; }

/*
important builtin functions
__gcd(value1, value2)
__builtin_ffs(x)
  Number of leading zeroes: __builtin_clz(x)
  Number of trailing zeroes : __builtin_ctz(x)
  Number of set bits: __builtin_popcount(x)
*/
 
void stArt()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}
void eNd()
{
	#ifndef ONLINE_JUDGE
  	cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";
  	#endif
}

//////////////////// start /////////////////////////////////
 

ll i,j,k,l,m,r,n;
ll a[MAX],b[MAX];

bool check(ll x)
{
	ll cnt = 0;
	fr(i,0,n)
	{
		cnt += (a[i]-1)/x;
		// if(a[i]%x)
		// 	cnt++;
	}
	return cnt<=k;
}

void bs()
{
	l=1,r=1e9;
	ll ans;
	while(l<=r)
	{
		ll mid = (l+r)/2;
		if(check(mid))
		{
			ans = mid;
			r = mid-1;
		}
		else
			l=mid+1;
	}
	cout << ans;
}

int main()
{
 
stArt();
fast
//cout << setprecision(15) << fixed;
	
	cin >> n >> k;
	fr(i,0,n)
		cin >> a[i];
	bs();
   
 eNd();
  return 0;
 
}

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


using namespace std;

int n;
vector<vector<int>> G;
vector<vector<int>> dis;

void dfs(int i, int s, int step){
    int b = s;
    if(s == n-1) b = 1;
    if(dis[b][i] >= 0) return;
    dis[b][i] = step;
    for(auto e : G[i]){
        dfs(e, s, step+1);
    }
}



int main(){

    cin >> n;
    G.resize(n);
    dis.assign(2, vector<int>(n, -1));
    for(int i = 0; i < n-1; ++i){
        int a, b;
        cin >> a >> b;
        --a; --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    dfs(0, 0, 0);
    dfs(n-1, n-1, 0);


    int cnt = 0;
    for(int i = 0; i < n; ++i){
        if(dis[0][i] <= dis[1][i]) ++cnt;
    }

    if(cnt > n/2) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
    
    return 0;
}


Measured memory_bytes: 11128
from collections import deque

sx, sy, tx, ty = map(int, input().split())
Done = [[-1]*3000 for _ in range(3000)]

Ans = ''
Ans += 'U' * (ty - sy)
Ans += 'R' * (tx - sx)
Ans += 'D' * (ty - sy)
Ans += 'L' * (tx - sx + 1)
Ans += 'U' * (ty - sy + 1)
Ans += 'R' * (tx - sx + 1)
Ans += 'DR'
Ans += 'D' * (ty - sy + 1)
Ans += 'L' * (tx - sx + 1)
Ans += 'U'

print(Ans)


Measured memory_bytes: 74100
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define pd(a,n) for(int i=0;i<n;i++)cout<<a[i]<<((i==n-1)?"\n":" ");cout<<endl;
#define pdd(a,n,m)for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";cout<<endl;}
#define mp make_pair
#define pb push_back
#define ll long long
//#define __int64 lng long
#define P pair<int,int>
#define PP pair<P,int>
int n,m;
int t[111111];
int sum;
int main(){
  cin>>n>>m;
  rep(i,n)cin>>t[i];
  rep(i,n)sum+=t[i];
  int ans=0;
  rep(i,n)if(t[i]*4*m>=sum)ans++;
  if(ans>=m)
  cout<<"Yes"<<endl;
  else 
    cout<<"No"<<endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  rep(i, n) cin >> a.at(i + 1);
  vector<int> b(n + 1, 0);
  for (int i = n; i >= 1; i--) {
    int sum = 0;
    for (int j = i + i; j <= n; j += i) {
      sum += b.at(j);
    }
    if (a.at(i) == 1) {
      if (sum % 2 == 1) {
        b.at(i) = 0;
      } else {
        b.at(i) = 1;
      }
    } else {
      if (sum % 2 == 1) {
        b.at(i) = 1;
      } else {
        b.at(i) = 0;
      }
    }
  }
  vector<int> res;
  for (int i = 1; i <= n; i++) {
    if (b.at(i) == 1) {
      res.push_back(i);
    }
  }
  cout << res.size() << endl;
  rep(i, res.size()) {
    if (i != 0) {
      cout << " ";
    }
    cout << res.at(i);
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 5220
def is_ok(W, truck, middle):
    loaded = 0
    for t in range(truck):
        this_total = 0
        while this_total + W[loaded] <= middle:
            this_total += W[loaded]
            loaded += 1
            if loaded == len(W):
                return True
    return False

def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(w, k, mid):
            ok = mid
        else:
            ng = mid
    return ok

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

w = [0]*n
for i in range(n):
    w[i] = int(input())

ans = meguru_bisect(-1,10**10+1)
print(ans)


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

using namespace std;

//#define FILE_IO

int N, M;
int cnt[100005], red[100005];

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d%d", &N, &M);
    for(int i = 1; i <= N; i++)
        cnt[i] = 1;
    red[1] = 1;
    for(int i = 1; i <= M; i++)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        cnt[x]--;
        cnt[y]++;
        if(red[x])  red[y] = 1;
        if(!cnt[x]) red[x] = 0;
    }

    int ans = 0;
    for(int i = 1; i <= N; i++)
        ans += red[i];
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
template< typename T >
struct segment_tree {
  int sz;
  vector<T> seg;
  const function<T(T, T)> o;
  const T id;
  segment_tree(int n, const function<T(T, T)> o, const T &id)
    : o(o)
    , id(id)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, id);
  }
  void update(int k, const T &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = o(seg[2 * k], seg[2 * k + 1]);
    }
  }
  T find(int l, int r) {
    T L = id, R = id;
    for(l += sz, r += sz; l < r; l >>= 1, r >>= 1) {
      if(l & 1) L = o(L, seg[l++]);
      if(r & 1) R = o(seg[--r], R);
    }
    return o(L, R);
  }
  T operator[](const int &k) const {
    return seg[k + sz];
  }
  void print() {
    cout << "segment_tree:" << endl;
    int crr = 1;
    for (int p = sz; p; p >>= 1) {
      for (int i = 0; i < sz; i++) {
        cout
            << setw(12)
            << (i % p == 0 ? to_string(seg[crr++]) : "")
            << (i < sz - 1 ? "" : "\n");
      }
    }
    cout << endl;
  }
};
int main() {
  pair<int, int> s, t;
  cin >> s.first >> s.second >> t.first >> t.second;
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
  sort(a.begin(), a.end());
  if (s.first > t.first) swap(s, t);
  vector<int> val;
  if (s.second > t.second) reverse(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    if (s.first <= a[i].first && a[i].first <= t.first && (
      (s.second <= a[i].second && a[i].second <= t.second)
    ||(t.second <= a[i].second && a[i].second <= s.second)
    )) {
      val.push_back(a[i].second);
    }
  }
  vector<int> srd = val;
  int sz = val.size();
  sort(srd.begin(), srd.end());
  map<int, int> mp;
  for (int i = 0; i < sz; i++) mp[srd[i]] = i;
  segment_tree<int> sgt(sz, [](int a, int b) { return max(a, b); }, 0);
  for (int i = 0; i < sz; i++) {
    sgt.update(mp[val[i]], sgt.find(0, mp[val[i]]) + 1);
  }
  double pi = acos(0) * 2;
  double w = abs(t.first - s.first);
  double h = abs(t.second - s.second);
  int cnt = sgt.find(0, sz);
  double ret = 100LL * (w + h);
  ret += cnt * (20 * pi / 4 - 20);
  if (w < cnt || h < cnt) ret += 20 * pi / 4;
  cout << setprecision(12) << ret << endl;
  return 0;
}

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

// Template Headers {{{
using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long; using vll = vector<long long>;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity() ? std::numeric_limits<T>::infinty() : std::numeric_limits<T>::max(); } };
template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } };
template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } };
constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf();
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}

int solve() {
	int n, s; cin >> n >> s;
	vi a(n); cin >> a;
	int ans = INF;
	ll cur = 0;
	int r = -1;
	for (int l = 0; l < n; l++) {
		while (r + 1 < n && cur < s) cur += a[r + 1], r++;
		if (cur >= s) ans = min(ans, r - l + 1);
		cur -= a[l];
	}
	cout << (ans >= INF ? 0 : ans) << endl;
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0);
	// precompute();
	// int t; cin >> t; for (int i=1;i<=t;i++)
	solve();
	// cout << "Case #" << i << ": ", solve();
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto it=v.begin();it!=v.end();) os << *it, os << " \n"[++it==v.end()];
	return os;
}

template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
	return is >> p.first >> p.second;
}

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

// vim: fdm=marker


Measured memory_bytes: 3320
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;

typedef long long ll;
typedef pair<int,ll> edge;
typedef pair<ll,int> P;
const ll INF=1e18;

const int MAX_N=1e5,MAX_M=1e5;
int N,M,S,T;
vector<edge> G[MAX_N][2];
ll dist[MAX_N][2];

void dijkstra(int i){
	int s;
	if (i==0){
		s=S;
	}else{
		s=T;
	}
	REP(v,N){
		dist[v][i]=INF;
	}
	dist[s][i]=0;
	priority_queue<P,vector<P> ,greater<P> > pque;
	pque.push(P(0,s));
	while(!pque.empty()){
		P p=pque.top();
		pque.pop();
		int v=p.second;
		if (dist[v][i]<p.first){
			continue;
		}
		REP(j,(int)G[v][i].size()){
			edge e=G[v][i][j];
			if (dist[e.first][i]>dist[v][i]+e.second){
				dist[e.first][i]=dist[v][i]+e.second;
				pque.push(P(dist[e.first][i],e.first));
			}
		}
	}
}

int main(){
	cin>>N>>M>>S>>T;
	S--;
	T--;
	REP(i,M){
		int u,v,a,b;
		cin>>u>>v>>a>>b;
		u--;
		v--;
		G[u][0].push_back(edge(v,a));
		G[v][0].push_back(edge(u,a));
		G[u][1].push_back(edge(v,b));
		G[v][1].push_back(edge(u,b));
	}
	dijkstra(0);
	dijkstra(1);
	vector<ll> vans(N);
	ll ans=0;
	for(int i=N-1;i>=0;i--){
		ans=max(ans,(ll)1e15-dist[i][0]-dist[i][1]);
		vans[i]=ans;
	}
	REP(i,N){
		cout<<vans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 19140
#include<iostream>
#include<vector>

using namespace std;

vector<int> ans;

int main(){
	while(1){
		int n,m,a;
		cin >> n >> m >> a;
		if(n + m + a == 0) break;
		int root[1001][101];
		for(int i = 0;i < 1001;i++){
			for(int j = 0;j < 101;j++){
				root[i][j] = 0;
			}
		}
		for(int i = 0;i < m;i++){
			int h,p,q;
			cin >> h >> p >> q;
			root[h][p] = q;
			root[h][q] = p;
		}
		int now = a;
		for(int i = 1000;i > 0;i--){
			if(root[i][now] != 0)now = root[i][now];
		}
		ans.push_back(now);
	}
	for(int i = 0;i < ans.size();i++) cout << ans[i] << endl;
	
	return 0;
}

Measured memory_bytes: 3480
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 1e9+7;
const int MAXN = 2e3 + 10;

int a[MAXN],b[MAXN];

int main()
{
    int n;
    ll k;
    scanf("%d%lld",&n,&k);
    ll k1 = k;
    k = k * (k - 1) / 2 % mod;
    for (int i = 1;i<=n;i++) scanf("%d",&a[i]);
    ll ans = 0;
    for (int i = 1;i<=n;i++)
    {
        ll tot = 0,num = 0;
        for (int j = 1;j<=n;j++)
        {
            if (a[j] < a[i])
            {
                if (j > i) tot++;
                num++;
            }
        }
        ans = ((ans + tot * k1 % mod) % mod + k * num % mod) % mod;
    }
    printf("%lld",ans);
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    int mins = 1e9;
    int maxs = -200;
    for(int i=0;i<n;i++){
        cin >> a[i];
        mins = min(mins,a[i]);
        maxs = max(maxs,a[i]);
    }
    if(mins == maxs){
        cout << 0 << endl;
        return 0;
    }
    long long ans=1e9;
    for(int i = mins;i<maxs;i++){
        long long ansa = 0;
        for(int j=0;j<n;j++){
            ansa += (a[j]-i)*(a[j]-i);
        }
        ans = min(ansa,ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
#!/usr/bin/env python3
n,y = map(int,input().split())
ans = (-1,-1,-1)
for i in range(n+1): 
	for j in range(n+1-i):
		if y == 1000*(i + j * 5 + (n-i-j) * 10 ): 
			print( n-i-j, j, i ) # 逆だった。出力は10000から出す
			exit(0)
print(-1,-1,-1)

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

int main() {
  long long N;
  cin>>N;
  for (long long h=1; h<=3500; h++) {
    for (long long n=1; n<=3500; n++) {
      long long a = 4*h*n - N*h - n*N;
      if (a <= 0) {
        continue;
      }
      long long b = N*h*n;
      if (b % a == 0) {
        printf("%lld %lld %lld\n", h, n, b / a);
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++) 
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
 
struct distination {
    int from;
    int to;
    int distance;
};
 
int N;
vector<vector<distination>> G;
vector<int> ans;
 
void dfs(int root, int p, int n) {
    ans[root] = n;
    for(auto e:G[root]){
      if(ans[e.to] != -1) continue;
      dfs(e.to,root,(n+e.distance)%2);
    }
}
 
int main() {
    cin >> N;
    G.resize(N);
    rep(i, N-1) {
        int from, to, distance;
        cin >> from >> to >> distance;
        from--;
        to--;
        distance = (distance % 2 == 1) ? 1 : 0;
        G[from].push_back({from, to, distance});
        G[to].push_back({to, from, distance});
    }
    ans.resize(N, -1);
    dfs(0,-1,0);
 
    for(auto e:ans) cout << e << endl;
}

Measured memory_bytes: 10240
#include<stdio.h>
int main(void)
{
  int k,x,i,min,max;
  scanf ("%d %d",&k,&x);
  min = x - (k-1);
  max = x + (k);
  for (min;min < max;min++)
  {
      printf("%d ",min);
  }
return 0;
}

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    //检查有没有特判0,有没有越界限.
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    ll a, b;
    cin >> a >> b;
    ll num = __gcd(a, b);
    int ans = 1;
    ll cur = num;
    for (ll i = 2; i * i <= num; i++)
    {
        if (num % i == 0)
        {
            ans++;
            while (num % i == 0)
            {
                num /= i;
            }
        }
    }
    if (num > 1)
        ans++;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n,x;
    int m[101];
    std::cin >> n >>x;
    int sum=0;
    for (int i = 0; i < n; i++) {
        std::cin >> m[i];
        sum+=m[i];
    }
    sort(m,m+n);
    std::cout << n+(x-sum)/m[0] << std::endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=998244353;
int main()
{
	int n, m; cin>>n>>m;
	int a[301][301];
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++) cin>>a[i][j];
	}
	int r=0;
	for(int i=0; i<n; i++){
		int j1=-1;
		for(int j=0; j<m; j++){
			if(a[i][j]){
				j1=j;
				break;
			}
		}
		if(j1==-1) continue;
		r++;
		for(int k=i+1; k<n; k++){
			if(a[k][j1]){
				for(int j=j1; j<m; j++){
					a[k][j]^=a[i][j];
				}
			}
		}
	}
	ll p2[301];
	p2[0]=1;
	for(int i=1; i<=max(n, m); i++) p2[i]=p2[i-1]*2%MOD;
	ll ans=(p2[n]-p2[n-r]+MOD)*p2[m-1]%MOD;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
 
int main(void){
	char a[200],b[200];
	int num,kekka;
	scanf("%s %s",&a,&b);
	strcat(a,b);
	num = atoi(a);
	kekka = (int)sqrt(num);
	if(num % kekka == 0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
 
 
void swap (int *x, int *y) {
  int temp;    
 
  temp = *x;
  *x = *y;
  *y = temp;
}
 
int gcd(int a,int b){
  if(a<b){
    swap(&a,&b);
  }
 
  if(b==0){
    return a;
  }
 
  int r=a%b;
  while(r!=0){
    a = b;
    b = r;
    r = (a%b);
  }
 
  return b;
}
 
/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}
 
 
int modpow(int a,int n,int mod){
  int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}
 
int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}
 
int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}
 
void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }
 
  return;
}
 
void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }
 
  return;
}
 

int main(void){
  char w[110];
  scanf("%s",w);
  int l=strlen(w);
  int c[26];
  for(int i=0;i<26;i++){
    c[i]=0;
  }
  for(int i=0;i<l;i++){
    c[(w[i]-'a')]++;
  }
  int ans=0;
  for(int i=0;i<26;i++){
    if(c[i]%2==1){
      ans++;
    }
  }
  if(ans==0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 1644
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    def main(x):
        xlen=len(x)
        if x==x[:xlen//2]*2:
            return True
        else:
            return False
    s=input()
    if len(s)==2:
        print(1)
    else:
        for i in range(2,len(s)-1,2):
            x=s[:-i]
            if main(s[:-i]):
                print(len(s[:-i]))
                break
resolve()

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

using namespace std;

const int NS = (int)1e5 + 4;
int N;
int arr[NS];

int main(){
    scanf("%d", &N);
    for(int i = 1; i <= N; ++i){
        int num; scanf("%d", &num);
        arr[num] = i;
    }
    for(int i = 1; i <= N; ++i){
        printf("%d ", arr[i]);
    }
    puts("");
    return 0;
}


Measured memory_bytes: 1152
N, A, B, C = list(map(int, input().split()))
l = []
for i in range(N):
  l.append(int(input()))
  
Ans = 1e15
for i in range(pow(4,N)):
  L = [0 for j in range(N)]
  t = i
  for j in range(N):
    L[j] = t % 4
    t //= 4
  if 1 not in L:
    continue
  if 2 not in L:
    continue
  if 3 not in L:
    continue

  a = 0
  b = 0
  c = 0
  Num = 0
  for j in range(N):
    if L[j] == 1:
      a += l[j]
      Num += 1
    elif L[j] == 2:
      b += l[j]
      Num += 1
    elif L[j] == 3:
      c += l[j]
      Num += 1

  k = abs(A - a) + abs(B - b) + abs(C - c) + (Num - 3) * 10
  if k < Ans:
    Ans = k

print(Ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<string, vector<pair<int, int>>> rest;
  for (int i = 0; i < n; i++) {
    string city;
    int score;
    cin >> city >> score;
    rest[city].push_back(make_pair(i, score));
  }
  for (auto e : rest) {
    vector<pair<int, int>> score = e.second;
    sort(score.begin(), score.end(), [](pair<int, int> a, pair<int, int> b) {
      return a.second > b.second;
    });
    for (auto i : score) {
      cout << i.first + 1 << endl;
    }
  }
  return 0;
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

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

#define MAX 100005
#define INF 1001001001

int main(int, char**)
{
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  vector<P> ans;
  int q;
  cin >> q;
  rep(i,q) {
    int k; cin >> k;
    auto itr1 = lower_bound(a.begin(), a.end(), k);
    auto itr2 = upper_bound(a.begin(), a.end(), k);
    ans.emplace_back(itr1-a.begin(), itr2-a.begin());
  }

  for (auto a : ans) cout << a.first << " " << a.second << endl;

  return 0;
}



Measured memory_bytes: 5312
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;

struct Union_Find{
    int d[SIZE],num[SIZE];
    void init(int n){
        REP(i,n)d[i]=i,num[i]=1;
    }
    int find(int x){return (x!=d[x])?(d[x]=find(d[x])):x;}
    bool is_root(int x){return d[x]==x;}
    bool uu(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y)return 0;
        if(num[x]>num[y])swap(x,y);
        num[y]+=num[x];
        d[x]=y;
        return 1;
    }
}U;
int main(){
    int N,M; R(N,M);
    U.init(N+1);
    REP(i,M){
        int x,y,v; R(x,y,v);
        U.uu(x,y);
    }
    int an=0;
    FOR(i,1,N)
        if(U.is_root(i))an++;
    W(an);
    return 0;
}


Measured memory_bytes: 4736
n = int(input())
a = [int(i) for i in input().split(" ")]

print(" ".join([str(i) for i in a]))
for i in range(1, n, 1):
    for j in range(i):
        if a[i] < a[j]:
            a.insert(j, a[i])
            a.pop(i+1)
    print(" ".join([str(i) for i in a]))


Measured memory_bytes: 5608
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn run() {
    input! {
        n: usize,
        m: usize,
        p: i64,
        e: [(usize1, usize1, i64); m],
    }
    let mut g = vec![vec![]; n];
    for (a, b, c) in e {
        let c = p - c;
        g[a].push((b, c));
    }
    let inf = 100000000000000000;
    let mut dp = vec![inf; n];
    dp[0] = 0;
    for _ in 0..n {
        for v in 0..n {
            if dp[v] == inf {
                continue;
            }
            for &(u, c) in g[v].iter() {
                let d = dp[v] + c;
                if d < dp[u] {
                    dp[u] = d;
                }
            }
        }
    }
    let ans = dp[n - 1];
    for _ in 0..n {
        for v in 0..n {
            if dp[v] == inf {
                continue;
            }
            for &(u, c) in g[v].iter() {
                let d = dp[v] + c;
                if d < dp[u] {
                    dp[u] = d;
                }
            }
        }
    }
    if ans != dp[n - 1] {
        println!("-1");
    } else {
        println!("{}", std::cmp::max(-ans, 0));
    }
}

fn main() {
    run();
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	private static Scanner sc=new Scanner(System.in);
	public static void main (String[] args){
		while(true){
			int m=sc.nextInt();
			int f=sc.nextInt();
			int r=sc.nextInt();
			if(m==-1&&f==-1&&r==-1) break;
			char result=judge(m,f,r);
			System.out.println(result);
		}
	}
	private static char judge(int m,int f,int r){
		if(m==-1||f==-1) return 'F';
		if(m+f>=80) return 'A';
		else if(m+f>=65) return 'B';
		else if(m+f>=50) return 'C';
		else if(m+f>=30&&r>=50) return 'C';
		else if(m+f>=30) return 'D';
		else return 'F';
	}
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H, W, K;
    cin >> H >> W >> K;
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    --x1, --y1, --x2, --y2;
    vector<vector<char>> C(H, vector<char>(W));
    vector<set<int>> unvisitedY(H), unvisitedX(W);
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> C[i][j];
            if (C[i][j] == '.') {
                unvisitedY[i].insert(j);
                unvisitedX[j].insert(i);
            }
        }
    }
    vector<vector<int>> left(H, vector<int>(W)), right(H, vector<int>(W)), up(H, vector<int>(W)), down(H, vector<int>(W));
    for (int i = 0; i < H; ++i) {
        for (int j = 0, prev = -1; j < W; ++j) {
            if (C[i][j] == '@') {
                prev = j;
            }
            left[i][j] = prev;
        }
        for (int j = W - 1, prev = W; j >= 0; --j) {
            if (C[i][j] == '@') {
                prev = j;
            }
            right[i][j] = prev;
        }
    }
    for (int i = 0; i < W; ++i) {
        for (int j = 0, prev = -1; j < H; ++j) {
            if (C[j][i] == '@') {
                prev = j;
            }
            up[j][i] = prev;
        }
        for (int j = H - 1, prev = H; j >= 0; --j) {
            if (C[j][i] == '@') {
                prev = j;
            }
            down[j][i] = prev;
        }
    }
    // BFS
    queue<pair<int, int>> F;
    F.push({x1, y1});
    unvisitedY[x1].erase(y1);
    unvisitedX[y1].erase(x1);
    int ans = 0;
    while (!F.empty()) {
        ++ans;
        int N = F.size();
        for (int i = 0; i < N; ++i) {
            auto P = F.front();
            F.pop();
            int x = P.first, y = P.second;
            // find positions to visit
            // left right
            int L = max(left[x][y] + 1, y - K), R = min(right[x][y] - 1, y + K);
            auto &SY = unvisitedY[x];
            auto itL = SY.lower_bound(L), itR = SY.upper_bound(R);
            auto it = itL;
            while (it != itR) {
                int curY = *it;
                // visit x, curY
                F.push({x, curY});
                if (x == x2 && curY == y2) {
                    cout << ans << '\n';
                    return 0;
                }
                unvisitedX[curY].erase(x);
                ++it;
            }
            SY.erase(itL, itR);
            // up down
            int U = max(up[x][y] + 1, x - K), D = min(down[x][y] - 1, x + K);
            auto &SX = unvisitedX[y];
            auto itU = SX.lower_bound(U), itD = SX.upper_bound(D);
            it = itU;
            while (it != itD) {
                int curX = *it;
                // visit curX, y
                F.push({curX, y});
                if (curX == x2 && y == y2) {
                    cout << ans << '\n';
                    return 0;
                }
                unvisitedY[curX].erase(y);
                ++it;
            }
            SX.erase(itU, itD);
        }
    }
    cout << "-1\n";
    return 0;
}

Measured memory_bytes: 163912
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
typedef vector<vector<int> > VVI;
const int INF = 1e9;
const double EPS = 1e-6;

const int MAX = 1e6;
vector<int> num;

int main()
{
	int dp[MAX+1], dp2[MAX+1];
	fill(dp, dp+MAX+1, INF);
	fill(dp2, dp2+MAX+1, INF);
	
	dp[0] = dp2[0] = 0;
	dp[1] = dp2[1] = 1;
	
	for (int i=1; ; i++) {
		int n = i*(i+1)*(i+2)/6;
		if (n > MAX) break;
		num.push_back(n);
	}
	
	for (int i=0; i<=MAX; i++) {
		for (int j=0; j<num.size(); j++) {
			int n = i + num[j];
			if (n <= MAX) {
				dp[n] = min(dp[n], dp[i]+1);
				if (num[j]%2==1)
					dp2[n] = min(dp2[n], dp2[i]+1);
			}
		}
	}
	
	int N;
	while (cin>>N, N) {
		cout << dp[N] << " " << dp2[N] << endl;
	}
}

Measured memory_bytes: 9028
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

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

int main()
{
	string s;
	int k;
	cin>>s; cin>>k;
	int n=s.size();
	int dp[301][301][301]={};
	for(int l=0; l<=k; l++){
		for(int i=0; i<n; i++){
			dp[l][i][i+1]=1;
		}
	}
	for(int d=2; d<=n; d++){
		for(int l=0; l<=k; l++){
			for(int i=0; i<=n-d; i++){
				if(s[i]==s[i+d-1]){
					dp[l][i][i+d]=max(dp[l][i][i+d], max(dp[l][i][i+d-1], max(dp[l][i+1][i+d], dp[l][i+1][i+d-1]+2)));
				}else{
					dp[l][i][i+d]=max(dp[l][i][i+d], max(dp[l][i][i+d-1], dp[l][i+1][i+d]));
					if(l>=1) dp[l][i][i+d]=max(dp[l][i][i+d], dp[l-1][i+1][i+d-1]+2);
				}
			}
		}
	}
	int ans=0;
	for(int l=0; l<=k; l++){
		ans=max(ans, dp[l][0][n]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 106752
import sys
input = sys.stdin.buffer.readline

def gcd(a: int, b: int):
    """ https://cocodrips.hateblo.jp/entry/2014/03/05/143623
    """
    while b:
        a, b = b, a%b
    return a

def lcm(a: int, b: int):
    return a * b // gcd(a, b)


def main():
    N, M = map(int, input().split())
    #print("gcd: ", gcd(N, M))
    print(lcm(N, M))

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060