akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
    static class FS {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        public long[] readLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }

    static final FS sc = new FS();
    static final PrintWriter out = new PrintWriter(System.out);
    static final int mod = 1000000007;

    public static void main(String[] args) {

        solve();
        out.close();

    }

    static void solve() {
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (n % a == 0) {
            out.println((n / a) * b);
        } else {
            out.println(((n / a) * b) + b );
        }

    }
}




Measured memory_bytes: 32712
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define cY cout << "Yes" << endl;
#define cN cout << "No" << endl;

int main() {
  int n,m;
  cin >> n >> m;
  if(n == m){
    cY;
  }
  else{
    cN;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
ans = A[0]
cnt = 2
for i in range(1,N):
    if cnt>=N:
        break
    ans += A[i]
    cnt += 1
    if cnt==N:
        break
    ans += A[i]
    cnt += 1
    if cnt==N:
        break
print(ans)

Measured memory_bytes: 92184
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n + 1];
		arr[0] = sc.nextInt();
		for (int i = 1; i <= n; i++) {
		    arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		int ans = arr[1] - arr[0];
		for (int i = 2; i <= n; i++) {
		    ans = gcd(ans, arr[i] - arr[0]);
		}
        System.out.println(ans);
	}
	
	static int gcd(int x, int y) {
	    if (x % y == 0) {
	        return y;
	    } else {
	        return gcd(y, x % y);
	    }
	}
}


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

using namespace std;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using D = double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;

#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())
#define rep(i, x)  for(int i = 0; i < (x); i++)
#define rrep(i, x) for(int i = (x - 1); i >= 0; i--)
#define sqrt(x) sqrt(abs(x))
#define y1 y1_1234413
#define j1 j1_235
#define y0 y0_235
#define j0 j0_256
#define fi first
#define se second
#define re return
#define prev PREV
#define next NEXT
#define sz(x) ((int)x.size())

template<typename T> T sqr(T a) { re a * a; }
template<typename T> T gcd(T a, T b) { re b ? gcd(b, a % b) : a; }
template<typename T> T sgn(T a) { re a > 0 ? 1 : (a < 0 ? -1 : 0); }
template<typename T> T abs(T a) { re a > 0 ? a : -a; }

const int inf = 2e9;
const ld st = 0.000001;
const ld pi = acos((ld)-1);
const int MAXN = 100000;
const int mod = 1e9 + 7;


#define FILENAME ""


int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    //  freopen(FILENAME ".in", "r", stdin);
    //  freopen(FILENAME ".out", "w", stdout);
    string s, s1;
    cin >> s >> s1;
    ll ans = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == s1[i]) {
            ans++;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "3 7" ].parse.expand.solve == "5 6 7 8 9" );
	assert( [ "4 0" ].parse.expand.solve == "-3 -2 -1 0 1 2 3" );
	assert( [ "1 100" ].parse.expand.solve == "100" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto kx = input.front.split.to!( long[] );
	return tuple( kx[ 0 ], kx[ 1 ] );
}

auto solve( long k, long x )
{
	auto anss = new long[ k * 2 - 1 ];
	foreach( i, ref ans; anss )
	{
		ans = x - ( k - 1 ) + i;
	}
	return anss.to!( string[] ).join( " " );
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        xl: [(i64, i64); n],
    }

    let mut lr = vec![];

    for (x, l) in xl {
        lr.push((x-l, x+l));
    }

    lr.sort_by_key(|&(_l, r)| r);
    let mut rems = vec![];

    let mut count = 0;

    for (l, r) in lr {
        if let Some(&(_li, ri)) = rems.last() {
            if l < ri {
                continue;
            }
        }
        rems.push((l, r));
        count += 1;
    }

    println!("{}", count);
}


Measured memory_bytes: 7996
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n, a, b;
	cin >> a >> b >> n;
	for(int i=0;i<n;i++){
		int s,f;
		cin >> s >> f;
		if(a<f && s<b){
			cout << 1 << endl;
			return 0;
		}
	}
	cout << 0 << endl;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  int a[n];
  rep(i,0,n){
    cin>>a[i];
  }
  sort(a,a+n);
  cout<<a[n-1]-a[0]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 100000
#define SENTINEL 2000000000

struct h
{
    char t;
    int m;
};
h A[100005], L[100005], R[100005];
int partition(h A[], int p, int r)
{
    int x = A[r].m;
    int i = p-1;
    for(int j=p; j<r; j++)
    {
        if(A[j].m <= x)
        {
            i++;
            swap(A[i],A[j]);

        }
    }
    swap(A[i+1],A[r]);
    return i+1;
}
void quickSort(h A[], int p, int r)
{
    if(p < r)
    {
        int q = partition(A, p, r);
        quickSort(A, p, q-1);
        quickSort(A, q+1, r);
    }
}
void merge(h A[], int n, int left, int mid, int right)
{
    int n1 = mid - left;
    int n2 = right - mid;
    for(int i=0; i<n1; i++)
        L[i] = A[left+i];
    for(int i=0; i<n2; i++)
        R[i] = A[mid+i];
    int i=0, j=0;
    L[n1].m = R[n2].m = SENTINEL;
    for(int k=left; k<right; k++)
    {
        if(L[i].m <= R[j].m)
        {
            A[k] = L[i++];
        }
        else
        {
            A[k] = R[j++];
        }
    }
}
void mergeSort(h A[], int n, int left, int right)
{
    if(left+1 < right)
    {
        int mid = (left+right)/2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}
int main()
{
    int n;
    cin >> n;
    h c1[100005], c2[100005];
    for(int i=0; i<n; i++)
    {
        cin >> c1[i].t >> c1[i].m;
        c2[i] = c1[i];
    }
    mergeSort(c1, n, 0, n);
    quickSort(c2, 0, n-1);
    for(int i=0; i<n; i++)
    {
        if(c1[i].t != c2[i].t)
        {
            cout << "Not stable" << endl;
            break;
        }
        if(i == n-1)   cout << "Stable" << endl;
    }
    for(int i=0; i<n; i++)
        cout << c2[i].t << " " << c2[i].m << endl;
    return 0;
}

Measured memory_bytes: 5344
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// const long double PI = acos(-1);
constexpr int inf = 1e9;
constexpr ll INF = 2e18;
// constexpr ll MOD = 1e9+7;
constexpr ll MOD = 998244353;

int n;
int a[1010];
ll b[1010];
bool ok[1000010];

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = a[i];
        ok[a[i]] = 1;
    }
}

void solve() {
    for (int i = 0; i < 6; i++) {
        for (int j = 0; j + i + 1 < n; j++) {
            b[j] = b[j] * 10 + a[j + i + 1];
            if (b[j] < 1000010)
                ok[b[j]] = 1;
        }
    }
    for (int i = 0; i < 1000010; i++) {
        if (!ok[i]) {
            cout << i << endl;
            return;
        }
    }
}

int main(int argc, char *argv[]) {
    input();
    solve();
    return 0;
}



Measured memory_bytes: 4008
//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>

using namespace std;  typedef long long ll;
inline int qr(){
	int ret=0,f=0,c=getchar();
	while(!isdigit(c)) f|=c==45,c=getchar();
	while( isdigit(c)) ret=ret*10+c-48,c=getchar();
	return f?-ret:ret;
}
const int maxn=1e5+5;
const int inf=1e9;
struct E{
	int to,nx;
}e[maxn<<2];
int head[maxn],ans[maxn<<1],usd[maxn],n,m,cnt,D[maxn];
char col[maxn];
void add(int fr, int to){
	static int cnt=1;
	e[++cnt]=(E){to,head[fr]}; head[fr]=cnt;
	e[++cnt]=(E){fr,head[to]}; head[to]=cnt;
}
priority_queue< pair<int,int> > q;

int main(){
	n=qr(); m=qr();
	for(int t=1;t<=n;++t)D[t]=qr();
	for(int t=1,a,b;t<=m;++t){
		a=qr(),b=qr(),add(a,b);
		if(D[a]==D[b]&&!col[a]&&!col[b]) q.emplace(D[a],a),q.emplace(D[b],b),col[a]='W',col[b]='B',ans[t]=D[a];
	}
	while(q.size()){
		int now=q.top().second; q.pop();
		for(int t=head[now];t;t=e[t].nx)
			if(!col[e[t].to]&&D[e[t].to]>=D[now])
				col[e[t].to]="WB"[col[now]=='W'],ans[t>>1]=D[e[t].to],q.emplace(D[e[t].to],e[t].to);
	}
	for(int t=1;t<=n;++t)
		if(col[t]==0)
			return puts("-1"),0;
	puts(col+1);
	for(int t=1;t<=m;++t)
		printf("%d\n",ans[t]?ans[t]:inf);
	return 0;
}


Measured memory_bytes: 7800
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
#include <atcoder/all>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

vector<ll> yakusu(ll n){
  vector<ll> ret;
  for(ll p = 1; p*p <= n; p++){
    if(n%p == 0){
      ret.push_back(p);
      if(p*p != n){
        ret.push_back(n/p);
      }
    }
  }
  sort(all(ret));
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  int n,q;cin>>n>>q;
  atcoder::dsu d(n);
  rep(i,q){
    int t,u,v;cin>>t>>u>>v;
    if(t==0){
      d.merge(u,v);
    }else{
      cout<<(d.same(u,v)?1:0)<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3928
n=int(input())
s=[input() for i in range(n)]
m=int(input())
t=[input() for i in range(m)]

b = [0]
for i in range (0,len(s)):
	a = s.count(s[i])-t.count(s[i])
	b.append(a)
print(max(b))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <climits>
#include <unordered_map>
#include <functional>
#include <queue>

#define rep(i, n) for(int i = 0, end = (int)(n); i < end; i++)

#define p2(a, b) cout << a << "\t" << b << endl
#define p3(a, b, c) cout << a << "\t" << b << "\t" << c << endl

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

inline int ctoi(char c) {
    return (int)(c -'0');
}

// ----------------------------------------------------------

bool t_water[33];
bool t_sugar[3010];

int main() {
    ll a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    // make water table
    rep(i,32) {
        rep(j,32) {
            ll water = i*a + j*b;
            if (water < (f / 100)) {
                t_water[water] = true;
            }
        }
    }
    // make sugar table
    rep(i, 3009) {
        rep(j, 3009) {
            ll sugar = i*c + j*d;
            if (sugar < f) {
                t_sugar[sugar] = true;
            }
        }
    }

    // calc all node
    const double m_node = 100.0*e / (100.0 + e);
    double max_node = 0.0;
    ll p_i = 0;
    ll p_j = 0;
    ll count = 0;
    rep(i, 32) {
        rep(j, 3009) {
            if (t_water[i] && t_sugar[j]) {
                ++count;
                if (i == 0) {
                    continue;
                }
                if (f < 100*i + j) {
                    continue;
                }
                const double node = 100.0*j / (100.0*i + j);
                if (m_node < node) {
                    continue;
                }
                if (max_node == 0.0) {
                    p_i = i;
                    p_j = j;
                }
                if (max_node < node) {
                    max_node = node;
                    p_i = i;
                    p_j = j;
                }
            }
        }
    }
    cout << 100*p_i + p_j<< " " <<  p_j << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cassert>
#define MAX 6000
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
struct P
{
  int to,d;
  P(int to=-1,int d=-1):to(to),d(d){}
};
 
struct Pox
{
  int cur,cost,tank;
  Pox(int cur = -1,int cost = -1,int tank = -1):cur(cur),cost(cost),tank(tank){}
  bool operator < (const Pox& a)const
  {
    if(cost != a.cost)return cost > a.cost;
    if(tank != a.tank)return tank > a.tank;
    return cur < a.cur;
  }
};
 
typedef vector<P> VP;
typedef vector<VP> VVP;
 
bool LPG[MAX];
int mincost[MAX][2001];
int N,M,cap;
VP G[MAX];
map<string,int> index;
int idx;
 
void add_edge(string s,string t,int d)
{
  if(index.find(s) == index.end())index[s] = idx++;
  if(index.find(t) == index.end())index[t] = idx++;
  int sindex = index[s];
  int tindex = index[t];
  G[sindex].push_back(P(tindex,d));
  G[tindex].push_back(P(sindex,d));
}
 
int main()
{
  while(cin >> N >> M >> cap,N|M|cap)
    {
      string ssrc,sdest;
      int src,dest;

      idx = 0;
      index.clear();
      rep(i,MAX)G[i].clear();
      cin >> ssrc >> sdest;
      index[ssrc] = idx++;
      index[sdest] = idx++;
      src = 0,dest = 1;
 
      rep(i,N)
	{
	  string c1,c2;
	  int d;
	  cin >> c1 >> c2 >> d;
	  add_edge(c1,c2,d);
	}
 
      assert(idx <= MAX);

      rep(i,idx) 
	{
	  LPG[i] = false;
	  rep(j,2001)mincost[i][j] = (1<<29);
	}    
 
      rep(i,M)
	{
	  string s;
	  cin >> s;
	  LPG[index[s]] = true;
	}
     
      int ans = (1<<29);
      priority_queue<Pox> que;
      que.push(Pox(src,0,cap*10));
      mincost[src][cap*10] = 0;
 
      while(!que.empty())
	{
	  Pox pox = que.top(); que.pop();
       
	  if(ans <= pox.cost)continue;
       
	  if(pox.cur == dest)
	    {
	      ans = min(ans,pox.cost);
	      break;
	    }
 
	  for(int i=0;i<G[pox.cur].size();i++)
	    {
	      P p = G[pox.cur][i];
	      int fuelConsumption = pox.tank - p.d; 
	      int next = p.to;
	      if(p.d > pox.tank)continue;
	      if(p.d == pox.tank && !LPG[next] && next != dest)continue;
 
	      if(mincost[next][fuelConsumption] > pox.cost + p.d)
		{
		  mincost[next][fuelConsumption] = pox.cost + p.d;
		  if(LPG[next])
		    {        
		      que.push(Pox(next,mincost[next][fuelConsumption],cap*10));
		      for(int j=cap*10;j>=0;j--)mincost[next][j] = min(mincost[next][j],mincost[next][cap*10]);
		    }
		  else
		    {
		      que.push(Pox(next,mincost[next][fuelConsumption],fuelConsumption));
		      for(int j=fuelConsumption;j>=0;j--)mincost[next][j] = min(mincost[next][j],mincost[next][fuelConsumption]);
		    }
		}
	    }
	}
      ans == (1<<29)?cout << -1 << endl:cout << ans << endl;
    }
  return 0;
}

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

#define rep(i,n) for(signed i=0;i<n;++i)
#define int long long
#define str string
#define debg(a) cout<<#a<<":"<<a<<endl;
#define vint vector<signed>
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define yn(a) cout<<((a)?"Yes":"No")<<endl;
#define YN(a) cout<<((a)?"YES":"NO")<<endl;

signed main(){
  int a,b;
  cin>>a>>b;
  if(b%a==0)cout<<(a+b);
  else cout<<(b-a);
  
  
  return 0;
}

Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

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

    ll devided = N / (A + B);
    ll left = N % (A + B);

    ll ans = 0;
    ans += devided * A;

    if (A > left) {
        ans += left;
    } else {
        ans += A;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3656
N, A, B = map(int, input().split())
S = input()

pass_count = 0
overseas_count = 1
for c in S:
    if c == 'a':
        if pass_count < A + B:
            print('Yes')
            pass_count += 1
        else:
            print('No')
    elif c == 'b':
        if pass_count < A + B and overseas_count <= B:
            print('Yes')
            pass_count += 1
            overseas_count += 1
        else:
            print('No')
    elif c == 'c':
        print('No') 

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

int main(){
    int l, r, d;
    cin >> l >> r >> d;
    int cnt = 0;
    for(int i=l; i<=r; i++){
        if(i%d == 0) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3632
/*author - Ashutosh Chitranshi*/
#include<bits/stdc++.h>
using namespace std;
#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define pow2(x) ((x)*(x))
#define ll long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define mod 1000000007
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define mp make_pair
#define ff first
#define ss second
#define null NULL
#define all(c) (c).begin(),(c).end()
#define nl "\n"
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vi > vvi;
typedef vector< vl > vvl;
typedef pair< int,int > ii;
typedef pair< ll,ll> pll;
typedef map< ll,ll> mll;
typedef map< int,int> mii;
#define MAX 1000000000000000001ll
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll product = 1ll;
    ll n;
    cin >> n;
    ll ar[n];
    for(int i=0;i<n;i++)
    {
    	cin >> ar[i];
    }
    sort(ar,ar+n);
    if(ar[0] == 0ll)
    	cout << 0ll << "\n";
    else
    {
    	for(int i=0;i<n;i++)
    	{
    		ll temp = (product*ar[i])%MAX;
    		if(ar[i] != temp/product)
    		{
    			cout << -1 << "\n";
    			exit(0);
    		}
    		product = temp;
    	}
    	cout << product << "\n";
    }
    return 0;
}


Measured memory_bytes: 4408
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>
#include <numeric>
#include <stdio.h>
#include<cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
 int main() {
   int n, k;
   cin >> n >> k;
   ll a[n];
   for (int i=0;i<n;i++) {
     cin >> a[i];
   }
   const ll INF = 1e18;
   ll res = INF;
   for(int bit=0; bit<(1<<n);bit++) {
     ll cost =0;
     ll mh = 0;
     int count = 0;
     for(int i=0; i<n;i++) {
       if((bit >> i) &1) {
         cost += max(0LL, mh-a[i] +1);
         mh = max(mh+1, a[i]);
         count++;
       } else if (mh < a[i]) {
         mh = a[i];
         count++;
       }
     }
     if(count >= k) res = min(res, cost);
   }
   cout << res << endl;
   return 0;
 }

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int dice[7], i, memo=6;
    char order[100];
    
    for(i=1; i<=6; i++){
        scanf("%d", &dice[i]);
    }
    scanf("%s", order);
    
    for(i=0; order[i]!='\0'; i++){
        dice[0]=dice[1];
        switch(order[i]){
            case 'E' :  dice[1]=dice[4];
                        dice[4]=dice[6];
                        dice[6]=dice[3];
                        dice[3]=dice[0];
                        break;
            case 'N' :  dice[1]=dice[2];
                        dice[2]=dice[6];
                        dice[6]=dice[5];
                        dice[5]=dice[0];
                        break;;
            case 'S' :  dice[1]=dice[5];
                        dice[5]=dice[6];
                        dice[6]=dice[2];
                        dice[2]=dice[0];
                        break;
            case 'W' :  dice[1]=dice[3];
                        dice[3]=dice[6];
                        dice[6]=dice[4];
                        dice[4]=dice[0];
                        break;
        }
    }
    
    printf("%d\n", dice[1]);
    
    return 0;
}


Measured memory_bytes: 2112
#include<cstdio>
using namespace std;
int n,ans;
int main(void){
	register int i,mx=-1,x,now,p;
	scanf("%d",&n);
	for(i=1;i<=n;++i){
		scanf("%d",&x);
		if(mx==-1)mx=x,p=1;
		else if(p==1){
			if(x>mx)mx=x,now=1,p=0;
			else if(x<mx)mx=x,now=0,p=0;
		}else{
			if(now==1){
				if(x>=mx)mx=x;
				else p=1,++ans,mx=x; 
			}
			else{
				if(x<=mx)mx=x;
				else p=1,++ans,mx=x;
			}
		}
	}
	printf("%d",ans+1);
	return 0;
}

Measured memory_bytes: 128
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let ans: String = read();
    if ((ans.chars().nth(2).unwrap()==ans.chars().nth(3).unwrap())&&(ans.chars().nth(4).unwrap()==ans.chars().nth(5).unwrap())){
    	println!("Yes");
    }else{
    	println!("No");
    }
    
}

Measured memory_bytes: 4352
using System;
using System.Linq;
public class Hello{
    public static void Main(){
        var input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var n = input[0];
        var a = input[1];
        var b = input[2];
        var max = 0L;
        var min = 0L;
        if(n >= 2 && a <= b){
            max = a + b * (n - 1);
            min = a * (n - 1) + b;
            Console.WriteLine(max - min + 1);
        }else if(n == 1 && a == b){
            Console.WriteLine(1);
        }else{
            Console.WriteLine(0);
        }
        
    }
}


Measured memory_bytes: 13268
import java.awt.Point;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int n = sc.nextInt();

		char[][] block = new char[h][w];
		Point[] point = new Point[n + 1];

		for (int y = 0; y < h; y++) {
			String s = sc.next();
			for (int x = 0; x < w; x++) {
				char c = s.charAt(x);
				if (c == 'S') {
					point[0] = new Point(x, y);
				} else if ('1' <= c && c <= '9') {
					point[c - '0'] = new Point(x, y);
				}
				block[y][x] = c;
			}
		}

		sc.close();

		int total = 0;
		int[][] time = new int[h][w];
		Deque<Point> q = new ArrayDeque<>();

		for (int i = 0; i < n; i++) {
			for (int y = 0; y < h; y++) {
				for (int x = 0; x < w; x++) {
					time[y][x] = 0;
				}
			}
			q.clear();
			q.offer(point[i]);
			while (!q.isEmpty()) {
				Point p = q.poll();
				if (p.equals(point[i + 1])) {
					total += time[p.y][p.x];
					break;
				}
				for (int j = 0; j < 4; j++) {
					int _x = p.x + dx[j];
					int _y = p.y + dy[j];
					if (((0 <= _y && _y < h) && (0 <= _x && _x < w)) && time[_y][_x] == 0 && block[_y][_x] != 'X') {
						time[_y][_x] = time[p.y][p.x] + 1;
						q.offer(new Point(_x, _y));
					}
				}
			}
		}

		System.out.println(total);
	}
}

Measured memory_bytes: 73240
#include <iostream>
#include <vector>
#include <string>

using namespace std;

bool has_integer_distance(const vector<vector<int>>& point, int d, int x, int y)
{
  long long square_distance = 0;
  for (int i = 0; i < d; i++) {
    square_distance += (point.at(x).at(i) - point.at(y).at(i)) * (point.at(x).at(i) - point.at(y).at(i));
  }
  long long ok = 0;
  long long ng = square_distance+1;
  while (abs(ok - ng) > 1) {
    long long mid = (ok + ng) / 2;
    if (mid * mid <= square_distance) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return ok * ok == square_distance;
}

int main()
{
  int npoints, d;
  cin >> npoints >> d;
  vector<vector<int>> point(npoints, vector<int>(d));
  for (int i = 0; i < npoints; i++) {
    for (int j = 0; j < d; j++) {
      cin >> point.at(i).at(j);
    }
  }
  int result = 0;
  for (int x = 0; x < npoints; x++) {
    for (int y = x+1; y < npoints; y++) {
      if (has_integer_distance(point, d, x, y)) {
        result++;
      }
    }
  }
  cout << result << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define li long long
#define itn int
 
using namespace std;
 
inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

template <typename T>
ostream& operator <<(ostream& ostr, const vector<T>& a) {
	ostr << "(";
	for (size_t i = 0; i < a.size(); ++i) {
		if (i) {
			ostr << ", ";
		}
		ostr << a[i];
	}
	ostr << ")";
	return ostr;
}

int main() {
	int n = nxt(), m = nxt();
	int d = nxt();
	string s = "RYGB";
	for (int i= 0; i < n; ++i) {
		for( int j = 0; j < m; ++j) {
			int x = (i + j);
			int y = (i - j) % (2 * d);
			if (y < 0) {
				y += 2 * d;
			}
			x /= d;
			y /= d;
			x %= 2;
			y %= 2;
			cout << s[x * 2 + y];
		}
		cout << "\n";
	}

	return 0;
}

Measured memory_bytes: 512
// Written By NewbieChd
#include <iostream>
#include <iomanip>
#include <cmath>
// #define double long double
using namespace std;

const int maxN = 100003;
const double eps = 1e-8;
inline double absolute(double x) { return x >= 0 ? x : -x; }
inline double square(double x) { return x * x; }

struct Vector {
    double x, y;
    Vector() {}
    Vector(double x, double y) : x(x), y(y) {}
    friend Vector operator+(const Vector& a, const Vector& b) { return Vector(a.x + b.x, a.y + b.y); }
    friend Vector operator-(const Vector& a, const Vector& b) { return Vector(a.x - b.x, a.y - b.y); }
    friend Vector operator*(const Vector& a, const double& b) { return Vector(a.x * b, a.y * b); }
    friend Vector operator/(const Vector& a, const double& b) { return Vector(a.x / b, a.y / b); }
    inline double length() { return sqrt(square(x) + square(y)); }
    inline void read() { cin >> x >> y; }
    inline void write() { cout << fixed << setprecision(10) << x << ' ' << y << '\n'; }
};
inline double distance(Vector a, Vector b) { return sqrt(square(b.x - a.x) + square(b.y - a.y)); }
inline double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
inline double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }

inline Vector project(Vector a, Vector b, Vector c) {
    b = a - b;
    return b * (dot(b, c - a) / square(b.length())) + a;
}
inline Vector reflect(Vector a, Vector b, Vector c) {
    a = project(a, b, c);
    return a * 2 - c;
}

inline bool intersect(Vector a, Vector b, Vector c, Vector d) {
    if (max(min(a.x, b.x), min(c.x, d.x)) > min(max(a.x, b.x), max(c.x, d.x)) + eps || 
        max(min(a.y, b.y), min(c.y, d.y)) > min(max(a.y, b.y), max(c.y, d.y)) + eps || 
        cross(a - c, d - c) * cross(d - c, b - c) + eps < 0 || 
        cross(c - a, b - a) * cross(b - a, d - a) + eps < 0)
        return 0;
    return 1;
}

int main() {
    ios::sync_with_stdio(false);
    int Q;
    Vector a, b, c, d;
    for (cin >> Q; Q; --Q) {
        a.read(), b.read(), c.read(), d.read();
        printf("%d\n", intersect(a, b, c, d));
    }
    return 0;
}



Measured memory_bytes: 3224
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  int ans=(1<<m)*(100*(n-m)+1900*m);
  printf("%d\n",ans);
}

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())


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

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

using namespace std;

int main(){

  int n,m;

  cin>>n;
  cin>>m;

  vector<int> a(n);
  vector<int> b(m);

  for(int i=0;i<n;++i)
	cin>>a[i];

  for(int i=0;i<m;++i)
	cin>>b[i];

  int cnt_a = 0;
  int cnt_b = 0;

  vector<int> ans;
  vector<int> and_ans;
  vector<int> or_ans;

  for(auto i:a)
	ans.push_back(i);

  for(auto i:b)
	ans.push_back(i);

  sort(ans.begin(),ans.end());  
  
  for(int i=0;i<ans.size()-1;++i){
	if(ans[i] == ans[i+1]){
	  and_ans.push_back(ans[i]);
	  or_ans.push_back(ans[i]);
	  i++;
	}
	else
	  or_ans.push_back(ans[i]);
  }

  if(ans[ans.size()-1] != ans[ans.size()-2])
	or_ans.push_back(ans[ans.size()-1]);
	
  cout<<and_ans.size()<<" "<<or_ans.size()<<endl;

  for(auto i:and_ans)
	cout<<i<<endl;

  for(auto i:or_ans)
	cout<<i<<endl;
  
}



Measured memory_bytes: 6600
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int sum = 0;

		for (int i = 0; i < n; i++) {
			sum += scanner.nextInt() - 1;
		}

		System.out.println(sum);
	}
}


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

using namespace std;

#define long long long
#define INF 2e18
#define MOD (long) (998244353)
#define umap unordered_map

int main()
{
    long t = 1;
    //cin >> t;

    while (t--) {
        long h, w, k;
        cin >> h >> w >> k;

        vector<string> s(h);
        for (auto &x : s) cin >> x;

        long ans = INF;
        for (long b = 0; b < (1 << (h-1)); b++) {
            set<long> horiz;
            long x = b;
            long i = 0;
            while (x > 0) {
                if (x & 1) horiz.insert(i);
                x >>= 1;
                i++;
            }
            horiz.insert(h-1);
            long l = -1;
            long total = horiz.size() - 1;
            vector<long> count(horiz.size());
            vector<long> last(horiz.size());
            vector<long> cur(horiz.size());
            long p = 0;
            for (long j = 0; j < w; j++) {
                long z = 0;
                for (long i = 0; i < h; i++) {
                    if (horiz.count(i-1)) z++;
                    if (s[i][j] == '1') {
                        count[z]++;
                        cur[z]++;
                        if (count[z] > k) {
                            if (j == p) goto end;
                            total++;
                            long q = 0;
                            for (long y = 0; y < h; y++) {
                                if (horiz.count(y-1)) q++;
                                count[q] -= last[q];
                                last[q] = 0;
                            }
                            p = j;
                        }
                    }
                }
                z = 0;
                for (long i = 0; i < h; i++) {
                    if (horiz.count(i-1)) z++;
                    last[z] += cur[z];
                    cur[z] = 0;
                }
            }
            ans = min(ans, total);
        end:
            ;
        }
        printf("%lld\n", ans);
    }
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;
 
int main() {
  ll h,w;
  cin >> h >> w;
  char a[h+2][w+2];
  rep(i,h+2) {
    a[i][0] = '.';
    a[i][w+1] = '.';
  }
  rep(i,w+2){
    a[0][i] = '.';
    a[h+1][i] = '.';
  }
  
  rep(i,h){
    rep(j,w){
      cin >> a[i+1][j+1];
    }
  }
  
  bool ans = true;
  rep(i,h){
    rep(j,w){
      if(a[i+1][j+1] == '#' && a[i][j+1] =='.' && a[i+2][j+1] == '.' && a[i+1][j+2] =='.' && a[i+1][j] == '.') ans = false;
    }
  }
  if(ans){
    cout << "Yes";
  } else {
    cout << "No";
  }
  
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;


int main(){
  int x,n;
  cin >> x >>n;
  priority_queue<int,vector<int>,greater<int>> p;
  for(int i=0;i<102;i++)p.push(i);
  int a[n+1];
  rep(i,n){cin >> a[i];}
  a[n]=1000;
  sort(a,a+n);

  int ans=1000,sa=10000;
  int rrr=0;
  while(!p.empty()){
    int q=p.top();
    p.pop();
    if(a[rrr]==q){rrr++;continue;}
    if(abs(x-q)<sa){ans=q,sa=abs(x-q);}
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

def main():
	a,b=MI()

	G=[]

	for _ in range(25):
		G+=[list("...#")*25,list(".#.#")*25,list("...#")*25,list("####")*25]

	#print(G)



	for i in range(25):
		for j in range(24):
			if a<25**2:
				G[4*i][4*j+3]="."
				a+=1
			else:
				break


	for i in range(25):
		if a<25**2:
			G[4*i+3][0]="."
			a+=1
		else:
			break

	for i in range(25):
		for j in range(25):
			if b<25**2+1:
				G[4*i+1][4*j+1]="."
				b+=1

	print(100,100)







	for i in G:
		print(*i,sep="")















if __name__ == "__main__":
	main()


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

using namespace std;
#define MAX 300010
#define MOD 998244353

#define lli unsigned long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define VIN(VECTOR,n)\
REP(CNT,n){\
	lli TMP;\
	cin>>TMP;\
	VECTOR.push_back(TMP);\
}

lli kaijo[MAX];
lli finv[MAX];
lli inv[MAX];

void calcKaijo(){

	REP(i,MAX){
		if(i==0 || i==1){
			kaijo[i]=1;
			finv[i]=1;
			inv[i]=1;
		}

		else {
			kaijo[i] = kaijo[i-1]*i;
			kaijo[i] %= MOD;
			inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
			finv[i] = finv[i-1]*inv[i] % MOD;
		}
	}
}

lli nCr(lli n,lli r){
	if(n<r)return 0;
	if(n<0 || r<0)return 0;
	return kaijo[n]*(finv[r]*finv[n-r]%MOD)%MOD;
}

int main(){

	lli d,n;
	cin>>d>>n;
	lli tmp=1;
	REP(i,d)tmp*=100;
	lli num=tmp*100;
	lli ans=0;
	for(int i=1;i<=n;i++){
		ans+=tmp;
		if((ans%num) == 0){
			ans+=tmp;
		}
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	long long int a[100][100], b[100][100], c[100][100], i, j, k, n, m, l;
	cin >> n >> m >> l;
	for (i = 0; i < n; i++) {
		for (j = 0; j < l; j++) {
			c[i][j] = 0;
		}
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	for (i = 0; i < m; i++) {
		for (j = 0; j < l; j++) {
			cin >> b[i][j];
		}
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < l; j++) {
			for (k = 0; k < m; k++) {
				c[i][j] += a[i][k] * b[k][j];
			}
		}
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < l; j++) {
			cout << c[i][j];
			if (j == l - 1)
				cout << endl;
			else
				cout << " ";

		}
	}
	return 0;
}

Measured memory_bytes: 1388
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in [0]*n]
cd = [list(map(int, input().split())) for _ in [0]*m]
for a, b in ab:
    t = 1001001001
    ti = 0
    for i, (c, d) in enumerate(cd):
        e = abs(a-c)+abs(b-d)
        if t > e:
            t = e
            ti = i+1
    print(ti)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
string check(string s)
{
	if( s[0] != 'A' )
		return "WA";
	int sum = 0;
	bool ch = false;
	for(int i = 0; i < s.size(); i++)
	{
		if( s[i] >= 'a' and s[i] <= 'z' )
			sum++;
		if( i > 1 and i < s.size()-1 and s[i] == 'C' )
			ch = true;
	}
	if( ch == false )
		return "WA";
	if( sum != s.size()-2 )
		return "WA";
	return "AC";
}
int main()
{
	string s;
	cin >> s;
	cout << check(s);
}

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

#define int long long
#define ll long long
#define f1(i,a,b) for(i=a;i<b;i++)
#define f2(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
int i,j;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/in.txt","r",stdin);
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/out.txt","w",stdout);
    // #endif
    string s,t;
    cin>>s>>t;
    int n=s.length(), m=t.length();
    vector<vector<tuple<int,int,int>>> dp(n+1,vector<tuple<int,int,int>>(m+1));
    f1(i,0,n+1)
    {
    	f1(j,0,m+1)
    	{
    		dp[i][j]=make_tuple(0ll,0ll,0ll);
    	}
    }
    f1(i,1,n+1)
    {
    	f1(j,1,m+1)
    	{
    		if(s[i-1]==t[j-1])
    		{
    			dp[i][j]=make_tuple(get<0>(dp[i-1][j-1])+1,i-1,j-1);

    		}
    		else if(get<0>(dp[i][j-1]) > get<0>(dp[i-1][j]))
    			dp[i][j]=make_tuple(get<0>(dp[i][j-1]),i,j-1);
    		else
    			dp[i][j]=make_tuple(get<0>(dp[i-1][j]),i-1,j);
    	}
    }
    int ans=get<0>(dp[n][m]);
    int x=n,y=m;
    string final;
    ///cout<<ans<<endl;
    //ans=99;

    // f1(i,0,n+1)
    // {
    // 	f1(j,0,m+1)
    // 	cout<<get<0>(dp[i][j])<<gp<<get<1>(dp[i][j])<<gp<<get<2>(dp[i][j])<<gp<<gp<<gp;
    // 	cout<<endl;
    // }
    while(1)
    {
    	//cout<<x<<gp<<y<<endl;
    	if(get<1>(dp[x][y])<x&&get<2>(dp[x][y])<y)
    	{
    		final.pb(s[x-1]);
    		x--;
    		y--;
    		ans--;
    	}
    	else
    	{
    		//cout<<gp<<get<1>(dp[x][y])<<gp<<get<2>(dp[x][y])<<endl;
    		temp=get<1>(dp[x][y]);
    		y=get<2>(dp[x][y]);
    		x=temp;
    		//cout<<gp<<get<1>(dp[x][y])<<gp<<get<2>(dp[x][y])<<endl;
    	}
    	if(x==0||y==0)
    		break;
    }
    reverse(final.begin(),final.end());
    cout<<final;
    return 0;
}

Measured memory_bytes: 211456
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

ll MOD = 1e9 + 7;

int main(){
    string s;
    cin >> s;
    int N = s.size();

    ll dp[N + 1][2];
    fill(dp[0], dp[N + 1], 0);
    dp[0][1] = 1;
    for(int i = 0; i < N; i++){
        int n = s[i] - '0';
        if(n == 0){
            dp[i + 1][0] += dp[i][0] * 3;
            dp[i + 1][0] %= MOD;
            dp[i + 1][1] += dp[i][1];
            dp[i + 1][1] %= MOD;
        } else {
            dp[i + 1][0] += dp[i][0] * 3 + dp[i][1];
            dp[i + 1][0] %= MOD;
            dp[i + 1][1] += dp[i][1] * 2;
            dp[i + 1][1] %= MOD;
        }
    }

    /*for(int i = 0; i <= N; i++){
        cout << dp[i][0] << " " << dp[i][1] << endl;
    }
    cout << endl;*/

    cout << (dp[N][0] + dp[N][1]) % MOD << endl;
    return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;
int main(){
    int N;
    cin >> N;
    vector<int> W(N);
    REP(i,N) cin >> W[i];
    int ans = 100100;
    REP(i,N){
        int S1, S2;
        S1 = S2 = 0;
        REP(j,i) S1 += W[j];
        for(int k = i; k < N; ++k) S2 += W[k];
        ans = min(ans, abs(S2 - S1));
    }
    cout << ans << endl;
}

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

int main()
{


string s;
cin >> s;  
   
if (s[0]=='A'&& s[1]=='A'&& s[2]=='A') {
 cout << "No" << endl; 
}
    
else if (s[0]=='B'&& s[1]=='B'&& s[2]=='B')  { 
 cout << "No" << endl;
    
} else {
    
 cout << "Yes" << 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,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
	ll k,a,b;
	cin >> k >> a >> b;
	if(a  + 2 >= b){
		cout << k + 1 << endl;
		return 0;
	} else if (k <= a - 1){
		cout << k + 1 << endl;
	}
	ll ans = a;
	ans += (b-a) * ((k-a+1) / (2)) + (k-a+1) % 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define per(i, n, s) for (int i = (n-1); i >= (int)(s); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;

int main(){
    int n; cin>>n;
    vector<string> a(n);
    vector<map<char,int>> mp(n);
    rep(i,0,n) cin>>a[i];

    rep(i,0,n){
        rep(j,0,a[i].size()){
            mp[i][a[i][j]]++;
        }
    }
    
    string ans="";
    rep(i,0,26){
        int mini=INF;
        rep(j,0,n){
            mini=min(mini,mp[j][(char)(i+'a')]);
        }
        // debug(mini);
        rep(k,0,mini){
            ans.push_back((char)(i+'a'));
        }
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3656
// C - Marks
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)

int main(){
	int N,K; cin>>N>>K;
	vector<int> A(N);
	rp(i, 0, N) cin>>A[i];
	rp(i, K, N) puts(A[i-K] < A[i]? "Yes":"No");
}


Measured memory_bytes: 4056
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    if (B - A <= 0) {
      System.out.println("delicious");
    } else if (X + A - B >= 0) {
      System.out.println("safe");
    } else {
      System.out.println("dangerous");
    } 
  }
}

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

using namespace std;

#define ll long long 
#define IOS ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define SIZE 100005

vector<int>v[100005];
bool vis[100005];
int dp[100005];

int func(int node)
{
	vis[node] = 1;
	int len = v[node].size();
	int ans = 0;
	
	for(int i = 0;i <len ;i++)
	{
		int child = v[node][i];
		if(!vis[child])
		{
			int curr = 1 + func(child);
			ans = max(ans,curr);
		}
		else
		{
			ans = max(ans,1+dp[child]);
		}
	}
	return dp[node] = ans;
}

int main()
{
	int n,m;
	
	scanf("%d %d", &n, &m);
	for(int i =1 ;i <= m; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		v[a].push_back(b);
	}
	int mx = 0;
	for(int i =1 ; i <= n; i++)
	{
		if(!vis[i])
		{
			int ans = func(i);
			mx = max(mx,ans);
		}
	}
	printf("%d\n",mx);
	return 0;
}


Measured memory_bytes: 8192
N = int(input())
d_list = list(map(int, input().split()))
d_list.sort()

k = d_list[int(N/2)]
count = 0
for i in range(N):
    if count == int(N/2):
        print(d_list[int(N/2)] - d_list[int(N/2)-1])
        break
    elif k > d_list[i]:
        count += 1
    else:
        pass
else: # kの候補の右端は必ずd_listの中
    print(0)


Measured memory_bytes: 14396
# Problem - バブルソート

def bubbleSort(A, N):
    sort_count = 0
    flag = 1
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j]<A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                sort_count += 1
                flag = 1
    return A, sort_count

# input
N = int(input())
a_list = list(map(int, input().split()))

# output
ans_list, ans_count = bubbleSort(a_list, N)
print(" ".join(list(map(str, ans_list))))
print(ans_count)



Measured memory_bytes: 5604
#include <stdio.h>
int main(void){
  int n,s,i,j,f;
  struct data{
    int c,m;
  }d[25],t;
  while(1){
    scanf("%d",&n);
    if(!n)
      break;
    for(i=0;i<n;i++)
      scanf("%d %d",&d[i].c,&d[i].m);
    for(i=0;i<n-1;i++){
      for(j=n-1;j>i;j--){
	if(d[j-1].m>d[j].m){
	  t=d[j-1];
	  d[j-1]=d[j];
	  d[j]=t;
	}
      }
    }
    s=0;
    f=1;
    for(i=0;i<n;i++){
      s+=d[i].c;
      if(s>d[i].m){
	f=0;
	break;
      }
    }
    if(f)
      puts("Yes");
    else
      puts("No");
  }
  return 0;
}

Measured memory_bytes: 584
from functools import lru_cache
import sys
sys.setrecursionlimit(10**7)

T = int(input())
INF = 10**18

for _ in range(T):
    N, A, B, C, D = map(int, input().split())

    @lru_cache(maxsize=None)
    def search(now):
        if now == 0:
            return 0

        ret = INF
        for div, cost in zip((2, 3, 5), (A, B, C)):
            q, r = divmod(now, div)
            ret = min(
                ret,
                search(q) + cost + r * D,
                search(q + 1) + cost + (div - r) * D if q + 1 < now else INF,
                now * D
            )
        return ret

    print(search(N))


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

int main(){
    string S;
    cin >> S;
    int res = 700;

    if(S[0] == 'o')res += 100;
    if(S[1] == 'o')res += 100;
    if(S[2] == 'o')res += 100;

    cout << res << endl;
}

Measured memory_bytes: 256