akhauriyash/Code-Regression huggingface dataset:
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

void printl(vector<pair<int, string>>);
vector<pair<int, string>> bubbleSort(vector<pair<int, string>> A, int N);
vector<pair<int, string>> selectionSort(vector<pair<int, string>> A, int N);

int main()
{
    int N;
    cin >> N;
    vector<string> S(N);
    rep(i, N) cin >> S.at(i);
    vector<pair<int, string>> A(N);
    rep(i, N)
    {
        int num;
        string ch;
        ch = S.at(i).at(0);
        num = int(S.at(i).at(1)) - 48;
        A.at(i) = make_pair(num, ch);
    }
    auto BS = bubbleSort(A, N);
    printl(BS);
    cout << "Stable" << endl;
    auto SS = selectionSort(A, N);
    printl(SS);
    if (BS == SS)
    {
        cout << "Stable" << endl;
    }
    else
    {
        cout << "Not stable" << endl;
    }
}

void printl(vector<pair<int, string>> A)
{
    rep(i, A.size())
    {
        cout << A.at(i).second << A.at(i).first;
        if (i != A.size() - 1)
        {
            cout << " ";
        }
        else
        {
            cout << endl;
        }
    }
}
vector<pair<int, string>> bubbleSort(vector<pair<int, string>> A, int N) //N個の要素を含む、0オリジンの配列 A
{
    for (int i = 0; i < N; i++)
    {
        for (int j = N - 1; j > i; j--)
        {
            if (A[j].first < A[j - 1].first)
            {
                swap(A[j], A[j - 1]);
            }
        }
    }
    return A;
}
vector<pair<int, string>> selectionSort(vector<pair<int, string>> A, int N)
{
    for (int i = 0; i < N; i++)
    {
        int minj = i;
        for (int j = i; j < N; j++)
        {
            if (A.at(j).first < A.at(minj).first)
            {
                minj = j;
            }
        }
        swap(A.at(minj), A.at(i));
    }
    return A;
}


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

int main(){
  string s;
  cin >> s;
  int c=0,f=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='C') c++;
    if(c&&s[i]=='F') f++;
  }
  if(c&&f) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3584
using System;
using System.Linq;

namespace ARC063_D___高橋君と見えざる手
{
    class Program
    {
        static void Main(string[] args)
        {
            var NT = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = NT[0];
            var A = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);

            var income = new long[N];
            var min = A[0];
            for (int i = 1; i < N; i++)
            {
                income[i] = A[i] - min;
                if (A[i] < min) min = A[i];
            }

            var maxIncome = income.Max();
            Console.WriteLine(income.Count(i => i == maxIncome));
        }
    }
}


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

main(){
int N;
  cin >> N;
  
  bool flag =false;
  
  for(int i=0; i*7<=N;i++){
    if((N-i*7)%4==0){
      flag = true;
      break;
    }
  }

  if(flag) cout<< "Yes"<< endl;
  if(!flag) cout<< "No"<< endl;
  
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Aojx
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            Dictionary<string, List<int>> dic =
                new Dictionary<string, List<int>>();
            
            string s;
            while ((s = Console.ReadLine()) != null)
            {
                var row = s.Split(' ');
                if (dic.ContainsKey(row[0]))
                {
                    dic[row[0]].Add(int.Parse(row[1]));
                }
                else
                {
                    dic[row[0]] = new List<int>();
                    dic[row[0]].Add(int.Parse(row[1]));
                }
            }

            foreach (var d in dic.OrderBy(e => e.Key))
            {
                Console.WriteLine(d.Key);
                Console.WriteLine(String.Join(" ", d.Value.OrderBy(e => e)
                    .Select(e => e.ToString()).ToArray()));
            }
        }
    }
}

Measured memory_bytes: 7020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    rep(i,N-1){
        rep2(j,i+1,N){
            int diff=j-i;
            rep(k,10) if (diff&1<<k){
                cout << k+1;
                break;
            }
            if (j!=N-1) cout << ' ';
            else cout << endl;
        }
    }
}

Measured memory_bytes: 512
#pragma optimize GCC("-O3","unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=105,INF=1<<30;

int main(){
    int A,B;cin>>A>>B;

    if(A==2) cout<<-1<<endl;
    else if(A==3){
        if(B==4) cout<<6<<endl;
        else cout<<-1<<endl;
    }else if(A==4){
        if(B==5||B==6) cout<<8<<endl;
        else if(B==9) cout<<12<<endl;
        else cout<<-1<<endl;
    }else{
    int m;
    for(int i=B;;i++){
        if(i%A==0){
            m=i;
            break;
        }
    }
    bool ok=false;

    for(int i=m;i<=2*B;i+=A){
        int a=(i/B)+(i%B)/A+(i%B)%A;
        int b=(i/A)+(i%A);
        if(a>b){
            cout<<i<<endl;
            ok=true;
            break;
        }
    }

    if(!ok) cout<<-1<<endl;
    }
    
}





Measured memory_bytes: 3104
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    if (a + b >= c) cout << b + c << endl;
    else cout << (a + b) + b + 1 << endl;
    return 0;
}

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

int digit ();
int main () {
	int a, b;
	while (scanf ("%d %d", &a, &b) != EOF) {
		printf ("%d\n", digit (a + b));
	}
	return 0;
}

int digit (int sum) {
	return (int) log10((double) sum) + 1;
}

Measured memory_bytes: 644
n, m = map(int, input().split(' '))
a = list(map(int, input().split(' ')))

sum_votes = sum(a)
pivot = sum_votes / (4*m)
cnt = m
for i in range(len(a)):
    if a[i] >= pivot:
        cnt -= 1
if cnt <= 0:
    print('Yes')
else:
    print('No')


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

int main() {
  int D, G; cin >> D >> G;
  G /= 100;
  auto p = vector<int>(D);
  auto c = vector<int>(D);
  for (int i = 0; i < D; ++i) {
    cin >> p[i] >> c[i];
    c[i] /= 100;
  }
  int ans = 1e9;
  for (int b = 0; b < 1 << D; ++b) {
    int sum = 0, cnt = 0, mx = -1;
    for (int i = 0; i < D; ++i) {
      if (b >> i & 1) {
        sum += (i + 1) * p[i] + c[i];
        cnt += p[i];
      } else {
        mx = i;
      }
    }
    if (G > sum) {
      int need = (G - sum + mx) / (mx + 1);
      if (need >= p[mx]) continue;
      cnt += need;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
a = int(input())
spl = [0] * 4

for i in range(4):
    spl[i] = a % 10
    a = a // 10

flag = 0

for i in range(4-1):
    if(spl[i]==spl[i+1]):
        flag = 1

if(flag==1):
    print("Bad")
if(flag==0):
    print("Good")

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct res{int num; char s[11]; int p;}res;

int dic(const void *a, const void *b){
    res *r1 = (res *)a;
    res *r2 = (res *)b;
    if(strcmp(r1->s, r2->s) == 0){return r2->p - r1->p;}
    return strcmp(r1->s, r2->s);
}

int main(){
    int n, i;
    scanf("%d", &n);
    res r[n];

    for(i=0; i<n; i++){
        scanf("%s %d", r[i].s, &r[i].p);
        r[i].num = i+1;
    }

    qsort(r, n, sizeof(res), dic);
    for(i=0; i<n; i++){
        printf("%d\n", r[i].num);
    }

    return 0;
}

Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(v) v.begin(), v.end()
typedef long long ll;



int main() {
    int k, x, y;
    cin >> k >> x >> y;
    int kk = k;
    while(k < x) k += kk;
    
    if(k > y) dunk("NG");
    else dunk("OK");
    
    return 0;
}


Measured memory_bytes: 3636
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    //tmp = input.split("\n");
    
    a = [3,5,7];
    if(a.indexOf(Number(input)) > -1)
    {
        console.log("YES");
    }else{
        console.log("NO");
    }
 
    //console.log(answer);
 
    
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
using System;
 
class Program{
	static void Main(){
		int n;
		while((n = int.Parse(Console.ReadLine())) != 0){
			int max = -100001;
			int sum = 0;
			
			while(n-- > 0){
				int m = int.Parse(Console.ReadLine());
				sum += m;
				if(sum > max) max = sum;
				if(sum < 0) sum = 0;
			}
			Console.WriteLine(max);
		}
	}
}

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

int main() {
  int N;
  int d[110000];
  int c = 0;
  int res = 0;
  cin >> N;
  
  for(int i = 0; i < N; ++i)
    cin >> d[i];
  sort(d, d+N);
  for(int j = 0; j < N; ++j){
    if(d[j] == d[j + 1])
      c++;
    else{
      c++;
      res += c % 2;
      c = 0;
    }
  }
    
  cout << res << endl;
}
  

Measured memory_bytes: 640
n, t = map(int, input().split())
s = list(map(int, input().split())) + [1145141919810]
ans = 0
for i in range(n):
    if s[i + 1] - s[i] > t:
        ans += t
    else:
        ans += s[i + 1] - s[i]
print(ans)

Measured memory_bytes: 25200
#!/usr/bin/env python3

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


all_weights = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
weights = [all_weights[i] for i in a]

# print(weights)

dp = [-1 for _ in range(n+1)]
dp[0] = 0

for i in range(1, n+1):
    # print(dp)
    for j in range(len(weights)):
        if i-weights[j] >= 0:
            dp[i] = max(dp[i-weights[j]]*10 + a[j], dp[i])

print(dp[-1])


Measured memory_bytes: 20392
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<ll> A(7);
  rep(i, 7) cin >> A[i];
  ll ans = 0;
  ans += A[0]/2 * 2;
  ans += A[1]   * 1;
  ans += A[3]/2 * 2;
  ans += A[4]/2 * 2;
  int id[] = {0, 3, 4};
  switch(A[0]%2+A[3]%2+A[4]%2) {
  case 3:
    ans += 3;
    break;
  case 2:
    rep(i, 3) {
      if(A[id[i]]%2==0) {
        if(A[id[i]] > 0) ans += 1;
        break;
      }
    }
    break;
  case 1:
    break;
  default: // 0
    break;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
 
 
int main() {
	int result = 0;
	string S;
	string T;
 
	cin >> S >> T;
	for (unsigned int i = 0; i < S.size(); i++) {
		if (S[i] != T[i]) {
			result++;
		}
	}
	cout << result;
}

Measured memory_bytes: 3920
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,te=0;
    scanf("%d",&n);
    for(int i=9;i>=1;i--){
        if(n%i==0){
            int r;
            r=(n/i);
            if(r<=9){
                printf("Yes\n");
                te=1;
                break;
            }
        }
    }
    if(te==0){
        printf("No\n");
    }


return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def main():
    Q = int(input())
    lr = []
    for i in range(Q):
        l, r = map(int,input().split())
        lr.append((l,r))
        
    mapd = []
    for i in range(0, 100001):
        if i == 0:
            mapd.append(0)
            continue
        if i == 1:
            mapd.append(0)
            continue
        if i % 2 == 0:
            mapd.append(mapd[i-1])
            continue
        if is_prime(i) and is_prime((i+1)/2):
            mapd.append(mapd[i-1] + 1)
        else:
            mapd.append(mapd[i-1])
            
        
    for i in lr:
        l, r = i
        print(mapd[r] - mapd[l-1])
    
def is_prime(n): 
    i = 2
    while i * i <=n:
        if n % i == 0:
            return False
        i += 1
    return True
	
if __name__ == "__main__":
	main()


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

int N;
int main(){
	cin >> N;
	vector<long long> A(N+1,0),B(N+1,0);
	for(int i=1;i<=N;i++){
		cin >> A[i];
	}
	for(int i=1;i<=N;i++){
		cin >> B[i];
	}
	long long C[N+1] = {0};
	long long c2 = 0,c1 = 0;
	bool judge = true;
	for(int i=1;i<=N;i++){
		C[i] = A[i]-B[i];
		if(C[i]<0 && abs(C[i])%2==1) C[i] += 1;
		if(C[i]<0) c2 += abs(C[i])/2;
		else if(C[i] > 0) c1 += C[i];
	}
	if(c2>=c1) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  
  int ans = 0;
  rep(i, s.size()) {
    if (s[i] != t[i]) ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3852
#include<cstdio>
using namespace std;
#define N 110
#define rep(i,j,k) for(i=j;i<=k;++i)
int n,i,j,k,sum;
int num[N];
void read(int &p){
	p=0; char x=getchar();
	while(x<'0' || x>'9') x=getchar();
	while(x>='0'&&x<='9'){p=p*10+x-'0'; x=getchar();}
}
int main(){
	read(n);
	rep(i,1,n){
		read(k);
		num[k]++;
		if(sum<k) sum=k;
	}
	i=sum;
	while(sum>1){
		if(num[i]<2) {
			puts("Impossible");
			return 0;
		}
		i--; sum-=2;
	}
	if(sum) {
		if(num[i]!=2) {
			puts("Impossible");
			return 0;
		}
	}else{
		if(num[i]!=1){
			puts("Impossible");
			return 0;
		}
	}
	rep(i,1,i-1)
	if(num[i]){
		puts("Impossible");
		return 0;
	}
	puts("Possible");
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <vector>
struct Edge {
  Edge(int from_, int to_, int capacity_, int rev_) : from(from_), to(to_), capacity(capacity_), rev(rev_) {}
  int from;
  int to;
  int capacity;
  int rev;
};

std::vector<Edge> edges[128];

void addEdge(int from, int to, int capacity) {
  int e1 = edges[from].size();
  int e2 = edges[to].size();
  edges[from].push_back(Edge(from, to, capacity, e2));
  edges[to].push_back(Edge(to, from, 0, e1));
}

bool checked[128];
void init_flow() {
  for(int i = 0; i < 128; ++i) checked[i] = false;
}
int flow(int from, int to, int v) {
  if( v <= 0 ) return 0;
  if( from == to ) return v;
  int res = 0;
  checked[from] = true;
  for(Edge& edge : edges[from]) {
    if( checked[edge.to] ) continue;
    int nv = flow(edge.to, to, std::min(v, edge.capacity));
    if( nv == 0 ) continue;
    edge.capacity      -= nv;
    edges[edge.to][edge.rev].capacity += nv;
    res = nv;
    break;
  }
  // checked[from] = false;
  return res;
}

int v;
int maximum_flow(int from, int to) {
  int res = 0;
  for(;;) {
    init_flow();
    // for(int i = 0; i < v; ++i) {
    //   printf("from : %d\n", i);
    //   for(Edge edge : edges[i]) {
    //     printf("%d -> %d : %d $ %d\n", edge.from, edge.to, edge.capacity, edges[edge.to][edge.rev].capacity);
    //   }
    // }
    int v = flow(from, to, (1 << 29));
    if( v == 0 ) break;
    res += v;
    // printf("+%d\n", v);
  }
  return res;
}

int main() {
  int e;
  scanf("%d %d", &v, &e);
  for(int i = 0; i < e; ++i) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    addEdge(a, b, c);
  }

  printf("%d\n", maximum_flow(0, v - 1));

  // for(int i = 0; i < v; ++i) {
  //   printf("from : %d\n", i);
  //   for(Edge edge : edges[i]) {
  //     printf("%d -> %d : %d $ %d\n", edge.from, edge.to, edge.capacity, edges[edge.to][edge.rev].capacity);
  //   }
  // }
  
  return 0;
}

Measured memory_bytes: 2784
#include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#define ll long long
#define lson (rt<< 1)
#define rson (rt<< 1 | 1)
#define gmid ((l+r)>> 1 )
using namespace std;

const int maxn=20000050;

int a[maxn];

int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)
	  {
	  	  cin>>a[i];
	  } 
	ll ans=0;
	int k=a[1];
	for(int i=2;i<=n;++i)
	  if(a[i]<k) 
	  {
	  	  ans+=k-a[i];
	  }  
	  else k=a[i];
	cout<<ans<<endl;  
}


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

int main() {
	long long N;
	vector<long long> A;
	cin >> N;
	A.resize(N);

	for (long long i = 0; i < N; ++i) {
		cin >> A[i];
	}
	int count = 0;
	sort(A.begin(), A.end());
	while (A.size() > 1) {
		if (A[0] <= 0) {
			A.erase(A.begin());
			++count;
			continue;
		}
		for (int i = 1; i < N - count; ++i) {
			int k = A[i] / A[0];
			if (A[i] % A[0] == 0) {
				++count;
				A.erase(A.begin() + i);
			}
			else {
				A[i] -= k * A[0];
				swap(A[i], A[0]);
			}
		}
	}

	cout << A[0] << endl;

	return 0;
}

Measured memory_bytes: 1024
import heapq
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
ab.sort()
ls = []
heapq.heapify(ls)
for i in range(m):
    if ab[i][0] == 1:
        heapq.heappush(ls, ab[i][1])
    else:
        while True:
            if len(ls) != 0:
                p = heapq.heappop(ls)
                if p == ab[i][0]:
                    if ab[i][1] == n:
                        print("POSSIBLE")
                        exit()
                    else:
                        heapq.heappush(ls, p)
                        break
                elif p > ab[i][0]:
                    heapq.heappush(ls, p)
                    break
            else:
                print("IMPOSSIBLE")
                exit()
print("IMPOSSIBLE")


Measured memory_bytes: 54324
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return (x);
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        int n;
        cin >> n;
        vl v(n);
        vl c(n);
        rep(i, n) cin >> v[i];
        rep(i, n) cin >> c[i];
        ll ans = 0;
        rep(i, n) {
            if (v[i] - c[i] > 0) ans += v[i] - c[i];
        }
        cout << ans << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <fstream>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}

};
typedef vector<vector<Edge>> Graph;

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

ll factorial(ll n) {//階乗
	ll ret = 1;
	rep(i, 1, n + 1)
		ret = (ret *i) % MODU;

	return ret;
}

ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x %mod;
		x = x * x%mod;
		n >>= 1;
	}
	return res;
}
ll divmod(ll a, ll b, ll m) { // a/b(mod m)
								  // a/b (mod m)
								  // a*b^-1
								  // b^-1 * b = 1
								  // b^(m-1) = 1 
								  // b^(m-2) * b = 1
								  // b^-1 = b^(m-2)

								  // a/b = a * b^(m-2)

	return (a * 1LL * mod_pow(b, m - 2, m)) % m;
}
ll ncr(ll n, ll r) {
	return divmod(factorial(n), (factorial(r) * (factorial(n - r))) % MODU, MODU);
}


signed main() {
	int n;
	cin >> n;
	vector<int> a(n);
	REP(i, n) cin >> a[i];

	int cur = 1;

	REP(i, n) {
		if (a[i] == cur) cur++;
	}

	if (cur == 1) cout << -1 << endl;
	else	cout << n - cur + 1<< endl;

	return 0;
}


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

int main()
{
        while(true)
        {
                int n,q;
                cin>>n>>q;
                if(n+q==0) break;

                int cnt[105]={0};
                rep(i,n){
                        int m; cin>>m;
                        rep(i,m){
                                int date; cin>>date;
                                cnt[date]++;
                        }
                }

                int M=0,ans=0;
                rep(i,100){
                        if(cnt[i]<q) continue;
                        if(cnt[i]>M){
                                M=cnt[i];
                                ans=i;
                        }
                }
                cout<<ans<<endl;
        }
}

Measured memory_bytes: 3076
/*

結果:
*/
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
/*
int max(int a, int b) { if (a>b) { return a; }return b; }
int min(int a, int b) { if (a<b) { return a; }return b; }
*/
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }




int main() {
	int A = in();
	int B = in();
	int c;
	int d;
	int flg = 0;

	for (c = 1; c <= 3; c++) {
		d = (A*B*c) % 2;
		if (d == 1) { flg = 1; }
	}
	if (flg) {
		printf("%s\n", "Yes");
	}
	else {
		printf("%s\n", "No");
	}



#ifdef DEBUGF
	getch();
#endif
	return 0;
	}



Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>

typedef long long LL;

const int N=3000005;
const int MOD=998244353;

int n,m,jc[N],ny[N];

int C(int n,int m)
{
	if (n<m) return 0;
	else return (LL)jc[n]*ny[m]%MOD*ny[n-m]%MOD;
}

LL solve(int x,int y)
{
	int ans=0;
	for (int i=0;i*m<=x;i++)
		if (i&1) (ans+=MOD-(LL)C(y,i)*C(x-i*m+y-1,y-1)%MOD)%=MOD;
		else (ans+=(LL)C(y,i)*C(x-i*m+y-1,y-1)%MOD)%=MOD;
	return ans;
}

int main()
{
	scanf("%d%d",&n,&m);
	jc[0]=jc[1]=ny[0]=ny[1]=1;
	for (int i=2;i<=3000000;i++) jc[i]=(LL)jc[i-1]*i%MOD,ny[i]=(LL)(MOD-MOD/i)*ny[MOD%i]%MOD;
	for (int i=2;i<=3000000;i++) ny[i]=(LL)ny[i]*ny[i-1]%MOD;
	int ans=0;
	for (int i=0;i<=std::min(n,m);i++)
	{
		if ((i&1)!=(m&1)) continue;
		(ans+=(LL)solve((m*3-i)/2,n)*C(n,i)%MOD)%=MOD;
		if (m-i>=0) (ans+=(LL)solve((m-i)/2,n-1)*n%MOD*C(n-1,i)%MOD)%=MOD;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 23680
lp = nil

loop do
  
  a, b = gets.split.map(&:to_i)
  
  break if a == 0
  
  puts if lp
  
  lp = []
  
  for i in a..b
     lp << i if i % 400 == 0 || (i % 4 == 0 && i % 100 != 0)
  end
  
  puts lp.empty? ? "NA" : lp
end

Measured memory_bytes: 8884
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <string.h>
#include <vector>
#include <deque>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

typedef int64_t int64;
typedef int64_t ll;

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

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

using namespace std;


class D {
	int n, m;
	vector<vector<ll>> cakes;
	vector<ll> val;
public:
	D()
	{
		cin >> n >> m;

		cakes.resize(n, vector<ll>(3));
		val.resize(n);

		REP(i, n)
			REP(j, 3)
			cin >> cakes[i][j];

	}
	void solve()
	{
		ll ans{ 0 };
		for (int bit{ 0 }; bit < 8; bit++)
		{
			int sign[3];
			sign[0] = (bit & 0b100) ? 1 : -1;
			sign[1] = (bit & 0b010) ? 1 : -1;
			sign[2] = (bit & 0b001) ? 1 : -1;

			REP(i, n)
			{
				val[i] = 0;
				REP(j, 3)
					val[i] += cakes[i][j] * sign[j];
			}

			sort(ALL(val), greater<ll>());
			ll tmpsum{ accumulate(val.begin(), val.begin() + m, 0ll) };
			chmax(ans, tmpsum);

		}

		cout << ans << endl;

	}
};


int main()
{
	D solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG

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

//loops
#define REP(i,n) for(int i=0;i<(ll)(n);i++)
#define REPD(i,n) for(int i=(ll)(n)-1;i>=0;i--)
#define OneToN(i,n) for(int i=1;i<(ll)(n+1);i++)
#define ZeroToN(i,n) for(int i=0;i<(ll)(n+1);i++)
#define AToB(i,a,b) for(int i=a;i<(ll)(b+1);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

//bitsearch
#define BITSEARCH(bit, n) for (int bit = 0; bit < (1<<n); ++bit)
#define isOne(bit, i) bit & (1<<i)


//arrays
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define add push_back


#define remove_unique(v) v.erase(unique(ALL(v)), v.end())

//comparision
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 (a>b) { a=b; return 1; } return 0; }

//pair
#define fir first
#define sec second
#define mp make_pair

//types
#define ll long long
#define vec vector
#define cord2d pair<int,int>
//UNCOMMENT WHEN NEEDED
//#define int ll

//input
template <class T> T get(){ T s; cin >> s; return(s);}
#define gi get<int>()
#define gs get<string>()

template <class T> vector<T> getv(int n) { vec<T> v(n); REP(i, n) cin >> v[i]; return v; }
#define gim(n) getv<int>(n)
#define gsm(n) getv<string>(n)

//output
void print(int a){ cout << a << endl; }
void print(long long a){ cout << a << endl; }
void print(string a){ cout << a << endl; }
void print(char a){ cout << a << endl; }
void print(double a){ cout << a << endl; }
void print(double a, int dig){ cout << std::setprecision(dig) << a << endl; }

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T = int>
void print(vec<T> v){ cout << v << endl; }

template <class T = int>
void print2dVec(vec<vec<T>> v2d){for(vec<T> v: v2d) {print(v);}}

void YesNo1(bool i = true){ return print(i?"Yes":"No"); }
void YESNO2(bool i = true){ return print(i?"YES":"NO"); }

//debug output
#define var_name(var) #var
template <class T> void debug(T &var, int nest = 0, string before = "") { cout << string("          ", nest) << before; print(var); }

//name replacement
#define y0 y0__
#define y1 y1__
#define j0 j0__
#define j1 j1__

//bool lambdas
#define lamb(exp) [](auto i){return exp;}
#define isEven [](int i){return i % 2 == 0;}
#define isOdd [](int i){return i % 2 != 0;}

//constants
const ll INF = 1e18;
const int MOD = 10000007;

//maths
int factorial(int k){ int sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; } return sum; }
int gcd(int a, int b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

////////////////////

void Main() {
    //code here
    int a = gi, b= gi;
    int dif = abs(a-b);
    if (dif%2 == 0) {
        print(max(a,b) - dif/2);
    } else {
        print("IMPOSSIBLE");
    }
}

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


Measured memory_bytes: 256
-- AtCoder My Practice
-- author: Leonardone @ NEETSDKASU
 
-- 解説読後
-- http://arc060.contest.atcoder.jp/data/arc/060/editorial.pdf
-- s > n のときは -1 を入れないと TLEすることも 
 
import qualified Data.List as L
 
main = print . solve . map read . lines =<< getContents
 
f b n = f' n 0 where
    f' x y
        | x < b     = x + y
        | otherwise = let (dv, md) = divMod x b in f' dv (md + y)
 
solve [n, s]
    | n == s    = n + 1
    | s >  n    = -1
    | otherwise = ans where
        en = maximum . takeWhile (\i -> i * i <= n) $ [1 .. ]
        ans = case L.find ((==) s . snd) . map (\i -> (i, f i n)) $ [2 .. en] of
            Just (i, _) -> i
            Nothing -> if en > 0 then ans' else -1 where
                ans' = case L.find ((==) s . snd) . map (\i -> (i, f i n)) $ bs of
                    Just (j, _) -> j
                    Nothing -> -1
                bs = map ((+) 1 . fst) . filter ((==) 0 . snd) . map (divMod (n - s)) $ [ en - k | k <- [0 .. en - 1]]
 

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

int main() {
  static set<int> g1{1, 3, 5, 7, 8, 10, 12}, g2{4, 6, 9, 11};
  int x, y;
  cin >> x >> y;
  if (g1.find(x) != g1.end() && g1.find(y) != g1.end()) cout << "Yes" << endl;
  else if (g2.find(x) != g2.end() && g2.find(y) != g2.end()) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
    int A, B;
    std::cin >> A >> B;
    int ans = 0;

    if (A > B) {
        ans += A + (A - 1);
    } else if ( A == B) {
        ans += A + B;
    } else {
        ans += B + (B - 1);
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

ll f(ll x){
    if (x == 1) return 1;
    return f(floor(ld(x / 2))) * 2 + 1;
}

int main() {
    ll H, ans = 0;
    cin >> H;
    cout << f(H) << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N,K=map(int,input().split())
a = list(map(int, input().split()))
dp = [False]*(K+1)

for i in range(1,K+1):
    for j in range(N):
        if i-a[j]<0: break
        if not(dp[i-a[j]]):
            dp[i]=True
            break
if dp[K]:
    print("First")
else:
    print("Second")

Measured memory_bytes: 43116
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }



int main() {

	ll N;
	cin >> N;
	vll A(N), B(N), C(N), Ar(N), Br(N);
	rep(i, N) cin >> A[i];
	rep(i, N) cin >> B[i];
	rep(i, N) cin >> C[i];
	sort(all(A)), sort(all(B)), sort(all(C));

	vll a(N), b(N);
	rep(i, N) Ar[i] = A[i] * -1;
	rep(i, N) Br[i] = B[i] * -1;
	reverse(all(Ar)), reverse(all(Br));
	rep(i, N) a[i] = Ar.end() - upper_bound(all(Ar), Br[i]);
	rep(i, N) b[i] = C.end() - upper_bound(all(C), B[i]);
	ll ans = 0;
	rep(i, N) ans += a[N - 1 - i] * b[i];
	cout << ans << endl;
	
}

Measured memory_bytes: 5760
n = int(input())
m = list(map(int,input().split()))
h = list(map(int,input().split()))
l = len(m)
s = 0
q=0
if(h[0] > m[0]):
    h[0] = h[0] - m[0]
    s = s+ m[0]
else:
    s = s + h[0]
    h[0]= 0
for i in range(1, n):
    if(i>l-1):
        break
    if(h[i-1]!=0):
        if(h[i-1] < m[i]):
            s = s+ h[i-1]
            m[i] = m[i] - h[i-1]
        else:
            s = s+ m[i]
            m[i] = 0
    if(h[i] > m[i]):
        h[i] = h[i] - m[i]
        s = s+ m[i]
        m[i] = 0
    else:
        s = s + h[i]
        m[i] = m[i] - h[i]
        h[i]= 0
if(l<=n):
    print(s)
else:
    if(m[n] > h[n-1]):
        print(s+ h[n-1])
    else:
        print(s+m[n])

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

namespace
{
const int MAX_N	= 50;

char S[ MAX_N + 5 ];
char T[ MAX_N + 5 ];

int ChkPos( const char *S, const char *T )
{
int i;
int iPos;
int iLenS;
int iLenT;
char C;

	iLenS = strlen( S );
	iLenT = strlen( T );
	iPos = iLenS - iLenT;
	if( iLenS <= 0 || iLenT <= 0 || iPos < 0 ) return - 1;
	if( iPos == 0 ) return iPos;

	for( ; iPos >= 0 ; iPos-- )
	{
		for( i = 0; i < iLenT ; i++ )
		{
			C = S[ iPos + i ];
			if( C != '?' && C != T[ i ] ) break;
		}

		if( i == iLenT ) return iPos;
	}

	return - 1;
}

}

int main( int argc, char *argv[] )
{
int i;
int iPos;
char C;
	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> S;
	cin >> T;

	iPos = ChkPos( S, T );
	if( iPos < 0 )
	{
		cout << "UNRESTORABLE" << endl;

		return 0;
	}

	i = 0;
	C = S[ i ];
	while( C != '\0' )
	{
		if( C == '?' ) S[ i ] = 'a';

		i++;
		C = S[ i ];
	}


	i = 0;
	C = T[ i ];
	while( C != '\0' )
	{
		S[ iPos + i ] = C;

		i++;
		C = T[ i ];
	}

	cout << S << endl;

	return 0;
}




Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] d = new int[n];
        for(int i=0; i<n; i++){
            d[i] = sc.nextInt();
        }
        sc.close();
        
        boolean[] b = new boolean[200];
        Arrays.fill(b, false);
        
        int ans = 0;
        for(int i=0; i<n; i++){
            if(!b[d[i]]){
                b[d[i]] = true;
                ans++;
            }
        }

        System.out.print(ans);
	}
}

Measured memory_bytes: 23380
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;

int main() {
  string S;

  cin >> S;

  if(S == "SUN") printf("%d\n",7);
  else if(S == "MON") printf("%d\n", 6);
  else if(S == "TUE") printf("%d\n", 5);
  else if(S == "WED") printf("%d\n", 4);
  else if(S == "THU") printf("%d\n", 3);
  else if(S == "FRI") printf("%d\n", 2);
  else if(S == "SAT") printf("%d\n", 1);

  return 0;
}


Measured memory_bytes: 256
n = int(input())
seq = [[],[]]
seq[0] = input()
seq[1] = input()
i = 0

ans = 3
cnt_vert = 0
cnt_hor = 0
m = 1000000007
# print(seq)
while i < len(seq[0]):
    if seq[0][i] == seq[1][i]: # vert
        if cnt_vert == 0:
            mult = 1
        elif cnt_vert > 0:
            mult = 2
        else:
            raise ValueError("wtf?")
        cnt_vert += 1
        cnt_hor = 0

    else:
        if cnt_hor == 0:
            mult = 2
        elif cnt_hor > 0:
            mult = 3
        else:
            # print(i, cnt_hor, cnt_vert)
            raise ValueError("wtf hor")
        cnt_vert = 0
        cnt_hor += 1
        i += 1
    
    i += 1
    ans *= mult
    if ans > m:
        ans = ans % m
print(ans)

Measured memory_bytes: 38384
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


A, B, K = read_ints()
ans1 = max(A - K, 0)
left_p = max(K - A, 0)
ans2 = max(B - left_p, 0)
print(ans1, ans2)


Measured memory_bytes: 3064
#include <cmath>
#include <vector>
#include <iostream>
#include <limits>
#include <iostream>
#include <vector>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <set>
#include <queue>
#include <algorithm>


using namespace std;
typedef long long Long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;

Long getSum(string s, int mas){
	Long r = 0, n = 0;
	for(int i = 0; i < s.size(); ++i){
		n = 10*n + s[i]-'0';
		if((1<<i) & mas){
			r += n;
			n = 0;
		}
	}
	return r + n;
}

int main()
{
	string S;
	cin >> S;
	Long s = 0;
	for(int i = 0; i < (1<<(S.size()-1)); ++i){
		s += getSum(S,i);
	}
	cout << s << endl;
	
}

/*

3 1 2 1
4 7 52 9
7 1 2 1
3 9 52 4
1 2 3 4
5 10 7 8
1 2 3 4
5 8 7 10
34 5 6 998
4 17 77 84
34 5 6 998
4 17 77 8481


 */



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

#define sc(x) scanf("%d",&x);
#define rep(x ,n) for(int x=0; x<n; x++)
#define ll long long
#define finish(x) return cout << x << endl,0;
#define scarr(a,n) for(int x=0; x<n; x++)scanf("%d",&a[x]);

int main()
{
    int n , a ,b;
    cin >> n >> a >> b;
    cout << min(n*a ,b) << endl;
}


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

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if((A == B && B != C) || (A == C && C != B) || (B == C && C != A)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

bool isPrime (long long int x) {
    for (long long int i = 2; i * i <= x; i++) {
        if (x % i == 0)
            return false;
    }
    return true;
}

int get_t(int t) {
    int k = 0;
    for (int i = 1; ; i++) {
        k += i;
        if (k > t)
            return i - 1;
    }
}

int main() {
    long long int n = 0, tmp;
    scanf("%lld", &n);

    tmp = n;

    if (n == 1) {
        printf("0\n");
        return 0;
    }

    if (isPrime(n)) {
        printf("1\n");
        return 0;
    }

    int ans = 0;

    for (long long int i = 2; i * i <= tmp; i++) {
        if (isPrime(i)) {
            int t = 0;
            while (n % i == 0) {
                t++;
                n /= i;
            }
            ans += get_t(t);
        }
    }

    if (isPrime(n) && n != 1) {
        ans++;
    }

    printf("%d\n", ans);
}

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

using namespace std;

int w[100002], v[100002];
long long dp[102][100002];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n, K;
    cin >> n >> K;

    for(int i = 0; i < n; i++) {
        cin >> w[i] >> v[i];
    }

    for(int pos = 0; pos < n; pos++) {
        for(int W = 0; W <= K; W++) {
            if(pos == 0) {
                if(W >= w[pos]) dp[pos][W] = 1LL * v[pos];
                else dp[pos][W] = 0;
            }
            else {
                dp[pos][W] = max(dp[pos - 1][W],  (W >= w[pos] ? 1LL * v[pos] + dp[pos - 1][W - w[pos]] : 0));
            }
        }
    }

    cout << dp[n - 1][K] << endl;

}

/**
 * Knapsack 1
 */

Measured memory_bytes: 80256
import java.util.Scanner;

	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			int[] a = new int[n-1];
			int[] ret = new int[n];
			
			for(int i=0;i<n-1;i++) {
				a[i] = sc.nextInt();
			}
			
			
			for(int i=0;i<n-1;i++) {
				ret[a[i]-1]++;
			}
			
			for(int i=0;i<n;i++) {
				System.out.println(ret[i]);
			}
		}
	}


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

ll powll(ll a,ll n){
  if(n==0)
  {
    return 1;
  }
  return powll(a,n-1)*a;
}


int main() {
   ll i,j,k;
   string s;
   cin >>s; 
   
   for(i=2; i<5; i+=2)
   {
     if(s[i]!=s[i+1])
     {
       cout<<  "No"<<endl;
       return 0;
     }
   }
   
   cout<< "Yes" <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define DEBUG 0

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

ll N, K;
#define MAX_N (2000)
#define MAX_A (2000)
ll A[MAX_N+5];
ll cnt[MAX_A+5];
const ll MOD = 1ll*(1000*1000*1000)+7;

ll sum(ll s, ll t) {
	ll ret=0;
	for(ll i=s; i<=t; i++) {
		ret+=cnt[i];
		DOUT<<"sum("<<s<<","<<t<<"):cnt["<<s<<"]="<<cnt[s]<<",ret="<<ret<<endl;
	}
	return ret%MOD;
}

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


	ll p=0;

	cin >> N >> K;
	FOR(n,N) {
		cin >> A[n];
		p+=sum(A[n]+1,2000);
		p%=MOD;
		cnt[A[n]]++;
	}

	for(ll i=1l; i<=2000; i++) {
		DOUT<<"cnt["<<i<<"]="<<cnt[i]<<endl;
	}

	ll q1=0;
	ll q2=0;
	FOR(n,N) {
		DOUT << "=== "<<n<<" ==="<<endl;
		DOUT << "sum("<<A[n]+1<<","<<2000<<")="<<sum(A[n]+1,2000)<<endl;
		DOUT << "sum("<<1<<","<<A[n]-1<<")="<<sum(1,A[n]-1)<<endl;
		q1+=sum(A[n]+1,2000);
		q2+=sum(1,A[n]-1);
	}

	DOUT << "p="<<p<<endl;
	DOUT << "q1="<<q1<<endl;
	DOUT << "q2="<<q2<<endl;

	p = p*K%MOD;
	q1=q1*(K*(K-1)/2%MOD);
	q2=q2*(K*(K-1)/2%MOD);
	DOUT << "p="<<p<<endl;
	DOUT << "q1="<<q1<<endl;
	DOUT << "q2="<<q2<<endl;
	cout << (p+q1)%MOD << endl;

	return 0;
}




Measured memory_bytes: 256
N,K=map(int,input().split())
L=[]
for i in range(N):
	x=int(input())
	L.append(x)
L=sorted(L)
ans=float("inf")
for i in range(N-K+1):
	ans=min(ans,(L[i+K-1]-L[i]))
print(ans)

Measured memory_bytes: 8280
#include <stdio.h>

int main(){
    int A, B, C, D, E, a, b, c, d, e, last;
    scanf("%d", &A);
    scanf("%d", &B);
    scanf("%d", &C);
    scanf("%d", &D);
    scanf("%d", &E);

    a = A%10;
    last = a == 0? 0 : 10-a;
    b = B%10;
    if(10-b > last && b != 0){
        last = 10-b;
    }
    c = C%10;
    if(10-c > last && c != 0){
        last = 10-c;
    }
    d = D%10;
    if(10-d > last && d != 0){
        last = 10-d;
    }
    e = E%10;
    if(10-e > last && e != 0){
        last = 10-e;
    }
    A = a==0? A : A+10-a;
    B = b==0? B : B+10-b;
    C = c==0? C : C+10-c;
    D = d==0? D : D+10-d;
    E = e==0? E : E+10-e;

    printf("%d", A+B+C+D+E-last);
    
    return 0;
}

Measured memory_bytes: 128