akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
#define P pair<int, int>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> A(n+1);
    for(int i = 1; i <= n; i++){
        int a;
        cin >> a;
        A[i] = a;
    }
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        int tmp = A[i];
        if(i == A[tmp]) cnt++;
    }
    cout << cnt/2 << endl;
    return 0;
}

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

const int MOD = 1000000007;
#define p(var)  std::cout<<var<<std::endl
#define pp(var) std::cout<<#var" = "<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for (int i = 0; i <  (n); i++)
#define repeq(i, n) for (int i = 1; i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
using ll = long long;
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a;}
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b;}

/*-----8<-----8<-----*/

int main(){
    int X,Y;
    cin >> X >> Y;
    
    if(X==Y)cout << X*2 << endl;
    else {int A=max(X,Y);
     cout << A*2-1 << endl;
    }
    return 0;
    
}






Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[100100];
int main()
{
	//cin>>ss;
	scanf("%s",s);
	int len=strlen(s);
	for(int i=len-1;i>=0;i--)
	 if(s[i]=='F'&&s[i+1]=='E') 
	 {
	 	s[i]='\0';
	 	break;
	 }
	 printf("%s",s);
}  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct unionFind{
  vector<int>par;
  vector<long>count;

  unionFind(int n):par(n){
    for(int i=0;i<n;i++)par[i] = i;
    count.resize(n);
    for(int i=0;i<n;i++)count[i]=1;
  }


  int find(int x){
    if(par[x]==x)return x;
    else return par[x]=find(par[x]);
  }

  void unite(int x,int y){
    int rx = find(x);
    int ry = find(y);
    if(rx==ry)return;
    else{
      par[rx]=ry;
      count[ry]+=count[rx];
      return;
    }
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
};


int main(){
  long n,m;
  cin >> n >> m;
  vector<long>ans(m,0);
  vector<int>a(m);
  vector<int>b(m);
  int i;
  for(i=0;i<m;i++){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  unionFind unif(n);
  ans[m-1] = (n*(n-1))/2;
  for(i=m-1;i>0;i--){
    if(!unif.same(a[i],b[i]))ans[i-1]=ans[i]-(unif.count[unif.find(a[i])]*unif.count[unif.find(b[i])]);
    else ans[i-1]=ans[i];
    unif.unite(a[i],b[i]);
  }

  for(i=0;i<m;i++){
    cout << ans[i]<<endl;
  }



}


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

typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;


//===

const ll mod = static_cast<ll>(1e9 + 7);



int main() {
	int n;
	cin >> n;
	Vi a(n);
	int ncnt = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		if (a[i] < 0) ++ncnt;
	}

	sort(a.begin(), a.end());
	if (ncnt == n) --ncnt;
	else if (ncnt == 0) ++ncnt;

	Vi x, y;
	int tmp = a[ncnt - 1];
	for (int i = ncnt; i < n - 1; ++i) {
		x.push_back(tmp);
		y.push_back(a[i]);
		tmp -= a[i];
	}

	int ans = a[n - 1];
	for (int i = 0; i < ncnt - 1; ++i) {
		x.push_back(ans);
		y.push_back(a[i]);
		ans -= a[i];
	}

	x.push_back(ans);
	y.push_back(tmp);
	ans -= tmp;

	cout << ans << endl;
	for (int i = 0; i < x.size(); ++i) {
		cout << x[i] << " " << y[i] << endl;
	}
}

Measured memory_bytes: 3316
#include <stdio.h>
#define p (int)(1e9 + 7)


long long int MOD(long long int a){
	return (a+p) % p;
}
 
long long int power(long long int a, int n){
	if(n == 0){
		return 1;
	}
	else if(n % 2 == 0){
		return power(MOD(a * a), n / 2);
	}
	else{
		return MOD(a * power(a, n - 1));
	}
}
 
long long int inverse(long long int a){
	return power(a, p - 2);
}


int main(void){
    int n;
    scanf("%d",&n);
    int a[n];
    for(int i=0;i<n;i++)a[i]=0;
    int kari;
    int nagasa;
    for(int i=0;i<n+1;i++){
        scanf("%d",&kari);
        if(a[kari-1]==0)a[kari-1]=i+1;
        else nagasa=i-a[kari-1];
    }
    long long int nCk1[n+2],nCk2[n+2];
    nCk1[0]=1;
    nCk2[0]=0;
    nCk2[1]=1;
    for(int i=1;i<=n+1;i++){
        nCk1[i]=MOD(MOD(nCk1[i-1]*(n+2-i))*inverse(i));
    }
    
    for(int i=2;i<=n+1;i++){
        if(n+1-nagasa<=i)nCk2[i]=0;
        else nCk2[i]=MOD(MOD(nCk2[i-1]*(n+1-i-nagasa))*inverse(i-1));
    }
    
    for(int i=1;i<=n+1;i++){
        printf("%lld\n",MOD(nCk1[i]-nCk2[i]));
    }
    
    return 0;
}


Measured memory_bytes: 3072
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
/* 約数の列挙 */
vector<ll> divisorExec(ll n)
{
	vector<ll> res;
    for(ll i = 1; i <= sqrt(n); i++){
		if ((n % i) == 0) {
			res.push_back(i);
			if ((i * i) != n) {
				res.push_back(n / i);
			}
		}
	}
	sort(res.begin(), res.end());
	return res;
}

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

	int ans = 0;
	vector<ll> divRes;
	REP(i, N + 1) {
		if (IsOdd(i)) {
			divRes = divisorExec(i);
			if (divRes.size() == 8) {
				ans++;
			}
		}
	}

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


Measured memory_bytes: 256
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] s = br.readLine().split(" ");
        int a = Integer.parseInt(s[0]);
        int b = Integer.parseInt(s[1]);
        int ans = b;
        
        if (a <= 12) {
            ans /= 2;
            if (a <= 5) {
                ans = 0;
            }
        }
        

        System.out.println(ans);
    }
}





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

int main()
{
    int m,n;
    while(cin>>m>>n)
    {
       if(n==0&&m==0) return 0;
       else{ 
              for(int i=0;i<m;i++)
                {
                      for(int j=0;j<n;j++)
                    {
                        cout<<"#";
                    }
                    cout<<endl;
                 }
           }
         cout<<endl;
    }
    return 0;
}


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


const ll MOD = 1000000007LL;

int main() {
  int N; cin>>N;
  vector<int> A(N), cnt(N+1, 0);
  REP(i,N) {
    cin>>A[i];
  }
  cnt[0] = 3;
  ll ans = 1;
  REP(i, N) {
    ans *= (ll)cnt[A[i]];
    ans %= MOD;
    cnt[A[i]]--;
    cnt[A[i]+1]++;
  }
  ans %= MOD;
  cout << ans << endl;
  return 0;
}


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

void solve(void)
{
    string s;
    cin >> s;
    int ans = 0;
    int len = s.length();
    int cta = 0;
    rep(i, len)
    {
        if (s[i] == 'S')
            cta++;
        else if (s[i] == 'T' && cta > 0)
            cta--;
        else
            ans++;
    }
    cout << ans + cta << endl;
}
int main(void)
{
    solve();
}

Measured memory_bytes: 3740
using System;
using System.Linq;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = Convert.ToInt32(Console.ReadLine());
            int[] P = Console.ReadLine().Split().Select(i => Convert.ToInt32(i)).ToArray();
            int[] sortedP = new int[N];
            Array.Copy(P, sortedP, N);
            Array.Sort(sortedP);
            int missCount = 0;
            for (var i = 0; i < N; i++)
            {
                if (P[i] != sortedP[i])
                {
                    missCount++;
                }
                if (missCount > 2)
                {
                    Console.WriteLine("NO");
                    return;
                }
            }
            Console.WriteLine("YES");
        }
    }
}


Measured memory_bytes: 13268
A = int(input()) #500円
B = int(input()) #100円
C = int(input()) #50円
X = int(input())

"""
A = 10C → C = 0.1A
B = 2C → C = 0.5B
"""
counter = 0

for a in range(A+1):
    tmpa = X - 500*a
    for b in range(B+1):
        tmpb = tmpa - 100*b
        for c in range(C+1):
            tmpc = tmpb - 50*c
            if tmpc == 0:
                counter += 1
                #print(a,b,c)

print(counter)


   




Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.Integer; 
 
public class Main {
    public static void main(String[] args) {
 
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
 
        String takoyaki = null;
        String oishisa = null;
        try {
            takoyaki = br.readLine();
            oishisa = br.readLine();
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Integer takoyakiInt= Integer.parseInt(takoyaki);
        String[] oishisaDankai = oishisa.split(" ");
        int kaihuku = 0;
        for (int i = 0;i < takoyakiInt; i++){
                for  (int j = i+1;j < takoyakiInt; j++){
                        Integer x= Integer.parseInt(oishisaDankai[i]);
                        Integer y= Integer.parseInt(oishisaDankai[j]);
                        kaihuku = kaihuku + x*y;
                }
        }
        System.out.println(kaihuku);
    } 
}

Measured memory_bytes: 22228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll x,ll y){
  if(x<y) swap(x,y);
  ll z=x%y;
  while(z){
    x=y;y=z;z=x%y;
  }
  return y;
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}
ll lcm(ll x,ll y,ll z){
  ll l1=lcm(x,y),l2=lcm(x,z);
  return lcm(l1,l2);
}
int main(){
  ll a[3],m[3];
  while(cin>>a[0]>>m[0]>>a[1]>>m[1]>>a[2]>>m[2],
	a[0]||m[0]||a[1]||m[1]||a[2]||m[2]){
    ll c[3]={};
    ll x[3];
    for(ll i=0;i<3;i++){
      c[i]=1;
      x[i]=a[i]%m[i];
      while(x[i]!=1){
	x[i]=(a[i]*x[i])%m[i];
	c[i]++;
      }
    }    
    cout << lcm(c[0],c[1],c[2]) << endl;
  }
  return 0;
}

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

typedef long long ll;

int n;
string s;
unordered_map<string, int> mp;
ll res;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> s;
        sort(s.begin(), s.end());
        if (mp.count(s))
            res += mp[s];
        ++mp[s];
    }
    cout << res << endl;

    return 0;
}



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


int main(){
    ll n,d,cnt=0;cin>>n>>d;
    while(n--){
        ll a,b;cin>>a>>b;
        if(a*a+b*b<=d*d)
            cnt++;
    }
    cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long int lint;
using namespace std;

//累積和
template <typename T>
struct cumulative_sum {
    // data[i]:元の数列
    vector<T> data;
    // sum[i]:[0,i)の和
    vector<long long int> sum;
    cumulative_sum(const int n) {
        data.assign(n, 0);
    }
    T& operator[](const int k) {
        return data[k];
    }
    // dataに基づいてsumを構築
    void build() {
        sum.assign(data.size() + 1, 0);
        for (int i = 0; i < (int)data.size(); i++) {
            sum[i + 1] = sum[i] + data[i];
        }
    }
    //[a,b)の和を求める
    long long int query(int a, int b) {
        return sum[b] - sum[a];
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    cumulative_sum<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    a.build();
    unordered_map<lint, int> count;
    for (int i = 0; i < n + 1; i++) {
        count[(a.sum[i]) % m]++;
    }
    lint ans = 0;
    for (auto itr = count.begin(); itr != count.end(); itr++) {
        lint temp = (*itr).second;
        ans += temp * (temp - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4876
A,B=map(int,input().split())
S=input()
list=[str(i) for i in range(10)]
for i in range(A):
    if not S[i] in list:
        print("No")
        quit()
if S[A]!="-":
    print("No")
    quit()
for i in range(B):
    if not S[i+A+1] in list:
        print("No")
        quit()
print("Yes")


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int N;
vector<int> es[214514];

pii Dfs(int v, int p) {
  pii ret(0, v);
  for (int u : es[v]) {
    if (u == p) continue;
    auto res = Dfs(u, v);
    res.X += 1;
    MX(ret, res);
  }
  return ret;
}

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);

  cin >> N;
  rep(i, N-1) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    es[u].eb(v);
    es[v].eb(u);
  }

  pii res = Dfs(0, 0);
  int d = Dfs(res.Y, res.Y).X;
  if (d%3 != 1) puts("First");
  else puts("Second");
}


Measured memory_bytes: 24064
import math
a,b = map(float, input().split())
min8 = 12.5*a
max8 = 12.5*(a+1)
min10 = 10*b
max10 = 10*(b+1)
if max8 < min10 or max10 < min8:
    print('-1')
    exit()
if min8 > min10:
    min = min8
else:
    min = min10
if max8 < max10:
    max = max8
else:
    max = max10
if math.ceil(min) < max:
    print(math.ceil(min))
else:
    print("-1")    


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
using namespace __gnu_pbds;
using namespace std;

#define pf(n) cout << n << endl
#define ps() cout <<" ";
#define sf(n) cin >> n
#define in(i,n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define vp vector<pair<int, int>>
#define graph vector< vector<int> >
#define vs vector<string>
/**  '' "\n" ^ - **/

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin>>a;
    for(int i=1;i<=9;i++)
    {
        for(int j=1;j<=9;j++)
        {
            if(i*j==a){
                cout<<"Yes\n";
                return 0;
            }
        }
    }
    cout<<"No\n";
}


Measured memory_bytes: 256
object Main extends App {
    var inputs = readLine.split(" ").map(_.toInt)
    var can = true
    for(i <- inputs) {
        if(i > 9) {
            can = false
        }
    }
    if(can) {
        println(inputs(0) * inputs(1))
    } else {
        println(-1)
    }
}

Measured memory_bytes: 27348
program sequence_sum
  implicit none
  integer(8) :: n, x, m, num, a(0:100000) = 0
  integer :: b(0:100000) = 0, period, offset, rem, i, j
  read(*,*) n, x, m
  if (n == 1) then
    write(*,'(i0)') x
    stop
  end if
  a(1) = x
  b(int(x, 4)) = 1
  do i = 2, int(m) + 1
    x = mod(x * x, m)
    a(i) = a(i - 1) + x
    if (i == n) then
      write(*,'(i0)') a(i)
      stop
    end if
    j = int(x, 4)
    if (b(j) > 0) then
      offset = b(j) - 1
      period = i - offset - 1
      exit
    end if
    b(j) = i
  end do
  num = (n - offset) / period
  rem = int(n - offset - num * period, 4)
  write(*,'(i0)') (a(offset + period) - a(offset)) * num + a(offset + rem)
end program sequence_sum

Measured memory_bytes: 3488
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int n;
    cin >> n;
    cout << n + n * n + n * n * n << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG



signed main() {
  int N, M; cin >> N >> M;
  vector<int> X(M);
  rep(i, M) cin >> X[i];
  
  sort(all(X));
  
  vector<int> Y(M-1);
  rep(i, M-1) Y[i] = X[i+1]-X[i];
  
  sort(all(Y));
  
  int ans = 0;
  rep(i, M-N) ans += Y[i];
  
  cout << ans << endl;
  
}


Measured memory_bytes: 1792
#include <stdio.h>

using namespace std;

int main(){
    int C[10001];
    for(int i = 0; i < 10001; i++) C[i] = 0;
    int n;
    scanf("%d",&n);
    int* A = new int[n];
    int* B = new int[n];
    for(int i = 0; i < n; i++){
        scanf("%d",&A[i]);
        C[A[i]]++;
    }

    for(int i = 0,j=0; i < 10001; i++){
        if(C[i] != 0){
            for(int k = 0; k < C[i]; k++){
                B[j++] = i;
            }
        }
    }

    for(int i = 0; i < n-1; i++) printf("%d ",B[i]);
    printf("%d\n",B[n-1]);
    delete[] A;
    delete[] B;
    return 0;
}


Measured memory_bytes: 17912
program main
  implicit none
  integer :: w, h, i, j, cnt
  character(50) :: l
  character(1), allocatable :: s(:, :)
  read(*, *) h, w
  allocate(s(0:w + 1, 0:h + 1))

  s(:, :) = "."
  do i = 1, h
    read(*, *) l
    do j = 1, w
      s(j, i) = l(j:j)
    end do
  end do

  do i = 1, h
    do j = 1, w
      if (s(j, i) /= "#") then
        cnt = 0
        if (s(j - 1, i - 1) == "#") cnt = cnt + 1
        if (s(j - 1, i    ) == "#") cnt = cnt + 1
        if (s(j - 1, i + 1) == "#") cnt = cnt + 1
        if (s(j    , i - 1) == "#") cnt = cnt + 1
        if (s(j    , i + 1) == "#") cnt = cnt + 1
        if (s(j + 1, i - 1) == "#") cnt = cnt + 1
        if (s(j + 1, i    ) == "#") cnt = cnt + 1
        if (s(j + 1, i + 1) == "#") cnt = cnt + 1
        write(s(j, i), "(i0)") cnt
      end if
    end do
  end do

  l = ''
  do i = 1, h
    do j = 1, w
      l(j:j) = s(j, i)
    end do
    write(*, "(a)") trim(l)
  end do
end program main


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	S, T := ReadString(), ReadString()
	S += S
	for i := 0; i < len(T); i++ {
		ok := true
		for j := 0; j < len(T); j++ {
			if S[i+j] != T[j] {
				ok = false
				break
			}
		}
		if ok {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#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;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t;cin>>s>>t;
    bool isok = true;
    for(int i=0;i<s.size();i++){
        if(s[i] != t[i]) isok = false;
    }
    cout<< (isok ? "Yes":"No")<<endl;
}

Measured memory_bytes: 3652
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long ll;

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

int main() {

    ll R;
    cin >> R;
    cout << 2*R*M_PI << endl;
    return 0;
}


Measured memory_bytes: 3788
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n, k, s; cin >> n >> k >> s;
	vector<int> a(n);
	if (s == 1000000000)
	{
		rep(i, n)a[i] = s - 2;
	}
	else rep(i, n)a[i] = s + 1;
	rep(i, k)a[i] = s;
	rep(i, n)cout << a[i] << " ";
}

Measured memory_bytes: 1664
N,L=map(int, input().split())
List=[]
i=1
while i<=N:
    List.append(L+i-1)
    i+=1
MIN=abs(List[0])
HIKU=List[0]
j=1
while j<N:
    if abs(List[j])<MIN:
        HIKU=List[j]
        MIN=abs(List[j])
    j+=1
del List[List.index(HIKU)]
print(sum(List))

Measured memory_bytes: 3064
S = list(input())

flag = True

if S[0] != 'A':
    flag = False
tmp = S[2:len(S)-1]
if not('C' in tmp and tmp.count('C') == 1):
    flag = False
for i in S:
    if not(i == 'A' or i == 'C') and i.isupper():
        flag = False
        break
print("AC" if flag else "WA")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	int ans = 1e8;
	for (int i = 0; i < s.size(); ++i) {
		if (i + t.size() - 1 >= s.size()) { break; }
		int tmp = 0;
		for (int j = 0; j < t.size(); ++j) {
			tmp += (s[i + j] != t[j]);
		}
		ans = min(ans, tmp);
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3624
using System;

namespace ABC168
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine()) % 10;
            var ans = string.Empty;

            switch (N)
            {
                case 0:
                case 1:
                case 6:
                case 8:
                    ans = "pon";
                    break;

                case 2:
                case 4:
                case 5:
                case 7:
                case 9:
                    ans = "hon";
                    break;

                case 3:
                    ans = "bon";
                    break;

                default:
                    ans = "";
                    break;
            }

            System.Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 27444
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}



signed main(){
	ll m,d,d1,d2,cnt = 0;
	cin >> m >> d;
	
	rep(i,1,d+1){
		d1 = i%10;
		d2 = i/10;
		
		if(d1 >= 2 && d2 >= 2 && d1*d2 >= 1 && d1*d2 <= m){
			cnt++;
		}
	}
	
	cout << cnt << endl;
    return 0;
}

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

int n, m;
int ans = 0; 

int main(){
  cin >> n >> m;
  vector<ll> a(n);
  rep(i, n) cin >> a.at(i);
  sort(a.begin(), a.end());
  vector<pair<ll, int>> cb(m);
  rep(i, m){
    cin >> cb.at(i).second >>  cb.at(i).first;
  }
  sort(cb.begin(), cb.end());
  int now = n-1;
  
  for(int i = m-1; i >= 0;){ 
    if(now > n-1) break;
    for(int j = 0; j < n;){
      if(cb.at(i).first > a.at(j)){
        for(int k = j; k <= min(n-1, j+cb.at(i).second-1); k++){
          if(cb.at(i).first <= a.at(k)){
            now = n;
            break;
          }
          a.at(k) = cb.at(i).first;
        }
        now = min(n-1, j+cb.at(i).second-1)+1;
        j = min(n-1, j+cb.at(i).second-1)+1;
        if(i > 0)i--;
        else break;
      }
      else{
        now = n;
        break;
      }
    }
  }
  ll ans = 0;
  rep(i, n) ans += a.at(i);
  cout << ans << endl;
}

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

int main() {
  int A,B;
  cin >> A >> B;
  if(A > 12){
    cout << B << endl;
  }
  
  if(A < 6){
  cout << 0 << endl;
  }
  
  if(A > 5 && A < 13){
cout << B / 2 << endl;
  }
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;

using mint = modint998244353;

int main(){
    ll n, m;
    cin >> n >> m;
    vector<mint> a(n), b(m);
    REP(i, n){
        ll ai;
        cin >> ai;
        a.at(i) = ai;
    }
    REP(i, m){
        ll bi;
        cin >> bi;
        b.at(i) = bi;
    }

    vector<mint> c = convolution(a, b);
    REP(i, c.size()){
        cout << c.at(i).val();
        if(i + 1 < c.size()){
            cout << ' ';
        }else{
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 19004
N = int(input())
A = [int(input()) for i in range(N)]
A_sorted = sorted(A, reverse=True)
max_value = A_sorted[0]
sub_max_value = A_sorted[1]

if max_value == sub_max_value:
    for i in range(N):
        print(max_value)
else:
    for Ai in A:
        if Ai == max_value:
            print(sub_max_value)
        else:
            print(max_value)

Measured memory_bytes: 14628
#include <cstdio>
#define scanf __builtin_scanf
#include <map>
#include <tuple>
#include <algorithm>
using namespace std;

int d[200010], res[200010];
tuple<int, int, int> f[200010];
int main()
{
    int n, q; scanf("%d%d", &n, &q);
    for(int i=0; i<n; ++i) {
        int s, t, x; scanf("%d%d%d", &s, &t, &x);
        f[i]=make_tuple(x, max(0, s-x), max(0, t-1-x));
    }
    sort(f, f+n);

    map<int, int> g;
    for(int i=0; i<q; ++i) {
        scanf("%d", d+i);
        res[i]=-1;
        g[d[i]]=i;
    }

    for(int i=0; i<n; ++i) {
        int x, s, t; tie(x, s, t)=f[i];
        auto it=g.lower_bound(s);
        auto jt=g.lower_bound(t);
        if (jt!=end(g)) ++jt;
        while (it!=end(g) and it!=jt) {
            if (s<=it->first and it->first<=t) {
                res[it->second]=x;
                it=g.erase(it);
            }
            else {
                it++;
            }
        }
    }
    for(int i=0; i<q; ++i) printf("%d\n", res[i]);
}


Measured memory_bytes: 15104
#include<stdio.h>
int n,a[50];
int solve(int i,int m)
{
    if(m==0) return 1;
    if(i>=n) return 0;
    int res=solve(i+1,m)||solve(i+1,m-a[i]);
    return res;
}
int main()
{
    int q,m,i;
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    scanf("%d",&q);
    for(i=0;i<q;i++)
    {
    scanf("%d",&m);
    if(solve(0,m)) printf("yes\n");
    else printf("no\n");
    }
    return 0;
}

Measured memory_bytes: 580
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))

# 数列の自分より後方で自分より小さい数
c1 = sum([1 if a[i]>j else 0 for i in range(n) for j in a[i+1:]])

# 数列内で自分より小さい数
from collections import Counter
ca = Counter(a)

c2 = 0
for n1,cnt1 in ca.items():
    for n2,cnt2 in ca.items():
        if n2<n1:
            c2+=cnt2*cnt1

MOD=10**9+7
k %= MOD
ans = (c1*k)%MOD + (c2*k*(k-1)//2)%MOD
ans %= MOD
print(ans)


Measured memory_bytes: 18888
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");
	public static void main(String[] args) {
		int N=sc.nextInt();//p("N"+N);
		int K=sc.nextInt();//p("K"+K);
		int ans=0;
		int tmp;
		for(int i=0;i<N;i++) {
			tmp=sc.nextInt();//p("tmp"+tmp);
			ans+=Math.min(Math.abs(K-tmp), tmp)*2;
		}
		p(ans);
		
	}
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
}
	

Measured memory_bytes: 21844
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Tue Mar 31 19:26:48 JST 2020
 **/

signed main() {
    std::string a, b;
    std::cin >> a >> b;
    if (a == b) {
        std::cout << "EQUAL" << std::endl;
    } else if (a.size() > b.size() || (a.size() == b.size() && a > b)) {
        std::cout << "GREATER" << std::endl;
    } else {
        std::cout << "LESS" << std::endl;
    }
}


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

using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int n, X, Y;
    cin >> n >> X >> Y;
    vector<int> cnt(n + 1);
    for (int i = 1; i <= n; i++)
    {
        for (int j = i + 1; j <= n; j++)
        {
            // if(i<X&&j<Y)
            // {
            //     cnt[j - i - (Y - X)]++;
            // }
            if (i < X && j <= X)
            {
                cnt[j - i]++;
            }
            else if (i < X && (j > X && j < Y))
            {
                int cur = min(j - i, X + Y - i - j + 1);
                cnt[cur]++;
            }
            else if (i < X && j >= Y)
            {
                cnt[j - i - (Y - X) + 1]++;
            }
            else if ((i >= X && i <= Y) && (j >= X && j <= Y))
            {
                int len = Y - X + 1;
                int cur = min(j - i, len - j + i);
                cnt[cur]++;
            }
            else if ((i >= X && i <= Y) && (j > Y))
            {
                int cur1 = j - i;
                int cur2 = i + j - X - Y + 1;
                int t = min(cur1, cur2);
                cnt[t]++;
            }
            else if (i > Y && j > Y)
            {
                cnt[j - i]++;
            }
        }
    }
    for (int i = 1; i < n; i++)
    {
        cout << cnt[i] << "\n";
    }
    return 0;
}

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

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

using namespace std;

const int V_MAX=50*50+2;
const int CAPA_INF=1<<29;
const int COST_INF=1<<29;

template<class capa_t,class cost_t>
struct edge{
	int v,rev;
	capa_t capa;
	cost_t cost;
	capa_t flow;
};

template<class capa_t,class cost_t>
void add_directed_edge(vector< edge<capa_t,cost_t> > *G,int u,int v,capa_t capa,cost_t cost){
	G[u].push_back((edge<capa_t,cost_t>){v,G[v].size()  ,capa, cost,0});
	G[v].push_back((edge<capa_t,cost_t>){u,G[u].size()-1,   0,-cost,0});
}

template<class T,class U>
pair<T,U> augment(int n,vector< edge<T,U> > *G,int s,int t,U *pot,bool fir){
	static int pre[V_MAX];
	static U d[V_MAX];
	rep(u,n) d[u]=(u==s?0:COST_INF);

	bool ok;
	if(fir){
		// Bellman-Ford
		while(1){
			bool end=true;
			rep(u,n) rep(i,G[u].size()) {
				edge<T,U> &e=G[u][i];
				if(e.capa-e.flow>0 && d[u]<COST_INF && d[u]+e.cost<d[e.v]){
					d[e.v]=d[u]+e.cost;
					pre[e.v]=e.rev;
					end=false;
				}
			}
			if(end) break;
		}
		ok=(d[t]<COST_INF);
	}
	else{
		// Dijkstra
		ok=false;
		priority_queue< pair<U,int> > Q; Q.push(make_pair(0,s));
		while(!Q.empty()){
			int u=Q.top().second;
			U cost=-Q.top().first; Q.pop();

			if(cost<d[u]) continue;
			if(u==t) ok=true;

			rep(i,G[u].size()){
				edge<T,U> &e=G[u][i];
				U cost2=cost+e.cost+pot[u]-pot[e.v];
				if(e.capa-e.flow>0 && cost2<d[e.v]){
					d[e.v]=cost2;
					pre[e.v]=e.rev;
					Q.push(make_pair(-cost2,e.v));
				}
			}
		}
	}

	if(!ok) return make_pair(0,0);

	T water=CAPA_INF;
	for(int v=t;v!=s;){
		edge<T,U> &e1=G[v][pre[v]];
		edge<T,U> &e2=G[e1.v][e1.rev];
		water=min(water,e2.capa-e2.flow);
		v=e1.v;
	}

	U cost=0;
	for(int v=t;v!=s;){
		edge<T,U> &e1=G[v][pre[v]];
		edge<T,U> &e2=G[e1.v][e1.rev];
		e1.flow-=water;
		e2.flow+=water;
		cost+=water*e2.cost;
		v=e1.v;
	}

	rep(u,n) pot[u]+=d[u];

	return make_pair(water,cost);
}

template<class T,class U>
pair<T,U> primal_dual(int n,vector< edge<T,U> > *G,int s,int t){
	static U pot[V_MAX];
	rep(u,n) pot[u]=0;

	T ans1=0;
	U ans2=0;
	for(bool fir=true;;fir=false){
		pair<T,U> tmp=augment(n,G,s,t,pot,fir);
		if(tmp.first==0) break;
		ans1+=tmp.first;
		ans2+=tmp.second;
	}
	return make_pair(ans1,ans2);
}

int main(){
	int h,w; cin>>h>>w;
	vector<string> B(h);
	rep(i,h) cin>>B[i];

	vector<edge<int,int>> G[50*50+2];
	int s=h*w,t=h*w+1;

	rep(i,h) rep(j,w) {
		if(B[i][j]=='o'){
			add_directed_edge(G,s,i*w+j,1,0);
		}
		if(B[i][j]!='#'){
			add_directed_edge(G,i*w+j,t,1,0);
		}
		if(i<h-1 && B[i][j]!='#' && B[i+1][j]!='#'){
			add_directed_edge(G,i*w+j,(i+1)*w+j,h*w,-1);
		}
		if(j<w-1 && B[i][j]!='#' && B[i][j+1]!='#'){
			add_directed_edge(G,i*w+j,i*w+(j+1),h*w,-1);
		}
	}

	printf("%d\n",-primal_dual(h*w+2,G,s,t).second);

	return 0;
}


Measured memory_bytes: 4188
#include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
    int n;
    cin>>n;
    int ans=n;
    for(int x=0;x<=n;x++)
    {
        int t,cnt=0;
        t=x;
        while(t>0)
        {
            cnt+=t%6;
            t/=6;
        }
        t=n-x;
        while(t>0)
        {
            cnt+=t%9;
            t/=9;
        }
        if(cnt<ans)
            ans=cnt;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		int a = sc.nextInt();
		int b = sc.nextInt();
		String u = sc.next();

		if (u.equals(s)) {
			System.out.println((a - 1) + " " + b);
		} else {
			System.out.println(a + " " + (b - 1));
		}

	}

}


Measured memory_bytes: 38592
#include<stdio.h>

int main(void)
{
	int A,B,C,D,sum=0;

	scanf("%d",&A);
	scanf("%d",&B);

	if(A<B){
		sum=sum+A;
	}else{
		sum=sum+B;
	}
	
	scanf("%d",&C);
	scanf("%d",&D);


	if(C<D){
		sum=sum+C;
	}else{
		sum=sum+D;
	}
	
	printf("%d",sum);
	return 0;
}

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

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    int a[12][12];

    rep(i,n){
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    }

    int ans = 1001001001;
    rep(s,1<<n){
        int cost = 0;
        vector<int> d(m);
        rep(i,n){
            if(s>>i&1){
                cost += c[i];
                rep(j,m) d[j] += a[i][j];
            }
        }
        bool ok = true;
        rep(j,m) if(d[j] < x) ok = false;
        if(ok) ans = min(ans, cost);
    }
    
    if(ans == 1001001001) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
import java.util.*;
public class Main {
 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), M = sc.nextInt();
		int[] a = new int[N];
		int[] b = new int[N];
		int[] c = new int[M];
		int[] d = new int[M];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		for(int j = 0; j < M; j++) {
			c[j] = sc.nextInt();
			d[j] = sc.nextInt();
		}
		for(int i = 0; i < N; i++) {
			int min = 0, man = 0,minn=0;
			for(int j = 0; j < M; j++) {
				man = Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j]);
				if(man < min || j == 0) {
					min = man;
					minn = j;
					//System.out.println(man);
				}
				man = 0;
			}
			System.out.println(minn + 1);
		}
	}
 
}

Measured memory_bytes: 21844
import numpy as np
import sys
# '#'からの距離を測る

buf = sys.stdin.buffer
H,W = map(int,buf.readline().split())
black = (np.frombuffer(buf.read(H*(W+1)),dtype='S1') == b'#').reshape(H,W+1)

INF = 10 ** 9
dist = np.zeros((H,W),dtype=np.int32)
dist[~black[:,:-1]] = INF

for n in range(1,H):
    np.minimum(dist[n-1]+1,dist[n],out=dist[n])
for n in range(H-2,-1,-1):
    np.minimum(dist[n+1]+1,dist[n],out=dist[n])

for n in range(1,W):
    np.minimum(dist[:,n-1]+1,dist[:,n],out=dist[:,n])
for n in range(W-2,-1,-1):
    np.minimum(dist[:,n+1]+1,dist[:,n],out=dist[:,n])

answer = dist.max()
print(answer)

Measured memory_bytes: 18292
//#include "oj/atcoder.h"
//#include "std.h"
#include <stdlib.h>
#include <stdbool.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include <float.h>

#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define SWAP(T,a,b) do { T _tmp=a; a=b; b=_tmp; } while (0)

void check_env() {
	assert(sizeof(long)==8);
	assert(sizeof(long long)==8);
}

//#include "oj/io.h"

void print_ai(int *a, int n) {
	for (int i=0; i<n; i++) {
		if (i) printf(" ");
		printf("%d", a[i]);
	}
	printf("\n");
}

int scan_ai(int *a, int n) {
	for (int i=0; i<n; i++) {
		if (scanf("%d", &a[i]) != 1)
			return i;
	}
	return n;
}


//#include "oj/debug.h"

void print_hr() {
	printf("---------------------------\n");
}

void print_al(long *a, int n) {
	for (int i=0; i<n; i++) {
		if (i) printf(" ");
		printf("%ld", a[i]);
	}
	printf("\n");
}


#define T long
//#include "misc/array/partial_sum.h"

void array_delta_create(T *a, int n) {
	for (int i=n-1; i>0; i--)
		a[i] -= a[i-1];
}

//add val to a[s,t)
void array_delta_range_add(T *a, int s, int t, T val) {
	a[s] += val;
	a[t] -= val;
}

void array_partial_sum_create(T *a, int n) {
	for (int i=0; i<n-1; i++)
		a[i+1] += a[i];
}


int main() {
	check_env();
	int n, m;
	//printf("%d %d %d\n", sizeof(int), sizeof(long), sizeof(long long));
	while (scanf("%d %d", &n, &m)==2) {
		int a[n];
		scan_ai(a, n);

		long g[m], h[m];
		memset(g, 0, sizeof(g));
		memset(h, 0, sizeof(h));
		array_delta_create(g, m);
		array_delta_create(h, m);

		/*
		steps from s to t:
		s<=t:
			x s t: t-s      0<x<=s
			s x t: t-x+1    s<x<=t
			s t x: t-s      t<x<=m
		s>t:
			x t s: t-x+1    0<x<=t
			t x s: t+m-s    t<x<=s
			t s x: t+m-x+1  s<x<=m
		
		sum[i=0..n-1](x) = g*x + h
			s = a[i]
			t = a[i+1]
		*/
		for (int i=0; i<n-1; i++) {
			int s = a[i], t = a[i+1];
			if (s <= t) {
				//0<x<=s
				array_delta_range_add(h, 0, s, t-s);
				//s<x<=t
				array_delta_range_add(h, s, t, t+1);
				array_delta_range_add(g, s, t, -1);
				//t<x<=m
				array_delta_range_add(h, t, m, t-s);
			}
			else {
				//0<x<=t
				array_delta_range_add(h, 0, t, t+1);
				array_delta_range_add(g, 0, t, -1);
				//t<x<=s
				array_delta_range_add(h, t, s, t+m-s);
				//s<x<=m
				array_delta_range_add(h, s, m, t+m+1);
				array_delta_range_add(g, s, m, -1);
			}
		}
		array_partial_sum_create(g, m);
		array_partial_sum_create(h, m);
		//print_al(g, m); print_al(h, m);

		long minz = LONG_MAX;
		int minx = 0;
		for (int x=1; x<=m; x++) {
			long z = g[x-1] * x + h[x-1];
			//printf("g=%ld h=%ld z=%ld\n", g[x-1], h[x-1], z);
			if (z < minz) {
				minz = z;
				minx = x;
			}
		}
		//printf("%d\n", minx);
		printf("%ld\n", minz);
	}
}


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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

void solve(){
    int n,k,ans=0;
    cin>>n>>k;
    rep(i,0,n){
        int h;
        cin>>h;
        if(h>=k) ans++;
    }
    cout<<ans<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
n, k = list(map(int, input().split()))

q, r = divmod(n, k)

if r == 0:
    print(0)
    exit()

if q < 1:
    if n < (k - r):
        print(n)
    else:
        print(k - r)

else:
    s = n - q * k
    t = abs(s - k)
    if s < t:
        print(s)
    else:
        print(t)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int W,H,N;
int G[110][110];

signed main()
{
    cin>>W>>H>>N;
    while(N--){
        int x,y,a; cin>>x>>y>>a;
            
        if(a==1){
            for(int i=0;i<x;i++) for(int j=0;j<H;j++) G[i][j]=1;
        }
        if(a==2){
            for(int i=x;i<W;i++) for(int j=0;j<H;j++) G[i][j]=1;
        }
        if(a==3){
            for(int i=0;i<W;i++) for(int j=0;j<y;j++) G[i][j]=1;
        }
        if(a==4){
            for(int i=0;i<W;i++) for(int j=y;j<H;j++) G[i][j]=1;
        }
    }
    
    int ans=0;
    REP(i,H) REP(j,W){
        if(G[j][i]==0) ans++;
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

vector< int > z_algorithm(const string &s) {
  vector< int > prefix(s.size());
  for(int i = 1, j = 0; i < s.size(); i++) {
    if(i + prefix[i - j] < j + prefix[j]) {
      prefix[i] = prefix[i - j];
    } else {
      int k = max(0LL, j + prefix[j] - i);
      while(i + k < s.size() && s[k] == s[i + k]) ++k;
      prefix[i] = k;
      j = i;
    }
  }
  prefix[0] = (int) s.size();
  return prefix;
}

signed main(){

  int n; cin >> n;
  string s; cin >> s;

  int ans = 0;
  for(int i = 0; i < n; i++){
    auto v = z_algorithm(s.substr(i,n));
    for(int j = 1; j < v.size(); j++){
      int res = min(v[j], i+j - i);
      ans = max(ans, res);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;


int n,a,b;
char s[100011];
int ans;
int main()
{
	int i,j,k;
	int aa,bb;
	
	cin>>n>>a>>b;
	cin>>s;
	
	aa=bb=0;
	for(i=0;i<n;i++)
	{
		if(s[i]=='c')
		{
			cout<<"No"<<endl;
		}
		else if(s[i]=='a')
		{
			if(aa+bb<a+b)
			{
				aa++;
				cout<<"Yes"<<endl;
			}
			else
			{
				cout<<"No"<<endl;
			}
		}
		else
		{
			if(aa+bb<a+b && bb<b)
			{
				bb++;
				cout<<"Yes"<<endl;
			}
			else
			{
				cout<<"No"<<endl;
			}
		}
	}
	
	
	return 0;
} 

Measured memory_bytes: 896
#include <cmath>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;

int n;
vi a;

void input() {
  cin >> n;

  a.resize(n);
  for (auto&& i : a)
    cin >> i;
}

void solve() {
  sort(a.rbegin(), a.rend());

  int x = 0;
  int y = 0;

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

  for (int i = 1; i < n; i += 2)
    y += a[i];

  cout << x - y << '\n';
}

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

  cout.precision(16);
  cout << fixed;

  int _times = 1;

#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  _times = 3;
#endif

  // cin >> _times;

  while (_times--) {
    input();
    solve();
  }
}


Measured memory_bytes: 3640
#include <stdio.h>

int main(){
    int N, sN = 0, aux;

    scanf("%d", &N);
    aux = N;

    while(aux){
        sN = sN + (aux%10);
        aux = aux/10;
    }
    
    if((N%sN) == 0){
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}

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

typedef long long ll;
vector<ll> s,t;
int a,b,q;
const ll INF = 1e12;
ll atob[100005];
ll btoa[100005];
ll qq[100005];
int main() {
  cin >> a >> b >> q;
  for(int i = 0; i < a; i++) {
    ll S;
    cin >> S;
    s.push_back(S);
  }
  s.push_back(-INF);
  s.push_back(INF);
  for(int i = 0; i < b; i++) {
    ll T;
    cin >> T;
    t.push_back(T);
  }
  t.push_back(-INF);
  t.push_back(INF);

  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  
  for(int i = 1; i < s.size() - 1; i++) {
    int j = lower_bound(t.begin(),t.end(),s[i]) - t.begin();
    //   cout <<"j = "<< j <<endl;
    atob[i] = min(abs(s[i] - t[j-1]),abs(s[i] - t[j]));
    //cout << "atob = "<<atob[i] << endl;
  }
  for(int i = 1; i < t.size() - 1; i++) {
    int j = lower_bound(s.begin(),s.end(),t[i]) - s.begin();
    btoa[i] = min(abs(t[i] - s[j-1]),abs(t[i] - s[j]));
    //cout << "btoa = "<<btoa[i] << endl;
  }
  atob[0] = btoa[0] = INF;
  atob[s.size() - 1] = btoa[t.size() - 1] = INF;

  for(int i = 0; i < q; i++) cin >> qq[i];
  for(int i = 0; i < q; i++) {
    int j = lower_bound(t.begin(),t.end(),qq[i]) - t.begin();
    int k = lower_bound(s.begin(),s.end(),qq[i]) - s.begin();
    cout << min(min(abs(qq[i] - t[j-1]) + btoa[j-1],abs(qq[i] - t[j]) + btoa[j]),min(abs(qq[i] - s[k-1]) + atob[k-1],abs(qq[i] - s[k]) + atob[k])) << endl;
  }
}


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

typedef long long int ll;
ll n, m, a;

int main() {
    cin >> n >> m;
    for(ll i = 0; i < m; ++i) {
        cin >> a;
        n -= a;
    }

    if(n < 0) n = -1;
    cout << n << endl;

    return 0;
}

Measured memory_bytes: 3600