akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll h,w;
  cin >> h >> w;
  vector<string> a(h);
  for(ll i=0;i<h;i++)  cin >> a[i];
  ll count=0;
  for(ll i=0;i<h;i++) for(ll j=0;j<w;j++) if(a[i][j]=='#') count++;
  if(count==h+w-1) {
    cout << "Possible" << endl;
  }
  else {
    cout << "Impossible" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstdio>

using namespace std;

char f[12][6];
bool checked[12][6];
int dx[4] = {0,-1,0,1};
int dy[4] = {1,0,-1,0};

int checkfrom(int i, int j){
    pair<int,int> tmp;
    deque<pair<int,int> > q;
    vector<pair<int,int> > modi;
    int cnt = 0,nx,ny;
    char color = f[i][j];

    q.push_back(make_pair(i,j));
    checked[i][j] = true;
    while(!q.empty()){
        tmp = q.front();
        q.pop_front();
        modi.push_back(tmp);
        cnt++;
        for(int i=0;i<4;i++){
            nx = tmp.first + dx[i];
            ny = tmp.second + dy[i];
            if(0 <= nx && nx < 12 &&
               0 <= ny && ny < 6 &&
               !checked[nx][ny] &&
               f[nx][ny] == color){
                q.push_back(make_pair(nx,ny));
                checked[nx][ny] = true;
            }
        }
    }
    if(cnt >= 4){
        for(int i=0;i<modi.size();i++){
            f[modi[i].first][modi[i].second] = '.';
            for(int j=0;j<4;j++){
                if(f[modi[i].first + dx[j]][modi[i].second + dy[j]] == 'O'){
                    f[modi[i].first + dx[j]][modi[i].second + dy[j]] = '.';
                }
            }
        }
    }
    return cnt;
}

int main(){
    int n;
    scanf("%d", &n);



    for(int x=0;x<n;x++){
        memset(f, 0, sizeof(f));

        for(int i=0;i<12;i++){
            for(int j=0;j<6;j++){
                scanf(" %c", &f[i][j]);
            }
        }
        int max_deleted = 0;
        int res = 0,tx,ty;
        bool shouldsearch;
        while(1){
            max_deleted = 0;
            memset(checked, false, sizeof(checked));
            for(int i=11;i>=0;i--){
                for(int j=0;j<6;j++){
                    shouldsearch = false;
                    for(int k=0;k<4;k++){
                        tx = i+dx[k];
                        ty = j+dy[k];
                        if(0 <= tx && tx < 12 &&
                           0 <= ty && ty < 6 && f[i][j] == f[tx][ty]){
                            shouldsearch = true;
                        }
                    }
                    if(f[i][j] != '.' && f[i][j] != 'O' && !checked[i][j] && shouldsearch){
                        max_deleted = max(checkfrom(i, j), max_deleted);
                    }
                }
            }
            for(int i=0;i<6;i++){
                int base = 11;
                for(int j=11;j>=0;j--){
                    if(f[j][i] != '.'){
                        f[base][i] = f[j][i];
                        base--;
                    }
                }
                while(base >= 0){
                    f[base][i] = '.';
                    base--;
                }
            }
            
            if(max_deleted < 4) break;
            res++;
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
using namespace std;
int main(void) {
    
   int x,y,z;
   cin>>x>>y>>z;

   int sum;
   if(x%(y+z)>=z)cout<<x/(y+z)<<endl;
   else cout<<x/(y+z)-1<<endl;

    return 0;
}

Measured memory_bytes: 256
N=int(input())
xyh=[]
for i in range(N):
    xyh.append(tuple(map(int,input().split())))
xyh.sort(key=lambda a:a[2],reverse=True)

fa=False
for CX in range(101):
    if fa:
        break
    for CY in range(101):
        f=lambda xi,yi,hi:hi+abs(xi-CX)+abs(yi-CY)
        H=f(xyh[0][0],xyh[0][1],xyh[0][2])
        fc=True
        for i in range(1,N):
            xi,yi,hi=xyh[i]
            if (hi>0 and H!=f(xi,yi,hi)) or (hi==0 and H>abs(xi-CX)+abs(yi-CY)):
                fc=False
                break
        if fc:
            print(CX,CY,H)
            fa=True
            break

Measured memory_bytes: 42224
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder bd = new StringBuilder();

        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i=0; i<N; i++) {
            A[i] = sc.nextInt();
        }

        int counter = selectionSort(A, N);
        for (int i=0; i<N-1; i++) {
            System.out.print(A[i] + " ");
        }
        System.out.println(A[N-1]);
        System.out.println(counter);
    }

    public static int selectionSort(int[] A, int N) {
        int minj = 0;
        int count = 0;
        for (int i=0; i<N; i++) {
            minj = i;
            for (int j=i; j<N; j++) {
                if (A[j] < A[minj])
                    minj = j;
            }
            if (i != minj) {
                int t = A[i];
                A[i] = A[minj];
                A[minj] = t;
                count++;
            }
        }
        return count;
    }


    public static int bubbleSort(int[] A, int N) {
        int flag = 1;
        int count = 0;
        while (flag == 1) {
            flag = 0;
            for (int i=N-1; i>=1; i--) {
                if (A[i] < A[i-1]) {
                    int t = A[i];
                    A[i] = A[i-1];
                    A[i-1] = t;
                    flag = 1;
                    count++;
                }
            }
        }
        return count;
    }
}


Measured memory_bytes: 26416
#include <iostream>
#include <stdio.h>
 using namespace std;
int main(){
  int x;
  cin >> x;
  if(x%10==7)cout << "Yes";
  else if(((int)(x/10))%10==7) cout << "Yes";
  else if(((int)(x/100))%10==7) cout << "Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 3596
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	string s; cin >> s; int m = (int)s.size();
    vector<int> a(m + 1, -1);
    int n = m + 1;
    if(s[0] == '<') {
        a[0] = 0;
    }
    if(s[m - 1] == '>') {
        a[n - 1] = 0;
    }
    rep(i, m - 1) {
        if(s[i] == '>' && s[i + 1] == '<') {
            a[i + 1] = 0;
        }
    }
    for(int i = 1; i < n; ++ i) {
        if(s[i - 1] == '<') {
            if(a[i] != 0) chmax(a[i], a[i - 1] + 1);
        }
    }
    for(int i = n - 2; i >= 0; -- i) {
        if(s[i] == '>') {
            if(a[i] != 0) chmax(a[i], a[i + 1] + 1);
        }
    }
    int ans = 0;
    rep(i, n) {
        ans += a[i];
        cerr << a[i] << endl;
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 4764
// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()
#include<bits/stdc++.h>

#define pb push_back
#define mp make_pair

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

#define fi first
#define se second

using namespace std;

typedef long long ll;   

const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e6 + 5;

int fact[MAXN];

int rev[MAXN];

int cnt[MAXN];

int n, ans;

int binPow(int a, int b, int m = MOD) {
    int ret = 1;

    while (b > 0) {
        if (b & 1) {
            ret = (ret * 1ll * a) % m;
        }

        a = (a * 1ll * a) % m;
        b >>= 1;
    }

    return ret;
}

void pre() {
    fact[0] = 1;
    rev[0] = 1;

    for (int i = 1; i < MAXN; ++i) {
        fact[i] = (fact[i - 1] * 1ll * i) % MOD;
        rev[i] = binPow(fact[i], MOD - 2, MOD);     
    }
}

void addMod(int &a, int b, int m = MOD) {
    a += b;

    if (m <= a) {
        a -= m;
    }
}

int C(int n, int k) {
    if (k > n) {
        return 0;
    }

    return fact[n] * 1ll * rev[k] % MOD * rev[n - k] % MOD;
}

void solve() {
    scanf("%d", &n);

    for (int k = 1; k < n; ++k) {
        cnt[k] = C(k - 1, n - k - 1) * 1ll * fact[k] % MOD * fact[n - k - 1] % MOD;
        addMod(ans, (cnt[k] - cnt[k - 1] + MOD + 0ll) * k % MOD);        
    }

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

int main() {
    int tt = 1;

    pre();

    while (tt--) {
        solve();
    }

    return 0;
}

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

#define debug(a) cout << #a << " " << a << endl;
#define _debug(a, i) cout << #a << "[" << i << "]" \
						  << " = " << a[i] << endl;
#define fastio                        \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);
#define PI 3.141592654
#define all(v) v.begin(), v.end()

using namespace std;

using ll = long long;
const int MOD = 1e9 + 7;
const ll INF = 1e18 + 9;
using pi = pair<int, int>;

ll powmod(ll base, ll exp, const ll MOD) { ll ans = 1; while (exp) { if (exp & 1)	ans = (ans * base) % MOD; base = (base * base) % MOD; exp >>= 1; }return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p); }

//ll f[500005];
//ll kCn(ll k, ll n) { return (f[n] * modInverse((f[n - k] * f[k]) % MOD, MOD)) % MOD; }


const int mxN = 1e6;


void test_case() {
	
}

int main() {
	fastio;

	int n;
	cin >> n;
	vector<int> ans(10001);
	for (int i = 1; i <= 100; ++i) {
		for (int j = 1; j <= 100; ++j) {
			for (int k = 1; k <= 100; ++k) {
				int x = i * i + j * j + k * k + i * j + j * k + k * i;
				if (x <= 1e4)
					++ans[x];
			}
		}
	}
	for (int i = 1; i <= n; ++i)
		cout << ans[i] << "\n";
	return 0;
}


Measured memory_bytes: 3620
N,M=map(int,input().split())
A=[int(input()) for i in range(M)]
dp=[1]*(N+1)
for i in A:
  dp[i]=0

for i in range(2,N+1):
  if dp[i]==1:
    dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)

print(dp[N])

Measured memory_bytes: 7848
#Educational DP Contest
#I-Coins

n = int(input())
lst1 = list(map(float,input().split()))

#dp table
dp = [[0.0]*(n+1) for _ in range(n+1)] #確率を0で初期化(2次元)
dp[0][0] = 1.0 #0番目は存在しないので1で初期化(単位元のような感じ。乗算だから単位元は1)


#process1
#dp[i][j]は、i回までのコインを投げて、j枚が表の確率。
#つまり、ループの内側が表の確率、外側がコインの枚数となる
#但し、i回までのコインでi枚以上の表は出ないので、jのループはi迄とする。
"""
図にするとこんなかんじ(1列目は実際に起きる数字ではない)
[[1.0, 0.0, 0.0, 0.0],
[0.7, 0.3, 0.0, 0.0], #0.7で裏,0.3で表
[0.28, 0.54, 0.18, 0.0],
[0.056, 0.33, 0.468, 0.144]] #0.056+0.33で裏、0.468+0.144で表
"""
for i in range(1,n+1):
    for j in range(i+1):
        dp[i][j] = dp[i-1][j]*(1-lst1[i-1])
        if j > 0:
            dp[i][j] += dp[i-1][j-1]*lst1[i-1]

#output process
#問題はdp[i][j] >= 0.5となる確率なので、j>= 0.5 = 表の枚数/全体の枚数
#となるj以上の確率の合計が答え(ちなみに、任意のdp[i]の合計sum(dp[i]) == 1となる)
ans = 0.0
for i in range((n+1)//2,n+1): #j(表が出る枚数)が半分以上のところから全部のところまでの確率の合計
    ans += dp[-1][i]
print(ans)

Measured memory_bytes: 112860
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a+b==15&&a*b==15){
		cout<<"x"<<endl;
		return 0;
	} 
	if(a+b==15){
		cout<<"+"<<endl;
		return 0;
	}
	if(a*b==15){
		cout<<"*"<<endl;
		return 0;
	}
	cout<<"x"<<endl;
	return 0;
}


Measured memory_bytes: 256
import numpy as np
N = int(input())
A = list(map(int,input().split()))
cnt = [0] * (10**6 + 1)
for i in range(N):
    cnt[A[i]] += 1

maxcount = 0
for i in range(2,10**6+1):
    maxcount = max(maxcount,sum(cnt[i::i]))

if np.gcd.reduce(A) != 1:
    print('not coprime')
elif maxcount <= 1:
    print('pairwise coprime')
else:
    print('setwise coprime')

Measured memory_bytes: 150428
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int k = Integer.parseInt(in.readLine());
    StringTokenizer st = new StringTokenizer(in.readLine());
    int a = Integer.parseInt(st.nextToken());
    int b = Integer.parseInt(st.nextToken());
    int largest = (b/k) * k;
    System.out.println(a<=largest?"OK":"NG");
  }
}

Measured memory_bytes: 32392
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	int n;
	int min;
	int max;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&t);
		if(i==0)
		{
			min=t;
			max=t;
		}
		if(min>t)
		{
			min=t;
		}
		if(max<t)
		{
			max=t;
		}
	}
	printf("%d",max-min);
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict

def check(i): #メモ化再帰でやります
    if d[i] > 0:
        return d[i]
    d[i] = 1 #チェック状態
    """長方形と仮定し、矛盾があればSUSPICUOUS"""
    for y in range(p[i][0],p[i][1]+1):
        for x in range(p[i][2],p[i][3]+1):
            if s[y][x] == ".": #長方形内部に空の部分が存在
                d[i] = 3 #SUSPICUOUS
                return d[i]
            elif s[y][x] != i: #長方形内部に他の物質が存在
                if d[s[y][x]] == 1: #その物質が現在チェック状態
                    d[i] = 3 #SUSPICUOUS(循環参照であるため。例:テストケース4)
                    return d[i]
                c = check(s[y][x]) #再帰でそいつの状態をみる
                if c == 3: #SUSPICUOUS
                    d[i] = 3 #SUSPICUOUS
                    return d[i]
    d[i] = 2 #SAFE
    return 2

n = int(sys.stdin.readline())
for _ in range(n):
    h,w = map(int, sys.stdin.readline().split())
    s = [sys.stdin.readline() for i in range(h)]
    p = defaultdict(list)
    """p[0]:上端,p[1]:下端,p[2]:左端,p[3]:右端"""
    for y in range(h):
        for x in range(w):
            if s[y][x] != "." and len(p[s[y][x]]) < 1:
                p[s[y][x]].append(y)
    for y in range(h)[::-1]:
        for x in range(w):
            if s[y][x] != "." and len(p[s[y][x]]) < 2:
                p[s[y][x]].append(y)
    for x in range(w):
        for y in range(h):
            if s[y][x] != "." and len(p[s[y][x]]) < 3:
                p[s[y][x]].append(x)
    for x in range(w)[::-1]:
        for y in range(h):
            if s[y][x] != "." and len(p[s[y][x]]) < 4:
                p[s[y][x]].append(x)

    d = defaultdict(lambda : 0) #メモ化再帰用のdict
    for i in p.keys():
        if check(i) == 3:
            print("SUSPICIOUS")
            break
    else:
        print("SAFE")



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

using namespace std;

bool ok(const vector<vector<int>> &w) {
    int n = w.size();
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if (w[i][j] == w[j][k] && w[j][k] == w[k][i]) return false;
            }
        }
    }
    return true;
}

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

    int n;
    cin >> n;
    int N = 1, log = 0;
    while (n > N) N <<= 1, log++;
    vector<vector<int>> w(N, vector<int>(N));
    for (int i = 0; i < log; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = 0; k < N; k++) {
                if ((j >> i & 1) != (k >> i & 1)) {
                    w[j][k] = i + 1;
                }
            }
        }
    }
//    assert(ok(w));
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            cout << w[i][j] << ' ';
        }
        cout << endl;
    }
}

Measured memory_bytes: 1536
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;

#define ARRAY_MAX 200005
#define MOD 1000000007


int main(){

    int n;
    cin >> n;
    vector<P> a(n);
    vector<int> b(n),ans(n);
    REP(i,n){
        cin >> a[i].first;
        //b[i] = a[i].first;
        a[i].second = i;
    }
    VSORT(a);
    /*REP(i,n){
        cout << a[i].first << " " << a[i].second << endl;
    }*/

    REP(i,n){

        if(i < n/2){
            //cout << "a" << endl;
            ans[a[i].second] = a[n/2].first;
        }else{
            //cout << "b" << endl;
            ans[a[i].second] = a[n/2-1].first;
        }
    }
    REP(i,n){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 5376
#include<stdio.h>
#define MAX 100005
#define NIL -1

void print(int);
int rec(int,int);

struct Node{
  int p,l,r;
};


int n,B[MAX];
struct Node A[MAX];


int main(){
  int i,j,a,b,c,d,e;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    A[i].p = NIL;
    A[i].l = NIL;
    A[i].r = NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&b,&a);
    for(j=0;j<a;j++){
      scanf("%d",&c);
      if(j==0){
	A[b].l = c;
      }
      else A[d].r = c;
      d = c;
      A[c].p = b;
    }
  }
  for(i=0;i<n;i++){
    if(A[i].p == NIL){
      e = i;
    }
  }
  rec(e,0);
  for(i=0;i<n;i++){
    print(i);

  }
  return 0;
}

void print(int s){
  int i,c;
  printf("node %d: ",s);
  printf("parent = %d, ",A[s].p);
  printf("depth = %d, ",B[s]);
  if(A[s].p == NIL){
    printf("root, ");
  }
  else if(A[s].l == NIL){
    printf("leaf, ");
  }
  else printf("internal node, ");

  printf("[");

  for(i = 0,c = A[s].l;c != NIL;i++,c = A[c].r){
    if(i>0){
      printf(", ");
    }
    printf("%d",c);
  }
  printf("]\n");
}

int rec(int t,int q){
  B[t] = q;
  if(A[t].r != NIL)rec(A[t].r,q);
  if(A[t].l != NIL)rec(A[t].l,q+1);
}



Measured memory_bytes: 7372
d, n = map(int, input().split())

cnt = 0
if d == 1:
    for i in range(1, 100**3 + 1):
        if i % 100 ** 1 == 0 and i % 100 ** 2 != 0:
            cnt += 1
        if cnt == n:
            print(i)
            exit()
elif d == 2:
    for i in range(1, 100 ** 4):
        if i % 100 ** 2 == 0 and i % 100 ** 3 != 0:
            cnt += 1
        if cnt == n:
            print(i)
            exit()
else:
    for i in range(1, 100**3+1):
        if i % 100 != 0:
            cnt += 1
        if cnt == n:
            print(i)
            exit()

Measured memory_bytes: 40172
#define ll long long
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#include<bits/stdc++.h>
using namespace std;
int qq,n;
vector <int> v;
map <int,int> m;
string s;
int main()
{
	scanf("%d", &qq);
	qq%=10;
	if(qq==3) printf("bon\n");
	else if(qq==0 || qq==1 || qq==6 || qq==8) printf("pon\n");
	else printf("hon\n");
	return 0;
}


Measured memory_bytes: 3680
n,k=map(int,input().split())
mod=10**9+7
def cmb(n,r,mod):
  return A[n]*B[n-r]*B[r]%mod
A=[1,1]
B=[1,1]
for i in range(n):
  A.append(A[-1]*(i+2)%mod)
  B.append(B[-1]*pow((i+2),mod-2,mod)%mod)
if k<n:
  ans=0
  for i in range(k+1):
    ans=(ans+cmb(n,i,mod)*cmb((n-1),i,mod))%mod
  print(ans)
else:
  ans=0
  for i in range(n):
    ans=(ans+cmb(n,i,mod)*cmb((n-1),i,mod))%mod
  print(ans)

Measured memory_bytes: 66928
def peaks(lookup, hs, n):
    ans = 0
    for k in lookup.keys():
        for kk in lookup[k]:
            if hs[k-1] <= hs[kk-1]:
                ans -= 1
                break
        ans += 1
    print(ans + n - len(lookup.keys()))

if __name__ == "__main__":
    import sys
    from collections import defaultdict as DD
    lookup = DD(dict)
    n, m = [int(_) for _ in input().split()]
    hs = [int(_) for _ in input().split()]
    for i in range(m):
        a, b = [int(_) for _ in input().split()]
        lookup[a][b] = lookup[b][a] = True
    peaks(lookup, hs, n)


Measured memory_bytes: 43856
n = int(input())
a = list(map(int, input().split()))

b = [0] * (max(a) + 1)
# b[i] = (aの要素がiであるような数)
for i in range(n):
    b[a[i]] += 1

ans = 0
for i in range(1, len(b)):
    if b[i] > 0:
        if b[i] == 1:
            ans += 1
        # print(i, ans)
        for j in range(len(b)):
            if i * j >= len(b):
                break
            b[i * j] = 0

print(ans)


Measured memory_bytes: 103228
#include<bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a; i<=b; ++i)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
using vl=vector<ll>;
using vp=vector<pll>;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll k;
    cin>>k;
    ll tmp=0;
    FOR(i,1,9*k){
        tmp=(tmp*10+7)%k;
        if(tmp%k==0){
            cout<<i;
            return 0;
        }
    }
    cout<<-1;
    return 0;
}

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

int main()
{
	int t[5], i, sum = 0;
	for (i = 0;i < 5;i++) {
		scanf("%d", &t[i]);
		if (t[i] < 40)t[i]=40;
		sum += t[i];
	}
	printf("%d\n", sum / 5);
	return 0;
}

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

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

void empty(int *,int *);
int dfs(int,int,int,int,const int);
int catch();
void swap(int *,int *);


int main() {
    int i,j,ans,x,y,V;
    
    for(i=0; i<3; i++) {
        for(j=0; j<3; j++) scanf("%d",&puz[i][j]);
    }
    
    
    empty(&x,&y);
    for(V=0; V<100; V++) {
       
        for(i=0; i<3; i++) {
            for(j=0; j<3; j++) tmp[i][j] = puz[i][j];
        }
        
        ans = dfs(x,y,-1,0,V);
        if(ans!=-1) {
            printf("%d\n",ans);
            break;
        }
        
        for(i=0; i<3; i++) {
            for(j=0; j<3; j++) puz[i][j] = tmp[i][j];
        }
        
         ans = -1;
        if(V==99) printf("%d\n",ans);
    }
    return 0;
}

void empty(int *x,int *y) {
    int i,j;
    for(i=0; i<3; i++) {
        for(j=0; j<3; j++) {
            if(!puz[i][j]) {
                *x = j;
                *y = i;
                return;
            }
        }
    }
}


void swap(int *a,int *b) {
    int tmp;
    
    tmp = *a;
    *a = *b;
    *b = tmp;
}


int catch() {
    int i,a,sum=0;
    
    for(i=0; i<9; i++) {
        a = puz[i/3][i%3];
        if(a) {
            a--;
            sum += abs(i/3 - a/3) + abs(i%3 - a%3);
        }
    }
    
    return sum;
}


int dfs(int x,int y,int p,int dep,const int lim) {
    int i,h,nx,ny,res;
    
    h = catch();
    if(h==0) return dep;
    if(dep+h>lim) return -1;
    
    for(i=0; i<4; i++) {
        nx = x+dx[i];
        ny = y+dy[i];
        
        if(~p && i==(p+2)%4) continue;
        if(!(0<=nx && nx<3 && 0<=ny && ny<3)) continue;
        
        swap(&puz[y][x],&puz[ny][nx]);
        res = dfs(nx,ny,i,dep+1,lim);
        if(~res) return res;
        
        swap(&puz[y][x],&puz[ny][nx]);
    }
    
    return -1;
}



Measured memory_bytes: 2036
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int place1 = (sc.nextInt() % 100) % 10;
        switch (place1) {
            case 2:
                System.out.println("hon");
                break;
            case 4:
                System.out.println("hon");
                break;
            case 5:
                System.out.println("hon");
                break;
            case 7:
                System.out.println("hon");
                break;
            case 9:
                System.out.println("hon");
                break;
            case 0:
                System.out.println("pon");
                break;
            case 1:
                System.out.println("pon");
                break;
            case 6:
                System.out.println("pon");
                break;
            case 8:
                System.out.println("pon");
                break;
            case 3:
                System.out.println("bon");
                break;
        }
    }
}


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

template <typename T>
struct node {
	T val;
	vector<node<T>*> chi;
	node() : chi() {}
	node(int v) : val(v), chi() {}
	void Init(int v) {
		val = v;
	}
	void erase() {
		for (auto p : chi) {
			p->erase();
			delete p;
		}
	}
};

template <typename T>
node<T>* merge(node<T>* a, node<T>* b) {
	if (a == nullptr) return b;
	if (b == nullptr) return a;
	if (a->val <= b->val) swap(a, b);
	a->chi.push_back(b);
	return a;
}

template <typename T>
node<T>* sub_merge(const vector<node<T>*>& p) {
	int n = p.size();
	vector<node<T>*> tmp;
	for (int i = 0; i < n; i += 2) {
		if (i + 1 < n) {
			tmp.push_back(merge(p[i], p[i + 1]));
		}
		else {
			tmp.push_back(p[i]);
		}
	}
	reverse(tmp.begin(), tmp.end());
	n = tmp.size();
	node<T> *res = tmp[0];
	for (int i = 1; i < n; i++) {
		res = merge(res, tmp[i]);
	}
	return res;
}

node<int> *new_node(int val) {
	return new node<int>(val);
}

class Priority_Queue {
	node<int> *root;
public:
	Priority_Queue() : root(nullptr) {}
	Priority_Queue(int val) : root(new_node(val)) {}
	void push(int val) {
		meld(new_node(val));
	}
	int top() {
		return root->val;
	}
	void meld(node<int>* p) {
		root = merge(root, p);
	}
	void pop() {
		if (root->chi.empty()) {
			delete root;
			root = nullptr;
			return;
		}
		auto t = root;
		root = sub_merge(root->chi);
		delete t;
	}
	~Priority_Queue() {
		if (root != nullptr) {
			root->erase();
			delete root;
		}
	}
};

int main()
{
	cin.sync_with_stdio(false);
	int val;
	string S;
	Priority_Queue pq;

	while (cin >> S, S != "end") {
		if (S == "extract") {
			printf("%d\n", pq.top());
			pq.pop();
		}
		else {
			cin >> val;
			pq.push(val);
		}
	}
	return 0;
}

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

namespace ABC120_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();

            var ans1 = S.Where(x => x == '0').Count();
            var ans2 = S.Where(x => x == '1').Count();

            Console.WriteLine(Math.Min(ans1, ans2) * 2);
        }
    }
}


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

int main(){
  int N,K;
  cin>>N>>K;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  int l=-5;
  for(int i=0;i<N;i++){
    if(v[i]>0){l=i;break;}
  }
  int ans=1000000000;
  for(int i=1;i<=min(N+1-l,K);i++){
    if(l-K+i>=0&&l-K+i<N&&l+i-1>=0&&l+i-1<N)ans=min(ans,(-1)*v[l-K+i]+2*v[l+i-1]);

  }

  for(int i=1;i<=min(N+1-l,K-1);i++){
    if(l-K+i>=0&&l-K+i<N&&l+i-1>=0&&l+i-1<N)ans=min(ans,(-2)*v[l-K+i]+v[l+i-1]);

  }
  
  if(l-K>=0)ans=min(ans,v[l-K]*(-1));
  if(l+K-1<=N-1)ans=min(ans,v[l+K-1]);
  if(l==0)ans=v[K-1];
  if(l==-5)ans=v[N-K]*(-1);
  cout<<ans<<endl;
}


Measured memory_bytes: 768
from sys import stdin
import heapq

[N,M] = [int(x) for x in  stdin.readline().rstrip().split()]
#heapqは最小値ヒープなので、ここで符号を逆転させる
def reverse(a):
    return -1*int(a)
As = [reverse(x) for x in  stdin.readline().rstrip().split()]


#単純に考えて、一番高いものに割引券を使うことを繰り返せばよい
#つまり、ヒープを使えば効率が良い
#M回割引券を使うわけなんだけれど、一回の操作での計算量はO(logN)なので、
#合計の計算量はO(MlogN)である。

heapq.heapify(As)

for i in range(M):
    temp = heapq.heappop(As)
    heapq.heappush(As,temp/2)

#値を切り捨て
As = [int(x)*-1 for x in As]
print(sum(As))


Measured memory_bytes: 94720
n=int(input())
num=list(map(int,input().split()))

cnt_m,cnt_z=0,0
for i in range(n):
  if num[i]<0:
    cnt_m+=1
  elif num[i]==0:
    cnt_z+=1

num1=[abs(i) for i in num]  

if cnt_m%2==0:
  ans=sum(num1)
else:
  if cnt_z>0:
    ans=sum(num1)
  else:
    ans=sum(num1)-2*min(num1)
    #print(7,sum(num1),min(num1))
print(ans)

Measured memory_bytes: 14212
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using data=pair<int,int>;
#define rep(i,N) for(i=0;i<N;i++)
#define rep1(i,N) for(i=1;i<N;i++)
#define mod 1000000007

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
 
ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

int main(){
  int i,N,K,a,b,ch,now;
  long t;
  cin>>N;
  vector<vector<data>> v(N);
  vector<int> st(N,-1);
  rep(i,N-1){
    cin>>a>>b>>t;
    ch=(int)(t%2);a--;b--;
    v[a].push_back(data(b,ch));
    v[b].push_back(data(a,ch));
  }
  st[0]=0;
  set<int> se;
  queue<int> que;
  auto p=se.insert(0);
  que.push(0);
  while(se.size()<N){
    a=que.front();que.pop();
    for(i=0;i<v[a].size();i++){
      p=se.insert(v[a][i].first);
      if(p.second){
        que.push(v[a][i].first);
        st[v[a][i].first]=(st[a]+v[a][i].second)%2;
      }
    }
  }
  rep(i,N){
    cout <<st[i]<<endl;
  }
  return 0;
}

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

int main() {
    int N,t,tt=0;
    string s,X;
    cin >> N;
    map<string,int> st;

    rep(i,N) {
        cin >> s >> t;
        tt += t;
        st[s] = tt;
    }

    cin >> X;

    cout << tt-st.at(X) << endl;
}

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

const int N = 55;

int dp[N][2];
int cnt[N][2];

signed main() {
  int n, k;
  cin >> n >> k;

  vector<int> a(n);
  rep(i,n) cin >> a[i];

  for (int i = 0; i < n; i++) {
    int x = a[i];
    for (int j = 0; j < N; j++) {
      cnt[j][(x >> j) & 1]++;
    }
  }

  memset(dp, -1, sizeof(dp));
  dp[50][0] = 0;

  for (int i = 49; i >= 0; i--) {
    bool bit = false;
    if((k >> i) & 1) bit = true;

    int x = (1LL << i) * cnt[i][0];
    int y = (1LL << i) * cnt[i][1];

    // tight -> tight
    if(dp[i + 1][0] != -1) {
      if(bit) chmax(dp[i][0], dp[i + 1][0] + x);
      else chmax(dp[i][0], dp[i + 1][0] + y);
    }

    // tight -> loose
    if(dp[i + 1][0] != -1) {
      if(bit) chmax(dp[i][1], dp[i + 1][0] + y);
    }

    // loose -> loose
    if(dp[i + 1][1] != -1) {
      chmax(dp[i][1], dp[i + 1][1] + x);
      chmax(dp[i][1], dp[i + 1][1] + y);
    }
  }

  int ans = max(dp[0][1], dp[0][0]);
  cout << ans << '\n';
}


Measured memory_bytes: 4004
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <set>
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int mod = 998244353;
const int inf = 1 << 30;
const int maxn = 100000 + 5;

int n;
string s;

int main() {
  ios::sync_with_stdio(false);
  cin >> n >> s;
  string ans;
  for (auto& x: s) {
    char tot = (x - 'A' + n) % 26 + 'A';
    ans.push_back(tot);
  }
  cout << ans;
  return 0;
}

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

int main() {
        int N, i, X,
            sum = 0;

        cin >> N;

        for (i = N; i > 0; i /= 10) {
                X = i % 10;
                sum += X;
        }

        if (N % sum == 0) {
                cout << "Yes" << endl;
        } else {
                cout << "No" << endl;
        }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll a[100010],b[100010];

int main() {
	string s;
	cin>>s;
	ll cnt=0,ans=0;
	for(int i=0;i<s.size();i++){
		if(cnt!=0){
			cnt--;
			if(s[i]=='g'){
				ans++;
			}
			continue;
		}
		if(cnt==0){
			cnt++;
			if(s[i]=='p'){
				ans--;
			}
		}
	}
	cout <<ans;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
int num[10][7]={{0,1,1,1,1,1,1},{0,0,0,0,1,1,0},{1,0,1,1,0,1,1},{1,0,0,1,1,1,1},{1,1,0,0,1,1,0},{1,1,0,1,1,0,1},{1,1,1,1,1,0,1},{0,1,0,0,1,1,1},{1,1,1,1,1,1,1},{1,1,0,1,1,1,1}};
int main(){
	int n;
	int segment[7]={0,0,0,0,0,0,0};
	int display[7];
	while(cin>>n,n!=-1){
		rep(i,7)segment[i]=0;
		for(int j=0;j<n;j++){
			int nm;
			cin>>nm;
			rep(i,7){
				display[i]=segment[i] xor num[nm][i];
				segment[i]=num[nm][i];
			}
			string s="";
			rep(i,7)s+=(char)(display[i]+'0');
			cout<<s<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1200
N = int(input())
src = [list(map(int,input().split())) for i in range(N)]

ans = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            if src[i][j] > src[i][k] + src[k][j]:
                print(-1)
                exit()

for i in range(N-1):
    for j in range(i+1,N):
        use = True
        for k in range(N):
            if k==i or k==j: continue
            if src[i][j] == src[i][k] + src[k][j]:
                use = False
                break
        if use:
            ans += src[i][j]
print(ans)

Measured memory_bytes: 45788
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))

import itertools
a,b=-1,-1
for i,v in enumerate(itertools.permutations(range(1,n+1))):
  if v == p: a=i
  if v == q: b=i
print(abs(a-b))

Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
  int N,A,B;
int main() {
    cin >> N >> A >> B;
    if(N*A > B){
      cout << B << endl;
    }
    else if(N*A < B){
      cout << N*A << endl;
    }
  else if(N*A == B){
    cout << B << endl;
  }
}

Measured memory_bytes: 256
import sys
x, y = input().split(" ")
for i in range(int(x)+1):
  exp_i = int(x) - i
#  print(i)
#  print(int(i) * 2 + exp_i * 4)
#  print(int(y))
  if int(i) * 2 + exp_i * 4 == int(y):
    print("Yes")
    sys.exit()

print("No")


Measured memory_bytes: 9168
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  long n, m;
  rd(n, m);
  long ans = 1;
  for (long k = 1; k * k <= m; k++) {
    if (m % k == 0) {
      if (n * k <= m) {
        ans = max(ans, k);
      }
      if (n * (m / k) <= m) {
        ans = max(ans, m / k);
      }
    }
  }
  writeln(ans);
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 575;

// d[l][r]
int d[MAX_N][MAX_N];

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

  CIN(N, M, Q);
  REP(i, M) {
    CIN(L, R);
    L--; R--;
    d[L][R]++;
  }

  /*
  REP(i, N) {
    REP(j, N) {
      debug(i + 1);
      debug(j + 1);
      debug(d[i][j]);
    }
    cout << endl;
  }
  */

  // 後ろから前に積み上げる(iはNから0に下がっていく)
  RREP(i, N + 1) {
    REP(j, N + 1) {
      d[i][j] += d[i + 1][j];
    }
  }

  // 前から後ろに積み上げる(jは0からNに上がっていく)
  REP(i, N + 1) {
    REP(j, N + 1) {
      if (j > 0) {
	d[i][j] += d[i][j - 1];
      }
    }
  }

  REP(qi, Q) {
    CIN(p, q);
    p--; q--;
    cout << d[p][q] << endl;
  }

  /*
  REP(i, N) {
    REP(j, N) {
      debug(i + 1);
      debug(j + 1);
      debug(d[i][j]);
    }
    cout << endl;
  }
  */

  return 0;
}



Measured memory_bytes: 2048
let rec push lst (n, s) = match lst with
  | [] -> (n, s) :: lst
  | (m, t) :: tl -> if n = m then (m, t+s) :: tl else (m, t) :: push tl (n, s)
let () =
  try
    while true do
      let init = Scanf.scanf "%d\n"
          (fun n -> if n = 0 then raise End_of_file
            else Array.to_list (Array.init n (fun _ -> Scanf.scanf "%d %d %d\n"
                             (fun e p q -> (e, p, q))))) in
      let second = List.map (fun (e, p, q) -> (e, p * q)) init in
      (* 社員ごと合計値を得たリスト作成する *)
      List.fold_left (fun lst (n, s) -> push lst (n, s)) [] second
      |> List.filter (fun (e, q) -> q >= 1000000)
      |> (fun lst -> if lst = [] then print_endline ("NA")
           else List.iter
               (fun (e, p) -> print_endline (string_of_int e)) lst)
    done
  with
  | End_of_file -> exit 0


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

int	calc_relative(const set<int> &s, int val)
{
	auto	it = lower_bound(s.begin(), s.end(), val);
	return distance(s.begin(), it);
}

int	calc_idx(int N, const vector<int> &R)
{
	vector<int> relative_vec(N);
	set<int>	appeared;
	int			relative, val;
	for (int i = N - 1; i >= 0; --i) {
		val = R.at(i);
		relative = calc_relative(appeared, val);
		relative_vec.at(i) = relative;
		appeared.insert(val);
	}
	int	idx = 0;
	for (int i = 0; i < N - 1; ++i) {
		idx += relative_vec.at(i);
		idx *= (N - 1 - i);
	}
	return idx;
}

int	main()
{
	int	N;
	cin >> N;
	vector<int> P(N), Q(N);
	for (int i = 0; i < N; ++i) cin >> P.at(i);
	for (int i = 0; i < N; ++i) cin >> Q.at(i);
	int	a = calc_idx(N, P);
	int	b = calc_idx(N, Q);
	int	dist = a > b ? a - b : b - a;
	cout << dist << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

struct Node {
    bool visit = false;
    vector<int> next;
    int d = -1;
};

int main() {
    int n, id, k, temp;
    Node node[101];
    queue<int> que;
    
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> id >> k;
        for (int j = 0; j < k; j++) {
            cin >> temp;
            node[id].next.push_back(temp);
        }
    }

    node[1].d = 0;
    node[1].visit = true;
    que.push(1);
    while (!que.empty()) {
        temp = que.front();
        for (int i = 0; i < node[temp].next.size(); i++) {
            if (node[node[temp].next[i]].visit == false) {
                node[node[temp].next[i]].d = node[temp].d + 1;
                node[node[temp].next[i]].visit = true;
                que.push(node[temp].next[i]);
            }
        }
        que.pop();
    }

    for (int i = 1; i <= n; i++) {
        cout << i << " " << node[i].d << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
	int a, b;
	cin >> a >> b;
	if (a > b) {
		cout << a + (a - 1) << endl;
	}
	else if (a < b) {
		cout << b + (b - 1) << endl;
	}
	else if (a == b) {
		cout << a * 2 << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
LL solve (LL n, LL m) {
    if (n == 1) {
        if (m == 1) return 1;
        return m-2;
    }
    if (n == 2) {
        return 0;
    }
    return (n-2)*(m-2);
}

int main() {
    int n, m;
    cin >> n >> m;
    cout << solve (min(n, m), max(n, m));

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

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

ll lcm(ll x, ll y) {
    return x / gcd(x,y) * y;
}

int main(void)
{
    IOS
    int N; cin >> N;
    int ans; cin >> ans;
    REP(i,N-1) {
        int a; cin >> a;
        ans = gcd(ans,a);
    }

    cout << ans << '\n';

    return 0;
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	int k;
	std::cin >> k;
	std::cout << (k/2) * (k/2 + !!(k%2)) << '\n';
	return 0;
}


Measured memory_bytes: 256
(let ((n (read))
      (tmax (read))
      (ans 1000000000))
  (loop repeat n do
       (let ((cost (read))
	     (time (read)))
	 (when (and
		(<= time tmax)
		(< cost ans))
	   (setq ans cost))))
  (print (if (<= ans 1000) ans 'TLE)))

Measured memory_bytes: 13024
#include <stdio.h>
unsigned long max(unsigned long a, unsigned long b) { return a > b ? a : b; }
int main(void){
    long int A,B,K;
    scanf("%ld %ld %ld",&A,&B,&K);
    if(K<=A)
    {
        A-=K;
    }
    else if(A<K&&(A+B)>=K)
    {
      K-=A;
      A=0;
      B-=K;
    }
    else
    {
        A=0;
        B=0;
    }
    
    printf("%ld %ld\n",A,B);
    
}

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

long long N, A[5];

int main()
{
	cin >> N >> A[0] >> A[1] >> A[2] >> A[3] >> A[4];

	sort(A, A + 5);
	cout << (N - 1) / A[0]  + 5;
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
p = list(map(lambda x: int(x) - 1, input().split()))
xy = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]

par = [i for i in range(n)]
rank = [0 for _ in range(n)]


def root(x):
    if par[x] == x:
        return par[x]
    par[x] = root(par[x])
    return par[x]


def is_same(x, y):
    return root(x) == root(y)


def union(x, y):
    x = root(x)
    y = root(y)
    if x == y:
        return
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[y] == rank[x]:
            rank[y] += 1


for x, y in xy:
    union(x, y)

count = 0
for i, p_i in enumerate(p):
    count += 1 if is_same(i, p_i) else 0
print(count)


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

#define SPEED cin.tie(0);ios::sync_with_stdio(false);
template <class T> void chmax(T& a, const T b){a=max(a,b);}

int main() {
    SPEED
    int N; cin >> N;
    vector<int> V(N+1),W(N+1);
    for(int i = 1; i <= N; ++i) cin >> V[i] >> W[i];

    //O(Q)
    int nl = 1<<11,nr=1<<7,L_max=100001;
    vector<int> msb(nl,0);
    for(int i = 1; i < nl; ++i) msb[i]=31-__builtin_clz(i);
    vector<int> bit_w_dp(nl,0);
    vector<int> bit_v_dp(nl,0);
    vector<vector<int>> dp(nl,vector<int>(L_max,0));

    //前計算
    for(int n = 1; n < min(nl,N+1); ++n) {
        int k = 2*n;
        vector<int> l;
        while(k/=2) l.push_back(k);
        int sz=l.size();
        //bit全探索
        for(int i = 1; i < (1<<sz); ++i) {
            bit_w_dp[i]=bit_w_dp[i^(1<<msb[i])]+W[l[msb[i]]];
            bit_v_dp[i]=bit_v_dp[i^(1<<msb[i])]+V[l[msb[i]]];
            if(bit_w_dp[i]<=L_max) chmax(dp[n][bit_w_dp[i]],bit_v_dp[i]);
        }
        //累積max
        for(int i = 1; i < L_max; ++i) {
            chmax(dp[n][i],dp[n][i-1]);
        }
    }

    int Q; cin >> Q;
    string ans_str="";

    //クエリ
    while(Q--) {
        int p,L; cin >> p >> L;
        vector<int> r;
        int k = 2*p,l=0;
        while(k/=2) {
            if(k<nl) chmax(l,k);
            else r.push_back(k);
        }
        int sz = r.size(),ans=dp[l][L];
        //bit全探索
        for(int i = 1; i < (1<<sz); ++i) {
            bit_w_dp[i]=bit_w_dp[i^(1<<msb[i])]+W[r[msb[i]]];
            bit_v_dp[i]=bit_v_dp[i^(1<<msb[i])]+V[r[msb[i]]];
            if(bit_w_dp[i]<=L) chmax(ans,dp[l][L - bit_w_dp[i]]+bit_v_dp[i]);
        }
        ans_str += to_string(ans)+"\n";
    }
    cout << ans_str;

    return 0;
}


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

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

  int N; cin >> N;
  vector<int> ans(N);
  for (int i = 0; i < N-1; i++) {
    int C, S, F; cin >> C >> S >> F;
    for (int j = 0; j <= i; j++) {
      ans[j] = max(ans[j], S);
      if (ans[j] % F) ans[j] += F - ans[j] % F;
      ans[j] += C;
    }
  }
  for (int i = 0; i < N; i++) cout << ans[i] << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
// #include <regex> //正規表現
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
// グリッドグラフの移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int N, W; cin >> N >> W;
VI w(N), v(N);
rep(i, 0, N) cin >> w[i] >> v[i];

// 全探索は 品物を選ぶ選ばないの O(2^N)
// ナップザックDP
// dp[i][j] = i 番目の品物まででの， 重さ j 以下での最大価値．サイズ O(NW)
// dp[0][0 ~ W] = 0
vector<vector<int64_t>> dp(N + 1, vector<int64_t>(W + 1, 0LL));

rep(i, 1, N+1){
    rep(j, 1, W + 1){
        if (w[i - 1] <= j) 
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i -1]);
        else 
            dp[i][j] = dp[i - 1][j];
    }
}

cout << dp[N][W] << "\n";
}

// 境界，出力文字列 チェック



Measured memory_bytes: 80256
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

int main() {
	int atoz[26]={};
	string S;
	cin >> S;
	
	for(int i=0; i<S.length(); i++){
		atoz[S[i]-'a']++;
	}
	
	for(int i=0; i<26; i++){
		if(atoz[i]==0){
			cout << (char)(i+'a') << endl;
			return 0;
		}
	}
	cout << "None" << endl;
	
	return 0;
}

Measured memory_bytes: 512