akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000000000
#include <iomanip>
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
constexpr int MOD = 1000000007;

void print(const std::vector<int>& v)
{
  std::for_each(v.begin(), v.end(), [](int x) {
    std::cout << x << " ";
  });
  std::cout << std::endl;
}


ll modpow(ll a,ll p){
    if(p==0) return 1;
    if(p%2==0){
        ll halfp = p/2;
        ll half = modpow(a,halfp);
        return half * half % MOD;
    }else{
        return a * modpow(a,p-1) % MOD;
    }
}

ll calcComb(ll a,ll b){
    if (b > a-b){
        return calcComb(a,a-b);
    }
    ll ansMul = 1;
    ll ansDiv = 1;
    REP(i,b){
        ansMul *= (a - i);
        ansDiv *= (i + 1);
        ansMul %= MOD;
        ansDiv %= MOD;
    }
    ll ans = ansMul * modpow(ansDiv,MOD-2) ;
    ans %= MOD;
    return ans;
}

int main ()
{
    int R,G,B,N;
    cin>>R>>G>>B>>N;
    ll cnt = 0;
    REP(i,(int)N/R + 1){
        REP(j,(int)N/G + 1){
            ll res = N - i * R - G * j;
            if(res<0) break;
            if (res%B == 0){
                cnt++;
            }
        }
    }
    cout<<cnt<<endl;
    return 0;
}

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

using namespace std;

const int N = 200005;

int n, a[N], res[N];

int main(){
  scanf("%d", &n);
  for(int i = 1; i <= n; ++i){
    scanf("%d", &a[i]);
  }
  int now = 1, l = 1, r = n;
  for(int i = n; i >= 1; --i){
    if(now){
      res[l++] = a[i];
    }
    else{
      res[r--] = a[i];
    }
    now ^= 1;
  }
  for(int i = 1; i <= n; ++i){
    printf("%d%c", res[i], i == n ? '\n' : ' ');
  }
  return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[109], b[109];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
	int ret = 0;
	for (int i = 0; i < n; i++) {
		int sum = 0;
		for (int j = 0; j <= i; j++) sum += a[j];
		for (int j = i; j < n; j++) sum += b[j];
		ret = max(ret, sum);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

k = int(input())
ans = "ACL"*k
print(ans)

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	for (auto &u : v) os << u << el;
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N, K;
	string S;
	cin >> N >> K >> S;
	int cnt = 0;
	for (int i = 0; i < N-1; i++) {
		if (S[i] == S[i+1]) cnt++;
	}
	
	function<int(string)> calc = [&](string T) -> int {
		int i = 0, j = 0;
		int t = 0;
		int cn = 0;
		for (i = 0; i < N-1 && t < K; i++) {
			if (T[i] == 'L' && T[i+1] == 'R') {
				chmax(j, i+1);
				while (j < N-1 && (T[j] != 'R' || T[j+1] != 'L')) j++;
				if (j >= N-1) {
					if (T[N-1] == 'R') {
						cn++;
						t++;
					}
					continue;
				}
				cn += 2;
				j++, t++;
			}
		}
		return (cn);
	};

	int an = calc(S);
	for (int i = 0; i < N; i++) {
		if (S[i] == 'L') S[i] = 'R';
		else S[i] = 'L';
	}
	chmax(an, calc(S));
	cout << cnt + an << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 512
/*Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound’s the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s=="ABC")
        cout<<"ARC";
    else
        cout<<"ABC";
    cout<<endl;
}

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

int bs(int a) {
    int l = 0;
    int r = 3 * a;
    while (r - l > 1) {
        int m = (l + r) / 2;
        if (m * (m + 1) <= 2 * a) {
            l = m;
        } else {
            r = m;
        }
    }
    return l;
}

int main() {
    ll N;
    cin >> N;
    vector<ll> a;
    ll t = N;
    for (ll i = 2; i * i <= N; i++) {
        int k = 0;
        while (t % i == 0) {
            t /= i;
            k++;
        }
        if (k != 0) a.push_back(k);
    }
    int ans = 0;
    if (t != 1) ans = 1;
    for (int i : a) {
        ans += bs(i);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3608
sx, sy, tx, ty = map(int, input().split())

dx = tx - sx
dy = ty - sy

result = ''
result += 'R' * dx + 'U' * dy  # 1st Forth
result += 'L' * dx + 'D' * dy  # 1st Back
result += 'D' + 'R' * (dx + 1) + 'U' * (dy + 1) + 'L'  # 2nd Forth
result += 'U' + 'L' * (dx + 1) + 'D' * (dy + 1) + 'R'  # 2nd Back
print(result)


Measured memory_bytes: 3060
#import sys
#import numpy as np
import itertools
from scipy.sparse import csr_matrix, coo_matrix
from scipy.sparse.csgraph import dijkstra, bellman_ford
#sys.setrecursionlimit(10000)

N, M, R = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]

rows = []
cols = []
weights = []

for _ in range(M):
    # u v 間のコスト
    u, v, a = [int(i) for i in input().split()]
    rows.append(u-1)
    cols.append(v-1)
    weights.append(a)

graph = coo_matrix((weights, (rows, cols)), shape=(N, N)).tocsr()
d1 = dijkstra(graph, directed=False, unweighted=False)

ans = float("inf")
for i in list(itertools.permutations(r)):
    dist = 0
    for j in range(R-1):
        dist += d1[i[j]-1][i[j+1]-1]
    ans = min(ans, dist)

print(int(ans))

Measured memory_bytes: 22392
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector <int> a(n,0);
    bool isDenied = false;
    for(int i = 0; i<n; i++){
        cin >> a[i];
        if(a[i]%2==0){
            if(a[i]%3==0){
                continue;
            }
            if(a[i]%5==0){
                continue;
            }
            isDenied = true;
            break;
        }
    }
    if(isDenied==true){
        cout << "DENIED" <<endl;
    }else{
        cout << "APPROVED" <<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
 
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
 
a, b = input().split()
a = int(a)
b = int(float(b)*1000)
ans = a * b
print(ans // 1000)

Measured memory_bytes: 65556
#include<iostream>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define maxn 100005
#define LL long long
#define INF 0x3f3f3f3f
#define mset(p,v) memset(p,v,sizeof(p))
using namespace std;
int a[maxn],b[maxn];
int m,n,p;
int A,B,M,ans;
void init()
{
    ans=INF;
    int mina=INF;
    int minb=INF;
    for(int i=1;i<=A;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]<mina) mina=a[i];
    }

    for(int i=1;i<=B;i++)
    {
        scanf("%d",&b[i]);
        if(b[i]<minb) minb=b[i];
    }

    for(int i=1;i<=M;i++)
    {
        scanf("%d%d%d",&m,&n,&p);
        ans=min(ans,a[m]+b[n]-p);
    }
    ans=min(ans,mina+minb);
}
int main()
{
    while(~scanf("%d%d%d",&A,&B,&M))
    {
        init();
        printf("%d\n",ans);
    }
	return 0;
}


Measured memory_bytes: 1024
raw = input()
s = bin(int(raw, 2))
n = len(raw)
m = bin(int(''.join([str(i%2) for i in range(n)]),2))
 
a = bin((int(s,2))^int(m,2)).count("1")
b = n-a
 
print(a if a < b else b)

Measured memory_bytes: 9580
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ZYCSwing
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            if (n <= 999) {
                out.println("ABC");
            } else {
                out.println("ABD");
            }
        }

    }
}



Measured memory_bytes: 21332
///スマホコーディング
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
typedef long long ll;
const int inf=1e9;
int main(){
  vector<vector<char>> v(3);
  rep(i,3)rep(j,3){
    char c;cin>>c;
    v[i].emplace_back(c);
  }
  cout<<v[0][0]<<v[1][1]<<v[2][2]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int, int> pi;
#define PI 3.14159265359
long long mod=1000000007;
//int count=INT_MAX;

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};
string multiply(string A, string B) {
    reverse(A.begin(),A.end());
    reverse(B.begin(),B.end());
    string s(A.size()+B.size()+2,'0');
    int idx=0;
    s.push_back('0');
    for(int i=0;i<A.size();i++){
        int p=0,c=0;
        p=(int)(A[i]-'0')*(int)(B[0]-'0');
        p+=(int)(s[idx]-'0');
        c=p/10;
        p=p%10;
        s[idx]=p+'0';
        s[idx+1]=c+'0';
        idx++;
        
    }
    //cout<<"("<<s<<")";
    for(int i=1;i<B.size();i++){
        idx=i;
        int p=0,c=0;
        for(int j=0;j<A.size();j++){
            
            p=(int)(A[j]-'0')*(int)(B[i]-'0');
            p+=(int)(s[idx]-'0')+c;
            c=p/10;
            p=p%10;
            s[idx]=p+'0';
            //s[idx+1]=c+'0';
            idx++;
        }
        if(i==B.size()-1&&c!=0){
            s[idx]=c+'0';
        }
        else{
            s[idx]=c+'0';
        } 
    }
    int t;
    for(int i=s.size()-1;i>=0;i--){
        if(s[i]=='0'){
            s.erase(s.begin()+i);
        }
        else{
            break;
        }
    }
    if(s.size()==0) s.push_back('0');
    reverse(s.begin(),s.end());
    return s;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    //cin>>t;
    //scanf("%d",&t);
    
    for(int l=0;l<t;l++){
        int n;
        cin>>n;
        long long a[n];
        long long m=(long long)pow(10,18);
        //cout<<m;
        int z=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            if(a[i]==0) z=1;
        }
        
        long long ans=1;
        for(int i=0;i<n;i++){
            long long req=m/ans;
            if(m%ans!=0) req++;
            if(a[i]>req){
                ans=-1;
                break;
            }
            else{
                ans*=a[i];
            }
            if(ans>m){
                ans=-1;
                break;
            }
            //ans*=a[i];

        }
        if(z==1) cout<<"0";
        else if(ans>m) cout<<"-1";
        else cout<<ans;
    }
    
    return 0;
}

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

int main() {

	string S; cin >> S;
	int w; cin >> w;
	for (int i = 0; i < S.size(); i += w) {
		cout << S[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BC
import Data.Maybe

readIntsLine :: IO [Int]
readIntsLine = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

main :: IO ()
main = do
  [n, x] <- readIntsLine
  xs <- map (\a -> abs $ a - x) <$> readIntsLine
  print $ foldr gcd (head xs) (tail xs)

Measured memory_bytes: 3580
import java.util.*;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int ans = N * (N-1);
		ans += M * (M-1);
		System.out.println(ans/2);
	}
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll x; cin >> x;
  ll tmp1 = x / 500 * 1000;
  x %= 500;
  ll tmp2 = x / 5 * 5;
  cout << tmp1 + tmp2 << endl;

}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

typedef struct{
  char suit;
  int value;
}Card;

Card L[MAX/2+2],R[MAX/2+2];

void merge(Card *, int, int, int, int);
void mergeSort(Card *, int, int, int);
int partition(Card *, int, int, int);
void quickSort(Card *, int, int, int);

int main(){
  int n, i, v;
  Card A[MAX],B[MAX];
  char S[10];
  int stable=1;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s %d",S,&v);
    A[i].suit=B[i].suit=S[0];
    A[i].value=B[i].value=v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++)
    if(A[i].suit!=B[i].suit)
      stable=0;

  if(stable==1)
    printf("Stable\n");
  else
    printf("Not stable\n");
  for(i=0;i<n;i++)
    printf("%c %d\n",B[i].suit,B[i].value);

  return 0;
}

void merge(Card A[], int n, int left, int mid, int right)
{
  int i, j, k;
  int n1, n2;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++)
    L[i]=A[left+i];
  for(i=0;i<n2;i++)
    R[i]=A[mid+i];
  L[n1].value=R[n2].value=SENTINEL;
  i=j=0;
  for(k=left;k<right;k++){
    if(L[i].value<=R[j].value)
      A[k]=L[i++];
    else
      A[k]=R[j++];
  }
}

void mergeSort(Card A[], int n, int left, int right)
{
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int partition(Card A[], int n, int p, int r)
{
  int i, j;
  Card tmp, x;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j].value<=x.value){
      i++;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;
  return i+1;
}

void quickSort(Card A[], int n, int p, int r)
{
  int q;
  if(p<r){
    q=partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}
      
  



Measured memory_bytes: 4040
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <algorithm>
#include <limits>
#include <numeric>

#define REP(i,n) for(int i=0;i<(int)n;++i)

int sum(std::vector<int>&x, int a) {
  int result=0;
  for (int i = 0; i < (int)x.size(); i++) {
    result += std::pow(x[i]-a, 2);
  }
  return result;
}

int main() {
  int N;
  std::cin >> N;
  std::vector<int> a(N);

  for (int i = 0; i < N; i++) {
    std::cin >> a[i];
  }

  int sum_floor = std::floor((double)std::accumulate(a.begin(), a.end(), 0) / N);
  int sum_ceil = std::ceil((double)std::accumulate(a.begin(), a.end(), 0) / N);
  
  int result = std::min(sum(a, sum_floor), sum(a, sum_ceil));

  std::cout << result << std::endl;
  return 0;
}


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

typedef unsigned long long ll;

int main()
{
    int n;
    ll x;
    int i,j;
    cin >> n >> x;
    vector<ll> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    ll ans = 0;
    for(i = 0;i < n-1;++i){
        if((a.at(i)+a.at(i+1)) > x){
            ans += a.at(i)+a.at(i+1)-x;
            a.at(i+1) -= min(a.at(i)+a.at(i+1)-x,a.at(i+1));
            a.at(i) -= a.at(i)+a.at(i+1)-x-min(a.at(i)+a.at(i+1)-x,a.at(i+1));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

#define MAX 10000
#define NIL -1

struct Node {int p, l, r;};
struct Node T[MAX];
int n;

void preParse(int u) {
  if(u == NIL) return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u) {
  if(u == NIL) return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

void postParse(int u) {
  if(u == NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(void) {
  int i, v, l, r, root;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    T[i].p = NIL;
  }
  
  for(i=0; i<n; i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }
  
  for(i=0;i<n;i++) if(T[i].p == NIL) root = i;
  
  printf("Preorder\n");
  preParse(root);
  printf("\n");

  printf("Inorder\n");
  inParse(root);
  printf("\n");

  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}


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

int main() {
  string o, e; cin >> o >> e;
  
  for (int i = 0; i < e.size(); ++i) cout << o[i] << e[i];
  if (o.size() != e.size()) cout << o[o.size() - 1];
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}


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

  string s;
  cin >> s;
  rep(i,s.size()){
    cout << s[i] ;
    if(i==3)cout << " " ;
  }
  cout  << endl;

  
  return 0;
}


Measured memory_bytes: 256
import math
abc = list(map(int, input().split()))
abc.sort()
a, b, c = abc
if a % 2 == 0 or b % 2 == 0 or c % 2 == 0:
    print(0)
else:
    print(a * b * (math.ceil(c/2) - math.floor(c/2)))


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

int main(){
	int N,X,min=1001,count;
	cin >> N >> X;
	int m[N];
	for(int i=0;i<N;i++){
		cin >>m[i];
		X=X-m[i];
		if(min>m[i]){
			min=m[i];
		}
	}
	count=X/min;
	cout << (count+N) <<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
  int n,k;
  cin >> n;
  cin >> k;
  int a = n;
  int count =0;
  while(a != 0){
    a /= k;
   count ++;
  }
  cout << count << endl;
  
  return 0;
}

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

using namespace std;

int main(){
  typedef long long int ll;
  ll N,sum = 0;
  cin >> N;
  for(ll i = 1; i < N+1; i++){
    if(i%5 != 0 && i%3 != 0){sum += i;}
  }
  

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

i64 pow(i64 x, i64 n, i64 m) {
	i64 ret = 1;
	while(n) {
		if(n & 1) (ret *= x) %= m;
		(x *= x) %= m;
		n >>= 1;
	}
	return ret;
}

i64 inv(i64 n, i64 m) {
	return pow(n, m - 2, m);
}

int main() {
	i64 n, m; scanf("%lld%lld", &n, &m);

	i64 N = 1;
	for(i64 i = 1; i <= 3 * n; i++) N = N * i % m;

	std::vector<int> tan(3 * n + 1);
	for(i64 i = 0; i < tan.size(); i++) tan[i] = inv(i, m);

	int offset = 3 * n;
	auto dp = make_v<int>(3 * n + 1, 6 * n + 1); dp[0][offset] = N;
	for(int i = 0; i < 3 * n; i++) {
		for(int j = 0; j < 6 * n; j++) {
			i64 from = dp[i][j];
			if(!from) continue;
			
			if(i + 1 <= 3 * n) (dp[i + 1][j + 1] += from * tan[i + 1] % m) %= m;
			if(i + 2 <= 3 * n)(dp[i + 2][j - 1] += from * tan[i + 2] % m) %= m;
			if(i + 3 <= 3 * n)(dp[i + 3][  j  ] += from * tan[i + 3] % m) %= m;
		}
	}

	i64 ans = 0;
	for(int i = offset; i < 6 * n + 1; i++) (ans += dp[3 * n][i]) %= m;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 281856
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

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

    cout << N*N*N << endl;
}

Measured memory_bytes: 3560
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

class CGreenBin {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        ll n,ans=0,a;
        in>>n;
        string s;
        map<string,ll> m;
        set<string> st;
        fr(i,n){
            in>>s;
            sort(s.begin(),s.end());
            ++m[s];
            st.insert(s);
        }
        for(auto t:st) a=m[t],ans+=(a*(a-1))/2;
        out<<ans<<endl;
    }
};

int main() {
    CGreenBin solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 20608
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define double long double
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    int n, m, k;
    cin >> n >> m >> k;
    int a[n], b[m];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (i != 0)
            a[i] += a[i-1];
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
        if (i != 0)
            b[i] += b[i-1];
    }
    int l = 0, r = n + m;
    int ans = 0;
    while (l <= r) {
        int mid = (l + r) / 2;
        int mn = inf;
        for (int i = 0; i <= min(mid, n); i++) {
            int j = mid - i;
            if (j > m) continue;
            if (i == 0) mn = min(mn, b[j-1]);
            else if (j == 0) mn = min(mn, a[i-1]);
            else mn = min(mn, b[j-1] + a[i-1]);
        }
        if (mn <= k || mid == 0) {
            ans = mid;
            l = mid + 1;
        }
        else r = mid - 1;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

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

  return 0;
}

Measured memory_bytes: 3604
# coding: utf-8
# Your code here!
import sys
import collections
from operator import mul
from functools import reduce

def input():
    return sys.stdin.readline().rstrip()
    
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())
a = [''.join(sorted(input())) for _ in range(N)]
c = collections.Counter(a)
c_array = list(filter(lambda x: x >= 2, c.values()))
ctr = 0

for i in c_array:
    ctr += cmb(i, 2)
print(ctr)

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

#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((ll)((a) + (b) - 1)/(ll)(b))

signed main() {
    int h, w, k;
    cin >> h >> w >> k;
    
    vector<string> field(h);
    rep(i,h) cin >> field[i];
    
    int ans = 0;
    rep(i, 1 << h)rep(j, 1 << w){
        int t = 0;
        rep(y,h)rep(x,w){
            if((i >> y) & 1) continue;
            if((j >> x) & 1) continue;
            if(field[y][x] == '#') t++;
        }
        if(t == k) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
w, h, n = list(map(int, input().split()))
x_max = 0
x_min = w
y_max = 0
y_min = h

for i in range(n):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        x_max = max(x_max, x)
    elif a == 2:
        x_min = min(x_min, x)
    elif a == 3:
        y_max = max(y_max, y)
    else:
        y_min = min(y_min, y)
        
if x_max >= x_min or y_max >= y_min:
    print(0)
else:
    print((x_min - x_max) * (y_min - y_max))
        
        

Measured memory_bytes: 3064
N = int(input())
D = [int(x) for x in input().split()]
res = [0]*(max(D)+1)
for n in range(N):
    res[D[n]] += 1
if D[0] != 0 or res[0] != 1:
  print(0)
else:
  k = 1
  for n in range(1,max(D)+1):
    k *= pow(res[n-1],res[n],998244353)
  print(k%998244353)


Measured memory_bytes: 14396
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)


using namespace std;
using ll = long long;

int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n,m,sum=0;
    cin >> n >>m;
    rep(i,m)
    {
        ll a;
        cin >>a;
        sum +=a;
    }
    if(sum<=n) cout <<n-sum << endl;
    else cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 3656
N, K = map(int, input().split())
p = list(map(lambda x: (int(x)+1)/2, input().split()))

_sum = sum(p[:K])
ans = _sum
for i in range(N-K):
    _sum -= p[i]
    _sum += p[i+K]
    ans = max(ans, _sum)
print(ans)


Measured memory_bytes: 23524
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i = (a); i <= (n); i++)
#define repr(i, a, n) for (int i = (a); i >= (n); i--)
#define repit(it, v) for (auto(it) = (v).begin(); (it) != (v).end(); (it)++)
#define sortt(v) sort((v).begin(), (v).end())
#define sortr(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define co(x) cout << (x);
#define con(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define mkp make_pair
#define mkt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/******* Variable ***********************************/
const int maxn = 1e6 * 50;
const double inf = 0x3f3f3f3f3f;
/******* Function ***********************************/

/******* Main ****************************************/
int main() {
  int n;
  cin >> n;
  set<string> S;
  rep(i, 0, n - 1) {
    string a, b;
    cin >> a >> b;
    if (a == "insert") {
      S.insert(b);
    } else {
      if (S.count(b)) {
        puts("yes");
      } else {
        puts("no");
      }
    }
  }
  return 0;
}


Measured memory_bytes: 32116
#include <iostream>
    #include <array>
    #include <map>
    #include <algorithm>
    #include <cmath>
    #include <vector>
    #include <fstream>
    #include <string>
    #include <random>
    #include <queue>
    #include <iomanip>
    #include <functional>
    #include <climits>
     
    using namespace std;
     
    using ll = long long int;
    using pii = pair<int, int>;
    using pll = pair<ll, ll>;
    using vll = std::vector<ll>;
    using vpll = std::vector<pll>;
    using vpii = std::vector<pii>;
    using vi = std::vector<int>;
    using vvi = std::vector<vi>;
     
    const ll mod197 = 1000000007LL;
    const ll INF = 200LL * 200 * 100000 + 10;
     
    const double PI11 = 3.14159265359;
     
     
    int main() {
     
    int n, m;
    cin >> n >> m;
     
    int time = (n - m) * 100 + m * 1900;
     
    double answer = 0;
     
    for (int i = 1; i <= 10000; i++) {
    //cout << answer << endl;
    answer += (i) * ( pow(1/2.0,m) * pow((pow(2,m)-1)/(pow(2,m)),i-1) );
    }
     
    cout << time * answer << endl;
     
    return 0;
    }

Measured memory_bytes: 256
/*
*         ****FOX****
*/
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <limits>
//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#include <utility>
#include <list>
#include <cstdio>
#include<forward_list>
#include<algorithm>
#include<string>
#define Omar_Hafez ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi 3.1415926536
#define ll long long
#define ull unsigned long long
#define lli long long int
using namespace std;
int main()
{
    Omar_Hafez
    string s, t; cin >> s >> t;
    ll res = 0;
    if (s == t) cout << 0 << "\n";
    else
    {
        ll num = s.size();
        for (int i = 0; i < num; i++) if (s[i] != t[i]) res++;
        cout << res << "\n";
    }
    return 0;
}


Measured memory_bytes: 3824
#include<bits/stdc++.h>
#define MIN -1000000
using namespace std;
typedef long long ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;
ll N,M;
ll p[100005];

const int MAX_N=1e5+5;
class UnionFind
{
  int par[MAX_N];
  int rnk[MAX_N];
  int sizes[MAX_N];
public:
  void init(int n)
  {
    for(int i=0;i<n;i++)
      {
	par[i]=i;
	rnk[i]=0;
	sizes[i]=1;
      }
  }
  int find(int x)
  {
    if(par[x]==x)
      {
	return x;
      }
    else
      {
	return par[x]=find(par[x]);
      }
  }

  void unite(int x,int y)
  {
    x=find(x);
    y=find(y);
    if(x==y) return;
    if(rnk[x]<rnk[y]) swap(x,y);
    par[y]=x;
    if(rnk[x]==rnk[y]) rnk[x]++;
    sizes[x]+=sizes[y];
  }
  bool same(int x,int y)
  {
    return find(x)==find(y);
  }

  int size(int x)
  {
    return sizes[find(x)];
  }
};


int main(void)
{
  ll ans=0;
  cin >> N >> M;
  UnionFind uf;
  uf.init(N);
  for(int i=0;i<N;i++)
    {
      cin >> p[i];
    }
  for(int i=0;i<M;i++)
    {
      ll x,y;
      cin >> x >> y;
      uf.unite(x,y);
    }
  for(int i=0;i<N;i++)
    {
      if(uf.same(i+1,p[i])) ans++;
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2176
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

int N, K, value;

int main()
{
    cin >> N >> K;
    value = 1;
    for (int i = 0; i < N; i++) {
        if (value < K) {
            value *= 2;
        } else {
            value += K;
        }
    }
    cout << value << endl;
    return 0;
}

Measured memory_bytes: 256
import java.lang.*;
import java.io.*;
import java.util.*;

class Main{
	public static void main(String args[]) throws FileNotFoundException{
		
		FScanner fs=new FScanner();
		
		int n=fs.readInt();
		
		if(n<=1199){
			System.out.println("ABC");
		}else if(n<=2799){
			System.out.println("ARC");
		}else{
			System.out.println("AGC");
		}
		
	}

	static void disp(int[] data){
		for(int i=0; i<data.length; i++){
				System.out.printf("%d ",data[i]);
		}
			System.out.println();
	}
	
	static class FScanner{
		Scanner sc;
		FScanner() throws FileNotFoundException{
			sc=new Scanner(System.in);
		}
		int readInt(){
			int i=Integer.parseInt(sc.nextLine());
			return i;
		}
		
	}
}


Measured memory_bytes: 23636
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
sc = 0
for i in range(N):
    A = list(map(int, input().split()))
    f = 0
    for j in range(M):
        f += A[j] * B[j]
    f = f + C
    if f > 0:
        sc += 1
print(sc)


Measured memory_bytes: 3060
#include<stdio.h>

int main (void)
{
   int ans,i,n,k;
   int a[100001];

   scanf("%d%d",&n,&k);
   for(i=1;i<=n;i++)
      scanf("%d",a+i);

   ans=(n-1)/(k-1);     
   if((n-1)%(k-1)!=0)
      ans++;
   printf("%d\n",ans);

   return 0;
}


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

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

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

int main() {
	int a,b;
 	cin>>a>>b;
  	if (a==b){
      cout<<"Draw";
    }
  	else{
      if (b!=1 and (a==1 or a>b)){
        cout<<"Alice";
      }
      else{
        cout<<"Bob";
      }
    }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Ho{
  static void Main(){
    var aho = Console.ReadLine().Split();
    var n = int.Parse(aho[0]);
    var m = int.Parse(aho[1]);
    var zen = Console.ReadLine().Split();
    var yama = new List<int>();
    foreach(var ab in zen){
       yama.Add(int.Parse(ab));
    }
    var max = new int[n];
    for(var i = 0; i< m ;i++){
       var gyou = Console.ReadLine().Split();
       var a = int.Parse(gyou[0])-1;
       var b = int.Parse(gyou[1])-1;
       if(max[a] < yama[b]){
         max[a] = yama[b];
       }
       if(max[b] < yama[a]){
         max[b] = yama[a];
       }
    }
    var ans = 0;
    for(var i = 0;i<n;i++){
       if(max[i] < yama[i]) ans++;
    }
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 49128
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: i32 = read(&mut stdin_lock, &mut buf, b'\n');

    let mut ans = 0;
    let mut m = n;
    while m > 0 {
        ans += m % 10;
        m /= 10;
    }
    println!("{}", if n % ans == 0 { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
import sys
def input(): return sys.stdin.readline().rstrip()


from collections import deque  #listよりdequeの方が両端へのアクセスは計算量が少ない
def main():
    n, k =map(int,input().split())
    p = list(map(int,input().split()))
    p.sort()
    s = sum(p[:k])
    print(s)	


if __name__=='__main__':
    main()

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

int main(void) {
    int a, b;
    cin >> a >> b;
    
    if (a > b) {
        cout << "a > b" << endl;
    }
    else if (a < b) {
        cout << "a < b" << endl;
    }
    else {
        cout << "a == b" << endl;
    }
    
    return 0;
    
}

Measured memory_bytes: 1156
a = sorted([int(i) for i in input().split()])

count = (a[1]-a[0])//2
a[0] += 2*count

if a[0] != a[1]:
    a[0] += 1
    a[2] += 1
    count += 1

count += a[2]-a[0]
print(count)




Measured memory_bytes: 2940
#include<stdio.h>
int h;
int A[2000000];

int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}

void maxHeapify(int i){
  int l = left(i);
  int r = right(i);
  int large;
  int tmp;

  if(l <= h && A[l] > A[i]){
    large = l;
  }else{
    large = i;
  }
  if(r <= h && A[r] > A[large]){
    large = r;
  }

  if(large != i){
    tmp = A[i];
    A[i] = A[large];
    A[large] = tmp;
    maxHeapify(large);
  }
}


int exact(){
  int max;
  if(h<1)return -10000000;

  max = A[1];
  A[1] = A[h--];
  maxHeapify(1);

  return max;
}


void heapIncreaseKey(int A[],int i,int k){
  int tmp;
  if(k < A[i])return;

  A[i] = k;

  while(i > 1 && A[i/2] < A[i]){
    tmp = A[i];
    A[i] = A[i/2];
    A[i/2] = tmp;
    i = i/2;
  }
}

void insert(int k){
  h++;
  A[h] = -1000000;
  heapIncreaseKey(A,h,k);
}

int main(){
  int k;
  char c[10];
  h = 0;
  while(1){
    scanf("%s",c);

    if(c[0] == 'e' && c[1] == 'n')break;
    else if(c[0] == 'i'){
      scanf("%d",&k);
      insert(k);
    }else{
      printf("%d\n",exact());
    }
  }

  return 0;
}



Measured memory_bytes: 5636
#include <cstdio>  
typedef long long lint;  
  
lint n, x;  
  
lint g(lint x, lint y){ return y ? g(y, x%y) : x; }  
  
int main(){  
scanf("%lld %lld",&n,&x);  
printf("%lld\n", (n - g(n, x)) * 3);  
}  


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

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef map<ll, ll> mii;
const int MOD = 1e9 + 7;

#define fastIO() \
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define mp make_pair 

int main() {
    int k, n;
    cin >> k >> n;
    vi a(n);
    for (auto& i : a)   cin >> i;
    vi p(2*n);
    for (int i = 1; i < 2 * n; ++i) {
        p[i] = p[i - 1] + a[i % n] - a[(i + n - 1) % n];
        if (a[i % n] < a[(i + n - 1) % n])
            p[i] += k;
        cerr << p[i] << " ";
    }
    ll curr = p[n - 1], ans = curr;
    for (int i = n; i < 2*n; ++i) {
        curr = p[i] - p[i - n + 1];
        ans = min(ans, curr);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
package main
         
        import (
        	"fmt"
        	"bufio"
          	"os"
          	"strconv"
        )
         
        func main() {
        	sc := bufio.NewScanner(os.Stdin)
        	sc.Split(bufio.ScanWords)
         	a := nextInt(sc)
        	s := nextString(sc)
        	fmt.Println(resolve(a, s))
        }
         
        func nextString(sc *bufio.Scanner) string {
        	sc.Scan()
        	return sc.Text()
        }
         
        func nextInt(sc *bufio.Scanner) int64 {
        	i, err := strconv.ParseInt(nextString(sc), 10, 64)
        	if err != nil {
        		panic(err)
        	}
        	return i
        }
         
        func resolve(a int64, s string) string {
        	if a >= 3200 {
        		return s
        	}
        	return "red"
        }

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <array>
#include <algorithm>
#include <set>
#include <iomanip>
#include <cstdio>

using namespace std;

#define int long long

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

    char a, s;

    cin >> a >> s;

    if (a < s)
    {
        cout << '<' << endl;
    }
    else if (a > s)
    {
        cout << '>' << endl;
    }
    else
    { 
        cout << '=' << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define ALLR(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EMP emplace
#define EMPB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 62;
const double EPS = 1e-10;

int N, K;
int x[50], y[50];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> K;
  REP(i, N) cin >> x[i] >> y[i];
  int ans = INF;
  REP(i, N) REP(j, N) FOR(k, i+1, N) FOR(l, j+1, N) {
    int L = min(x[i], x[k]);
    int R = max(x[i], x[k]);
    int U = max(y[j], y[l]);
    int D = min(y[j], y[l]);
    int cnt = 0;
    REP(a, N) {
      cnt += (L <= x[a] && x[a] <= R && D <= y[a] && y[a] <= U);
    }
    if (cnt >= K) chmin(ans, (R-L)*(U-D));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        Arrays.sort(h);
        int result = 1000000000;
        for (int i = 0; i <= n - k; i++) {
            int min = h[i];
            int max = h[i + k - 1];
            result = Math.min(result, max - min);
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 48168
h, w, d = map(int, input().split())
zahyo = [0] * (h * w + 1)
for i in range(h):
    a = list(map(int, input().split()))
    for j in range(w):
        zahyo[a[j]] = (i + 1, j + 1)
D = [0] * 100000
for i in range(d + 1, h * w + 1):
    D[i] = D[i - d] + abs(zahyo[i][1] - zahyo[i - d][1]) + abs(zahyo[i][0] - zahyo[i - d][0])
q = int(input())
for i in range(q):
    L, R = map(int, input().split())
    print(D[R] - D[L])

Measured memory_bytes: 14796
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 99999999
#define eps 1e-9
int l;
int mini;
string str;

bool isOK(string s){
    if(s.size()%2!=0){
        if(s[(int)(s.size()/2)]=='('||s[(int)(s.size()/2)]==')')return false;
        s=s.substr( 0,(int)(s.size()/2) )+s.substr( (int)((s.size()+1)/2),(int)(s.size()/2));
    }
    string a,b;
    a=s.substr( 0,(int)(s.size()/2) );
    b=s.substr( s.size()/2,(int)(s.size()/2) );
    reverse(b.begin(),b.end());
    rep(i,b.size()){
        if(  (a[i]==b[i]&&a[i]!=')'&&a[i]!='(')||( (a[i]==')'&&b[i]=='(') || (a[i]=='('&&b[i]==')') )  ){}
        else{
            return false;
        }
    }
    return true;
}

int solve(string a,string b){
    int ret=0;
    rep(i,a.size()){
        if(a[i]!=b[i])ret++;
    }
    
    return ret;
}

void dfs(string s){
    if(s.size()==l){
        if(isOK(s)){
            mini=min(mini,solve(s,str));
        }
        return ;
    }
    string iwi="iw()";
    rep(i,4){
        dfs(s+iwi[i]);
    }
}


int main(){
    mini=INF;
    cin>>str;
    l=str.size();
    
    dfs("");
    cout<<mini<<endl;
}

Measured memory_bytes: 1196
#include <iostream>

using namespace std;

int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if(x-r>=0 && x+r<=W){
        if(y-r>=0 && y+r<=H){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3044
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <string>
using namespace std;

int main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
 
	int n,k,i,j,r;
  vector<int> v;
  cin>>n>>k;
  
  i=1;
  while(1){
    if(pow(k,i-1) <= n && n < pow(k,i))
      break;
    i++;
  }
  cout<<i;


  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main () {
  int n;
  cin >> n;
  int p[n];
  int k=0;
  for ( int i = 0; i < n; i++ ){
    cin >> p[i];
    if(p[i] != i+1){
        k++;
    }
  }
  if(k<=2){
      cout << "YES" << endl;
  }else{
      cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 212345
int a[N];
int b[1048576] = {};

int main(){
	int n; scanf("%d", &n);
	REP(i, n){
		scanf("%d", a+i);
		b[a[i]]++;
	}
	int ans = 0;
	REP(i, n){
		b[a[i]]--;
		bool ok = true;
		for(int j = 1; j*j <= a[i]; j++){
			if(a[i]%j) continue;
			DEBUG("%d=>%d %d=>%d\n", j, b[j], a[i]/j, b[a[i]/j]);
			if(b[j]) ok = false;
			if(b[a[i]/j]) ok = false;
		}
		b[a[i]]++;
		DEBUG("%d: %d\n", a[i], ok);
		ans += ok;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 8400