akhauriyash/Code-Regression huggingface dataset:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append('{}: {}'.format(name, val))
    print(' | '.join(ret), file=sys.stderr)


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N = I()
    A = LI()
    m = defaultdict(int)

    for i in range(N-1):
        m[A[i]] += 1

    for i in range(1, N+1):
        if i in m:
            print(m[i])
        else:
            print(0)




if __name__ == '__main__':
    main()


Measured memory_bytes: 128168
# -*- coding: utf-8 -*-
a = int(input())  # Nを入力
b = input()  # a1,a2...anを入力
b = map(int, b.split())  # a1,a2...anをint型でリストに入れる
b = sorted(b)  # 大きい順に並べる
b = b[::-1]  # リストの要素の順番を逆転する
c = b[::2]  # Aliceのとる要素を抽出
c_number = len(c)
d = b[1::2]  # Bobのとる要素を抽出
d_number = len(d)
c_sum = 0
d_sum = 0
for i in range(c_number):  
    c_sum += c[i] # Aliceのとる要素の合計

for g in range(d_number):
    d_sum += d[g]  # Bobのとる要素の合計

print(c_sum - d_sum)  # 差分を出力

Measured memory_bytes: 3064
#include <stdio.h>
int main(void){
while(1){
    int h,w;
    scanf("%d%d",&h,&w);
    if(h==0&&w==0)
    break;
    
    int i,j;
    
 
    
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            if((i+j)%2)
            printf(".");
            else
            printf("#");
        }
       printf("\n");
    }
   
    printf("\n");
}
return 0;
}

Measured memory_bytes: 2592
#include <iostream>
#include <vector>
#include <stack>
#include <unordered_set>
#include <numeric>
#include <iterator>
#include <unordered_map>
#include <array>
#include <map>
#include <cstring>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctgmath>
#include <set>
#include <queue>

using namespace std;
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin >> n;

	if (n == 1)
	{
		cout << "Hello World\n";
	}
	else
	{
		int a, b;
		cin >> a >> b;
		cout << a + b << "\n";
	}
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

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

  int n,m;
  while(cin >> n >> m){
    vector<pair<int,int>> dat(n);
    REP(i,n){
      int a,b; cin >> a >> b;
      dat[i] = make_pair(a,b);
    }

    sort(RALL(dat));

    LLI ans = 0;

    priority_queue<int> pq;

    vector<int> memo(m+1);
    REV(i,m,0){
      while(dat.size()){
        if(dat.back().fst <= m-i){
          pq.push(dat.back().snd);
          dat.pop_back();
        }else{
          break;
        }
      }

      if(pq.size()){
        memo[i] = pq.top();
        ans += pq.top();
        pq.pop();
      }
    }

    // join(cerr, ALL(memo));



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


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

using namespace std;

#define ll long long

#define all(x) x.begin(), x.end()

const int mod = 998244353;

int main(){

	cin.tie(0);
	cin.sync_with_stdio(0);

	#ifdef Cyborg101
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	string s;
	cin >> s;
	cout << s.substr(0, s.size() - 8) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll N,W,w[101],v[101];
ll dp[100001];ll sum=0;
int main(){
      cin>>N>>W;for(ll i=0;i<N;i++)cin>>w[i]>>v[i];
      memset(dp,1e9+1,sizeof(dp));dp[0]=0;
      for(ll i=0;i<N;i++){
            for(ll j = 100000-v[i];j>=0;j--){
                  dp[j+v[i]] = min(dp[j]+w[i],dp[j+v[i]]);
            }
      }
      for(ll i=100000;i>=0;i--){
            if(dp[i]<=W){
                  cout<<i<<endl;break;
            }
      }
      return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll h, w;
  cin >> h >> w;
  vector<string> ah(w, "");
  rep(i, h) {
    string s;
    cin >> s;
    bool is_alldot = true;
    for(char c : s) {
      if (c == '#') is_alldot = false;
    }
    if (!is_alldot) {
      rep(j, ll(s.size())) ah[j] += s[j];
    }
  }

  for(int i = w-1; i >= 0; i--) {
    bool is_alldot = true;
    for(char c : ah[i]) {
      if (c == '#') is_alldot = false;
    }
    if (is_alldot) {
      ah.erase(ah.begin()+i);
    }
  }

  rep(i, ll(ah[0].size())) {
    rep(j, ll(ah.size())) {
      cout << ah[j][i];
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

char buf[1005];

int main() {
  bool n = false;
  bool w = false;
  bool e = false;
  bool s = false;
  scanf("%s", buf);
  for(int i = 0; i < strlen(buf); i++) {
    n |= buf[i] == 'N';
    w |= buf[i] == 'W';
    e |= buf[i] == 'E';
    s |= buf[i] == 'S';
  }
  if(w^e) {
    printf("No\n");
    return 0;
  }
  if(n^s) {
    printf("No\n");
    return 0;
  }
  printf("Yes\n");
}


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

int main(){
    while(true){
    int n=0;
    cin>>n;
    int p;cin>>p;
    if(n==0&&p==0)break;
    vector<int> v(1100000,0);
    bool flag=false;
    int win;
    int P=p;
    while(1){
        for(int i=0;i<n;i++){
            if(p){
                v[i]++;
                p--;
                if(p==0&&P==v[i]){
                    win=i;
                    flag=true;break;
                }
            }
            else{
                p+=v[i];
                v[i]=0;
            }
        }
        if(flag)break;
    }
    cout<<win<<endl;
    }
}


Measured memory_bytes: 7300
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


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

    ll cnt = 0;
    // １になるまで割る
    while(H!=1) {
        cnt++;
        H/=2;
    }

    ll ans = 1;
    // 復元
    REP(_,cnt) ans = ans * 2 + 1;

    cout << ans << endl;

    return 0;
}


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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)
#define Rep(i, n) for(i = 1; i < n; i++)
#define Ans(s) cout << s << endl;

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

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

	vector<ll> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];

	}

	vector<ll> nums(n + 1);
	for (int i = 1; i < n + 1; i++)
	{
		nums[i] = nums[i - 1] + a[i - 1];
	}

	/*
	for (int i = 0; i < n + 1; i++)
	{
		cout << nums[i] << " ";
	}
	*/


	ll min_ = INF;

	for (int i = 1; i < n; i++)
	{
		ll sunuke = nums[i];
		ll araiguma = nums[n] - nums[i];

		//cout << abs(sunuke - araiguma) << " ";
		//cout << sunuke << " : " << araiguma << endl;

		min_ = min(min_, abs(sunuke - araiguma));
	}
	cout << min_ << endl;

}


Measured memory_bytes: 3456
n=int(input())
t,a=map(int,input().split())
h=[int(x) for x in input().split()]

m = 1000
for i in range(n):
  d=t-h[i]*0.006
  if abs(a-d) < m:
    m = abs(a-d)
    c = i
print(c+1)


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

#define ll long long
#define ull unsigned long long 

int main(){
    int a, b, c;
    cin >> a >> b >> c;

    for(int i=1; i<=b; ++i){
        if((a*i)%b == c){
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
}

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

int main(){
  long long N;
  cin>>N;
  long long n=floor(sqrt(N));
  bool sagyou=1;
  long long answer=0;
  while(sagyou){
    if(N%n==0){
      answer=n+N/n-2;
      sagyou=0;
    }
    n--;
  }
  cout<<answer<<endl;
}


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

const int mn=2e5+7,mod=1e9+7;
int n,m,siz[mn],fa[mn],ans;

int find(int x)
{
    if(fa[x]==x) return x;
    return fa[x]=find(fa[x]);
}

int main()
{
    scanf("%d%d",&n,&m);
    int u,v;
    for(int i=1;i<=n;++i) fa[i]=i,siz[i]=1;
    for(int i=1;i<=m;++i) {
        scanf("%d%d",&u,&v);
        u=find(u),v=find(v);
        if(u==v) continue;
        fa[u]=v;siz[v]+=siz[u];
    }
    for(int i=1;i<=n;++i) ans=max(ans,siz[i]);
    cout<<ans;
}

Measured memory_bytes: 5244
#include <iostream>
#include <vector>
#include <cmath>
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n-1; i >= 0; i--)
using namespace std;

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int ans = min(b/a, c);
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define INF 1e9

int main() {
  long long N, L;
  cin >> N >> L;
  
  int org_sum = 0;
  for (int i = 1; i < N+1; i++) {
    org_sum += L + i - 1;
  }
  
  int choice = INF;
  for (int i = 1; i < N+1; i++) {
    if (abs(choice) > abs(L + i - 1)) {
      choice = L + i - 1;
    }
  }
  
  long long result = org_sum - choice;
  cout << result << endl;
  
  return 0;
}

Measured memory_bytes: 256
N, T = map(int, input().split())
plan = [input().split() for i in range(N)]

min_cost = 10000

for i in range(N):
    if int(plan[i][1]) <= T:
        min_cost = min(min_cost, int(plan[i][0]))

if min_cost > 1000:
    print('TLE')
else:
    print(min_cost)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int count =0;
		for (int i=0;i<N;i++) {
			int temp = sc.nextInt();
			while (temp%2==0) {
				count ++;
				temp/=2;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 34132
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define append push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<int> h(n+1);
  rep(i,0,n) cin >> h[i+1];
  int ans = 0;
  rep(i,0,100) {
    int cnt = 0;
    rep(j,1,n+1) {
      if (h[j-1] <= i && h[j] > i) cnt++;
    }
    ans += cnt;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3584
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    from collections import defaultdict
    dd = defaultdict(int)
    
    N=I()
    for i in range(N):
        A=I()
        dd[A]+=1
    ans=0
    for k,v in dd.items():
        if v%2==1:
            ans+=1
    print(ans)

main()


Measured memory_bytes: 56664
import math

N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

t = 0
a, b, c, d, e = 0, 0, 0, 0, 0
n = N

#while(True):
#    t += 1
#    # calc minus
#    x1 = A if n > A else n
#    x2 = B if a > B else a
#    x3 = C if b > C else b
#    x4 = D if c > D else c
#    x5 = E if d > E else d
#
#    n -= x1
#    a -= x2
#    b -= x3
#    c -= x4
#    d -= x5
#
#    # calc add
#    a += x1
#    b += x2
#    c += x3
#    d += x4
#    e += x5
#
#    if e >= N:
#        break
# print(t)

print(math.ceil(N / min([A, B, C, D, E])) + 4)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int n,h;
    cin >> n >> h;
    vector<int> a(n), b(n);
    rep(i,n){
        cin >> a[i] >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    vector<int> v;
    auto it = lower_bound(b.begin(), b.end(), a[n - 1]);
    int cnt = 0;
    for(it; it != b.end();it++){
        v.push_back(*it);
    }
    reverse(v.begin(), v.end());
    for(auto e:v){
        h -= e;
        cnt++;
        if(h<=0){
            cout << cnt << endl;
            return 0;
        }
    }
    cnt += (h + a[n - 1] - 1) / a[n - 1];
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>

int main() {
	int n, m, c, f = 0, ans = 0;
	std::cin >> n >> m >> c;
	int a[20][20],b[20];
	for (int i = 0; i < m; ++i) {
		std::cin >> b[i];
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			std::cin >> a[i][j];
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			f += a[i][j] * b[j];
		}
		if (f + c > 0) { ans += 1; }
		f = 0;
	}
	std::cout << ans << std::endl;
}

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


int main(void) {
    using namespace std;

    long t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2;
    cin >> a1 >> a2;
    cin >> b1 >> b2;

    if(a1*t1 + a2*t2 == b1*t1 + b2*t2) {
        cout << "infinity" << endl;
        return 0;
    }

    if(a1 > b1) {
        swap(a1, b1);
        swap(a2, b2);
    }
    assert(a1 < b1);

    if(a2 < b2) {
        cout << "0" << endl;
        return 0;
    }
    assert(a2 > b2);

    if(a1*t1 + a2*t2 < b1*t1 + b2*t2) {
        cout << "0" << endl;
        return 0;
    }

    long r = 0;

    long d = (a1*t1 + a2*t2) - (b1*t1 + b2*t2);

    long d1 = (b1*t1) - (a1*t1);

    r += d1 / d;
    r += (d1+d-1) / d;
    cout << r << endl;


    return 0;
}

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

//  A... Z  a... z
// 65...90 97...122

int main() {
    std::string s, p;
    int count;
    std::cin >> s >> p;
    for (int i=0;i<s.length();++i) {
        count = 0;
        for (int j=0;j<p.length();++j)
            if (s[(i + j) % s.length()] == p[j])
                ++count;
        if (count == p.length()) {
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }
    std::cout << "No" << std::endl;
        
    return 0;
}


Measured memory_bytes: 3212
#include<iostream>
using namespace std;
int main(){
    long n,a[10000],i,sum=0,max=-1000000,low=1000000;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
        if(max<a[i]){max=a[i];}
        if(low>a[i]){low=a[i];}
    }
    cout<<low<<" "<<max<<" "<<sum<<endl;
    return 0;}

Measured memory_bytes: 3200
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N,M=get_i
ans=array(N,false)
ans[0]=true
cnt=array(N,1)
M.times do|i|
  x,y=get_i
  x-=1
  y-=1
  cnt[x]-=1
  cnt[y]+=1
  if ans[x]
      ans[y]=true
  end
  if cnt[x].zero?
      ans[x]=false
  end
end
puts ans.select{|x| x}.size

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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

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

    int q;
    cin >> q;
    rep (_, q)
    {
        string x, y;
        cin >> x >> y;
        int nx = x.size();
        int ny = y.size();

        int dp[nx + 1][ny + 1];
        rep (i, nx + 1) rep (j, ny + 1) dp[i][j] = 0;

        rep (i, nx)
        {
            rep (j, ny)
            {
                if (x[i] == y[j])
                {
                    dp[i + 1][j + 1] = dp[i][j] + 1;
                }
                else
                {
                    dp[i + 1][j + 1] = MAX(dp[i + 1][j], dp[i][j + 1]);
                }
            }
        }
        cout << dp[nx][ny] << "\n";
    }

    return 0;
}



Measured memory_bytes: 7072
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

vector<string> v;
int n, m;

int cnum(int &d, int &s) {
	int cnt = 0;
	rep(i, n) {
		bool f = true;
		rep(j, m) {
			if (s&(1 << j)) {
				if ((v[i][j] == '1') != ((d&(1 << j))==0))f = false;
			}
		}
		if (f)cnt++;
	}
	return cnt;
}
map<P, bool> used;
map<P, int> res;
int dfs(int d,int s) {
	int z = cnum(d, s);
	if (z==1)return res[{d, s}]=0;
	else if (z == 0)return res[{d, s}] = mod;
	if (used[{d, s}])return res[{d, s}];
	used[{d, s}] = true;
	int ret = mod;
	rep(i, m) {
		if (s & (1 << i))continue;
		int ns = s ^ (1 << i);
		int nd = d ^ (1 << i);
		int le = dfs(d, ns), ri = dfs(nd, ns);
		ret = min(ret, max(le, ri) + 1);
	}
	return res[{d, s}] = ret;
}
void solve() {
	used.clear(); res.clear();
	v.clear(); v.resize(n);
	rep(i, n) {
		cin >> v[i];
	}
	int ans = dfs(0, 0);
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(9);
	while (cin >>m>>n,n) {
		solve();
	}
	//stop
	return 0;
}


Measured memory_bytes: 14588
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

A, B, C, D = [int(v) for v in list(s())]

if A+B+C+D == 7:
    print('{}+{}+{}+{}=7'.format(A, B, C, D))
elif A+B+C-D == 7:
    print('{}+{}+{}-{}=7'.format(A, B, C, D))
elif A+B-C+D == 7:
    print('{}+{}-{}+{}=7'.format(A, B, C, D))
elif A-B+C+D == 7:
    print('{}-{}+{}+{}=7'.format(A, B, C, D))
elif A+B-C-D == 7:
    print('{}+{}-{}-{}=7'.format(A, B, C, D))
elif A-B+C-D == 7:
    print('{}-{}+{}-{}=7'.format(A, B, C, D))
elif A-B-C+D == 7:
    print('{}-{}-{}+{}=7'.format(A, B, C, D))
elif A-B-C-D == 7:
    print('{}-{}-{}-{}=7'.format(A, B, C, D))


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <limits.h>

#define lli long long int
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define	abs(a) ((a)<0?-(a):(a))



int main(void){
	char *s;
	int count = 0;
	char prev;
	s = calloc(sizeof(char),10001);
	scanf("%s",s);
	prev = *s;
	while(*s){
		if(*s != prev){
			prev = *s;
			count++;
		}
		s++;
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 10**9 + 7

n, k = map(int, input().split())
a = [int(item) for item in input().split()]
# Use all
if n == k:
    ans = 1
    for item in a:
        ans *= item
        ans %= MOD
    print(ans % MOD)
    exit()
plus = 0; minus = 0; zero = 0
p = []; m = []
for item in a:
    if item > 0:
        plus += 1
        p.append(item)
    elif item == 0:
        zero += 1
    else:
        minus += 1
        m.append(-item)
p.sort()
m.sort()
# plus only, minus only
if plus == 0:
    if k % 2 == 0:
        if minus >= k:
            ans = 1
            for i in range(k):
                ans *= m.pop()
                ans %= MOD
            print(ans)
            exit()
        else:
            print(0)
            exit()
    else:
        if zero:
            print(0)
            exit()
        ans = 1
        for item in m[:k]:
            ans *= -item
            ans %= MOD
        print(ans % MOD)
        exit()
if minus == 0:
    if plus >= k:
        ans = 1
        for i in range(k):
            ans *= p.pop()
            ans %= MOD
        print(ans % MOD)
        exit()
    else:
        print(0)
        exit()

# Can make it positive
if k <= (minus // 2) * 2 + plus:
    if k % 2 == 0:
        ans = 1
    else:
        ans = p.pop()
        k -= 1
    for i in range(k // 2):
        pval = 0; mval = 0
        if len(p) > 1:
            pval = p[-1] * p[-2]
        if len(m) > 1:
            mval = m[-1] * m[-2]
        if pval > mval:
            p.pop(); p.pop()
            ans *= pval
            ans %= MOD
        else:
            m.pop(); m.pop()
            ans *= mval
            ans %= MOD
    print(ans % MOD)
    exit()
# Cannot make positive
else:
    if zero > 0:
        print(0)
        exit()
    else:
        # Not occur
        exit()

Measured memory_bytes: 102596
/*
	ITP1-2-A: Small, Large, or Equal
*/
#include	<iostream>

using namespace std;

int main(void) {
	int a, b;
	
	cin >> a >> b;
	if(a == b) { cout << "a == b" << endl; }
	else if(a < b) { cout << "a < b" << endl; }
	else { cout << "a > b" << endl; }
	
	return 0;
}

Measured memory_bytes: 1156
#include<iostream>
using namespace std;
int a[10],n,s;
int dp[11][331];
void f(int i,int sum)
{
    dp[i][sum]++;
    if(i==10)return;
    for(int j=0;j<10;j++)
    {
        if(a[j])continue;
        a[j]=1;
        f(i+1,sum+j*(i+1));
        a[j]=0;
    }
}
main()
{
    f(0,0);
    while(cin>>n>>s)
    {
        cout<<(s>330?0:dp[n][s])<<endl;
    }
}


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

int main( void ) {
	int i, j;
	int n;

	while ( scanf( "%d", &n ), n ) {
		int matrix[ 11 ][ 11 ];

		memset( matrix, 0, sizeof matrix );

		for ( i = 0; i < n; i++ )
			for ( j = 0; j < n; j++ ) {
				scanf( "%d", matrix[ i ] + j );
				matrix[ i ][ n ] += matrix[ i ][ j ];
				matrix[ n ][ j ] += matrix[ i ][ j ];
			}
		for ( j = 0; j < n; j++ )
			matrix[ n ][ n ] += matrix[ n ][ j ];

		for ( i = 0; i < n + 1; i++ ) {
			for ( j = 0; j < n + 1; j++ )
				printf( "%5d", matrix[ i ][ j ] );
			putchar( '\n' );
		}
	}

	return 0;
}

Measured memory_bytes: 616
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string t = Console.ReadLine();
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(t);
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(s[i]);
            }
            for (int i = n; i > 0; i--)
            {
                Console.Write(a[i-1]);
                if (i == 1)
                {
                    break;
                }
                Console.Write(" ");
            }
            Console.WriteLine("");
        }
    }
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int k,x; cin >> k >> x;
    if(500*k >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
/*input
6
11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
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 IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (int)(lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=505;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

int n;
int p[maxn*maxn];

int d[maxn][maxn];

bool vis[maxn][maxn];
vector<pii> q;

bool isValid(int x,int y){
	return x>=0&&x<n&&y>=0&&y<n;
}

ll sumD;

int main(){
	IOS;
	cin>>n;

	REP(i,n) REP(j,n){
		d[i][j] = min({i+1, n-i, j+1, n-j});
		sumD+=d[i][j];
	}
	REP(i,n) REP(j,n) vis[i][j]=1;

	int ans = 0;

	REP(I,n*n){
		int u,v;
		{
			int tmp;
			cin>>tmp;
			tmp--;
			u = tmp/n;
			v = tmp%n;
		}
		ans+=d[u][v];
		d[u][v]--;
		vis[u][v]=0;
		
		int pt=0;
		q.eb(u,v);

		while(pt<SZ(q)){
			int x = q[pt].F, y = q[pt].S;
			pt++;

			{
				int _x = x+1, _y = y;
				if(isValid(_x, _y) && d[_x][_y] > d[x][y] + vis[_x][_y]){
					d[_x][_y] = d[x][y]+ vis[_x][_y];
					q.eb(_x,_y);
				}
			}
			{
				int _x = x-1, _y = y;
				if(isValid(_x, _y) && d[_x][_y] > d[x][y] + vis[_x][_y]){
					d[_x][_y] = d[x][y]+ vis[_x][_y];
					q.eb(_x,_y);
				}
			}
			{
				int _x = x, _y = y+1;
				if(isValid(_x, _y) && d[_x][_y] > d[x][y] + vis[_x][_y]){
					d[_x][_y] = d[x][y]+ vis[_x][_y];
					q.eb(_x,_y);
				}
			}
			{
				int _x = x, _y = y-1;
				if(isValid(_x, _y) && d[_x][_y] > d[x][y] + vis[_x][_y]){
					d[_x][_y] = d[x][y]+ vis[_x][_y];
					q.eb(_x,_y);
				}
			}
		}
		// REP(i,n) REP(j,n) cout<<d[i][j]<<" \n"[j==n-1];
		// cout<<endl;	
		
		q.clear();	
	}
	cout<<ans-n*n<<'\n';
	return 0;
}


Measured memory_bytes: 6480
package main

import (
	"fmt"
)

func main() {

	var X,Y,Z string

	fmt.Scan(&X,&Y,&Z)

	var temp  string

	temp = X

	X = Y

	Y = temp

	temp = X

	X = Z

	Z = temp


	fmt.Println(X,Y,Z)


}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

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

	int N;
	cin >> N;
	int ans = 1;
	int l;
	cin >> l;
	int type = 0;
	for(int i=1; i<N; i++){
		int tmp;
		cin >> tmp;
		if(type == 0){
			if(tmp > l) type = 1;
			if(tmp < l) type = -1;
		}
		if(type == 1){
			if(l > tmp){
				ans++;
				type = 0;
			}
		}
		if(type == -1){
			if(l < tmp){
				ans++;
				type = 0;
			}
		}
		l = tmp;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
int main() {
	priority_queue<int>pq;
	char s[10];
	while (cin >> s) {
		if (s[2] == 'd')return 0;
		if (s[0] == 'i') { int x; cin >> x; pq.push(x); }
		else {
			int x = pq.top(); pq.pop();
			cout << x << endl;
		}
	}
}

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

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	
	deque<int> b;
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) b.push_back(a[i]);
		else b.push_front(a[i]);
	}
	if (n % 2 != 0) reverse(b.begin(), b.end());
	for (const auto& item : b) cout << item << " ";
	cout << endl;
}

Measured memory_bytes: 3840
#include <algorithm> // std::sort(begin,end), std::min, std::max
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>
#include <utility> // std::swap
#include <vector>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

template <typename T> // 0<1<2<3<4
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
template <typename T> // 0>1>2>3>4
using pq_dsc = priority_queue<T>;

int main(int argc, char const *argv[]) {

  int n, k, q;
  cin >> n >> k >> q;
  vector<int> p(n, 0);
  int a;

  for (int i = 0; i < q; i++) {
    cin >> a;
    p[a-1]++;
  }

  for (int i = 0; i < n; i++) {
    if ( k - q + p[i]  > 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
for i in range(n):
    c.append(a[i]-b[i])
if sum(c)<0:
    print(-1)
else:
    c.sort()
    s=[i for i in c if i<0]
    if len(s)==0:
        print(0)
    else:
        d=sum(s)
        t=0
        for i in range(n-1,-1,-1):
            t+=c[i]
            if t>=-d:
                print(n-i+len(s))
                break

Measured memory_bytes: 18356
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, m, idx = 0;
int c[100055][32];
int q[100005];
long long solve(int x){
    int mm = min(n - 1, q[x]);
    return c[q[x]+n-1][mm];
}
int main(){
    c[1][1] = 1; c[1][0] = 1;
    for(int i = 2; i <= 100040; ++i){
        c[i][0] = 1;
        for(int j = 1; j <= min(i, 31); ++j){
            c[i][j] = (c[i-1][j-1] + c[i-1][j]) % mod;
        }
    }
    /*
    for(int i = 1; i <= 10; ++i){
        for(int j = 1; j <= i; ++j) cout <<c[i][j] << " ";
        cout << endl;
    }
    */
    scanf("%d%d", &n, &m);
    for(int i = 2; i * i <= m; ++i){
        if(m % i == 0){
            //q[idx] = 1;
            while(m % i == 0) m /= i, q[idx]++;
            //q[idx++] = i;
            idx++;
        }
    }
    if(m > 1) q[idx++] = 1;
    //for(int i = 0; i < idx; ++i) cout << q[i] << endl;
    long long ans = 1;
    for(int i = 0; i < idx; ++i){
        ans = ans * solve(i) % mod;
    }
    printf("%I64d\n", ans);
    return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

int main() {

  int n;
  cin >> n;

  for ( int i = 0; i < n; i++ ) {

    double x1,y1,x2,y2,x3,y3;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

    for ( int j = 0; j < 3; j++ ) {
      if ( y1 == y2 || y2 == y3 ) {
	double k;
	k = x1;
	x1 = x2;
	x2 = x3;
	x3 = k;
	k = y1;
	y1 = y2;
	y2 = y3;
	y3 = k;
	continue;
      }
      double t1 = ( x1 - x2 ) / ( y2 - y1 );
      double t2 = ( x2 - x3 ) / ( y3 - y2 );
      double x = ( y1/2 - y3/2 - (x1+x2)/2*t1 + (x2+x3)/2*t2 ) / ( t2 - t1 );
      double y = ( x - (x1+x2)/2 ) * t1 + (y1+y2)/2;
      double l = sqrt( (x1-x)*(x1-x) + (y1-y)*(y1-y) );
      cout << fixed << setprecision(3) << x << " " << y << " " << l << endl;
      break;
    }

  }

}

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

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    for(int i = sx; i < tx; i++) cout << 'R';
    for(int i = sy; i < ty; i++) cout << 'U';
    for(int i = tx; i > sx; i--) cout << 'L';
    for(int i = ty; i > sy - 1; i--) cout << 'D';
    for(int i = sx; i < tx + 1; i++) cout << 'R';
    for(int i = sy - 1; i < ty; i++) cout << 'U';
    cout << "LU";
    for(int i = tx; i > sx - 1; i--) cout << 'L';
    for(int i = ty + 1; i > sy; i--) cout << 'D';
    cout << 'R' << endl;
}

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    ll x;
    cin >> x;
    ll kane = 100;
    int year = 0;
    while(kane<x)
    {
        kane += kane/100;
        year++;
    }
    cout << year << endl;

}

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

#define llint long long int
#define pb push_back

using namespace std;

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#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++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1e9+7;
const ll  longinf = 1LL<<60;
const int mod=1e9+7;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  string s;cin>>s;
  int n=s.size();
  int all=1<<(n-1);
  ll ans=0;
  rep(i,all){
    ll ret=0,pos=s[0]-'0';
    rep(j,n-1){
      if((i>>j)&1){
        ret+=pos;
        pos=s[j+1]-'0';
        }
      else{
        pos=10*pos+(s[j+1]-'0');
        }
      }
    ret+=pos;
    ans+=ret;
    }
  cout<<ans<<endl;  
  return 0;         
  }

Measured memory_bytes: 256
/*
P135
AOJ 0558 Cheese
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0558
*/


#include <iostream>
#include <map>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <functional>
#include <string.h>
using namespace std;


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

int num;
int pos0;
typedef pair<int,int> PAIR;
map<int, int> mp;

int pow10[8] = {1,10,100,1000,10000,100000,1000000,10000000};

bool check(int x, int y)
{
    return (x>=0&&x<2 && y>=0 && y<4);
}



bool read()
{
    num = 0;
    int x;
    for(int i=0; i<8; ++i){
        if(scanf("%d", &x) == EOF) return false;
        num *= 10;
        num += x;
    }
    return true;
}


int swapPos(int n, const int& p0, const int& p2){
    int d = n / pow10[7-p2] % 10;
    n -= d * pow10[7-p2];
    n += d * pow10[7-p0];
    return n;
}


void bfs(){
    queue<PAIR> q;
    mp[1234567] = 0;
    q.push(make_pair(1234567, 0));

    while(!q.empty()){
        PAIR cur = q.front(); q.pop();
        int curNum = cur.first;
        int p0 = cur.second;
        int step = mp[curNum];
        int x = p0>>2, y = p0&3;

        for(int d=0; d<4; ++d){
            int cx = x + dx[d], cy = y + dy[d];
            if(check(cx, cy)){
                int cn = (cx*4 + cy);
                int v = swapPos(curNum, p0, cn);
                if(!mp.count(v)) {
                    mp[v] = step+1;
                    q.push(make_pair(v, cn));
                }
            }
        }
    }
}


void solve()
{
    printf("%d\n", mp[num]);
}

int main()
{
    bfs();
    while(read())
        solve();

}




/*
int W, H;
char board[110][110];
int a[10];
bool read()
{
    for(int i=0; i<10; ++i)
        scanf("%d", a+i);
}

bool isVisited[110][110];
int step;

void dfs(int x, int y, char c){
    if(x<0 || x>=H || y<0 || y>=W) return;
    if(board[x][y]!=c) return;
    if(isVisited[x][y]) return;
    isVisited[x][y] = true;
    dfs(x+1, y, c);
    dfs(x-1, y, c);
    dfs(x, y+1, c);
    dfs(x, y-1, c);
}



void solve1()
{
    int x1=0, x2=0;
    bool ans = true;
    for(int i=0; i<10; ++i)
    {
        if(x1 < x2) swap(x1, x2);
        if(x1 < a[i]) x1 = a[i];
        else if(x2 < a[i]) x2 = a[i];
        else {ans = false; break;}
    }
    if(ans) printf("YES\n");
    else printf("NO");
}



vector<int> L_bucket;
vector<int> R_bucket;

bool dfs2(int d){
    if(d == 10) return true;
    bool flag;
    if(L_bucket.size() == 0 || L_bucket.back() < a[d]){
        L_bucket.push_back(a[d]);
        flag = dfs2(d+1);
        L_bucket.pop_back();
    }
    if(flag) return true;
    if(R_bucket.size() == 0 || R_bucket.back() < a[d]){
        R_bucket.push_back((a[d]));
        flag = dfs2(d+1);
        R_bucket.pop_back();
    }
    if(flag) return true;
    return false;

}

void solve2()
{
    if(dfs2(0))
        printf("YES\n");
    else printf("NO\n");
}

int main()
{
    int T;
    scanf("%d", &T);
    while(T--){
        read();
        solve2();
    }
}
*/

Measured memory_bytes: 2156
#include<bits/stdc++.h>
using namespace std;
 
int H,W,N;
int yoko(int a,int b){
  int h = a-1;
  int id;
  //b_w, a_h , 1_index
  if( ((b & 1) && (a & 1)) || (!(b&1) && !(a&1)) ){     
      if( b - h < 1 ){
    h -= b;
      } else return b - h;
      int fh = h/W;
      if( fh & 1 ){ //left
    id = W - (h%W);
      } else { //right
    id = h%W + 1;
      }
  } else {
    if( b + h > W ){
      h -= (W+1-b);
    } else return b + h;
    int fh = h/W;
    if( fh & 1){//right
      id = h%W + 1;
    } else {//left
      id = W - h%W;
    }
  }
  return id;
}
int res[222222];
int ind[222222];
typedef pair<int,int> P;
P p[222222];
int main(){
   
  cin >> H >> W >> N;
  for(int i=1;i<=W;i++){
    res[yoko(H+1,i)] = i;
    ind[i] = i;
  }
  for(int i=0;i<N;i++)
    cin >> p[i].first >> p[i].second;
  sort(p,p+N);
  for(int i=N-1;i>=0;i--){
    int a = p[i].first, b = p[i].second;
    int l = yoko(a,b);
    int r = yoko(a,b+1);
    // cout << a << " " << b << "- > " << l << " " << r << endl;
    //swap(ind[l],ind[r]);
       swap(res[l],res[r]);
  }
  for(int i=1;i<=W;i++) cout << res[ind[i]] << endl;
 
}

Measured memory_bytes: 4468
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){

   int a,p;
   cin >> a >> p;

   int ans = (3*a+p)/2;

   cout << ans << endl;




   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll M, K;
  cin>>M>>K;
  if(K==0) {
    for(int i=0;i<(1<<M);++i) {
      cout<<i<<" "<<i<<" ";
    }
    cout<<endl;
    return 0;
  }
  ll tmp=0;
  for(int i=0;i<(1<<M);++i) {
    if(i==K) continue;
    tmp ^= i;
  }
  if(tmp!=K) {
    cout<<-1<<endl;
    return 0;
  }
  cout<<0<<" "<<K<<" "<<0<<" ";
  for(int i=1;i<(1<<M);++i) {
    if(i==K) continue;
    cout<<i<<" ";
  }
  cout<<K<<" ";
  for(int i=(1<<M)-1;i>0;--i) {
    if(i==K) continue;
    cout<<i<<" ";
  }
  cout<<endl;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;

signed main() {
    int n;
    cin >> n;
    int a[n];
    rep (i, 0, n) {
        cin >> a[i];
        if (i == 0) {
            if (a[i] != 0) {
                cout << "-1\n";
                return 0;
            }
        } else {
            if (a[i] - a[i - 1] > 1) {
                cout << "-1\n";
                return 0;
            }
        }
    }
    int ans = 0;
    per (i, 1, n) {
        if (a[i] == a[i - 1] + 1) {
            ans++;
        } else {
            ans += a[i];
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 5100
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024
var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

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

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

func main() {
	s, t := next(), next()
	a, b := nextInt(), nextInt()
	u := next()

	if s == u {
		a--
	} else if t == u {
		b--
	}

	fmt.Println(a, b)
}

Measured memory_bytes: 640
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    x = I()
    flag = [False]*(x+1)
    flag[1] = True
    for b in range(1, x+1):
        for p in range(2, x+1):
            temp = b**p
            if temp > x:
                break
            flag[temp] = True
    for i in range(x, 0, -1):
        if flag[i]:
            print(i)
            break

if __name__ == '__main__':
    main()

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

#define rep(i, a, b) for(lli i  = (lli)(a); i < (lli)(b);i++)
#define REP(i,n) for(lli(i)=0;(i)<(lli)(n);(i)++)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(v) (v).size()
#define all(v) (v).begin(), (v).end()
#define trace(x) cerr << #x << ": " << x << endl;

typedef long long int lli;
typedef pair<lli, lli> ii;
typedef pair<ii, lli> iii;
typedef vector<lli> vi;
typedef vector<ii> vii;
typedef double C;

int main(){
	fastio;
	lli n,m,sum=0; cin>>n;
	vi t; t.pb(0);
	vii ps;
	rep(i,0,n){
		lli num; cin>>num;
		t.pb(num);
		sum+=num;
	}
	cin>>m;
	rep(i,0,m){
		lli p,x; cin>>p>>x;
		cout<<sum-t[p]+x<<endl;
	}

	return 0;
}

Measured memory_bytes: 256