akhauriyash/Code-Regression huggingface dataset:
//============================================================================
// Name        : PapaCoder.cpp
// Author      : Tohru Fujii
// Version     :
// Copyright   : Oredayo
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,P> P2;
const ll INF=100000000000000001;
int A[200001]={};

int main() {

	int n,k;
	cin>>n>>k;
	int a1;
	for(int i=0;i<n;++i){
		cin>>a1;
		A[a1]++;
	}

	sort(A,A+n,greater<int>());

	int total=0;
	for(int i=k;i<n+1;++i)total+=A[i];

	cout << total << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int x[300005];
int ans;
int p[300005];
int sum[300005],mx[300005];
int main(){
	int n,l;
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;i++)scanf("%d",&x[i]);
	for(int i=1;i<=n;i++){
		int t;
		scanf("%d",&t);
		ans+=t/(2*l)*2;
		t%=(2*l);
		if(!t)p[i]=0;
		else if(t>max(2*x[i],2*(l-x[i]))){
			ans+=2;
			p[i]=0;
		}else
		if(t>2*x[i]){
			p[i]=1;
			ans+=1;
		}else
		if(t>2*(l-x[i])){
			p[i]=2;
			ans+=1;
		}else{
			p[i]=-1;
			ans+=1;
		}
		// printf("%d ",p[i]);
	}
	// puts("");
	// printf("%d\n",ans);
	for(int i=n;i>=1;i--)sum[i]=sum[i+1]+(!p[i]?0:(p[i]!=2?-1:1));
	memset(mx,-1,sizeof(mx));
	for(int i=n;i>=1;i--)mx[i]=max(mx[i+1],sum[i]);
	int res=1e9;
	// printf("%d\n",ans);
	for(int i=1,mn=0,s=0;i<=n+1;i++){
		int t=max(-mn+1,i<=n?max(-(sum[i]-mx[i]+s)+1,-(sum[i]+s)):-(sum[i]+s) );
		// printf("%d %d %d\n",t,t+(t+s+sum[i]),-(sum[i]-mx[i]+s)+1);
		res=min(res,t+(t+s+sum[i]));
		if(p[i]){
			if(p[i]!=1)s++;
			else s--;
		}
		mn=min(mn,s);
	}
	printf("%lld\n",1ll*l*(res+ans));
	return 0;
}

Measured memory_bytes: 4864
A,B,C,D = map(int,input().split())
MOD = 998244353

dp = [[0 for _ in range(D+1)] for _ in range(C+1)]
dp[A][B] = 1
for i in range(A,C+1):
  for j in range(B,D+1):
    if i > A or j > B:
      dp[i][j] += dp[i-1][j]*j+dp[i][j-1]*i-dp[i-1][j-1]*(i-1)*(j-1)
    dp[i][j] %= MOD

ans = dp[C][D]
print(ans)
      

Measured memory_bytes: 152516
using System;

namespace _1_csharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(" ");
            int[] X = new int[input.Length];
            for (int i = 0; i < input.Length; i++){
                X[i] = int.Parse(input[i]);
            }

            int sum = 1000001;
            for (int p = 0; p <= 100; p++)
            {
                int tempSum = 0;
                foreach (var x in X)
                {
                    tempSum += (x - p) * (x - p);
                }
                if (sum > tempSum)
                {
                    sum = tempSum;
                }
            }
            System.Console.WriteLine(sum);
        }
    }
}


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

typedef long long lli;

int f(int a, int b) {
    int x = 1;
    int i = 0;
    do {
        x = (a * x) % b;
        i++;
    } while(x != 1);
    return i;
}

lli lcm(lli p, lli q) {
    return p / __gcd(p, q) * q;
}

int main() {
	for(lli a1, m1, a2, m2, a3, m3; cin >> a1 >> m1 >> a2 >> m2 >> a3 >> m3 ;) {
        if(a1 + m1 + a2 + m2 + a3 + m3 == 0) break;
        int r1 = f(a1, m1);
        int r2 = f(a2, m2);
        int r3 = f(a3, m3);
        lli ans = lcm(lcm(r1, r2), r3);
        cout << ans << endl;
	}
}

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

int main(){
    char a,b;

    cin >> a >> b;

    if(a == 'H'){
        if(b == 'H'){
            cout << 'H' <<endl;
        }
        else if(b == 'D'){
            cout << 'D' <<endl;
        }
    }
    else if(a == 'D'){
        if(b == 'H'){
            cout << 'D' <<endl;
        }
        else if(b == 'D'){
            cout << 'H' <<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
use std::io;
use std::str::FromStr;
use std::collections::HashSet;

fn input_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn main() {
    let n: u64 = input();
    let a_vec = input_vec();
    let mut set: HashSet<u64> = HashSet::new();
    for a in &a_vec {
        set.insert(*a);
    }
    if set.len() == a_vec.len() {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 13996
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b,c;cin>>a>>b>>c;
  int aa=0,bb=0,cc=0;
  int now=0;
  for(;;){
    if(now==0){
      if(aa==a.size()){
        cout<<"A";
        return 0;
      }
      now=a[aa]-'a';
      aa++;
    }
    if(now==1){
      if(bb==b.size()){
        cout<<"B";
        return 0;
      }
      now=b[bb]-'a';
      bb++;
    }
    if(now==2){
      if(cc==c.size()){
        cout<<"C";
        return 0;
      }
      now=c[cc]-'a';
      cc++;
    }
  }
}

Measured memory_bytes: 256
a, b = map(int, input().split())

cnt = 0
total = 0

if b == 1:
    print(0)
    exit()

for i in range(30):
    if i == 0:
        total = a
        cnt += 1
    else:
        total += a-1
        cnt += 1
    
    if b <= total:
        break

print(cnt)
        

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
    int n;
	cin>>n;
	int sum = 0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			for(int k=1;k<=n;k++)
			{
				sum += __gcd(i,__gcd(j,k));
			}
		}
	}
	cout<<sum<<"\n";

	return 0;	
}

Measured memory_bytes: 3584
A,B = map(int, input().split())
cnt = 0
ans = 0
if B == 1:
        print(0)
        exit()
while 1:
        if cnt == 0:
                cnt += A
        else:
                cnt += A - 1
        ans += 1
        if cnt >= B:
                print(ans)
                exit()



Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,a,b;
  cin>>n>>a>>b;
  long long e=a+b;
  long long s=n/e;
  long long s1=n%e;
  long long t;
  if(s1<a)
    t=s*a+s1;
  else
    t=s*a+a;
  cout<<t<<endl;
  return 0;
}

Measured memory_bytes: 256
def calc(n, p):
    min_p = 200000

    count = 0
    
    for i in p:
        # 最小値更新
        if (min_p >= i):
            min_p = i
        if (min_p >= i):
            count += 1

    print(count)


n = int(input())
p = [int(x) for x in input().split()]

calc(n, p)


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define rep2r(i, l, r) for (int i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using ull = unsigned long long;
void solve();
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); solve(); }

pair<bool, vector<int>> bfs_restore(const vector<vector<int>> &g, int s, int t) {
  const int n = g.size();
  vector<int> prev(n, -1);
  queue<int> q;
  q.push(s);
  prev[s] = s;
  while (!q.empty()) {
    int u = q.front(); q.pop();
    for (int v : g[u]) {
      if (prev[v] == -1) {
        prev[v] = u;
        q.push(v);
      }
    }
  }
  if (prev[t] == -1) return {false, {}};
  vector<int> res;
  for (int i = t; i != s; i = prev[i]) {
    res.push_back(i);
  }
  res.push_back(s);
  reverse(res.begin(), res.end());
  return {true, res};
}

void solve() {
  int N, M; cin >> N >> M;
  vector<vector<int>> G(N);
  rep(_, M) {
    int a, b; cin >> a >> b; a--; b--;
    G[a].push_back(b);
  }
  vector<int> ans;
  rep(i, N) for (int j : G[i]) {
    auto p = bfs_restore(G, j, i);
    if (!p.first) continue;
    if (ans.empty() || ans.size() > p.second.size()) {
      ans = p.second;
    }
  }
  if (ans.size() == 0) {
    cout << -1 << endl;
    return;
  }
  cout << ans.size() << endl;
  for (int x : ans) cout << x+1 << '\n';
}

Measured memory_bytes: 384
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

int main(){
    map<char, int> alps;
    map<char, int> buf;
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        string a;
        cin >> a;
        for(char c : a){
            buf[c]++;
        }
        for(int j = 97; j < 123; j++){
            if(i==0){
                alps[(char)j] = buf[(char)j];
            } else {
                alps[(char)j] = min(alps[(char)j], buf[(char)j]);
            }
            buf[(char)j] = 0;
        }
    }
    for(int i = 97; i < 123; i++){
        while(alps[(char)i] > 0){
            cout << (char)i;
            alps[(char)i]--;
        }
    }
    cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long  N, A,B;
  cin >> N >> A >> B;
  long long c = N%(A+B);
  if(A < c){//青いボールはジャストセットになる
    cout << (N/(A+B)+1)*A << endl;
  }
  else{
    cout << c+(N/(A+B))*A <<endl;
  }

}

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

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    vector<long long int> even, odd;
    for (int i = 0; i < n*(n+1)/2; ++i) {
      long long int b;
      cin >> b;
      if (b & 1LL)
	odd.push_back(b);
      else
	even.push_back(b);
    }
    sort(even.begin(), even.end());
    sort(odd.begin(), odd.end());

    long long int a0 = static_cast<long long int>(sqrt(even[0] / __gcd(even[0], odd[0]) * (even[1] / (odd[0] / __gcd(even[0], odd[0])))));


    cout << a0 << endl;
    for (int i = 0; i < (int)even.size()-1; ++i)
      cout << even[i]/a0 << " ";
    cout << even.back()/a0 << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
#include <random>
//#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;
using pis = std::pair<int, std::string>;

const long long INF = 1000000000000000001;
const long long _MOD_ = 1000000000000000009;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
//namespace mp = boost::multiprecision;

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

	int s;
	cin >> s;
	if (s < 3) {
		cout << 0 << "\n";
		return 0;
	}

	ll* dp = new ll[s + 1];
	ll* pre = new ll[s + 1];
	memset(dp, 0, sizeof(ll)*(s + 1));
	rep(i, s + 1) dp[i] = 1;

	for (int i = 2; i * 3 <= s; ++i) {
		memcpy(pre, dp, sizeof(ll)*(s + 1));
		ll sum = 0;
		REP(j, i * 3, s + 1) {
			sum += pre[j - 3];
			sum %= _MOD;
			if (j == s) dp[j] += sum;
			else dp[j] = sum;
			dp[j] %= _MOD;
		}
	}

	cout << dp[s] << "\n";

	return 0;
}


Measured memory_bytes: 3660
Scanf.scanf "%d %d" (fun n q ->
    let par = Array.init (n + 1) (fun i -> i) in
    let rec root x =
        if x = par.(x) then x else
            let r = root par.(x) in
            let () = par.(x) <- r in
            r
    in
    let merge a b =
        if root a <> root b then par.(par.(b)) <- par.(a)
    in
    for i = 1 to q do
        Scanf.scanf " %d %d %d" (fun t u v ->
            if t = 0 then merge u v else
                Printf.printf "%d\n" @@ if root u = root v then 1 else 0
        )
    done
)

Measured memory_bytes: 7352
class QQ {
	int size;
	
	QQ(int n){
		size = n;
	}

	void printQQ(){
		for(int i=1; i<=size; i++)
			for(int j=1; j<=size; j++)
				System.out.println(i+"x"+j+"="+i*j);
	}
}

class Main {
	public static void main (String [] args){
		QQ q = new QQ(9);
		q.printQQ();
	}
}

Measured memory_bytes: 9344
// ITP1_5_D Structured Programming
import java.util.*;

class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.next());
      for (int i = 1; i <= n; i++) {
         int x = i;
         if (x % 3 == 0) {
            System.out.print(" " + i);
         } else {
            while (x != 0) {
               if (x % 10 == 3) {
                  System.out.print(" " + i);
                  break;
               }
               x /= 10;
            }
         }
      }
      System.out.println();
   }
}

Measured memory_bytes: 24272
// --------------
// Tejas Pandey  |
// 13 - 09 - 20  |
// Atcoder BC 178|
// --------------

#include <bits/stdc++.h>
using namespace std;
     
#define mod 1000000007
#define maxn 20007
#define vi vector<int>
typedef long long int ll;

ll fact[maxn],ifact[maxn];

ll mpow(ll a, ll b){
	ll res = 1;
	while(b){
		if(b&1) res *= a,res %= mod;
		a *= a;
		a %= mod;
		b >>= 1;
	}
	return res;
}

void pre(){
	fact[0]  = fact[1] = ifact[0]  = ifact[1] = 1;
	for(int i = 2;i < maxn;i++){
		fact[i] = (fact[i - 1]*i)%mod;
		ifact[i] = mpow(fact[i],mod - 2);
	}
}

ll comb(ll a,ll b){
	ll ans = (fact[a]*ifact[b])%mod;
	ans *= ifact[a - b];
	ans %= mod;
	return ans;
}
    
int main (void){
  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  pre();
  int n;
  cin >> n;
  if(n < 3){
	cout << "0\n";
	return 0;
  }
  ll ans = 1;
  for(int i = 2;i*3 <= n;i++){
	int place = n - i*3;
	ans += comb(place - 1 + i,place);
	ans %= mod;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 4000
#include <iostream>

using namespace std;
typedef long long ll;
ll n,N = 200020,bit[200020],a[100010];
ll sum(int i){
	ll s = 0;
	while(i>=0){
		s += bit[i];
		i = (i&(i+1)) -1;
	}
	return s;
}

ll add(int i, int x){
	while(i<=N){
		bit[i] += x;
		i |= i+1;
	}
}

bool check(ll x){
    for(int i=0;i<N;i++) bit[i] = 0;
    ll s = 100000,t = 0;
    add(s,1);
    for(int i=0;i<n;i++){
        if(a[i]>=x) s += 1;
        else s -= 1;
        t += sum(s);
        add(s,1);
    }
    if(t>=n*(n+1)/4) return true;
    else return false;
}

int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    if(n==1){
        cout << a[0] << endl;
        return 0;
    }
    ll l = 0,r = 1000000001;
    while(r-l>1){
        ll mid = (l+r)/2;
        if(check(mid)) l = mid;
        else r = mid;
    }
    cout << l << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}


int main(){
    string s;
    cin >> s;
    if(s=="ARC")puts("ABC");
    else puts("ARC");
    return 0;
}

Measured memory_bytes: 3564
import std.algorithm, std.conv, std.range, std.stdio, std.string;

const auto ri = [[-1, 2, 4, 1, 3,-1],
                 [ 3,-1, 0, 5,-1, 2],
                 [ 1, 5,-1,-1, 0, 4],
                 [ 4, 0,-1,-1, 5, 1],
                 [ 2,-1, 5, 0,-1, 3],
                 [-1, 3, 1, 4, 2,-1]];

void main()
{
  auto di = readln.split.map!(to!int).array;
  auto q = readln.chomp.to!size_t;

  foreach (_; 0..q) {
    auto rd = readln.split.map!(to!int), t = rd[0], f = rd[1];
    auto ti = di.countUntil(t), fi = di.countUntil(f);
    writeln(di[ri[ti][fi]]);
  }
}

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


int main()
{
    string s;
    cin >> s;

    ll A_pos = INF_LL;
    ll Z_pos = 0;
    rep(i,s.size())
    {
        if( s[i] == 'A' ) chmin(A_pos, (ll)i);
        else if( s[i] == 'Z' ) chmax(Z_pos, (ll)i);
    }

    cout << Z_pos - A_pos+1 << endl;
}


Measured memory_bytes: 644
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
ll INF = (1LL << 60) - 1;
int MOD = 1e9+7;
main(){
    int N,C;
    cin >> N >> C;
    int D[C][C],E[N][N];
    rep(i,0,C)rep(j,0,C)cin >> D[i][j];
    rep(i,0,N)rep(j,0,N){cin >> E[i][j];E[i][j]--;}

    ll sum[C][3] = {};
    rep(i,0,C){
        rep(j,0,N){
            rep(k,0,N){
                sum[i][(j + k) % 3] += D[ E[j][k] ][i];
            }
        }
    }
    ll mini = INF;
    rep(i,0,C)rep(j,0,C)rep(k,0,C){
        if(i == j || j == k || k == i)continue;
        mini = min(mini, sum[i][0] + sum[j][1] + sum[k][2]);
    }
    cout << mini << endl;
}

Measured memory_bytes: 1280
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	const inputLines = input.split("\n");
	const line0 = inputLines[0];
	const line0vars = line0.split(" ");

	var x = parseInt(line0vars[0], 10);
	var k = parseInt(line0vars[1], 10);
	const d = parseInt(line0vars[2], 10);

	if (x < 0) {
		x = x * -1;
	}

	var result = x - k * d;
	if (0 <= result) {
		return console.log(result);
	}

	result = x % d;
	var count = (x - result) / d;
	if (count%2 == k%2) {
		var p = -1 * (result - d * 2);

		// console.log({
		// 	x: x,
		// 	k: k,
		// 	d: d,
		// 	result: result,
		// 	p: p
		// });
	
		if (p < result) {
			result = p;
		}	

		return console.log(result);
	} 

	var a1 = result + d;
	var a2 = Math.abs(result - d);

	// console.log({
	// 	x: x,
	// 	k: k,
	// 	d: d,
	// 	result: result,
	// 	a1: a1,
	// 	a2: a2
	// });

	result = a1;

	if (a2 < result) {
		result = a2;
	}
	console.log(a2);

	

	// tmp = input[1].split(" ");
	// //文字列から10進数に変換するときはparseIntを使います
	// var a = parseInt(input[0], 10);
	// var b = parseInt(tmp[0], 10);
	// var c = parseInt(tmp[1], 10);
	// var s = input[2];

	//出力
	// console.log('%d %s',a+b+c,s);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

// node index.js
// 1
// 2 3
// test
// (Ctrl + D)


Measured memory_bytes: 29708
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
#include <queue>
#include <cassert>
#include <forward_list>
#include <chrono>
#include <deque>
#include <list>
#include <random>
#include <cstdio>
#include <sstream>

using namespace std;

//最大公約数
template<class T>
inline T GCD(T m, T n)
{
	T temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

//最小公倍数
template<class T>
inline T LCM(T m, T n)
{
	return m * n / GCD(m, n);
}

int main()
{
	int n, d; cin >> n >> d;
	vector<vector<int>> x(n, vector<int>(d));
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < d; ++j)
		{
			cin >> x[i][j];
		}
	}
	int ans = 0;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			if (i != j)
			{
				double z = 0;
				for (int k = 0; k < d; ++k)
				{
					z += pow(static_cast<double>(x[i][k] - x[j][k]), 2);
				}
				z = sqrt(z);
				if (ceil(z) == floor(z)) { ans++; }
			}
		}
	}

	cout << ans/2 << endl;
	return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main() {
	int a,b;
	cin >> a >> b;
	vector<int>p(b);
	for (int i = 0; i < b; i++) {
		cin >> p[i];
	}
	int d = 0;
	for (int j = 0; j < b; j++) {
		d += p[j];
	}
	if (d >= a) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0; 
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = sc.nextDouble();
		
		double men = a * a * Math.PI;
		double ensyu = a * 2 * Math.PI;
		
		String str1 = String.format("%.5f", men);
		String str2 = String.format("%.5f", ensyu);
		
		System.out.println(str1 +" "+ str2);
	}
}

Measured memory_bytes: 28172
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int ans = 0;
        String S = sc.next();
        for(int i=0;i<6;i++){
            ans += S.charAt(i)-'0';
        }
        System.out.println(ans);
    }
}

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

#define dlog(str) cout << "====" << str << endl;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main(){
    int N;
    cin>>N;
    cout<<180*(N-2);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less

#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define show(x) cerr << #x << " = " << x << "\n"
#define mem( a , b ) memset( a , b , sizeof a )
#define popcnt(x) __builtin_popcount(x)
#define all(x) x.begin() , x.end()
#define mod(x,m) ((x%m + m )%m)
#define SZ(a) (int)a.size()
#define ll  long long
#define ld  long double
#define vii vector  <ll>
#define dqi deque   <ll>
#define sii set     <ll>
#define vpi vector  <pii>
#define mii map     <ll,ll>
#define pii pair    <ll,ll>
#define pi  pair    <int,int>
#define pb  push_back
#define F   first
#define S   second
#define L   length()
#define OO  (ll)1e18
#define EPS 1e-9
using namespace std;
using namespace __gnu_pbds;
void ONLINE__JUDGE();

typedef tree<ll, null_type, less<ll>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
pii swapii( pii pr ){ return { pr.S , pr.F }; }
ll binEXP( ll x , ll pw , ll MOD = LLONG_MAX );
int dx[] = {  0 ,  0 , -1 , +1 , -1 , +1 , -1 , +1 };
int dy[] = { -1 , +1 ,  0 ,  0 , -1 , +1 , +1 , -1 };

const ll MOD = 1e9 + 7;
const ll MAX = 1e2 + 9;

ll x; vii vec , cnt , res;

int main()
{
    //FASTIO ONLINE__JUDGE();

    cin >> x; vec.resize(x+1); cnt.resize(x+1 , 0);
    for ( int i = 1; i <= x; i++ ){
        cin >> vec[i];
    }

    for ( int i = x; i >= 1; --i ){

        ll sum = 0;
        for ( int j = i; j <= x; j += i ){
            sum += cnt[j];
        }
        if ( sum%2 != vec[i] ){
            cnt[i]++; res.pb(i);
        }
    }

    for ( int i = x; i >= 1; --i ){

        ll sum = 0;
        for ( int j = i; j <= x; j += i ){
            sum += cnt[j];
        }
        if ( sum%2 != vec[i] ){
            return cout << -1 , 0;
        }
    }

    cout << SZ(res) << "\n"; sort( all(res) );
    for ( ll i : res ) cout << i << " ";
    return 0;
}


void ONLINE__JUDGE()
{
    #ifndef ONLINE_JUDGE
    freopen( "inp.c"         , "r" , stdin  );
    //freopen( "OutPut.txt"   , "w" , stdout );
    #endif // ONLINE_JUDGE
}

ll binEXP( ll x , ll pw , ll MOD )
{ ll res=1; while(pw>0){ pw%2 ? res *= x : 0; x *= x; x%=MOD; pw /= 2; res%= MOD; } return res%=MOD; }


Measured memory_bytes: 4980
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (ll i = ll(a); i <= ll(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end

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

    string s, t;
    in >> s >> t;
    ll n = s.size(), m = t.size();
    ll dp[n+1][m+1] = {};

    ll idx = 1;
    REP_AB(i, 1, n){
        REP_AB(j, 1, m){
            if(s[i-1] == t[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
                if(idx == dp[i][j]){
                    idx += 1;
                }
            }else{
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }

    string ans = "";
    ll x = n;
    ll y = m;
    while(x > 0 && y > 0){
        if(dp[x][y] == dp[x-1][y]){
            x--;
        }else if(dp[x][y] == dp[x][y-1]){
            y--;
        }else{
            x--;
            y--;
            ans += s[x];
        }
    }
    REVERSE(ans);
    out << ans << endl;
}


Measured memory_bytes: 70656
def resolve():
    K, N = map(int, input().split()) 
    A_list = list(map(int, input().split()))

    max_interval = 0
    for i in range(N-1):
        tmp_interval = A_list[i + 1] - A_list[i]
        if max_interval < tmp_interval:
            max_interval = tmp_interval

    first_interval = A_list[0] + (K - A_list[N-1])

    if max_interval < first_interval:
        max_interval = first_interval

    ans = K - max_interval

    print(ans)

if __name__ == "__main__":
    resolve()

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

bool U[100005];

int main() {
    ll N, K, R, S, P;
    cin >> N >> K >> R >> S >> P;
    string T;
    cin >> T;

    memset(U, 0, sizeof(U));
    ll ans = 0;
    REP(i, N) {
        ll p = i - K;
        if (p >= 0 && T[i] == T[p] && U[p])
            continue;
        U[i] = true;
        if (T[i] == 'r')
            ans += P;
        else if (T[i] == 's')
            ans += R;
        else
            ans += S;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
from scipy.misc import comb
#from scipy.special import comb

N, K = map(int, input().split())
B = K
R = N - K
for i in range(1, K+1):
    # R+i C i
    tmp1 = comb(R+1, i, exact = True)
    # i H rest
    tmp2 = comb(i+(B-i)-1, B-i, exact = True)

    ans = int((tmp1*tmp2)%1000000007)
    print(ans)

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

int main(){
    int n;
    cin >> n;
    for(int i=0; i < n; i++){
        long a;
        cin >> a;
        if(a%2 != 0){
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0), cin.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 2e5 + 5;
const int inf = ~0u >> 1;
typedef pair<int, int> P;
#define REP(i, a, n) for (int i = a; i < (n); ++i)
#define PER(i, a, n) for (int i = (n)-1; i >= a; --i)
const ll mod = 1e9 + 7;
ll a[maxn];
ll sum[maxn];
int main() {
    IO;
    int n;
    cin >> n;
    REP(i, 1, n + 1) {
        cin >> a[i];
        sum[i] = sum[i - 1] + a[i];
    }
    ll ans = 0;
    REP(i, 2, n + 1) {
        ans = (((a[i] % mod) * (sum[i - 1] % mod) % mod) + ans) % mod;
    }
    cout << ans % mod << endl;
    return 0;
}



Measured memory_bytes: 6648
#include <stdio.h>
#include <math.h>

int main()
{
    int i,j,k,n,m,s,x,y,z;

    double p;

    scanf("%d %d",&n,&m);

    s=1;p=0;
    while(s*n<m)
    {
        s*=2;
    }
    p=p+((1/(double)n)*(1/(double)s));

    for(i=n-1;i>0;i--)
    {
        while(s*i<m)
        {
            s*=2;
        }
        p=p+((1/(double)n)*(1/(double)s));
    }

    printf("%.13lf\n",p);
}


Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    string ans;
    ans = s;
    for(int i=n;i>=1;i--){
        if(s.substr(n-i,i)==t.substr(0,i)){
            if(i<n) ans += t.substr(i);
            cout << (int)ans.size() << endl;
            return 0;
        }
    }
    ans += t;
    cout << (int)ans.size() << endl;

    return 0;
}

Measured memory_bytes: 256
// problem: "https://atcoder.jp/contests/abc140/tasks/abc140_e"

#include<bits/stdc++.h>
#define ll long long

using namespace std;

ll sumIt(vector<ll>&V,ll n)
{
    vector<ll>L(n+2),R(n+2),LL(n+2),RR(n+2);

    V.push_back((ll)(1e9));
    V.insert(V.begin(),(ll)(1e9));

    ll i,j;

    for(i=1;i!=n+1;i++)
    {
        j = i-1;

        while(j > 0 && V[j] < V[i])
            j = L[j];

        L[i] = j;
    }

    for(i=n;i>0;i--)
    {
        j = i+1;

        while(j < n+1 && V[j] < V[i])
            j = R[j];

        R[i] = j;
    }

    for(i=1;i!=n+1;i++)
    {
        j = max(L[i]-1,(ll)0);

        while(j > 0 && V[j] < V[i])
            j = L[j];

        LL[i] = j;
    }

    for(i=n;i>0;i--)
    {
        j = min(R[i]+1,n+1);

        while(j < n+1 && V[j] < V[i])
            j = R[j];

        RR[i] = j;
    }

    // for(i=1;i!=n+1;i++)
    // {
    //     cout<<L[i]<<' '<<R[i]<<' '<<LL[i]<<' '<<RR[i]<<'\n';
    // }

    ll s = 0;
    for(i=1;i!=n+1;i++)
        s += ((L[i]-LL[i]) * (R[i]-i) + (RR[i]-R[i]) * (i-L[i])) * V[i];

    return s;
}

int main()
{
    ll n;
    cin>>n;

    vector<ll>V;
    ll i,x;

    for(i=0;i!=n;i++)
    {
        cin>>x;
        V.push_back(x);
    }

    cout<<sumIt(V,n);       // define

    return 0;
}


Measured memory_bytes: 4340
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n][3];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>a[i][j];
        }
    }
    int dp[n+1][3];
    memset(dp,0,sizeof dp);
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<3;j++)
        {
            for(int k=0;k<3;k++)
            {
                if(j==k)continue;
                dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i-1][j]);
            }
        }
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
}


Measured memory_bytes: 2560
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			var a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
			var b = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
			var c = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

			Array.Sort(a);
			Array.Sort(b);
			Array.Sort(c);

			var btc = new long[n];
			int ci = 0;
			for (int i = 0; i < n; i++) {
				long sizeB = b[i];
				int ct = -1;
				for (int j = ci; j < n; j++) {
					if (c[j] > sizeB) {
						ct = j;
						break;
					}

					++ci;
				}

				if (ct == -1) {
					btc[i] = 0;
				} else {
					btc[i] = n - ct;
				}
			}

			var rui = new long[n];
			rui[n - 1] = btc[n - 1];
			for (int i = n - 2; i >= 0; i--) {
				rui[i] += rui[i + 1] + btc[i];
			}

			long ans = 0;
			int bi = 0;
			for (int i = 0; i < n; i++) {
				long sizeA = a[i];
				int bt = -1;
				for (int j = bi; j < n; j++) {
					if (b[j] > sizeA) {
						bt = j;
						break;
					}

					++bi;
				}

				if (bt == -1) {
					break;
				}

				ans += rui[bt];
			}

			Console.WriteLine(ans);
		}
	}
}

Measured memory_bytes: 41708
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
typedef long long ll;
//プロトタイプ宣言
int gcd(int , int);
int GCD(int , int);


int main(){
    ll n;
    cin >> n;
    vector<ll> l(n + 1,0),r(n + 1,0),a(n);
    rep(i,n) cin >> a[i];
    for(int i=0;i<n;++i) l[i + 1] = GCD(l[i] , a[i]);
    for(int i=n-1;i>=0;--i) r[i] = GCD(r[i + 1] , a[i]);
    ll ans = 0;
    rep(i,n){
        ll m = GCD(l[i],r[i + 1]);
        ans = max(ans , m);
    }
    cout << ans << endl;
}








































//以下、ライブラリ
//ユークリッドの互除法
int gcd(int a, int b){
    while(1){
        int remain = a % b;
        if(remain == 0) return b;
        else{
            a = b;
            b = remain;
        }
    }
}

int GCD(int a, int b) {
  return b ? GCD(b, a%b) : a;
}

Measured memory_bytes: 2560
a,b,c = map(int, input().split())

ganma = a%b
if ganma == 0:
  if ganma == c:
    print("YES")
  else:
    print("NO")

else:
  mod_list = []
  for i in range(b):
    mod = (i*ganma)%b
    mod_list.append(mod)

  zero_one_list = []
  for i in range(b):
    if mod_list[i] == c:
      zero_one_list.append(1)
    else:
      zero_one_list.append(0)
    
  sum_list = sum(zero_one_list)

  if sum_list >= 1:
    print("YES")
  else:
    print("NO")

Measured memory_bytes: 9196
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e6 + 10; 

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

vector<pair<int, int>> G[N];

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int h,w;
   cin >> h >> w;
   int ch,cw;
   cin >> ch >> cw;
   --ch,--cw;
   int dh,dw;
   cin >> dh >> dw;
   --dh,--dw;
   string s[h];
   for(int i = 0; i < h; ++i){
      cin >> s[i];
   }
   int n = h, m = w;
   auto chk = [&](int x,int y){
      return x >= 0 and x < n and y >= 0 and y < m and s[x][y] == '.';
   };
   for(int i = 0; i < h; ++i){
      for(int j = 0; j < w; ++j){
         int nd = i*w+j;
         // debug(i,j);
         for(int k = 0; k < 4; ++k){
            int x = dx[k]+i;
            int y = dy[k]+j;
            if(chk(x,y)){
               // cout << x << ' ' << y << '\n';
               G[nd].push_back({x*m+y,0});
            }
         }
         for(int k = max(0ll,i-2); k <= min(n,i+2); ++k){
            for(int l = max(0ll,j-2); l <= min(m,j+2); ++l){
               if(abs(l-j)+abs(k-i) > 1){
                  if(chk(k,l)){
                     // cout << k << ' ' << l << '\n';
                     G[nd].push_back({k*m+l,1});
                  }
               }
            }
         }
      }
   }

   int INF = 1e15;
   int ss = ch*m+cw;
   // debug(ss);
   vector<int> d(N, INF);
   d[ss] = 0;
   deque<int> q;
   q.push_front(ss);
   while (!q.empty()) {
       int v = q.front();
       q.pop_front();
       for (auto edge : G[v]) {
           int u = edge.first;
           int w = edge.second;
           if (d[v] + w < d[u]) {
               d[u] = d[v] + w;
               if (w == 1)
                   q.push_back(u);
               else
                   q.push_front(u);
           }
       }
   }

   int r = d[dh*m+dw];
   if(r == INF){
      cout <<  -1;
   }else{
      cout << r;
   }
   return 0;
} 


Measured memory_bytes: 298704
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var n = int.Parse(input);

            for (int a = 1; a <=9; a++)
            for (int b = 1; b <=9; b++) {
                if (n == a*b) {
                    Console.WriteLine("Yes");
                    return;
                }
            }
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e15;

struct edge{
    int from, to;
    long long int cost;
};

int V,E;// number of (vertices, edges)
vector<edge> e;
vector<long long int> d;// shortest distances
vector<bool> negative;

void shortest_path(int s){// s = starting point
    // initialize (INF)
    for(int i=0; i<V; i++){
        d[i] = INF;
    }
    d[s] = 0LL;

    // search (rather naive)
    for(int i=0; i<V; i++){
        bool update = false;// flag
        for(int j=0; j<E; j++){
            if(d[e[j].from] != INF 
            && d[e[j].to] > d[e[j].from] + e[j].cost){
               d[e[j].to] = d[e[j].from] + e[j].cost;// update minimum cost
               update = true;
               if(i == V-1) negative[e[j].to] = true;
            }
            if(negative[e[j].from] == true) negative[e[j].to] = true;
        }
        if(update == false) break;// no updates anymore
    }
}

int main(){
    int s = 0;
    cin >> V >> E;
    d.resize(V);
    e.resize(E);
    negative.resize(V);

    for (int i=0; i<E; i++){
        cin >> e[i].from >> e[i].to >> e[i].cost;
        e[i].from -= 1;
        e[i].to -= 1;
        e[i].cost = -e[i].cost;
    }
    shortest_path(s);// starting from s
    if(negative[V-1] == true)  cout << "inf" << endl;
    if(negative[V-1] == false) cout << -d[V-1] << endl;
    return 0;
}

Measured memory_bytes: 256
program juice
	implicit none
    integer :: n, k, i, m, j
    integer,allocatable :: p(:)
    
    read(*,*) n, k
    allocate(p(n))
    
    read(*,*) p
    
    do i = n, 2, -1
    	do j = 1, i-1
        	if ( p(j)>=p(j+1) ) then
            	m = p(j+1)
                p(j+1) = p(j)
                p(j) = m
            end if
        end do
    end do
    
    write(*,*) sum(p(1:k))
    
    stop
end program juice

Measured memory_bytes: 2800
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 2LL << 60;
using ll = long long;
using P = pair<ll, ll>;

int main(int argc, char const *argv[]) {
    ll k, n, l;
    l=0;
    cin >> k >> n;
    vector<ll> a(n+1);
    rep(i, n){
        cin >> a.at(i);
    }
    a.at(n)=a.at(0)+k;
    rep(i, n){
        chmax(l, a.at(i+1)-a.at(i));
    }
    cout << k-l << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define all(v) (v.begin(),v.end())
#define ff first
#define ss second
const ll maxn=2e5+10;
const ll mod=998244353;


int main() {
  	fast;
  	ll k,s=0;
  	cin>>k;
  	for(ll a=1;a<=k;++a)
  	{
  		for(ll b=1;b<=k;++b)
  		{
  			for(ll c=1;c<=k;++c)
  			{
  				s+=__gcd(__gcd(a,b),c);
			  }
		  }
	  }
	  cout<<s;
}

Measured memory_bytes: 3692
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  for(int cs = 0 ; cs < n ; cs++){
    int A[10];
    for(int i = 0 ; i < 10 ; i++) cin >> A[i];

    int B = 0, C = 0;
    bool flag = 1;
    
    for(int i = 0 ; i < 10 ; i++){
      if(A[i] > B) B = A[i];
      else if(A[i] > C) C = A[i];
      else flag = 0;
      
      if(B < C) swap(B, C);
    }
    
    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    double ans = 0;
    int ans1 = 0, ans2 = 0;
    rep(a, 31) {
        rep(b, 31) {
            int water = a * A * 100 + b * B * 100;
            if (water > F) continue;
            int able_sugar = E * (water / 100);
            able_sugar = min(F - water, able_sugar);
            rep(c, 3001) {
                int sugarc = c * C;
                int sugard = D * ((able_sugar - sugarc) / D);
                int sugar = sugarc + sugard;
                if (water + sugar == 0 || able_sugar < sugar || sugard < 0 || water + sugar > F) continue;
                double sugarwater = (100.0 * sugar) / (water + sugar);
                if (ans <= sugarwater) {
                    // cout << able_sugar << " " << a << " " << b << " " << sugarc << " " << sugard << endl;
                    ans = sugarwater;
                    ans1 = water + sugar;
                    ans2 = sugar;
                }
            }
        }
    }

    cout << ans1 << " " << ans2 << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <list>

using namespace std;

int main() {
    int n;cin>> n;
    list <string> lt;
    list <string> md;
    list <string> rt;
    list <string> ot;
    for(int i = 0;i < n;i++){
        string s;cin >> s;
        if(s[0] == 'B' && s[s.length() - 1] == 'A'){
            md.push_back(s);
        }else if(s[0] == 'B'){
            rt.push_back(s);
        }else if(s[s.length() - 1] == 'A'){
            lt.push_back(s);
        }else{
            ot.push_back(s);
        }
    }
    int result = 0;
    string str = "";
    if(!lt.empty()) str += lt.front(),lt.pop_front();
    while(!md.empty()) str += md.front(),md.pop_front();
    if(!rt.empty()) str += rt.front(),rt.pop_front();
    while(!lt.empty() && !rt.empty()) str+= lt.front() + rt.front(), lt.pop_front(), rt.pop_front();
    while(!lt.empty())str += lt.front(),lt.pop_front();
    while(!rt.empty())str += rt.front(),rt.pop_front();
    while(!ot.empty())str += ot.front(),ot.pop_front();

    for(int i = 0;i < str.length();i++){
        if(str[i] == 'A' && str[i + 1] == 'B') result++;
    }
    cout << result << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 998244353
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n,a,b;
	cin>>n>>a>>b;
	vector<int> ans;
	if( abs(a-b) % 2 == 0 ){
		ans.pb( abs(a-b)/2 );
	}
	int a1 = a-1;
	a1 += (b-a)%2;
	a1 += (b-a)/2;
	int a2 = n-b;
	a2 += (b-a)%2;
	a2 += (b-a)/2;
	ans.pb(a1);
	ans.pb(a2);
	sort(ans.begin(),ans.end());
	cout<<ans[0]<<endl;
	return 0;
}

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

int main() {
	//input
	int N, M;
	cin >> N >> M;

	int sum = 0;

	vector<int> A(M);
	for (int i = 0; i < M; i++) {
		int temp;
		cin >> temp;
		sum += temp;
	}

	//calculation
	int output = N - sum;
	if (output < 0) {
		output = -1;
	}

	//output
	cout << output << endl;


	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int k,s;
    cin >> k>>s;
    int ans=0;
    for(int x=0;x<=k;x++){
        for(int y=x;y<=k;y++){
            for(int z=y;z<=k;z++){
                if(x+y+z==s){
                    if(x==y&&y==z){
                        ans +=1;
                    }
                    else if(x==y || y==z){
                        ans += 3;
                    }
                    else{
                        ans += 6;
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{

    ios::sync_with_stdio(false);

    int n;
    cin>>n;

    string s;
    cin>>s;

    string ans = "";

    for(int i=0;i<(int)s.length();++i)
        ans += ((n%26 + (s[i] - 65))%26 + 65);

    cout<<ans<<'\n';

    return 0;

}


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

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  ll h,n;
  cin >> h >> n;
  ll total = 0;
  rep(i, n) {
    int tmp;
    cin >> tmp;
    total += tmp;
    if(total >= h) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
S = input()
str_list = ['A','C','G','T']
cnt = 0
ans = 0

for i in range(len(S)):
    for j in range(i,len(S)):
        if S[j] in str_list:
            cnt += 1
        else:
            break
    ans = max(ans,cnt)
    cnt = 0
        
print(ans)

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

int main(int argc, const char * argv[]) {
    char x[200]={0},y[200]={0};
    int i=0,j=0,a=0;
    
    scanf("%d",&a);
    while(1){
        if(a==0){
            break;
        }
        scanf("%s %s",x,y);
        if(strcmp(x,y)>0){
            i+=3;
        }else if(strcmp(y,x)>0){
            j+=3;
        }else{
            i+=1;
            j+=1;
        }
        a--;
    }
    printf("%d %d\n",i,j);
    return 0;
}

Measured memory_bytes: 604