akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  ll cnt=0;
  judge=false;
  rep(i,0,n){
    ll d1,d2;cin>>d1>>d2;
    if(d1==d2)cnt++;
    else cnt=0;
    if(cnt>=3)judge=true;
  }
  ans1(judge);
  return 0;
}

Measured memory_bytes: 3648
#include<cstdio>
#include<cstring>

const int mod=1000000007;
struct node
{
	int lx,rx,ly,ry;
	void readx() {scanf("%d%d",&lx,&rx);}
	void ready() {scanf("%d%d",&ly,&ry);}
}a,b,c;
struct P{int x,y;}A[4],B[4],C[4];
int jc[2000001],inv[2000001],ans;

int quickmi(int a,int b)
{
	int t=1;
	while (b)
	{
		if (b&1) t=1ll*t*a%mod;
		a=1ll*a*a%mod;
		b>>=1;
	}
	return t;
}

int fuck(int x,int y) {return 1ll*jc[x]*inv[y]%mod*inv[x-y]%mod;}

int work(P a,P c,P b)
{
	int ans=0;
	for (int i=a.x; i<=b.x; i++) ans=(ans+1ll*fuck(c.x-i+c.y-b.y-1,c.x-i)*fuck(i-a.x+b.y-a.y,b.y-a.y)%mod*(b.y-a.y+i-a.x+1))%mod;
	for (int i=a.y; i<=b.y; i++) ans=(ans+1ll*fuck(c.x-b.x-1+c.y-i,c.x-b.x-1)*fuck(i-a.y+b.x-a.x,b.x-a.x)%mod*(b.x-a.x+i-a.y+1))%mod;
	return ans;
}

int main()
{
	jc[0]=1;
	for (int i=1; i<=2000000; i++) jc[i]=1ll*jc[i-1]*i%mod;
	inv[2000000]=quickmi(jc[2000000],mod-2);
	for (int i=2000000; i; i--) inv[i-1]=1ll*i*inv[i]%mod;
	a.readx(); b.readx(); c.readx();
	a.ready(); b.ready(); c.ready();
	A[0].x=a.lx-1; A[0].y=a.ly-1;
	A[1].x=a.lx-1; A[1].y=a.ry;
	A[3].x=a.rx; A[3].y=a.ly-1;
	A[2].x=a.rx; A[2].y=a.ry;
	C[0].x=c.lx; C[0].y=c.ly;
	C[1].x=c.lx; C[1].y=c.ry+1;
	C[3].x=c.rx+1; C[3].y=c.ly;
	C[2].x=c.rx+1; C[2].y=c.ry+1;
	B[0].x=b.lx-1; B[0].y=b.ly-1;
	B[1].x=b.lx-1; B[1].y=b.ry;
	B[3].x=b.rx; B[3].y=b.ly-1;
	B[2].x=b.rx; B[2].y=b.ry;
	ans=0;
	for (int i=0; i<4; i++)
		for (int j=0; j<4; j++)
			for (int k=0; k<4; k++)
				ans=(ans+(1-((i+j+k)&1)*2)*work(A[i],C[j],B[k]))%mod;
	printf("%d\n",(ans+mod)%mod);
	return 0;
}

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

const ll INF = 1e+18;
const ll MAX_N = 10000001;
ll A[MAX_N] = {INF};

int main()
{
    ll N;
    cin >> N;

    ll ans = 0;
    for (int k = 1; k <= N; k++)
    {
        for (int i = k; i <= N; i += k)
        {
            A[i]++;
        }

        ans += k * A[k];
    }

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

Measured memory_bytes: 81724
#include<iostream>
#include<cassert>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	int N, K;
	cin >> N >> K;
	int ans1 = N % K;
	int ans2 = abs(ans1 - K);
	int ans = min(ans1, ans2);
	cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define yes "Yes\n"
#define no "No\n"
//int m,n;
//int i,j,k,l;
//int a,b,c,d,e,f,g;
//int sum,total;
//long long int ;
//float ;
//double ;
//char a[101],b[101],s[101],t[101],u[101];
int i,n,k;
char s[51],abc[4];
int main(void){
    scanf("%d %s",&n,s);
    for ( i = 0; i < n-2; i++)
    {
        if ((s[i]=='A'&&s[i+1]=='B')&&s[i+2]=='C')
        {
            k++;
        }
        
    }
    printf("%d\n",k);
    
    return 0;
}

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

int main(){
vector<int> K(3);
for(int i=0;i<3;i++){
  cin>>K[i];
}
if((K[0]==K[1]&&K[0]!=K[2])||(K[1]==K[2]&&K[0]!=K[2])||(K[0]==K[2]&&K[0]!=K[1])){
  cout<<"Yes"<<endl;
}else{
  cout<<"No"<<endl;
}





return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <math.h>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <queue>

#define MAX 100005
#define ll long long int
using namespace std;

int main(void) 
{
	int n, r;
	int i, j;
	vector <int> ans, p, c;
	int temp1, temp2;

	vector <int> huda(55);

	queue <int> temp; //????????????????´???????

	while (1) {
		cin >> n >> r;
		if (n == 0 && r == 0) {
			break;
		}

		for (i = 0; i < r; i++) {
			cin >> temp1 >> temp2;
			p.push_back(temp1);
			c.push_back(temp2);
		}

		huda[0] = 0;

		for (i = n; i > 0; i--) { //?????????????¨????
			huda[n - i + 1] = i;


		}

		for (i = 0; i < r; i++) {

			for (j = 0; j < c[i]; j++) {
				temp.push(huda[p[i] + j]); 
			}

			for (j = p[i] + c[i] - 1; j > c[i]; j--) {
				huda[j] = huda[j - c[i]]; // ??±???????????¨???
			}

			for (j = 1; j <= c[i]; j++) {
				huda[j] = temp.front();
				temp.pop();

			}



		}

		ans.push_back(huda[1]);

		p.clear();
		c.clear();

		


	}



	 
	for (i = 0; i < ans.size(); i++) {
		cout << ans[i] << endl;
	}


	return (0);
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

class RangeFind {
    int n;
    vector<i64> data;
    
    int find(int a, int b, const i64 x, int k, int l, int r) {
        if (data[k] > x || r <= a || b <= l) return -1;
        if (k >= n) {
            return k - n;
        }
        int t = find(a, b, x, 2 * k + 1, (l + r) >> 1, r);
        if (t != -1) return t;
        return find(a, b, x, 2 * k, l, (l + r) >> 1);
    }
    
public:
    RangeFind(const vector<i64>& as) {
        n = 1;
        while (n < as.size()) n <<= 1;
        data.assign(2 * n, 1e18);
        for (int i = 0; i < as.size(); i++) {
            data[n + i] = as[i];
        }
        for (int i = n - 1; i > 0; i--) {
            data[i] = min(data[2 * i], data[2 * i + 1]);
        }
    }
    
    void update(int k, const i64& x) {
        k += n;
        data[k] = x;
        while (k >>= 1) {
            data[k] = min(data[2 * k], data[2 * k + 1]);
        }
    }
    
    i64 query(int a, int b) {
        i64 L = 1e18, R = 1e18;
        for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
            if (a & 1) {
                L = min(L, data[a++]);
            }
            if (b & 1) {
                R = min(data[--b], R);
            }
        }
        return min(L, R);
    }
    
    // [a, b)でx以下の値をもつ最右の要素の位置
    int find(int a, int b, const i64& x) {
        return find(a, b, x, 1, 0, n);
    }
};

int main() {
    int n;
    cin >> n;
    vi as(n), bs(n), ind(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
        bs[n - 1 - i] = as[i];
        ind[as[i]] = i;
    }
    RangeFind rf1(as), rf2(bs);
    i64 sum = 0;
    for (i64 i = 1; i <= n; i++) {
        int k = ind[i];
        int r = rf2.find(0, n - k - 1, i);
        if (r == -1) {
            r = n - 1;
        } else {
            r++;
            r = n - 1 - r;
        }
        int l = rf1.find(0, k, i);
        l++;
        sum += i * (k - l + 1) * (r - k + 1);
    }
    cout << sum << endl;
}


Measured memory_bytes: 13312
#include <bits/stdc++.h>
        using namespace std;
        #define mod 1000000000000000000
        #define MOD 		1000000007
        #define ll long long
        #define ull unsigned ll
        #define mp 		make_pair
        #define pb 		push_back
        #define forn(i,n) 	for(ll i=0;i<n;i++)
        #define for1(i,n) 	for(ll i=1;i<=n;i++)
        #define forn1(i,n) 	for(int i=1;i<n;i++)
        #define rep(i,x,n)  for(ll i=x;i<=n;i++)
        #define repr(i,x,j) for(ll i=x;i>=j;i--)
        #define vi vector<ll>
        #define mii map<ll,ll>
        #define vii vector<pair<ll,ll>>
        #define vvi vector<vector<ll>>
        #define pii pair<ll,ll>
        #define F first
        #define S second
        #define fill(a,x) memset(a,x,sizeof a);
        #define all(x) x.begin(),x.end()
        #define test ll t;cin>>t;while(t--)
        #define yes cout<<"YES"<<endl
        #define no cout<<"NO"<<endl
        #define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        ll flag[100000];
        #define R return 0
        int main()
        {
          IOS;
          string s;
          cin>>s;
          if(s[s.size()-1]!='s')
          cout<<s<<'s'<<endl;
          else 
          cout<<s<<"es"<<endl;
           R;

        }
        
        /// Happy coding ):
        ///Thanks to repl.it -_-

Measured memory_bytes: 3616
#if defined(LOCAL)
#define PROBLEM_NAME "b"
const double _max_double_error = 1e-9;
#include "testutils.h"
#define L(x...) (debug(x, #x))
#define I(x, ...) (x)
#define C(x...) CHECK(x)
#else
#define L(x, ...) (x)
#define I(x, ...) (x)
#define C(x, ...) ;
#include <bits/stdc++.h>
#endif

using namespace std;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using ii = pair<int,int>; using lu = unsigned long long; using l = long long;
using vs = vector<string>; using vii = vector<ii>;
using vl = vector<l>; using vvl = vector<vl>; using vvvl = vector<vvl>;
using ll = pair<l,l>; using vll = vector<ll>; using vvll = vector<vll>;
using vb = vector<bool>; using vvb = vector<vb>;
using vd = vector<double>; using vvd = vector<vd>;
using mll = unordered_map<l, l>;
const l INF = numeric_limits<l>::max();
const double EPS = 1e-10; static constexpr auto PI = acos(-1);
const l e0=1, e3=1000, e5=100000, e6=10*e5, e7=10*e6, e8=10*e7, e9=10*e8;
const char lf = '\n';
#define all(x) begin(x), end(x)
#define F(a,b,c) for (l a = l(b); a < l(c); a++)
#define B(a,b,c) for (l a = l(c) - 1; a >= l(b); a--)
#define VVL(x, a, b, i) vvl x(a, vl(b, l(i)));
#define VVVL(x, a, b, c, i) vvvl x(a, vvl(b, vl(c, l(i))));

void solve(istream& cin, ostream& cout) {
  l n; cin >> n;
  vl v(n), idx(n);
  F(i, 0, n) cin >> v[i];
  F(i, 0, n) idx[v[i] - 1] = i;
  l s = 1;
  l b = 1;
  F(i, 1, n) {
    if (idx[i - 1] < idx[i]) {
      s++;
      b = max(b, s);
    } else {
      s = 1;
    }
  }
  cout << (n - b) << lf;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout << fixed << setprecision(15);
#if defined(LOCAL)
  // _generate_random_test = generate_random;
  // _solve_brute = solve_brute;
  // _player_b = player_b;
  // _custom_solution_checker = solution_checker;
  maybe_run_tests(cin, cout);
#else
  solve(cin, cout);
#endif
}


Measured memory_bytes: 3328
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ACBO098
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, max;

            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);

            max = a + b;
            if (max < a - b) max = a - b;
            if (max < a * b) max = a * b;


            Console.WriteLine(max);

            Console.ReadKey();

        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<cmath>
 
#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)
 
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9
#define MOD 1000000007
 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef std::pair<ll, ll> P;
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
 
 
using namespace std;

int main()
{
    int H, W;
    int h, w;
    cin >> H >> W >> h >> w;
    ll ans = (H-h)*(W-w);
    cout << ans;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"

int main()
{
	db w,h,x,y;
	cin>>w>>h>>x>>y;
	pf("%0.9lf ",(w*h)/2);
	if(x==w/2 && y==h/2) cout<<1<<nw;
	else cout<<0<<nw;
	
	return 0;
}

Measured memory_bytes: 256
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end
a = lines[0]
b = lines[1]
if a[1] == 0
  puts a[0]
  exit
end

arr = (0..101).to_a - b
arrr = arr.map {|x| a[0] - x}
abs_arr = arrr.map(&:abs)
min_i = abs_arr.min
min_n = abs_arr.index(min_i)
puts arr[min_n]

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    for(int i=1; i<=9; i++) {
        for(int j=1; j<=9; j++) {
            cout << i << "x" << j << "=" << i * j << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1160
import java.io.*;

class Main{
	public static void main(String args[]) throws IOException{
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(buf.readLine());
		String[] str = buf.readLine().split(" ");

		int tmp;
		int max = -1000000;
		int min = 1000000;
		long sum=0;
		for(int i=0; i< str.length; i++){
			tmp = Integer.parseInt(str[i]);
			if(tmp <= min)
				min = tmp;
			if(tmp >= max)
				max = tmp;
			sum += tmp;
		}
		System.out.println(min+" "+max+" "+sum);
	}
}

Measured memory_bytes: 28328
N = int(input())
A1 = list(map(int, input().split(' ')))
A2 = list(map(int, input().split(' ')))
now_gain = sum(A2) + A1[0]
max_gain = now_gain
for i in range(1, N):
    now_gain = now_gain - A2[i-1] + A1[i]
    max_gain = max(max_gain, now_gain)
print(max_gain)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
using namespace std;

long N,M;
int a[100009],b[100009];
vector<pair<int, int> > pairs(100009);
long east;
long long sum;
int main() {
  east=0;
  cin>>N>>M;
  for(int i;i<M;i++){
      cin>>a[i]>>b[i];
      pairs[i] = make_pair(b[i], a[i]);
  }
  sort(pairs.begin(), pairs.end());
  east=1;
  for(int i;i<100009;i++){
      if(east<=pairs[i].second){
          sum++;
          east=pairs[i].first;
      }
  }
  cout<<sum<<"\n";
}

Measured memory_bytes: 1920
#include<stdio.h>
#include<string.h>
int main(void)
{
	int n;
	int i,j;
	int flg=0;
	int s;
	char w[100][100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",&w[i]);
	}
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			s=strcmp(w[i],w[j]);
			//printf("%d\n",s);
			if(s==0) flg=1;
		}
	}
	for(i=0;i<n-1;i++){
		if(w[i][strlen(w[i])-1]!=w[i+1][0]) flg=1;
		//printf("%c %c\n",w[i][strlen(w[i])-1],w[i+1][0]);
	}
	if(flg==0) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#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>
using namespace std;
#define MOD (long long int)(1e9+7)
#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 INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#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()



int main(void){
    int N;
    cin >> N;

    int a[N];
    int amax = 0;
    int a3[3];
    int b3[3];
    rep(i,3){
        a3[i] = -1;
        b3[i] = 0;
    }
    string ans = "Yes";
    if(N%3 >0){
        ans = "No";
    }
    rep(i,N){
        cin >> a[i];
        amax = max(a[i],amax);
        if(i == 0){
            a3[0] = a[i];
            b3[0] += 1;
        }else if(a[i] != a3[0] && a3[1] < 0){ 
            a3[1] = a[i];
            b3[1] += 1;
        }else if(a[i] != a3[0] && a[i] != a3[1] && a3[2] < 0){
            a3[2] = a[i];
            b3[2] += 1;
        }else if(a[i] == a3[0]){
            b3[0] += 1;
        }else if(a[i] == a3[1]){
            b3[1] += 1;
        }else if(a[i] == a3[2]){
            b3[2] += 1;
        }else{
            ans = "No";
        }
    }

    
    if(a3[2] < 0){
        a3[2] = max(a3[0],a3[1]);
    }
    //cout << a3[0] << a3[1] << a3[2] << endl;

    if(b3[0] == b3[1] && b3[0] == b3[2]){

    }else if(a3[0] == 0 && b3[0]*2 == b3[1]){

    }else if(a3[1] == 0 && b3[1]*2 == b3[0]){

    }else{
        ans = "No";
    }



    int p = 1;
    int q;
    rep(i,36){
        p = p*2;
        if(amax <= p){
            q = i+2;
            break;
        }
    }

    int b[3][q];
    rep(i,3){
        int pp = p;
        rep(j,q){
            if(a3[i] >= pp){
                b[i][j] = 1;
                a3[i] -= pp;
            }else{
                b[i][j] = 0;
            }
            pp = pp/2;
        }
    }
    
    rep(i,q){
        if((b[0][i]+b[1][i])%2 != b[2][i]){
            ans = "No";
        }
    }

    if(amax == 0){
        ans = "Yes";
    }



    /* rep(i,3){
        rep(j,q){
            cout << b[i][j] << " ";
        }
        cout << endl;
    }*/
    
    //cout << amax << p << q << ans << endl;
    
    //cout << b3[0] << b3[1] << b3[2] << endl;
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void){
	int N, A;
    int count_one = 0, max_count_one = 0;
	int i;
	
	scanf("%d", &N);
	for(i = 0; i < N; i++){
		scanf("%d", &A);
        if(A == 0){
            if(max_count_one < count_one){
                max_count_one = count_one;
            }
            count_one = 0;
        }else if(A == 1){
            count_one++;
        }
	}
	
    if(max_count_one < count_one){
        max_count_one = count_one;
    }
	printf("%d\n", max_count_one + 1);

	return 0;
}


Measured memory_bytes: 2108
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#define Rint register int
#define mem(a,b) memset(a,(b),sizeof(a))
#define Temp template<typename T>
using namespace std;
typedef long long LL;
Temp inline void read(T &x){
    x=0;T w=1,ch=getchar();
    while(!isdigit(ch)&&ch!='-')ch=getchar();
    if(ch=='-')w=-1,ch=getchar();
    while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^'0'),ch=getchar();
    x=x*w;
}

int n,a,b;

inline bool check(){
	int dert=b-a-1;
	if(dert&1)return 1;
	return 0;
}

int main(){
	read(n);read(a);read(b);
	if(check())printf("Alice\n");
	else printf("Borys\n");
    return 0;
}

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

using namespace std;

int c2i[128], i2c[52];

int main()
{
    for(int i=0; i<26; i++)
    {
        c2i['a'+i] = i;
        c2i['A'+i] = i + 26;
        i2c[i] = 'a' + i;
        i2c[i+26] = 'A' + i;
    }

    int n;
    while(cin >> n, n)
    {
        int ks[n];
        for(int i=0; i<n; i++) cin >> ks[i];
        string s;
        cin >> s;
        for(int i=0; i<s.size(); i++) s[i] = i2c[(c2i[s[i]] - ks[i%n]  + 52) % 52];
        cout << s << endl;
    }
}

Measured memory_bytes: 3148
/*
#include <boost/functional/hash.hpp>
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int mlint;
*/
#include <bits/stdc++.h>
using namespace std;

#define debug 0
#define print(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define fcout(d) cout << fixed << setprecision(d)
#define each(i,v) for(auto i = begin(v); i != end(v); ++i)
#define reach(i,v) for(auto i = rbegin(v); i != rend(v); ++i)
#define urep(i,s,t) for(int i = (int)(s); i <= (int)(t); ++i)
#define drep(i,s,t) for(int i = (int)(s); i >= (int)(t); --i)
#define rep(i,n) urep(i,0,(n) - 1)
#define rep1(i,n) urep(i,1,(n))
#define rrep(i,n) drep(i,(n) - 1,0)
#define all(v) begin(v),end(v)
#define rall(v) rbegin(v),rend(v)
#define vct vector
#define prique priority_queue
#define l_bnd lower_bound
#define u_bnd upper_bound
#define rsz resize
#define ers erase
#define emp emplace
#define emf emplace_front
#define emb emplace_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second

typedef long long ll;
typedef double db;
typedef vct<vct<ll>> mat;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
typedef map<int,int> mpii;
typedef unordered_map<int,int> umpii;

template <class T, class U> ostream& operator << (ostream& s, pair<T,U> p) { return s << p.fir << " " << p.sec; }
template <class T> ostream& operator << (ostream& s, vct<T> v) { each(i,v) { if(i != begin(v)) s << " "; s << *i; } return s; }

auto esc = [](auto ret) { cout << ret << endl; exit(0); };
auto odd = [](auto x) { return x & 1; };
auto even = [](auto x) { return !odd(x); };
auto qceil = [](auto x, auto y) { return x > 0 ? (x - 1) / y + 1 :  x / y; };
auto parity = [](auto x, auto y) { return odd(x) ^ even(y); };
auto chmax = [](auto& m, auto x) { if(m < x) { m = x; return 1; } return 0; };
auto chmin = [](auto& m, auto x) { if(m > x) { m = x; return 1; } return 0; };
auto cmprs  = [](auto& v) {
    auto tmp = v;
    sort(all(tmp));
    tmp.erase(unique(all(tmp)),end(tmp));
    for(auto it = begin(v); it != end(v); ++it) *it = l_bnd(all(tmp),*it) - begin(tmp) + 1;
    return tmp.size() != v.size();
};

const int dir[8][2] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const ll inf32 = (1 << 30) - 1;
const ll inf64 = (1LL << 62) - 1;
const ll mod = 1e9 + 7;
const db eps = 1e-15;

int n,m;
string s,t;
ll gcd(ll a, ll b) { if(!b) return abs(a); if(a % b) return gcd(b, a % b); return b; };
ll lcm(ll a, ll b) { if(a | b) return a / gcd(a, b) * b; };

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

    cin>>n>>m;
    cin>>s>>t;
    int g=gcd(n,m);
    int nn=n/g,mm=m/g;
    rep(i,g){
        if(s[nn * i] != t[mm * i]) esc(-1);
    }
    esc(lcm(n,m));
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#define CL(a) memset(a,0,sizeof(a))
#define cl(a,b) memset(a,(b),sizeof(a))
#define For(i,a,b) for(i=a;i<b;i++)
#define LL long long 
using namespace std;
const int maxn = 1e5 + 30;
int m,n; 
LL a[maxn];
map<int,int> mp;
map<int,int>::iterator it;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		scanf("%lld",a+i);
	mp[0] = 1;
	for(int i=1;i<=n;i++) 
	{
		a[i] = (a[i]+a[i-1])%m;
		mp[a[i]]++;
	}
	LL ans = 0;
	for(it=mp.begin();it!=mp.end();it++) 
	{
		int x = it->second;
		ans += 1ll*x*(x-1)/2;
	}
	cout<<ans<<endl;
	
	
	return 0;
}

Measured memory_bytes: 3968
a =list(map(int,input().split()))
x=a[0]
y=a[1]
z=a[2]
t=0
for i in range(1,x+1):
	if i//10000+((i//1000)%10)+((i//100)%10)+((i//10)%10)+(i%10)>=y and i//10000+((i//1000)%10)+((i//100)%10)+((i//10)%10)+(i%10)<=z:
		t=t+i
print(t)

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

	int main() {
	#ifdef LOCAL_DEFINE
		// freopen("data.in", "rt", stdin);
		// freopen("data.out", "w", stdout);
		auto _start = chrono::high_resolution_clock::now();
	#endif

		ios::sync_with_stdio(false);
		cin.tie(0);
		cout << fixed << setprecision(15);
		int n, k;
		cin >> n >> k;
		vector<int> a(n);
		for(int i = 0; i < n; i++) {
			cin >> a[i];
		}
		vector<bool> dp(k + 1, false);
		for(int j = 1; j <= k; j++) {
			for(int i = 0; i < n; i++) {
				dp[j] = dp[j] | (a[i] <= j && !dp[j - a[i]]);
			}
		}
		cout << (dp[k] ? "First" : "Second") << '\n';

	#ifdef LOCAL_DEFINE
		auto _end = chrono::high_resolution_clock::now();
		cerr << "elapsed time: " << chrono::duration<double, milli>(_end - _start).count() << " ms\n";
	#endif
		return 0;
	}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template <class T> void swap(T& a, T& b) { T t = std::move(a); a = std::move(b); b = std::move(t); }

int main(void)
{
    ll N, K, i, count=0;

    cin >> N >> K;

    vector<pair<ll, ll>> pairs(N);

    for(i=0; i<N; i++){
        cin >> pairs[i].first >> pairs[i].second;
    }

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

    for(i=0; i<N; i++){
        count += pairs[i].second;

        if(count >= K){
            cout << pairs[i].first << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string YES = "Yes";
const string NO = "No";

void solve(long long D, long long T, long long S) {
    if (S * T >= D) {
        cout << YES << endl;
    } else {
        cout << NO << endl;
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main() {
    long long D;
    scanf("%lld", &D);
    long long T;
    scanf("%lld", &T);
    long long S;
    scanf("%lld", &S);
    solve(D, T, S);
    return 0;
}


Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define intt long long
using namespace std;
int i , j ;
int main ()
{
    int n,m;
    cin >> n >> m;
    char c[n+1][m+1];
    for ( i = 1 ; i <= n ; i++ )
    {
        for ( j =1 ; j <= m ; j++ )
        {
            cin >> c[i][j];
        }
    }
    for ( i = 1 ; i <= n ; i++ )
    {
        for ( j =1  ; j <= m ; j++ )
        {
            if ( c[i][j] == '#' )
                break;
        }
        if ( j == m+1 )
        {
            for ( j = 1 ;  j<= m ; j++ )
            {
                c[i][j] = '1';
            }
        }
    }
    for ( i =1 ; i <= m ; i++ )
    {
        for ( j =1 ;  j<= n ; j++ )
        {
            if ( c[j][i] == '#' )
                break;
        }
        if ( j == n+1 )
        {
            for ( j =1 ;  j<= n ; j++ )
            {
                c[j][i] = '1';
            }
        }
    }
    for ( i =1 ;  i<= n ; i++ )
    {
        bool flag = false;
        for ( j =1 ;  j <= m ; j++ )
        {
            if ( c[i][j] == '1' )
                continue;
            cout << c[i][j];
            flag = 1;
        }
        if ( flag )
            cout << endl;
    }
}


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

const ll MAX = 1e6 + 1;
const ll MOD = 1e9 + 7;
vector<ll> fac(MAX);
vector<ll> finv(MAX);
vector<ll> inv(MAX);

void COMinit(){
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(ll i = 2; i < MAX; i++){
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}

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

bool isPrime(ll n){
  if(n <= 1) return false;
  if(n == 2) return true;
  if(n % 2 == 0) return false;
  for(ll i = 3; i*i <= n; i += 2){
    if(n % i == 0) return false;
  }
  return true;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  COMinit();
  ll N, M; cin >> N >> M;
  map<ll, ll> mp;
  if(isPrime(M)){
    mp[M]++;
  }else{
    ll cnt = 0;
    while(M%2==0){
      M /= 2;
      cnt++;
    }
    if(cnt != 0) mp[2] = cnt;
    ll tmp = M;
    for(ll i = 3; i*i <= M; i += 2){
      cnt = 0;
      while(tmp%i == 0){
        tmp /= i;
        cnt++;
      }
      if(cnt != 0) mp[i] = cnt;
    }
    if(tmp != 1) mp[tmp]++;
  }
  ll ans = 1;
  for(auto &i : mp){
    ans = ans * nCr(N+i.second-1, i.second) % MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 23680
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a[]= new int[7];
		int i,as=0;
		a[0]=sc.nextInt();
		a[1]=sc.nextInt();
		a[2]=sc.nextInt();
		a[3]=sc.nextInt();
		a[4]=sc.nextInt();
		a[5]=sc.nextInt();
		as=a[0]+a[1]+a[2]+a[3]+a[4]+a[5];
		
		if(as==15) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}	
	}
}


Measured memory_bytes: 23380
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int w,h,x,y,r;

    cin >> w >> h >> x >> y >> r;
    if(x+r > w || y+r > h || x-r <0 || y-r<0){
        printf("No\n");
    }else
    {
        printf("Yes\n");
    }
    return 0;
       
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

class Graph{
	private:
	int n;
	vvp g;
	public:
	vi DIJ(int s){
		priority_queue<P> q;
		vi d(n,inf);
		d[s]=0;
		q.push({0,s});
		while(!q.empty()){
			P p=q.top();
			q.pop();
			int v=p.second;
			if(d[v]<-p.first) continue;
			for(auto i:g[v]){
				int u=i.first,D=d[v]+i.second;
				if(d[u]>D){
					d[u]=D;
					q.push({-D,u});
				}
			}
		}
		return d;
	}
	Graph(int v){
		n=v;
		g=vvp(v);
	}
	void add_edge(int s,int t,int c){
		g[s].push_back({t,c});
		g[t].push_back({s,c});
	}
};

int n;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	while(1){
		int n;
		cin>>n;
		if(n==0) break;
		string s,t;
		vs a(n),b(n);
		for(int i=0;i<n;i++){
			cin>>a[i]>>b[i];
		}
		cin>>s>>t;
		queue<pair<string,int>> q;
		q.push(make_pair(s,0));
		int res=-1;
		while(!q.empty()){
			auto p=q.front();q.pop();
			auto str=p.first;
//			cout<<str<<endl;
			if(str==t){
				res=p.second;
				break;
			}
			for(int i=0;i<n;i++){
				string tmp;
				for(int j=0;j<str.size();j++){
					if(str.substr(j,a[i].size())==a[i]){
						tmp+=b[i];
						j+=a[i].size()-1;
					}
					else tmp+=str[j];
				}
				if(tmp.size()<=t.size()&&str.size()<tmp.size()){
					q.push(make_pair(tmp,p.second+1));
				}
			}
		}
		cout<<res<<endl;
	}
}


Measured memory_bytes: 3396
#include<cstdio>
#include <algorithm>
#include <iostream>
#include <functional>
#include<cmath>

using namespace std;

int main(){
	int n,a;
	bool bl=true;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a);
		if(a%2==0){
			if(!(a%3==0||a%5==0)) bl = false;
		}
	}
	if(bl)printf("APPROVED\n");
	else printf("DENIED\n");
	return 0;
}

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

map<long long, int> prime_factorize(long long n) {
    map<long long, int> res;
    for (long long p = 2; p * p <= n; ++p) {
        while (n % p == 0) { ++res[p]; n /= p; }
    }
    if (n != 1) res[n] = 1;
    return res;
}

int main() {
    int n; cin >> n;
    cout << n << ":";
    for (auto prime_beki: prime_factorize(n)) {
        while (prime_beki.second--) cout << " " << prime_beki.first;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef struct {
	int b;
	int c;
}Ope;


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

	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	vector<Ope> bc(m);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> bc[i].b >> bc[i].c;
	}
	sort(a.begin(), a.end(), [](int& i, int& j) {return i > j; });
	sort(bc.begin(), bc.end(), [](Ope& i, Ope& j) {return i.c > j.c; });
	int count = 0;
	int bc_i = 0;
	int a_i = 0;
	long long ans = 0;
	while (count < n) {
		if (bc_i == m) {
			ans += a[a_i];
			a_i++;
		}
		else if (a[a_i] >= bc[bc_i].c) {
			ans += a[a_i];
			a_i++;
		}
		else {
			ans += bc[bc_i].c;
			bc[bc_i].b--;
			if (bc[bc_i].b == 0)bc_i++;
		}
		count++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
 
typedef long long   ll;
typedef long double ld;
const int N  = 5e5+10;
const ll mod = 1e9+7;
const ll inf = 1e18;
 
#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define ub              upper_bound                 // first element >  val(itr)
#define lb              lower_bound                 // first element >= val(itr) 
#define all(x)          (x).begin(),(x).end()
#define reset(a,x)      memset(a,x,sizeof(a))       // x can be 0 or -1
#define leadzero(a)     __builtin_clz(a)            // count leading zeroes
#define trailzero(a)    __builtin_ctz(a)            // count trailing zeroes
#define bitcount(a)     __builtin_popcount(a)       // count set bits
#define iceil(n,x)      ((n)+(x)-1)/(x)
#define test            int t; cin>>t; while(t--)
#define forn(i,a,e)     for(ll i = a; i < e; i++)
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;    }
ll powm(ll base,ll exp){ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
ll modinv(ll n)    { ll ans=powm(n,mod-2); return ans; }
ll add(ll a,ll b)  { return (a%mod+b%mod)%mod;        }
ll sub(ll a, ll b) { return (a%mod+mod-b%mod)%mod;    }
ll mult(ll a,ll b) { return ((a%mod)*(b%mod))%mod;    }
ll choose2(ll n)   { ll ans=(n*(n-1))/2; return ans;  }
ll dist2(ll x1,ll y1,ll x2,ll y2){ ll ans=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1); return ans;}

int main()
{
	fast
	ll n;
	string s;
	cin>>n>>s;

	if(n<3200)
	cout<<"red";
	else
	cout<<s; 
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<queue>
#include<set>
#include<vector>
#include<cmath>
#include<ctime>
#include<locale>
using namespace std;
long c[1000];
int main()
{
    long n;
    cin>>n;
    for(long i=0;i<n;i++)scanf("%d",&c[i]);
    long a=0,b=1000;
    for(long i=0;i<n;i++)
    {
        if(a<c[i])a=c[i];
        if(b>c[i])b=c[i];
    }
    cout<<a-b;
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vector<int>> mi;
typedef vector<vector<pair<int, int>>> w_graph;
typedef vector<vector<int>> uw_graph;

const ll mod = 1e9 + 7;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef DEBUG
	freopen("out.txt", "w", stdout);
#endif

	int n, k; cin >> n >> k;
	vector<ll> a(n);
	vector<ll> dp(k + 1);
	vector<ll> prefix(k + 1);

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

	dp[0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= k; j++)
		{
			if (j == 0) prefix[j] = dp[j];
			else prefix[j] = prefix[j - 1]  + dp[j];
		}

		for (int j = k; j >= 1; j--) {
			int r = j - 1;
			int l = max(0LL, j - a[i]);
			ll sum = 0;
			if (l == 0) sum = prefix[r];
			else sum = prefix[r] - prefix[l - 1];
			dp[j] += sum;
			dp[j] %= mod;
		}
	}

	cout << dp[k] % mod << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<ll> x(1), y(1);
    vector<ll> a(n), b(n), c(n), d(m), e(m), f(m);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i];
        x.emplace_back(a[i]);
        x.emplace_back(b[i]);
        y.emplace_back(c[i]);
    }
    for (int i = 0; i < m; i++) {
        cin >> d[i] >> e[i] >> f[i];
        x.emplace_back(d[i]);
        y.emplace_back(e[i]);
        y.emplace_back(f[i]);
    }
    sort(x.begin(), x.end());
    x.erase(unique(x.begin(), x.end()), x.end());
    sort(y.begin(), y.end());
    y.erase(unique(y.begin(), y.end()), y.end());
    int h = x.size(), w = y.size();
    vector<vector<int>> g(2 * h + 1, vector<int>(2 * w + 1));
    for (int i = 0; i < n; i++) {
        int ax = lower_bound(x.begin(), x.end(), a[i]) - x.begin();
        int bx = lower_bound(x.begin(), x.end(), b[i]) - x.begin();
        int cy = lower_bound(y.begin(), y.end(), c[i]) - y.begin();
        ax = ax * 2 + 1;
        bx = bx * 2 + 1;
        cy = cy * 2 + 1;
        for (int j = ax; j <= bx; j++) {
            g[j][cy] = 1;
        }
    }
    for (int i = 0; i < m; i++) {
        int dx = lower_bound(x.begin(), x.end(), d[i]) - x.begin();
        int ey = lower_bound(y.begin(), y.end(), e[i]) - y.begin();
        int fy = lower_bound(y.begin(), y.end(), f[i]) - y.begin();
        dx = dx * 2 + 1;
        ey = ey * 2 + 1;
        fy = fy * 2 + 1;
        for (int j = ey; j <= fy; j++) {
            g[dx][j] = 1;
        }
    }
    ll ans = 0;
    int px = lower_bound(x.begin(), x.end(), 0) - x.begin();
    int py = lower_bound(y.begin(), y.end(), 0) - y.begin();
    px = px * 2 + 1;
    py = py * 2 + 1;
    queue<pair<int, int>> que;
    que.emplace(px, py);
    while (!que.empty()) {
        for (int id = que.size(); id > 0; id--) {
            int i, j;
            tie(i, j) = que.front();
            que.pop();
            if (g[i][j] == 1) {
                continue;
            }
            if (i == 0 || j == 0 || i == 2 * h || j == 2 * w) {
                cout << "INF" << '\n';
                exit(0);
            }
            g[i][j] = 1;
            if (i % 2 == 0 && j % 2 == 0) {
                ans += (x[i / 2] - x[i / 2 - 1]) * (y[j / 2] - y[j / 2 - 1]);
            }
            for (int ni = i - 1; ni <= i + 1; ni++) {
                for (int nj = j - 1; nj <= j + 1; nj++) {
                    if (g[ni][nj] == 0) {
                        que.emplace(ni, nj);
                    }
                }
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 144832
#n=int(input())
a,b,c,d=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

l=a+b;r=c+d
if l<r:
    print('Right')
elif l==r:
    print('Balanced')
else:
    print('Left')




Measured memory_bytes: 9140
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <deque>
#include <utility>
#include <set>
#include <queue>
#include <functional>

#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for(int i = int(a); i < int(b); ++i)
#define RREP(i, n) RFOR(i, 0, n)
#define RFOR(i, a, b) for(int i = int(b) - 1; i >= int(a); --i)

constexpr double EPS = 1e-7;

using PAIR = std::pair<int, int>;

struct Part {
	char num;
	std::vector<PAIR> p;
};

int dy4[] = { -1,0,1,0 };
int dx4[] = { 0,1,0,-1 };

int w, h;
char mat[63][13];
bool visited[63][13];

Part getPart(int y, int x) {
	if (mat[y][x] == '.') return Part();
	Part res;
	char c = mat[y][x];
	res.num = c;

	std::set<PAIR> set;
	set.insert(PAIR(y, x));
	std::queue<PAIR> que;
	que.push(PAIR(y, x));

	while (!que.empty()) {
		PAIR now = que.front(); que.pop();

		REP(d, 4) {
			int dy = now.first + dy4[d];
			int dx = now.second + dx4[d];
			if (dy < 1 || dy >= h + 1 || dx < 0 || dx >= w) continue;
			if (mat[dy][dx] != c) continue;
			PAIR to(dy, dx);
			if (set.count(to)) continue;
			set.insert(to);
			que.push(to);
		}
	}

	for (auto& p : set) {
		res.p.emplace_back(p);
	}
	return res;
}



signed main() {

	while (true) {
		std::cin >> w >> h;
		if (w == 0 && h == 0) break;
		REP(i, h) REP(j, w) {
			std::cin >> mat[i + 1][j];
			visited[i + 1][j] = false;
		}
		REP(j, w) mat[0][j] = '.', mat[h + 1][j] = '#';

		bool ok = [&] {
			RFOR(i, 1, h + 1) REP(j, w) {
				if (mat[i][j] == '.') continue;
				if (visited[i][j]) continue;

				auto base = getPart(i, j);
				int l = 1000, r = -1;
				for (auto& pos : base.p) {
					int y = pos.first, x = pos.second;
					visited[y][x] = true;
					if (mat[y + 1][x] != '.' && mat[y + 1][x] != base.num) {
						l = std::min(l, x);
						r = std::max(r, x + 1);
					}
				}

				std::set<PAIR> above;
				std::function<void(int,int,bool)> calcAbove = [&](int y, int x, bool clear = true) {
					if (clear) above.clear();
					if (above.count(PAIR(y, x))) return;

					Part part = getPart(y, x);
					for (auto& p : part.p) above.insert(p);

					for (auto & p : part.p) {
						char c = mat[p.first - 1][p.second];
						if (c != part.num && c != '.') {
							calcAbove(p.first - 1, p.second, false);
						}
					}
				};

				calcAbove(i, j, true);
				int sz = above.size();
				int sumx = 0;
				for (auto& p : above) {
					sumx += p.second;
				}
				if (l * 2 * sz >= sumx * 2 + sz || sumx * 2 + sz >= r * 2 * sz) return false;
			}
			return true;
		}();
		std::cout << (ok ? "STABLE" : "UNSTABLE") << "\n";
	}

	return 0;
}


Measured memory_bytes: 2940
#include<stdio.h>
int main()
{
	int a, b;
	char s[10];
	bool n = true;
	scanf("%d%d%s", &a, &b,s);
	if (s[a] != 45 )
	{
		n = false;
	}
	for (int i = 0; i < (a + b + 1); i++)
	{
		if (i == a)
		{
			continue;
		}
		if (s[i] < '0' || s[i] > '9')
		{
			n = false;
		}
	}
	if (n)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

inline int abs(int a) {
    if (a < 0)
        return -a;
    return a;
}

int get_min(int pos, int look_back, vector <int> &h, vector <int> &dp) {
    int min = 0x3f3f3f3f, nr;
    for (int i = pos - 1; i >= 0 && pos - i <= look_back; i--) {
        nr = dp[i] + abs(h[pos] - h[i]);
        if (nr < min)
            min = nr;
    }
    return min;
}

int main() {
    int n, k;
    cin >> n >> k;
    vector <int> h(n), dp(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    dp[0] = 0;

    for (int i = 1; i < n; i++) {
        dp[i] = get_min(i, k, h, dp);
    }

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

Measured memory_bytes: 1024
#include <stdio.h>

int main ()
{
long long int a,b,t,g,c,d;
long long int l;
while (scanf("%lld %lld", &a, &b)!=EOF){
if (a==0){
g=a;
}
else if (b==0) {
g=b;
}
else {
d=a;
c=b;
while (c!=0){
t=c;
c=d%c;
d=t;
}
g = d;
}

l = (a*b)/g;
printf ("%lld %lld\n", g, l);
}
return 0;
}

Measured memory_bytes: 1856
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M = map(int, input().split())
lamps = [list(map(lambda x:int(x)-1, input().split()))[1:]
         for _ in range(M)]
p = list(map(int, input().split()))
ans = 0

# bit全探索(スイッチの入れ方を全探索する)
for i in range(1 << N):
    for r in range(M):  # 全てのランプがついてるかチェック
        on_sum = 0  # ランプrにおいて、onのスイッチの数
        for j in range(N):  # スイッチのj番目について
            if i >> j & 1 and j in lamps[r]:
                on_sum += 1  # スイッチjがランプrに繋がってて、onならon_sum+=1
        if on_sum % 2 != p[r]:  # on_off check
            break  # 一つでもoffなら次のbitに
    else:
        ans += 1
print(ans)

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
	"strings"

)

func main() {
	solve(os.Stdin, os.Stdout)
}

type inInfo struct {
	in    int
	after int
}

type inInfoSorter []inInfo

func (a inInfoSorter) Len() int      { return len(a) }
func (a inInfoSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a inInfoSorter) Less(i, j int) bool {
	switch {
	case a[i].in > a[j].in:
		return true
	case a[i].in < a[j].in:
		return false
	case a[i].after > a[j].after:
		return true
	default:
		return false
	}
}

func sum(w []int) int {
	s := 0
	for _, v := range w {
		s += v
	}
	return s
}

type ptr []int

func (x ptr) top(i int) int {
	ptrs := []int(x)
	var his []int
	cur := i
	for ; cur >= 0 && ptrs[cur] != cur; cur = ptrs[cur] {
		his = append(his, cur)
	}
	for _, v := range his {
		ptrs[v] = cur - 1
	}
	if cur >= 0 {
		ptrs[cur] = cur - 1
	}
	return cur
}

func solve(stdin io.Reader, stdout io.Writer) {
	var n, m int
	var infos []inInfo
	reader := bufio.NewScanner(stdin)
	fmt.Fscanln(stdin, &n, &m)

	for i := 0; i < n; i++ {
		var info inInfo
		//fmt.Fscanln(stdin, &info.after, &info.in)
		reader.Scan()
		var s = strings.Fields(reader.Text())
		info.after, _ = strconv.Atoi(s[0])
		info.in, _ = strconv.Atoi(s[1])
		infos = append(infos, info)
	}

	sort.Sort(inInfoSorter(infos))

	var ans = make([]int, m)
	var p = make([]int, m)
	for i := range p {
		p[i] = i
	}
	ptrs := ptr(p)

	for _, w := range infos {
		i := ptrs.top(m - w.after)
		if i >= 0 {
			ans[i] = w.in
		}
	}

	fmt.Fprintln(stdout, sum(ans))

}



Measured memory_bytes: 8704