akhauriyash/Code-Regression huggingface dataset:
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

template<class T> inline bool chmin(T& a, T b) {if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if(a<b){a=b;return true;}return false;}

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  double n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  double k;
  IN2(n,k);
  Vd Pv(n);
  Vd Per(n);
  VIN(Pv)
  REP(i,n){
    Per[i] = (Pv[i]+1.0)/2.0;
  }
  //累積和を使う
  Vd RUISEKI(n+1);
  RUISEKI[0] = 0.0;
  FOR(i,1,n+1){
    RUISEKI[i] = Per[i-1] + RUISEKI[i-1];
  }
  //k個ずつ調べる
  REP(i,n-k+1){
    z = max(z, RUISEKI[i+k] - RUISEKI[i]);
  }
  FIX;
  OUT(z);
}

Measured memory_bytes: 4992
N=io.read()
s={}
count={}
for i=1,N do
  s[i]=io.read()
  count[s[i]]=(count[s[i]] or 0) +1
end
M=io.read()
t={}
for i=1,M do
  t[i]=io.read()
  count[t[i]]=(count[t[i]] or 0) -1
end
local earn=0
for _,v in pairs(count) do
  if v>earn then
    earn=v
  end
end
print(earn)


Measured memory_bytes: 256
module ABC122.B

open System

let rec acgt cnt max_cnt lst =
    match lst with
    | [] -> max_cnt
    | ['A'] -> max (cnt + 1) max_cnt
    | ['C'] -> max (cnt + 1) max_cnt
    | ['G'] -> max (cnt + 1) max_cnt
    | ['T'] -> max (cnt + 1) max_cnt
    | [_] -> max cnt max_cnt
    | 'A' :: tail -> acgt (cnt + 1) max_cnt tail
    | 'C' :: tail -> acgt (cnt + 1) max_cnt tail
    | 'G' :: tail -> acgt (cnt + 1) max_cnt tail
    | 'T' :: tail -> acgt (cnt + 1) max_cnt tail
    | _ :: tail -> acgt 0 (max cnt max_cnt) tail

[<EntryPoint>]
let main argv =
    Console.ReadLine()
    |> Seq.toList
    |> acgt 0 0
    |> printfn "%d"
    0


Measured memory_bytes: 14044
#include<stdio.h>
const int N = 10000;
int main()
{
	int a[N];
	for(int i = 0; i < 10; i++)
	{
		scanf("%d", &a[i]);
	}
	for(int i = 0; i < 10; i++)
	{
		for(int j = 0; j < 10; j++)
		{
			if(a[i] < a[j])
			{
				int temp = a[i];
				a[i] = a[j];
				a[j] = temp;
			} 
		}
	}
	printf("%d\n", a[9]);
	printf("%d\n", a[8]);
	printf("%d\n", a[7]);
	
	return 0;
}


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

using namespace std;

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

  vector<int> a(n);

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

  sort(a.begin(), a.end());

  printf("%d", a[n - 1] - a[0]);
}

Measured memory_bytes: 256
n = int(raw_input())
i=1
x=i
nums = []


def include3():
    global n
    global i
    global x
    global nums

    while True:
        if x % 10 == 3:
            nums.append(str(i))
            if end_check_num():
                return 0
            return 1

        x /= 10
        if x==0:
            if end_check_num():
                return 0
            return 1
    return 1

def end_check_num():
    global n
    global i
    global x

    i+=1
    if i <= n:
        return False
    return True


while True:
    x=i
    if x % 3==0:
        nums.append(str(i))
        if end_check_num():
            break
        continue
    if 0==include3():
        break

print " " + " ".join(nums)

Measured memory_bytes: 4548
A, B, K = map(int, input().split())

if 2*K-1 >= B-A+1:
    for i in range(A, B+1):
        print(i)
else:

    for i in range(A, A+K):
        print(i)

    for i in range(B-K+1, B+1):
        print(i)


Measured memory_bytes: 3060
(* unihernandez22
 * https://atcoder.jp/contests/abc131/tasks/abc131_b
 * implementation
 * *)

let rec solution n l i cum eat =
    if i > n then cum-eat
    else
        let curr = i+l-1 in
        if abs curr < abs eat then
            solution n l (i+1) (cum+curr) curr
        else
            solution n l (i+1) (cum+curr) eat;;

Printf.printf "%d\n" @@
Scanf.scanf "%d %d\n" @@ fun n l ->
    solution n l 1 0 300;;



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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
const int maxN = 205;
const int INF = 999999999;
int get(char a[maxN])
{
	int ln = strlen(a+1);
	int ans = 0;
	int ep = 1;
	for(int i=ln;i>=1;i--)
	{
		ans += (a[i] - 48)*ep;
		ep *= 10;
	}
	return ans;
}
char a[maxN];
char s[maxN];
int main() {
	scanf("%s",s+1);
	int len = strlen(s+1);
	int minv = INF;
	for(int i=3;i<=3;i++)  
	{
		for(int j=1;j<=len;j++)
		{
			int k = (j-i+1);
			if(k<1) continue;
			else
			{
				int g = 0; 
				for(int c = k;c<=j;c++)
				{
					a[++g] = s[c];
				}
				int ans = get(a);
				if(abs(ans - 753) < minv)
				{
					minv = abs(ans - 753);
				}
			}
		}
	}
	printf("%d\n",minv);
    return 0;
}


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

using namespace std;
typedef long long ll;
int main()
{
   string s="zabcdefghijklmnopqrstuvwxy";
   ll n;string a="";
   cin>>n;
   while(n>0)
   {
       a+=s[n%26];
       if(n%26==0)
       {n=n/26;n--;}
       else
       n=n/26;
   }
   reverse(a.begin(),a.end());
   cout<<a;
}

Measured memory_bytes: 3628
W=[]
K=[]
for i in range(20):
    n=int(input())
    if i<10:
        W.append(n)
    else:
        K.append(n)

list.sort(W,reverse=True)
list.sort(K,reverse=True)
print(W[1]+W[2]+W[0],end=" ")
print(K[1]+K[2]+K[0])


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 4e18;
const int MOD = 1e9+7; //998244353;
const int N = 2e5+1;
ll n, x, d, g, e, ad;
V<P<ll, ll>> v[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> x >> d;
  if(!d){
    cout << (x?n+1:1) << endl;
    return 0;
  }
  g = __gcd(abs(x), abs(d));
  x /= g;
  d /= g;
  ad = abs(d);
  FOR(i, 0, n+1){
    ll mi = x*i+d*i*(i-1)/2;
    ll ma = x*i+d*i*(n*2-i-1)/2;
    if(mi>ma) swap(mi, ma);
    v[i%d].pb(mp(mi, ma+ad));
  }
  ll ans = 0;
  FOR(i, 0, min(n+1, ad)){
    e = -LINF;
    sort(all(v[i]));
    for(auto&p:v[i]){
      if(p.se<e) continue;
      maxs(e, p.fi);
      ans += (p.se-e)/ad;
      e = p.se;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 11264
//jinhaonan
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
template<class T>inline void read(T &x){
	x=0;char c=getchar();bool f=0;
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';x=(x<<1)+(x<<3)+c-'0',c=getchar());
	x=f?-x:x;
}
template<class T>inline void write(T x){
	if(x<0)putchar('-'),x=-x;
	if(x>=10)write(x/10);
	putchar(x%10+48);
}
template<class T>inline bool chkmax(T &a,T const &b){
	return a<b?a=b,1:0;
}
template<class T>inline bool chkmin(T &a,T const &b){
	return a>b?a=b,1:0;
}
const int N=200000+10;
int a[N];
int main(){
	// freopen("in.txt","r",stdin);
	int n;read(n);
	for(int i=1;i<=n;++i){
		read(a[i]);
		a[i]-=i;
	}
	sort(a+1,a+n+1);
	int b=a[(n+1)/2];
	long long ans=0;
	for(int i=1;i<=n;++i){
		ans+=abs(b-a[i]);
	}
	write(ans),putchar('\n');
	return 0;
}

Measured memory_bytes: 1024
X = int(input())

if X >= 1800:
    print(1)
elif X >= 1600:
    print(2)
elif X >= 1400:
    print(3)
elif X >= 1200:
    print(4)
elif X >= 1000:
    print(5)
elif X >= 800:
    print(6)
elif X >= 600:
    print(7)
else:
    print(8)

Measured memory_bytes: 9200
#include<stdio.h>
int main(void){
    int a[101][101]={}, b[101][101]={};
    long long int c[101][101]={};
    int i, j, k, n, m, l;
    
    scanf("%d %d %d", &n, &m, &l);
    for(i=1; i<=n; i++){
        for(j=1; j<=m; j++){
            scanf("%d", &a[i][j]);
        }
    }
    
    for(j=1; j<=m; j++){
        for(k=1; k<=l; k++){
            scanf("%d", &b[j][k]);
        }
    }
    
    for(i=1; i<=n; i++){
        for(k=1; k<=l; k++){
            for(j=1; j<=m; j++){
                c[i][k]+=a[i][j]*b[j][k];
            }
            printf("%lld", c[i][k]);
            if(k!=l) printf(" ");
        }
        printf("\n");
    }
    return 0;
    
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
bool jg[500];
bool a[500][500];
int res[500][500];
int main()
{
	int n,m,k,br=0;
	cin>>n>>m>>k;
	string s;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		for(int j=0;j<m;j++) if(s[j]=='#') {jg[i]=true; a[i][j]=true;}
	}
	int pj=0; while(!jg[pj]) pj++;
	for(int i=pj;i<n;i++)
	{
		if(!jg[i]) for(int j=0;j<m;j++) res[i][j]=res[i-1][j];
		else
		{
			br++;
			int k=0;
			while(!a[i][k]) {res[i][k++]=br;}
			res[i][k++]=br;
			while(k<m) 
			{
				if(a[i][k]) br++;
				res[i][k++]=br;
			}
		}
	}
	for(int i=pj-1;i>=0;i--) for(int j=0;j<m;j++) res[i][j]=res[i+1][j];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++) cout<<res[i][j]<<" ";
		cout<<endl;
	}
}

Measured memory_bytes: 1536
fun main(args: Array<String>) = println(run {
    val n = readLine()!!.toLong()
    val divisors = divisors(n)
    val x = divisors.minBy { Math.abs(it - Math.sqrt(n.toDouble())) }!!
    val y = n/x
    x+y-2
})

fun divisors(x: Long): List<Long> = (1..Math.sqrt(x.toDouble()).toLong()).asSequence().filter { x % it == 0L }.map { listOf(it, x / it) }.flatten().distinct().sorted().toList()


Measured memory_bytes: 42824
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

ll lcm(ll a,ll b){
    return (a*b/gcd(a,b));
}

int check(string t){
    int a=t.size();
    int b=0;
    if(a%2!=0){
        rep(i,(a-1)/2){
            if(t[i]==t[a-1-i]) b++;
        }
        if(b!=((a-1)/2)) return false;
        else return true;  
    } else{
        rep(i,a/2){
            if(t[i]==t[a-1-i]) b++;
        }
        if(b!=a/2) return false;
        else return true;
    }
}

int main(){
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n=s.size();
    string l=s.substr(0,(n-1)/2);
    string r=s.substr(((n-1)/2)+1,(n-1)/2);
    if(check(s)&&check(l)&&check(r)) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100
int main(){
  int i,j,key,n,A[N],count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<n;i++){
    for(j=n-1;j>=0;j--){
      if(A[j-1]>A[j]){
	key=A[j-1];
	A[j-1]=A[j];
	A[j]=key;
	count++;
      }  
    }
  }
  printf("%d",A[0]);
  for(i=1;i<n;i++){
    printf(" %d",A[i]);
  }
  printf("\n%d\n",count);
      return 0;
    
  }

Measured memory_bytes: 600
#include "bits/stdc++.h"
using namespace std;
using ll = long long;


int main() {
    int n;
    cin >> n;
    vector<int> d(2 * n);
    for (int i = 0; i < 2 * n; i++) {
        cin >> d[i];
    }
    bool f = false;
    for (int i = 0; i < 2 * (n - 2); i += 2) {
        if (d[i] == d[i + 1] && d[i + 2] == d[i + 3]&& d[i + 4] == d[i + 5]) {
            f = true;
        }
    }
    if (f) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
inline void add(int &x, int v) { x += v; if (x >= MOD) x -= MOD; }
int N;
int V[200000];
int L[200000], R[200000];
vector<int> G[200000];
int dp[200001];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  vector<P> ps;
  vector<int> vs;
  rep(i, N) {
    int x, y;
    cin >> x >> y;
    vs.pb(y);
    ps.pb(P(x, y));
  }
  sort(all(vs));
  sort(all(ps));
  rep(i, N) V[i] = index(vs, ps[i]._2);
  int cur = -1;
  rep(i, N) {
    cur = max(cur, V[i]);
    R[i] = cur;
  }
  cur = vs.size();
  for (int i=N-1; i>=0; i--) {
    cur = min(cur, V[i]);
    L[i] = cur;
  }
  rep(i, N-1) assert(L[i] <= L[i+1] && R[i] <= R[i+1]);
  rep(i, N) G[R[i]].pb(L[i]);

  dp[0] = 1;
  rep(r, N) {
    add(dp[r+1], dp[r]);
    for (int l : G[r]) add(dp[r+1], (dp[r+1] + MOD-(l>0?dp[l-1]:0))%MOD);
  }
  cout << (dp[N]+MOD-dp[N-1])%MOD << "\n";
  return 0;
}


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

using namespace std;

int main()

{
    int n;
    cin>>n;


    int arr[n+1];

    for(int i=1;i<=n;i++)
        cin>>arr[i];
    if(n%2==0)
    {
        for(int i=n;i>=2;i-=2)
        {
            cout<<arr[i]<<" ";
        }

        for(int i=1;i<n;i+=2)
        {
            cout<<arr[i]<<" ";
        }
    }
    else
    {
        for(int i=n;i>=1;i-=2)
        {
            cout<<arr[i]<<" ";
        }
         for(int i=2;i<n;i+=2)
        {
            cout<<arr[i]<<" ";
        }
    }

    cout<<endl;



    return 0;
}




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

int main(){
  int k,t; cin>>k>>t;
  priority_queue<int> que;
  for(int i=0;i<t;i++){
    int x; cin>>x;
    que.push(x);
  }
  for(int i=0;i<k;i++){
    int a=que.top(); que.pop();
    a--;
    if(que.size()==0){
      cout<<a<<endl;
      return 0;
    }else{
      int b=que.top(); b--;
      que.pop();
      if(a!=0) que.push(a);
      if(b!=0) que.push(b);
      if(que.size()==0){
        cout<<0<<endl;
        return 0;
      }
    }
  }
}   

Measured memory_bytes: 256
use std::io::*;
use std::str::*;

fn read<T: FromStr>(s: &mut StdinLock) -> Option<T> {
    let s = s.by_ref().bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main(){
    let stdin = stdin();
    let mut stdin = stdin.lock();
    let stdin = &mut stdin;
    let a: i32 = read(stdin).unwrap();
    let s: String = read(stdin).unwrap();
    if a < 3200 {
        println!("red")
    } else {
        println!("{}",s)
    }
}


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

// int/long:		-2147483648 - 2147483648 (-2^31 <= int < 2^31)
// long/long long:	-9223372036854775808 - 9223372036854775807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536870912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// bit: &/and, |/or, ^/xor, ~/not

#define	MOD 1000000007

int	main() {
	int N, T;
	cin >>N >>T;
	vector<int> A(N, 0);
	for (int i=0; i<N; i++)
		cin >>A.at(i);
	int MAX=0;
	int GAIN=0;
	for (int i=N-1; i>=0; i--) {
		MAX=max(MAX, A.at(i));
		GAIN=max(GAIN, MAX-A.at(i));
	}
	vector<vector<int>> M;
	M.push_back({0, 0, 0});
	for (int i=N-1; i>=0; i--) {
		if (M.back().at(0)==A.at(i))
			M.back().at(1)++;
		else if (M.back().at(0)<A.at(i))
			M.push_back({A.at(i), 1, 0});
		else if (GAIN==M.back().at(0)-A.at(i))
			M.back().at(2)++;
	}
	int K=0;
	for (int i=0; i<M.size(); i++)
		K +=min(M.at(i).at(1), M.at(i).at(2));
	cout <<K <<endl;
	return 0;
}



Measured memory_bytes: 3380
/*input
15
1 3 5 2 1 3 2 8 8 6 2 6 11 1 1
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
ll a[maxn];
set<ll> st;
int main()
{
	IOS;
	int n;
	cin>>n;
	REP(i,n) cin>>a[i];
	REP(i,n) st.insert(a[i]);
	int ans=SZ(st);
	if(ans%2!=n%2) ans--;
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 5760
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		int[,]A = new int[M,2];
		for(var i=0;i<M;i++){
			string[] str2 = Console.ReadLine().Split();
			A[i,0] = int.Parse(str2[0])-1;
			A[i,1] = int.Parse(str2[1])-1;
		}
		var uf = new UnionFind(N);
		int[]D = new int[N];
		for(var i=0;i<M;i++){
			uf.Unite(A[i,0],A[i,1]);
		}
		for(var i=0;i<N;i++){
			D[uf.Root(i)]++;
		}
		long ans = 0;
		for(var i=0;i<N;i++){
			ans = Math.Max(ans,D[i]);
		}
		Console.WriteLine(ans);
	}
}

public class UnionFind
{
    private int[] data;
	public UnionFind(int size){
        data = new int[size];
        for (int i = 0; i < size; i++) data[i] = -1;
    }
    public bool Unite(int x, int y){
        x = Root(x);
        y = Root(y);
        if (x != y){
            if (data[y] < data[x]){
                var tmp = y;
                y = x;
                x = tmp;
            }
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
	public bool IsSameGroup(int x, int y){
        return Root(x) == Root(y);
    }
    public int Root(int x){
        return data[x] < 0 ? x : data[x] = Root(data[x]);
    }
}

Measured memory_bytes: 24500
#include <bits/stdc++.h>
using namespace std;
int main() {
int H,W;
  cin >> H >> W;
  //cout << H << W << ends;// 仮
  for(int j = 0; j < W + 2;j++){
    cout << "#";
    if(j == W + 1)
      cout << endl;
  }//最上段
   for(int i = 0; i < H;i++){
    string A;
     cin >> A;
    
       cout << "#";
   
     for(int k = 0; k < W;k++){
    cout << A.at(k);
     if (k == W - 1)
    cout << "#" << endl; // 右端の＃
     }
   }
  for(int j = 0; j < W + 2;j++){
    cout << "#";
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();

		String ans = "";

		if (A % 3  == 0 || B % 3 == 0 || (A+B)%3 ==0 ) {
			ans = "Possible";
		}else {
			ans = "Impossible";
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21972
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instr = lambda: sys.stdin.readline()
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n,k,q = inintm()
A = []
con = [0]*n

border = q-k

for _ in range(q):
    A.append(inint())

for a in A:
    con[a-1] += 1

for c in con:
    if c > border:
        print("Yes")
    else:
        print("No")



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

int main(){
  int n;
  while(cin>>n && n){
    int status=0; //0->ground ,1->on the upstair
    int left_leg=0;
    int right_leg=0;
    int count=0;
    while(n--){
      string str;
      cin>>str;
      if(str=="lu"){
	left_leg=1;
      }
      if(str=="ru"){
	right_leg=1;
      }
      if(str=="ld"){
	left_leg=0;
      }
      if(str=="rd"){
	right_leg=0;
      }
      if(status==0 && left_leg==1 && right_leg==1){
	count++;
	status=1;
      }
      if(status==1 && left_leg==0 && right_leg==0){
	count++;
	status=0;
      }

    }
    cout<<count<<endl;
  }
  return 0;
}

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

int main(){
  string sol,ans;
  while(cin >> sol >> ans,sol!="0"&&ans!="0"){
  int hit=0,blow=0;
    for(int i=0;i<4;i++){
	  for(int n=0;n<4;n++){
	    if(sol[i]==ans[n]){
		  if(i==n)hit++;
		  else blow++;
		}
	  }
	}
	cout << hit << ' ' << blow << endl;
  }
  return 0;
}

Measured memory_bytes: 916
N = int(input())
L = list(map(int, input().split()))
verbose = False
L.sort(reverse=True)

count = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if verbose:
                print(L[i], L[j], L[k], (L[i] < L[j] + L[k]))
            if L[i] < L[j] + L[k] and L[i] != L[j] and L[j] != L[k]:
                count += 1
print (count)


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

int main(){
  int i;
  string s;
  cin>>s;
  int a=0,ma=0;
  for(i=0;i<s.size();i++){
    if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T'){
      a++;
    }else{
      ma=max(ma,a);
      a=0;
    }
  }
  cout<<max(ma,a);
}

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

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g)
{
    for(int i=g; i<n; i++)
    {
        int v = A[i];
        int j = i-g;
        while(j>=0 && A[j]>v)
        {
            A[j+g] = A[j];
            j -= g;
            cnt++;
        }
        A[j+g] = v;
    }
}
void shellSort(int A[], int n)
{
    for(int h = 1; ; )
    {
        if(h > n)   break;
        G.push_back(h);
        h = 3*h + 1;
    }
    for(int i=G.size()-1; i>=0; i--)
    {
        insertionSort(A, n, G[i]);
    }
}

int main()
{
    cin >> n;
    for(int i=0; i<n; i++)
        scanf("%d", &A[i]);
    cnt = 0;
    shellSort(A,n);
    cout << G.size() << endl;
    for(int i=G.size()-1; i>=0; i--)
    {
        printf("%d", G[i]);
        if(i)  printf(" ");
    }
    cout << endl;
    cout << cnt << endl;
    for(int i=0; i<n; i++)
        cout << A[i] << endl;
    return 0;
}

Measured memory_bytes: 7092
#include <iostream>
using namespace std;
int main(void){
  int a,b,c;
  cin >> a;
  cin >> b;
  cin >> c;

  if(a <= b && b <= c){
      cout << a<< " "  << b<< " "  << c;
  }
  else if(a <= c && c <= b){
      cout << a << " " << c<< " "  << b;
  }
  else if(b < a && a < c){
      cout << b << " " << a << " " << c;
  }
  else if(b <= c && c <= a){
      cout << b << " " << c << " " << a;
  }
  else if(c <= a && a<= b){
      cout << c << " " << a << " " << b;
  }
  else{
      cout << c<< " "  << b<< " "  << a;
  }

  cout << endl;
}




Measured memory_bytes: 3068
#include <stdio.h>
int A[1000000],n;
int main(){
  int i,q,k,sum=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&k);
    if(binarySearch(k)==1){
      sum++;
    }
  }
  printf("%d\n",sum);
  return 0;
}
 
int binarySearch(int key){
  int a=0,b=n;
  while(a < b){
    if(key==A[a]){
      return 1;
    }
    a++;
  }
  return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<20;



int main(){
    string s;cin >> s;
    int x=(s[5]-'0')*10+s[6]-'0';
    int y=(s[8]-'0')*10+s[9]-'0';
    if(4>x)puts("Heisei");
    else if(4<x) puts("TBD");
    else{
        if(y==31) puts("TBD");
        else puts("Heisei");
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<string>

using namespace std;

int main(){
	int n;
	scanf("%d",&n);
	int max = 0,p,sum = 0;
	for(int i = 0;i<n;i++){
		scanf("%d",&p);
		sum += p;
		if(p>max)max = p;
	}
	printf("%d\n",sum - max/2);
	
}

Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {
	var a1, a2, a3 int
	fmt.Scan(&a1, &a2, &a3)
	if a1+a2+a3 >= 22 {
		fmt.Println("bust")
	} else {
		fmt.Println("win")
	}
}


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

int main() {
    int N;
    cin>>N;
    string W;
    cin>>W;
    string save_W[N];
    save_W[0]=W;
    int index=1;
    char tail_W=W.back();
    bool flag=true;
    for (int i=1; i<N; i++) {
        cin>>W;
        for (int j=0; j<index; j++) {
            if (W==save_W[j]) {
                flag=false;
            }
        }
        char ch=W[0];
        if (ch!=tail_W) {
            flag=false;
        }
        tail_W=W.back();
        save_W[index]=W;
        index++;
    }
    cout<<(flag?"Yes":"No")<<endl;
    return 0;
}

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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 2e5 + 100;

int N;
int main() {
	cin >> N; 
	ll sum = 0;
	int minV = INF;
	for(int i=0; i<N; i++) {
		int x, y; scanf("%d%d", &x, &y);
		sum += x;
		if(x > y && minV > y) minV = y;
	}
	if(minV == INF) puts("0");
	else printf("%lld\n", sum-minV);
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

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

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vs){
  for (const T& v : vs) os << v << " ";
  return os;
}

int main() {
  int N; cin >> N;
  vector<int> A(N); cin >> A;

  while (A.size() > 1) {
    sort(A.begin(), A.end());
    vector<int> B = {A[0]};
    for (int i = 1; i < A.size(); ++i) {
      int v = A[i] % A[0];
      if (v > 0) B.push_back(v);
    }
    A = B;
  }

  cout << A[0] << endl;
}


Measured memory_bytes: 4288
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(){

  int i, j, n;
  double t, a, h, c;

  scanf("%d", &n);
  scanf("%lf %lf", &t, &a);

  scanf("%lf", &h);
  c = fabs((t-h*0.006)-a);
  j = 1;

  for(i=2;i<=n;i++){
    scanf("%lf", &h);
    if(c > fabs((t-h*0.006)-a)){
      c = fabs((t-h*0.006)-a);
      j = i;
    }
  }

  printf("%d\n", j);

  return 0;
}

Measured memory_bytes: 128
(let* ((n (read))
       (k (read))
       (a (make-array (list n)))
       (l 0)
       (mn 0)
       (r (1- n))
       (ans 1)
       (b (+ (expt 10 9) 7)))
  (defun mod-* (x y)
    (mod (* x y) b))
  ;
  (loop :for i :from 0 :to (1- n)
        :do (let ((x (read)))
              (if (< x 0) (incf mn))
              (setf (aref a i) x)))
  (setf a (sort a #'>))
  (if (and (= mn n) (oddp k))
      (loop :for i :from 0 :to (1- k)
            :do (setf ans (mod-* ans (aref a i))))
      ;;
      (loop :while (< (+ l (- n 1 r)) k)
            :if (and (>= (- k 2) (+ l (- n 1 r)))
                     (< (* (aref a l) (if (< (1+ l) n) (aref a (1+ l)) 1))
                        (* (aref a r) (aref a (1- r)))))
            :do (progn
                  (setf ans (mod-* ans (mod-* (aref a r) (aref a (1- r)))))
                  (decf r 2))
            :else
            :do (progn
                  (setf ans (mod-* ans (aref a l)))
                  (incf l))))
  (format t "~A~%" ans))


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

#define ll long long int
#define Mod 1000000007

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n; cin>>n;
    ll arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    int dp[n+10];
    memset(dp,0,sizeof(dp));
    dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;

#define int long long

#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define rrep(i, n) for (int i=(int)n-1;i>=0;--i)
#define rrep1(i, n) for (int i=n;i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)r;++i)
#define rrange(i, l, r) for (int i=(int)r-1;i>=(int)l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}
constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}

int f(int a, int b)
{
	return a / b;
}

signed main()
{
	int A, B, N; cin >> A >> B >> N;
	int m = min(B - 1, N);

	cout << A * m / B - A * (m / B) << endl;
}



Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>

#define dump(x) cerr << #x << "=" << (x) << endl;
using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define IN(x) int (x); cin >> x
#define INS(x) string (s); cin >> s
#define INL(x) ll (x); cin >> x
#define VINT(a,n) vector<int> a(n)
#define VIN(a,n) VINT(a,n); REP(i,n){cin >> a[i];}
#define ALL(x) (x).begin(),(x).end()

int main () {
  IN(l);
  IN(r);
  int ans;
  if(r/2019>l/2019)
    ans=0;
  else{
    l=l%2019;
    r=r%2019;
    ans=2019;
    int i, j;
    for(i=l; i<=r-1; i++){
      for(j=i+1; j<=r; j++){
	ans=min(ans, (i*j)%2019);
      }
    }
  }
  cout<<ans;
    
  
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        long k = in.nextLong();
        int i = 0;
        while (s.charAt(i) == '1') {
            k--;
            if (k == 0) {
                System.out.println('1');
                return;
            }
            i++;
        }

        System.out.println(s.charAt(i));
    }
}


Measured memory_bytes: 21972
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n, a;

	cin >> n;

	ll ans = 0;

	REP(i, n) {
		cin >> a;
		ans += a - 1;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
N = gets.to_i
A = gets.split.map(&:to_i)
num=0
x=nil
is_up=nil
A.each do |a|
    if x.nil?
        x=a
        num+=1
        is_up=nil
        next
    end
    next if x==a
    if a < x
        if is_up.nil?
            is_up=true
        end
        if is_up
            x=a
            next
        end
        x=a
        num+=1
        is_up=nil
    else
        if is_up.nil?
            is_up=false
        end
        unless is_up
            x=a
            next
        end
        x=a
        num+=1
        is_up=nil
    end
end
puts num

Measured memory_bytes: 20764
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Counting Roads
            var line = ReadLine();
            int n = line[0];
            int m = line[1];

            var roads = new int[n + 1]; //インデックス0は使わない

            for(int i = 0; i < m; i++)
            {
                line = ReadLine();
                int a = line[0];
                int b = line[1];

                roads[a]++;
                roads[b]++;
            }

            for(int i = 1; i <= n; i++)
            {
                Console.WriteLine(roads[i]);
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
 
#define rp(i, k, n) for (int i = k; i < n; i++)
using ll = long long;
using ld = double;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
// const ll MOD = 1e9 + 7ll;
const ll MOD = 998244353;
const double PI=3.14159265358979323846;



int main() {
    int n, k; cin >> n >> k;
    vector<pair<int, int>> S;
    rp(i, 0, k) {
        int l, r; cin >> l >> r;
        S.emplace_back(l, r);
    }  
    vector<ll> res(n+10);
    res[0] = 1;
    rp(i, 1, n) {
        ll sum = 0;
        for(auto x: S) {
            ll left, right;
            if(i - x.second - 1 < 0) left = 0;
            else left = res[i - x.second - 1];
            if(i - x.first < 0) right = 0;
            else right = res[i - x.first];
            sum += right - left; sum = (sum%MOD+MOD)%MOD;
        }
        res[i] = (res[i-1] + sum) %MOD;
    }
    cout << ((res[n-1] - res[n-2])%MOD+MOD)%MOD << endl;
    return 0;
}


Measured memory_bytes: 4832
#include <iostream>

using namespace std;

int main() {

  int T = 0, S = 0;
  string n;
  cin >> n;
  for(int i = 0;i < n.size();i++){
    if(n[i] =='T'){
      if(S > 0){
        S--;
      }else{
        T++;
      }
    }else{
      S++;
    }
  }
  cout << S + T;
  return 0;
}


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

using namespace std;

#define MAX_V 1000
#define MAX_E 2000
#define INF 1e9

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

int V,E,d[MAX_V];
edge es[MAX_E];

bool find_negative_loop(int s){
  for(int i = 0 ; i < V ; i++){
    d[i] = INF;
  }
  d[s] = 0;
  for(int v = 0 ; v < V ; v++){
    bool update = false;
    for(int i = 0 ; i < E ; i++){
      edge e = es[i];
      if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
        d[e.to] = d[e.from] + e.cost;
        if(v == V-1){ return true; }
        update = true;
      }
    }
    if(!update){ break; }
  }
  return false;
}

int main(){
  int r;
  cin >> V >> E >> r;
  for(int i = 0 ; i < E ; i++){
    cin >> es[i].from >> es[i].to >> es[i].cost;
  }
  if(find_negative_loop(r)){
    cout << "NEGATIVE CYCLE" << endl;
  }else{
    for(int i = 0 ; i < V ; i++){
      if(d[i] == INF){
        cout << "INF" << endl;
      }else{
        cout << d[i] << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1184
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
 
int main()
{
    int n;
    int d, min, max;
    long long sum;
 
    scanf("%d%d", &n, &d);
    sum = min = max = d;
    while (--n > 0) {
        scanf("%d", &d);
        if (d < min) min = d;
        if (d > max) max = d;
        sum += d;
    }
    printf("%d %d %lld\n", min, max, sum);
    return 0;
}


Measured memory_bytes: 2104
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    int b = 0;
    for (int i = 1; i <= n; i++) {
      int a = 0;
      for (int j = 1; j <= i; j++) {
        if (i % 2 == 1 && i % j == 0) {
          a++;
        }
      }
      if (a == 8) {
        b++;
      }
    }
    System.out.println(b);
  }
}


Measured memory_bytes: 23892
program knapsack_for_all_subsets
  implicit none
  integer :: n, s, a(3000) = 0, i
  integer(8) :: md = 998244353, f(0:3000) = 0, g(0:3000)
  read(*,*) n, s
  read(*,*) a(1:n)
  f(0) = 1
  do i = 1, n
    g = f
    f(a(i):s) = f(a(i):s)+g(0:s-a(i))
    f = mod(f+g,md)
  end do
  write(*,'(i0)') f(s)
end program knapsack_for_all_subsets

Measured memory_bytes: 2996
#include <iostream>
#include <algorithm>
using namespace std;
#define int long long
const int MAXN=200005;
int n,k;
int a[MAXN];

signed main()

{
	cin>>n>>k;
	for (int i=1;i<=n;i++)
		cin>>a[i];

	if (n<=k){
		cout<<0<<endl;
		return 0;
	}

	sort(a+1,a+1+n);

	int sum=0;
	for (int i=1;i<=n-k;i++)
		sum+=a[i];

	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1792
l= input().split(' ')
x= int(l[0])
y= int(l[1])

def f(x,y):
	if y%2==1:
		return 'No'
	for i in range(2*x, 4*x+1):
		if i==y:
			return 'Yes'
	return 'No'


print(f(x,y))

Measured memory_bytes: 9188
#include <cstdint>
#include <iostream>
#include <queue>

using namespace std;

int main() {
  int64_t N, K;
  cin >> N >> K;

  queue<int64_t> q;
  for (int n = 0; n < N; ++n) {
    int64_t A;
    cin >> A;
    if (K <= n) {
      int64_t num = q.front();
      q.pop();
      if (num < A) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
    q.push(A);
  }
  
  return 0;
}


Measured memory_bytes: 5240
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n, temp, count = 0;
        double[] a = new double[1000];

        while(true){
            n = sc.nextInt();
            if(n == 0) break;

            double ave = 0;
            ArrayList<Integer> s = new ArrayList<Integer>();

            for(int i = 0; i < n; i++){
                temp = sc.nextInt();
                s.add(temp);
                ave += s.get(i);
            }
            ave =(double) ave / n;

            for(int i = 0; i < n; i++){
                a[count] += Math.pow(s.get(i) - ave, 2);
            }
            a[count] /= n;

            a[count] = Math.sqrt(a[count]);

            count++;
        }

        for(int i = 0; i < count; i++){
            System.out.println(a[i]);
        }
        sc.close();
    }
}


Measured memory_bytes: 32424
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
ll n;
const ll MOD = 1000000007;
void Main(){    
    cin>>n;
    vector<pair<ll,ll>> a(n);
    For(i,0,n){
        cin>>a.at(i).first;
        a.at(i).second=i;
    }
    sort(a.begin(),a.end());
    For(i,0,n){
        cout<<a.at(i).second+1<<endl;
    }
}
int main(){
    Main();
    return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x*2<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll n,k,q;cin>>n>>k>>q;
    ll s[n];mset(s);
    for(int i=0;i<q;i++){
        ll d;cin>>d;d--;
        s[d]++;
    }
    for(int i=0;i<n;i++){
        if(s[i]+k-q<=0)cout<<"No\n";
        else cout<<"Yes\n";
    }
}


Measured memory_bytes: 4432
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll value[1005],weight[1005];
ll dp[105][100005];
ll ans(ll n,ll w)
{
    if(w<0)
    return INT_MIN;
    if(n<0)return 0;
    if(dp[n][w]!=-1)return dp[n][w];
    return dp[n][w]=max(value[n]+ans(n-1,w-weight[n]),ans(n-1,w));
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,w;
    cin>>n>>w;
    memset(dp,-1,sizeof(dp));
    for(ll i=0;i<n;i++)
    cin>>weight[i]>>value[i];
    cout<<ans(n-1,w);
    return 0;
}

Measured memory_bytes: 85704
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;	

int main() {
	int n, sum, i; cin >> n;
	sum = 0;
	i = n;

	while (i > 0) {
		sum += i % 10;
		i /= 10;
	}
	if (n % sum == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
;}


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

int n;

int parent(int i) {
	return i / 2;
}

int left(int i) {
	return 2 * i;
}

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

void swap(int *x, int *y) {
	int tmp;

	tmp = *x;
	*x = *y;
	*y = tmp;
}

void maxHeapify(int *A, int i) {
	int l, r, largest;

	l = left(i);
	r = right(i);

	if (l <= n && A[l] > A[i]) largest = l;
	else largest = i;

	if (r <= n && A[r] > A[largest]) largest = r;
	if (largest != i) {
		swap(&A[i], &A[largest]);
		maxHeapify(A, largest);
	}
}

void buildHeap(int *A) {
	int i;

	for (i = (n / 2); i >= 1; i--) {
		maxHeapify(A, i);
	}
}

main() {
	int *node;
	int i;

	scanf("%d", &n);

	node = (int*)malloc(sizeof(int) * (n + 1));

	for (i = 1; i <= n; i++) scanf("%d", &node[i]);

	buildHeap(node);

	for (i = 1; i <= n; i++) printf(" %d", node[i]);
	puts("");

	free(node);

	return 0;
}

Measured memory_bytes: 2468
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007

int main()
{
  string o;
  cin>> o;
  int a=0,hold=0;
  rep(i, o.size())
  {
    if(o[i]=='A'||o[i]=='T'){
    a++;
      
    hold=max(hold,a);
    }
    else if(o[i]=='C'||o[i]=='G'){
    a++;
      
    hold=max(hold,a);
    }
    else
      a=0;
    
  }
  cout << hold << endl;
}

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

if(isupper(s[0]))
{
cout<<s[0];
}
for(int i=1;i<s.length();i++)
{
if(isupper(s[i])&&s[i-1]==' '){
cout<<s[i];
}}
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int V[5];
    int li = -1;
    int x = 999;
    for(int i = 0; i < 5 ; i++){
        cin >> V[i];
        int tmp = V[i]%10;
        if(tmp < x && tmp != 0){
            x = tmp;
            li = i;
        }
    }
    int ans = 0;
    for(int i = 0; i < 5 ; i++){
        if(i == li){
            ans += V[i];
        }else{
            int x = V[i]%10;
            x = 10 - x;
            if(x!= 10){
                ans += (V[i]+x);
            }else{
                ans += V[i];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int K; cin >> K;
    int x = 7%K;
    set<int> st;
    int i = 0;
    while(st.count(x) == 0){
        st.insert(x);
        i++;
        if(x == 0) {
            cout << i << '\n';
            return 0;
        }
        x = (10*x + 7)%K;
    }
    cout << -1 << '\n';
    return 0;
}
//Saw the editorial video

Measured memory_bytes: 50360