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

int main() {
  int P, Q, R;
  int A, B, C;
  cin >> P >> Q >> R;
  
  A = P + Q;
  B = Q + R;
  C = R + P;
  
  cout << min(A, min(B, C)) << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<random>

//使い方がよくわからない
#include<stack>
#include<queue>
#include<bitset>
#include<sstream>

#define rep(i,n) for(int i=0;i<(n);i++) 
#define rep1(i,n) for(int i=1;i<(n);i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]){
    int n;
    cin >> n;
    vector<ll> a(n),b(n-1);
    rep(i,n-1) cin >> b[i];
    a[0]=b[0];
    a[n-1] = b[n-2];
    rep1(i,n-1){
        a[i]=min(b[i],b[i-1]);
    }
    ll ans = 0;
    rep(i,n) ans += a[i];
    co(ans);
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int s[1 << 17] = {}, n, q;

int sum(int ind)
{
    int sm = 0;
    for (; ind; sm += s[ind], ind -= ind & -ind){}
    return sm;
}

void add(int ind, int val)
{
    for (; ind <= n; s[ind] += val, ind += ind & -ind) {}
    
}

int main()
{
    scanf("%d%d", &n, &q);
    for (int i = 1; ; i <<= 1)
    {
        if (i >= n)
        {
            n = i;
            break;
        }
    }
    for (int i = q + 1, c, x, y; --i; )
    {
        scanf("%d%d%d", &c, &x, &y);
        if (c)
        {
            printf("%d\n", sum(y) - sum(x - 1));
        }
        else
        {
            add(x, y);
        }
    }
}



Measured memory_bytes: 3600
MOD = 10**9 + 7

H, W = map(int, input().split())
Ass = [input() for _ in range(H)]

dp = [[0]*(W) for _ in range(H)]
dp[0][0] = 1
for i in range(H):
    for j in range(W):
        if Ass[i][j] == '#': continue
        dp[i][j] %= MOD
        if i < H-1:
            dp[i+1][j] += dp[i][j]
        if j < W-1:
            dp[i][j+1] += dp[i][j]

print(dp[-1][-1])


Measured memory_bytes: 43712
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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


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

	vector<int> ans;

	for (int i = 1; i < n; i++) {
		ans.push_back(a[i] - a[i - 1]);
	}
	ans.push_back(k-a[n-1]+a[0]);
	sort(ans.begin(), ans.end());
	int res = 0;
	rep(i, ans.size()-1) {
		res += ans[i];
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 2168
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace ABC141C
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            var N = input[0];
            var K = input[1];
            var Q = input[2];

            var players = new List<Player>(N);
            for (var i = 0; i < N; i++)
                players.Add(new Player { No = i + 1});


            for (var i = 0; i < Q; i++)
            {
                var A = int.Parse(Console.ReadLine());
                players[A - 1].CollectedCount++;
            }

            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            foreach (var p in players)
            {
                if (K - (Q - p.CollectedCount) > 0)
                    Console.WriteLine("Yes");
                else
                    Console.WriteLine("No");
            }

            Console.Out.Flush();
        }
    }

    class Player
    {
        public int No { get; set; }
        public int CollectedCount { get; set; }
    }
}


Measured memory_bytes: 22620
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    words = []
    flag = True
    for i in range(n):
        w = ns()
        if w in words:
            flag = False
        elif i != 0 and w[0] != words[-1][-1]:
            flag = False
        else:
            words.append(w)
    print('Yes' if flag else 'No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9072
def solve():
    N,M = map(int, input().split())
    # A = []; B = []
    AB = [list(map(int, input().split())) for _ in range(N)]
    AB.sort(key=lambda x:x[0])
    ret = 0
    # print(AB)
    while M>0:
        ab = AB.pop(0)
        if ab[1] < M:
            ret += ab[0]*ab[1]
        else:
            ret += ab[0]*M
            
        M -= ab[1]
        # print(ret,M)
    
    print(ret)
    
solve()

Measured memory_bytes: 28980
import math
import copy
import sys
import fractions
# import numpy as np
# import statistics
import decimal
import heapq
import collections
import itertools
import bisect

# from operator import mul

sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputIntList():
    outputDataList = []
    inputData = input().split()
    outputDataList = [int(n) for n in inputData]

    return outputDataList


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===


n = int(input())

data_set = getSomeInputListInt(n)
data_set.insert(0, 0)

INF = sys.maxsize

dp = [[INF for _ in range(n+1)] for _ in range(n+1)]
for i in range(1, n+1):
    dp[i][i] = 0
next_dp = copy.deepcopy(dp)

# ans = INF
# for s in range(1, n):
#     for i in range(1, n+1):
#         for j in range(i+s, n+1):
#             for k in range(i, j+1):
#                 if k >
#                 if dp[i][k] < INF and dp[k+1][j] < INF:
#                     next_dp[i][j] = min(next_dp[i][j], dp[i][k]+dp[k+1][j]+data_set[i][0]*data_set[k][1]*data_set[j][0])
#
#     dp = next_dp
#     ans = min(ans, dp[1][n])
# print(ans)


for s in range(1, n):
    for i in range(1, n+1):
        j = i+s
        if j > n:
            break
        for k in range(i, j):
            if dp[i][k] < INF and dp[k+1][j] < INF:
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + data_set[i][0] * data_set[k][1] * data_set[j][1])

print(dp[1][n])






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

n=int(input())
d=list(map(int,input().split()))

if d[0]!=0:
  print(0)
  exit()

 #1からmaxdまでの距離について、それぞれ何個のdが該当するかメモした配列
maxd=max(d)
kyori=[0]*(maxd+1)

#計算量減らし、、
for i in d:
  kyori[i]+=1

#1個目以外で距離0のやつある場合は停止。
if kyori[0]!=1:
  print(0)
  exit()

ans=1
for i in range(1,maxd):
  temp=kyori[i]**kyori[i+1]
  ans*=temp%998244353
  ans=ans%998244353
print(ans)

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

int64_t N, r, g, b, ans;
string S;

int main() {
    cin >> N >> S;
    for (char c: S) {
        if (c == 'R') r++;
        if (c == 'G') g++;
        if (c == 'B') b++;
    }
    ans = r * g * b;
    for (int i = 0; i < N; i++) {
        for (int j = 1; i + j * 2 < N; j++) {
            if (S[i] != S[i+j] && S[i+j] != S[i+j*2] && S[i] != S[i+j*2]) {
                ans--;
            }
        }
    }
    cout << ans << endl;
}

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

long long x[1000000];
int v[1000000];
long long c[1000000], cc[1000000];
long long cmx[1000000], ccmx[1000000];

int main()
{
	int n;
	long long C;
	scanf("%d%lld", &n, &C);
	for (int i = 1; i <= n; i++) scanf("%lld %d", &x[i], &v[i]);
	
	for (int i = 1; i <= n; i++)
	{
		c[i] = c[i - 1] + v[i] - (x[i] - x[i - 1]);
		cmx[i] = max(cmx[i - 1], c[i]);
	}
	x[n + 1] = C;
	for (int i = n; i >= 1; i--)
	{
		cc[n - i + 1] = cc[n - i] + v[i] - (x[i + 1] - x[i]);
		ccmx[n - i + 1] = max(ccmx[n - i], cc[n - i + 1]);
	}
	long long ans = 0;
	for (int i = 0; i <= n; i++)
	{
		ans = max(ans, c[i] - x[i] + ccmx[n - i]);
		ans = max(ans, cc[i] - (C - x[n - i + 1]) + cmx[n - i]);
	}
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 15360
def read_input():
    h, w = map(int, input().split())

    clist = []
    for i in range(h):
        clist.append(input().strip())

    return h, w, clist

def submit():
    h, w, clist = read_input()

    for c in clist:
        print(c)
        print(c)

if __name__ == '__main__':
    submit()


Measured memory_bytes: 38256
N,H = map(int,input().split())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)

maxA = max(A)

ans = 0
B.sort(reverse=True)
for i in range(N):
    if B[i] <= maxA: break
    if H <= 0: break
    H -= B[i]
    ans += 1

if H > 0:
    ans += H//maxA + (1 if H % maxA != 0 else 0)

print(ans)

Measured memory_bytes: 11336
v1 = int(input())
v2 = list(map(int, input().split()))

count = -1
stop = True
while stop:
    count = count + 1
    for i in range(v1):
        if v2[i] % 2 != 0:
            stop = False
            break
        v2[i] = v2[i] / 2
print(count) 

Measured memory_bytes: 3060
a = input()
li = list(a)
judge = 'Yes'

for i in range(len(a)):
  if (i+1)%2 == 0 and li[i] == 'R':
    judge = 'No'
  if (i+1)%2 == 1 and li[i] == 'L':
    judge = 'No'
    
print(judge)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const char INF = '9' + 1;
int main(){
  int n;
  string data[50];
  string temp[50];
  string tmp;
  string junban[10];
  char minv;
  int m;
  int p[10] = {0};
  int i,j;
  cin >> n;
  for(i = 0;i < n;i++){
    cin >> data[i];
    temp[i] = data[i];
    junban[temp[i][1] - '0'] += temp[i][0];
  }
  
  for(i = 0;i < n - 1;i++){
    for(j = 0;j < n - i - 1;j++){
      if(temp[j][1] > temp[j + 1][1])swap(temp[j],temp[j + 1]);
    }
  }
  for(i = 0;i < n - 1;i++){
    cout << temp[i] << " ";
  }
  cout << temp[i] << endl;
  for(i = 0;i < n;i++){
    if(junban[temp[i][1] - '0'][p[temp[i][1] - '0']] != temp[i][0]){
      cout << "Not stable" << endl;
      break;
    }
    p[temp[i][1] - '0']++;
  }
  if(i == n)cout << "Stable" << endl;
  for(i = 0;i < 10;i++){
    p[i] = 0;
  }
  for(i = 0;i < n - 1;i++){
    minv = INF;
    for(j = i;j < n;j++){
      if(minv > data[j][1]){
	minv = data[j][1];
	m = j;
      }
    }
    swap(data[i],data[m]);
    cout << data[i] << " ";
  }
  cout << data[i] << endl;
  for(i = 0;i < n;i++){
    if(junban[data[i][1] - '0'][p[data[i][1] - '0']] != data[i][0]){
      cout << "Not stable" << endl;
      break;
    }
    p[temp[i][1] - '0']++;
  }
  if(i == n)cout << "Stable" << endl;
  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
const int MAXN=17;
long long a[MAXN][MAXN],score[1<<MAXN],dp[1<<MAXN];
int n;

int main(){
	cin>>n;
	for(int i=0;i<n;++i)
		for(int j=0;j<n;++j)
			cin>>a[i][j];
	for(int S=0;S<(1<<n);++S)
		for(int i=0;i<n;++i)
			for(int j=0;j<i;++j)
				if(S>>i&1 && S>>j&1) score[S]+=a[i][j];
	for(int S=1;S<(1<<n);++S)
		for(int k=S;k;k=(k-1)&S)
			dp[S]=max(dp[S],score[k]+dp[S^k]);
	cout<<dp[(1<<n)-1]<<endl;
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    string s;
    cin>>s;
    ll n = s.size();
    ll i;
    ll out[n+5] = {};
    ll cur = 0;
    FOR0(i, n)
    {
        out[i] = cur;
        if(s[i] == '<')
            cur++;
        else 
        {
            cur = 0;
        }
    }
    if(s[n-1] == '<')
        out[n] = cur;
    cur = 0;
    FORD(i, n-1, 0)
    {
        out[i+1] = MAX2(cur, out[i+1]);
        if(s[i] == '>')
            cur++;
        else
        {
            cur = 0 ;
        }
    }
    if(s[0] == '>')
        out[0] = MAX2(out[0], cur);
    ll ans = 0;
    FOR0(i, n+1)
        ans += out[i];
    cout<<ans<<endl;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

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

int main() {
	int N,M,a=0,t=0,ans=0;
  	cin>> N >> M;
  	int s[M];
  	int c[M];
  	int digit[N];
  	
  
  	for(int i=0;i<M;i++){
     	cin>>s[i];
      	cin>>c[i];
    }
  
  	for(int i=0;i<N;i++){
     	digit[i]=0; 
    }
  	
  	for(int i=0;i<M;i++){
     	digit[s[i]-1]=c[i]; 
    }
  	
  	for(int i=0;i<N;i++){
		ans+=digit[i];
      	ans*=10;
    }
  
  	for(int i=0;i<3;i++){
		if(digit[i]!=0){
         	a=1;
        }
  	}
  	if(a==0) ans=0;
  	
  
  	for(int i=0;i<M;i++){
		for(int j=0;j<M;j++){
         	if(s[i]==s[j]&&c[i]!=c[j]){
             	ans=-10; 
            }
        }
      	if(s[i]==1&&c[i]==0&&N!=1){
         	ans=-10; 
        }
      	if(s[i]==1){
         	t=1; 
        }
    }
  
  	if(t==0){
      if(N==1){
         	ans+=10; 
        }
      	if(N==2){
         	ans+=100; 
        }
        if(N==3){
			ans+=1000;
        }
     	 
    }
  	
  	
  
  for(int i=0;i<M;i++){
		for(int j=0;j<M;j++){
         	if(s[i]==s[j]&&c[i]!=c[j]){
             	ans=-10; 
            }
        }
      	if(s[i]==1 && c[i]==0&& N!=1){
         	ans=-10; 
        }
      	if(s[i]==1){
         	t=1; 
        }
    }
  
  	if(M==0){
     	if(N==1){
         	ans=0; 
        }
      	if(N==2){
         	ans=100; 
        }
        if(N==3){
			ans=1000;
        }
    }
  
  	
  	cout<<ans/10<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int ques1(int *p,int n){
    int dp[100001]; dp[2]=abs(p[2]-p[1]); dp[1]=0;
    for(int i=3;i<=n;i++){
      dp[i]=min(dp[i-1]+abs(p[i-1]-p[i]),dp[i-2]+abs(p[i-2]-p[i]));
    }
    cout<<dp[n];
}
int main() {
	int n;
	cin >> n;
	int p[n+1];
	p[0]=0;
	for(int i=1;i<=n;i++){
	    cin >> p[i];
	}
	ques1(p,n);
	return 0;
}

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

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


Measured memory_bytes: 256
<?php
$n=fgets(STDIN);
$a=explode(' ',fgets(STDIN));
$x=0;
for($i=0;$i<$n;$i++){
    $x|=$a[$i];
}
$ans=0;
while(!($x%2)){
    $x>>=1;
    $ans++;
}
echo $ans;
?>

Measured memory_bytes: 4728
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from collections import deque
from itertools import product
def resolve():
    m, n = map(int, input().split())
    si, sj = map(lambda x : int(x) - 1, input().split())
    ti, tj = map(lambda x : int(x) - 1, input().split())
    grid = [input() for _ in range(m)]

    queue = deque([(si, sj, 0)])
    dist = [[INF] * n for _ in range(m)]
    dist[si][sj] = 0
    while queue:
        i, j, d = queue.popleft()
        if d > dist[i][j]:
            continue
        for di, dj in product(range(-2, 3), repeat = 2):
            if di == dj == 0:
                continue
            ni, nj = i + di, j + dj
            if not (0 <= ni < m and 0 <= nj < n):
                continue
            if grid[ni][nj] == '#':
                continue
            dd = int(abs(di) + abs(dj) > 1)
            nd = dist[i][j] + dd
            if nd < dist[ni][nj]:
                dist[ni][nj] = nd
                if dd == 0:
                    queue.appendleft((ni, nj, nd))
                else:
                    queue.append((ni, nj, nd))


    ans = dist[ti][tj]
    if ans == INF:
        ans = -1
    print(ans)
resolve()

Measured memory_bytes: 133264
#include<stdio.h>
#include<string.h>
int main()
{
    char s[11], t[11], u[11];
    int a, b;

    scanf("%s %s %d %d %s", s, t, &a, &b, u);
    if(strcmp(s,u)==0)
        a--;
    else b--;
    printf("%d %d\n", a, b);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 200000
#define INF 10000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
    int a,b;
    cin>>a>>b;
    if((a+b)%2!=0){
        OUT("IMPOSSIBLE");
    }else{
        OUT((a+b)/2);
    }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
ll inf=1e10;

int main(){
  ll N,M;
  cin>>N>>M;
  ll ans(0);
  if (N-2>0&&M-2>0){
    cout << (N-2)*(M-2) << endl;
  }else{
    if (N==1&&M==1) cout << 1 << endl;
    else if (N==1&&M>=2) cout << M - 2 << endl;
    else if (M==1&&N!=2) cout << N - 2 << endl;
    else cout << 0 << endl;
  }
  return 0;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  ll ans=0;
  rep(i,n-1) ans+=i+1;
  cout<<ans<<endl;
  
}

Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main()
{
    int N,M,n,m;
    cin>>N>>M;
    n=N*(N-1)/2;
    m=M*(M-1)/2;
    if(N<=1){
        n=0;
    }
    if(M<=1){
        m=0;
    }
    cout<<n+m<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int H, A;
	cin >> H >> A;
	cout << (H+(A-1)) / A << endl;
}


Measured memory_bytes: 256
N, L = map(int, input().split())

ans = 0
if L+N-1 <= 0:
    for i in range(N-1):
       ans += L+i
elif L >= 0:
    for i in range(1, N):
        ans += L+i
else:
    for i in range(N):
        ans += L+i
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //ATTENTION: <a> must be sorted in advance

lng power(lng b, lng n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7


/*********** variables ************/
int N, M;
int cnt[51];
/**********************************/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        cnt[a]++;
        cnt[b]++;
    }
    FOR(i, 1, N) {
        cout << cnt[i] << endl;
    }
}


Measured memory_bytes: 256
#!/bin/bash

awk -M '\
function abs(x){
    x+=0;
    return x > 0 ? x : -x
}
NR==1{N=$1; M=$2}
END{
    MOD = int((1e9)+7)
    if(abs(N-M)>1){
        print 0;exit;
    }
    n=N;m=M;
    while(1){
        if(N==1&&M==1)break;
        if(N>1)n*=--N;
        if(M>1)m*=--M;
        n%=MOD
        m%=MOD
    }
    if($1==$2)print (n*m*2)%MOD
    else print (n*m)%MOD
}'


Measured memory_bytes: 4360
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    long n;
    cin >> n;
    long ans = 0;
    vector<long> a(n+1,0); 
    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j+=i) a[j]++;
    }
    for(int i=1;i<=n;i++) ans += i*a[i];
    cout << ans << endl;
}


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

int main() {
	int N, X;
	cin >> N >> X;
	int ret = N;
	int mi = 10001;
	int m;
	for (int i = 0; i < N; i++) {
		cin >> m;
		X -= m;
		mi = min(m, mi);
	}
	while (X - mi >= 0)X -= mi, ret++;
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
def abc050_b():
    number_of_problem = int(input())
    time_to_solve_list = [int(i) for i in input().split()]
    sum_of_solve_list = sum(time_to_solve_list)
    
    variety_of_drinks = int(input())

    problem_vs_time = []

    for _ in range(variety_of_drinks):
        buf = list(map(int, input().split()))
        problem_num = buf[0] - 1
        time_to_solve = buf[1]

        problem_vs_time.append([problem_num, time_to_solve])

    for key, value in problem_vs_time:
        print(sum_of_solve_list + value - time_to_solve_list[key])


if __name__ == '__main__':
    abc050_b()


Measured memory_bytes: 3064
import java.util.Scanner;
public class Main{
	int x;
	public void solve(){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		System.out.println(x *=x *=x);
		
	
	}
	
	public static void main(String[] args){
		Main obj = new Main();
		obj.solve();	
	}
}

Measured memory_bytes: 17156
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(l);
            int ans = 0;
            for (int i = 0; i < n; i++)
            {
                ans += l[i * 2];
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 3032
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	ll N,K,Q; cin >> N >> K >> Q;
	vector<ll> A(Q);
	rep(i,Q) cin >> A[i];

	vector<ll> B(N);
	rep(i,Q) {
		--A[i];
		B[A[i]]++;
	}

	rep(i,N) {
		B[i] += K - Q;
		if (B[i] > 0) cout << "Yes" << ln;
		else cout << "No" << ln;
	}
}


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

int main(){
  int n;
  cin >>n;
  int curMax = 0;
  int ans = 0;
  rep(i,n){
    int a,b;
    cin >>a >>b;
    if(a>curMax) {
      curMax = a;
      ans = a+b;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
  ll N;
  cin>>N;
  ll a[3*N];
  FOR(i,0,3*N-1){
    cin>>a[i];
  }
  ll ans=0;
  sort(a,a+3*N);
  FOR(i,0,N-1){
    ans+=a[3*N-2-i*2];
  }

  cout <<ans<<endl;

  return 0;
}
 


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define PI 3.141592653589793
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vvll G(N, vll(0));
  vector<Pll> edge(N-1);
  for(int i = 0; i < N-1; i++){
    ll a, b;
    cin >> a >> b;
    a--; b--;
    G.at(a).push_back(b); G.at(b).push_back(a);
    edge.at(i) = Pll(a, b);
  }
  vll c(N);
  ll sum = 0LL;
  for(int i = 0; i < N; i++){
    cin >> c.at(i);
    sum += c.at(i);
  }
  sort(ALL(c), greater<ll>());
  sum -= c.at(0);

  queue<ll> que;
  vll num(N, -INF);

  que.push(0);
  int counter = 0;
  num.at(0) = c.at(counter);
  counter++;

  while(!que.empty()){
    ll v = que.front();
    que.pop();
    for(int i = 0; i < G.at(v).size(); i++){
      ll next = G.at(v).at(i);
      if(num.at(next) != -INF) continue;
      num.at(next) = c.at(counter);
      counter++;
      que.push(next);
    }
  }
  cout << sum << endl;
  for(int i = 0; i < N; i++){
    cout << num.at(i);
    if(i == N-1) cout << endl;
    else cout << ' ';
  }
}


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

typedef long long ll;

int main() {
	int n; cin >> n;
	vector<int>tak(n), aok(n);
	ll T, A; T = A = 1;
	for (int i = 0; i < n; i++) {
		cin >> tak[i] >> aok[i];
		ll tmp = max(((T + tak[i] - 1) / tak[i]), (A + aok[i] - 1) / aok[i]);
		T = tak[i] * tmp, A = aok[i] * tmp;
	}
	cout << A + T << endl;

	return 0;
}

Measured memory_bytes: 256
N=gets.to_i
array=gets.chomp.split(" ").map(&:to_i).sort
MAX_A=array[-1]
MEMO=Array.new(MAX_A+1,0)
array.each do |a|
    next if MEMO[a] == 2
    if MEMO[a] == 1
        MEMO[a]=2
        next
    end
    MEMO[a]=1
    e=2
    while a*e <= MAX_A+1 do
        MEMO[a*e]=2
        e+=1
    end
end
puts array.select{|a| MEMO[a]==1 }.length


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

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int  MOD=1000000007;
const int  INF= int(1e9);
const int  MAX= int(1e5) + 7;

int a[MAX], b[MAX], c[MAX], dp[MAX][3];

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;

    for( int i = 0 ; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for(int day = 1; day < n ; day++) {
        for(int prev = 0 ; prev < 3 ; prev++) {
            for(int cur = 0 ; cur < 3 ; cur++) {
                if( prev != cur) {
                    int current = dp[day-1][prev];
                    if(cur == 0) {
                        dp[day][cur] = max(dp[day][cur],a[day] + current);
                    } else if ( cur == 1) {
                        dp[day][cur] = max(dp[day][cur],b[day] + current);
                    } else {
                        dp[day][cur] = max(dp[day][cur],c[day] + current);
                    }
                }
            }
        }
    }

    int res = 0;
    for(int i = 0 ; i < 3 ; i++) {
        res=max(res,dp[n-1][i]);
    }
    cout<<res<<"\n";
    return 0;
}



Measured memory_bytes: 2560
#include <iostream>
using namespace std;
int ans,n,s;
void solve(int n, int s, int m){
    if(n==0 && s==0){
        ans++;
        return;
    }
    for(int i=m; i<10 && n>0; i++){
        if(s-i>=0) solve(n-1, s-i, i+1);
    }
}


int main(void){
    while(1){
        ans=0;
        cin>>n>>s;
        if(n==0 && s==0) break;
        solve(n,s,0);
        cout<<ans<<endl;
    }
}



Measured memory_bytes: 3120
class Factorials:
    def __init__(self, n=10**6, mod=10**9 + 7):
        self.mod = mod

        # self.fac[i] ≡ i! (factorial:階乗)
        self.fac = [1]
        num = 1
        for i in range(1, n+1):
            num *= i
            num %= mod
            self.fac.append(num)

        # self.rec[i] ≡ 1 / i! (reciprocal:逆数)
        num = pow(num, mod-2, mod)
        self.rec = [1 for i in range(n+1)]
        self.rec[n] = num
        for i in range(n-1, 0, -1):
            num *= i + 1
            num %= mod
            self.rec[i] = num

    # comb(n, r) ≡ nCr
    def comb(self, n, r):
        return self.fac[n] * self.rec[r] * self.rec[n - r] % self.mod
    
    # perm(n, r) ≡ nPr
    def perm(self, n, r):
        return self.fac[n] * self.rec[n-r] % self.mod

    # fact(n) ≡ n!
    def fact(self, n):
        return self.fac[n]

mod = 10**9 + 7
s = int(input())

fct = Factorials(s, mod)

ans = 0
for i in range(3, s+1, 3):
    ans += fct.comb(s - i + i//3 - 1, s - i)
    ans %= mod

print(ans)

Measured memory_bytes: 65180
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

w=list(ss())
a=Counter(w)
ans=0
for i in a.values():
    if i%2==0:
        ans+=1
if ans == len(list(set(w))):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 66924
X=int(input())
dp=[True]*(10**5+10000)
dp[0]=False
dp[1]=False
for i in range(2,len(dp)):
  if dp[i]:
    for j in range(i*2,len(dp),i):
      dp[j]=False
      
for i in range(X,len(dp)):
  if dp[i]:
    print(i)
    break


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  int n;cin >> n;
  vector<int> a(n);
  for(auto &i:a){
    cin >> i;
  }
  int now=1,c=0;
  for(;;){
    if(now==2){
      cout << c << endl;
      return 0;
    }
    if(c>=n){
      cout << -1 << endl;
      return 0;
    }
    c++;
    now=a[now-1];
  }
}


Measured memory_bytes: 640
#include <bits/stdc++.h> 
using namespace std; 
typedef long long ll; 
const int N = 2e5+5;

ll a[N],b[N];

int main()
{	
	ll n,m,x,k;
	scanf("%lld%lld%lld",&n,&m,&k);
	a[0] = b[0] = 0;
	
	for(int i = 1;i <= n;++i) scanf("%lld",&x),a[i] = a[i-1] + x;
	for(int i = 1;i <= m;++i) scanf("%lld",&x),b[i] = b[i-1] + x;
	
	ll res,num,ans = 0;
	for(int i = 1;i <= n;++i){
		if(a[i] > k){
			num = 0;
			res = k;
		}
		else{
			num = i;
			res = k-a[i];
		}
		
		ll pos = lower_bound(b+1,b+m+1,res)-b;
		while((b[pos] > res && pos > 0) || pos > m) pos--;
		ans = max(ans,num+pos);
	}
	for(int i = 1;i <= m;++i){
		if(b[i] > k){
			num = 0;
			res = k;
		}
		else{
			num = i;
			res = k-b[i];
		}
		
		ll pos = lower_bound(a+1,a+n+1,res)-a;
		while((a[pos] > res && pos > 0) || pos > n) pos--;
		ans = max(ans,num+pos);
	}
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 6940
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <tuple>
# include <functional>
# include <utility>
# define INF 1000000000
# define MOD 1000000000+7
using namespace std;

int main() {
	int a, b;
	while (cin >> a >> b) {
		cout << a + b << endl;
	}
}

Measured memory_bytes: 2960
#include <bits/stdc++.h>
using namespace std;
int main() {
  string w, t;
  int result = 0;
  cin >> w;
  while(1) {
    cin >> t;
    if (t == "END_OF_TEXT") break;
    for (int i = 0; i < t.size(); i++) {
      if (isupper(t[i])) {
        t[i] = tolower(t[i]);
      }
    }
    if (w == t) {
      result++;
    }
  }
  cout << result << endl;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string ans = "Three"; 
  for (int i = 0; i < N; i++) {
    char w;
    cin >> w; 
  if(w == 'Y') ans = "Four"; 
  }
  cout << ans << endl; 
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import numpy as np
input = sys.stdin.readline
n=int(input())
Z = [chr(i) for i in range(97, 97+26)]
ans = ""
def div(k):
    k ,mod = divmod(k, 26)

    global ans
    ans += Z[mod-1]
    if mod == 0:
        return k-1
    else:
        return k


for i in range(20):
    n = div(n)
    if n == 0 and len(ans)==1:
        print(ans)
        sys.exit()

    elif n ==0 :
        print(ans[::-1])
        sys.exit()

sys.exit()
    

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

int n,A[50];

int solve(int i,int m){
    if(m==0) return 1;
    if(i>=n) return 0;
    int res=solve(i+1,m) || solve(i+1,m-A[i]);
    return res;
}

int main(){
    int q,s;
    cin>>n;
    for(int i=0;i<n;i++) cin>>A[i];
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>s;
        if(solve(0,s)) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3076
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
using ll = long long;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int k, ans = 0;
	cin >> k;
	if (a >= b && a >= c)ans = a * pow(2, k) + b + c;
	else if (b >= a && b >= c)ans = b * pow(2, k) + a + c;
	else ans = c * pow(2, k) + a + b;
	cout << ans << endl;
}


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

int main() {
  vector<vector<int>> a(3,vector<int>(3));
  for (int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> a[i][j];
    }
  }
  int n;cin>>n;
  vector<int> tate(3);
  vector<int> yoko(3);
  vector<int> naname(2);
  int ans=0;
  int tmp;
  for(int k=0;k<n;k++){
    cin >> tmp;
    for (int i=0;i<3;i++){
      for(int j=0;j<3;j++){
        if(tmp == a[i][j]){
          tate[i]++;
          yoko[j]++;
          if(i==j){
            naname[0]++;
            if(naname[0]==3)ans++;
          }
          if(i==(2-j)){
            naname[1]++;
            if(naname[1]==3)ans++;
          }
          if(tate[i]==3)ans++;
          if(yoko[j]==3)ans++;
        }
      }
    }
  }
  
  if(ans>0){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 256
a, b, n = map(int, input().split())
# for x in range(n + 1):
#     t1 = (a * x) // b
#     t2 = a * (x // b)
#     print(t1 - t2)
# print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")

if a <= b:
    if n >= b - 1: print(a - 1)
    else:
        x = n - 1
        t1 = (a * x) // b
        t2 = a * (x // b)
        print(t1 - t2)
else:
    ans = -1
    for x in range(min(n + 1, a + 1)):
        t1 = (a * x) // b
        t2 = a * (x // b)
        ans = max(ans, t1 - t2)
    print(ans)

Measured memory_bytes: 9144
#include <iostream>

using namespace std;

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

    int cost_l = 0;
    int cost_r = 0;
    for(int i = 0; i < M; ++i)
    {
        int Ai;
        cin >> Ai;
        if(Ai < X) cost_l++;
        if(Ai > X) cost_r++;
    }
    cout << min(cost_l, cost_r) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }


int main(int argc, char const *argv[]) {
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];

  vector<vector<int>> cnt(h,vector<int>(w));

  rep(i,h){
    vector<int> done(w);//既に見たかどうか
    rep(j,w){
      if(s[i][j]=='#') continue;
      if(done[j]) continue;
      int l=0;//連続して光が当たるマス数
      while(j+l<w){//はみ出ない
        if(s[i][j+l]=='#')break;//障害にぶつかったらオワリ
        l++;
      }
      rep(k,l){
        cnt[i][j+k]+=l;
        done[j+k]=1;//もう見たことに
      }
    }
  }

  rep(j,w){
    vector<int> done(h);//既に見たかどうか
    rep(i,h){
      if(s[i][j]=='#') continue;
      if(done[i]) continue;
      int l=0;
      while(i+l<h){
        if(s[i+l][j]=='#')break;
        l++;
      }
      rep(k,l){
        cnt[i+k][j]+=l;
        done[i+k]=1;
      }
    }
  }
  int ans=0;
  rep(i,h) rep(j,w) ans=max(ans,cnt[i][j]-1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 20096
import sys

input = sys.stdin.readline


def main():
    b = input().rstrip()

    if b == "A":
        ans = "T"
    elif b == "T":
        ans = "A"
    elif b == "G":
        ans = "C"
    else:
        ans = "G"

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9100
#include <iostream>
#include <vector>

using namespace std;

typedef long long   ll;
typedef long double ld;

#define rep(i, n)      for (int i = 0; i < (int)(n); ++i)
#define rep3(i, m, n)  for (int i = (m); i < (int)(n); ++i)
#define rrep(i, n)     for (int i = (int)(n)-1; i >= 0; --i)
#define rrep3(i, m, n) for (int i = (int)(n)-1; i >= (m); --i)

#define endl '\n'
#define INF  0x7f7f7f7f7f7f7f7f
#define INFi 0x7f7f7f7f


ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll solve(int N, ll D, const vector<ll> & X, const vector<ll> & Y) {
  ll res = 0;
  rep(i, N)
    if ((X[i]*X[i]+Y[i]*Y[i]) <= D*D) res++;
  return res;
}

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

  ll N;
  ll D;
  cin >> N;
  vector<ll> X(N), Y(N);
  cin >> D;
  rep (i, N) {
    cin >> X[i] >> Y[i];
  }

  auto ans = solve(N, D, X, Y);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5992
import scala.io.StdIn

object Main extends App {
  val out = new java.io.PrintWriter(System.out)
  val Array(n, m) = StdIn.readLine.split(" ").map(_.toInt)
  val city = Array.ofDim[Int](n+1)
  Iterator.continually(StdIn.readLine)
    .take(m)
    .map(_.split(" "))
    .foreach(e => {
      city(e(0).toInt) += 1
      city(e(1).toInt) += 1
    })

  city.tail.foreach(r => out.println(r))
  out.flush
}

Measured memory_bytes: 25544
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef long double lld;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define cerr if(true)cerr

template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
    out << "(" << p.first << ", " << p.second << ")";
    return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>
void print(const ContainerType<ValueType, Args...> &c)
{
    for (const auto &v : c)
        cout << v << ' ';
    cout << '\n';
}

void print() { cout << '\n'; }
template <typename T, typename... Args>
void print(T a, Args... args)
{
    cout << a << " ";
    print(args...);
}

lli llipower(lli x, lli y, lli p = LLONG_MAX)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli binarySearch(vector<int> arr, int l, int r, int x)
{
    if (r >= l)
    {
        lli mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}

//---------------------------------------------------------------------------------

int main()
{
    // int t,tt;
    // cin >> t;
    // tt=t;
    // while (t--)
    // {
    //     int n;
    //     cin>>n;
    //     vector<int> a(n);
    //     fori(n) cin>>a[i];
    //     vector<int> pref(n+1,0);
    //     int sumv=0;
    //     fori(n){
    //         sumv+=a[i];
    //         pref[i+1]=sumv;
    //     }
    //     vector<int> sqs;
    //     fori(10000){
    //         if(i*i<=10000099) sqs.pb(i*i);
    //     }
    //     int curr;
    //     int ans=0;
    //     for(int i=1;i<=n;i++){
    //         curr=pref[i];
    //         for(auto j:sqs){
    //             if(binarySearch(pref,0,n,pref[i]-j)!=-1 &&){
    //                 ans++;
    //                 cout<<i<<" "<<j<<endl;
    //             }
    //         }
    //     }

        
    //     cout<<"Case #"<<tt-t<<": "<<ans<<endl;
    // }
    string n;
    int k;
    cin>>k>>n;
    if(n.size()<=k) cout<<n<<endl;
    else{
        fori(k) cout<<n[i];
        cout<<"..."<<endl;
    }
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

ll h,w;
string c[302];
ll tab[302][302];
ll dp[302][302];
ll ans = 0;

int main(){
  cin >> h >> w;
  for(ll i = 0;i < h;i++){
    cin >> c[i];
  }
  // for(ll i = 0;i < h;i++){
  //   cerr << c[i] << endl;
  // }
  for(ll i = 0;i < w-1;i++){
    // l < r;
    for(ll j = 0;j <= h;j++){
      fill(tab[j],tab[j]+h+1,0ll);
    }
    for(ll j = 0;j <= h;j++){
      fill(dp[j],dp[j]+h+1,INF);
    }
    for(ll j = 0;j < h;j++){
      tab[0][j] = 0;
      for(ll k = j,l = 0;k < h;k++,l++){
        tab[l+1][k+1] = tab[l][k] + (c[l][i] == c[k][i+1]);
        // cerr << l << " " << k << " " << (ll)c[l][i] << " " << (ll)c[k][i+1] << endl;
      }
    }
    // l > r;
    for(ll j = 0;j < h;j++){
      tab[j][0] = 0;
      for(ll k = 0,l = j;l < h;k++,l++){
        tab[l+1][k+1] = tab[l][k] + (c[l][i] == c[k][i+1]);
      }
    }
    // for(ll j = 0;j <= h;j++){
    //   for(ll k = 0;k <= h;k++){
    //     cerr << tab[j][k] << " ";
    //   }
    //   cerr << endl;
    // }
    dp[h][h] = 0;
    for(ll i = h;i >= 0;i--){
      for(ll j = h;j >= 0;j--){
        if(i-1 >= 0) dp[i-1][j] = min(dp[i-1][j],dp[i][j]+tab[i][j]);
        if(j-1 >= 0) dp[i][j-1] = min(dp[i][j-1],dp[i][j]+tab[i][j]);
      }
    }
    // for(ll j = 0;j <= h;j++){
    //   for(ll k = 0;k <= h;k++){
    //     cerr << dp[j][k] << " ";
    //   }
    //   cerr << endl;
    // }
    ans += dp[0][0];
  }
  cout << ans << endl;

}


Measured memory_bytes: 1792
N, K = map(int, input().split())
a = list(map(int, input().split()))
ans = 10 ** 9
for i in range(len(a) - K + 1):
  l = a[i]
  r = a[i + K - 1]
  ans = min(ans, abs(l) + abs(r - l), abs(r) + abs(l - r))
print(ans)

Measured memory_bytes: 14252