akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9

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 N;
ll a[100010][3];

ll dp[100010][3];

int main(){
    int N; cin>>N;
    
    for(int i=0;i<N;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
        }
    }

    
    for(int i=0;i<N;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j==k) continue;
                chmax(dp[i+1][k], dp[i][j]+a[i][k]);
            }
        }
    }
    
    ll res=0;
    for(int j=0;j<3;j++) chmax(res,dp[N][j]);
    cout<<res<<endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <unordered_set>
#include <string>
#include <algorithm>
#include <math.h>

using namespace std;

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

	long long result = 0;
	result = pow((k-1), (n-1)) * k;

	cout << result << endl;

	// k * (k-1) * (k-1) * (k-1);
}

Measured memory_bytes: 384
N = int(input())
 
intervals = tuple(tuple(map(int,input().split())) for _ in range(N))
 
L = sorted((l for l,r in intervals))
R = sorted((r for l,r in intervals), reverse=True)
 
def helper(L,R,turn):
  x = 0
  cost = 0
  T = [L,None,R]
  while True:
    y = T[turn+1].pop()
 
    if turn*(y-x) < 0:
      cost += abs(x-y)
      x = y
    else:
      break
    turn *= -1
  cost += abs(x)
  return cost

print(max(helper(L.copy(), R.copy(), t) for t in (-1,1)))

Measured memory_bytes: 21648
n = int(input())
card_list = [input().split() for _ in range(n)]
for i in range(len(card_list)):
    card_list[i][1] = int(card_list[i][1])

sort_key = ["S", "H", "C", "D"]
answer = []

# 絵柄毎に処理
for i in range(len(sort_key)):
    target = []
    # 各絵柄のカード番号を収集
    for j in range(len(card_list)):
        if card_list[j][0] == sort_key[i]:
            target.append(card_list[j][1])

    # 持っていない番号を収集
    for j in range(1, 13 + 1):
        if j not in target:
            answer.append([sort_key[i], j])

[print(*answer[i]) for i in range(len(answer))]


Measured memory_bytes: 5612
#import random

q=int(input())
A=[]
for i in range(q):
    A.append(list(map(int,input().split())))
    A[i].sort()

#A=[]
#q=10000
#for i in range(q):
#    A.append([random.randint(1,1000000)]*2)
#    A.sort()
#print(A)

for i in range(q):
    a=A[i][0]
    b=A[i][1]
    if a==b :
        ans1=2*(a-1)
    elif a+1==b :
        ans1=2*a-2
    else :
        c=int((a*b-1)**0.5)+2
        while c*c>=a*b :
            c-=1
        #print("c "+str(c))
        if c*(c+1)>=a*b :
            ans1=2*c-2
        else :
            ans1=2*c-1

    print(ans1)


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

int main() {
  string s;
  cin >> s;
  bool f = false;
  if(s == "AKIHABARA") f = true;
  if(s == "KIHABARA") f = true;
  if(s == "AKIHBARA") f = true;
  if(s == "AKIHABRA") f = true;
  if(s == "AKIHABAR") f = true;
  if(s == "KIHBARA") f = true;
  if(s == "KIHABRA") f = true;
  if(s == "KIHABAR") f = true;
  if(s == "AKIHBRA") f = true;
  if(s == "AKIHBAR") f = true;
  if(s == "AKIHABR") f = true;
  if(s == "KIHBRA") f = true;
  if(s == "KIHBAR") f = true;
  if(s == "AKIHBR") f = true;
  if(s == "KIHABR") f = true;
  if(s == "KIHBR") f = true;
  if(f) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

int main() {
  string a,b,c;
  cin>>a>>b>>c;
  if(a.at(a.size()-1)==b.at(0) && b.at(b.size()-1)==c.at(0)){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;

int main()
{
    int N,K;
    cin>>N>>K;
    if(N%K==0)
    {
        cout<<0<<endl;
    }
    else
    {
        cout<<1<<endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  cout << n*(n+1)/2 << endl;
  return 0;
}


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

int main(){
    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<set<int>> is(26);
    rep(i,n) is[s[i]-'a'].insert(i);
    rep(qi,q){
        int ty;
        cin >> ty;
        if(ty==1){
            int i; char c;
            cin >> i >> c;
            --i;
            is[s[i]-'a'].erase(i);
            s[i] = c;
            is[c-'a'].insert(i);
        }else{
            int l, r;
            cin >> l >> r;
            --l;
            int ans = 0;
            rep(i,26){
                auto it = is[i].lower_bound(l);
                if(it!=is[i].end() && *it<r)++ans;
            }
            printf("%d\n", ans);
        }
    }
    return 0;
}

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

int main(){
  int k, s, ans = 0;
  cin >> k >> s;
  rep(x, k){
    rep(y, k){
      int z = s - x - y;
      if(0 <= z && z <= k){
        ans = ans + 1; 
      }
    }
  }
  cout << ans << endl;
}

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

int A[40],B[40],ary[40];
int main(){
	int W,N;
	cin>>W>>N;
	char hog[9];
	for(int i=1;i<=N;i++){
		cin>>hog;
		if(strlen(hog)==3){
			A[i]=hog[0]-'0';
			B[i]=hog[2]-'0';
		}
		else if(strlen(hog)==5){
			A[i]=(hog[0]-'0')*10+(hog[1]-'0');
			B[i]=(hog[3]-'0')*10+(hog[4]-'0');
		}
		else if(hog[1]=','){
			A[i]=(hog[0]-'0');
			B[i]=(hog[2]-'0')*10+(hog[3]-'0');
		}
		else{
			A[i]=(hog[0]-'0')*10+(hog[1]-'0');
			B[i]=hog[3]-'0';
		}
	}
	for(int i=1;i<=W;i++){
		ary[i]=i;
	}
	for(int i=1;i<=N;i++){
		swap(ary[A[i]],ary[B[i]]);
	}
	for(int i=1;i<=W;i++){
		cout<<ary[i]<<endl;
	}
	return 0;
}

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

int main()
{
	map<string, int> mp;
	mp["SAT"] = 1;
	mp["FRI"] = 2;
	mp["THU"] = 3;
	mp["WED"] = 4;
	mp["TUE"] = 5;
	mp["MON"] = 6;
	mp["SUN"] = 7;

	string s;
	cin >> s;

	cout << mp[s];
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPL(i,f,n) for(int i=f, i##_len=(n); i<i##_len; ++i)
typedef long long ll;

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

	int W,H,N;
	cin >> W >> H >> N;
	int xmin = 0, xmax = W, ymin = 0, ymax = H;
	REP(i, N) {
		int a, x,y;
		cin >> x >> y >> a;
		switch(a) {
			case 1:
				xmin = max(xmin, x);
				break;
			case 2:
				xmax = min(xmax, x);
				break;
			case 3:
				ymin = max(ymin, y);
				break;
			case 4:
				ymax = min(ymax, y);
				break;
		}
	}
	cout << max(0,ymax-ymin)*max(0,xmax-xmin) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():

    return

#B
def B():
    n,k = LI()
    h = LI()
    ans = 0
    for i in h:
        if i >= k:
            ans += 1
    print(ans)
    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    B()


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

int main()
{
    string s;
    cin >> s;
    while (!s.empty())
    {
        string str = s.substr(s.length() - 5, s.length());
        if (str == "dream" || str == "erase")
            s.erase(s.length() - 5, s.length());
        else
        {
            string str = s.substr(s.length() - 6, s.length());
            if (str == "eraser")
                s.erase(s.length() - 6, s.length());
            else
            {
                string str = s.substr(s.length() - 7, s.length());
                if (str == "dreamer")
                    s.erase(s.length() - 7, s.length());
                else
                {
                    cout << "NO" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll  long long int
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define rall(x)  (x).rbegin(),(x).rend()
#define tr(c,i) for(auto i :c)
#define pii pair< int,int >
#define Fast_IO() ios_base::sync_with_stdio(false);cin.tie(0)
#define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x,y) cout << x << " "<<y
const int MOD = 1000 * 1000 * 1000 + 7; // odd modulus
const int N = 100;
using namespace std;
clock_t time_p=clock();
void dem()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
int main()
{
    Fast_IO();
    ll l , r ;
    cin >> l >> r ;
    ll mn = 2018 ;
    for ( ll  i = l ; i <= min ( r , l + 2019 ) ; ++i )
    {
        for ( ll   j  = l  ;  j <= min ( r , l +2019 ) ; ++j)
        {   if ( i!= j)
            mn = min ( mn , (i % 2019 * j % 2019 )% 2019  ) ;

        }
    }

    cout << mn ;



    return 0 ;
}


Measured memory_bytes: 256
from fractions import gcd
from functools import reduce


def lcm(x, y):
    res = (x * y) // gcd(x, y)
    if 10 ** 9 < res:
        res = 0
    return res


def solve():
    N, M, *a = map(int, open(0).read().split())
    
    half_a = [ai // 2 for ai in a]
    half_lcm = reduce(lcm, half_a)
    
    for ai in half_a:
        if (half_lcm // ai) % 2 == 0:
            print(0)
            exit()
    
    if half_lcm == 0:
        ans = 0
    else:
        ans = (M // half_lcm) - (M // (2 * half_lcm))
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 16144
#include <stdio.h>

int main(){

  int n,m[100],p[100][100],k,l[100],i,j,a,x[100],num;

  while(scanf("%d",&n),n){

    for(i=0;i<n;i++){
      scanf("%d",&m[i]);
      for(j=0;j<m[i];j++){
	scanf("%d",&p[i][j]);
      }
    }

    scanf("%d",&k);

    for(i=0;i<k;i++)scanf("%d",&l[i]);


    num = 0;

    for(i=0;i<n;i++)x[i]=0;


    for(i=0;i<n;i++){
      for(j=0;j<m[i];j++){
	for(a=0;a<k;a++){
	  if(p[i][j]==l[a]){
	    x[i]++;
	    break;
	  }
	}
      }
      if(x[i]==k){
	if(num != 0){
	  num=0;
	  break;
	}else{
	  num=(i+1);
	}
      }
    }

    if(num == 0)printf("-1\n");
    else printf("%d\n",num);

  }


  return 0;

}
    

Measured memory_bytes: 652
#include<bits/stdc++.h>
using namespace std ;
int main(){
  int n;
  cin>>n;
  string s1,s2;
  cin>>s1>>s2;
  string s3 ;
  int j=0;
  int k=0;
  for(int i=0;i<2*n;i++){
      if(i%2==0) 
      {
          s3 = s3 + s1[k];
          k++;
      }
      if(i%2!=0) 
      {
          s3 = s3 + s2[j];
         j++;
      }
      
  }
  cout<<s3<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    COMinit();

    ll H, W, A, B;
    cin >> H >> W >> A >> B;

    ll ans = 0;
    Rep (i, H - A) {
        ans += COM(B-1+i, B-1) * COM(H-1+W-B-1-i, W-B-1) % MOD;
        ans %= MOD;
    }

    cout << ans << "\n";
}

Measured memory_bytes: 12160
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long int lli;
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
int main(void)
{
	int n, d, k=1;
	scanf("%d%d", &n, &d);
	while(1){
		n -= (2*d+1);
		if(n <= 0) break;
		k++;
	}
	printf("%d", k);
	return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {
	var n, m, q int
	fmt.Scan(&n, &m, &q)
	a := make([]int, q)
	b := make([]int, q)
	c := make([]int, q)
	d := make([]int, q)
	for i := 0; i < q; i++ {
		fmt.Scan(&a[i], &b[i], &c[i], &d[i])
	}
	result := 0
	for _, xs := range gen(n, m) {
		r := calc(xs, q, a, b, c, d)
		if r > result {
			result = r
		}
	}
	fmt.Println(result)
}

func gen(n int, m int) [][]int {
	result := make([][]int, 0, m)
	for i := 1; i <= m; i++ {
		result = append(result, []int{i})
	}
	for i := 2; i <= n; i++ {
		r := make([][]int, 0)
		for _, xs := range result {
			for i := xs[len(xs)-1]; i <= m; i++ {
				b := make([]int, 0, len(xs)+1)
				b = append(b, xs...)
				b = append(b, i)
				r = append(r, b)
			}
		}
		result = r
	}
	return result
}

func calc(xs []int, q int, a, b, c, d []int) (result int) {
	for i := 0; i < q; i++ {
		if xs[b[i]-1]-xs[a[i]-1] == c[i] {
			result += d[i]
		}
	}
	return result
}


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

using namespace std;

int N, dp[100009];
vector < int > v[100009];

void dfs (int nod)
{
    vector < int > h;
    for (auto it : v[nod])
        dfs (it), h.push_back (dp[it]);
    sort (h.rbegin (), h.rend ());
    for (int i=0; i<h.size (); i++)
        if (h[i] + i + 1 > dp[nod])
            dp[nod] = h[i] + i + 1;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=2; i<=N; i++)
{
    int t;
    scanf ("%d", &t);
    v[t].push_back (i);
}
dfs (1);
printf ("%d\n", dp[1]);
return 0;
}


Measured memory_bytes: 17024
INF=10**18

A=list(map(lambda x:ord(x)-48,list(input())))
B=list(map(lambda x:ord(x)-48,list(input())))

fl=False

for i in B:
	fl|=i

if fl==False:
	for i in A:
		if i:
			print("-1")
			exit(0)
	print("0")
	exit(0)

n=len(A)

bi=[]

for i in range(n):
	bi.append([0,0,i])
	for j in range(n):
		if B[(i-j)%n]:
			bi[i][0]=-j
			break
	for j in range(n):
		if B[(i+j)%n]:
			bi[i][1]=j
			break

bi.sort()

ans=INF

def Update(d):
	q=[]
	nr=max(0,d)
	for i in range(n):
		x=bi[i][2]
		if A[x]!=B[(x+d)%n]:
			q.append(bi[i][:2])
	ans=INF
	for i in q:
		ans=min(ans,2*(nr-min(0,min(d,i[0])))-abs(d))
		nr=max(nr,i[1])
	ans=min(ans,2*(nr-min(0,d))-abs(d))+len(q)
	return ans

for i in range(-n,n):
	ans=min(ans,Update(i))

print(ans)


Measured memory_bytes: 67556
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {long long int X;cin >> X;
            bool C = 0;
  for(int A = -200; A < 200; A++){
  for(int B = -200; B < 200; B++){
  if(pow(A, 5) - pow(B, 5) == X)
  {cout << A << " " << B;C = 1;}
}if(C)break;
}
}

Measured memory_bytes: 4016
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 100000000;
int main() {
	int N, M, R;
	cin >> N >> M >> R;
	int dis[210][210];
	vector<int>r(R);
	for (int i = 0; i < 200; i++) {
		for (int j = 0; j <200; j++) {
			if (i == j) dis[i][j] = 0;
			else dis[i][j] = INF;
		}
	}
	for (int i = 0; i < R; i++) {
		cin >> r[i];
		r[i]--;
	}
	for (int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--; 
		dis[a][b] = c;
		dis[b][a] = c;
	}
	for (int k = 0; k <N; k++) {
		for (int i = 0; i <N; i++) {
			for (int j = 0; j <N; j++) {
				dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
			}
		}
	}
	sort(r.begin(), r.end()); 
	int ans = INF;
	do {
		int sum = 0;
		for (int i = 0; i < R - 1; i++) {
			sum += dis[r[i]][r[i + 1]];
		}
		ans = min(ans, sum);	
	} while (next_permutation(r.begin(), r.end()));
	cout << ans << endl;

}


Measured memory_bytes: 384
import java.util.*;
import java.io.*;
public class Main
{
	public static void main(String args[]) throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=0;
		n=Integer.parseInt(br.readLine());
		String brr[]=br.readLine().split(" ");
		long arr[]=new long[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=Long.parseLong(brr[i]);
		}
		long ans=0;
		for(int i=1;i<n;i++)
		{
			if(arr[i-1]>arr[i])
			{
				ans+=Math.abs(arr[i]-arr[i-1]);
				arr[i]+=Math.abs(arr[i]-arr[i-1]);
			}
		}
		System.out.println(ans);
	}
}		

Measured memory_bytes: 61236
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()

const int N = 1010;
int a[N], n, k;

int main() {
  scanf("%d%d", &n, &k); 
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a + n);
  int ans = 0;
  for (int i = 0; i < k; i++) ans += a[i];
  printf("%d\n", ans);
}



Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
int n;
string s;

struct ewdata {
    int esum;
    int wsum;
};

int main() {
    cin >> n >> s;
    vector<ewdata> ewsum;
    for(int i = 0; i < n; ++i) {
        ewdata indata;
        if(i == 0) {
            if(s.at(i) == 'E') {
                indata.esum = 1;
                indata.wsum = 0;
            }else {
                indata.esum = 0;
                indata.wsum = 1;
            }
        }else {
            if(s.at(i) == 'E') {
                indata.esum = ewsum.at(i-1).esum + 1;
                indata.wsum = ewsum.at(i-1).wsum;
            }else {
                indata.wsum = ewsum.at(i-1).wsum + 1;
                indata.esum = ewsum.at(i-1).esum;
            }
        }
        ewsum.push_back(indata);
    }   

    int ewmin = 1e9+7;

    for(int i = 0; i < n; ++i) {
        int sum = 0;
        if(s.at(i) == 'E') {
            sum += ewsum.at(i).wsum;
            sum += ewsum.at(n-1).esum - ewsum.at(i).esum;
        }else {
            sum += ewsum.at(i).wsum-1;
            sum += ewsum.at(n-1).esum - ewsum.at(i).esum;
        }

        ewmin = min(ewmin, sum);
    }

    cout << ewmin << endl;
}

Measured memory_bytes: 6648
def main():
    n, k = map(int, input().split())
    ps = list(map(int, input().split()))
    e = [(1+p)/2 for p in ps]

    s = [0]
    for i in range(n):
        s.append(s[i]+e[i])

    ans = max([s[i+k] - s[i] for i in range(n-k+1)])
    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for (int i=0; i<n; i++) {
        int l;
        scanf("%d", &l);
        a[l-1] = i+1;
    }
    for (int i: a) {
        printf("%d ", i);
    }
    printf("\n");
}

Measured memory_bytes: 1152
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>

using namespace std;

int pos = 0;
vector<int> pre, in, post;

void reconstruct(int l, int r) {
    if(l >= r) return;
    int root = pre[pos++];
    int index = distance(in.begin(), find(in.begin(), in.end(), root));
    reconstruct(l, index);
    reconstruct(index+1, r);
    post.push_back(root);
}

void solve() {
    reconstruct(0, pre.size());
    vector<int>::iterator it;
    for(it = post.begin(); it != post.end(); it++) {
        printf("%d", *it);
        if(it != (post.end() - 1)) printf(" ");
    }
    printf("\n");
}

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

    int temp1, temp2;
    for(int i = 0; i < n; i++) {
        scanf("%d", &temp1);
        pre.push_back(temp1);
    }

    for(int i = 0; i < n; i++) {
        scanf("%d", &temp2);
        in.push_back(temp2);
    }
    solve();
    return 0;
}

Measured memory_bytes: 3260
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define per(i,a,b) for(int i=(b),i##_end=(a);i>=i##_end;--i)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;++i)
#define foe(i,a) for(__typeof(a.begin())i=a.begin();i!=a.end();++i)
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define Es(x,i) for(Edge *i=G[x];i;i=i->nxt)
typedef double ld;
typedef long long L;
typedef long double lf;
typedef unsigned int uint;
typedef unsigned long long uL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f,mo=1e9+7;
template<typename A,typename B>inline bool upmx(A&x,const B&y){return x<y?x=y,1:0;}
template<typename A,typename B>inline bool upmn(A&x,const B&y){return x>y?x=y,1:0;}
template<typename T>inline T gcd(T x,T y){for(;y;swap(x,y))x%=y;return x;}
inline int Pow(int a,int b,int p=mo){int r=1;for(;b;b>>=1,a=1ll*a*a%p)if(b&1)r=1ll*r*a%p;return r;}
#ifdef flukehn
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
const int N=3e5+11;
char s[N];
int n,f[N],g[N];
int F[N],G[N];
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>s+1;
	for(int i=1;i<=n;i++){
		f[i]=f[i-1]+(s[i]=='W');
		g[i]=g[i-1]+(s[i]=='E');
	}
	for(int i=n;i;i--){
		F[i]=F[i+1]+(s[i]=='W');
		G[i]=G[i+1]+(s[i]=='E');
	}
	int ans=n;
	for(int i=1;i<=n;i++){
		ans=min(ans,f[i-1]+G[i+1]);
	}
	cout<<ans;
}

Measured memory_bytes: 5376
program main
  implicit none
  integer(8) :: a, b

  read (*, *) a, b

  print "(i0)", ieor(xor_sum_0_n(a - 1), xor_sum_0_n(b))

  contains

  function xor_sum_0_n(n) result(res)
    integer(8), intent(in) :: n
    integer(8) :: res, i, d, k, q, m
    res = 0
    do d = 0, 60
      k = 2 ** d
      q = (n + 1) / (2 * k)
      m = modulo(n + 1, 2 * k)
      i = modulo(q * k + max(m - k, 0_8), 2_8)
      res = ieor(res, k * i)
    end do
  end function xor_sum_0_n
end program main


Measured memory_bytes: 384
#include <cstdio>
#include <utility>
#include <cctype>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;char c;while(isspace(c = gcu()));do{s+=c;}while(c=gcu(),c!=' '&&c!='\n'&&c!=EOF);return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H &&h, T... t){out(h);out(t...);}
template <typename... T> _OUTL(T... t){out(t...);outl();}
struct range{
	int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

long extGCD(long a, long b, long &x, long &y) {
	if (b == 0) {
		x = 1, y = 0;
		return a;
	}
	long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

int main() {
	long a {in}, b {in}, x, y;
	extGCD(a, b, x, y);
	outl(x, ' ', y);
}


Measured memory_bytes: 2624
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A, B, C = map(int, readline().split())

    for n in range(1, B):
        if n * A % B == C:
            print('YES')
            return

    print('NO')
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9168
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;

int n;
double x[100010], y[100010];
char d[100010];

double f(double t){
    vector<double> tx(n), ty(n);
    rep(i, n){
        tx[i] = x[i];
        ty[i] = y[i];
        if(d[i] == 'L') tx[i] -= t;
        if(d[i] == 'R') tx[i] += t;
        if(d[i] == 'U') ty[i] += t;
        if(d[i] == 'D') ty[i] -= t;
    }
    sort(tx.begin(), tx.end());
    sort(ty.begin(), ty.end());
    return (tx[n-1] - tx[0]) * (ty[n-1] - ty[0]);
}

int main(){
    scanf("%d", &n);
    rep(i, n) cin >> x[i] >> y[i] >> d[i];
    double high = 1e9;
    double low = 0;
    double m2 = high;
    double m1 = low;
    rep(i, 100){
        m1 = (high + low*2) / 3;
        m2 = (high*2 + low) / 3;
        if(f(m1) > f(m2)) low = m1;
        else high = m2;
    }
    printf("%.10f", min({f(low), f(m1), f(m2), f(high)}));
}

Measured memory_bytes: 3540
#include<stdio.h>
#define N 100

int main(){
  int Mtw[N][N];
  int i,j,n,utw,ktw,vtw;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++)Mtw[i][j]=0;
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&utw,&ktw);
    utw--;
    for(j=0;j<ktw;j++){
      scanf("%d",&vtw);
      vtw--;
      Mtw[utw][vtw]=1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j)printf(" ");
      printf("%d",Mtw[i][j]);
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2052
#!/usr/bin/ruby
#encoding: utf-8

# input
n = gets.to_i
d,x = gets.split.map(&:to_i)
a = Array.new(n)
(0..n-1).each do |i|
  a[i] = gets.to_i
end

ans = 0

(0..n-1).each do |i|
  ans += (d-1)/a[i]+1
end

puts ans + x

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
ll gcd(ll a, ll b){
  return b ? gcd(b, a%b) : a;
}

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  
  vector<ll> left(n+1, 0);
  vector<ll> right(n+1, 0);

  for(int i=0; i<n; i++) left[i+1]=gcd(left[i], a[i]);
  for(int i=n-1; i>=0; i--) right[i]=gcd(right[i+1], a[i]);

  int res=0;
  for(int i=0; i<n; i++){
    int l=left[i];
    int r=right[i+1];

    if(res<gcd(l,r)){
      res=gcd(l,r);
    }
  }
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 2560
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		a: usize,
		b: usize,
		c: usize,
		x: usize,
		y: usize,
	}

	// Cを買わない
	// 少ない方の枚数だけCを買う
	// 全部C

	let p1 = a*x + b*y;
	let p2 = if x >= y {
		c*y*2 + a*(x-y)
	}
	else {
		c*x*2 + b*(y-x)
	};
	let p3 = if x >= y {
		c*x*2
	}
	else {
		c*y*2
	};

	println!("{}", min(p1, min(p2, p3)));
}



Measured memory_bytes: 2172
//A
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define red(i,r,l) for(int i=r;i>=l;i--)
#define re(i,n) for(int i=0;i<n;i++)
#define db(x) cout<<#x<<"="<<(x)<<" "
#define el cout<<endl
#define PII pair<int, int>
#define PIII pair<PII, int>
#define c0 first
#define c1 second
using namespace std;
const int MXN = 100010;
int n;
int a[MXN], cnt[2] = {};

namespace solve
{
    int f[MXN] = {};
    bool judge()
    {
        if (n % 2 == 0)
        {
            return 0;
        }
        f[0] = 1;
        rep(i, 1, n)
        {
            if (a[i] & 1)
                rep(j, 1, i) if (a[j] & 1)
                    if ((i - j) % 2 == 0)
                        f[i] |= f[j - 1];
        }
        return f[n];
    }
    void solve()
    {
        if (judge())
        {
            puts("Yes");
        }
        else puts("No");
    }
}

int main()
{
    int ans = 0;
    cin >> n;
    rep(i, 1, n) cin >> a[i];
    rep(i, 1, n - 1)
        if (a[i] == i)
        {
            swap(a[i], a[i + 1]);
            ++ans;
        }
    if (a[n] == n)
    {
        swap(a[n], a[n - 1]);
        ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#define max(x, y) ((x)<(y) ? (y) : (x))
#define min(x, y) ((x)>(y) ? (y) : (x))
#define swap(type, x, y) do{ type t = x; x = y; y = t; }while(0)

void quick(long a[], long left, long right){
  long pl = left, pr = right, x = a[(left+right)/2];
  do{
    while(a[pl] > x)  pl++;
    while(a[pr] < x)  pr--;
    if(pl <= pr){
      swap(long, a[pl], a[pr]);
      pl++, pr--;
    }
  }while(pl <= pr);
  if(pl < right)  quick(a, pl, right);
  if(pr > left)   quick(a, left, pr);
}

int main(){
  int n;  scanf("%d", &n);
  long a[200005];
  for(int i=1; i<=n; i++)
    scanf("%ld", a+i);
  quick(a, 1, n);

  long ans = a[1], idx = 2, num = 1;
  while(n-1-num > 0){
    ans = ans + a[idx]*min(max(0, n-1-num), 2);
    idx++;
    num += 2;
  }
  printf("%ld\n", ans);
  return 0;
}


Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,a[114514],b[114514]={},cnt1=0,cnt2=0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
    b[a[i]-1]++;
  }
  sort(a,a+n);
  for(int i=0;i<a[n-1];i++){
    if(b[i]>=3){
      b[i]%=2;
      if(b[i]==0){
        b[i]=2;
      }
    }
    if(b[i]==1){
      cnt1++;
    }else if(b[i]==2){
      cnt2++;
    }
  }
  if(cnt2%2==1){
    cout << cnt1+cnt2-1 << endl;
  }else{
    cout << cnt1+cnt2 << endl;
  }
  return 0;
}


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

int main() {
  string S; cin >> S; // 入力文字列
  string R = "consonant"; // 計算結果 or vowel
  
  rep(i,S.size()){
    if (S.at(i)=='a'|| 
        S.at(i)=='e'|| 
        S.at(i)=='i'|| 
        S.at(i)=='o'|| 
        S.at(i)=='u') {
      R = "vowel";
    }
  }
  cout << R << endl;
}


Measured memory_bytes: 256
K = int(input())
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
sum=0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            sum += gcd(gcd(i,j),k)

print(sum)
# print(gcd(2,6))


Measured memory_bytes: 76748
use proconio::input;
use proconio::marker::Chars;
use std::cmp::{max, min};
const alpha: [char; 26] = [
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
    't', 'u', 'v', 'w', 'x', 'y', 'z',
];

const Alpha: [char; 26] = [
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
    'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
];
fn main() {
    input!(n: usize, m: usize, mut k: usize);
    input!(mut a: [usize; n]);
    input!(mut b: [usize; m]);
    let mut ans = 0;
    let mut sum1 = acc_sum(&a);
    let mut sum2 = acc_sum(&b);
    let mut j = m;
    for i in 0..n + 1 {
        if sum1[i] > k {
            break;
        }

        while sum2[j] > k - sum1[i] {
            j -= 1;
        }

        ans = max(ans, i + j);
    }

    println!("{}", ans);
}

fn acc_sum(v: &Vec<usize>) -> Vec<usize> {
    let n = v.len();
    let mut ret = vec![0; n + 1];
    for i in 0..n {
        ret[i + 1] = ret[i] + v[i];
    }
    ret
}


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

string s[3];

signed main(){
  rep(i,3)cin>>s[i];
  cout<<s[0][0]<<s[1][1]<<s[2][2]<<endl;
  return 0;
}


Measured memory_bytes: 764
# https://atcoder.jp/contests/arc097/tasks/arc097_b
class UnionFind:
    def __init__(self, elements):
        self.elements = elements

    def same(self, a, b):
        return self.find(a) == self.find(b)

    def find(self, a):
        parent = self.elements[a]
        if parent < 0:
            return a
        self.elements[a] = self.find(parent)
        return self.elements[a]

    def unite(self, a, b):
        a_parent = self.find(a)
        b_parent = self.find(b)

        # already same union
        if a_parent == b_parent:
            return

        self.elements[a_parent] += self.elements[b_parent]
        self.elements[b_parent] = a_parent


N, M = map(int, input().split())
P = list(map(int, input().split()))

union = UnionFind([-1 for _ in range(N)])
for _ in range(M):
    a, b = map(int, input().split())
    union.unite(a - 1, b - 1)

answer = 0
for i in range(N):
    answer += union.same(P[i] - 1, i)

print(answer)


Measured memory_bytes: 14452
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
	long long a,b,c,sum;
	scanf("%lld %lld",&a,&b);
	c = b;
	sum = 0;
	while(c)
	{
		sum++;
		c /= 10;
	}
	for(int i = 1;i <= sum;i++) a *= 10;
	c = a+b;
	a = sqrt(c);
	if(a*a==c) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define si(x) int(x.size())
const int mod=1000000007,MAX=500005;
const ll INF=1LL<<60;

vector<int> Zalgo(string S){
    vector<int> A(S.size());
    int c=0;
    for(int i=1;i<S.size();i++){
        if(i+A[i-c]<c+A[c]){
            A[i]=A[i-c];
        }else{
            int j=max(0,c+A[c]-i);
            while(i+j<S.size()&&S[j]==S[i+j]) j++;
            A[i]=j;
            c=i;
        }
    }
    A[0]=S.size();
    
    return A;
}

vector<int> d[MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S;cin>>S;
    int N=si(S);
    vector<int> dd;
    for(int i=1;i*i<=N;i++){
        if(N%i==0){
            dd.push_back(i);
            if(i*i!=N) dd.push_back(N/i);
        }
    }
    
    sort(all(dd));
    
    for(int a:dd){
        if(a==N){
            cout<<1<<endl;
            cout<<1<<endl;
            return 0;
        }
        bool check=true;
        
        for(int j=a;j<N;j+=a){
            if(S.substr(j,a)!=S.substr(0,a)) check=false;
        }
        if(check){
            if(a==1){
                cout<<N<<endl;
                cout<<1<<endl;
                return 0;
            }
            break;
        }
    }
    
    for(int i=1;i<=N;i++){
        for(int j=2;i*j<=N;j++){
            d[i*j].push_back(i);
        }
    }
    
    vector<int> A=Zalgo(S);
    reverse(all(S));
    vector<int> B=Zalgo(S);
    reverse(all(S));
    
    cout<<2<<endl;
    int ans=0;
    
    for(int i=1;i<N;i++){
        int a=i,b=N-i;
        bool ok=true;
        
        for(int k:d[a]){
            if(A[k]+k>=a) ok=false;
        }
        
        for(int k:d[b]){
            if(B[k]+k>=b) ok=false;
        }
        
        if(ok) ans++;
    }
    
    cout<<ans<<endl;
    
}


Measured memory_bytes: 60720
#include <stdio.h>

int main(void){

        int i,n;
        long int sum = 0;

        scanf("%d",&n);

        for(i=1;i<=n;i++){
                if(i%3 == 0){ 
                        sum += 0;
                }else if(i%5 == 0){ 
                        sum += 0;
                }else{
                        sum += i;
                }   
        }   
        printf("%ld\n",sum);
return 0;
}


Measured memory_bytes: 1736
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n):
  for j in range(i+1, n):
    left = l[j]-l[i]
    right = l[i]+l[j]
    ans += max(0, bisect_left(l, right) - (j+1))
print(ans)

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

void pattern01 (ll &H, ll &W, ll &ans) {
    ll Smin, Smax;
    Smin = (H / 3) * W;
    if ((H - H / 3) % 2 == 0) Smax = ((H - H / 3) / 2) * W;
    else Smax = ((H - H / 3) / 2 + 1) * W;
    ans = min(ans, Smax-Smin);
}

void pattern02 (ll &H, ll &W, ll &ans) {
    if (H % 2 == 0) {
        for (int i = 1; i * 2 <= W + 1; ++i) {
            ll Smin = min(H/2*(W-i), H*i);
            ll Smax = max(H/2*(W-i), H*i);
            ans = min(ans, Smax-Smin);
        }
    } else {
        for (int i = 1; i * 2 <= W + 1; ++i) {
            ll Smin = min(H/2*(W-i), H*i);
            ll Smax = max((H/2+1)*(W-i), H*i);
            ans = min(ans, Smax-Smin);
        }
    }
}

int main() {
    ll H, W;
    cin >> H >> W;
    ll ans = 10e10;
    if (H > 2) pattern01(H, W, ans);
    if (W > 2) pattern01(W, H, ans);
    pattern02(H, W, ans);
    pattern02(W, H, ans);
    cout << ans << endl;
}



Measured memory_bytes: 3596
#include<cstdio>
#include<iostream>

using namespace std;

struct Card{
    char suit;
    char value;
    bool operator==(Card& c){
        if(this->suit==c.suit && this->value==c.value){
            return true;
        }
        else{
            return false;
        }
    }
};


const int MAX=100;
const int N=36;

int main(void){
    void bubble(struct Card*,int);
    void select(struct Card*,int);
    void print(struct Card*,int);
    string isStable(struct Card*,struct Card*,int);
    
    Card c1[MAX],c2[MAX],ic[MAX];
    int n;
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>c1[i].suit>>c1[i].value;
    }
    for(int i=0;i<n;++i){
        c2[i]=c1[i];
        ic[i]=c1[i];
    }
    bubble(c1,n);
    select(c2,n);
    
    print(c1,n);
    cout<<isStable(ic,c1,n)<<endl;
    print(c2,n);
    cout<<isStable(ic,c2,n)<<endl;
    
    return 0;
}

void print(struct Card* c, int n){
    for(int i=0;i<n;++i){
        if(i) printf(" ");
        printf("%c%c",c[i].suit,c[i].value);
    }
    printf("\n");
    return;
}

void bubble(struct Card* c, int n){
    for(int i=0;i<n;++i){
        for(int j=n-1;j>=i+1;--j){
            if(c[j].value<c[j-1].value){
                Card tmp = c[j];
                c[j] = c[j-1];
                c[j-1] = tmp;
            }
        }
    }
    return;
}

void select(struct Card* c, int n){
    int k;
    Card tmp;
    for(int i=0;i<n;++i){
        k=i;
        for(int j=i;j<n;++j){
            if(c[j].value<c[k].value){
                k=j;   
            }
        }
        tmp = c[i];
        c[i] = c[k];
        c[k] = tmp;
    }
}

string isStable(struct Card* input, struct Card* output, int n){
    for(int i=0;i<n;++i){
        for(int j=i+1;j<n;++j){
            for(int a=0;a<n;++a){
                for(int b=a+1;b<n;++b){
                    if(input[i].value==input[j].value && input[i]==output[b] && input[j]==output[a]){
                        return "Not stable";
                    }
                }
            }
        }
    }
    return "Stable";
}



Measured memory_bytes: 3288
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include<math.h>
#include<stdio.h>


int main()
{
	
	int n;
	
	std::string a;
	std::cin >> n >> a;
	int b = (int)a.size();
	for (int i = 0; i < b; i++)
	{
		for (int f = 0; f < n; f++) {
			if (a[i] == 'Z')
			{
				a[i] = 'A';
			}
			else a[i]++;
		}
	}
	std::cout <<a << std::endl;
	
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int a[3],d=0;
 
scanf("%d %d %d",&a[0],&a[1],&a[2]);
 
for(int i=0;i<2;i++)
{
for(int j=1;j<=2;j++)
{
if(a[i]>a[j])
{
d=a[i];
a[i]=a[j];
a[j]=d;
}
}
}
printf("%d %d %d\n",a[0],a[1],a[2]);
return 0;
}

Measured memory_bytes: 1024
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import bisect
import sys
import logging
import heapq
logging.basicConfig(level=logging.DEBUG)

input = sys.stdin.readline

setrecursionlimit(1000000)

def main():
    S=input()

    A=[0]*(len(S)-1)
    mode="L"
    s=0
    b=0
    e=0
    l=0
    for i in range(len(S)):
        c=S[i]
        if mode=="L" and c==mode:
            mode="R"
            b=i-1
        elif mode=="R" and c==mode:
            mode="L"
            e=i-1

            calc(A,s,b,e)
            
            s=i
        elif c=="\n":
            e=i-1
            calc(A,s,b,e)

    print(*A)

def calc(A, s, b, e):
    l=e-s+1
    if l//2==0:
        A[b]=A[b+1]=l/2
    else:
        A[b]=(b-s)//2+(e-b)//2+1
        A[b+1]=l-A[b]

main()

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

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll x = min(N, B - 1);
  cout << (A * x) / B - A * (x / B) << endl;
}

Measured memory_bytes: 3584
using System;
class Program {
    static void Main(string[] args) {
        var input = Console.ReadLine().Split(' ');
        var n = int.Parse(input[0]);
        var a = int.Parse(input[1]);
        var b = int.Parse(input[2]);
        Console.WriteLine(n * a < b ? n * a : b);
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P; 
#define INF 100000000
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
   string s,t;
   cin>>s>>t;
   s=t+s;
   OUT(s);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
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++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

//まず愚直！！

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    ll ans = A * X + B * Y;
    if(X > Y) {
        ans = min(ans, 2 * C * X);
        ans = min(ans, 2 * C * Y + A * (X - Y));
    }
    else if(X == Y) {
        ans = min(ans, 2 * C * X);
    }
    else {
        ans = min(ans, 2 * C * Y);
        ans = min(ans, 2 * C * X + B * (Y - X));
    }
    cout << ans << endl;
	return 0;
}

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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int n; cin >> n;

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

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += a[i] - 1;
    }

    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

const int N=200005;
int n;
vector<array<int,2>> treea(4*N,{N,0});
vector<array<int,2>> treeb(4*N,{0,0});

void updatea(int idx,int l,int r,int pos,array<int,2> val)
{
    if(l==r) treea[idx]=val;
    else
    {
        int m=(l+r)/2;
        if(pos<=m) updatea(2*idx,l,m,pos,val);
        else updatea(2*idx+1,m+1,r,pos,val);
        treea[idx]=min(treea[2*idx],treea[2*idx+1]);
    }
}

array<int,2> querya(int idx,int l,int r,int ql,int qr)
{
    if(ql>qr) return {N,0};
    if(l==ql&&r==qr) return treea[idx];
    int m=(l+r)/2;
    return min(querya(2*idx,l,m,ql,min(qr,m)),querya(2*idx+1,m+1,r,max(ql,m+1),qr));
}

void updateb(int idx,int l,int r,int pos,array<int,2> val)
{
    if(l==r) treeb[idx]=val;
    else
    {
        int m=(l+r)/2;
        if(pos<=m) updateb(2*idx,l,m,pos,val);
        else updateb(2*idx+1,m+1,r,pos,val);
        treeb[idx]=max(treeb[2*idx],treeb[2*idx+1]);
    }
}

array<int,2> queryb(int idx,int l,int r,int ql,int qr)
{
    if(ql>qr) return {0,0};
    if(l==ql&&r==qr) return treeb[idx];
    int m=(l+r)/2;
    return max(queryb(2*idx,l,m,ql,min(qr,m)),queryb(2*idx+1,m+1,r,max(ql,m+1),qr));
}

void upd(int pos,array<int,2> val)
{
    updatea(1,1,n,pos,val);
    updateb(1,1,n,pos,val);
}

void rm(int pos)
{
    updatea(1,1,n,pos,{N,0});
    updateb(1,1,n,pos,{0,0});
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    vector<int> x(n+1,0);
    vector<int> y(n+1,0);
    vector<int> h(n+1,0);
    for(int i=1;i<=n;i++)
    {
        cin >> x[i] >> y[i];
        h[x[i]]=i;
        upd(x[i],{y[i],x[i]});
    }
    vector<int> res(n+1,0);
    vector<bool> vis(n+1,0);
    for(int i=1;i<=n;i++)
    {
        if(vis[i]) continue;
        vector<int> v={i};
        int idx=0;
        rm(x[i]);
        vis[i]=1;
        while(idx<(int)v.size())
        {
            int a=v[idx++];
            while(1)
            {
                auto [val,pos]=querya(1,1,n,1,x[a]-1);
                if(y[a]<val) break;
                v.push_back(h[pos]);
                vis[h[pos]]=1;
                rm(pos);
            }
            while(1)
            {
                auto [val,pos]=queryb(1,1,n,x[a]+1,n);
                if(y[a]>val) break;
                v.push_back(h[pos]);
                vis[h[pos]]=1;
                rm(pos);
            }
        }
        for(int a:v) res[a]=v.size();
    }
    for(int i=1;i<=n;i++) cout << res[i] << "\n";
    return 0;
}


Measured memory_bytes: 19868