akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#include<random>
#include<string.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

int main() {
	int ans = 10000000;
	makei(N);
	rep(N) {
		makei(a);
		int cnt = 0;
		while (a % 2 == 0) {
			++cnt;
			a /= 2;
		}
		ans = min(ans, cnt);
	}
	say(ans);
}

Measured memory_bytes: 256
N = int(input())
cards_num = [int(x) for x in input().split(' ')]

cards_num.sort(reverse=True)

bob = []
alice = []

for j in range(len(cards_num)):
    if j % 2 == 0:
        bob.append(cards_num[j])
    else:
        alice.append(cards_num[j])

print(sum(bob)-sum(alice))

Measured memory_bytes: 3060
#include <stdio.h>
 
int main(void) {
    double x[3],y[3],xp,yp;
    double temp;
    double xkeisuu[2],teisuu[2];
    int ok;
    while(!feof(stdin)) {
        scanf("%lf %lf %lf %lf %lf %lf %lf %lf",
            &x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&xp,&yp);
        if(feof(stdin))break;
        if(x[0]>x[1]) {
            temp=x[0];x[0]=x[1];x[1]=temp;
            temp=y[0];y[0]=y[1];y[1]=temp;
        }
        if(x[1]>x[2]) {
            temp=x[1];x[1]=x[2];x[2]=temp;
            temp=y[1];y[1]=y[2];y[2]=temp;
        }
        if(x[0]>x[1]) {
            temp=x[0];x[0]=x[1];x[1]=temp;
            temp=y[0];y[0]=y[1];y[1]=temp;
        }
        ok=0;
        if(xp>x[0] && xp<x[2]) {
            if(xp<x[1]) {
                xkeisuu[0]=(y[0]-y[1])/(x[0]-x[1]);
                teisuu[0]=y[0]-x[0]*xkeisuu[0];
                xkeisuu[1]=(y[0]-y[2])/(x[0]-x[2]);
                teisuu[1]=y[0]-x[0]*xkeisuu[1];
                if(xkeisuu[0]>xkeisuu[1]) {
                    temp=xkeisuu[0];xkeisuu[0]=xkeisuu[1];xkeisuu[1]=temp;
                    temp=teisuu[0];teisuu[0]=teisuu[1];teisuu[1]=temp;
                }
            } else if(xp>=x[1]) {
                xkeisuu[0]=(y[0]-y[2])/(x[0]-x[2]);
                teisuu[0]=y[2]-x[2]*xkeisuu[0];
                xkeisuu[1]=(y[1]-y[2])/(x[1]-x[2]);
                teisuu[1]=y[2]-x[2]*xkeisuu[1];
                if(xkeisuu[0]<xkeisuu[1]) {
                    temp=xkeisuu[0];xkeisuu[0]=xkeisuu[1];xkeisuu[1]=temp;
                    temp=teisuu[0];teisuu[0]=teisuu[1];teisuu[1]=temp;
                }
            }
            if(yp>xkeisuu[0]*xp+teisuu[0] && yp<xkeisuu[1]*xp+teisuu[1])
                ok=1;
        }
        printf("%s\n",ok?"YES":"NO");
    }
    return 0;
}

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int a,b;
	cin >> a >> b;
	if((a*b) % 2 == 1) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
//author: dazhong_feliks

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

int main() {
  char c;
  cin >> c;

  if ( c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ){
    cout << "vowel" ;
  }
    else {
      cout << "consonant" << endl;
    }
  }

Measured memory_bytes: 256
def main():
    x = int(input())

    _n = int(x ** .2)
    for n in range(_n-2, _n+3):
        if n ** 5 == x:
            print(n, 0)
            return
    
    for i in range(1, 100):
        if x - i ** 5 < 0:
            continue
        _n = int((x - i ** 5) ** .2)
        for n in range(_n-2, _n+3):
            if n ** 5 == (x - i ** 5):
                print(i, -n)
                return
    
    for i in range(1, 1000):
        fif = x + i ** 5
        _n = int(fif ** .2)
        for n in range(_n-2, _n+3):
            if n ** 5 == fif:
                print(n, i)
                return

main()


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

int main() {
	long long int N, count = 0;
	cin >> N;
	int n = N % 11;
	count += (N - n) * 2 / 11;
	if (1 <= n) count++;
	if (7 <= n) count++;
	cout << count;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;

int main() {
  int s[32] = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
               1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;

  cout << s[k - 1];
  return 0;
}


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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;
  int n;

  vector<PII> up;
  vector<PII> down;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;

    int cur_cnt = 0;
    int max_min = 0;
    for (auto &c : s) {
      if (c == '(') {
        cur_cnt++;
      } else {
        cur_cnt--;
      }
      max_min = min(max_min, cur_cnt);
    }

    if (cur_cnt >= 0) {
      up.emplace_back(max_min, cur_cnt - max_min);
    } else {
      down.emplace_back(cur_cnt - max_min, max_min);
    }
  }

  sort(all(up));
  reverse(all(up));
  sort(all(down));
  reverse(all(down));

  bool possible = true;

  int sum = 0;
  for (auto &p : up) {
    int max_min, rest;
    tie(max_min, rest) = p;

    sum += max_min;
    if (sum < 0) {
      possible = false;
    }

    sum += rest;
    if (sum < 0) {
      possible = false;
    }
  }

  for (auto &p : down) {
    int max_min, rest;
    tie(rest, max_min) = p;

    sum += max_min;
    if (sum < 0) {
      possible = false;
    }

    sum += rest;
    if (sum < 0) {
      possible = false;
    }
  }

  if (sum != 0) {
    possible = false;
  }

  if (possible) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}

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

using ll = long long;
// #define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

int Lcm(int, int);
bool IsPrime(int);
int Factorial(int);
int NPR (int, int);
int NCR (int, int);

/***** MAIN *****/
signed main() {
  int n;
  cin >> n;
  int a[n], b[n];
  vector<int> v(n);
  REP(i,n) {
    cin >> a[i];
    v[i] = i+1;
  }
  REP(i,n) cin >> b[i];
  int a_position = 0, b_position = 0;
  bool a_flag = true, b_flag = true;
  int current_position = 0;
  do {
    REP(i,n) {
      if(a_position && b_position) break;
      if(!a_position) {
        if(a[i] != v[i]) a_flag = false;
      }
      if(!b_position) {
        if(b[i] != v[i]) b_flag = false;
      }
    }
    if(!a_position && a_flag) a_position = current_position;
    if(!b_position && b_flag) b_position = current_position;
    a_flag = true;
    b_flag = true;
    ++current_position;
  } while(next_permutation(ALL(v)));

  cout << abs(a_position - b_position);
  
  cout << "\n";
  return 0;
}
/***** MAIN *****/

int Lcm(int a, int b) {
  int bigger = max(a,b);
  int smaller = min(a,b);
  int ans = bigger;
  while(ans%smaller!=0) ans+=bigger;
  return ans;
}

bool IsPrime(int a) {
  if(a <= 1) return false;
  if(a == 2) return true;
  if(a%2 == 0) return false;
  for(int i = 3; i*i <= a; i+=2) {
    if(a%i==0) return false;
  }
  return true;
}

int Factorial(int n){
  int ans = 1;
  while(n > 1){
    ans *= n;
    --n;
  }
  return ans;
}

int NPR(int n, int r) {
  return Factorial(n)/Factorial(n-r);
}

int NCR (int n, int r){
  return NPR(n,r)/Factorial(r);
}

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

int binarySearch(int );
#define N 100000
#define Q 50000
#define true 1
#define fault 0

int S[N], n;

int main(){
  int T[Q];
  int q, i, hantei, count=0;

  scanf("%d", &n);
  if(n > N) exit(1);
  for(i=0; i<n; i++){
    scanf("%d", &S[i]);
    if(S[i] < 0 || S[i] > 1000000000) exit(2);
  }

  scanf("%d", &q);
  if(q > Q) exit(3);
  for(i=0; i<q; i++){
    scanf("%d", &T[i]);
    if(T[i] < 0 || T[i] > 1000000000) exit(4);

    hantei = binarySearch( T[i] );
    if(hantei == 1) count++;
  }

  printf("%d\n",count);


  return 0;
}

int binarySearch(int x){
  int left=0, right=n, mid;

  while(left < right){
    mid = (left + right)/2;
    if ( S[mid] == x) return true;
    else if( x < S[mid]) right = mid;
    else left = mid +1;
  }

  return fault;
}



Measured memory_bytes: 2320
import Control.Applicative( (<$>))
import Data.List( sort)
import Control.Monad( replicateM)
main = do
    [n_, c_, k_] <- map read . words <$> getLine
    ts_ <- replicateM n_ readLn::IO [Int]
    let
	sortedT = sort ts_

	bus total onbus	_	[]	    
	  | onbus > 0			    = total+1
	  | otherwise			    = total
	bus total onbus limt times@(t:ts)   = case limt of

	    Nothing	-> bus total (onbus+1) (Just$t+k_) ts
	    Just lim    -> if t <= lim
			    then if onbus<c_
				    then bus total (onbus+1) (Just lim) ts
				    else bus (total+1) 0 Nothing times
			    else bus (total+1) 0 Nothing times
    print $ bus 0 0 Nothing sortedT

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

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x = x2, y = y2;
  int dx = x2 - x1, dy = y2 - y1;

  for (int i = 0; i < 2; i++) {
    swap(dx, dy);
    dx = -dx;
    x += dx;
    y += dy;
    cout << x << " " << y << (i ? '\n' : ' ');
  }
  return 0;
}

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


using namespace std;

int main(){

	int N;

	cin >> N;

	if( N == 1){
		cout << "Hello World" << endl;
	} else {
		int A, B;
		cin >> A >> B;
		cout << A + B << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rep(i, l, r) for(int i = (l); i < (r); ++i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
//-------
int n, m;
int main() {
	scanf("%d%d", &n, &m);
	ll ans = (m != 0) * (n - m);
	for(int base = m + 1; base <= n; base++) {
		for(int l = base; l <= n; l += base) {
			int r = min(n + 1, l + base);
			ans += max(0, r - (l + m));
		}
		ans += n - base;
	}
	printf("%lld\n", ans);
	return 0;
}



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

int main() {

    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll ans = max(a*c, a*d);
    ans = max(ans, b*c);
    ans = max(ans, b*d);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

int sum_int(vector<int> &a){
  int sum=0;
  rep(i,a.size()) sum+=a.at(i);
  return sum;
}

int main(){
  int n,g;
  cin>>n>>g;
  g=g/100;
  vector<int> p(n),c(n);
  rep(i,n){
    cin>>p.at(i)>>c.at(i);
    c.at(i)=c.at(i)/100;
  }
  int ans=10000;
  rep(trs,(1<<n)){
    int sum=0;
    int count=0;
    bitset<10>r =trs;
    rep(i,10){
      if(r.test(i)){
        
        sum+=(i+1)*p.at(i)+c.at(i);
        count+=p.at(i);
        
      }
      
    }
    //if(trs==1)
          //cout<<"1a "<<count<<" "<<c.at(0)<<endl;
    if(sum<g){
        for(int i=n;i>0;i--){
          if(!r.test(i-1)){
            rep(j,p.at(i-1)){
              sum+=i;
              count++;
              if(sum>=g)
                break;
            }
          }
          if(sum>=g)
            break;
        }
    }
    if(sum<g)
      continue;
    //else
      //cout<<r<<endl;
    //cout<<count<<" ";
    ans=min(count,ans);
    
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>
#include <cstring>
#include <algorithm>
#include <list>
using namespace std;
typedef struct _pt {
	int X;
	int Y;
	int color;
}MyPoint;
bool myfunctionX(MyPoint &a, MyPoint &b)
{
	return  (a.X < b.X);
		
}
bool myfunctionY(MyPoint &a, MyPoint &b)
{
	return  (a.Y < b.Y);

}
int main()
{
	int N,res=0;
	cin >> N;
	MyPoint * pMypts;
	list<MyPoint> mylist;

	pMypts = new MyPoint[2*N];
	
	for (int i = 0; i < N; i++)
	{
		cin >> pMypts[i].X >> pMypts[i].Y;
		pMypts[i].color = 0;
	}
	for (int i = N; i < 2*N; i++)
	{
		cin >> pMypts[i].X >> pMypts[i].Y;
		pMypts[i].color = 1;
	}
	sort(pMypts, pMypts + 2 * N,myfunctionX);
	for (int i = 0; i < 2 * N; i++)
	{
		if (pMypts[i].color == 0)
		{
			mylist.push_back(pMypts[i]);
		}
		else if(mylist.size() > 0)
		{
			mylist.sort(myfunctionY);
			mylist.reverse();
			for (list<MyPoint>::iterator it = mylist.begin(); it != mylist.end(); it++)
			{
				if (pMypts[i].Y > it->Y)
				{
					mylist.erase(it);
					res++;
					break;
				}
			}
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
// D - Pairs

using namespace std;

#define MAXPROD 1000000000000000001LL
#define EPS 1e-12L

long long A[200005];

int main() {
    int N,i;
    long long lo,hi,mid,cnt,K;

    scanf("%d%lld",&N,&K);
    for (i = 0;i < N;i++)
        scanf("%lld",&A[i]);
    sort(A,A + N);

    lo = -MAXPROD;
    hi = MAXPROD;
    while ((hi - lo) > 1) {
        mid = (lo + hi) / 2LL;
        
        cnt = 0;
        for (i = 1;i < N;i++) {
            if (A[i] == 0) {
                if (mid >= 0)
                    cnt += i;
            }
            else if (mid == 0) {
                if (A[i] < 0)
                    cnt += i - (lower_bound(A,A + i,0) - A);
                else
                    cnt += upper_bound(A,A + i,0) - A;
            }
            else {
                if (A[i] < 0) {
                    if (mid % A[i] == 0)
                        cnt += i - (lower_bound(A,A + i,mid / A[i]) - A);
                    else if (mid > 0)
                        cnt += i - (lower_bound(A,A + i,mid / A[i]) - A);
                    else
                        cnt += i - (upper_bound(A,A + i,mid / A[i]) - A);
                }
                else {
                    if (mid % A[i] == 0)
                        cnt += upper_bound(A,A + i,mid / A[i]) - A;
                    else if (mid > 0)
                        cnt += upper_bound(A,A + i,mid / A[i]) - A;
                    else
                        cnt += lower_bound(A,A + i,mid / A[i]) - A;
                }
            }
        }

        if (cnt >= K)
            hi = mid;
        else
            lo = mid;
    }

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

    return 0;
}


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

int main() {
    int n,m,a,b;
    cin>>n>>m;
    vector<int>cnt(n,0);
    for (int i = 0; i < m; i++)
    {
        cin>>a>>b;
        cnt[a-1]++;
        cnt[b-1]++;
    }
    for (int i = 0; i < n; i++)
    {
        cout<<cnt[i]<<endl;
    }
    
    
}

Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
mod=1000_000_000+7
l=[0]*n
r=[0]*n
total=[0]*n
for i in range(n):
    for j in range(n):
        if a[i]>a[j]:
            if i>=j:
                l[i]+=1
            else:
                r[i]+=1
            total[i]+=1


ans=0

for i in range(n):
    ans+=(total[i]*k*(k+1))//2 
    ans-=k*l[i]

print(ans%mod)

Measured memory_bytes: 9240
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

h,w = inm()
a = []
for i in range(h):
    a.append(list(ins()))
q = []
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            q.append((i,j))
cnt = 0
#ddprint(a)
#ddprint(q)
while len(q)>0:
    qq = []
    while len(q)>0:
        i,j = q.pop()
        for dx,dy in [(0,1),(0,-1),(1,0),(-1,0)]:
            x = i+dx
            y = j+dy
            if 0<=x<h and 0<=y<w and a[x][y]=='.':
                a[x][y] = '#'
                qq.append((x,y))
    q = qq
    if len(q)>0:
        cnt += 1
    #ddprint(a)
    #ddprint(q)
print(cnt)


Measured memory_bytes: 127916
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;
int main(){
  int A,B,C;cin>>A>>B>>C;
  if( (A==5&&B==5&&C==7) || (A==5&&B==7&&C==5) ||(A==7&&B==5&&C==5)  )cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int k, n;
int a[1000][1000];
int main() {
	scanf("%d", &k); n = (k + 3) / 4 * 2;
	if (k == 1) {
		printf("1\n1\n"); return 0;
	}
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j) {
			if (i & 1) a[i][j] = n + (i + j) % n;
			else a[i][j] = (i + j) % n;
			if (a[i][j] >= k) a[i][j] -= n;
		}
	printf("%d\n", n);
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			printf("%d%c", a[i][j] + 1, " \n"[j == n - 1]);
}


Measured memory_bytes: 3200
import qualified Data.Vector.Unboxed as V
import Data.Array.IArray (listArray, accumArray, (!))
import Data.Array.MArray
import Data.Array.ST (STUArray, runSTUArray)
import Data.Array.Unboxed (UArray)
import Data.List (sortOn, sortBy, unfoldr, partition)
import Data.Char (isSpace)
import Control.Monad.ST (ST)
import Control.Monad.Trans.State (StateT(..))
import qualified Data.ByteString.Char8 as B

-- utility functions

--   Input functions
readInt = B.readInt . B.dropWhile isSpace

readInts :: Int -> B.ByteString -> [Int]
readInts n = take n . unfoldr readInt

readIntsV :: Int -> B.ByteString -> V.Vector Int
readIntsV n = V.unfoldrN n readInt

readIntsA :: Int -> B.ByteString -> UArray Int Int
readIntsA n bs = runSTUArray $ do
  arr <- newArray_ (0,n-1)
  go arr 0 bs
  return arr
  where
    go :: STUArray s Int Int -> Int -> B.ByteString -> ST s ()
    go arr i bs
      | i==n = return ()
      | otherwise = do
        let Just (x,bs') = readInt bs
        writeArray arr i x
        go arr (i+1) bs'

readTsV :: Int -> B.ByteString -> V.Vector (Int,Int)
readTsV n = V.unfoldrN n $ runStateT ((,) <$> StateT readInt <*> StateT readInt)

readTs :: Int -> B.ByteString -> [(Int,Int)]
readTs n = take n . unfoldr readT where
  readT = runStateT ((,) <$> StateT readInt <*> StateT readInt)

-- main

main = do
  [a,b] <- map read . words <$> getLine :: IO [Int]
  if a==b then print $ a*2
  else let x = max a b in print $ x + (x-1)


Measured memory_bytes: 508
#include <iostream>
using namespace std;
 
int main(){
  string s;
  long long k;
  cin>>s;
  cin>>k;
  for(int i=0;i<min((long long)s.size(),k);i++){
    if(s[i]>='2'){
      cout<<s[i]<<endl;
      return 0;
    }
  }
  cout<<'1'<<endl;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long double ld;
typedef long long ll;
const int MOD =  1000000007;
const int IINF = INT_MAX;
const ll INF = 1LL << 60;


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

    ll tmp = 100;
    ll cnt = 0;
    while(1){
        tmp += (tmp / 100);
        cnt++;
        if(tmp >= x){
            cout << cnt << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3644
int main() {
int i,X,Y,s;
int a[10];
scanf("%d",&X);
Y=X;
for (i=0;i<10;i++) {
a[i]=Y%10;
Y=(Y-a[i])/10;
}
for (i=0;i<10;i++) {
s=s+a[i];
}
if (X%s==0)
printf("Yes\n");
else
printf("No\n");
return 0;
}

Measured memory_bytes: 128
N = int(input())
A = [int(input()) for i in range(N)]
m1 = max(A[0], A[1])
m2 = min(A[0], A[1])
for i in range(2,N):
    if m1 < A[i]:
        m1, m2 = A[i], m1
    elif m2 < A[i]:
        m2 = A[i]
print("\n".join(map(str, [m1 if i != m1 else m2 for i in A])))

Measured memory_bytes: 32764
/*
	RAone00
	Rohit sharma
	*/

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

	typedef long long ll;
	typedef long double ld;
	typedef pair < ll, ll > pll;
	typedef vector < vector < ll > > matrix;
	typedef vector < ll > vll;

	#define pb push_back
	#define debug(x) cout << (#x) << " is " << (x) << endl
	#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

	const ll mod = 1e9 + 7;
	const ll inf = LLONG_MAX;
	const ll N = 1e5 + 10;

	
	int main() {
	    fast_io();
	    int a, s;
	    cin >> a >> s;
	    if (s == a) cout << "Yes\n";
	    else cout << "No\n";
	    return 0;
	}

 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
 
int main(){
    ll x;
    cin >> x;
    ll money = 100;
    int year = 0;
    while(money < x){
        money += money * 0.01;
        year++;
    }
    cout << year << endl;
    return 0;
}

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

#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define Puts(x) puts(x? "Yes":"No")
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(int n, int m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(int n, int m) {return (n / gcd(n, m) * m);}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};

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

  int n, w;
  cin >> n >> w;
  vt<int> value(n), weight(n);
  rep(i, 0, n) cin >> value[i] >> weight[i];

  vvt<int> dp(n + 1, vt<int>(w + 1, 0));
  rep(i, 0, n) {
    rep(j, 0, w + 1) {
      if(j >= weight[i]) dp[i + 1][j] = max(dp[i][j], dp[i][j - weight[i]] + value[i]);
      else dp[i + 1][j] = dp[i][j];
    }
  }
  cout << dp[n][w] << endl;
}



Measured memory_bytes: 6756
#include <iostream>
#include <cmath>
#include <vector>
using  std::endl;
using  std::cin;
using  std::cout;
using std::vector;
using std::pair;

int main(void)
{
    int32_t n;
    cin >> n;
    
    uint32_t v[n];
    for (uint32_t i = 0; i < n; i++) {
        cin >> v[i];
    }

    vector<vector<pair<uint32_t, uint32_t>>> patNum;
    patNum.resize(2);
    for (uint32_t i = 0; i < n; i++) {
        bool isMached = false;
        for(uint32_t j = 0; j < patNum[i%2].size(); j++) {
            if (v[i] == patNum.at(i%2).at(j).first) {
                patNum.at(i%2).at(j).second++;
                isMached = true;
            }
        }
        if (!isMached) {
            patNum[i%2].push_back(std::make_pair(v[i], 1));
        }
    }

    if (patNum[0].size() == 1 && patNum[1].size() == 1 && 
        patNum.at(0).at(0).first == patNum.at(1).at(0).first)
    {
        cout << n/2 << endl;
    } else {
        uint32_t maxApNum[2] = {0,0};
        uint32_t maxApIdx[2] = {0,0};
        uint32_t sndMaxApNum[2] = {0,0};
        uint32_t sndMaxApIdx[2] = {0,0};
        for (uint32_t j = 0; j < 2; j++) {
        for (uint32_t i = 0; i < patNum[j].size(); i++) {
            if (maxApNum[j] <= patNum.at(j).at(i).second) {
                sndMaxApNum[j] = maxApNum[j];
                sndMaxApIdx[j] = maxApIdx[j];
                maxApNum[j] = patNum.at(j).at(i).second;
                maxApIdx[j] = patNum.at(j).at(i).first;
            } else if (sndMaxApNum[j] <= patNum.at(j).at(i).second) {
                sndMaxApNum[j] = patNum.at(j).at(i).second;
                sndMaxApIdx[j] = patNum.at(j).at(i).first;
            };
        }
        }

        if (maxApIdx[0] != maxApIdx[1]){
            cout << n - maxApNum[0] - maxApNum[1]; 
        } else {
            if (sndMaxApNum[0] > sndMaxApNum[1]) {
                cout << n - sndMaxApNum[0] - maxApNum[1];
            } else {
                cout << n - maxApNum[0] - sndMaxApNum[1];
            }
        }
        
    }
    
    return 0;
}



Measured memory_bytes: 1660
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array

main :: IO ()
main = do
  (n:m:_) <- fmap (map read . words) getLine :: IO [Int]
  abs <- replicateM n $ (\(a:b:_) -> (read a, read b)) . words <$> getLine :: IO [(Integer, Int)]
  print $ solve m abs

solve m abs = sum . take m . join . map (\(a, b) -> replicate b a) $ sortOn fst abs

Measured memory_bytes: 136572
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	H := getInt()
	N := getInt()
	a := make([]int, N)

	sum := 0
	for i := 0; i < N; i++ {
		a[i] = getInt()
		sum += a[i]
	}

	if sum >= H {
		out("Yes")
	} else {
		out("No")
	}
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A+B>C+D) cout << "Left" << endl;
  else if (A+B<C+D) cout << "Right" << endl;
  else cout << "Balanced" << endl;
}


Measured memory_bytes: 3628
#include<stdio.h>
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<b){
		printf("a < b\n");
	}else if(a>b){
		printf("a > b\n");
	}else{
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
#define ll long long
#define fast ios::sync_with_stdio(false); cin.tie(0);
#define f(i,s,e) for(int i=s;i<e;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define mod 1000000007
#define all(x) x.begin(),x.end()
using namespace std;
int smu[100005];

int main(){
    fast;
    string s;
    cin>>s;
    int ans=0;
    f(i,0,s.size()){
        int curr=0;
        if(s[i]=='A' || s[i]=='G' || s[i]=='C' || s[i]=='T')
        for(int j=i;j<s.size();j++){
            if(s[j]=='A' || s[j]=='G' || s[j]=='C' || s[j]=='T')
                curr++;
            else
                break;
        }
        ans=max(ans,curr);
    }
    cout<<ans;
}


Measured memory_bytes: 256
a = input().split()
b = input().split()
c = []
for i in b:
    c.append(int(i))

if int(a[0]) >= int(a[1]):
    print(0)
else:
    c.sort()
    d = []
    for i in range(int(a[1]) - 1):
        d.append(c[i + 1] - c[i])
    d.sort()
    for i in range(int(a[0]) - 1):
        d.pop()
    ans = 0
    for i in d:
        ans += i
    print(ans)


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

int main(){
	char c11, c12, c13, c21, c22, c23;
	
	cin >> c11 >> c12 >> c13;
	cin >> c21 >> c22 >> c23;

	if (c11 == c23 && c12 == c22 && c13 == c21){
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
	cout << fixed << setprecision(10);
	int n;
	int ans = 0;
	cin >> n;
	vector<int> v(n),c(n);
	rep(i,n) cin >> v[i];
	rep(i,n) cin >> c[i];
	rep(i,n){
		if(v[i]-c[i]>0){
			ans += v[i] - c[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//            ____             ____
//           /@@@@\           |@@@@|      ____
//          /@@@@@@\          |@@@@|     |@@@@|
//         /@@@@@@@@\         |@@@@|   __|@@@@|___    ____       ____      ___  _________     ____        ____    ____________      ___  _________     ____         ____
//        /@@@@/\@@@@\        |@@@@|   @@@@@@@@@@@   |@@@@|     |@@@@|    |@@@\/@@@@@@@@@\   (@@@@\      /@@@@)  /@@@@@@@@@@@@|    |@@@\/@@@@@@@@@\   (@@@@\       /@@@@)
//       /@@@@/  \@@@@\       |@@@@|     |@@@@|      |@@@@|     |@@@@|    |@@@@|    \@@@@@|   \@@@@\    /@@@@/  |@@/     |@@@@|    |@@@@|    \@@@@@|   \@@@@\     /@@@@/
//      /@@@@(____)@@@@\      |@@@@|     |@@@@|      |@@@@|     |@@@@|    |@@@@|     |@@@@|    \@@@@\  /@@@@/            |@@@@|    |@@@@|     |@@@@|    \@@@@\   /@@@@/
//     /@@@@@@@@@@@@@@@@\     |@@@@|     |@@@@|      |@@@@|     |@@@@|    |@@@@|     |@@@@|     \@@@@\/@@@@/    /@@@@@@@@@@@@@|    |@@@@|     |@@@@|     \@@@@\ /@@@@/
//    /@@@@@@@@@@@@@@@@@@\    |@@@@|     |@@@@|___   |@@@@|____/@@@@@|    |@@@@|     |@@@@|      \@@@@@@@@/    (@@@@(   )@@@@@|    |@@@@|     |@@@@|      \@@@@|@@@@/
//   /@@@@/          \@@@@\   |@@@@|     |@@@@@@@@    \@@@@@@@@@@@@@@|    |@@@@|     |@@@@|       \@@@@@@/      \@@@@\_/@@@@@@|    |@@@@|     |@@@@|       \@@@@@@@/
//  /@@@@/            \@@@@\  |@@@@|      \@@@@@@/      \@@@@@/  \@@@|    |@@@@|     |@@@@|        )@@@@/        \@@@@@@@/\@@@|    |@@@@|     |@@@@|        \@@@@@/
//                                                                                                (@@@@/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

//-----------------------------------------------
#define all(x)  x.begin(), x.end()
#define sz(x)   (int)x.size()
#define sq(x)   (x) * (x)
#define fr      first
#define sc      second
//-----------------------------------------------
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pli = pair<ll, int>;

const int N = 3000 * 1000 + 5;
const ll mod = 1000000007;
const ll INF = 1000000000 * 1ll * 1000000000 + 500000;
const ld pi = acosl(-1.0);

string s, t;

void input() {
    cin >> s >> t;
}

void solve(int testId) {
    int ans = 1000000;
    for (int i = 0; i < s.length() - t.length() + 1; i++) {
        int cur = 0;
        for (int j = 0; j < t.length(); j++) {
            cur += (s[i + j] != t[j]);
        }
        ans = min(ans, cur);
    }
    cout << ans << endl;
}

int main() {
    // freopen("test", "r", stdin);
    int testcases = 1;
    // scanf("%d", &testcases);
    for(int testId = 1; testId <= testcases; testId++) {
        input();
        solve(testId);
    }
    return 0;
}


Measured memory_bytes: 3640
//Bismillahir Rahmanir Raheem
#include<bits/stdc++.h>
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
#define pb push_back
#define inf 1e9
#define all(x) (x).begin(), (x).end()
vector<int> h;
int dp[100002];
int n;

int main()
{
    memset(dp, -1, sizeof(dp));
    cin >> n;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        h.pb(x);
    }
    dp[n - 1] = 0;
    dp[n - 2] = abs(h[n - 1] - h[n - 2]);
    for(int i = n - 3; i >= 0; i--)
        dp[i] = min(dp[i + 1] + abs(h[i] - h[i + 1]), dp[i + 2] + abs(h[i] - h[i + 2]));
    cout << dp[0] << endl;

}






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

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

using namespace std;
const long long MOD = 998244353;
const long long INF = 1LL << 61;

int main() {
	int H, N;
	cin >> H >> N;
	vector<int> A(N), B(N);

	rep(i, N) {
		cin >> A[i];
		cin >> B[i];
	}
	int sumA = accumulate(A.begin(), A.end(), 0);
	int maxA = *max_element(A.begin(), A.end());
	int sumB = accumulate(B.begin(), B.end(), 0);
	vector<vector<long long>> dp(N + 1, vector<long long>(H + maxA + 1, INF));
	rep(i, N + 1)dp[i][0] = 0;

	rep(i, N) {
		rep(w, H + maxA + 1) {
			dp[i + 1][w] = min(dp[i + 1][w], dp[i][w]);
			//dp[i + 1][min(w + A[i], H)] = min(dp[i + 1][min(w + A[i], H)], dp[i + 1][w] + B[i]);
			if (w >= A[i]) dp[i + 1][w] = min(dp[i + 1][w], dp[i + 1][w - A[i]] + B[i]);
		}
	}
	int ans = *min_element(dp[N].begin() + H, dp[N].end());
	cout << ans;
}

Measured memory_bytes: 87936
#include<stdio.h>
int main(){
int X, Y;
int i, ans = 0;

scanf("%d %d", &X, &Y);
for(i = 0; i <=X; ++i){
  if((2*i + 4*(X-i)) == Y){
    ans =1;
  }
}
if(ans == 0){
  printf("No");
}else{
  printf("Yes");
}
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, 0);
  for(int i = 0; i < m; i++){
    int k;
    cin >> k;
    a.at(k) = 1;
  }
  const long long mod = 1000000007;
  
  if(n == 1){
    cout << 1 << endl;
    return 0;
  }
  vector<long long> dp(n);
  dp.at(0) = 1;
  if(!a.at(1)) dp.at(1) = 1;
  for(int i = 2; i < n; i++){
    if(a.at(i)){
      dp.at(i) = 0;
      continue;
    }
    dp.at(i) = (dp.at(i - 1) + dp.at(i - 2)) % mod;
  }
  
  long long ans = (dp.at(n - 1) + dp.at(n - 2)) % mod;
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define mod 1000000007
int main() {
    fio;
    int n, x, t;
    cin >> n >> x >> t;
    if (n <= x) {
        cout << t << endl;
    }
    else if (n % x == 0) {
        cout << t*(n / x);
    }
    else if (n % x != 0) {
        ll ans = (n / x) + 1;
        cout << t*ans << endl;
    }
    return 0;
}

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

#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()

const int mod = 1e9+7;
const int inf = 2e18;

int modularExponentiation(int base,int exponent,int modulo)
{
	if(exponent==0)
		return 1;
	
	
	if(!(exponent&1))
	{	
		int res = modularExponentiation(base,exponent/2,modulo);
		return (res*res)%modulo;
	}
	else
	return ((base%modulo)*modularExponentiation(base,exponent-1,modulo))%modulo;
}


int32_t main()
{	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	string s;
	cin>>s;

	int n = s.size();

	int mp[2029]={0};	


	int k = 0;
	int pre[n+1]={0};

	int m = 2019;
	//pre[0]=1;
	for(int i=n-1;i>=0;i--)
	{
		int curr_digit = s[i]-'0';
		int curr_pow = modularExponentiation(10,k,m);

		int t1 = ((curr_pow%m)*(curr_digit%m))%m;
		int t2 = ((i+1)<n)?pre[i+1]:0;

		pre[i] = (t1%m+t2%m)%m;
		k++;
	}
	mp[0]++;
	for(int i=0;i<n;i++)
	{
		mp[pre[i]]++;
		//cout<<pre[i]<<" ";
	}

	int ans = 0;

	for(int i=0;i<2019;i++)
	{
		int val = mp[i];
		ans+=(val*(val-1))/2;
	
	}
	cout<<ans<<'\n';
	return 0;
}	

Measured memory_bytes: 5316
def d():
    h, w = map(int, input().split())
    n = int(input())
    a = [int(ai) for ai in input().split()]
    s = ''
    tmp = ''
    for i in range(h*w):
        if (i // w) % 2 == 0:
            # print('l2r')
            # from left to right
            tmp += '{'+str(i)+'}'
            if i%w == w-1:
                tmp += '\n'
                s += tmp
                tmp = ''
            else:
                tmp += ' '
        else:
            # print('r2l')
            # from right to left
            tmp = '{'+str(i)+'}' + tmp
            if i%w == w-1:
                tmp += '\n'
                s += tmp
                tmp = ''
            else:
                tmp = ' ' + tmp
    aa = []
    for i, n in enumerate(a):
        aa += [i+1]*n
    print(s.format(*aa)[:-1])

d()

Measured memory_bytes: 3796
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int a,b,c,d; cin>>a>>b>>c>>d;
  int A;
  if(a<c){
    swap(a,c);
    swap(b,d);
  }
  if(d<a)
  cout<<0<<endl;
  else if(d>b)
  cout<<b-a<<endl;
  else
  cout<<d-a<<endl;


  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int mymin(int x,int y) {return x<y?x:y;}
int mymax(int x,int y) {return x>y?x:y;}

int hou[110];
int match[110],chw[110];
struct edge
{
	int y,g;
}e[11000];
int ln=0;
void ins(int x,int y)
{
	ln++;
	e[ln].y=y;
	e[ln].g=hou[x];
	hou[x]=ln;
}

int t;
int solve(int x)
{
	for(int k=hou[x];k>0;k=e[k].g)
	{
		int y=e[k].y;
		if(chw[y]<t)
		{
			chw[y]=t;
			if(match[y]==0 or solve(match[y]))
			{
				match[y]=x;
				return 1;
			}
		}
	}
	return 0;
}

int a[110],b[110],c[110],d[110];
int main()
{
	int n;scanf("%d",&n);ln=0;
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
	for(int i=1;i<=n;i++) scanf("%d%d",&c[i],&d[i]);
		
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(a[i]<c[j] and b[i]<d[j])
				ins(i,j);
		
	memset(chw,0,sizeof(chw));
	int ans=0;
	for(t=1;t<=n;t++) ans+=solve(t);
	printf("%d",ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <sstream>

using namespace std;

int ans[10000];

int main(){
	
	for(int i = 0; i < 10000; i++){
		ans[0] = 0;
	}
	
	for(int i = 1; i <= 1000; i++){
		int sum = 0;
		for(int j = i; j <= 1000; j++){
			sum += j;
			if(sum > 1000){
				break;
			}
			if(j - i > 0){
				ans[sum]++;
			}
		}
	}
	
	int N;
	
	while(true){
		cin >> N;
		if(N == 0){
			break;
		}
		cout << ans[N] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3060
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

K, Q = na()
d = na()

for z in range(Q):
    n, x, m = na()

    n -= 1

    rem = n%K
    pre = m-1
    x %= m
    ans = 0
    for i in range(rem):
        pre = x
        x = (x + d[i]) % m
        if pre < x:
            ans += 1

    lpre = 0
    turn = 0
    # print(d[rem:] +  d[:rem])
    for v in d[rem:] + d[:rem]:
        cur = (lpre + v) % m
        if lpre < cur:
            turn += 1
        lpre = cur
    my = turn*m - lpre
    # print(turn, m, my, n//K, x)
    ans += (my * (n//K) + m-x-1) // m - (m-x-1)//m
    print(ans)


Measured memory_bytes: 51932
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int N, M;
map<pair<int,int>,int> edges;
vector<int> G[55];

vector<int> getPath(int x, int y){
  vector<int> dist(55, -1);
  queue<pair<int,int>> que;
  que.push(make_pair(x,0));
  while(!que.empty()){
    pair<int,int> p = que.front(); que.pop();
    dist[p.first] = p.second;
    rep(i,G[p.first].size()){
      int nxt = G[p.first][i];
      if(dist[nxt] != -1) continue;
      que.push(make_pair(nxt,p.second+1));
    }
  }

  vector<int> ret;
  int now = y;
  while(now != x){
    int nxt = -1;
    rep(i,G[now].size()){
      if(dist[now]>dist[G[now][i]]){
        nxt = G[now][i];
      }
    }
    ret.push_back(edges[make_pair(now,nxt)]);
    now = nxt;
  }
  return ret;
}

int main(){
  cin >> N;
  rep(i,N-1){
    int a, b;
    cin >> a >> b;    
    edges[make_pair(a,b)] = i;
    edges[make_pair(b,a)] = i;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  cin >> M;
  vector<ll> cst;
  rep(i,M){
    int u, v;
    cin >> u >> v;
    ll tmp = 0;
    vector<int> res = getPath(u,v);
    rep(j,res.size()){
      tmp |= (1LL<<res[j]);
    }
    cst.push_back(tmp);
  }

  ll ret = 0;
  for(ll S=1; S<(1<<M); S++){
    int cnt = 0;
    ll tmp = 0;
    rep(i,M){
      if((S>>i)&1){
        cnt++;
        tmp |= cst[i];
      }
    }
    int n_edge = 0;
    rep(i,N-1) if((tmp>>i)&1) n_edge++;
    
    ll sum = 1LL<<(N-1-n_edge);
    if(cnt%2==1){
      ret += sum;
    }else{
      ret -= sum;
    }
  }
  
  cout << (1LL<<(N-1)) - ret << endl;
  
  return 0;
}



Measured memory_bytes: 256
import bisect
N, M, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]

A_sum = [0]
a_sum = 0
for a in A:
  a_sum += a
  A_sum.append(a_sum)
B_sum = [0]
b_sum = 0
for b in B:
  b_sum += b
  B_sum.append(b_sum)

ans = 0
for i in range(N+1):
  b_time = K - A_sum[i]
  if b_time < 0:
    break
  idx = bisect.bisect_right(B_sum, b_time)
  ans = max(ans, i + idx-1)
print(ans)


Measured memory_bytes: 127236
#include <bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
const int INF = 1000100100;

int main(){
    ll n,m,p,q,t,min=INF;
    cin>>n>>m;
    p=n%2019;
    q=m%2019;  
    if(m-n>=2019||p>=q){
        cout<<0;
    }else{
        for(int i=p;i<=q-1;i++){
            for(int j=i+1;j<=q;j++){
                t=(i*j)%2019;
                if(min>t){
                    min=t;
                }
            }
        }
        cout<<min;
    }
}

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

bool isPossible(int px, int py, int nx, int ny, int t) {
    int dt = t - (abs(nx - px) + abs(ny - py));
    if (dt % 2 == 0 && dt >= 0) {
        return true;
    }
    return false;
}

int main() {
    int count;
    cin >> count;

    int pt = 0, px = 0, py = 0;
    for (int i = 0; i < count; i++) {
        int t, x, y;
        cin >> t >> x >> y;
        if (!isPossible(px, py, x, y, t - pt)) {
            cout << "No" << endl;
            return 0;
        }
        pt = t; px = x; py = y;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if (n == 0) {
		    System.out.println(0);
		    return;
		}
		boolean flag = true;
		StringBuilder sb = new StringBuilder();
		while (n != 0) {
		    int mod = n % 2;
		    sb.append(Math.abs(mod));
		    if (flag) {
		        n -= Math.abs(mod);
		    } else {
		        n += Math.abs(mod);
		    }
		    n /= 2;
		    flag ^= true;
		}
		System.out.println(sb.reverse());
	}
}


Measured memory_bytes: 23764
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
count=0
for i in range(n):
    t,x,y=l[i][0],l[i][1],l[i][2]
    if t>=x+y and t%2==(x+y)%2:
        count+=1
print("Yes" if count==n else "No")

Measured memory_bytes: 27300
def solve(d,c,s,k):
    last=[0]*27
    srate=[]
    ans=[]
    for i in range(1,d+1):
        a=0
        for j in range(1,27):
            a-=c[j-1]*(i-last[j])
        pa=0
        mlast=[0]*2
        for t in range(1,27):
            if s[i-1][t-1]+c[t-1]*(min(k*(k-1)/2,(366-d)*((366-d)-1)/2))>pa:
                mlast=[t,i]
                pa=s[i-1][t-1]+c[t-1]*(i-last[t])
        a+=pa
        last[mlast[0]]=mlast[1]           
        ans.append(mlast[0])
        srate.append(a)
    return ans,srate

def main():
    d=int(input())
    c=list(map(int,input().split()))
    s=[list(map(int,input().split())) for _ in range(d)]
    mrate=0
    ans,srate=solve(d,c,s,3)
    for i in ans:
        print(i)
    #print(srate[-1])

if __name__ == '__main__':
    main()

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

typedef long long ll;

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	vector<int> p(n, 0), l(n, 0);
	vector<ll> c(n, 0), s(n, 0);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &p[i]);
		p[i]--;
	}
	for (int i = 0; i < n; ++i) {
		scanf("%lld", &c[i]);
	}
	for (int i = 0; i < n; ++i) {
		if (l[i] == 0) {
			int C = 1;
			ll S = c[i];
			for (int j = p[i]; j != i; S += c[j], ++C, j = p[j]);
			l[i] = C;
			s[i] = S;
			for (int j = p[i]; j != i; l[j] = C, s[j] = S, j = p[j]);
		}
	}
	ll a = ll(-1e18);
	for (int i = 0; i < n; ++i) {
		if (k < l[i]) {
			ll tmp = 0;
			for (int j = p[i], m = k; m; --m, j = p[j]) {
				tmp += c[j];
				a = max(a, tmp);
			}
		}
		else if (s[i] > 0) {
			ll tmp = s[i]*ll(k/l[i]-1);
			a = max(a, tmp);
			for (int j = p[i], m = l[i]+k%l[i]; m; --m, j = p[j]) {
				tmp += c[j];
				a = max(a, tmp);
			}
		}
		else {
			ll tmp = 0;
			for (int j = p[i], m = l[i]; m; --m, j = p[j]) {
				tmp += c[j];
				a = max(a, tmp);
			}
		}
	}
	printf("%lld\n", a);
}

Measured memory_bytes: 3916