akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;

const ll MOD_CONST = 1000000007;



int main()
{

	int a, b;
	cin >> a >> b;

	

	vector<string> ans(100);
	for (int i = 0; i < 50; i++) {
		ans[i] = string(100, '#');
	}

	for (int i = 50; i < 100; i++) {
		ans[i] = string(100, '.');
	}


	vector<vector<int>> direction{ {1,0},{0,1},{-1,0},{0,-1} };

	for (int i = 0; i < 49; i+=2) {
		for (int j = 0; j < 100; j += 2) {
			if (a == 1) {
				break;
			}


			ans[i][j] = '.';
			a--;
			//cout << ans[i][j] << endl;

		}
	}


	for (int i = 51; i < 100; i+=2) {
		for (int j = 0; j < 100; j += 2) {
			if (b == 1) {
				break;
			}


			ans[i][j] = '#';
			b--;
			//cout << ans[i][j] << endl;

		}
	}



	cout << 100 << " " << 100 << endl;
	for (int i = 0; i < 100; i++) {
		cout << ans[i] << endl;
	}

	
}  



Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;

class team {
public:
  int num;
  int time;
  int solveNum;
  int p[10];
  bool j[10];
  int probTime[10];
  team(int a, int b, int c) {
    num = a;
    time = b;
    solveNum = c;
    for (int i = 0; i < 10; i++) {
      p[i] = 0;
      j[i] = false;
      probTime[i] = 0;
    }
  }
};

bool compare(team a, team b) {
  return (a.solveNum > b.solveNum ||
	  (a.solveNum == b.solveNum && a.time < b.time) ||
	  (a.solveNum == b.solveNum && a.time == b.time && a.num > b.num));
}

bool tie(team a, team b) {
  return (a.solveNum == b.solveNum && a.time == b.time);
}

int main() {
  int M, T, P, R;
  while(true) {
    cin >> M >> T >> P >> R;
    if (M == 0 && T == 0 && P == 0 && R == 0) break;

    vector <team> myTeam;
    for (int i = 0; i < T; i++) {
      myTeam.push_back(team(i+1, 0, 0));
    }

    for (int i = 0; i < R; i++) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      myTeam[t-1].probTime[p-1] = m;
      if (j == 0) {
	myTeam[t-1].solveNum++;
	myTeam[t-1].time += myTeam[t-1].probTime[p-1]+ myTeam[t-1].p[p-1]*20;
      }else {
	myTeam[t-1].p[p-1]++;
      }
    }
    //    for (int i = 0; i < R; i++) {
      //      for (int j = 0; j < 10; j++) {
    //	if (!myTeam[i].j[j]) {
    //	  myTeam[i].time -= myTeam[i].probTime[j-1];
    //	}
    //      }
    //    }

    sort(myTeam.begin(), myTeam.end(), compare);
    for (int i = 0; i < T-1; i++) {
      std::cout << myTeam[i].num;
      if (tie(myTeam[i], myTeam[i+1])) {
	std::cout << "=";
      }else {
	std::cout << ",";
      }
    }
    std::cout << myTeam[T-1].num << std::endl;

  }
}

Measured memory_bytes: 1224
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

#define ALL(a) (a).begin(),(a).end()
#define ITER(e, v) for(const auto& e : v)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"

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

  deque<int> q;
  REP(i, N) {
    IN(a);
    if (i % 2 == 1)
      q.push_back(a);
    else
      q.push_front(a);
  }
  if (N % 2 == 0) {
    reverse(ALL(q));
  }
  bool first = true;
  ITER(e, q) {
    if (first)
      cout << e;
    else
      cout << " " << e;
    first = false;
  }
  cout << "\n";

  return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    vector<int> sCheck(200), tCheck(200);
    for (int i = 0; i < S.length(); ++i) {
        sCheck[S[i]]++;
        tCheck[T[i]]++;
    }
    sort(sCheck.begin(), sCheck.end());
    sort(tCheck.begin(), tCheck.end());
    if (sCheck == tCheck) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 916
#include<bits/stdc++.h>
using namespace std;
#include<vector>
#include<queue>
#define ll long long
#define inf INT_MAX
ll int d[101][200000];
/*ll int solve(ll int a[][2],ll int n,ll int w,ll int i)
{
	
	if(w>=0&&i>=n)
	  return 0;
	if(a[i][0]>w)
	{
		return solve(a,n,w,i+1);
	}
	else
	{
		return max(a[i][1]+solve(a,n,w-a[i][0],i+1),solve(a,n,w,i+1));
	}
}*/
main()
{
	memset(d,0,sizeof(d));
	ll int n,w;
	cin>>n>>w;
	
	ll int a[n+1][2];
	//a[0][0]=0;
	//a[0][1]=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i][0]>>a[i][1];
	}
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=w;j++)
    	{
    		if(a[i-1][0]>j)
    		d[i][j]=d[i-1][j];
    		else
    		d[i][j]=max(a[i-1][1]+d[i-1][j-a[i-1][0]],d[i-1][j]);
    		
		}
	}
/*	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=w;j++)
		{
			cout<<d[i][j]<<" ";
		}
		cout<<endl;
	}*/
	cout<<d[n][w]<<endl;

	
}


Measured memory_bytes: 158080
#include <stdio.h>
#include <cmath>
#include <stdlib.h>
#include <algorithm>

int main()
{
    int n, h, w;
    scanf("%d", &n);
    scanf("%d", &h);
    scanf("%d", &w);

    int p = n - h + 1;
    int q = n - w + 1;

    printf("%d", p * q);
    return 0;
}


Measured memory_bytes: 128
# p: max in adder ; n: number of adders;  s: sum
def dfs(p, n, s):
    if not p:
        if n == 1 and s == 0:
            return 1
        else:return 0
    elif n == 1:
        if 0 <= s <= p:
            return 1
        else: return 0
    elif s < 0:
        return 0
    else:
        return dfs(p-1, n-1, s-p) + dfs(p-1, n, s)

while True:
    try:
        n, s = list(map(int, input().split()))
        if (not n and not s):
            break
        print(dfs(9, n, s))
    except:
        break


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

struct sample {
	char suit;
	char value;
} A[100], B[100];

int isStable(struct sample A[], struct sample B[], int N) {
	int i;
	for (i = 0; i < N; i++) {
		if (A[i].suit != B[i].suit || A[i].value != B[i].value) {
			return 0;
		}
	}
	return 1;
}

void sSort(struct sample A[], int N) {
	int i, j;
	int min;
	for (i = 0; i < N; i++) {
		min = i;
		for (j = i; j < N; j++) {
			if (A[j].value < A[min].value) {
				min = j;
			}
		}
		if (i != min) {
			struct sample temp = A[i];
			A[i] = A[min];
			A[min] = temp;
		}
	}
}

void bSort(struct sample A[], int N) {
	int i, j;
	for (i = 0; i < N; i++) {
		for (j = N - 1; j >= i; j--) {
			if (A[j].value < A[j - 1].value) {
				struct sample v = A[j];
				A[j] = A[j - 1];
				A[j - 1] = v;
			}
		}
	}
}

int main() {
	int N;
	int i;
	char s[5];
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%s", s);
		A[i].suit = s[0];
		A[i].value = atoi(s + 1);
		B[i] = A[i];
	}
	bSort(A, N);
	for (i = 0; i < N; i++) {
		if (i > 0)
			printf(" ");
		printf("%c%d", A[i].suit, A[i].value);
	}
	printf("\nStable\n");
	sSort(B, N);
	for (i = 0; i < N; i++) {
		if (i > 0)
			printf(" ");
		printf("%c%d", B[i].suit, B[i].value);
	}
	if (isStable(A, B, N)) {
		printf("\nStable\n");
	} else {
		printf("\nNot stable\n");
	}
	return 0;
}



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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;


int main(){
    int H, N; cin >> H >> N;
    vi A(N), B(N);
    for(int i=0; i<N; i++){
        cin >> A[i] >> B[i];
    }
    vector<ll> dp(H+1, LINF);
    dp[H]=0;
    for(int i=H; i>=1; i--){
        for(int j=0; j<N; j++){
            if(i+A[j] <= H){
                dp[i]=min(dp[i], dp[i+A[j]]+B[j]);
            }
        }
    }
    ll res=LINF;
    for(int i=0; i<N; i++){
        for(int j=1; j<=min(A[i], H); j++){
            res=min(res, dp[j]+B[i]);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3716
#include <cstdio> 
using namespace std; //This makes the code much more cleaner

int main()
{
	

	int a, b, c, d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	int area = a*b;
	int areatwo = c*d;
		if (area>=areatwo)
		{
			printf("%d", area);
		}
		else
		{
			printf("%d",areatwo);
		}

	return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define reps(i, n , m) for(ll i = n; i <= m; i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
const int mod = 1000000007; 
long long inv[200000],fact[200000],ifact[200000];
long long comb(ll n, ll k){
	if(n<k)return 0;
	else if (n<0||k<0) return 0;
	else return fact[n] * ifact[k] % mod * ifact[n-k] % mod;
}
typedef long long ll;template<typename Typell>Typell G_C_D(Typell a, Typell b){if (a < 0) a = -a;if (b < 0) b = -b;while (b != 0) {a %= b;if (a == 0) return b;b %= a;}return a;}template<typename Typell>
Typell G_C_D(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = G_C_D(a, list[i]);}return a;}template<typename Typell>Typell L_C_M(Typell a, Typell b) {if( a == 0 && b == 0)return 0;return a / G_C_D(a, b) * b;}
template<typename Typell>Typell L_C_M(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = L_C_M(a, list[i]);}return a;}
 
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	/*inv[1] = fact[0] = fact[1] = ifact[0] = ifact[1] = 1; for (int i=2;i<200000;i++){ inv[i] = (mod - mod / i) * inv[mod % i] % mod; fact[i] = fact[i-1] * i % mod;ifact[i] = ifact[i-1] * inv[i] % mod;
	}*/ //nCr
	int A,B;
	cin>>A>>B;
	B=B*2;
	if(A>B) cout<<A-B<<endl;
	else cout<<0<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(v) for(int k=head[v];k;k=e[k].ne)
//#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef pair<int,int> pa;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
const int N=2e3+5,M=2e6+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
int n,m,bin[30]={1};
int f[N],g[N],k,ans;
int main(){
	read(n,m,k);
	f[0]=1;
	for(int i=1;;i++){
		if(i*(k-1)+1>n+m)break;
		int sum=(i-1)*(k-1),sa,sb;
		rep(j,0,n)if(f[j])re(a,1,k){
			sa=j+a;sb=sum-j+k-a;
			if(sa>n||sb>m||sb<0)continue;
			if((n-sa)%(k-1)==0&&(m-sb)%(k-1)==0)(ans+=f[j])%=mod;
		}
		rep(j,0,n)g[j]=0;
		rep(j,0,n)re(x,0,k)
			(g[j+x]+=f[j])%=mod;
		rep(j,0,n)f[j]=g[j];
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll mi = INF;

void dfs(ll N,ll six,ll nine, ll sum){
  if(N==0){
    mi=min(sum,mi);
    return;
  }
  else{
    while(six>N){
      six/=6;
    }
    while(nine>N){
      nine/=9;
    }
  }
  dfs(N-six,six,nine,sum+1);
  dfs(N-nine,six,nine,sum+1);
}

int main(){
  ll N;
  cin >> N;
  dfs(N,46656,59049,0);
  cout << mi << endl;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)

function main()
	a,b,c = parseInt.(split(readline()))
	flg = 0
	for i in 1:b
		if a*i%b==c
			print("YES")
			flg = 1
			break
		end
	end
	if flg == 0
		print("NO")
	end
end

main()

Measured memory_bytes: 115932
#include<stdio.h>
int main() {
  int a, b, c, d, p, sum1 = 0, sum2 =0;
  scanf("%d %d %d %d %d", &a, &b, &c, &d, &p);
  sum1 = a * p;
  if(p > c) {
    sum2 = b + (p - c) * d;
  }else{
    sum2 = b;
  }
  if(sum1 < sum2) {
    printf("%d\n", sum1);
  }else{
    printf("%d\n", sum2);
  }
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
const int INF=1<<31;
const int SUP=0x7fffffff;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

int main(){
	std::ios::sync_with_stdio(0);
	cin.tie(0);
	
	ull h,w;
	cin>>h>>w;
	
	ull ans;
	if(h<2 || w<2) ans=1;
	else{
		if(h%2==0) ans=w*h/2;
		else ans=w*(h/2)+(w+1)/2;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
typedef long long ll;
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
typedef struct{
    int a,b;
}data;

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
//構造体降順
int comp( const void *c1, const void *c2 )
{
  data test1 = *(data *)c1;
  data test2 = *(data *)c2;
  int tmp1 = test1.b;   /* b を基準とする */
  int tmp2 = test2.b;
  return tmp2 - tmp1;
}


int kai(int n){
    if(n==0){
        return 1;
    }
    int sum=1;
    for(int i=1;i<=n;i++){
        sum*=i;
    }
    return sum;
}

int main(){
    int N,a,b;
    scanf("%d%d%d",&N,&a,&b);
    int sum=0;
    for(int i=1;i<=N;i++){
        int temp=0;
        int damy=i;
        while(damy>0){
            temp+=damy%10;
            damy/=10;
        }
        if(temp>=a &&temp<=b){
            sum+=i;
        }
    }
    printf("%d",sum);
}


Measured memory_bytes: 1696
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <regex>
#include <list>
int main() {
	int w, h, x, y, r;
	std::cin >> w >> h >> x >> y >> r;
	if (0 <= (x - r) && 0 <= (y - r) && w >= (x + r) && h >= (y + r)) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}
	return 0;
}



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

int main(){
	string s;
	while(cin >> s){
		int n = s.size();
		vector<vector<int> > dp(n + 2, vector<int>(n + 2));

		int x = 0, y = 0;
		for(int i = 1; i <= n; ++i){
			dp[i][i] = dp[i-1][i+1] + 1;
			if(dp[x][y] < dp[i][i]){
				x = y = i;
			}

			for(int j = n; j > i; --j){
				if(s[i-1] == s[j-1]){
					dp[i][j] = dp[i-1][j+1] + 2;
				}
				else{
					dp[i][j] = max(dp[i-1][j], dp[i][j+1]);
				}

				if(dp[x][y] < dp[i][j]){
					x = i;
					y = j;
				}
			}
		}

		string t, u;
		while(x > 0 && y <= n){
			if(x == y && dp[x][y] == dp[x-1][y+1] + 1){
				--x;
				++y;
				t += s[x];
			}
			else if(x != y && s[x-1] == s[y-1] && dp[x][y] == dp[x-1][y+1] + 2){
				--x;
				++y;
				t += s[x];
				u += s[x];
			}
			else if(dp[x][y] == dp[x-1][y]){
				--x;
			}
			else{
				++y;
			}
		}
		
		reverse(t.begin(), t.end());
		cout << t << u << '\n';
	}
}

Measured memory_bytes: 16884
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    N ,W = I2()
    w = [0]*N
    v = [0]*W
    dp = [[0]*(W+1)for _ in range(N+1)]
    for i in range(N):
        a,b = I2()
        w[i] = a
        v[i] = b
    for i in range(N):
        for j in range(0,W+1):
            if(j >= w[i]):
                dp[i+1][j] = max(dp[i+1][j],dp[i][j-w[i]] + v[i])
            dp[i+1][j] = max(dp[i+1][j],dp[i][j])
            #print(dp)
    print(dp[N][W])

Measured memory_bytes: 120684
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
using ll = long long;
using P = pair<int, int>;

int f(int x)
{
    int ret = 0;
    while (x % 2 == 0)
    {
        x /= 2;
        ret++;
    }
    return ret;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int b1 = 0, b2 = 0, b4 = 0;
    rep(i, n)
    {
        int num = f(a[i]);
        if (num == 0)
            b1++;
        else if (num == 1)
            b2++;
        else
            b4++;
    }
    if (b2 > 0)
        b1++;
    if (b1 <= b4 + 1)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3728
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 51;
int n;
string s[N];
int mnCnt[26];

int main() {
    ios_base :: sync_with_stdio(false); cin.tie(0);
    for (int i = 0; i < 26; i++) mnCnt[i] = N;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        for (char c = 'a'; c <= 'z'; c++) {
            int cnt = 0;
            for (int j = 0; j < s.size(); j++)
                if (s[j] == c) cnt++;
            mnCnt[c - 'a'] = min(mnCnt[c - 'a'], cnt);
        }
    }
    string res = "";
    for (int i = 0; i < 26; i++)
        for (int c = 0; c < mnCnt[i]; c++)
            res += char(i + 'a');
    cout << res;
    return 0;
}


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

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

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

	string s;
	ll k;

	cin >> s >> k;

	int cnt = 0;
	for (int i = 0;i < s.size();i++){
		if(s[i] == '1') cnt++;
		else break;
	}

	if(cnt >= k) cout << 1 << endl;
	else cout << s[cnt] << endl;

	return 0;

}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
class Bit:
    def __init__(self, lst):
        t = 1
        while (t << 1) <= len(lst):
            for i in range(t, len(lst) - t + 1, t << 1):
                lst[i + t - 1] += lst[i - 1]
            t <<= 1
        self.lst = lst

    def add(self, pos, value):
        pos += 1
        while pos <= len(self.lst):
            self.lst[pos - 1] += value
            pos += pos & (-pos)

    def update(self, pos, value):
        diff = value - self.at(pos)
        self.add(pos, diff)

    def at(self, pos):
        return self.sum(pos + 1) - self.sum(pos)
    
    def sum(self, pos):
        # sum of [0, pos)
        if pos == 0:
            return 0
        s = 0
        while pos > 0:
            s += self.lst[pos - 1]
            #pos -= pos & (-pos)
            pos &= ~(-pos)
        return s
    
def solve():
    N = int(readline())
    A = [float(readline()) for i in range(N)]

    C = [0] * N
    c5s = set()

    for i, a in enumerate(A):
        b = round(a * (10 ** 9))
        c2, c5 = -9, -9
        while b % 2 == 0:
            b //= 2
            c2 += 1
        
        while b % 5 == 0:
            b //= 5
            c5 += 1
        
        C[i] = (c2, c5)
        c5s.add(c5)
        c5s.add(-c5)

    c5_to_i = {c5: i for i, c5 in enumerate(sorted(c5s))}
    
    C.sort()

    c5_comp = [c5_to_i[c5] for c2, c5 in C]
    
    bit = Bit([0] * len(c5_to_i))

    c5_max = max(c5 for c2, c5 in C)


    ans = 0
    j = N - 1
    for i, (c2, c5) in enumerate(C):
        if c2 < 0:
            l, r = i, N
            while l + 1 < r:
                m = (l + r) // 2
                if C[m][0] + c2 >= 0:
                    r = m
                else:
                    l = m
            if r == N:
                continue
            
            while j >= r:
                bit.add(c5_comp[j], 1)
                j -= 1
            
            ans += bit.sum(c5_to_i[c5_max] + 1) - bit.sum(c5_to_i[-c5])
        else:
            while j < i:
                j += 1
                bit.add(c5_comp[j], -1)
            
            while j > i:
                bit.add(c5_comp[j], 1)
                j -= 1

            ans += bit.sum(c5_to_i[c5_max] + 1) - bit.sum(c5_to_i[-c5])
    
    print(ans)


solve()

Measured memory_bytes: 102716
N = int(input())
xy = [map(int, input().split()) for _ in range(N)]
x, y = [list(i) for i in zip(*xy)]
flag = 0
for i in range(0,N-2):
    if x[i]==y[i]:
        if x[i+1]==y[i+1]:
            if x[i+2]==y[i+2]:
                flag = 1
                print("Yes")
                break
if flag == 0:
    print("No")

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

int main(){
	int N;
	cin >> N;
	int a[N];
	int flag = 0;
	for(int i=0; i<N; i++){
		cin >> a[i];
		if(a[i]%2 == 1){
			flag = 1;
		}
	}
	if(flag == 1){
		cout << "first" << endl;
	}else{
		cout << "second" << endl;
	}
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, a, b, c, d);
    Cout((3*a+b)/2);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>
#include <chrono>
#include <set>


#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

vector<vector<ll>> graph;
vector<ll> query;
vector<ll> ans;
vector<ll> visited;


const long long MAX_N = 1 << 17;
const long long MOD = 1000000007;

long long dat[2 * MAX_N - 1];

//E
int main(void) {
	ll n;
	cin >> n;
	vector<ll> a = vector<ll>(n);
	rep(i, 0, n) cin >> a[i];
	ll ans = 1;
	vector<ll> clr = vector<ll>(3, 0);
	rep(i, 0, n) {
		if (i == 0) {
			if (a[i] == 0) {
				ans *= 3;
				clr[0]++;
				continue;
			}
			else {
				ans = 0;
				break;
			}
		}
		ll count = 0;
		bool isNotDone = true;
		rep(j, 0, 3) {
			if (a[i] == clr[j]) {
				count++;
				if (isNotDone) clr[j]++;
				isNotDone = false;
			}
		}

		ans *= count;
		ans %= MOD;

		if (count == 0) break;

	}

	cout << ans << endl;
}

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

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      List<List<Integer>> list = new ArrayList<>();
      for(int i = 0; i < m; i++) {
        int k = sc.nextInt();
        List<Integer> l = new ArrayList<>();
        for(int j = 0; j < k; j++)
          l.add(sc.nextInt() - 1);
        list.add(l);
      }
      int[] pArr = new int[m];
      for(int i = 0; i < m; i++)
        pArr[i] = sc.nextInt();

      int cnt = 0;
      loop:
      for(int i = 0; i < (1 << n); i++) {
        for(int bulb = 0; bulb < m; bulb++) {
          int onCnt = 0;
          for(int stch : list.get(bulb)) {
            if(((i >> stch) & 1) == 1)
              onCnt++;
          }
          if(onCnt % 2 != pArr[bulb])
            continue loop;
        }
        cnt++;
      }
      System.out.println(cnt);
  }
}

Measured memory_bytes: 21844
N=int(input())
mod=10**9+7


A=5
dp=[[[[0]*A for _ in range(A)] for _ in range(A)] for _ in range(N+1)]

def check1(a,b,c):
    t=[a,b,c]
    if t==[1,2,4] or t==[1,4,2] or t==[2,1,4]:
        return False
    return True

def check2(a,b,c,m):
    if ([b,c]==[2,4] and m==1) or ([a,c]==[2,4] and m==1):
        return False
    return check1(a,b,c)
    
    
#初期化
for n in range(min(4,N+1)):
    for i in range(A):
        for j in range(A):
            for k in range(A):
                if check1(i,j,k):
                    dp[n][i][j][k]=1
                    
for n in range(4,N+1):
    for i in range(1,A):
        for j in range(1,A):
            for k in range(1,A):
                for m in range(1,A):
                    if check2(i,j,k,m):
                        dp[n][i][j][k]+=dp[n-1][m][i][j]
                dp[n][i][j][k]%=mod
                        
ans=0
if N>=3:
    for i in range(1,A):
            for j in range(1,A):
                for k in range(1,A):
                    ans+=dp[N][i][j][k]

if N==1:
    ans=4
elif N==2:
    ans=16

print(ans%mod)




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

int a, b, n = 100;
char ans[105][105];
int main()
{
	int i, j;
	cin >> a >> b;
	a--;
	b--;
	printf("%d %d\n", n, n);
	for (i= 0; i < 100; i++) {
		for (j = 0; j < 100; j++) {
			if (i < 50) ans[i][j] = '#';
			else ans[i][j] = '.';
		}
	}
	for (i = 0; i < a; i++) {
		ans[i / 50 * 2][i % 50 * 2] = '.';
	}
	for (i = 0; i < b; i++) {
		ans[60 + i / 50 * 2][i % 50 * 2] = '#';
	}
//	for (i = 0; i < 100; i++) {
//		for (j = 0; j <100; j++) {
//			if (i < 50 && a[i][j] != '.') a[i][j] = '#';
//			else if (i >= 50 && a[i][j] != '#') a[i][j] = '.';
//		}
//	}
	for (i = 0; i < 100; i++) {
		printf("%s\n", ans[i]);
	}
//	for (i = 1; i <= n; i++) {
//		for (j = 1; j <= n; j++) {
//			if (i <= n / 2 && i % 2 == 1 && j % 2 == 1 && a > 0) {printf("."); a--;}
//			else if (i > n / 2 && i % 2 == 1 && j % 2 == 1 && b > 0) {printf("#"); b--;}
//			else if (i <= n / 2) printf("#");
//			else printf(".");
//		}
//		puts("");
//	}
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<algorithm>
 
int main(){
	long long int n;
	cin>>n;
	vector<long long int> a(n);
	
	long long int sum=0;
	
	for(long long int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	
	long long int b=0;
	long long int c=sum;
	
	long long int ans=1e10+7;
	
	for(long long int i=0;i<n-1;i++){
		b+=a[i];
		c-=a[i];
		long long int ans2=abs(b-c);
		ans=min(ans,ans2);
		//cout<<b<<" "<<c<<" "<<ans<<endl;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

const int INF = 110000;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

ll dp[110][100010];

int main() //input->compute->output
{
        int N, W;
        cin >> N >> W;
        vector<int> We(N), V(N);

        rep(i, N)
        {
                cin >> We[i] >> V[i];
        }

        rep(i, N)
        {
                rep2(s, 0, W + 1)
                {
                        if (s - We[i] >= 0)
                        {
                                dp[i + 1][s] = max(dp[i + 1][s], dp[i][s - We[i]] + V[i]);
                        }

                        dp[i + 1][s] = max(dp[i + 1][s], dp[i][s]);
                }
        }

        cout << dp[N][W] << endl;
        return 0;
}

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

const int p = 1000000007;

long long le[2];
long long eq[2];

int main() {
	string l;
	cin >> l;
	int n = l.size();
	le[0] = 1;
	eq[0] = 1;
	for(int i=0;i<n;i++) {
		if(l[i] == '0') {
			le[(i+1) % 2] = (3 * le[i % 2] + 2 * p - 2 * eq[i % 2]) % p;
			eq[(i+1) % 2] = eq[i % 2];
		} else {
			le[(i+1) % 2] = (3 * le[i % 2]) % p;
			eq[(i+1) % 2] = (2 * eq[i % 2]) % p;
		}
	}
	cout << le[n % 2] << endl;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef long double ld;


int main() {
    ll N;
    cin >> N;
    ll L[87];
    L[0] = 2;
    L[1] = 1;
    REP(i, N-1) {
        L[i + 2] = L[i + 1] + L[i];
    }
    cout << L[N];
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <utility>
using namespace std;
int _time = 0;
stack<int> route;
void dfs(int root, vector<vector<bool>> &conn_mat, vector<bool> &accessed, vector<pair<int, int>> &result)
{
	accessed[root] = true;
	result[root].first = _time;
	int index;
	bool end = true;
	for (index = 0; index < conn_mat.size(); index++)
	{
		if (conn_mat[root][index] == true && accessed[index] == false)
		{
			_time++;
			result[index].first = _time;
			dfs(index, conn_mat, accessed, result);
			end = false;
		}
	}
	if (end)
	{
		_time++;
		result[root].second = _time;
		return;
	}
	_time++;
	result[root].second = _time;
	return;
}

int main()
{

	int n_node, index, n_cn, cn;
	cin >> n_node;
	vector<bool> vertex(n_node, false);
	vector<vector<bool>> conn_mat(n_node, vertex);
	vector<bool> &accessed = vertex;
	vector<pair<int, int>> result(n_node, make_pair(1, 0));
	while (n_node--)
	{
		cin >> index >> n_cn;
		while (n_cn--)
		{
			cin >> cn;
			conn_mat[index - 1][cn - 1] = true;
		}
	}
	bool end = false;
	while (!end) {
		_time++;
		int i = 0;
		while (accessed[i]) {
			i++;
		}
		dfs(i, conn_mat, accessed, result);
		end = true;
		for (auto acc : accessed) {
			end = end && acc;
		}
	}
	int i = 1;
	for (auto out : result) {
		cout << i << ' ' << out.first << ' ' << out.second << endl;
		i++;
	}
	return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 1666666
int arr[N];
signed main(){
    
    int a,b,c;
    cin>>a>>b>>c;
    if(!b){
        cout<<"0";return 0;
    }
    int ans=a/(b+c);
    ans*=b;
    ans+=min(a%(b+c),b);
    cout<<ans;
    return 0;
}

/*
))((())(

*/

Measured memory_bytes: 256
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)   make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

signed main(){
    int a,b;
    cin >> a >> b;
    cout << a * b - (a + (b - 1)) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define MAX_H (500010)
#define PARENT_ID(i) (i >> 1)
#define LEFT_ID(i)   (i << 1)
#define RIGHT_ID(i)  ((i << 1) + 1)

void maxHeapify( int A[], int i, int H ) {
    int l = LEFT_ID(i);
    int r = RIGHT_ID(i);
    int max_index = i;
    int max_v = A[i];
    
    if ( l <= H && max_v < A[l] )  {
	max_index = l;
	max_v = A[l];
    }
    if ( r <= H && max_v < A[r] )  {
	max_index = r;
	max_v = A[r];
    }
    
    if ( max_index != i ) {
	int tmp = A[i]; A[i] = A[max_index]; A[max_index] = tmp;
	maxHeapify( A, max_index, H );
    }
    
}


int main()
{
    int H;
    int A[MAX_H + 1];

    scanf("%d", &H);
    
    for ( int i = 1; i <= H; i++ ) {
	scanf("%d", &A[i]);
    }

    for ( int i = (H/2); i > 0; i-- ) {
	maxHeapify( A, i, H );
    }

    for ( int i = 1; i <= H; i++ ) {
	printf(" %d", A[i]);
    }

    printf("\n");
    
    return 0;
}

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

int main(){
    string S, T;
    const char *s = NULL;
    const char *t = NULL;
    cin >> S >> T;
    s = S.c_str();
    t = T.c_str();
    bool okok=1;
    for(int i=0; i<S.size(); i++){
        if(s[i]!=t[i]){
            okok=0;
        }
    }
    if(okok==1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 3688
#include<stdio.h>

#include<algorithm>
#include<iostream>


using namespace std ;

typedef long long llong ;

typedef pair< llong ,llong > Data ;
#define size	first
#define value	second

#define N_MAX 500000
Data art[ N_MAX ] ;

inline llong Max( llong a ,llong b )
{
	return a > b ? a : b ;
}


int main( void )
{
	int N ;
	scanf( "%d" ,&N ) ;

	int i ;
	for( i = 0 ; i < N ; ++i )
	{
		scanf( "%lld %lld" ,&art[ i ].size ,&art[ i ].value ) ;
	}

	sort( art ,art + N ) ;

	llong min_size	= art[ 0 ].size		;
	llong sum_value	= art[ 0 ].value	;

	llong ans = art[ 0 ].value ;
	for( i = 1 ; i < N ; ++i )
	{
		llong value	= art[ i ].value	;
		llong size	= art[ i ].size		;

		llong tmp =  sum_value + value  - ( size -  min_size ) ;
		if( tmp < value )
		{
			ans = Max( ans ,value ) ;

			sum_value	= value	;
			min_size	= size	;
		}

		else
		{
			ans = Max( ans ,tmp ) ;

			sum_value += value ;
		}
	}

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

	return 0 ;
}


Measured memory_bytes: 11044
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e5+10;
#define fi first
#define se second
#define pb push_back
int n,k,r,s,p;
char a[N];
int vis[N];
int main() {
    ios::sync_with_stdio(false);
    cin>>n>>k>>r>>s>>p>>a+1;
    int ans=0;
    for(int i=1;i<=n;i++){
        if(i<=k){
            if(a[i]=='r'){
                ans+=p;
            }else if(a[i]=='s'){
                ans+=r;
            }else{
                ans+=s;
            }
            vis[i]=1;
        }else{
            if(a[i]==a[i-k]){
                if(vis[i-k]){
                    continue;
                }else{
                    vis[i]=1;
                    if(a[i]=='r'){
                        ans+=p;
                    }else if(a[i]=='s'){
                        ans+=r;
                    }else{
                        ans+=s;
                    }
                }
            }else{
                vis[i]=1;
                if(a[i]=='r'){
                    ans+=p;
                }else if(a[i]=='s'){
                    ans+=r;
                }else{
                    ans+=s;
                }
            }
        }
      //  cout<<i<<' '<<ans<<'\n';
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 768
'use strict'
const main = input => {
  input = input[0].split(' ').map(val => parseInt(val));
  const a = input[0], b = input[1], m = b+(a-b)/2;
  console.log(m == Math.round(m) ? m : 'IMPOSSIBLE');
  
  
  
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 7372
s = input()

dp1 = {'A': 0, 'AB': 0, 'ABC': 0}
dp2 = {'A': 0, 'AB': 0, 'ABC': 0}

c = 1000000000 + 7
n = len(s)
tmp = [1]*n
for i in range(1, n):
    tmp[i] = (tmp[i-1] * 3)%c
#print(tmp)

count = 0
for i in range(n):
    #dp2 = {'A': 0, 'AB': 0, 'ABC': 0}

    # if s[i] == '?':
    #     dp2['A'] = dp1['A']*3 + (3**count)
    # elif s[i] == 'A':
    #     dp2['A'] = dp1['A'] + (3**count)
    # else:
    #     dp2['A'] = dp1['A']
    #
    # if s[i] == '?':
    #     dp2['AB'] = dp1['AB']*3 + dp1['A']
    # elif s[i] == 'B':
    #     dp2['AB'] = dp1['AB'] + dp1['A']
    # else:
    #     dp2['AB'] = dp1['AB']
    #
    # if s[i] == '?':
    #     dp2['ABC'] = dp1['ABC']*3 + dp1['AB']
    # elif s[i] == 'C':
    #     dp2['ABC'] = dp1['ABC'] + dp1['AB']
    # else:
    #     dp2['ABC'] = dp1['ABC']
    #
    # if s[i] == '?':
    #     count += 1

    if s[i] == '?':
        dp2['A'] = dp1['A']*3 + tmp[count]
        dp2['AB'] = dp1['AB']*3 + dp1['A']
        dp2['ABC'] = dp1['ABC']*3 + dp1['AB']
        count += 1
    elif s[i] == 'A':
        dp2['A'] = dp1['A'] + tmp[count]
        dp2['AB'] = dp1['AB']
        dp2['ABC'] = dp1['ABC']
    elif s[i] == 'B':
        dp2['A'] = dp1['A']
        dp2['AB'] = dp1['AB'] + dp1['A']
        dp2['ABC'] = dp1['ABC']
    elif s[i] == 'C':
        dp2['A'] = dp1['A']
        dp2['AB'] = dp1['AB']
        dp2['ABC'] = dp1['ABC'] + dp1['AB']

    # for j in dp2.keys():
    #     dp2[j] = dp2[j] % c\
    # dp1 = dp2

    dp1['ABC'] = dp2['ABC'] % c
    dp1['AB'] = dp2['AB'] % c
    dp1['A'] = dp2['A'] % c

    #print(i, dp1)

print(dp1['ABC'])


Measured memory_bytes: 7284
#include "bits/stdc++.h"

using namespace std;

int N,M,K,L,R,H,W;

const long long int MOD=1000000007;


int main(){
	
	int N;
	while(cin>>N,N){
		vector<int>v(N);
		vector<int>w(N);
		vector<int>x(N);
		vector<int>y(N);
		int a,b,c,d;
		for(int i=0;i<N;i++){
			cin>>v[i]>>w[i]>>x[i]>>y[i];
		}
		vector<int>ans;
		cin>>a>>b>>c>>d;
		for(int i=0;i<N;i++){
			int sum=w[i]*4+x[i]*9+y[i]*4;
			if(w[i]<=a&&x[i]<=b&&y[i]<=c&&sum<=d)ans.push_back(v[i]);
		}
		if(ans.empty())cout<<"NA\n";
		else{
			for(auto i:ans)cout<<i<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3184
#include<iostream>
#include<string>
#include<vector>
#include<string.h>
#include<algorithm>
using namespace std;

int main(){
    int a[5];
    char c;
    while(cin>>a[0]>>c>>a[1]>>c>>a[2]>>c>>a[3]>>c>>a[4]){
        sort(a,a+5);
        int c[5],j=0;
        memset(c,0,sizeof(c));
        for(int i=0;i<4;i++){
            if(a[i+1]!=a[i])
                j++;
            if(a[i+1]==a[i]){
                c[j]++;
            }
        }
        int p=0,t=0,f=0;
        for(int i=0;i<5;i++){
            if(c[i]==1)p++;
            if(c[i]==2)t++;
            if(c[i]==3)f++;
        }
        if(p==2){
            cout<<"two pair"<<endl;
        }
        else if(p==1&&t==1)
            cout<<"full house"<<endl;
        else if(t==1)
            cout<<"three card"<<endl;
        else if(f==1)
            cout<<"four card"<<endl;
        else if(p==1){
            cout<<"one pair"<<endl;
        }
        else if((a[3]==a[4]-1)&&(a[1]==a[2]-1)&&(a[2]==a[3]-1)&&((a[0]==a[1]-1)||(a[4]==13&&a[0]==1)))
            cout<<"straight"<<endl;
        else cout<<"null"<<endl;
    }
}

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

using namespace std;
using lli = int_fast64_t;
using ulli = unsigned long long;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = copy(x);cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

constexpr lli MOD = (lli)1e9 + 7;
constexpr lli LIMIT = 1000000000000000000 * 5;


int main() {
	int N, M,X;
	cin >> N >> M >> X;
	vector<int> C(N);
	vector<vector<int>> A(N, vector<int>(M));
	for (int i = 0; i < N; i++) {
		cin >> C[i];
		for (int j = 0; j < M; j++) {
			cin >> A[i][j];
		}
	}
	bitset<13> bs(0);
	int ans = (int)MOD;
	for (int bbb = 0; bbb < 1 << N; bbb++) {
		bs = bitset<13>(bbb);
		vector<int> R(M,0);
		int sum = 0;
		for (int i = 0; i < N; i++) {
			if (bs[i]) {
				sum += C[i];
				for (int j = 0; j < M; j++) {
					R[j] += A[i][j];
				}
			}
		}
		bool ok = true;
		for (int j = 0; j < M; j++) {
			if (R[j] < X) {
				ok = false;
				break;
			}
		}
		if (ok)ans = min(ans, sum);
	}
	if (ans == (int)MOD) {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int MOD = 1e9 + 7;
const int N = 3e5 + 7;

int add(int a, int b) {
	return (a + b) % MOD;
}

int sub(int a, int b) {
	return (a - b + MOD) % MOD;
}

int mul(int a, int b) {
	return (a * b) % MOD;
}

int binpow(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = mul(res, a);
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}

int divv(int a, int b) {
	return mul(a, binpow(b, MOD - 2));
}

int f[N];

void init() {
	f[0] = 1;
	for (int i = 1; i < N; i++) {
		f[i] = mul(f[i - 1], i);
	}
}

int C(int n, int k) {
	return divv(f[n], mul(f[k], f[n - k]));
}

int solve(int n, int m) {
	int ans = 0;
	for (int dl = 1; dl < n; dl++) {
		int cnt = n - dl;
		cnt = mul(cnt, m);
		cnt = mul(cnt, m);
		ans = add(ans, mul(cnt, dl));	
	}
	return ans;
}

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

	init();
	int n, m, k;
	cin >> n >> m >> k;
	int ml = C(n * m - 2, k - 2);
	int sn = solve(n, m) + solve(m, n);
	cout << mul(ml, sn) << endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
		#include <bitset>
		using namespace std;
		#define ll long long 
		#define ld long double
		#define MOD 1000000007
		#define mod9 1000000009
		#define mod 1000003
		#define fast ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
		#define mp make_pair
		#define pb push_back
		#define ct ll t;cin>>t;while(t--)
		#define bi begin()
		#define ei end()
		#define fi first 
		#define se second   	
		bool isPrime(ll n) 
		{ 
			// Corner case 
			if (n <= 1) 
				return false; 
			
			// Check from 2 to n-1 
			for (ll i = 2; i*i <= n; i++) 
				if (n % i == 0) 
					return false; 
			
			return true; 
		}
		long long binpow(long long a, long long b) {
			long long res = 1;
			while (b > 0) {
				if (b & 1)
					res = (res%mod) * (a%mod);
				a = (a%mod) * (a%mod);
				b >>= 1;
			}
			return res%mod;
		}

		bool compare(const pair<ll,ll>&a,const pair<ll,ll>&b)
		{
			return (a.se<b.se);
		}
		ll lcm(ll a,ll b)
		{
			return(a*b)/__gcd(a,b);
		}
		vector<ll>s[2005];
		void SieveOfEratosthenes() 
		{  
			ll n=2005;
			bool prime[1000005]; 
			memset(prime, true, sizeof(prime)); 
			// s[0]=1;
			// s[1]=1;
			for (int p=2; p*p<=n; p++) 
			{ 
				s[p].pb(1);
				if (prime[p] == true) 
				{   
					for (int i=p+p; i<=n; i += p) {
						prime[i] = false; 
						s[i].pb(p);
						}
				} 
			} 
			// for(ll i=2;i<10005;i++)
			// {
			// 	if(prime[i])
			// 	{
			// 		// s.pb(i);
			// 	}
			// }
		} 
		void eea(ll a, ll b, ll & x, ll & y) {
		if (a == 0) {
			x = 0;
			y = 1;
			return ;
		}
		ll x1, y1;
		eea(b % a, a, x1, y1);
		x = y1 - (b / a) * x1;
		y = x1;
		return ;
	}
	ll modinverse(ll a,ll m)
	{
		ll x, y;
		eea(a, m, x, y);
		if (__gcd(a,m) != 1) {
		return -1;
		}
	else {
		x = (x % m + m) % m;
		cout << x << endl;
		return x;
	}
	}
		ll fact[1000007]={0};
		ll expo(ll x, ll y) {ll res=1;x=x%MOD;while(y>0){if(y&1)res=(1ll*res*x)%MOD;
		y=y>>1;x=(1ll*x*x)%MOD;} return res;}
		void facto() {fact[0]=1;fact[1]=1;for(ll i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%MOD;}
		ll npr(ll n,ll r) {facto(); ll res=1; res=fact[n]; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res; }
		ll ncr(ll n,ll r){ ll res=1; if(r>n-r)r=n-r; for(ll i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res;}
			ll C(ll n, ll k) {
    ll res = 1;
    for (ll i = 1; i <= k; ++i)
        res = ((res) * (n - k + i) / i)%MOD;
    return (ll)(res + 0.01)%MOD;
}
				
		int main()
		{
			fast
			queue<ll>q;
			ll n;
			cin>>n;
			for(ll i=1;i<=9;i++)
			{
				q.push(i);
			}
			ll t;
			for(ll i=1;i<=n;i++)
			{
				 t=q.front();
				if(t%10!=0)q.push(10*t+t%10-1);
				q.push(10*t+t%10);
				if(t%10!=9)q.push(10*t+t%10+1);
				q.pop();
			}
			cout<<t;
			}

 

Measured memory_bytes: 1920