akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);

class UnionFind {
public:
	vector<int>rank, parent;
	//初期化
	UnionFind(int size) {
		rank.resize(size, 0);
		parent.resize(size, 0);
		REP(i, size)parent[i] = i;
	}
	//木の根を求める
	int find(int x) {
		if (parent[x] == x)return x;
		else return parent[x] = find(parent[x]);
	}
	//xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (rank[x] < rank[y])
			parent[x] = y;
		else {
			parent[y] = x;
			if (rank[x] == rank[y])rank[x]++;
		}
	}
	//xとyが同じ集合に属するか否か
	bool same(int x, int y) {
		return (find(x) == find(y));
	}
	//parentの内容を出力
	void debug() {
		for (auto num : parent) {
			cout << num << " ";
		}
		cout << "more:" << endl;
		REP(i, parent.size()) {
			cout << find(i) << " ";

		}
		cout << endl << "more:" << endl;
		for (auto num : parent) {
			cout << num << " ";
		}
		cout << endl;
	}
};

//変数
class Kruskal {
public:
	//引数：頂点数
	Kruskal(){}
	Kruskal(int size) :V(size), E(0) {}

	//u-v間の辺をcostで結びます
	void add_edge(int u, int v, int cost) {
		es.push_back({ u, v, cost });
		E++;
	}

	//クラスカル法を適用します
	LL kruskal() {
		sort(es.begin(), 
			es.end(), 
			[](const edge& e1, const edge& e2) { return e1.cost < e2.cost; }
		);//コストが小さい順にソート
		return kruskal_impl();
	}


private:
	struct edge {
		int u, v, cost;
	};

	bool comp(const edge& e1, const edge& e2) { return e1.cost < e2.cost; }
	int V, E;        //頂点数と辺数
	vector<edge> es; //辺


	LL kruskal_impl() const {
		UnionFind uf(V);
		LL res = 0;
		for (edge e : es) {
			if (!uf.same(e.u, e.v)) {
				uf.unite(e.u, e.v);
				res += e.cost;
			}
		}
		return res;
	}
};


int N;
vector<pair<int, int>>xy;
Kruskal kr;




//サブ関数
//入力
void input()
{
	cin >> N;
	kr = Kruskal(N);
	REP(i, N) {
		int x, y;
		cin >> x >> y;
		xy.push_back(make_pair(x, y));
	}
}



void make_road(vector<int> p) 
{
	vector<pair<int, int>> road;
	REP(i,(int) p.size()) {
		road.push_back(make_pair(p[i], i));
	}
	sort(road.begin(), road.end());

	REP(i, (int)road.size() - 1) {
		kr.add_edge(
			road[i].second, 
			road[i + 1].second, 
			abs(road[i].first - road[i + 1].first)
		);
	}
}



//計算
void calc()
{
	vector<int> xs;
	vector<int> ys;
	for (auto num : xy)xs.push_back(num.first);
	for (auto num : xy)ys.push_back(num.second);
	make_road(xs);
	make_road(ys);

}


//出力
void output()
{
	cout << kr.kruskal() << endl;
}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}


Measured memory_bytes: 8608
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N], b[N];
int32_t main(){_

   cin>>n;

   for (int i = 1; i <= n-1; ++i)
   {
      cin>>b[i];
   }  

   a[1] = b[1];
   for (int i = 2; i <= n-1; ++i)
   {
      a[i] = min(b[i-1], b[i]);
   }

   a[n] = b[n-1];

   int sum = 0;
   for (int i = 1; i <= n; ++i)
   {
      sum += a[i];
   }
   
   cout<<sum;

   return 0;
}

Measured memory_bytes: 2304
object Main {
  def w(c: Char, n: Int): Unit = (0 until n) foreach (_ => System.out.print(c))

  def main(args: Array[String]): Unit = {
    val Array(sx, sy, tx, ty) = io.Source.fromInputStream(System.in).getLines().next().split(' ') map (_.toInt)

    val dx = tx - sx
    val dy = ty - sy
    // first
    w('U', dy)
    w('R', dx)
    w('D', dy)
    w('L', dx)

    // second
    w('L', 1)
    w('U', dy + 1)
    w('R', dx + 1)
    w('D', 1)
    w('R', 1)
    w('D', dy + 1)
    w('L', dx + 1)
    w('U', 1)

    System.out.println()
  }
}


Measured memory_bytes: 32864
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

string s;
ll mod;

vector<vector<ll>> dp;
vector<vector<ll>> dp2;

ll dfs(ll k,ll d,bool mx){
    if(mx){
        if(dp2[k][d]!=-1){return dp2[k][d];}
        ll c=s[k]-'0';
        if(k==0){
            ll count=0;
            for(ll i=0;i<=c;i++){
                if(i%mod==d){count++;}
            }
            return dp2[k][d]=count;
        }
        dp2[k][d]=0;
        for(ll i=0;i<c;i++){
            dp2[k][d]+=dfs(k-1,(d+mod*100-i)%mod,false);
        }
        dp2[k][d]+=dfs(k-1,(d+mod*100-c)%mod,true);
        return dp2[k][d]%=MOD;
    }
    else{
        if(dp[k][d]!=-1){return dp[k][d];}
        if(k==0){
            ll count=0;
            for(ll i=0;i<10;i++){
                if(i%mod==d){count++;}
            }
            return dp[k][d]=count;
        }
        dp[k][d]=0;
        for(int i=0;i<10;i++){
            dp[k][d]+=dfs(k-1,(d+mod*100-i)%mod,false);
        }
        return dp[k][d]%=MOD;
    }
    return -1;
}


int main(){
    cin>>s>>mod;
    reverse(s.begin(),s.end());
    dp.resize(s.size(),vector<ll>(mod,-1));
    dp2.resize(s.size(),vector<ll>(mod,-1));
    ll ans=dfs(s.size()-1,0,true)-1;
    ans%=MOD;
    if(ans<0){ans+=MOD;}
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 17280
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pi pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define in1(x) int x; cin>>x;
#define in2(x, y) int x, y; cin>>x>>y;
#define in3(x, y, z) int x, y, z; cin>>x>>y>>z;
#define in4(x, y, z, w) int x, y, z, w; cin>>x>>y>>z>>w;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
using namespace std;
bool primes[1000001];vi prime; void seive(); int gcd(int a, int b); int power(int x, int y);

int32_t main(void){
	IOS;
	in1(n);
	int arr[n];
	rep(i, 0, n) cin>>arr[i];
	int ans = 1000;
	int tmp;
	rep(i, 0, n-1)
	{
		tmp = 0;
		if(arr[i] < arr[i+1]) tmp = ans/arr[i];
		ans += (arr[i+1] - arr[i])*tmp;
	}
	cout<<ans<<endl;
}

void seive(){memset(primes, true, sizeof(primes));primes[0] = primes[1] = false;for(int i = 2; i*i<=1000000;i += 1){
if(primes[i]){for(int j = i*i; j <= 1000000;j += i) primes[j] = false;}}rep(i, 2, 1000001){if(primes[i]) prime.pb(i);}}
int gcd(int a, int b){return b==0 ? a : gcd(b, a%b);}
int power(int x, int y){ int res = 1;x = x % mod; if (x == 0) return 0;
while (y > 0){ if(y & 1) res = (res*x) % mod; y = y>>1; x = (x*x) % mod;} return res;}


Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <math.h>

using namespace std;
int T[200], A[200], B[200], C[200], D, N;
int Cs[200][200], CsNumber[200], valueCs[200][200];

inline void readinput(){
//	ifstream fin("input_2012_4.dat");
	cin >> D >> N;
	for(int i=0; i<D; i++) cin >> T[i];
	for(int i=0; i<N; i++) cin >> A[i] >> B[i] >> C[i];
}

inline void output_2d(int X[200][200]){
	for(int i=0; i<D; i++){
		for(int j=0; j<N; j++){
			cout << X[i][j];
			if(j != N-1) cout << " ";
			else cout << endl;
		}
	}
}

inline void putCs(){
	int idx;
	for(int i=0; i<D; i++){
		idx = 0;
		for(int j=0; j<N; j++){
			if(A[j]<=T[i] && T[i]<=B[j]){
				Cs[i][idx] = C[j];
				idx += 1;
			}
		CsNumber[i] = idx;
		}
	}
}

inline int solver(){
	int max, maxidx, buf;
	
	//initialize
	for(int i=0; i<200; i++){
		for(int j=0; j<200; j++) valueCs[i][j] = 0;
	}
	
	for(int i=D-1; i>0; i--){	// D-1 to 1
		for(int j1=0; j1<CsNumber[i-1]; j1++){
			max = 0;
			for(int j2=0; j2<CsNumber[i]; j2++){
				buf = fabs(Cs[i-1][j1] - Cs[i][j2]) + valueCs[i][j2];
				if(max < buf){
					max = buf;
					maxidx = j2;
				}
			}
			valueCs[i-1][j1] += max;
		}
	}
	max = 0;
	for (int j=0; j<CsNumber[0]; j++){
		buf = valueCs[0][j];
		if(max < buf) max = buf;
	}
	return max;
}

int main(){
	readinput();
	putCs();
	cout << solver() << endl;
//	cout << "--- Cs ---" << endl;
//	output_2d(Cs);
//	cout << "--- valueCs ---" << endl;
//	output_2d(valueCs);
	return 0;
}
	

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

#define ll long long
#define d long double

#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define dscf(n) scanf("%Lf",&n)
#define pri(n) printf("%d ",(int)n)
#define lpri(n) printf("%lld ",n)
#define dpri(n) printf("%Lf ",n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define dprin(n) printf("%Lf\n",n)

#define rep(i,ini,n) for(ll i=ini;i<(int)n;i++)
#define all(x) x.begin(),x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define bitcount(n) __builtin_popcount(n)
#define tc   int tt; scf(tt); while(tt--)
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265358979323846264

const ll M =1e9+7;
const int N = 1e6+7;


int main()
{
    int n,x,t;
    scf(n);scf(x);scf(t);
    if(n%x==0)
    pri((n/x)*t);
    else
    {
        pri((n/x+1)*t);
    }
return 0;
}

Measured memory_bytes: 3820
#include<stdio.h>

int main(){
  int x,y;

  scanf("%d %d",&x,&y);
  if(x>y){
    printf("a > b\n");
  }
  else if(x<y){
    printf("a < b\n");
  }
  else{
    printf("a == b\n");
  }
  return 0;
}

Measured memory_bytes: 2512
// Problem : C - Distinct or Not
// Contest : AtCoder Beginner Contest 154
// URL : https://atcoder.jp/contests/abc154/tasks/abc154_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);
#define endl "\n"

int32_t main()
{
	IOS;
	int t = 1;
	//cin >> t;	
	for(int msi = 1; msi <= t; msi++)
	{
		int n;
		cin >> n;
		set<int> s;
		for(int i = 0; i < n; i++)
		{
			int x; cin >> x;
			s.insert(x);
		}
		if((int)s.size() == n){
			cout <<"YES";
		}else{
			cout <<"NO";
		}
	}	
	return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
#pragma GCC optimize ("-O3")
    using namespace std;
    #define ll long long
    #define ld long double
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define pll pair<ll,ll>
    #define ff first
    #define ss second
    #define pb push_back
    #define deb(x) cout<<#x<<" : "<<x<<endl;
    #define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
    #define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define deb4(w,x,y,z) cout<<#w<<" : "<<w<<"\t"<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define printv(a)  for(ll i=0;i<a.size();i++)  cout<<a[i]<<" ";
   
   
    const int mod=1e9+7;
    const int N=1e6+5; 
    const ll inf=1e18+5;
   
    bool sortbysec(const pair<pair<ll,ll>,ll> &a, 
                      const pair<pair<ll,ll>,ll> &b) 
        { 
            return (a.second > b.second); 
        } 
        ll powermod(ll x, ll y, ll p)
        {
            ll res = 1;
            x = x % p;
            while (y > 0)
            {
                if (y & 1) res = (res*x) % p;
                y = y>>1;
                x = (x*x) % p;
            }
            return res;
        }
       
        bool isprime(int n) 
        { 
            if (n <= 1)  return false; 
            if (n <= 3)  return true; 
            if (n%2 == 0 || n%3 == 0) return false; 
            for (int i=5; i*i<=n; i=i+6) 
                if (n%i == 0 || n%(i+2) == 0) 
                   return false; 
           return true; 
        }
        
      
        int main()
    {
        FAST;
        string k;
        cin>>k;
        ll d;
        cin>>d;
        vector<vector<ll>> dp(d,vector<ll>(2));
        dp[0][0]=1;
        for(ll i=0;i<k.size();i++)
        {
             vector<vector<ll>> new_dp(d,vector<ll>(2));
            
            for(ll sum=0;sum<d;sum++)
            {
                for(bool sum_already:{false,true})
                {
                    for(ll digit=0;digit<10;digit++)
                    {  // deb2(digit,sum_already);
                        if(digit > k[i]-'0' && !sum_already)
                        break; 
                        
                        new_dp[(sum+digit)%d][sum_already || digit<k[i]-'0']+=dp[sum][sum_already];
                        new_dp[(sum+digit)%d][sum_already || digit<k[i]-'0']%=mod;
                    }
                }
            }
            dp=new_dp;
        }
        ll ans=(dp[0][true]+dp[0][false])%mod;
        ans--;
        if(ans<mod)
        ans+=mod;
        cout<<ans%mod<<"\n";
    
        
        return 0;
    }

Measured memory_bytes: 256
A, B, H, M = gets.chop.split.map(&:to_i)

total_m = 60 * H + M
a = total_m * 0.5
b = M * 6

x = 0
ans = nil

if a == b && a == 0
  ans = (A - B).abs
elsif a - b == 0
  ans = (A - B).abs
elsif (a - b).abs == 180
  ans = A + B
else
  if a > b
    if a - b < 180
      x = a - b
    else
      x = b + 360 - a
    end
  else
    if b - a < 180
      x = b - a
    else
      x = a + 360 - b
    end
  end
end

if ans
  puts ans
else
  puts Math.sqrt(A**2 + B**2 - 2 * A * B * Math.cos(x / 180.0 * Math::PI))
end


Measured memory_bytes: 14748
//えられる文から
#include<bits/stdc++.h>
using namespace std;
int main() {
	char c;
	int a,b;
	cin>>a>>b;
	for(int i=0; i<a; i+=1) {
		cin>>c;
		if(c<'0'||c>'9') {
			cout<<"No"<<"\n";
			return 0;
		}
	}
	cin>>c;
	if(c!='-') {
		cout<<"No"<<"\n";
		return 0;
	}
	for(int i=0; i<b; i+=1) {
		cin>>c;
		if(c<'0'||c>'9') {
			cout<<"No"<<"\n";
			return 0;
		}
	}
	cout<<"Yes"<<"\n";
	return 0;
}
//にして

Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<algorithm>
#include<string>
#define MOD 1000000007
using namespace std;
typedef vector<int > vi;
typedef long long ll;
typedef vector<ll> vll;

int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	ll pre;
	cin >> pre;
	ll ans = 0;;
	for (ll i = 1; i < n; i++) {
		ll x;
		cin >> x;
		ans += min(b, a*(x - pre));
		pre = x;
		
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// 解き直し.
// AtCoder Beginner Contest 123 解説.
// https://img.atcoder.jp/abc123/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using LL = long long;
const LL MOD = 1e9 + 7;
const int MAX = 1e3 + 1;
LL A[MAX], B[MAX], C[MAX];

struct cake{
    LL  d; // 美味しさの合計.
    int a; // A の index.
    int b; // B の index.
    int c; // C の index.
    bool operator < (const cake &C) const { return d < C.d; }
};

// 与えられた情報を結合して, 文字列を返却.
// @param prefix: 接頭語.
// @param d: 美味しさの合計.
// @param a: A の index.
// @param b: B の index.
// @param c: C の index.
// @return ret: map に 登録する 文字列 key.
string makeKey(string prefix, LL d, int a, int b, int c){
    string ret = prefix;
    ret += {"_"};
    ret += to_string(A[a] + B[b] + C[c]);
    ret += {"_"};
    ret += to_string(a);
    ret += {"_"};
    ret += to_string(b) + "_" + to_string(c);
    return ret;
}

int main(){
    
    // 1. 入力情報取得.
    int X, Y, Z, K;
    scanf("%d %d %d %d", &X, &Y, &Z, &K);
    FOR(i, 0, X) scanf("%lld", A + i);
    FOR(i, 0, Y) scanf("%lld", B + i);
    FOR(i, 0, Z) scanf("%lld", C + i);
    
    // 2. 降順sort.
    sort(A, A + MAX, greater<LL>());
    sort(B, B + MAX, greater<LL>());
    sort(C, C + MAX, greater<LL>());
    
    // 3. 解説通り(※Priority Queue (優先度付きキュー) を 使うパターン).
    int a = 0, b = 0, c = 0;
    priority_queue<cake> pq;
    map<string, int> m;
    pq.push({A[a] + B[b] + C[c], a, b, c});
    string s = makeKey("p", A[a] + B[b] + C[c], a, b, c);
    m[s]++;
    int index = 1;
    while(!pq.empty()){
        // 3-1. pq の中で, 一番美味しさの大きい要素を取得.
        cake i = pq.top();
        a = i.a, b = i.b, c = i.c;
        pq.pop();
        
        // 3-2. 追加されてないパターンを追加.
        cake p1 = {A[a + 1] + B[b] + C[c], a + 1, b, c};
        string s1 = makeKey("p", A[a + 1] + B[b] + C[c], a + 1, b, c);
        cake p2 = {A[a] + B[b + 1] + C[c], a, b + 1, c};
        string s2 = makeKey("p", A[a] + B[b + 1] + C[c], a, b + 1, c);
        cake p3 = {A[a] + B[b] + C[c + 1], a, b, c + 1};
        string s3 = makeKey("p", A[a] + B[b] + C[c + 1], a, b, c + 1);
        if(a < X - 1 && m[s1] == 0) pq.push(p1), m[s1]++;
        if(b < Y - 1 && m[s2] == 0) pq.push(p2), m[s2]++;
        if(c < Z - 1 && m[s3] == 0) pq.push(p3), m[s3]++;

        // 3-3. index番目 のケーキの美味しさの合計を出力.
        printf("%lld\n", i.d);
        
        // 3-4. increment.
        index++;
        
        // 3-5. index番目 が Kより大きくなったら終了.
        if(index > K) break;
    }
    // printf with std::string?
    // https://stackoverflow.com/questions/10865957/printf-with-stdstring
    // for(auto &e : m) printf("key=%s, value=%d\n", e.first.c_str(), e.second);
    return 0;
    
}

Measured memory_bytes: 1280
using System;
using System.Linq;

namespace atcoder.abc170.a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inputArray = getIntParams();
            int ret = 0;
            foreach (int x in inputArray)
            {
                ret++;
                if (x == 0)
                {
                    break;
                }
            }
            Console.WriteLine(ret);
        }

        //↓↓↓ shared function ↓↓↓
        static int getIntParam()
        {
            return int.Parse(Console.ReadLine());
        }
        static int[] getIntParams()
        {
            return Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
        }
        static long getLongParam()
        {
            return long.Parse(Console.ReadLine());
        }
        static long[] getLongParams()
        {
            return Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
        }
        static string getStringParam()
        {
            return Console.ReadLine();
        }
        static string[] getStringParams()
        {
            return Console.ReadLine().Split(' ');
        }
    }
}


Measured memory_bytes: 28176
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
string alphabet="abcdefghijklmnopqrstuvwxyz";
int main() {
    string s;
    cin>>s;
    if(s.size() != 26){
        cout << s;
        rep(i , 26){
            if(count(s.begin() , s.end() , alphabet[i]) == 0){
                cout << alphabet[i];
                break;
            }
        }
    }
    else{
        if(s == "zyxwvutsrqponmlkjihgfedcba"){
            cout<<-1;
        }
        else{
        rep(i , 25){
            if(s[25 - i] > s[24 - i]){
                rep(j , 24 - i){
                    cout<<s[j];
                }
                    for(int j = 25; j >= 25 - i; j--){
                        if(s[j] > s[24 - i]){
                            cout << s[j];
                            break;
                            }
                    }
                    break;
                }
            }
        }
    }
 
}

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

using namespace std;

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

    vector<int> A(N+1), B(N);

    for (int i = 0; i <= N; i++)
        cin >> A[i];
    for (int i = 0; i < N; i++)
        cin >> B[i];

    long long int count = 0;
    
    for (int i = 0; i < N; i++)
    {
        if (A[i] >= B[i])
        {
            count += B[i];
        }
        else if (A[i] + A[i+1] > B[i])
        {
            count += B[i];
            A[i+1] += A[i] - B[i];
        }
        else
        {
            count += A[i] + A[i+1];
            A[i+1] = 0;
        }
    }
    
    cout << count << endl;
}


Measured memory_bytes: 1024
// 2017/05/19 Tazoe

#include <iostream>
using namespace std;

bool isprime(int x)
{
	if(x==2)
		return true;

	if(x<2 || x%2==0)
		return false;

	for(int i=3; i*i<=x; i+=2){
		if(x%i==0)
			return false;
	}

	return true;
}

int main()
{
	int n;
	cin >> n;

	int cnt = 0;

	for(int i=0; i<n; i++){
		int x;
		cin >> x;

		if(isprime(x)){
			cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

typedef long long ll;

int main(){
    ll a,b,c,d;
    vector<ll> ans(4);
    ll out = -1e19;
    cin >> a >> b >> c >> d;
    ans[0] = a*c;
    ans[1] = a*d;
    ans[2] = b*c;
    ans[3] = b*d;
    for(int i = 0; i < 4; i++){
        out = max(out,ans[i]);

    }
    cout << out << endl;
    return 0;
}

Measured memory_bytes: 3624
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
from functools import reduce


N = 10**6
mod = 10**9+7

inv_t = [0] + [1]
for i in range(2, N):
    inv_t += [inv_t[mod % i] * (mod - int(mod / i)) % mod]

kai = [1, 1]
rev_kai = [1, inv_t[1]]
for i in range(2, N):
    kai.append(kai[-1] * i % mod)
    rev_kai.append(rev_kai[-1] * inv_t[i] % mod)

def cmb(n, r):
    return kai[n] * rev_kai[r] * rev_kai[n - r] % mod

def prm(n, r):
    return kai[n] * rev_kai[n - r] % mod

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

a = 0
for k in range(n+1):
    a += prm(m, k)*prm(m-k,n-k)**2*(-1)**k*cmb(n,k) % mod

print(a % mod)

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

// 小数点以下桁数
// fixed << setprecision(i)

int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int a,int b){return (int64_t)a*b/gcd(a, b);}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//	for(auto x : v) cout << x << " "; cout << "\n";     // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//	bitset<ビット数> s(tmp);
//	// (ビット列sに対する処理)
// }

int main()
{
	int n, a;

	cin >> n >> a;
	vector<int> x(n);
	for (int i = 0; i < n; i++)
	{
		cin >> x[i];
		x[i] -= a;
		x[i] = abs(x[i]);
	}
	for (int i = 1; i < n; i++)
		x[0] = gcd(x[0], x[i]);
	cout << x[0] << endl;
}


Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  
  if((c-b) > a)
    cout << "dangerous" << endl;
  else if(b<c)
    cout << "safe" << endl;
  else
    cout << "delicious" << endl;
}


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

typedef complex<double>Point;

struct Segment{
    Point p1,p2;
    Segment(const Point &p1=Point(),const Point &p2=Point()):p1(p1),p2(p2){}
};

struct Circle{
    Point p;
    double r;
    Circle(const Point &p=Point(),double r=0.0):p(p),r(r){}
};

typedef Point Vector;
typedef Segment Line;
typedef vector<Point>Polygon;

const double PI=acos(-1);
const double EPS=1e-8;
const double INF=1e16;
const int COUNTER_CLOCKWISE=1;
const int CLOCKWISE=-1;
const int ONLINE_BACK=2;
const int ONLINE_FRONT=-2;
const int ON_SEGMENT=0;

inline double square(double a){return a*a;}
inline double norm(const Point &a){return square(a.real())+square(a.imag());}
inline double dot(const Point &a,const Point &b){return (conj(a)*b).real();}
inline double cross(const Point &a,const Point &b){return (conj(a)*b).imag();}
inline double toDeg(double t){return t/PI*180.0;}
inline double toRad(double t){return t/180.0*t;}
#define equals(a,b) (fabs((a)-(b))<EPS)

void getPoint(Point &p){
    double x,y;
    scanf("%lf%lf",&x,&y);
    p=Point(x,y);
}

void getSegment(Segment &s){
    getPoint(s.p1);
    getPoint(s.p2);
}

bool orthogonal(Vector a,Vector b){
    return equals(dot(a,b),0.0);
}

bool orthogonal(Point a1,Point a2,Point b1,Point b2){
    return orthogonal(a1-a2,b1-b2);
}

bool orthogonal(Segment s1,Segment s2){
    return orthogonal(s1.p1-s1.p2,s2.p1-s2.p2);
}

bool parallel(Vector a,Vector b){
    return equals(cross(a,b),0.0);
}

bool parallel(Point a1,Point a2,Point b1,Point b2){
    return parallel(a1-a2,b1-b2);
}

bool parallel(Segment s1,Segment s2){
    return parallel(s1.p1-s1.p2,s2.p1-s2.p2);
}

Point project(Segment s,Point p){
    Vector base=s.p2-s.p1;
    double r=dot(p-s.p1,base)/norm(base);
    return s.p1+base*r;
}

Point reflection(Segment s,Point p){
    return p+(project(s,p)-p)*2.0;
}

int ccw(Point p0,Point p1,Point p2){
    Vector a=p1-p0;
    Vector b=p2-p0;
    if(cross(a,b)>EPS)return COUNTER_CLOCKWISE;
    if(cross(a,b)<-EPS)return CLOCKWISE;
    if(dot(a,b)<-EPS)return ONLINE_BACK;
    if(norm(a)<norm(b))return ONLINE_FRONT;
    return ON_SEGMENT;
}

bool intersect(Point p1,Point p2,Point p3,Point p4){
    return ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0&&
            ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0;
}

bool intersect(Segment s1,Segment s2){
    return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}

Point getCrossPoint(Segment s1,Segment s2){
    Vector base=s2.p2-s2.p1;
    double d1=abs(cross(base,s1.p1-s2.p1));
    double d2=abs(cross(base,s1.p2-s2.p1));

    double t=d1/(d1+d2);
    return s1.p1+(s1.p2-s1.p1)*t;
}

int main(){
    int q;
    scanf("%d",&q);
    while(q--){
        Segment s1,s2;
        getSegment(s1);
        getSegment(s2);
        Point a=getCrossPoint(s1,s2);
        printf("%.20lf %.20lf\n",a.real(),a.imag());
    }

    return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K ;
  
  int A = 1 ;
  for ( int i=0; i<N; i++){
    if (A<K)
      A *= 2;
    else
      A += K;
  }
  
  cout << A << endl;
}

Measured memory_bytes: 3616
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/10/ALDS1_10_B
# 普通に難しい
# アイデアは写真の解説を参照

# データの入力
N = int(input())

for i in range(N):
    if i == 0:
        P = list(map(int, input().split()))
        continue
    P.append(int(input().split()[1]))

# dpテーブルの用意 minを取るときはinf埋めしておくと処理が楽になるしバグが見つかりやすい
INF = 2**32-1
dp = [[INF]*N for _ in range(N)]

# dpテーブルの初期化
# 対角成分0
for ij in range(N):
    dp[ij][ij] = 0

# dpの更新 どう更新しているのか、なんでこう更新するのかは写真を参照
for l in range(1, N):  # lは対角成分からいくつ離れているか (なん個行列をかけるかという解釈も可)
    for i in range(N):
        j = i+l
        if j >= N:
            continue
        for k in range(i, j):  # 最小値探索
            dp[i][j] = min(dp[i][k] + dp[k+1][j] +
                           P[i] * P[k+1] * P[j+1], dp[i][j])
print(dp[0][-1])



Measured memory_bytes: 5656
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int dx[] = {-1, 0, 1, 1, 0, -1};
int dy[] = {0, 1, 1, 0, -1, -1};

int main() {
	for (;;) {
		int t, n; cin >> t >> n;
		if (t == 0 && n == 0) break;
		vector< vector<int> > a(121, vector<int>(121, INT_MAX));
		while (n--) {
			int x, y; cin >> x >> y;
			x += 60; y += 60;
			a[y][x] = 0;
		}
		int xs, ys; cin >> xs >> ys;
		xs += 60; ys += 60;
		a[ys][xs] = 0;
		queue<i_i> q;
		q.push(i_i(xs, ys));
		int ans = 0;
		while (!q.empty()) {
			i_i p = q.front(); q.pop();
			ans++;
			int x = p.first, y = p.second;
			if (a[y][x] == t) continue;
			for (int k = 0; k < 6; k++) {
				int _x = x + dx[k], _y = y + dy[k];
				if (a[_y][_x] > a[y][x] + 1) {
					a[_y][_x] = a[y][x] + 1;
					q.push(i_i(_x, _y));
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1284
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/rope"
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
#define lambdify(x) [&](auto &&...args){ return x(forward<decltype(args)>(args)...); }
template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	long long x, y;
	cin >> x >> y;
	cout << __lg(y / x) + 1 << "\n";
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 256
s = input()
k = int(input())
s_list = []
ans = 0

def rle(s):
    tmp, count = s[0], 1
    for i in range(1, len(s)):
        if tmp == s[i]:
            count += 1
        else:
            s_list.append(count)
            tmp = s[i]
            count = 1
    s_list.append(count)
    return

rle(s)

if len(s_list) >= 2:
    for i in range(len(s_list)):
        if s_list[i] >= 2:
            ans += s_list[i] // 2

    ans *= k

    if (s_list[0] + s_list[-1]) % 2 == 0 and s[0] == s[-1]:
        ans += k - 1

else:
    ans = len(s) * k // 2

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
    int n;
    cin >> n;
    ll a[n], r[n];
    ll tmp = 0;
    rep(i, n) {
        cin >> a[i];
        tmp += a[i];
        r[i] = tmp;
    }
    int ind;
    rep(i, n){
        if (r[i] > (r[n-1] - r[i])){
            ind = i;
            break;
        }
    }
    cout << min(abs(r[n-1] - 2 * r[ind]), abs(r[n-1] - 2 * r[ind-1])) << endl;

    return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  for (auto&& e : a) {
    cin >> e;
  }
  sort(begin(a), end(a));
  while (q--) {
    int l, r;
    cin >> l >> r;
    int res = upper_bound(begin(a), end(a), r) - lower_bound(begin(a), end(a), l);
    cout << res << '\n';
  }
}



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

using namespace std;

#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)
struct Traversed {
  int index;
  int next_index;
  int count;
};

Traversed traverse(int start, vector<int> & towns, unsigned long long int max_count) {
  int current = start;
  int count = 0;
  vector<bool> visited(towns.size());
  Rep(i, max_count) {
    if (visited[current]) break;
    count++;
    visited[current] = true;
    current = towns[current];
  }
  return { current, towns[current], count };
}

int main() {
  int n;
  unsigned long long int k;
  cin >> n >> k;
  
  vector<int> towns(n);
  Rep(i, n) {
    int town;
    cin >> town;
    towns[i] = town - 1;
  }

  auto until_loop = traverse(0, towns, towns.size());
  auto loop = traverse(until_loop.index, towns, towns.size());

  if (k <= until_loop.count) {
    auto t = traverse(0, towns, k);
    cout << t.index + 1 << endl;
    return 0;
  }

  auto mod = traverse(
    until_loop.index, towns, (k - until_loop.count) % loop.count
  );
  cout << mod.index + 1 << endl;

  return 0;
}


Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int a,b,c,d;
    cin >> a >> b >> c;
    d = max(max(a,b), c);
    if(d == a){
        cout << b+c << endl;
    }
    else if(d == b){
        cout << a+c << endl;
    }
    else cout << a+b << endl;

}

Measured memory_bytes: 3584
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <vector>
#include <set>
using namespace std;

void read(int &x)
{
	char ch=getchar();bool f=0;x=0;
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	if(f)x=-x;
} 

void read(long long &x)
{
	char ch=getchar();bool f=0;x=0;
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	if(f)x=-x;
}


vector <int> graph[1001];

void addedge(int u,int v)
{
	graph[u].push_back(v);
}

int vis[1001][1001];
struct
{
	int first,second;
}edge[200001];
int mark[1001];
int times=1;
int tmp;

void dfs(int from,int now)
{
	vis[from][now]++;
	mark[now]=times;
	for(auto to:graph[now])
	{
		if(to==from)continue;
		if(vis[from][to]<2&&mark[to]!=times)
		{
			dfs(from,to);
		}
	}
}

int main()
{
//	freopen("sep2_0.in","r",stdin);
//	freopen("sep.out","w",stdout);
	int n,m;
	read(n);read(m);
	for(int i=0;i<m;i++)
	{
		int from,to;
		read(from);read(to);
		addedge(from,to);
		edge[i].first=from;
		edge[i].second=to;
	}
	for(int i=1;i<=n;i++)
	{
		for(auto to:graph[i])
		{
			if(vis[i][to]<2)
			{
				times++;
				dfs(i,to);
			}
		}
	}
	//return 0;
/*	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cout<<"("<<vis[i][j]<<","<<vis2[i][j]<<")";
		}
		cout<<endl;
	}*/
	for(int i=0;i<m;i++)
	{
		int from=edge[i].first,to=edge[i].second;
		if(vis[to][from])
		{
			if(vis[from][to]>1)
			{
				puts("same");
			}
			else
			{
				puts("diff");
			}
		}
		else
		{
			if(vis[from][to]>1)
			{
				puts("diff");
			}
			else
			{
				puts("same");
			}
		}
	}
	return 0;
}
/*
3 3
1 2
1 3
2 3

2 2
1 2
2 1
*/


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

int dp[101][4][2];

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  string s; cin >> s;
  int x; cin >> x;

  dp[0][0][0] = 1;

  rep(i, si(s)) rep(j, 4) rep(k, 2) {
    int nd = s[i] - '0';

    rep(d, 10) {
      int ni = i+1, nj = j, nk = k;

      if (d != 0) ++nj;
      if (nj > x) continue;
      if (k == 0) {
        if (d > nd) continue;
        if (d < nd) nk = 1;
      }

      dp[ni][nj][nk] += dp[i][j][k];
    }
  }

  cout << dp[si(s)][x][0] + dp[si(s)][x][1] << endl;

  return (0);
}


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

int main() {
    int A, B, C, a, b, c,cnt = 0;
    cin >> A >> B >> C;
    
    while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
        if (A == B && B == C) {
            cout << -1 << endl;
            return 0;
        }
        a = A;
        b = B;
        c = C;
        A = b / 2 + c / 2;
        B = c / 2 + a / 2;
        C = a / 2 + b / 2;
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import Data.List

main :: IO ()
main = do
    [x,y] <- map read . words <$> getLine :: IO [Int]
    print . length $ unfoldr (f y) x
  where
    f :: Int -> Int -> Maybe (Int,Int)
    f y x
      | x > y     = Nothing
      | otherwise = Just (x, x*2)


Measured memory_bytes: 508
H,W = map(int, input().split())
grid = [-1] * (W+4) * 2
black_ind = []
for _ in range(H):
	grid += [-1]*2
	I = input()
	for i in range(W):
		if I[i] == '#':
			grid.append(1)
			black_ind.append(len(grid)-1)
		else:
			grid.append(0)
	grid += [-1]*2

grid += [-1] * (W+4) * 2

move = [1,-1,W+4,-(W+4)]
ans = 0
for b in black_ind:
	if grid[b] == 2:
		continue
	cnt_b = 1
	cnt_w = 0
	q = [b]
	grid[b] = 2
	while q:
		cp = q.pop()
		if grid[cp] == 2:
			for d in move:
				if grid[cp+d] == 0:
					grid[cp+d] = 3
					cnt_w += 1
					q.append(cp+d)
		elif grid[cp] == 3:
			for d in move:
				if grid[cp+d] == 1:
					grid[cp+d] = 2
					cnt_b += 1
					q.append(cp+d)

	ans += cnt_b * cnt_w
print(ans)



Measured memory_bytes: 10752
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    ans = 0
    for i in range(1, n + 1):
        ans += i & 1
    print(ans/n)
    return

#B
def B():
    n, k = LI()
    h = LI()
    ans = 0
    for i in h:
        ans += i >= k
    print(ans)
    return

#C
def C():
    n = II()
    a = LI()
    d = defaultdict(int)
    for i in range(n):
        d[a[i] + 1] = i + 1
    for _, v in sorted(d.items()):
        print(v, end=" ")
    print()
    return

def primes(n):
    """ Input n>=6, Returns a list of primes, 2 <= p < n """
    """ 6以上の数であれば p (素数) <= n のlistを返す """
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1,int(n**0.5)//3+1):
        if sieve[i]:
            k=3*i+1|1
            sieve[      k*k//3      ::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
            sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]

#D
def D():
    a, b = LI()
    p = primes(int(math.sqrt(max(a, b))) + 1)
    ans = 1
    for i in p:
        if a % i == b % i == 0:
            ans += 1
    print(ans)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


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

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

    int n;
    long long k;
    cin >> n >> k;

    map<int, long long> mp;
    for(int i = 0; i < n; i++){
        int a;
        long long b;
        cin >> a >> b;
        mp[a] += b;
    }

    long long total = 0;
    for(auto x : mp){
        total += x.second;
        if(total >= k){
            cout << x.first << endl;
            return 0;
        }
    }

    return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll A,B,ans;
  cin >> A >> B;
  if (A != B){
    ans = 2*max(A,B)-1;
  }else{
    ans = 2*A;
  }
  cout << ans<< endl;
  return 0;
}

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

using namespace std;

int main(void) {
  int D, G, p[11], c[11];
  cin >> D >> G;
  for(int i = 0; i < D; i++) {
    cin >> p[i] >> c[i];				
  }
  
  int ans = 1e9;
  for(int mask = 0; mask < (1 << D); mask++) {
    int s = 0, num = 0, rest_max = -1;
    for(int i = 0; i < D; i++) {
      if(mask >> i & 1) {
	s += 100 * (i + 1) * p[i] + c[i];
	num += p[i];
      }
      else {
	rest_max = i;
      }
    }
    if(s < G) {
      int s1 = 100 * (rest_max + 1);
      int need = (G - s) / s1;
      if((G - s) % s1 != 0) {
	need++;
      }
      //      int need = (G - s + s1 - 1) / s1;
      if(need >= p[rest_max]) {
      	continue;
      }
      num += need;
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;

int main(){
	
	int p[100000]={0},k;
	p[0]=6;
	for(int i=1;i<100000;i++){
		if(i%2==0)k=i/2*7+6;
		else k=(i-1)/2*7+8;
		for(int j=0;j<100000;j++){
			if(p[j]==0){p[j]=k;break;}
			if(k%p[j]==0)break;
		}
	}
	int n;
	while(cin>>n,n!=1){
		cout<<n<<":";
		for(int i=0;i<100000;i++){
			if(p[i]==0||p[i]>n)break;
			if(n%p[i]==0)cout<<" "<<p[i];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=1000;
const int MAXW=10000;
struct Z { int w,s,v; };
bool operator<(const  Z &a,const Z &b) { return a.s+a.w<b.s+b.w; }

int n;
Z z[MAXN];

ll dp[2*MAXW+1];

ll solve() {
	sort(z,z+n);
	memset(dp,0,sizeof(dp));
	REP(i,n) for(int j=z[i].s;j>=0;--j) dp[j+z[i].w]=max(dp[j+z[i].w],dp[j]+z[i].v);
	ll ret=0; REPE(j,2*MAXW) ret=max(ret,dp[j]); return ret;
}

void run() {
	scanf("%d",&n);
	REP(i,n) scanf("%d%d%d",&z[i].w,&z[i].s,&z[i].v);
	printf("%lld\n",solve());
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 384
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace abc177
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
            solve_abc177C2();
            Console.Out.Flush();
        }
        public static void solve_abc177C2()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            long mod = 1000000007;
            long[] pref = new long[n];
            pref[0] = a[0];
            for (int i = 1; i < n; i++)
            {
                pref[i] += a[i] + pref[i - 1];
            }
            long sum = 0;
            for (int i = 0; i < n; i++)
            {
                sum = (sum + (((pref[n - 1] - pref[i]) % mod) * a[i]) % mod) % mod;
            }
            Console.WriteLine(sum);
        }

        public static void solve_abc177C1()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            long mod = 1000000007;
            long sum = a[0];
            long ans = 0;
            for (int i = 1; i < n; i++)
            {
                ans = (ans + ((sum * a[i]) % mod)) % mod;
                sum = (sum + a[i]) % mod;
            }

            Console.WriteLine(ans);
        }

        public static void solve_abc177B()
        {
            string s = Console.ReadLine();
            string t = Console.ReadLine();
            int min = 10001;
            for (int i = 0; i < s.Length - t.Length + 1; i++)
            {
                int cnt = 0;
                int j = 0;
                while (j < t.Length)
                {
                    if (s[i + j] != t[j])
                    {
                        cnt++;
                    }
                    j++;
                }
                min = Math.Min(min, cnt);
            }

            Console.WriteLine(min);
        }

        public static void solve_abc177A()
        {
            int[] dts = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int d = dts[0];
            int t = dts[1];
            int s = dts[2];
            double taken = (double)d / s;
            Console.WriteLine(taken > t ? "No" : "Yes");
        }

        public static int binSerachLeft(int[] a, int x)
        {
            int l = -1;
            int r = a.Length;
            while (r > l + 1)
            {
                int m = (l + r) / 2;
                if (a[m] <= x)
                {
                    l = m;
                }
                else
                {
                    r = m;
                }
            }
            return l;
        }
    }
}

Measured memory_bytes: 48464
#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() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n + 1);
  rep(i, n) {
    cin >> a[i + 1];
  }
  vector<int> num(n + 1);
  int step = 1;
  int i = 1;
  for(; num[i] == 0; i = a[i]) {
    num[i] = step++;
    if(step > k + 1) break;
  }
  if(step > k + 1) {
    cout << i << endl;
    return 0;
  }
  k -= num[i] - 1;
  ll m = k % (step - num[i]);
  rep(j, m) {
    i = a[i];
  }
  cout << i << endl;
  return 0;
}

Measured memory_bytes: 4784