akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<vector<int>> x(N, vector<int> (N, 0));
    vector<vector<int>> c(N, vector<int> (N+1, 0));
    int tmp1,tmp2;
    for (int i = 0; i < M; i++){
        cin >> tmp1 >> tmp2; tmp1--; tmp2--;
        x[tmp1][tmp2]++;
    }
    for (int i = 0; i < N; i++) {
        c[i][0] = 0;
    }
    for (int i = 0; i < N; i++) {
        for (int j = 1; j < N+1; j++) {
            c[i][j] = c[i][j-1] + x[i][j-1];
        }
    }   
    int ans = 0;
    for (int i = 0; i < Q; i++) {
        cin >> tmp1 >> tmp2; tmp1--; tmp2--;
        ans = 0;
        for (int j = tmp1; j <= tmp2; j++) {
            ans += c[j][tmp2+1] - c[j][tmp1];
        }
        printf("%d\n", ans);
    }

    


}


Measured memory_bytes: 2944
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a*b > c*d) cout<<a*b<<endl;
    else if(a*b < c*d) cout<<c*d<<endl;
    else cout<<a*b<<endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
using namespace std;


int main() {
	const long long int mod = 1000000007;
	map<long long int, long long int>mp;
	long long int  s[200][200];
	//cout << fixed << setprecision(10);
	long long int n, m, k, p, q, r, w[200005], sum[200005] = {}, res = 999999999;
	cin >>n;
	for (int i = 1; i <= n; i++) {
		cin >> w[i];
		sum[i] = sum[i - 1] + w[i];
	}
	for (int i = 1; i <= n; i++) {
		if (abs(sum[n] - 2 * sum[i])<res) {
			res = abs(sum[n] - 2 * sum[i]);
		}
	}
	cout << res;
}


Measured memory_bytes: 3328
S = input()

N = "None"
count = 0
app = [0] * 26
for i in range(len(S)):
    app[ord(S[i]) - ord("a")] = 1

for i in range(26):
    if app[i] == 1:
        count += 1
        if count == 26:
            print(N)

    if app[i] == 0:
        print (chr(i + ord("a")))
        break

Measured memory_bytes: 3188
#include <cstdio>

int fib(int *a,int n){
    if(n==0 || n==1)return 1;
    else{
        int tmp;
        if(a[n])tmp = a[n];
        else{
            tmp = fib(a,n-1) + fib(a,n-2);
            a[n] = tmp;
        }
        return tmp;
    }
}

int main(){
    int i, n;
    int a[45];
    for(i=0;i<45;i++)a[i]=0;
    scanf("%d",&n);
    printf("%d\n",fib(a,n));
    return 0;
}



Measured memory_bytes: 2716
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
using namespace std;
ll ans,cnt;
string s;
int main()
{
	cin>>s;
	for (int i=0;i<s.size();i++)
		if (s[i]=='B') cnt++;
		else ans+=cnt;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

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

        if (a + b <= k) {
                cout << "0 0" << endl;
                return 0;
        }

        if (a < k) {
                cout << "0 " << b - (k - a) << endl;
                return 0;
        }

        cout << a - k << ' ' << b << endl;
        return 0;
}

Measured memory_bytes: 256
/*
* @Author Silviase(@silviasetitech)
* For ProCon
*/

import java.util.*;
import java.lang.*;
import java.math.*;

class Main{

        // usual use input int
        static int n;
        static int m;
        static int ni;
        static int hi;
        static int wi;
        static int lefi;
        static int rigi;
        static int ansi;
        //
        static String s;
        static String anss;
        // 
        static String[] sAr;
        //
        static long ansl;
        //
        static int[] ari;
        //
        static int[][] sqari;
        //

        // for dfs
        static int[] w;
        static int[] ww;
        static boolean[] isvisited;
        //
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
             
        s = sc.next();
        System.out.println(s.substring(0,4) + " " + s.substring(4));


        sc.close();
    }


        public static int gcd_int(int a, int b) {
        
            if (a < b) {
                int tmpp = a;
                a = b;
                b = tmpp;
            }
            if (b == 0) {
                return a;
            }else{
                return gcd_int(b, a%b);
            }
        }

        public static long gcd_long(long a, long b) {
        
            if (a < b) {
                long tmpp = a;
                a = b;
                b = tmpp;
            }
            if (b == 0) {
                return a;
            }else{
                return gcd_long(b, a%b);
            }
        }

        public static int lcm_int(int a, int b) {
            int gcd = gcd_int(a,b);
            return a/gcd*b;
        }

        public static long lcm_long(long a, long b) {
            long gcd = gcd_long(a,b);
            return a/gcd*b;
        }

        public static void dfs(int placenow) {
            // if went all -> success! 
            // if not went all -> fail...
            
            /*
            dfs    
            Go All Place that there is way to and not having been yet. 

             if island 1 is start point, dfs(1);
            if there is way to island 2 and island 3,
            - island 2 changes non-visited -> visited, and dfs(2).
            - island 3 changes non-visited -> visited, and dfs(3).
    
            */

            isvisited[placenow] = true;
            boolean success = true;
            for (int i = 0; i < n; i++) {
                if (isvisited[i] == false) { // not go all place
                    success = false;
                    break;
                }
            }
            if (success) {
                ansi++;
                isvisited[placenow] = false;
                return;
            }

            for (int i = 0; i < n; i++) {
                if (w[i] == placenow && isvisited[ww[i]] == false ) {
                    dfs(ww[i]);
                }else if(ww[i] == placenow && isvisited[w[i]] == false){
                    dfs(w[i]);
                }else{
                    continue;
                }
            }
            isvisited[placenow] = false;
            return;
        }

}



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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
    
    int n; cin >> n;
    vector<ll> a(n); REP(i, n) cin >> a[i];

    ll ans = 1e18;
    REP(x, 100) {
        ll temp = 0;
        REP(i, n) {
            temp += pow(a[i] - x, 2);
        }
        ans = min(ans, temp);
    }
    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int w[100],v[100];
int n;
long long dp[100001];
long long solve(int weight) {
  for(int i=0;i<n;i++) {
    for(int j=weight;j>=w[i];j--) {
      dp[j] = max(dp[j],dp[j-w[i]] + v[i]);
    }
  }
  return dp[weight];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int W; cin >> n >> W;

  for(int i=0;i<n;i++) {
    cin >> w[i] >> v[i];
  }
  cout << solve(W);
  return 0;
}

Measured memory_bytes: 1024
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

n = int(input())
print(n//3)







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

int main() {
  int x,a;
  cin>>x>>a;
  if(x<a) cout<<0<<endl;
  else cout<<10<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define M 10000

double SimpleInterest(int, int);
double ComposedInterest(int, int);

int main(){
  int i, n, year, bank, percent, type, ans;
  double rate, max;

  while(1){
    scanf("%d", &n);
    if(n == 0) break;

    scanf("%d", &year);
    for(i=0; i<n; i++){
      scanf("%d %d %d", &bank, &percent, &type);
      if(type == 1) rate = SimpleInterest(year, percent);
      else rate = ComposedInterest(year, percent);

      if(i == 0 || max < rate){
	ans = bank;
	max = rate;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}

double SimpleInterest(int year, int percent){
  return M * (1 + ((double)year * percent)/100);
}

double ComposedInterest(int year, int percent){
  double i, x, ans;
  x = 1 + ((double)percent)/100;
  for(i=0, ans=1.0; i<year; i++) ans *= x;
  return M * ans;
}

Measured memory_bytes: 0
using System;

namespace Beginner081_B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] fuge = Console.ReadLine().Split(' ');
            long[] hoge = new long[n];
            for (int i = 0; i < n; i++)
            {
                hoge[i] = long.Parse(fuge[i]);
            }
            int cnt = 0;
            bool flag = true;
            while (flag)
            {
                
                for (int j = 0; j < n; j++)
                {
                    if (hoge[j] % 2 == 0)
                    {
                        hoge[j] /= 2;
                    }   
                    else flag=false;
                }
                if (flag) cnt++;
            }
            Console.WriteLine(cnt);
        }
    }
}


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

const int M = 998244353;

int Count(int p, string s) {
    int n = s.size();
    assert(n%p == 0);
    int ans = 0;
    for (int i=0; i<p; i++)
        ans = (ans*2 + s[i]-'0')%M;

    string t(s.begin(), s.begin()+p);
    for (int i=p; i<n; i++) {
        t += '0' + ('1' - t[i-p]);
    }
//    cout<<p<<" "<<ans<<" "<<t<<endl;
    return (ans + (t<=s))%M;
}

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

    int n;
    cin>>n;

    string s;
    cin>>s;

    vector<pair<int,int>> prs;

    for (int i=1; i<=2*n; i++) {
        if ((2*n)%i)    continue;
        if (n%i==0)     continue;
        int p = i/2;
        int cnt = Count(p, s);

        prs.emplace_back(i, cnt);
//        cout<<i<<" "<<cnt<<endl;
    }

    long long ans = 0;
    long long total = 0;

    for (int i=0; i<prs.size(); i++) {
        ans = (ans + 1LL*prs[i].first*prs[i].second)%M;
        for (int j=i+1; j<prs.size(); j++) {
            if (prs[j].first%prs[i].first == 0) {
                prs[j].second = (prs[j].second + M - prs[i].second)%M;
            }
        }
        total += prs[i].second;
    }
//    cout<<total<<endl;
    cout<<ans<<endl;
}


Measured memory_bytes: 1268
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
	int n, m;
	char **a, **b;
	scanf("%d %d", &n, &m);
	a = malloc(sizeof(char*) * n);
	b = malloc(sizeof(char*) * m);
	for(int i = 0; i < n; i++){
		a[i] = malloc(sizeof(char) * (n + 1));
		scanf("%s", a[i]);
	}
	for(int i = 0; i < m; i++){
		b[i] = malloc(sizeof(char) * (m + 1));
		scanf("%s", b[i]);
	}

	for(int i = 0; i < n - m + 1; i++){
		for(int j = 0; j < n - m + 1; j++){
			for(int k = 0; k < m; k++){
				if(strncmp(a[i + k] + j, b[k], m))break;
				if(k == m - 1){
					printf("Yes\n");
					return 0;
				}
			}
		}
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#define _USE_MATH_DEFINES
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)

vector<int> to[200005];
vector<int> ans;
void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}

int main() {
	int n, q;
	cin >> n >> q;
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	ans.resize(n);
	rep(i, q) {
		int p, x;
		cin >> p >> x;
		--p;
		ans[p] += x;
	}
	dfs(0);
	
	rep(i, n) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 24960
import bisect
x = int(input())

beki = []
for i in range(1,40):
  for j in range(2,10):
    if i**j <= 1000 and i**j not in beki:
      beki.append(i**j)
beki.sort()

index = bisect.bisect(beki, x)
print(beki[index-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll a,b,k;cin>>a>>b>>k;
    ll val=min(a,k);
    a-=val;
    k-=val;

    val=min(b,k);
    b-=val;
    k-=val;

    cout<<a<<" "<<b;
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
const int MOD=1000000007;
const int INF=LLONG_MAX/2;

signed main() {cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    cout<<max(0LL,b+c-a)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#include <fstream>
#include <cassert>
#include <cmath>
#include <sstream>
#include <time.h>
#include <complex>

#include <unordered_map>
#include <unordered_set>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define DFOR(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define rep(i,n) FOR(i,0,n)
#define repn(i,n) FORN(i,1,n)
#define drep(i,n) DFOR(i,n-1,0)
#define drepn(i,n) DFOR(i,n,1)
#define MAX(a,b) a = Max(a,b)
#define MIN(a,b) a = Min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define Reset(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(all(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)
#define forever for(;;)
#define PINF 1000000000000
#define newline '\n'

#define test if(1)if(0)cerr
using namespace std;

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
typedef pair<char,char> cc;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l4;
const double pi = acos(-1.0);


const int maxn = 1e5+1;
int a[maxn];
int n;

int main()
{
    cin >> n;
    rep(i, n)
    {
        cin >> a[i];
    }
    int cur = 0;
    int ans = 0;
    while (cur < n)
    {
        ++ans;
        int nxt = cur+1;
        while (nxt < n && a[nxt] <= a[nxt-1]) ++nxt;
        int nnxt = cur+1;
        while (nnxt < n && a[nnxt] >= a[nnxt-1]) ++nnxt;
        MAX(nxt, nnxt);
        cur = nxt;
    }
    cout << ans << newline;
}

Measured memory_bytes: 640
/*
          , -- 、
        /;;;;;;', 　　　
        i二二二i
      , ' 　    ヽ ???
     i　ﾉﾉﾉﾉﾉﾍ .', 　　
     〉ﾘi' ﾟ ヮﾟﾉﾚく　 WAyon..........
  ○⊂}〈lﾄ--ｲl〉{つ● 　　
      ,ｒ/ー i-ヽヽ 　　　
     ｀｀i_ﾗi_ﾗ
*/

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
const int INF=(int)1e12;
const int mod=(int)1e9+7;
#define all(a) (a).begin(),(a).end()
typedef vector<vector<int>> graph;

#define pb push_back

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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


signed main() {
    double x;cin >>x;double now=100;
    for(int i=1;i<=4000;i++){
        now=(int)now+now/100;
        if((int)now>=x){
            cout <<i<<endl;
            return 0;
        }
    }
}

















Measured memory_bytes: 3712
#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>>;
typedef long long ll;
typedef pair<long long,int> P;


int main(){
    int h, w;
    cin >> h >> w;
    vector<string> s;
    rep(i, h){
        string t;
        cin >> t;
        s.push_back(t);
    }

    int u[h][w], d[h][w], l[h][w], r[h][w];

    rep(x, w){
        int tmp = 0;
        rep(y, h){
            if (s[y][x] == '.') tmp++;
            else tmp = 0;
            u[y][x] = tmp;
        }
        tmp = 0;
        rrep(y, h){
            if (s[y][x] == '.') tmp++;
            else tmp = 0;
            d[y][x] = tmp;
        }
    }

    rep(y, h){
        int tmp = 0;
        rep(x, w){
            if (s[y][x] == '.') tmp++;
            else tmp = 0;
            l[y][x] = tmp;
        }
        tmp = 0;
        rrep(x, w){
            if (s[y][x] == '.') tmp++;
            else tmp = 0;
            r[y][x] = tmp;
        }
    }


    ll ans = 0;

    rep(y, h){
        rep(x, w){
            if (s[y][x] == '#') continue;
            ll res = u[y][x] + d[y][x] + l[y][x] + r[y][x] - 3;
            ans = max(ans, res);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 66816
import sys
import math
import heapq
mod=10**9+7
inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict, OrderedDict
#すべてのkeyが用意されてる defaultdict(int)で初期化
#順序を保ったdict
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

n,m,r=map(int,input().split())
R=[i-1 for i in list(map(int,input().split()))]#いくまち
G=[[] for i in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    a-=1;b-=1
    G[a].append([c,b])
    G[b].append([c,a])  #G[i]:=iから出る道の[重み、行先]の配列


def dijkstra(s):
    dist=[inf for i in range(n)] #sからの距離のリスト
    dist[s]=0
    mirai=[True for i in range(n)] #Trueなら未確定
    mirai[s]=False

    queue=[] #こいつがheapqになる
    for kyori,to in G[s]:
        heapq.heappush(queue , kyori*10**6+to)  #重みと行先を1つの変数で表してる！
    while queue:
        minedge= heapq.heappop(queue)
        #miraiがTrueのやつ(未確定なやつ)から最小距離のものをさがす
        if not mirai[minedge%(10**6)]: continue
        #距離が小さいものから"確定"していく
        v=minedge%(10**6) #最小距離の頂点
        dist[v] = minedge//(10**6) #その距離
        mirai[v]=False
        for kyori,to in G[v]:
            if mirai[to]:
                heapq.heappush(queue, (kyori+dist[v])*(10**6)+to)
                #queueに入る数は、必ず「sからの」距離と行先を持っている
    return dist


from itertools import permutations as per
ans=inf
P=[dijkstra(i) for i in range(n)]
for l in per(R):
    now=0
    for i in range(r-1):
        now+=P[l[i]][l[i+1]]
    ans=min(ans,now)

print(ans)

Measured memory_bytes: 119176
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
using namespace std;
const int SIZE=1005;
const int INF=1<<29;
const LL p=1e9+7;
int P[SIZE];
int X[SIZE];
int rev[SIZE];
int nokori[SIZE];
const int SSIZE=6005;
bool able[2][SIZE][SSIZE];
bool isnow[SIZE];
int sums[SIZE];
int ables(int now,int i){
	return able[isnow[now]][now][i];
}
void update(int now,int x){
	FOR(i,x,SSIZE){
		able[isnow[now]][now][i]|=able[!isnow[now]][now][i-x];
//		if(able[isnow[now]][now][i]) cout << now <<" " << i <<endl;
	}
}
bool solve(){
	int N;
	cin >> N;
	FOR(i,1,N){
		cin >> P[i];
		P[i]--;
		nokori[P[i]]++;
	}
	queue<int> qu;
	REP(i,N){
		able[0][i][0]=true;
		cin >> X[i];
		if(nokori[i]==0) qu.push(i);
	}
	while(!qu.empty()){
		int now=qu.front();
		qu.pop();
	//	cout << now << endl;
		int maxim=-1;
		REP(i,X[now]+1){
			if(ables(now,i)){
				maxim=i;
			}
		}
//		cout << maxim << endl;
		if(maxim==-1) return false;
		rev[now]=sums[now]-maxim;
		if(now==0) break;
		nokori[P[now]]--;
		sums[P[now]]+=rev[now]+X[now];
		isnow[P[now]]^=1;
		REP(i,SSIZE) able[isnow[P[now]]][P[now]][i]=0;
		update(P[now],rev[now]);
		update(P[now],X[now]);			

		if(nokori[P[now]]==0){
			qu.push(P[now]);
		}
	}
	return true;
}
int main(){
	if(solve()){
		cout << "POSSIBLE" << endl;
	}
	else{
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 11392
using Yorukatsu058.Questions;
using Yorukatsu058.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu058.Questions
{
    /// <summary>
    /// https://atcoder.jp/contests/abc140/tasks/abc140_b
    /// </summary>
    public class QuestionA : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadIntArray();
            var dishes = inputStream.ReadIntArray().Select(i => i - 1).ToArray();
            var happyness = inputStream.ReadIntArray();
            var bonus = inputStream.ReadIntArray();

            var sum = 0;

            for (int i = 0; i < dishes.Length; i++)
            {
                sum += happyness[dishes[i]];

                if (i + 1 < dishes.Length && dishes[i + 1] - dishes[i] == 1)
                {
                    sum += bonus[dishes[i]];
                }
            }

            yield return sum;
        }
    }
}


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

#region Base Classes

namespace Yorukatsu058.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 Yorukatsu058.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: 13396
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

ll gcd(ll a,ll b)
{

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

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

}

int main()
{
    ll t=1;


    while(t--)
    {
        ll a,b,c,d;
        //cout<<lcm(3,4)<<endl;
        cin>>a>>b>>c>>d;
        ll tot=b-a+1;
        ll a1=(a-1)/c+(a-1)/d-((a-1)/lcm(c,d));
        ll b1=b/c+b/d-(b/lcm(c,d));
        //ans= tot-ans;
        //cout<<a1<<" "<<b1<<" "<<tot<<endl;
        cout<<tot-(b1-a1)<<endl;

    }




}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 #include <string> 
 #include <math.h>
 #include <bitset>
 #include <numeric>
 #include <stdio.h>
 #include <algorithm>

 using namespace std;

 int main(){
    int D, T, S;
    int time;
    cin >> D >> T >> S ;

    if(D%S!=0)
        time = D/S + 1; 
    else
        time = D/S; 

    if (T<time)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

    return 0;
 }
 


Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const ll INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

//
int main() {
	int N; cin >> N;
	string s; cin >> s;
	int ans[100100];//1が羊
	for (int i = 0; i < 2; ++i) {
		//ans[0]が羊か狼か
		for (int j = 0; j < 2; ++j) {
		//ans[1]が羊か狼か
			ans[0] = i;
			ans[1] = j;
			for (int k = 2; k < N; ++k) {
				if (ans[k-1] == 1) {
					if (s[k-1]=='o') {
						ans[k] = ans[k-2];
					}
					else {
						ans[k] = 1 - ans[k-2];
					}
				}
				else {
					if (s[k-1]=='o') {
						ans[k] = 1 - ans[k-2];
					}
					else {
						ans[k] = ans[k - 2];
					}
				}
			}
			if (s[0]=='o') {
				if (ans[0] == 1) {
					if (ans[N - 1] != ans[1])continue;
				}
				else {
					if (ans[N - 1] == ans[1])continue;
				}
			}
			else {
				if (ans[0] == 1) {
					if (ans[1] == ans[N - 1])continue;
				}
				else {
					if (ans[1] != ans[N - 1])continue;
				}
			}
			if (s[N - 1] == 'o') {
				if (ans[N - 1] == 1) {
					if (ans[0] != ans[N - 2])continue;
				}
				else {
					if (ans[0] == ans[N - 2])continue;
				}
			}
			else {
				if (ans[N - 1] == 1) {
					if (ans[0] == ans[N - 2])continue;
				}
				else {
					if (ans[0] != ans[N - 2])continue;
				}
			}
			REP(i, N) {
				if (ans[i] == 1)cout << 'S';
				else cout << 'W';
			}
			cout << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	cout << (n + 1) / 2 << '\n';
	return 0;
}


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

typedef long long ll;
ll MOD;ll N;
ll qp(ll q,ll n,ll mod=MOD)
{
    ll ans=1,now=q%mod;
    while(n)
    {
        if(n&1) ans=ans*now%mod;
        now=now*now%mod;
        n>>=1;
    }
    return ans;
}
const int maxn = 3000+10;
ll f[maxn][maxn],c[maxn][maxn];
void getC()
{
    for(int i=1;i<maxn;++i) c[0][i]=0;
    for(int i=0;i<maxn;++i) c[i][0]=1;
    for(int i=1;i<maxn;++i)
        for(int j=1;j<=i;++j)
            c[i][j]=(c[i-1][j]+c[i-1][j-1])%MOD;
}
void getF()
{
    f[1][1]=1,f[1][2]=0;
    for(int i=1;i<maxn;++i) f[i][0]=1;
    for(int i=2;i<maxn-1;++i)
        for(int k=1;k<=i;++k)
            f[i][k]=(f[i-1][k]*(1+k)+f[i-1][k-1])%MOD;
}
int main()
{
    cin>>N>>MOD;
    getC();getF();
    ll ans=0;
    ll q=-1;
    ll tmp=0;
    for(int j=1;j<=N;++j)
    {
        q=-q;
        tmp=0;
        for(int k=0;k<=j;++k)
        {
            tmp=(tmp+(f[j][k])*qp(2,(N-j)*k)%MOD)%MOD;
        }
        tmp=(tmp*(qp(2,qp(2,(N-j),MOD-1)))-1)%MOD;
        ans=(ans+q*c[N][j]*tmp%MOD)%MOD;
        (ans+=MOD)%=MOD;
    }
    ll tot=qp(2,qp(2,N,MOD-1))-1;
    ans=(tot-ans);
    ((ans%=MOD)+=MOD)%=MOD;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 140160
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<cctype>
using namespace std;
const int inf=0x7fffffff;
const double eps=1e-10;
const double pi=acos(-1.0);
//char buf[1<<15],*S=buf,*T=buf;
//char getch(){return S==T&&(T=(S=buf)+fread(buf,1,1<<15,stdin),S==T)?0:*S++;}
inline int read(){
	int x=0,f=1;char ch;ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=0;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch&15);ch=getchar();}
	if(f)return x;else return -x;
}
const int N=2e5+10;
int isit[N];
int n,k;
long long ans;
int main()
{
	n=read();k=read();
	for(int i=1;i<=n;i++)isit[i%k]++;
	ans+=1ll*isit[0]*isit[0]*isit[0];
	if((k&1)==0)
	ans+=1ll*isit[k>>1]*isit[k>>1]*isit[k>>1];
	printf("%lld\n",ans);
	return 0;
}


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

int main(int argc ,char *const argv[]){
    string s;
    while(cin>>s){
    string ss=s;
    reverse(s.begin(),s.end());
    if(ss==s)  cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

using namespace std;
typedef long long ll;

int main() {
	int K;
	ll A[100000] = {};
	cin >> K;
	for (int i = 0; i < K; i++)cin >> A[i];
	reverse(A, A + K);

	if (A[0] != 2) {
		cout << "-1" << endl;
		return 0;
	}

	ll minans = 2, maxans = 3;
	for (int i = 1; i < K; i++) {
		if (minans / A[i] == maxans / A[i] && 
			(minans % A[i] != 0 && maxans % A[i] != 0)) {
			cout << "-1" << endl;
			return 0;
		}

		if (minans % A[i] != 0)minans = (minans / A[i] + 1) * A[i];
		maxans = (maxans / A[i] + 1) * A[i] - 1;

	}
	cout << minans << " " << maxans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int a=0,b=0,c=0,d=0;
  for (int i = 0; i < N; i++) {
    string op;
    cin >> op;
 
    if (op == "P") {
      a=1;
    }
    else if (op == "Y") {
      b=1;
    }
    else if (op == "W") {
      c=1;
    }
    else if (op == "G") {
      d=1;
    }
  }
  if(a==1 && b==1 && c==1 && d==1){
    cout << "Four" << endl;}else{
    cout << "Three" <<endl;}
  }

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

using namespace std;

int main()
{
    int N,K,Q;
    cin >> N >> K >> Q;
    vector<int> A(Q);
    for (int i = 0;i < Q;i++) {
     cin >> A[i];
    }
    vector<int> vec(N);
    for (int i = 0;i < Q;i++) {
        vec[A[i]-1]++;
    }
    for (int i = 0;i < N;i++) {
        if(K - (Q - vec[i]) > 0){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
            return 0;
}


Measured memory_bytes: 1408
k,s = map(int,input().split())
counter = 0
for x in range(k+1):
    if s-x >= k:
        for y in range(k+1):
            z = s-x-y
            if 0<=z<=k:
                counter += 1
    else:
        for y in range((s-x)+1):
            z = s-x-y
            if 0<=z<=k:
                counter += 1
print(counter)

Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>

using namespace std;

#define INF 999999999

int main(){
	int n, m, i, j, door, who;
	vector<string> u, t;
	string s;
	
	door = 0;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> s;
		u.push_back(s);
	}
	cin >> m;
	for(j=0;j<m;j++){
		cin >> s;
		who = -1;
		for(i=0;i<n;i++) if(s == u[i])who = i;
		if(who >= 0){
			if(!door) cout << "Opened by " << u[who] << endl;
			else cout << "Closed by " << u[who] << endl;
			door = 1 - door;
		}
		else cout << "Unknown " << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    N = int(input())
    if N == 0:
        break
    square = []
    direct = [(-1,0),(0,-1),(1,0),(0,1)]
    square.append((0,0))
    topleft = (0,0)
    bottomright = (0,0)
    for i in range(N-1):
        n,d = map(int,input().split(" "))
        nextSquare = (square[n][0]+direct[d][0],square[n][1]+direct[d][1])
        topleft = (min(topleft[0],nextSquare[0]),max(topleft[1],nextSquare[1]))
        bottomright = (max(bottomright[0],nextSquare[0]),min(bottomright[1],nextSquare[1]))
        square.append(nextSquare)
    print(bottomright[0]-topleft[0]+1,topleft[1]-bottomright[1]+1)

Measured memory_bytes: 6744
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.SynchronousQueue;

class Main {
	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextLong();
		}
		long[] sum = new long[n];
		for (int i = 0; i < n; ++i) {
			sum[i] = (i > 0 ? sum[i - 1] : 0) + a[i];
		}

		long ans = Long.MAX_VALUE / 16;
		long[] first = { -1, 1, a[0] };
		out: for (long f : first) {
			long cnt = 0;
			long d = f - a[0];
			cnt = Math.abs(d);
			for (int i = 1; i < n; ++i) {
				if (sign(sum[i] + d) * sign(sum[i - 1] + d) < 0) {
					continue;
				}
				if (sum[i - 1] + d > 0 && sum[i] + d >= 0) {
					cnt += sum[i] + d + 1;
					d -= sum[i] + d + 1;
				} else if (sum[i - 1] + d < 0 && sum[i] + d <= 0) {
					cnt += -(sum[i] + d) + 1;
					d += -(sum[i] + d) + 1;
				} else {
					continue out;
				}
			}
			ans = Math.min(ans, cnt);
		}
		System.out.println(ans);

	}

	int sign(long x) {
		return Long.compare(x, 0);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

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

int main(){
  int K, S, ans=0;
  cin >> K >> S;
  
  for(int i=0 ; i<=K ; i++)
    for(int j=i ; j<=K ; j++)
      for(int k=j ; k<=K ; k++)
        if(i+j+k==S)
          if(i==j && j==k)
            ans++;
          else if(i==j || j==k || k==i)
            ans+=3;
          else
            ans+=6;
  
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(),x.end()
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
using namespace std; 

int n,a,b,cur;

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	//freopen("dat.in","r",stdin); 
#endif
	cin>>n>>a>>b; 
	if(a==1){
		if(b!=n)return puts("-1"),0; 
		dec(i,n,1)printf("%d ",i);puts(""); 
		return 0; 
	}
	int x=(n-b)/(a-1),y=(n-b)%(a-1);
	if(x==0||x>b||(y&&x+1>b))return puts("-1"),0;

	dec(i,b,1)printf("%d ",i); cur=b;
	rep(z,1,y){ dec(i,x+1,1)printf("%d ",cur+i); cur+=x+1; }
	rep(z,1,a-1-y){ dec(i,x,1)printf("%d ",cur+i); cur+=x; }
	puts(""); 
	return 0; 
}


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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader buff = null;
		buff = new BufferedReader(new InputStreamReader(System.in));

		int N = Integer.parseInt(buff.readLine());
		boolean flag = true;
		int t = 0,x = 0, y = 0;
		while(N-- > 0){
			String[] box = buff.readLine().split(" ");
			int t_tmp = Integer.parseInt(box[0]);
			int x_tmp = Integer.parseInt(box[1]);
			int y_tmp = Integer.parseInt(box[2]);

			int abs_t = Math.abs(t - t_tmp);
			int abs_x = Math.abs(x - x_tmp);
			int abs_y = Math.abs(y - y_tmp);

			//System.out.println("x : " + x + " y : " + y + " t : " + t + " x_tmp : " + x_tmp + " y_tmp : " + y_tmp + " abs_x : " + abs_x + "abs_y : " + abs_y);
			boolean stay_flag = (abs_x + abs_y % 2 == 0) == (abs_t % 2 == 0);
			if(abs_t == abs_x + abs_y){
				t = t_tmp;
				x = x_tmp;
				y = y_tmp;
			} else if(abs_t > abs_x + abs_y && stay_flag){
				t = t_tmp;
				x = x_tmp;
				y = y_tmp;
			} else {
				flag = false;
			}
		}

		if(flag){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	static long f() {
		long ans = 0;

		return ans;
	}
}

Measured memory_bytes: 42116
#include <stdio.h>
int main(void) {

	int A, B;

	do {
		scanf("%d%d", &A, &B);
	} while (A < 3 && A > 20 && B < 3 && B > 20);

	int get1, get2;

	if (A >= B) {
		get1 = A;
		A--;
	}
	else {
		get1 = B;
		B--;
	}
	if (A >= B) {
		get2 = A;
	}
	else {
		get2 = B;
	}
	printf("%d\n", get1 + get2);
	return 0;
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s,co;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>s;
      co=s;
      if(s=="zyxwvutsrqponmlkjihgfedcba")Cout(-1);
      else{

        map<char,ll> mp;
        rep(i,Size(s)){
          mp[s[i]]++;
        }
        for(char c='a';c<='z';c++){
          if(mp[c]==0)fl=false;
        }

        if(fl){
      do{
        if(s>co){
          rep(i,Size(s)){
            if(s[i]>co[i]){
              cout<<s[i];
              return 0;
            }
            cout<<s[i];
          }
        }
      }while(next_permutation(all(s)));
        }
        else{
          cout<<s;
          rep(i,26){
            if(mp[alph[i]]==0){
              cout<<alph[i];
              return 0;
            }
          }
        }
      }
     

       
return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

unordered_map<ll, ll> mp;
ll n, ma, mb;
vector<ll> a, b, c;

void solve() {
    ll dp[n + 1][500][500]; // dp[i][j][k] = i番目まででaをj個，bをk個選んだ時の最小コスト．
    rep(i, n + 1) rep(j, 500) rep(k, 500) dp[i][j][k] = inf;
    dp[0][0][0] = 0;
    rep(i, n) {
        rep(j, 500) {
            rep(k, 500) {
                dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
                if (j >= a[i] && k >= b[i]) {
                    dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j - a[i]][k - b[i]] + c[i]);
                }
            }
        }
    }

    ll ans = inf;
    repone(i, 400) {
        repone(j, 400) {
            if (i * mb == ma * j) {
                ans = min(dp[n][i][j], ans);
            }
        }
    }
    cout << (ans == inf ? -1 : ans) << endl;
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = unordered_map<ll, ll>();
#pragma clang diagnostic pop
#endif

        cin >> n >> ma >> mb;
        a.resize(n), b.resize(n), c.resize(n);
        rep(i, n) cin >> a[i] >> b[i] >> c[i];
        solve();

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 80384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

struct BinomialCoefficient  {
    BinomialCoefficient() {}
    BinomialCoefficient(int n) : fac(n + 2), finv(n + 2), inv(n + 2) {
        initialize(n, false);
    }
    
    void initialize(int n, bool resize = true) {
        if (resize) {
            fac.resize(n + 2);
            finv.resize(n + 2);
            inv.resize(n + 2);
        }
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i <= n; i++) {
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
    
    ll factorial(int n) {
        return fac[n];
    }
    
    ll combination(int n, int r) {
        if ((n < r) || (n < 0) || (r < 0)) return 0;
        return fac[n] * (finv[r] * finv[n - r] % mod) % mod;
    }
    
    ll permutation(int n, int r) {
        if ((n < r) || (n < 0) || (r < 0)) return 0;
        return fac[n] * finv[n - r] % mod;
    }
    
private:
    int mod = 1e9 + 7;
    vector<ll> fac, finv, inv;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll x, y;
    cin >> x >> y;
    if ((x + y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    ll t = (x + y) / 3;
    ll a = y - t;
    BinomialCoefficient bc(t);
    cout << bc.combination(t, a) << endl;
    return 0;
}


Measured memory_bytes: 15872
#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>;

const int mod = 1e9 + 7;

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, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

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

  mint ans = 1, x = 1, y = 1;
  rep(i, n) {
    ans *= 10;
    x *= 9;
    y *= 8;
  }
  x *= 2;

  ans -= x;
  ans += y;

  cout << ans << endl;
  return 0;
}

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


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

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
typedef string::const_iterator State;

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


int main(void) {

	bool flag = false;
	string s, t;
	string p;
	int que;

	cin >> s >> t;

	que = s.size();

	FOR(i, 0, que) {
		p = s[que - 1];
		p += s;
		p.pop_back();
		s = p;
		if (s == t) {
			flag = true;
			break;
		}
	}

	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256