akhauriyash/Code-Regression huggingface dataset:
//srinivas
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
// using namespace __gnu_pbds;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define fr(x,in,n,r) for(x=in;x<n;x+=r)
#define ifr(x,n) for(x=0;x<n;x++)
#define dfr(x,n) for(x=n-1;x>=0;x--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pof(a) pop_front(a)
#define pob(a) pop_back(a)
#define eb(a) emplace_back(a)
#define ef(a) emplace_front(a)
typedef long long ll;
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007

bool fun(pll a,pll b){
	return a.ss>b.ss;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt","r",stdin);
    ll i,n,m,l,r;
	cin>>n>>m;
	ll a[n];
	ll sum=0;
	ifr(i,n) cin>>a[i],sum+=a[i];
	sort(a,a+n);
	ll x,s1=0,ans=sum,s2=0;
	pll b[m];
	ifr(i,m){
		cin>>b[i].ff>>b[i].ss;
	}
	sort(b,b+m,fun);
	ll j=0;
	ifr(i,n){
		if(j<m){
			s1+=b[j].ss;
			b[j].ff--;
			if(b[j].ff==0)
				j++;
		}
		s2+=a[i];
		ans=max(ans,sum-s2+s1);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
from collections import defaultdict
from bisect import bisect_right

s = input()
t = input()

indices = defaultdict(list)
for i, v in enumerate(s):
    indices[v].append(i)

cnt = 0
cur = -1
mod = len(s)
flag = False
for v in t:
    if v not in indices:
        flag = True
        break

    i = bisect_right(indices[v], cur)
    if i == len(indices[v]):
        j = indices[v][0]
    else:
        j = indices[v][i]

    if cur >= j:
        cnt += 1
    cur = j

if flag:
    print(-1)
else:
    print(cnt * mod + cur + 1)


Measured memory_bytes: 80144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1000000007;
const double PI = 3.14159265359;
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define INF 1000000000000
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define count_1(n)  __builtin_popcountll(n)
#define parity(n)   __builtin_parityll(n)   //Even parity 0 as output
void show    (int a[], int arraysize) { for (int i = 0; i < arraysize; ++i)  {cout << a[i] << " ";}	cout<<endl;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
void sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
int main()
{FAST
int n,x=0,k;
cin>>n;
int a[n];
FOR(i,n)
{
	cin>>a[i];

		 x=x^a[i];
	
	
}
FOR(i,n)
{k=a[i];
	cout<<(k^x)<<" ";

}
return  0;
}






Measured memory_bytes: 4364
import java.util.*;
	public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			char[] Sa = sc.next().toCharArray();
			char[] Sb = sc.next().toCharArray();
			char[] Sc = sc.next().toCharArray();			
			int a = Sa.length;
			int b = Sb.length;
			int c = Sc.length;
			char card = 'a';			
			while(true) {
				if(card=='a') {
					if(a==0) {
						System.out.println("A");
						return;
					}
					card = Sa[Sa.length-a];
					a--;
				}
				if(card=='b') {
					if(b==0) {
						System.out.println("B");
						return;
					}	
					card = Sb[Sb.length-b];
					b--;
				}	
				if(card=='c') {
					if(c==0) {
						System.out.println("C");
						return;
					}
					card = Sc[Sc.length-c];
					c--;
				}
			}		
		}
	}

Measured memory_bytes: 35476
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

/* 最大公約数 (ユークリッドの互除法) */
long long gcd(long long m, long long n) {
	long long temp;
	if (n > m) swap(m , n);
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

int main() {
	ll		b,c,d,w,h,i,j,k,l,m,n,x,y,z;
	ll		ans = 0;
	string	s;
	cin >> n;
	vector<ll>	a(n);
	for(i=0;i<n;i++) cin >> a[i];
	//vector<ll>	dp(n+1,INFL);
	//vector<vector<ll>>	dp2(x , vector<ll>(y,INFL));
	ans = gcd(a[0],a[1]);
	for(i=2;i<n;i++) {
		ans = gcd(ans,a[i]);
	}

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


Measured memory_bytes: 4044
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second

using namespace std;
int main()
{
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   
   
   long long int n;
   cin>>n;
  
   unordered_map<long long int ,long long int>mp;
   
   long long int m=n;
   
    while (n % 2 == 0)  
    {  
        //cout << 2 << " ";  
        mp[2]++;
        n = n/2;  
    }  
  

    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
       while (n % i == 0)  
        {  
           mp[i]++;
            n = n/i;  
        }  
    }  
  
  
    if (n > 2 && m==n)  
    {
        cout<<1<<endl;
        return 0;
    }
    else if(n>2)
    {
        mp[n]++;
    }
   
    long long int ans=0;
    
    for(auto x : mp)
    {
        if(x.second<=2)
        {
            ans++;
            
        //   cout<<"ans = "<<ans<<endl;
        }
        else
        {
            long long int p = x.second-1 , i=1,cnt=1;
            
            // cout<<x.first<<"p= "<<p<<endl;
            while(i<p)
            {
                i++;
                p-=i;
                
                if(p>=0)
                cnt++;
            }
        //   cout<<"SFans = "<<ans<<endl;
           ans+= cnt;
        }
    }
    
    cout<<ans<<endl;
   
   return 0;
}


Measured memory_bytes: 3688
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
#define pii pair<int,int>
typedef long long ll;
typedef unsigned long long ull;
 
void IO(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("test.txt","r",stdin);
    #endif
}
 
const int N=2e6+3,M=2e3+5,mod=1e9+7,dx[]={1,-1,0,0},
                                    dy[]={0,0,1,-1};
const double eps=1e-9;

int tc, n, a[N], p[N], dp[N], ans;

int solve(int sum = 0){
    if (sum == n)
        return 1;
    int& r = dp[sum];
    if (~r)
        return r;
    r = 0;
    for(int i = 3 ; sum + i <= n ; i++)
        r = (r + solve(sum + i)) % mod;
    return r;
}

int main(){
    memset(dp, -1, sizeof dp);
    scanf("%d",&n);
    printf("%d\n", solve());
}


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

long long gcd(long long x, long long y)
{
    if (y == 0)
        return x;
    return gcd(y, x % y);
}

long long lcm(long long x, long long y)
{
    if (x == 0 || y == 0)
        return 0;
    return x / gcd(x, y) * y;
}

const int p[] = {-1, 1, 1};
int N;

int main()
{
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }

    long cnt = pow(3, N);
    int even = 0;
    for (int i = 0; i < N; i++)
    {
        if (A[i] % 2 == 0)
            even++;
    }
    cnt -= pow(2, even);

    cout << cnt << endl;
}

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

int main() {
  string A, B;
  cin >> A >> B;
  int k = 2;//判定用 k = 1でA > B, k = 2でA = B, k = 3でA < B
  
  //桁数で判定
  if(A.size() > B.size()){
    k = 1;
    goto RESULT;
  }else if(A.size() < B.size()){
    k = 3;
    goto RESULT;
  }
  
  //桁数が同じ時の判定
  for(int i = 0; i < A.size(); i++){
    if(A.at(i) > B.at(i)){
      k = 1;
      goto RESULT;
    }else if(A.at(i) < B.at(i)){
      k = 3;
      goto RESULT;
    }
  }
  
  //結果出力
  RESULT:
  if(k == 1){
    cout << "GREATER" <<endl;
  }else if(k == 2){
    cout << "EQUAL" <<endl;
  }else{
    cout << "LESS" <<endl;
  }
}
  
  

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

using namespace std;

bool DEBUG = false;

long long int gcd(long long int a, long long int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
 
 long long int lcm(long long int a, long long int b)  
 {  
    return (a*b)/gcd(a, b);  
 }

int main(){
    long long int a, b, c, d;
    cin >>a >>b >>c >>d;
    //for(long long int i=a; i<=b; i++){
    //    if(i%c > 0 && i%d > 0){
    //        cnt++;
    //    }
    //}
    long long int n = b-a+1;
    long long int lcmOfCD = lcm(c,d);
    long long int multiplesInRange = b/c - (a-1)/c + b/d - (a-1)/d;
    long long int repeatedMultiplesInRange = b/lcmOfCD - (a-1)/lcmOfCD;
    if(DEBUG){
        cout <<"lcm of c and d is " <<lcmOfCD <<endl;
        cout <<n <<" numbers in range" <<endl;
        cout <<b/c <<" multiples of " <<c <<" up to " <<b <<endl;
        cout <<(a-1)/c <<" multiples of " <<c <<" up to exc " <<a <<endl;
        cout <<b/c - (a-1)/c <<" multiples of " <<c <<" in range " <<endl <<endl;
        
        cout <<b/d <<" multiples of " <<d <<" up to " <<b <<endl;
        cout <<(a-1)/d <<" multiples of " <<d <<" up to exc " <<a <<endl;
        cout <<b/d - (a-1)/d <<" multiples of " <<d <<" in range " <<endl <<endl;
        
        cout <<multiplesInRange <<" multiples in range" <<endl <<endl;
        
        cout <<b/lcmOfCD <<" common multiples up to " <<b <<endl;
        cout <<(a-1)/lcmOfCD <<" common multiples up to exc " <<a <<endl;
        cout <<repeatedMultiplesInRange <<" repeated multiples in range" <<endl <<endl;
        
        cout <<"guess inc commons = " <<n - multiplesInRange  <<endl;
        cout <<"guess exc commons = " <<n - multiplesInRange + repeatedMultiplesInRange <<endl;
    }
    cout <<n - multiplesInRange + repeatedMultiplesInRange <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll ksm(int a,int b)
{
	ll ans =1;
	while(b)
	{
		if(b&1) ans=ans*a%mod;
		b/=2;
		a=a*a%mod;
	}
	return ans%mod;
}
int main()
{
	int n,k,s[5000];
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&s[i]);
	}
	ll h[5000],sum[5000];
	memset(h,0,sizeof h);
	memset(sum,0,sizeof sum);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<i;j++)
			if(s[i]>s[j])
				sum[i]++;
		for(int j=i+1;j<n;j++)
			if(s[i]>s[j])
				h[i]++;
		sum[i]+=h[i];
//		cout<<sum[i]<<' '<<h[i]<<endl;
	}
	ll ans=0;
	ll res=((ll)k*(k-1)/2)%mod;
	//cout<<res<<endl;
	for(int i=0;i<n;i++)
	{
	//	ans=((ans+(sum[i]*((k-1)*k/2%mod)%mod)%mod)%mod+h[i]*k)%mod;
		ans=(ans+(ll)h[i]*(k)%mod)%mod;
		ans=(ans+(res*sum[i]%mod)%mod)%mod;
	}
	cout<<ans%mod;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}
int32_t main()
{
	int k;
	cin >> k;
	int a,b;
	cin >> a >> b;
	int ff=0;
	for(int i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			ff=1;
			break;
		}
	}
	if(ff)
	cout << "OK";
	else
	cout << "NG";
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int a[]= {-1, 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};
	int x, y;
	cin >> x >> y;
	cout << (a[x] == a[y] ? "Yes" : "No") << endl;
	return 0;
}


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


int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n)
    cin >> a[i];
  int axor = 0;
  rep(i, n)
    axor ^= a[i];
  rep(i, n)
    printf("%d%c", axor ^ a[i], i < n - 1 ? ' ' : '\n');
  return 0;
}

Measured memory_bytes: 3952
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {

  int n;
  cin >> n;
  map<string, bool> mp;
  vector<string> t(n);
  bool f = true;
  string last = "";
  for(int i=0; i<n; i++){
    string s;
    cin >> s;
    t[i] = s;
    if(mp.find(s) == mp.end()){
      mp[s] = true;
      if(i != 0 && t[i-1][t[i-1].size()-1] != s[0]){
        f = false;
      }
    }else{
      f = false;
    }
  }
  cout << (f ? "Yes" : "No") << endl;

  return 0;
}



//


Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    auto dp = new long[][](100 + 1, (10 ^^ 5) + 1);
    long N, W;
    scan(N, W);
    auto w = new long[](100 + 1);
    auto v = new long[](100 + 1);
    foreach (i; 0 .. N)
        scan(w[i], v[i]);

    foreach (n; 0 .. N)
        foreach (m; 0 .. W + 1)
        {
            dp[n + 1][m].maxAssign(dp[n][m]);
            if (m + w[n] <= W)
            {
                dp[n + 1][m + w[n]].maxAssign(dp[n][m] + v[n]);
            }
        }
    dp[N][W].writeln();
}


Measured memory_bytes: 82172
data = [[]]*3
for i in range(0,3): data[i] = list(input())

turn = 0 #012 abc
abc = list("abc")
while len(data[turn])>0:
    s = data[turn].pop(0)
    turn = abc.index(s)

ABC = list("ABC")
print(ABC[abc.index(s)])

Measured memory_bytes: 3060
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]

# nCrの剰余
def combinations_mod(n, r, mod=1000000007):
    """Returns nCr in mod."""
    r = min(r, n - r)
    combs = 1
    for i, j in zip(range(n - r + 1, n + 1), range(1, r + 1)):
        combs *= (i % mod) * pow(j, mod - 2, mod)
        combs %= mod
    return combs


def main():
    N, K = NMI()
    A = NLI()
    A.sort()
    ans = 0
    fac = [1]*(N+1)
    inv = [1]*(N+1)

    for i in range(1, N+1):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = inv[i-1] * pow(i, -1, MOD) % MOD

    for i in range(N):
        max_num = 0
        min_num = 0
        if i >= K-1:
            max_num = fac[i] * inv[K-1] * inv[i-K+1]
        if N-1-i >= K-1:
            min_num = fac[N-1-i] * inv[K-1] * inv[N-K-i]
        ans += (max_num - min_num) * A[i] % MOD
    print(ans%MOD)


if __name__ == "__main__":
    main()

Measured memory_bytes: 21380
#include<stdio.h>
#include<algorithm>

using namespace std;

int main(){
	int n,a,b,c;
	int m=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a[3];
		for(int j=0;j<3;j++)scanf("%d",&a[j]);
		std::sort(a,a+3);
		
		int d = 10;
		if(a[0]>d || a[1]>d || a[2]>d)puts("hogehogehoge");
		
		if(a[0]*a[0]+a[1]*a[1] == a[2]*a[2]){
			puts("YES");
		}else{
			puts("NO");
		}
	}
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n, m;
    vector<pair<ll, ll>> v;

    cin >> n >> m;

    for (int i = 0; i < n; i++)
    {
        long long tmp, tmp2;
        cin >> tmp >> tmp2;
        v.push_back(make_pair(tmp, tmp2));
    }

    int cnt = 0;
    long long min = 0;

    // cout << "MM" << endl;
    sort(v.begin(), v.end());
    /*
    for (auto itr = v.begin(); itr != v.end(); itr++)
    {
        cout << "<" << itr->first << "," << itr->second << ">" << endl;
    }
*/

    for (auto itr = v.begin(); itr != v.end(); itr++)
    {
        if (cnt + (itr->second) >= m)
        {
            min += ((m - cnt) * itr->first);
            break;
        }
        else
        {
            cnt += itr->second;
            min += (itr->first) * (itr->second);
        }
    }

    cout << min << endl;
    // cout << INF << "," << MOD << endl;
}


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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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 P = pair<int,int>;
//Write From this Line

// now += mint(2).pow(s) - 1; こんな感じで、2のs乗を求められrう
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int main()
{
	string s;
	cin >> s;

	int m = 13;
	vector<mint> dp(m);
	dp[0] = 1;
	for(char c : s){
		vector<mint> p(m);
		swap(dp,p);
		rep(i,10) {
			if (c == '0' + i || c == '?'){
				rep(j,m){
					dp[(j*10+i)%m] += p[j];
				}
			}
		}
	}
	cout << dp[5] << endl;

}


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

int main() {
    char ch[5];
    int a, b, c, d;
    cin >> ch;

    int num = atoi(ch);
    a = num / 1e3;
    b = (num - a * 1e3) / 1e2;
    c = (num - a * 1e3 - b * 1e2) / 1e1;
    d = (num - a * 1e3 - b * 1e2 - c * 1e1 );

    if(a + b + c + d == 7) {
        cout << a << '+' << b << '+' << c << '+' << d << "=7" << endl;
        return 0;
    }
    if(a - b + c + d == 7) {
        cout << a << '-' << b << '+' << c << '+' << d << "=7" << endl;
        return 0;
    }
    if(a + b - c + d == 7) {
        cout << a << '+' << b << '-' << c << '+' << d << "=7" << endl;
        return 0;
    }
    if(a + b + c - d == 7) {
        cout << a << '+' << b << '+' << c << '-' << d << "=7" << endl;
        return 0;
    }
    if(a - b - c + d == 7) {
        cout << a << '-' << b << '-' << c << '+' << d << "=7" << endl;
        return 0;
    }
    if(a + b - c - d == 7) {
        cout << a << '+' << b << '-' << c << '-' << d << "=7" << endl;
        return 0;
    }
    if(a - b + c - d == 7) {
        cout << a << '-' << b << '+' << c << '-' << d << "=7" << endl;
        return 0;
    }
    if(a - b - c - d == 7) {
        cout << a << '-' << b << '-' << c << '-' << d << "=7" << endl;
        return 0;
    }

    return 0;

}

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

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size(), m = t.size();
  set < string > ans;
  bool can = 0;
  for (int i = 0; i + m <= n; ++i) {
    bool here = 1;
    string cur = s.substr(i, m);
    for (int j = 0; j < m; ++j) {
      if (!(t[j] == s[i + j] || s[i + j] == '?'))
        here = 0;
    }
    if (here) {
      can = 1;
      string tho = "";
      for (int j = 0; j < i; ++j) {
        if (s[j] == '?')
          tho += 'a';
        else
          tho += s[j];
      }
      tho = tho + t;
      for (int j = i + m; j < n; ++j) {
        if (s[j] == '?')
          tho += 'a';
        else
          tho += s[j];
      }
      ans.insert(tho);
    }
    for (int j = 0; j < m; ++j)
      s[i + j] = cur[j];
  }
  if (can) {
    cout << *ans.begin() << '\n';
  }
  else
    cout << "UNRESTORABLE\n";
}


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

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) (x & (-x))
#define BIT(a,b) ((ll)(a&(1<<b))==0 ? false : true)

const ll MAXN=6e5+10;

ll dp[MAXN];
ll d[MAXN];
ll u[MAXN];

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

    ll n,D;
    cin>>n>>D;

    for(ll i=0;i<n;i++)
    {
        cin>>d[i];
    }

    if (d[n-1]==1)
    {
        dp[n-1]=1;
    }
    else
    {
        dp[n-1]=0;
    }

    for(ll i=n-2;i>=0;i--)
    {
        if (2*dp[i+1]>=d[i] || (2*dp[i+1])==(d[i]-1))
        {
            dp[i]=d[i]+dp[i+1];
        }
        else
        {
            dp[i]=dp[i+1];
        }
    }

    u[0]=D;

    for(ll i=1;i<n;i++)
    {
        if (d[i-1]<=u[i-1])
        {
            u[i]=u[i-1]-d[i-1];
        }
        else
        {
            if (d[i-1]<=2*u[i-1])
            {
                u[i]=d[i-1]-u[i-1];
            }
            else
            {
                u[i]=u[i-1];
            }
        }
    }

    ll q;
    cin>>q;

    for(ll i=0;i<q;i++)
    {
        ll x;
        cin>>x;

        x--;

        if (u[x]<=dp[x+1])
        {
            cout<<"NO"<<endl;
        }
        else
        {
            cout<<"YES"<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 15232
def resolve():
    N, Y = [int(i) for i in input().split()]
    for x in range((Y // 10000) + 1):
        for y in range((Y // 5000) + 1):
            z = N - x - y
            if z < 0:
                continue
            if 10000 * x + 5000 * y + 1000 * z == Y:
                print(x, y, z)
                return
    print(-1, -1, -1)

resolve()


Measured memory_bytes: 8924
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String line = sc.nextLine();

        String[] inputs = line.split(" ");
        int K = Integer.parseInt(inputs[0]);
        int X = Integer.parseInt(inputs[1]);

        int min = X - K + 1;
        int max = X + K - 1;
        
        String answer = IntStream.rangeClosed(min, max).mapToObj(Integer::toString).collect(Collectors.joining(" "));
        
        System.out.println(answer);

    }
}


Measured memory_bytes: 27092
using System;

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long n = int.Parse(input[0]);
            long m = int.Parse(input[1]);

            long a = Math.Max(n, m);
            long b = Math.Min(n, m);

            if (a == 1)
            {
                Console.WriteLine(1);
                return;
            }

            if (b == 1)
            {
                Console.WriteLine(a - 2);
                return;
            }
            
            Console.WriteLine((a - 2) * (b - 2));
        }
    }
}

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

public class Hello
{
    public static void Main()
    {
    　　string last = "0";
    　　string first = "1";
        // Your code here!
        int N = int.Parse(Console.ReadLine());
        string[] array = new string[N];
        for(int i = 0; i < N; i++)
        {
            array[i] = Console.ReadLine();
            if(i > 0)
            {
                first = array[i].Substring(0,1);
                if(first != last)
                {
                    Console.WriteLine("No");
                    return;
                }
            }
            
            
            //文字の最後の文字のルールチェック
            last = array[i].Substring(array[i].Length - 1);
            
        }
        
        Dictionary<string, int> dic = new Dictionary<string, int>();
        for(int i = 0; i < N; i++)
        {
            if(!dic.ContainsKey(array[i]))
            {
                dic[array[i]] = 0;
                dic[array[i]]++;
            }
            else
            {
                Console.WriteLine("No");
                return;
            }
        }
        
        Console.WriteLine("Yes");
    }
}


Measured memory_bytes: 13152
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:108777216")
#define _FORTIFY_SOURCE 0
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <utility>
#include <algorithm>
#include <ctime>
#include <cstdarg>
#include <sstream>
#include <functional>
using namespace std;

int const MAX_N = 512 * 1024;
long long const LL_INF = 5000000000000000000LL;

int cnt[MAX_N], p[MAX_N];

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		cnt[a]++; cnt[b+1]--;
	}
	p[0] = cnt[0];
	for (int i = 1; i <= n; i++)
		p[i] = p[i - 1] + cnt[i];
	int ans = 0;
	for (int i = 0; i <= n; i++) ans += p[i] == m;
	cout << ans;
	return 0;
}


Measured memory_bytes: 2688
#include<stdio.h>
#include<stdlib.h>

#define N 4

int Puzzle[N][N];
int tmp[N][N];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

void empty(int *,int *);
int dfs(int ,int,int ,int ,int );
int cal(void);


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

	for(i =0;i < N; i++){
		for(j = 0 ; j < N ; j++){
			scanf("%d",&Puzzle[i][j]);
		}
	}
	empty(&a,&b);

	for(limit = 0; limit < 60 ; limit++){
		for(i = 0; i < N ; i++){
			for(j = 0; j < N ; j++){
				tmp[i][j] = Puzzle[i][j];
			}
		}
		c = dfs(a,b,-1,0,limit);
		if(c!= -1){
			printf("%d\n",c);
			break;
		}

		for(i = 0; i < N ; i++){
			for(j = 0 ; j < N ; j++){
				Puzzle[i][j] = tmp[i][j];
			}
		}
		c =-1;
		if(limit == 59)printf("%d\n",c);
	}

	return 0;
}


int dfs(int x,int y,int p, int dep, int lim){
	int i,j,h,n1,n2,res;
	int cp;

	h = cal();

	if(h == 0)return dep;
	if(dep + h > lim) return -1;

	for(i = 0; i< 4; i++){
		n1 = x + dx[i];
		n2 = y + dy[i];

		if(~p && i == (p+2)%4) continue;
		if(!(0 <= n1 && n1 < 4 && 0 <= n2 && n2 < 4)) continue;

		cp = Puzzle[y][x];
		Puzzle[y][x] = Puzzle[n2][n1];
		Puzzle[n2][n1] = cp;

		res = dfs(n1,n2,i,dep+1,lim);
		if(~res)return res;

		cp = Puzzle[y][x];
		Puzzle[y][x] = Puzzle[n2][n1];
		Puzzle[n2][n1] = cp;

	}
	return -1;
}

void empty(int *x,int *y){
	int i,j;
	for(i = 0; i < N ; i++){
		for(j = 0 ; j < N ; j++){
			if(!Puzzle[i][j]){
				*x = j;
				*y = i;
				return;
			}
		}
	}
}

int cal(void){
	int i,a;
	int sum = 0;

	for(i = 0; i< N+12 ; i++){
		a = Puzzle[i/N][i%N];
		if(a){
			a--;
			sum += abs(i/N - a/N)  + abs(i%N - a%N);
		}
	}
	return sum;
}



Measured memory_bytes: 2140
n,a,b=map(int,raw_input().split())
s=raw_input()
cnta=0
cntb=0
for i in xrange(len(s)):
    if s[i]=="a":
        if cnta+cntb>=a+b:
            print('No')
        else:
            cnta+=1
            print('Yes')
    elif s[i]=="b":
        if cnta+cntb>=a+b:
            print('No')
        else:
            if cntb<b:
                cntb+=1
                print('Yes')
            else:
                print('No')
    else:
        print('No')

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

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(0);
	int k,x;
	cin>>k>>x;
	if(k*500-x>=0)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define END getchar();getchar();return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1000000007

signed main() {
	string s;
	cin >> s;
	int g = 0, p = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'g') {
			g++;
		}
		else p++;
	}
	cout << (g - p) / 2 << endl;

	END;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
typedef pair<int,int> P;
typedef long long ll;

int main(void){
  string s;cin >> s;
  if(s[2] == s[3] && s[4] == s[5]) cout << "Yes\n";
  else cout << "No\n";
}

Measured memory_bytes: 256
import java.io.*; 
import java.math.*;
import java.util.*;
 
public class Main {
	//static final long MOD = 998244353;
	static final long MOD = 1000000007;
	static final int INF = 1000000007;
	static int[][] perms;
	static int index;
    public static void main(String[] args) throws IOException {
    	FastScanner sc = new FastScanner();
    	int W = sc.nextInt();
    	int H = sc.nextInt();
    	int x = sc.nextInt();
    	int y = sc.nextInt();
    	System.out.print(((double)W)*H/2 + " ");
    	if (W % 2 == 0 && x == W/2 && H % 2 == 0 && y == H/2) {
    		System.out.println(1);
    	} else {
    		System.out.println(0);
    	}
    }
    
    public static long power(long x, long y, long p) { 
        // Initialize result
        long res = 1;
         
        // Update x if it is more   
        // than or equal to p 
        x = x % p;  
      
        while (y > 0) 
        { 
            // If y is odd, multiply x 
            // with result 
            if((y & 1)==1) 
                res = (res * x) % p; 
      
            // y must be even now 
            // y = y / 2 
            y = y >> 1;  
            x = (x * x) % p;  
        } 
        return res; 
    }
    
    public static long dist(int[] point, int[] point2) {
    	return (long)(Math.pow((point2[1]-point[1]),2)+Math.pow((point2[0]-point[0]),2));
    }
    
    public static long gcd(long a, long b) {
    	if (b == 0)
    		return a;
    	else
    		return gcd(b,a%b);
    }
    
    public static int[][] sort(int[][] array) {
    	//Sort an array (immune to quicksort TLE)
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    int[] temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		Arrays.sort(array, new Comparator<int[]>() {
			  @Override
        	  public int compare(int[] arr1, int[] arr2) {
				  return arr2[1]-arr1[1];
	          }
		});
		return array;
	}
    
    static class FastScanner { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastScanner() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try { 
                str = br.readLine(); 
            } catch (IOException e) {
                e.printStackTrace(); 
            } 
            return str; 
        }
    }
}

Measured memory_bytes: 21204
n=int(input())
f=[0]*3
for i in range(n):
	g=list(map(int,input().split()))
	h=[0]*3
	for j in range(3):
		for k in range(3):
			if j!=k:
				h[j]=max(h[j],f[k]+g[j])
	f=h
print(max(f))

Measured memory_bytes: 47064
import collections


n = int(input())
V = list(map(int, input().split()))

V0 = [V[i] for i in range(len(V)) if i % 2 == 0]
V1 = [V[i] for i in range(len(V)) if i % 2 == 1]

c0 = collections.Counter(V0)
c1 = collections.Counter(V1)

R0 = (n // 2) + (n % 2) - c0.most_common()[0][1]

if c0.most_common()[0] != c1.most_common()[0]:
    R0 += (n // 2) - c1.most_common()[0][1]
else:
    try:
        R0 += (n // 2) - c1.most_common()[1][1]
    except:
        R0 += (n // 2)

R1 = (n // 2) + (n % 2) - c1.most_common()[0][1]

if c0.most_common()[0] != c0.most_common()[0]:
    R1 += (n // 2) - c0.most_common()[0][1]
else:
    try:
        R1 += (n // 2) - c0.most_common()[1][1]
    except:
        R1 += (n // 2)

print(min(R0, R1))


Measured memory_bytes: 19040
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int A,B,C;
	cin>>A>>B>>C;
	
	if(A==B&&B==C){
      if(A%2==0)
		ce(-1)
        else
          ce(0)
	}else{
	
	int a=A,b=B,c=C;
	int ans=0;
	while(A%2==0&&B%2==0&&C%2==0){
		a=B/2+C/2;
		b=A/2+C/2;
		c=A/2+B/2;
		A=a;
		B=b;
		C=c;
		ans++;
	}
	ce(ans)
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define mod 1000000007LL
#define nax 200009LL
#define FOR(i,n,m) for(int i = (n); i < (m); i++)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) v.begin(),v.end()
#define sz(v) int(v.size())
 
 
typedef long long ll;
typedef vector<int> vi; 
typedef pair<int,int> ii;


int main(){
	fastio;

    ll x, y, a, b, c;
    cin>>x>>y>>a>>b>>c;
    vector<ll> r(a), g(b), q(c);
    multiset<ll> s;
    
    
    REP(i,a) cin>>r[i];
    REP(i,b) cin>>g[i];
    REP(i,c) cin>>q[i];

    sort(all(r));
    sort(all(g));
    sort(all(q));

    for(int i=sz(r)-1; i>=sz(r)-x; i--){
        s.insert(r[i]);
    }
    for(int i=sz(g)-1; i>=sz(g)-y; i--){
        s.insert(g[i]);
    }

    for(int i=sz(q)-1; i>=0; i--){
        s.insert(q[i]);
    }
    ll sum=0, cont=0;
    
    for(auto it=s.rbegin(); it!=s.rend(); ++it){
        if(cont>=x+y) break;
        sum+=(*it);
        cont++;
    }

    cout<<sum;
	return 0;
}

Measured memory_bytes: 15744
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int n;
vector<double> v;
double ans = 0.0;

int main()
{
    cin >> n;
    v.resize(n);
    for (int i = 0; i < n; ++i) cin >> v[i];
    sort(v.begin(), v.end(), greater<double>());

    ans = (v[n-1] + v[n-2]) / 2;
    for (int i = n - 3; i >= 0; --i) ans = (ans + v[i]) / 2;

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

    return 0;
}

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

int main() {
  int n;
  while(cin >> n, n) {
    int result = 0;
    for(int k = 2, d = 1; n >= k + d; d += k, ++k) {
      if(!((n - d) % k)) ++result;
    }
    cout << result << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define test long long int t; cin>>t; while(t-->0)
#define fIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define loop(i,n) for (ll i = 0; i < n; i++)
 
#define sz(x) int(x.size())
#define F first
#define S second
 
#define mii map<ll,ll>
#define vi vector<ll>
#define seti set<ll>
#define pii pair<ll,ll>
 
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a/gcd(a,b))*b

#define endl '\n'
using namespace std;
const int N=1e6;
    

int main()
    {
        fIO
        ll a,b;
        cin>>a>>b;
        char c; cin>>c;
        ll d;
        cin>>d;
        b=b*100;
        b+=d;
        ll x=(a*b)/100;
        cout<<x;
        
        
        
        
    }

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

void solve(string s, string t, vector<vector<int> > &dp){

  for(int i=0; i<=s.size(); i++)
    dp[i][0] = 0;
  for(int j=0; j<=t.size(); j++)
    dp[0][j] = 0;

  for(int i=1; i<=s.size(); i++){
    for(int j=1; j<=t.size(); j++){
      if(s[i-1] == t[j-1]){
        dp[i][j] = 1 + dp[i-1][j-1];
      }
      else{
        dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
      }
    }
  }

  string res = "";
  int i = s.size(), j = t.size();

  while(i>0 && j>0){
    if(s[i-1] == t[j-1]){
      res.insert(res.begin(), s[i-1]);
      i--;
      j--;
    }
    else if(dp[i-1][j] > dp[i][j-1])
      i--;
    else j--;
  }

  cout << res<< endl;
}


int main(){

  string s, t;
  cin >> s >> t;

  vector<vector<int> > dp(3001, vector<int> (3001));
  solve(s, t, dp);

  return 0;
}

/*
 .
axyb
 .
abyxb

*/

Measured memory_bytes: 35584
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int t = b - a - 1;
    int ans = -a;

    for (int i = 1; i <= t; i++) {
      ans += i;
    }

    System.out.println(ans);

  }
}

Measured memory_bytes: 35688
#include<bits/stdc++.h>
#define ll long long
#define mod7 1000000007

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    int dp[n][m];
    vector<vector<char>>bd;
    for(int i=0;i<n;i++)
    {
        vector<char> temp;
        for(int j=0;j<m;j++)
        {
           char t;
           cin>>t;
           temp.push_back(t);
           dp[i][j]=0;
        }
        bd.push_back(temp);
    }
    dp[0][0]=1;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(bd[i][j]=='.')
            {
                if(i>0&&j>0)
                    dp[i][j]=(dp[i][j-1]%mod7+dp[i-1][j]%mod7)%mod7;
                else if(i>0)
                    dp[i][j]=dp[i-1][j]%mod7;
                else if(j>0)
                    dp[i][j]=dp[i][j-1]%mod7;
            }
        }
    }
    cout<<dp[n-1][m-1];


}



Measured memory_bytes: 5120
N, X = list(map(int, input().split()))
L = list(map(int, input().split()))

# while d <= X:
#     if i >= i_max:
#         break
#     d += L[i]
#     i += 1
count = 1
total = 0
for i in range(len(L)):
    total += L[i]
    if total <= X:
        count += 1
print(count)

Measured memory_bytes: 3060
H, W, n = gets.chomp.split.map(&:to_i)
b_squares = []
n.times do
  b_squares.push(gets.chomp.split.map{|i| i.to_i - 1})
end

def cal_squares_including_black_square bs = [nil,nil]
  (0..2).map do |i|
    (0..2).map do |j|
      next if bs[0] - i < 0 || bs[1] - j < 0
      next if (bs[0] - i + 2) > (H - 1) || (bs[1] - j + 2) > (W - 1)
      "#{(bs[0] - i).to_s}-#{(bs[1] - j).to_s}"
    end.compact
  end
end

frequencies = b_squares.map do |b_square|
  cal_squares_including_black_square b_square
end.flatten.each_with_object({}) do |attr, memo|
  if memo[attr]
    memo[attr] += 1
  else
    memo[attr] = 1
  end
end.each_with_object({}) do |attr, memo|
  if memo[attr[1]]
    memo[attr[1]] += 1
  else
    memo[attr[1]] = 1
  end
end

zero = (H-2)*(W-2) - frequencies.reduce(0){|sum, i| sum + i[1]}
puts zero
frequencies = frequencies.to_a
9.times do |i|
  if idx = frequencies.map(&:first).index(i + 1)
    puts frequencies[idx][1]
  else
    puts 0
  end
end

Measured memory_bytes: 197884
#include <iostream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;
 
 
/*bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}*/
// use case
//sort(V.begin(), V.end(), compare_function);
 
/*struct compare
{
    bool operator ()(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second-a.first==b.second-b.first)
    {
        return a.first>b.first;
    }
    return a.second-a.first < b.second-b.first;}
};
priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/
 
/*void print1(vector <int> X)
{
    for (int i=0; i<X.size(); i++)
    {
        cout<<X[i]<<" ";
    }
    cout<<endl;
    return;
}
 
void print2(vector <vector <int>> X)
{
    for (int i=0; i<X.size(); i++)
    {
    for (int j=0;j<X[i].size();j++) {
        cout<<X[i][j]<<" ";}
    cout<<endl;}
    return;
}*/
void solve(int n, vector <ll> &A) {
	ll x=1000000000000000000;
	ll ats=1;
	for (int i=0;i<n;i++) {
		if (ats<=x/A[i]) {ats=ats*A[i];}
		else {cout<<-1<<endl; return;}
		}
		cout<<ats<<endl;
		return;
	}

 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int nul=0;
    vector <ll> A(n,0);
    for (int t=0; t<n; t++)
    {
	cin>>A[t];
	if (A[t]==0) {nul=1;}
    }
    if (nul==1) {cout<<0<<endl;}
    else {solve(n,A);}
    return 0;
}


Measured memory_bytes: 3992
#include <algorithm>
#include <iostream>
#include <list>
#include <map> //連想配列
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector> //動的配列

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

bool check(char c) {
  for (int i = 0; i < 10; i++) {
    if (c == '0' + i) {
      // std::cout << "OK" << std::endl;
      return true;
    }
  }
  // std::cout << "NO" << std::endl;

  return false;
}
int main() {

  int A, B;
  std::string S;
  std::cin >> A >> B >> S;
  for (int i = 0; i < A; i++) {
    if (!check(S[i])) {
      std::cout << "No" << std::endl;
      return 0;
    }
  }
  if (S[A] != '-') {
    std::cout << "No" << std::endl;
    return 0;
  }
  for (int i = A + 1; i < S.size(); i++) {
    if (!check(S[i])) {
      std::cout << "No" << std::endl;
      return 0;
    }
  }
  std::cout << "Yes" << std::endl;
  return 0;
}


Measured memory_bytes: 256
N = gets.to_i
a = [0] + gets.split(" ").map(&:to_i)

(N / 2).downto(1) do |i| #N / 2以降はa[]と変わらないから、N / 2以下だけを考える
    s = 0
    j = i
    while j <= N do
        s += a[j]
        j += i
    end
    a[i] = s & 1 # ビット二項演算子（両方とも1なら1）
end
ans = (1..N).select{|i| a[i] == 1}
puts ans.size, ans.join(" ")


Measured memory_bytes: 22076
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int MOD = 1e9 + 7;

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

    string S;
    cin >> S;
    for (int i = 0; i < S.length(); ++i)
        cout << 'x';
    cout << endl;

    return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> V(N);
    vector<int> C(N);
    for (int i = 0; i < N; i++){
        cin >> V.at(i);
    }
    for (int i = 0; i < N; i++){
        cin >> C.at(i);
    }
    int ans = 0;
    for (int i = 0; i < N; i++){
        if (V.at(i) - C.at(i) > 0){
            ans += V.at(i) - C.at(i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256