akhauriyash/Code-Regression huggingface dataset:
while True:
    H, W = map(int, input().split())
    if H == W == 0:
        break
    for i in range(W):
        print('#', end='')
    print('')
    for i in range(H - 2):
        print('#', end='')
        for j in range(W - 2):
            print('.', end='')
        print('#')
    for i in range(W):
        print('#', end='')
    print('\n')

Measured memory_bytes: 8992
#include<stdio.h>

int main(){
  int x,y,z;
  scanf("%d%d",&x,&y);
	while(1){
		z=x%y;
		if(z==0){
			printf("%d\n",y);
			break;
		}
		else{
			x=y;
			y=z;
		}
	}
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
#define print printf("==================\n")
#define ll long long
#define pi acos(-1.0)
#define eps 1e-16
const ll INF = 1 << 30;
typedef pair<ll, ll  > payar;
typedef struct
{
    ll  x, y;
} point;
priority_queue<payar, vector<payar>,  greater<payar> > pq; ///accending
vector< pair<ll,payar  > > vpp;
vector < payar >  vp;

ll n ;
int ara[100005];

ll dp[100005];

ll par[100005];
ll cal(int pos)
{
    if(pos>=n )
    {
        return 0 ;
    }
    if(dp[pos]!=-1)
    {
        return dp[pos];
    }

    if(pos+1>n)
    {
        return 10000000000000000;
    }
    else if(pos+2>n)
    {

      return  dp[pos]=abs(ara[pos]-ara[pos+1]);

    }
    else{

        return dp[pos]=min( abs(ara[pos]-ara[pos+1])+ cal(pos+1), abs(ara[pos]-ara[pos+2])+cal(pos+2) );
    }

}
int main()
{

    cin>>n;
    memset(dp,-1,sizeof dp);
    for(int i =  1 ; i<=n ; i++)
    {
      //  cin>>ara[i];
        scanf("%d",&ara[i]);
    }
    cout<<cal(1);



    return  0 ;
}


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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] NK = Console.ReadLine().Split(' ');
            int N = int.Parse(NK[0]);
            int K = int.Parse(NK[1]);
            List<int> children = Enumerable.Range(1, N).ToList();
            for(int i = 0; i < K; i++){
                Console.ReadLine();
                String[] strAs = Console.ReadLine().Split(' ');
                foreach(String strA in strAs){
                    children.Remove(int.Parse(strA));
                }
            }
            Console.WriteLine(children.Count);
        }
    }
}


Measured memory_bytes: 28276
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

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

    ll a=0;
    ll c=1;
    ll ans=1;
    rep(i,10000000){
        ll tmp=(7*c)%k;
        a=(a+tmp)%k;
        if(a%k==0){
            cout<<ans<<endl;
            return 0;
        }
        c=(c*10)%k;
        ans++;
    }

    cout<<-1<<endl;
}


Measured memory_bytes: 3608
///not today

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

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair< int, pair<int, int> >
#define plpll pair< ll, pair<ll, ll> >

using namespace std;

int32_t main(){
      int a, b, c;
      cin >>a >>b >>c;
      cout <<min(a* b, c);
      return false;
}


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

using namespace std;

int main(){
    int time;
    int sum, rem, min_rem, c_rem;
    min_rem = 10;
    c_rem = 0;
    while(cin >> time){
        sum += time/10*10;
        rem = time % 10;
        if(rem != 0){
            min_rem = min(rem, min_rem);
            c_rem++; 
        }
    }
    sum += ((c_rem - 1)*10 + min_rem);
    cout << sum << "\n";    
}


Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define sz size()

const double EPS = 1e-10;
const int INF = 100000000;

int main(){
    int c=0;
    rep(i,4){
        int a;
        cin>>a;
        c+=a;
    }
    cout<<(int)c/60<<endl;
    cout<<c%60<<endl;
    
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define F first
#define S second
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define p_b push_back
#define all(c)              c.begin(), c.end()
using namespace std;
typedef long long ll; //printf("%lld ", ll); to out put long
typedef pair <int , int> pii;
typedef pair <ll , ll> pll;
const double eps = 1e-6;
const int MAXN = 1e6 + 5;
const ll MOD = 1e9 + 7;
bool ODD(ll O) {return (O % 2 != 0);}
ll gcd(ll a, ll b) {return __gcd(a , b);}
int dx[] = {1, 0, -1 ,0 , -1 , 0};
int dy[] = {0, 1, 0, -1 , -1 , 0};
ll power (ll x, ll y) {
    if(y == 0) return 1;
    if(ODD(y)) return x * power(x , y / 2) * power(x , y / 2);
    return power(x , y / 2) * power(x , y / 2);
}
/*------ never give up --------*/

int main () {
    int t = 1;
    //cin >> t;
    while(t--) {
        int a, b;
        cin >> a >> b;
        int ans = 1e9 + 5;
        for(int i = a; i <= b; i++) {
            for(int j = i + 1; j <= b; j++) {
                int x = i % 2019;
                int y = j % 2019;
                ans = min(ans , (x * y) % 2019);
                if(ans == 0) {
                    cout << ans;
                    return 0;
                }
            }
        }
        cout << ans;
    }
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
           
int main()
{
  int W, H, x, y, r;
  cin >>W>>H>>x>>y>>r;
   
  if(((r<=x)&&(x<=W-r))&&((r<=y)&&(y<=H-r)))
  {
    cout <<"Yes\n";
  }
  else
  {       
    cout <<"No\n";
  }
 
  return 0;
}

Measured memory_bytes: 1128
#include <bits/stdc++.h>
#include <math.h>
#include <list>
#include <cmath>
#include <queue>
using namespace std;
#define fo(i, n) for (ll i = 0; i < n; ++i)
#define ll long long
void sor(vector<ll> &x)
{
    sort(x.begin(), x.end());
}

void rev(vector<ll> &x)
{
    reverse(x.begin(), x.end());
}

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

list<ll> a[5];
void bfs(int src)
{
    queue<int> q;
    bool *vis = new bool[5 + 1]{0};
    q.push(src);
    vis[src] = true;
    while (!q.empty())
    {
        int node = q.front();
        cout << node << " ";
        q.pop();
        for (int n : a[node])
        {
            if (!vis[n])
            {
                q.push(n);
                vis[n] = true;
            }
        }
    }
}

ll max(ll x, ll y)
{
    if (x > y)
    {
        return x;
    }
    else
    {
        return y;
    }
}

ll min(ll x, ll y)
{
    if (x > y)
    {
        return y;
    }
    else
    {
        return x;
    }
}

void primeFactors(ll n, vector<ll> &vec)
{

    while (n % 2 == 0)
    {
        vec.push_back(2);
        n = n / 2;
    }

    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            vec.push_back(i);
            n = n / i;
        }
    }

    if (n > 2)
        vec.push_back(n);
}

ll lcm(ll x, ll y)
{
    return x * y / gcd(x, y);
}

ll g(ll x)
{
    for (ll i = 2; i <= sqrt(x); i++)
    {
        if (x % i == 0)
        {
            return i;
        }
    }
    return 0;
}

ll countDivisors(ll n)
{
    ll cnt = 0;
    for (ll i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            if (n / i == i)
                cnt++;

            else
                cnt = cnt + 2;
        }
    }
    return cnt;
}

ll bina(vector<ll> a, ll n, ll m)
{
    ll start = 0, end = n - 1;
    ll c = 0;
    if (m >= a[n - 1])
    {
        return n;
    }
    while (start <= end)
    {
        ll mid = (start + end) / 2;
        if (m >= a[mid])
        {
            c = mid + 1;
            start = mid + 1;
        }
        else
        {
            end = mid - 1;
        }
    }
    return c;
}

void solve()
{

    ll n;
    cin >> n;
    string s = "ACL";
    fo(i, n)
    {
        cout << s;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while (t--)
    {
        solve();
    }

    return 0;
}

//0 3 1 0 5 2 6
//0 0 1 2 3 5 6

Measured memory_bytes: 3628
n, d, a = gets.split(" ").map(&:to_i)
monsters = []
num = 0
boms = []
damage = 0
n.times do |i|
  monsters[i] = gets.split(" ").map(&:to_i)
end
a = a.to_f
monsters = monsters.sort_by {|y| y[0]}
monsters.each do |monster|
  while boms.length > 0
  	break if monster[0] <= boms[0][0] 
    damage -= boms[0][1]
    boms.shift
  end
  next if damage > monster[1]
  nu = ((monster[1]-damage)/a).ceil
  num += nu
  damage += nu*a
  boms.push([monster[0]+d*2, nu*a])
end
puts num


Measured memory_bytes: 22520
#include "bits/stdc++.h"
using namespace std ;



int main(){
	int N ;
	string s ;
	cin >>  N>> s ;
	if( N&1 ) {
		puts("No");
		return 0 ;
	}
	for( int i = 0 ; i < N / 2 ; i++ ){
		if( s[i] != s[i+N/2 ] ){
			puts("No");
			return 0 ;
		}

	}
	puts("Yes");

	return 0 ;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void) {
  int n[6];
  for(int i=0;i<6;i++)
    cin>>n[i];
  cout<<(n[0]+5*n[1]+10*n[2]+50*n[3]+100*n[4]+500*n[5]>=1000)<<endl;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define EM 100000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
using vint = vector<int>;
using vLL = vector<LL>;
using vvint = vector<vector<int>>;
using vvLL = vector<vector<LL>>;

vvint vp(100000);
vint ans, used(100000, 0);

void dfs(int v){
	for(auto s : vp[v]){
		if(!used[s]){
			ans.push_back(s);
			used[s] = 1;
			dfs(s);
			break;
		}
	}
}
int main(){
	int N, M;
	cin >> N >> M;
	for(int i = 0;i < M;i++){
		int ai, bi;
		cin >> ai >> bi;
		vp[ai-1].push_back(bi-1);
		vp[bi-1].push_back(ai-1);
	}
	ans.push_back(0);
	used[0] = 1;
	dfs(0);
	reverse(ans.begin(), ans.end());
	for(auto s : vp[0]){
		if(!used[s]){
			ans.push_back(s);
			used[s] = 1;
			dfs(s);
			break;
		}
	}
	cout << ans.size() << endl;
	for(auto s : ans)	cout << (s+1) << " ";
}

Measured memory_bytes: 10104
#include <iostream>
#include <stdio.h>
#include <strings.h>
#include <cstring>

using namespace std;
 
int main(){
    string ch;
    int m;
    int h;
    string po,mi;
    for(int i = 0; i < 10; i++){
        cin >> ch;
        if(ch == "-") break;
        cin >> m;
        for(int j = 0; j < m; j++){
            cin >> h;
            po = ch.substr(0, h);
            mi = ch.erase(0, h);
            ch = mi.insert((int)mi.size(), po);
        }
        cout << ch << endl;
    }
    return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
constexpr ll INF = 1e18;
constexpr double PI = 3.14159265358979;

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

  ll n, a = 1e9;
  cin >> n;  
  cout << "0 0 1000000000 1 " << (a-n%a)%a << " " << n/a+(n%a > 0) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// #define debug(a) cout << "["; rep(i,a.size()) cout << a[i] << ", "; cout<<"]"<< endl;

const ll mod = 1000000007;

int main() {
    ll n, d; cin >> n >> d;
    int ans = 0;
    rep(i, n){
        ll x, y; cin >> x >> y;
        if(x * x + y * y <= d * d) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>

int main(){
	int N;	//要素数
	int count = 0;	//入れ替えがあった回数
	int flag = 1;	//フラグ
	int s;			//ソート用変数
	int index = 0;	//未ソート部分の先頭インデックス
	
	//要素数の入力
	scanf("%d",&N);
	
	int A[N];	//配列
	
	for(int i = 0;i < N;i++){
		scanf("%d",&A[i]);
	}
	
	while(flag){
		flag = 0;
		for(int j = N - 1;j >= index + 1;j--){
			if(A[j] < A[j - 1]){
				s = A[j];
				A[j] = A[j - 1];
				A[j - 1] = s;
				
				flag = 1;
				count++;
			}
		}
		//インデックスを後ろにずらす
		index++;
	}
	
	//配列の出力
	for(int i = 0;i < N;i++){
		if(i == N - 1){
			printf("%d\n",A[i]);
		}
		else{
			printf("%d ",A[i]);
		}
	}
	
	//交換回数の出力
	printf("%d\n",count);
	
	return 0;
}



Measured memory_bytes: 2016
#include <bits/stdc++.h>
#define MOD 998244353

using namespace std;

typedef long long ll;

ll pow_mod(ll x,int k) {
  ll ans=1;
  while (k) {
  	if (k&1) ans=ans*x%MOD;
  	x=x*x%MOD;
  	k>>=1;
  }
  return ans;
}

void fwt(int *p,int len) {
  for(int i=1;i<len;i<<=1)
    for(int j=0;j<len;j++)
      if (j&i) {
      	int u=p[j^i],v=p[j];
      	p[j^i]=(u+v)%MOD;
      	p[j]=(u-v+MOD)%MOD;
	  }
}

int p[1<<18],q[1<<18],ans[1<<18];
ll l[(1<<18)+1],r[(1<<18)+1];

void solve(int n) {
  fwt(p,1<<n);
  l[0]=r[(1<<n)]=1;
  for(int i=1;i<(1<<n);i++) l[i]=l[i-1]*(1LL-p[i]+MOD)%MOD;
  for(int i=(1<<n)-1;i>0;i--) r[i]=r[i+1]*(1LL-p[i]+MOD)%MOD;
  for(int i=1;i<(1<<n);i++) {
  	ll s=l[i-1]*r[i+1]%MOD;
  	q[0]=(q[0]-p[i]*s%MOD+MOD)%MOD;
  	q[i]=(q[i]-p[0]*s%MOD+MOD)%MOD;
  }
  ll s=0;
  for(int i=0;i<(1<<n);i++) s=(s+q[i])%MOD;
  fwt(q,1<<n);
  ll inv=pow_mod((ll)r[1]*r[1]%MOD,MOD-2);
  for(int i=0;i<(1<<n);i++) ans[i]=r[1]*(q[i]-s+MOD)%MOD*inv%MOD;
}

int main() {
  int n;
  scanf("%d",&n);
  ll s=0;
  for(int i=0;i<(1<<n);i++) {
  	scanf("%d",&p[i]);
  	s+=p[i];
  }
  s=pow_mod(s,MOD-2);
  for(int i=0;i<(1<<n);i++) p[i]=p[i]*s%MOD;
  solve(n);
  for(int i=0;i<(1<<n);i++) printf("%d\n",ans[i]);
  return 0;
}

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

using namespace std;

string S;
int N;
bool az=true;
int cnt =0;

int main(){
  cin >> S;
  for(int i=0;i<S.size();i++){
    if(az && S[i]=='A'){
      az = false;
    }
    if(!az && S[i]=='Z'){
      az = true;
      cnt++;
    }
  }

  if(cnt==0){
    cout << "-1" << endl;
    return 0;
  }


    for(int i=0;i<cnt;i++){
      cout << "AZ";
    }
    cout << endl;

}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int a[5];
    for(int i =0;i<5;i++){
        int b;
        cin >> b;
        a[i] = b;
    }
    int k;
    cin >> k;
    string frag = "Yay!";
    for(int i = 0;i<5;i++){
        for(int j = i+1;j<5;j++){
               if(abs(a[j] - a[i]) > k){
                   frag = ":(";
               }
        }
    }
    cout << frag << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int main()
{
	int a,b;
	cin>>a>>b;
	if(a>0)cout<<"Positive"<<endl;
	else if((a<0&&b<0)&&((b-a)%2))cout<<"Positive"<<endl;
	else if((a<0&&b<0)&&((b-a)%2==0))cout<<"Negative"<<endl;
	else if(a<=0&&b>=0)cout<<"Zero"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int n; sc(n)
    int ans = 0;
    vector<int> a(n);
    for (int i = 0; i < n; i++) sc(a[i])
    for (int i = 0; i < n; i++) ans += a[i];
    cout << ans - n << endl;
    return 0;
}

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

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

using namespace std;

using ll = long long;
struct E {
  ll to;
  ll c;
};

ll n;
ll k;
ll s;
ll x[3000],y[3000],z[3000];
vector<vector<E>> G;
vector<bool> used;


void dfs(int i, vector<ll>& m){
  for (auto v : G[i]) {
    if (!used[v.to]) {
      used[v.to] = true;
      m.push_back(v.to);
      dfs(v.to, m);
      break;
    }
  }
}

ll con (int i, int j) {
  for (auto e : G[i]) {
    if (j == e.to) {
      return e.c;
    }
  }
  return 0;
}

void solve(void) {
  G.clear();

  rep (i,n) G.push_back(vector<E>());

  rep(i,n) {
    rep (j,n) {
      if (i >= j) continue;

      ll xd = s - abs(x[i] - x[j]);
      ll yd = s - abs(y[i] - y[j]);
      ll zd = s - abs(z[i] - z[j]);
      if (xd <= 0 || yd <= 0 || zd <= 0) continue;
      ll cm = -2 * (xd * yd + yd * zd + zd * xd);
      G[i].push_back((E){j,cm});
      G[j].push_back((E){i,cm});
    }
  }

  used.resize(n);
  ll ans = 0;
  rep (i,n) {
    vector<ll> vs;
    fill(used.begin(), used.end(), false);
    vs.push_back(i);
    used[i] = true;
    dfs(i, vs);

    if (vs.size() < k || k == 1) continue;
    bool flag = false;
    if (k >= 3 && con(vs[0],vs.back()) != 0) {
      flag = true;
    }

    if (flag && vs.size() == k) {
      ll sum = 0;
      rep (i,vs.size() - 1) {
        sum += con(vs[i],vs[i+1]);
      }
      sum += con(vs[0], vs.back());
      ans = min(ans, sum);
    } else {
      ll sum = 0;
      rep (i, vs.size()) {
        if (i == 0) {
          rep (j, k-1) {
            sum += con(vs[j], vs[j+1]);
          }
        } else {
          if (!flag && i + k - 1 >= vs.size()) break;
          sum += con(vs[(i + k - 2) % vs.size()], vs[(i + k - 1) % vs.size()]) - con(vs[i - 1], vs[i]);
        }
        ans = min(sum, ans);
      }
    }
  }
  if (k > 1 && ans == 0) cout << -1 << endl;
  else cout << s * s * 6 * k + ans << endl;
}

signed main (void) {
  while(true) {
    cin >> n >> k >> s;
    if (n == 0) break;

    rep (i,n) cin >> x[i] >> y[i] >> z[i];
    solve();
  }
}


Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, T t){return v2<T>(r, vector<T>(c, t));}

int n, t;
void solve(){
    cin >> n >> t;
    vector<int> a(n), mi(n);
    for(int i = 0; i < n; i++)cin >> a[i];

    mi[0] = a[0];
    for(int i = 1; i < n; i++) mi[i] = min(a[i], mi[i-1]);

    map<int, int> prof;
    for(int i = 1; i < n; i++) prof[a[i] - mi[i-1]]++;

    cout << prof.rbegin()->second << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 8724
n = int(input())
data = list(map(int, input().split()))
d = {}

for i in data:
    if d.get(i) is None:
        d[i] = 1
    else:
        d[i] += 1

ans = 0
for i, score in d.items():
    if score < i:
        ans += score
    else:
        ans += score - i

print(ans)

Measured memory_bytes: 18164
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);

int main ()
{
    fastio
        string s1;
        string s2;
        cin>>s1;
        cin>>s2;
        ll n = s1.size();
        ll m = s2.size();
        ll dp[n+1][m+1];
        for(ll i=0; i<=m; i++){
            dp[0][i] = 0;
        }
        for(ll i=0; i<=n; i++){
            dp[i][0] = 0;
        }
        for(ll i=1; i<=n; i++){
            for(ll j=1; j<=m; j++){
                if(s1[i-1]==s2[j-1])
                    dp[i][j]= dp[i-1][j-1]+1;
                else
                    dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
            }
        }
        string ans = "";
        ll i=n; ll j=m;
        while(i>0 && j>0){
        ll check = dp[i][j];
           if(check ==dp[i][j-1]){
            j = j-1;
           }
           else if(check==dp[i-1][j]){
            i=i-1;
           }
           else{
            ans= s1[i-1]+ans;
            i-=1;
            j-=1;
           }
        }
        cout<<ans<<endl;
    return 0;
}


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

vector<int> prime;
bool erased[110001];

int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    for (ll i = 2; i <= 110000; i++) {
        if (!erased[i]) {
            prime.push_back(i);
            for (ll j = i * 2; j <= 110000; j += i) {
                erased[j] = true;
            }
        }
    }

    ll x; cin >> x;
    for (auto it : prime) {
        if (it >= x) {
            cout << it << '\n';
            return 0;
        }
    }


    return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
#include <memory>
using namespace std;

struct node_t {
        shared_ptr<node_t> left, right;
        node_t(shared_ptr<node_t> l, shared_ptr<node_t> r) : left(l), right(r) {}
};

using node = shared_ptr<node_t>;

node new_node() {
        return node(new node_t(NULL, NULL));
}

int main() {
        int n;
        long long l;
        scanf("%d %lld", &n, &l);
        vector<string> s(n);
        for (int i = 0; i < n; i ++) {
                cin >> s[i];
        }
        node root = new_node();
        function<void (node, const string&, int)> dfs = [&](node u, const string &str, int depth) {
                if (depth >= (int) str.size()) {
                        return;
                }
                if (str[depth] == '0') {
                        if (u->left == NULL) {
                                u->left = new_node();
                        }
                        dfs(u->left, str, depth + 1);
                } else {
                        if (u->right == NULL) {
                                u->right = new_node();
                        }
                        dfs(u->right, str, depth + 1);
                }
        };
        for (int i = 0; i < n; i ++) {
                dfs(root, s[i], 0);
        }
        function<long long (long long)> get_grundy = [&](long long x) {
                int ctz = __builtin_ctzll(x);
                return 1LL << ctz;
        };
        long long ans = 0;
        function<void (node, int)> dfs2 = [&](node u, int depth) {
                if ((u->left == NULL && u->right != NULL) || (u->left != NULL && u->right == NULL)) {
                        ans ^= get_grundy(l - depth);
                }
                if (u->left != NULL) {
                        dfs2(u->left, depth + 1);
                }
                if (u->right != NULL) {
                        dfs2(u->right, depth + 1);
                }
        };
        dfs2(root, 0);
        puts(ans ? "Alice" : "Bob");
        return 0;
}


Measured memory_bytes: 20608
#include <iostream>                                             
#include <vector>                                               
using namespace std;                                            
                                                                
int main(void) {                                                
  int r, c;                                                     
  cin >> r >> c;                                                
  vector< vector<int> > rc(r+1,vector<int>(c+1,0));             
  for (int i=0; i<r; i++) {                                     
    for (int j=0; j<c; j++) {                                   
      cin >> rc[i][j];                                          
    }                                                           
  }                                                             
  for (int i=0; i<r; i++) {                                     
    for (int j=0; j<c; j++) {                                   
      rc[i][c] += rc[i][j];                                     
    }                                                           
  }                                                             
  for (int j=0; j<c+1; j++) {                                   
    for (int i=0; i<r; i++) {                                   
      rc[r][j] += rc[i][j];                                     
    }                                                           
  }                                                             
  for (int i=0; i<r+1; i++) {                                   
    for (int j=0; j<c+1; j++) {                                 
      cout << rc[i][j] << flush;                                
      cout << (j-c?" ":"\n") << flush;                          
    }                                                           
  }                                                             
  return 0;                                                     
}                                  

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  cin >> N;
  cout << "ABC" << N << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s, t;
    cin >> s >> t;
    int count = 0;
    for(int i=0; i < s.size(); i++){
        if(s.at(i) != t.at(i)) count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3916
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a = inp()
        a -= 1
        g[i].append(a)
        g[a].append(i)
    return n,g

def gcd(a, b): #最大公約数
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

def lcm(a, b): #最小公約数
    return((a*b)//gcd(a,b))

def main():
    n = inp()
    a = inpl()
    LCM = a[0]
    for e in a:
        LCM = lcm(LCM,e)
    sumation = 0
    for e in a:
        sumation = (sumation + pow(e,mod-2,mod))%mod
    print((LCM%mod)*sumation%mod)
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 72276
n,m=map(int,input().split())
g=[[] for i in range(1+n)]
v=[0]*(1+n)
for i in range(m):
    a,b=map(int,input().split())
    g[a].append(b)
    g[b].append(a)
v[a]=v[b]=1

def dfs(p):
    path=[]
    while p:
        c=p.pop()
        path.append(c)
        v[c]=1
        flg=True
        for i in g[c]:
            if v[i]==0:
                flg=p.append(i)
        if flg:
            return path

ans=dfs([a])[::-1]+dfs([b])
print(len(ans))
print(*ans)

Measured memory_bytes: 66208
#include<cstdio>
#include<iostream>
#include<unordered_set>
#include<string>
#define MAX 200010
int mem[MAX]={0};
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int temp;
		scanf("%d",&temp);
		mem[temp]+=1;
	}
	for(int i=1;i<=n;i++){
		printf("%d\n",mem[i]);
	}
	return 0;
} 

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

using namespace std;
using ll = long long;

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

  int k, a, b;
  cin >> k >> a >> b;
  for (int i = a; i <= b; i++) {
    if (i % k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;

  return 0;
}



Measured memory_bytes: 3656
import sys

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
if __name__ == '__main__':
    input = sys.stdin.readline
    n, m = map(int, input().split())
    uf = UnionFind(n)
    for i in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        uf.union(a, b)

    print(uf.group_count()-1)

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

int main() {
  int n;
  cin>>n;
  vector<P> path[n];
  rep(i,n-1){
    int a,b,c;
    cin>>a>>b>>c;
    path[a-1].push_back(P(b-1,c));
    path[b-1].push_back(P(a-1,c));
  }
  int q,k;
  cin>>q>>k;
  k--;
  ll dis[n];
  rep(i,n) dis[i]=-1;
  dis[k]=0;
  queue<int> que;
  que.push(k);
  while(que.size()){
    int r=que.front();
    que.pop();
    rep(i,path[r].size()){
      if(dis[path[r][i].first]==-1){
        dis[path[r][i].first]=dis[r]+path[r][i].second;
        que.push(path[r][i].first);
      }
    }
  }
  rep(i,q){
    int x,y;
    cin>>x>>y;
    cout<<dis[x-1]+dis[y-1]<<endl;
  }
}

Measured memory_bytes: 8820
h, w = list(map(int, input().split()))
ss = []
for _ in range(h):
    s = input().strip()
    if '#' in s:
        ss.append(s)
new_h = len(ss)
dels = []
for i in range(w):
    rep = True
    for j in range(new_h):
        if ss[j][i] == '#':
            rep = False
    if rep:
        dels.append(i)
for i in range(new_h):
    now = ss[i]
    pri = []
    for j in range(w):
        if j not in dels:
            pri.append(now[j])
    print(''.join(pri))


Measured memory_bytes: 39024
//		HYSO SERIOUS? WHY SO SERIOUS                            RIOUS? WHY SO SERIOUS? WHYSO SERIO
//		 ERIOUS? WHY SO SERIOUS ? WHY                          WHY SO SERIOUS? WHY SOSERIOUSWHYS
//		       OSERIOUS? WHY SO SERIOU         SERIOUS        ERIOUS? WHY SO SERIOUS? WHYS
//		          WHY SO SERIOUS? WHY SOSERIOUS? WHYSOSERIOUS? WHY SO SERIOUS?WHY SO SE
//		           ERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SOSERIO
//		           WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WH
//		            SERIOUS?WHYSO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHYSO SE
//		              ?WHYSOSERIOUS?WHY SO SERIOUS? WHY SO SERIOUS?WHYSO SERIOUS?
//		                           OSERIOUS? WHY SO SERIOUS?WHYSOSER
//		                                 HYSOSERIOUS?WHYSOSERI
//		                                     SOSERIOUS?W
//		                                         SER
//		                                          W


#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;
#include<bits/stdc++.h>
#include <algorithm>
#define ll long long int
#define read(a) long long int a; cin>>a;
#define readstr(s) string s; cin>>s;
#define readarr(a,l) long long int a[l]={0}; for(ll i=0;i<l;i++) cin>>a[i];
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rloop(i,a,b) for(ll i=a;i>b;i--)
#define ff first
#define ss second
#define readmtrx(i,j,a,b) ll arr[a][b]={0};for(ll i=0;i<a;i++)for(ll j=0;j<b;j++) cin>>arr[i][j];
#define v(pi) vector<ll>pi
#define vp(pi) vector<pair<ll,ll>>pi
#define fast ios_base::sync_with_stdio(false);cin.tie(0);
#define pb(p) push_back(p)
#define mp make_pair
#include <cmath>
#include <map>
#include <string>
#define mi(lol) map<ll,ll>lol
#define fsort(vec) sort(vec.begin(),vec.end())
#define rsort(vec) sort(vec.begin(),vec.end(),compare)
#define inf ll inf=INT_MAX
//sorting according to the second element vector 

bool compare(pair<ll,ll> p,pair<ll,ll> q){
	return p.second < q.second;	
}

//   example:-
//   sort(vec.begin(),vec.end(),compare);


int main() {
	fast;
// #ifndef ONLINE_JUDGE
//   freopen("input.txt","r",stdin);
//   freopen("output.txt","w",stdout);
// #endif
	read(a)
	read(b)
	ll m=a*(a-1)/2;
	ll n=b*(b-1)/2;
	cout<<m+n<<endl;
	return 0;
}


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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;

int H, W, K;
char S[330][330];
int ma[330][330];

signed main() {
    cin >> H >> W >> K;
    int kidx = -1;
    rep(i, H) {
        int kk = 0;
        rep(j, W) {
            cin >> S[i][j];
            if (S[i][j] == '#')kk++;
        }
        if (kk == 0) {
            if (kidx == -1) {
                //後で
            } else {
                rep(j, W) {
                    ma[i][j] = ma[i - 1][j];
                }
            }
        } else {
            if (kidx == -1) {
                //今までの行全てに適用
                kidx += 1;
                bool flag = false;
                rep(j, W) {
                    if (S[i][j] == '#' && flag)kidx++;
                    else if (S[i][j] == '#')flag = true;
                    ma[i][j] = kidx;
                }
                rep(ii, i) {
                    rep(j, W) {
                        ma[ii][j] = ma[i][j];
                    }
                }
            } else {
                kidx += 1;
                bool flag = false;
                rep(j, W) {
                    if (S[i][j] == '#' && flag)kidx++;
                    else if (S[i][j] == '#')flag = true;
                    ma[i][j] = kidx;
                }
            }
        }
    }
    rep(i, H) {
        rep(j, W) {
            cout << ma[i][j] + 1;
            if (j != W - 1)cout << " ";
        }
        cout << endl;
    }
    return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<int,int> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int,pair<int,int> > iii;
#define PI 3.141592653589793
#define mod 1000000009
# define N 300005
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=((ans%m)*(a%m))%m; b/=2; a=((a%m)*(a%m))%m; } return ans%m; }
# define INF (ll)1e18
# define LG 20	
typedef pair<int,pair<int,int> > pii;
# define INF1 (int)1e9
# define maxn 300005


ll cf[2][maxn];

int main()
{
	int n;
	string s;
	cin >> n;
	cin >> s;
	ll sume=0,sumw=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='E')
		{
			sume++;
			
		}
		else
		{
			sumw++;
			
		}
		cf[0][i]=sume;
		cf[1][i]=sumw;
	}

    ll fans=3000000;
    ll ans=0;
   
	for(int i=0;i<n;i++)
	{
		ans=0;
		ans+=cf[1][i-1];
		//trace2(i,ans);
		ans+=cf[0][n-1]-cf[0][i];
        //trace2(i,ans);
		if(ans<fans)
			fans=ans;
	}
	cout << fans;
}

Measured memory_bytes: 5380
N, *A = map(int, open(0).read().split())
P = [-e for e in set(A)]
P.sort()
P.append(1)
MP = {e: i for i, e in enumerate(P)}
N += 1

data = [0]*(N+1)
def get(k):
    r = 0
    while k:
        r += data[k]
        k -= k & -k
    return r
def add(k, x):
    while k <= N:
        data[k] += x
        k += k & -k
N0 = 2**(N-1).bit_length()
def lower_bound(x):
    w = i = 0
    k = N0
    while k:
        if i+k <= N and w + data[i+k] <= x:
            w += data[i+k]
            i += k
        k >>= 1
    return i+1

for a in A:
    j = MP[-a]
    i = lower_bound(get(j+1))
    if i != N+2:
        add(i, -1)
    add(j+1, 1)
print(get(N))

Measured memory_bytes: 72180
#include <iostream>
#include <string>
#include <cstdlib>

typedef long long int64;

int main (void) {
  int64 n, a, b;
  std::cin >> n >> a >> b;
  int64 p = n / (a + b);
  int64 q = n % (a + b);
  int64 ans = a * p + std::min(a, q);
  std::cout << ans << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }


int main() {
	
	ll n;
	cin >> n;
	if (n <= 999) cout << "ABC" << endl;
	else cout << "ABD" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ull unsigned long long
# define ll long long
# define mod 1000000007LL 
using namespace std;
int main()
{
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s=="RRS" || s=="SRR")
    cout<<2;
    else if(s=="SSS")
    cout<<0<<"\n";
    else if(s=="RRR")
    cout<<3;
    else
    {
        cout<<1;
    }
    
    
    
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <cstring>
#include <set>
using namespace std;

typedef long long ll;

const ll MOD = 998244353;
const int MAX_N = 200005;

ll DP[MAX_N][3][3][2];

char f(char a, char b) {
    if(a > b) swap(a,b);
    if(a == 'a' && b == 'b') return 'c';
    if(a == 'a' && b == 'c') return 'b';
    return 'a';
}

int brut(string S) {
    set<string> words;
    words.insert(S);
    
    bool go = true;
    while(go) {
        go = false;
        for(string w : words) {
//             cout << "+" << w << "\n";
            string ww = w;
            if(ww[0] != ww[1]) {
                char l = f(ww[0], ww[1]);
                ww[0] = l;
                ww[1] = l;
                if(words.find(ww) == words.end()) {
                    words.insert(ww);
//                     cout << ww << endl;
                    go = true;
                    break;
                }
            }
            ww = w;
            if(ww.length() == 3 && ww[1] != ww[2]) {
                char l = f(ww[1], ww[2]);
                ww[1] = l;
                ww[2] = l;
                if(words.find(ww) == words.end()) {
                    words.insert(ww);
//                     cout << ww << endl;
                    go = true;
                    break;
                }
            }
        }
    }
    
    return words.size();
}

int main() {
    string S;
    cin >> S;
    int n = S.length();
    
    
    
    if(n <= 3) {cout << brut(S); return 0;}
    
    bool the_same = true;
    for(int i = 0; i < n; i++) if(S[0] != S[i]) the_same = false;
    if(the_same) {
        cout << "1";
        return 0;
    }
    
    bool consecutive = false;
    for(int i = 0; i < n - 1; i++) if(S[i] == S[i+1]) consecutive = true;
    
    int S_sum = 0;
    for(int i = 0; i < n; i++) S_sum += (S[i] - 'a');
    S_sum %= 3;
    
    DP[1][0][0][0] = 1;
    DP[1][1][1][0] = 1;
    DP[1][2][2][0] = 1;
    
    for(int i = 2; i <= n; i++) {
        for(int sum = 0; sum < 3; sum++) {
            for(int ost = 0; ost < 3; ost++) {
                DP[i][sum][ost][0] = DP[i - 1][(sum - ost + 3) % 3][(ost + 1) % 3][0];
                DP[i][sum][ost][0] += DP[i - 1][(sum - ost + 3) % 3][(ost + 2) % 3][0];
                DP[i][sum][ost][0] %= MOD;
                
                DP[i][sum][ost][1] = DP[i - 1][(sum - ost + 3) % 3][ost][0];
                DP[i][sum][ost][1] += DP[i - 1][(sum - ost + 3) % 3][ost][1];
                DP[i][sum][ost][1] %= MOD;
                DP[i][sum][ost][1] += DP[i - 1][(sum - ost + 3) % 3][(ost + 1) % 3][1];
                DP[i][sum][ost][1] %= MOD;
                DP[i][sum][ost][1] += DP[i - 1][(sum - ost + 3) % 3][(ost + 2) % 3][1];
                DP[i][sum][ost][1] %= MOD;
            }
        }
    }
    cout << (((consecutive ? 0 : 1) + DP[n][S_sum][0][1]) % MOD + (DP[n][S_sum][1][1] + DP[n][S_sum][2][1]) % MOD) % MOD;

    return 0;
}

Measured memory_bytes: 28676
#!/usr/bin/env python3
import sys


def solve(N: int, T: int, c: "List[int]", t: "List[int]"):
    ret = float('inf')
    for i in range(N):
        if t[i] <= T:
            ret = min(ret, c[i])
    if ret == float('inf'):
        print('TLE')
    else:
        print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    c = [int()] * (N)  # type: "List[int]" 
    t = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        c[i] = int(next(tokens))
        t[i] = int(next(tokens))
    solve(N, T, c, t)

if __name__ == '__main__':
    main()


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

int main() {
  int H, W, K;
  cin >> H >> W >> K;
  vector<vector<char>> grid(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> grid[i][j];
    }
  }
  int ans = 0;
  vector<char> yoko(W, 'r');
  for (int bit1 = 0; bit1 < (1<<H); bit1++) {
    for (int bit2 = 0; bit2 < (1<<W); bit2++) {
      int black = 0;
      auto grid_copy = grid;
      for (int i = 0; i < H; i++) {
        if (bit1 & (1<<i)) grid_copy[i] = yoko;
      }
      for (int i = 0; i < W; i++) {
        if (bit2 & (1<<i)) {
          for (int j = 0; j < H; j++) {
            grid_copy[j][i] = 'r';
          }
        }
      }
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          if (grid_copy[i][j] == '#') black++;
        }
      }
      if (black == K) ans++;
    }
  }
  cout << ans << endl;
}


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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

inline int getIdx(char c) {
    return c - 'A';
}

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

    int n;
    cin >> n;

    array<ll, 3> v;
    int cnt0 = 0;
    for (int i = 0; i < 3; i++) {
        cin >> v[i];
        cnt0 += (v[i] == 0);
    }

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (s == "AB") a[i] = 2;
        else if (s == "BC") a[i] = 0;
        else a[i] = 1;
    }

    string ans = "";
    for (int i = 0; i < n; i++) {
        if (cnt0 == 3) {
            cout << "No\n";
            return 0;
        } else if (cnt0 == 2) {
            if (v[a[i]] != 0) {
                cout << "No\n";
                return 0;
            }

            int i1 = (a[i] + 1) % 3;
            int i2 = (a[i] + 2) % 3;
            if (v[i1] != 0) {
                --v[i1];
                ++v[i2];
                ans += 'A' + i2;
            } else {
                --v[i2];
                ++v[i1];
                ans += 'A' + i1;
            }
        } else if (cnt0 == 1 && v[a[i]] != 0) {
            int i1 = (a[i] + 1) % 3;
            int i2 = (a[i] + 2) % 3;

            if (v[i1] == 0) {
                --v[i2];
                ++v[i1];
                ans += 'A' + i1;
            } else {
                ++v[i2];
                --v[i1];
                ans += 'A' + i2;
            }
        } else if (cnt0 == 1 && i + 1 < n && a[i + 1] != a[i]) {
            int i1 = (a[i] + 1) % 3;
            int i2 = (a[i] + 2) % 3;

            if (a[i + 1] == i1) {
                --v[i1];
                ++v[i2];
                ans += 'A' + i2;
            } else {
                ++v[i1];
                --v[i2];
                ans += 'A' + i1;
            }
        } else {
            int i1 = (a[i] + 1) % 3;
            int i2 = (a[i] + 2) % 3;
            --v[i1];
            ++v[i2];

            ans += 'A' + i2;         
        }

        cnt0 = 0;
        for (int j = 0; j < 3; j++) {
            cnt0 += (v[j] == 0);            
        }

        // cerr << v[0] << " " << v[1] << " " << v[2] << newl;
    }

    cout << "Yes\n";
    for (char c : ans) {
        cout << c << newl;
    }
    return 0;
}

Measured memory_bytes: 4048
local function combination(x,y)
    if y==0 then
        return 1
    else
        return x*combination(x-1,y-1)//y
    end
end

n,p=io.read("*n","*n")
local co=0
local ce=n
for i=1,n do
    if io.read("*n")%2==1 then
        co=co+1
        ce=ce-1
    end
end

local cootal=0
local ceotal=0
for i=p,co,2 do
    cootal=cootal+combination(co,i)
end
for i=0,ce do
    ceotal=ceotal+combination(ce,i)
end
print(cootal*ceotal)

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

#define ll long long

const int MAX = 1e3, MOD = 1e9+7;
int H, W, dp[MAX][MAX];
string grid[MAX];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> H >> W;
	for(int i = 0; i < H; ++i)
		cin >> grid[i];
	dp[0][0] = 1;
	for(int i = 0; i < H; ++i){
		for(int j = 0; j < W; ++j){
			if(i)
				(dp[i][j] += dp[i-1][j]) %= MOD;
			if(j)
				(dp[i][j] += dp[i][j-1]) %= MOD;
			if(grid[i][j]=='#')
				dp[i][j] = 0;
		}
	}
	cout << dp[H-1][W-1] << '\n';
	return 0;
}



Measured memory_bytes: 8580
#include <stdio.h>

int main(void){
    int ls,h,m,s;
    scanf("%d",&ls);
    h = ls / 3600;
    m = ls % 3600 / 60;
    s = ls % 60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


Measured memory_bytes: 2064
#include<bits/stdc++.h>
#define mo 998244353
#define N 200005
using namespace std;
char s[N];
int f[N][3][3];
int power(int x,int y){
	int s=1;
	for (;y;y/=2,x=1ll*x*x%mo)
		if (y&1) s=1ll*s*x%mo;
	return s;
}
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	if (n==2){
		printf("%d\n",1+(s[1]!=s[2]));
		return 0;
	}
	if (n==3){
		if (s[1]==s[2]&&s[2]==s[3]) puts("1");//3
		else if (s[1]==s[2]||s[2]==s[3]) puts("6");//12
		else if (s[1]==s[3]) puts("7");//6
		else puts("3");//6
		return 0;
	}
	int fl=1;
	for (int i=1;i<n;i++)
		if (s[i]!=s[i+1]) fl=0;
	if (fl){
		puts("1");
		return 0;
	}
	int ans=power(3,n-1);
	int v=0;
	for (int i=1;i<=n;i++)
		v=(v+s[i]-'a')%3;
	for (int i=0;i<3;i++)
		f[1][i][i]=1;
	for (int i=2;i<=n;i++)
		for (int j=0;j<3;j++)
			for (int k=0;k<3;k++)
				for (int l=0;l<3;l++)
					if (k!=l)
						f[i][(j+l)%3][l]=(f[i][(j+l)%3][l]+f[i-1][j][k])%mo;
	for (int i=0;i<3;i++)
		ans=(ans+mo-f[n][v][i])%mo;
	fl=1;
	for (int i=1;i<n;i++)
		if (s[i]==s[i+1]) fl=0;
	printf("%d\n",(ans+fl)%mo);
}


Measured memory_bytes: 7424