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

using namespace std;

int calc(int n);

int main()
{
    int N;
    int A;
    int num;

    cin >> N;

    for(int i=0; i<N; i++){
        cin >> A;

        int a = calc(A);

        if(i == 0){
            num = a;
        }
        else if(num > a){
            num = a;
        }
    }

    cout << num << endl;
}

int calc(int n)
{
    int ans = 0;

    while(true){
        int s = n % 2;

        if(s != 0){
            break;
        }

        n /= 2;
 
        ans++;
    }

    return ans;
}

Measured memory_bytes: 256
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#define inf (1<<28)
#define ll long long
#define db double
#define c233 cout<<"233"<<endl
#define mem(s) memset(s,0,sizeof(s))
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
const int N=205;
const int M=1050;
using namespace std;

int l[N][N],s[N][N],dp[M][N],way[M];
int n,m,r,ans;

void fre(){
  freopen("in","r",stdin);
  freopen("out","w",stdout);
}

inline int gi(){
  int x=0,res=1;char ch=getchar();
  while(ch>'9'||ch<'0'){if(ch=='-')res*=-1;ch=getchar();}
  while(ch<='9'&&ch>='0')x=(x<<1)+(x<<3)+ch-48,ch=getchar();
  return x*res;
}

void init(){
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
      l[i][j]=s[i][j]=inf;
  for(int i=1;i<=n;i++)
    l[i][i]=s[i][i]=0;
  for(int i=1;i<=m;i++){
    int a,b,c;
    char d;
    scanf("%d%d%d %c",&a,&b,&c,&d);
    if(d=='L')l[a][b]=l[b][a]=min(l[a][b],c);
    if(d=='S')s[a][b]=s[b][a]=min(s[a][b],c);
  }
  r=gi();
  for(int i=1;i<=r;i++)
    way[i]=gi();
}

void pre(){
  for(int k=1;k<=n;k++)
    for(int i=1;i<=n;i++)
      for(int j=1;j<=n;j++){
	l[i][j]=min(l[i][j],l[i][k]+l[k][j]);
	s[i][j]=min(s[i][j],s[i][k]+s[k][j]);
      }
  for(int i=1;i<=r;i++)
    for(int j=1;j<=n;j++)
      dp[i][j]=inf;
  ans=inf;
}

void work(){
  dp[1][way[1]]=0;
  for(int i=2;i<=r;i++)
    for(int j=1;j<=n;j++){
      dp[i][j]=min(dp[i][j],dp[i-1][j]+l[way[i-1]][way[i]]);
      for(int k=1;k<=n;k++)
	dp[i][j]=min(dp[i][j],dp[i-1][k]+l[way[i-1]][k]+s[k][j]+l[j][way[i]]);
    }
  for(int i=1;i<=n;i++)
    ans=min(ans,dp[r][i]);
  printf("%d\n",ans);
}

int main(){
  //fre();
  while(1){
    n=gi();m=gi();
    if(n==0&&m==0)break;
    init();
    pre();
    work();
  }
  return 0;
}

Measured memory_bytes: 4276
from collections import deque
def bfs(start, g, visited, goal):
    q = deque([start])
    visited[start] = 0
    while q:
        curr_node = q.popleft()
        for next_node in g[curr_node]:
            if visited[next_node] >= 0: continue
            visited[next_node] = visited[curr_node] + 1
            if next_node == goal: return
            q.append(next_node)


n,m = map(int, input().split())
g = [ [] for _ in range(3*n)]

for _ in range(m):
    u,v = map(int, input().split())
    g[u*3-3].append(v*3-2)
    g[u*3-2].append(v*3-1)
    g[u*3-1].append(v*3-3)

s,t = map(int, input().split())
visited = [-3]*(3*n)
bfs(s*3-3, g, visited, t*3-3)
print(visited[t*3-3]//3)

Measured memory_bytes: 106352
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int X = sc.nextInt();
    
    if(A>X){
    System.out.println("NO");        
    }else if(A+B>=X){
    System.out.println("YES");
    }else{
    System.out.println("NO");    
    }
}
    }


Measured memory_bytes: 35896
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var firstLine = Console.ReadLine().Split(' ').Select(value => long.Parse(value)).ToList();
			var n = firstLine[0];
			var x = firstLine[1];
			var aList = Console.ReadLine().Split(' ').Select(value => long.Parse(value)).ToList();

			long operation = 0;

			for(int i = 1; i < n; i++)
			{
				var sum = aList[i - 1] + aList[i];
				if (sum > x)
				{
					var diff = sum - x;
					operation += diff;

					if(aList[i] >= diff)
					{
						aList[i] -= diff;
					}
					else
					{
						diff -= aList[i];
						aList[i] = 0;
						aList[i - 1] -= diff;
					}
				}
			}

			Console.WriteLine(operation);
		}
	}
}


Measured memory_bytes: 26588
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  ll N, M; cin >> N >> M;
  cout << (1900*M+100*(N-M))*(ll)pow(2, M) << endl;
}

Measured memory_bytes: 256
#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 ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
 
void solve(){
    ll a, b, c;
    cin >> a >> b >> c;
    // k a % b == c
    // ka = m * b + c
    for(ll i = 1; i <= 1e7  +1233; ++i) {
        if((i * a) % b == c) {
            cout << "YES";
            return;
        }
    }
    cout << "NO";
}
 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

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

typedef long long ll;

void solve()
{
	int n;
	cin >> n;
	int a,ans = 0;
	for (int i= 0; i < n; i++)
	{
		cin >> a;
		if (i % 2 == 0 && a % 2)
			ans++;
	}
	cout << ans;
}

int main()
{

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

	ios_base::sync_with_stdio(false);
	cin.tie(0);

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




Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;
 
int main(){
    int n;
    cin>>n;
    for (int i=1; i <= n; i++) {
        if (n == 1) cout<<1<<endl;
        else if (i*i > n) {
            cout<<(i-1)*(i-1)<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();

        List<Pair> pairs = new List<Pair>();
        for (int i = 0; i < n; i++)
        {
            pairs.Add(new Pair() { index = i, order = a[i] });
        }

        pairs.Sort((x, b) => x.order - b.order);

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++)
        {
            if (i == n - 1)
            {
                sb.Append($"{pairs[i].index + 1}");
                break;
            }
            sb.Append($"{pairs[i].index + 1} ");
        }

        Console.WriteLine(sb.ToString());
    }

    class Pair {
        public int index;
        public int order;
    }
}


Measured memory_bytes: 32596
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const ll INF = 1e18 + 10;

ll A, B, C, D;
ll num(ll n, ll c, ll d) {
    ll G = __gcd(c,d);
    ll L = c / G *d;
    return n - n/c - n/d + n/L;
}

int main() {
    cin >> A >> B >> C >> D;
    cout << num(B,C,D) - num(A-1,C,D) << endl;
}

Measured memory_bytes: 3576
def main():
    n, m = map(int, input().split())
    a_lst = list(map(int, input().split()))
    total = sum(a_lst)
    cnt = 0

    for a in a_lst:
        if a * 4 * m >= total:
            cnt += 1

    if cnt >= m:
        ans = "Yes"
    else:
        ans = "No"

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61392
import java.util.*;

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

        if(a < 1200){
            System.out.println("ABC");
        } else {
            System.out.println("ARC");
        }
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


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

using ll = long long;
#define double long double
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x, c) for (auto&& x : (c))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))
#define endl _endl
const char _endl = (cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout.precision(16), '\n');

int main() {
  ll n, m;
  cin >> n >> m;
  cout << (n - 1) * (m - 1) << endl;
}


Measured memory_bytes: 3560
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main{

	static int N;
	static int M;
	static 		ArrayList<ArrayList<Integer>> map;
	static boolean[] used;
	static int f = 0;
	static int s = 0;

	static long mod = 1000000007;
	static ArrayList<Integer> saitan;




	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);			//文字の入力
		String string = sc.next();
		char[] cs = string.toCharArray();
		Arrays.sort(cs);
		for(int i = 0;i < string.length()-1;i++){
			if(cs[i] == cs[i+1]){
				System.out.println("no");
				return;
			}
		}
		System.out.println("yes");







	}
	static int lowerbond(int k, int[] data){		//kより小さい最小の値をdataの中から探し、返す二分探索
		int min = -1;
		int max = data.length;

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data[mid] >= k){
				max = mid;
			}else{
				min = mid;
			}
		}
		return data[max];
	}


	static long cal(int n){
		long x = (long)n;
		for(int i = n-1;i > 0;i--){
			//	System.out.println(i);
			x *= i;
			x %= mod;
		}
		return x;
	}

}




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

int main() {
  int K, A=0;
  long long X;
  cin >> K;
  queue<long long> Q;
  rep(i, 9) Q.push(i+1);
  rep(i, K-1){
    X=Q.front();
    if(X%10!=0) Q.push(10*X+X%10-1);
    Q.push(10*X+X%10);
    if(X%10!=9) Q.push(10*X+X%10+1);
    Q.pop();
  }
  cout << Q.front() << endl;
}

Measured memory_bytes: 1792
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(tmp[0],10);
	var b = parseInt(tmp[1],10);
	var c = parseInt(tmp[2],10);
	if(b-a===c-b){
    	s="YES";
    }
  	else{
    	s="NO";	
    }
    
  	
  	
	//出力
	console.log('%s',s);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
n,k=map(int,input().split())
mod=10**9+7
ans=0
a=0
b=0
for i in range(k):
    a+=n-i
    b+=i
for i in range(k,n+2):
    ans+=(a-b+1)
    ans%=mod
    a+=n-i
    b+=i
print(ans)


Measured memory_bytes: 64204
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

n, m, s = map(int, input().split())
uvab = [list(map(int, input().split())) for _ in range(m)]
cd = [list(map(int, input().split())) for _ in range(n)]

AMAX = 50
NODE_MAX = AMAX * (n - 1)
N = (NODE_MAX + 1) * n

U = []
V = []
C = []

for u, v, a, b in uvab:
    u -= 1
    v -= 1
    u *= NODE_MAX + 1
    v *= NODE_MAX + 1
    for i in range(NODE_MAX + 1 - a):
        U.append(u + i + a)
        V.append(v + i)
        C.append(b)
        U.append(v + i + a)
        V.append(u + i)
        C.append(b)


for i, (c, d) in enumerate(cd):
    base = i * (NODE_MAX + 1)
    for j in range(NODE_MAX):
        nxt = base + min(j + c, NODE_MAX)
        frm = base + j
        U.append(frm)
        V.append(nxt)
        C.append(d)

g = csr_matrix((C, (U, V)), shape=(N, N))
dist = dijkstra(g, indices=min(s, NODE_MAX)).astype(int)
dist[dist < 0] = dist.max()
for i in range(1, n):
    base = i * (NODE_MAX + 1)
    ans = dist[base:base+NODE_MAX+1].min()
    print(ans)



Measured memory_bytes: 112972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	ll wa = 0;
	cin >> n;
	map<ll,ll> m;
	m[wa]++;
	ll ans = 0;
	FOR(i,0,n){
		ll k;
		cin >> k;
		wa += k;
		ans += m[wa];
		m[wa]++;
	} 
	cout << ans << endl;
}

Measured memory_bytes: 12800
def main():
    N = int(input())
    t_x_ys = []
    for _ in range(N):
        t_x_ys.append(list(map(int, input().split())))
    
    t_x_yi_minus_1 = [0, 0, 0]
    for t_x_yi in t_x_ys:
        ti_minus_1, xi_minus_1, yi_minus_1 = t_x_yi_minus_1
        ti, xi, yi = t_x_yi
        delta_t = ti - ti_minus_1
        dis = abs(xi - xi_minus_1) + abs(yi - yi_minus_1)

        if delta_t < dis:
            print("No")
            return 
        elif delta_t == dis:
            t_x_yi_minus_1 = t_x_yi
            continue
        else:
            if (dis - delta_t) % 2:
                print("No")
                return 
            else:
               t_x_yi_minus_1 = t_x_yi
               continue
             
    print("Yes")

main()

Measured memory_bytes: 27324
from copy import deepcopy, copy
class QueenMAP():
    __slots__ = ["yoko", "tate", "naname1", "naname2", "MAP"]
    def __init__(self):
        self.yoko = set()
        self.tate = set()
        self.naname1 = set()
        self.naname2 = set()
        self.MAP = [["."] * 8 for _ in range(8)]
    def add(self, y, x):
        self.MAP[y][x] = "Q"
        self.yoko.add(y)
        self.tate.add(x)
        self.naname1.add(y - x)
        self.naname2.add(x + y)
    def check(self, y, x):
        if x in self.tate or (y - x) in self.naname1 or (x + y) in self.naname2:
            return False
        return True
    def allcheck(self):
        for i in range(8):
            if not "Q" in self.MAP[i]:
                return False
        return True
def MAIN():
    f = lambda M: "\n".join("".join(map(str, m)) for m in M)
    QM = QueenMAP()
    n = int(input())
    for _ in range(n):
        a, b = map(int, input().split())
        QM.add(a, b)
    dp = [(deepcopy(QM), n)]
    while dp:
        Q, cnt = dp.pop()
        if cnt == 8:
            if Q.allcheck():
                print(f(Q.MAP))
                break
            continue
        cnt += 1
        for i in range(8):
            if i in Q.yoko:
                continue
            for j in range(8):
                if Q.check(i, j):
                    CQ = deepcopy(Q)
                    CQ.add(i, j)
                    dp.append((CQ, cnt))
MAIN()



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

bool judge(int y){
  if(y%400==0)return true;
  if(y%100==0)return false;
  if(y%4==0)return true;
  return false;
}

int main(){
  int a, b, n=0;
  while(true){
    bool flag=true;
    cin>>a>>b;
    if(a==0&&b==0)break;
    if(n!=0)cout<<endl;
    for(int i=a; i<=b; i++){
      if(judge(i)){cout<<i<<endl; flag=false;}
    }
    if(flag)cout<<"NA"<<endl;
    n++;
  }
  return 0;
}

Measured memory_bytes: 1160
from collections import Counter
n = int(input())
v = [i for i in map(int, input().split())]
v_e, v_o = v[0::2], v[1::2]
cnt_e, cnt_o = Counter(v_e), Counter(v_o)
val_e, val_o = list(cnt_e.values()), list(cnt_o.values())
val_e.sort()
val_o.sort()
val_e, val_o = val_e[::-1], val_o[::-1]
cnt_e = sorted(cnt_e.items(), key=lambda x:x[1])[::-1]
cnt_o = sorted(cnt_o.items(), key=lambda x:x[1])[::-1]
key_e, key_o = cnt_e[0][0], cnt_o[0][0]
if key_e == key_o:
    if len(val_e) == len(val_o) == 1:
        print(n // 2)
    elif len(val_e) == 1:
        print(n // 2 - val_o[1])
    elif len(val_o) == 1:
        print(n // 2 - val_e[1])
    else:
        print(min(n - val_e[0] - val_o[1], n - val_e[1] - val_o[0]))
else:
    if len(val_e) == len(val_o) == 1:
        print(0)
    elif len(val_e) == 1:
        print(n // 2 - val_o[0])
    elif len(val_o) == 1:
        print(n // 2 - val_e[0])
    else:
        print(n - val_o[0] - val_e[0])

Measured memory_bytes: 19644
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1 , number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1 , number1);
    }
}

ll i,j,k,ii,jj,n,m,a,b,c,d,e,f,g,h,r,w,l;
ll num,ans,sum,ok,ng;
ll x[500005],y[500005],z[500005];
ll dp[5005][5005];
char s[500005],t[500005],u[500005];
bool dame,flag;

int main(){
	cin >> n;
	for(i=0;i<n;i++){
		cin >> x[i];
	}
	for(i=0;i<n;i++){
		dp[i][1] = x[i];
	}
	for(j=1;j<n;j++){
		for(i=0;i<n+1-j;i++){
			a = x[i+j] - dp[i][j];
			b = x[i] - dp[i+1][j];
			dp[i][j+1] = max(a,b);
		}
	}
	p(dp[0][n]);
	return 0;
}

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

using namespace std;

typedef long long ll;

void cldflm()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);

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

int main()
{

	cldflm();

	int n, d, cnt = 0;
	cin >> n >> d;
	while (n--)
	{
		ll x, y;
		double var;
		cin >> x >> y;
		var = sqrt(x * x + y * y);
		if (var <= d)
			cnt++;

	}

	cout << cnt;


	return 0;
}



Measured memory_bytes: 3696
n,x = map(int,input().split())
l = [int(i) for i in input().split()]
xg = [0]*(n+1)
for i in range(n):
    xg[i+1] = l[i] + xg[i]
count = 0
for i in xg:
    if i <= x:
        count += 1
print(count)

Measured memory_bytes: 38384
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
#include <utility>
#include <queue>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

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

ll fact(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    return n * fact(n - 1) % MOD;
}

int main()
{
    ll a, b, x;
    cin >> a >> b >> x;
    if (a == 0) {
        cout << (b/x) + 1 << endl;
    } else {
        cout << (b / x) - ((a - 1LL) / x) << endl;
    }
}

Measured memory_bytes: 256
N = int(input())
T,A = map(int,(input().split()))
H = list(map(int,(input().split())))
nim = 1000000000
for i in range(N):
    H[i] = abs(T-H[i]*0.006 - A)
    if H[i] <= nim:
        nim = H[i]
        ans = i+1
print(ans)

Measured memory_bytes: 38384
def main():
    from bisect import bisect_left
    n=int(input())
    l=list(map(int,input().split()))
    l.sort()
    ans=0
    for i in range(n-2):
        for j in range(i+1,n-1):
            ans+=bisect_left(l,l[i]+l[j])-j-1
    print(ans)
if __name__=="__main__":
    main()

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

const ll inf = 1e18;
int N , W;
ll w[105] , v[105];
ll DP[100005];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> W;
    for(int i = 1; i <= 100000; ++i)DP[i] = inf;
    for(int i = 1; i <= N; ++i){
        cin >> w[i] >> v[i];
    }
    for(int i = 1; i <= N; ++i){
        for(int j = 100000; j >= 0; --j){
            if(j - v[i] >= 0)
                DP[j] = min(DP[j] , DP[j - v[i]] + w[i]);
        }
    }
    int ret = 0;
    for(int i = 0; i <= 100000; ++i){
        if(DP[i] <= W){
            ret = max(ret , i);
        }
    }
    cout << ret << endl;
}


Measured memory_bytes: 1024
X = int(input())
A = 1
for i in range(2, X):
  if A == X:
    print(A)
    exit()
  j = 2
  t = i ** j
  while i ** j <= X:
    if i ** j > A:
      A = i ** j
    else:
      j += 1
print(A)

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }

    if (n % 2 == 0) {
        for (int i = n - 1; i >= 1; i -= 2) {
            cout << a.at(i) << " ";
        }
        for (int i = 0; i < n; i += 2) {
            cout << a.at(i) << " ";
        }
    }
    else {
        for (int i = n - 1; i >= 0; i -= 2) {
            cout << a.at(i) << " ";
        }
        for (int i = 1; i < n; i += 2) {
            cout << a.at(i) << " ";
        }
    }
    cout << endl;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long 
#define pb push_back
#define fo(i,N) for(int i = 0 ; i < N ; i++)
#define foo(i,x,N) for (int i = x; i < N ; i++)
#define fill(a,val) memset(a,val,sizeof(a))
#define fastio()  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'
#define ff first
#define ss second
#define MAX 1234567
#define pii pair<int,int> 
#define pll pair<ll,ll> 
#define all(a) a.begin(),a.end()

int dp[100005];
int arr[100005];
int n,k;

ll solve()
{ 
  
  dp[0] = 0;

  
  for(int i = 1 ; i < k ; i++)
  { 
    dp[i] = INT_MAX;

    for(int j = 0 ; j < i ; j++)
    { 
       dp[i] = min(dp[i],dp[j]+abs(arr[i]-arr[j]));
    }
  }
    for(int i = k ; i < n ; i++)
    {  dp[i] = INT_MAX;
      for(int j = i-k; j < i ; j++)
      {
        dp[i] = min(dp[i],dp[j]+abs(arr[i]-arr[j]));
      }
    }

    return dp[n-1];

}

int main()
{ 
  cin >> n >> k;
  fo(i,n)
  cin >> arr[i];
  fill(dp,-1);

  cout << solve() << endl;
 
        

}

    

  




Measured memory_bytes: 1024
/**Bismillahir Rahmanir Rahim.**/
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include <bits/stdc++.h>
using namespace std;
#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  ll               long long
#define  vi               std::vector<int>
#define  pb               push_back
#define  MAX              100007
#define  End              return 0;
#define  pi               acos(-1)

int main () {
    ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
    int T=1; // cin>>T;
    while(T--){
        ll a,b;
        cin>>a>>b;
        ll ans=a*b;
        cout<<ans<<endl;
    }
    End
}
/* pray for me
Do before die
*/



Measured memory_bytes: 3636
/********************************************************************************
	
	Code by a weak man who named CYJian, and he hopes the code can get more points.

	Algorithm: 

 ********************************************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

//{{{ FAST IO AND SOME FUNCTIONS
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define ra read_alpha()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline char read_alpha() { char c = ge; while(!isalpha(c) && c != EOF) c = ge; return c; }
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T> inline void chkmin(T&a, T b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T&a, T b) { a = a > b ? a : b; }
//}}}

const int MAXN = 1010;
const int MAXM = 200010;

struct Edge {
	int u, v;

	Edge() {}
	Edge(int u, int v):u(u), v(v) {}
}E[MAXM];

vector<int>to[MAXN];

int Mark[MAXN];
bitset<MAXN>vis;
bool G1[MAXN][MAXN];
bool G2[MAXN][MAXN];

inline void dfs1(int x, int st) {
	G1[st][x] = 1, vis.set(x);
	for(auto u : to[x]) if(!vis[u]) dfs1(u, st);
}

inline void dfs2(int x, int col, int k, int st) {
	if(k) G2[st][x] = Mark[x] != col;
	else Mark[x] = col; vis.set(x);
	for(auto u : to[x]) if(!vis[u]) dfs2(u, col, k, st);
}

int main() {
#ifdef LOCAL
	FILE("");
#endif
	int n = ri, m = ri;
	for(int i = 1; i <= m; i++) {
		int u = ri, v = ri;
		to[u].push_back(v);
		E[i] = Edge(u, v);
	}
	for(int i = 1; i <= n; i++) vis.reset(), dfs1(i, i);
	for(int i = 1; i <= n; i++) {
		vis.reset(), vis.set(i);
		memset(Mark, 0, sizeof(Mark));
		int d = to[i].size();
		for(int j = 0; j < d; j++) if(!vis[to[i][j]]) dfs2(to[i][j], j + 1, 0, i);
		vis.reset(), vis.set(i);
		for(int j = d - 1; ~j; --j) if(!vis[to[i][j]]) dfs2(to[i][j], j + 1, 1, i);
	}
	/*
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			printf("%d%c", G1[i][j], " \n"[j == n]);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			printf("%d%c", G2[i][j], " \n"[j == n]);
	*/
	for(int i = 1; i <= m; i++)
		puts(G1[E[i].v][E[i].u] ^ G2[E[i].u][E[i].v] ? "diff" : "same");
	return 0;
}

Measured memory_bytes: 6528
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int inf = 1e9+7;
const int N = 1e6+9;

void solve() {
    int a, b, n, m;
    cin>>n;
    ll s=0;
    map<ll, ll> mp;
    for(int i=0;i<n;++i) {
        cin>>a;
        mp[a]++;
        s+=a;
    }
    cin>>m;
    while(m--) {
        cin>>a>>b;
        ll x = mp[a];
        mp[a]=0;
        mp[b]+=x;

        ll p = x*a;
        ll q = x*b;
        if(b>=a) {
            ll d = b-a;
            s += x*d;
        }
        else {
            ll d = a-b;
            s -= x*d;
        }
        cout<<s<<endl;
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    int T=1 ,cas=0;
    while(T--) {
        solve();
    }
    return 0;
}

// ll, reset, 1, bottom

Measured memory_bytes: 9508
n = int(input())
s = input()

left_blacks = [0] * (n + 1)
right_whits = [0] * (n + 1)
for i in range(n):
    left_blacks[i+1] = left_blacks[i] + 1 if s[i] == "#" else left_blacks[i]

for i in range(n, 0, -1):
    right_whits[i-1] = right_whits[i] + 1 if s[i-1] == "." else right_whits[i]

ans = 9999999999999999999
for i in range(n+1):
    ans = min(ans, left_blacks[i] + right_whits[i])

print(ans)

Measured memory_bytes: 12808
def solve() :
    a, b = input().split()

    a = int(a)
    b = b.replace('.', '')
    b100 = int(b[0])*100 + int(b[1])*10 + int(b[2])

    print(a*b100//100)
    return


if __name__ == "__main__" :
    solve()

Measured memory_bytes: 61772
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
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;
}
const int mod = 998244353;
int main(){
    int N;
    cin>>N;
    vector<ll> D(N);
    rep(i,N) cin>>D[i];
    if(D[0]!=0){
        cout<<0<<endl;
        return 0;
    }
    sort(D.begin(),D.end());
    ll a=0;
    map<int,int> cnt;
    rep(i,N) cnt[D[i]]++;
    ll ans = 1;
    for(int i=1; i<N; i++){
        //D[i]-1が親なのでそうする
        ans = ans * cnt[D[i]-1];
        ans %= mod;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5760
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

ll dp[200100][4];

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  vll as(n);
  rep(i,n) cin >> as[i];

  rep(i,n+1) rep(j, 4) dp[i][j] = -INF;
  dp[0][0] = 0;
  rep(i, n){
    rep(j, 3){
      chmax(dp[i+1][j+1], dp[i][j]);
      ll tmp = dp[i][j];
      if((i+j)%2==0) tmp += as[i];
      chmax(dp[i+1][j], tmp);
    }
  }

  ll k = 1+n%2;
  cout << dp[n][k] << endl;

  return 0;
}


Measured memory_bytes: 11180
from collections import deque
N, Q = list(map(int, input().split()))
S = [set() for _ in range(N)]
for _ in range(N-1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    S[a].add(b)
    S[b].add(a)
node = [0]*N
for _ in range(Q):
    t, v = list(map(int, input().split()))
    t -= 1
    node[t] += v

seen = [False]*N
stk = deque([(0, 0)])
while stk:
    t, v = stk.pop()
    seen[t] = True
    node[t] += v
    s = S[t]
    for k in s:
        if not seen[k]:
            stk.appendleft((k, node[t]))
print(*node)


Measured memory_bytes: 177924
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    cout << (N <= 999 ? "ABC" : "ABD") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mx 100000
#define md 1000000007ll
#define prMX 10000000
ll prime[prMX+2];
bool vis[prMX+2];
#define MX 10000000000000ll

int main(){

    int n,m;
    cin>>n>>m;
    int ar[n+2];
    memset(ar,0,sizeof ar);

    for(int i=1;i<=m;i++){
        int x,y;
        cin>>x>>y;
        ar[x]++;
        ar[y+1]--;
    }
   int ans =0;
    for(int i=1;i<=n;i++){
        ar[i]+=ar[i-1];
        if(ar[i]==m)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	vector<ll> m(2);
  vector<ll> d(2);
  rep(i,2){
    cin>>m[i]; m[i];
    cin>>d[i]; d[i];
  }
	cout<<(m[0]!=m[1]) NL;
	return 0;
}


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

#define NIL -1
#define MAX 100001
struct Node {int parent, left, right;};
struct Node tree[MAX];
int Depth[MAX];
int Height[MAX];

int SiblingCheck(int u){
  if (tree[u].parent == NIL) {
       return NIL;
   }
   if (tree[tree[u].parent].left != u && tree[tree[u].parent].left != NIL) {
       return tree[tree[u].parent].left;
   }
   if (tree[tree[u].parent].right != u && tree[tree[u].parent].right != NIL) {
       return tree[tree[u].parent].right;
   }

   return NIL;
}

int HeightCheck(int u) {
    int h1 = 0, h2 = 0;
    if (tree[u].left != NIL) {
        h1 = HeightCheck(tree[u].left) + 1;
    }
    if (tree[u].right != NIL) {
        h2 = HeightCheck(tree[u].right) + 1;
    }
    return Height[u] = max(h1, h2);
}

void DepthCheck(int u, int d){
  if (u == NIL) return;

    Depth[u] = d;

    DepthCheck(tree[u].left, d + 1);
    DepthCheck(tree[u].right, d + 1);
}

int CheckDeg(int u){
  int deg;
  if (tree[u].left != NIL) deg++;
  if (tree[u].right != NIL) deg++;
  return deg;
}

void nodePrint(int u){
  cout << "node " << u << ": ";
  cout << "parent = " << tree[u].parent << ", ";
  cout << "sibling = " << SiblingCheck(u) << ", ";
  cout << "degree = " << CheckDeg(u) << ", ";
  cout << "depth = " << Depth[u] << ", ";
  cout << "height = " << Height[u] << ", ";

  if (tree[u].parent == NIL) cout << "root" << "\n";
  else if (tree[u].left == NIL && tree[u].right == NIL) cout << "leaf" << "\n";
  else cout << "internal node" << "\n";
}

int main(){
  int i, j, n, id, c, ri, r;
  cin >> n;
  for (i = 0; i < n; i++) {
    tree[i].parent = tree[i].left = tree[i].right = NIL; //初期値
  }
  for (i = 0; i < n; i++){
    cin >> id;
    for (j = 0; j < 2; j++){
      cin >> c;
      if (j == 0) tree[id].left = c;
      else tree[id].right = c;
      // ri = c;
      if (c != NIL) tree[c].parent = id;
    }
  }
  for (i = 0; i < n; i++){
    if (tree[i].parent == NIL) r = i;
  }

  // cout << "rの値" << r;
  DepthCheck(r, 0);
  HeightCheck(r);
  for (i = 0; i < n; i++) nodePrint(i);

  return 0;
}



Measured memory_bytes: 3128
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#define rep(i, n) for (int i=0; i<(n); i++)
using namespace std;

int main(){
    int N; cin >> N;
    long long count[200005]={}, pair[200005]={}, sum=0;
    vector<int> a(N, 0);
    rep(i, N){
        cin >> a[i];
    }
    rep(i, N) count[a[i]] += 1;
    rep(i, 200005){
        pair[i] = count[i]*(count[i]-1)/2;
        sum += pair[i];
    }
    rep(i, N) cout << sum-count[a[i]]+1 << endl;
}

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

int main() {
  int x, n;
  cin >> x >> n;
  vector<int> d(102);
  rep(i,n) {
    int p;
    cin >> p;
    d[p] = 1;
  }
  P ans(99999, -1);
  for (int i = 0; i <= 101; i++) {
    if (d[i] == 1) continue;
    int dif = abs(x-i);
    ans = min(ans, P(dif,i));
  }
  cout << ans.second << endl;
  return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<sstream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cfloat>
#include<functional>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<bitset>
#include<list>
#include<numeric>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;
typedef vector<int> vint;
typedef vector<char> vchar;

#define PI 3.141592653589793238462643383279
#define intinf 2000000014
#define longinf 2000000000000000014LL
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define sc(x) cin >> x
#define sc2(x, y) cin >> x >> y
#define sc3(x, y, z) cin >> x >> y >> z
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << x << "\n"
#define pri2(x, y) cout << x << " " << y << "\n"
#define pri3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << x << "\n"
#define debug2(x, y) cout << " --- " << x << " " << y << "\n"
#define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n"
#define debugn(i, n, a) rep(i, n)cout << " --- " << a[i] << "\n";
#define debugin(i, n, a) rep(i, n)printf(" --- %10d\n", a[i])
#define debugi2n(i, n, a, b) rep(i, n)printf(" --- %10d %10d\n", a[i], b[i])
#define debugiin(i, n, a) rep(i, n)printf(" --- %10d %10d\n", a[i].first, a[i].second)
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

ll d[100][100];
bool warshallfloyd(int v){
  int i, j, k;
  rep(k, v)rep(i, v)rep(j, v)if(d[i][k] != longinf && d[k][j] != longinf && d[i][j] > d[i][k] + d[k][j])d[i][j] = d[i][k] + d[k][j];
  rep(i, v)if(d[i][i] < 0)return false;
  return true;
}
signed main(void){
  int i, j, tmp, tmp2;
  for(int testcase = 0;;testcase++){
    int2(v, e);
    rep(i, v)rep(j, v)(i == j) ? d[i][j] = 0LL : d[i][j] = longinf;
    rep(i, e){
      int3(s, t, dd);
      d[s][t] = dd;
    }
    if(warshallfloyd(v)){
      rep(i, v){
        if(d[i][0] >= longinf)cout << "INF";
        else cout << d[i][0];
        rep1(j, v){
          if(d[i][j] >= longinf)cout << " INF";
          else cout << " " << d[i][j];
        }
        kara;
      }
    }else pri("NEGATIVE CYCLE");

/*/

//*/ break;
  }
  return 0;
}

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

using namespace std;

constexpr int MAX_V = 550;
constexpr int INF = (1 << 29);

int N;
int cap[MAX_V][MAX_V];
bool G[MAX_V][MAX_V];
bool used[MAX_V];

int dfs(int v, int t, int f)
{
    if (v == t) return f;
    used[v] = 1;
    for (int i = 0; i < N; i++) {
        if (!used[i] && cap[v][i] > 0) {
            int d = dfs(i, t, min(f, cap[v][i]));
            if (d > 0) {
                cap[v][i] -= d;
                cap[i][v] += d;
                return d;
            }
        }
    }
    return 0;
}

int one_flow(int s, int t)
{
    memset(used, 0, sizeof(used));
    return dfs(s, t, 1);
}

int max_flow(int s, int t)
{
    int flow = 0;
    for (;;) {
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF);
        if (f == 0) return flow;
        flow += f;
    }
}

void add_edge(int from, int to)
{
    cap[from][to] = cap[to][from] = 1;
}

void remove_edge(int from, int to)
{
    cap[from][to] = cap[to][from] = 0;    
}

int main()
{
    int E, Q;
    cin >> N >> E >> Q;
    
    for (int i = 0; i < E; i++) {
        int F, T;
        cin >> F >> T;
        add_edge(F - 1, T - 1);
    }
    
    int f = max_flow(0, N - 1);
    for (int i = 0; i < Q; i++) {
        int M, A, B;
        cin >> M >> A >> B;
        A -= 1; B -= 1;
        if (M == 1) {
            add_edge(A, B);
            f += one_flow(0, N - 1);
        } else {
            if (cap[A][B] != 0) swap(A, B);

            if (cap[A][B] == 0 && one_flow(A, B) == 0) {
                one_flow(N - 1, B);
                one_flow(A, 0);
                f -= 1;
            }
            
            remove_edge(A, B);
        }
        
        cout << f << endl;
    }
}

Measured memory_bytes: 4196
import sys
import math
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

num = I()
s = S()
N = len(s)

ret = {"A":0,"B":1,"C":2,"D":3,"E":4,"F":5,"G":6,"H":7,"I":8,"J":9,"K":10,"L":11,"M":12,"N":13,"O":14,"P":15,"Q":16,"R":17,"S":18,"T":19,"U":20,"V":21,"W":22,"X":23,"Y":24,"Z":25}
t = {0:"A",1:"B",2:"C",3:"D",4:"E",5:"F",6:"G",7:"H",8:"I",9:"J",10:"K",11:"L",12:"M",13:"N",14:"O",15:"P",16:"Q",17:"R",18:"S",19:"T",20:"U",21:"V",22:"W",23:"X",24:"Y",25:"Z"}

ans = ""
for i in range(N):
  ans += t[(ret[s[i]] + num) % 26]
print(ans)

Measured memory_bytes: 41196
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, A, B;
string S;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> A >> B >> S;
  int c = 0, b = 0;
  rep(i, N) {
    if (S[i] == 'a') {
      if (c < A+B) {
        c++;
        cout << "Yes\n";
      }
      else {
        cout << "No\n";
      }
    }
    else if (S[i] == 'b') {
      if (c < A+B && b < B) {
        c++;
        b++;
        cout << "Yes\n";
      }
      else cout << "No\n";
    }
    else cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 848
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll n,k;
vp a;

int main(){
	cin>>n>>k;
	ll res;
	a=vp(n);
	for(int i=0;i<n;i++) cin>>a[i].first>>a[i].second;
	sort(a.begin(),a.end());
	for(int i=0;i<n;i++){
		k-=a[i].second;
		if(k<=0){
			res=a[i].first;
			break;
		}
	}
	cout<<res<<endl;
}

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

int calcNumOfCombination(long n, long r){
    long num = 1;
    for(long i = 1; i <= r; i++){
        num = num * (n - i + 1) / i;
    }
    return num;
}

int main() {
    int n;
    cin >> n;
    
    vector<string> s(n);
    rep(i, n) cin >> s.at(i);

    map<string, long> b;
    rep(i, n) {
        sort(s.at(i).begin(), s.at(i).end());
        string key = s.at(i);
        if (b.find(key) == b.end()) {
            b[key] = 1;
        } else {
            b[key]++;
        }
    }
    
    long cnt = 0;
    for (auto& kv : b) {
        cnt += kv.second * (kv.second - 1) / 2;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 18176
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

int main(void){
  int n,k;
  cin>>n>>k;

  ll res=0;
  for(int b=1;b<=n;b++){
    res+=(n/b)*(max(0,b-k));
    res+=max(0,(n%b)-k+1);
  }
  if(k==0) res-=n;
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256