akhauriyash/Code-Regression huggingface dataset:
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
        PEOPLE'S LIVES DON'T END WHEN THEY DIE.
        IT ENDS WHEN THEY LOSE FAITH
                                     -ITACHI UCHIHA
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
void solve()
{
   ll n,i;cin>>n;
   ll A[n];
   ll sum=0;
   map<ll,ll>M,N;
   fo(i,0,n)cin>>A[i],M[A[i]]++;
   
   N=M;
   for(auto a:M)
   {
       a.S=a.S*(a.S-1)/2;
       sum+=a.S;
   }
   
   fo(i,0,n)
   cout<<sum-(N[A[i]]-1)<<"\n";
   
}
int main()
{
   fastio
   solve();
  return 0;
}


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

ll MOD = 1000000007;

ll powMod(ll x, ll k) {
  if (k == 0) return 1;
  if (k % 2 == 0)
    return powMod(x * x % MOD, k / 2);
  else
    return x * powMod(x, k - 1) % MOD;
}

int main() {
  int N;
  cin >> N;
  vector<ll> A(N), B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }

  map<pair<ll, ll>, pair<int, int>> m;
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] == 0 && B[i] == 0) {
      cnt++;
    } else if (A[i] == 0) {
      m[{0, 1}].first++;
    } else if (B[i] == 0) {
      m[{0, 1}].second++;
    } else {
      ll g = __gcd(A[i], B[i]);
      A[i] /= g, B[i] /= g;
      if (B[i] < 0) {
        A[i] *= -1;
        B[i] *= -1;
      }
      if (A[i] > 0) {
        m[{A[i], B[i]}].first++;
      } else {
        m[{B[i], -A[i]}].second++;
      }
    }
  }

  ll ans = 1;
  for (auto a : m) {
    ll tmp = 1;
    tmp += powMod(2, a.second.first) - 1 + MOD;
    tmp %= MOD;
    tmp += powMod(2, a.second.second) - 1 + MOD;
    tmp %= MOD;
    ans *= tmp;
    ans %= MOD;
  }

  cout << (ans - 1 + cnt + MOD) % MOD << endl;
}

Measured memory_bytes: 18736
//#include <bits/stdc++.h>
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
#include <cctype>
#include <fstream>   // ifstream, ofstream
#include <sstream>   // istringstream
using namespace std;
using ll = long long;
const int mod = 1000000007;

ll gcd(ll a, ll b){return b ? gcd(b,a%b) : a;};//最大公約数
ll lcm(ll a, ll b){return a*b/gcd(a,b);};//最小公倍数
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
typedef pair<string,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
//ll a[100000];
//ll dom[100001];

int main(){
  string s;
  int a=0,b=0;
  cin>>s;
  for(int i=0;i<3;i++){
    if(s[i]=='A') a++;
    else b++;
  }
  if(a==3||b==3) cout<<"No";
  else cout<<"Yes";
  return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;
fn gcd(a: u64, b: u64) -> u64 { if b == 0 { a } else { gcd(b, a % b) } }
fn lcm(a: u64, b: u64) -> u64 { a * b / gcd(a, b) }

fn main() {
    let mut sc = Scanner::new();
    let a: u64 = sc.cin::<u64>() - 1;
    let b: u64 = sc.cin();
    let c: u64 = sc.cin();
    let d: u64 = sc.cin();
    put!(b-b/c-b/d+b/lcm(c,d)-a+a/c+a/d-a/lcm(c,d))
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#include <stdio.h>

int main () {
	
	int i, j, N, a[100], temp, minj, count;
	
	count = 0 ;
	
	scanf ("%d",&N) ;
	for ( i = 0 ; i < N ; i ++ ) {
		scanf("%d", &a[i] ) ;
	}
		
	for (i = 0 ; i < N ; i++ ) {
		minj =i ;
		for ( j = i ; j < N ; j++ ) {
			if ( a[j] < a[minj] ){
				minj = j ;
			}
		}
		
		temp =a[i] ;
		a[i] = a[minj] ;
		a[minj] = temp ;
		if ( minj !=  i ) {
			count++ ;
		}
	}
	
	for ( i = 0 ; i < N ; i ++ ) {
		printf("%d",a[i] ) ;
		if (i != N-1)
		printf(" ");
	}
	printf("\n") ;
    printf ("%d\n", count) ;

return 0;
}

Measured memory_bytes: 604
def main():
    import sys
    from fractions import gcd
    input = sys.stdin.readline

    
    def init():
        #set_val
        for i in range(n):
            seg[i+num-1]=a[i]    
        #built
        for i in range(num-2,-1,-1) :
            seg[i]=gcd(seg[2*i+1],seg[2*i+2]) 
    
    def update(k,z):
        k += num
        seg[k] = x
        while k+1:
            k = (k-1)//2
            date[k] = gcd(seg[k*2+1],seg[k*2+2])
    
    def query(p,q):
        if p>n-1 or q<1:
            return 0
        if abs(q-p)<=1:
            return a[p]
        p += num-1
        q += num-2
        res=0
        while q>p:
            if p&1 == 0:
                res = gcd(res,seg[p])
            if q&1 == 1:
                res = gcd(res,seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        res = gcd(res,seg[p])
        return res
 
    n = int(input())
    a = tuple(map(int,input().split()))

    #num:n以上の最小の2のべき乗
    num =2**(n-1).bit_length()
    seg=[0]*2*num
    
    init()
 
    ans = -1
    for i in range(n):
        ans = max(ans,gcd(query(0,i),query(i+1,n)))
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 88288
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;

//再帰関数による深さ優先探索
void dfs_visit(int u)
{
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for(v=0;v<n;v++){
    if(M[u][v] == 0) continue;
    if(color[v] == WHITE){
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

void dfs()
{
  int u;

  for(u=0;u<n;u++) color[u] = WHITE;
  tt = 0;

  for(u=0;u<n;u++) {
    if(color[u] == WHITE) dfs_visit(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

int main()
{
  int u,v,k,i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++) M[i][j] = 0;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  dfs();

  return 0;
}

  



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 30)
using namespace std;

const int kN = 1000005;

void primeNumber(bool prime[kN]){
    rep(i,kN) prime[i] = 1;
    prime[0] = prime[1] = 0;
    rep(i,kN){
        if(prime[i]){
            for(int j = i + i; j < kN; j+=i){
                prime[j] = 0;
            }
        }
    }
}

void primeOfCuisine(int n, int a[40], bool prime[kN]){
    prime[0] = 1;
    rep(i,n){
        rep(j,kN){
            if(prime[j] == 1){
                if(j + a[i] >= kN) continue;
                prime[j + a[i]] = 1;
            }
        }
    }
}

void outputAns(bool a[kN], bool b[kN], int x){
    for(int i = x; i >= 0; i--){
        if(a[i] == 1 && b[i] == 1){
            cout << i << endl;
            return;
        }
    }
    cout << "NA" << endl;
    return;
}

int main(){
    int n, x, a[40];
    while(cin >> n >> x, n||x){
        bool is_prime[kN] = {0};
        bool is_prime_of_cuisine[kN] = {0};
        rep(i,n) cin >> a[i];
        primeNumber(is_prime);
        primeOfCuisine(n, a, is_prime_of_cuisine);
        outputAns(is_prime, is_prime_of_cuisine, x);
    }
}

Measured memory_bytes: 3120
package main

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

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

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

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

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

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

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

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

// sort ------------------------------------------------------------

type int64Array []int64

func (s int64Array) Len() int           { return len(s) }
func (s int64Array) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s int64Array) Less(i, j int) bool { return s[i] < s[j] }

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

func main() {
	n := readInt()
	l := readInt()

	tt := l
	ans := 0
	for i := 0; i < n; i++ {
		t := i + l
		ans += t
		if abs(t) < abs(tt) {
			tt = t
		}
	}

	fmt.Println(ans - tt)
}


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


int main() {
    int n;
    cin >> n;
    long long int res, t;
    res = 1;
    for (int i = 0; i < n; i++) {
        cin >> t;
        res /= gcd(res, t);
        res *= t;
    }
    cout << res << endl;
}




Measured memory_bytes: 3620
#include<stdio.h>
#define rep(i,a,b) for(int i = a;i <= b;i++)

int main(void){
  int a,b,c,d; scanf("%d%d%d%d",&a,&b,&c,&d);
  rep(i,1,200){
    if(i%2!=0){
      c -= b;
      if(c <= 0){
        printf("Yes");
        break;
      }
    }
    else{
      a -= d;
      if(a <= 0){
        printf("No");
        break;
      }
    }
  }

  return 0;
}


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

int main(){
    int i, count = 0;
    string s, text;
    cin >> s;
    while(1){
        cin >> text;
        if (text =="END_OF_TEXT") {
            cout << count << endl;
            return 0;
        }
        for (i = 0; i < text.size(); i++){
            if ('A' <= text[i] && text[i] <= 'Z')
                text[i] += 32;
        }
        if (s == text) count++;
    }
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  unsigned long long int H, W;
  cin >> H >> W;
  if (H == 1 || W == 1) cout << 1 << endl;
  else if (H%2 != 0 && W%2 != 0) cout << H*W/2 + 1 << endl;
  else cout << H*W/2 << endl;
}

Measured memory_bytes: 256
from itertools import combinations

N, K = map(int, input().split())
A = list(map(int, input().split()))

# best_score = float("inf")
# for sel in combinations(range(N), K):
#     cost = 0

#     # 左からコストを見る
#     # 先頭未満の最大高さを超すまで上げる
#     first = sel[0]
#     first_max = A[first]
#     for k in range(first):
#         first_max = max(first_max, A[k])
#     current = first_max
#     if first_max > 0:
#         cost += abs(A[first] - current) 
    
#     for i in range(1, K):
#         if current > A[sel[i]]:
#             cost += abs(A[sel[i]] - current) + 1
#             current += 1
#         else:
#             current = A[sel[i]] + 1
#     # print(sel, cost)
#     best_score = min(best_score, cost)
# print(best_score)

best_score = float("inf")
for sel in combinations(range(N), K):
    sel = sorted(sel)
    cost = 0
    m = -1

    for i in range(N):
        if i not in sel:
            # これ以上の高さにならないといけない
            m = max(m, A[i])
        else:
            if m >= A[i]:
                cost += 1 + m - A[i]
                m += 1
            else:
                m = A[i]
    best_score = min(best_score, cost)
print(best_score)

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    ll s; cin >> s;
    ll x1,x2,x3,y1,y2,y3;
    x1 = y1 = 0;
    x2 = 1e9;
    y2 = 1;
    y3 = (s+(int)1e9-1)/(int)1e9;
    x3 = (int)1e9*y3 - s;

    cout << x1 << ' ';
    cout << y1 << ' ';
    cout << x2 << ' ';
    cout << y2 << ' ';
    cout << x3 << ' ';
    cout << y3 << '\n';

//    cout << abs((int)1e9 * y3 - x3 * 1);

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 256
from bisect import bisect_left

n = int(input())
l = list(map(int, input().split()))

l.sort()

ans = 0
for i, a in enumerate(l):
    for j, b in enumerate(l[i+1:], i + 1):
        k = bisect_left(l, a + b)
        ans += k - j - 1

print(ans)


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

int main() 
{ 
  int n;
  cin >> n;
  int p;
  int num = 0;
  for(int i=0;i<n;i++){
    cin >>p;
    if(i+1!=p)num++;
  }
  
  if(num<=2) cout << "YES";
  else cout << "NO";
  return 0; 
} 

Measured memory_bytes: 256
from collections import defaultdict

N, K = map(int,input().split( ))

a = []
b = []

for i in range(N):
	a_i, b_i = map(int, input().split( ))
	a.append(a_i)
	b.append(b_i)

d = defaultdict(int)

for i in range(N):
    if a[i] in d:
        d[a[i]] += b[i]
    else:
        d[a[i]] = b[i]

d_sorted = sorted(d.items())

l = 0

for i in range(N):
	a_i = d_sorted[i][0]
	b_i = d_sorted[i][1]
	l += b_i
	if l >= K:
		print(a_i)
		break

Measured memory_bytes: 19684
#include<stdio.h>
#include<math.h>
int main()
{
	long long int i, j, x;
	scanf("%lld", &x);
	for (i = 0; i < 3000; i++)
	{
		for (j = 0; j < 3000; j++)
		{
			if (i*i*i*i*i+j*j*j*j*j == x)
			{
				printf("%lld %lld", i, -j);
				return 0;
			}
			else if (i*i*i*i*i-j*j*j*j*j == x)
			{
				printf("%lld %lld", i, j);
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1732
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int N = in.nextInt();
			int D = in.nextInt();
			int X = in.nextInt();
			int[] A = new int[N];
			int total = N;
			for(int i = 0; i < N; i++) {
				A[i] = in.nextInt();
				total += (D - 1) / A[i];
			}
			out.println(total + X);
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

	}
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

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

    for (auto i = 0; i < (int)t.size(); i++) {
        if(t.substr(i, 2) == "?D") t[i] = 'P';
        if(t.substr(i, 2) == "P?") t[i+1] = 'D';
        if(t.substr(i, 2) == "??") {
            t[i] = 'P';
            t[i+1] = 'D';
        }
        if(t[i] == '?') t[i] = 'D';
    }

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

Measured memory_bytes: 3724
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 
#define PI 3.141592653589793238

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;
typedef gp_hash_table<long int,long int> HashTable;

int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */
   
    long int n,x,MOD;
    cin>>n>>x>>MOD;

    map<long int,long int> m, m2;
    long int ans = 0;


    for(long int i = 1; i <= n; i++){
        if(m.find(x) != m.end()){
            long int occur = m[x];
            long int dis = i - occur;
            long int dealWith = n - i + 1;
            long int ansTillThere = m2[occur - 1];
            long int ansTillNow = ans;
            long int diff = ansTillNow - ansTillThere;
            long int cycles = dealWith / dis;
            ans += cycles * diff;
            long int req = dealWith % dis;
            ans += m2[req + occur - 1] - m2[occur - 1];
            break;
        }
        else{
          m[x] = i;
          ans += x;
          m2[i] = ans;
          x = (x * x) % MOD;
        }
    }

    cout<<ans;


   return 0;
}

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

int X,N,p;
set<int>st;
pair<int,int>res;
int main(){
	res={10000,-1};
	cin>>X>>N;
	while(N--){
		cin>>p;
		st.insert(p);
	}
	for(int i=-100;i<=200;i++){
		if(st.find(i)==st.end()){
			res=min(res,{abs(X-i),i});
		}
	}
	cout<<res.second<<endl;
}


Measured memory_bytes: 3640
import sys
import  math
import bisect
from statistics import *
from collections import *
from operator import itemgetter

from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, m = na()
s = input()
t = input()
l = lcm(n, m)
flag = True
ln = l // n
lm = l // m
d = {}
ans = l
for i in range(n):
    d[1 + i * ln] = s[i]
for i in range(m):
    if 1 + i * lm in d.keys():
        if d[1 + i * lm] != t[i]:
            ans = -1
            break
print(ans)

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

using namespace std;

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

	int n, k, x, y;
	cin >> n >> k >> x >> y;
	cout << min(n, k) * x + max(n - k, 0) * y << '\n';

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

ll gcd(ll x, ll y) {return y ? gcd(y,x%y):x;}

int main(){
    ll l, r; cin >> l >> r;
    r = min(r, l + 4038);
    int ans = 2018;
    for(ll i = l; i <= r; i++){
        for(ll j = i+1; j <= r; j++){
            int tmp = i * j % 2019;
            ans = min(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    long int W,H,X,Y;
    cin>>W>>H>>X>>Y;
    
    cout<<double(W)*double(H)/2<<' ';
    int ans2;
    if(X==W/2 && Y==H/2 && W%2==0 && H%2==0) ans2=1;
    else ans2=0;
    cout<<ans2<<endl;
}

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

#define MOD (1000000000+7)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) x.begin(), x.end()
#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i > (b); i--)
// template starts
typedef long long int ll;
ll fact(ll n, ll p){
	ll ans = 1;
	for(ll i = 1; i <= n; i++){
		ans *= i;
		ans %= p;
	}
	return ans;
}
ll power(ll x, ll n, ll p){
	ll res = 1;
	if(n == 1) return x%p;
	if(n%2 == 1) res = x%p;

	ll temp = power(x,n/2,p);
	return res*((temp*temp)%p)%p;
}
ll inv(ll a, ll p){
	return power(a,p-2,p);
}
ll nCr(ll n, ll r, ll p){
	if(r > n) return 0;
	ll t1 = fact(n,p);
	ll t2 = inv(fact(r,p),p);
	ll t3 = inv(fact(n-r,p),p);

	return (((t1*t2)%p)*t3)%p;
}
vector<vector<ll> > multiply(vector<vector<ll> > &a, vector<vector<ll> > &b, ll p){
	int r1,c1,r2,c2;
	r1 = a.size(); c1 = a[0].size();
	r2 = b.size(); c2 = b[0].size();

	vector<vector<ll> > result(r1,vector<ll>(c2,0));

	if(c1 != r2) return result;

	for(int i = 0; i < r1; i++){
		for(int j = 0; j < c2; j++){
			for(int k = 0; k < c1; k++){
				result[i][j] += a[i][k]*b[k][j];
				result[i][j] %= p;
			}
		}
	}
	return result;
}

vector<vector<ll> > power(vector<vector<ll> >&a,ll n, ll p){
	int r = a.size();
	vector<vector<ll> > result(r,vector<ll>(r,0));
	for(int i = 0; i < r; i++) result[i][i] = 1;

	while(n > 0){
		if(n%2 == 1){
			result = multiply(result,a,p);
		}
		n /= 2;
		a = multiply(a,a,p);
	}
	return result;
}
// template ends here

void solve(){
	// code starts from here
	ll N; cin >> N;
	ll sum = 0;
	for(ll i = 1; i <= N; i++){
		if(i%3 == 0 || i%5 == 0) continue;
		sum += i;
	}
	cout << sum << endl;
}

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

	int T;
	//cin >> T;
	T = 1;
	while(T--){
		solve();
	}

	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
double R1, R2;
  cin >>R1>>R2;
  double ans=(double (1./R1)+double (1./R2));
  double ans1=1./ans;
  cout<<fixed<<setprecision(10)<<ans1<<endl;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_DEPRECATE
#include<bits/stdc++.h>
#define Rint register int
#define MP make_pair
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii; // 注意必要时改类型
typedef vector<int> vi;
const int N = 1e5;
int n, h[N];
ll dp[N];
void Process() {
	cin >> n;
	for (Rint i = 0; i < n; ++i)
		cin >> h[i];
	dp[0] = (ll)0; dp[1] = (ll)abs(h[1] - h[0]);
	for (Rint i = 2; i < n; ++i)
		dp[i] = min(dp[i - 1] + (ll)abs(h[i] - h[i - 1]), dp[i - 2] + (ll)abs(h[i] - h[i - 2]));
	cout << dp[n - 1] << endl;

}


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
#ifdef _DEBUG
	int tt = clock();
	freopen("in.txt", "r", stdin);
#endif 
	int Tcase = 1;
	// cin >> Tcase;
	while (Tcase--) {
		Process();
	}

#ifdef _DEBUG
	cerr << "\nTIME = " << clock() - tt << endl;
	tt = clock();
#endif
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9

int main(){
    int n;cin>>n;
    vvi t(n-1,vi(3));
    rep(i,n-1){
        rep(j,3)cin>>t[i][j];
    }
    rep(i,n){
        int a=0;
        range(j,i,n-1){
            if(a>t[j][1]){
                int diff=(a-t[j][1])%t[j][2];
                if(diff!=0){
                    a+=t[j][2]-(a-t[j][1])%t[j][2];
                }
            }else{
                a=t[j][1];
            }
            a+=t[j][0];
        }
        cout<<a<<endl;
    }
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int n;
	double a[55];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lf",&a[i]);
	}
	for(int i=0;i<n-1;i++){
		for(int j=i;j<n;j++){
			if(a[j]<a[i]){
				int temp=a[i];
				a[i]=a[j];
				a[j]=temp;
			}
		}
	} 
	for(int i=1;i<n;i++){
		double s=(a[i-1]+a[i])/2;
		a[i]=s;
	} 
	printf("%.6lf",a[n-1]);
	return 0;
} 

Measured memory_bytes: 256
//
// Created by Hideaki Imamura on 2020-03-28.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

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

void print_vec(vector<ll> v) {
    for (auto x : v) cout << x << " ";
    cout << endl;
}

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

ll X, Y, A, B, C;
vector<ll> p, q, r;

int main() {
    cin >> X >> Y >> A >> B >> C;
    p.resize(A);
    q.resize(B);
    r.resize(C);
    for (int i = 0; i < A; ++i) cin >> p[i];
    for (int i = 0; i < B; ++i) cin >> q[i];
    for (int i = 0; i < C; ++i) cin >> r[i];

    sort(p.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());
    p.insert(p.begin() + X, q.begin(), q.begin() + Y);
    //print_vec(p);
    p.insert(p.begin() + X + Y, r.begin(), r.end());
    //print_vec(p);
    sort(p.begin(), p.begin() + X + Y + C, greater<ll>());
    //print_vec(p);

    ll ans = 0;
    for (int i = 0; i < X + Y; ++i) ans += p[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6256
#include <stdio.h>
#include <math.h>

int main(void){
    int a,b,c;
    
    scanf("%d %d",&a,&b);

    if(a+b >= a-b){
        if(a+b >= a*b){
            c=a+b;
        }
        else{
            c=a*b;
        }
    }
    else{
         if(a-b >= a*b){
            c=a-b;
        }
        else{
            c=a*b;
        }
    }

    printf("%d" , c);
    return 0;
}

Measured memory_bytes: 128
/**
*	  Name: Ajay Subhash Jadhav
*	  Institute: International Institute of Technology Hyderabad 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define LL long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vii vector<ppi>
#define vll vector<LL>
#define mp make_pair
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void inputread()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}

int main(){
      
  fastio();
  string s;
  int i,n,dif=inf;
  cin>>s;
  n=s.size();
  for(i=0;i<n;i++)
  {
  	if(i+2<n)
  	{
  		//cout<<s[i]<<s[i+1]<<s[i+2]<<"\n";
  		int num=(((s[i]-'0')*100)+((s[i+1]-'0')*10)+((s[i+2]-'0')*1));
  		//cout<<"num:"<<num<<"\n";
  		if(abs(753-num)<dif)
  			dif=abs(753-num);
  	}
  }
  cout<<dif;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

ll dp[3005][3005][4];

int main() {
    int r, c, k; cin >> r >> c >> k;
    vvint data(r,vint(c,-1));
    rep(i,k) {
        int a, b, v; cin >> a >> b >> v;
        a--; b--;
        data[a][b] = v;
    }
    dp[0][0][0] = 0;
    if (data[0][0] != -1) dp[0][0][1] = data[0][0];
    rep(i,r)rep(j,c)rep(k,4) {
        if (i+1 < r) {
            chmax(dp[i+1][j][0],dp[i][j][k]);
            if (data[i+1][j] != -1) {
                chmax(dp[i+1][j][1],dp[i][j][k]+data[i+1][j]);
            }
        }
        if (j+1 < c) {
            chmax(dp[i][j+1][k],dp[i][j][k]);
            if (data[i][j+1] != -1) {
                if (k != 3) {
                    chmax(dp[i][j+1][k+1],dp[i][j][k]+data[i][j+1]);
                }
            }
        }
    }
    ll ans = -inf_l;
    rep(i,4) ans = max(ans,dp[r-1][c-1][i]);
    cout << ans << endl;
}

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

    return 0;
}

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

using ll = long long;
using pp = pair<ll,ll>;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end() //昇順
#define enb(a) a.rbegin(),a.rend() //降順
#define pb(a,b) a.push_back(b)
//fixed << setprecision(20)

int main(){
	int n;
	cin >> n;
	int ok = 0;

	for(int i = 1; i <= n; i++){
		if(n % i == 0 && i < 10 && n / i < 10){
			ok = 1;
		}
	}
	if(ok)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include 	<ext/pb_ds/assoc_container.hpp> 
#include 	<ext/pb_ds/tree_policy.hpp> 
#include 	<iostream>
#include 	<queue>
#include 	<tuple>
#include 	<vector>
#include	<bits/stdc++.h>
#include	<algorithm>
#include 	<cmath>
#include 	<map>
#include 	<string>
#include 	<iomanip> 
#include 	<ctype.h>
#define 	ll  long long int
#define		read(a) long long int a; cin>>a;
#define 	readstr(s) string s; cin>>s;
#define 	readc(c) char c; cin>>c;
#define 	readarr(a,l) long long int a[l]={0}; for(ll i=0;i<l;i++) cin>>a[i];
#define 	loop(i,a,b) for(ll i=a;i<b;i++)
#define 	rloop(i,a,b) for(ll i=a;i>b;i--)
#define 	loopchar() for(char c='a';c<='z';c++)
#define 	printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define		printv(v) for (int i: v) cout << i << " "; cout << endl;
#define 	loopitr(vec) for(auto itr=vec.begin();itr!=vec.end();itr++)
#define 	ff first
#define 	ss second
#define 	readmtrx(i,j,a,b) ll arr[a][b]={0};for(ll i=0;i<a;i++)for(ll j=0;j<b;j++) cin>>arr[i][j];
#define 	all(a) a.begin(), a.end()
#define 	yes cout <<"YES"<<endl;
#define 	no cout <<"NO"<<endl;
#define 	sc(x) cout << (#x) << " is " << (x) << endl;
#define 	fast ios_base::sync_with_stdio(false);cin.tie(0);
#define 	pb(p) push_back(p)
#define 	mp make_pair
#define 	fsort(vec) sort(vec.begin(),vec.end())
#define 	rsort(vec) sort(vec.begin(),vec.end(),compare)
#define 	Endl endl
#define 	ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define 	roundoff std::cout << std::setprecision(15)
#define 	inf 9223372036854775807
#define 	infn -9223372036854775807
#define 	pi 3.14159265358979323846
const 		int mod = 1e9+7; 
#define 	intsize ll size = trunc(log10(num)) + 1
#define 	REVERSE(vec) reverse(vec.begin(),vec.end())
using 		namespace __gnu_pbds; 
using 		namespace std;

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

//code start from here 

int main() {
	fast;
	readstr(s)
	if(s=="ARC") cout<<"ABC"<<endl;
	else cout<<"ARC"<<endl;
	return 0;
}

//ends here 

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
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;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 N, K;
  cin >> N >> K;

  N %= K;
  cout << min(N, K -N) << endl;
}

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

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール
// 剰余演算
constexpr ll p = 1000000007LL; // 10^9+7
ll powll(ll a, ll n) {
    if (n == 0) {
        return 1LL;
    } else if (n == 1) {
        return a % p;
    } else {
        ll temp = powll(a, n/2);
        temp = temp * temp % p;
        return n % 2 ? temp * a % p : temp;
    }
}

inline ll invll(ll a) { return powll(a, p-2); }

vector<ll> fac_cache = {1}, invfac_cache = {1};
void make_fac_cache(ll a) {
    ll old_max = fac_cache.size() - 1;
    if (a > old_max) {
        fac_cache   .resize(a+1);
        invfac_cache.resize(a+1);
        for (ll i = old_max + 1; i <= a; i++) {
            fac_cache[i] = fac_cache[i-1] * i % p;
        }
        invfac_cache[a] = invll(fac_cache[a]);
        for (ll i = a-1; i > old_max; i--) {
            invfac_cache[i] = invfac_cache[i+1] * (i + 1) % p;
        }
    }
}

inline ll    facll(ll a) { make_fac_cache(a); return fac_cache[a]; }
inline ll invfacll(ll a) { make_fac_cache(a); return invfac_cache[a]; }
inline bool isoutll(ll n, ll r) { return n < 0 || r < 0 || n < r; }
inline ll nPr(ll n, ll r) { return isoutll(n, r) ? 0 : facll(n) * invfacll(n-r) % p; }
inline ll nCr(ll n, ll r) { return isoutll(n, r) ? 0 : facll(n) * invfacll(n-r) % p * invfacll(r) % p; }

// 処理内容
int main() {
    
    string l; cin >> l;

    ll n = l.size();
    vector<ll> mimic(n+1);
    mimic[0] = 1;
    REP(i, n) {
        ll term = l[i] == '1' ? 2 : 1;
        mimic[i+1] = mimic[i] * term % p;
    }
    ll ans = mimic[n];
    DSRNG(i, n-1, 0) {
        if (l[i] == '0') continue;
        ans += mimic[i] * powll(3, n-i-1) % p;
        ans %= p;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>

using namespace std;

void solve()
{
	int A, B, K;
	cin >> A >> B >> K;
	bool isChokudai = true;
	for (int i = 0; i < K; ++i)
	{
		if (isChokudai)
		{
			if (A % 2 == 1)
			{
				--A;
			}
			int size = A / 2;
			B += size;
			A -= size;
		}
		else
		{
			if (B % 2 == 1)
			{
				--B;
			}
			int size = B / 2;
			A += size;
			B -= size;
		}
		isChokudai = !isChokudai;
	}
	cout << A << " " << B << endl;
}

int main()
{
	solve();
	return(0);
}

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


int main(void) {
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n){
        cin >> d.at(i);
    }
    sort(d.begin(),d.end());
    int ans = 0;
    rep(i,n){
        if(i > 0 && d.at(i) == d.at(i-1)){}
        else ans ++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
l = []
for i in range(M):
    P, Y = map(int, input().split())
    l.append([i, P, Y])
l = sorted(l, key = lambda x: (x[1], x[2]))
ans = []
prev_P = 0
for i in range(M):
    if prev_P != l[i][1]:
        j = 0
    j += 1
    ans.append([l[i][0], str(l[i][1]).zfill(6) + str(j).zfill(6)])
    prev_P = l[i][1]
ans = sorted(ans)
for i, s in ans:
    print(s)

Measured memory_bytes: 41920
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;

using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int 			long long int
#define pll 			pair<ll , ll>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007

ll mod_pow(ll a,ll b) {
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) {
	return mod_pow(a , mod-2);
}

const int MAXN = 1e5+5;

map<pair<int,int> , int > color;

vector< vector<int> > a(MAXN);

int vis[MAXN];

void dfs(int u , int p , int pp) {
	vis[u] = 1;
	int cur = 1;
	
	for(auto v : a[u]) {
		if(!vis[v]) {
			if(cur == color[{p , pp}]) {
				cur++;
			}
			
			int mi = min(u , v);
			int mx = max(u , v);
			
			color[{mi , mx}] = cur++;
		}
	}
	
	for(auto v : a[u]) {
		if(!vis[v]) {
			int mi = min(u , v);
			int mx = max(u , v);
			
			dfs(v , mi , mx);
		}
	}
}

void solve() {
    
    int n;
    
    cin >> n;
    
    int x , y;
    
	vector<pair<int,int>> b(n);
	
	int mx = 0;
    
    for(int i = 0; i < n-1; ++i) {
    	cin >> x >> y;
    	
    	b[i].F = x;
    	b[i].S = y;
    	
    	a[x].pb(y);
    	a[y].pb(x);
    	
    	mx = max(mx , (int)a[x].size());
    	mx = max(mx , (int)a[y].size());
    }
    
    cout << mx << endl;
    
    color[{0,1}] = 0;
    
    dfs(1 , 0 , 1);
    
    for(int i = 0; i < n-1; ++i) {
    	cout << color[{min(b[i].F,b[i].S) , max(b[i].F , b[i].S)}] << endl;
    }
}       

signed main() {
    fast;
    
    int t = 1;
    
    //cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


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

using namespace std;

int N, a[509], ans[250009], ap2[509];
bool ap[250009];
pair < int, int > h[509];
deque < int > need;

void Ans ()
{
    printf ("No\n");
    exit (0);
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
    scanf ("%d", &a[i]), ap[a[i]] = 1, h[i] = make_pair (a[i], i);
sort (h + 1, h + N + 1);
for (int i=N; i>=1; i--)
    for (int j=1; j<h[i].second; j++)
        need.push_back (h[i].second);
int j = 1;
for (int i=1; i<=N; i++)
{
    while (1)
    {
        while (j <= N * N && ap[j] == 1) j ++;
        if (j >= h[i].first) break;
        if (need.empty ()) Ans ();
        int val = need.back (); need.pop_back ();
        ans[j ++] = val, ap2[val] ++;
    }
    if (ap2[h[i].second] != h[i].second - 1) Ans ();
    ans[h[i].first] = h[i].second;
    int steps = N - h[i].second;
    while (steps --) need.push_front (h[i].second);
}
while (1)
{
    while (j <= N * N && ap[j] == 1) j ++;
    if (j > N * N) break;
    if (need.empty ()) Ans ();
    int val = need.back (); need.pop_back ();
    ans[j ++] = val;
}
printf ("Yes\n");
for (int i=1; i<=N * N; i++)
    printf ("%d ", ans[i]);
printf ("\n");
return 0;
}


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

using namespace std;

constexpr long long INF64 = 1e18;

using Weight=long long;

struct Edge{
    int src,dst;
    Weight weight;
    Edge(int src,int dst,Weight weight):
    src(src),dst(dst),weight(weight){}
};

auto operator < (const Edge &e,const Edge &f){
    if(e.weight!=f.weight)return e.weight>f.weight;
    else if(e.src!=f.src)return e.src<f.src;
    else return e.dst<f.dst;
}

using Edges=vector<Edge>;
using Graph=vector<Edges>;
//??????????????????
bool BellmanFord(const Graph &g,int s,vector<Weight>&dist,vector<int>&prev){
    const int V=g.size();
    dist[s]=0;
    bool negative_cycle=false;
    for(int i=0;i<V;++i){
        for(int j=0;j<V;++j){
            for(auto e:g[j]){
                if(dist[e.src]!=INF64 && dist[e.dst]>dist[e.src]+e.weight){
                    dist[e.dst]=dist[e.src]+e.weight;
                    prev[e.dst]=e.src;
                    if(i==V-1){
                        dist[e.dst]=-INF64;
                        negative_cycle=true;
                    }
                }
            }
        }
    }
    return negative_cycle;
}

int main(){
    cin.sync_with_stdio(false);
    int V,E,r;
    cin>>V>>E>>r;
    Graph g(V);
    for(int i=0;i<E;++i){
        int s,t,d;
        cin>>s>>t>>d;
        g[s].emplace_back(s,t,d);
    }
    vector<Weight>dist(V,INF64);//???????????§????????¢?????\???
    vector<int>prev(V,-1);//????????????????????\???
    if(BellmanFord(g,r,dist,prev)){
        cout<<"NEGATIVE CYCLE"<<endl;
    }else{
        for(int i=0;i<V;++i){
            if(dist[i]==INF64)cout<<"INF"<<endl;
            else cout<<dist[i]<<endl;
        }
    }
}
//be checked by AOJ(GRL-1-B).

Measured memory_bytes: 3240