akhauriyash/Code-Regression huggingface dataset:
def sub():
    N, Vs, Cs = [input() for _ in range(3)]
    N = int(N)
    Vs = [int(e) for e in Vs.split(" ")]
    Cs = [int(e) for e in Cs.split(" ")]
    ds = [v - c for v, c in zip(Vs, Cs)]
    ds = [d for d in ds if d > 0]
    print(sum(ds))


sub()


Measured memory_bytes: 3060
#include<stdio.h>
typedef unsigned u;
char A[55][55],B[55][55];
int main()
{
	u a,b,i,j,k,I,J;
	scanf("%u%u",&a,&b);
	for(i=-1;++i<a;)scanf("%s",A[i]);
	for(i=-1;++i<b;)scanf("%s",B[i]);
	k=a-b+1;
	for(I=-1;++I<k;)for(J=-1;++J<k;)
	{
		for(i=-1;++i<b;)for(j=-1;++j<b;)
		{
			if(A[I+i][J+j]!=B[i][j])
			goto tjan;
		}
		printf("Yes\n");
		return 0;
		tjan:;
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		circle();

	}
	
	public static void circle() {
		
		Scanner sc = new Scanner(System.in);
		double r = sc.nextDouble();
		
		System.out.println(String.format("%.8f" , r * r * Math.PI) + " " + String.format("%.8f" , 2 * r * Math.PI));
	}
}


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

using namespace std;
 
 
int main() {

    int n;
    cin>>n;
    vector<int>A;

    int j = 0;
    for (int i = 0; i < n-1; i++) {
        cin>>j;
        A.push_back(j);
    }

    int sum = 0;
    int size = A.size();
    for (int i = 0; i < size; i++) {
        //first
        if(i==0){
            sum+=A[i];

            //others
        }else{
            if(A[i] < A[i-1]){
                sum+=A[i];
            }else{
                sum+=A[i-1];
            }
        }

    }
    sum+=A[size-1];

    cout<<sum;

    return 0;

}




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

using namespace std;

constexpr int N = 100000;
constexpr int MOD = 998244353;

int depth[N + 1];
vector<int> d[N + 1];

int main() {
	int max_d, n, i, j;
	long long ans;

	scanf("%d", &n);
	assert(1 <= n and n <= N);
	max_d = 0;

	for (i = 1; i <= n; i++) {
		scanf("%d", depth + i);
		d[depth[i]].push_back(i);
		max_d = max(max_d, depth[i]);
	}

	if (depth[1] != 0 or d[0].size() != 1) {
		printf("0\n");
		return 0;
	}

	ans = 1;

	for (i = 1; i <= max_d; i++) {
		for (j = 0; j < d[i].size(); j++) {
			ans = (ans * (long long)d[i - 1].size()) % MOD;
		}
	}

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 6144
#include "bits/stdc++.h"
using namespace std;
int main() {
	string S, T;
	cin >> S >> T;
	for (int i = 0; i < S.size() + T.size(); i++) {
		if (i % 2 == 0) cout << S.at(i / 2);
		else cout << T.at(i / 2);
	}
	cout << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
typedef struct scale{
	double x;
	double y;
} S;

void kock(int n, S p1,S p2);
int main(void){
	int n, i;
	S p1, p2;
	p1.x = 0.0;
	p1.y =0.0;
	p2.x = 100.0;
	p2.y = 0.0;
	
	scanf("%d", &n);
	printf("%f %f\n", p1.x, p1.y);
	kock(n, p1, p2);
	printf("%f %f\n", p2.x, p2.y);
	return 0;

}

void kock(int n, S p1,S p2){
	if( n == 0){
        return;
	}

    // p1, p2 から s, t, u を計算
	S s, u, t;
	s.x = (2*p1.x + p2.x)/3;
	s.y = (2*p1.y + p2.y)/3;
	t.x = (p1.x + 2*p2.x)/3;
	t.y = (p1.y + 2*p2.y)/3;
	u.x = (t.x - s.x)*cos(60*M_PI/180) - (t.y-s.y)*sin(60*M_PI/180) + s.x;
	u.y = (t.x - s.x)*sin(60*M_PI/180) + (t.y-s.y)*cos(60*M_PI/180) + s.y;
	
    kock(n-1, p1, s);
	printf("%f %f\n", s.x, s.y);
    kock(n-1, s, u);
	printf("%f %f\n", u.x, u.y);
    kock(n-1, u, t);
	printf("%f %f\n", t.x, t.y);
    kock(n-1, t, p2);
	
	
}



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

int main()
{
    int a[5];
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    sort(a, a+5, greater<int>());
    cout << a[0] << " "<< a[1] << " "<< a[2]  << " " << a[3] << " " << a[4];
    cout << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 1180
require'matrix'
h,w,k=gets.split.map &:to_i
f=1,1,2,3,5,8,13,21
m=Matrix.build(w){|r,c|(r-c)**2<2?f[(r+c)/2]*f[w-1+(-r-c)/2]:0}
v=Matrix.build(w,1){|r,c|r==k-1?1:0}
p (m**h*v)[0,0]%(10**9+7)

Measured memory_bytes: 2684
n = int(input())
h = list(map(int, input().split()))

dp = [0, abs(h[0] - h[1])]

for i in range(2, n):
    small_jump = dp[i - 1] + abs(h[i] - h[i - 1])
    big_jump = dp[i - 2] + abs(h[i] - h[i - 2])
    dp.append(min(small_jump, big_jump))

print(dp[-1])


Measured memory_bytes: 20420
/*
    atcoder_begineer_c_112A
   28/10/18
   by ahmed_drawy


*/


#include <bits/stdc++.h>
using namespace std;
//#define push_back               pb;
//#define make_pair               mp;
#define lp(i,start , end)       for(int i = start ; i<end ; ++i)
#define Rlp(i,start , end)      for(int i = start ; i>end ; --i)
#define all(v)                   ((v).begin(),(v).end())
#define sz(v)                  (int)((v).size())
#define clr(v,d)                memset(v , d , sizeof(v))
#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1 << n) - 1)

#define modulo(S, N) ((S) & (N - 1))   // returns S % N, where N is a power of 2 *haven't understood this yet
#define isPowerOfTwo(S) (!(S & (S - 1)))            // done

#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))  // TBD


#define turnOffLastBit(S) ((S) & (S - 1))       // turn off last unset bit from right
#define turnOnLastZero(S) ((S) | (S + 1))       //turn on last unset bit from right
#define turnOffLastConsecutiveBits(S) ((S) & (S + 1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S - 1))



typedef long long               ll;
typedef vector<int>             vi;
typedef vector  <ll>            vll;
typedef vector<vector<int> >    adj;
typedef pair<int ,int>          pii;


const double EPS =1e-7;
const int OO = 1e6;
bool sortpair( const pair<int , int> & x, const pair<int , int> & y)
{

    return  x.first != y.first ? x.first < y.first : x.second > y.second ;


}
int dcomp(double x , double y)
{
    return fabs(x-y) <= EPS? 0: x>y?1:-1;
}
void smile(){
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);
        cout.tie(NULL);
}

void printarr(int arr [] , int n){
lp(i,0,n) cout<<arr[i]<<" ";cout<<endl;
}

void printset(int n ){
    stack <int> myst;
    while(n)    myst.push(n%2), n/=2;
    while(!myst.empty())    cout<<myst.top(), myst.pop();
    cout<<endl;
}

int main(){
	smile();
    int n , t ;cin>>n>>t;
    int mn = INT_MAX;
    bool iss= 0;
    lp(i,0,n){
        int c , T;
        cin>>c>>T;
        if(T<=t){
            mn=min(mn , c);
            iss= 1;
        }

    }
    if(iss)
    cout<<mn;
    else cout<<"TLE";
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static final char SEVEN = '7';
    
    private static final String YES = "Yes";
    
    private static final String NO = "No";

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next().trim();
        boolean lucky = false;
        
        for (int i = 0; i < 3; i++) {
            if (s.charAt(i) == SEVEN) {
                lucky = true;
            }
        }
        
        if (lucky) {
            System.out.println(YES);
        } else {
            System.out.println(NO);
        }
    }
}

Measured memory_bytes: 26952
(function (stdin) {
  var lines = stdin.trim().split('\n');
  var n = parseInt(lines.shift(), 10);
  lines.forEach(function(node) {
    var me = [];
    for (var i = 0; i < n; i++) {
      me.push(0);
    }
    var adj = node.split(' ').map(Number).slice(2);
    adj.forEach(function (a) {
      me[a - 1] = 1;
    });
    console.log(me.join(' '));
  });
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 17116
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<chrono>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];
#define vll(a,n) vll a(n); rep(i, n) cin >> a[i];
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
// #define MOD (998244353)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int n; cin >> n;
    ll ans = 1;
    vint cap(3);
    rep(i, n){
        int a; cin >> a;
        int cnt = 0;
        rep(j, 3) if(cap[j]==a) cnt++;
        // pr(cnt);
        ans *= cnt;
        ans %= MOD;
        rep(j, 3) if(cap[j]==a) {
            cap[j]++;
            break;
        }
        sort(RALL(cap));
    }
    pr(ans);
    return 0;}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <map> 
#include <algorithm>
#include <string.h>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

typedef long long int ll;



void pre_process(string p, int *back_table){
    int i = 0, j = -1, length = p.length();
    back_table[0] = -1;

    while(i <= length) { 
        while(j != -1 && p[i] != p[j]) j = back_table[j];
        i++; j++;
        back_table[i] = j;
    }

}

void _search(string p, string t, int *back_table){
    int i = 0, j = 0, length = t.length(), m = p.length();

    while(i <= length){
        while(j != 0 && t[i] != p[j]) j = back_table[j];
        i++; j++;
        if(j == m) { cout << "Pattern at: " << i - j << endl; j = back_table[j]; }
    }
}

int func(int arr[],int n,int m) {
    int maxsum;
    int incl[n];
    int excl[n];
    incl[0] = arr[0];
    excl [0] = 0;
    for(int i=1;i<n;i++) {
        if(i-m-1 >=0) {
            incl[i] = max(incl[i-m-1],excl[i-m-1]) + arr[i];
        }
        else
            incl[i] = arr[i];
        
        excl[i] = max(excl[i-1],incl[i-1]);
        maxsum = max(maxsum,max(incl[i],excl[i]));
    }

    return maxsum;
}

int show(int x, float y){
    return x + y;
}


int show(int x){ return x; }

float fn_(int x = show(2, 3.3)){
    return x;
}

int fn(int x = show(2)){
    return x;
}

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


int main() {
    solve();
}



// akasakaakas 
// akasakaakas


// akasakaakasaka

// kesav696@sbi
// kesav1096@sbi








Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
typedef long double ld;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
 
#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 3005
int n;
int s;
int a[MN];
ll dp[MN][MN]; //after i elements, sum of j. account for extras

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

    cin >> n >> s;
    FOR(i, 1, n) cin >> a[i];

    ll sm = 0;
    RFOR(i, n, 1){
        if(a[i] < s){
            sm += dp[i+1][s-a[i]]*i;
            sm %= MOD;
        } else if(a[i] == s){
            sm += i*(n-i+1);
            sm %= MOD;
        }
        FOR(j, 1, s-1){
            dp[i][j] += dp[i+1][j];
        }
        FOR(j, a[i]+1, s-1){
            dp[i][j] += dp[i+1][j-a[i]];
            dp[i][j] %= MOD;
        }
        dp[i][a[i]] += (n-i+1);
        dp[i][a[i]] %= MOD;
    }
    /*RFOR(i, n, 1){
        FOR(j, 1, s-1){
            cout << dp[i][j] << " ";
        }
        cout << "\n";
    }*/

    cout << sm << "\n";

    return 0;
}


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

using namespace std;

int main(){
    int v[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int n;
    cin  >> n;
    cout << v[n-1] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()

int main(){
	int n,m;
	int data[110][110];
	int data2[110];
	cin >> n >> m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin  >> data[i][j];
		}
	}
	for(int i=0;i<m;i++){
		cin >> data2[i];
	}
	for(int i=0;i<n;i++){
		int tmp = 0;
		for(int j=0;j<m;j++){
			tmp += data[i][j]*data2[j];
		}
		cout << tmp << endl;
	}

	return 0;
}

Measured memory_bytes: 1208
#include<stdio.h>

int main(){
	
	char c;
	int i,j,k;
	int c2d,cnt;
	char str[1200]={0};
	
	while( scanf("%c",&c) != EOF){
		if( c >= 'A' && c <= 'Z'){
			c2d = c - 'A';
			str[c2d]++;
		}else if(c >= 'a' && c <= 'z'){
			c2d = c - 'a';
			str[c2d]++;
		}else{ 
			;
		}
	}
	
	for(i=0; i<26; i++){
		printf("%c : %d\n",i+'a',str[i]);
	}
	return 0;
}


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

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) ((v).begin(),(v).end())
#define COUT(x) cout<<(x)<<"\n"

int main(){
    ll n,k;
    cin >> n >> k;
    vector<int> vec(n);
    REP(i,n)cin >> vec[i];
    vector<ll> kazu1(n,0);
    vector<ll> kazu2(n,0);
    REP(i,n){
        FOR(j,i+1,n){
            if(vec[i]>vec[j])kazu1[i]++;
        }
        REP(m,n){
            if(vec[i]>vec[m])kazu2[i]++;
        }
    }
    ll test= (k*(k-1)/2)%MOD;
    ll ans = 0;
    REP(i,n){
        ans += (kazu1[i]*k+kazu2[i]*test)%MOD;
        ans %= MOD;
    }
    COUT(ans);
    return 0;
}

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;


int main(void) {
  int n;
  scanf("%d", &n);
  map<int,int> t;
  REP(i, n) {
    int x;
    scanf("%d", &x);
    t[x]++;
  }
  for(auto it : t) {
    if(it.second != 1) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  return 0;
}


Measured memory_bytes: 9600
import bisect
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ruiseki_a = [0]
for i in range(n):
         ruiseki_a.append(a[i] + ruiseki_a[i])
ruiseki_b = [0]
for i in range(m):
         ruiseki_b.append(b[i] + ruiseki_b[i])
ans = 0
aread = bisect.bisect_right(ruiseki_a,k) - 1
for i in range(aread,-1,-1):
         zantime = k - ruiseki_a[i]
         bread = bisect.bisect_right(ruiseki_b,zantime) - 1
         tmp = (i + bread)
         if ans < tmp:
                  ans = tmp
print(ans)


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

using namespace std;

int main(){
  string S; cin >> S; 
 
  int ans = 1e9;
  
  for(int i = 0; i < (int) S.size(); i++){
    int res = 0;
    vector<int> vec; vec.push_back(i + 1);
    
      for(int j = i + 1; j < (int)S.size(); j++){
        
        if( S[j] == S[i]){ vec.push_back(j + 1);}}

     vec.push_back( (int) S.size());
      for(int i = 0; i < (int) vec.size(); i++){
       if( i == 0){ res = vec[0] - 1;}
       else if( 1 <= i && i <= (int) vec.size() - 2){
          res = max(res, vec[i] - vec[i-1] - 1);}
       else{
         res = max( res, vec[(int)vec.size() -1 ] - vec[(int)vec.size() - 2]);}
                   }
    
    ans = min(ans,res);
  }
  
  cout << ans << endl; return 0;}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

int main(){
  fastIO();
  int val;
  for(int i=0;i<5;i++){
    cin>>val;
    if(val==0){
      cout<<i+1<<endl;
      break;
    }
  }
  return 0;
}


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const ll maxn=1000001,mod=1e9+7;

int main(){
sync

    ll n;
    cin>>n;
    ll a[n],b[n];
    forn(i,n){
        cin>>a[i];
    }
    forn(i,n){
        cin>>b[i];
    }
    ll sum=0;
    ll cnt=0;
    vi temp;
    forn(i,n){
        if(a[i]>b[i])
            temp.pb(a[i]-b[i]);
        else{
            sum+=abs(a[i]-b[i]);
            cnt++;
        }
    }
    sort(all(temp));
    reverse(all(temp));
    if(sum==0){
        cout<<0;
        return 0;
    }
    ll cur=0;
    ll i=0;
   // cout<<sum<<endl;

    while(i<temp.size()&&cur<sum){
        cur+=temp[i++];
    }
   // cout<<i<<" "<<temp.size()<<endl; 
    if(cur<sum){
        cout<<-1;
    }
    else{
        cout<<i+cnt;
    }
return 0;
}

Measured memory_bytes: 2428
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define DELNL        cin.ignore(numeric_limits<streamsize>::max(),'\n')
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}

array<ll,100001>fac_mod;
array<ll,100001>fac_inv;
ll pow_mod(ll x,ll y)
{
    return 
    (
        y==0?1
        :y%2==0?pow_mod(((x%MOD)*(x%MOD))%MOD,y/2)
        :(x%MOD)*pow_mod((x%MOD),y-1)
    )%MOD;
}
ll stare(ll n)
{
    ll ret=0;
    for(ll a=n,b=0;a>=0;a-=2,b+=1){
        ret+=((((fac_mod[a+b]%MOD)*(fac_inv[a]%MOD))%MOD)*(fac_inv[b]%MOD))%MOD;
        ret%=MOD;
    }
    return ret;
}
int main()
{
    fac_mod[0]=1;
    REP1(i,100000)fac_mod[i]=(((fac_mod[i-1])%MOD)*(i%MOD))%MOD;
    REP(i,100001)fac_inv[i]=pow_mod(fac_mod[i],MOD-2);

    ll n=in(),m=in();
    vector<ll>a(m);REP(i,m)a[i]=in();
    ll now=0,ans=1;
    REP(i,m){
        ans%=MOD;
        ans=ans*stare(a[i]-now-1)%MOD;
        now=a[i]+1;
    }
    ans%=MOD;
    cout<<ans*stare(n-now)%MOD<<endl;
}

Measured memory_bytes: 2560
import re
s=str(input())
s = s.replace('?', '.')
t=str(input())
for i in range(len(s)-len(t),-1,-1):
  if re.match(s[i:i+len(t)],t):
    s=s.replace(".","a")
    print(s[:i]+t+s[i+len(t):])
    exit()
else:
  print("UNRESTORABLE")

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(void){
	string s,t;
	int i,j,MIN,cnt;
	cin >> s >> t;
	MIN = INT_MAX;
	for(i = 0; i < (int)s.size(); i++){
		if((int)s.size() - 1 >= i + (int)t.size() - 1){
			//cout << "check" << endl;
			cnt = 0;
			for(j = 0; j < (int)t.size(); j++){
				if(s[i + j] != t[j])	cnt++;
			}
		}
		MIN = min(MIN,cnt);
	}
	cout << MIN << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
using ll = long long;
//#define int ll
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
signed main(){
    string a,b; cin>>a>>b;
    a+=b;
    int n=stoi(a);
    for(int i=0;i<=100*10;i++)
        if(i*i==n)return puts("Yes")*0;
    return puts("No")*0;
}


Measured memory_bytes: 256
n = int(input())
p = [int(input()) for _ in range(n)]
q = [0] * (n+1)

for i in range(n):
    q[p[i]] = i
maxl = 1
cnt = 1
for i in range(1, n):
    if q[i+1] > q[i]:
        cnt += 1
    else:
        maxl = max(maxl, cnt)
        cnt = 1
print(n - max(maxl, cnt))


Measured memory_bytes: 18960
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,m = inm()
if n%2==1:
    for i in range(1,m+1):
        print('{} {}'.format(i,n-i))
elif n%4==0:
    e = min(m+1,n//4)
    for i in range(1,e):
        print('{} {}'.format(i,n//2-i))
    if m>=n//4:
        for i in range(m-n//4+1):
            print('{} {}'.format(n-1-i,n//2+i))
else:
    e = min(m+1,n//4+1)
    for i in range(1,e):
        print('{} {}'.format(i,n//2-i+1))
    if m>=n//4+1:
        for i in range(m-n//4):
            print('{} {}'.format(n-1-i,n//2+i+1))


Measured memory_bytes: 9256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define uu unsigned
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define pi pair<int,int>
#define pl pair<ll,ll>
#define mkp make_pair
#define ss second
#define ff first
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define pb push_back
#define pf push_front
#define printcas cout<<"Case "<<cas<<": "
#define _ continue;
#define endl '\n'
#define __ cout<<endl;continue;
#define vc4d(nam,type,a,b,c,d,fix) vector<vector<vector<vector<type>>>> nam(a,vector<vector<vector<type>>>(b,vector<vector<type>>(c,vector<type>(d,fix))))
const ll oo=(1ll<<60);
ll n,k;
ll p[5005],c[5005];
int vis[5005]={0};
ll dfs(ll u)
{
    vl nodes={u};vis[u]=1;
    ll cyclesum=c[u],now;
    for( now=p[u];now!=u;now=p[now])
    {
        cyclesum+=c[now];
        nodes.pb(now);
        vis[now]=1;
    }
    ll nn=nodes.size(),mx=-oo;

        ll cnt=min(nn,k);
        for(int i=0;i<nn;i++)
        {
            int j=cnt;now=nodes[i];ll val=0;
            while(j--)
        {
            now=p[now];
            val+=c[now];
            mx=max(mx,val);
        }
        }
     if(cyclesum<=0 or k<=nn)   return mx;
   ll pp=mx;mx=-oo;
    ll baki=k%nn;
    for(int i=0;i<nn;i++)
    {
        int j=baki;now=nodes[i];ll val=0;
        while(j--)
        {
            now=p[now];
            val+=c[now];
            mx=max(mx,val);
        }
    }
    return max(max(pp,(((k/nn)-1)*cyclesum)+pp),(((k/nn)*cyclesum)+mx));

}

int main()
{
     io;
    int T=1;
    //cin>>T;
    //for(int cas=1;cas<=T;cas++)
    while(T--)
    {
       ll i,j,l,mx=-oo;
       cin>>n>>k;
       for(i=1;i<=n;i++)cin>>p[i];
       for(i=1;i<=n;i++)cin>>c[i];
       for(i=1;i<=n;i++)
       {
           if(!vis[i])
           {
              mx=max(mx,dfs(i));
           }
       }
       cout<<mx;
    }
    return 0;
}


Measured memory_bytes: 3832
import java.util.Scanner;

public class Main {
	static int n;
	static int top[];
	static int bot[];
	static long dp[][];

	public static long f(int left, int right) {
		if (0 < dp[left][right]) {
			return dp[left][right];
		}
		if (left == right) {
			return dp[left][right] = 0;
		}
		
		long min = Long.MAX_VALUE;
		for (int i = left; i < right; i++) {
			long costL = f(left, i);
			long costR = f(i + 1, right);
			long costM = top[left] * bot[i] * top[i + 1] * bot[right];
			min = Math.min(min, costL + costR + costM);
		}
		
		return dp[left][right] = min;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();
		top = new int[n];
		bot = new int[n];
		dp = new long[n][n];
		for (int i = 0; i < n; i++) {
			top[i] = sc.nextInt();
			bot[i] = sc.nextInt();
		}

		System.out.println(f(0, n - 1));
	}
}

Measured memory_bytes: 22636
#include <stdio.h>

int main() {
	int n;

	scanf("%d", &n);
	printf(n <= 9 || (n % 2 == 0 && n / 2 <= 9) || (n % 3 == 0 && n / 3 <= 9) || (n % 4 == 0 && n / 4 <= 9) || (n % 5 == 0 && n / 5 <= 9) || (n % 6 == 0 && n / 6 <= 9) || (n % 7 == 0 && n / 7 <= 9) || (n % 8 == 0 && n / 8 <= 9) || (n % 9 == 0 && n / 9 <= 9) ? "Yes\n" : "No\n");
	return 0;
}


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

void print_tommorow_weather(string today_weather){
  if(today_weather=="Sunny") cout << "Cloudy" << endl;
  if(today_weather=="Cloudy") cout << "Rainy" << endl;
  if(today_weather=="Rainy") cout << "Sunny" << endl;
}

int main(){
  string today_weather;
  cin >> today_weather;
  print_tommorow_weather(today_weather);
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define y first
#define x second

using namespace std;
typedef unsigned long long ll;

ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}
int main()
{
        int n;
        cin >> n;
        ll a[n], b[n];
        ll x, y;


        fr(i, 0, n){
            cin >> a[i] >> b[i];
            if(i == 0){
                x = a[i];
                y = b[i];
            }
            else{
                ll p1 = 1;
                if(a[i] < x) p1 = x / a[i];
                if(p1 * a[i] < x) p1 ++;
                ll p2 = 1;
                if(b[i] < y) p2 = y / b[i];
                if(p2 * b[i] < y) p2 ++;
                p1 = max(p1, p2);
                x = a[i] * p1;
                y = b[i] * p1;


            }
        }

        cout << x + y << endl;


    return 0;
}


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

int main() {
	string S, T;
	cin >> S >> T;
	vector<string> ans;
	if (S.size() >= T.size()) {
		for (int i = 0; i <= S.size() - T.size(); ++i) {
			int j;
			for (j = 0; j < T.size(); ++j) {
				if (S[i + j] != '?' && S[i + j] != T[j]) break;
			}
			if (j == T.size()) {
				string tmp = S;
				for (int j = 0; j < T.size(); ++j) tmp[i + j] = T[j];
				for (int j = 0; j < tmp.size(); ++j) {
					if (tmp[j] == '?') tmp[j] = 'a';
				}
				ans.push_back(tmp);
			}
		}
	}
	if (ans.empty()) cout << "UNRESTORABLE";
	else {
		sort(ans.begin(), ans.end());
		cout << ans[0];
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	bool b=true;
	rep(i,s.size()){
		if(i%2==0){
			if(s[i]=='L')b=false;
		}
		if(i%2==1){
			if(s[i]=='R')b=false;
		}
	}
	Yn(b);
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()?.toLong() ?: return
    Math.sqrt(n.toDouble()).toLong().downTo(1).forEach {
        if (n % it == 0L) {
            println(Math.max("$it".length, "${n / it}".length).toString())
            return
        }
    }
}

Measured memory_bytes: 33432
import java.util.*;

class Main{
   public static void main(String[] args){
      Scanner x = new Scanner(System.in);
   int a,b,c,d;
    a = x.nextInt();
    b = x.nextInt();
    c = a*b;
    a = a*2+b*2;
   System.out.println(c+" "+a);
}
}

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

int main(){
    string S, T;
    vector <int> flag1(26, 0), flag2(26, 0);
    int i, flag3 = 0;

    cin >> S >> T;

    for(i = 0; i < S.size(); i++){
        flag1[S[i] - 0x61]++;
    }

    for(i = 0; i < T.size(); i++){
        flag2[T[i] - 0x61]++;
    }

    sort(flag1.begin(), flag1.end());
    sort(flag2.begin(), flag2.end());
    
    for(i = 0; i < 26; i++){
        if(flag1[i] != flag2[i]){
            flag3 = 1;
            break;
        }
    }

    if(flag3 == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 776
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <cmath>
#include <cstring>
#include <stack>
using namespace std;

const int X = 1e6;

int main(){
    int a, b;
    cin >> a >> b;
    for(int i = 0; i < X; i++){
        if((i*8)/100 == a && (i/10) == b){
            cout << i << '\n';
            return 0;
        }
    }
    cout << "-1\n";
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

#define REP(i, a, b) for(int i = a; i <= b; ++i)
#define DEC(i, a, b) for(int i = a; i >= b; --i)
#define getmid(l,r) ((l) + ((r) - (l)) / 2)
#define MEM(a,b) memset(a,b,sizeof(a))
#define FI first
#define SE second
#define SZ(x) ((int)(x).size())
#define MP make_pair
#define PB push_back
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pii > VPI;
typedef vector<pll > VPL;
const int mod = 1000000007;

char S[3][2010];
int avai[3][3][2010], len[3];

bool judge(int a, int b, int k){
    REP(i, k, min(len[a], k + len[b] - 1)){
        if(S[a][i] != '?' && S[b][i - k + 1] != '?' &&
                S[a][i] != S[b][i - k + 1]) return false;
    }
    return true;
}

int cal(int a, int b, int c){
    int res = 1 << 30;
    REP(i, 1, len[a]) if(avai[a][b][i]){
        // matched start point for b
        int top = max(len[a], i + len[b] - 1);
        REP(j, i, top){
            // matched start point for c
            if(j <= len[a] && avai[a][c][j] == 0) continue;
            if(j <= i + len[b] - 1 && avai[b][c][j - i + 1] == 0) continue;
            res = min(res, max(top, j + len[c] - 1));
        }
    }
    return res;
}

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> S[0] + 1 >> S[1] + 1 >> S[2] + 1;
    REP(i, 0, 2) len[i] = strlen(S[i] + 1);
    REP(i, 0, 2){
        REP(j, 0, 2) if(i != j){
            REP(k, 1, len[i]){
                // si con sj
                avai[i][j][k] = judge(i, j, k);
            }
        }
    }
    int ans = len[0] + len[1] + len[2];
    int arr[3] = {0, 1, 2};
    do{
        ans = min(ans, cal(arr[0], arr[1], arr[2]));
    }while(next_permutation(arr, arr + 3));
    cout << ans << endl;
    return 0;
}


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

int main()
{
  int64_t N, ans = 1;
  cin >> N;
  vector<int64_t> A(N + 1), MA(N + 1), MI(N + 1);
  for (int i = 0; i <= N; i++)
  {
    cin >> A.at(i);
  }
  MA[N] = MI[N] = A[N];
  for (int i = N - 1; i >= 0; i--)
  {
    MI[i] = (MI[i + 1] + 1) / 2 + A[i];
    MA[i] = MA[i + 1] + A[i];
  }
  if (!(MI[0] <= 1 && 1 <= MA[0]))
  {
    cout << -1 << endl;
    return 0;
  }
  int64_t prev = 1;
  for (int i = 1; i <= N; i++)
  {
    ans += min((prev - A[i - 1]) * 2, MA[i]);
    prev = min((prev - A[i - 1]) * 2, MA[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 5636
/**
 *      purpose : ABC 124 A
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'

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

  int a, b; cin >> a >> b;
  print(max({2 * a - 1, 2 * b - 1, a + b}));


  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,cnt=0;
	pair<int,int> b[110];
	cin>>a;
	for (int i=0;i<a;i++)
		cin>>b[i].first>>b[i].second;
	for (int i=0;i<a;i++)
	{
		if (b[i].first==b[i].second)
			cnt++;
		else
			cnt=0;
		if (cnt==3)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3544
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
int main(){
  int n;cin>>n;
  int count=0;
  if(n<10)count=n;
  if(n>=10&&n<100)count=9;
  if(n>=100&&n<1000)count=n-99+9;
  if(n>=1000&&n<10000)count=909;
  if(n>=10000&&n<100000)count=n-9999+909;
  else if(n==100000){
    count=90909;
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ツ篠ゥツ督ョツ青カツ青ャツつウツづェツつスツδソツッツドツ・ツスツタツブ
		Scanner sc=new Scanner(System.in);
		long a,b,g,l;
		while(sc.hasNext()){
			a=sc.nextLong();
			b=sc.nextLong();
			if(a<b){
				g=gcd(a,b);
			}
			else{
				g=gcd(b,a);
			}
			l=a*b/g;
			System.out.printf("%d %d\n",g,l);
		}
	}
	static long gcd(long a,long b){
		if(b==0){
			return a;
		}
		else{
			return gcd(b,a%b);
		}
	}
	

}

Measured memory_bytes: 11000
n=int(input())
cards=list(map(int,input().split()))
cards.sort()
prevnum=cards[0]
difnum=1
for i in range(n):
    if(cards[i]!=prevnum):
        prevnum=cards[i]
        difnum+=1
if (n-difnum)%2==0:
    print(str(difnum))
else:
    print(str(difnum-1))

Measured memory_bytes: 14396
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){
    int n;
    int a[80000]={0};
    while(cin>>n&&n){

        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        int k=0,m=n;
        while(1){
            //cout<<"---"<<k<<endl;
            bool flg=0;
            for(int i=0,j=1;i<m;i++){
                //cout<<"a["<<i<<"]="<<a[i]<<"  j="<<j<<endl;
                if(a[i]!=0&&a[i]!=j){
                    flg=1;
                    break;
                }
                else if(a[i]==j)j++;
            }
            if(k==10000){
                cout<<-1<<endl;
                break;
            }
            for(int i=0;i<m;i++){
                if(a[i])a[i]--,a[m]++;

            }

            if(!flg){
                cout<<k<<endl;
                break;
            }
            k++,m++;
        }
        memset(a,0,80000);
    }
    return 0;
}

Measured memory_bytes: 1480
using System;
using System.Collections.Generic;
using System.Linq;
namespace _2100
{
    class Program
    {
        static void Main(string[] args)
        {
            int n123 = int.Parse(Console.ReadLine());
            for (int i = 0; i < n123; i++)
            {
                int n = int.Parse(Console.ReadLine());
                int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
                int max = int.MinValue;
                int min = int.MaxValue;
                for (int j = 0; j < n - 1; j++)
                {
                    max = Math.Max(max, a[j + 1] - a[j]);
                    min = Math.Min(min, a[j + 1] - a[j]);
                }
                Console.WriteLine(Math.Max(0, max) + " " + Math.Max(0, 0 - min));

            }
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9684
#include <iostream>

using namespace std;

int main(void){
    // Your code here!
    string a, b;
    cin >> a >> b;
    if(a[0] == b[2] && a[1] == b[1] && a[2] == b[0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){

	int N;
	cin >> N;
	int score[N], rank[N];
	vector<int> log;
	for(int i = 0; i < N; i++){
		score[i] = 0;
		rank[i] = 0;
	}

	for(int i = 0; i < (N*(N-1))/2; i++){
		int point1, point2, team1, team2;
		cin >> team1 >> team2 >> point1 >> point2;
		if(point1 == point2){
			score[team1-1]++;
			score[team2-1]++;
		}else if(point1 < point2){
			score[team2-1] += 3;
		}else if(point1 > point2){
			score[team1-1] += 3;
		}
	}
	for(int i = 0; i < N; i++){
		log.push_back( score[i] );
	}
	sort(log.begin(), log.end(),greater<int>());

	for(int i = 0; i < N; i++){
		//if(i > 0 && log[i] == log[i-1]){continue;}
		for(int j = 0; j < N; j++){
			if(log[j] > score[i]){
				rank[i]++;
			}
		}
	}
	for(int i = 0; i < N; i++){
		cout << rank[i]+1 << endl;
	}

	return 0;
}

Measured memory_bytes: 1220
def main():
    """
    連結: ずれて重なっていてもよい
    """
    W, a, b = map(int, input().split())

    # b <= a <= b + W or a <= b <= a + W:
    # 別の長方形とすでに重なっている
    ans = 0
    if b - (a + W) >= 0:
        # bの左端がaの右側
        ans = b - (a + W)
    elif a - (b + W) >= 0:
        # bの右端がaの左側
        ans = a - (b + W)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

func Solve() {
  var N int
  NextInt(&N)
  N--
  cnt := 0
  for k := 1; ; k++ {
    d := N / k
    cnt += d
    if d <= k { break }
    cnt += k * (d - MaxInt(k + 1, N / (k + 1)))
  }
  Write(cnt)
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntSlice(A *[]int) {
  L := strings.Split(NextLine(), " ")
  if len(L) == 1 && L[0] == "" {
    (*A) = make([]int, 0)
    return
  }
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatSlice(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  if len(L) == 1 && L[0] == "" {
    (*A) = make([]float64, 0)
    return
  }
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(S ...interface{}) {
  fmt.Fprintln(writer, S...)
}
func WriteIntSlice(A []int) {
  B := make([]interface{}, len(A))
  for i, a := range A { B[i] = a }
  fmt.Fprintln(writer, B...)
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

Measured memory_bytes: 1820
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rd3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define rl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009

void solve()
{
	ll a,b;
	rl2(a,b);
	if(a>=13)
		wl(b);
	else if(a>=6)
	{
		b=b/2;
		wl(b);
	}
	else
	{
		b=0;
		wl(b);

	}
	NL;
	return;
}
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	solve();
	return 0;
}

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

#define rep(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumlate(all(a),0)
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;
#define int ll

main(){
  int n,a; cin >> n >> a;
  vi x(n); rep(i,n) cin >> x[i];
  int dp[n+1][n+1][n*a+1];

  //rep(i,n) cout << x[i] << endl;

  rep(j,n+1){
    rep(k,n+1){
      rep(s,n*a+1){
	if(j == 0 and k == 0 and s == 0) dp[j][k][s] = 1;
	else if((j > 0) and (s < x[j-1])) dp[j][k][s] = dp[j-1][k][s];
	else if((j > 0) and (k > 0) and (x[j-1] <= s)) dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]];
	else dp[j][k][s] = 0;
	//cout << dp[j][k][s];
      }
      //cout << endl;
    }
    //cout << endl;
  }
  
  int ans = 0; FOR(i,1,n+1){
    ans += dp[n][i][i*a];
    //cout << i << " : " << dp[n][i][i*a] << endl;
  }
  cout << ans << endl;
}


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

int n,m;

int main(){
  int i,j,a,b,c,d;

  cin >> a >> b >> c >> d;
  if(c-a<=d&&c-a>=0)cout << "Yes" << endl;
  else if(a-c<=d&&a-c>=0)cout << "Yes" << endl;
  else if(a<=b&&b<=c&&b-a<=d&&c-b<=d)cout << "Yes" <<endl;
  else if(c<=b&&b<=a&&b-a<=d&&a-b<=d)cout << "Yes" << endl;
  else cout <<"No" << endl;
  return 0;
}


Measured memory_bytes: 256