akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
 
int LCSLength(char*,char*);
 
int main(){
  int q,i;
  char X[1000],Y[1000];
 
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%s",X);
    scanf("%s",Y);
    printf("%d\n",LCSLength(X,Y));
  }
 
  return 0;
}
 
int LCSLength(char *X,char *Y){
  int c[1001][1001];
  int i,j,m,n;
  m = strlen(X);
  n = strlen(Y);
   
  for(i=1;i<=m;i++){
    c[i][0] = 0;
  }
  for(j=0;j<=n;j++){
    c[0][j] = 0;
  }
   
  for(i=1;i<=m;i++){
    for(j=1;j<=n;j++){
      if(X[i-1]==Y[j-1]) c[i][j]=c[i-1][j-1]+1;
      else if(c[i-1][j]>=c[i][j-1]) c[i][j]=c[i-1][j];
      else c[i][j] = c[i][j-1];
    }
  }
 
  return c[m][n];
}

Measured memory_bytes: 4524
from functools import cmp_to_key
N = int(input())

my_list = []

for i in range(N):
    t, c = input().split()
    my_list.append((t, int(c), i+1))

def cmp(a, b):
    if a == b: return 0
    return -1 if a < b else 1

my_list.sort(key=cmp_to_key(lambda x, y: cmp(x[0], y[0]) or cmp(y[1],x[1])))

for mi in my_list:
    print(mi[2])

Measured memory_bytes: 3572
#include <stdio.h>
int main(){
int x,y;
        scanf("%d %d", &x, &y);
    while(1){
        printf("%d %d\n", x>=y?y:x , x>=y?x:y);
        scanf("%d %d", &x, &y);
        if(x==0 and y==0) break;
    }
}



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

public class Main {
	static class SegTree{
		int dat[];
		int N;
		public SegTree(int N) {
			int v = 1;
			while(v < N){
				v *= 2;
			}
			this.N = v;
			dat = new int[v * 2];			
		}
		void update(int k , int a){
			k += N - 1;
			dat[k] = a;
			while(k > 0){
	            k = (k - 1) / 2;
	            dat[k] = Math.max(dat[k*2+1], dat[k*2+2]);				
			}
		}
	    int query(int a, int b) { return query(a, b, 0, 0, N); }
	    int query(int a, int b, int k, int l, int r) {
	        if(r <= a || b <= l) return 0;
	        if(a <= l && r <= b) return dat[k];
	        int m = (l + r) / 2;
	        return Math.max(query(a, b, k*2+1, l, m), query(a, b, k*2+2, m, r));
	    }		
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int A[] = new int[N];
		int M = 0;
		for(int i = 0 ; i < N ; ++i){
			A[i] = sc.nextInt();
			M = Math.max(M, A[i]);
		}
		SegTree st = new SegTree(M + 1);
//		int dp[] = new int[M + 1];
		for(int a : A){
			int l = Math.max(0, a - K);
			int r = Math.min(M, a + K);
			int v = 1 + st.query(l, r + 1);
//			System.out.println(a+" "+v+" "+l+" "+r);
			st.update(a, v);
//			for(int i = 1 ; i <= M ; ++i){
//				System.out.println(i+" "+st.query(i, i));
//			}
//			System.out.println(Arrays.toString(st.dat));
		}
//		System.out.println(Arrays.toString(st.dat));
		System.out.println(st.query(0, M + 1));
	}
}


Measured memory_bytes: 60968
const t={input:require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/),n:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.n())}return a}else{const a=t.input[0];t.input.shift();return Number(a)}},s:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.s())}return a}else{const a=t.input[0];t.input.shift();return String(a)}},c:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.c())}return a}else{let a=t.input[0].split('');const b=a[0];a.shift();if(a.length>0){t.input[0]=a.join('')}else{t.input.shift()}return String(b)}},o:(...arg)=>{console.log(...arg)},abs:(a)=>{return Math.abs(a)},min:(...a)=>{return Math.min(...a)},max:(...a)=>{return Math.max(...a)},floor:(a)=>{return Math.floor(a)},asc:(ar:number[])=>{return ar.sort((a,b)=>{return a-b})},desc:(ar:number[])=>{return ar.sort((a,b)=>{return b-a})},sw:(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]}};
const main=()=>{
  let [a,b]=t.n(2)
  let ans =''
  for(let i=b-a+1;i<=b+a-1;i++){
    t.o(i)
  }
}
main()

Measured memory_bytes: 9260
# @oj:atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-04-20 10:31
# @url:https://atcoder.jp/contests/dp/tasks/dp_b
import sys
def input():
    return sys.stdin.readline().strip()

def main():
    nk=list(map(int,input().split()))
    h=list(map(int,input().split()))
    n=nk[0]
    k=nk[1]
    dp=[10**9]*n
    dp[0]=0
    dp[1]=abs(h[1]-h[0])

    for i in range(2,n):
        # dp[i]=min(dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i))
        for j in range(max(0,i-k),i):
            dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i])

    print (dp[-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 52320
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	if(*max_element(a.begin(),a.end())-*min_element(a.begin(),a.end())>1){
		cout << "No" << endl;
	}else{
		if(*max_element(a.begin(),a.end())-*min_element(a.begin(),a.end())==1){
			int m=0;
			for(int i=0;i<n;i++){
				if(a[i]==a[0]){
					m+=1;
				}
			}
			if(m+(n-m)/2>=a[0]+1&&m<=a[0]){
				cout << "Yes" << endl;
			}else{
				cout << "No" << endl;
			}
		}else{
			if(n/2>=a[0]||a[0]==n-1){
				cout << "Yes" << endl;
			}else{
				cout << "No" << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
const ll mod = 1e9+7;
typedef pair<int,int> P;
#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,m,N) for(int i=m;i<N;i++)
#define mm(n,m) memset(n,m,sizeof(n))

int main(){
    string s;
    cin>>s;
    if(s=="Sunny"){
        cout<<"Cloudy"<<endl;
    }else if(s=="Cloudy"){
        cout<<"Rainy"<<endl;
    }else{
        cout<<"Sunny"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin >> s;
    bool sol = false;
    for(int i=0; i<s.length()-1; i++){
        if(s[i] == 'A' && s[i+1] == 'C'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long double;
using ull = unsigned long long;
constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;
//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

ll n,m;
vector<int> G[1010];

ll f(int k) {
    ll dp[1010] = {};
    for (int i = n - 1; i >= 1; i--) {
        ll ma = 0;
        ll sum = 0;
        ll num = G[i].size();
        for (int j = 0; j < num; j++) {
            ma = max(ma, dp[G[i][j]]);
            sum += dp[G[i][j]];
        }
        if (i == k && num >= 2) {
            num--;
            sum -= ma;
        }
        dp[i] = sum / num + 1;
    }
    return dp[1];
}

void solve() {
    cin >> n >> m;
    REP(i,m) {
        int s,t;
        cin >> s >> t;
        G[s].pb(t);
    }
    ll ans = INF;
    for (int i = 1; i <= n - 1; i++) {
        ans = min(ans, f(i));
    }
    cout << setprecision(20) << ans << endl;
}

int main(int argc, char *argv[]){
    // /* Regular */
    // int case_num = 1;
    // if (argc > 1 && stoi(argv[1])) cin >> case_num;
    // REP(case_no, case_num) {
    //   cerr << endl << "case " << case_no + 1 << endl;
    //   solve();
    // }
    /* AOJ */
    solve();
    return 0;
}

Measured memory_bytes: 1408
n = int(input())
dat_s = []
for i in range(n):
    dat_s.append(int(input()))
total = sum(dat_s)
f = True

if total % 10 != 0:
    print(total)
    f = False
else:
    dat_s.sort()
    for i in range(len(dat_s)):
        if dat_s[i] % 10 != 0:
            print(total - dat_s[i])
            f = False
            break

if f:
    print("0")

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

using namespace std;
int main()
{
    // 文字列の入力
    char a;
	cin >> a;
	
	if(a >= 'a' && a <= 'z') {
		cout << "a" << endl;
	} else if (a >= 'A' && a <= 'Z') {
		cout << "A" << endl;
	}
	
    return 0;
}

Measured memory_bytes: 3628
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD


# --------------------------------------------

dp = None


def main():
    S = input()

    pre_s = S[0]
    ans = 0

    for i in range(1, len(S)):
        if S[i] != pre_s:
            ans += 1
            pre_s = S[i]

    print(ans)


main()


Measured memory_bytes: 4852
from collections import deque

Ss = input()
Q = int(input())

anss = deque(Ss)
isRev = False
for _ in range(Q):
    vs = input().split()
    if vs[0] == '1':
        isRev = not isRev
    else:
        F, C = vs[1], vs[2]
        if F == '1':
            if isRev:
                anss.append(C)
            else:
                anss.appendleft(C)
        else:
            if isRev:
                anss.appendleft(C)
            else:
                anss.append(C)

#print('anss:', anss)
#print('isRev:', isRev)
anss = ''.join(anss)
if isRev:
    anss = anss[::-1]

print(anss)


Measured memory_bytes: 8692
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define debug(x) cerr << #x << " " << x << endl;
#define debug_p(x) cerr << #x << " [" << x.fi << " " << x.se << "]"<<endl;
#define debug_v(x) {cerr << #x << " "; for (auto ioi : x) cerr << ioi << " "; cerr << endl;}
#define debug_vp(x) {cerr << #x << " "; for (auto ioi : x) cerr << '[' << ioi.fi << " " << ioi.se << ']'; cerr << endl;}
#define debug_v_v(x) {cerr << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cerr << ioi2 << " "; cerr << '\n';} cerr << "*/" << #x << endl;}
#define gen_clock(x) ll x = clock(); cerr << "Clock " << #x << " created" << endl;
#define check_clock(x) cerr << "Time spent in " << #x << ": " << (double)(clock() - x)/CLOCKS_PER_SEC << endl; x = clock();
#define reset_clock(x) x = clock()
 
const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
 
void solve()
{
	ll n;
	ll ct=0;
	cin>>n;
	for(ll i=1;i<n;i++)
	{
		ct+=(n-1)/i;
	}
	cout<<ct<<endl;
    
}
 
int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


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

uint64_t pow64(const uint64_t base, const uint64_t index) {
    uint64_t x = 1;
    for(uint64_t i = 0; i < index; ++i) {
        x *= base;
    }
    return x;
}

uint64_t pow64_mod(uint64_t base, uint64_t index, const uint64_t mod) {
    base %= mod;

    uint64_t x = 1;
    uint64_t factor = base;

    while(index) {
        if(index & 1) {
            x = (x * factor) % mod;
        }
        factor = (factor * factor) % mod;
        index >>= 1;
    }
    return x;
}

uint64_t mod_p_inverse(const uint64_t x, const uint64_t mod_p) {
    return pow64_mod(x, mod_p - 2, mod_p);
}

uint64_t mod_factorial(const uint64_t n, const uint64_t mod) {
    static auto memo = std::vector<uint64_t>(1, 1);

    if(memo.size() > n) {
        return memo[n];
    }

    for(uint64_t i = memo.size(); i <= n; ++i) {
        const auto x = memo[i - 1] * i % mod;
        memo.push_back(x);
    }

    return memo[n];
}

uint64_t mod_factorial_inverse(const uint64_t n, const uint64_t mod) {
    const auto f = mod_factorial(n, mod);
    return mod_p_inverse(f, mod);
}

uint64_t combination_mod(const uint64_t n, const uint64_t r, const uint64_t mod) {
    const auto a = mod_factorial(n, mod);
    const auto b = mod_factorial_inverse(r, mod);
    const auto c = mod_factorial_inverse(n - r, mod);

    return (a * b % mod) * c % mod;
}

int main() {
    int x, y;
    std::cin >> x >> y;

    if((x + y) % 3 != 0) {
        std::cout << 0;
    } else {
        const int m = (2 * x - y) / 3;
        const int n = (2 * y - x) / 3;
        if(m < 0 || n < 0) {
            std::cout << 0;
        } else {
            const uint64_t mod = pow64(10, 9) + 7;
            std::cout << combination_mod(m + n, m, mod);
        }
    }
    return 0;
}


Measured memory_bytes: 10220
#include <bits/stdc++.h>
using namespace std;
#define trace1(a) cout << a << 'n';
#define trace2(a, b) cout << a << ' ' << b << 'n';
#define trace3(a, b, c) cout << a << ' ' << b << ' ' << c << 'n';
#define trace4(a, b, c, d) cout << a << ' ' << b << ' ' << c << ' ' << d << 'n';
#define trace5(a, b, c, d, e) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << 'n';
#define trace6(a, b, c, d, e, f) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << ' ' << f << 'n';
#define range(n) for(int i = 0; i < n; i++)
#define printArr(harry, tam) range(tam) cout << harry[i] << " n"[i == tam -1];
#define maxn -2000000 //negative value to break code and force you to put right constraint
#define mod 1000000007
#define md(x) (x) % mod;
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ps push
#define prt(x) cout << (#x) << " is " << (x) << endl
#define EPS 1e-9
#define INF 1000000000
#define INFd 1e9
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<double> vd;

int main(){

  string s;
  cin>>s;
  for(int i=0;i<s.length();i++)
  {
      if((i+1)%2==0)
      {
        if(s[i]=='R')
        {
          cout<<"No";
          exit(0);
        }

      }
      if((i+1)%2==1)
      {
        if(s[i]=='L')
        {
          cout<<"No";
          exit(0);
        }

      }

  }
  cout<<"Yes";

   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include <set>
using namespace std;
int main()
{
	int N;
	cin >> N;
	std::string S;
	set<std::string> list;

  	for(int i = 0;i<N;i++){
		cin >> S;
		list.insert(S);
		
	}
	cout << list.size() << endl;
	
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    ll N,K,S; cin >> N >> K >> S;

    if(S == 1e9){
        for (int i = 0; i < K;i++){
            cout << int(1e9) << " ";
        }
        for (int i = K;i < N;i++){
            cout << 1 << " ";
        }
        cout << endl;
    }else{
        for (int i = 0;i < K;i++){
            cout << S << " ";
        }
        for (int i = K;i < N;i++){
            cout << int(1e9) << " ";
        }
        cout << endl;
    }

    return 0;

}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;



int main() {
    li s, w;
    cin >> s >> w;
    cout << (s > w ? "safe" : "unsafe") << endl;

    return 0;
}

Measured memory_bytes: 3592
package main

import (
	"fmt"
)

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	C := 1
	for i := 1; i <= N; i++ {
		if i == 1 {
			C *= K
		} else {
			C *= (K - 1)
		}
	}
	fmt.Println(C)
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main()
{   int n, t;
    cin>>n>>t;
    int tablou[n];
    for(int i=0; i<n; i++){
        cin>>tablou[i];
    }
    int suma=0;
    for(int i=1; i<n; i++){
        if(tablou[i]-tablou[i-1]<t){
            suma+=tablou[i]-tablou[i-1];
        }
        else if(tablou[i]-tablou[i-1]>= t){
            suma+=t;
        }
    }
    suma=suma+t;
    cout<<suma;


    return 0;
}


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

int main()
{
	int N,L; cin>>N>>L;
    int sum = (L+L+N-1)*N/2;
   	if(L>0){
    	cout<<sum-L<<endl; return 0;
    }
    else{
    	if(L+N-1<0){
        	cout<<sum-(L+N-1)<<endl; return 0;
        }
        else {
        	cout<<sum<<endl; return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
int main(){
    double N, inx, ans=0;
    string inu;
    cin >> N;
    
    vector<double> x;
    vector<string> u;
    for(int i=0; i<N; i++){
        cin >> inx >> inu;
        x.push_back(inx);
        u.push_back(inu);
    }

    for(int i=0; i<N; i++){
        if(u[i] == "JPY"){
            ans += x[i];
        }else{
            ans += x[i]*380000;
        }
    }
    cout << ans << endl;
}


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

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


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

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

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

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

int main()
{
	int n;
	cin>>n;
	vi A(n);
	take(A,0,n);
	sort(all(A));
	set<int> S;
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(i!=n-1&&A[i]==A[i+1])
		{
			S.insert(A[i]);
			continue;
		}
		set<int> P;
		bool can=true;
		for(int j=1;j*j<=A[i];j++)
		{
			if(A[i]%j==0)
			{
				if(S.count(j)||S.count(A[i]/j)) {can=false;break;}
			}
		}
		if(can)
		{
			ans++;
		}
		S.insert(A[i]);
	}
	cout<<ans<<endl;
}		

Measured memory_bytes: 17444
#include<iostream>
#define SIZE 200000
using namespace std;
  
struct Queue{
  int table[SIZE];
  int tail,head;
  
  void init(){
    head=tail=0;
  }
  
  bool empty(){
    return head==tail;
  }
    
  void inqueue(int x){
    table[tail]=x;
    tail++;
    tail%=SIZE;
  }
  
  int dequeue(){
    if(empty())return 0;
    int res=table[head];
    head++;
    head%=SIZE;
    return res;
  }
};
  
int main(){
  Queue queue,queue2;
  int n,q,num;
  string table[SIZE];
  cin>>n>>q;
  queue.init();
  queue2.init();
  for(int i=0;i<n;i++){
    cin>>table[i]>>num;
    queue.inqueue(num);
    queue2.inqueue(i);
  }
    
  int now=0,A,B;
  while(!queue.empty()){
    A=queue.dequeue();
    B=queue2.dequeue();
    if(A<=q){
      now+=A;
      cout<<table[B]<<' '<<now<<endl;
    }else{
      now+=q;
      A-=q;
      queue.inqueue(A);
      queue2.inqueue(B);
    }
  }
    
  return 0;
}


Measured memory_bytes: 8392
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int q;cin>>q;
    vector<int>l(q),r(q);
    for(int i=0;i<q;i++)
        cin>>l[i]>>r[i];
    bool vv[100006];
    memset(vv, 0, sizeof(vv));
    for(int i=1;i<=100005;i+=2){
        if(IsPrime(i)&&IsPrime((i+1)/2))
            vv[i]=1;
    }
    int s[100006];
    memset(s, 0, sizeof(s));
    s[1]=vv[1];
    for(int i=3;i<=100005;i+=2){
            s[i]+=vv[i];
            s[i]+=s[i-2];
    }
    for(int i=0;i<q;i++){
        if(l[i]>1)
        cout<<s[r[i]]-s[l[i]-2]<<endl;
        else{
            cout<<s[r[i]]<<endl;
        }
    }
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


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

int main() {
	double w, h, x, y;
	cin>>w>>h>>x>>y;
	
	int judge;
	if(x==w/2 && y==h/2) judge=1;
	else judge=0;
	
	printf("%.9lf %d", w*h/2.0, judge);
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

str s;
ll md = 1000000007;
ll dp[100010][5];
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>s;
    s = " "+s;
    dp[0][0] = 1;

    for(int i=1;i<s.size();i++){
        if(s[i]=='?'){
            for(int j=0;j<=3;j++) dp[i][j] = ((dp[i-1][j] % md) * (3 % md)) % md;

        }
        else{
            for(int j=0;j<=3;j++) dp[i][j]=dp[i-1][j];
        }

        if(s[i]=='A' || s[i]=='?'){
            dp[i][1] = ((dp[i][1]%md) + (dp[i-1][0]%md)) % md;
        }
        if(s[i]=='B' || s[i]=='?'){
            dp[i][2] = ((dp[i][2]%md) + (dp[i-1][1]%md)) % md;
        }
        if(s[i]=='C' || s[i]=='?'){
            dp[i][3] = ((dp[i][3]%md) + (dp[i-1][2]%md)) % md;
        }
    }
    cout<<dp[s.size()-1][3]<<newl;

}



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

int main(){
    int c[3][3];
    rep(i,3){
        rep(j,3){
        cin>>c[i][j];
        }
    }
    bool f=true;
    rep(i,2){
        rep(j,2){
            if(c[i+0][j+0]-c[i+0][j+1]!=c[i+1][j+0]-c[i+1][j+1]) f=false;
            if(c[i+0][j+0]-c[i+1][j+0]!=c[i+0][j+1]-c[i+1][j+1]) f=false;
        }
    }
    if(f==false) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int n, k;
	int i, s;
	int num=0;

	cin >> n >> k;
	int a[n];

	for(i=0; i < n; i++)
		cin >> a[i];

	num = (n-1)/(k-1);
	if((n-1)%(k-1) > 0) num++;

	cout << num << endl;

	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

  int a,b,c,d;cin>>a>>b>>c>>d;

  int l=max(a,c),r=min(b,d);

  out(max(r-l,0));

  return 0;
}


Measured memory_bytes: 256
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
public class Program
{
    public static void Main()
    {
        long N = long.Parse(Console.ReadLine());
        long[] l = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();

        long ans = 9999999999;
        long a = 0;
        long b = l.Sum();
        long abs = 0;
        for (int i = 0;i < N - 1; ++i)
        {
            a += l[i];
            b -= l[i];
            abs = Math.Abs(a - b);
            if (abs < ans) { ans = abs; }
            if (ans == 0) { break; }
        }

        Console.WriteLine(ans);
        
    }
}

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

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector<vi> vii;
const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5, Ns = 105;

typedef long long ll;

ll dp[N];
ll w[Ns];
ll v[Ns];

int main(){
    ll n, W;
    dp[0] = 0;
    for(ll j=1;j<N;j++){
        dp[j] = LINF;
    }

    cin >> n >> W;

    for(ll i=0;i<n;i++){
        cin >> w[i] >> v[i];
    }
    for(ll i=0;i<n;i++){
        for(ll j=N;j>=v[i];j--){
            dp[j] = min(dp[j] , dp[j-v[i]]+w[i]);
        }
    }
    ll ans = 0;

    for(ll j=0;j<N;j++){
        if(dp[j]<=W) ans = max(j,ans);
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 1024
import itertools
import math

def q37(n, d, x):
    count = 0
    for i in itertools.combinations(x, 2):
        c = 0
        for l in range(d):
            c += (i[0][l] - i[1][l])**2

        if math.sqrt(c).is_integer():
            count += 1
        
    return count

N, D = [int(i) for i in input().split()]

x = []
for n in range(N):
    x.append([int(i) for i in input().split()])

print(q37(N, D, x))

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

int n,k;
int p[1002];

int main(){

	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>p[i];
	sort(p,p+n);
	int ans = 0;
	for(int i=0;i<k;i++){
		ans += p[i];
	}
	cout<<ans<<endl;
	return(0);
}

Measured memory_bytes: 3620
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//233
	int n;
	cin>>n;
	map<string, vpii> m;
	REP(i,1,n) {
		string s;
		int sc;
		cin>>s>>sc;
		if(m.count(s)==0)m[s]=vpii();
		m[s].PUB({sc,i});
	}
	for(auto a:m) {
		vpii v = a.S;
		sort(v.rbegin(),v.rend());
		for(auto i:v)cout<<i.S<<"\n";
	}
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

int p, n;

int modpow(int a, int b) {
	int ans = 1;
	while (b) {
		if (b & 1) ans *= a; ans %= p;
		a = a * a%p;
		b >>= 1;
	}
	return ans;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n;
	cin >> n;
	int m = 2 * n - 1;
	vector<int> a(m);
	rep(i, m) cin >> a[i];
	int ok = -1, ng = 200010;
	while (ng - ok > 1) {
		int mid = (ok + ng) / 2;
		bool check = false;
		vector<int> l, r;
		for (int i = n - 1; i >= 0; i--) {
			if (a[i] >= mid) l.pb(1);
			else l.pb(0);
		}
		for (int i = n - 1; i < m; i++) {
			if (a[i] >= mid) r.pb(1);
			else r.pb(0);
		}
		bool flag = false;
		for (int i = 0; i < n - 1; i++) {
			if (l[i] == l[i + 1] || r[i] == r[i + 1]) {
				if (l[i]) check = true;
				else check = false;
				flag = true;
				break;
			}
		}
		if (!flag) {
			if (l[0] && n % 2 == 1 || !l[0] && n % 2 == 0) check = true;
		}
		if (check) ok = mid;
		else ng = mid;
	}
	cout << ok << endl;
}

Measured memory_bytes: 4484
n,m = list(map(int,input().split()))
d = [0]*m
spr = [True]*m
ma = 0
mi = 0
for i in range(m):
    a,b = list(map(int,input().split()))
    d[i] = [a,b]

d = sorted(d)
pre = d[0][1]
ans = 1
for i,(a,b) in enumerate(d):
  if a < pre:
    if b < pre:
      pre = b
  else:
    ans += 1
    pre = b

print(ans)

Measured memory_bytes: 22112
p,q= input().split()
a,b =(int(p), int(q))
h = map(int, input().split())
h_list = list(h)
h_list.sort()
ans_list =[]
if a<=b:
    print(0)
else:
    for i in range(a-b):
        
        ans_list.append(h_list[i])
    print(sum(ans_list))

Measured memory_bytes: 26024
// D - Checker

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int N, K;
int h[4000][4000];
int cum[4001][4001];

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

	for (int i=0; i<N; i++) {
		int x, y;
		char c;
		cin >> x >> y >> c;

		// W to B
		if (c == 'W') x += K;

		// 0 < x < K*2, 0 < y < K*2 の範囲に変換
		x = x % (K*2);
		y = y % (K*2);

		h[x][y]++;

		// 二次元累積和の算出を楽にするために
		// 0 < x < K*4, 0 < y < K*4 の範囲でループさせる
		h[x + K*2][y]++;
		h[x][y + K*2]++;
		h[x + K*2][y + K*2]++;
	}

	/*
	// **** debug ****
	for (int y=0; y<K*4; y++) {
		for (int x=0; x<K*4; x++) {
			cout << h[x][y] << " ";
		}
		cout << endl;
	}
	*/

	for (int y=0; y<K*4; y++) {
		for (int x=0; x<K*4; x++) {
			cum[x+1][y+1] = cum[x][y+1] + cum[x+1][y] - cum[x][y] + h[x][y];
		}
	}

	int ans = 0;
	for (int y=0; y<K*2; y++) {
		for (int x=0; x<K*2; x++) {
			int ok1 = cum[x + K][y + K] - cum[x][y + K] - cum[x + K][y] + cum[x][y];
			int ok2 = cum[x + K*2][y + K*2] - cum[x + K][y + K*2] - cum[x + K*2][y + K] + cum[x + K][y + K];
			ans = max(ans, ok1 + ok2);
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 125312
#include<iostream>
#include<string>
using namespace std;
int main() {
	string s;
	cin >> s;
	int a = 0;
    if (s == "SAT") a = 1;
	if (s == "FRI") a = 2;
	if (s == "THU") a = 3;
	if (s == "WED") a = 4;
	if (s == "TUE") a = 5;
	if (s == "MON") a = 6;
	if (s == "SUN") a = 7;
	cout << a << endl;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

// extgcd(a, b) = (g, s, t)
// g: GCD of a and b, s, t: a solution of sa + tb = g
template <typename T>
std::tuple<T, T, T> extgcd(T a, T b){
    if(b == 0){
        return std::make_tuple(a, 1, 0);
    }
    T g, _s, _t;
    std::tie(g, _s, _t) = extgcd(b, a % b);
    return std::make_tuple(g, _t, _s - (a/b) * _t);
}

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

    int A, B, C;
    std::cin >> A >> B >> C;

    int res = -1;
    for(int i=0;i<=A;++i){
        int g, s, t;
        tie(g, s, t) = extgcd(A + B, -60);
        
        // std::cout << i << std::endl;
        // std::cout << "!" << s << ", " << t << std::endl;
        
        if((C - i) % g == 0){
            t *= (C - i) / g;
            // std::cout << t << std::endl;
            while(t < 0){
                t += (A + B) / abs(g);
            }
            while(t - (A + B) / abs(g) >= 0){
                t -= (A + B) / abs(g);
            }
            t = 60 * t + C;
            if(res == -1 || t < res){
                res = t;
            }
            // std::cout << t << std::endl;
        }
        // std::cout << "----------" << std::endl;
    }

    std::cout << res << std::endl;
}



Measured memory_bytes: 3188
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
bool DEBUG = 0; void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void main(string[] args){ args ~= ["", ""]; string cmd = args[1]; if(cmd == "-debug") DEBUG = 1;
if(cmd == "-gen") gen; else if(cmd == "-jury") jury; else solve; } 
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ std.stdio.write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void gen(){
}
void jury(){
}

const long infty = 1_000_000_000_000;

void solve(){
    int n = scan!int, k = scan!int;
    long[] hs = scan!long(n) ~ 0;
    log("hs:", hs);

    long[][][] xf = new long[][][](n, k + 1, n + 1);
        // xf[i][l][j]: i 列目で、すでに l 回権利を行使し、高さが hs[j]
        // のときの最小のペナルティ
    
    log("infty:", infty);
    
    foreach(i; 0 .. n){
        foreach(l; 0 .. k + 1){
            log("xf:", xf);
            log("i:", i, "l:", l);
            
            // 最初の列
            if(i == 0){
                if(l == 0){
                    foreach(j, h; hs) xf[i][l][j] = infty;
                    xf[i][l][i] = hs[i];
                }
                else if(l == 1) foreach(j, h; hs) xf[i][l][j] = h;
                else foreach(j, h; hs) xf[i][l][j] = infty;
                continue;
            }

            // 前に合わせる（権利を行使する）
            foreach(j, h; hs){
                if(l == 0) xf[i][l][j] = infty;
                else xf[i][l][j] = xf[i - 1][l - 1][j];
            }

            // 初期値に合わせる
            long tmp = xf[i - 1][l][i];
            foreach(j, h; hs){
                tmp.lowerTo(xf[i - 1][l][j] + max(0, hs[i] - h));
            }
            xf[i][l][i] = tmp;
        }
    }

    long ans = infty;
    foreach(l; 0 .. k + 1) foreach(j, h; hs) ans.lowerTo(xf[n - 1][l][j]);

    ans.writeln;

}
/*
    xf[i][l][j]: i 列目で、すでに l 回権利を行使し、高さが hs[j]
    のときの最小のペナルティ
    
    「直前は白なのに自分は黒」の個数がペナルティになる。
    直前より上がる場合は、上がり幅がペナルティ。
    直前より下がる場合はペナルティはなし。
    初期値と異なる場合は l が増加する。

    現実的に意味があるのは
    ・直前に合わせる。（ペナルティは増加せず、権利が消費される）
    ・初期値に合わせる。（権利は消費されず、ペナルティが増加する）
    のどちらかのみ。

    DPの遷移としては
    ・直前に合わせる
    　　xf[i][l][j] = xf[i - 1][l - 1][j]　（各 j について）
    ・初期値に合わせる
    　　xf[i][l][hs[i]] = xf[i - 1][l][j] + max(0, hz[j] - hs[i])
    　　ただし j は右辺が最小となるような j
*/


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

int main() {
  string cards;
  while (true) {
    cin >> cards;
    if (cards == "-") break;

    int m;
    cin >> m;
    for (int i = 0; i < m; i++) {
      int num;
      cin >> num;
      cards = cards.substr(num, cards.size() - num) + cards.substr(0, num);
    }

    cout << cards << endl;
  }

  return 0;
}


Measured memory_bytes: 3208
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
using namespace std;

int main()
{
    long long int N, A, B;
    if (scanf("%lld%lld%lld", &N, &A, &B) < 3) return 0;

    long long int X[100000];

    for (int i = 0; i < N; i++)
    {
        if (scanf("%lld", &X[i]) < 1) return 0;
    }

    long long int bkX = X[0];
    long long int sum = 0;
    for (int i = 1; i < N; i++)
    {
        long long int d = X[i] - bkX;
        sum += min(d * A, B);
        bkX = X[i];
    }

    printf("%lld\n", sum);
    return 0;
}


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

int main(){
  int N;
  cin >>N;
  vector<long long int> a(N);
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int count =1;
  int flag =0;
  long long int b=0,c=0;
  for(int i=1;i<N;i++){
    if(a.at(i-1) != a.at(i)){
      count =1;
      continue;
    }
    else count++;
    if(count == 2 && flag == 0){
      b = a.at(i);
      flag = 1;
      continue;
    }
    if(count == 4){
      c = a.at(i);
      break;
    }
    if(count == 2 && flag == 1){
      c = a.at(i);
      break;
    }
  }
  long long int ans=b*c;
  cout << ans << endl;
}
    

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

int main(){
  int a,b;
  cin >> a >> b;
  if(1<=a && a<=9 && 1<=b && b<=9){
    cout << a*b << endl;
    return 0;
  }
  cout << -1 << endl;
}

Measured memory_bytes: 3556
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int a,b,c,x;
	cin>>a>>b>>c;
	if(a==b){
		x=c;
	}
	if(b==c){
		x=a;
	}
	if(a==c){
		x=b;
	}
	cout<<x<<endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		new Main().execute();
	}

	public void execute() {
		Scanner sc = new Scanner(System.in);
		final int A = sc.nextInt();
		final int B = sc.nextInt();
		final int C = sc.nextInt();

		int m = Math.max(A, Math.max(B, C));

		int d = 3 * m - (A + B + C);
		if (d % 2 == 0) {
			System.out.println(d / 2);
		} else {
			System.out.println((d + 3) / 2);
		}
		sc.close();

	}

}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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


bool check(ll a,ll b,ll c){
    return (a < b && b < c);
}

void solve() {
    ll a, b, c, k; cin >> a >> b >> c >> k;
    rep(i, k+1){
        rep(j, k+1){
            rep(l, k+1){
                if(i+j+l > k) continue;
                ll ta = a, tb=b, tc=c;
                rep(x, i) ta *= 2;
                rep(x, j) tb *= 2;
                rep(x, l) tc *= 2;
                if(check(ta, tb, tc)){
                    cout << "Yes" << endl;
                    return;
                }
            }
        }
    }
    cout << "No" << endl;
}

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


Measured memory_bytes: 7736