akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  int t = 0;
  FOR(i,1,1000){
    t += i;
    int tt = t + i + 1;
    if(t - a == tt - b){
      cout << t - a << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
Q = int(input())

def isPrime(p):
    for i in range(2, int(p**0.5)+1):
        if p % i == 0:
            return False
    return True

F = [1]*(10**5+1)
F[0], F[1] = 0, 0
for j in range(2, len(F)):
    if isPrime(j) == True:
        for k in range(j*2, len(F), j):
            F[k] = 0

for e in range(2, len(F))[::-1]:
    if F[e] == 1 and (e) % 2 == 1:
        if F[int((e+1)/2)] == 0:
            F[e] = 0
    else:
        F[e] = 0

t = [0]*len(F)
for a in range(len(F)-1):
    t[a+1] = t[a] + F[a]

for b in range(Q):
    l, r = map(int, input().split(" "))
    print(t[r+1] - t[l])

Measured memory_bytes: 7380
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    
    cout << max(0, c-(a-b)) << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200010;
const int MOD = 998244353;

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

int64_t 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()
{
  int64_t N, M, K, ans = 0;
  cin >> N >> M >> K;
  vector<int64_t> POW(N);
  int64_t m = M;
  for (int i = 0; i < N; i++)
  {
    POW.at(i) = m;
    m = (m * (M - 1)) % MOD;
  }
  COMinit();
  for (int k = 0; k <= K; k++)
  {
    int64_t x = COM(N - 1, k) % MOD;
    x = (x * POW.at(N - 1 - k)) % MOD;
    ans = (ans + x) % MOD;
  }
  cout << ans % MOD << endl;
}

Measured memory_bytes: 9580
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int w, h;
    while(cin >> w >> h, w|h){
        vector<vector<char>> v(h+2, vector<char>(w+2, -1));
        vector<string> g(h);
        for (int i = 0; i < h; ++i) {
            cin >> g[i];
            for (int j = 0; j < w; ++j) {
                v[i+1][j+1] = (g[i][j] != '.');
            }
        }
        queue<pair<int, int>> Q;
        array<int, 4> di = {1, -1, 0, 0}, dj = {0, 0, 1, -1};
        vector<vector<char>> visited(h, vector<char>(w, 0));

        int ansW = 0, ansB = 0;
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                for (auto &&l : visited) {
                    fill(l.begin(),l.end(), 0);
                }
                int hitW = 0, hitB = 0;
                if(g[i][j] != '.') continue;
                Q.emplace(i, j);
                while(!Q.empty()){
                    int s, t; tie(s, t) = Q.front(); Q.pop();
                    visited[s][t] = 1;
                    for (int k = 0; k < 4; ++k) {
                        if(v[s+di[k]+1][t+dj[k]+1] == 0 && !visited[s+di[k]][t+dj[k]]){
                            Q.emplace(s+di[k], t+dj[k]);
                            visited[s+di[k]][t+dj[k]] = 1;
                        }else if(v[s+di[k]+1][t+dj[k]+1] == 1){
                            if(g[s+di[k]][t+dj[k]] == 'B') hitB = 1;
                            else hitW = 1;
                        }
                    }
                }
                if(hitW && !hitB) ansW++;
                if(hitB && !hitW) ansB++;
            }
        }
        cout << ansB << " " << ansW << "\n";
    }

    return 0;
}


Measured memory_bytes: 3176
#include <iostream>

int main()
{
  int n;
  std::cin >> n;
  int v[n], c[n];
  int ans = 0;
  for (int i = 0; i < n; i++) std::cin >> v[i];
  for (int i = 0; i < n; i++) std::cin >> c[i];
  for ( int i = 0; i < n; i++ ) {
    if ( v[i] - c[i] > 0 ) ans += v[i] - c[i];
  }
  std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>

using namespace std;

int main(){
    int n;
    int d;
    int cnt=0;
    long long d_sq;

    cin >> n >> d;

    int x[n], y[n];

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

    for(int i=0; i<n; i++){
        d_sq = pow(x[i],2) + pow(y[i],2);
        if(sqrt(d_sq) <= d){
            cnt++;
        }
    }  

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

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

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

    int A, B, T;
    cin >> A >> B >> T;

    int numBiscuit = 0;

    for (int t = A; t <= T; t += A) {
        numBiscuit += B;
    }

    cout << numBiscuit << "\n";
}

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

using VI = vector<long>;
using VVI = vector<VI>;
using P = pair<int, int>;
VVI adj;
VI score;
VI color;
map<P, long> weight;
constexpr long INIT = -1e18;

bool hasScore = true;
bool isBipartite_ = false;

void dfsColor(int v, int c) {
    if (color[v] != -1) {
        if (color[v] != c) {
            isBipartite_ = true;
        }
        return;
    }
    color[v] = c;
    for (int a: adj[v]) {
        dfsColor(a, !c);
    }
}

bool isBipartite() {
    dfsColor(0, 0);
    return isBipartite_;
}

long illegalScoreDif;

void dfsScore(int v, long s) {
    // update hasScore
    if (score[v] != INIT) {
        if (score[v] != s) {
            illegalScoreDif = abs(score[v] - s);
            hasScore = false;
            return;
        }
        return;
    }
    score[v] = s;
    for (int a: adj[v]) {
        dfsScore(a, weight[P(v,a)] - s);
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    adj = VVI(n);
    score = VI(n, INIT);
    color = VI(n, -1);
    for (int i = 0; i < m; i++) {
        int u, v, s;
        cin >> u >> v >> s;
        u--;
        v--;
        weight[P(u,v)] = s;
        weight[P(v,u)] = s;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    
    if (!isBipartite()) {
        dfsScore(0, 0);
        if (hasScore) {
            VI blackScores, whiteScores;
            for (int i = 0; i < n; i++) {
                if (color[i] == 0) {
                    blackScores.push_back(score[i]);
                } else {
                    whiteScores.push_back(score[i]);
                }
            }
            sort(blackScores.begin(), blackScores.end());
            sort(whiteScores.begin(), whiteScores.end());
            long toAdd = 1 - blackScores.front();
            long maxScore = whiteScores.front() - toAdd;
            if (maxScore < 1) {
                cout << 0 << endl;
            } else {
                cout << maxScore << endl;
            }
        } else {
            cout << 0 << endl;
        }
    } else {
        dfsScore(0, 0);
        hasScore = true;
        score = VI(n, INIT);
        if (illegalScoreDif % 2 == 1) {
            cout << 0 << endl;
            return 0;
        }
        dfsScore(0, illegalScoreDif / 2);
        if (hasScore) {
            for (int i = 0; i < n; i++) {
                if (score[i] < 1) {
                    cout << 0 << endl;
                    return 0;
                }
            }
            cout << 1 << endl;
        } else {
            cout << 0 << endl;
        }
    }
}


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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int x;
    cin >> x;
    print(x >= 30 ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 3620
import sys
from operator import itemgetter
from itertools import combinations, takewhile
from math import sqrt

def solve(a: list, sorted_axis: int = -1):
    length = len(a)
    if length <= 3:
        return sqrt(min((x1-x2)**2+(y1-y2)**2 for (x1, y1), (x2, y2) in combinations(a, 2)))

    x_set_len = len(set(x for x, _ in a))
    axis1 = 0 if x_set_len > length/2 else 1

    if sorted_axis != axis1:
        a.sort(key=itemgetter(axis1))

    mid_index = length//2
    left, right = a[:mid_index], a[mid_index:]
    delta = min(solve(left, axis1), solve(right, axis1))

    axis2 = not axis1
    median = a[mid_index][axis1]
    mid_a = sorted([p for _iter in (
        (takewhile(lambda p: median-delta < p[axis1], left[::-1])),
        (takewhile(lambda p: p[axis1] < median+delta, right))
    ) for p in _iter], key=itemgetter(axis2))

    for i, (x1, y1) in enumerate(mid_a):
        ub = (x1 if axis1 else y1) + delta
        for x2, y2 in takewhile(lambda p: p[axis2] < ub, mid_a[i+1:]):
            delta = min(delta, sqrt((x1-x2)**2+(y1-y2)**2))

    return delta

if __name__ == "__main__":
    N = int(input())
    a = [tuple(map(float, l.split())) for l in sys.stdin.readlines()]
    print("{:.10f}".format(solve(a)))


Measured memory_bytes: 25552
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		String[] s = saori.nextHayami().split("");
		Arrays.sort(s);
		if(s[0].equals(s[1]) && s[2].equals(s[3]) && !(s[0].equals(s[3]))){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21204
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    long n = scan.nextLong();
    long k = scan.nextLong();
    
    long digit = n % k;
    System.out.println(digit < k - digit ? digit : k - digit);
  }
}

Measured memory_bytes: 21588
#include  <bits/stdc++.h>
using namespace  std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rep2(r, aa, bb) for (int r = (aa)-1; r >= (bb); r--)
#define be(x) (x.begin(), x.end())
#define pb(t) push_back(t)
#define ll long long
int main()
{
	int n;
	cin>>n;
	vector<ll>A(n+1), B(n);
	rep(i,0,n+1)cin>>A[i];
	rep(i,0,n)cin>>B[i];
	ll counter=0;
	rep(i,0, n)
	{
//		cout<<B[i]<<endl;
		counter+=min(A[i], B[i]);
		ll x=A[i], y=B[i];
		B[i]-=min(x, y);
		A[i]-=min(x,y);
		if(B[i])
		{
			counter+=min(A[i+1], B[i]);
			A[i+1]-=min(A[i+1], B[i]);
		}
	//	cout<<B[i]<<" "<<min(x,y)<<endl;
	}
	cout<<counter<<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
//NIL is NULL
#define NIL NULL
//Node structure
struct Node{
  int key;
  struct Node *parent;
  struct Node *leftc;
  struct Node *rightc;
};
//define Nodepointer
typedef struct Node * Nodepointer;
  
//root       
Nodepointer root;
  
//function insert
void insert(int k){
  Nodepointer x,y,z;
  y=NIL;
  x=root;
  //make memory
  z=new struct Node();
  
  z->key=k;
  z->leftc=NIL;
  z->rightc=NIL;
  
  while(x!=NIL){
    y=x;
    if(z->key < x->key) x=x->leftc;
    else x=x->rightc;
  }
  
  z->parent=y;
  
  if(y==NIL) root=z;
  
  else if(z->key<y->key) y->leftc=z;
  
  else y->rightc=z;
  
  
}
  
//function search
Nodepointer find(Nodepointer now,int data){
  if(now==NIL||data==now->key) return now;
  if(data<now->key) return find(now->leftc,data);
  else return find(now->rightc,data);
}
  
//function treeminimum
Nodepointer treeminimum(Nodepointer x){
  while(x->leftc!=NIL){
    x=x->leftc;
  }
  return x;
}
//function treesuccerssor
Nodepointer treesuccessor(Nodepointer x){
  Nodepointer y;
  if(x->rightc!=NIL) return treeminimum(x->rightc);
  y=x->parent;
  while(y!=NIL && x==x->rightc){
    x=y;
    y=y->parent;
  }
  return y;
}
//function treedelete
void treedelete(Nodepointer z){
  Nodepointer x,y;
  if(z->leftc==NIL ||z->rightc==NIL)y=z;
  else y=treesuccessor(z);
  
  if(y->leftc!=NIL)x=y->leftc;
  else x=y->rightc;
   
  if(x!=NIL)x->parent=y->parent;
  if(y->parent==NIL) root=x;
  else if(y==y->parent->leftc) y->parent->leftc=x;
  else y->parent->rightc=x;
  if(y!=z) z->key=y->key;
}
  
//print
void inorderprint(Nodepointer now){
  if(now!=NIL){
    inorderprint(now->leftc);
    printf(" %d",now->key);
    inorderprint(now->rightc);
  }
}
  
void preorderprint(Nodepointer now){
  if(now!=NIL){
    printf(" %d",now->key);
    preorderprint(now->leftc);
    preorderprint(now->rightc);
  }
}
  
  
int main(){
  
  int n,i,j,data;
  Nodepointer del;
  char str[10];
  //load n
  scanf("%d",&n);
  //load commnad and key
  for(i=0;i<n;i++){
    scanf("%s",str);
    //insert
    if(strcmp(str,"insert")==0) {
      scanf("%d",&data);
      insert(data);
    }
    //find
    else if(strcmp(str,"find")==0){
      scanf("%d",&data);
      if(find(root,data)!=NIL) printf("yes\n");
      else printf("no\n");
    }
    //delete
    else if(strcmp(str,"delete")==0){
      scanf("%d",&data);
      del=find(root,data);
      treedelete(del);
    }
    //print
    else if(strcmp(str,"print")==0){
      inorderprint(root);
      cout <<endl;
      preorderprint(root);
      cout <<endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 10000
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] s = new int[N];
		int[] check10 = new int[N];
		for(int i=0;i<N;i++){
			s[i] = sc.nextInt();
			check10[i] = (s[i]%10==0)?1:0;
		}
		int ans = 0;
		sort(s,check10);
		for(int i=0;i<N;i++){
			ans += s[i];
		}
		if(ans%10 == 0){
			int now = 0;
			while(ans > 0){
				for(int i=now;i<N;i++){
					if(check10[i]%10!=1){
						System.out.println((ans-s[i]));
						return;
					}
				}
				ans = ans - s[now];
				now++;
			}
		}
		System.out.println(ans);
	}

	public static void sort(int[] list,int[] check){
		for(int i=0;i<list.length-1;i++){
			for(int j=i+1;j<list.length;j++){
				if(list[i]>list[j]){
					int swap = list[i];
					list[i] = list[j];
					list[j] = swap;
					swap = check[i];
					check[i] = check[j];
					check[j] = swap;
				}
			}
		}
	}

}


Measured memory_bytes: 22100
let list_to_array n a xs =
  let res = Array.make n a in
  List.iteri (fun i x -> res.(i) <- x) xs;
  res

(* O(n * log(n)) *)
let solve n ds =
  let sorted_ds = list_to_array n 0 ds in
  Array.sort compare sorted_ds;
  Array.fold_left
    (fun (count, last) d ->
      (count + if d <> last then 1 else 0), d)
    (0, -1)
    sorted_ds |> fst

let fold_int f a n =
  let rec fold f a i n =
    if i >= n then
      a
    else
      fold f (f a i) (i + 1) n
  in
    fold f a 0 n

let read_ints n =
  fold_int
    (fun sofar _ -> read_int () :: sofar)
    []
    n |> List.rev

let _ =
  let n = read_int () in
  let ds = read_ints n in
  solve n ds |> string_of_int |> print_endline

Measured memory_bytes: 2432
n = int(input())
h = [int(i) for i in input().split()]

INF = 10**12

dp = [INF]*100010

dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, n):
    dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))
    dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))

print(dp[n-1])


Measured memory_bytes: 13928
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Long a = sc.nextLong();
        String op = sc.next();
        Long b = sc.nextLong();

        if ("+".equals(op)) {
            System.out.println(a + b);
        } else if ("-".equals(op)) {
            System.out.println(a - b);
        }
    }

}


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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007
typedef long long ll;

bool is_available(int a) {
  return (a >= 1 && a <= 9);
}

int main() {
  int a, b;
  cin >> a >> b;
  if(is_available(a) && is_available(b)) printf("%d", a * b);
  else printf("-1");
  printf("\n");
  return 0;
}

Measured memory_bytes: 256
from sys import stdin
readline = stdin.readline


def main():
    q = int(readline())
    for i in range(q):
        xy = map(int, readline().split())
        p0, p1, p2, p3 = [x + y * 1j for x, y in zip(*[xy] * 2)]
        print(1 if is_intersected_ls(p0, p1, p2, p3) else 0)


def is_intersected_ls(a1, a2, b1, b2):
    eps = 0
    if max(a1.real, a2.real) < min(b1.real, b2.real)\
      or max(b1.real, b2.real) < min(a1.real, a2.real)\
      or max(a1.imag, a2.imag) < min(b1.imag, b2.imag)\
      or max(b1.imag, b2.imag) < min(a1.imag, a2.imag):
        return False

    #print(cross(a2-a1, b1-a1))
    #print(cross(a2-a1, b2-a1))
    #print(cross(b2-b1, a1-b1))
    #print(cross(b2-b1, a2-b1))
    return (cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) <= eps)\
        and (cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) <= eps)


def cross(a, b):
    return a.real * b.imag - a.imag * b.real
main()

Measured memory_bytes: 6772
#include <stdio.h>

int round_sen(int n) {
  n += 999;
  n /= 1000;
  n *= 1000;
  return n;
}

int main() {

  const int money = 100000;
  int n, debt = money, week;
  
  scanf("%d", &n);
  
  for (week = 1; week <= n; week++) {
    debt *= 1.05;
    
    //printf("Week%d Debt1 : %d\t Debt2 : %d\n", week, debt, round_sen(debt));
    
    debt = round_sen(debt);
    
  }
  
  printf("%d\n", debt);
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N, K;
    int A = 1;
    cin >> N;
    cin >> K;
    for (int i = 0; i < N; i++){
        if (A * 2 >= A + K){
            A = A + K;
        }
        else {
            A = A * 2;
        }
    }
    cout << A << endl;
}

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

[N, X] = [int(i) for i in input().split()]
L = [int(i) for i in input().split()]

distance = 0
jump_number = 1
for l in L:
    distance += l
    if distance > X:
        break
    else:
        jump_number += 1

print(jump_number)


Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>

int main() {
    char s[101], p[101];
    int i = 0, cou = 0, jud = 0;
    scanf("%101s", s);
    scanf("%101s", p);
    int len = strlen(p);
    
    while (1) {
        if (s[i] == p[cou]) {
            cou++;
            if (cou == len) {jud = 1;}
        } else if (jud == 2) {
            jud = 0;
            break;
        }
        if (jud == 1) {break;}
        i++;
        if (s[i] == '\0') {
            i = 0;
            jud = 2;
        }
    }
    
    if (jud == 1) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    
    return 0;
}


Measured memory_bytes: 2112
n = int(input())
l = []
for _ in range(n):
    a,b = map(int,input().split())
    l.append((a+b,a,b))
l = sorted(l,reverse=True)
takahashi = 0
aoki = 0
for i in range(n):
    if i%2:
        aoki+=l[i][2]
    else:
        takahashi+=l[i][1]
print(takahashi-aoki)

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

using namespace std;

using ll = long long;

constexpr int kMaxN = 2e5 + 7;
constexpr ll inf = 1e18;

vector<pair<int, bool>> in[kMaxN];
vector<pair<int, bool>> out[kMaxN];

struct SegTree {
  struct node {
    ll big = -inf;
    ll lazy = 0;
  };
  int sz, n;
  vector<node> nodes;

  SegTree(int n): n{n} {
    sz = 1;
    while (sz < n) {
      sz *= 2;
    }
    nodes.resize(2 * sz);
  }

  ll get_max() {
    ll v = -inf;
    rec(1, 0, sz - 1, 0, sz - 1, v, false);
    return v;
  }

  void add(int l, int r, ll val) {
    rec(1, 0, sz - 1, l, r, val, true);
  }

private:

  void prop(int idx) {
    if (!nodes[idx].lazy) {
      return;
    }

    int l = 2 * idx, r = l + 1;
    if (r < 2 * sz) {
      nodes[l].lazy += nodes[idx].lazy;
      nodes[r].lazy += nodes[idx].lazy;
    }

    nodes[idx].big += nodes[idx].lazy; 
    nodes[idx].lazy = 0;
  }

  void rec(int idx, int L, int R, int l, int r, ll& val, bool add) {
    prop(idx);
    if (l > R || r < L) {
      return;
    }
    if (l <= L && R <= r) {
      if (add) {
        nodes[idx].lazy += val;
        prop(idx);
      } else {
        val = max(val, nodes[idx].big);
      }
      return;
    }
    int M = (L + R) / 2;
    rec(2 * idx, L, M, l, r, val, add);
    rec(2 * idx + 1, M + 1, R, l, r, val, add);
    nodes[idx].big = max(nodes[2 * idx].big, nodes[2 * idx + 1].big);
  }
};

struct inter {
  int l, r;
  ll a;
};

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

  int n, m;
  cin >> n >> m;

  vector<inter> original(m);
  for (int i = 0; i < m; ++i) {
    int l, r;
    ll a;
    cin >> l >> r >> a;

    original[i] = {l, r, a};
    in[l].emplace_back(i, true);
    out[r].emplace_back(i, false);
  }

  SegTree st(n + 2);

  st.add(0, 0, inf);
  for (int i = 1; i <= n; ++i) {
    for (auto& p: in[i]) {
      auto &interval = original[p.first];
      st.add(0, interval.l - 1, interval.a);
    }

    st.add(i, i, st.get_max() + inf);

    for (auto& p: out[i]) {
      auto &interval = original[p.first];
      st.add(0, interval.l - 1, -interval.a);
    }
  }

  cout << st.get_max() << '\n';

  return 0;
}


Measured memory_bytes: 33464
import numpy as np

A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

num = min(a) + min(b)

for _ in range(M):
    m1,m2,m3 = map(int,input().split())
    res = a[m1-1]+b[m2-1] - m3
    num = min(num,res)

print(num)

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

using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define all(v) v.begin(),v.end()
#define ve vector
#define vi vector<int>
#define vi2 vector<vi>
#define vl vector<long long>
#define vl2 vector<vl>

template <class T> T maxAny(T a, T b){
    if(a > b) return a;
    else return b;
}

template <class T> T minAny(T a, T b){
    if(a > b) return b;
    else return a;
}

int main(){
    long long k, num = 7;
    cin >> k;
    rep1(i, k){
        if(num % k == 0){
            cout << i << endl;
            return 0;
        }
        else num = ((num%k)*10+7)%k;
    }
    cout << -1 << endl;
}

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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  string s;
  cin >> s;
  vector< vector< ul > > dp(s.size()+1, vector< ul >(13, 0));
  dp[0][0] = 1;
  ul mod = 1e9+7;
  for (ul i=0; i<s.size(); ++i) {
    if (s[i]=='?') {
      for (ul j=0; j<13; ++j) {
        for (ul k=0; k<10; ++k) {
          ul tgt = (j*10+k)%13;
          dp[i+1][tgt] += dp[i][j];
        }
      }
    } else {
      for (ul j=0; j<13; ++j) {
        ul tgt = (j*10+(s[i]-'0'))%13;
        dp[i+1][tgt] += dp[i][j];
      }
    }
    for (ul j=0; j<13; ++j) {
      dp[i+1][j] %= mod;
    }
  }
  cout << dp[s.size()][5] << endl;
  return 0;
}


Measured memory_bytes: 13648
#include <iostream>
#include <cmath>
#include <functional>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>

template <class Integer>
auto boost_irange(Integer last) { return boost::irange(static_cast<Integer>(0), last); }
template <class Integer>
auto boost_irange(Integer first, Integer last) { return boost::irange(first, last); }

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    inline input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    inline T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            cin >> *head;
            ++head;
        }
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

public:
    class proxy
    {
        std::ostream& cout;

    public:
        proxy() : cout(std::cout) {}
        ~proxy() { cout << std::endl; }
        template <class T>
        proxy& operator,(T&& val)
        {
            cout << val << ' ';
            return *this;
        }
    };

public:
    output() : cout(std::cout) {}
    template <class T>
    proxy operator<<(T&& val)
    {
        cout << val << ' ';
        return {};
    }
};

template <class T, std::size_t n>
class StaticVector : public boost::container::static_vector<T, n>
{
    using Parent = boost::container::static_vector<T, n>;

public:
    // is_constructible_v >= C++17
    template <class... Args, std::enable_if_t<std::is_constructible<Parent, Args&&...>::value, std::nullptr_t> = nullptr>
    StaticVector(Args&&... args) : Parent(std::forward<Args>(args)...) {}
    StaticVector(input& in, std::size_t n_) : Parent(n_)
    {
        for (std::size_t i = 0; i < n_; ++i) in >> static_cast<Parent&>(*this)[i];
    }
};

int main()
{
    input in;
    output out;
    int N = in.read<int>();
    int res = 0;
    int prev = 0, chain = 0;
    in.online<int>(N, [&](int x) {
        if (x <= prev) {
            ++chain;
            res = std::max(res, chain);
        } else {
            chain = 0;
        }
        prev = x;
    });
    out << res;

    return 0;
}


Measured memory_bytes: 256
while True:
    n,x=map(int,input().split())
    if n==x==0:
        break
    else:
        count=0
        for i in range(1,n+1):
            for j in range(i+1,n+1):
                for k in range(j+1,n+1):
                    if i+k+j==x:
                        count=count+1
        print(count)         


Measured memory_bytes: 5592
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <iomanip>

using namespace std;

typedef long long LL;
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) cin>>v
#define OUT(v) cout<<v<<endl

LL combination(int n, int r) {
  if (n < r)
    return 0;
  vector<vector<LL>> v(n + 1, vector<LL>(n + 1, 0));
  for (int i = 0; i <= n; i++)
    v[i][0] = v[i][i] = 1;

  for (int j = 1; j <= n; j++)
    for (int k = 1; k < j; k++)
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);

  return v[n][r];
}

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

  vector<LL> V(N);
  REP(i, N)
    cin >> V[i];

  sort(ALL(V), greater<LL>()); // 降順
  LL sum = 0;
  REP(i, A)
    sum += V[i];
  cout << fixed << setprecision(6) << ((long double)sum / A) << endl;

  SORT(V); // upper_boundとかのために昇順にする

  LL a_th = V[V.size() - A];
  int X = upper_bound(ALL(V), a_th) - lower_bound(ALL(V), a_th);
  if (V.back() != a_th) {
    int Y = upper_bound(V.end() - A, V.end(), a_th) - lower_bound(V.end() - A, V.end(), a_th);
    OUT(combination(X, Y));
  } else {
    LL res = 0;
    FOR(i, A, B+1)
      res += combination(X, i);
    OUT(res);
  }
  return 0;
}


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

using namespace std;

typedef long long ll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define rep(i,n) for(int i=0;i<(n);i++)

int main(){
    int N;
    cin>>N;
    vector<pair<int,int> >A(N),B(N);
    rep(i,N){
        int a,b;
        cin>>a>>b;
        B[i]=make_pair(a,b);
    }
    rep(i,N){
        int a,b;
        cin>>a>>b;
        A[i]=make_pair(a,b);
    }
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());

    int Co=0;

    for(int i=0;i<N;i++){
        int x=A[i].first,y=A[i].second;
        int by=INF,it;
        for(int j=0;j<N;j++){//青より左にある赤で、一番高いものを探索
            if(x<=B[j].first)break;
            if(y>B[j].second&&(by==INF||by<B[j].second))by=B[j].second,it=j;
        }
        if(by!=INF){
            Co++;
            B[it].second=INF;
        }
    }

    cout<<Co<<endl;

    return 0;
}

//赤<青の時であり、
/*
一番左にある、青と、そこから左にある中で、一番上のものをとればよい。
青、赤をxを基準としてソート。
解説より
*/

//a=97,z=122

Measured memory_bytes: 256
def main():
  H, W, D = map(int, input().split())
  num = [[] for _  in range(H*W)]
  for i in range(H):
    temp = list(map(int, input().split()))
    for j in range(len(temp)):
      num[temp[j]-1] = [i, j]
  #num = np.array(num)
  num_sum = [0]*(H*W)
  for i in range(D, H*W):
    num_sum[i] = num_sum[i-D] + (abs(num[i][0]-num[i-D][0])+ abs(num[i][1]-num[i-D][1]))
  Q = int(input())
  for i in range(Q):
    L, R = map(int, input().split())
    print(num_sum[R-1]-num_sum[L-1])
if __name__ == "__main__":
  main()

Measured memory_bytes: 65020
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

class UnionFind
{
public:
    UnionFind(){};
    ~UnionFind(){};

    void Init(int num_entries) {
        num_entries_ = num_entries;
        par_.resize(num_entries_);
        rank_.resize(num_entries_, 0);
        for (int i = 0; i < num_entries_; ++i)
        {
            par_[i] = i;
        }
    }
    int Find(int x) {
        if (par_[x] == x)
        {
            return x;
        }
        else
        {
            return par_[x] = Find(par_[x]);
        }
    }
    void Unite(int x, int y) {
        x = Find(x);
        y = Find(y);
        if (x == y) return;

        if (rank_[x] < rank_[y])
        {
            par_[x] = y;
        }
        else
        {
            par_[y] = x;
            if (rank_[x] == rank_[y])
            {
                rank_[x]++;
            }
        }
    }
    bool Same(int x, int y) {
        return Find(x) == Find(y);
    }

private:
    int num_entries_;
    std::vector<int> par_;
    std::vector<int> rank_;
};

set<int> get_intersect(const set<int>& s1, const set<int>& s2) {
    set<int> intersect;
    set_intersection(s1.begin(),s1.end(),s2.begin(),s2.end(),
                     std::inserter(intersect,intersect.begin()));
    return intersect;
}

int main(void)
{
    cin.sync_with_stdio(false);
    int N, M;
    cin >> N >> M;

    vector<vector<int>> speaker_to_langs(N);
    vector<char> seen_langs(M);

    UnionFind uf;
    uf.Init(M);

    
    REP(n,N) {
        int k;
        cin >> k;
        vector<int> langs(k);
        REP(k1,k) {
            int l;
            cin >> l; --l;
            langs[k1] = l;
            seen_langs[l] = 1;
        }
        speaker_to_langs[n] = langs;

        // REP(i,k-1){
        //     FOR(j,i+1,k){
        //         uf.Unite(langs[i], langs[j]);
        //     }
        // }
        FOR(i,1,k) {
            uf.Unite(langs[0], langs[i]);
        }
    }

    set<int> common_lang;
    for(auto lang : speaker_to_langs[0]){
        common_lang.insert( uf.Find(lang) );
    }
    FOR(n,1,N){
        auto& langs = speaker_to_langs[n];
        set<int> langs_set;
        for(auto lang : langs) {
            langs_set.insert( uf.Find(lang) );
        }
        common_lang = get_intersect(common_lang, langs_set);
    }

    if (SIZE(common_lang) > 0) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

    return 0;
}


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

int W_Length(char *str){
	int length = 0;
	while(*str++ != '\0')
		length++;
	return length;
}

void swap(int *a, int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
}
//swap(&a, &b)

double deg(double theta){//deg to theta
return theta*(2*3.14159265359)/360;
}

int cmp( const void *p, const void *q ) {
    return *(int*)p - *(int*)q;
}//ちいさい順
//qsort(a,n,sizeof(int),cmp);
//char s[n][11]

int cmp_s(const void * left, const void * right)
{
	char *left_char = (char *)left;
  char *right_char = (char *)right;
  return strcmp(left_char, right_char);
}
//qsort(s,n,sizeof(s[0]),cmp_s);


int main (void)
{
	int a[10005]={0},b,c,n,i,j,k,count,x=1,y=1,z=1,temp;

scanf("%d",&n);
  
  	for(x=1;x*x<=10000;x++){
    for(y=1;y*y<=10000;y++){
    for(z=1;z*z<=10000;z++){
      temp=x*x+y*y+z*z+x*y+y*z+z*x;
    if(temp<=10000){
    a[temp]++;
    }
    }
    }
    }
  for(i=1;i<=n;i++){
  printf("%d\n",a[i]);
  }
return 0;
}


Measured memory_bytes: 1708
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int visit(const vector<vector<int>> &g, vector<bool> &visited, int x, int n)
{
	if (visited[x]) {
		return 0;
	}
	visited[x] = true;
	if (n == g.size()) {
		return 1;
	}
	int ans = 0;
	for (int y : g[x]) {
		if (!visited[y]) {
			ans += visit(g, visited, y, n + 1);
			visited[y] = false;
		}
	}
	return ans;
}

int countPaths(const vector<vector<int>> &g, int s)
{
	int ans = 0;
	vector<bool> visited(g.size(), false);
	return visit(g, visited, s, 1);
}

int main()
{
	int N, M;
	cin >> N >> M;
	vector<vector<int>> g(N);
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	cout << countPaths(g, 0) << endl;
}


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


int main(){
    int n;
    cin >> n;
    int x[n],y[n];
    for (int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
    }
    double sum = 0;
    for (int i = 0; i < n-1; i++){
        for (int j = i+1; j < n; j++){
            sum += sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
        }
    }
    cout << fixed << setprecision(10) << sum/n*2;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


n, c = map(int, input().split())
sushi = [list(map(int, input().split())) for _ in range(n)]
half = c//2

DP_left = {}
DP_right = {}
ans = []
# 時計まわりでスタート地点からposまでの最高値
energy = 0
maxim = 0
prev = 0
for pos, cal in sushi:
    lost = pos - prev
    energy += cal - lost
    maxim = max(maxim, energy)
    DP_left[pos] = maxim
    prev = pos
ans.append(maxim)

# 反時計回り
energy = 0
maxim = 0
prev = c
for pos, cal in sushi[::-1]:
    lost = prev - pos
    energy += cal - lost
    maxim = max(maxim, energy)
    DP_right[pos] = maxim
    prev = pos
ans.append(maxim)

# 時計まわりで途中でターン
energy = 0
maxim = 0
prev = 0
for idx, (pos, cal) in enumerate(sushi):
    if idx == n-1:
        break
    if pos > half:
        break
    lost = pos - prev
    energy += cal - lost
    next_pos, _ = sushi[idx+1]
    back_cost = pos
    result = energy - back_cost + DP_right[next_pos]
    maxim = max(maxim, result)
    prev = pos
ans.append(maxim)

# 反時計まわりで途中でターン
energy = 0
maxim = 0
prev = c
for idx, (pos, cal) in enumerate(sushi[::-1], 1):
    if idx == n:
        break
    if pos < half:
        break
    lost = prev - pos
    energy += cal - lost
    back_cost = c - pos
    next_pos, _ = sushi[-idx-1]
    result = energy - back_cost + DP_left[next_pos]
    maxim = max(maxim, result)
    prev = pos
ans.append(maxim)

print(max(ans))

Measured memory_bytes: 53860
#include <cstdio>
#include <iostream>
#include <cassert>
#include <algorithm>    
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
// #define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef unsigned long long ull; 
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int M = 1e9 + 7;
//__int128
int res = inf;
int a[3];
int b[3][10];
int c[5];
int n;
int l[10];
void dfs(int cur) {
	if(cur == n) {
		int cost = 0;
		int len[3] = {0};
		for(int i = 0; i < 3; ++i) {
			if(c[i] == 0) {
				return;
			}
			for(int j = 0; j < c[i]; ++j) {
				if(j) {
					cost += 10;
				}
				len[i] += b[i][j];
			}
		}
		sort(len, len + 3);
		for(int i = 0; i < 3; ++i) {
			cost += abs(len[i] - a[i]);
		}
		res = min(res, cost);
		return;
	} 
	for(int i = 0; i < 4; ++i) {
		if(i < 3) {
			b[i][c[i]++] = l[cur];
		}
		dfs(cur + 1);
		c[i]--;
	}
}

signed main()
{
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 	cin >> n;
 	for(int i = 0; i < 3; ++i) {
 		cin >> a[i];
 	}   
 	sort(a, a + 3);
 	for(int i = 0; i < n; ++i) {
 		cin >> l[i];
 	}
 	sort(l, l + n);
 	dfs(0);
 	cout << res << endl;
	return 0;
}

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

#ifdef _WIN32
#define scanfll(x) scanf("%I64d", x)
#define printfll(x) printf("%I64d", x)
#else
#define scanfll(x) scanf("%lld", x)
#define printfll(x) printf("%lld", x)
#endif
#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using vll = vector<ll>; using vvll = vector<vll>;
using ld = long double;  using vld = vector<ld>; 
using vi = vector<int>; using vvi = vector<vi>;
vll conv(vi& v) { vll r(v.size()); rep(i, v.size()) r[i] = v[i]; return r; }
using P = pair<ll, ll>;

template <typename T, typename U> ostream &operator<<(ostream &o, const pair<T, U> &v) {  o << "(" << v.first << ", " << v.second << ")"; return o; }
template<size_t...> struct seq{}; template<size_t N, size_t... Is> struct gen_seq : gen_seq<N-1, N-1, Is...>{}; template<size_t... Is> struct gen_seq<0, Is...> : seq<Is...>{};
template<class Ch, class Tr, class Tuple, size_t... Is>
void print_tuple(basic_ostream<Ch,Tr>& os, Tuple const& t, seq<Is...>){ using s = int[]; (void)s{0, (void(os << (Is == 0? "" : ", ") << get<Is>(t)), 0)...}; }
template<class Ch, class Tr, class... Args> 
auto operator<<(basic_ostream<Ch, Tr>& os, tuple<Args...> const& t) -> basic_ostream<Ch, Tr>& { os << "("; print_tuple(os, t, gen_seq<sizeof...(Args)>()); return os << ")"; }
ostream &operator<<(ostream &o, const vvll &v) { rep(i, v.size()) { rep(j, v[i].size()) o << v[i][j] << " "; cout << endl; } return o; }
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "]";  return o; }
template <typename T>  ostream &operator<<(ostream &o, const set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]";  return o; }
template <typename T, typename U>  ostream &operator<<(ostream &o, const map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]";  return o; }
template <typename T, typename U>  ostream &operator<<(ostream &o, const unordered_map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it; o << "]";  return o; }
string bits_to_string(ll mask, ll n) { string s; rep(i, n) s += '0' + !!(mask & (1ll << i)); return s; }
#define ldout fixed << setprecision(40) 

static const double EPS = 1e-14;
static const long long INF = 1e18;
static const long long mo = 1e9+7;

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll k, s; cin >> k >> s;
    ll ret = 0;
    rep(x, k+1) rep(y, k+1) {
        ll z = s - x - y;
        if (0 <= z && z <= k) 
            ret++;
    }
    cout << ret << endl;

    return 0;
}


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

ll solver(string s){

    int N = s.size();
    vector<int> l_smaller_r(N+1);
    vector<int> l_larger_r(N+1);

    int cnt = 0;
    for(int i = 0; i != N; ++i){
        if(s.at(i) == '<') ++cnt;
        else cnt = 0;
        l_smaller_r.at(i+1) = cnt;
    }

    //  debug
    cerr << "called"s << endl;

    cnt = 0;
    for(int i = N-1; i != -1; --i){
        if(s.at(i) == '>') ++cnt;
        else cnt = 0;
        l_larger_r.at(i) = cnt;
    }

    //  debug
    cerr << "called"s << endl;

    ll ans = 0;
    for(int i = 0; i != N+1; ++i) ans += max(l_smaller_r.at(i), l_larger_r.at(i));

    return ans;
}

int main(){

    string s;
    cin >> s;

    cout << solver(s) << endl;

    return 0;
}

Measured memory_bytes: 8176
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

if __name__ == "__main__":
    N = int(input())
    ans = 0

    for i in range(1, N+1):
        for j in range(1, N+1):
            x = math.gcd(i, j)
            if(x==1):
                ans += N
            else:
                for k in range(1, N+1):
                    ans += math.gcd(x, k)

    print(ans)


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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int D, N;
    cin >> D >> N;

    int num;
    if(D == 0) num = 1;
    if(D == 1) num = 100;
    if(D == 2) num = 10000;
    
    if(N != 100) cout << num * N << endl;
    else cout << num * 101 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
   int N; cin >> N;
   int ans = 0;
   for(int i = 1; i <= N; i+=2){
       int cnt = 0;
       repr(j,1,i+1){
           if(i % j == 0) cnt++;
       }
       if(cnt == 8) ans++;
   }
   cout << ans << endl;
   
}


Measured memory_bytes: 256
/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//  cout <<  s.at(1)-'0'-49  <<endl;
int main() {
  int n,m,x;
  cin >> n >> m >> x;
  vector<int>a(m);
  rep(i,m) cin >> a.at(i);
  int Acost=0;
  int Bcost=0;
  rep(i,m){
    if(x < a.at(i) ) Acost++;
  }
  Bcost = m - Acost;
  if(Acost > Bcost) cout << Bcost <<endl;
  else cout << Acost << endl;
  }

Measured memory_bytes: 256