akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

bool xy[200010];
typedef long long ll;

vector<int> g[200010];

ll XX;
ll YY;
ll ans;

void dfs(int v) {
  xy[v] = true;

  if(v < 100000) XX++;
  else YY++;

  for(int i = 0; i < g[v].size(); i++) {
    int u = g[v][i];
    if(xy[u]) continue;
    dfs(u);
  }
  return;
}
    
int main() {
  int n;
  cin >> n;

  for(int i = 0; i < n; i++) {
    int X,Y;
    cin >> X >> Y;
    X--;
    Y--;
    Y += 100000;
    g[X].push_back(Y);
    g[Y].push_back(X);
  }

  for(int i = 0; i < 200000; i++) {
    if(xy[i]) continue;
    XX = 0;
    YY = 0;
    dfs(i);
    ans += XX * YY;
  }

  cout << ans - n << endl;

}


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

const int INF = 1e9;
int h, w;
int sy, sx, gy, gx;
int cnt;

int grid[25][25];

void init() {
    cnt = 0;
    for (int i = 0; i < 25; i++) {
        for (int j = 0; j < 25; j++) {
            grid[i][j] = 0;
        }
    }
}

bool check(int ni, int nj) {
    if (ni < 0 || ni >= h) return false;
    if (nj < 0 || nj >= w) return false;
    if (grid[ni][nj] == 1) return false;
    return true;
}

int di[] = {-1, 0, 1, 0};
int dj[] = {0, -1, 0, 1};
int dfs(int ci, int cj, int c) {
    if (c > 10) return INF;
    int res = INF;
    for (int i = 0; i < 4; i++) {
        int ni = ci, nj = cj;
        while (check(ni + di[i], nj + dj[i])) {
            ni += di[i];
            nj += dj[i];
            if (ni == gy && nj == gx) return c + 1;
        }
        if (ni == ci && nj == cj) continue;
        if (ni + di[i] == -1 || ni + di[i] == h) continue;
        if (nj + dj[i] == -1 || nj + dj[i] == w) continue;
        grid[ni + di[i]][nj + dj[i]] = 0;
        res = min(res, dfs(ni, nj, c + 1));
        grid[ni + di[i]][nj + dj[i]] = 1;
    }
    return res;
}

int main() {
    while (cin >> w >> h, w | h) {
        init();
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cin >> grid[i][j];
                if (grid[i][j] == 2) {
                    sy = i, sx = j;
                } else if (grid[i][j] == 3) {
                    gy = i, gx = j;
                }
            }
        }
        int ans = dfs(sy, sx, 0);
        if (ans > 10) ans = -1;
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3076
## for use in beginner level questions where speed is key
## and also for single test case code
## mastercopy for x,y,z

import sys
import heapq, functools, collections
import random
from collections import Counter, defaultdict

# read line as a string
strr = input()

# read line as an integer
# k = int(input())

# read one line and parse each word as a string
# lst = input().split()

# read one line and parse each word as an integer
# arr = list(map(int,input().split()))

if strr[-1] == "s":
    print(strr + "es")
else:
    print(strr + "s")


Measured memory_bytes: 76868
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	LL A,B;
	cin >> N >> A >> B;
	vector<LL> H(N);
	priority_queue <LL> maxque;
	for(int i=0;i<N;++i){
		cin >> H[i];
	}
	/////////
	if( N == 1 ){
		cout << (H[0]+A-1)/A << endl;
		return;
	}
	sort( H.begin(),H.end());
	LL NG,OK,mid;
	NG = 0;
	OK = INF;
	LL D = B;
	LL add = A-B;
	while(OK-NG>1){
		mid = (OK+NG)/2;
		LL rest = mid;
		for(int i=0;i<N;++i){
			LL temp = H[i] - mid * D;
			
			if( temp > 0 ){
				rest -= (temp+add-1)/add;//追加で必要
			}
			if( rest < 0 ){
				break;
			}
		}
		if( rest >= 0 ){
			OK = mid;
		}else{
			NG = mid;
		}
	}
	cout << OK << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define IO() (void)freopen("in.in", "rt", stdin),freopen("out.out", "wt", stdout)
#define FastIO() ios::sync_with_stdio(false);
#define debug(x) cout << __LINE__ << ": " << #x << " = " << (x) << endl

typedef long long ll;
const ll MOD=1e9+7;
const int N = 1e7+9, M = 1e5+9, OO = 0x3f3f3f3f;
const double EPS = 1e-10;

inline int readi(){int n;scanf("%d", &n);return n;}
inline ll readll(){ll n;scanf("%I64d", &n);return n;}
inline char readc(){char c;scanf("%c ", &c);return c;}
inline double readd(){double n;scanf("%lf", &n);return n;}
inline bool dCMP(const long double& a, const long double& b){return fabsl(a-b)<EPS;}
char str[N];
int main()
{
	// #ifndef ONLINE_JUDGE
	// IO();
	// #endif
	scanf("%s",str);
	int n=strlen(str);
	for(int i=1;i<n;++i) if(str[i]==str[i-1]){printf("Bad"); return 0;}
	printf("Good");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
  int x,y,a,b;
  scanf("%d %d",&x,&y);
  if(x<1 || y<1 || x>1000000000 || y>1000000000 ){
    end(1);
  }
  if(x>y){
    a=y;
    y=x;
    x=a;
  }
  //printf("x:%d y:%d\n",x,y);
  b=y%x;
  while(b!=0){
    y=x;
    x=b;
    b=y%x;
  }
  printf("%d\n",x);
  return 0;
}
  



Measured memory_bytes: 2128
from collections import deque

n = int(input())
s = input()
lCnt = 0
rCnt = 0
stack = deque()
stack.append(s[0])

for i in range(1, len(s)):
#for i in range(0, len(s)):
    if len(stack) == 0:
        stack.append(s[i])
        continue

    prev = stack.pop()

    if prev == '(' and s[i] == ')':
        continue
    else:
        stack.append(prev)
        stack.append(s[i])

#print(stack)

for i in range(len(stack)):
    if stack[i] == '(':
        lCnt += 1
    else:
        rCnt += 1

s += ')' * lCnt
s = '(' * rCnt + s

print(s)



Measured memory_bytes: 38768
import sys
import  math
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()

s = input()
t = input()
s = sorted(list(s))
t = sorted(list(t), reverse=True)
if s < t:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 5276
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// //k!
// ll facctorialMethod(ll k){
//     ll sum = 1;
//     for (int i = 1; i <= k; ++i)
//     {
//         sum = (sum%MOD*i%MOD)%MOD;
//     }
//     return sum;
// }

// //nCr
// ll permutationMethod(ll n,ll r){
//     ll n_sum,r_sum;
//     ll i;
//     r = n - r;
// 	if(r==0)return 1;
//     n_sum = facctorialMethod(n);
//     r_sum = facctorialMethod(r);
//     return n_sum/r_sum;
// }

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
	int n,k;cin>>n>>k;
	COMinit();
	for(int i = 1; i<=k; i++){
		if(i!=1){
			if(k-i>0){
				cout << (COM(n-k+1,i)*COM(k-i+i-1,k-i))%MOD << endl;
			}else{
				cout << COM(n-k+1,i) << endl;
			}
		}else{
			cout << COM(n-k+1,i) << endl;
		}
	}
}

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

int main()
{
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;
    cin >> n;
    cout << a[n - 1] << "\n";
}


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

const int INF = 1e8;
int n, m;
int c[22];
int dp[55555];

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

    fill(dp, dp+n+1, INF);
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < m; j++) {
            if (i >= c[j]) {
                dp[i] = min(dp[i], dp[i-c[j]]+1);
            }
        }
    }
    cout << dp[n] << endl;

    return 0;
}


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

public class Main {

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

        final int N = sc.nextInt();

        Work[] works = new Work[N];
        for (int i = 0; i < N; i++) {
            final int A = Integer.valueOf(sc.next());
            final int B = Integer.valueOf(sc.next());
            works[i] = new Main().new Work(A, B);
        }

        boolean finished = true;
        int workTime = 0;

        Arrays.sort(works);

        for (Work work : works) {
            workTime += work.a;
            if (workTime > work.b) {
                finished = false;
                break;
            }
        }
        
        System.out.println(finished ? "Yes" : "No");
    }

    private class Work implements Comparable<Work> {
        public int a;
        public int b;

        public Work(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Work o) {
            return b - o.b;
        }

        public String toString() {
            return "a: " + a + ", b: " + b;
        }
    }
}


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

int main() {
    int N;
    cin >> N;
    if (N == 1) {
        cout << "Hello World" << endl;
    } else {
        int A, B;
        cin >> A >> B;
        cout << A + B << endl;
    }
    return 0;
}


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

using ll = long long;

void solve(long long X, long long K, long long D){
    ll cnt = abs(X) / D;
    if(cnt > K){
        if(X < 0){
            X += K * D;
        }else{
            X -= K * D;
        }
        cout<<abs(X)<<endl;
    }else{
        if(X < 0){
            X += cnt * D;
        }else{
            X -= cnt * D;
        }
        K -= cnt;
        if(K % 2 == 0){
            cout<<abs(X)<<endl;
        }else{
            if(X < 0){
                cout<<abs(X + D)<<endl;
            }else{
                cout<<abs(X - D)<<endl;
            }
        }
    }
}

int main(){
    long long X;
    scanf("%lld",&X);
    long long K;
    scanf("%lld",&K);
    long long D;
    scanf("%lld",&D);
    solve(X, K, D);
    return 0;
}


Measured memory_bytes: 3748
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)
#define MP(a,b) make_pair(a,b)

#if __has_include("debug.hpp")
#include "debug.hpp"
#else
template<typename T>
void debug(T& obj) {}
#endif

template<typename T>
T in(){
	T val;
	cin >> val;
	return val;
}

template<typename T>
vector<T> inv(ll num) {
	vector<T> val(num);
	rep(i,num) cin >> val[i];
	return val;
}

//----------------------------------------------------------------------
void solve() {

	ll n;
	cin >> n;
	string p="",q="";
	vector<int> vec(n);
	rep(i,n) {
		int t;
		cin >> t;
		p += to_string(t);
		vec[i] = i+1;
	}
	rep(i,n) {
		int t;
		cin >> t;
		q += to_string(t);
	}

	debug(p);
	debug(q);

	map<string, ll> m;
	ll cnt = 0;
	do {
		string s="";
		rep(i,n) s+=to_string(vec[i]);
		m[s] = cnt;
		cnt++;
	}while(next_permutation(vec.begin(),vec.end()));

	cout << abs(m[p]-m[q]);



}
//----------------------------------------------------------------------

int main(int argc, char* argv[]) {
	solve();
	return 0;
}


Measured memory_bytes: 6664
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値
		int X = scan.nextInt();
		int Y = scan.nextInt();
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		Long[] P = new Long[A];
		Long[] Q = new Long[B];
		Long[] R = new Long[C];

		for (int i = 0; i < A; i++) {
			P[i] = scan.nextLong();
		}
		for (int i = 0; i < B; i++) {
			Q[i] = scan.nextLong();
		}
		for (int i = 0; i < C; i++) {
			R[i] = scan.nextLong();
		}

		Arrays.sort(P, Collections.reverseOrder());
		Arrays.sort(Q, Collections.reverseOrder());
		Arrays.sort(R, Collections.reverseOrder());

		Long[] ALL = new Long[X+Y];

				for (int i = 0; i < X; i++) {
					ALL[i] = P[i];
				}
				for (int i = X; i < X+Y; i++) {
					ALL[i] = Q[i-X];
				}

				Arrays.sort(ALL);

				int indexALL = 0;
				int indexC = 0;

				while (indexALL < X+Y && indexC < C ) {

					if (ALL[indexALL] < R[indexC]) {
						ALL[indexALL] = R[indexC];
						indexC++;
					}
					indexALL++;
				}

				long result = 0L;

				for (long element: ALL) {
					result += element;
				}

		System.out.println(result);
	}
}

Measured memory_bytes: 104236
#include <iostream>
#include <string>
using namespace std;
int N,X;
int m[101];
int nokori,sum,mini;
int main(){
    sum = 0; mini = 10000;
    cin >> N >> X;
    for(int  i = 0; i < N; i++){
        cin >> m[i];
        sum += m[i];
        if(m[i] < mini){
            mini = m[i];
        }
    }
    nokori = X - sum;
    cout << N + (nokori / mini) << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace C
{

    class Depth
    {
        public int dep(Node[] node, int id)
        {
            if (node[id].parent == -1)
            {
                return 0;
            }
            return dep(node, node[id].parent) + 1;
        }
    }

    class Node
    {
        public int id;
        public int k;
        public int[] child = new int[0];
        public int parent;
        public int depth;
        public string type;

        public void node()
        {
            id = 0;
            k = 0;
            parent = -1;
            depth = 0;
            child[0] = -1;
            type = " ";
        }
    }

    class A
    {
        static void Main(string[] args)
        {
            string input1;
            input1 = Console.ReadLine();
            int n = int.Parse(input1), i, j;
            Node[] node = new Node[n];
            Depth dep = new Depth();
            for (i = 0; i < n; i++)
            {
                node[i] = new Node();
                node[i].id = i;
                node[i].parent = -1;
            }
            string[] input2 = new string[100000];
            
            //入力
            for (i = 0; i < n; i++)
            {
                input2 = Console.ReadLine().Split(' ');
                node[int.Parse(input2[0])].k = int.Parse(input2[1]);
                Array.Resize(ref node[int.Parse(input2[0])].child, node[int.Parse(input2[0])].k);
                if (node[int.Parse(input2[0])].k == 0) node[int.Parse(input2[0])].type = "leaf";
                for (j = 0; j < node[int.Parse(input2[0])].k; j++)
                {
                    node[int.Parse(input2[0])].child[j] = int.Parse(input2[j + 2]);
                }
            }
            for (i = 0; i < n; i++)
            {
                for (j = 0; j < node[i].k; j++)
                {
                    node[node[i].child[j]].parent = node[i].id;
                }
            }

            for (i = 0; i < n; i++)
            {
                node[i].depth = dep.dep(node, i);
            }
            
            //表示
            for (i = 0; i < n; i++)
            {
                if (node[i].depth == 0)
                {
                    node[i].type = "root";
                }
                else if (node[i].type!="leaf")
                {
                    node[i].type = "internal node";
                }
                Console.Write("node "+node[i].id + ": parent = "+node[i].parent+", depth = "+node[i].depth+", "+node[i].type+", [");
                for (j = 0; j < node[i].k; j++)
                {
                    if (j != 0)
                    {
                        Console.Write(", ");
                    }
                    Console.Write(node[i].child[j]);
                }
                Console.WriteLine("]");
            }
        }
    }
}



Measured memory_bytes: 29004
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<vector>

#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 all(x)  (x).begin(), (x).end()
#define MAX 100000
using namespace std;

int main(){
  int N, T; cin >> N >> T;
  int c[101], t[101];
  int ans = 1001;
  rep(i, 0, N){
    cin >> c[i] >> t[i];
    if(c[i]<ans && t[i] <= T){
      ans = c[i];
    }
  }
  if(ans != 1001) cout << ans << endl;
  else cout << "TLE" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll n,k;
    cin>>n>>k;
    ll point;
    double p=0;
    FOR(i,1,n+1){
        point=i;
        ll count=0;
        while(point<k){
            point*=2;
            count++;
        }
        p+=1/(pow(2,count)*n);
    }
    cout << fixed << setprecision(10)<<p;
    return 0;
}

Measured memory_bytes: 4180
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) {
		if ( a < b ) swap(a, b);
		if ( b == 0 ) return a;
		else gcd(b, a % b);
}

int main() {
		int N;
		ll X;
		cin >> N >> X;
		vector<ll> x(N, 0);
		vector<ll> d(N, 0);
		for (int i = 0; i < N; i++) {
				cin >> x[i];
				d[i] = abs(x[i] - X);
		}

		ll ans = d[0];
		for (int i = 1; i < N; i++) {
				ans = gcd(ans, d[i]);
		}

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


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

using namespace std;

typedef long long ll;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

ll get(ll x, ll y) {
  return (x / y);
}

int main() {
  int n; read(n);
  set <int> s;
  while(n--) {
    int x; cin >> x;
    s.insert(x);
  }
  print(s.size());
}

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

bool view_ocean(int H[], int i);

int main()
{
    int N;
    cin >> N;
    int H[N];
    for (int i = 0; i < N; i++) cin >> H[i];
    bool is_view;
    int sum_view = 0;
    for (int i = 0; i < N; i++) {
        is_view = view_ocean(H, i);
        if (is_view) sum_view++;
    }
    cout << sum_view << endl;
    return 0;
}

bool view_ocean(int H[], int i)
{
    bool is_view = true;
    for (int j = 0; j < i; j++) {
        if (H[j] <= H[i]) {}
        else {
            is_view = false;
            break;
        }
    }
    return is_view;
}


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

long long cabs(long long num){
    return num < 0 ? -num : num;
}

int main(){
    long long x, k, d;
    cin >> x >> k >> d;
    x = cabs(x);
    long long mod = x / d;
    if(mod > k){
        x = x - (k * d);
        cout << x << endl;
    } else {
        x = x - (mod * d);
        k = k - mod;
        if(k % 2 == 0){
            cout << x << endl;
        } else {
            x = cabs(x - d);
            cout << x << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3672
v=[0 for i in range(100001)]
n=int(input())
ar=list(map(int,input().split()))
s=0
for i in ar:
    s+=i
    v[i]+=1
q=int(input())
for i in range(q):
    a,b=map(int,input().split())
    s-=a*v[a]
    s+=b*v[a]
    v[b]+=v[a]
    v[a]=0
    print(s)


Measured memory_bytes: 89964
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int t = sc.nextInt();
		int i = 1;
		int sum = 0;
		while(a * i <= t){
			sum += b;
			i += 1;
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

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

struct Coins {
    ll a, b, c;
};

int x, y, z;
vector<Coins> vec;

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

    cin >> x >> y >> z;
    int n = x + y + z;
    vec.resize(n);
    for(Coins &a : vec)
        cin >> a.a >> a.b >> a.c;

    sort(ALL(vec), [](Coins a, Coins b) { return a.a - a.b > b.a - b.b; });

    vector<ll> ac(n, -inf), bc(n, -inf);

    ll sum = 0;
    priority_queue<ll> que;
    rep(i, x) {
        sum += vec[i].a;
        que.push(vec[i].c - vec[i].a);
    }
    ac[x - 1] = sum;
    FOR(i, x, x + z) {
        que.push(vec[i].c - vec[i].a);
        ll p = que.top();
        que.pop();
        sum += p + vec[i].a;
        ac[i] = sum;
    }

    sum = 0;
    priority_queue<ll> que2;
    for(int i = n - 1; i >= n - y; i--) {
        sum += vec[i].b;
        que2.push(vec[i].c - vec[i].b);
    }
    bc[n - y] = sum;
    for(int i = n - y - 1; i >= x; i--) {
        que2.push(vec[i].c - vec[i].b);
        ll p = que2.top();
        que2.pop();
        sum += p + vec[i].b;
        bc[i] = sum;
    }

    ll ans = -inf;
    rep(i, n - 1) chmax(ans, ac[i] + bc[i + 1]);

    cout << ans << endl;

    return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int m; cin >> m;
    vector<vector<int>> s(m);
    for(int i=0;i<m;i++){
        int k; cin >> k;
        for(int j=0;j<k;j++){
            int a; cin >> a; a--;
            s[i].emplace_back(a);
        }
    }

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

    ll ans = 0;
    for(int bit=0; bit<(1<<n); bit++){  
        
        bool ok = false;
        for(int i=0;i<m;i++){
            int on =0;
            for(auto v: s[i]){
                if(bit & (1<<v)) on++;
            }
            
            if(on%2 == p[i])
                ok = true;
            if(on%2 != p[i]){
                ok = false; break;
            }
        }
        
        if(ok) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
long mod = (long) 1e9 + 7;

int main(){
    
    int k, a, b;
    cin >> k >> a >> b;
    
    if(a % k == 0){
        cout << "OK" << "\n";
    } else if(b / k - a / k > 0){
        cout << "OK" << "\n";
    } else {
        cout << "NG" << "\n";
    }
    
    return 0;
}


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

int main() {
	string s, ans = "";
	cin >> s;

	for (int i = 0; i < s.size(); i++) {
		if (s[i] != 'B') {
			ans.push_back(s[i]);
		}
		else {
			if (ans.size() > 0) {
				ans.pop_back();
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#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 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;

vii graph;
vll dp;
/*FUNCs=================================================*/
ll length(int x) {
    if(dp[x] != -1) return dp[x];
    ll res = 0;
    for(auto i : graph[x]) {
        chmax(res, length(i) + 1);
    }
    dp[x] = res;
    return res;
}

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

    int n,m,x,y; cin >> n >> m;
    graph.resize(n+1);
    dp.resize(n+1, -1);
    rep(i,m) {
        cin >> x >> y;
        graph[0].push_back(x);
        graph[x].push_back(y);
    }
    ll ans = length(0) - 1;
    cout << ans << '\n';
}

Measured memory_bytes: 9464
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define mod 998244353LL
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 100000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pii a, pii b)//true for a before b
{
	if(a.S < b.S)
		return 1;
	if(a.S > b.S)
		return 0;
	if(a.F <= b.F)
		return 1;
	return 0;
}

const int N = (2e3) + 9;
const int M = (2e6) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 900;

int a[N];
bitset < M > dp;

void solve()
{
	int n, i, ans = 0, sum = 0, val;
	cin >> n;
	fo(i,1,n+1)
	{
		cin >> a[i];
		sum += a[i];
	}
	val = sum/2;
	dp[0] = 1;
	fo(i,1,n+1)
		dp |= (dp<<a[i]);
	ans = 0;
	fo(i,1,val+1)
		if(dp[i])
			ans = i;
	cout << (sum-ans) << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	//io_file;
	// srand(clock());

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(3);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case " << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 1024
import sys
import queue
import math

sys.setrecursionlimit(10**7)

n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(m):
    r1, r2 = map(int, input().split())
    edges[r1-1].append(r2-1)
    edges[r2-1].append(r1-1)

sign = [None for _ in range(n)]
q = queue.Queue()
q.put(0)
while True:
    if q.empty():
        break
    rm = q.get()
    for to in edges[rm]:
        if sign[to] is None:
            sign[to] = rm
            q.put(to)
if None in sign[1:]:
    print("No")
else:
    print("Yes")
    for i in range(1, n):
        print(sign[i]+1)

Measured memory_bytes: 97908
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		int ans = 0;

		for(int i = a; i <= b; i++){
			if(c%i == 0)ans++;
		}

		System.out.printf("%d\n",ans);
	}
}




Measured memory_bytes: 26440
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100005;

vector<pair<int,int> > graph[maxn];
bool color[maxn], visit[maxn];

void bfs(int s)
{
    queue<int> Q;
    Q.push(s);
    color[s] = false;

    while(!Q.empty())
    {
        int sz = (int) Q.size();

        while(sz--)
        {
            int u = Q.front();
            Q.pop();
            for(int i = 0; i < graph[u].size(); i++)
            {
                int v = graph[u][i].first;
                if(!visit[v])
                {
                    visit[v] = true;
                    Q.push(v);
                    if(graph[u][i].second == 1)
                    {
                        color[v] = !color[u];
                    }
                    else
                    {
                        color[v] = color[u];
                    }
                }
            }
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

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

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


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

int main () {

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);

  int64_t a, b, c, d; cin >> a >> b >> c >> d;
  int64_t ans = -1e18;
  for (int64_t i: {a, b}) {
    for (int64_t j: {c, d}) {
      ans = max (i*j, ans);
    }
  }cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define LLI long long int
#define pii pair<int,int>
#define fst first
#define sec second
#define ULTRA 2134567890
#define de(x) if(x!=0 && MODE==x)
#define MODE 1
using namespace std;

LLI A[100007] = {};
LLI cht[100007] = {};

int main() {
    int i,j;
    int N;

    scanf("%d", &N);
    for( i=1; i<=N; i++) {
        scanf("%lld", &A[i]);
    }

    LLI ans = 0;
    for( i=1; i<=N; i++) {
        cht[ A[i] ]++;
        ans += A[i];
    }
    int Q;
    scanf("%d", &Q);
    while(Q--) {
        LLI B,C;
        scanf("%lld %lld", &B, &C);
        ans -= B * cht[B];
        ans += C * cht[B];
        cht[C] += cht[B];
        cht[B] = 0;
        printf("%lld\n", ans);
    }

    return 0;
}

//
//          ___ ___  __________  __________
//         /////\  \/\   ______\/\\\\\\\\\\\  Code by ~Ice Tea~ of
//        //// \ \  \ \  \_____/\ \\\\_____/      New Empire of CHSH ...
//       ////   \ \  \ \  \      \ \\\\\\\\\\\
//      ////__   \ \  \ \  \      \ \\\\_____/
//     ///////\   \ \  \ \  \______\ \\\\_______   ________
//    ////____/    \ \__\ \___   ___\ \\\\\\\\\\\ _\  ___  \_
//   /__/           \/__/\/__/\  \__/\ \\\\_____//\  .\_/\_  \
//                           \ \  \   \ \\\\\\\\\\\\  \_\/_\  \
// ... with the AC Power of   \ \  \   \ \\\\_____/ \   _____  \
//   The Great Tsundere Doggy. \ \  \   \ \\\\     \ \  \  \ \  \
//                              \ \__\   \ \\\\\\\\\\ \__\  \ \__\
//                               \/__/    \/________/\/__/   \/__/
//


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

typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define mp make_pair

char s[110];
int n;

int main(){
    scanf("%s", s);
    int ans = 0;
    n = strlen(s);
    int m = n / 2;
    for(int i=0; i<m; i++){
        if(s[i] != s[n-i-1]){
            ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static Scanner scan  = new Scanner(System.in);
    public static void main(String[]args){
        int n,m;
        n=nextInt();
        m=nextInt();
        int[] arr = new int[m];
        for(int i=0;i<m;i++){
            arr[i]=nextInt();
        }
        int sum =0;
        for(int a:arr){
            sum+=a;
        }
        int tmp = n-sum;
        if(tmp<0){
            print(-1);
        }
        else print(tmp);
    }



    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }
    public static void print(Object a){
        System.out.println(a);
    }
}

Measured memory_bytes: 41944
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

static constexpr int MAX = 100001;

int main() {
  int n;
  vector<int> imos(MAX, 0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a,b;
    cin >> a >> b;
    for (int i = a; i <= b; ++i) {
      imos[i] += 1;
    }
  }
  int mmax = 0, m = -1;
  for (int i = 2; i <= MAX; ++i) {
    if (i - 1 <= imos[i]) {
      mmax = i - 1;
    }
  }

  cout << mmax << endl;
}



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

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

    //freopen("input.txt","r",stdin);

    long long n,c=0;
    cin>>n;
    long long a[n];
    for(long long i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    for(long long i=0;i<n-2;i++){
        for(long long j=i+1;j<n-1;j++){
            for(long long k=j+1;k<n;k++){
                if(a[i]+a[j] > a[k]
                   && a[i] + a[k] > a[j]
                   && a[k] + a[j] > a[i]
                   && a[i]!=a[j]
                   && a[j]!=a[k]
                   && a[k]!=a[i])c++;
            }
        }
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  ll ans = 0;
  for(int i=1;i<=n;i++){
    ll d = n/i;
    d = (d*(d+1))/2;
    ans += d*i;
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

void solve()
{
	ll s, w;
	cin >> s >> w;
	if (w >= s)
		cout << "unsafe" << ln;
	else
		cout << "safe" << ln;
	return;
}

int main()
{
	FASTIO;
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve();
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 3636
#define USE_MATH_DEFINES 1
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 998244353ll
#define INF 1000000000000000000ll
#define EPS 1e-9

#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock

typedef long long         ll;
typedef long double       ld;
typedef pair <ll,ll>      pl;
typedef tuple <ll,ll,ll>  tl;

ll N, V[3], M[100005];
string S[100005];

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> N >> V[0] >> V[1] >> V[2];
	for (ll i = 1; i <= N; i++) cin >> S[i];
	
	for (ll i = 1; i <= N; i++) {
		ll x, y;
		if (S[i] == "AB") {
			x = 0;
			y = 1;
		} else if (S[i] == "AC") {
			x = 0;
			y = 2;
		} else if (S[i] == "BC") {
			x = 1;
			y = 2;
		}
		if (V[x] <= 0 && V[y] <= 0) {
			cout << "No";
			return 0;
		} else if (V[x] > V[y]) {
			M[i] = y;
			V[x]--;
			V[y]++;
		} else if (V[x] < V[y] || i == N) {
			M[i] = x;
			V[x]++;
			V[y]--;
		} else {
			ll p, q;
			if (S[i+1] == "AB") {
				p = 0;
				q = 1;
			} else if (S[i+1] == "AC") {
				p = 0;
				q = 2;
			} else if (S[i+1] == "BC") {
				p = 1;
				q = 2;
			}
			V[x]++;
			V[y]--;
			if (V[p] <= 0 && V[q] <= 0) {
				M[i] = y;
				V[x] -= 2;
				V[y] += 2;
			} else {
				M[i] = x;
			}
		}
	}
	
	cout << "Yes\n";
	for (ll i = 1; i <= N; i++) {
		if (M[i] == 0) cout << "A\n";
		else if (M[i] == 1) cout << "B\n";
		else cout << "C\n";
	}
	
    return 0;
}

Measured memory_bytes: 7568
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
bool check(int n){
    if((n/100)%10==(n/10)%10 and (n/100)%10==n%10 and (n/10)%10==n%10){
        return true;
    }else return false;
}
int main(void){
    int n;
    cin>>n;
    int ans=0;
    for(int i=n;i<=999;i++){
        if(check(i)){
            ans=i;
            break;
        }
    }
    cout<<ans<<endl;
 return 0;   
}

Measured memory_bytes: 256
#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>
#include <numeric>

using namespace std;

template <typename T>
using TABLE = vector<vector<T>>;

using LONG = long long;
using LVEC = vector<long long>;

#define FOR(_i, s, e) for(_i = s; _i < e; ++_i)
#define FOR_INV(_i, s, e) for(_i = e - 1; _i >= s; --_i)

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;


using pos = std::pair<LONG, LONG>;


int main(){
    LONG N, M, Q;
    cin >> N >> M >> Q;

    vector<LVEC> sum(N + 1, LVEC(N+1, 0));
    LONG L, R;
    LONG i, j;

    FOR(i, 0, M){
        cin >> L >> R;
        sum[L][R] += 1;
    }


    FOR(i, 0, N){
        FOR(j, 0, N){
            sum[i+1][j+1] = sum[i+1][j+1] + sum[i][j+1] + sum[i+1][j] - sum[i][j];
//            cout << sum[i+1][j+1] << " ";
        }

//        cout << endl;
    }



    LVEC result(Q, 0);
    FOR(i, 0, Q){
        cin >> L >> R;
        result[i] = sum[R][R] - sum[L-1][R];
    }

    FOR(i, 0, Q){
        cout << result[i] << endl;
    }
}




Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <bitset>
using namespace std;
int main(){
    long long N, K;
    cin >> N >> K;
    vector<long long> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    vector<long long> sum(N + 1, 0);
    for(int i = 1; i < N + 1; i++) sum[i] = sum[i - 1] + a[i - 1];
    vector<long long> bit(45, 0);
    vector<long long> t;
    for(int i = 1; i < N + 1; i++){
        for(int j = 0; j < i; j++){
            long long temp = sum[i] - sum[j];
            t.push_back(temp);
            int c = 0;
            while(temp > 0){
                if(temp & 1) bit[c]++;
                temp >>= 1;
                c++;
            }
        }
    }
    long long ans = 0;
    while(1){
        long long ind = 0;
        vector<long long> res;
        vector<long long> tbit(45, 0);
        int flag = 0;
        for(int i = 0; i < 45; i++){
            if(bit[44 - i] >= K) {
                ind = 44- i;
                ans ^= (1LL << ind);
                flag = 1;
                break;
            }
        }
        if(flag == 0) break;
        for(int i = 0; i < t.size(); i++){
            if(t[i] & (1LL << ind)){
                t[i] ^= (1LL << ind);
                res.push_back(t[i]);
            }
        }
        for(int i = 0; i < res.size(); i++){
            long long s = res[i];
            long long c = 0;
            while(s > 0){
                if(s & 1) tbit[c]++;
                s >>= 1;
                c++;
            }
        }
        t = res;
        bit = tbit;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6516
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll K; cin >> K;
    ll i = 7;
    ll cnt = 1;
    ll M = i % K;
    while (1) {
        if (M == 0) break;
        M = (M * 10 + 7) % K;
        cnt++;
        if (cnt > K) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3588
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(P: int, Q: int, R: int):
    return sum([P, Q, R]) - max(P, Q, R)

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    P = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    result = solve(P, Q, R)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5948
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int dsum(ll n) {
  int result = 0;
  while (n!=0) {result+=n%10; n/=10;}
  return result;
}

int main() {
  int K; cin >> K;
  rep(i,min(K,9)) { cout << i+1 << endl; }
  if (K<=9) return 0;
  K -= 9;
  ll result = 9, digsum = 9;
  rep(i,K) {
    ll r = result, d = digsum;
    for (int dig = 0; pow(10,dig)<=r; dig++) {
      ll tr = ceil(r/pow(10,dig+1)+1)*pow(10,dig+1)-1;
      ll td = 0; for (ll tmp = tr; tmp>0; tmp/=10) td += tmp%10;
      if (dig==0||result*td>=tr*digsum) { result = tr; digsum = td; }
      // cout << tr << " " << td << endl;
    }
    cout << result << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A;
  int64_t B,N;
  cin >> A >> B >> N;
  int ans=0;
  if(B>N){
    cout << int(A*N/B) << endl;
  }else if(B==N){
    cout << max(int(A*(N-1)/B),int(A*N/B)-A*int(N/B)) << endl;
  }else{
    cout << max( int(A*(int(N/B)*B-1)/B)-A*int((int(N/B)*B-1)/B) ,int(A*N/B)-A*int(N/B)) << endl;
  }



}



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

using namespace std;
using ll = long long;

void solve(){
	int n;
	cin >> n;
	vector<int> a(n+1);
	for(int i=1;i<=n;++i) cin >> a[i];
	ll dp[n+1][2];
	memset(dp,0,sizeof dp);
	dp[2][1] = a[2];
	dp[2][0] = a[1];
	for(int i=3;i<=n;++i){
		if(i&1){
			ll temp = max({dp[i-3][1],dp[i-3][0],dp[i-2][1],dp[i-2][0]});
			dp[i][1] = a[i]+temp;
			dp[i][0] = max({a[i-1]+dp[i-2][0],a[i-1]+dp[i-3][1],a[i-1]+dp[i-3][0],a[i-2]+dp[i-3][0]});		
		}
		else{
			dp[i][1] = a[i] + max({dp[i-2][1],dp[i-2][0],dp[i-1][0]});
			dp[i][0] = a[i-1]+dp[i-2][0];
		}
	}
	cout << max(dp[n][1], dp[n][0]) << '\n';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin >> t;
	while(t--){ 
		solve();
	}
	return 0;
}

Measured memory_bytes: 7128
#include<stdio.h>
int main()
{
    char c[4][4];
    int i;
    for (i = 0; i < 3; i++)
        scanf("%s", &c[i]);
    for (i = 0; i < 3; i++)
        printf("%c", c[i][i]);
    printf("\n");
    return 0;
}

Measured memory_bytes: 128