akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
 
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1000000007
#define hell2 1000000009
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll unsigned long long
#define ld long double 
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cerr << (#x) << " is " << (x) << endl
#define INF 1e13
#define LL_MAX 1e18
// memset(array, -1, sizeof(array[0][0]) * row * count)
using namespace std;
 
ll mult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll multbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=multbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;}
ll add(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll sub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
int isPowerof2(ll x) { return (x && !(x & x-1)); } 
ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; } 
bool isPerfectSquare(long double x) {long double sr = sqrt(x); return ((sr - floor(sr)) == 0); }
bool check(ll i,ll j,ll n){return (i>=0 && i<n && j>=0 &&  j<n);} //matrix boundary checking
 
 
ll ceil(const ll &a, const ll &b){return (a - 1)/b + 1;}
 
// max({a, b, c, d})
// cout << fixed for removing e notation
 
bool comp(pair<string, ll>a, pair<string, ll>b)
{
    if(a.fi < b.fi) return true;
    else if(b.fi < a.fi) return false;
    else
    {
        if(a.se > b.se) return true;
        else return false;
    }
}
 
void convert(int arr[], int n) 
{ 
    int temp[n+1];
    for(int i=1;i<=n;i++)
        temp[i] = arr[i]; 
    // memcpy(temp, arr, n*sizeof(int)); 
  
    sort(temp+1, temp+n+1);   
    unordered_map<int, int> umap;
    int val = 1; 
    for (int i = 1; i <= n; i++) 
        umap[temp[i]] = val++;
    for (int i = 1; i <= n; i++) 
        arr[i] = umap[arr[i]]; 
}
 
bool prime[10000005];
void SieveOfEratosthenes(int n) 
{
    memset(prime, true, sizeof(prime)); 
    prime[0] = prime[1] = 0;
    for (int p=2; p*p<=n; p++) 
    {
        if (prime[p] == true) 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
    }
}

int foo(int a, int b, int c)
{
    return (abs(a-b) + abs(b-c) + abs(a-c));
}


ll getFirstSetBitPos(ll n) 
{ 
    return log2(n & -n) + 1; 
} 

int main()
{
    int r, d, x2;

    cin >> r >> d >> x2;

    ll ans = r*x2 - d;
    for(int i=x2+1;i<=x2+10;i++)
    {
        cout << ans << "\n";

        ans = r*ans - d;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int k, x, i;
    cin >> k >> x;
    for(i=(x-k+1); i<=(x+k-1); i++){
        cout << i << ' ';
    }

    return 0;
}


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

public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		while (true) {
			int a = Integer.parseInt(reader.readLine());
			if (a == 0)
				break;
			int count = 0;
			for (int i = 5; i <= a; i *= 5) {
				count += a / i;
			}
			System.out.println(count);
		}

	}
}

Measured memory_bytes: 16864
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
//cout << fixed << setprecision(0)
int main() {
  int n;cin >> n;
  int ans = 0;
  rep(i,n){
    int a;cin >> a;
    while(a%2==0){
      a/=2;
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

long long inv(int a, int p) { return a==1 ? 1 : (1-p*inv(p%a,a))/a+p; }
static const int MODVAL = 1000000007;
struct mint {
  int val;
  mint():val(0){}
  mint(int x):val(x%MODVAL) { if(val<0) val+= MODVAL; }
  mint(size_t x):val(x%MODVAL) {}
  mint(long long x):val(x%MODVAL) { if(val<0) val+= MODVAL; }
  mint& operator+=(mint y) { val+=y.val; if(val>=MODVAL) val-=MODVAL; return *this; }
  mint& operator-=(mint y) { val-=y.val; if(val<0) val+= MODVAL; return *this; }
  mint& operator*=(mint y) { val=(val*(long long)y.val)%MODVAL; return *this; }
  mint& operator/=(mint y) { val=(val*inv(y.val,MODVAL))%MODVAL; return *this; }
};
inline mint operator+(mint x, mint y) { return x+=y; }
inline mint operator-(mint x, mint y) { return x-=y; }
inline mint operator*(mint x, mint y) { return x*=y; }
inline mint operator/(mint x, mint y) { return x/=y; }
mint POW(mint x, long long n) { mint r(1); for(;n;x*=x,n>>=1) if(n&1) r*=x; return r; }
mint FAC(int n) { static vector<mint> FAC_(1,1);
  while(int(FAC_.size())<=n) FAC_.push_back(FAC_.back()*FAC_.size()); return FAC_[n]; }
inline mint CMB(int n, int k) { return k<0||n<k ? 0 : FAC(n) / (FAC(k) * FAC(n-k)); }
inline ostream& operator<<(ostream& os, mint a) { return os << a.val; }


mint calc(int x, int y) {
  return CMB(x+y+2, x+1) - 1;
}

int main(void) {
  int r1, c1, r2, c2;
  scanf("%d%d%d%d", &r1, &c1, &r2, &c2);
  mint res = calc(r2, c2) - calc(r2, c1-1) - calc(r1-1, c2) + calc(r1-1, c1-1);
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 9964
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cstdlib>
#include <algorithm>

using namespace std;

const int nmax=40,abmax=10,inf = 1000000;
int a[nmax],b[nmax],c[nmax];
int dp[nmax+1][nmax*abmax+1][nmax*abmax+1];
int main(void){
	int n,ma,mb;
	cin >> n >> ma >> mb;
	for(int i=0;i<n;++i){
		cin >> a[i] >> b[i] >> c[i];
	}
	for(int i = 0; i <= n; ++i){
		for(int ca = 0; ca <= nmax*abmax; ++ca){
			for(int cb = 0; cb <= nmax*abmax; ++cb){
				dp[i][ca][cb]=inf;
			} 
		}
	}
	dp[0][0][0]=0;
	for(int i=0;i<n;++i){
		for(int ca = 0; ca <= nmax*abmax; ++ca){
			for(int cb = 0; cb <= nmax*abmax; ++cb){
				if(dp[i][ca][cb]==inf) continue;
				dp[i+1][ca][cb]=min(dp[i+1][ca][cb],dp[i][ca][cb]);
				dp[i+1][ca+a[i]][cb+b[i]]=min(dp[i+1][ca+a[i]][cb+b[i]],dp[i][ca][cb]+c[i]);
			} 
		}
	}
	int ans=inf;
	for(int ca = 1; ca <= nmax*abmax; ++ca){
		for(int cb = 1; cb <= nmax*abmax; ++cb){
			if(ca*mb==cb*ma) ans=min(ans,dp[n][ca][cb]);
		}
	}
	if(ans==inf) ans=-1;
	cout << ans << endl;
	return 0; 
}


Measured memory_bytes: 25984
L = [] ;
L2 = [] ;
for x in range (3 )  :
	arr = list (  map ( int , input().strip().split(" ") ) );
	L.append( arr ) ; 

	L2.append (  [ False for c in range ( 3 ) ] ) ;


r = int( input().strip() ) ; 
for c  in range ( r ) :
	v = int( input().strip() ) ; 
	for y in range ( 3 ) :
		for x in range ( 3 ) :
			if L[y][x] == v :
				L2[y][x] = True ;

b1 = False ;
for x in range ( 3 ) :
	if L2[x][0] and L2[x][1] and L2[x][2] :
		b1 = True ;

	if L2[0][x] and L2[1][x] and L2[2][x] :
		b1 = True ;
	if L2[0][0] and L2[1][1] and L2[2][2] :
		b1 = True ;
	if L2[0][2] and L2[1][1] and L2[2][0] :
		b1 = True ;
if b1 :
	print ("Yes") ;
else :
	print ("No") ;

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

int n,m;
vector <int> a;
vector <long long int> memo;
vector <bool> isDanger;
bool secondFound;

const int MOD = 1000000007;

int main(){
    scanf ("%d %d",&n,&m);
    a.resize(m);
    memo.resize(n+1);
    isDanger.resize(n+1);
    for (int i = 0; n >= i; i++) {
        isDanger[i] = false;
        memo[i] = 0;
    }
    for (int i = 0; m > i; i++){
        scanf ("\n%d",&a[i]);
        isDanger[a[i]] = true;
    }

    secondFound = false;
    for (int i = 0; n >= i; i++){
        if (isDanger[i]) memo[i] = 0;
        else if  (i == 0) memo[i] = 1;
        else if (i == 1) memo[i] = 1;
        else memo[i] =  (memo[i-1] + memo[i-2])%MOD;
    }

    /*for  (int i = 0; n >=  i;  i++){
        printf ("%d %lld\n",i,memo[i]);
    }*/
    printf ("%lld",memo[n]);
}



Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;

namespace GuessTheNumber
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');

            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]);
            int output = 0;
            bool loopOn = true;

            while(loopOn)
            {
                n /= k;
                output += 1;

                if(n <= 0)
                {
                    break;
                }
            }

            Console.WriteLine(output);

        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1100;
double x,y,a;
inline int read()
{
	int x=0,ff=1;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
	while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*ff;
}
int main()
{
	//freopen("1.in","r",stdin);
	a=read();
	x=a/3;
	y=x*x*x;
	printf("%.12lf",y);
	return 0;
}


Measured memory_bytes: 256
N, L = gets.chomp.split.map(&:to_i)
T = Array.new(N) {|i| L + i}
min = T.map(&:abs).min
sum = 0
eat = false
T.each do |t|
  if !eat && t.abs == min
    eat = true
  else
    sum += t
  end
end
puts sum


Measured memory_bytes: 1788
/*input

*/
#include<bits/stdc++.h>
#define ll        	long long 
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)  for(ll int i=a;i<b;i++)
#define rrep(i,a,b) for(ll int i=a;i>=b;i--)
#define all(a)      (a).begin(),(a).end()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define tr(i, cont) for(auto i=cont.begin();i!=cont.end();i++)
#define ios        	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define trace(x)                 cerr << #x << ": " << x << "\n";
#define trace1(x)                cerr << #x << ": " << x << "\n";
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << "\n";

#define endl "\n"
using namespace std;


int main(){
	ll n;
	cin>>n;
	vi v(n-1);
	rep(i,0,n-1)
		cin>>v[i];
	ll ans=v[0]+v[n-1-1];
	rep(i,1,n-1){
		ans+=min(v[i-1],v[i]);
	}
	cout<<ans;
}


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

using namespace std;

int main(){
    long long n,k;
    cin>>n>>k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
    }
    long long cnt=0;
    for (int i = 0; i < n; ++i) {
        for (int j = i+1;j < n; ++j) {
            if(a[i]>a[j])++cnt;
        }
    }

    long long acnt=0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0;j < n; ++j) {
            if(a[i]>a[j])++acnt;
        }
    }

    long long ans=k*(k-1);
    ans/=2;
    ans=ans%1000000007ll;
    ans*=acnt;
    ans+=cnt*k;
    ans=ans%1000000007ll;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    L = []
    for i in range(N-1):
        c, s, f = MI()
        L.append([i, s])
        for j in range(i+1):
            k, t = L[j-1]
            if s <= t:
                if t % f == 0:
                    L[j-1] = [k, t+c]
                else:
                    t = t + f - (t % f)
                    L[j-1] = [k, t+c]
            else:
                L[j-1] = [k, s+c]
    # print(L)

    for (i, t) in L:
        print(t)
    print(0)
            
        
        
if __name__ == '__main__':
    solve()


Measured memory_bytes: 9244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

//#define DEBUG


int main(void)
{
  int N;
  cin >> N;
  
  double X;
  X = (100./108.*(double)N + 0.99999999999);
//  cout << (int)((int)X*1.08) << endl;
  
  if( N==(int)((int)X*1.08) )
  {
      cout << (int)X;
  }
  else
  {
    cout << ":(";
  }
  

  return 0;
} 

Measured memory_bytes: 256
N = input()
A = list(map(int, input().split()))
B = [0]

siz = len(A)
for i in range(siz-1):
    if A[i] <= A[i+1]:
        B.append(0)
    elif A[i] > A[i+1]:
        B.append(A[i] - A[i+1])
        A[i+1] = A[i+1] + B[i+1]
    else:
        pass
ans = 0
for i in range(siz):
    ans += B[i]
print("{0}".format(ans))


Measured memory_bytes: 32220
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
    int N,W,v,w,ans=0;
    scanf("%d %d",&N,&W);
    vector<int> dp(W+1);
    fill(dp.begin(), dp.end(), 0);
    for(int i=0;i<N;i++){
        scanf("%d %d",&v,&w);
        for(int j=W-w;j>0;j--){
            if(dp[j]!=0){
                dp[j+w]=max(dp[j+w],dp[j]+v);
            }
        }
        dp[w]=max(dp[w],v);
            
    }
    for(int i=0;i<W+1;i++){
        ans=max(ans,dp[i]);
    }
    printf("%d\n",ans);
    return 0;
}

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

using namespace std;

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

  int n;
  cin >> n;

  int tmp = n;
  int sum = 0;
  while (tmp > 0) {
    sum += tmp%10;
    tmp /= 10;
  }
  cout << (n%sum == 0 ? "Yes" : "No") << endl;


  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

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

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

int main(){
    int n, m; cin>>n>>m;
    vector<int> a(n), b(n);
    for(int i=0; i<n; i++) cin>>a[i]>>b[i];
    vector<int> c(m), d(m);
    for(int i=0; i<m; i++) cin>>c[i]>>d[i];

    vector<int> ans(n);
    for(int i=0; i<n; i++){
        int nmin=1e9;
        for(int j=0; j<m; j++){
            int d1=abs(a[i]-c[j]), d2=abs(b[i]-d[j]);
            if(nmin>d1+d2){
                nmin=d1+d2;
                ans[i]=j+1;
            }
        }
    }
    
    for(int i=0; i<n; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        int i=0;
        Map<Integer,Integer> store=new HashMap<Integer,Integer>();
        for(int j=0;j<30;j++){store.put(j+1, j+1);}
        int[] a=new int[2];
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            while ((line = br.readLine()) != null) {
            	store.remove(Integer.parseInt(line));
                i++;
                if(i==28){
                	break;
                }
            }
            i=0;
            for(Map.Entry<Integer, Integer> e : store.entrySet()) {
            	a[i]=e.getValue();
            	i++;
            }
            System.out.println(Integer.min(a[0], a[1]));
            System.out.println(Integer.max(a[0], a[1]));
        }
    }

}

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

#define nl      '\n'
#define fi      first
#define se      second
#define mp      make_pair
#define pb      push_back
#define si(x)   scanf("%d", &x)
#define sl(x)   scanf("%lld", &x)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef map<ll, ll> mll;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef map<char, int> mci;
typedef map<char, char> mcc;
typedef pair<char, int> pci;
typedef map<string, int> msi;
typedef unsigned long long ull;

const double EPS = 1e-11;
const ll MOD = 1000000007;
const double PI = 2 * acos(0.0);

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

    int I = 0, arr[n], c = 0, start = n;
    for (int i = 0; i < n; i++) cin >> arr[i];
    while (I < n) {
        int ct = 1, J;
        for (J = I + 1; J < n; J++) {
            if (arr[J] == arr[I]) ct++;
            else break;
        }
        I = J;
        if (ct == 1) continue;
        c += (ct / 2);
    }
    cout << c << nl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

int64_t modpow(int64_t a, int64_t n, int64_t mod) {
    int64_t res = 1;

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

    return res;
}

int main(){
    int m, n;
    cin >> m >> n;
    const int MOD = 1000000007;

    cout << modpow(m, n, MOD) << endl;
    return 0;
}


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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

void LOG(const int& x) { cerr << x << "\n"; }
void LOG(const vector<int>& a) { for (int x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

int ceil(int a, int b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

signed main() {
  i32 x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<i64> A(x), B(y), C(z);
  cin >> A >> B >> C;
  sort(ALL(A), greater<i64>());
  sort(ALL(B), greater<i64>());
  sort(ALL(C), greater<i64>());
  vector<i64> ABC;
  REP(u, x) {
    REP(v, y) {
      REP(w, z) {
        if (u * v * w > k) break;
        ABC.push_back(A[u] + B[v] + C[w]);
      }
    }
  }
  sort(ALL(ABC), greater<i64>());
  REP(i, k) {
    cout << ABC[i] << endl;
  }
}

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

int main() {
    int A,B,C;
    cin >> A >> B >> C;
    if((A==B && B!=C) || (B==C && C!=A) || (C==A && A!=B))
        cout << "Yes";
    else
        cout << "No";
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <bitset>
#include <string>
#include <cmath>
#include <set>
#include <map>
#define Rep(i, x, y) for (int i = x; i <= y; i ++)
#define Dwn(i, x, y) for (int i = x; i >= y; i --)
#define RepE(i, x) for (int i = pos[x]; i; i = g[i].nex)
#define ev g[i].y
using namespace std;
typedef long long ll;
typedef double db;
const int N = 100010;
const int mod = 1000000007;
int n, t;
ll A, B, a[N], k, f[N];
int main()
{
	scanf ("%d%lld%lld", &n, &A, &B);
	if (A > B) swap(A, B);
	Rep(i, 1, n) scanf ("%lld", &a[i]);
	a[n + 1] = a[n] + B;
	n ++;
	t = 1, k = 1;
	Rep(i, 1, n) {
		if (i > 2 && a[i] - a[i - 2] < A) break ;
		while (a[i] - a[t] >= B) (k += f[t]) %= mod, t ++;
		f[i] = k;
		if (i > 1 && a[i] - a[i - 1] < A) t = i - 1, k = 0;
	}
	printf("%lld\n", f[n]);

	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int p[N],n,x;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&x);
		p[x]=i;
	}
	int now=n-1;
	while (now&&p[now]<p[now+1])now--;
	if (!now){
		puts("0");
		return 0;
	}
	int ans=1,pre=now+1;
	for (;now;now--){
		if (p[pre]<=p[now]&&p[now]<=p[now+1])continue;
		if (p[now]<=p[now+1]&&p[now+1]<=p[pre])continue;
		if (p[now+1]<=p[pre]&&p[pre]<=p[now])continue;
		ans++;pre=now+1;
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 1024
val = list(input())

while True:
    if int(val[0]) + int(val[1]) + int(val[2]) + int(val[3]) == 7:
        print("{0}+{1}+{2}+{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break
    elif int(val[0]) - int(val[1]) - int(val[2]) - int(val[3]) == 7:
        print("{0}-{1}-{2}-{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break
    elif int(val[0]) - int(val[1]) + int(val[2]) + int(val[3]) == 7:
        print("{0}-{1}+{2}+{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break
    elif int(val[0]) + int(val[1]) - int(val[2]) + int(val[3]) == 7:
        print("{0}+{1}-{2}+{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break
    elif int(val[0]) + int(val[1]) + int(val[2]) - int(val[3]) == 7:
        print("{0}+{1}+{2}-{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break
    elif int(val[0]) - int(val[1]) - int(val[2]) + int(val[3]) == 7:
        print("{0}-{1}-{2}+{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break
    elif int(val[0]) - int(val[1]) + int(val[2]) - int(val[3]) == 7:
        print("{0}-{1}+{2}-{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break
    elif int(val[0]) + int(val[1]) - int(val[2]) - int(val[3]) == 7:
        print("{0}+{1}-{2}-{3}=7".format(int(val[0]), int(val[1]), int(val[2]), int(val[3])))
        break



Measured memory_bytes: 3192
t = input()
lent = len(t)
ans = ""
if t[lent-1] == 'D':
    ans+='D'
elif t[lent-1] == 'P':
    ans+='P'
else:
    ans+='D'
for i in range(2,lent+1):
    if t[lent-i] == 'D':
        ans+='D'
    elif t[lent-i] == 'P':
        ans+='P'
    else:
        ans+='D'
ans = ans[::-1]
print(ans)

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

int n,C,i,sum=0,max;
scanf("%d",&n);
int A[n];
for(i=0;i<n;i++)
{
scanf("%d",&A[i]);
sum=sum+A[i]; 
}
max=A[0];
for(i=1;i<n;i++)
{
  if(max<A[i])
  max=A[i];
}
C=sum-max;
if(C>max) printf("Yes\n");
else printf("No\n");
return 0;

}

Measured memory_bytes: 1660
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
pii Dir [] = {
	{ 0, 1 },{ -1 ,1 },{ -1, 0 },
	{ -1 ,-1 },{ 0,-1 },{ 1 ,-1 },
	{ 1,0 },{ 1 ,1 }
};

signed main() {
	int n, m;

	scanf("%d %d", &n, &m);

	vector<vector<int>> tri(n+3, vector<int>(n+3,0));

	REP(i, m) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		a--; b--;
		tri[a][b] += 1;
		tri[a][b + 1] += -1;
		tri[a + c + 1][b] += -1;
		tri[a + c + 2][b+1] += 1;
		tri[a + c + 1][b+c+2] += 1;
		tri[a + c + 2][b +c+2] += -1;
	}
	REP(i, n+2) {
		REP(j, n+2) {
			tri[i][j + 1] += tri[i][j];
		}
	}
	REP(i, n + 2) {
		REP(j, n + 2) {
			tri[j+1][i] += tri[j][i];
		}
	}
	REP(i, n + 2) {
		REP(j, n + 2) {
			tri[i+1][j + 1] += tri[i][j];
		}
	}
	int ans = 0;
	REP(i, n) {
		REP(j, n) {
			ans += (bool)tri[i][j];
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;
int main()

{
    int a,b;
    cin>>a>>b;
    
    if(  a % 3 == 0 or  b % 3 == 0 or (a+b) % 3 == 0 ){
        cout<<"Possible"<<endl;
    }
    
    else cout<<"Impossible"<<endl;
    
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int a, b, c, x; cin>>a>>b>>c>>x;
int res = 0;
for(int i=0; i<=a; ++i){
for(int j=0; j<=b; ++j){
for(int k=0; k<=c; ++k){
if(i*500+j*100+k*50 == x) ++res;
}
}
}
cout<<res;
}

Measured memory_bytes: 256
import java.io.*;

class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split(" ");
		long a = Long.parseLong(str[0]);
		long b = Long.parseLong(str[1]);
		long x = Long.parseLong(str[2]);
		long ans1 = a / x;
		long ans2 = b / x;
		if(a%x!=0){
			System.out.println(ans2-ans1);
		}else{
			System.out.println(ans2-ans1+1);
		}
	}
}

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

using namespace std;
using ll = long long;


int n;
ll c;
vector<ll> x, v;

ll solve() {
    vector<ll> dp(n + 1); // [N, i]に行くときの最大値
    ll val = 0;
    for(int i = n - 1; i >= 0; i--) {
        val += v[i];
        ll cost = -(c - x[i]) + val;
        dp[i] = max(dp[i + 1], cost);
    }
    //print(dp);

    ll nax = 0; //即退店
    val = 0;
    for(int i = 0; i < n; i++) {
        val += v[i];
        ll cost = val - x[i];
        nax = max(cost, nax);
        nax = max(nax, dp[i + 1] + cost - x[i]);
    }
    return nax;
}


int main()
{
     cin >> n >> c;
     x.resize(n), v.resize(n);
     for(int i = 0; i < n; i++)cin >> x[i] >> v[i];
     ll nax = solve();
     for(int i = 0; i < n; i++)x[i] = c - x[i];

     reverse(x.begin(), x.end());
     reverse(v.begin(), v.end());
     cout << max(nax, solve()) << endl;
}

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

int main(){
    int x, y, z;
    cin >> x >> y >>z;

    cout << z <<" " << x << " " << y << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
char s[N];
int main(){
	scanf("%s",s);
	int ans=0;
	char x=s[0];
	for(int i=0;s[i];i++){
		 if(s[i]!=x) ans++,x=s[i];
	}
	printf("%d\n",ans); 
	return 0;
}

Measured memory_bytes: 3812
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

int main(int argc, const char * argv[]) {
    ll n, a, b;
    cin >> n >> a >> b;
    if ((a - b) % 2 == 0){
        cout << (b-a) / 2 << endl;
    }
    else{
        ll rounds_to_1 = a-1;
        ll b2 = b - rounds_to_1-1;
        ll a2 = 1;
        ll ct1 = rounds_to_1 + 1 + (b2-a2) / 2;
        ll rounds_to_n = n-b;
        b = n;
        a += rounds_to_n + 1;
        ll ct2 = rounds_to_n + 1 + (b-a) /2;
        cout << min(ct1,ct2) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=100010;
string s;
int main()
{
  cin>>s;
  int n=s.size();
  if(s[n-1]=='1' || s[0]=='0')
  {
    cout<<"-1\n";
    return 0;
  }
  for(int i=0;i<n-1;i++) if(s[i]!=s[n-i-2])
  {
    cout<<"-1\n";
    return 0;
  }
  int last=1;
  for(int i=1;i<n;i++)
  {
    int now=i+1;
    cout<<now<<" "<<last<<endl;
    if(s[i-1]=='1') last=now;
  }
  return 0;
}


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

int main() {
  string S, T;
  cin >> S >> T;
  cout << T << S << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
const int A_MAX = 1000005 ; 

int main() {
  int N ; 
  cin >> N ; 
  vector<int> A(A_MAX+1) ;
  vector<int> C(A_MAX+1), cnt(A_MAX+1); 
  
  for(int i = 1 ; i <= N ; i++) {
    cin >> A.at(i) ; 
    C.at(A.at(i))++ ; //Cは要素の分布 
  }
  
  int ans = 0 ; 

  for(int i = 1 ; i <= A_MAX ; i++){
    for(int j = i ; j <= A_MAX ; j += i ){
      cnt.at(j) += C.at(i)   ;//cntは　
    }
  }
  
  for(int i = 1 ; i <= A_MAX ; i++ ){
    if(cnt.at(i) == 1 && C.at(i) ){
      ans += C.at(i) ; 
    }
  }
  
  cout << ans << endl ; 
  
}

Measured memory_bytes: 14876
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<ll> vec(N+1,0);
    map<ll,ll> m;
    m[0]=1;
    for(int i=0; i<N; i++){
        ll a;
        cin >> a;
        vec[i+1]=vec[i]+a;
        if(m.count(vec[i+1])){
            m[vec[i+1]]++;
        }else{
            m[vec[i+1]]=1;
        }
    }

    ll ans=0;
    for(auto it=m.begin(); it!=m.end(); it++){
        ans+=(it->second)*((it->second)-1)/2;
    }
    cout << ans << endl; 
}

Measured memory_bytes: 17092
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,n) for(int i(0);i<n;i++)
#define fast  ios_base::sync_with_stdio(0); cin.tie(0);

#define pb push_back
#define all(v) v.begin(), v.end()



int main() {
   
    
    
	int n,k;
	cin>>n>>k;
	int arr[n],dp[n];
	for(int i=0;i<n;i++)cin>>arr[i];
		dp[0] = 0;
			dp[1] = abs(arr[1]-arr[0]);
		for(int i=2;i<n;i++){
			int mini = INT_MAX;
			for(int j=1;(j<=i)&& (j<=k);j++){
				mini = min(mini , dp[i-j]+abs(arr[i]-arr[i-j]) );
						
			}
			dp[i] = mini;
		}

		cout<<dp[n-1];
	    
	    
	    
	
	return 0;
}


Measured memory_bytes: 1024
n = gets.chomp.to_i
h = gets.chomp.split(" ").map { |e| e.to_i }

max = h.max
record = Array.new(n,0)

ans = 0


for i in 1..max+1 do

  for k in 0..n-1 do
    if 1 <= k
      if h[k-1] != 0 && h[k] == 0
        ans += 1
      end
    end
  end
  if h[n-1] != 0
    ans += 1
  end


  for j in 0..n-1 do
    if h[j] != 0
      h[j] -= 1
    end
  end
end

puts ans


Measured memory_bytes: 1788
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;

#define rep(i, a, b) for (int (i)=(a);(i)<=(b);(i)++)
#define Rep(i, a, b) for (int (i)=(a)-1;(i)<(b);(i)++)
#define REP(i, a, b) for (int (i)=(a);(i)>=(b);(i)--)
#define reg(i, x) for (int (i)=head[x];(i);i=e[i].next)
#define clr(a) memset(a,0,sizeof(a))
#define Sort(a, len) sort(a + 1, a + len + 1)
#define Sort2(a, len, cmp) sort(a + 1, a + len + 1, cmp)
#define ass(a, sum) memset(a, sum, sizeof(a))

#define ull unsigned long long
#define ll long long
#define ls ((rt) << 1)
#define rs ((rt) << 1 | 1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
#define Pii pair<int, int>

const int N = 100010 ;
const int iinf = INT_MAX/2 ;
const ll linf = LLONG_MAX/2 ;
const int MOD = 1e9+7 ;

inline int read(){
    int X = 0,w = 0 ;
	char ch = 0;
    while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}
    while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar();
    return w ? -X : X;
}

void write(int x){
     if(x < 0) putchar('-'),x = -x;
     if(x > 9) write(x / 10);
     putchar(x%10 + '0');
}

void print(int x) {
	cout << x << endl ;
	exit(0) ;
}

void douout(double x){
	 printf("%lf\n", x + 0.0000000001) ;
}

int n, t, tot1, tot2 ;
int a[N], b[N], c[N] ;
vector <Pii> B, C ;

bool cmp(Pii a, Pii b){
	return a.fi > b.fi ;
}

int main(){
	scanf("%d", &n) ;
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]) ;
	for (int i = 1; i <= n; i++){
		t = max(t, a[i]) ;
		if (i % 2 == 1) b[a[i]]++ ;
		else c[a[i]]++ ;
	}
	for (int i = 1; i <= t; i++) if (b[i] != 0) B.pb(mp(b[i], i)) ;
	for (int i = 1; i <= t; i++) if (c[i] != 0) C.pb(mp(c[i], i)) ;
	B.pb(mp(0, 0)) ;
	C.pb(mp(0, 0)) ;
	sort(B.begin(), B.end(), cmp) ;
	sort(C.begin(), C.end(), cmp) ;
	if (B[0].se == C[0].se) {
		int ans = min(n - B[1].fi - C[0].fi, n - B[0].fi - C[1].fi) ;
		cout << ans << endl ;
	}
	else cout << n - B[0].fi - C[0].fi << endl ;
}

/*
写代码时请注意：
	1.是否要开Long Long？数组边界处理好了么？
	2.特殊情况处理好了么？
	3.做一些总比不做好。
	4.最大值和最小值问题可不可以用二分答案？
	5.有没有贪心策略？否则能不能dp？
	6.实数精度有没有处理？
*/


Measured memory_bytes: 2552
n=int(input())
h=list(map(int,input().split()))
d=0
mx=0
i=1
while i<n:
    if(h[i]>h[i-1]):
        if(d>mx):
            mx=d
        d=0
    else:
        d+=1
    i+=1
print(max(mx,d))

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,k = -1;
	vector<vector<int> > vec;
	cin >> n;
	for(int i = 0;i <= n + 1;i++){
		if((i - 1) * i / 2 == n){
			k = i;
			break;
		}
	}
	if(k == -1){
		No();
		return 0;
	}
	Yes();
	cout << k << endl;
	vec.resize(k);
	int l = 0,r = 1;
	for(int i = 0;i < n;i++){
		vec[l].pb(i + 1);
		vec[r].pb(i + 1);
		r++;
		if(r >= k){
			l++;
			r = l + 1;
		}
	}
	for(int i = 0;i < k;i++){
		cout << vec[i].size();
		for(int v : vec[i]) cout << " " << v;
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3200
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ls = Console.ReadLine().Trim().Split(' ');
            int n = int.Parse(ls[0]); int q = int.Parse(ls[1]);
            Queue<string[]> queue = new Queue<string[]>();
            while (n != 0)
            {
                queue.Enqueue(Console.ReadLine().Trim().Split(' '));
                n--;
            }
            int total = 0;
            while(queue.Count > 0)
            {
                if (int.Parse(queue.Peek()[1]) <= q)
                {
                    total += int.Parse(queue.Peek()[1]);
                    Console.WriteLine(queue.Dequeue()[0] + " " + total);
                }
                else
                {
                    string[] temp = queue.Dequeue();
                    temp[1] = (int.Parse(temp[1]) - q).ToString();
                    total += q;
                    queue.Enqueue(temp);
                }
            }
        }
    }
}



Measured memory_bytes: 27008
N = int(input())
b = list(map(int, input().split()))

#成り立たせることができるかどうか
for i in range(1, N + 1):
    if b[i - 1] > i:
        print (-1)
        exit()


check_lst = [False] * N #i番目の数を使ったかどうか

ans_lst = [] #答え

#後ろから順にチャックし、使うことができるものから順に使う
index = N - 1
while len(ans_lst) != N: #全て使ったとき終了
    if check_lst[index] == False and b[index] == check_lst[:index].count(True) + 1: #使われていない　かつ　その数字より前にその数字の数 + 1個の使われた数字
        ans_lst.append(b[index])
        check_lst[index] = True
        index = N - 1
    else:
        index -= 1

for i in ans_lst:
    print (i)    
        

Measured memory_bytes: 3064
#!/bin/python3

import sys
input = sys.stdin.readline

def main():
  n = int(input().strip())
  a = list(map(int, input().strip().split()))
  result = 1
  LIMIT = 10**18
  if 0 in a:
    print(0)
    sys.exit()
  for i in a:
    result *= i
    if result > LIMIT:
      print(-1)
      sys.exit()
  print(result)

main()


Measured memory_bytes: 87880
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;

typedef long long ll;
typedef short int sh;

const int inf=0x3f3f3f3f;
const int MAX=1e2+10;
const int mod=1e9+7;

bool flag[10];

bool Check(ll n)
{
    while(n)
    {
        if(flag[n%10])
            return false;
        n/=10;
    }
    return true;
}

int main()
{
    ll ans;
    int k;
    while(scanf("%lld%d",&ans,&k)!=EOF)
    {
        memset(flag,false,sizeof(flag));
        while(k--)
        {
            int x;
            scanf("%d",&x);
            flag[x]=true;
        }
        while(!Check(ans))
        {
            ans++;
        }
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 3212
#pragma region

#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;
typedef long long ll;

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "vec[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  int a, b;
  cin >> a >> b;

  int ans = 0;
  rep(i, max(a, b)) {
    ans += min(a, b) * pow(10, i);
  }

  out(ans);
}


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

int main() {
	int b[120], a[120], n;
	cin >> n;
	for (int i = 0; i < n-1; i++) {
		cin >> b[i];
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (i == 0) {
			a[i] = b[0];
		}
		else if (i == n - 1) {
			a[i] = b[n - 2];
		}
		else {
			a[i] = min(b[i - 1], b[i]);
		}
		ans += a[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count());
//int rnd(int x) { return mrand()%x;}
typedef long long ll;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll md=1e9+7;
ll qp(ll a,ll b){
	ll ret=1;
	while(b){
		if(b&1) ret=ret*a%md;
		a=a*a%md;
		b>>=1;
	}
	return ret;
}
ll C(ll x,ll y){
	ll ret=1;
	for(ll i=x;i>x-y;i--){
		ret=ret*i%md;
	}
	for(ll i=1;i<=y;i++){
		ret=ret*qp(i,md-2)%md;
	}
	return ret;
}
int main(){
	ll n,a,b;
	scanf("%lld%lld%lld",&n,&a,&b);
	printf("%lld\n",(qp(2,n)-1-C(n,a)-C(n,b)+md*3)%md);
	return 0;
}


Measured memory_bytes: 256
#python3
# utf-8

parts_nr = int(input())
a_part_idx___size = sorted([int(x) for x in input().split()], reverse=True)
b_part_idx___size = sorted([int(x) for x in input().split()], reverse=True)
c_part_idx___size = sorted([int(x) for x in input().split()], reverse=True)

b_part_idx___good_c_nr = []
curr_nr = 0
for b_part_idx in range(parts_nr):
    while curr_nr < parts_nr and c_part_idx___size[curr_nr] > b_part_idx___size[b_part_idx]:
        curr_nr += 1
    b_part_idx___good_c_nr.append(curr_nr)

curr_b_part_idx = 0
curr_ans = 0
a_part_idx___ans = []
for a_part_idx in range(parts_nr):
    while curr_b_part_idx < parts_nr and a_part_idx___size[a_part_idx] < b_part_idx___size[curr_b_part_idx]:
        curr_ans += b_part_idx___good_c_nr[curr_b_part_idx]
        curr_b_part_idx += 1
    a_part_idx___ans.append(curr_ans)
print(sum(a_part_idx___ans))


Measured memory_bytes: 23760
import java.util.*;
import java.awt.geom.*;

public class Main{
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			if((a|b|c) == 0) break;
			int n = sc.nextInt();
			int [][] data = new int[n][4];
			for(int i = 0; i < n; i++){
				for(int j = 0; j < 4; j++){
					data[i][j] = sc.nextInt();
				}
			}
			int [] state = new int[a + b + c];
			Arrays.fill(state, 2);
			for(int i = 0; i < n; i++){
				if(data[i][3] == 1){
					for(int j = 0; j < 3; j++){
						state[data[i][j] - 1] = 1;
					}
				}
			}
			
			for(int i = 0; i < n; i++){
				int count = 0;
				for(int j = 0; j < 3; j++){
					if(state[data[i][j] - 1] != 1){
						count++;
					}
				}
				
				if(count == 1){
					for(int j = 0; j < 3; j++){
						if(state[data[i][j] - 1] == 2){
							state[data[i][j] - 1] = 0;
						}
					}
				}
			}
			for(int i = 0; i < state.length; i++){
				System.out.println(state[i]);
			}
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 28412
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    int n;
    cin >> n;
    cout << n*n*n << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,n,i,min1,min2,max;
    cin>>n;
    for( i=1;i<=n;i++)
    {
        cin>>a>>b>>c;
        if(a>b&&a>c)
        {
            max=a;
            min1=b;
            min2=c;

        }
        else if(b>a&&b>c)
        {
            max=b;
            min1=a;
            min2=c;
        }
        else
        {
            max=c;
            min1=a;
            min2=b;
        }

        if(min1*min1+min2*min2==max*max)
            cout<<"YES"<<"\n";
        else
            cout<<"NO"<<"\n";
    }
    return 0;

}

Measured memory_bytes: 1120