akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

class UnionFind{
private:
  vector<int> par, rank;
public:
  UnionFind(int n){
	par.assign(n, 0);
	rank.assign(n, 0);
	for(int i=0;i<n;++i)
	  par[i] = i;
  }

  //find root of x
  int find(int x){
	if(par[x] == x)
	  return x;
	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);
  }
};


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

  int N, M, K;
  cin >> N >> M >> K;
  UnionFind uf(N+1);
  VI club(N+1);

  FOR(k,1,K+1){
	int a, b, c;
	cin >> a >> b >> c;
	if(a == 1){
	  int rb = uf.find(b);
	  int rc = uf.find(c);
	  int t = 0;
	  if(club[rb]){
		if(club[rc] && club[rc] != club[rb]){
		  cout << k << endl;
		  return 0;
		}
		t = club[rb];
	  }
	  else t = club[rc];
		
	  club[rb] = club[rc] = t;
	  uf.unite(b, c);
	}
	else{
	  int rb = uf.find(b);
	  if(club[rb] && club[rb] != c){
		cout << k << endl;
		return 0;
	  }
	  club[rb] = c;
	}
  }

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



Measured memory_bytes: 4148
A, B, C = [input() for i in range(3)]

A_ = list(A)
B_ = list(B)
C_ = list(C)


turn = 0
#0 = A ,1 = B, 2 = C 変数でターンを制御する
mai = 300

for i in range(mai):

    if turn == 0:
        if len(A_) == 0:
            print('A')
            break  
        else:
            p = A_[0]
            A_.pop(0)
            mai = len(A_)
            if p == 'a':
                turn = 0
            elif  p == 'b':
                turn = 1
            elif  p == 'c':
                turn = 2

    if turn == 1:
        if len(B_) == 0:
            print('B')
            break
        else:
            p = B_[0]
            B_.pop(0)
            mai = len(B_)
            if p == 'a':
                turn = 0
            elif  p == 'b':
                turn = 1
            elif  p == 'c':
                turn = 2

    if turn == 2:
        if len(C_) == 0:
            print('C')
            break
        else:
            p = C_[0]
            C_.pop(0)
            mai = len(C_)
            if p == 'a':
                turn = 0
            elif  p == 'b':
                turn = 1
            elif  p == 'c':
                turn = 2


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

int main() {
	ios::sync_with_stdio(0),cin.tie(0);
	int result=0,len;
	string str;
	cin>>str;
	len=str.length();
	for(int i=1;i<len;i++)
	{
		if(str[i-1]==str[i])
		{
			if(str[i-1]=='0')
				str[i]='1';
			else
				str[i]='0';
			result++;
		}
	}
	cout<<result<<endl;
}

Measured memory_bytes: 512
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;

import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {



    public static void main(String[] args) throws Exception {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] s = in.readLine().split(" ");
        int N = Integer.parseInt(s[0]);
        int M = Integer.parseInt(s[1]);
        int X = Integer.parseInt(s[2]);
        List<Integer[]> books = new ArrayList<>();
        for(int i = 0; i < N; i++) {
            s = in.readLine().split(" ");
            Integer[] row = new Integer[s.length];
            for(int j = 0; j < row.length; j++) {
                row[j] = Integer.parseInt(s[j]);
            }
            books.add(row);
        }
        List<Integer[]> curr = new ArrayList<>();
        int ans = recurse(books, 0, curr, Integer.MAX_VALUE, X, M);
        if(ans == Integer.MAX_VALUE) System.out.println(-1);
        else System.out.println(ans);
    }

    public static  List<Integer[]> clone( List<Integer[]> list) {
        List<Integer[]> clone = new ArrayList<>();
        for(int i = 0; i < list.size(); i++) {
            Integer[] item = list.get(i);
            Integer[] row = new Integer[item.length];
            for(int j = 0; j < item.length; j++) {
                row[j] = item[j];
            }
            clone.add(row);
        }
        return clone;
    }

    public static void printL(List<Integer[]> curr) {
        for(Integer[] row: curr) {
            System.out.print(row[0] + " ");
        }
        System.out.println();
    }
    public static int recurse(List<Integer[]> books, int start, List<Integer[]> curr, int maxsum, int X, int M) {
        //printL(curr);
        if(curr.size() > 0) {
            int sum = verify(curr, X, M);
            maxsum =  Math.min(maxsum, sum);
        }
        for(int i = start; i < books.size(); i++) {
            List<Integer[]> clone = clone(curr);
            clone.add(books.get(i));
            maxsum = Math.min(recurse(books, i + 1, clone, maxsum, X, M), maxsum);
        }
        return maxsum;
    }

    public static int verify(List<Integer[]> curr, int x, int m) {
        int sum = 0;
        int[] summatrix = new int[m];
        for(int i = 0; i < curr.size(); i++) {
            Integer[] row = curr.get(i);
            for(int j = 0; j < row.length - 1; j++) {
                summatrix[j] += row[j + 1];
            }
            sum += row[0];
        }
        for(int i = 0; i < summatrix.length; i++) {
            if(summatrix[i] < x) return Integer.MAX_VALUE;
        }
        return sum;
    }

}


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

int main(){
    string s;
    int counter;

    cin >> s;

    if(s[0] == 'o') ++counter;
    if(s[1] == 'o') ++counter;
    if(s[2] == 'o') ++counter;

    cout << 700 + (100 * counter) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define print(x) std::cout<<x<<"\n"
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SZ(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

const ll INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
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 <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll GCD(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = gcd(a, v[i]);} return a;}
ll LCM(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = lcm(a, v[i]);} return a;}
VI Bit2Vector(const ll bit, ll n) {	VI s;	rep(i,n) if (bit & (1 << i)) s.push_back(i); return s;}


void Main()
{
	ll n,m,l; ll res=0;
	string s,t,u; string sres="No or NO";

	cin>>n;
	VI a(n),b(n),c;
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	rep(i,n) c.emplace_back(i+1);
	SORT(c);
	ll cnta=0,cntb=0,i=0;
	do{
		i++;
		bool samea=true,sameb=true;
		rep(i,n) if(a[i]!=c[i]) samea=false;
		rep(i,n) if(b[i]!=c[i]) sameb=false;
		if(samea) cnta=i;
		if(sameb) cntb=i;
	}while(next_permutation(ALL(c)));
	res=abs(cnta-cntb);
	cout << res << "\n";
	return;
}

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


Measured memory_bytes: 256
import functools
import math

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


def inl():
    return list(map(int, input().split()))


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper
a, b, c = inl()
print(a * b // 2)

Measured memory_bytes: 3572
from bisect import bisect_left, bisect_right
n = int(input())
*a, = sorted(map(int, input().split()))
*b, = sorted(map(int, input().split()))
*c, = sorted(map(int, input().split()))

ans = 0
for i in range(n):
    ans += (bisect_left(a, b[i])*(n-bisect_right(c, b[i])))
print(ans)


Measured memory_bytes: 23244
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
int bfs[15000000], power[20], n, K, b, c, a[15];
queue<vector<int> >Q;
int hush(vector<int>v) {
	int p = 0;
	for (int i = 0; i < v.size(); i++) p += power[i] * v[i];
	return p;
}
int main() {
	power[0] = 1;
	for (int i = 1; i < 20; i++)power[i] = power[i - 1] * 3;
	while (true) {
		for (int i = 0; i < 15000000; i++)bfs[i] = 1000000000;
		cin >> n >> K; vector<int>s;
		if (n == 0 && K == 0)break;
		cin >> b; for (int i = 0; i < b; i++) { cin >> c; a[c - 1] = 0; }
		cin >> b; for (int i = 0; i < b; i++) { cin >> c; a[c - 1] = 1; }
		cin >> b; for (int i = 0; i < b; i++) { cin >> c; a[c - 1] = 2; }
		for (int i = 0; i < n; i++)s.push_back(a[i]);
		bfs[hush(s)] = 0; Q.push(s);
		while (!Q.empty()) {
			vector<int>a1, a2, a3, t = Q.front(); Q.pop();
			int V = hush(t);
			int A1 = -1, A2 = -1, A3 = -1;
			for (int i = 0; i < n; i++) {
				if (t[i] == 0)A1 = i;
				if (t[i] == 1)A2 = i;
				if (t[i] == 2)A3 = i;
			}
			if (A1 >= 0 && A2 <= A1) {
				int P1 = hush(t) + power[A1];
				if (bfs[P1] == 1000000000) { t[A1] = 1; bfs[P1] = bfs[V] + 1; Q.push(t); t[A1] = 0; }
			}
			if (A2 >= 0 && A1 <= A2) {
				int P1 = hush(t) - power[A2];
				if (bfs[P1] == 1000000000) { t[A2] = 0; bfs[P1] = bfs[V] + 1; Q.push(t); t[A2] = 1; }
			}
			if (A2 >= 0 && A3 <= A2) {
				int P1 = hush(t) + power[A2];
				if (bfs[P1] == 1000000000) { t[A2] = 2; bfs[P1] = bfs[V] + 1; Q.push(t); t[A2] = 1; }
			}
			if (A3 >= 0 && A2 <= A3) {
				int P1 = hush(t) - power[A3];
				if (bfs[P1] == 1000000000) { t[A3] = 1; bfs[P1] = bfs[V] + 1; Q.push(t); t[A3] = 2; }
			}
		}
		int L = min(bfs[0], bfs[power[n] - 1]);
		if (L > K)L = -1;
		cout << L << endl;
	}
	return 0;
}

Measured memory_bytes: 59816
class _Node {
  constructor(key, parent = null, left = null, right = null) {
    this.key = key;
    this.parent = parent;
    this.left = left;
    this.right = right;
  }

  getChildrenNumber() {return Number(this.left !== null) + Number(this.right !== null);}

  isLeftChild() {
    if (this.parent === null) return null;
    return this.parent.left === this;
  }

  getLeftOrRight() {return this.isLeftChild() ? 'left' : 'right';}

  getSuccessor() {
    let n;
    if (this.right !== null) {
      n = this.right;
      while (n.left !== null) n = n.left;
    } else {
      n = this.parent;
      while (!n.isLeftChild && n.parent != null) n = n.parent;
    }
    return n;
  }
}

class BinaryTree {
  constructor() {
    this.root = null;
  }

  static get Node() { return _Node; }

  insert(key) {
    if (this.root === null) {
      this.root = new BinaryTree.Node(key);
      return;
    }
    let x = this.root, y;
    let newNode = new BinaryTree.Node(key);
    while (x !== null) {
      y = x;
      x = x[key < x.key ? 'left' : 'right'];
    }
    newNode.parent = y;
    y[key < y.key ? 'left' : 'right'] = newNode;
  }

  find(key, n = this.root) {
    if (n === null || n.key === key) return n;
    return this.find(key, n[key < n.key ? 'left' : 'right']);
  }

  delete(key) {
    const n = this.find(key);
    const leftOrRight = n.getLeftOrRight();
    switch (n.getChildrenNumber()) {
    case 0:
      n.parent[leftOrRight] = null;
      break;
    case 1:
      n.parent[leftOrRight] = n.left || n.right;
      n.parent[leftOrRight].parent = n.parent;
      break;
    default:
      const skey = n.getSuccessor().key;
      this.delete(skey);
      n.key = skey;
    }
  }

  printByIneorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      innerFunc(n.left);
      str += " " + n.key;
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  printByPreorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      str += " " + n.key;
      innerFunc(n.left);
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  print() {
    this.printByIneorder();
    this.printByPreorder();
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  const tree = new BinaryTree();
  lines.forEach(function(cmd) {
    switch (cmd.charAt(0)) {
    case 'i': tree.insert(Number(cmd.split(' ')[1])); break;
    case 'f': console.log(tree.find(Number(cmd.split(' ')[1])) ? 'yes' : 'no'); break;
    case 'd': tree.delete(Number(cmd.split(' ')[1])); break;
    default: tree.print();
    }
  });
})();



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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

struct Node {
    int val;
    Node* parent;
};

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

    vector<ll> sum_r(n + 1);
    vector<ll> sum_g(n + 1);
    vector<ll> sum_b(n + 1);
    sum_r[0] = 0;
    sum_g[0] = 0;
    sum_b[0] = 0;

    rep(i, n)
    {
        if (s.at(i) == 'R') {
            sum_r.at(i + 1) = sum_r.at(i) + 1;
            sum_g.at(i + 1) = sum_g.at(i);
            sum_b.at(i + 1) = sum_b.at(i);
        }
        if (s.at(i) == 'G') {
            sum_g.at(i + 1) = sum_g.at(i) + 1;
            sum_r.at(i + 1) = sum_r.at(i);
            sum_b.at(i + 1) = sum_b.at(i);
        }
        if (s.at(i) == 'B') {
            sum_b.at(i + 1) = sum_b.at(i) + 1;
            sum_g.at(i + 1) = sum_g.at(i);
            sum_r.at(i + 1) = sum_r.at(i);
        }
    }

    ll ans = 0;
    for (int i = 0; i < n - 2; i++) {
        for (int k = i + 2; k < n; k++) {
            if ((s.at(i) == 'R' && s.at(k) == 'B') || (s.at(i) == 'B' && s.at(k) == 'R')) {
                ans += sum_g.at(k) - sum_g.at(i + 1);
                if ((i + k) % 2 == 0 && s.at((i + k) / 2) == 'G')
                    ans--;
            }
            if ((s.at(i) == 'R' && s.at(k) == 'G') || (s.at(i) == 'G' && s.at(k) == 'R')) {
                ans += sum_b.at(k) - sum_b.at(i + 1);
                if ((i + k) % 2 == 0 && s.at((i + k) / 2) == 'B')
                    ans--;
            }
            if ((s.at(i) == 'B' && s.at(k) == 'G') || (s.at(i) == 'G' && s.at(k) == 'B')) {
                ans += sum_r.at(k) - sum_r.at(i + 1);
                if ((i + k) % 2 == 0 && s.at((i + k) / 2) == 'R')
                    ans--;
            }
        }
    }

    cout << ans << endl;
}


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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	string s;

	cin >> s;

	int ans = 0;
	string  c = "CODEFESTIVAL2016";
	for(int i = 0; i < (int)s.size(); i++)
		if(s[i] != c[i])
			ans++;

	cout << ans << endl;

	return 0;
}

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

const int N = 3e3+5;
int n, a[N], u, v;
vector<int> adj[N];

bool isLeaf(int u)
{
    return adj[u].size() == 0;
}

bool solve(int u, int p, int depth)
{
    //cout << root << ' ' << u << endl;
    if (isLeaf(u))
        return depth&1;
    for (auto v: adj[u])
    {
        if (v == p) continue;
        if (solve(v,u,depth+1) == !(depth&1)) return !(depth&1);
    }
    return depth&1;
}

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 0; i < n-1; i++)
    {
        cin >> u >> v;
        if (a[u] > a[v])
        adj[u].push_back(v);
        if (a[v] > a[u])
        adj[v].push_back(u);
    }
    for (int i = 1; i <= n; i++)
    {
        //cout << i << ' ' << isLeaf(i) << endl;
        if (solve(i,i,0)) cout << i << ' ';
    }
}


Measured memory_bytes: 384
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define REP(i,l,r) for(ll i=l; i<(ll)(r); i++)
#define max(l,r) ((l)>(r)?l:r)
#define min(l,r) ((l)<(r)?l:r)
#define swap(l,r) {ll tp=l;l=r;r=tp;}
const ll MOD = 1000000007;
int upcmpll(const void *a,const void *b){
    return (*(ll*)a == *(ll*)b?0:(*(ll*)a > *(ll*)b?1:-1));
}
void sort_u(ll *a,int n){qsort(a,n,sizeof(ll),upcmpll);}

int main(){
    int n, a, b, c ,d; scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
    char s[201010];
    scanf("%s", s);
  
    int ok = 1;
    REP(i, a-1, d-1){
        if(s[i] == s[i+1] && s[i] == '#'){
           ok = 0;
        }
    }
    if(c > d && ok){
        ok = 0;
        REP(i, b-1, d){
            if(s[i] == s[i+1] && s[i] == s[i-1] && s[i] == '.'){
                 ok = 1;
            }
        }
    }
    if(ok) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 1852
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from itertools import *
import random

S_input = input()
def greedy(S):
    stack = 0
    score = 0
    debug = []
    for ch in S:
        my = ''
        if stack == 0:
            my = 'g'
            stack += 1
        else:
            my = 'p'
            stack -= 1

        debug.append(my)
        if my == 'g' and ch == 'p':
            score -= 1
        elif my == 'p' and ch == 'g':
            score += 1
    # print("myans:",debug)
    return max(score,0)

# def bf(S):
#     leng = len(S)
#     ret = 0
#     best = ""
#     for comb in product("gp", repeat=leng):
#         g_num = 0
#         valid = True
#         for ch in comb:
#             if ch == 'g':
#                 g_num += 1
#             else:
#                 g_num -= 1
#             if g_num < 0:
#                 valid = False
#                 break
#         if not valid:
#             continue


#         score = 0
#         for ch,my in zip(S,comb):
#             if my == 'g' and ch == 'p':
#                 score -= 1
#             elif my == 'p' and ch == 'g':
#                 score += 1
#         if score > ret:
#             ret = score
#             best = comb

#     # print("bf:",best)
#     return ret

# def main():

#     while True:
#         # q = "gggggp"

#         q = []
#         g_num = 0
#         for i in range(6):
#             if g_num == 0:
#                 q.append('g')
#                 g_num += 1
#             else:
#                 tmp = random.choice("gp")
#                 q.append(tmp)
#                 if tmp == 'g':
#                     g_num += 1
#                 else:
#                     g_num -= 1

#         ans1 = greedy(q)
#         ans2 = bf(q)
#         if ans1 != ans2:
#             print("q:", q)
#             print("ans1:",ans1)
#             print("ans2:",ans2)
        
# main()

print(greedy(S_input))



Measured memory_bytes: 5352
#include <cstdio>
#include <cstring>
using namespace std;


const int MAXN = 2e5 + 10;
int dp[2][3000];
char s[MAXN];

int main() {
    scanf("%s", s + 1);// no &
    int n = strlen(s + 1);
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= 2018; j++) {
            dp[i & 1][j] = 0;
        }
        for (int j = 0; j <= 2018; j++) {
            int cur = (j * 10 + s[i] - '0') % 2019;
            dp[i & 1][cur] += dp[(i - 1) & 1][j];
        }
        dp[i & 1][s[i] - '0']++;
        ans += dp[i & 1][0];
    }
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 1940
// こういう問題が解けるようになる気がしない
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)  cin >> a[i];
    int k = *max_element(a.begin(), a.end());
    int l = *min_element(a.begin(), a.end());
    string ans;
    if(k-l > 1){
        ans = "No";
    }else if(k == l){
        ans = k == n-1 || 2*k <= n ? "Yes" : "No";
    }else{
        int lonely = 0;
        for(int i = 0; i < n; i++)  lonely += (a[i] == k-1);
        ans = lonely < k && 2*(k-lonely) <= n-lonely ? "Yes" : "No";
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
n = int(input())
c = 0

for i in range(1,n+1):
    if i >= 1 and i <= 9:
        c += 1
    
    elif i >= 100 and i <= 999:
        c += 1
    
    elif i >= 10000 and i <= 99999:
        c += 1

print(c)

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

int main()
{
    int m, d, ans = 0;
    cin >> m >> d;
    for (int i = 4; i <= m; i++)
    {
        for (int j = 22; j <= d; j++)
        {
            if (j % 10 == 0 || j % 10 == 1)
                continue;
            if ((j / 10) * (j % 10) == i)
                ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from math import ceil

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

left = 1
prob = 0
ac = 0.5 ** m
for i in range(1, 10000):
    prob += i * left * ac
    left -= left * ac

ans = (100 * (n - m) + 1900 * m) * prob
ans = ceil(ans)
print(ans)


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

int		main(void)
{
	string ans = "No";
	int n;

	cin >> n;
	for (int i = 0; i < 26; i++)
	{
		for (int j = 0; j < 15; j++)
		{
			if ((4 * i + 7 * j) == n)
				ans = "Yes";
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <sstream>

using namespace std;

const int maxn = 15;
char a[maxn][maxn];
int visit[maxn];
int way = 0;
int cnt = 0;
int n, k;
bool ishuiwen(string a)
{
    string t(a.rbegin(), a.rend());
    if(a == t)
        return 1;
    else
        return 0;
}


int main()
{
    int a, b;
    cin >> a >> b;
    for(int i=a;i<=b;i++)
    {
        string temp;
        stringstream ss;
        ss << i;
        ss >> temp;
        if(ishuiwen(temp))
            cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 1000000009

int	a[111111];

int main() {
	int n;
	scanf("%d", &n);
	REP(i,n){
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	int m = a[n-1];
	int ans = -1;
	int tmp_score = 1000000000;
	int x = m/2;
	int y = (m + 1) / 2;
	REP(i, n-1) {
		int score = min(abs(a[i] - x), abs(a[i] - y));
		if (score < tmp_score) {
			tmp_score = score;
			ans = a[i];
		}
	}
	printf("%d %d\n", m, ans);
	return 0;
}

Measured memory_bytes: 640
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

int main() {
    int H, W;
    cin >> H >> W;
    auto grid = make_vec_nd('@', W, H);
    int wall_cnt = 0;
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            char c;
            cin >> c;
            grid[x][y] = c;
            if (c == '#') {
                wall_cnt++;
            }
        }
    }
    auto distance = make_vec_nd(numeric_limits<int>::max(), W, H);
    deque<pair<int, int>> seeds;
    seeds.push_back(pair<int, int>{0, 0});
    distance[0][0] = 0;
    while (!seeds.empty()) {
        pair<int, int> now = seeds.front();
        seeds.pop_front();
        for (pair<int, int> vec : {make_pair(-1, 0), make_pair(1, 0), make_pair(0, -1), make_pair(0, 1)}) {
            pair<int, int> next = {now.first + vec.first, now.second + vec.second};
            if (next.first < 0 || next.first >= W || next.second < 0 || next.second >= H) {
                continue;
            }
            if (grid[next.first][next.second] == '#') {
                continue;
            }
            if (distance[next.first][next.second] != numeric_limits<int>::max()) {
                continue;
            }
            distance[next.first][next.second] = distance[now.first][now.second] + 1;
            seeds.push_back(next);
        }
    }
    if (distance[W-1][H-1] == numeric_limits<int>::max()) {
        cout << -1 << endl;
    } else {
        cout << W * H - wall_cnt - distance[W-1][H-1] - 1 << endl;
    }
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef stack<int> SI;
typedef queue<int> QI;
typedef pair<int,int> PII;
typedef long long LL;

#define d(x)  cout<<#x<<" = "<<(x)<<endl;
#define c cout<<"#"<<endl;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).rbegin()) i=(c).rbegin(); i!=(c).rend(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c,n) sort(c,c+n)
#define VSORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define DFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define DREP(i,n) DFOR(i,n,0)
#define INF 2000000000

const double EPS = 1e-10;
const double PI  = acos(-1.0);
////////////////////////////////////////////////
VVI a;
int n,b,d[100010],p[100010];
QI q;
int main()
{
	//??£????????????????????????
	cin>>n>>b;
	REP(i,n+1)
	{
		a.push_back({0});
	}
	REP(i,b)
	{
		int s,t;cin>>s>>t;s++;t++;
		a[s][0]++;
		a[s].push_back(t);
		a[t][0]++;
		a[t].push_back(s);
	}
	FOR(i,1,n+1)
	{
		sort(&a[i][1],&a[i][a[i][0]+1]);
	}
	
	REP(i,n+1)p[i]=1,d[i]=0;
	d[1]=1;
	int g=1;
	for(q.push(1);SZ(q)!=0;)
	{
		int u=q.front();
		q.pop();
		if(a[u][0]==0)
		{
			d[u]=g;g++;
		}
		else
		{
			for(;p[u]<=a[u][0];)
			{
				int v=a[u][p[u]];p[u]++;
				if(v!=1&&d[v]==0)
				{
					d[v]=g;
					q.push(v);
				}
			}
		}
		if(q.empty())
		{
			int i;
			for(i=2;d[i]!=0;i++);
			if(i>n)
			{
				break;
			}
			else
			{
				g++;
				q.push(i);
			}
		}
	}
	cin>>n;
	REP(i,n)
	{
		int first,second;
		cin>>first>>second;first++;second++;
		if(d[first]==d[second])cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}

Measured memory_bytes: 9668
#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
#endif
//BEGIN CUT HERE
template<typename Data, typename T>
struct ReRooting{
  struct Node{
    int to,rev;
    Data data;
    Node(int to,int rev,Data data):to(to),rev(rev),data(data){}
  };

  using F1 = function<T(T, T)>;
  using F2 = function<T(T, Data)>;

  vector<vector<Node> > G;
  vector<vector<T> > ld,rd;
  vector<int> lp,rp;

  const F1 f1;
  const F2 f2;
  const T id;

  ReRooting(int n,const F1 f1,const F2 f2,const T id):
    G(n),ld(n),rd(n),lp(n),rp(n),f1(f1),f2(f2),id(id){}

  void add_edge(int u,int v,Data d){
    G[u].emplace_back(v,(int)G[v].size(),d);
    G[v].emplace_back(u,(int)G[u].size()-1,d);
  }

  T dfs(int v,int p){
    while(lp[v]!=p&&lp[v]<(int)G[v].size()){
      auto &e=G[v][lp[v]];
      ld[v][lp[v]+1]=f1(ld[v][lp[v]],f2(dfs(e.to,e.rev),e.data));
      lp[v]++;
    }
    while(rp[v]!=p&&rp[v]>=0){
      auto &e=G[v][rp[v]];
      rd[v][rp[v]]=f1(rd[v][rp[v]+1],f2(dfs(e.to,e.rev),e.data));
      rp[v]--;
    }
    if(p<0) return rd[v][0];
    return f1(ld[v][p],rd[v][p+1]);
  }

  vector<T> build(){
    for(int i=0;i<(int)G.size();i++){
      ld[i].assign((int)G[i].size()+1,id);
      rd[i].assign((int)G[i].size()+1,id);
      lp[i]=0;
      rp[i]=(int)G[i].size()-1;
    }
    vector<T> res;
    for(int i=0;i<(int)G.size();i++){
      res.emplace_back(dfs(i,-1));
    }
    return res;
  }
};
//END CUT HERE
#ifndef call_from_test
struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed YUKI_768(){
  int n;
  cin>>n;
  auto f1=[](int a,int b){return max(a,0)+max(b,0);};
  auto f2=[](int a,int d){return d-a;};
  ReRooting<int, int> G(n,f1,f2,0);
  for(int i=1;i<n;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G.add_edge(a,b,1);
  }
  auto res=G.build();
  vector<int> ans;
  for(int i=0;i<n;i++)
    if(1-res[i]>0) ans.emplace_back(i);
  cout<<ans.size()<<"\n";
  for(int x:ans) cout<<x+1<<"\n";
  cout<<flush;
  return 0;
};
/*
  verified on 2019/03/04
  https://yukicoder.me/problems/no/768
*/

signed DP_V(){
  int n,m;
  cin>>n>>m;
  auto f1=[m](int a,int b)->int{return (long long)a*b%m;};
  auto f2=[m](int a,int d)->int{return (a+d)%m;};
  ReRooting<int, int> G(n,f1,f2,1);
  for(int i=1;i<n;i++){
    int x,y;
    cin>>x>>y;
    x--;y--;
    G.add_edge(x,y,1);
  }
  auto ans=G.build();
  for(int x:ans) cout<<x<<"\n";
  cout<<flush;
  return 0;
}
/*
  verified on 2019/10/15
  https://atcoder.jp/contests/dp/tasks/dp_v
*/

signed main(){
  //YUKI_768();
  DP_V();
  return 0;
}
#endif


Measured memory_bytes: 28284
N = int(input())
CSF = [list(map(int, input().split())) for i in range(N - 1)]
for i in range(N - 1):
    t = 0
    for j in range(i, N - 1):
        C = CSF[j][0]
        S = CSF[j][1]
        F = CSF[j][2]
        if t <= S:
            t = S
        elif t % F == 0:
            1
        else:
            t += F - t % F
        t += C
    print(t)
print(0)


Measured memory_bytes: 3188
#include <iostream>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <utility>
#include <unordered_map>
#define ll long long int
#define pb push_back
#define mp make_pair


using namespace std;

ll power(ll n, ll dig){
    while(dig-->1){
        n = n*10;
    }
    // cout <<n<<endl;
    return n;
}

void solve(){
    ll n;
    cin>>n;
    cout<<(1000-n%1000)%1000<<endl;
}

int main(){
    // int t; cin>>t;

    solve();

    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(void)
{
    int S,h,m,s;
    scanf("%d",&S);
    h=S/3600;
    m=S%3600/60;
    s=S%3600-m*60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}



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

const int N = 2e5 + 5, mod = 1e9 + 7;
string s;
int dp[N][5];

int solve(int i, int pre)
{
    if (i == s.size())
        return 0;
    if (dp[i][pre] != -1)
        return dp[i][pre];
    int ans = 0;
    if (i == 0)
    {
        for (int j = 1; j < 4; j++)
            ans = max(ans, solve(i + j, j) + 1);
    }
    else
    {
        string t;
        int j = i - pre;
        while (j < i)
            t += s[j++];
        for (j = 1; j < 4 && j + i <= s.size(); j++)
        {
            if (j != pre)
                ans = max(ans, solve(i + j, j) + 1);
            else
            {
                string l;
                int k = i;
                while (k < i + j)
                    l += s[k++];
                if (t != l)
                    ans = max(ans, solve(i + j, j) + 1);
            }
        }
    }
    return dp[i][pre] = ans;
}

int main()
{
    //ios::sync_with_stdio(false);cin.tie(nullptr);ios_base::sync_with_stdio(false);
    cin >> s;
    memset(dp, -1, sizeof dp);
    cout << solve(0, 0);
    return 0;
}

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

using namespace std;

int main() {
	Int a, b, c, d;
	cin >> a >> b >> c >> d;

	Int ans = max({ a*c, a*d, b*c, b*d });
	if ((a <= 0 && 0 <= b) || (c <= 0 && 0 <= d)) {
		ans = max(ans, Int(0));
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3632
n=int(input())
a=list(map(int,input().split()))
x=0
for i in range(n):
	x+=a[i]*(-1)**i
res=[str(x)]
for i in range(1,n):
	res.append(str(2*a[i-1]-x))
	x=2*a[i-1]-x
print(" ".join(res))

Measured memory_bytes: 74212
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> V(N);
    vector<int> result(Q);
    for (int i = 1; i < N; i++){
        if (S[i-1] == 'A' && S[i] == 'C'){
            V[i] = V[i-1] + 1;
        }
        else{
            V[i] = V[i-1];
        }
    }
    for (int i = 0; i < Q; i++){
        int l, r;
        cin >> l >> r;
        result[i] = V[r - 1] - V[l - 1];
    }
    for (auto v : result) cout << v << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main()
{ int a,b,d,r;
	double f;
	scanf("%d %d",&a,&b);
	d=a/b;
	r=a%b;
	f=1.0*a/b;
	printf("%d %d %.8lf",d,r,f);
	
	return 0;
}


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

int main() {
	int a, b;
	cin >> a >> b;

	if (a <= b)
	{
		for (int i = 0; i < b; ++i)
		{
			cout << a;
		}
	}
	else
	{
		for (int i = 0; i < a; ++i)
		{
			cout << b;
		}
	}
}


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

int main()
{
    int n;
    while(cin>>n,n){
        long long ALL=0;
        long long a[n],max=-500000000;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=0;i<n;i++){
            for(int j=i;j<n;j++){
                ALL += a[j];
                if(ALL>max){
                    max=ALL;
                }
            }
            ALL=0;
        }
        cout<<max<<endl;
    }
    return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定 setprecision()
#include <list> //前後に数値を入れれる配列
#include <map> //map
#include <vector> //vecror

#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = acos(-1); //円周率
ll mod = 1e9 + 7;


//提出コード↓




int s, w;

int main() {
	
	cin >> s >> w;
	if (s <= w) cout << "unsafe" << endl;
	else cout << "safe" << endl;

	return 0;
}



Measured memory_bytes: 3596
#include<stdio.h>

int main(){

  int task[3];

  scanf("%d %d %d",&task[0],&task[1],&task[2]);

  int i,j;

  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      if(task[i]<task[j]){
        int a=task[i];
        task[i]=task[j];
        task[j]=a;
      }
    }
  }
  int sum;
  sum=(task[1]-task[0])+(task[2]-task[1]);
  printf("%d",sum);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
int compare(const void *c,const void *b){
    return *(int*)b-*(int*)c;
}
int main(){
    int a,i,r=0,t=1;
    int arr[999];
    scanf("%d",&a);
    for(i=0;i<a;i++)scanf("%d",&arr[i]);
    qsort(arr,a,4,compare);
    for(i=0;i<a;i++){
        r+=t*arr[i];
        t=-t;
    }
    printf("%d\n",r);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define prique priority_queue
signed main(){
    string s,t="zzzzz";
    int k;
    cin>>s>>k;
    int l=s.size();
    vector<string>vec;
    if(l>=5){
        rep(i,l-4){
            if(s.substr(i,5)<t)t=s.substr(i,5);
        }
        l=5;
    }
    else t=s;
    for(int i=1;i<=l;i++){
        for(int j=0;j<l-i+1;j++){
            vec.push_back(t.substr(j,i));
        }
    }
    sort(vec.begin(),vec.end());
    vec.erase(unique(vec.begin(),vec.end()),vec.end());
    cout<<vec[k-1]<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
    {
    	static void Main(string[] args)
    	{
            string a = Console.ReadLine();
            string b = Console.ReadLine();
            string c = Console.ReadLine();
            string d = Console.ReadLine();
            string e = Console.ReadLine();
            string l = Console.ReadLine();
            if (int.Parse(e) - int.Parse(a) > int.Parse(l)) Console.WriteLine(":(");
            else Console.WriteLine("Yay!");
        }
    }
    //mcs Main.cs
    //mono Main.exe

Measured memory_bytes: 13140
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 100000;

int ds[N];

int find(int i) {
	return ds[i] < 0 ? i : (ds[i] = find(ds[i]));
}

void join(int i, int j) {
	i = find(i);
	j = find(j);
	if (i == j)
		return;
	if (ds[i] > ds[j])
		ds[i] = j;
	else {
		if (ds[i] == ds[j])
			ds[i]--;
		ds[j] = i;
	}
}

int main() {
	int n, m; cin >> n >> m;
	fill(ds, ds + n, -1);
	while (m--) {
		int i, j, z; cin >> i >> j >> z, i--, j--;
		join(i, j);
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
		if (ds[i] < 0)
			ans++;
	cout << ans << '\n';
	return 0;
}


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

int main(){
    long long n, i, a[200100], ans[200100]={0}, tmp=0;
    map<long long, long long> mp;
    cin >> n ;
    for(i=0;i<n;i++){
        cin >> a[i];
        mp[a[i]]++;
    }
    for(auto x : mp){
        tmp+=x.second*(x.second-1)/2;
    }
    for(i=0;i<n;i++){
        ans[i]=tmp-(mp[a[i]]*(mp[a[i]]-1)/2);
        mp[a[i]]--;
        ans[i]+=mp[a[i]]*(mp[a[i]]-1)/2;
        mp[a[i]]++;
    }
    for(i=0;i<n;i++){
        cout << ans[i] <<endl;
    }
    return 0;
}

Measured memory_bytes: 12672
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;

map< int, int > prime_factor(int64_t n) {
  map< int, int > ret;
  for(int i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}



signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[n];
  rep(i,n) cin>>a[i];
  int gcdd=gcd(a[0],a[1]);
  map<int,int> mp;
  bool pawis=true,setws=true;
  rep(i,n){
    gcdd=gcd(gcdd,a[i]);
    if(pawis){
      map<int,int> x=prime_factor(a[i]);
      for(auto itr=x.begin();itr!=x.end();itr++){
	if(mp.count(itr->F) ){pawis=false;break;}
	else{
	  mp[itr->F]++;
	}
      }
    }
    // for(auto itr=mp.begin();itr!=mp.end();itr++){
      // cout<<itr->F<<" ";
    // }
    // cout<<endl;
  }
  if(pawis) cout<<"pairwise coprime"<<endl;
  else if(gcdd==1) cout<<"setwise coprime"<<endl;
  else cout<<"not coprime"<<endl;
	  

  return 0;
}


Measured memory_bytes: 11424
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
//グリッド探索用クラス
class Grid{
public:
	int h, w;
	vector<vector<char>> s;
	vector<vector<bool>> flag;

	//グリッド情報の入力(探索のしやすさのため，グリッドのふちは'#'or'.'とする)
	void input(){
		cin>>h>>w;
		s=vector<vector<char>>(h+2, vector<char>(w+2, '#'));
		flag=vector<vector<bool>>(h+2, vector<bool>(w+2, false));

		for(int i=1; i<h+1; i++){
			for(int j=1; j<w+1; j++) cin>>s[i][j];
		}
	}

	//幅優先探索(ただし，グリッドの座標(i, j)はi*(w+2)+jで表す)
	int BFS()
	{
		queue<pair<int, int>> que;

		//(1, 1)からスタート
		que.push(make_pair(w+3, 0));
		flag[1][1]=true;

		pair<int, int> p;

		while(!que.empty()){
			p=que.front(); que.pop();
			int pos=p.first, cost=p.second;
			int y=pos/(w+2), x=pos%(w+2);

			if(y==h&&x==w) return cost;
			if(s[y-1][x]=='.'&&!flag[y-1][x]){
				que.push(make_pair((y-1)*(w+2)+x, cost+1));
				flag[y-1][x]=true;
			}
			if(s[y+1][x]=='.'&&!flag[y+1][x]){
				que.push(make_pair((y+1)*(w+2)+x, cost+1));
				flag[y+1][x]=true;
			}
			if(s[y][x-1]=='.'&&!flag[y][x-1]){
				que.push(make_pair(y*(w+2)+x-1, cost+1));
				flag[y][x-1]=true;
			}
			if(s[y][x+1]=='.'&&!flag[y][x+1]){
				que.push(make_pair(y*(w+2)+x+1, cost+1));
				flag[y][x+1]=true;
			}
		}
		return -1;
	}

	int count(){
		int ans=0;
		rep(i, h+2){
			rep(j, w+2){
				if(s[i][j]=='.') ans++;
			}
		}
		return ans;
	}


};
int main(void)
{
	Grid g;

	g.input();

	int ans=g.BFS();

	if(ans!=-1){
		cout<<g.count()-ans-1<<endl;
	}else{
		cout<<-1<<endl;
	}
}


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


int main() {

    int n, k;
    cin >> n >> k;
    int ans = 1;
    for (int i = 0; i < n; ++i) {
        if (2 * ans > ans + k) ans += k;
        else ans *= 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import*
I=9**9
(h,w),(s,t),(f,g)=eval('map(int,input().split()),'*3)
m=[input()for _ in range(h)]
d=[w*[I]for _ in m]
q=deque([(s-1,t-1,1)])
while q:
  y,x,c=q.popleft()
  if d[y][x]<I:continue
  d[y][x]=c
  for i in range(y-2,y+3):
    for j in range(x-2,x+3):
      if h>i>-1<j<w<I==d[i][j]!=m[i][j]>'#':
        if abs(y-i)+abs(x-j)<2:q.appendleft((i,j,c))
        else:q.append((i,j,c+1))
print(d[f-1][g-1]%I-1)

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

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i = 0; i < n; i++) cin >> d[i];
  set<int> quantity;
  for(int i = 0; i < n; i++){
    quantity.insert(d[i]);
  }
  cout << quantity.size() << endl;
  return 0;
}

Measured memory_bytes: 3600
x,k,d=map(int,input().split())
x=abs(x)
if d*k<x:
    exit(print(x-d*k))
l=0
r=k
while r-l>1:
    m=l+r>>1
    if d*m>=x:
        r=m
    else:
        l=m
if(k-r)%2:
    print(min(abs(d*~-r-x),abs(d*-~r-x)))
else:
    a=d*r-x
    if r<k:
        a=min(a,abs(d*(r-2)-x),abs(d*(r+2)-x))
    print(a)

Measured memory_bytes: 61872
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		int[][] grid = new int[h][w];
		int nowH = 0;
		int nowW = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < arr[i]; j++) {
				grid[nowH][nowW] = i + 1;
				if (nowH % 2 == 0) {
					if (nowW == w - 1) {
						nowH++;
					} else {
						nowW++;
					}
				} else {
					if (nowW == 0) {
						nowH++;
					} else {
						nowW--;
					}
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (j != 0) {
					sb.append(" ");
				}
				sb.append(grid[i][j]);
			}
			sb.append("\n");
		}
		System.out.print(sb);
	}
}


Measured memory_bytes: 33304
#include <stdio.h>

int main(int argc, char** argv)
{
	int i, max, num[10010];
	i = 0;
	while (1) {
		scanf("%d", &num[i]);

		if (num[i] == 0) {
			break;
		}
		i++;
	}

	max = i;
	for (i = 0; i < max; i++) {
		printf("Case %d: %d\n", i+1, num[i]);
	}
	return 0;
}

Measured memory_bytes: 640