akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
string res[4] = {"maerd","remaerd","esare","resare"};
int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int cnt = 0;
    reverse(s.begin(),s.end());
    int i = 0;
    bool ok = true;
    while(i < n){
        if(i+2 >=n){
            ok = false;
            break;
        }
        string hoge = "";
        hoge += s[i];
        hoge += s[i+1];
        hoge += s[i+2];

        if( i+2 < n &&hoge == "mae"){
            if(i+4 >=n){
                ok = false;
                break;
            }
            hoge += s[i+3];
            hoge += s[i+4];
            if(hoge != res[0]){
                ok = false;
                break;
            }
            i += 5;


        }
        else if(i+2 < n &&hoge == "rem"){
            if(i+6>=n ){
                ok = false;
                break;
            }
            hoge += s[i+3];
            hoge += s[i+4];
            hoge += s[i+5];
            hoge += s[i+6];
            if(hoge != res[1]){
                ok = false;
                break;
            }
            i += 7;

        }
        else if(i+2 < n &&hoge == "esa"){
               if(i+4 >=n){
                ok = false;
                break;
            }
            hoge += s[i+3];
            hoge += s[i+4];
            if(hoge != res[2]){
                ok = false;
                break;
            }
            i += 5;


        }
        else if(i+2 < n &&hoge== "res"){
            if(i +5 >= n){
                ok = false;
                break;
            }
            hoge += s[i+3];
            hoge += s[i+4];
            hoge += s[i+5];
            if(hoge!= res[3]){
                ok = false;
                break;
            }
            i+= 6;

        }
        else{
            ok = false;
            break;
        }
    }
    if(ok)puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 512
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort((x).rbegin(),(x).rend())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
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;}
// clang-format on

void solve(long long A, long double B) {
  cout << fixed << setprecision(0) << floor((long double)A * B) << endl;
}

// clang-format off
int main() {
  long long A;
  scanf("%lld",&A);
  long double B;
  scanf("%Lf",&B);
  solve(A, B);
  return 0;
}


Measured memory_bytes: 3868
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const ll inf = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+5;
//int a[N];

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int n;

    cin >> n;

    cout << pow(n, 3);

    return 0;
}


Measured memory_bytes: 256
S = input()
T = input()
N = len(S)

d = {chr(i):chr(i) for i in range(97,97+26)}

ans = 'Yes'
for i in range(N):
    now_si = d[S[i]]
    for k,v in d.items():
        if v == now_si:
            d[k] = T[i]
        elif v == T[i]:
            d[k] = now_si

for i in range(N):
    if d[S[i]] != T[i]:
        ans = 'No'


print(ans)



Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <set>
#define MaxN 1000006
using namespace std;
vector<int> prime(MaxN,1);
vector<int> fact(MaxN,0);

int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}
void sieve()
{
    for(int i = 2; i < MaxN; i++)
    {
        if(!prime[i]) continue;
        fact[i] = i;
        long long j = i+i;
        while(j < MaxN)
        {
            if(prime[j] == 1)
            {
                prime[j] = 0;
                fact[j] = i;
            }

            j += i;
        }
    }
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    set<int> ss;
    sieve();
    for(int i = 0; i< n;i++) scanf("%d",&a[i]);
    int flag = 1;
    int g = a[0];
    for(int i = 0; i< n;i++)
    {
        if(i>0) g = gcd(g,a[i]);
        int now = a[i];
       // cout << a[i] << " : ";
        while(now > 1)
        {
            int f = fact[now];
          //  cout << f << " " ;
            while(now%f == 0) now /= f;
            if(ss.find(f) != ss.end() && f != 1)
            {
                //cout << a[i] << " " << now << " " << f << endl;
                flag = 0;
                break;
            }
            ss.insert(f);
        }
        //cout << endl;
    }
    if(flag)
        cout << "pairwise coprime" << endl;
    else if(g==1)
        cout << "setwise coprime" << endl;
    else
        cout << "not coprime" << endl;
}


Measured memory_bytes: 18576
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

def bfs(c,sy=0, sx=0, gy=0, gx=0, blocks=['#'], dire=[(1,0), (0,1), (-1,0), (0,-1)], return_maximum_distance=False):
    H = len(c)
    W = len(c[0])
    distance_limit = H*W+1
    dist = [[distance_limit]*W for i in range(H)]

    q = deque()

    q_append = q.append
    q_popleft = q.popleft

    if (type(sy)==list) or (type(sx)==list):
        for syi, sxi in zip(sy, sx):
            dist[syi][sxi] = 0
            q.append((syi, sxi))
    else:
        dist[sy][sx] = 0
        q_append((sy, sx))

    while q:
        y, x = q_popleft()
        d = dist[y][x]
        for dy, dx in dire:
            if (y+dy<H) and (y+dy>=0) and (x+dx<W) and (x+dx>=0):
                if (c[y+dy][x+dx] in blocks):
                    continue
                else:
                    if (y+dy==gy) and (x+dx==gx) and (not return_maximum_distance):
                        return (d+1)
                    elif (dist[y+dy][x+dx] > d+1):
                        dist[y+dy][x+dx] = d+1
                        q_append((y+dy, x+dx))
    if (return_maximum_distance):
        return d
    return -1

H, W = LI()
c = SR(H)

sy = []
sx = []

for i in range(H):
    for j in range(W):
        if (c[i][j]=="#"):
            sy.append(i)
            sx.append(j)

print(bfs(c, sy, sx, return_maximum_distance=True))



def bfs(c,sy=0, sx=0, gy=0, gx=0, blocks=['#'], dire=[(1,0), (0,1), (-1,0), (0,-1)], return_maximum_distance=False):
            H = len(c)
            W = len(c[0])


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
vl modinv;
void fillModInv(ll n, ll mod){
  modinv = vl(n+1);
  modinv[1] = 1;
  FOR(i,2,n+1){
    modinv[i] = modinv[mod%i] * (mod - mod/i) % mod;
  }
}
/*}}}*/
int main() {
  ll n,a,b,c;
  cin >> n >> a >> b >> c;
  vector<string> str(n);
  REP(i,n) cin >> str[i];

  vector<string> ans = vector<string>(n);

  REP(i,n){
    //cout << str[i] << "," << a << "," << b << "," << c << "->";
    if(str[i]=="AB"){
      if(a==b){
        if(a==0){
          cout << "No" << endl;
          return 0;
        }
        //else if(a>1 || i==n-1){
        //  a--;
        //  b++;
        //  ans[i] = "B";
        //}
        //else if(a==1 && i<n-1){
        else{
          if(str[i+1]=="AC"){
            a++;
            b--;
            ans[i] = "A";
          }else{
            a--;
            b++;
            ans[i] = "B";
          }
        }
      }
      else if(a<b){
        a++;
        b--;
        ans[i] = "A";
      }
      else if(a>b){
        a--;
        b++;
        ans[i] = "B";
      }
    }
    if(str[i]=="AC"){
      if(a==c){
        if(a==0){
          cout << "No" << endl;
          return 0;
        }
        //else if(a>1 || i==n-1){
        //  a--;
        //  c++;
        //  ans[i] = "C";
        //}
        //else if(a==1 && i<n-1){
        else{
          if(str[i+1]=="AB"){
            a++;
            c--;
            ans[i] = "A";
          }else{
            a--;
            c++;
            ans[i] = "C";
          }
        }
      }
      else if(a<c){
        a++;
        c--;
        ans[i] = "A";
      }
      else if(a>c){
        a--;
        c++;
        ans[i] = "C";
      }
    }
    if(str[i]=="BC"){
      if(c==b){
        if(c==0){
          cout << "No" << endl;
          return 0;
        }
        //else if(c>1 || i==n-1){
        //  c--;
        //  b++;
        //  ans[i] = "B";
        //}
        //else if(c==1 && i<n-1){
        else{
          if(str[i+1]=="AC"){
            c++;
            b--;
            ans[i] = "C";
          }else{
            c--;
            b++;
            ans[i] = "B";
          }
        }
      }
      else if(c<b){
        c++;
        b--;
        ans[i] = "C";
      }
      else if(c>b){
        c--;
        b++;
        ans[i] = "B";
      }
    }
    //cout << a << "," << b << "," << c << endl;
  }
  
  //cout << fixed << setprecision(10);
  cout << "Yes" << endl;
  REP(i,n){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 9596
N = int(input())
S = sorted([int(s) for s in input().split()])
Q = int(input())
T = sorted([int(t) for t in input().split()])

cnt = 0
for t in T:
    left = 0
    right = len(S)
    while left < right:
        mid = int((left + right) / 2)
        if t < S[mid]:
            right = mid
        elif S[mid] < t:
            left = mid + 1
        elif t == S[mid]:
            cnt += 1
            break

print(cnt)


Measured memory_bytes: 16896
'use strict'

class Main {
  solve() {
    const nums = input.nextIntArr();
    const table = input.nextIntRange(nums[0]);
    table.sort((a,b) => a[0] - b[0]);
    let sum = 0;
    let remain = nums[1];
    for (let line of table) {
      const buy = Math.min(line[1],remain);
      sum += buy * line[0];
      remain -= buy;
      if (remain == 0) {
        break;
      }
    }
    console.log(sum);
  }
}

class Input {
  constructor() {
	this.cursor = 0;
	this.inputAll();
  }

  inputAll() {
	this.data = (require("fs").readFileSync("/dev/stdin", "utf8")).split('\n');
	return this.data;
  }

  nextLine(n) {
	if (n) {
	  const ret = this.data.slice(this.cursor, this.cursor + n);
	  this.cursor += n;
	  return ret;
	}
	return this.data[this.cursor++];
  }

  nextStrArr() {
	return this.nextLine().split(' ');
  }

  nextIntArr() {
	return this.nextStrArr().map((e) => parseInt(e));
  }

  nextFloatArr() {
	return this.nextStrArr().map((e) => parseFloat(e));
  }

  nextIntLine(n) {
	return this.nextLine(n).map((e) => parseInt(e))
  }

  nextFloatLine(n) {
	return this.nextLine(n).map((e) => parseFloat(e))
  }

  nextStrRange(n) {
	return this.nextLine(n).map((line) => line.split(' '));
  }

  nextIntRange(n) {
	return this.nextLine(n).map((line) => line.split(' ').map((e) => parseInt(e)));
  }

  nextFloatRange(n) {
	return this.nextLine(n).map((line) => line.split(' ').map((e) => parseFloat(e)));
  }
}

const input = new Input();
(new Main()).solve();


Measured memory_bytes: 53060
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    string s;
    cin >> s;
    int ini = 0, last = 0;
    bool ok1 = 0, ok2 = 0;
    forn(i, sz(s)) {
        if (!ok1 && s[i] == 'A') {
            ini = i;
            ok1 = 1;
        }
        if (!ok2 && s[sz(s) - i - 1] == 'Z') {
            last = sz(s) - i - 1;
            ok2 = 1;
        }
    }
    cout << last - ini + 1 << endl;

    return 0;
}


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

void Operation(int b,int f,int r,int v,vector<vector<vector<int>>>& info)
{
  info[b][f][r]+=v;
}

void writeline(vector<vector<vector<int>>>& info)
{
  for(int i=0;i<info.size();i++)
  {
    for(int j=0;j<info[i].size();j++)
    {
      for(int k=0;k<info[i][j].size();k++)
      {
        cout << " " << info[i][j][k];
      }
      cout << endl;
    }
    if(i<info.size()-1) cout << "####################" << endl;
  }
}

int main(int argc,char* argv[])
{
  int count=0;
  int b,f,r,v;
  vector<vector<vector<int>>> information(4,vector<vector<int>>(3,vector<int>(10,0)));
  cin >> count;
  for(int i=0;i<count;i++)
  {
    cin >> b >> f >> r >> v;
    Operation(b-1,f-1,r-1,v,information);
  }
  writeline(information);
}

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

int main() {
	ll		a,b,c,h,i,j,k,l,m,n,x,y;
	ll		ans = 0;
	string	s;
	cin >> n >> k >> s;
	vector<ll> aa(n+1);
	s += '1';
	a = 0;
	c = -1;
	for(i=1;i<n;i++) {
		if (s[i-1]=='0' && s[i]=='1') {
			c = i;
		}
		if (s[i]=='1') a++;
		else {
			if (c>0) {
				aa[c] = a;
			}
			c = -1;
			a = 0;
		}
	}
	if (c>0) aa[c] = a;
	//for(i=0;i<=n;i++) cout << aa[i] << endl;
	c = 0;
	for(i=1;i<=n;i++) {
		if (s[i-1]=='0' && s[i]=='1') {
			c++;
			if (c==k) break;
		}
	}
	if (c<k || i==n) {
		cout << n << endl;
		return 0;
	}
	j = 0;
	ans = i+1;
	//cout << i << ' ' << c << ' ' << endl;
	for(i++;i<=n;i++) {
		if (s[i-1]=='0' && s[i]=='1') {
			for(j++;j<i;j++) {
				if (s[j-1]=='0' && s[j]=='1') {
					if (i==n) x = i-j;
					else x = i-j+aa[i];
					ans = max(ans , x);
					break;
				}
			}
		}
	}

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


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


bool bless(const pair<int, int> &p, const pair<int, int> &q) {
  return (p.first != q.first) ? p.first > q.first : p.second < q.second;
}

int main() {
  int n,f=0;
  while(cin>>n, n) {
    if(f) cout<<endl;
    vector< pair<int, int> > v;
    vector<string> w;
    string s;
    int a,b,c;
    for(int i=0; i<n; ++i) {
      cin>>s>>a>>b>>c;
      v.push_back( pair<int,int>(a*3+c,i) );
      w.push_back(s);
    }

    stable_sort(v.begin(), v.end(), bless);

    for(int i=0; i<n; ++i)
      cout<<w[v[i].second]<<","<<v[i].first<<endl;
    f=1;
  }
}

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


int main(){
  ll d,t,s;cin >> d >> t >> s;
  if( t*s >= d )
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

int n, m, rv = 0;

vector<int> g[8];
void dfs(int v, int bit) {
	if (bit == (1 << n) - 1) {
		rv++;
		return;
	}
	for (int nv : g[v]) {
		if (bit & (1 << nv))
			continue;
		dfs(nv, bit | (1 << nv));
	}
}

int main() {
	cin >> n >> m;
	for (int i = 0, a, b; i < m; i++) {
		cin >> a >> b, a--, b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0, 1);
	cout << rv << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

char map[60][60], v[60][60], visited[60][60];
int H, W;
int dr[]={-1, 0, 1, 0}, dc[]={0, -1, 0, 1};

int dfs(int r, int c, int k)
{
    int i;
    char *t=&v[r][c];
    *t|=k;
    for(i=0;i<4;++i) {
        int nr=r+dr[i];
        int nc=c+dc[i];
        if (nr<0 || nr>=H || nc<0 || nc>=W)
            *t|=4;
        else if (map[nr][nc]=='B')
            *t|=1;
        else if (map[nr][nc]=='W')
            *t|=2;
    }
    for(i=0;i<4;++i) {
        int nr=r+dr[i];
        int nc=c+dc[i];
        if (nr<0 || nr>=H || nc<0 || nc>=W || map[nr][nc]!='.' || (*t&v[nr][nc])==*t)
            continue;
        dfs(nr, nc, *t);
    }
}

int main(void)
{
    while (scanf("%d%d", &W, &H), W) {
        int r, c, b, w;
        memset(map, 0, sizeof(map));
        memset(v, 0, sizeof(v));
        b=w=0;
        for(r=0;r<H;++r) scanf("%s", map[r]);

        for(r=0;r<H;++r) for(c=0;c<W;++c) {
            if (!v[r][c] && map[r][c]=='.') dfs(r, c, 0);
        }
        for(r=0;r<H;++r) for(c=0;c<W;++c) {
            b+=(v[r][c]==1 || v[r][c]==5);
            w+=(v[r][c]==2 || v[r][c]==6);
        }
        printf("%d %d\n", b, w);
    }
    return 0;
}

Measured memory_bytes: 764
//============================================================================
// Name        : LinearSearch.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
using namespace std;



int main() {
	int n, m;
	cin >> n;
	vector<int> s, t;
	int input;

	for(int i=0; i<n; i++){
		cin >> input;
		s.push_back(input);
	}

	cin >> m;

	for(int i=0; i<m; i++){
		cin >> input;
		t.push_back(input);
	}

	int n_common = 0;
	for(int i=0; i<t.size(); i++){
		for(int j=0; j<s.size(); j++){
			if(s.at(j) == t.at(i)){
				n_common = n_common + 1;
				break;
			}
		}
	}

	cout << n_common << "\n";

	return 0;
}



Measured memory_bytes: 3168
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <functional>
#include <vector>
#include <math.h>
#include <typeinfo>
#include <numeric>
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <queue>

using namespace std;


int main()
{
	int a;
	string s;

	cin >> a >> s;

	if (a < 3200)
	{
		s = "red";
	}

	cout << s << endl;

	return 0;
 
}

Measured memory_bytes: 256
from collections import deque
n,m, = map(int,input().split())
# ab =[list(map(int,input().split())) for i in range(m)]

v = [[i,-1] for i in range(n+1)]
v[1][1] = 0
for i in range(m):
    a,b = map(int,input().split())
    v[a].append(b)
    v[b].append(a)
dq = deque([])
dq.append(v[1])
# print(v)
while dq:
    t = list(deque.popleft(dq))
    # print(t)
    for i in t[1:]:
        if v[i][1] == -1:
            v[i][1] = t[0]
            dq.append(v[i])
print("Yes")
for i in range(n-1):
    print(v[i+2][1])

Measured memory_bytes: 38408
#include <bits/stdc++.h>
#define rg register
#define us unsigned
#define ll long long
#define ui <int>
#define pi <int, int>
#define tmpl template <typename typ>
#define oprt operator
#define sp putchar(32)
#define el putchar(10)
#define flin(x) freopen(x, "r", stdin)
#define flout(x) freopen(x, "w", stdout)
#define flio(x) flin(x".in"), flout(x".out")
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define itrt iterator
using namespace std;
tmpl inline bool up(typ &x, const typ &y) { return x < y ? x = y, 1 : 0; }
tmpl inline bool dn(typ &x, const typ &y) { return y < x ? x = y, 1 : 0; }
tmpl inline bool inr(const typ &x, const typ &l, const typ &r) { return !(x < l) && !(r < x); }
namespace orh {
inline void useios() { ios_base::sync_with_stdio(false); cin.tie(0); }
inline char rc() { rg char ch; while (!isgraph(ch = getchar())); return ch; }
tmpl typ ri() {
	rg typ x = 0; rg bool neg = false; rg char ch;
	while (!inr(ch = getchar(), '0', '9')) neg |= ch == '-';
	do x = (x << 1) + (x << 3) + (ch ^ 48); while (inr(ch = getchar(), '0', '9'));
	return neg ? -x : x;
}
tmpl typ ru() {
	rg typ x = 0; rg char ch;
	while (!inr(ch = getchar(), '0', '9'));
	do x = (x << 1) + (x << 3) + (ch ^ 48); while (inr(ch = getchar(), '0', '9'));
	return x;
}
tmpl void wi(rg typ x) {
	if (x < 0) { putchar('-'); x = -x; }
	static int sta[42]; rg int top = 0; rg typ t;
	do t = x / 10, sta[top++] = x - (t << 1) - (t << 3), x = t; while (x);
	while (top) putchar(sta[--top] ^ 48);
}
tmpl void wu(rg typ x) {
	static int sta[42]; rg int top = 0; rg typ t;
	do t = x / 10, sta[top++] = x - (t << 1) - (t << 3), x = t; while (x);
	while (top) putchar(sta[--top] ^ 48);
}
}

const int maxn = 1e5 + 5;
int n, m, a[maxn], sum;

signed main() {
	orh::useios();
	
	cin >> m >> n;
	for (rg int i = 1; i <= n; ++i) { 
		cin >> a[i];
		sum += a[i];
	}
	
	if (sum >= m) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

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

using namespace std;

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

int main() {
    while (true) {
        string x;
        cin >> x;
        if (x == "0")return 0;
        int sum = 0;
        rep(i, x.size()) {
            string n;
            n += x[i];
            int a = stoi(n);
            sum += a;
        }
        cout << sum << endl;
    }
}


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

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<int> ans(n);
    for(int i=0;i<n;i++){
        ans[i]=(s[i]=='x');
    }

    
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            vector<int> res(n);
            res[0]=i,res[1]=j;
            for(int k=2;k<n;k++){
                res[k]=res[k-1]^res[k-2]^ans[k-1];
            }
            bool bn=((ans[n-1]^res[n-2]^res[0]^res[n-1])==0);
            bool b0=((ans[0]^res[n-1]^res[1]^res[0])==0);
            if(bn && b0){
                for(int i=0;i<n;i++){
                    cout<<(res[i] ? "W" : "S");
                }
                cout<<endl;
                return 0;
            }
        }
    }
    cout<<-1<<endl;

    return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef long long int ld;
typedef unsigned long long int lu;
typedef vector< int > vi;
typedef vector < ld > vd;
typedef set <ld> sd;
typedef vector< vi > vvi;
typedef vector< vd > vvd;
typedef pair< int,int > ii;
typedef pair< ld,ld > id;
#define sz(a) ld((a).size())
#define test(t) ll t;cin>>t;while(t--)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define Vi vector
#define pr pair
#define mpr make_pair
#define fi first
#define se second
#define isnum(a) (a>=48 && a<=57)
#define isS(a) (a>='a' && a<='z')
#define isU(a) (a>='A' && a<='Z')
#define toS(a) (isU(a)?a+32:a)
#define toU(a) (isS(a)?a-32:a)
#define toC(a) a&15

set <ld> s[100005];
ld d[100005];

vector<char> prime (100000+1, true);
void sieve(ld n)
{	
	//O(nloglogn) time
	prime[0] = prime[1] = false;
	for (ld i=2; i<=n; ++i)
	{
		if (prime[i])
		{
			s[i].insert(i);			
			for (ld j=2*i; j<=n; j+=i)
			{
				prime[j] = false;
				s[j].insert(i);
			}
		}
	}
}
#define forn(i,e) for(int i = 0; i < e; i++)
#define rep(i,a,b) for(i=a;i<b;i++)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define reprev(i,a,b) for(i=a;i>=b;i--)

#define leadzero(a) __builtin_clz(a) //count leading zeros
#define trailzero(a) __builtin_ctz(a) //count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout<<"\n"
#define sp cout<<" "
#define maxe(a) *max_element(a.begin(),a.end())
#define maxi(a) max_element(a.begin(),a.end())-a.begin()
#define mine(a) *min_element(a.begin(),a.end())
#define mini(a) min_element(a.begin(),a.end())-a.begin()
ld gcd(ld a, ld b) { if(b == 0) return a; return gcd(b, a % b); }
ld fastpowMOD(ld a, ld p,ld MOD){ if(p==0) return 1; ld z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }
ld fastpow(ld a, ld p){ if(p==0) return 1; ld z = fastpow(a,p/2); z = (z*z); if(p%2) z = (z*a); return z; }
ld a,b;

ld search1(ld a[], ld f,ld n)
{
	ld left=1;
	ld right=n+1;
	while(right-left>1)
	{
		ld mid = left + (right-left)/2;
		if(a[mid]<f)
		{
			left=mid;
		}
		else right=mid;
	}
	return a[left];
}
ld MOD = 1e9+7;
ld n;
void mult(ld ar[50][50],ld br[50][50])
{
	ld temp[50][50];
	ld i,j,k;
	memset(temp,0,sizeof(temp));
	rep(i,0,n)
	{
		rep(j,0,n)
		{
			rep(k,0,n)
			{
				temp[i][j]+= ar[i][k]*br[k][j]%MOD;
			}
			temp[i][j]%=MOD;
		}
	}
	rep(i,0,n)
	{
		rep(j,0,n)ar[i][j]=temp[i][j];
	}
}

void matmult(ld ar[50][50],ld k)
{
	if(k==1)return;
	ld temp[50][50];
	ld i,j;
	rep(i,0,n)
	{
		rep(j,0,n)temp[i][j]=ar[i][j];
	}
	matmult(ar,k/2);
	mult(ar,ar);
	if(k&1)
	{
		mult(ar,temp);
	}
}

int main(){
	ld i,j,k;
	cin >> n >> k;
	ld ar[50][50];
	rep(i,0,n)
	{
		rep(j,0,n)cin >> ar[i][j];
	}
	ld sum=0;
	matmult(ar,k);
	rep(i,0,n)
	{
		rep(j,0,n)
		{
			sum+=ar[i][j]%MOD;
		}
	}
	sum%=MOD;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 6272
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n, a[100000], dp[5005][2];
int main() {
	cin >> n; for (int i = 0; i < n - 1; i++)cin >> a[i];
	for (int i = 0; i < 5005; i++) { dp[i][0] = 999999999; dp[i][1] = 999999999; }
	dp[n / 2][0] = 0; dp[n / 2][1] = 0;
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j <= n / 2; j++) {
			dp[j][0] = min(dp[j][0], dp[j][1] + a[i]);
			dp[j][1] = min(dp[j + 1][1], dp[j + 1][0] + a[i]);
		}
	}
	cout << min(dp[0][0], dp[0][1]) << endl;
	return 0;
}

Measured memory_bytes: 3128
s = input()
s = list(reversed(s))
n = len(s)
dp1 = [0]*n
dp2 = [0]*n
counting = [0]*2019
counting[0] += 1
dp1[0] = 1
dp2[0] = int(s[0])
counting[dp2[0]] += 1
if n >= 2:
    for i in range(1,n):
        dp1[i] = (10*dp1[i-1]) % 2019
        dp2[i] = (int(s[i])*dp1[i]+dp2[i-1]) % 2019
        counting[dp2[i]] += 1
sm = 0
for j in range(2019):
    sm += int(counting[j]*(counting[j]-1)/2)
print(sm)

Measured memory_bytes: 24752
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b,x=0,y;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int c,d=0,e=0,f=0,g=1,h=0;
    string s;
    cin >>s;
    a=s.size()/2;
    for(int n=0;n<a;n++){
      if(s[n]!=s[s.size()-1-n]) d++;
    }
    cout <<d<<'\n';
    return (0);
}


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

int main(){
	int N,M,K;
	//std::cin >> N >> M;
    //std::cin >> N >> M >> K;
    
    std::vector<long long> v(5);
 	
 	//stack<int> sta;   
    //queue<int> que;
    
 	
    // 入力
    for(long long i=0; i<5; i++){
		std::cin >> v[i];
	}
	std::cin >> N;
	//std::sort(v.begin(),v.end());;
    int flag;
    flag=0;

    if(v[4]-v[0]<= N){
		
    printf("Yay!");
    }
    else{
		printf(":(");
	}
    //printf("%d",N*M);
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;
const int N = 1e5 + 5;
struct node{
	int a, b,c;
}s[N];
long long dp[N][3];
int main() {
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s[i].a >> s[i].b >> s[i].c;
	}
	dp[0][0] = s[0].a;
	dp[0][1] = s[0].b;
	dp[0][2] = s[0].c;
	for(int i = 1; i < n ;i++){
		dp[i][0] = max(dp[i][0], dp[i - 1][1] + s[i].a);
		dp[i][0] = max(dp[i][0], dp[i - 1][2] + s[i].a);

		dp[i][1] = max(dp[i][1], dp[i - 1][0] + s[i].b);
		dp[i][1] = max(dp[i][1], dp[i - 1][2] + s[i].b);

		dp[i][2] = max(dp[i][2], dp[i - 1][0] + s[i].c);
		dp[i][2] = max(dp[i][2], dp[i - 1][1] + s[i].c);
	}
	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL gcd(LL a,LL b)
{
    return b==0?a:gcd(b,a%b);
}
LL lcm(LL a,LL b)
{
    return a/gcd(a,b)*b;
}
int main()
{
    LL ans,T,i,n;
    ans=1;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>T;
        ans=lcm(ans,T);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
if s[0] == "R":
    if s[1] == "R":
        if s[2] == "R":
            ans = 3
        else:
            ans = 2
    else:
        ans = 1
else:
    if s[1] == "R":
        if s[2] == "R":
            ans = 2
        else:
            ans = 1
    elif s[2] == "R":
        ans = 1
    else:
        ans = 0
print(ans)

Measured memory_bytes: 9016
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
vector<int> vec;
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a / g * b;
}

int main() {
    int N;
    cin >> N;
    ll ans = 1LL;
    rep(i, 0, N) {
        ll T;
        cin >> T;
        ans = lcm(ans, T);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#/*
    AUTHOR:shivam51
    IIESTS
*/
  #include<bits/stdc++.h>
  using namespace std;
  //
  // #define MAX 100001
  #define md 998244353
  #define add accumulate
  #define ll long long int
  #define ld long double
  #define ff first
  #define ss second
  #define pb push_back
  #define mp make_pair
  #define vll vector<ll>
  #define lb lower_bound
  #define ub upper_bound
  #define pll pair<ll,ll>
  #define vpll vector<pll>
  #define all(v) v.begin(), v.end()
  #define rep(i,k,n) for(int i=k;i<n;i++)
  #define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
  #define repa(a,n) for(int i=a;i<n;i++)
  const int MAX=1e5+5;
  const int mod=1e9+7;
  const int N=3e5+9;
  const long double eps=1e-9;
  const ld PI=acos(-1.0);
    ll dx[]={1,0,-1,0};
	ll dy[]={0,1,0,-1};
	int dp[MAX];
  //
  //
	int arr[MAX],k;
	ll oper(ll index){
		if(dp[index]!=-1)
			return dp[index];
		ll fst=abs(arr[index]-arr[index-1])+oper(index-1);
		// ll snd=abs(arr[index]-arr[index-2])+oper(index-2);
		for(int i=2;i<=k;i++){
			fst=min(fst,abs(arr[index]-arr[index-i])+oper(index-i));
		}
		dp[index]=fst;
		return dp[index];
	}
  int main(){
  	rep(i,0,MAX)
  		dp[i]=-1;
  	ll n;
  	cin>>n>>k;
  	rep(i,0,n)	cin>>arr[i];
  	rep(i,0,k+1){
  		dp[i]=abs(arr[i]-arr[0]);
  	}/*
  	dp[0]=0;
  	dp[1]=abs(arr[1]-arr[0]);
  	dp[2]=abs(arr[2]-arr[0]);
*/  	// cout<<oper(n-1);
  	oper(n-1);
  	cout<<dp[n-1]<<" ";
  	// rep(i,0,n)
  		// cout<<dp[i]<<" ";
  	return 0;
  }

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

using namespace std;

int r,c;

int sd(pair<int,int> a){
    int x,y;
    tie(x,y) = a;
    if(x==0)
        return 0;
    if(y==c)
        return 1;
    if(x==r)
        return 2;
    if(y==0)
        return 3;
    return -1;
}

int main(){
    scanf("%d%d",&r,&c);
    int n;
    scanf("%d",&n);
    vector<pair<pair<int,int>,int>> xvec;
    for(int i = 0; i<n; i++){
        int x1,y1,x2,y2;
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        if(sd({x1,y1})!=-1&&sd({x2,y2})!=-1){
            xvec.push_back({{x1,y1},i});
            xvec.push_back({{x2,y2},i});
        }
    }
    auto bcmp = [](const pair<pair<int,int>,int>& a, const pair<pair<int,int>,int>& b){
        if(sd(a.first)!=sd(b.first))
            return sd(a.first)<sd(b.first);
        if(sd(a.first)<2)
            return a.first<b.first;
        return a.first>b.first;
    };
    sort(xvec.begin(),xvec.end(),bcmp);
    int xsz = xvec.size();
    for(int i = 0; i<xsz; i++)
        xvec.push_back(xvec[i]);
    xsz+=xsz;
    stack<int> ist;
    vector<int> xc(n,0);
    bool failed = false;
    for(int i = 0;i<xsz; i++){
        if(!ist.empty()&&ist.top()==xvec[i].second){
            xc[xvec[i].second]--;
            ist.pop();
        }else if(!xc[xvec[i].second]){
            xc[xvec[i].second]++;
            ist.push(xvec[i].second);
        }else{
            failed = true;
            break;
        }
    }
    if(failed)
        printf("NO\n");
    else
        printf("YES\n");
    return 0;
}

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

using namespace std;

int main()
{
	int w, h, n;
	scanf("%d %d %d", &w, &h, &n);
	
	int m[w][h];
	memset(m, -1, sizeof(m));
	for(int i = 0; i < n; i++) {
		int x, y, a;
		scanf("%d %d %d", &x, &y, &a);

		if(a == 1) {
			for(int i = 0; i < x; i++) 
				for(int j = 0; j < h; j++)
					m[i][j] = 0;
		} else if (a == 2) {
			for(int i = x; i < w; i++) 
				for(int j = 0; j < h; j++)
					m[i][j] = 0;
		} else if(a == 3) {
			for(int i = 0; i < w; i++) 
				for(int j = 0; j < y; j++)
					m[i][j] = 0;
		} else {
			for(int i = 0; i < w; i++) 
				for(int j = y; j < h; j++)
					m[i][j] = 0;
		}
	}
	
	int cnt = 0;
	for(int i = 0; i < w; i++)
		for(int j = 0; j < h; j++)
			if(m[i][j] == -1)
				cnt++;
	printf("%d\n", cnt);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>

using namespace std;
typedef unsigned long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

/*

int xcomp(vector<LL>& a, vector<LL>& b) {
return a[0] < b[0];
}
*/
int xcomp(pair<LL,LL>& a, pair<LL,LL>& b) {
	return a.first < b.first;
}

#define XSORT(c) sort((c).begin(),(c).end(),xcomp)

#define ALL(x) (x).begin(),(x).end()
LL mod = 1000000007;
LL hoge = 200000000;

int main() {
	LL R, C, N;
	cin >> R >> C >> N;

	vector<pair<LL, LL>> v(0);


	REP(i, N) {
		LL x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		if (((x1 == 0 || x1 == R) || (y1 == 0 || y1 == C))&&((x2 == 0 || x2 == R) || (y2 == 0 || y2 == C))) {
			LL a, b;
			if (x1 == 0) {
				a = y1;
			}
			else 
			if(y1==C){
				a = hoge + x1;
			}else
				if (x1 == R) {
					a = hoge * 2 + (C - y1);
				}
				else {
					a = hoge * 3 + (R - x1);
				}

				if (x2 == 0) {
					b = y2;
				}
				else
					if (y2 == C) {
						b = hoge + x2;
					}
					else
						if (x2 == R) {
							b = hoge * 2 + (C - y2);
						}
						else {
							b = hoge * 3 + (R - x2);
						}
						if (a > b) {
							swap(a, b);
						}
						v.push_back(make_pair(a, b));
		}
	}

	XSORT(v);

	vector<pair<LL, LL>> vv(0);

	REP(i, v.size()) {
		vv.push_back(make_pair(v[i].first, i));
		vv.push_back(make_pair(v[i].second, i));
	}

	XSORT(vv);

	vector<LL> vvv(0);

	REP(i, vv.size()) {
		vvv.push_back(vv[i].second);
	}

	bool flag = true;

	//LL count = -1;

	vector<LL> w(vvv.size(),0);

	vector<LL> c(0);

	REP(i, vvv.size()) {
		if (w[vvv[i]] == 0) {
			//count = vvv[i];
			w[vvv[i]]++;
			c.push_back(vvv[i]);
		}
		else {
			if (vvv[i] == c[c.size() - 1]) {
				c.pop_back();
			}
			else {
				flag = false;
				break;
			}
		}
	}


	if (flag) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 9708
W = 5

def calc_score(ban, score):
    add_score = 0
    after_ban = []
    H = len(ban)
    for h in range(H):
        row = []
        cnt = 1
        cur = ban[h][0]
        for w in range(1, W):
            if cur == ban[h][w]:
                cnt += 1
            else:
                row.append([cur, cnt])
                cur = ban[h][w]
                cnt = 1
        row.append([cur, cnt])

        after_row = []
        for cur, cnt in row:
            if cnt >= 3:
                add_score += cur * cnt
                after_row.extend([0]*cnt)
            else:
                after_row.extend([cur]*cnt)
        after_ban.append(after_row)

    # 下が0のマスだったら落ちる
    for _ in range(10):
        for h in range(0, H-1):
            for w in range(W):
                if after_ban[h+1][w] == 0:
                    after_ban[h+1][w] = after_ban[h][w]
                    after_ban[h][w] = 0

    score += add_score
    if add_score == 0:
        return score
    else:
        return calc_score(after_ban, score)

ans = []

while True:
    H = int(input())
    if H == 0:
        break
    ban = [list(map(int, input().split())) for _ in range(H)]
    ans.append(calc_score(ban, 0))

print(*ans, sep='\n')


Measured memory_bytes: 5776
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
using namespace std;
typedef long long s64;

const int ONE = 200005;
const int INF = 214748364;

#define next nxt

int get()
{
		int res = 1, Q = 1; char c;
		while( (c = getchar()) < 48 || c > 57)
			if(c == '-') Q = -1;
		if(Q) res = c - 48;
		while( (c = getchar()) >= 48 && c <= 57)
			res = res * 10 + c - 48;
		return res * Q;
}

struct power
{
		int l, r;
}val[ONE];

int n, k;
int x, y;
int pd[ONE];
int next[ONE], first[ONE], go[ONE], tot;

void Add(int u, int v)
{
		next[++tot] = first[u], first[u] = tot, go[tot] = v;
		next[++tot] = first[v], first[v] = tot, go[tot] = u;
}

void dfs(int u, int father)
{
		if(val[u].l == val[u].r) pd[u] = val[u].l % 2;
		for(int e = first[u]; e; e = next[e])
		{
			int v = go[e];
			if(v == father) continue;
			dfs(v, u);
			if(pd[v] == 2) continue;
			if(pd[u] == 2) {pd[u] = pd[v] ^ 1; continue;}
			if(pd[u] != (pd[v] ^ 1)) {printf("No"); exit(0);}
		}
}

void dfs1(int u, int father)
{
		for(int e = first[u]; e; e = next[e])
		{
			int v = go[e];
			if(v == father) continue;
			dfs1(v, u);
			val[u].l = max(val[u].l, val[v].l - 1);
			val[u].r = min(val[u].r, val[v].r + 1);
			if(val[u].l > val[u].r) {printf("No"); exit(0);}
		}
}

int A[ONE];

void dfs2(int u, int father)
{
		for(int e = first[u]; e; e = next[e])
		{
			int v = go[e];
			if(v == father) continue;
			if(val[v].l <= A[u] - 1 && A[u] - 1 <= val[v].r) A[v] = A[u] - 1;
			if(val[v].l <= A[u] + 1 && A[u] + 1 <= val[v].r) A[v] = A[u] + 1;
			dfs2(v, u);
		}
}

int main()
{
		n = get();
		for(int i = 1; i < n; i++) x = get(), y = get(), Add(x, y);
		for(int i = 1; i <= n; i++) val[i] = (power){-INF, INF}, pd[i] = 2;
		k = get();
		for(int i = 1; i <= k; i++) x = get(), y = get(), val[x] = (power){y, y};

		dfs(1, 0);
		dfs1(1, 0);

		A[1] = val[1].l;
		if(pd[1] != 2 && A[1] % 2 != pd[1]) A[1]++;
		if(A[1] > val[1].r) {printf("No"); exit(0);}

		dfs2(1, 0);

		printf("Yes\n");
		for(int i = 1; i <= n; i++)
			printf("%d\n", A[i]);
}

Measured memory_bytes: 9856
#include<vector>
#include<iostream>
#include<algorithm>
#include<map>

using namespace std;

int main(){
  int n;
  cin >> n;
  string s[n];
  for(int i = 0;i < n;++i) cin >> s[i];
  int m;
  cin >> m;
  string t[m];
  for(int i = 0;i < m;++i) cin >> t[i];
  map<string,int> a;
  for(int i = 0;i < n;++i){
    a[s[i]]++;
  }
  for(int i = 0;i < m;++i){
    a[t[i]]--;
  }
  int mi = 0;
  for(auto itr = a.begin(); itr != a.end(); ++itr) {
   //cout << itr -> first << itr -> second << endl;
       mi = max(mi,itr -> second);
   }
  /*for(const auto& [key,value]:a){
     mi = max(m,value);
  }*/
  cout << mi <<endl;
  return 0;
}

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

int main() {
  std::string s;
  std::cin >> s;
  std::string b(s.length(), '1'), w(s.length(), '0');
  long long bc = 0, wc = 0;
  for (long long i = 0; i < s.length(); i++) {
    if (i % 2 == 1) {
      b[i] = '0';
      w[i] = '1';
    } else {
      b[i] = '1';
      w[i] = '0';
    }
  }
  for (long long i = 0; i < s.length(); i++) {
    if (s[i] != b[i]) {
      bc++;
    }
    if (s[i] != w[i]) {
      wc++;
    }
  }
  std::cout << std::min(bc, wc) << "\n";
  return 0;
}

Measured memory_bytes: 512
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    x, y = map(int, input().split())

    for tsuru in range(0, x + 1):
        kame = x - tsuru
        if 2 * tsuru + 4 * kame == y:
            print("Yes")
            exit()
    print("No")

if __name__ == '__main__':
    main()

Measured memory_bytes: 65248
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   

int main(){
    std::ios::sync_with_stdio(false);
    int d,n;
    cin>>d>>n;
    if(n==100)
    	n++;
    int val=1;
    int i;
    rep(i,d){
    	val*=100;
    }
    val*=n;
    cout<<val<<endl;
    return 0;  
    
}



Measured memory_bytes: 384
### constant

N = 20
K = 10
S = 155

### main

dp = Array.new(N + 1){Array.new(K + 1){Array.new(S + 1){0}}}
dp[0][0][0] = 1

for n in (1..N)
  for k in (0..K)
    for s in (0..S)
      dp[n][k][s] = dp[n - 1][k][s]
      dp[n][k][s] += dp[n - 1][k - 1][s - n] if k > 0 && s >= n
    end
  end
end
#p dp; exit

loop do
  n, k, s = gets.split.map(&:to_i)
  break if (n | k | s) == 0

  puts dp[n][k][s]
end

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

void solve(long long N, long long L, long long T, vector<long long> X, vector<long long> W){
	vector<long long> Y(N);
	for(int i = 0 ; i <= N-1 ; i++) {
		if (W[i] == 1) Y[i] = (X[i]+T)%L; else Y[i] = (X[i]-T)%L;
		if (Y[i] < 0) Y[i] += L;
	}
	long long sumc = 0;
	for(int i = 1 ; i <= N-1 ; i++) {
		if (W[0] != W[i]) {
			if (W[0] == 1 && X[i]-X[0] <= T*2) {
				sumc += 1+(T*2 - (X[i]-X[0]))/L;
			}
			if (W[0] == 2 && L-(X[i]-X[0]) <= T*2) {
				sumc += 1+(T*2 - (L-(X[i]-X[0])))/L;
			}
		}
	}
	long long z;
	// cout << sumc << "\n";
	if (W[0] == 1) {
		z = sumc%N;
	} else {
		z = (N-sumc%N)%N;
	}
	// cout << z << "\n";
	long long y = Y[0], n;
	sort(Y.begin(), Y.end());
  // n = distance(Y.begin(), upper_bound(Y.begin(), Y.end(), y))-1;
	if (W[0] == 1) {
		n = distance(Y.begin(), lower_bound(Y.begin(), Y.end(), y));
		if (Y[n] == Y[(n+1)%N]) z--;
	} else {
		n = distance(Y.begin(), upper_bound(Y.begin(), Y.end(), y))-1;
		if (Y[n] == Y[(n-1+N)%N]) z++;
	}
	// cout << n << "\n";
	// for (int i = 0; i < N; i++) cout << Y[i] << "\n";

	for(int i = n-z+N ; i <= n-z+N+N-1 ; i++) {
		cout << Y[i%N] << "\n";
	}

}

int main(){
	long long T;
	long long L;
	long long N;
	scanf("%lld",&N);
	vector<long long> X(N-1+1);
	vector<long long> W(N-1+1);
	scanf("%lld",&L);
	scanf("%lld",&T);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&X[i]);
		scanf("%lld",&W[i]);
	}
	solve(N, L, T, X, W);
	return 0;
}


Measured memory_bytes: 5120
n=int(input())
csf=[list(map(int,input().split())) for i in range(n-1)]
for i in range(n):
    t=0
    for j in csf[i:]:
        c,s,f=j
        if(s>=t):
            t=s+c
        else:
            t=f*-(-t//f)+c
    print(t)

Measured memory_bytes: 3188
n = int(input())
k = int(input())
dp = [[0,0] for i in range(n+1)]
dp[0] = [1,1]
# print(dp)
for i in range(1,n+1):
    dp[i][0] = min(dp[i-1][0],dp[i-1][1])*2
    dp[i][1] = min(dp[i-1][0],dp[i-1][1])+k
print(min(dp[n]))


Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

int N, M;
string field[50];

/*==================================================*/

/*==================================================*/

int main() {
    cin>>N>>M;
    REP(i,0,N){
        cin>>field[i];
    }

    REP(i,0,N){
        REP(j,0,M){
            if(field[i][j] == '#') continue;
            int cnt = 0;
            REP(k,0,8){
                int y = i + dy[k];
                int x = j + dx[k];
                if(!CK(y,0,N) || !CK(x,0,M)) continue;
                if(field[y][x] == '#') cnt++;
            }
            field[i][j] = (char)('0' + cnt);
        }
    }


    REP(i,0,N){
        cout<<field[i]<<endl;;
    }

    return 0;
}


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

int main() {
    int N, M=0, temp=0;
    cin >> N;
    vector<int> a(N+1);
    for(int i=0; i<N; i++) {
        cin >> a[i+1];
    }
    vector<int> res(N+1, 0);

    for(int i=N; i>0; i--) {
        temp = 0;
        for(int j=1; i*j<=N; j++) {
            temp ^= res[i*j];
        }
        if(res[i] = temp^a[i]) M++;
    }

    cout << M << endl;
    for(int i=1; i<=N; i++) {
        if(res[i]) cout << i << " ";
    }
    
    return 0;


}

Measured memory_bytes: 2432