akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll       long long
#define DS       pair<int, int>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 30;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    int n, m;
    cin >> n >> m;
    puts(n == m ? "Yes" : "No");
    return 0;
}


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

Measured memory_bytes: 128
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))}
const main=()=>{
  let [a,b,c]=tnn(3)
  for(let i=1;i<=b;i++){
    if(a*i%b==c){
      to('YES')
      return
    }
  }
  to('NO')
}
main()

Measured memory_bytes: 7372
n=gets.to_i
a=gets.split.map(&:to_i)
a.insert(0,0)
a<<0

sum=0
1.upto(n) do |i|
  sum+=(a[i]-a[i-1]).abs
end
sum+=(a[n]).abs

1.upto(n) do |i|
  diff = (a[i-1]-a[i+1]).abs - (a[i-1]-a[i]).abs - (a[i]-a[i+1]).abs
  puts sum+diff
end

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

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    if(a <= b / k * k)
        cout << "OK" << endl;
    else
        cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#define REP(i,n) for (int i=1;i<=(n);++i)
#define FOR(i,a,b) for (int i=(a);i<=(b);++i)
#define ROF(i,a,b) for (int i=(a);i>=(b);--i)
#define FEC(p,u) for (edge*p=head[u];p;p=p->nxt)
using namespace std;
typedef long long LL;

char s[100], t[100];
int main(){
	scanf("%s", s);
	FOR(i,0,3) t[i] = s[i]; t[4] = ' '; FOR(i,4,11) t[i+1] = s[i];
	printf("%s\n", t);
	return 0;
}


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

using namespace std;

int main(void) {
  int n;
  while (cin >> n, n) {
    int ans = 0;
    while (n != 1) {
      ans++;
      if (n % 2 == 0) n /= 2;
      else n = 3 * n + 1;
    }

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3076
/*
 * Author : Sadi
 * Mon 06/07/2020
 * 14:32:03.56
 */
#include <iostream>
#include <cstdio>
#include <climits>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; ++i) {
    	cin >> v[i];
    }
    sort(all(v));
    int a = n / 2 - 1;
    int b = n / 2;
    cout << (v[b] - v[a]) << endl;
    return 0;
}


Measured memory_bytes: 3716
#include<set>
#include<cstdio>
#include<queue>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
long long read(){
	long long f=1,x=0;
	char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
	return f*x;
}
int len_si[10]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};
int main(){
	long long  a=read(),b=read();
	int i;
	for(i=1;i<=5;i++)
		if(len_si[i]>b)
			break;
	a=a*len_si[i]+b;
	for(int i=1;i<=1000;i++)
		if(i*i==a)
		{
			printf("Yes\n");
			return 0;
		}
	printf("No\n");
	return 0;
}


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

bool startFromLeft(string &str,char l,char r){
    for(int i = 1; i < str.size(); i++){
        if(i%2==1)
            r=str[i];
        else
            l=str[i];
        // ツ妥δ督鳴青ォツ板サツ津ィ
        if((l=='U'&&r=='L')||(l=='R'&&r=='U')||(l=='R'&&r=='L')){
            return false;
            break;
        }
    }
    return true;
}
bool startFromRight(string &str,char l,char r){
    for(int i = 1; i < str.size(); i++){
        if(i%2==1)
            l=str[i];
        else
            r=str[i];
        // ツ妥δ督鳴青ォツ板サツ津ィ
        if((l=='U'&&r=='L')||(l=='R'&&r=='U')||(l=='R'&&r=='L')){
            return false;
            break;
        }
    }
    return true;
}


int main(){
    int n;
    cin>>n;
    while(n--){
        string str;
        cin>>str;
        bool fin=false;
        for(int i = 1; i < str.size(); i++){
            if(str[i]==str[i-1]){
                fin=true;
                break;
            }
        }
        if(fin){
            cout<<"No"<<endl;
            continue;
        }
        char l,r;
        l='L';r='R';
        // ツ右ツ堕ォツつゥツづァ
        if(str[0]=='R'){
            if(!startFromRight(str,l,r)){
                cout<<"No"<<endl;
                continue;
            }
        }
        // ツ債カツ堕ォツつゥツづァ
        else if(str[0]=='L'){
            if(!startFromLeft(str,l,r)){
                cout<<"No"<<endl;
                continue;
            }
        }
        else{
            l=str[0];
            // u or dツつェツ催渉可づ個湘ェツ債づ債猟シツ堕ォツ篠篠つキ
            if(!startFromLeft(str,l,r)){
                r=str[0];
                if(!startFromRight(str,l,r)){
                    cout<<"No"<<endl;
                    continue;
                }
            }
        }
        cout<<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>

    using namespace std;

    int num1, num2, num3;

    int main() {
        cin >> num1 >> num2 >> num3;
        if (num3>num2 && num3>num1){
            if (num3 == num1 + num2) cout << "Yes";
            else cout << "No";
        }
        else if (num2 > num1 && num2 > num3 ){
            if (num2 == num1 + num3) cout << "Yes";
            else cout << "No";
        }
        else {
            if (num1 == num2 + num3) cout << "Yes";
            else cout << "No";}


        return 0;
    }

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    double sum = 0.0;
    rep(i, n) sum += 1.0 / a[i];
    double ans = 1.0 / sum;
    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>

using namespace std;
using ll = long long;

#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N, A, B; in(N); in(A); in(B);

  int X[N];
  rep(i, N) {
    in(X[i]);
  }
  ll ans = 0;
  int diff[N];
  adjacent_difference(X, X + N, diff);
  loop(i, 1, N) {
    ans += min((ll)diff[i] * A, (ll)B);
  }
  out(ans);

  return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        double half = (double)a[n-1]/2d;
        int ans2 = a[0];
        for(int i = 1; i < n-1; i++){
            if(Math.abs(ans2-half) > Math.abs(a[i]-half)){
                ans2 = a[i];
            }
        }
        System.out.println(a[n-1] + " " + ans2);
    }
}

Measured memory_bytes: 50104
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import defaultdict,deque
def resolve():
    n,k=map(int,input().split())
    A=list(map(lambda x:int(x)-1,input().split()))
    S=[0]*(n+1)
    for i in range(n):
        S[i+1]=S[i]+A[i]
        S[i+1]%=k

    C=defaultdict(int)
    Q=deque()
    ans=0
    for s in S:
        ans+=C[s]
        C[s]+=1
        Q.append(s)
        if(len(Q)==k):
            C[Q.popleft()]-=1
    print(ans)
resolve()

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

int main(){
  int N,count=0;
  cin >> N;
  for(int i=0;i<N;i++){
    int A;
    cin >> A;
    if((i+1)%2==1 && A%2==1){
      count++;
    }
  }
  cout << count << endl;
} 

Measured memory_bytes: 3588
#include<algorithm>
#include<cassert>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<iomanip>
#include<map>
#include<numeric>
#include<queue>
#include<vector>
#include<set>
#include<string>
#include<stack>
#include<sstream>
#include<complex>

#define pb push_back
#define clr clear()
#define sz size()
#define fs first
#define sc second

#define rep(i,a) for(int i=0;i<(int)(a);i++)
#define rrep(i,a) for(int i=(int)(a)−1;i>=0;i−−)
#define all(a) (a).begin(),(a).end()
#define EQ(a,b) (abs((a)−(b)) < EPS)
#define INIT(a) memset(a,0,sizeof(a))

using namespace std;
typedef double D;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const D EPS = 1e-8;
const int INF = 1e8;
const D PI = acos(-1);

struct edge{
  int to,cost;
  bool operator<(const edge x)const{return cost>x.cost; }
};
int v; //頂点数
int d[20]; //s から i への最短路
vector<edge> G[20]; //ク&#12441;ラフの隣接リスト表現

void AddEdge(int s,int g,int p){
  G[s].pb((edge){g,p});
}


void dijkstra(int s){
  fill(d,d+v,INF);
  d[s] = 0;
  priority_queue<P ,vector<P> ,greater<P> > q; q.push(P(0,s));
  while(q.sz){
    P p = q.top();q.pop();
    int u = p.second;
    if(d[u] < p.first)continue; rep(i,G[u].sz){
      edge e = G[u][i]; if(d[e.to] > d[u] + e.cost){
	d[e.to] = d[u] + e.cost;
	q.push(P(d[e.to],e.to));
      }
    }
  }
}

int n;
int a,b,c;

int main(){
  while(cin >> n,n){
    rep(i,20){
      G[i].clear();
    }

    v = 0;
    rep(i,n){
      cin >> a >> b >> c;
      v = max(v,max(a,b));
      AddEdge(a,b,c);
      AddEdge(b,a,c);
    }
    v++;

    int res = -1, dis = INF;
    rep(i,v){
      int tmp = 0;
      dijkstra(i);
      rep(j,v)tmp += d[j];
      if(dis > tmp){
	dis = tmp; res = i;
      }
    }
    cout << res << " " << dis <<  endl;
  }
    
}

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

using namespace std;

//int dirs[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
//int dirs[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};


long long modd=1e9+7;

int main()
{
    ios::sync_with_stdio(false);
    //freopen("inp.in","r",stdin);
    //freopen("outp.out","w",stdout);
    int N;
    cin >> N;
    vector<int> v(N);
    int amountZeros=0;
    for(int i=0; i<N; i++)
    {
        cin >> v[i];
        if(v[i]==0) amountZeros++;
    }
    long long ans=1;
    vector<int> counts(3,0);
    for(int i=0; i<N; i++)
    {
        long long mogelijk=0;
        int firstIdx=-1;
        for(int j=0; j<3; j++)
        {
            if(counts[j]==v[i])
            {
                mogelijk++;
                firstIdx=j;
            }
        }
        ans=(ans*mogelijk)%modd;
        if(firstIdx==-1) break;
        counts[firstIdx]++;
    }
    if(amountZeros==0 || amountZeros>3)
    {
        ans=0;
    }
    cout << ans << endl;
    return 0;
}


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


int main() {
	int n, k;
	cin >> n >> k;
	vector<int> h(100100);
	for(int i=0; i<n; i++){
		cin >> h.at(i);
	}
	vector<long long> cost(100100);
	for(int i=0; i<n; i++){
		cost.at(i) = 1000000000;
	}
	cost.at(0) = 0; 
	for(int i=0; i<n-1; i++){
		for(int j=1; j<=k; j++){
			if(i+j > n-1) break;
			int tmp = abs(h.at(i+j) - h.at(i));
			cost.at(i+j) = min(cost.at(i+j), cost.at(i) + tmp);
		}
	}
	cout << cost.at(n-1) << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define rusha scanf("%d",&n);rep(i,1,n)scanf("%d",&a[i]);
#define rushb scanf("%d",&t);while(t--)
#define debug(x) cout<<"LBWNB    "<<x<<"---\n"
#define pb push_back
#define pii pair<int,int>
#define vii vector<int>
#define fi first
#define se second
#define mp make_pair
#define p() puts("")
#define mem(a,b) memset(a,b,sizeof a)
#define all(x) (x.begin(),x.end())
#define judgef printf("%s\n",f?"Yes":"No")
#define Judgef printf("%s\n",f?"YES":"NO")
#define sz(x) ((int)(x).size())
#define sf(x) (sizeof(x))
using namespace std;
typedef long long ll;
typedef double db;
//const int mod=998244353;
const int mod=1e9+7;
//const int inf=1e9+7;
const int maxn=2e5+10;
inline ll ksm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;
x=x*x%mod; y>>=1;} return res; }
inline ll inv(ll a,ll p){if(a==1)return 1;return (p-p/a)*inv(p%a,p)%p;}

//int t,n,m,k;
ll n,k;
int main(){
    scanf("%lld%lld",&n,&k);
    ll s=0;
    for(ll i=k;i<=n+1;i++){
        s=(s+(n+n-i+1)*i/2)%mod;
        s=(s-(i-1)*i/2+1)%mod;
    }
    printf("%lld\n",(s+mod)%mod);
	return 0;
}




//const int M=1<<20;
//ll t1[M*2+5],t2[M*2+5],ans,ca[M],cb[M];
//inline void upd(int i){t1[i]=t1[i<<1]+t1[i<<1|1];t2[i]=max(t2[i<<1],t1[i<<1]+t2[i<<1|1]);}
//inline void add(int i,int v){for(t1[i+=M]+=v;i>>=1;upd(i));}
//int n,m,p,x,y,i,j;
//struct mons{int x,y,z;}a[M];
//int main(){
//	for(i=0;i<M;++i)ca[i]=cb[i]=1ll<<60;ans=-(1ll<<60);
//	scanf("%d%d%d",&n,&m,&p);
//	for(i=1;i<=n;++i)scanf("%d%d",&x,&y),ca[x]=min(ca[x],(ll)y);
//	for(i=1;i<=m;++i)scanf("%d%d",&x,&y),cb[x]=min(cb[x],(ll)y);
//	for(i=0;i<M;++i)t2[i+M]=-cb[i];for(i=M-1;i;--i)upd(i);
//	for(i=1;i<=p;++i)scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
//	sort(a+1,a+p+1,[&](const mons&a,const mons&b){return a.x<b.x;});
//	for(i=0,j=1;i<M;++i){
//		for(;j<=p && a[j].x<i;++j)add(a[j].y,a[j].z);
//		ans=max(ans,t2[1]-ca[i]);
//	}
//	printf("%lld\n",ans);
//	return 0;
//}


Measured memory_bytes: 3776
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int DFS(const vector<vector<int>>& outs, vector<int>& dp, const int start) {
  if (dp[start] != 0) return dp[start];
  int res = 0;
  for (int to : outs[start]) {
    res = max(res, 1 + DFS(outs, dp, to));
  }
  dp[start] = res;

  return res;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> outs(N+1);
  for (int m = 0; m < M; ++m) {
    int from, to;
    cin >> from >> to;
    outs[from].push_back(to);
  }

  vector<int> dp(N+1, 0);
  int res = 0;
  for (int i = 1; i <= N; ++i) {
    res = max(res, DFS(outs, dp, i));
  }
  
  cout << res << endl;

  return 0;
}

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

int main(){
  int N = 9;
  int a[N*N];
  rep(i, N){
    rep(j, N){
      a[N*i+ j] = (i+1)*(j+1);
    }
  }
  int tf=0;
  int x;
  cin >> x;
  rep(i, N*N){
    if(x==a[i]){
       tf=1;
    }
  }
  if(tf==1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}
  

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace atcoder096_B
{
    class Program
    {
        static void Main(string[] args)
        {

            //入力を受け取る
            string[] t_input = Console.ReadLine().Split();
            int[] input = t_input.Select(i => int.Parse(i)).ToArray();
            int K = int.Parse(Console.ReadLine());

            Array.Sort(input);
            int result = input[input.Length-1]*(int)Math.Pow(2, K);
            for (int i = 0;i < input.Length-1;i++)
            {
                result += input[i];
            }

            Console.WriteLine(result);

        }
    }
}


Measured memory_bytes: 11348
n, x = map(int, input().split())
L = [int(i) for i in input().split()] 
d = 0
count = 0
for i in range(n+1):
  if i >= 1:
    d = d + L[i-1]
  if d <= x:
    count = count +1
  else:
    break
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll i=0,ans=0;string S;cin>>S;
  while(S[i]=='T')i++;
  while(i<S.size()){
    ll j=i;while(j<S.size()&&S[j]=='S')j++;
    ans+=j-i;ll k=j;
    while(k<S.size()&&S[k]=='T')k++;
    ans=max((ll)0,ans-k+j);
    i=k;
  }
  cout<<2*ans<<endl;
  return 0;
}

Measured memory_bytes: 640
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	if a == b && b == c {
		fmt.Println(1)
	} else if a != b && a != c && b != c {
		fmt.Println(3)
	} else {
		fmt.Println(2)
	}
}


Measured memory_bytes: 512
using System;


class Program
{
  
  public static int Main()
  {
    //Scanner cin = new Scanner();
    while (true) {
      string str = Console.ReadLine();
      if (str == "END OF INPUT") {
        break;
      }
      string[] strs = str.Split(' ');
      foreach (var item in strs) {
        Console.Write(item.Length);
      }
      Console.WriteLine();
    }
    return 0;
  }
}

class Scanner {
  string[] s;
  int i;

  char[] cs = new char[] { ' ' };

  public Scanner() {
    s = new string[0];
    i = 0;
  }

  public string next() {
    if (i < s.Length) return s[i++];
    do {
      s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
    } while ((s.Length == 1 && s[0] == "") || s.Length == 0);
    i = 0;
    return s[i++];
  }

  public int nextInt() {
    return int.Parse(next());
  }

  public long nextLong() {
    return long.Parse(next());
  }

  public double nextDouble() {
    return double.Parse(next());
  }

}

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

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

  int N;
  cin >> N;
  int A[N], C[N];
  rep(i, N) cin >> A[i];
  if(N%2 == 0){
    for(int i=0;i<N/2;i++){
      C[i] = A[N-1-i*2];
    }
    for(int i=N-1;i>=N/2;i--){
      C[i] = A[N-(N-i)*2];
    }
  }
  else{
    for(int i=0;i<=N/2;i++){
      C[i] = A[N-1-i*2];
    }
    for(int i=N-1;i>N/2;i--){
      C[i] = A[N-(N-i)*2];
    }
  }


  rep(i, N){
    cout << C[i] << endl;
  }
}

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

int gcd(int a, int b) {
    int tmp = a % b;
    while (tmp != 0) {
        a = b;
        b = tmp;
        tmp = a % b;
    }
    return b;
}

int gcd3(int a, int b, int c) {
    return (gcd(gcd(a, b), c));
}

int main() {
    int K;
    cin >> K;
    ll ans = 0;
    FOR(a, 1, K + 1) FOR(b, 1, K + 1) FOR(c, 1, K + 1) {
        ans += gcd3(a, b, c);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  int r,d, x;
  cin >> r >> d >> x;
  rep(i, 10) {
    x = r*x - d;
    cout << x << "\n";
  }
}


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

int main(){
    string t;
    cin>>t;
    int c=0,temp;

    for(int i=0;i<t.size()+1;i++){
        if(c==0&&t[i]=='S'){
            continue;
        }
        if(t[i]=='R'){
            c++;
        }
        else{
           temp=c;
           c=0;
        }

    }
    if(t[0]=='R'&&t[1]=='R'&&t[2]=='S'){
     cout<<2<<endl;
    }
    else if(t[0]=='S'&&t[1]=='R'&&t[2]=='S'){
      cout<<1<<endl;
    }
    else if(t[0]=='R'&&t[1]=='S'&&t[2]=='S'){
      cout<<1<<endl;
    }
    else{
        cout<<temp<<endl;
    }

}


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

int main(){
	int a,b;
	cin>>a>>b;
	if (a<=5){
		cout<<0<<endl;
	}
	else if(a<=12){
		cout<<b/2<<endl;
	}
	else{
		cout<<b<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
U = 0
R = 1
D = 2
L = 3

dx = [0, 1, 0, -1]
dy = [-1, 0, 1, 0]

h, w = gets.split.map(&:to_i)

a = (1..h).map { gets.chomp }
y0 = x0 = nil

dir = nil
(0..h-1).each do |i|
    (0..w-1).each do |j|
        if a[i][j] =~ /[URDL]/
            dir = eval(a[i][j])
            y0 = i
            x0 = j
            a[i][j] = ?.
        end
    end
end

pond = a.reverse.map(&:reverse).join.tr('.o', '01').to_i(2)

def encode(pond, dir, x, y)
    (pond << 10) + (dir << 8) + (x << 4) + y
end

def decode(state)
    [(state >> 10), (state >> 8) & 0b11, (state >> 4) & 0b1111, state & 0b1111]
end

start_state = encode(pond, dir, x0, y0)

stack = [start_state]

prev_state = {start_state => start_state}
goal = nil

catch(:finish) do
    loop do
        state = stack.pop
        pond, dir, x0, y0 = decode(state)

        dirs = [dir-1, dir, dir+1].map {|x| x % 4}
        dirs.each do |new_dir|
            x, y = x0, y0
            catch(:break) do
                loop do
                    x += dx[new_dir]
                    y += dy[new_dir]
                    throw(:break) if x < 0 || x >= w
                    throw(:break) if y < 0 || y >= h
                    break if pond[y * w + x] == 1
                end
                new_pond = pond - (1 << y * w + x)
                new_state = encode(new_pond, new_dir, x, y)
                if ! prev_state[new_state]
                    prev_state[new_state] = state
                    stack << new_state
                end
                if new_pond == 0
                    goal = new_state
                    throw(:finish)
                end
            end
        end
    end
end

v = goal
a = [?U, ?R, ?D, ?L]
route = []
loop do
    _, dir, _, _ = decode(v)
    route << a[dir]
    u = prev_state[v]
    break if u == prev_state[u]
    v = u
end
puts route.join.reverse

Measured memory_bytes: 10772
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<queue>
#define mp make_pair
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<int, piii> piiii;

int dx[9] = {1, 1, 2, 1, 2, 3, 1, 2, 1};
int dy[9] = {2, 1, 1, 0, 0, 0, -1, -1, -2};
int main(int argc, char *argv[]){
  priority_queue<piiii, vector<piiii>, greater<piiii> > que;
  int w, h;
  while(cin >> w >> h, h){
    int foot[2][h][w];
    char g[h][w];
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> g[i][j];
        if(g[i][j] == 'S'){
          que.push(mp(0, mp(0, mp(j, i))));
          que.push(mp(0, mp(1, mp(j, i))));
        }
      }
    }
    int ans = 1e9;
    for (int j = 0; j < h; j++) {
      for (int k = 0; k < w; k++) {
        if(g[j][k] != 'S'){
          foot[0][j][k] = 1e9;
          foot[1][j][k] = 1e9;
        }else{
          foot[0][j][k] = 0;
          foot[1][j][k] = 0;
        }
      }
    }
    
    while(!que.empty()){
      piiii v = que.top();que.pop();
      int c = v.first;
      int f = v.second.first;
      int x = v.second.second.first;
      int y = v.second.second.second;
      for (int i = 0; i < 9; i++) {
        int nx, ny, nc;
        if(f == 1){
          nx = x - dx[i], ny = y + dy[i];
        }else{
          nx = x + dx[i], ny = y + dy[i];
        }
        if(g[ny][nx] == 'S' || g[ny][nx] == 'T')nc = c;
        else nc = c + g[ny][nx] - '0';
        // std::cout << "ny:" << ny << std::endl;
        // std::cout << "nx:"<<nx << std::endl;
        // std::cout << (int)g[ny][nx]  - '0'<< std::endl;
        if(0 <= nx && nx < w &&
           0 <= ny && ny < h &&
           g[ny][nx] != 'X' &&
           foot[f][ny][nx] > nc){
          foot[f][ny][nx] = nc;
          que.push(mp(nc, mp((f+1)&1, mp(nx, ny))));
        }
      }
    }
    for (int j = 0; j < h; j++) {
      for (int k = 0; k < w; k++) {
        if(g[j][k] == 'T'){
        ans = min(ans, foot[0][j][k]);
        ans = min(ans, foot[1][j][k]);
        }
      }
    }
    if(ans != 1e9)std::cout << ans << std::endl;
    else std::cout << -1 << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1228
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    int n; cin>>n;
    ll ans =0;
    vector<int>l(n);
    rep(i,n)cin>>l[i];
    sort(l.begin(),l.end());
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            int a=lower_bound(l.begin(),l.end(),l[i]+l[j])-l.begin();
            ans+=a-(j+1);
        }
    }
    cout<<ans<<endl;
    }


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

template<typename T>
void VIN(vector<T> &v,int n){for(int i=0;i<n;i++) cin >> v[i];}

template<typename T>
void VOUT(vector<T> &v){
    ll n=(int)v.size();
    for(int i=0;i<n;i++) cout << v[i] << (i==n-1?"\n":" ");
}

template<typename T>
void VOUTL(vector<T> &v){
    ll n=(int)v.size();
    for(int i=0;i<n;i++) cout << v[i] << endl;
}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

bool three(ll n){
	string s=to_string(n);
	bool ret=false;
	rep(i,SIZE(s)){
		if(s[i]=='3') ret=true;
	}
	return ret;
}

int main()
{
	ll n;
	cin >> n;
	for(ll i=1;i<=n;i++){
		if(three(i) || i%3==0) cout << " " << i;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3256
import math

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

while not (n+x==0):
    if (x < 6) or ((n*3 -3) < x):
        print(0)
    else:
        answer = 0
        a = 1
        if n*2-1 < x:
            a = x-n*2+1
        for i in range(a, x//3):
            if (x-i >= n):
                if (x-i-n) > i:
                    answer += math.ceil((n*2-x+i)/2)
                else:
                    answer += math.ceil((x-i*3-2)/2)
            else:
                answer += math.ceil((x-i*3-2)/2)
        print(answer)
    n, x = map(int, input().split())
        


Measured memory_bytes: 5660
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cfloat>
#include <climits>
#include <cassert>
#include <random>

int main(){
	int n; std::cin >> n;
	std::vector<int> num(n); for (auto& a : num) std::cin >> a;
	std::sort(num.begin(), num.end());
	num.erase(std::unique(num.begin(), num.end()), num.end());
	std::cout << (num.size() == n ? "YES\n" : "NO\n");
}


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

#define pb push_back
#define fi first
#define se second
typedef long long ll;

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

	int n;
	cin >> n;

	int A[n], ans[n];
	for (int i = 0; i < n; ++i) {
		cin >> A[i];
		ans[A[i] - 1] = i + 1;
	}
	for (int i = 0; i < n; ++i)
		cout << ans[i] << ' ';
	cout << '\n';
}


Measured memory_bytes: 1664
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque




def main():
    num = int(input())
    data = list(map(int, input().split()))
    odd_list = Counter(data[::2])
    even_list = Counter(data[1::2])
    odd_list = sorted(odd_list.items(), key=lambda x: -x[1])
    even_list = sorted(even_list.items(), key=lambda x: -x[1])

    a, b = num // 2, num // 2
    if odd_list[0][0] != even_list[0][0]:
        a = even_list[0][1]
        b = odd_list[0][1]
    elif len(odd_list) == 1 and len(even_list) == 1:
        a = 0
    elif len(odd_list) == 1:
        a = even_list[1][1]
    elif len(even_list) == 1:
        a = odd_list[1][1]
    else:
        if odd_list[0][1] + even_list[1][1] > odd_list[1][1] + even_list[0][1]:
            a = odd_list[0][1]
            b = even_list[1][1]
        else:
            a = odd_list[1][1]
            b = even_list[0][1]
    ans = num - a - b
    print(ans)



if __name__ == '__main__':
    main()



Measured memory_bytes: 65584
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
//#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
 
//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


//}

int ans,a,b,c,x;

main(){
	cin>>a>>b>>c>>x;
	rep(i,a+1){
		rep(j,b+1){
			rep(k,c+1){
				((i*500+j*100+k*50)==x)?ans++:0;
			}
		}
	}
	dump(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;

int x;
char t;
string s;

int a,b,o,ab;

int main(){
	a=b=o=ab=0;
	while(cin>>x>>t>>s){
		if(s=="AB") ab++;
		if(s=="A") a++;
		if(s=="B") b++;
		if(s=="O") o++;
	}
	cout<<a<<endl<<b<<endl<<ab<<endl<<o<<endl;
	return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int n;
    cin>>n;
    int a[n];
    f(i, n) cin>>a[i];
    int pre[n];
    pre[0] = a[0];
    rep(i, 1, n - 1) pre[i] = pre[i - 1] + a[i];
    int ans = pre[n - 1];
    rep(i, 1, n - 1){
        int cans = abs(pre[n - 1] - 2 * pre[i - 1]);
        ans = min(ans, cans);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

printList [a] = print a
printList (a:as) = putStr ( show a ) >> putChar ' ' >> printList as

main = readInt >>= flip replicateM readInts >>= putStrLn . which "Yes" "No" . ( 3 <= ) . maximum . ( 0 : ) . map length . filter ( head ) . group . map ( uncurry (==) . mp )

Measured memory_bytes: 3948
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define Vec2(T, n1, n2, vs) vector<vector<T>> vs(n1, vector<T>(n2))
#define Cin(T, x) T x; cin >> x
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n1, n2, xs) Vec2(T, xs, n1, n2); For(i, n1) For(j, n2) cin >> xs[i][j]
#define Cout(x) cout << (x) << "\n"
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) find(Range(c), x) != c.end()
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))

using namespace std;
using ll = long long;

vector<int> p {
    3, 13, 23, 43, 53,
    73, 83, 103, 113, 163,
    173, 193, 223, 233, 263,
    283, 293, 313, 353, 373,
    383, 433, 443, 463, 503,
    523, 563, 593, 613, 643,
    653, 773, 823, 853, 863,
    883, 953, 983, 1013, 1213,
    1483, 2003, 1153, 1163, 1193, 
    1223, 1823, 1493, 733, 743,
    1033, 1063, 1873, 1423, 1433,
};

int main(void){
    Cin(int, n);
    For(i, n) cout << p[i] << " "; 
    Cout("");
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;

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

int main() {
    ll N,T,A;
    cin >> N >> T >> A;
    ll H[N];
    rep(i,N) cin >> H[i];
    ll out = 0;
    double def = 100000;
    rep(i,N){
        double tem = T-H[i]*0.006;
        if(abs(tem-A)<def){
            out = i+1;
            def = abs(tem-A);
        }
    }
    cout << out << endl;
    return 0;
}



Measured memory_bytes: 3612
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;


int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    int k=n%10;
    if (k==3) cout << "bon" << endl;
    else if (k<2 || k==6 || k==8) cout << "pon" << endl;
    else cout << "hon" << endl; 

    return 0;   
}


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

for i in range(len(a)):
    a[i]-=i+1

aa=sorted(a)
if n%2==0:
  b=(aa[int(n/2-1)]+aa[int(n/2)])/2
else:
  b=aa[int((n-1)/2)]

s=0
for i in aa:
  s+=abs(i-b)
print(int(s))



Measured memory_bytes: 26128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

const int EMAX = 1e5+10;
vector<PII> edge(EMAX);
vector<vector<int> > G(EMAX);
map<PII,int> mp;
int n_c = 0;

void dfs(int v, int p){
  int num = 1;
  int pnum = mp[PII(v,p)];
  for(const int &u : G[v]){
    if(u==p)continue;
    if(num==pnum)++num;
    mp[PII(v,u)] = num;
    mp[PII(u,v)] = num;
    dfs(u,v);
    n_c = max(n_c,num);
    ++num;
  }
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  rep(i,N-1){
    cin >> edge[i].first >> edge[i].second;
    G[edge[i].first].emplace_back(edge[i].second);
    G[edge[i].second].emplace_back(edge[i].first);
  }
  dfs(1,0);
  cout << n_c << endl;
  rep(i,N-1){
    cout << mp[edge[i]] << endl;
  }
  return 0;
}



Measured memory_bytes: 20864
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

struct edge {
	bool used;
	int to, d, rev;
};

ll INI = 1e18;
ll d[100003];
vector<edge> edg[100003];
bool vis[100003];

bool func(int pos, ll dis) {
	if (vis[pos]) return d[pos] == dis;
	vis[pos] = true;
	d[pos] = dis;
	bool ret = true;
	for (int i = 0; i < (int)edg[pos].size(); ++i) {
		edge &e = edg[pos][i];
		if (e.used) continue;
		e.used = true;
		edg[e.to][e.rev].used = true;
		ret &= func(e.to, dis + e.d);
	}
	return ret;
}

int main() {
	int n, m; cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int l, r, d; cin >> l >> r >> d;
		--l; --r;
		edg[l].push_back({ false, r, d, edg[r].size() });
		edg[r].push_back({ false, l, -d, edg[l].size() - 1 });
	}
	bool ans = true;
	for (int i = 0; i < n; ++i) {
		if (vis[i]) continue;
		ans &= func(i, 0);
	}
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 17536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	for(ll i=1;i<=n;i++)
	{
		if (i==k)
			cout<<char(tolower(s[i-1]));
		else
			cout<<s[i-1];
	}
}

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

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define all(co) co.begin(), co.end()
using namespace std;
//using P = pair<int, int>;

int main() {
	int n;
	while (cin >> n && n) {
		int k; cin >> k;
		vector<string> vec(n);
		rep(i, n) cin >> vec[i];

		set<string> sets;
		vector<bool> used(n);
		function<void(string, int)> dfs = [&](string str, int count) {
			if (count == k) {
				sets.insert(str);
				return;
			}
			rep(i, n) if (!used[i]) {
				used[i] = true;
				dfs(str + vec[i], count + 1);
				used[i] = false;
			}
		};
		dfs("", 0);
		cout << sets.size() << endl;
	}
	return 0;
}

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

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int A[16];
int x[16][15];
int y[16][15];
int honest[16];

int main()
{
	int N, ans = 0;

	cin >> N;
	repc(i, 1, N) {
		cin >> A[i];
		rep(j, A[i]) cin >> x[i][j] >> y[i][j];
	}

	honest[1] = -1;
	repc(i, 2, N) honest[i] = 0;

	while (true) {
		bool end = true;
		bool ok = true;
		int cnt = 0;

		repc(i, 1, N) {
			if (honest[i] == 1) honest[i] = 0;
			else {
				honest[i] = 1;
				break;
			}
		}

		repc(i, 1, N) {
			rep(j, A[i]) {
				if (honest[i] == 1 && y[i][j] == 1 && honest[x[i][j]] == 0) ok = false;
				else if (honest[i] == 1 && y[i][j] == 0 && honest[x[i][j]] == 1) ok = false;
			}
		}

		if (ok) {
			repc(i, 1, N) if (honest[i] == 1) cnt++;
			ans = max(ans, cnt);
		}

		repc(i, 1, N) if (honest[i] == 0) end = false;
		if (end) break;
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
    LL N;
    cin >> N;
    vector<LL>  a(N);
    vector<LL>  cnt(100001);
    for(int i = 0;i < N;i++){
        cin >> a[i];
        cnt[a[i]]++;
    }
    LL count1 = 0;
    LL count2 = 0;
    LL ans = 0;
    for(int i = 0;i < 100001;i++){
        if(cnt[i] > 0){
            if(cnt[i] > 1){
                count1++;
                count2 += cnt[i];
            }
            ans++;
        }
    }
    if((count2-count1)&1)   cout << ans-1 << endl;
    else    cout << ans << endl;
}

Measured memory_bytes: 1792