akhauriyash/Code-Regression huggingface dataset:
# https://atcoder.jp/contests/abc165/tasks/abc165_c
# C - Many Requirements
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m, q = map(int, input().split())
    ABCD = [list(map(int, input().split())) for _ in range(q)]

    # 数列Aのスコアを返す
    def calc_score(L):
        score = 0
        for a, b, c, d in ABCD:
            if L[b - 1] - L[a - 1] == c:
                score += d
        return score

    # 数列Aを全パターン試す
    def dfs(A):
        if len(A) == n:
            return calc_score(A)

        res = 0
        prev = A[-1] if len(A) > 0 else 1
        for v in range(prev, m + 1):
            A.append(v)
            res = max(res, dfs(A))
            A.pop()

        return res

    print(dfs([]))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9276
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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;
}

int main(void) {
    ll A, B, N;
    cin >> A >> B >> N;

    ll x = min(N, B - 1);
    cout << ((A * x) / B) - (A * (x / B)) << endl;

    return 0;
}


Measured memory_bytes: 3600
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI=3.14159265358979323846;

typedef priority_queue<int, vector<int>, greater<int>> priority_queue_asc;

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

    int sum = 0;
    int maxL = 0;
    vector<int> L(N);
    for (int i = 0; i < N; i++) {
        cin >> L[i];
        sum += L[i];
        maxL = max(L[i], maxL);
    }

    if (maxL < (sum - maxL)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3108
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void rollN(int[] dice) {
		int oki;
		oki = dice[0];
		dice[0] = dice[1];
		dice[1] = dice[5];
		dice[5] = dice[4];
		dice[4] = oki;
	}

	public static void rollE(int[] dice) {
		int oki;
		oki = dice[0];
		dice[0] = dice[3];
		dice[3] = dice[5];
		dice[5] = dice[2];
		dice[2] = oki;
	}

	public static void turn(int[] dice) {
		int oki;
		oki = dice[1];
		dice[1] = dice[3];
		dice[3] = dice[4];
		dice[4] = dice[2];
		dice[2] = oki;
	}

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int[] dice1 = { scanner.nextInt(), scanner.nextInt(), scanner.nextInt(), scanner.nextInt(), scanner.nextInt(),
				scanner.nextInt() };
		int[] dice2 = { scanner.nextInt(), scanner.nextInt(), scanner.nextInt(), scanner.nextInt(), scanner.nextInt(),
				scanner.nextInt() };
		boolean flag = false;
		if (Arrays.equals(dice1, dice2)) {
			flag = true;
		} else {
			for (int i = 0; i < 4; i++) {
				rollN(dice1);
				if (Arrays.equals(dice1, dice2)) {
					flag = true;
					break;
				} else {
					for (int j = 0; j < 4; j++) {
						turn(dice1);
						if (Arrays.equals(dice1, dice2)) {
							flag = true;
							break;
						}
					}
					if (flag) {
						break;
					}
				}
				rollE(dice1);
				if (Arrays.equals(dice1, dice2)) {
					flag = true;
					break;
				} else {
					for (int j = 0; j < 4; j++) {
						turn(dice1);
						if (Arrays.equals(dice1, dice2)) {
							flag = true;
							break;
						}
					}
					if (flag) {
						break;
					}		}
			}
		}
		if (flag) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}
}


Measured memory_bytes: 26232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

bool isPrime(int n){
    if(n == 1) return false;
    for(int i=2; i*i<=n; i++){
        if(n%i == 0) return false;
    }
    return true;
}

bool is2017(int n){
    if(n%2 == 0) return false;
    
    if(isPrime(n) && isPrime((n+1)/2)) return true;
    else return false;
}

int main(){
    vector<int> cum(100005, 0);
    for(int i=1; i<100005; i++){
        if(is2017(i)) cum[i] = cum[i-1]+1;
        else cum[i] = cum[i-1];
    }

    int Q; cin >> Q;
    vector<int> ans(Q);
    for(int i=0; i<Q; i++){
        int l, r; cin >> l >> r;
        ans[i] = cum[r]-cum[l-1];
    }

    for(auto e:ans) cout << e << endl;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int main()
{
    string S; cin>>S;
  int n=0, s=0, w=0, e=0;
  for(auto c:S){
    if(c=='N') n++;
    else if(c=='S') s++;
    else if(c=='W') w++;
    else e++;
  }
  if((n==0 && s>0) || (n>0 && s==0) || (w==0 && e>0) || (w>0 && e==0)) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO.Pipes;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Numerics;

namespace cswork
{
    class Program
    {
        class Scanner
        {
            string[] s;
            int i;

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

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

            public string next()
            {
                if (i < s.Length) return s[i++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();

                s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
                i = 0;
                return next();
            }

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

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

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

        public Program() { }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }

        void Omame()
        {
            cin = new Scanner();
            long N = cin.nextLong();
            List<long> list = new List<long>();
            for (int i = 0; i < N; i++)
            {
                long x = cin.nextLong();
                list.Add(x);
                if(x == 0)
                {
                    Console.WriteLine(0);
                    return;
                }
            }

            BigInteger ans = new BigInteger(decimal.One);
            for (int i = 0; i < N; i++)
            {
                ans *= list[i];
                if (ans > 1000000000000000000)
                {
                    Console.WriteLine(-1);
                    return;
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 42408
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
vector<int> ch1[2][110000];
int par1[2][110000];
int root[2];

int rep[2][110000];

//int par2[2][110000];
//vector<int> ch2[2][110000];

vector<int> edges[110000];

int m2[110000];
int vis[110000];

/*void fixtree(int z, int a){
	for(int j = 0; j < ch1[z][a].size(); j++){
		if(m2[a] == 1) par2[z][ch1[z][a][j]] = a;
		if(m2[a] == 0) par2[z][ch1[z][a][j]] = par2[z][a];
		fixtree(z, ch1[z][a][j]);
	}
}*/

void findrep(int z, int a){
	for(int j = 0; j < ch1[z][a].size(); j++){
		findrep(z, ch1[z][a][j]);
	}
	if(m2[a] == 1){
		rep[z][a] = a;
	} else {
		int f = ch1[z][a][ch1[z][a].size()-1];
		rep[z][a] = rep[z][f];
	}
}

void dfs(int a, int c){
	if(vis[a]) return;
	vis[a] = 1;
	m2[a] = c;
	for(int j = 0; j < edges[a].size(); j++){
		dfs(edges[a][j], -c);
	}
}


int main(){
	int n;
	cin >> n;
	for(int z = 0; z < 2; z++){
		for(int i = 0; i < n; i++){
			vis[i] = 0;
			int p;
			cin >> p;
			if(p >= 1) p--;
			par1[z][i] = p;
			if(p != -1){
				ch1[z][p].push_back(i);
			} else {
				root[z] = i;
			}
		}
	}
	for(int i = 0; i < n; i++){
		if((ch1[0][i].size() % 2) != (ch1[1][i].size() % 2)){
			cout << "IMPOSSIBLE" << endl;
			return 0;
		}
		m2[i] = 1 - (ch1[0][i].size() % 2);
	}

	/*par2[0][root[0]] = par1[0][root[0]];
	par2[1][root[1]] = par1[1][root[1]];
	fixtree(0,root[0]);
	fixtree(1,root[1]);

	for(int z = 0; z < 2; z++){
		for(int i = 0; i < n; i++){
			if(par2[z][i] != -1){
				ch2[z][par2[z][i]].push_back(i);
			} else {
				if(m2[i] != 0) ch2[z][n].push_back(i);
			}
		}
	}*/

	findrep(0,root[0]);
	findrep(1,root[1]);

	for(int z = 0; z < 2; z++){
		for(int i = 0; i <= n; i++){
			if(i < n){
			}
			for(int j = 0; j+1 < ch1[z][i].size(); j += 2){
				int a = ch1[z][i][j];
				int b = ch1[z][i][j+1];
				int r = rep[z][a];
				int s = rep[z][b];
				edges[r].push_back(s);
				edges[s].push_back(r);
				//cout << r << " " << s << endl;
			}
		}
	}

	for(int c = 0; c < n; c++){
		dfs(c, m2[c]);
	}
	cout << "POSSIBLE" << endl;
	for(int i = 0; i < n; i++){
		cout << m2[i] << " ";
	}
	cout << endl;
}


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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

const int mxn = 1005 * 3, inf = 1e9 + 7;
const int dx[] = { -1, 1, 0, 0 }, dy[] = { 0, 0, -1, 1 };

int n, m;
int ro[mxn][mxn], co[mxn][mxn];
int a[mxn], b[mxn], c[mxn], d[mxn], e[mxn], f[mxn];
int vx[mxn], xsz, vy[mxn], ysz;
bool ban[mxn][mxn][4], vis[mxn][mxn];
int que[mxn * mxn * 2], ql, qr;

int main() {
	scanf("%d %d", &n, &m);
	vx[xsz ++] = -inf, vx[xsz ++] = inf, vx[xsz ++] = 0;
	vy[ysz ++] = -inf, vy[ysz ++] = inf, vy[ysz ++] = 0;
	rep(i, n) scanf("%d %d %d", &a[i], &b[i], &c[i]), vx[xsz ++] = a[i], vx[xsz ++] = b[i], vy[ysz ++] = c[i];
	rep(i, m) scanf("%d %d %d", &d[i], &e[i], &f[i]), vx[xsz ++] = d[i], vy[ysz ++] = e[i], vy[ysz ++] = f[i];
	sort(vx, vx + xsz); xsz = unique(vx, vx + xsz) - vx; sort(vy, vy + ysz), ysz = unique(vy, vy + ysz) - vy;
	rep(i, n) {
		a[i] = lower_bound(vx, vx + xsz, a[i]) - vx;
		b[i] = lower_bound(vx, vx + xsz, b[i]) - vx;
		c[i] = lower_bound(vy, vy + ysz, c[i]) - vy;
		co[a[i]][c[i]] ++, co[b[i]][c[i]] --;
	}
	rep(i, m) {
		d[i] = lower_bound(vx, vx + xsz, d[i]) - vx;
		e[i] = lower_bound(vy, vy + ysz, e[i]) - vy;
		f[i] = lower_bound(vy, vy + ysz, f[i]) - vy;
		ro[d[i]][e[i]] ++, ro[d[i]][f[i]] --;
	}
	rep(i, xsz) rep(j, ysz) {
		if (i) co[i][j] += co[i - 1][j];
		if (j) ro[i][j] += ro[i][j - 1];
	}
	rep(i, xsz) rep(j, ysz) {
		ban[i][j][0] = ro[i][j] > 0;
		ban[i][j][1] = ro[i + 1][j] > 0;
		ban[i][j][2] = co[i][j] > 0;
		ban[i][j][3] = co[i][j + 1] > 0;
	}
	int sx = lower_bound(vx, vx + xsz, 0) - vx;
	int sy = lower_bound(vy, vy + ysz, 0) - vy;
	ll ans = 0;
	vis[sx][sy] = 1, que[qr ++] = sx, que[qr ++] = sy;
	while (ql < qr) {
		int x = que[ql ++], y = que[ql ++];
		if (x == 0 || x + 1 == xsz - 1 || y == 0 || y + 1 == ysz - 1) { puts("INF"); return 0; }
		ans += 1LL * (vx[x + 1] - vx[x]) * (vy[y + 1] - vy[y]);
		rep(d, 4) if (!ban[x][y][d]) {
			int nx = x + dx[d], ny = y + dy[d];
			if (nx < 0 || ny < 0 || nx >= xsz - 1 || ny >= ysz - 1 || vis[nx][ny]) continue;
			vis[nx][ny] = 1, que[qr ++] = nx, que[qr ++] = ny;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
#define MAX 2000000000
#define PI 3.1415926535897932
using ll = long long;
using Graph = vector<vector<int>>;
//二項係数を求める。

int main(){
  int a,b;cin>>a>>b;
  if(a>2*b)cout<<a-2*b<<endl;
  else cout<<0<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int f1(int _n){
	if(_n >= 100000){
    	return f1(99999);
    }else if(_n >= 10000){
    	return (_n - 10000 +1) + f1(999);
    }else if(_n >= 1000){
    	return f1(999);
    }else if(_n >= 100){
    	return (_n - 100 +1) + f1(9);
    }else if(_n >= 10){
    	return f1(9);
    }else{
    	return _n;
    }
}

int main (void)
{
    int n;
    scanf("%d", &n);
    printf("%d\n", f1(n));
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    if((b+1) - a <= 2*k) {
        exrep(i, a, b) {
            out(i);
        }
    }
    else {
        exrep(i, a, a+k-1) {
            out(i);
        }
        exrep(i, b-k+1, b) {
            out(i);
        }
    }

    re0;
}

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

int main()
{
  int64_t K, N;
  cin >> K >> N;
  vector<int64_t> A(N);
  for (int64_t i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  int64_t ans = K, tmp;
  for (int i = 0; i < N; i++)
  {
    if (i == 0)
    {
      tmp = min(abs(A.at(0) - A.at(N - 1)), K - abs(A.at(0) - A.at(1)));
    }
    else if (i == N - 1)
    {
      tmp = min(abs(A.at(0) - A.at(N - 1)), K - abs(A.at(N - 1) - A.at(N - 2)));
    }
    else
    {
      tmp = min(K - abs(A.at(i) - A.at(i - 1)), K - abs(A.at(i) - A.at(i + 1)));
    }
    ans = min(tmp, ans);
  }
  cout << ans << endl;
}

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

using namespace std;

char str[21];

int main(){
  scanf("%s",str);
  for (int i=0,l=strlen(str);i<l/2;i++){
    swap(str[i],str[l-i-1]);
  }
  printf("%s\n",str);
  return 0;
}

Measured memory_bytes: 1108
import numpy as np
import sys

input = sys.stdin.readline

s = input()
t = input()

x = sorted(s)[1:]
y = sorted(t,reverse=True)[:len(t)-1]

#print(x[:len(x)])
#print(y[:len(x)])
if x[0] < y[0]:
    print("Yes")
    exit()
else:
    if len(x) < len(y) and (x[:len(x)] == y[:len(x)]) :
        print("Yes")
        exit()
    else:
        print("No")




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

using namespace std;

int main(void) {
        int N;
        int M;
        int x;

        int sum = 0;

        scanf("%d", &N);
        scanf("%d", &M);

        for(int i=0; i<M; i++) {
                scanf("%d", &x);
                sum +=x;
        }

        if(N-sum < 0) {
                printf("-1\n");
        } else {
                printf("%d\n", N-sum);
        }

        return 0;
}


Measured memory_bytes: 3760
import java.util.Scanner;

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

		int n=sc.nextInt();
		int k=sc.nextInt();

	int ans=0;
	for(int i=0;i<n;i++){
		if(k<=sc.nextInt()){
			ans++;
		}
	}
	System.out.println(ans);
	}}

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

using namespace std;

struct Edge
{
  long long to, cost;
};

void dijkstra(vector<Edge> edge[], int n, int s, vector<long long> &far)
{
  priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;
  far[s] = 0;
  pq.push({0, s});
  while (pq.size())
  {
    pair<long long, int> p = pq.top();
    pq.pop();
    cerr << " " << p.second << " " << p.first << endl;
    for (Edge t : edge[p.second])
      if (far[p.second] + t.cost < far[t.to])
      {
        far[t.to] = far[p.second] + t.cost;
        pq.push({far[t.to], t.to});
      }
  }
}

int main()
{
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  vector<Edge> edgeY[n], edgeS[n];
  for (int i = 0; i < m; i++)
  {
    long long u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    edgeY[u].push_back({v, a});
    edgeY[v].push_back({u, a});
    edgeS[u].push_back({v, b});
    edgeS[v].push_back({u, b});
  }
  vector<long long> costY(n, 1e18), costS(n, 1e18);
  dijkstra(edgeY, n, s - 1, costY);
  dijkstra(edgeS, n, t - 1, costS);
  vector<pair<long long, int>> cost(n);
  for (int i = 0; i < n; i++)
    cost[i] = {costY[i] + costS[i], i + 1};
  sort(cost.begin(), cost.end());
  int index = 0;
  for (int i = 0; i < n; i++)
  {
    while (cost[index].second <= i)
      index++;
    cout << (long long)1e15 - cost[index].first << endl;
  }

  return 0;
}


Measured memory_bytes: 19836
import java.util.Scanner;
     
class Main{
    public static void main(String arg[]) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        sc.nextLine();
		
		String[] str = new String[H];
		String[][] S = new String[H][W];
		
		for(int i = 0; i < H; i++ ) {
			str[i]= sc.nextLine(); 
		}
        sc.close();
        
        for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				String ss[] = str[i].split("");
				S[i][j] = ss[j];
			}
		}
        
        for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
                if(S[i][j].equals("#")){
                    if(painting(i,j,S)==true){
                        continue;
                    }else{
                        System.out.println("No");
                        System.exit(0);
                    }
                }
			    
			}
        }
        System.out.println("Yes");
    }
    public static boolean painting(int h, int w, String[][] S){
        boolean isOK = false;
        if( h-1 >= 0 && S[h-1][w].equals("#") ) {
			isOK =true;
		}else if(h+1 < S.length && S[h+1][w].equals("#")) {
			isOK = true;
		}else if(w-1 >= 0 && S[h][w-1].equals("#")) {
			isOK = true;
		}else if(w+1 < S[0].length && S[h][w+1].equals("#")) {
			isOK = true;
		}
        return isOK;
    }
}

Measured memory_bytes: 33364
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  int n, q;
  cin >> n >> q;
  queue<pair<string, ll> > qu;
  rep(i, n){
    string s;
    ll t;
    cin >> s >> t;
    qu.push(mk(s, t));
  }
  ll T = 0;
  while(!qu.empty()){
    pair<string, ll> p = qu.front(); qu.pop();
    if(p.second <= q){
      T += p.second;
      cout << p.first << " " << T << endl;
    }else{
      T += q;
      qu.push(mk(p.first, p.second - q));
    }
  }
	return 0;
}



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

using namespace std;

int main() {
  int a, b, c, k;
  cin >> a >> b >> c;
  cin >> k;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k - i; j++) {
      int l = k - i - j;
      if (a * pow(2, i) < b * pow(2, j) && b * pow(2, j) < c * pow(2, l)) {
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
  return 0;
}


Measured memory_bytes: 3896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main()
{
    INIT;
    ull x;
    ll count = 0;
    cin >> x;
    ll ryoukin = 100;
    while(true){
        if(ryoukin >= x) break;
        count++;
        ryoukin = 1.01 * ryoukin; 
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3668
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  rep(i,N){
    cin >> vec.at(i);
  }
  int sum = 0;
  for(int i = 0;i < N-1;i++){
    for(int j = i+1;j < N;j++){
      sum = sum + vec.at(i)*vec.at(j);
    }
  }
  cout << sum <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int N;
int dp[105][10][10][10];

const int A = 0, G = 1, C = 2, T = 3;

int main() {
	cin>>N;

	//初期条件
	dp[0][T][T][T] = 1;
	rep(len,N){
		//後ろから3文字目
		rep(i,4){
			//後ろから2文字目
			rep(j,4){
				//後ろから1文字目
				rep(k,4){

					//前の状態で0だったらもうすでにダメだった配列なので抜ける
					if(dp[len][i][j][k] == 0)continue;
					//次の文字を考えたときに
					rep(next,4){
						//次に加える文字がnextのときダメな条件5個を列挙
						if(j == A && k == G && next == C)continue;
						if(j == A && k == C && next == G)continue;
						if(j == G && k == A && next == C)continue;
						if(i == A && k == G && next == C)continue;
						if(i == A && j == G && next == C)continue;

						dp[len+1][j][k][next] += dp[len][i][j][k];
						dp[len+1][j][k][next] %=MOD;
					}
				}
			}
		}
	}
	int ans =0;
	rep(i,4)rep(j,4)rep(k,4){
		ans += dp[N][i][j][k];
		ans %= MOD;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
import java.util.*; 
import java.io.*; 

public class Main {
	public static void main(String[] args) throws IOException {
       Scanner sc = new Scanner(System.in);
       int n = sc.nextInt(); 
       int arr[] = new int[n]; 
       
       for(int i = 0; i<n; i++) {
    	   arr[i] = sc.nextInt();
    	   if(arr[i] % 2 == 0 && arr[i] % 3 != 0 && arr[i] % 5 != 0) {
    		   System.out.println("DENIED"); 
    		   return ; 
    	   }
       }
      System.out.println("APPROVED");        
	}
}

Measured memory_bytes: 23764
(defun maximum (list)
  (reduce #'max list))

(defun filter (fn lst)
  (let ((acc nil))
    (dolist (x lst)
      (let ((val (funcall fn x)))
        (if val (push val acc))))
    (nreverse acc)))

(defun power-set (ls)
  (if (null ls)
    (list nil)
    (append (power-set (cdr ls))
            (mapcar #'(lambda (xs) (cons (car ls) xs))
                    (power-set (cdr ls))))))

(defun combination (n ls)
  (labels ((comb-sub (n ls)
                     (cond ((zerop n) (list nil))
                           ((= n (length ls)) (list ls))
                           (t
                             (append (mapcar #'(lambda (x) (cons (car ls) x))
                                             (comb-sub (1- n) (cdr ls)))
                                     (comb-sub n (cdr ls)))))))
    (if (< (length ls) n)
      nil
      (comb-sub n ls))))

(defun main()
  (let ((N (read)))
    ; (princ N)
    (loop :for i :from 1 :do
          (if (> (* i i) N) (progn (format t "~D~%" (* (1- i) (1- i))) (return)) nil))
    )
)
(main)

Measured memory_bytes: 15456
#include<iostream>
#define R(i,n)for(int i=0;i<=n;i++)
using namespace std;int a,H,W,A,c[10][10];main(){cin>>H>>W;R(i,9)R(j,9)cin>>c[i][j];R(k,9)R(i,9)R(j,9)c[i][j]=min(c[i][j],c[i][k]+c[k][j]);R(i,H-1)R(j,W-1){cin>>A;a+=c[A>=0?A:1][1];}cout<<a;}

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

int main(){
    int N;
    cin >> N;
    int p[N];
    for(int i=0; i<N; i++){
        cin >> p[i];
    }

    int minj=p[0];
    int count =1;

    for(int i=1; i<N; i++){
        if( minj > p[i] ){
            count++;
        }
        if( i<N-1 && minj > p[i] ){
            minj = p[i];
        }
    }

    cout << count << endl;

    return 0;
}

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

int main() {
    vector<vector<int>> data(4,vector<int>(13,0));
    int n, x;
    char ch;
    scanf("%d",&n);
    for(int i=0; i<n; i++){
        scanf("%c",&ch);
        scanf("%c %d",&ch ,&x);
        if(ch == 'S') data.at(0).at(x-1)=1;
        else if(ch == 'H') data.at(1).at(x-1)=1;
        else if(ch == 'C') data.at(2).at(x-1)=1;
        else data.at(3).at(x-1)=1;
    }
    for(int i=0; i<data.size(); i++){
        for(int j=0; j<data.at(0).size(); j++){
            if(data.at(i).at(j) == 0){
                switch (i){
                    case 0: 
                            cout << "S " << j+1 << endl;
                            break;
                    case 1: 
                            cout << "H "  << j+1 << endl;
                            break;
                    case 2: 
                            cout << "C " << j+1 << endl;
                            break;
                    case 3:
                            cout << "D " << j+1 << endl; 
                }
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int n;cin >> n;
	int x = 800*n;
	int y = 200*(n/15);
	cout << x- y << endl;

	return 0;
}

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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll solve(int N, const vector<ll>& xs)
{
    return 0;
}

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

    int N, M;
    cin >> N >> M;

    cout << N*(N - 1)/2 + M*(M - 1)/2 << '\n';

    return 0;
}


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

#define File freopen("in.txt","r",stdin);
#define ll long long

const int mINF = 0x80000000;
const int INF = 0x3f3f3f3f;
const int maxn = 100000 + 10;
int a[] = {8, 5, 2, 10, 7, 4, 1, 9, 6, 3, 0};
int cnt[20];
int b[] = {7, 5, 3, 1, 10};


int main()
{
    ll n, k;
    cin >> n >> k;
    ll mod = n % 11;
    ll times = n / 11;
//    cout << n << "   " << mod << " " << times << endl;
    for(int i = 0; i < 11 ; i++) {
        cnt[i] = times;
        if(mod >= i + 1) {
            cnt[i]++;
        }
    }
    ll last1,last2,last3;
    last1 = (n*63)%11; last2 = ((n-1)*63)%11;
    for(int i=0; i<11; i++){
      if(a[i] == last1 || a[i] == last2 ){
        cnt[i]--;
      }
    }
    ll ans = 0;
    for(int i = 0; i < 5; i++) {
        for(int j = 0; j < 11; j++) {
            if((a[j] + b [i]) % 11 == k ) {
//              if(cnt[j] != 0)
//                cout<<i<<" "<<j<<endl;
                    ans += cnt[j];
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

n = int(input())
Sn = [input() for i in range(n)]

# 各文字列が含むアルファベットを集計
az_list = []
for i in range(n):
    s_list = list(Sn[i])
    az_dict = {}
    for c in s_list:
        if c not in az_dict:
            az_dict[c] = 1
        else:
            az_dict[c] += 1
    az_list.append(az_dict)

# 集計結果から、全ての文字列が共通で持っているアルファベットとその数を出す
sum_dict = {}
for i in range(97, 97+26):
    c = chr(i)
    for j in range(len(az_list)):  
        if c not in az_list[j]:
            sum_dict[c] = 0
            break
        else:
            if j == 0:
                sum_dict[c] = az_list[j][c]
            else:
                sum_dict[c] = min(sum_dict[c], az_list[j][c])

# 辞書順で解答となる文字列を作っていく
ans = ""
for i in range(97, 97+26):
    c = chr(i)
    if c in sum_dict:
        for j in range(sum_dict[c]):
            ans += c

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
#define all(v) v.begin(), v.end()
const int INF = 1 << 30;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    int n,m;
    cin >> n >> m;
    vector<vector<int>> graph(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        graph[a-1].push_back(b-1);
        graph[b-1].push_back(a-1);
    }
    int res = 0;
    vector<int> route;
    rep(i,n)route.push_back(i);
    do{
        if(route.front() != 0)continue;
        int pos = 0;
        bool can = true;
        for(int i = 1;i < n;i++){
            if(find(all(graph[route[i]]),pos) != graph[route[i]].end()){
                pos = route[i];
            }else{
                can = false;
                break;
            }
        }
        if(can)res++;
    }while(next_permutation(all(route)));
    cout << res <<"\n";
    return 0;
}

Measured memory_bytes: 3600
n,m=map(int, input().split())
lamp=[]
for i in range(m):
    lamp.append(list(map(int, input().split())))
p=list(map(int, input().split()))

ans=0

for i in range(2**n):
    All_On=True
    for j in range(m):
        k_on=0
        for k in range(1,lamp[j][0]+1):
            if i>>lamp[j][k]-1 & 1:
                k_on+=1
        if k_on%2!=p[j]:
            All_On=False
            break
    if All_On:
        ans+=1
print(ans)

Measured memory_bytes: 70564
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const int MOD2=15000007;
const ll MAX=9187201950435737471;
const int N=100005;
const int INF=1e17;
const long double PI=acos(-1);



void solve(int T){
    int k,n;
    cin>>k>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]%=k;
    }
    int ans=min(a[n-1]-a[0],a[0]+(k-a[1]));
    //cout<<ans<<"\n";
    int j=0;
    for(int i=1;i<n-1;i++){
        ans=min(ans,min(a[j]+(k-a[i]),a[i]+(k-a[i+1])));
        //cout<<ans<<" "<<j<<"\n";
        j++;
    }
    cout<<ans<<"\n";
}

int main() {
    fastio
    int T=1;
    //cin>>T;
    for(int i=1;i<=T;i++){
        solve(i);
        //if(i<T)cout<<"\n";
    }
    return 0;
}





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

long long abc (int x, int y) {
  return (x - y) * (x - y);  
}

int main () {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];  
  }  
  sort(a.begin(), a.end());
  long long ans = -1;
  long long sub = 0;
  for (int i = a[0]; i <= a[a.size() - 1]; i++) {
    for (int j = 0; j < N; j++) {
      if (j == 0) {
        sub = 0;    
      }
      // 全てをiにする 
      sub = sub + abc(i, a[j]);
      if (j == N - 1) {
        if (sub < ans || ans == -1) {
          ans = sub;  
        }  
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//I am a  noo0o0o0o0o0o0o0o00oOb
#include <bits/stdc++.h>
#include <cmath>
 
using namespace std;
 
typedef long long ll;
#define pi   acos(-1) 
#define endl "\n"
const int mod = 1000000007; 

int main()
{
	int a;
	cin >> a ;
	if ( a % 2 == 0){
		cout << a / 2  << endl;
	}
	else 
		cout << (a /2) + 1 << endl;
		
    return 0;
}

Measured memory_bytes: 3612
import sys

A = list(map(int, input().split()))
A1 =  list(map(int, input().split()))
A2 =  list(map(int, input().split()))

bingo_lis = A + A1 + A2




N = int(input())
b = []
for _ in range(N):
    b.append(int(input()))  # S += [input()] とも書ける


lis=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[2,4,6],[0,4,8]]


for i in range(len(lis)):
    tmp_lis = lis[i]
    ans = 0
    for j in tmp_lis:
        if bingo_lis[j] in b:
            ans = ans + 1
    if ans == 3:
        print("Yes")
        sys.exit()
print("No")

Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {
 int a,b,c,d=0;
 scanf("%d %d %d",&a,&b,&c);
 for(a;a<b+1;a++){
   if(c%a==0)
   d++;}
   printf("%d\n",d);
 return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <vector>

using namespace std;

int main()
{
  int N;
  cin >> N;
  
  vector<int> t(N+1), x(N+1), y(N+1);
  for (int i = 1; i <= N; i++) {
    cin >> t[i] >> x[i] >> y[i];
  }
  
  for (int i = 1; i <= N; i++) {
    int dist = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
    if (t[i] - t[i-1] >= dist && (t[i] - t[i - 1])%2 == dist%2) {
    	;
    } else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  
  return 0;
}

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

int power2(long long a){
    int cnt=0;
    while(a%2==0){
        a/=2;
        cnt++;
    }
    return cnt;
}


int main(){
    int n;
    cin >> n;
    long long a[n];

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

    int ans=0;

    for(int i=0;i<n;i++){
        ans += power2(a[i]);
    }

    cout << ans << endl;
}



Measured memory_bytes: 3672
# -*- coding: utf-8 -*-
N=input()
T=list(map(int,input().split()))
M=int(input())
go=[]
for c in range(M):
    P,X=map(int,input().split())
    place=P-1
    result=T[place]
    Result=result-X
    ans=sum(T)-Result
    go.append(ans)
for Ans in go:
    print(Ans)


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

int main()
{
   
    double m,n,s=0.0,c=0.0,v;
    long long int i;
   
    cin>>n>>m;
     vector<double> a;
    for(i=0;i<n;i++)
    {
    cin>>v;
    a.push_back(v);
    s+=v;
    }
    double t=s/(4*m);
    for(i=0;i<n;i++)
    {
        if(a[i]>=t)
        c++;
    }
    if(c>=m)
    cout<<"Yes";
    else
    cout<<"No";
    return 0;
}


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

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000001
using namespace std;
typedef long long ll;

int n,k;
int x[100100];

int main(int argc, char const *argv[]) {

  std::cin >> n >> k;
  rep(i,1,n+1){
    std::cin >> x[i];
  }
  int res = MAX;
  rep(i,1,n-k+2){
    int left = abs(x[i]);
    left += abs(x[i+k-1] - x[i]);
    int right = abs(x[i+k-1]);
    right += abs(x[i] - x[i+k-1]);
    int tmp = min(left, right);
    res = min(res, tmp);
  }
  std::cout << res << '\n';
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

int n;
ll ans;
map<PII,int> hs;
int main() {
	scanf("%d",&n);
	rep(i,0,n) {
		double x;
		scanf("%lf",&x);
		ll p=(ll)(x*1000000000+0.1);
		ll q=1000000000;
		ll d=gcd(p,q);
		p/=d; q/=d;
		int c2=0,c5=0;
		while (p%5==0) c5++,p/=5;
		while (p%2==0) c2++,p/=2;
		while (q%5==0) c5--,q/=5;
		while (q%2==0) c2--,q/=2;
		hs[mp(c2,c5)]++;
	}
	for (auto p1:hs) for (auto p2:hs) {
		if (p1.fi.fi+p2.fi.fi<0||p1.fi.se+p2.fi.se<0) continue;
		if (p1.fi==p2.fi) {
			ans+=(ll)(p1.se-1)*(p1.se)/2;
		} else if (p1.fi<p2.fi) ans+=(ll)p1.se*p2.se;
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 3784
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif

	int c=0,z,p=0;
    char a[100];
    gets(a);
    z=strlen(a);
    for (int i = 0; i < z; ++i)
    {
    	if(a[i]=='R'&&a[i+1]=='R')
    		c++;
    	if(a[i]=='R'&&a[i+1]!='R')
    		p++;
    }
    if(c>0)
    	printf("%d\n",c+1 );
    else if(p>0)
    	printf("1\n");
    else
    	printf("0\n");


    
}

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

const int mod = 1e9 + 7;

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

/*-------------------------------------------*/

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i], a[i]--;
    int ans = 0;
    rep(i, n) if(a[a[i]] == i) ans++;
    cout << ans / 2 << endl;
}

Measured memory_bytes: 640
import heapq

N, M =map(int, input().split())
A = list(map(int, input().split()))
A.sort()
reversed_A = [n * (-1) for n in A]
heapq.heapify(reversed_A)
for i in range(M):
    max_value = heapq.heappop(reversed_A) * (-1)
    half_value = max_value // 2
    heapq.heappush(reversed_A, (-1)*half_value)

discount_prices = [n * (-1) for n in reversed_A]
ans = sum(discount_prices)
print(ans)

Measured memory_bytes: 15044
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,gram;
    cin>>n>>gram;
    int weight[100009];
    for(int i=0;i<n;i++)
    {
        cin>>weight[i];
    }
    sort(weight,weight+n);
    int totalwight=0,Count=0;
    for(int i=0;i<n;i++)
    {
        totalwight+=weight[i];
        if(totalwight<gram)
        {
            Count++;
        }
        else
        {
            totalwight-=weight[i];
                break;
        }

    }
    //cout<<Count<<"*"<<endl;
    int m;
    if(totalwight<gram)
    {
         m=(gram-totalwight)/weight[0];
         Count=Count+m;
    }

    cout<<Count<<endl;
}


Measured memory_bytes: 256
// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int T = 1; 
    // cin >> T; 
    while (T--) {
        int n, m;
        cin >> n >> m;

        int ans = n * (n - 1) / 2 + m * (m - 1) / 2;
        cout << ans << '\n';
        
    }
    
    return 0;
}



Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, Y;
    cin >> X >> Y;
    if (X % Y == 0) {
        cout << "-1" << endl;
    } else {
        cout << X << endl;
    }


    return 0;
}


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



int main() {
   long long n,cnt=0;
   cin >> n;
   map<string,int> s;
   for(int i=0;i<n;i++){
       string a;
       cin >> a;

       if(s[a] == 0) s[a] = -1;
       else if(s[a] =-1){
           cnt++;
       }
   }
   cout << n-cnt << endl;
   return 0;
}


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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using pint = pair<int, int>; 
using pll  = pair<ll, ll>;
using vint = vector<int>; 
using vll  = vector<ll>;
using vstr = vector<string>;

//　定数, 変数 *********************************************
const ll MOD=1e9+7;
const ll INF=1ll<<60;

int n,x,t;

// *********************************************************
int main(){

    cin >> n >> x >> t;

    if(n%x == 0){
        cout << n/x *t <<endl;
    }else{
        cout << n/x *t +t << endl;
    }


    return 0;
}

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

int main() 
{ 
    
    int n;
    cin>>n;
    vector<vector<int> > dp( n , vector<int> (3, 0)); 
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>dp[i][j];
        }
    }
    for(int i=1;i<n;i++){
        dp[i][0] = dp[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = dp[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] = dp[i][2]+max(dp[i-1][1],dp[i-1][0]);
    }
    
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
      
    return 0; 
} 

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

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

const int maxn = 505;
int n, m;
string s[maxn];
string red[maxn], blue[maxn];

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for(int i = 0;i < n;i++){
        cin >> s[i];
        red[i] = s[i];
        blue[i] = s[i];
        for(int j = 0;j < m;j++){
            red[i][j] = '.';
            blue[i][j] = '.';
        }
    }
    for(int i = 0;i < n;i++){
        red[i][0] = '#';
        blue[i][m - 1] = '#';
        if(i & 1){
            for(int j = 1;j < m - 1;j++){
                red[i][j] = '#';
                blue[i][j] = s[i][j];
            }
        }else{
            for(int j = 1;j < m - 1;j++){
                blue[i][j] = '#';
                red[i][j] = s[i][j];
            }
        }
    }
    for(int i = 0;i < n;i++){
        cout << red[i] << endl;
    }
    cout << endl;
    for(int i = 0;i < n;i++){
        cout << blue[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 1536
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"

using namespace std;
typedef long long ll;

int valuation2(int n)
{
  int ans = 0;
  while (true)
  {
    if (n % 2 == 0)
    {
      n /= 2;
      ans++;
    }
    else
    {
      break;
    }
  }
  return ans;
}

int main()
{
  int n;
  cin >> n;
  int sum0 = 0;
  int sum2 = 0;
  int a[100100];
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    if (valuation2(a[i]) < 1)
    {
      sum0++;
    }
    if (valuation2(a[i]) > 1)
    {
      sum2++;
    }
  }
  cout << (sum0 <= sum2 || (sum0 - sum2 == 1 && sum0 + sum2 == n) ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 640