akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <unistd.h>
#include <random>
using namespace std;

typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    int N;
    cin >> S >> N;
    vector<char> vec (S.size());
    vector<string> readed (0);
    for(int i = 0;i < S.size();i++){
        vec[i] = S.at(i);
    }
    SORT(vec);
    char testchar = '#';
    for(int i = 0;i < S.size();i++){
        if(testchar == vec[i]){
            continue;
        }
        testchar = vec[i];
        vector<string> str (0);
        for(int j = 0;j < S.size();j++){
            if(S.at(j) == testchar){
                str.push_back(S.substr(j,S.size()-j));
            }
        }
        SORT(str);
        for(int j = 0;j < str.size();j++){
            for(int k = 1;k <= str[j].size();k++){
                bool read = false;
                for(int i = 0;i < readed.size();i++){
                    if(str[j].substr(0,k) == readed[i]){
                        read = true;
                        break;
                    }
                }
                if(read == false){
                    if(N == 1){
                        cout << str[j].substr(0,k) << endl;
                        ED
                    }
                    N--;
                    readed.push_back(str[j].substr(0,k));
                }
            }
        }
    }
}


Measured memory_bytes: 16128
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<iomanip>
#define ll long long
#define For(i,a,n) for(register int i=a;i<=n;i++)
#define RF(i,a,n) for(register int i=a;i>=n;i--)
#define NIL -1
#define MAX 200005
using namespace std;
int n,ans;
int A[MAX];
int dp[MAX];
bool B[MAX];

int main(){
    ios::sync_with_stdio(false);
    cin>>n;
    For(i,1,n){
    	cin>>A[i];dp[i]=1;
    }
    For(i,1,n){
    	B[A[i]]=true;
    	if(B[A[i]-1]) dp[A[i]]=max(dp[A[i]],dp[A[i]-1]+1);
    	ans=max(ans,dp[A[i]]);
    }
    cout<<n-ans<<endl;
    return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 2000000000
#define InfLL 4000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	int N;
	cin >> N;
	vl A(N);
	vector<vl> A25(19);
	rep(i, 19)
		A25[i].resize(19, 0);
	rep(i, N) {
		string Atmp;
		cin >> Atmp;
		int n = Atmp.length();
		bool I = true;
		rep(i, n) {
			if (Atmp[i] == '.')
				I = 0;
		}
		if (I) {
			Atmp.push_back('.');
			Atmp.push_back('0');
		}
		n = Atmp.length();
		int dot = n;
		rep(i, n) {
			if (Atmp[i] == '.')
				dot = i;
		}
		rep(i, dot - n + 10)
			Atmp.push_back('0');
		n = Atmp.length();
		string a;
		rep(i, n) {
			if (Atmp[i] != '.')
				a.push_back(Atmp[i]);
		}
		A[i] = stoll(a);
		ll AA = A[i];
		ll A2 = 0, A5 = 0;
		while (1) {
			if (A[i] % 2 != 0)
				break;
			A2++;
			A[i] /= 2;
		}
		while (1) {
			if (A[i] % 5 != 0)
				break;
			A5++;
			A[i] /= 5;
		}
		A2 = min(A2, 18LL);
		A5 = min(A5, 18LL);
		A25[A2][A5]++;
		A[i] = AA;
	}
	ll ans = 0;
	rep(i, N) {
		ll A2 = 0, A5 = 0;
		while (1) {
			if (A[i] % 2 != 0)
				break;
			A2++;
			A[i] /= 2;
		}
		while (1) {
			if (A[i] % 5 != 0)
				break;
			A5++;
			A[i] /= 5;
		}
		A2 = min(A2, 18LL);
		A5 = min(A5, 18LL);
		if (A2 >= 9 && A5 >= 9)
			ans--;
		rep(a, 19) {
			rep(b, 19) {
				if (a + A2 >= 18 && b + A5 >= 18)
					ans += A25[a][b];
			}
		}
	}
	ans /= 2;


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

Measured memory_bytes: 4788
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    lint N;
    cin >> N;
    lint ans = 1e18;
    for(lint i = 1; i * i <= N; i++){
        if(N % i == 0){
            ans = min(ans, i + (N / i));
        }
    }
    cout << ans - 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
 
const int INF=1<<30;
const ll LINF = 1e18+5;
 
const ll M = 1000000007; // modの値
 
vector<ll> fac(10000000); // n! mod M
vector<ll> ifac(10000000); // k^{M-2} mod M
 
ll mpow(ll x, ll n){ // x^n(modM)
    ll ans = 1;
    while (n!=0) {
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n= n>>1;
    }
    return ans;
}
 
ll comb(ll a, ll b) { // aCb mod M
    if (a==0 && b==0) return 1;
    if (a<b || a<0) return 0;
    ll tmp = ifac[a-b] * ifac[b] % M;
    return tmp * fac[a] % M;
}
 
void init_comb() {
    fac[0] = 1;
    ifac[0] = 1;
    for (ll i=0;i<10000000;i++) {
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i] * mpow(i+1, M-2) % M; // k^{M-2} mod M
    }
}
 
int main() {
    int N;
    ll A[300000] = {};
    cin >> N;
    init_comb();
    rep(i,N) cin >> A[i];
    ll ans = 0;
    ll totalcomb = comb(N,2);
    rep(i,60) {
        ll count_0 = 0;
        rep(j,N) {
            if (((A[j] >> i) & 1) == 0) count_0++;
        }
        ll count = (totalcomb - comb(count_0,2) - comb(N-count_0,2) + 3 * M) % M;
        ans = (ans + count * mpow(2,i)) % M;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 158848
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
cnt = 0
for i in range(n):
    if a[i] >= b[i]:
        cnt += b[i]
    else:
        cnt += a[i]
        if a[i+1] > b[i]-a[i]:
            a[i+1] -= (b[i] - a[i])
            cnt += b[i]-a[i]
        else:
            cnt += a[i+1]
            a[i+1] = 0
print(cnt)


Measured memory_bytes: 18476
#include<iostream>
#include<string>

using namespace std;
int main()
{
    int a[5];
    string str;
    int k;
    for(int i = 0;i<5;i++)
    {
        cin>>str;
        a[i] = stoi(str);
    }
    cin>>str;
    k = stoi(str);

    if(a[4]-a[0]<=k)
        cout<<"Yay!";
    else
    {
        cout<<":(";
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;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; }

const lli mod = 1e9;
lli s;

int main(void){
    cin >> s;
    vector<lli> x(3), y(3);
    x[0] = y[0] = 0;
    x[1] = 1e9, y[1] = 1;
    y[2] = (s+mod-1)/mod;
    x[2] = mod*y[2]-s;
    //assert(abs(x[1]*y[2]-x[2]*y[1]) == s);
    rep(i, 3) cout << x[i] << " " << y[i] << " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * b / g;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}



const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	sort(ALL(a));
	int ans = 0;
	rep(i, n) {
		for (int j = i + 1; j < n; j++) {
			int tmp = a[i] + a[j];
			int now = lower_bound(a.begin(), a.end(), tmp) - a.begin();
			ans += now - j - 1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<stdlib.h>
//#include<string.h>
//#include<algorithm>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)

#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pLL pair<long long,long long>
#define pDB pair<double,double>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define PRINT_CASENL  printf("Case %d:\n",tc++)
//#define mx 100005
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
#define IN(a,x,y) (a>=x && a<=y)
#define popcountL __builtin_popcountll
#define popcount __builtin_popcount
/// int other=mask^((1<<n)-1);
typedef long long ll;
typedef long long int lln;
typedef pair<int,int> pii;
ll INF=1<<28;
//typedef long long lld;
const double PI=acos(-1.0);
//int fx[]={1,-1,0,0}; //direction array
//int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};
int knight[8][2]={1,2,1,-2,2,1,2,-1,-1,2,-1,-2,-2,1,-2,-1};
const long double EPS=1e-7;
//#define INF 10000

struct compare
{
  bool operator()(const pair<int,pii>& l, const pair<int,pii>& r)
  {
      if(l.ff==r.ff)
      {
          return l.sn.ff>r.sn.ff;
      }
      return l.ff<r.ff;
  }
};
// bool operator<(pair<int,pii> l, pair<int,pii> r)
//  {
//      if(l.ff==r.ff)
//      {
//          cout<<"ok "<<endl;
//          return l.sn.ff<r.sn.ff;
//      }
//      return l.ff>r.ff;
//  }

/////////////////////////////////////template sesh/////////////////////////////////////////////////////

///code goes from here
const int mx=500150;
///
int mod=1000000007;

string arr[mx];

int main()
{
//    SPEED;
    int n;
    sf(n);
    string s;
    map<string,int>mp;
    mp["AC"]=0;
    mp["WA"]=0;
    mp["TLE"]=0;
    mp["RE"]=0;

    for(int i=0;i<n;i++)
    {
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;

    return 0;
}



Measured memory_bytes: 19324
#include<iostream>
using namespace std;
int main()
{
	int q;
	cin >> q;
	for(int i=0;i<q;++i){
		int c,a,n,counter=0;
		cin >> c >> a >> n;
		while(1){
			if(c>0 && a>0 && n>0){
				counter+=1;
				c--;
				a--;
				n--;
			}
			else if(c>=2 && a>0){
				counter+=1;
				c-=2;
				a--;
			}
			else if(c>=3){
				counter+=1;
				c-=3;
			}
			else{
				break;
			}
		}
		cout << counter << endl;
	}
	return 0;
}

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


#define M_MAX 20
#define N_MAX 50000
#define INFTY 1 << 29

int main(){
int n,l;
cin >> n>>l;
int data[n];
int datan[n];
for(int i=0;i<n;i++){
data[i]=l+i;
datan[i]=abs(l+i);
}

sort(datan,datan+n);
int temp=datan[0];
int dat=0;
for(int i=0;i<n;i++){
if(temp==data[i] || temp==-data[i]){
}else{
dat+=data[i];
}
}
cout << dat;

}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class B
{
	public static void Main()	
	{
		long A = GetLong();
		long B = GetLong();
		long C = GetLong();
		Console.WriteLine((C % gcd(A,B) == 0) ? "YES" : "NO");
	}

	private static long gcd(long x, long y)
	{
		return (y == 0) ? x : gcd(y, x % y);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


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


int main(){
	char s[1000];
	scanf("%s",s);
	int cnt=0;
	int len=strlen(s);
	for(int i=0;i<len/2;++i){
		if(s[i]!=s[len-i-1])cnt++;
	}
	printf("%d\n",cnt);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
  while (true) {
    int m, f, r; cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1) break;

    char ans;
    if (m == -1 || f == -1) ans = 'F';
    else if (m + f >= 80) ans = 'A';
    else if (m + f >= 65) ans = 'B';
    else if (m + f >= 50) ans = 'C';
    else if (m + f >= 30) {
      if (r >= 50) ans = 'C';
      else ans = 'D';
    } else {
      ans = 'F';
    }

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

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string a;
   cin>>a;
   if(a[a.length()-1]=='s')
   {
      cout<<a<<"es"<<endl;
   }
   else
   {
      cout<<a<<"s"<<endl;
   }
   return 0;
}

Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
"""
D - AtCoder Express 2
https://atcoder.jp/contests/abc106/tasks/abc106_d

"""
import sys


def solve(N, M, Q, lines, queries):
    dp = [[0]*(N+1) for _ in range(N+1)]
    for f, t in lines:
        dp[f][t] += 1
    for f in range(N-1, 0, -1):
        for t in range(f, N+1):
            dp[f][t] += (dp[f][t-1] + dp[f+1][t] - dp[f+1][t-1])
    for f, t in queries:
        print(dp[f][t])


def main(args):
    N, M, Q = map(int, input().split())
    lines = [[int(i) for i in input().split()] for _ in range(M)]
    queries = [[int(i) for i in input().split()] for _ in range(Q)]
    solve(N, M, Q, lines, queries)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 54472
#include<stdio.h>
int main(){
  int x1,x2,x3,x4,y1,y2,y3,y4;
  scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
  x3=x2+y1-y2;
  y3=y2+x2-x1;
  x4=x1+y1-y2;
  y4=y1+x2-x1;
  printf("%d %d %d %d\n",x3,y3,x4,y4);
  return 0;
}

Measured memory_bytes: 128
N,M = map(int,input().split())
L = []
for i in range(M):
  L.append(list(map(int,input().split())))
for j in range(M):
  L[j].append(j)
L.sort()
l = L[0][0]
cnt = 0
for k in range(M):
  if l == L[k][0]:
    cnt += 1
    L[k].append(cnt)
  else:
    l = L[k][0]
    cnt = 1
    L[k].append(cnt)
L = sorted(L, key = lambda x:x[2])
for i in range(M):
  print('0'*(6-len(str(L[i][0])))+str(L[i][0])+'0'*(6-len(str(L[i][3])))+str(L[i][3]))


Measured memory_bytes: 36228
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++) 

//int main(){
    //A
    /*
    vector<int> a={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 K;
    cin>>K;
    cout<<a[K-1]<<endl;
    */
   //B
   /*
   long long H,W;
   cin>>H>>W;
   if(H==1||W==1) cout<<1<<endl;
   else cout<<(H*W+1)/2<<endl;
   */
   //C
   /*
   long long a,b,c; //int型は2*10^9くらいの値まで
   cin>>a>>b>>c;
   long long d = c-a-b;
   if(d>0&&d*d>4*a*b) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   */
   //D dfsのリターンについて・・・1度のdfs関数への代入で複数のreturnが起こる？
   int n;
   void dfs(string s,char end){
       if(s.size()==n){//このif文を通過するものは複数、nが増えるほど枝状に分岐していく
           cout<<s<<endl;
           return ;
       }
       for(char i='a';i<=end;i++){
           char nxt = end;
           if(i==end) nxt++;//nxtが更新されるのはsの文字数が増えるとき
           dfs(s+i,nxt);
       }
   }
  // }
//return 0;
//}
    int main(){
        cin>>n;
        dfs("",'a');//sが空文字列のときから始めるとちょうど良いタイミング
        return 0;
    }

Measured memory_bytes: 1536
def main():
    n = int(input())

    i = 0
    capacity = []
    for _ in range(5):
        c = int(input())
        capacity.append(c)
        i += 1

    l = (len(capacity) + 1)
    city = [0] * l
    city[0] = n

    p0 = 0
    for i, c in enumerate(capacity):
        p = i + 1 + (n - 1) // c
        p0 = max(p, p0 + 1)

    print(p0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

set<ll> S;

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}


void divisor(ll n, ll l) {
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
        if(l % i == 0){
            S.insert(i);
            if(i * i != n){
                if(l % (n/i) == 0){
                    S.insert(n / i);
                }
            }
        }
    }
  }
  return;
}

bool IsPrime(ll num)
{
    if (num == 1) return true;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main()
{
    ll A,B;
    cin >> A >> B;

    divisor(A,B);

    ll Scount = 0;
    for(auto value : S){
        if(IsPrime(value)) Scount++;
    }

    vector<ll> vec;
    ll C = 0;
    C = gcd(A,B);
    vec = divisor(C);

    ll SScount = 0;
    for(auto value : vec){
        if(IsPrime(value)) SScount++;
    }


    //cout << Scount << endl;
    cout << SScount << endl;

    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

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

namespace xmaho
{
inline namespace input
{
template<typename T>
T get_value(std::istream& is = std::cin);
template<typename C>
C get_container(std::istream& is = std::cin, typename C::size_type length = std::numeric_limits<typename C::size_type>::max());
}
}
using namespace xmaho;

struct book
{
  unsigned long long price;
  std::vector<unsigned long long> exp;
};

int main()
{
  unsigned long long N, M, X;
  cin >> N >> M >> X;
  std::vector<book> books(N);
  for (auto& e : books) {
    e.exp.resize(M);
    cin >> e.price;
    for (auto& m : e.exp) {
      cin >> m;
    }
  }

  auto ans {numeric_limits<unsigned long long>::max()};
  std::vector<unsigned long long> sum(M); // cache
  for (auto i {1ull}; i < (1 << N); ++i) {
    std::cerr << "i: " << i << '\n';
    for (auto& e : sum) e = 0; // init
    unsigned long long sum_cost {0};
    for (auto j {0ull}; j < N; ++j) {
      if (i & (1 << j)) {
        std::cerr << "i, j: " << i << ' ' << j << '\n';
        sum_cost += books[j].price;
        for (auto k {0ull}; k < M; ++k) {
          sum[k] += books[j].exp[k];
        }
      }
    }
    std::cerr << "sum:";
    for (auto e : sum) std::cerr << ' ' << e;
    std::cerr.put(' ');
    std::cerr << "sum_min: " << *min_element(sum.begin(), sum.end()) << endl;
    if (*min_element(sum.begin(), sum.end()) >= X) {
      ans = min(ans, sum_cost);
    }
  }

  if (ans == numeric_limits<unsigned long long>::max()) {
    cout << -1 << '\n';
    return 0;
  }
  cout << ans << '\n';

  return 0;
}

class initalization
{
  class custom_numpunct: public std::numpunct<char>
  {
  public:
    using numpunct::numpunct;
  protected:
    std::string do_truename() const override { return "Yes"; }
    std::string do_falsename() const override { return "No"; }
  };

public:
  initalization()
  {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.imbue(std::locale(std::cout.getloc(), new custom_numpunct{}));
    std::cout << std::boolalpha << std::fixed << std::setprecision(15);
  }
} initalize;

template<typename T>
T xmaho::input::get_value(std::istream& is)
{ T v {}; is >> v; return v; }

template<typename C>
C xmaho::input::get_container(std::istream& is, typename C::size_type length)
{
  C v {};
  if (length != std::numeric_limits<typename C::size_type>::max())
    v.reserve(length);
  typename C::value_type e {};
  for (auto i {length}; i != 0 && is >> e; --i)
    v.push_back(std::move_if_noexcept(e));
  return v;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main(){
    ios_base::sync_with_stdio(false);
    srand(time(0));
    //freopen("input.txt", "r", stdin);
    cin >> a >> b;
    if (a + b == 15) cout << '+';
    else if (a * b == 15) cout << '*';
    else cout << 'x';
    return 0;
}


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

int main()
{
	int n;
	int a, b, c;
	
	scanf("%d%d%d%d", &n, &a, &b, &c);

	vector<int> topping(n);
	for (int i = 0; i < n; i++){
		scanf("%d", &topping[i]);
	}

	sort(topping.begin(), topping.end());
	reverse(topping.begin(), topping.end());

	vector<int> cpd(n); // cal per doll
	int sum = c;

	for (int i = 0; i < n; i++){
		sum += topping[i];
		cpd[i] = sum / (b * (i + 1) + a);
	}

	sort(cpd.begin(), cpd.end());

	printf("%d\n", max(c / a, cpd[n - 1]));

	return (0);
}

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

int dp[100010][3];//2つめの添え字は当日の行動
const int INF = 1 << 30;
int a[100010][3];

int main(){
    int N;
    cin >> N;
    for(int i=0; i<N; ++i){
        for(int j=0; j<3; ++j)
        cin >> a[i][j];
    }

    for(int i=0; i<100010; ++i){
        dp[i][0] = 0;
        dp[i][1] = 0;
        dp[i][2] = 0;
    }

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

    for(int i=0; i<N; ++i){
        for(int j=0; j<3; ++j){
            for(int k=0; k<3; ++k){
                if(j==k)
                    continue;
                if( dp[i+1][k] < dp[i][j] + a[i][k]){
                    dp[i+1][k] = dp[i][j] + a[i][k];
                }
            }
        }
    }

    cout << max(max(dp[N][0],dp[N][1]),dp[N][2]) << endl;

    return 0;
}

Measured memory_bytes: 2688
# -*- coding: utf-8 -*-

S = input()

list_a = S[0::2]
list_b = S[1::2]

#result_a: 010101 にする場合の回数
#result_b: 101010 にする場合の回数
result_a, result_b = 0,0

for l in list_a:
  black = l.count("0")
  white = l.count("1")
  result_a += white
  result_b += black

for l in list_b:
  black = l.count("0")
  white = l.count("1")
  result_a += black
  result_b += white

result = min([result_a, result_b])
print(result)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define debug(x) cout << #x << " = " << x << endl
#define pb push_back
#define F first
#define S second

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

    string s;
    int n, aux = 0, cantB = 0, i = 0;
    ll ans = 0;
    cin >> s;
    n = s.size();
    while(i < n){
        char c = s[i];
        if(c == 'B')cantB++;
        else if(cantB > 0){
            ans += cantB;
        }
        i++;
    }

    cout << ans << "\n";
}


Measured memory_bytes: 720
class TreasureHunter
  def initialize
    @x = 0
    @y = 0
    @deg = 0
  end

  def to_rad(deg)
    return Math::PI * deg / 180.0
  end
  
  def walk(distance)
    @x += Math.sin(to_rad(@deg)) * distance
    @y += Math.cos(to_rad(@deg)) * distance
  end

  def turn(direction)
    @deg += direction
  end

  def dumpXY
    return [@x.round(1).to_i, @y.round(1).to_i]
  end
end

t = TreasureHunter.new
$<.each_line do |line|
  distance, direction = line.split(/,/).map(&:to_i)
  t.walk(distance)
  t.turn(direction)
end
puts t.dumpXY

Measured memory_bytes: 9020
#include<iostream>
long N,X,p,i;
int main(){
	std::cin>>N>>X;
	for(i=(1LL<<N/2)*(1<<(N+3>>1));i;i>>=1,--X){
		if(X+1>=i){
			p|=i>>1;
			X-=i-2;
		}
	}
	std::cout<<p;
	return 0;
}


Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    h, w = map(int, input().split())
    lst = []
    for i in range(h):
        lst.append(list(input()))

    R = [[0] * w for _ in range(h)]
    L = [[0] * w for _ in range(h)]
    U = [[0] * w for _ in range(h)]
    D = [[0] * w for _ in range(h)]

    for i in range(h):
        for j in range(w):
            if lst[i][j] == '.':
                if j == 0:
                    L[i][j] = 1
                else:
                    L[i][j] = L[i][j - 1] + 1

    for i in range(h):
        for j in range(w - 1, -1, -1):
            if lst[i][j] == '.':
                if j == w - 1:
                    R[i][j] = 1
                else:
                    R[i][j] = R[i][j + 1] + 1

    for i in range(h):
        for j in range(w):
            if lst[i][j] == '.':
                if i == 0:
                    U[i][j] = 1
                else:
                    U[i][j] = U[i - 1][j] + 1

    for i in range(h - 1, -1, -1):
        for j in range(w):
            if lst[i][j] == '.':
                if i == h - 1:
                    D[i][j] = 1
                else:
                    D[i][j] = D[i + 1][j] + 1

    ans = 0
    x = [[0] * w for _ in range(h)]
    for i in range(h):
        for j in range(w):
            x[i][j] = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
        ans = max(ans, max(x[i]))
    print(ans)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 339848
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define wuyt main
typedef long long ll;
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
//#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
if(c == '-')Nig = -1,c = getchar();
while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
return Nig*x;}
#define read read()
const ll inf = 1e15;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
#define start int wuyt()
#define end return 0
char ss[maxn];
start{
    int cnt1=0,cnt2=0;
    scanf("%s",ss+1);
    int len=strlen(ss+1);
    for(int i=1;i<=len;i++)
    {
        if(ss[i]=='1') cnt1++;
        else cnt2++;
    }
    cout<<min(cnt1,cnt2)*2;
	end;
}


Measured memory_bytes: 384
// 2011/11/07 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){

	int total;
	cin >> total;

	if(total==0)
		break;

	int price[10];
	for(int i=0; i<9; i++)
		cin >> price[i];

	price[9] = total;
	for(int i=0; i<9; i++)
		price[9] -= price[i];

	cout << price[9] << endl;

	}

	return 0;
}

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

class WalkOnMultp
{
    static void Main(string[] args)
    {
        var input = long.Parse(Console.ReadLine());

        var cut = Math.Sqrt(input);

        var cut_a = (long)(cut);

        long n = 0;
        long b = 0;

        for(var i = 1;i <= cut_a; i++)
        {
            if(input % i == 0)
            {
                b = i;
                n = input / i;
            }
        }

        long ans = (b + n  - 2);

        Console.WriteLine(ans);



       
    }
}

Measured memory_bytes: 13140
from collections import deque

nNM = []
nNM = input().rstrip().split(' ')

nH = int(nNM[0])
nW = int(nNM[1])
nTmp = [0 for i in range(nW)]

graph = {}
kyori = {}
checked = {}

nWallCnt = 0

for i in range(nH):
    nTmp=input()
#    print(nTmp)
    
    for i2 in range(nW):

#        print(nTmp[i2]) 
        nPoi=('%d-%d' %(i,i2))
        graph[nPoi] = []
        kyori[nPoi] = float("inf")
        checked[nPoi] = 0
        
        if i==0 and i2==0:
            nStart = ('%d-%d' %(0,0))
            kyori[nPoi] = int (0)

        if i==nH - 1 and i2==nW - 1:
            nGoal = ('%d-%d' %(nH - 1, nW - 1))

        elif nTmp[i2]=='#':
            nWall = ('%d-%d' %(i,i2))
            nWallCnt += 1
            checked[nPoi] = 1

        else:
            if i - 1 >= 0:
                graph[nPoi].append('%d-%d' %(i - 1, i2))

            if i + 1 < nH :
                graph[nPoi].append('%d-%d' %(i + 1 , i2))

            if i2 - 1 >= 0:
                graph[nPoi].append('%d-%d' %(i , i2 - 1))

            if i2 + 1 < nW:
                graph[nPoi].append('%d-%d' %(i , i2 + 1))
        


root_queue = deque()
root_queue += graph[nStart]
nCount = len(graph[nStart])

for i in range(nCount):
    kyori[(graph[nStart][i])] = 1


nFlag = 0


while root_queue:
    nPoi2 = root_queue.popleft()

    if checked[nPoi2] == 0:
        if nPoi2 == nGoal:
            nFlag = 1
            break
        else:
            root_queue += graph[nPoi2]
            for i in range(len(graph[nPoi2])):
                nTmpCount = kyori[nPoi2] + 1
                if kyori[(graph[nPoi2][i])] > nTmpCount:
                    kyori[(graph[nPoi2][i])] = nTmpCount
            checked[nPoi2] = 1


if nFlag == 0:
    print('-1')
else:
    nTmp = kyori[nGoal] + 1
    nTotal = nH * nW
    nAns = nTotal - (nTmp + nWallCnt )
    print(nAns)



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

int main() {
  int N, K; cin >> N >> K;
  vector<int> l(N);
  for (int i = 0; i < N; i++)
  {
    cin >> l.at(i);
  }
  
  sort(l.begin(), l.end(), greater<int>());

  int ans = 0;

  for (int i = 0; i < K; i++)
  {
    ans += l.at(i);
  }
  
  cout << ans << endl;
}

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

int main() {
    long long int n,k,d,temp;
    cin >>n >>k ;
    long long int arr[n],ans=n;
    for(long long int i=0;i<n;i++)
    {
        arr[i]=1;
    }
    while(k--)
    {
        cin >>d;
        while(d--)
        {
            cin >> temp;
            if(arr[temp-1])
            {
                ans--;
                arr[temp-1]=0;
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P  = pair<int,int>;
using vi = vector<ll>;
using vv = vector<vi>;
//const int MOD = 1000000007;
//const int MOD = 998244353;
const ll INF = 1001001001001;

int main(){
    ll x,k,d;
    cin>>x>>k>>d;
    
    x = abs(x);
    
    if(x/d>=k)cout<<x-d*k<<endl;
    else{
        ll amari = x/d;
        
        if((amari-k)%2==0)cout<<x-d*amari<<endl;
        else cout << d - (x-d*amari) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout << s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
   int n; cin>>n;
   cout<< n/3 <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;

int n;
string s;

string dfs(string str)
{
    FOR(i,2,s.size()) {
        int l = str.size();
        if (str[l-1] == 'S') {
            if (str[l-2] == 'S' ^ s[l-1] == 'o') {
                str += 'W';
            } else {
                str += 'S';
            }
        } else {
            if (str[l-2] == 'S' ^ s[l-1] == 'o') {
                str += 'S';
            } else {
                str += 'W';
            }
        }
    }

    return str;
}

int main()
{
    cin>>n>>s;
    int cnt = count(ALL(s), 'x');

    string ans;
    int l = s.size();
    vector<string> vs = {"SS", "SW", "WS", "WW"};
    REP(i,4) {
        ans = dfs(vs[i]);

        bool flag = true;
        if (ans[0] == 'S' ^ s[0] == 'o') {
            flag &= ans[1] != ans[l-1];
        } else {
            flag &= ans[1] == ans[l-1];
        }

        if (ans[l-1] == 'S' ^ s[l-1] == 'o') {
            flag &= ans[0] != ans[l-2];
        } else {
            flag &= ans[0] == ans[l-2];
        }

        if (flag) {
            cout<<ans<<endl;
            return 0;
        }
    }

    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n;
    cin >> n;
    ll lim = 1;
    for(int i = 0; i < 18; i++) lim *= 10;
    ll ans = 1;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(a[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    for(int i = 0; i < n; i++) {
        if(lim/a[i] < ans) {
            cout << -1 << endl;
           return 0;
        }
        ans *= a[i];
        if(ans > lim) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
int N, R, L, d, t, x, X[100009], A[100009]; vector<pair<int, int> > v[1000009];
int main() {
    scanf("%d%d%d", &N, &R, &L);
    for(int i = 0; i < R; i++) {
        scanf("%d%d%d", &d, &t, &x);
        v[t].push_back(make_pair(d - 1, x));
    }
    priority_queue<pair<int, int> > que;
    for(int i = 0; i < N; i++) que.push(make_pair(0, -i));
    for(int i = 0; i < L; i++) {
        for(pair<int, int> z : v[i]) {
            X[z.first] += z.second;
            que.push(make_pair(X[z.first], -z.first));
        }
        pair<int, int> w;
        while(true) {
            w = que.top();
            if(w.first == X[-w.second]) {
                A[-w.second]++;
                break;
            }
            que.pop();
        }
    }
    printf("%d\n", (int)(max_element(A, A + N) - A + 1));
    return 0;
}

Measured memory_bytes: 52236
#include <bits/stdc++.h>
#define FASTIO
#define endl "\n"  // Since endl forces a buffer flush which slows down large I/O operations.
#define ff first
#define ss second
#define pb push_back
#define input(c, n) for (int i = 0; i < n; i++) cin >> c[i];
#define exit_message(s) return 0*printf(s)
#define show(c) for (auto i: c) cout << i << " "; cout << "\n";
#define display(c, n) for (int i = 0; i < n; i++) cout << c[i] << " "; cout << "\n";
#define forl(i, a, n) for (int i = a; i < n; i++)
#define dugbe(k) cout << "-\t> " << #k << " = " << k << "\n";

/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/

using namespace std;
typedef long long ll;
typedef pair<int, int> pr;
typedef pair<ll, ll> prll;
typedef vector<int> vi;
typedef vector<ll> vill;
typedef vector<pr> vpr;
ifstream in("input.txt");
const ll mod = 1e9 + 7;
const int N = 1e5 + 5;

ll mod_pow(ll a, ll b)
{
	if (b == 0)
		return 1LL;

	ll res = mod_pow(a, b>>1);
	res = (res*res)%mod;
	if (b&1LL)
		res = (res*a)%mod;
	
	return res;
}

ll n, k;
ll h[N], cost[N];

int32_t main()
{
	#ifdef FASTIO
		// ios_base::sync_with_stdio(false);
		// cin.tie(NULL);
	#endif
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n;
	cin >> n;
	forl(i, 0, n)
	{
		cin >> h[i];
	}
	cost[0] = 0, cost[1] = abs(h[1] - h[0]);
	forl(i, 2, n)
	{
		cost[i] = min(cost[i - 1] + abs(h[i] - h[i - 1]), cost[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << cost[n - 1] << "\n";

	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;

#define N 200003
long long a[N] = {0};
int n;
int main(){
	ios::sync_with_stdio(false);
	int i;
	long long ret = 0, sum=0, t;
	cin>>n;
	for(i=1; i<=n; i++){
		cin>>t;
		a[i] = a[i-1] + t;
	}
	sort(a+1, a+n+1);
	
	t = a[1];
	sum = 0;
	for(i=1; i<=n; i++){
		if(a[i]==0)
			ret++;
		if(a[i]==t){
			sum++;
		} else {
			if(sum>1)
				ret += sum * (sum-1) / 2; 
			sum = 1;
			t = a[i];
		}		
	}
	if(sum>1)
		ret += sum * (sum-1)/2;
	cout<<ret<<endl;
	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());

        int[] d = new int[N];
        for (int i = 0; i < N; i++) {
            d[i] = Integer.parseInt(sc.next());
        }

        int sum = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                sum += d[i] * d[j];
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 25044
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define maxn 1005

using namespace std;
int vis[maxn];
 long double dis[maxn][maxn];
 long double d[maxn];
const long double inf=1e18;
int n;

struct point
{
    int x,y,r;
}p[maxn];
  long double getdis(int i,int j)
{
 long double ans=(long double)sqrt((long double)(p[j].x-p[i].x)*(p[j].x-p[i].x)+(long double)(p[j].y-p[i].y)*(p[j].y-p[i].y))-(long double)p[i].r-(long double)p[j].r;
if(ans>(long double)0)
    return ans;
else
    return (long double)0;
}
void dij(int s)
{
    memset(vis,0,sizeof(vis));
    for(int i=0;i<maxn;i++)
        d[i]=(i==s)?(long double)0:inf;
        for(int i=0;i<=n+1;i++)
        {
            int x;
          long minn=inf;
            for(int y=0;y<=n+1;y++)
                if(!vis[y]&&minn>=d[y])
                minn=d[x=y];
            vis[x]=1;
            for(int y=0;y<=n+1;y++)
              d[y]=min(d[y],d[x]+dis[x][y]);
        }
}
int main()
{
    int x1,y1,x2,y2;
    scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
    scanf("%d",&n);
    p[0].x=x1;
    p[0].y=y1;
    p[0].r=0;
    p[n+1].x=x2;
    p[n+1].y=y2;
    p[n+1].r=0;
    for(int i=1;i<=n;i++)
        scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].r);
        for(int i=0;i<=n;i++)
            for(int j=i+1;j<=n+1;j++)
            dis[i][j]=dis[j][i]=getdis(i,j);
        dij(0);
        printf("%.9Lf\n",d[n+1]);

}


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

int g[100][100];

int main() {
  int n, m;
  while(cin >> n >> m) {
    memset(g,0x3f,sizeof(g));
    while(m--) {
      int a,b;
      cin >> a >> b;
      a--;b--;
      g[b][a] = -1;
    }
    for (int i=0; i<n; ++i) g[n][i] = 0;
    n++;
    for (int k=0; k<n; ++k)
      for (int i=0; i<n; ++i)
        for (int j=0; j<n; ++j)
          g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
    vector<pair<int,int>> v;
    for (int i=0; i<n-1; ++i) {
      v.emplace_back(g[n-1][i], i);
    }
    sort(v.begin(), v.end());
    for (auto p : v) {
      cout << p.second+1 << endl;
    }
  }
}

Measured memory_bytes: 1248
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) throws IOException {
    new Main().execute(System.in);
//    ByteArrayOutputStream os = new ByteArrayOutputStream();
//    os.write(("123\n" +
//        "123\n" +
//        "123\n" +
//        "123\n" +
//        "123").getBytes());
//    InputStream is = new ByteArrayInputStream(os.toByteArray());
//    new Main().execute(is);
  }

  public void execute(InputStream in) {
    Scanner sc = new Scanner(in);
    int m = 0;
    int maxRest = 0;
    for (int i = 0; i < 5; i++) {
      int t = sc.nextInt();
      int span = (int) Math.ceil((t * 1.0) / 10) * 10;
      m += span;
      int rest = span - t;
      maxRest = Math.max(maxRest, rest);
    }
    System.out.println(m - maxRest);
  }
}

Measured memory_bytes: 22996
int main(){
	char op;
	int a,b;
	while (1){
		scanf("%d %c %d",&a,&op,&b);
		if      (op=='?') break;
		else if (op=='+') printf("%d\n",a+b);
		else if (op=='-') printf("%d\n",a-b);
		else if (op=='*') printf("%d\n",a*b);
		else if (op=='/') printf("%d\n",a/b);
	}
	return 0;
}

Measured memory_bytes: 600