akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int x,y;
    cin>>x>>y;
    if(x<y)cout<<min(y-x,abs(x+y)+1);
    if(x>y)cout<<min(abs(y-x)+2,abs(x+y)+1);
    
    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

int main(){
    ll n,counter=0;
    cin >> n;
    rep(i,n){
        int num;
        cin >> num;
        if((i+1)%2==1 && num%2==1){
            counter++;
        }
    }
    cout << counter << endl;
}


Measured memory_bytes: 3632
package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func main() {
	//sc.Split(bufio.ScanWords)
	S := readLine()

	fmt.Printf("%d\n", AGC029A(S))
}

// AGC029A ...
func AGC029A(S string) int {
	res := 0

	tail := len(S) - 1
	for i := 0; i < len(S); i++ {
		if S[i] == 'B' {
			res += tail - i
			tail--
		}
	}

	return res
}


Measured memory_bytes: 2428
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: 753
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  if (x == 7 || x == 5 || x == 3) puts("YES");
  else puts("NO");
  return 0;
}


Measured memory_bytes: 256
n = input()
s = raw_input()

def calc(x, y):
    S = [0]*n
    S[0] = x; S[1] = y
    for i in xrange(2, n):
        if (S[i-1] and s[i-1] == 'o') or (not S[i-1] and s[i-1] == 'x'):
            S[i] = S[i-2]
        else:
            S[i] = S[i-2] ^ 1
    if (S[n-1] and s[n-1] == 'o') or (not S[n-1] and s[n-1] == 'x'):
        if S[n-2] != S[0]:
            return ''
    else:
        if S[n-2] == S[0]:
            return ''
    if (S[0] and s[0] == 'o') or (not S[0] and s[0] == 'x'):
        if S[n-1] != S[1]:
            return ''
    else:
        if S[n-1] == S[1]:
            return ''
    return "".join(map("WS".__getitem__, S))

for i in xrange(4):
    res = calc(i & 1, (i>>1)&1)
    if res:
        print res
        break
else:
    print "-1"

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

template<typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

template<int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(int x_) { if ((x = x_ % mod + mod) >= mod) x -= mod; }
    ModInt& operator+=(ModInt rhs) { if ((x += rhs.x) >= mod) x -= mod; return *this; }
    ModInt& operator-=(ModInt rhs) { if ((x -= rhs.x) < 0) x += mod; return *this; }
    ModInt& operator*=(ModInt rhs) { x = (unsigned long long) x * rhs.x % mod; return *this; }
    ModInt& operator/=(ModInt rhs) { x = (unsigned long long) x * rhs.inv().x % mod; return *this; }

    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }

    friend ostream& operator<<(ostream& s, ModInt<mod> a) { s << a.x; return s; }
    friend istream& operator>>(istream& s, ModInt<mod>& a) { s >> a.x; return s; }
};

using mint = ModInt<(int) 1e9 + 7>;
mint fact[202020];
mint factinv[202020];

void init() {
    fact[0] = 1;
    for (int i = 1; i < 202020; i++) {
        fact[i] = fact[i - 1] * i;
    }
    factinv[202020 - 1] = fact[202020 - 1].inv();
    for (int i = 202020 - 2; i >= 0; i--) {
        factinv[i] = factinv[i + 1] * (i + 1);
    }
    assert(factinv[0] == 1);
}

mint ncr(int n, int r) {
    return fact[n] * factinv[r] * factinv[n - r];
}

int main() {
    init();
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    n--;

    mint p = mint(100).inv() * a;
    mint q = mint(100).inv() * b;

    p = p / mint(a + b) * 100;
    q = q / mint(a + b) * 100;

    vector<mint> powp(101010), powq(101010);
    powp[0] = powq[0] = 1;
    for (int i = 1; i < 101010; i++) {
        powp[i] = powp[i - 1] * p;
        powq[i] = powq[i - 1] * q;
    }

    mint prob = 0;
    for (int i = n; i >= 0; i--) {
        prob += (ncr(2 * n - i, n) * powp[n] * powq[n - i]) * p * (2 * n - i + 1);
        prob += (ncr(2 * n - i, n) * powp[n - i] * powq[n]) * q * (2 * n - i + 1);
    }

    mint r = mint(100).inv() * c;
    prob = prob * (-r + 1).inv();

    cout << prob << endl;
}

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

vector<P>dat[1200000];
struct st { int a, b, c; }p[500000];
bool operator<(st a, st b) {
	return P(a.a, a.b) < P(b.a, b.b);
}
void init(int k, int l, int r) {
	if (r - l == 1) {
		dat[k].push_back(P(p[l].b, p[l].c)); return;
	}
	int lb = k * 2 + 1, rb = k * 2 + 2;
	init(lb, l, (l + r) / 2);
	init(rb, (l + r) / 2, r);
	dat[k].resize(r - l);
	merge(dat[lb].begin(), dat[lb].end(), dat[rb].begin(), dat[rb].end(), dat[k].begin());
}
vector<int>query(int a, int b, int c, int d, int k, int l, int r) {
	if (b <= l || r <= a)return vector<int>();
	if (a <= l&&r <= b) {
		int u = upper_bound(dat[k].begin(), dat[k].end(), P(d, INT_MAX)) - dat[k].begin();
		int v = upper_bound(dat[k].begin(), dat[k].end(), P(c, INT_MIN)) - dat[k].begin();
		vector<int>res;
		for (int i = v; i < u; i++)res.push_back(dat[k][i].second);
		return res;
	}
	auto lb = query(a, b, c, d, k * 2 + 1, l, (l + r) / 2);
	auto rb = query(a, b, c, d, k * 2 + 2, (l + r) / 2, r);
	for (int i : rb)lb.push_back(i);
	return lb;
}
int main() {
	int n; scanf("%d", &n);
	rep(i, n)scanf("%d%d", &p[i].a, &p[i].b), p[i].c = i;
	sort(p, p + n);
	init(0, 0, n);
	int q; scanf("%d", &q);
	rep(i, q) {
		int sx, tx, sy, ty; scanf("%d%d%d%d", &sx, &tx, &sy, &ty);
		int a = lower_bound(p, p + n, st{ sx, INT_MIN,0 }) - p;
		int b = lower_bound(p, p + n, st{ tx, INT_MAX,0 }) - p;
		auto res = query(a, b, sy, ty, 0, 0, n);
		sort(res.begin(), res.end());
		for (int j : res)printf("%d\n", j);
		puts("");
	}
}

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

int c[10] = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
int d[5009][10009], p[5009][10009], r[5009][10009], a[10009];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	for (int i = 0; i < m; i++) 
		cin >> a[i];
	sort(a, a + m); reverse(a, a + m);
	for (int i = 0; i <= n / 2; i++)
		for (int j = 0; j <= n; j++) {
			p[i][j] = -1000000000; r[i][j] = -1;
		}
	p[0][0] = 0;
	for (int i = 1; i <= n / 2; i++)
		for (int j = 1; j <= n; j++)
			for (int k = 0; k < m; k++)
				if (j - c[a[k]] >= 0 && p[i][j] < p[i - 1][j - c[a[k]]] + 1) {
					p[i][j] = p[i - 1][j - c[a[k]]] + 1; r[i][j] = k;
					d[i][j] = a[k];
				}
	for (int i = n / 2; i >= 1; i--) 
		if (p[i][n] >= 0) {
			int ti = i, tj = n;
			while (ti) {
				cout << d[ti][tj];
				tj -= c[a[r[ti][tj]]]; ti--;
			}
			break;
		}
	cout << '\n';
	return 0;
}

Measured memory_bytes: 587520
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
 
public class Main implements Runnable {
	
    public static void main(String[] args) {
    	new Thread(null, new Main(), "", 1 * 1024 * 1024).start();
    }
    
    public void run() {
        FastScanner sc = new FastScanner();
        
        char[] s = sc.next().toCharArray();
        ArrayDeque<Character> q = new ArrayDeque<>();
        for(char c:s){
        	q.offerLast(c);
        }
        
        long ans = 0;
        
    	int anum = 0;
    	
        loop:while(q.size()!=0){
        	char now = 'A';
        	
        	while(now == 'A'){
        		if(q.size()==0){
        			break loop;
        		}
        		now = q.pollFirst();
        		if(now == 'A'){
        			anum++;
        		}
        	}
        	
        	if(now == 'B'){
        		if(q.size()==0){
        			break loop;
        		}
        		now = q.peekFirst();
        		
            	if(now == 'C'){
            		q.pollFirst();
            		ans += anum;
            	}
            	else{ //A→B→AorB
            		anum = 0;
            	}
        	}
        	else{ //A→C
        		anum = 0;
        	}
        }
        
        System.out.println(ans);

    }
    

 
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}
	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 25992
//                          **********  YATIN KWATRA  ********** 

//AC bakshi Rabha

#include <bits/stdc++.h>
#define ll                      long long 
#define ull                     unsigned long long 
#define FIO                     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl                    "\n"
#define fo(i,a,b)               for(int i = a; i<=b ; i++)
#define rfo(i,a,b)              for(int i = a; i>=b ; i--)
#define vii                      vector<int>
#define vll                     vector<ll>
#define pq                      priority_queue
#define uom                      unordered_map                
#define all(v)                  v.begin(),v.end()
#define mp                      make_pair
#define pb                      push_back
#define pob                     pop_back
#define ff                      first
#define ss                      second
#define pii                     pair<int,int> 
#define pll                     pair<long,long>
#define mll                     map<long,long>
#define mii                     map<int,int>
#define vvii                    vector<vii>
#define mod                     1000000007
// #define node                    Node

using namespace std;

void INPUT() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

}

#define pi 3.14159265358979323846

 


void dfs(vii &ans , vii v[],int f , int parent , vector<bool>&vis)
{
  vis[f] = true;
  ans[f] = parent;

  for(auto x : v[f])
  {
    if(!vis[x]) dfs(ans,v,x,f,vis);
  }
}



void solve()
{ 
    int n,m,x,y;
     cin >> n >> m;

   vii v[n+1];

   while(m--)
   {

      cin >> x >> y;

      v[x].pb(y);
      v[y].pb(x);
   }

  

   vii parent(n+1,-1);
   vector<int>ans(n+1,0);
   vector<bool>vis(n+1,false);

  // dfs(ans,v,1,1,vis);
   queue<int>q;
   q.push(1);
   vis[1] = true;
     while(!q.empty())
   {
      int f = q.front();
      q.pop();

      for(auto i : v[f])
      {
        if(!vis[i])
        {
          vis[i] = true;
          ans[i] = f;
          q.push(i);
        }
      }
     
   }

   int ok = 1;

   fo(i,2,n)
   {
    if(!vis[i])
    {
      ok = 0;
      break;
    }
   } 

   if(!ok) cout << "No\n";
   else
   {
      cout << "Yes\n";

      fo(i,2,n) cout << ans[i] << endl;
   }
  
}
int main() {
    
    FIO
  //  INPUT();
    
    int t;
    t = 1;
    //cin >> t;
    
    while(t--)
    {
       solve();
    }
    return 0;
}


Measured memory_bytes: 10680
use whiteread::parse_line;

fn main() {
    let (a, b): (f64, f64) = parse_line().unwrap();
    let p1 = a / 0.08;
    let p2 = b / 0.1;

    let mut p = p1.min(p2).floor();
    while (p * 0.08).floor() == a || (p * 0.1).floor() == b {
        if (p * 0.08).floor() == a && (p * 0.1).floor() == b {
            println!("{}", p.round() as u32);
            return;
        }
        p += 1.0;
    }
    let mut p = p1.max(p2).floor();
    while (p * 0.08).floor() == a || (p * 0.1).floor() == b {
        if (p * 0.08).floor() == a && (p * 0.1).floor() == b {
            println!("{}", p.round() as u32);
            return;
        }
        p += 1.0;
    }
    println!("-1");
}


Measured memory_bytes: 2664
from functools import reduce
import fractions

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
  
N=int(input())
A=[int(x) for x in input().split()]
lcm=lcm_list(A)
ans=0
for a in A:
  ans+=lcm//a
print(ans%1000000007)

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

    if(a.size()>b.size()){
	puts("GREATER");
	return 0;
    }
    else if (a.size()<b.size()){
	puts("LESS");
	return 0;	
    }
    
    if(a==b)
	puts("EQUAL");
    else if(a>b)
	puts("GREATER");
    else
	puts("LESS");
}


Measured memory_bytes: 256
import sys
input  = sys.stdin.readline


def solve():
    N = int(input())
    an = list(map(int,input().strip().split()))
    counter=1
    chk=False
    for i in range(N):
    	if counter == an[i]:
    		chk=True
    		counter+=1
    if chk:
    	print(N-counter+1)
    else:
    	print(-1)


if __name__ == '__main__':
    solve()


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

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

    int n, W;
    cin >> n >> W;

    int dp[101][300] = {};

    int w0;
    for (int h = 0; h < n; h++) {
        int w, v;
        cin >> w >> v;

        if (h == 0) w0 = w;
        w -= w0;

        for (int i = min(h, W / w0 - 1); i >= 0; i--) {
            for (int j = max(h * 3 - 3, 0); j >= 0; j--) {
                int& p = dp[i + 1][j + w];
                p = max(p, dp[i][j] + v);
            }
        }
    }

    int r = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= n * 3 - 3; j++) {
            if (i * w0 + j <= W) r = max(r, dp[i][j]);
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
signed main(){
  string S;
  cin>>S;
  int N=S.size();
  int ans=0;
  rep(i,0,N/2){
    if(S.at(i)!=S.at(N-1-i)) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int read() {
	int x; scanf("%lld", &x); return x;	
}
const int maxn = 1e6 + 10;
const int INF = 1e9;
int mod = 1e9 + 7;
#define ll long long 
main() {
	#ifdef LOCAL
		freopen("1.in", "r", stdin);
	#endif
	int x = abs(read()), k = read(), d = read();
	
	int ans;
	int p;
	if (x / d <= k) {
		k -= (x / d);
		if (k % 2 == 0) ans = x - (x / d) * d; 
		else if (k & 1) ans = abs(x - (x / d) * d - d);
	} else {
		ans = x - k * d;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3748
A,B = map(int,input().split())
ans=10000

import math
for i in range(1250):
  if math.floor(i *0.08)==A and math.floor(i*0.1)==B:
    if ans>i:
      ans=i
if ans==10000:
  print(-1)
else:
  print(ans)
    

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
int main()
{
  int t,a=0,b=0,c=0,d=0;
  cin>>t;
  while(t--)
  {
  	string s;
  	cin>>s;
  	if(s[0]=='A')
  	a++;
  	if(s[0]=='W')
  	b++;
  	if(s[0]=='T')
  	c++;
  	if(s[0]=='R')
  	d++;
  }	
  cout<<"AC"<<" "<<"x"<<" "<<a<<"\n";
   cout<<"WA"<<" "<<"x"<<" "<<b<<"\n";
    cout<<"TLE"<<" "<<"x"<<" "<<c<<"\n";
     cout<<"RE"<<" "<<"x"<<" "<<d<<"\n";
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
int main(){
    int n;
    int a = 4, b = 7;
    cin >> n;

    int num = 0;
    for(int k = 0; k < 100; k++){
        for (int p = 0; p < 100; p++){
            num = a * k + b * p;  
            if (num == n){
                cout << "Yes" << endl;
                exit(0);
            } else if (num > n) {
                break;
            }
        }
    }
    cout << "No" << endl;
}


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

int main() {
  int a;
  cin >> a;
  int YABAI;
  YABAI = 0;
  int P, W, G, Y;
  P = 0;
  W = 0;
  G = 0;
  Y = 0;
  string WAYO;
  
  while(YABAI <= a){
    cin >> WAYO;
    YABAI++;
    if(WAYO == "P"){
     if(P == 0){
      P++;
     }
    }
    else if(WAYO == "W"){
      if(W == 0){
        W++;
      }
    }
    else if(WAYO == "G"){
      if(G == 0){
        G++;
      }
    }
    else if(WAYO == "Y"){
      if(Y == 0){
        Y++;
      }
    }
  }
  int KYR;
  KYR = P + W + G + Y;
  if(KYR == 3){
    cout << "Three" << endl;
  }
  else{
    cout << "Four" << endl;
  }
  
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const long long MOD = 1000000007;

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

    ll n, m;
    cin >> n >> m;
    vector<ll> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    ll tot = 0;
    for (int i = 0; i < n - m; i++) {
        tot += v[i];
    }
    cout << tot;
    return 0;
}

Measured memory_bytes: 1792
N=int(input())
if N%2==1:
  print(0)
else:
  n=N//2
  A=n
  a=0
  b=0
  while A>=5**a:
    a+=1
  while A>=2**b:
    b+=1

  cntfive=0  
  cnttwo=0
  for i in range(1,a):
    cntfive+=n//(5**i)
  for j in range(1,b):
    cnttwo+=n//(2**j)

  ans=min(cntfive,cnttwo+n)
  print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

/**
 * Banned K
 * 
 * https://atcoder.jp/contests/abc159/tasks/abc159_d
 */
public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) throws Exception {
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        long[] B = new long[N + 1];
        for (int a : A) {
            B[a]++;
        }

        long K = 0;
        for (int i = 1; i <= N; i++) {
            K += B[i] * (B[i] - 1) / 2;
        }

        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < N; i++) {
            long b = B[A[i]];
            if (b < 2) {
                ans.append(K).append("\n");
            } else {
                ans.append(K - b * (b - 1) / 2 + (b - 1) * (b - 2) / 2).append("\n");
            }
        }

        System.out.println(ans.toString());
    }

}


Measured memory_bytes: 62628
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define mod 1000000007
#define rg register
using namespace std;
int read()
{
    rg int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,k;
int f[2][22][(1<<20)+5];
int a[22][22];
int nxt[(1<<20)][22];
int main()
{
    n=read();m=read();k=read();
    n--;
    for(rg int i=1;i<=k;i++)
    {
        rg int q=read(),w=read(),e=read();
        a[q][w]=e+1;
    }
    for(rg int i=0;i<(1<<n);i++)
    {
        rg int tmp=0; 
        for(rg int j=n;j>=1;j--)
        {
            if((i&(1<<(j-1)))!=0)  tmp=j;
            else                   nxt[i][j]=tmp;
        }
    }
    f[0][n][0]=1;
    int now=0;
    for(rg int i=1;i<=m;i++)
    {
        now^=1;
        for(rg int j=0;j<(1<<n);j++)  f[now][0][j]=f[now^1][n][j];
        for(rg int j=0;j<(1<<n);j++)  f[now^1][n][j]=0;
        for(rg int j=0;j<n;j++)
        {
            for(rg int k=0;k<(1<<n);k++)
            {
                if(!f[now][j][k])  continue;
                if(!a[i][j+1]||((k>>j)&1)==a[i][j+1]-1)
                {
                    f[now][j+1][k]=(f[now][j+1][k]+f[now][j][k])%mod; 
                }
                if(((k>>j)&1)==0&&a[i][j+1]!=1)
                {
                    rg int tmp=k+(1<<j);
                    if(nxt[k][j+1])  tmp-=(1<<(nxt[k][j+1]-1));
                    f[now][j+1][tmp]=(f[now][j+1][tmp]+f[now][j][k])%mod;
                }
                f[now][j][k]=0;
            }
        }
    }
    int ans=0;
    for(rg int i=0;i<(1<<n);i++)  ans=(ans+f[now][n][i])%mod;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 211200
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, k; cin >> n >> k;
  ll ans = 0;
  for(ll i=k; i<=n+1; i++) {
    ll mn = (i-1)*i/2;
    ll mx = (n+n-i+1)*i/2;
    (ans += (mx-mn+1)) %= mod;
  }
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h> 
 
#define INF (1<<31) - 1 //INT_MAX/2
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using P = std::pair<int, int>;

int main(int argc, char *argv[])
{
    int x, y;
    std::cin >> x >> y;

    if ((x == 1 || x == 2 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) && (y == 2 || y == 4 || y == 6 || y == 9 || y == 11)) {
        std::cout << "No" << std::endl;
    } else if ((y == 1 || y == 2 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12) && (x == 2 || x == 4 || x == 6 || x == 9 || x == 11)) {
        std::cout << "No" << std::endl;
    } else {
        std::cout << "Yes" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 1<<29
#define linf (1e16)
#define eps (1e-8)
#define Eps (1e-12)
#define mod 1000000007
#define pi acos(-1.0)
#define phi (1.0+sqrt(5.0))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define pld(a) printf("%.10Lf\n",(ld)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define Unique(v) v.erase(unique(all(v)),v.end())
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<pii> vpi;

string s = "";
string ans = "123456780";
int d[4] = {-1,1,-3,3};

typedef pair<string,pair<int,int> > state;

int solve(){
  int ind = 0;
  FOR(i,0,9)if(s[i]=='0')ind=i;
  queue<state> q;
  set<string> st;
  st.insert(s);
  q.push(mp(s,mp(0,ind)));
  while(!q.empty()){
    state u = q.front();
    q.pop();
    if(u.f==ans)return u.s.f;
    FOR(i,0,4){
      int index = u.s.s;
      if(index%3==0 && d[i]==-1)continue;
      if((index+1)%3==0 && d[i]==1)continue;
      if(index<=2 && d[i]==-3)continue;
      if(6<=index && d[i]==3)continue;
      string v = u.f;
      swap(v[index],v[index+d[i]]);
      if(st.count(v)==0){
        q.push(state(v,mp(u.s.f+1,index+d[i])));
        st.insert(v);
      }
    }
  }
  return inf;
}

int main()
{
  FOR(i,0,9){
    string a;
    cin>>a;
    s+=a;
  }
  cout<<solve()<<endl;
  return 0;
}


Measured memory_bytes: 20396
player_list = ['a', 'b', 'c']
s = {player_list[n]: list(raw_input()) for n in xrange(len(player_list))}

get_winner = lambda x, s: not s[x] and x.upper() or get_winner(s[x].pop(0), s)

print get_winner(player_list[0], s)

Measured memory_bytes: 2820
n, k = gets.split.map(&:to_i)
hs = (0...n).map { |_| gets.to_i }.sort
ans = 1e9
(n - k + 1).times do |i|
  diff = hs[i + k - 1] - hs[i]
  ans = diff if diff < ans
  break if ans == 0
end
puts ans


Measured memory_bytes: 4528
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <functional>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using Graph = vector<vector<int> >;

int N;
Graph G;

vector<int> res;


void dfs(int v, int p) {
  if(p!=-1)res[v]+=res[p];
  for (auto nv : G[v]) {
    if (nv == p) continue;
    dfs(nv, v);
  }
}

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N,Q;
  cin>>N>>Q;
  G.assign(N, vector<int>());
  res.assign(N,0);
  for(int i=0;i<N-1;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  REP(i,Q){
    int p,x;
    cin>>p>>x;
    p--;
    res[p]+=x;
  }

  dfs(0,-1);

  REP(i,N-1){
    cout<<res[i]<<" ";
  }
  cout<<res[N-1]<<endl;
}


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

using namespace std;

#define int long long

#ifndef bhupixb
    #define var(...)
    #define stl(...)
#endif

#define single_test

vector<int> spf, primes;
void RunLinearSieve(int n) {
    spf.assign(n + 1, 0);
    for(int i = 2; i < n; ++i) {
        if(!spf[i]) {
            spf[i] = i;
            primes.push_back(i);
        }
        for(int x : primes) {
            int calc = i * x;
            if(x > spf[i] || calc > n) {
                break;
            }
            spf[calc] = x;
        }
    }
}

const int maxn = 1e6 + 4;

int a[maxn];

void solve() {
    RunLinearSieve(1e6+4);
    int n;
    cin >> n;
    int g;
    map<int,int> used;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        if (i == 1) {
            g = a[i];
        }
        else {
            g = __gcd(a[i], g);
        }
        int x = a[i];
        while (x > 1) {
            int pf = spf[x];
            while (x % pf == 0) {
                x /= pf;
            }
            used[pf]++;
        }
    }
    for (int i = 1; i < n; ++i) {
        int x = a[i];
        bool f = 0;
        while (x > 1) {
            int pf = spf[x];
            while (x % pf == 0) {
                x /= pf;
            }
            int c = --used[pf];
            if (c == 0) used.erase(pf);
            else f = 1;
        }
        if (f) {
            cout << (g == 1 ? "setwise coprime" : "not coprime");
            return;
        }
    }
    cout << "pairwise coprime" << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    #ifndef single_test
        cin >> t;
    #endif
    for (int i = 1; i <= t; ++i) {
        // cout << "Case #" << i << ": ";
        solve();
    }

    return 0;
}

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

int main() {
  int n;
  int a,b;
  int t;
  t = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    t += b + 1 - a;
  }
  cout << t << endl;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
i = 2
m = 0
while(i<n):
    x = p[i-2]
    y = p[i-1]
    z = p[i]
    if(x<y<z or x>y>z):
        m += 1
    i += 1
print(m)

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

#define fi first
#define se second

const int N = 100100;
const long long mod = 1e9 + 7;

using namespace std;

int n;
int k;
int a[N];
int d[N];

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin >> n >> k;
        for(int i = 1; i <= n; i++){
                cin >> a[i];
        }
        for(int i = 0; i <= k; i++){
                d[i] = 2;
                for(int j = 1; j <= n; j++){
                        if(i >= a[j] && d[i - a[j]] == 2){
                                d[i] = 1;
                        }
                }
        }
        if(d[k] == 1){
                cout << "First" << "\n";
        }
        else{
                cout << "Second" << "\n";
        }
}



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

typedef long long ll;

int main() {
	int n; cin >> n;
	if (n < 1000) cout << "ABC" << endl;
	else cout << "ABD" << endl;
	return 0;
}

Measured memory_bytes: 256
//by Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<s32>
#define p32 pair<int,int>
#define p64 pair<ll,ll>
#define fi first
#define se second
#define ln '\n'
#define debug(x) cout << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream& operator<<(ostream& out, const pair<T,U>& p){
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename ...Args>
void print_container(const ContainerType<ValueType, Args...>& c){
	cout << "{ ";
	for(const auto& v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

int main()
{
	FASTIO;
	int n;
	cin >> n;
	v64 arr(n,0);
	for(int i = 0;i < n;i++)
		cin >> arr[i];
	sort(arr.begin(),arr.end());
	ll ans = 0;
	for(int i = n - 1;i >= 0;i--)
	{
		for(int j = i - 1;j >= 0;j--)
		{
			int idx = lower_bound(arr.begin(),arr.end(),arr[i] + arr[j]) - arr.begin();
			int inv = n - idx;
			ans += ((n - 1 - i) - inv);
		}
	}
	cout << ans << ln;
	return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);

int main()
{
    speed;
    ll i = 0, j = 0, cs = 0, in;
    ll n; cin>>n;
    vll v(n);
    for(i = 0; i < n; i++) cin>>v[i];
    set<ll> s;
    bool f = 1;
    for(i = 0; i < n && f; i++){
        vi lol;
        ll para = v[i];
        for(ll j = 2; j * j <= para; j++){
            if(para % j == 0){
                while(para % j == 0) para /= j;
                lol.pb(j);
            }
        }
        if(para) lol.pb(para);
        for(auto i : lol){
            if(s.count(i) && i != 1) f = 0;
            else s.insert(i);
        }
    }
    if(f) cout << "pairwise coprime" << endl;
    else{
        ll gcd = v[0];
        for(auto i : v) gcd = __gcd(gcd, i);
        if(gcd == 1) cout << "setwise coprime" << endl;
        else cout << "not coprime" << endl;
    }
    return 0;
}


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

int main()
{
	int N;

	cin >> N;

	bool a = false;

	for (int a = 1; a <= 9; a++)for (int b = 1; b <= 9; b++)
	{
		if (a * b == N)
		{
			cout << "Yes";
			a = true;
			return 0;
		}

	}

	if (a == false)
	{
		cout << "No";
	}

}

Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const H = parseInt(arg[0].split(" ")[0]);
    const W = parseInt(arg[0].split(" ")[1]);
    const table = arg.slice(1, H + 1).map(n=>n.split(""));
    
    const bfs = (sy, sx) => {
        const dy = [-1, 0, 1, 0];
        const dx = [0, 1, 0, -1];
        
        let visited = [...Array(H)].map(n=>[...Array(W)].fill(-1));
        let que = [];
        let cost = 0;
        let answer = 0;
        
        que.push([sy, sx]);
        visited[sy][sx] = 0;
        
        while(que.length > 0) {
            const p = que.shift();

            // 上右下左の順で見ていく
            for(let i=0; i<4; i++) {
                const ny = p[0] + dy[i];
                const nx = p[1] + dx[i];
                
                // はみ出し、壁衝突を考慮する
                if(nx < 0 || W <= nx) continue;
                if(ny < 0 || H <= ny) continue;
                if(table[ny][nx] === '#') continue;
                if(visited[ny][nx] !== -1) continue;
                
                que.push([ny, nx]);
                visited[ny][nx] = visited[p[0]][p[1]] + 1;
                
                answer = Math.max(answer, visited[ny][nx]);
            }
        }
        
        // console.log(visited.join("\n"));
        // console.log("---------")
         
        return answer;
    }
    
    let answer = 0;
    
    for(let h=0; h<H; h++) {
        for(let w=0; w<W; w++) {
            if(table[h][w] === "#") continue;
            answer = Math.max(answer, bfs(h, w));
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 24836
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,v) for(auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (lower_bound(ALL(c),x)-upper_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T min(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

signed main()
{
   int N, W; cin >> N >> W;
   V<int> v(N), w(N);
   REP(i, N) {
      cin >> v[i] >> w[i];
   }

   V<int> dp(W+1);
   REP(j, N) RREP(i, W) if (i + w[j] <= W) {
      chmax(dp[i + w[j]], dp[i] + v[j]);
   }
   cout << dp[W] << endl;

   // V<V<int>> dp(N+1, V<int>(W+1));
   // REP(i, W) {
   //    REP(j, N) if (i + w[j] <= W) {
   //       chmax(dp[j+1][i + w[j]], dp[j][i] + v[j]);
   //       chmax(dp[j+1][i], dp[j][i]);
   //    }
   // }

   return 0;
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = int(1e9) + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 200 * 1000 + 13;

int n;
li k;
int a[N];

bool read () {
	if (scanf("%d%lld", &n, &k) != 2)
		return false;
	forn(i, n)
		scanf("%d", &a[i]);
	--k;
	return true;
}

bool used[N];
vector<int> pos[N];
int st[N];

void solve() {
	memset(used, 0, sizeof(used));
	forn(i, N) pos[i].clear();
	forn(i, n) pos[a[i]].pb(i);
	
	int x = 0;
	st[0] = 0;
	int cyc = 1;
	while (cyc <= k){
		used[x] = true;
		//cerr << "! " << x << " " << cyc << endl;
		if (x != pos[a[x]].back())
			x = *upper_bound(all(pos[a[x]]), x) + 1;
		else
			x = n + pos[a[x]][0] + 1;
		
		if (x == 2 * n){
			st[cyc] = n;
			x = 0;
			++cyc;
		}
		
		if (used[x % n])
			break;
		
		if (x >= n){
			x %= n;
			st[cyc] = x;
			++cyc;
		}
	}
	
	//forn(i, cyc)
	//	cerr << st[i] << " ";
	//cerr << endl;
	
	//cerr << cyc << endl;
	
	k %= cyc;
	int pos = st[k];
	
	//cerr << k << " " << pos << endl;
	
	memset(used, 0, sizeof(used));
	vector<int> cur;
	if (pos == n){
		cur.pb(a[0]);
		used[a[0]] = true;
		pos = 0;
		//cerr << cur << endl;
	}
	
	fore(i, pos, n - (st[k] == n)){
		if (used[a[i]]){
			while (cur.back() != a[i]){
				used[cur.back()] = false;
				cur.pop_back();
			}
			used[cur.back()] = false;
			cur.pop_back();
		}
		else{
			cur.pb(a[i]);
			used[a[i]] = true;
		}
		//cerr << cur << endl;
	}
	
	for (auto it : cur)
		printf("%d ", it);
	puts("");
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

#ifdef _DEBUG
	while(read()) {	
#else
	if(read()) {
#endif
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

Measured memory_bytes: 14584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
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; }
#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010
#define lb lower_bound 

int main()
{
   vector<int> a(5);
  for (int i=0;i<5;i++)
  {
    cin>>a[i];
    if (a[i]==0)
      cout<<i+1<<endl;
  }
}

Measured memory_bytes: 3592
/*					                                
									   *                             *
	                                    *             * * * * * * * *
	                                    *             *
	                                    *             *
	                                    *             *
	                                    *             *
	                                    *             *
	                                    *             *
	                                    * * * * * * * * * * * * * * *
	                                                  *             *
	                                                  *             *
	                                                  *             *
	                                                  *             *
	                                                  *             *
	                                                  *             *
	                                    * * * * * * * *             *
	                                   *                             *                             
*/
import java.util.*;
import java.io.*;
import java.lang.*;
class Main{
	public static int dp[][]=new int[100002][3];
	public static int happiness(int arr[][],int n,int m) {
		/*if(n==0) {
			if(m==0) 
				return Main.dp[0][0];
			else if(m==1)
				return Main.dp[0][1];
			else
				return Main.dp[0][2];
		}*/
		if(dp[n][m]!=-1) {
			return Main.dp[n][m];
		}
		else if(m==0) {
			Main.dp[n][m]=arr[n][0]+Math.max(Main.happiness(arr, n-1, 1),Main.happiness(arr, n-1, 2));
			return dp[n][m];
		}
		else if(m==1) {
			Main.dp[n][m]=arr[n][1]+Math.max(Main.happiness(arr, n-1, 0),Main.happiness(arr, n-1, 2));
			return dp[n][m];
		}
		else {
			dp[n][m]=arr[n][2]+Math.max(Main.happiness(arr, n-1, 0),Main.happiness(arr, n-1, 1));
			return dp[n][m];
		}
	}
	public static void main(String []args) {
		for(int i=0;i<100002;i++) {
			for(int j=0;j<3;j++) {
				Main.dp[i][j]=-1;
			}
		}
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int arr[][]=new int[N][3];
		for(int i=0;i<N;i++) {
			arr[i][0]=sc.nextInt();
			arr[i][1]=sc.nextInt();
			arr[i][2]=sc.nextInt();
		}
		Main.dp[0][0]=arr[0][0];
		Main.dp[0][1]=arr[0][1];
		Main.dp[0][2]=arr[0][2];
	    int x=Main.happiness(arr,N-1,0);
	    int y=Main.happiness(arr,N-1,1);
	    int z=Main.happiness(arr,N-1,2);
		System.out.println(Math.max(x,Math.max(y, z)));
		sc.close();
	}
}

Measured memory_bytes: 71148
s = input()
state = [0, 1]
for i in s:
    n = int(i)
    state_new = [min(state[0] + n, state[1] + 10 - n), 
                 min(state[0] + n + 1, state[1] + 9 - n)]
    state = state_new
print(state[0])

Measured memory_bytes: 5492
// https://atcoder.jp/contests/abc136/tasks/abc136_d
// 参考 https://atcoder.jp/contests/abc136/submissions/6715672
// 偶奇性 parity
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

string s;
int n;
vector<int> ans;
void solve();
void solveR();
void solveL();

int main() {
  cin >> s;
  n = s.size();
  ans.resize(n);

  solve();

  rep(i, n) { printf("%d ", ans[i]); }
  cout << endl;
}

void solve() {
  solveR();
  solveL();
}

void solveR() {
  int cnt = 0;
  rep(i, n) {
    if (s[i] == 'R') {
      // 連続するRを数え上げる
      cnt++;
    } else {
      // 半分（切り捨て）
      ans[i] += cnt / 2;
      // 半分（切り上げ）
      ans[i - 1] += (cnt + 1) / 2;
      // カウントをリセット
      cnt = 0;
    }
  }
}

void solveL() {
  int cnt = 0;
  for (int i = n - 1; i > -1; i--) {
    if (s[i] == 'L') {
      cnt++;
    } else {
      ans[i] += cnt / 2;
      ans[i + 1] += (cnt + 1) / 2;
      cnt = 0;
    }
  }
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
  int a,i=0,count=0;
  scanf("%d",&a);
    for(i=a;i>0;i--){

    if(i%2 != 0)
    count++;


  }
  printf("%.10lf\n",(double)count/a);

    return 0;
}


Measured memory_bytes: 128
// Last Update:2017-11-29 22:27:04
// author:sjy
#include<bits/stdc++.h>
using namespace std;
typedef  long long LL;
int find(int n);
int bin[100005];
int du[100005];
int id[100005];
bool flag[100005];
int main(void)
{
    LL N,M;
    while(scanf("%lld %lld",&N,&M)!=EOF)
    {
       for(int i = 0;i < 100005;i++)
           bin[i] = i,du[i] = 1;
       for(int i = 0;i < M;i++)
       {
           int a,b;
           scanf("%d %d",&a,&b);
           int ida = find(a);
           int idb = find(b);
           if(ida!=idb)
           {
               if(du[ida] > du[idb])
                   bin[idb] = ida,du[ida] += du[idb];
               else bin[ida] = idb,du[idb] += du[ida];
           }
       }
       int id1 = find(1);
       int id2 = find(2);
       LL c = du[id1];
       LL d = du[id2];
       if(c < d)
        swap(c,d);
       memset(flag,0,sizeof(flag));
       flag[id1] = true,flag[id2] = true;
       for(int i = 3;i <= N;i++)
       {   int ic = find(i);
           if(!flag[ic])
           {
               flag[ic] = true;
               c+=du[ic];
           }
       }
       LL sum = c*(c-1)/2LL + d*(d-1)/2LL;
       sum -= M;
       printf("%lld\n",sum);
    }
    return 0;
}
int find(int n)
{
    while(n!=bin[n])
        n = bin[n];
    return n;
}


Measured memory_bytes: 1152
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let r: i32 = read();
    println!("{}", 3 * r.pow(2));
}

Measured memory_bytes: 4352