akhauriyash/Code-Regression huggingface dataset:
rectangles = 0 ; lozenges = 0
while True:
	try:
		a,b,c, = map(int,raw_input().split(','))
		if a*a + b*b == c*c: rectangles += 1
		else:
			if a == b: lozenges += 1
			else: pass
	except: break
print rectangles ; print lozenges

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

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

    int mins = 10000;
    for (int T=0; T < N-1; T++) {
        int s1 = 0;
        int s2 = 0;
        for (int i=0; i<=T; i++) {
            s1 += W[i];
        }
        for (int i=T+1; i<N; i++) {
            s2 += W[i];
        }

        mins = min(mins, abs(s1-s2));
    }

    cout << mins << endl;
   
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define PP pair<P,P>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	random_device rnd;
	mt19937_64 mt64(rnd());
	uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/

int n, k;
vector<int>G[2005];
vector<P>edge;
int far[2005];
bool flag;
void dfs(int x) {
	for (int i : G[x]) {
		if (far[i] == inf) {
			far[i] = far[x] + 1;
			dfs(i);
		}
	}
}
signed main() {
	cin >> n >> k;
	rep(i, n - 1) {
		int a, b; cin >> a >> b; a--; b--;
		G[a].push_back(b); G[b].push_back(a);
		edge.push_back({ a,b });
	}
	REP(i, n)far[i] = inf;
	int ans = inf;
	if (k % 2) {
		for (P p : edge) {
			rep(i, n)far[i] = inf;
			far[p.first] = 0, far[p.second] = 0;
			dfs(p.first); dfs(p.second);
			int cnt = 0;
			rep(i, n) { if (far[i] > k / 2)cnt++; }
			chmin(ans, cnt);
		}
	}
	else {
		rep(i, n) {
			rep(j, n)far[j] = inf;
			far[i] = 0;
			dfs(i);
			int cnt = 0;
			rep(j, n) { if (far[j] > k / 2)cnt++; }
			chmin(ans, cnt);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        long ans = 0;
        long min = 99999999999;
        for(int i = 0; i < n; i++)
        {
            long tmp = long.Parse(Console.ReadLine());
            ans += tmp;
            if(tmp % 10 != 0){
                min = Math.Min(min, tmp);
            }
        }

        if(min == 99999999999)
        {
            Console.WriteLine(0);
            return;
        }
        
        if(ans % 10 == 0)
        {
            Console.WriteLine(ans - min);
        }
        else
        {
            Console.WriteLine(ans);
        }

    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i,q) for(int i = 0; (q) > i; i++)
int main(){
  int a,b;cin>>a>>b;
  if(b%a == 0)cout << a+b << endl;
  else cout << b - a << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

struct Combination {
	vector<long long> inv,finv,fac;
	Combination(int n, int kmax) : inv(kmax+1),finv(kmax+1),fac(kmax){
		if(kmax>=1){
			inv.at(1)=1;
			finv.at(1)=1;
			fac.at(0) = n;
		}
	for(int i=2; i<=kmax; i++) inv.at(i) = MOD - inv.at(MOD%i) * (MOD/i) %MOD;
	for(int i=2; i<=kmax; i++) finv.at(i) = finv.at(i-1) * inv.at(i) % MOD;
	for(int i=1; i<kmax; i++) fac.at(i) = fac.at(i-1) * (n-i) % MOD;
	}
	long long comb(int k) {return (k ? fac.at(k-1) * finv.at(k) % MOD : 1 );}
};

int main(){
	
	ll n,k; cin>>n>>k;
	if(n-1<=k){
		Combination c(2*n-1,n);
		cout << c.comb(n) << endl;
	}
	else{
		Combination c(n,k);
		Combination d(n-1,k);
		ll sum{};
		for(int i=k; i>=0; i--){
			(sum += c.comb(i)*d.comb(i)) %= MOD;
		}
		cout << sum << endl;
	}
	
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define LONGMAX 1e18
#define MOD 1000000007
#define mp make_pair
#define endl "\n"
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define fr(a,n) for(int i=a;i<n;i++)

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n,k;
	cin>>n>>k;
	vector<int> a(n,0);

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

	//dp[i] =true if first player wins when there are i stone left

	vector<bool> dp(k+1);

	for(int i=0;i<=k;i++)
	{
		for(int x : a)
			if(i>=x and !dp[i-x])
				dp[i]=true;
	}

	if(dp[k])
		cout<<"First"<<endl;
	else
		cout<<"Second"<<endl;
}


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

#define rep(i, N) for(int i = 0; i < (int)N; i++)
#define ll long long
const ll INF = 2LL<<60;

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

    vector<int> L(N);
    rep(i,N)    cin >> L[i];

    vector<int> D(N + 10);

    D[0] = 0;
    for(int i = 1; i <= N + 1; i++)
    {
        D[i] = D[i - 1] + L[i - 1];
    }

    int ans = 0;
    rep(i, N+1)
    {
        if(D[i] <= X)   ans++;
        
        if(D[i] > X)    break;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
import itertools

N, X, Y = map(int, input().split())

# 距離が0,1,2,...,n-1のパスの本数
l = [0] * N

# 1,2,...,Nから2つを選ぶ組み合わせ
# 生成される組み合わせ(i,j)は既にi<jになっている
comb = itertools.combinations(range(1, N + 1), 2)

# (直接iとjを繋ぐ)or(特殊なパスを通る)の２種類が考えられる
# 両方計算してminを取れば欲しい距離が得られる
for v in comb:
    min_dist = min(v[1] - v[0], abs(X - v[0]) + 1 + abs(Y - v[1]))
    l[min_dist] += 1

# 距離が1,2,3,...,N-1について総数を出力
for item in l[1:]:
    print(item)


Measured memory_bytes: 9268
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
P<int,int> p[100005];
int a[100005],n,dp[100005];
int dfs(int e){
	if(dp[e]!=-1)return dp[e];
	if(e==n+1)return dp[e]=0;
	return dp[e]=max(dfs(e+1),dfs(upper_bound(a+1,a+n+1,a[e]+p[e].S)-a)+1);
}
signed main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	cin>>n;
	FOR(i,1,n){
		cin>>p[i].F>>p[i].S;p[i].S--;
		p[i].F+=1e9;p[i].F-=p[i].S;p[i].S*=2;p[i].S++;
		a[i]=p[i].F; 
	}
	sort(a+1,a+n+1);
	sort(p+1,p+n+1);
	memset(dp,-1,sizeof(dp));
	cout<<dfs(1);
	return 0;
}




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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    map<char, ll> mp;
    string S;
    ll N;
    cin >> N >> S;
    for(int i = 0; i < N; i++) {
        mp[S[i]]++;
    }
    ll ans = 1;
    for(char moji = 'a'; moji <= 'z'; moji++) {
        ans = (ans * (mp[moji] + 1)) % mod;
    }
    cout << (ans - 1 + mod) % mod << endl;
    return 0;
}


Measured memory_bytes: 512
let gcd x y =
  let rec doit x y =
    if y = 0 then x
    else doit y (x mod y) in
  doit (max x y) (min x y)

let lcm x y = x / (gcd x y) * y

let () =
  let n = read_int () in
  Array.init n (fun _ -> read_int ())
  |> Array.fold_left lcm 1
  |> Printf.printf "%d\n"

Measured memory_bytes: 384
#include <iostream>
using namespace std;
#define endl '\n'

int main(){

    int n;
    cin >> n;

    int num_2, num_4, odd;
    num_2 = num_4 = odd = 0;
    for(int i=0; i<n; i++){
        int number;
        cin >> number;

        if(number%4 == 0){
            num_4 ++;
        }else if(number%2 == 0){
            num_2 ++;
        }else{
            odd++;
        }
    }

    if(num_2 == 0){
        if(num_4+1 >= odd){
            cout << "Yes" << endl;
            
        }
        else{
            cout << "No" << endl;
            
        }
    }else{
        if(num_4 >= odd){
            cout << "Yes" << endl;
           
        }else{
            cout << "No" << endl;
        }
    }



    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<tgmath.h>
#include<stdbool.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

int N, F[111][10], P[111][11], ans = -1001001001;
int main(){
    scanf("%d", &N);
    for(int i=0; i<N; i++){
        for(int j=0; j<10; j++)scanf("%d", &F[i][j]);
    }
    for(int i=0; i<N; i++){
        for(int j=0; j<=10; j++)scanf("%d", &P[i][j]);
    }
    for(int i=1; i<1024; i++){
        int profit = 0;
        for(int j=0; j<N; j++){
            int cnt = 0;
            for(int k=0; k<10; k++){
                if(i&(1<<k))cnt += F[j][k];
            }
            profit += P[j][cnt];
        }
        ans = max(ans, profit);
    }
    printf("%d\n", ans);
    return 0;
}

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

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

    int n, time;
    cin >> n >> time;
    vector<int> t(n);
    for (int i = 0; i < n; ++i) cin >> t[i];

    ll totalTime = 0;
    for (int i = 1; i < n; ++i) {
        totalTime += min(time, t[i] - t[i-1]);
    }
    cout << totalTime + time << endl;

    return 0;
}

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

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

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 main() {
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    vector<int> good(n, 1);

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

    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        if (h[a] == h[b]) {
            good[a] = good[b] = 0;
        } else if (h[a] < h[b]) {
            good[a] = 0;
        } else {
            good[b] = 0;
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (good[i] > 0) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4052
#include<stdio.h>
int b_search(int t, int S[], int ns)
{
   int i;
   int tf = 0;
   if (S[ns / 2 - 1] == t) {
	  tf = 1;  
   }
   else if (S[ns / 2 - 1] > t) {
	  for (i = 0; i < (ns / 2 - 1); ++i) {
		 if (S[i] == t) {
			tf = 1; break;
		 }
	  }
   }
   else {
	  for (i = ns / 2 - 1; i < ns; ++i) {
		 if (S[i] == t) {
			tf = 1;  break;
		 }
	  }
   }
   return tf;
}

int main()
{
   int ns, nt;
   int S[150000], T[55000];
   int i = 0,
	   count = 0;
   int flag;

   scanf("%d", &ns);
   while (i < ns) {
      scanf("%d", &S[i]);
      i++;
   }
   i = 0;
   scanf("%d", &nt);
   while (i < nt) {
	   scanf("%d", &T[i]);
	   i++;
   }

   for (i = 0; i < nt; ++i) {
      count += b_search(T[i], S, ns);
   }

   printf("%d\n", count);
   return 0;
}

Measured memory_bytes: 2288
#include<stdio.h>
#include<stdlib.h>

#define MAX 10000

void CountingSort(unsigned short *,unsigned short  *,int );
int n;

int main(){
  int i,k;

  scanf("%d",&n);

  unsigned short *A, *B;

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);


  scanf("%d",&A[0]);
  k = A[0];
  for(i=1;i<n;i++){
    scanf("%d",&A[i]);
    if(k < A[i])k = A[i];
  }

  CountingSort(A,B,k);

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

void CountingSort(unsigned short *A,unsigned short  *B,int k){
  int i,C[MAX+1];

  for(i=0;i<=k;i++)
    C[i] = 0;

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

  for(i=1;i<=k;i++)
    C[i] = C[i] + C[i-1];

  for(i=n;i>=0;i--){
    B[C[A[i]]] = A[i];
    C[A[i]]--;
  }

}

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

int main() {
  long long a, v;
  long long b, w;
  long long t;
  cin >> a >> v;
  cin >> b >> w;
  cin >> t;
  string ans;
  if ( w >= v ) {
    ans = "NO";
  } else {
    long long len = v-w;
    long long dif = ( a > b ) ? a-b : b-a;
    ans = ( len*t >= dif ) ? "YES" : "NO";
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

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

  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  long long ans = 1000;
  int l = 0;
  for (int i = 0; i < n; ++i) {
    int mn = *min_element(a.begin() + l, a.begin() + i + 1);
    if (mn < a[i]) {
      ans += 1ll * (ans / mn) * (a[i] - mn);
      l = i;
    }
  }
  cout << ans;

  return 0;
}


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

int main() {
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  for(int i=1; i<=H; i++) {
    for(int j=1; j<=W; j++) {
      if (i <= H-B) {
        cout << (j <= A ? 1 : 0);
      }
      else if (i > H-B) {
        cout << (j <= A ? 0 : 1);
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 1280
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner sc = null;
		Map<Integer, Integer> nums = new HashMap<Integer, Integer>();
		try {
			sc = new Scanner(System.in);
			int maxValue = 0;
			while (sc.hasNextInt()) {
				int num = sc.nextInt();
				nums.put(num, nums.containsKey(num) ? nums.get(num) + 1 : 1);
				if (maxValue < nums.get(num)) {
					maxValue = nums.get(num);
				}
			}
			Arrays.sort(nums.keySet().toArray());
			for (Entry<Integer, Integer> entry : nums.entrySet()) {
				if (maxValue == entry.getValue()) {
					System.out.println(entry.getKey());
				}
			}

		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 26152
#include<cstdio>
#include<algorithm>

using namespace std;

int a[100005];
long long int fibo[100005];
long long int mod = 1000000007;

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

  fibo[0] = 1;
  fibo[1] = 1;
  for (int i = 2; i <= n; i++) {
    fibo[i] = fibo[i-1] + fibo[i-2];
    fibo[i] = fibo[i] % mod;
  }

  long long int ans = 1;
  int b = -1;
  for (int i = 0; i < m; i++) {
    scanf("%d", &a[i]);
    if (a[i] == b) continue;

    if (a[i] - b - 2 >= 0) {
      ans = (ans * fibo[a[i] - b - 2]) % mod;
    } else {
      ans = 0;
    }
    b = a[i];
  }
  ans = (ans * fibo[n+1 - b - 2]) % mod;

  printf("%lld\n", ans);

  return 0;
}


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

int main() {
  int N;
  long long int K;
  cin>>N>>K;
  vector<pair<int,int>> p(N);
  for(int i=0;i<N;i++){
    cin>>p.at(i).first>>p.at(i).second;
  }
  sort(p.begin(),p.end());
  int a,b=p.at(0).first;
  long long int c=p.at(0).second;
  deque<int> x{};
  deque<long long int> y{};
  for(int i=1;i<N;i++){
    a=b;
    b=p.at(i).first;
    if(a == b){
      c += p.at(i).second;
    }
    else{
      x.push_back(a);
      y.push_back(c);
      c=p.at(i).second;
    }
  }
  x.push_back(b);
  y.push_back(c);
  long long int z=0;
  int u=x.back();
  while(!x.empty()){
    if(z+y.front()<K){
      z += y.front();
      x.pop_front();
      y.pop_front();
    }
    else{
      cout<<x.front()<<endl;
      return 0;
    }
  }
  cout<< u<<endl;
}

Measured memory_bytes: 1792
#デフォルト
import itertools
from collections import defaultdict
import collections
import math
import sys
sys.setrecursionlimit(200000)
mod = 1000000007

x, n = map(int, input().split())
p = list(map(int, input().split()))

sub = [False] * 210
for i in range(n):
    sub[p[i] + 105] = True
sub[x] = True

ans = mod
nn = 0
for i in range(210):
    if not sub[i]:
        if ans > abs((i - 105) - x):
            nn = i - 105
            ans = abs((i - 105) - x)
            

print(nn)

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

int main(void){
    int T,D,L;
    while(cin>>T>>D>>L,T|D|L){
        vector<int> imos(T+D);
        rep(i,T){
            int x;
            cin>>x;
            if(x>=L)imos[i]++,imos[i+D]--;
        }
        int res=0;
        rep(i,T-1){
            imos[i+1]+=imos[i];
            if(imos[i]>0)res++;
        }
        cout<<res<<endl;
    }
    return 0;
}

Measured memory_bytes: 4272
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long int ll;

int main() {
  int N,M;
  cin>>N>>M;
  
  int wa=0;
  vector<int> A(M);
  rep(i,M){
    cin>>A[i];
    wa+=A[i];
  }
  
  int ans=N-wa;
  if(ans<0)
    ans=-1;
  
  cout<<ans<<endl;
  

}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int64_t saiki(int64_t n, int64_t x, vector<int64_t> p){
    int64_t ans;
    if (x == 1) {
        if (n == 0) ans = 1;
        else ans = 0;
        return ans;
    }
    if (x > 1 && x < (pow(2, n + 1) - 1)){
        //cout << "jj" << endl;
        ans = saiki(n - 1, x - 1, p);
    }
    if (x == pow(2, n + 1) - 1){
        //cout << "ii" << endl;
        ans = p.at(n - 1) + 1;
    }
    if (x > pow(2, n + 1) - 1 && x < pow(2, n + 2) - 3){
        ans = p.at(n - 1) + 1 + saiki(n - 1, x - (pow(2, n + 1) - 1), p);
    }
    if (x == pow(2, n + 2) - 3){
        ans = p.at(n);
    }
    return ans;
    
}
int main(){
    int64_t N, X;
    cin >> N >> X;
    vector<int64_t> p(N + 2, 1);
    for (int i = 0; i <= N; i++){
        p.at(i + 1) = 2 * p.at(i) + 1;
    }
    int64_t ans = saiki(N, X, p);
    cout << ans << endl;
}

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

int main()
{
    string S;
    cin >> S;
    vector<char> op(3);

    for (int bit = 0; bit < (1 << S.size() - 1); bit++) {
        long long int res = 0;
        for (int i = 0; i < S.size() - 1; i++) {
            if (bit & (1 << i)) {
                res -= stoll(S.substr(i + 1, 1));
                op[i] = '-';
            }
            else {
                res += stoll(S.substr(i + 1, 1));
                op[i] = '+';
            }
        }
        res += stoll(S.substr(0, 1));
        if (res == 7) {
            break;
        }
    }

    cout << S[0] << op[0] << S[1] << op[1] << S[2] << op[2] << S[3] << "=7" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}

void solve()
{
	ll n, k;
	cin >> n >> k;
	cout << min(n % k, abs(n % k - k));
}


 
 
int main()
{
    Red;
	int T = 1;
	//cin >> T; 
	for(int i = 1; i <= T; ++i){
		solve();
	}
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;
 
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1)
 
const double EPS = 1e-10;
 
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

ll modpow(ll a, ll n, ll m){
    if(n == 0) return 1;
    ll half = modpow(a,n/2,m);
    ll res = half * half % m;
    if(n & 1) res = res * (a%m) % m;
    return res;
}

int main(){
    int k; cin >> k;
    ll now = 0;
    repr(i,1,k+1){
        ll d = modpow(10,i-1,k)*7%k;
        now += d;
        now %= k;
        if(now == 0){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 3624
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int s = Integer.parseInt(sc.next());
	static List<Integer> a = new ArrayList<>();
	public static void main(String[] args) {
		a.add(s);
		for (int i = 0; i <= 1000000 -2; i++) {
			int temp = calc(a.get(i));
			if (a.contains(temp)) {
				System.out.println(i+2);
				break;
			}
			a.add(temp);
		}
	}
	static int calc(int ai) {
		if (ai%2 == 0) {
			return ai/2;
		} else {
			return 3*ai + 1;
		}
	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
//RMQ
const int MAX_N = 1 << 17;//over 100000
int n,dat[(MAX_N<<1)-1];
void init(){
  int nn = 1;
  while(nn < n) nn <<= 1;
  n = nn;
  fill(dat,dat+(n<<1)-1,INT_MAX);
}
void update(int k,int a){
  k += n-1;
  dat[k] = a;
  while(k > 0){
    k = (k-1)>>1;
    dat[k] = min(dat[(k<<1)+1],dat[(k<<1)+2]);
  }
}
//[a,b),[l,r)
int query(int a,int b,int k = 0,int l = 0,int r = n){
  if(r <= a || b <= l) return INT_MAX;
  if(a <= l && r <= b) return dat[k];
  int vl = query(a,b,(k<<1)+1,l,(l+r)>>1);
  int vr = query(a,b,(k<<1)+2,(l+r)>>1,r);
  return min(vl,vr);
}
int main(){
  int q,i,c,x,y;scanf("%d%d",&n,&q);
  init();
  for(i=0;i<q;i++){
    scanf("%d%d%d",&c,&x,&y);
    if(c == 0) update(x,y);
    else printf("%d\n",query(x,y+1));
  }
}


Measured memory_bytes: 4236
fn main() {
    let (a, b) = input();

    println!("a {} b", if a == b { "==" } else if a > b { ">" } else { "<" });
}

fn input() -> (i32, i32) {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut i = s.trim().split_whitespace().map(|q| q.parse::<i32>().unwrap());

    (i.next().unwrap(), i.next().unwrap())
}



Measured memory_bytes: 5024
#include <stdio.h>
#include <string.h>
int main()
{
    char s[11];
    int i,len;
    gets(s);
    len = strlen(s);
    for(i=0;i<len;i++)
    {
        if(i==3)
        {
            s[i]+=1;
        }
    }
    printf("%s\n",s);
    return 0;
}


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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
#define VL vector<lol>
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define PI 3.1415926535897932385 //pi
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
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 gcd(int a,int b){return b?gcd(b,a%b):a;}
//繰り返し二乗法
int modPow(long long a, long long n, long long p) {
    if (n == 0) return 1; // 0乗にも対応する場合
    if (n == 1) return a % p;
    if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
    long long t = modPow(a, n / 2, p);
    return (t * t) % p;
}
int modDev(lol a, lol b)
{
    if(a < b || a < 0) return 1;
    return (a*(modPow(b, MOD-2, MOD)))%MOD;
}

int main()
{
    
    string s; cin >> s;
    if(s[s.length()-1] == 's') s += "es";
    else s += 's';
    cout << s << endl;

    
    return 0;
}

Measured memory_bytes: 3628
n, m = map(int, input().split())
a = set([int(input()) for x in range(m)])

l = [0]*(n+1)
l[0] = 1

for i in range(1, n+1):
  if i in a:
    l[i] = 0
    continue
  else:
    l[i] = l[i-2] + l[i-1]

print(l[-1] % 1000000007)


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

using namespace std;

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

	long long n;
	cin >> n;

	vector<pair<long long, long long>> arr;
	
	for (long long i = 2; i * i <= n; ++i) {
		if (n % i == 0) {
			long long cnt = 0;
			while (n % i == 0) {
				n /= i;
				cnt++;
			}
			arr.push_back({i, cnt});
		}
	}
	if (n > 1) {
		arr.push_back({n, 1});
	}

	int ret = 0;
	for (auto a : arr) {
		long long cnt = 0, sum = 0;
		for (int i = 1; sum + i <= a.second; ++i) {
			sum += i;
			++cnt;
		}
		ret += cnt;
	}
	cout << ret << "\n";

}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
 
const int INF=1e9;
int N,M;
 
int K[200],S[200][200],H[200][200];
int X[200];
int sum[200][441];
 
int dp[2][201][21];
 
int main(){
    cin>>N>>M;
    for(int i=0;i<N;i++){
        cin>>K[i];
        int cur=0;
        for(int j=0;j<K[i];j++){
            cin>>S[i][j]>>H[i][j];
            int next=cur;
            while(next-cur<H[i][j]){
                sum[i][next]=S[i][j]+(next?sum[i][next-1]:0);
                next++;
            }
            cur=next;
            X[i]+=H[i][j];
        }
        sum[i][cur]=INF;
    }
 
 
    fill_n(**dp,2*201*21,INF);
    dp[0][0][0]=0;
 
    for(int i=0;i<N;i++){
        for(int j=0;true;j++){
            for(int k=0;k<=M;k++){
                int v=(j?sum[i][j-1]:0),s=sum[i][j]-(j?sum[i][j-1]:0);
                for(int l=0;l<=20;l++){
                    int t=(sum[i][j]==INF?l:(l?min(l,s):s));
                    if(k+j<=M)dp[(i+1)&1][k+j][t]=min(dp[(i+1)&1][k+j][t],dp[i&1][k][l]+v);
                }
            }
            if(sum[i][j]==INF)break;
        }
 
        for(int j=0;j<=M;j++){
            for(int k=0;k<=20;k++){
                dp[i&1][j][k]=INF;
            }
        }
    }
 
    double ans=0;
 
    for(int i=0;i<=M;i++){
        for(int j=0;j<=20;j++){
            if(dp[N&1][i][j]<=M){
                ans=max(ans,i+(j?min(1.0,1.0*(M-dp[N&1][i][j])/j):0.0));
            }
        }
    }
 
    printf("%.8lf\n",ans);
    return 0;
}

Measured memory_bytes: 3868
#include <bits/stdc++.h>
using namespace std;
#define FASTIO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vi vector<ll>
#define all(a) (a).begin(), (a).end()
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define tr(it, a)   for(auto it=a.begin();it!=a.end();it++)
#define pb push_back
#define endl  "\n"
const ll MAX=1e5+3;
const ll mod=1e9+7;
vi wt(105),profit(105);
ll n,total;
ll fun()
{
    ll dp[105][100005]={0},i,j;
    //memset(dp,0,sizeof(dp));
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=total;j++)
        {
            if(j<wt[i-1])
                dp[i][j]=dp[i-1][j];
            else{
            dp[i][j]=max(dp[i-1][j],profit[i-1]+ dp[i-1][j-wt[i-1]]);
            //cout<<profit[i-1]+ dp[i-1][j-wt[i-1]]<<endl;
            }
        }
    }
   /* for(i=0;i<=n;i++)
    {
        for(j=0;j<=total;j++)
        {
        cout<<dp[i][j]<<" ";
    }
    cout<<endl;*/

    return dp[n][total];

}
int main()
{
   FASTIO
   int t=1;
  // cin>>t;
   while(t--)
  {
       // ll n,k;
        cin>>n>>total;
        ll x,y;
        rep(i,0,n)
        {
            cin>>x>>y;
            wt[i]=x;
            profit[i]=y;
        }
        ll ans=fun();
        cout<<ans;

   }
 return 0;
}


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

int main(){
    string S;
    cin >> S;
    int N = S.length();

    string invS = S;
    reverse(invS.begin(), invS.end());
    if (S != invS){
        cout << "No" << endl;
        return 0;
    }

    string substr = S.substr(0, (N - 1) / 2);
    // cout << substr << endl;
    string invsubstr = substr;
    reverse(invsubstr.begin(), invsubstr.end());
     if (substr != invsubstr){
        cout << "No" << endl;
        return 0;
    }   

    string substr2 = S.substr((N + 3) / 2 - 1, N - 1);
    // cout << substr2 << endl;
    string invsubstr2 = substr2;
    reverse(invsubstr2.begin(), invsubstr2.end());
     if (substr2 != invsubstr2){
        cout << "No" << endl;
        return 0;
    }   

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

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 30

int table[30] = {};

signed main()
{
    string S;
    cin >> S;
    REP(i, S.length()) {
        table[S[i] - 'a']++;
    }
    REP(i, 30) {
        if(table[i] % 2 != 0) {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");

    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		List<Integer> aList = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			aList.add(sc.nextInt());
		}
		int ans = (N + K - 3) / (K - 1);
		System.out.println(ans);
	}
}

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

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

  int A[105];
  int sum = 0;
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
    sum += A[i];
  }

  double border = ((double)sum) / 4.0 / ((double)M);
  int count = 0;
  for (int i = 0; i < N; i++)
  {
    if (A[i] >= border)
    {
      count++;
    }
  }

  if (count >= M)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }

  return 0;
}

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

vector<pair<int, int> >adj[16];
int mx = 0;
int n;
void check(vector<int> &v){
    vector<int>a(n + 1, -1);
    f(i, n){
        if(v[i] == 0)a[i + 1] = 0;
    }
    auto check1 = [&](int p){
        for(auto &it : adj[p]){
            if(a[it.first] == -1)a[it.first] = it.second;
            else if(a[it.first] == 0 && it.second != 0)return false;
            else if(a[it.first] == 1 && it.second != 1)return false;
        }
        return true;
    };
    int cnt = 0;
    f(i, n){
        if(v[i] == 1){++cnt;
            int j = i + 1;
            if(a[j] != -1 && a[j] != 1)return;
            a[j] = 1;
            for(auto &it : adj[j]){
                int p = it.first;
                int q = it.second;
                if(q == 1)if(!check1(p))return;
                if(a[it.first] == -1)a[it.first] = it.second;
                else if(a[it.first] == 0 && it.second != 0)return;
                else if(a[it.first] == 1 && it.second != 1)return;
            }
        }
    }
    mx = max(mx, cnt);
}
void solve(int i, vector<int>&v){
    if(i > n){
        check(v);return;
    }
    v.pb(0);
    solve(i + 1, v);
    v.pop_back();
    v.pb(1);
    solve(i + 1, v);
    v.pop_back();
}
void input(){
  cin >> n;
  f(i, n){
    int x; cin >>x;
    while(x--){
        int p, q;
        cin >> p >> q;
       adj[i + 1].pb({p, q});
    }
  }
  vector<int>v;
  solve(1, v);
  cout << mx << endl;
}
int main(){
    input();
    return 0;
}



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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

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

    string S;
    cin >> S;

    string keyence = "keyence";
    
    bool f = false;
    for (int i = 0; i <= 7; i++) {
        if (i == 0 || keyence.substr(0, i) == S.substr(0, i)) {
            // cout << FMT3(i, keyence.substr(0, i), S.substr(0, i)) << endl;
            if (i == 7 || keyence.substr(i, 7-i) == S.substr(S.size() - 7 + i, 7-i)) {
                // cout << FMT3(i, keyence.substr(i, 7-i), S.substr(S.size() - 7 + i, 7-i)) << endl;
                f = true;
                break;
            }
        }
    }
    YES(f);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
    if(c == '-') f = -1;
    c = getchar();
    }
    while(c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
int A[MAXN];
int pw[MAXN][25],cnt[MAXN],ans;
vector<pii > v;
void Init() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) read(A[i]);
    cnt[1] = 1000000000;
    for(int i = 1 ; i <= N ; ++i) {
        pw[i][0] = 1;
        for(int j = 1 ; j <= 20 ; ++j) {
            if(pw[i][j - 1]  > N / i) {
                cnt[i] = j - 1;break;
            }
            pw[i][j] = pw[i][j - 1] * i;
        }
    }
}
bool check(int mid) {
    v.clear();
    v.pb(mp(A[1],0));int sum = A[1];
    for(int i = 2 ; i <= N ; ++i) {
	if(A[i] <= A[i - 1]) {
	    if(mid == 1) return false;
	    if(sum < A[i - 1]) {v.pb(mp(A[i - 1] - sum,0));sum = A[i - 1];}
	    int s = v.size() - 1;
	    for(int k = s ; k >= 0 ; --k) {
		if(sum - v[k].fi >= A[i]) {sum -= v[k].fi;v.pop_back();}
		else {
		    int t = sum - A[i];
		    if(t > cnt[mid]) v[k].se = 0;
		    else v[k].se /= pw[mid][t];
		    v[k].fi -= t;
		    sum = A[i];
		}
		if(sum == A[i]) break;
	    }
	    s = v.size() - 1;
	    for(int k = s ; k >= 0 ; --k) {
		if(v[k].fi <= cnt[mid]) {
		    if(v[k].se + 1 < pw[mid][v[k].fi]) {++v[k].se;break;}
		    else {
			v[k].se = 0;if(k == 0) return false;
		    }
		}
		else {++v[k].se;break;}
	    }
	}
    }
    return true;
}
void Solve() {
    int l = 1,r = N;
    while(l < r) {
	int mid = (l + r) >> 1;
	if(check(mid)) r = mid;
	else l = mid + 1;
    }
    out(l);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Init();
    Solve();
}


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

int main() {
  char index[6] = {'A', 'B', 'W', 'X', 'Y', 'Z'};
  int field[6][6] = {
    {-1, -1, -1,  0,  1, -1},
    {-1, -1, -1,  1,  0, -1},
    {-1,  0, -1, -1,  1, -1},
    {-1, -1, -1, -1, -1,  1},
    {-1, -1, -1,  0, -1, -1},
    {-1,  1,  0, -1, -1, -1}
  };

  string s;
  while(cin >> s, s != "#") {
    int f = 0;
    bool b = true;
    for(int i = 0; i < s.size(); i++) {
      int next = s[i]-'0';
      int p = -1;
      for(int j = 0; j < 6; j++) {
        if(next == field[f][j]) p = j;
      }
      if(p == -1) b = false;
      f = p;
    }

    if(b && f == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 1188
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Ord

main :: IO ()
main = readLine >>= main'
    where
        main' [n, k] = readContents n >>= print . solve k 

solve :: Int -> [[Int]] -> Int
solve k = check k . sortBy cmpf
    where
        cmpf = comparing head
        check c ([a, b] : xs)
            | c > b = check (c - b) xs
            | otherwise = a

readLine :: IO [Int]
readLine = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

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

    	
    	
#define ll long long
#define pb push_back
#define mp make_pair

ll power(ll x,ll b)
{
    ll res=1;
    if(b==0)
    return 1;
    while(b>0)
    {
      if(b%2!=0)
      res=(res*x);
      b=b/2;
      x=(x*x);
      
    }
    return res;
}
 
 
       


  



      
   
    	
using namespace std;

 
vector<ll> primes;
void SieveOfEratosthenes(int n) 
{ 
    
    vector<ll>prime(200001,0);
  
    for (int p=2; p*p<=n;p++) 
    { 
       
        if (prime[p] == 0) 
        { 
           
            for (int i=p*p; i<=n; i += p) 
                prime[i] = 1; 
        } 
    } 
    
  
    // Print all prime numbers 
    for (int p=1; p<=n; p++) 
       if (prime[p]==0) 
        {
            primes.pb(p);
        }
} 












int main()
{
   
    ll n,k;
    cin>>n>>k;
    ll arr[n+1];
    for(ll i=0;i<n;i++)
    cin>>arr[i+1];
  
    ll dp[n+1],i,j;
    ll x=n/k;
    ll r=n-k*x;
    ll ans=0,l=1;
    
    if(n>k+1)
    {
        if(k!=1)
        {
            for(i=2;i<=k+1;i++)
            dp[i]=abs(arr[i]-arr[1]);
        
        for(i=k+2;i<=n;i++)
        {
            
          
            for(j=0;j<k;j++)
            {
                if(j==0)
                ans=dp[i-k]+abs(arr[i]-arr[i-k]);
                else
                ans=min(ans,dp[j+i-k]+abs(arr[i]-arr[i-k+j]));
                
            }
            dp[i]=ans;
            
            
            
        }
        cout<<dp[n];
        }
       // cout<<dp[2]<<" "<<dp[3]<<" "<<dp[4];
        //}
        else
        {
            for(i=1;i<n;i++)
            ans=ans+abs(arr[i+1]-arr[i]);
            cout<<ans;
        }
        
        
        
    }
    else
    {
        ans=arr[2]-arr[1];
        if(n>2)
        {
            for(i=3;i<=n;i++)
        {
            ans=min(ans,abs(arr[i]-arr[1]));
        }
        }
        cout<<ans;
    }
   
  
      
       
    

   







}



Measured memory_bytes: 5152
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define INF (1ll<<60)
typedef pair<int, int> pii;
#define FI first
#define SE second
#define all(s) s.begin(),s.end()

int N, M;

signed main() {
	cin >> N >> M;
	if (M / 2 <= N) {
		cout << M / 2 << endl;
		return 0;
	}
	cout << (N + M / 2) / 2 << endl;
}


Measured memory_bytes: 256
def eachdigitsum(n):
	x = len(str(n))
	sum = 0
	for i in range(x):
		t = n//10**(x-i-1)
		n = n - t*10**(x-i-1)
		sum += t
	return sum
	
n = int(input())
min = 1000000
for i in range(1,n//2 + 2):
	x = eachdigitsum(i) + eachdigitsum(n-i)
	if min > x:
		min = x
print(min)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

constexpr int MOD = int(1e9) + 7;

int N;
vector<int> a;
vector<int> idxs[200010];

i64 memo[200010];
i64 dp(int i) {
    if (i > N) {
        return 0;
    }
    if (i == N) {
        return 1;
    }

    i64 &ret = memo[i];
    if (~ret) return ret;

    ret = 0;
    const int nxt = *upper_bound(all(idxs[a[i]]), i);
    ret += dp(i+1); ret %= MOD;
    if (nxt != INF) {
        ret += dp(nxt); ret %= MOD;
        // ret += dp(nxt + 1); ret %= MOD;
    }

    return ret;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    read(N);

    a.resize(N);
    rep(i, N) read(a[i]);

    a.erase(unique(all(a)), a.end());
    N = a.size();

    rep(i, N) {
        idxs[a[i]].push_back(i);
    }

    rep(i, 200010) {
        idxs[i].push_back(INF);
    }

    memset(memo, -1, sizeof(memo));
    print(dp(0));

    return 0;
}


Measured memory_bytes: 20736
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T &v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

ll k;

template<class T1, class T2>
T1 intpow(const T1& a, const T2 n) {
  if (n == 0) return 1;
  auto t = intpow(a, n / 2);
  t = t * t;
  if (n & 1) t = t * a;
  return t;
}

int main() {
  in(k);
  ll x = 0;
  loop(i,0,10000000) {
    x = ((x * 10) + 7) % k;
    if (x % k == 0) {
      print(i+1);
      return 0;
    }
  }
  
  print(-1);
  return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		for(int i=0;i<n;i++){
			int x=sc.nextInt();
			int y=sc.nextInt();
			int z=sc.nextInt();
			if(x>y&&x>z){
				if(x*x==y*y+z*z){
					System.out.println("YES");
				}else{
					System.out.println("NO");
				}
			}else if(y>x&&y>z){
				if(y*y==x*x+z*z){
					System.out.println("YES");
				}else{
					System.out.println("NO");
				}
			}else if(z>x&&z>y){
				if(z*z==x*x+y*y){
					System.out.println("YES");
				}else{
					System.out.println("NO");
				}
			}else{
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 23396
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;

int kaisuu(int x,int y,vvc a,vvi rec){
  if(x==0&&y==0){
    int k=0;
    if(a[0][0]=='#')k=1;
    rec[0][0]=k;
    return k;
  }
  
  if(x==0){
    int k=rec[0][y-1];
    if(a[0][y]=='#'&&a[0][y-1]=='.')k++;
    rec[0][y]=k;
    return k;
  }
  if(y==0){
    int k=rec[x-1][0];
    if(a[x][0]=='#'&&a[x-1][0]=='.')k++;
    rec[x][0]=k;
    return k;
  }
  
  
  int k=rec[x-1][y];
  int l=rec[x][y-1];
  if(a[x][y]=='#'&&a[x-1][y]=='.')k++;
  if(a[x][y]=='#'&&a[x][y-1]=='.')l++;
  int c=min(k,l);
  rec[x][y]=c;
  return c;
}



int main() {
  int h,w;
  cin >> h >> w;
  vvc a(h,vc(w));
  rep(i,h) rep(j,w) cin >> a[i][j];
  vvi rec(h,vi(w,0));
  rep(i,h) rep(j,w) rec[i][j]=kaisuu(i,j,a,rec);
  cout << rec[h-1][w-1] << endl;
  
}


Measured memory_bytes: 384
import std.stdio, std.conv, std.string, std.algorithm,
       std.math, std.array, std.container, std.typecons;

void main() {
  long n, m;
  readf("%d %d\n", &n, &m);
  auto h = readln.chomp.split.to!(long[]);
  DList!long[] connected = new DList!long[n];
  for(long i=0; i<m; i++) {
    long a, b;
    readf("%d %d\n", &a, &b);
    a--; b--;
    connected[a].insert(b);
    connected[b].insert(a);
  }
  long count=0;
  for(long i=0; i<n; i++) {
    bool good = true;
    foreach(c;connected[i]) {
      good &= h[i] > h[c];
    }
    if(good) count++;
  }
  count.writeln;
}


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

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


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    ABC = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j")

    def dfs(s, n, i):
        if n == N:
            print(s)
            return
        for j in range(i+1):
            dfs(s + ABC[j], n+1, i + 1 if i == j else i)
    dfs("a", 1, 1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 4412