akhauriyash/Code-Regression huggingface dataset:
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef LOCAL
    #define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define debug(...) 42
    #define eprintf(...) 42
#endif

#define PI 3.1415926535897932384626433832795
#define INF 2e9
#define SINV(t) greater<t>()
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define FOREACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;
#define vv(t) vector< t > 

#define CHC(mp, x) if(mp.end() != mp.find(x))
#define CHCV(mp, x) if(mp.end() != find(ALL(mp), x))

template<typename T>
inline T lcm(T a, T b) {return a / __gcd(a, b) * b;}

#pragma endregion

template<typename T>
void SV(vector<T> v){
    #ifdef LOCAL
        REP(i,v.size()){
                cout << i << " : " << v[i] << endl;
        }
    #endif
}

template<typename T>
void SV(map<int, T> v){
    #ifdef LOCAL
        FOREACH(i, v){
            cout << i.first << " : " << i.second << endl;
        }
    #endif
}
int bitCount(int bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >> 16);
}

int main(void){
    unsigned long long a, b, x;
    cin >> a >> b >> x;
    if(a==0)
        cout << (b/x+1) << endl;
    else if(b==0)
        cout << 1 << endl;
    else
        cout << (b/x - (a-1)/x) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <stdio.h>
#include <string.h>
int main()
{
	int n, T = 0, H = 0, Bool = 1;
	char a[101], b[101];
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a >> b;
		for (int j = 0; a[j] != '\0' && b[j] != '\0'; j++){
			if (a[j] > b[j]) { T += 3; Bool = false; }
			if (a[j] < b[j]) { H += 3; Bool = false; }
			if (Bool == false) break;
			if (a[j + 1] == '\0' || b[j+1] =='\0' ){
				if (a[j + 1] == b[j + 1]) { T++; H++; }
				else {
					if (a[j + 1] == '\0') H += 3;
					if (b[j + 1] == '\0') T += 3;
				}
			}
		}
		Bool = true;
	}
	printf("%d %d\n", T, H);
	return 0;
}

Measured memory_bytes: 1148
import std.stdio, std.conv, std.string, std.algorithm,
       std.math, std.array, std.container, std.typecons;

void main() {
  auto x = readln.chomp.to!long;
  DList!long pAB;
  for(long i=0; abs(i*i*i*i*i - (i-1)*(i-1)*(i-1)*(i-1)*(i-1)) <= x; i++) {
    pAB.insert(i);
    pAB.insert(-i);
  }
  foreach(i;pAB) foreach(j;pAB) {
    if(i*i*i*i*i - j*j*j*j*j == x) {
      writef("%d %d\n", i, j);
      return;
    }
  }
}


Measured memory_bytes: 2888
#include <stdio.h>
#include <math.h>//"Compiler options:"???"-lm"??¨??\???

int main(void){
    double a,b,c,C,rad,S,L,h;
    double PI = 3.14159265359;  
    scanf("%le %le %le",&a,&b,&C);
    rad = C*PI/180.0;
    S = a*b*sin(rad)/2;
    c = sqrt(a*a+b*b-2*a*b*cos(rad));
    L = a+b+c;
    h = 2*S/a;
    printf("%lf %lf %lf\n",S,L,h);
    return 0; /*0?????????*/
}

Measured memory_bytes: 648
from heapq import heappush, heappop

N = int(input())
vLst = list(map(int, input().split()))
v = []
for i in range(N):
    heappush(v, vLst[i])

ans = 0
for i in range(N - 1):
    tmp1 = heappop(v)
    tmp2 = heappop(v)
    ans = float((tmp1 + tmp2) / 2)
    heappush(v, ans)

print(v[0])


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(void){
  int N;
  cin >> N;

  int i, j;
  for(i=1; i<=9; i++)
    for(j=1; j<=9; j++)
      if(i*j == N){
	cout << "Yes" << endl;
	return 0;
      }
  
  cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

int main() {
  //
  ll n, k;
  cin >> n >> k;
  vl a(n), after(n, 0), before(n, 0);
  rep(i, n) { cin >> a[i]; }
  rep(i, n) {
    ll cnt = 0;
    REP(j, i + 1, n) {
      if (a[i] > a[j]) {
        cnt++;
      }
    }
    after[i] = cnt;
  }
  rep(i, n) {
    ll cnt = 0;
    REP(j, 0, i) {
      if (a[i] > a[j]) {
        cnt++;
      }
    }
    before[i] = cnt;
  }
  ll ans = 0;
  rep(i, n) {
    ll afterAdd = (k * (k + 1) / 2 % MOD) * after[i] % MOD;
    ll beforeAdd = (k - 1) * k / 2 % MOD * before[i] % MOD;
    ans = (ans + afterAdd) % MOD;
    ans = (ans + beforeAdd) % MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 888
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <bits/stdc++.h>
#include <string>
using namespace std;
using ll = long long;

int main(){
    string S;
    string T;
    cin>>S>>T;
    ll S_len = S.length();
    ll T_len = T.length();
    bool flag=true;
    if(T_len>S_len){
        flag = false;
    }
    if(flag){
        for(ll i=S_len-T_len;i>=0;i--){
            bool f = true;
            for(ll j=0;j<T_len;j++){
                if(T[j]!=S[j+i]&&S[i+j]!='?'){
                    f=false;
                }
            }
            if(f){
                for(auto j=0;j<T_len;j++){
                    S[j+i] = T[j];
                }
                for(auto j=0;j<S_len;j++){
                    if(S[j]=='?')S[j]='a';
                }
                break;
            }
            if(i==0)flag = false;
        }
    }
    cout<<(flag?S:"UNRESTORABLE")<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    char a[6];
    int i;
    for (i = 0; i < 6; i++)
    {
        cin >> a[i];
    }
    if (a[2] == a[3] && a[4] == a[5])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import numpy as np
n = int(input())
u = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))
ma = 0
for i in range(n):
    ma = max(np.sum(u[:i+1]) + np.sum(b[i:]), ma)
print(ma)

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

int main()
{
	string s;
	cin >> s;
	if (s == "BBB") {
		cout << "No";
	}
	else if (s == "AAA") {
		cout << "No"; // 1が表示される
	}
	else {
		cout << "Yes";
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int x1,x2,x3,x4,x5;
  cin>>x1>>x2>>x3>>x4>>x5;
  if(x1==0){
    cout<<"1";
  }else if(x2==0){
  	cout<<"2";
  }else if(x3==0){
    cout<<"3";
  }else if(x4==0){
  	cout<<"4";
  }else{
    cout<<"5";
  }
  return 0;
}

Measured memory_bytes: 3528
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

const int N = 20;
int n, ans;

int main()
{
	scanf("%d", &n); ans = pow(3, n);
	int tmp = 1;
	for (int i = 1; i <= n; i ++){
		int x; scanf("%d", &x);
		if (x%2 == 0) tmp *= 2;
	}
	ans -= tmp;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define intt unsigned long long
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main()
{
    fast;
    intt n,W;
    cin>>n>>W;
    intt wt[n];
    intt v[n];

    for(intt i = 0;i<n;i++)
        cin>>wt[i]>>v[i];
    intt dp[n+1][W+1];
    for(intt i = 0;i<=n;i++)
        for(intt w = 0;w<=W;w++)
        {
            if(i == 0 || w == 0)
                dp[i][w] = 0;
            else if(w>=wt[i-1])
                dp[i][w] = max(v[i-1]+dp[i-1][w-wt[i-1]],dp[i-1][w]);
            else
                dp[i][w] = dp[i-1][w];
        }
    cout<<dp[n][W];
}


Measured memory_bytes: 79232
#include<bits/stdc++.h>
using namespace std;
const long long md=998244353;
long long n,s,dp[3030],a[3030];
int main()
{
	cin>>n>>s;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	dp[0]=2;
	if(a[0]<=s)
	{
		dp[a[0]]=1;
	}
	for(int i=1;i<n;i++)
	{
		for(int j=s;j>=0;j--)
		{
			dp[j]*=2;
			dp[j]%=md;
			if(j>=a[i])
			{
				dp[j]+=dp[j-a[i]];
				dp[j]%=md;
			}
		}
	}
	cout<<dp[s]<<endl;
	return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f

using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<pair<int,int>,null_type, less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
const int N=1e8+1, mod=1e9+7;

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int m,d,res=0;
	cin>>m>>d;
	for(int i=1;i<=m;i++){
		for(int j=20;j<=d;j++){
			if( j%10>=2 && (j%10)*(j/10)==i ) res++;
		}
	}
	cout<<res;
}
// check for any potential overflow before submitting



Measured memory_bytes: 256
#include <cstdio>
#include <stack>
#include <iostream>

using namespace std;

int gcd(int a,int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

int main(){
    int n,in[3],ans;
    
    scanf("%d",&n);
    
    for(int i=0;i<n;i++){
        scanf("%d",&in[i]);
    }
    
    ans = gcd(in[0],in[1]);
    if(n==3) ans=gcd(ans,in[2]);
    
    for(int i=1;i<=ans;i++)
        if(ans%i==0)
            printf("%d\n",i);
    
    return 0;
}
    

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string c;
    cin >> c;
    vector<int> rs(n), ws(n);
    for (int i = 0; i < n; ++i) {
        if (c[i] == 'R')
            rs[i]++;
        else
            ws[i]++;
    }
    for (int i = 1; i < n; ++i) {
        ws[i] += ws[i - 1];
    }
    for (int i = n - 2; i >= 0; --i) {
        rs[i] += rs[i + 1];
    }
    int ret = min(rs[0], ws[n - 1]);
    for (int i = 0; i < n - 1; ++i) {
        ret = min(ret, max(ws[i], rs[i + 1]));
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 5124
PROGRAM kagamiMochi
      IMPLICIT NONE
      INTEGER :: N
      INTEGER,ALLOCATABLE :: d(:)
      INTEGER :: a, buffer(2),ans
      LOGICAL :: flag
      
      READ*,N
      ALLOCATE( d(N) )
      DO a = 1,N
        READ*,d(a)
      END DO
      
      DO while(.TRUE.)
      flag = .TRUE.
        DO a = 1,N-1
          IF( d(a)<d(a+1) )THEN
            buffer(1:2) = d(a:a+1)
            d(a) = buffer(2); d(a+1) = buffer(1)
            flag = .FALSE.
          END IF
          
        END DO
        
        IF(flag) EXIT
      END DO
      
      
      ans = 1
      DO a = 1,N-1
        IF( d(a)>d(a+1) )THEN
          ans = ans + 1
        END IF
      END DO
      
      
      print'(I0)',ans
      
      
      
      END PROGRAM

Measured memory_bytes: 256
import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	#b , c = tin()
	s = list(input())[:-1]

	count_s = 0
	delete_num=0
	for c in s:
		if c == 'S':
			count_s+=1
		else: #if c == 'T':
			if count_s == 0:
				pass
			else:
				count_s-=1
				delete_num+=2
	return len(s)-delete_num
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 62320
import collections
n=int(input())
l=list(map(int,input().split()))
c=collections.Counter(l)
mc=c.most_common()
lec=sorted([i[0] for i in mc if i[1]>=4]+[i[0] for i in mc if i[1]>=2],reverse=True)
if len(lec)<=1:print(0);exit()
else:print(lec[0]*lec[1])

Measured memory_bytes: 21668
s=input()[:2]
if s=="SU":
    print(7)
elif s=="MO":
    print(6)
elif s=="TU":
    print(5)
elif s=="WE":
    print(4)
elif s=="TH":
    print(3)
elif s=="FR":
    print(2)
else:
    print(1)


Measured memory_bytes: 2940
#include<stdio.h>

int main(void){
  int i;
  int a,b;
  int s=1;

  scanf("%d %d",&a,&b);

  if(a<0 && b>0) s=0;

  else if(a>0) s=1;

  else if((b-a)%2==0) s=-1;

  if(s>0)
    printf("Positive\n");
  else if(s<0)
    printf("Negative\n");
  else
    printf("Zero\n");

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;


int main() {
  int N, M;
  cin >> N >> M;
  int L[M], R[M];
  int maxl = 0;
  int minr = 100000;
  for (int i = 0; i < M; i++) {
    cin >> L[i] >> R[i];
    maxl = max(L[i], maxl);
    minr = min(R[i], minr);
  }
  
  if (minr - maxl < 0) {cout << 0 << endl;}
  else {cout << minr - maxl + 1 << endl;}
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};
int color[100010]; 
void dfs(const vector<vector<edge> > g, int now){
    for (int i = 0; i < g[now].size(); i++){
        if (color[g[now][i].to] != -1) continue;

        if (color[now] == 0){
            if (g[now][i].cost % 2 == 1){
                color[g[now][i].to] = 1;
            } else if (g[now][i].cost % 2 == 0){
                color[g[now][i].to] = 0;
            }
        } else if (color[now] == 1){
            if (g[now][i].cost % 2 == 1){
                color[g[now][i].to] = 0;
            } else {
                color[g[now][i].to] = 1;
            }
        }
        dfs(g, g[now][i].to);
    }
}

// 0 - white, 1 - black
int main(){
    int N; cin >> N;
    vector<ll> u(N),v(N),w(N);
    vector<vector<edge> > g(N);
    fill(color,color+100010,-1);

    for (int i = 0; i < N-1; i++){
        cin >> u[i] >> v[i] >> w[i];
        u[i]--; v[i]--;
        w[i] %= 2;
        g[u[i]].push_back({v[i],w[i]});
        g[v[i]].push_back({u[i],w[i]});
    }
    //check
    //cout << "check" << endl;
    color[0] = 0;
    queue<ll> que;
    que.push(0);
    while(que.size()){
        ll q = que.front();
        que.pop();
        for (int i = 0; i < g[q].size(); i++){
            int tmp = g[q][i].to;
            if (color[tmp] != -1) continue;
        
            if (color[q] == 0){
                if (g[q][i].cost % 2 == 0){
                    color[g[q][i].to] = 0;
                } else {
                    color[g[q][i].to] = 1;
                }
            } else {
                if (g[q][i].cost % 2 == 0){
                    color[g[q][i].to] = 1;
                } else {
                    color[g[q][i].to] = 0;
                }
            }
            que.push(tmp);
        }
    }

    for (int i = 0; i < N; i++){
        if (color[i] == -1) cout << 1 << endl;
        else cout << color[i] << endl;
    }
}

Measured memory_bytes: 10624
# -*- coding: utf-8 -*-
"""
queue
"""
from collections import deque

N, Q = map(int, input().split())

que = deque()
for i in range(N):
    name, time = map(str, input().split())
    que.append([name, int(time)])

cnt = 0
while len(que) != 0:
    cur = que.popleft()
    # もう1回
    if cur[1] - Q > 0:
        cnt += Q
        que.append([cur[0], cur[1] - Q])
    # やりきった
    else:
        cnt += cur[1]
        print(cur[0], cnt)



Measured memory_bytes: 13312
#include <iostream>
#ifndef LIB_REPEAT_HPP
#define LIB_REPEAT_HPP
#define repeat(i,n) for (int i = 0; i < (n); ++i)
#define repeat_from(i,m,n) for (int i = (m); i < (n); ++i)
#define repeat_one(i,n) for (int i = 1; i <= (n); ++i)
#define repeat_rev(i,n) for (int i = (n)-1; 0 <= i; --i)
#define foreach(it, cont) for (typeof(cont.begin()) it = cont.begin(); it != cont.end(); ++it)
#endif
using namespace std;
string encode_char(int n, int d) {
    string s = "";
    if (n == 0) {
    } else if (n == 1) {
        s += d;
    } else {
        s += n+'0';
        s += d;
    }
    return s;
}
string encode(int n) {
    string s = "";
    s += encode_char((n / 1000) % 10, 'm');
    s += encode_char((n /  100) % 10, 'c');
    s += encode_char((n /   10) % 10, 'x');
    s += encode_char((n /    1) % 10, 'i');
    return s;
}
int decode(const string s) {
    int i = 0;
    int n = 0;
    while (i < (int)s.length()) {
        int m = 1;
        if ('0' <= s[i] and s[i] <= '9') {
            m = s[i] - '0';
            ++ i;
        }
        switch (s[i]) {
            case 'm': n += 1000*m; break;
            case 'c': n +=  100*m; break;
            case 'x': n +=   10*m; break;
            case 'i': n +=    1*m; break;
        }
        ++ i;
    }
    return n;
}
int main() {
    ios_base::sync_with_stdio(false);
    int n; cin >> n;
    repeat (i,n) {
        string a, b; cin >> a >> b;
        cout << encode(decode(a) + decode(b)) << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
import copy
from typing import List, Tuple


def partition(elements: List[Tuple[str, int]], start_idx: int, pivot_idx: int) -> int:
    pivot = elements[pivot_idx][1]
    i = start_idx - 1

    for j in range(start_idx, pivot_idx):
        if elements[j][1] <= pivot:
            i += 1
            elements[i], elements[j] = elements[j], elements[i]
    elements[i + 1], elements[pivot_idx] = elements[pivot_idx], elements[i + 1]

    return i + 1


def quick_sort(elements: List[Tuple[str, int]], p: int, r: int) -> None:
    if p < r:
        q = partition(elements, p, r)
        quick_sort(elements, p, q - 1)
        quick_sort(elements, q + 1, r)


if __name__ == "__main__":
    n = int(input())
    elements = [("", 0)] * n
    for i in range(n):
        element = input().split()
        elements[i] = (element[0], int(element[1]))

    elements_copy = copy.deepcopy(elements)
    quick_sort(elements, 0, n - 1)

    for i in range(n - 1):
        if elements[i][1] == elements[i + 1][1]:
            if elements_copy.index(elements[i]) > elements_copy.index(elements[i + 1]):
                print("Not stable")
                break
    else:
        print("Stable")

    for elem in elements:
        print(f"{elem[0]} {elem[1]}")



Measured memory_bytes: 18564
#include<stdio.h>
#include<stdlib.h>
int main(void) {
	int n;
	int h[100000];
	int dp[10000];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &h[i]);
	}

	int sum = 0;
	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);
	for (int i = 2; i < n; i++) {
		if (dp[i - 2] + abs(h[i] - h[i - 2]) > dp[i - 1] + abs(h[i] - h[i - 1])) {
			dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
		}
		else {
			dp[i] = dp[i - 2] + abs(h[i] - h[i - 2]);
		}
	}
	printf("%d\n", dp[n-1]);
	return 0;
}

Measured memory_bytes: 640
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextStr() 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 gcd(n, m int) int {
	var temp, rem int
	if n < m {
		temp = n
		n = m
		m = temp
	}
	for {
		rem = n % m
		if rem == 0 {
			break
		}
		n = m
		m = rem
	}
	return m
}

func main() {
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()
	//aとb最小公倍数 = a * b / aとbの最大公約数
	fmt.Println(a * b / gcd(a, b))
}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
#define int long long

signed main() {
    int n;
    cin >> n;
    int a;
    int ans = INF;
    rep(i, n) {
        cin >> a;
        int cnt = 0;
        while (a % 2 == 0) {
            cnt++;
            a /= 2;
        }
        chmin(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <limits>
#include <numeric>
#include <iomanip>
#include <cstdlib>
#include <iterator>
#include <functional>

using namespace std;

typedef unsigned                    ui;
typedef int                         si;
typedef long                        sl;
typedef long long                   ll;
typedef unsigned long long          ull;

#ifdef LOCALHOST
std::ifstream in("input.txt", std::ifstream::in);
#endif // LOCALHOST

#ifdef LOCALHOST
#define is in
#else
#define is cin
#endif // LOCALHOST

int main(int argc, char *argv[])
{
    std::ios_base::sync_with_stdio(false);

    string s;
    cin >> s;

    int count = 0;
    for (int i = 0; i < s.size() / 2; ++i) {
        if (s[i] != s[s.size() - i - 1]) {
            ++count;
        }
    }

    cout << count << endl;

    return 0;
}


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

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

  //順列を格納する
  vector<int> ac(n),pena(n);//ACしたか、ペナルティしたか、問題番号は0～n-1とする


  //各問題提出を記録する
  rep(i,m) {
    int p;
    string s;
    cin >> p >> s;
    --p;//0からなのでデクリメントする
    if (ac[p]) continue;//同じ問題で既にACしていたら以降の処理をしない(0ならFalse、1ならTrue)
    if (s == "AC") {
      ac[p] = 1;
    }
    else {
      pena[p]++;
    }
  }

  //結果を集計する
  int AC = 0,PENA = 0;
  rep(i,n) {
    AC += ac[i];
    if (ac[i]) PENA += pena[i];//ACした問題だけペナルティを加算する
  }
  printf("%d %d\n",AC,PENA);
}

Measured memory_bytes: 1024
def resolve():
    n = int(input())
    pp = list(map(int, input().split()))

    cnt = 0

    for p1,p2,p3 in zip(pp,pp[1:],pp[2:]):
        if p1 > p2 >= p3 or p1 <= p2 < p3:
            cnt += 1

    print(cnt)
    
resolve()

Measured memory_bytes: 38256
# -*- coding: UTF-8 -*-

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))


s = 0
before = -1

for i in a:
    s += b[i-1]
    if i == before + 1:
        s += c[before-1]
    before = i

print(s)


Measured memory_bytes: 3060
#!/usr/bin/env ruby
while line = gets
  sentence = line.chomp!

  alphs = ('a'..'z').to_a
  reserves = ['this', 'the', 'that']

  26.times do |n|
    pros = ''
    sentence.chars do |chr|
      if alphs.include?(chr)
        index = (alphs.index(chr) + n) % alphs.length
        pros << alphs[index]
      else
        pros << chr
      end
    end
    if Regexp.union(reserves) =~ pros
      puts pros
      break
    end
  end
end

Measured memory_bytes: 8856
#include <bits/stdc++.h>
using namespace std;
 
#define mod 1000000000
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vs vector<string>
#define psi pair<string,ll>
#define pii pair<ll,ll>
#define vsi vector<psi>
#define vii vector<pii>
#define mp make_pair
#define pb push_back
#define rep(n) for(long i=0;i<n;i++)
#define repr(n) for(long i=(n-1);i>=0;i--)
#define fori(i,a,b) for(auto i=a;i<=b;i++)
#define ford(i,b,a) for(auto i=b;i>=a;i--)
#define mset(a,i) memset(a,i,sizeof(a))
#define minv(a) min_element(a.begin(),a.end())
#define maxv(a) max_element(a.begin(),a.end())
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define sotit(a) sort(a.begin(),a.end());
#define sot(a) sort(a,a+n);
#define ff first
#define maxheap(v) priority_queue<v>
#define minheap(v) priority_queue<v, vector<v>, greater<v>>
#define ss second
#define endl "\n"
#define NL cout<<endl;
#define printmat(a,m,n) for(int i=0;i<m;i++){       \
							for(int j=0;j<n;j++){   \
								cout<<a[i][j]<<" "; \
							}                       \
							cout<<endl;             \
						}
#define dbgn(x) cout<<" $ "<<x<<" $ "<<endl;
#define dbg(x) cout<<" $ "<<x<<" $ ";
#define all(v) v.begin(),v.end()
#define len(s) (ll)(s.size())
#define show(a,n) for(int i=0;i<n;i++){ cout<<a[i]<<" "; } NL
#define fast_io() cin.sync_with_stdio(false);cout.sync_with_stdio(false);cin.tie(NULL);
 
// lower_bound - which does not compare less than val
// upper_bound - which compares greater than val

int main() {
	fast_io()
 
	ll t;
	//cin>>t;
	t=1;
	while(t--){
		ll n,k;
		cin>>n>>k;
		ll h[n],dp[n];
		rep(n){
			cin>>h[i];
		}
		mset(dp,0);
		dp[1]=abs(h[1]-h[0]);
		ll ans;
		fori(i,2,n-1){
			ans=LLONG_MAX;
			fori(j,1,min((ll)i,k)){
				if(i-j>=0)
					ans=min(ans,dp[i-j]+abs(h[i]-h[i-j]));
			}
			dp[i]=ans;
		}
		cout<<dp[n-1];
	}
	return 0;
}

Measured memory_bytes: 1792
#include"bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef pair<int, int> P;
int a[20], b[20];

int dp[1 << 18][18];
int popcnt(int n) {
	if (!n)return 0;
	return (n & 1) + popcnt(n >> 1);
}
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i]; rep(i, n)cin >> b[i];
	rep(j, 1 << n)rep(i, n)dp[j][i] = 1e9;
	rep(i, n)dp[1 << i][i] = i;

	rep(i, 1 << n) {
		rep(j, n) {
			if (i&(1 << j)) {
				int now;
				if (abs(j - popcnt(i)) & 1)now = a[j];
				else now = b[j];
				rep(k, n) {
					if (!(i&(1 << k))) {//kを追加
						int po = popcnt(i);
						int nxt;
						if (abs(k - po) & 1)nxt = b[k];
						else nxt = a[k];
						if (now <= nxt) {
							int cst = k-popcnt(i&((1 << k) - 1));
							dp[i | (1 << k)][k] = min(dp[i | (1 << k)][k], dp[i][j] + cst);
						}
					}
				}
			}
		}
	}
	int res = 1e9;
	rep(i, n)res = min(res, dp[(1 << n) - 1][i]);
	if (res == 1e9)res = -1;
	cout << res << endl;
}

Measured memory_bytes: 37120
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(30);
  
  ld a, b;
  cin >> a >> b;
  b *= a;
  cout << (ll)floor(b) << newl;
  return 0;
}


Measured memory_bytes: 3812
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int main(void){
    long long n,ans=0;
    scanf("%lld",&n);
    long long p[n];
    for (int i=0; i<n; i++){
        scanf("%lld",&p[i]);
    }
    for (int i=1; i<n-1; i++){
        if (p[i-1]<p[i] && p[i]<p[i+1]){
            ans++;
        } else if (p[i-1]>p[i] && p[i]>p[i+1]){
            ans++;
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

ll a[100010], t[100010], m[100010];

void fail(){
    cout << 0 << endl;
    exit(0);
}

int main(){
    int n;
    cin >> n;
    rep(i, n) cin >> t[i];
    rep(i, n) cin >> a[i];

    if (a[0] != t[n-1]) fail();

    m[0] = t[0];
    m[n-1] = a[n-1];

    rep(i, n-1) {
        if (t[i] < t[i+1]) {
            if (m[i+1] > 0 && m[i+1] != t[i+1]) fail();
            if (a[i+1] < t[i+1]) fail();
            m[i+1] = t[i+1];
        }
    }
    for(int i = n-1; i > 0; i--) {
        if (a[i] < a[i-1]) {
            if (m[i-1] > 0 && m[i-1] != a[i-1]) fail();
            if (a[i-1] > t[i-1]) fail();
            m[i-1] = a[i-1];
        }
    }


    ll ans = 1;

    rep(i, n){
        if (m[i] == 0){
            ans *= min(a[i], t[i]);
            ans %= MOD;
        }
    }

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


Measured memory_bytes: 5864
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define FOR(i, n) for (int i = 0; i < n; i++)

int main() {
  ll n;
  cin >> n;
  // ll a,b,c;
  // string s;
  ll tmp, n_max = 0, sum = 0;
  FOR(i, n) {
    cin >> tmp;
    n_max = max(tmp, n_max);
    sum += tmp;
  }
  ll ans = sum - n_max / 2;
  //  cout << ((  )? "YES" : "NO) <<endl;
  //  cout << ((  )? "Yes" : "No) <<endl;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
class dice():
    
    def __init__(self,a,b,c,d,e,f):
        self.A=[a,b,c,d,e,f]
        self.temp=[]
        
    def N_method(self):
       for i in self.A:
        self.temp.append(i)       


       self.A[0]=self.temp[1]
       self.A[1]=self.temp[5]
       self.A[4]=self.temp[0]
       self.A[5]=self.temp[4]
       self.A[2]=self.temp[2]
       self.A[3]=self.temp[3]
       self.temp=[]
       #print(self.A[0])
    def S_method(self):
        for i in self.A:
           self.temp.append(i)
       
        self.A[0]=self.temp[4]
        self.A[1]=self.temp[0]
        self.A[2]=self.temp[2]
        self.A[3]=self.temp[3]
        self.A[4]=self.temp[5]
        self.A[5]=self.temp[1]
        self.temp=[]
        #print(self.A[0])
    def W_method(self):
       for i in self.A:
          self.temp.append(i)
       
       self.A[0]=self.temp[2]
       self.A[1]=self.temp[1]
       self.A[2]=self.temp[5]
       self.A[3]=self.temp[0]
       self.A[4]=self.temp[4]
       self.A[5]=self.temp[3]
       self.temp=[]
       #print(self.A[0])
    def E_method(self):
        for i in self.A:
            self.temp.append(i)
        
        self.A[0]=self.temp[3]
        self.A[1]=self.temp[1]
        self.A[2]=self.temp[0]
        self.A[3]=self.temp[5]
        self.A[4]=self.temp[4]
        self.A[5]=self.temp[2]
        self.temp=[]
        #print(self.A[0])
    
    def printout(self):
        print(self.A[0])
if __name__=="__main__":

    input_text=""
    input_text=input()
    array=[]
    array=input_text.split()

    ob1=dice(array[0],array[1],array[2],array[3],array[4],array[5])

    input_order=input()
    order_array=[]
    order_array=list(input_order)


    for i in range(0,len(order_array)):
        
        if order_array[i]=="E":
            ob1.E_method()
        elif order_array[i]=="S":
            ob1.S_method()
        elif order_array[i]=="W":
            ob1.W_method()
        elif order_array[i]=="N":
            ob1.N_method()
  
    ob1.printout()


Measured memory_bytes: 5580
#include <iostream>
    #include <algorithm>
    #include <cstdlib>
    #include <cstdio>
    #include <numeric>
    #include <utility>
    #include <cmath>
    #include <vector>
    #include <queue>
    #include <string>
    #include <map>
    #define MAX_U   10
    #define MIN_U   0
    #define rep(i,n) for(int i=0;i<n;i++)
    #define sz(x) ((int)(x).size())
    using namespace std;
    typedef long long ll;
    typedef vector<int> vi;
    typedef vector<char> vc;
    typedef vector<string> vs;
    typedef queue<int> qi;
    const int INF=numeric_limits<int>::infinity();
    void printa(){cout<<"\n";}
    template<class T, class... A>void printa(const T&first,const A&... rest){cout<<first;printa(rest...);}
    template<class... A>void printa(const A&... rest){printa(rest...);}
    void prints(){cout<<" ";}
    template<class T, class... A>void prints(const T&first,const A&... rest){cout<<first;prints(rest...);}
    template<class... A>void prints(const A&... rest){prints(rest...);}
    int factorial(int x){int f=1;for(int i=1;i<x+1;i++)f=f*i;return f;}
    int sigma(int x){int s;for(int i=1;i<x+1;i++)s=s+i;return s;}
    int middle(int x){if(x%2==0)return x/2;else return x/2+1;}
    double heron(int a,int b,int c){double s;s=(a+b+c)/2;return sqrt(s*(s-a)*(s-b)*(s-c));}
    double trapezium(int a,int b,int h){return (a+b)*h/2;}
    double triangle(int a,int h){return a*h/2;}
    void sorm(vector<int> vec){sort(vec.begin(),vec.end());}
    void sorg(vector<int> vec){sort(vec.begin(),vec.end(),greater<int>());}
    int cmp( const void *p, const void *q ) {
    if( *(double*)p > *(double*)q ) return 1;
    if( *(double*)p < *(double*)q ) return -1;
    return 0;
    }
    int main(void){
        cin.tie(0);
        ios::sync_with_stdio(false);
        int a,b,c,d; 
        cin>>a>>b>>c>>d;
        if(a>100||b>100||c>100||d>100)exit(0);
        else if(b-a<=d&&c-b<=d&&b-a>=d-2*d&&c-b>=d-2*d){
            printa("Yes");
        }
        else if(c-a<=d&&c-a>=d-2*d){
            printa("Yes");
        }
        else printa("No");
        return 0;
    }

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

int main(){ int n; long long a = 0;
	cin >> n;
	for (int i=0; i<=10000007; i++){
		a = (a*10+7)%n;
		if(a == 0){
			cout << i+1 << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>

using namespace std;

int main(){
	int N,T,c[120],t[105];
	cin >> N >> T;
	
	for(int i=0; i<N; i++){
		cin >> c[i] >> t[i];
	}
	
	int ans = 99999;
	
	for(int i=0;i<N;i++){
		if(t[i] <= T){
			if(c[i] < ans){
				ans = c[i];
			}
		}
	}
	if(ans <99999){
		cout<<ans<<endl;
	}
	else{
		cout<<"TLE"<<endl;
	}
	return 0;
}

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

int main() {

  string key[10] ={
    "00000",
    ".,!? ",
    "abc",
    "def",
    "ghi",
    "jkl",
    "mno",
    "pqrs",
    "tuv",
    "wxyz"
  };


  int n;
  cin >> n;
  string str;
  for(int j=0;j<n;j++){
    cin >> str;
    int cnt = -1;
    int ima;
    for(int i=0;i<str.size();i++){
      if(cnt == -1 && str[i] == '0') continue;
      if(str[i] == '0'){
	cout <<key[ima][cnt%key[ima].size()];
	cnt = -1;
      }
      else{
	ima = str[i]-'0';
	cnt++;
      }   
    }
    cout << endl;
    
  }

    return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MAX = 55;
const Int D = 22;
Int c[MAX][MAX];
Int r[MAX*MAX];
Int x[MAX],y[MAX];
Int w,h,n;
Int used[MAX];
Int ok;
bool check(Int a){
  Int u[MAX][MAX];
  memset(u,0,sizeof(u));
  
  Int dy[]={0,0,1,-1};
  Int dx[]={1,-1,0,0};
  
  using P = pair<Int, Int>;
  queue<P> q;
  u[y[a]][x[a]]=1;
  q.emplace(y[a],x[a]);

  Int cnt=0;
  while(!q.empty()){
    Int cy,cx;
    tie(cy,cx)=q.front();q.pop();
    cnt++;
    for(Int k=0;k<4;k++){
      Int ny=cy+dy[k],nx=cx+dx[k];
      if(u[ny][nx]) continue;
      if(!c[ny][nx]) continue;
      Int b=r[ny*MAX+nx];
      assert(~b);
      if(used[a]!=used[b]) continue;
      u[ny][nx]=1;
      q.emplace(ny,nx);
    }
  }
  return (cnt*2==n);
};

void print(Int k){
  //return;
  if(k&1){
    for(Int i=D;i+D<MAX;i++){
      for(Int j=D;j+D<MAX;j++){
	cout<<c[i][j]<<" ";
      }
      cout<<endl;
    }
  }
  if(k&2){
    for(Int i=D;i+D<MAX;i++){
      for(Int j=D;j+D<MAX;j++){
	if(!c[i][j]) cout<<c[i][j]<<" ";
	else cout<<used[r[i*MAX+j]]<<" ";
      }
      cout<<endl;
    }
  }
}

void dfs(Int a,Int b,Int k,Int d,Int p){
  if(p==n){
    ok|=check(a)&&check(b);
    if(ok) print(0);
    return;
  }
  if(ok) return;
  if(used[p]){
    dfs(a,b,k,d,p+1);
    return;
  }
  // used[p]=1
  [&]{
    Int dy=y[a]-y[p];
    Int dx=x[a]-x[p];
    if(k) dx*=-1;
    for(Int i=0;i<d;i++){
      Int ny=-dx,nx=dy;
      dy=ny;dx=nx;
    }
    Int qy=y[b]-dy;
    Int qx=x[b]-dx;
    if(!c[qy][qx]) return;
    Int q=r[qy*MAX+qx];
    assert(~q);
    if(used[q]) return;
    if(p==q) return;
    
    used[p]=1;
    used[q]=2;
    
    dfs(a,b,k,d,p+1);

    used[p]=0;
    used[q]=0;
  }();
  if(ok) return;
  // used[p]=2
  [&]{
    Int dy=y[b]-y[p];
    Int dx=x[b]-x[p];
    for(Int i=0;i<4-d;i++){
      Int ny=-dx,nx=dy;
      dy=ny;dx=nx;
    }
    if(k) dx*=-1;
    Int qy=y[a]-dy;
    Int qx=x[a]-dx;
    {
      if(k) dx*=-1;
      for(Int i=0;i<d;i++){
	Int ny=-dx,nx=dy;
	dy=ny;dx=nx;
      }
      assert(y[b]-y[p]==dy);
      assert(x[b]-x[p]==dx);
    }
    if(!c[qy][qx]) return;
    Int q=r[qy*MAX+qx];
    assert(~q);
    if(used[q]) return;
    if(p==q) return;
    
    used[p]=2;
    used[q]=1;
    
    dfs(a,b,k,d,p+1);

    used[p]=0;
    used[q]=0;
  }();
};
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  while(cin>>w>>h,w){
    memset(c,0,sizeof(c));
    for(Int i=0;i<h;i++)
      for(Int j=0;j<w;j++)
	cin>>c[i+D][j+D];
    
    memset(r,-1,sizeof(r));
    memset(y,-1,sizeof(y));
    memset(x,-1,sizeof(x));
    n=0;
    for(Int i=0;i<MAX;i++){
      for(Int j=0;j<MAX;j++){
	if(!c[i][j]) continue;
	y[n]=i;
	x[n]=j;
	r[i*MAX+j]=n++;
      }
    }
    if(n&1){
      cout<<"NO"<<endl;
      continue;
    }
    ok=0;
    for(Int i=0;i<n;i++){
      for(Int j=0;j<i;j++){
	for(Int k=0;k<2;k++){
	  for(Int d=0;d<4;d++){
	    memset(used,0,sizeof(used));
	    used[i]=1;
	    used[j]=2;
	    dfs(i,j,k,d,0);
	    if(ok) goto END;
	  }
	}
      }
    }
  END:
    cout<<(ok?"YES":"NO")<<endl;
  }
  return 0;
}



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

int h, w;
string field[50]; 

int main(){
    cin >> h >> w;
    for(int i = 0; i < h; i++){
       cin >> field[i];
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(field[i][j] == '#'){
                if(i != 0){
                    if(field[i - 1][j] == '#') continue;
                }
                if (i != h - 1){
                    if (field[i + 1][j] == '#') continue;
                }
                if (j != 0){
                    if (field[i][j - 1] == '#') continue;
                }
                if (j !=  w - 1){
                    if (field[i][j + 1] == '#') continue;
                }
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main() {
  vector<int> dp(100001);
  dp[0] = 0;
  for(int i = 1; i <= 100000; i++){
    dp[i] = 100001;
    int p = 1;
    while(p <= i){
      dp[i] = min(dp[i], dp[i-p]+1);
      p *= 6;
    }
    p = 1;
    while(p <= i){
      dp[i] = min(dp[i], dp[i-p]+1);
      p *= 9;
    }
  }
  int n;
  cin >> n;
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
int main() {
	ll n,k;
	cin>>n>>k;
	for(ll i=0;i<k;i++){
		ll now;
		cin>>now;
		n-=now;
	}
	if(n<=0){
		cout <<"Yes";
	}
	else{
		cout << "No";
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    string s;
    cin >> s;
    int ans = INF;
    rep(i, s.size() - 2)
    {
        int num = 0;
        rep(j, 3)
            num = 10 * num + (s[i + j] - '0');
        int tmp = abs(753 - num);
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;


int main() {
	int n,ans=0;
	cin >> n;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		sort(a.begin(), a.end());
		if(i%2){
			ans -= a[n-i-1];
		}
		else {
			ans += a[n-i-1];
		}
		a.pop_back();
	}
	cout << ans;
	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 256
#include <iostream>
#define llint long long

using namespace std;

llint N;
llint X[100005];
llint A, B;

int main(void)
{
	cin >> N >> A >> B;
	for(int i = 0; i < N; i++) cin >> X[i];
	
	llint ans = 0;
	for(int i = 0; i < N-1; i++){
		ans += min( A*(X[i+1] - X[i]), B );
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)


int main() {
	cin.sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int>a(N);
	bool flag = true;
	rep(i, N) {
		cin >> a[i];
		if (a[i] == 2)flag = false;
	}
	if (flag) {
		cout << -1 << endl;
		return 0;
	}
	int ans = 0;
	int k = 0;
	while (1) {
		ans++;
		if (a[k] == -1) {
			cout << -1 << endl;
			return 0;
		}
		if (a[k] == 2) {
			break;
		}
		else {
			int x = a[k];
			a[k] = -1;
			k = x - 1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
//#include <cstdio>
//#include <algorithm>
//#include <cmath>
//#include <cstring>
//#include <iostream>
using namespace std;
typedef long long ll;
const int maxx=1e5+100;
const int INF=1e9;
const int MOD=1e9+7;
char s[maxx];
 
int main()
{
    scanf("%s",s);
    for(int i=0; i<strlen(s); i+=2){
        printf("%c",s[i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define F first
#define S second

int s[100009];
typedef long long ll;
#define MOD 998244353
ll calc(ll a,ll b){
  ll res=1;
  for(int i=0;(1LL<<i)<=b;i++){
    if(b>>i&1) res=(res*a)%MOD;
    a=(a*a)%MOD;
  }
  return res % MOD;
}

signed main(){
	int n;
	cin>>n;
	int a[n];
	r(i,n){
		cin>>a[i];
		if(i && !a[i]){
			cout<<0<<endl;
			return 0;
		}
		s[a[i]]++;
	}
	if(s[0]!=1){
		cout<<0<<endl;
		return 0;
	}
	int sum=1;
	for(int i=1;i<n;i++){
		if(s[i]==0){
			continue;
		}
		else{
			if(s[i-1]==0){
				cout<<0<<endl;
				return 0;
			}
		}
		sum *= calc(s[i-1],s[i]);
		sum %= 998244353;
	}

	cout<<sum<<endl;

}

Measured memory_bytes: 1792
#include<iostream>
#include <string>
using namespace std;
int main()
{
    // 整数の入力
    int a;
    int b;
    int c;

    cin >> a;
    if (a == 1){
    cout << "Hello World" << endl;
    }
    else{
    cin >> b;
    cin >> c;
    cout << b+c << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int D, N;
	cin >> D >> N;
	int T[D];
	rep(i, 0, D) cin >> T[i];
	int A[N], B[N], C[N];
	rep(i, 0, N) cin >> A[i] >> B[i] >> C[i];

	int dp[D + 1][N + 1];
	memset(dp, 0, sizeof(dp));


	rep(i, 1, D) {
		rep(j, 0, N) {
			rep(k, 0, N) {
				if(A[j] <= T[i] && T[i] <= B[j] && A[k] <= T[i - 1] && T[i - 1] <= B[k]) {
					dp[i + 1][j] = max(dp[i][k] + abs(C[k] - C[j]), dp[i + 1][j]);
				}
			}
		}
	}

	int ans = 0;
	rep(i, 0, N) {
		ans = max(ans, dp[D][i]);
	}

	cout << ans << endl;

}




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

int main(){
    int N, M;
    cin >> N >> M;

    vector<int> p(M, 0);
    for(int i=0;i<N;i++){
        int K;
        cin >> K;
        for(int j=0;j<K;j++){
            int a;
            cin >> a;
            p[a - 1]++;
        }
    }
    int ans = 0;
    for(int i=0;i<M;i++){
        if(p[i] == N) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256