akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<(n);i++)
#define rep2(i, m, n) for(int i=m;i<(n);i++)
#define rrep(i, n, m) for(int i=n;i>=(m);i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N, M;
    cin >> N >> M;
    vector<tuple<int, int, int>> items;
    for (int i = 0; i < M; ++i) {
        int p, y;
        cin >> p >> y;
        items.push_back(make_tuple(p, y, i));
    }
    sort(items.begin(), items.end());
    unordered_map<int, string> ans;
    int ken = -1;
    int cnt = 1;
    for (auto item : items) {
        int p = get<0>(item);
        int i = get<2>(item);
        if (p != ken) {
            cnt = 1;
            ostringstream s1, s2;
            s1 << setw(6) << setfill('0') << p;
            s2 << setw(6) << setfill(('0')) << cnt;
            ans[i] = s1.str() + s2.str();
            ken = p;
        }else{
            cnt ++;
            ostringstream s1, s2;
            s1 << setw(6) << setfill('0') << p;
            s2 << setw(6) << setfill(('0')) << cnt;
            ans[i] = s1.str() + s2.str();
        }
    }
    for (int i = 0; i < M; ++i) {
        cout << ans[i] << endl;
    }

}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


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

int main(){
    int N,M;
    cin >> N >> M;
    if(N>=M){
        cout << 0 << endl;
        return 0;
    }
    vector<int> X(M);
    for(int i = 0; i < M; i++)
    {
        cin >> X[i];
    }
    sort(X.begin(),X.end());
    vector<int> dif(M-1);
    for(int i = 0; i < M-1; i++)
    {
        dif[i]=X[i+1]-X[i];
    }
    sort(dif.begin(),dif.end());

    int Ans = X[M-1] - X[0];
    for(int i = 0; i < N-1; i++)
    {
        Ans -= dif[M-2-i];
    }
    cout << Ans << endl;
}

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

int main(){
	ll N,A,B; cin>>N>>A>>B;
	if (A>B){
		cout<<0<<endl;
		exit(0);
	}
	if (A==B){
		cout<<1<<endl;
		exit(0);
	}
	if (N==1){
		cout<<0<<endl;
		exit(0);
	}
	ll minR=A*(N-1)+B;
	ll maxR=A+(N-1)*B;
	ll ret=maxR-minR+1;
	cout<<ret<<endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stdbool.h>
#include<math.h>
#include<sstream>
typedef long long ll;
#define N (1000000000+7)
using namespace std;
typedef pair<int, int> P;
#define INF (-1000)

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

int num[110] = { 0 };

int main(void) {
	ll n, h, a, b, ans = 0;
	cin >> n >> h;
	vector<pair<ll, ll>>p(n), q(n);
	for (int i = 0;i < n;i++) {
		cin >> a >> b;
		p[i] = make_pair(a, b);
		q[i] = make_pair(b, a);
	}
	if (n == 1) {
		ll c = h / p[0].first + 1;
		while (true) {
			if (c*p[0].first + p[0].second >= h)c--;
			else {
				c++;
				break;
			}
		}
		cout << c + 1 << endl;
		return 0;
	}
	sort(p.begin(), p.end());
	sort(q.begin(), q.end());
	/*for (int i = 0;i < n;i++) {
		cout << p[i].first << " " << p[i].second << endl;
	}*/
	ll base = p[n - 1].first;
	for (int i = n-1;i >= 0;i--) {
		if (base <= q[i].first) {
			h -= q[i].first;
			ans++;
			if (h <= 0) {
				cout << ans << endl;
				return 0;
			}
		}
	}
	ll c = h / base;
	if (h%base != 0)c++;
	cout << ans + c << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    string s, t;
    cin >> s >> t;
    vector<int> appear[26];
    for (int i = 0; i < s.length(); i++) {
        appear[s[i] - 'a'].push_back(i);
    }
    
    bool isPossible = true;
    for (int i = 0; i < t.length(); i++) {
        if (appear[t[i] - 'a'].size() <= 0) isPossible = false;
    }
    if (isPossible) {
        long long ans = 0;
        int nowIndex = appear[t[0] - 'a'][0];
        ans += nowIndex;
        for (int i = 1; i < t.length(); i++) {
            vector<int>::iterator it = upper_bound(appear[t[i] - 'a'].begin(), appear[t[i] - 'a'].end(), nowIndex);
            if (it != appear[t[i] - 'a'].end()) {
                ans += *it - nowIndex;
                nowIndex = *it;
            } else {
                ans += s.length() - nowIndex + appear[t[i] - 'a'][0];
                nowIndex = appear[t[i] - 'a'][0];
            }
        }
        cout << ans + 1 << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 1216
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mp make_pair
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define sf(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);


int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const double pi = acos(-1.0);

int main()
{
     double r;
     cin >> r;
     cout << 2*pi*r << endl;

    return 0;
}





Measured memory_bytes: 3784
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

k=int(input())
a,b=map(int,input().split())
tmp=0
while tmp<=b:
    tmp+=k
    if a<=tmp<=b:
        print("OK")
        quit()
print("NG")

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

using i32 = int_fast32_t;
using i64 = int_fast32_t;

int main() {
    i32 n, k;
    cin >> n >> k;
    vector<i32> a(n);
    i32 nn = 0, n0 = 0, np = 0;
    for (auto& e : a) {
        cin >> e;
        if (e < 0) nn++;
        if (e == 0) n0++;
        if (e > 0) np++;
    }
    
    i64 ans = 0;
    if (k <= nn * np) {
        vector<i64> v { INT64_MAX };
        vector<i64> n, p;
        for (auto& e : a) {
            if (e > 0) p.push_back(e);
            if (e < 0) n.push_back(e);
        }
        sort(begin(p), end(p));
        sort(begin(n), end(n));
        
        i64 bl = -INT64_MAX / 2, br = -1;
        while (abs(br - bl) > 1) {
            i64 mid = (br + bl) / 2;
            i32 count = 0;
            for (i32 ni = 0, pi = 0; ni < nn; ni++) {
                while (pi < np && n[ni] * p[pi] > mid) pi++;
                count += np - pi;
            }
            (count < k ? bl : br) = mid;
        }
        ans = br;
    } else if ((k -= nn * np + (nn + np) * n0 + n0 * (n0 - 1) / 2) > 0) {
        vector<i64> n, p;
        for (auto& e : a) {
            if (e > 0) p.push_back(e);
            if (e < 0) n.push_back(-e);
        }
        sort(begin(p), end(p));
        sort(begin(n), end(n));

        i64 bl = 0, br = INT64_MAX / 2;
        while (abs(br - bl) > 1) {
            i64 mid = (br + bl) / 2;
            i32 cnt = 0;
            for (auto& e : { n, p }) {
                i32 l = e.size();
                for (i32 i0 = 0, i1 = l-1; i0 < l; i0++) {
                    while (i1 >= 0 && e[i0] * e[i1] > mid) i1--;
                    if (e[i0] * e[i0] < mid) cnt--;
                    cnt += i1 + 1;
                }
            }

            (cnt / 2 < k ? bl : br) = mid;
        }
        ans = br;
    }

    cout << ans << endl;
}


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


int main()
{
  int n, m, p;
  cin >> n >> m >> p;
  vector<int> from(m), to(m), value(m);
  vector<vector<int>> v(n);
  rep(i, m)
  {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    c = p - c;
    from[i] = a;
    to[i] = b;
    value[i] = c;
    v[a].push_back(b);
  }
  vector<ll> cost(n, INT_MAX);
  cost[0] = 0;
  rep(i, n * 2)
    rep(j, m)
    {
      if (cost[from[j]] == INT_MAX)
        continue;
      if (cost[to[j]] > cost[from[j]] + value[j])
      {
        cost[to[j]] = cost[from[j]] + value[j];
        if (i >= n - 1)
        {
          queue<int> q;
          q.push(to[j]);
          vector<bool> chk(n, false);
          while (!q.empty())
          {
            int p = q.front();
            q.pop();
            if (chk[p])
              continue;
            chk[p] = true;
            for (auto&& nxt : v[p])
              q.push(nxt);
          }
          if (chk[n-1])
          {
            cout << "-1\n";
            return 0;
          }
        }
      }
    }
  cout << max(-cost[n-1], 0ll) << endl;
  return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int a[200000];
int main(void)
{
    int i, n, l, r, x = 1, f = 0;
    l = r = 100000;
    scanf("%d",&n);
    if(n%2==0)f=1;
    scanf("%d",&a[100000]);
    while(x<n)
    {
        if(f){scanf("%d",&a[--l]);x++;}
        if(x>=n)break;
        scanf("%d",&a[++r]);x++;
        f = 1;
    }
    for (i=l; i<=r; i++)
    {
        printf("%d ",a[i]);
    }
    return 0;
}


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

int main() {
	string s; cin >> s;
	
	int ans = 10000;
	for(int i=0; i<s.length()-2; i++) {
		int num = 100*(s[i]-'0')+10*(s[i+1]-'0')+(s[i+2]-'0');
		ans = min(ans,abs(num-753));
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;
 
int main(){
  using namespace std;
  long long n, a, b;
  cin>>n>>a>>b;
  long long q, r;
  q = n / (a + b);
  r = n % (a + b);
  long long ans = q * a;
  if(r <= a){
    ans += r;
  }else{
    ans += a;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>

using namespace std;

void solve(long long N, vector<long long> L, vector<long long> R){
    vector< pair< long long, int> > r, l;
    for (int i = 0; i < N; i++) {
        r.push_back(make_pair(L[i], i));
        l.push_back(make_pair(R[i], i));
    }
    sort(r.begin(), r.end());
    sort(l.begin(), l.end());
    vector<int> used(N, 0);
    int ridx = N-1;
    int lidx = 0;
    long long p = 0;
    long long ret = 0;
    for (int i = 0; i < N;) {
        while (used[r[ridx].second] != 0) {
            ridx--;
        }
        if (p < r[ridx].first) {
            ret += r[ridx].first - p;
            p = r[ridx].first;
        }
        used[r[ridx].second] = 1;
        i++;
        if (i >= N) {
            break;
        }
        while (used[l[lidx].second] != 0) {
            lidx++;
        }
        if (p > l[lidx].first) {
            ret += p - l[lidx].first;
            p = l[lidx].first;
        }
        used[l[lidx].second] = 1;
        i++;
        if (i >= N) {
            break;
        }
    }
    ret += abs(p);

    for (int i = 0; i < N; i++) {
        used[i] = 0;
    }
    ridx = N-1;
    lidx = 0;
    p = 0;
    long long ret2 = 0;
    for (int i = 0; i < N;) {
        while (used[l[lidx].second] != 0) {
            lidx++;
        }
        if (p > l[lidx].first) {
            ret2 += p - l[lidx].first;
            p = l[lidx].first;
        }
        used[l[lidx].second] = 1;
        i++;
        if (i >= N) {
            break;
        }
        while (used[r[ridx].second] != 0) {
            ridx--;
        }
        if (p < r[ridx].first) {
            ret2 += r[ridx].first - p;
            p = r[ridx].first;
        }
        used[r[ridx].second] = 1;
        i++;
        if (i >= N) {
            break;
        }
    }
    ret2 += abs(p);
    std::cout << max(ret, ret2) << std::endl;
}

int main(){	
    struct timeval start,end;
    long long span;
    gettimeofday(&start,NULL);

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

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 7012
while True:
    n=int(input())
    if n==0:break
    m=int(input())
    rel=sorted([[int(s)for s in input().split(" ")]for i in range(m)],key=lambda x:x[0])
    isf=[False for i in range(n)]
    inv=[False for i in range(n)]
    isf[0]=True
    for r in rel:
        if r[0]==1:isf[r[1]-1]=True
    for r in rel:
        if isf[r[0]-1]==True:inv[r[1]-1]=True
        elif isf[r[1]-1]==True:inv[r[0]-1]=True
    print(inv.count(True))

Measured memory_bytes: 9552
#pragma warning(disable:4996)
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iostream>
#include<time.h>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
using namespace std;
const int INF = 0x3f3f3f3f;

int p1()
{
    int a,b;
    cin >> a >> b;
    return (a+b+24)%24;
}

void p2()
{
    int m,n;
    cin >> m >> n;
    vector<int> study;
    while(m){
        int a1,b1;
        cin >> a1 >> b1;
        study.push_back(a1);
        study.push_back(b1);
        m--;
    }
    vector<int> point;
    while(n) {
        int c1,d1;
        cin >> c1 >>d1;
        point.push_back(c1);
        point.push_back(d1);
        n--;
    }
    int dist2 = 0;
    int ma = 1000000000;
    int x,y;
    for(int i =0; i<study.size(); i=i+2)
    {
        for(int j=0, index = 0; j<point.size(); j=j+2, ++index)
        {
            dist2 = abs(study[i]-point[j])
                + abs(study[i+1]-point[j+1]);
            if(dist2 < ma)
            {
                ma = dist2;
                x = i+1, y = index+1;
            }
        }
        cout <<y<<endl;
        dist2 = 0;
        ma = 1000000000;
    }
}

int main()
{
    p2();
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    long long i,j,k,n,m,t=75.5,l,r,t1=0,x,y,ans=0;
    cin>>s;
    for(int i=0;i<3;i++)
        ans+=(s[i]=='1');
    cout<<ans<<'\n';
    return 0;
}

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

typedef vector< long long > vi;
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define ll long long
#define MAX 1005
#define mod 1000000007

ll dp[MAX][MAX];
ll table[MAX][MAX];

ll path(ll i, ll j)
{
    if (i < 0 || j < 0)
        return 0;

    if (dp[i][j] == -1)
    {
        if (table[i][j] == 0)
            dp[i][j] = ((path(i - 1, j) % mod) + (path(i, j - 1) % mod)) % mod;
        else
            dp[i][j] = 0;
    }
    return dp[i][j];
}

int main(void)
{
    ll row, col;
    cin >> row >> col;

    for (int i = 0; i < row; i++)
    {
        for (int j = 0; j < col; j++)
        {
            dp[i][j] = -1;
            char c;
            cin >> c;
            if (c == '#')
                table[i][j] = 1;
            else
                table[i][j] = 0;
        }
    }
    dp[0][0] = 1;

    cout << path(row - 1, col - 1) << "\n";
}


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

int main() {
	int n, x, y;
	cin >> n >> x >> y;
	vector<vector<int>> to(n);
	rep(i, n - 1) {
		to[i].push_back(i + 1);
		to[n - i - 1].push_back(n - i - 2);
	}
	x--;
	y--;
	to[x].push_back(y);
	to[y].push_back(x);

	vector<int> ans(n, 0);
	queue<int> que;
	rep(i, n) {
		vector<int> dist(n, -1);
		que.push(i);
		dist[i] = 0;
		while (!que.empty()) {
			int vert = que.front();
			que.pop();
			for (int w : to[vert]) {
				if (dist[w] != -1) continue;
				dist[w] = dist[vert] + 1;
				que.push(w);
			}
		}
		rep(j, n) {
			ans[dist[j]]++;
		}
	}

	for (int i = 1; i < n; i++) {
		cout << ans[i] / 2 << endl;
	}
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
"""
Created on Thu May 14 23:42:46 2020

@author: Kanaru Sato
"""

s = list(input())
Noflag = 0

for i in range(0,len(s)):
    if i%2 == 0:
        if s[i] != "R" and s[i] != "U" and s[i] != "D":
            Noflag = 1
            break
    if i%2 != 0:
        if s[i] != "L" and s[i] != "U" and s[i] != "D":
            Noflag = 1
            break

if Noflag == 1:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
/*
    Created by Ezio112
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
//#define inf ll(10e16)
#define mod ll(10e8+7)
#define ff first
#define ss second
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    ll t;
    //cin>>t;
    t=1;
    while(t--)
    {
        ll n,m;
        cin>>n>>m;
        vector<ll> height(n+1);
        for(ll i=1;i<=n;++i)
            cin>>height[i];

        vector<vector<ll>> graph(n+1);
        vector<ll> good(n+1);
        for(ll i=0;i<m;++i)
        {
            ll a,b;
            cin>>a>>b;
            graph[a].push_back(b);
            graph[b].push_back(a);
        }
        ll count=0;
        for(ll i=1;i<=n;++i)
        {
            if(good[i])
            continue;

            good[i]=1;
            for(ll x:graph[i])
            {
                if(height[x]>=height[i])
                {
                    good[i]=0;
                    break;
                }
            }
        }
        for(ll x:good)
            count+=x;

        cout<<count;
    }
    return 0;
}


Measured memory_bytes: 10564
/** Author : Parth Prajapati
 * 	Institute : Pandit Deendayal Petroleum University
**/
#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    string s[n];
    int i,mx=0;
    map<string,int> mp;
    for(i=0;i<n;++i)
    {
        cin>>s[i];
        ++mp[s[i]];
        mx = max(mp[s[i]],mx);
    }
    set<string> st;
    for(i=0;i<n;++i)
    {
        if(mp[s[i]] == mx)
            st.insert(s[i]);
    }
    for(auto i : st)    cout<<i<<"\n";
    return 0;
}

Measured memory_bytes: 34816
import java.util.*;
public class Main {
	public static void main(String[] args){
      	Scanner sc = new Scanner(System.in);
      	int a1 = sc.nextInt();
        int prev = 0;
        Set<Integer> used = new HashSet<>();
      	for (int i = 1; ; i++) {
          	if (i == 1) {
            	used.add(a1);
              	prev = a1;
            } else {
            	int val = helper(prev);
              	if (used.contains(val)) {
                	System.out.println(i);
                  	break;
                } else {
                	used.add(val);
                  	prev = val;
                }
            }
        }
	}
  
    private static int helper(int n) {
    	if (n % 2 == 0) {
        	return n / 2;
        } else {
        	return 3 * n + 1;
        }
    }
}

Measured memory_bytes: 21844
//Author: AnandRaj doubleux
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test(t) int t;cin>>t;while(t--)
#define forn(i,f,n) for(int i=f;i<f+n;i++)
#define rforn(i,l,n) for(int i=l;i>l-n;i--)
#define all(v) v.begin(),v.end()
#define prin(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int i=f;i<f+n;i++) cin>>V[i]
#define what(x) cerr<<#x<<" = "<<x<<endl

const int MOD = 1e9+7,MAX = 1e5+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
/////////////////FastExp///////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX+1, true);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
        	for (j = i * i; j <= MAX; j += i)
            	is_prime[j] = false;
    	}
	}
}
//////////////////Sieve////////////////////


int main()
{	
	int fac[9];
	fac[0]=1;
	for(int i=1;i<9;i++) fac[i]=i*fac[i-1];
	int n;
	cin>>n;
	vi P(n),Q(n),R(n);
	for(int i=0;i<n;i++) R[i]=i+1;
	take(P,0,n);
	take(Q,0,n);
	int a,b;
	for(int i=0;i<fac[n];i++)
	{
		bool yes=true;
		for(int j=0;j<n;j++)
		{
			if(P[j]!=R[j]) yes=false;
		}
		if(yes) a=i;
		yes=true;
		for(int j=0;j<n;j++)
		{
			if(Q[j]!=R[j]) yes=false;
		}
		if(yes) b=i;
		next_permutation(all(R));
	}
	cout<<abs(a-b)<<endl;
	
}

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

#define ll long long

int main(){

    int i,j,k;
    int N,H,W;
    int a,b,c;
    int count = 0;

    cin >> a;
    cin >> b;

    if(a < b){
        if(16-2*a >= (b-a)*2)cout << "Yay!" << endl;
        else cout << ":(" << endl;
        return 0;
    }

    else{
        if(16-2*b >= (a-b)*2)cout << "Yay!" << endl;
        else cout << ":(" << endl;
        return 0;        
    }

    return 0;

}

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

using namespace std;
const int maxn = 1e5 + 5;
int f[maxn], h[maxn], n, k;

int dp(int i)
{
    if (i > n) return 1e9;
    if (i == n) return 0;
    if (f[i] != -1) return f[i];
    f[i] = 1e9 + 7;
    for(int j=1; j<=k; ++j){
        int cost = abs(h[i] - h[i+j]);
        f[i] = min(f[i], dp(i + j) + cost);
    }
    return f[i];
}

int main()
{
    #ifdef NTMA 
        freopen("abc.inp", "r", stdin);
    #endif
    memset(f, 255, sizeof(f));
    cin >> n >> k;
    for(int i=1; i<=n; ++i) cin >> h[i];
    cout << dp(1) << endl;
}

Measured memory_bytes: 5760
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n = int(input())

if n%2 == 1:
    print(0)
    exit()

base = 10
ans = 0
while base <= n:
    x = n // base
    ans += x
    base *= 5


print(ans)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

class Dijkstra{
public:
  
  typedef tuple<Int,Int> T;
  long long INF = 1LL<<55;
  Int V;
  vector<vector<T> > G;
  
  
  Dijkstra():V(-1){}
  Dijkstra(Int V):V(V),G(V){}
  
  void add_edge(Int a,Int b,Int c){
    assert(a >= 0 && b >= 0);
    assert(a < V && b < V);
    G[a].push_back(T(b,c));
    G[b].push_back(T(a,c));
  }

  vector<Int> dijkstra(Int start){
    vector<Int> D(V,INF);
    vector<Int> visited(V,0);
    priority_queue<T,vector<T>,greater<T> > Q;
    Q.push(T(0,start));
    D[start] = 0;
    while(!Q.empty()){
      Int cost, pos;
      tie(cost,pos) = Q.top(); Q.pop();

      assert(!visited[pos] || D[pos] <= cost);
      if(visited[pos]++) continue;

      for(auto t:G[pos]){
        Int to = get<0>(t);
        Int ncost = cost + get<1>(t);
        if(D[to] <= ncost) continue;
        D[to] = ncost;
        Q.push(T(ncost,to));
      }
    }
    return D;
  }
};


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int n,m,s,t;
  cin>>n>>m>>s>>t; s--, t--;
  Dijkstra A(n), B(n);
  for(Int i=0;i<m;i++){
    Int u,v,a,b;
    cin>>u>>v>>a>>b; u--, v--;
    A.add_edge(u, v, a);
    B.add_edge(u, v, b);
  }

  
  auto DA = A.dijkstra(s);
  auto DB = B.dijkstra(t);

  priority_queue<P, vector<P> ,greater<P> > Q;
  for(Int i=0;i<n;i++){
    Int a = DA[i];
    Int b = DB[i];
    Int cost = a + b;
    Q.push(P(cost, i));
  }

  const Int N = 1e15;
  for(Int i=0;i<n;i++){
    while(Q.top().second < i) Q.pop();
    Int ans = Q.top().first; 
    cout<<N - ans<<endl;
  }

  
  
  return 0;
}


Measured memory_bytes: 20900
#!/usr/bin/env python3
import sys
from bisect import bisect_left
INF = float("inf")


def solve(N: int, A: "List[int]"):
    X = []
    for a in A:
        i = bisect_left(X, a)
        if i < len(X) and X[i] == a:
            X.pop(i)
        else:
            X.insert(i, a)
    print(len(X))

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 7840
#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;
int main(){
  int n,dp[1010][1010],i,j,k,a,b;
  scanf("%d\n",&n);
  for(k=0;k<n;k++){
    string x,y;
    cin >> x >> y;
    a=x.size(),b=y.size();
    for(i=0;i<=a;i++){
      for(j=0;j<=b;j++){
        dp[i][j]=0;
      }
    }
    for(i=1;i<=a;i++){
      for(j=1;j<=b;j++){
        if(x[i-1]==y[j-1]){
          dp[i][j]=dp[i-1][j-1]+1;
        }
        else{
          if(dp[i-1][j]>dp[i][j-1]){
            dp[i][j]=dp[i-1][j];
          }
          else{
            dp[i][j]=dp[i][j-1];
          }
        }
      }
    }
      printf("%d\n",dp[a][b]);
    }
  return 0;
}


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

int main(void)
{
    int merchant_num;
    int popular_merchant_num;

    cin >> merchant_num >> popular_merchant_num;

    vector<int> vote_num(merchant_num);

    //総得票数
    int vote_sum = 0;
    double select_criteria;
    for(int i = 0; i < (int)vote_num.size(); i++)
    {
        cin >> vote_num[i];
        vote_sum += vote_num[i];
    }
    select_criteria = (double)vote_sum / (double)(4 * popular_merchant_num);

    int select_cnt = 0;
    //cout << "vote_sum = " << vote_sum << endl;
    //cout << "criteria = " << select_criteria << endl;
    
    for(int i = 0; i < (int)vote_num.size(); i++)
    {
        if(vote_num[i] >= select_criteria)
        {
            select_cnt++;
        }
    }

    if(select_cnt >= popular_merchant_num)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	using graph_t = std::vector<std::set<index_t>>;
	template<class T>using weighted_graph_t = std::vector<std::map<index_t, T>>;
	template<class T>using pair = std::pair<T, T>;

	struct max_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::max(lhs, rhs);
		}
	};
	struct min_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::min(lhs, rhs);
		}
	};

	constexpr max_t max;
	constexpr min_t min;

	template<class T>auto order_by(T func)
	{
		return [=](auto&& lhs, auto&& rhs)
		{
			return func(lhs) < func(rhs);
		};
	}

	template<class T>constexpr auto max_v = std::numeric_limits<T>::max();
	template<class T>constexpr auto min_v = std::numeric_limits<T>::min();

	template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;
	
	template<class T>constexpr T pow(T val, std::uint64_t p)
	{
		auto ret = T(1);
		auto s = 1ULL;
		for (auto i = 0; i < 63; ++i, s <<= 1)
		{
			if (p & s)
			{
				ret *= val;
			}
			val *= val;
		}
		return ret;
	}
	template<class Range>void sort(Range& rng)
	{
		std::sort(std::begin(rng), std::end(rng));
	}
	template<class Range, class Pred>void sort(Range& rng, Pred pred)
	{
		std::sort(std::begin(rng), std::end(rng), pred);
	}
}

void Main()
{
	std::size_t N;
	std::cin >> N;
	std::int64_t sum = 0, prev = 0;
	for (auto _ : boost::irange(N))
	{
		std::int64_t v;
		std::cin >> v;
		sum += std::max(std::int64_t(), prev - v);
		prev = std::max(prev, v);
	}
	std::cout << sum << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P; typedef unsigned long long int ull;
const ll mod = 1000000007;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define vec vector<int>
#define vecb vector<bool>
#define vecd vector<double>
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr) {
	if (firstItr < 0 || secondItr>int(str.size() - 1))return str;
	while (firstItr < secondItr) {
		swap(str[firstItr], str[secondItr]);
		firstItr++; secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str) {
	int itr = 0; std::string res;
	while (itr < int(str.size())) {
		char tmp = str[itr++];
		int length = 1;
		while (itr <int(str.size()) && str[itr] == tmp) { ++itr; ++length; }
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
std::string split(std::string str, size_t first_itr, bool isFront) {
	if (first_itr < 0 || first_itr > str.size()) {
		return str;
	}
	else {
		if (isFront) {
			std::string tmp;
			for (size_t i = 0; i < first_itr; i++) {
				tmp.push_back(str.at(i));
			}
			return tmp;
		}
		else {
			std::string tmp;
			for (size_t i = first_itr; i < str.size(); i++) {
				tmp.push_back(str.at(i));
			}
			return tmp;
		}
	}
}

int main() {
	int a, b; cin >> a >> b;
	if (a <= b) {
		cout << "unsafe" << endl;
	}
	else {
		cout << "safe" << endl;
	}

	return 0;
}

Measured memory_bytes: 3632
import sys
sys.setrecursionlimit(1000000000)
N = int(input())

color = [-1 for i in range(N)]

G = [[] for i in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    tpl1 = (v, w)
    tpl2 = (u, w)
    G[u].append(tpl1)
    G[v].append(tpl2)

def dfs(u, c):
    color[u] = c
    for v, w in G[u]:
        if color[v] != -1:
            if color[v] == c and w % 2 != 0:
                return False
        else:
            if w % 2 == 0:
                dfs(v, c)
            else:
                dfs(v, 1-c)
    return True

if dfs(0, 0):
    for i in range(N):
        print(color[i])

Measured memory_bytes: 79408
#include <iostream>

using namespace std;

int n,gx,gy,k;
int x1,x2,y1,y2;

int main()
{
    cin >> n;
    for(int i=0;i<n;i++)
    {
        int a[16][16]={};   //全ての元の値が0になる配列を定義する
        cin >> gx >> gy >> k;
        a[0][0]=1;
        for(int j=0;j<k;j++)
        {
            cin >> x1 >> y1 >> x2 >> y2;
            if(x1==x2)   //より右下の点を探し出す
            {
                y2=max(y1,y2);
                a[x2][y2]+=1;
            }else
            {
                x2=max(x1,x2);
                a[x2][y2]+=2;
            }
        }
        for(int j=1;j<=gx;j++)
        {
            if(a[j][0]==0)
            {
                a[j][0]=a[j-1][0];
            }else
            {
                a[j][0]=0;
            }
        }
        for(int j=1;j<=gy;j++)
        {
            if(a[0][j]==0)
            {
                a[0][j]=a[0][j-1];
            }else
            {
                a[0][j]=0;
            }
        }
        for(int x=1;x<=gx;x++)
        {
            for(int y=1;y<=gy;y++)
            {
                if(a[x][y]==0)
                {
                    a[x][y]=a[x-1][y]+a[x][y-1];
                }else if(a[x][y]==2)
                {
                    a[x][y]=a[x][y-1];
                }else if(a[x][y]==1)
                {
                    a[x][y]=a[x-1][y];
                }else
                {
                    a[x][y]=0;
                }
            }
        }
        if(a[gx][gy]==0)
        {
            cout << "Miserable Hokusai!" << endl;
        }else
        {
            cout << a[gx][gy] << endl;
        }
        
    }
    return 0;
}


Measured memory_bytes: 3016
#include <bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v)              \
  cerr << #v ":[ ";          \
  for (auto macro_vi : v)    \
  {                          \
    cerr << macro_vi << " "; \
  }                          \
  cerr << "]" << endl;
#define ddump(v)                     \
  cerr << #v ":" << endl;            \
  for (auto macro_row : v)           \
  {                                  \
    cerr << "[";                     \
    for (auto macro__vi : macro_row) \
    {                                \
      cerr << macro__vi << " ";      \
    }                                \
    cerr << "]" << endl;             \
  }
#define damp(m)                                                   \
  for (auto macro_pair : m)                                       \
  {                                                               \
    cerr << macro_pair.first << ":" << macro_pair.second << endl; \
  }
#define dpair(p) cerr << #p ":" \
                      << "(" << p.first << "," << p.second << ")" << endl;
// iterate
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define itr(macro_v, i) macro_v.begin() + i
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll x;
  cin >> x;
  vector<bool> dp(10000000, false);
  dp[100] = true;
  dp[101] = true;
  dp[102] = true;
  dp[103] = true;
  dp[104] = true;
  dp[105] = true;
  for (int i = 106; i <= x; i++)
  {
    if (dp[i - 100] or dp[i - 101] or dp[i - 102] or dp[i - 103] or dp[i - 104] or dp[i - 105])
    {
      dp[i] = true;
    }
  }
  if (dp[x] == true)
  {
    cout << 1 << endl;
  }
  else
  {
    cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>

typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
#define rep_r(i,s,n)for(ll i = n;i>s;i--)
#define rep_re(i,s,n)for(ll i = n;i>=s;i--)
using namespace std;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;

ll b[101];
ll a1[101];
ll a2[101];
int main() {
	ll n; cin >> n;
	rep(i, 1, n)cin >> b[i];
	repe(i, 1, n)a1[i] = INF;

	rep(i, 1, n) {
		a1[i] = min(a1[i],b[i]);
		a1[i+1] = min(a1[i+1],b[i]);
	}

	ll ans = 0;
	repe(i, 1, n) ans += a1[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
int s[100][100];
int vis[100];
int main()
{
	ll n,m,i,j,a; ll ss=0;
	for(i=0;i<3;i++)
	for(j=0;j<3;j++)
	{
		cin>>s[i][j];
	}
	cin>>m;
	for(i=0;i<m;i++)
	{
		cin>>a; vis[a]=1;
	}
	if(vis[s[0][0]]==1&&vis[s[1][1]]==1&&vis[s[2][2]]==1)
	ss=1;
//	printf("%d %d %d\n",vis[s[0][0]],vis[s[1][1]],vis[s[2][2]]);
	if(vis[s[2][0]]==1&&vis[s[1][1]]==1&&vis[s[0][2]]==1)
	ss=1;
	for(i=0;i<3;i++)
	{
		if(vis[s[i][0]]==1&&vis[s[i][1]]==1&&vis[s[i][2]]==1)
		ss=1;
	}
	for(j=0;j<3;j++)
	{
		if(vis[s[0][j]]==1&&vis[s[1][j]]==1&&vis[s[2][j]]==1)
		ss=1;
	}
	if(ss)
	printf("Yes\n");
	else
	printf("No\n");


}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
bool read()
{
    char ch=getchar();
    while (ch!='#'&&ch!='.')
        ch=getchar();
    return ch=='#';
}
int n,m,cnt;
bool ma[10][10];
bool f[10][10];
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
        {
            ma[i][j]=read();
            if (ma[i][j])
				cnt++;
		}
	ma[0][1]=true;
	f[0][1]=true;
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
        {
			if (!ma[i][j])
				continue;
			f[i][j]|=f[i-1][j]|f[i][j-1];
            if (ma[i-1][j]^ma[i][j-1]==false)
            {
            	printf("Impossible");
            	return 0;
			}
		}
	if (f[n][m]&&cnt==n+m-1)
    	printf("Possible");
	else
		printf("Impossible");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
const int N=2e5+5;
string s;
int dp[N];
int solve( int i, int prv ) {
    if ( i>=s.size() ) return 0;
    if ( dp[i] ) return dp[i];
    int res=0;
    for ( int j=i; j<=min(i+2,(int)s.size()); j++ ) {
        if ( s.substr(prv,i-prv)==s.substr(i,j-i+1) ) continue;
        chmax(res,solve(j+1,i)+1);
    }
    return dp[i]=res;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> s;
    cout << solve(0,0) << '\n';
    return 0;
}



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

int main() {
  string S;
  cin >> S;
  int sum = 0;
  for (int i = 0; i < S.size(); i++){
    if (S.at(i) == 'o'){
      sum++;
    }
  }
  if (8 - sum <= 15 - S.size()){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


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

int main(){
    int i, n, a, c, m = 100;
    cin >> n;
    for(i=0; i<n; i++){
        cin >> a;
        c = 0;
        while(a%2 == 0){
            a /= 2;
            c++;
        }
        m = min(m, c);
    } 
    cout << m;
    return 0;
}

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

vector<ll> ans;
vector<bool> seen;
void dfs(const Graph &G,int v) {
  seen[v]=true;
  for(auto next_v:G[v]) { 
    if(seen[next_v]) continue; // next_v が探索済だったらスルー
    ans[next_v]+=ans[v];
    dfs(G,next_v);
  }
}
 
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}
ll mpower(ll a,ll b,ll c){
  int z;
  if(b==0){
    z=1;
    z%=c;
    return z;
  }
  if(b==1){
    z=a;
    z%=c;
    return z;
  }
  else{
    return (((mpower(a,b/2,c))*(mpower(a,b/2,c))%c)*mpower(a,b%2,c)%c);
  }
}

int main(){
  int n,q;
  cin>>n>>q;
  Graph G(n);
  for(int i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    G[a-1].push_back(b-1);
    G[b-1].push_back(a-1);
  }
  seen.assign(n,false);
  ans.assign(n,0);
  for(int i=0;i<q;i++){
    int p;
    ll x;
    cin>>p>>x;
    ans[p-1]+=x;
  }
  dfs(G,0);
  for(int i=0;i<n;i++){
    cout<<ans[i]<<" ";
  }
}

Measured memory_bytes: 24320
function Main(input) {
  var L = parseInt(input.split(" ")[0]);
  var R = parseInt(input.split(" ")[1]);
  var min = 2019;
  if((R - L) >= 2019){
     console.log(0);
    	return;
     }
  L = L % 2019;
  R = R % 2019;
  for(var i = L; i < R; i++){
    if(i % 2019 == 0){
       console.log(0);
    	return;
    }
    for(var j = i + 1; j <= R; j++){
      if(j % 2019 == 0){
         console.log(0);
    	return;
         }
      var cal = (i * j) % 2019;
      if(min > cal){
         min = cal;
        if(min == 0){
           console.log(min);
          return;
           }
      }
    }
  }
  console.log(min);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
int main(void) {
 int l, r, d,ans=0;
  cin >> l >> r >> d;
  for (int i=l; i <= r; i++) {
    if (i % d == 0) {
      ans++;
    }
  }
  cout << ans << '\n';
 return 0; 
}

Measured memory_bytes: 3580
#include <iostream>
#include <map>
using namespace std;
map<int, int> prime;

int count(int n){
  int num = 0;
  for(map<int,int>::iterator it=prime.begin(); it!=prime.end(); it++){
    if(it->second >= n){
      num++;
    }
  }
  return num;
}

int main() {

  int N;
  cin >> N;

  for(int i=2; i<=N; i++){
    int n = i;
    for(int p=2; p<=n; p++){
      while(n % p == 0){
        prime[p]++;
        n /= p;
      }
    }
  }

  int ans = 0;
  ans += count(74);
  ans += count(24) * (count(2) - 1);
  ans += count(4) * (count(4) - 1) * (count(2) - 2)/2;
  ans += (count(4) - 1) * count(14);
  cout << ans << endl;
}

Measured memory_bytes: 256
class Solution:
    def solve(self, N: int, A: int, B: int) -> str:

        return min(N*A, B)


if __name__ == '__main__':

    # standard input
    N, A, B = map(int, input().split())

    # solve
    solution = Solution()
    print(solution.solve(N, A, B))


Measured memory_bytes: 2940
N,x = list(map(int,input().split()))
a = list(map(int,input().split()))

ans = 0
for i in range(N):
  if a[i] > x:
    ans += a[i]-x
    a[i] = x

for i in range(1,N):
  tmp = a[i-1]+a[i] - x
  if tmp > 0:
    a[i] -= tmp
    ans += tmp
print(ans)

Measured memory_bytes: 63984
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args){
		try {
			BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
			String line;
			while ((line = stdReader.readLine()) != null){
				String[] temp = line.split(" ");
				put(Integer.parseInt(temp[0]), Integer.parseInt(temp[1]));
			}
		} catch (Exception e) {
			e.getStackTrace();
			System.exit(0);
		}
	}

	private static void put(int a, int b){
		if(a < b){
			System.out.println("a < b");
		}else if (a > b){
			System.out.println("a > b");
		} else {
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 24408
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let (h,w) = {
        let t = read_vec::<usize>();
        (t[0],t[1])
    };
    let mut ans = vec![];
    let mut an = read_vec2::<i64>(h as u32);
    for j in 0..h{
        for k in 0..w{
            if an[j][k] % 2  == 1 {
                if k + 1 < w {
                    an[j][k] -= 1;
                    an[j][k+1] += 1;
                    ans.push((j,k,j,k+1));
                } else if j + 1 < h {
                    an[j][k] -= 1;
                    an[j+1][k] += 1;
                    ans.push((j,k,j+1,k));
                }
            }
        }
    }
    println!("{}", ans.len() );
    for (x1,y1,x2,y2) in ans{
        println!("{} {} {} {}", x1+1,y1+1,x2+1,y2+1);
    }
}

Measured memory_bytes: 13304
#include <iostream>
#include <complex>
#include <vector>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <map>
#include <cstring>

using namespace std;

int main(){
    string s;
    cin >> s;
    int o = 0;
    for(int i = 0 ; i < s.size() ; i++){
        if( o == 0 and s[i] == 'C') o++;
        if( o == 1 and s[i] == 'F') o++;
    }
    cout << (o==2?"Yes":"No")<< endl;
}

Measured memory_bytes: 764