akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>

struct edge{int u,v,cost;};

int par[101],rank[101];
edge es[500];
int V,E;

void init_union_find(int);
int find(int);
void unite(int,int);
bool same(int,int);
bool comp(const edge& e1,const edge& e2);
int kruskal(void);

using namespace std;

int main(void){
  int i,a,b,c;

  while(cin >> V >> E && V){
    for(i=0;i<E;i++){
      cin >> a >> b >> c;
      es[i].u=a;
      es[i].v=b;
      es[i].cost=c;
    }
    printf("%d\n",kruskal());
  }
  return 0;
}

void init_union_find(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    rank[i]=0;
  }
}

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

void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y)return;
  
  if(rank[x] < rank[y]){
    par[x]=y;
  }
  else {
    par[y]=x;
    if(rank[x]==rank[y])rank[x]++;
  }
}

bool same(int x,int y){
  return find(x)==find(y);
}

bool comp(const edge& e1,const edge& e2){
  return e1.cost < e2.cost;
}

int kruskal(){
  sort(es,es+E,comp);
  init_union_find(V);
  int res=0;
  for(int i=0;i<E;i++){
    edge e=es[i];
    if(!same(e.u,e.v)){
      unite(e.u,e.v);
      res+=e.cost;
    }
  }
  return res;
}

Measured memory_bytes: 0
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n; cin >> n;
    vll a(n);
    ll cnt = 0;
    int rem = 0;
    rep(i, n) {
        cin >> a[i];
        cnt += (a[i] + rem)/2;
        if(a[i] == 0) rem = 0;
        else rem = (a[i] + rem) % 2;
    }
    cout << cnt << endl;
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 3968
N = int(input())
say = {}
for i in range(N):
    say[i] = []
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split())
        x -= 1
        say[i].append((x, y))
ans = 0
for i in range(1 << N):
    ok = True
    Honecount = 0
    for j in range(N):
        if((i >> j) & 1 == 0):
            continue
        Honecount += 1
        for k in say[j]:
            if ((i >> k[0]) & 1) != k[1]:
                ok = False
                break
        if ok == False:
            break
    if ok == True:
        ans = max(ans, Honecount)

print(ans)


Measured memory_bytes: 9224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << endl
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rrep(i,n) for(int i=(n); (i)>=0; --(i))
#define reps(i,s,n) for(int i=(s); (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
#define maxemt(v) *max_element(v.begin(), v.end())
#define minemt(v) *min_element(v.begin(), v.end())
#define lb(v,x) v[lower_bound(v.begin(), v.end(), x) - v.begin()]
#define ub(v,x) v[upper_bound(v.begin(), v.end(), x) - v.begin()]
template<class T> inline bool print(T& x){ cout << x << endl; return true; }
template<class T> inline bool print_(T& x){ cout << x << " "; return true; }
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; }
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
const int INF = 1e9;
const ll llINF = 1LL<<60;
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main(){
    int n; cin >> n;
    vector<int> a(n); rep(i,n) cin >> a[i];
    int ans=0;
    rep(i,n) while(a[i]%2 == 0) ans++, a[i]/=2;
    cout << ans;
    
    return 0;
}




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

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

const long long MOD = 1000000007;

int main(){
  int n;
  cin>>n;
  set<string> s;
  vector<tuple<int,string,int>> t(n);
  string x;
  int y;
  rep(i,n){
    cin>> x>> y;
    s.insert(x);
    t.at(i) = make_tuple(y,x,i+1);
  }
  sort(t.begin(),t.end());
  for(string a:s){
    rep(i,n){
      if(get<1>(t.at(n-1-i)) == a) cout<<get<2>(t.at(n-1-i))<<endl;
    }
  }
}


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

typedef long long ll;

#define REP(i, N) for (int i = 0; i < (int)(N); i++)

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


int main() {
    int N,M;
    cin >> N;
    vector<string> s(N);
    REP(i,N) cin >> s[i];
    cin >> M;
    vector<string> t(M);
    REP(i,M) cin >> t[i];
    
    map <string,int> m;
    REP(i,N){
        m[s[i]] = m[s[i]] + 1;
    }
    REP(i,M){
        m[t[i]] = m[t[i]] - 1;
    }
    int ans = 0;
    for ( auto a: m){
        int x = a.second;
        chmax(ans,x);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3600
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(b%a==0) printf("%d",a+b);
	else printf("%d",b-a);
} 

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    X, K, D = map(int, rl().split())
    X = abs(X)
    
    if K < X // D:
        print(X - D * K)
        return
    
    ans = X - D * (X // D)
    K -= X // D
    if K % 2 == 0:
        print(ans)
    else:
        print(abs(ans - D))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 61872
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = input.trim().split("\n");
var a = arr[1].split(" ").map(Number);
var ans = -1;
for (var i = 0; i < a.length; i++) {
   for (var j = i + 1; j < a.length; j++) {
      var v = (a[i] * a[j]) + "";
      var flag = true;
      v.split("").map(Number).reduce(function(a, b) {
         if (a + 1 != b) flag = false;
         return b;
      });
      if (flag) ans = Math.max(ans, v - 0);
   }
}
console.log(ans);

Measured memory_bytes: 60624
a = list(map(int,input().split()))
wa = 0
wa += a[1]
if a[0] > 0 and a[3] > 0 and a[4] > 0:
  wa = max(wa+(a[0]//2+a[3]//2+a[4]//2)*2,wa+3+((a[0]-1)//2+(a[3]-1)//2+(a[4]-1)//2)*2)
else:
  wa = wa+(a[0]//2+a[3]//2+a[4]//2)*2
print(wa)

Measured memory_bytes: 38384
#include "bits/stdc++.h"
using namespace std;

int main(){
    int N,M;
    cin >> N >> M;
    int Q[40]={0};

    for(int i=0;i<N;i++) {
        int K;
        cin >> K;
        int A[K];
        for(int j=0;j<K;j++){
            cin >> A[j];
        }
        for(int j=0;j<K;j++){
            for(int h=1;h<=M;h++){
                if(A[j]==h) Q[h-1]++;
            }
        }
    }
    
    int sum=0;
    for(int i=0;i<M;i++){
        if(Q[i]==N) sum++;
    }
    cout << sum <<endl;

}

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

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int K;
    cin >> K;
    cout << (K/2)*( (K-1)/2 + 1) << endl;
}

Measured memory_bytes: 256
from sys import stdin
import sys
import math
from functools import reduce
import itertools

n,m = [int(x) for x in stdin.readline().rstrip().split()]

check = [0 for i in range(n)]
count = [0 for i in range(n)]

for i in range(m):
    p, q = [x for x in stdin.readline().rstrip().split()]
    p = int(p)

    if q == 'AC':
        check[p-1] = 1

    if q == 'WA' and check[p-1] == 0:
        count[p-1] = count[p-1] + 1

for i in range(n):
    if check[i] == 0: count[i] = 0

print(sum(check), sum(count))


Measured memory_bytes: 11116
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		long n = Long.parseLong(br.readLine());

		System.out.println((n - 1) * n / 2);
	}
}


Measured memory_bytes: 21716
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし

S = LI2()
K = I()

for i in range(K):
    if i == K-1 or S[i] != 1:
        print(S[i])
        break
else:
    print(1)

Measured memory_bytes: 61808
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

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

    if(n<10) {
        cout<<n<<endl;
        return 0;
    }
    if(n<100){
        cout << 9 << endl;
    }
    else if(n < 1000) {
        cout << (n-90) << endl;
    }
    else if(n < 10000){
        cout << 909 << endl;
    }
    else if(n < 100000) {
        cout << (n-90-9000) << endl;
    }
    else {
        cout << 90909 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//define
typedef pair<int,int>pi;
#define elif else if
#define int long long
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define vint vector<int>
#define vvint vector<vector<int>>
#define vtr vector<string>
#define vvtr vector<vector<string>>
#define vhar vector<char>
#define vvhar vector<vector<char>>
#define mod 100000007
#define elif else if
#define str string

signed main(){
  int N,M,O,P=0,c=0,c2=0,crash=0,nowtab=1;
  double D,D2;
  char C;
  str S,T,U;
  vint v(0);
  cin>>S;
  S.erase(S.size()-1);
  S.erase(S.size()-1);
  M=S.size();
  rep(0,M){
    REP(0,S.size()/2){
      if(S[j]==S[S.size()/2+j])c++;
    }
    if(c==S.size()/2){
      c2=S.size();
      break;
    }
    c=0;
    S.erase(S.size()-1);
    S.erase(S.size()-1);
  }
  cout<<c2<<endl;
}


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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;
typedef vector<vector<int>> vvi;

void DFS(vvi &graph, int cur, ll weight[], multiset<ll> &acc, int res[], int par = 0) {

	acc.insert(weight[cur]);
	auto k = acc.lower_bound(weight[cur]);

	bool last_erased = false;
	ll last_erased_val;

	k++;
	if (k != acc.end()) {
		last_erased = true;
		last_erased_val = *k;
		acc.erase(k);
	}

	res[cur] = acc.size();

	for (int x: graph[cur])
		if (x != par)
			DFS(graph, x, weight, acc, res, cur);

	
	if (last_erased) {
		acc.insert(last_erased_val);
	}
	acc.erase(acc.find(weight[cur]));
}

void SOLVE(vvi &graph, ll weight[], int n) {

	int res[n+1];

	multiset<ll> acc;

	DFS(graph, 1, weight, acc, res);

	for (int i = 1; i <= n; i++)
		cout << res[i] << endl;
}

int main() {

	IOS

	int n;
	cin >> n;

	vvi graph(n+1);
	ll weight[n+1];

	for (int i = 1; i <= n; i++)
		cin >> weight[i];

	int u, v;
	for (int i = 0; i < n-1; i++) {
		cin >> u >> v;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}

	SOLVE(graph, weight, n);

	return 0;
}

Measured memory_bytes: 39548
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
fast_io
int a,b,c,d; cin>>a>>b>>c>>d;
int l=a+b, r=c+d;
if(l>r) cout<<"Left";
else if(l==r) cout<<"Balanced";
else cout<<"Right";
return 0;
}

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

int main(){
    int A[5];
    for(int i=0; i<5; i++)
        cin >> A[i];
    int k, flag=0;
    for(int i=0;i<5;i++){
        if(A[i] % 10 != 0){
            k = i;
            flag = 1;
            break;
        }  
    }
    if(flag == 0)
        k = 4;
    for(int i=k+1; i<5; i++){
        if(A[i] % 10 < A[k] % 10 && A[i] % 10 != 0)
            k = i;
    }
    int time=0;
    for(int i=0; i<5; i++){
        if(i == k){
            time += A[i];
        }else{
            if(A[i] % 10 == 0)
                time += A[i];
            else
                time += (A[i] / 10) * 10 + 10;
        }
    }
    
    cout << time << endl;
}


Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;
import std.range;

void main() {
	auto S = readln.chomp.to!(char[]);
	auto ni = (iota('a', 'z').chain('z'.only)).find!(c => !S.canFind(c));
	ni.empty ? writeln("None") : writeln(ni.front);
}


Measured memory_bytes: 536
#include <bits/stdc++.h>
#define INF 1e18
#define Rep(i, a, n) for (ll i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
#define MAX 1000000
#define ll long long
#define P pair<int,int>
#define cout_set(n) cout << setprecision(10) << (n) << endl; 
const double PI=3.14159265358979323846;
using namespace std;
const int mod = 1000000007; 
int vy[4] ={1,-1,0,0}, vx[4] = {0,0,-1,1}; //up,down,left,right 

ll lt[MAX+1]={};

signed main(){
    int x; cin >> x ;
    if(x == 0) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;

LL inf = 1000000000000;
LL mod = 1000000007;

long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

LL gcdExtended(LL a, LL b, LL *x, LL *y); 
  
// Function to find modulo inverse of a 
LL mi(LL a, LL m) 
{ 
    LL x, y; 
    LL g = gcdExtended(a, m, &x, &y); 
	LL res = (x%m + m) % m;
	return res;
} 
  
// C function for extended Euclidean Algorithm 
LL gcdExtended(LL a, LL b, LL *x, LL *y) 
{ 
    // Base Case 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    LL x1, y1; // To store results of recursive call 
    LL gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    // Update x and y using results of recursive 
    // call 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
} 

int main()
{

	LL n, a, b;
	cin >> n >> a >> b;

	LL ans = 0;
	if (n == 2) { 
	}
	else {
		ans = (binpow(2, n, mod) - 1)%mod;

		LL x1 = 1;
		for (LL i = 1; i <= a; ++i) {
			x1 *= (n-i+1);
			x1 %= mod;
			x1 *= mi(i, mod);
			x1 %= mod;
		}

		LL x2 = 1;
		for (LL i = 1; i <= b; ++i) {
			x2 *= (n-i+1);
			x2 %= mod;
			x2 *= mi(i, mod);
			x2 %= mod;
		}
		ans -= x1 + x2;
		ans %= mod;

		//cout << x2 << "\n";
	}

	cout << (ans+mod)%mod << "\n";
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, M = 1e9 + 7, N = 2e6 + 7;

int inv[N], f[N], fi[N];

int qpow(int a, int b) {
	if(b == 0) return 1;
	ll t = qpow(a, b / 2);
	t = t * t % M;
	if(b & 1) return t * a % M;
	else return t;
}
int C(int n, int k) {
	return (ll) f[n] * fi[k] % M * fi[n - k] % M;
}

int H(int n, int k) {
	if(k == 0) return 1;
	return C(n + k - 1, k);
}

signed main()
{
	IO_OP;

	f[0] = 1;
	for(int i = 1; i < N; i++) f[i] = (ll) f[i - 1] * i % M;
	inv[1] = 1;
	for(int i = 2; i < N; i++) inv[i] = M - (ll) M / i * inv[M % i] % M;
	fi[0] = 1;
	for(int i = 1; i < N; i++) fi[i] = (ll) fi[i - 1] * inv[i] % M;
	
	int k;
	string s;
	cin >> k >> s;
	int n = s.size();
	int ans = 0;
	for(int i = 0; i <= k; i++) {
		int cur = qpow(26, i);
		cur = (ll) cur * qpow(25, k - i) % M;
		cur = (ll) cur * H(n, k - i) % M;
		ans = (ans + cur) % M;	
	}
	cout << ans << endl;

}





Measured memory_bytes: 27664
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int N;
P comment[15][15];
int beki(int l){
	if(l==0) return 1;
	else return 2*beki(l-1);
}

int main(){
	int  x, y;
  	cin >> N;
  	int A[N];
  	for(int i=0;i<N;i++){
  		cin >> A[i];
  		for(int j=0;j<A[i];j++){
  			cin >> x >> y;
  			comment[i][j] = make_pair(x-1, y);
  		}
	}
	int M = beki(N);
	int ans = 0;
	for(int x=0;x<M;x++){
		int cnt = 0;
		bool flag = true;
		for(int i=0;i<N;i++){
			if(x&(1<<i)){
				//cout << i <<endl;
				cnt++;
				for(int j=0;j<A[i];j++){
					if(x&(1<<comment[i][j].first) && comment[i][j].second==0){
						flag = false;
						break;
					}
					if((!(x&(1<<comment[i][j].first)))&& comment[i][j].second==1){
						flag = false;
						break;
					}
				}
			}
			if(!flag) break;
		}
		if(flag) ans = max(ans, cnt);
	}
	cout << ans <<endl;

 	return 0;
}




Measured memory_bytes: 256
n = int(input())
S = input()

def ans(S, cnt=0):
    H = []
    for i in S:
        if i == ")":
            if H:
                H.pop()
            else:
               cnt += 1
        else:
            H.append(1)
    return [cnt, len(H)]

L = ans(S)
A = "(" * L[0]
Z = ")" * L[1]

print(A + S + Z)

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

#define all(x) x.begin(), x.end()
#define lc (i << 1)
#define rc (i << 1 | 1)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 2e5 + 5, LN = 17, MOD = 1e9 + 7, INF = 0x3f3f3f3f;
int N, a[MN];
map<ll, int> mp;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
        mp[i - a[i]]++;
    }
    ll ret = 0;
    for (int i = 1; i <= N; i++) {
        ret += mp[i + a[i]];
    }
    cout << ret << '\n';
    return 0;
}


Measured memory_bytes: 27144
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int N=256;
int a[105];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
        scanf("%d",&a[i]);
    int num=0;
    for(int i=0; i<n-2; i++)
        for(int j=i+1; j<n-1; j++)
            for(int k=j+1; k<n; k++)
            {
                if(a[i]==a[j])continue;
                if(a[j]==a[k])continue;
                if(a[i]==a[k])continue;
                if(a[i]+a[j]>a[k]&&a[j]+a[k]>a[i]&&a[i]+a[k]>a[j])num++;
            }
    printf("%d\n",num);
    return 0;
}


Measured memory_bytes: 3820
# -*- coding: utf-8 -*-


s = input()
t = input()
i = 0
count = 0

while i < len(s):
    s = list(s)
    a = s.pop(0)
    s.append(a)
    s = ''.join(s)

    if s == t:
        count += 1

    i += 1


if count >= 1:
    print('Yes')
else:
    print('No')


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

#ifdef DEBUG
    #include "debug.h"
    #define dump(...)                                                              \
        DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
                << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
                << endl                                                            \
                << "    ",                                                         \
            dump_func(__VA_ARGS__)
#else
    #define dump(...)
#endif


// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//////////////////

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

#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
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 (a>b) { a=b; return 1; } return 0; }

//*
#define mod 1000000007 /*/
#define mod 998244353 //*/

typedef pair<int, int> P;
#define INF (1LL<<60)



void solve(){
    int N;
    cin >> N;
    int k = (N+999)/1000*1000;
    cout << k - N << endl;
}


signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed << setprecision(18);
    solve();
}


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

count=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            b=[a[i], a[j], a[k]]
            b.sort()
            if b[0]+b[1]>b[2]:
                if b[0]<b[1] and b[1]<b[2]:
                    count+=1
print(count)

Measured memory_bytes: 68272
import java.lang.reflect.Array;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {

    private static void nCombination3(int c) {
        int count = c;
        int num = 0;
        for (int i = 0; i < count - 2; i++) {
            for (int j = i + 1; j < count - 1; j++) {
                for (int k = j + 1; k < count; k++) {
                    num++;
                }
            }
        }
    }



    public static void main(String[] args) {
        // write your code here
        Scanner sc=new Scanner(System.in);
        String S=sc.next();
        if(S.equals("ABC")){
            System.out.println("ARC");
        }else{
            System.out.println("ABC");
        }
    }
}


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

int N,A[10010];
int main(){
	while(cin>>N && N>0){
		int sum = 0;
		for(int i=1;i<=N;i++){
			cin >> A[i];
			sum += A[i];
		}
		int ans = 0;
		for(int i=1;i<=N;i++){
			if(A[i]*N<=sum) ans++;
		}
		cout << ans << endl;
	}
}


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

using namespace std;

int main()
{
    long long n,i,j,x,y;
    cin >> n;
    long long dp[100001]={0};
    vector<long long> v;
    for(i=0;i<n;i++){
        cin >> x; v.push_back(x);
    }
    dp[1]=abs(v[0]-v[1]);

    for(i=2;i<n;i++){
        dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]), dp[i-2]+abs(v[i]-v[i-2]));
    }
    cout << dp[n-1];
    return 0;
}


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

using namespace std;

typedef pair <int,int>	PII;
typedef vector <int>	VI;
typedef vector <PII>    VII;

const int MD=998244353;
const int INF = 1e7+9;

const int N=1e5+33;

int n,k;


int main() {
	ios_base::sync_with_stdio(false);cout.tie(nullptr);cin.tie(nullptr);
	cin>>n;
	int ans=0;
	//for(int i=0;i<n;i++)cin>>arr[i];
    while(n>0){
        if(n%10 ==2 )ans++;
        n/=10;
    }

    cout<<ans;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  vector<string> s(n);
  for(int i=0; i<n; i++){
    cin >> s[i];
  }
  
  vector<int> a(4);
  for(int j=0; j<n; j++){
    if(s[j] == "AC"){
      a[0]++;
    }
    else if(s[j] == "WA"){
      a[1]++;
    }
    else if(s[j] == "TLE"){
      a[2]++;
    }
    else{
      a[3]++;
    }
  }
  
    cout << "AC x " << a[0] << endl;
    cout << "WA x " << a[1] << endl;
    cout << "TLE x " << a[2] << endl;
    cout << "RE x " << a[3] << endl;
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    vector<ll> l(m),r(m),sum(n+2,0);
    rep(i,m){
      cin>>l[i]>>r[i];
      sum[l[i]]++;
      sum[r[i]+1]--;
    }
    FOR(i,1,n+1){
      sum[i]+=sum[i-1];
    }
    ll ans=0;
    FOR(i,1,n+1){
      //cout<<sum[i]<<endl;
      if(sum[i]==m){
        ans++;
      }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
a = input()
N = len(a)
old_a = a
count1 = 0
count2 = 0
for i in range(N):
    if i%2:
        if a[i:i+1] != "0":
            a = a[:i] + "0" + a[i+1:]
            count1 += 1
    else:
        if a[i:i+1] != "1":
            a = a[:i] + "1" + a[i+1:]
            count1 += 1
a = old_a
for i in range(N):
    if i % 2:
        if a[i:i+1] != "1":
            a = a[:i] + "1" + a[i+1:]
            count2 += 1
    else:
        if a[i:i+1] != "0":
            a = a[:i] + "0" + a[i+1:]
            count2 += 1
if count1 > count2:
    print(count2)
else :
    print(count1)


Measured memory_bytes: 3576
import java.util.*;

public class Main {

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

        int n = sc.nextInt();
        int m = sc.nextInt();
        long[] h = new long[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextLong();
        }
        List<TreeSet<Long>> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(new TreeSet<>(Collections.reverseOrder()));
        }
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() -1;
            int b = sc.nextInt() -1;
            list.get(a).add(h[b]);
            list.get(b).add(h[a]);
        }

        int count = 0;
        for (int i = 0; i < n; i++) {
            Set<Long> tmp = list.get(i);
            if (tmp.isEmpty()){
                count++;
                continue;
            }

            for (Long t : tmp){
                if (h[i] > t) {
                    count++;
                }
                break;
            }
        }

        System.out.println(count);
    }
}

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

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


i64 H, A;

int main() {
  cin >> H >> A;
  i64 cnt = 0;
  cnt += H / A;
  if (H % A > 0) {
    cnt++;
  }
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int ru2(int a){
		int i,r=1;
		for(i=0;i<a;i++)r=r*2;
		return r;
}
 
int main(){
		char s[11];
		scanf("%s",s);
		int i,gen=0,j;
		long long ans=0;
		while(s[gen]!=0)gen++;
		for(i=0;i<ru2(gen);i++){
				int a[10]={0},tmp=0;
				while(tmp<gen){
					if(i&(1<<tmp)){
								a[tmp]=1;
						}
						tmp++;
				}
				long long t=0;
				for(j=0;j<gen;j++){
						t=t*10+s[j]-'0';
						if(a[j]==1){
								ans+=t;
								t=0;
						}
				}
				ans+=t;
		}
		printf("%lld\n",ans/2);
		return 0;
}


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



int main(void)
{
	//乗車券 , 特急券 , 乗車特急券
	int h_input[4] = {0};
	//掛け算変数(Bit演算で使用)
	int kakeru = 100;

	for (int i = 0; i < 3; i++)
	{
		cin >> h_input[i];
		h_input[3] += h_input[i] * kakeru;
		//次は10の位
		kakeru /= 10;
	}

	if (h_input[3] == 110 || h_input[3] == 1)
	{
		cout << "Open" << endl;
	}
	else
	{
		cout << "Close" << endl;
	}

	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false),cin.tie(0);
#define F first
#define S second
using namespace std;
typedef long long ll;
ll a,b,c;
const ll maxn=200005;
const ll mod=1e9+7;
typedef pair<ll,ll> pii;
ll num[100005];
ll n,k,x,y;
string s;
int main()
{
    //IOS
    while(cin>>s)
    {
        for(int i=0;i<=3;i++)
        {
            if(s[i]==s[i+1])
            {
                cout<<"Bad\n";
                return 0;
            }
        }
        cout<<"Good\n";
    }


}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    rep(i, 2) {
        if (a > b) {
            ans += a;
            a--;
        }else {
            ans += b;
            b--;
        }
    }
    out(ans);
    return 0;
}


Measured memory_bytes: 256
while(1):
    n,x=map(int,input().split())
    count = 0
    if x==0 and n==0:
        break
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for k in range(j+1,n+1):
                if i + j + k == x: 
                    count += 1
    print(count)

Measured memory_bytes: 7664
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	x := readInt64()
	y := readInt64()

	var count int
	for i := x; i <= y; i, count = i*2, count+1 {
	}
	println(count)
}


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

int main(){
  int ans=0,judge=0;
  string s;
  cin>>s;
  
  for(int i=0;i<s.size()/2;i++){
    if(s.at(i)!=s.at(s.size()-i-1))
      ans++;
  }

  cout<<ans<<endl;
 
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int a[3], b[3];
  int cnt[5] = {0};
  for (int i = 0; i < 3; i++) {
    cin >> a[i] >> b[i];
    cnt[a[i]]++;
    cnt[b[i]]++;
  }
  bool flag = true;
  for (int i = 1; i < 5; i++) {
    if (cnt[i] == 3 || cnt[i] == 0) {
      flag = false;
      break;
    }
  }
  if (flag) {
    cout << "YES\n";
  }
  else {
    cout << "NO\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,m;
int d[100007];
int main()
{
	n=read(),m=read();
	memset(d,0,sizeof(d));
	for (int i=1;i<=m;i++) ++d[read()],++d[read()];
	bool check=true;
	for (int i=1;i<=n;i++) if (d[i]%2!=0) check=false;
	if (check) cout << "YES" << endl; else cout << "NO" << endl;
	return 0;
}


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

int main() {
  int a, b, c,d;
  cin >> a >> b >> c>>d;
 if(a+b>c+d){
cout <<"Left"<<endl;
}
else{
if(a+b==c+d){
cout <<"Balanced"<<endl;
}
else{
cout<<"Right"<<endl;
}
}
}


Measured memory_bytes: 3624
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    print((1000 - n % 1000) % 1000)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61660
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

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

signed main() {
    cin >> A >> B;
    if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
}

Measured memory_bytes: 3604
#include <stdio.h>

int main(void)
{
	int n,b,f,r,v,a[5][4][11]={0},i,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d %d %d %d",&b,&f,&r,&v);
		a[b][f][r]+=v;
	}
	for(i=1;i<=15;i++){
		if(i%4==0){
			for(j=1;j<=20;j++){
				printf("#");
			}
		}
		else{
			for(j=1;j<=10;j++){
				printf(" %d",a[(i/4)+1][i%4][j]);
			}
		}
			printf("\n");
		}
	
	
	return 0;
}


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


bool can_reach(const vector<int> &xstep, int nstep, int pos, int goal, vector<vector<bool>> &dp){
    if(nstep==xstep.size()){
        if(pos==goal) return true;
        else return false;
    } 
    if(dp[nstep][pos+8000]) return false;
    dp[nstep][pos+8000] = true;

    return can_reach(xstep, nstep+1, pos+xstep[nstep], goal, dp) || can_reach(xstep, nstep+1, pos-xstep[nstep], goal, dp);
}

int main() {
    string s; cin >> s;
    int x, y; cin >> x >> y;
    vector<int> xstep, ystep;
    int i = 0;
    for(; i < s.size(); i++)
    {
        if(s[i]=='T'){
            i++;
            break;
        } 
        x--;        
    }
    bool is_x = false;
    int cnt = 0;
    for (; i < s.size(); i++)
    {
        if(s[i]=='F') cnt++;
        else {
            if(cnt!=0){
                if(is_x) xstep.push_back(cnt);
                else ystep.push_back(cnt);
            }
            is_x = !is_x;
            cnt = 0;
        }
    }
    if(cnt!=0){
        if(is_x) xstep.push_back(cnt);
        else ystep.push_back(cnt);
    }
    sort(xstep.begin(),xstep.end());
    sort(ystep.begin(),ystep.end());
    //for(int j : xstep) cout << j << " ";
    //cout << endl;
    //for(int j : ystep) cout << j << " ";    
    //cout << endl;
    //set<pair<int,int>> xdp, ydp;
    vector<vector<bool>> xdp(xstep.size(), vector<bool>(16001, false)), ydp(ystep.size(), vector<bool>(16001, false));
    if(can_reach(xstep, 0, 0, x, xdp) && can_reach(ystep, 0, 0, y, ydp)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 8448
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n = Integer.parseInt(scanner.nextLine());
		int a = Integer.parseInt(String.valueOf(n).substring(0,1));
		int atama = 0;
		for(int i = 0; i < 3; i++) {

			atama += a * (int)Math.pow(10, i);
		}

		boolean flg = true;

		if(atama < n) {

			a++;
			atama = 0;
			for(int i = 0; i < 3; i++) {

				atama += a * (int)Math.pow(10, i);
			}

		}

		System.out.println(atama);
	}

}

Measured memory_bytes: 35648
#include<iostream>
#include<map>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    int N = (int)S.size(), M = (int)T.size();
    map<char, bool> s_cnt, t_cnt;
    for (int i = 0; i < N; ++i) {
        s_cnt[S[i]] = true;
    }
    for (int i = 0; i < M; ++i) {
        t_cnt[T[i]] = true;
    }
    for (int i = 0; i < 26; ++i) {
        if (!s_cnt[char('a' + i)] && t_cnt[char('a' + i)]) {
            cout << -1 << endl;
            return 0;
        }
    }
    vector<vector<int> > pos(N, vector<int>(26, -1));   // pos[i][j]: i番目以降で'a'+jが出てくるインデックス
    for (int i = 2 * N - 1; i >= 0; --i) {
        for (int j = 0; j < 26; ++j) {
            if ((int)(S[((i % N) + 1) % N] - 'a') == j) {
                pos[i % N][j] = ((i % N) + 1) % N;
            }
            else {
                pos[i % N][j] = pos[((i % N) + 1) % N][j];
            }
        }
    }
    /*
    for (int i = 0; i < N; ++i) {
        cout << i << "-th pos: ";
        for (int j = 0; j < 26; ++j) {
            cout << (char)(j + 'a') << ':' << pos[i][j] << ' ';
        }
        cout << endl;
    }
    */
    ll ans = 0;
    int prev_idx = -1;
    for (int i = 0; i < M; ++i) {
        if (prev_idx < 0) {
            if (S[0] == T[0]) prev_idx = 0;
            else prev_idx = pos[0][(int)(T[i] - 'a')] % N;
            continue;
        }
        int next_idx = pos[prev_idx][(int)(T[i] - 'a')] % N;
        if (next_idx <= prev_idx) ans++;
        prev_idx = next_idx;
    }
    ans *= (ll)N;
    ans += (ll)(prev_idx + 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13776
n=gets.to_i
v=gets.split.map(&:to_i)
count=Array.new(2){Array.new(10**5+1,0)}
v.each_with_index{|a,i|
  count[i%2][a]+=1
}
count.map!{|c|c=c.each_with_index.sort_by(&:first).reverse}

if count[0][0][1]!=count[1][0][1]
  puts n-count[0][0][0]-count[1][0][0]
else
  puts n-[count[0][0][0]+count[1][1][0],count[0][1][0]+count[1][0][0]].max
end

Measured memory_bytes: 24712
#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 n,m;
	cin >> n >> m;
	int wa = 0;
	int ac = 0;
	//インデックスに対応する問題を最終的にACしたか
	vector<int> vec(n);
	//インデックスに対応する問題を何回waしたか
	vector<int> w(n);
	vector<pair<int,string>> pv(m);
	for(int i = 0;i < m;i++){
		cin >> pv[i].first >> pv[i].second;
		pv[i].first--;
		if(vec[pv[i].first]) continue;
		if(pv[i].second == "AC"){
			vec[pv[i].first] = 1;
			ac++;
			wa += w[pv[i].first];
		}else{
			w[pv[i].first]++;
		}
	}
	
	cout << ac << " " << wa << endl;
}

Measured memory_bytes: 7296
#include <iostream>
#include <string>

int main(){
  std::string s;
  getline(std::cin, s);
  int n = s.size();
  std::string s0(n,' ');
  std::string s1(n,' ');
  if(n%2==0){
    for(int i=0;i<n/2;i++){
      s0.at(2*i)='0';
      s0.at(2*i+1)='1';    
      s1.at(2*i)='1';
      s1.at(2*i+1)='0';    
    }
  }else{
    for(int i=0;i<n/2;i++){
      s0.at(2*i)='0';
      s0.at(2*i+1)='1';    
      s1.at(2*i)='1';
      s1.at(2*i+1)='0';    
    }
    s0.at(n-1)='0';
    s1.at(n-1)='1';
  }
//  std::cout << "s0 " << s0 << std::endl;
//  std::cout << "s1 " << s1 << std::endl;

  int count[2]={};
  for(int i=0;i<n;i++){
    if(s.at(i)!=s0.at(i)) count[0]++;
    if(s.at(i)!=s1.at(i)) count[1]++;    
  }
  if(count[0] < count[1]) std::cout << count[0] << std::endl;
  else std::cout << count[1] << std::endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
int a[200005];
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	int n,k,t,s=0;
	set<int> q;
	set<int>::iterator it;
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++)
	{
		int t;
		scanf("%d",&t);
		q.insert(t);
		a[t]++;
	}
	int sum=0;
	for(it=q.begin();it!=q.end();it++)
		sum++;
	if(sum>k)
	{
		sort(a,a+200004,cmp);
		if(sum>k)
		{
			for(int i=k;i<=200004;i++)
			{
				s+=a[i];
				if(a[i]==0)break;
			}
		}	
	}
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 10368
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	inputArr := strings.Split(stdin.Text(), " ")
	numbers := make([]int, len(inputArr))
	for i, v := range inputArr {
		j, _ := strconv.Atoi(v)
		numbers[i] = j
	}
	remainder := numbers[2] - (numbers[0] - numbers[1])
	if remainder >= 0 {
		fmt.Println(remainder)
	} else {
		fmt.Println(0)
	}
}


Measured memory_bytes: 640
from collections import deque
n = int(input())
a = list(map(int,input().split()))
b = deque()
for i in range(n):
  if i%2==0:
    b.append(a[i])
  else:
    b.appendleft(a[i])
if n%2==0:
  print(*b)
else:
  print(*reversed(b))

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

#define pb push_back
#define mp make_pair

typedef long long ll;

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

  for(int i = 1;;i++){
    if(i*(i+1)/2 >= x){
      cout << i << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main ()
{
	int n,t;
	cin>>n;
	t=n%10;
	if(t==2|| t==4|| t==5||t==7||t==9)
	{
		cout<<"hon";
	}
	if(t==0||t==1||t==6||t==8)
	{
		cout<<"pon";
	}
	if(t==3)
	{
		cout<<"bon";
	}
	return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
vector <int> que,ans;

int main()
{
    int n,pp;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&pp);
        que.push_back(pp);
        ans.push_back(pp);
    }
    sort(ans.begin(),ans.end());
    int med = ans[n/2];
    for(int i=0;i<n;i++)
    {
        if(que[i]<med)
            printf("%d\n",med);
        else
            printf("%d\n",ans[n/2-1]);
    }
}


Measured memory_bytes: 3948
// atcoder/abc124/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b;
  while (cin >> a >> b) {
    vector<int> v({a, b});
    int x = 0;
    sort(begin(v), end(v));
    x += v.back();
    --v.back();
    sort(begin(v), end(v));
    x += v.back();
    --v.back();
    cout << x << endl;
  }

  return 0;
}


Measured memory_bytes: 256
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int n, m, i, j, tmp, sum;
    int[] d, p;

    for(;;){
      n = sc.nextInt(); m = sc.nextInt();
      if(n == 0 && m == 0)break;
      d = new int[n]; p = new int[n];
      for(i = 0;i < n;i++){
        d[i] = sc.nextInt(); p[i] = sc.nextInt();
      }
      for(i = 0;i < n - 1;i++)for(j = 0;j < n - 1 - i;j++)if(p[j] < p[j + 1]){
        tmp = d[j]; d[j] = d[j + 1]; d[j + 1] = tmp;
        tmp = p[j]; p[j] = p[j + 1]; p[j + 1] = tmp;
      }
      for(i = 0;i < n;i++){
        if(m >= d[i]){
          m -= d[i]; d[i] = 0;
        }else{
          d[i] -= m; m = 0; break;
        }
      }
      if(m > 0)out.println("0");
      else{
        for(sum = 0;i < n;i++)sum += d[i] * p[i];
        out.println(sum);
      }
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 62904