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

using namespace std;
//Note that in this problem weights are large but values are smaller. So put values as a dimension

//State
//dp[i][j]: The minumum knapsack weight required to get 
//	a value of atleast i using the first j items

//Initialization
//dp[0][j] = 0, if i<=V[0] then dp[i][0] = W[i] else dp[i][0] = 0

//Transitions
//dp[i][j] = min(dp[i-V[j]][j-1]+W[j], dp[i][j-1])

//Order of evaluation
//Rowwise or columnwise

//Answer
//Binary search on dp[...][N-1] to find an greatest index(value) <= w

//Time Complexity: O(V*n) + O(logV)|O(V)

using ll = long long;
ll dp[100005][101] = {0};
ll W[105];
ll V[105];
const ll INF = 1e18 + 5;

int main(){
	ll N, w;
	cin >> N >> w;
	ll v = 0;
	
	for(ll i=0; i<N; i++){
	    cin>> W[i] >> V[i];
	    v = v+V[i];
	}
	
	for(ll i=0; i<N; i++){
		dp[0][i] = 0;
	}
	for(ll i=1; i<=v; i++){
		if(i<=V[0]){
			dp[i][0] = W[0]; 
		}
		else{
			dp[i][0] = INF;
		}
	}

	for(ll i=1; i<=v; i++){
		for(ll j=1; j<N; j++){
			if(i-V[j]>=0){
				dp[i][j] = min(dp[i-V[j]][j-1]+W[j], dp[i][j-1]);
			}
			else{
				dp[i][j] = dp[i][j-1];
			}
		}
	}
	
	ll result= INF;
	for(ll i=0; i<=v; i++){
		if(dp[i][N-1]<=w){
			result = i;
		}
	}
	cout << result << endl;
}   
  

Measured memory_bytes: 82440
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		StringTokenizer st1;
		int[] tri = new int[3];
		
		str=br.readLine();

		int count=Integer.parseInt(str);


		for(int i=0;i<count;i++){
			st1=new StringTokenizer(br.readLine()," ");
			tri[0]=Integer.parseInt(st1.nextToken());
			tri[1]=Integer.parseInt(st1.nextToken());
			tri[2]=Integer.parseInt(st1.nextToken());
			sortTri(tri);
			if(tri[0]*tri[0]+tri[1]*tri[1] == tri[2]*tri[2]){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}


	}

	public static void sortTri(int[] num){
		int tmp;
		for(int i=0;i<num.length-1;i++){
			for(int j=i+1;j<num.length;j++){
				if(num[i]>num[j]){
					tmp=num[i];
					num[i]=num[j];
					num[j]=tmp;
				}
			}
		}
	}

}

Measured memory_bytes: 25764
#include<bits/stdc++.h>
using namespace std;
long long int A[200005],B[200005];
int main(){
    int n,m,k;
    cin >> n >> m >> k;
    long long int a[n],b[m];
    for(int i=0;i<n;i++){
        cin >> a[i];
        A[i+1] = A[i]+a[i];
    }
    for(int i=0;i<m;i++){
        cin >> b[i];
        B[i+1] = B[i] + b[i];
    }
    int j=m;
    int ans=0;
    for(int i=0;i<n+1;i++){
        while(A[i]+B[j]>k && j>0)j--;
        if(A[i]+B[j]<=k)ans=max(ans,i+j);
    }
    cout << ans;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main(){
  string S[3];
  REP(i, 3){
    cin >> S[i];
  }
  int turn = 0;
  while(1){
    if(S[turn].size() == 0){
      cout << (char)('A'+turn) << endl;
      break;
    }
    int next = S[turn][0]-'a';
    S[turn].erase(S[turn].begin());
    turn = next;
  }
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

int main() {
    vector<int> n(3);
    cin >> n[0] >> n[1] >> n[2];
    sort(n.begin(), n.end());
    
    cout << n[2] * 10 + n[0] + n[1];
    return 0;
}


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

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> x;
	n = x;
	m = 0;
	while(n > 0){
		m += n%10;
		n /= 10;
	}
	if(x%m == 0) cout << "Yes" << endl;
	else cout << "No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int h,w; cin>>h>>w;
  vector<string> s(h);
  for(auto& i:s) cin>>i;
  queue<pair<int,pair<int,int>>> q;
  int res=0;
  for(int i=0; i<h; ++i) for(int j=0; j<w; ++j){
    vector<vector<bool>> z(h,vector<bool>(w,false));
    if(s[i][j]=='.') q.push({i,{j,0}});
    while(!q.empty()){
      int x=q.front().first;
      int y=q.front().second.first;
      int cnt=q.front().second.second;
      q.pop();
      if(z[x][y]==true) continue; else z[x][y]=true;
      if(x>0) if(s[x-1][y]=='.') q.push({x-1,{y,cnt+1}});
      if(y>0) if(s[x][y-1]=='.') q.push({x,{y-1,cnt+1}});
      if(x<h-1) if(s[x+1][y]=='.') q.push({x+1,{y,cnt+1}});
      if(y<w-1) if(s[x][y+1]=='.') q.push({x,{y+1,cnt+1}});
      res=max(res,cnt);
    }
  }
  cout<<res;
  return 0;
}

Measured memory_bytes: 3608
from collections import deque


def bfs(maze, visited, sy, sx, gy, gx):
    queue = deque([[sy, sx]])
    visited[sy][sx] = 0
    while queue:
        # queueには訪れた地点が入っている。そこから、4方向に移動できるか考え、queueから消す。
        y, x = queue.popleft()  # queueに入っていたものを消す。
        if [y, x] == [gy, gx]:  # もしゴールについていたならば、そのときの手数を出す。
            return visited[y][x]
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            l = 1
            while True:
                new_y, new_x = y + j * l, x + k * l
                if (0 <= new_y < H) and (0 <= new_x < W):
                    if maze[new_y][new_x] == "@":
                        break
                    elif visited[new_y][new_x] == -1:  # まだ来たことない点だったという条件
                        visited[new_y][new_x] = visited[y][x] + 1
                        queue.append([new_y, new_x])  # 新しい点を足す。
                    elif visited[new_y][new_x] < visited[y][x] + 1:
                        break
                else:
                    break
                l += 1
                if l == K + 1:
                    break


H, W, K = map(int, input().split())
# K = min(K, max(H, W))
x1, y1, x2, y2 = map(int, input().split())
x1, y1, x2, y2 = x1 - 1, y1 - 1, x2 - 1, y2 - 1
C = [0] * H
for i in range(H):
    C[i] = str(input())
visited = [[-1] * W for i in range(H)]
bfs(C, visited, x1, y1, x2, y2)
# print(visited)
print(visited[x2][y2])

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

double dp[3001][3001];
double solve(vector<double>&arr,int i,int x)
{
   if(x==0) return 1;
   if(i==0) return 0;

   if(dp[i][x]>-0.9) return dp[i][x];

   return dp[i][x]=arr[i]*solve(arr,i-1,x-1)+(1-arr[i])*solve(arr,i-1,x);
}
int main()
{
    int n;
    cin>>n;
    memset(dp,-1,sizeof(dp));
    vector<double>arr(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    cout<<fixed<<setprecision(10)<<solve(arr,n,(n+1)/2);
}

Measured memory_bytes: 70912
# coding: utf-8
"""this is python work script"""

def solver(price, counts):
    """solve this problem"""
    answer = ['-1', '-1', '-1']
    for z in range(counts+1):
        sum_z = z * 1000
        for y in range(counts + 1 - z):
            x = counts - y - z
            sum_y = y * 5000
            sum_x = x * 10000
            sum_all = sum_x + sum_y + sum_z
            if sum_all == price:
                return list(map(str, [x, y, z]))
    return answer

def main():
    """main function"""
    N, Y = list(map(int, input().split()))
    answer = solver(Y, N)
    print(" ".join(answer))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int group(int k)
{
    if (k == 2)
        return 3;
    if (k == 4 || k == 6 || k == 9 || k == 11)
        return 2;
    return 1;
}
int main()
{
    int x, y;
    cin >> x >> y;
    if (group(x) == group(y))
        puts("Yes");
    else
        puts("No");
}


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

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

	int N = 0;
	cin >> N;

	vector<double> A(N);
	for (int i = 0; i < N; i++)
		cin >> A[i];

	double ans = 0;
	for (int i = 0; i < N; i++)
	{
		ans += (1 / A[i]);
	}

	cout << 1 / ans;

	return 0;
}

Measured memory_bytes: 256
import sys
def main():
    a, b = map(int, input().split())
    k = 1
    cnt = 0

    if b == 1:
        print(cnt)
        sys.exit()

    while True:
        k += a-1
        cnt += 1
        if k >= b:
            break

    print(cnt)


if __name__ == '__main__':
    main()

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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  ll n, a, b, c, d, e;
  cin >> n >> a >> b >> c >> d >> e;
  
  ll minmove = min(a, min(b, min(c, min(d, e))));
  
  ll ans = (n+minmove-1) / minmove + 4;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3668
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n, m;
    cin >> n >> m;
    string a[n], b[m];
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j + m > n) continue;
            if (i + m > n) continue;
            int jud = 0;
            for (int k = 0; k < m; k++) {
                for (int l = 0; l < m; l++) {
                    if(b[k][l] != a[i + k][j + l]) jud++;
                }
            }
            if (jud == 0) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
def bfs(n, g):
    from collections import deque
    color = [-1] * n
    q = deque([0])
    while q:
        tmp = q.popleft()
        for u, w in g[tmp]:
            if color[u] != -1:
                continue
            color[u] = color[tmp] + w
            q.append(u)
    for c in color:
        if c % 2 == 0:
            print(1)
        else:
            print(0)


def main():
    n = int(input())
    g = [[] for _ in range(n)]
    for _ in range(n - 1):
        u, v, w = map(int, input().split())
        u -= 1
        v -= 1
        g[u].append([v, w])
        g[v].append([u, w])
    bfs(n, g)


if __name__ == "__main__":
    main()


Measured memory_bytes: 49356
from itertools import combinations

N = int(input())
P = []
for _ in range(N):
    x, y = map(int, input().split())
    P.append((x, y))

memo = dict()
for (a, b) in combinations(P, 2):
    p, q = a[0] - b[0], a[1] - b[1]
    if p < 0:
        p, q = -p, -q
    elif p == 0 and q < 0:
        q = -q
    if (p, q) in memo:
        memo[(p, q)] += 1
    else:
        memo[(p, q)] = 1

print(N - max(memo.values()) if N > 1 else 1)


Measured memory_bytes: 3188
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <algorithm>
#include <unordered_map>

using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
//static const auto _____ = []()
//{
//	ios::sync_with_stdio(false);
//	cin.tie(nullptr);
//	return nullptr;
//}();

int main(int argc, char *argv[]) {
    int H, W;
    cin >> H >> W;
    string tmp;
    vector<string> tb(H + 1, string(W + 1, '.'));
    for (int i = 1; i <= H; i++) {
        cin >> tmp;
        tb[i] = '.' + tmp;
    }
    int dp[H + 1][W + 1];
    memset(dp, 0, sizeof(dp));
    //base case
    for (int i = 1; i <= W; i++) {
        if (tb[1][i] == '#') break;
        else dp[1][i] = 1;
    }
    for (int i = 1; i <= H; i++) {
        if (tb[i][1] == '#') break;
        else dp[i][1] = 1;
    }
    for (int i = 2; i <= H; i++) {
        for (int j = 2; j <= W; j++) {
            if (tb[i][j] == '#') continue;
            else {
                if (tb[i - 1][j] == '.') dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
                if (tb[i][j - 1] == '.') dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
            }
        }
    }
    cout << dp[H][W];
    return 0;
}

Measured memory_bytes: 5120
N = int(input())
X = [-1] * N
A = [int(a)-1 for a in input().split()]
a, b, c = 0, 0, 0
for i in range(N+1):
    if X[A[i]] >= 0:
        a = X[A[i]]
        b = i - X[A[i]] - 1
        c = N - i
        break
    else:
        X[A[i]] = i

P = 10**9+7
fa = [1]
for i in range(1, N + 10):
    fa.append(fa[-1] * i % P)
fainv = [pow(fa[-1], P-2, P)]
for i in range(1, N + 10)[::-1]:
    fainv.append(fainv[-1] * i % P)
fainv = fainv[::-1]

def C(i, j):
    if j < 0 or j > i: return 0
    return fa[i] * fainv[j] % P * fainv[i-j] % P

for K in range(1, N+2):
    ans = C(N-1, K)
    ans += C(a+c, K-1) + 2 * (C(a+b+c, K-1) - C(a+c, K-1))
    ans += C(a+b+c, K-2)
    ans %= P
    print(ans)

Measured memory_bytes: 60140
#include <stdio.h>

int main(){
  int i,n,fib[45];

  fib[0]=1;
  fib[1]=1;


  for(i=2;i<45;i++){
    fib[i]=fib[i-1]+fib[i-2];
  }
  
  scanf("%d",&n);

  printf("%d\n",fib[n]);

  return 0;
}



Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int N; cin >> N;
  vector<int> A(N); rep(i,N) cin >> A[i];
  rep(i,N){
    if(A[i]%2==0){
      if(A[i]%3!=0 && A[i]%5!=0){
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}


Measured memory_bytes: 256
from sys import stdin, setrecursionlimit


def cmb(n, r, mod=10 ** 9 + 7):
    r = min(r, n - r)
    x = y = 1
    for i in range(r):
        x *= n - i
        x %= mod
        y *= i + 1
        y %= mod
    return x * pow(y, mod - 2, mod) % mod


def main():
    input = stdin.buffer.readline
    n, a, b = map(int, input().split())
    mod = 10 ** 9 + 7

    print((pow(2, n, mod) - 1 - cmb(n, a, mod) - cmb(n, b, mod)) % mod)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38512
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << endl;
#else
	#define DBG(X)
#endif

using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::pair;
using std::swap;
using std::sort;
using std::lower_bound;
using std::unique;

using int64 = long long int;
using pii   = pair<int, int>;
using pii64 = pair<int64, int64>;

const int NIL = -1;

void init_IO() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}

void solve() {
	int m, k;
	cin >> m >> k;

	if(m == 1) {
		if(k == 0) {
			cout << "0 0 1 1\n";
		} else {
			cout << "-1\n";
		}
	} else {
		int n = 1 << m;

		if(k < n) {
			for(int i = 0; i < n; ++i) {
				if(i != k)
					cout << i << ' ';
			}

			cout << k << ' ';

			for(int i = n - 1; i >= 0; --i) {
				if(i != k)
					cout << i << ' ';
			}

			cout << k << '\n';
		} else {
			cout << "-1\n";
		}
	}
}

int main() {
	init_IO();
	solve();

	return 0;
}


Measured memory_bytes: 1792
N = int(input())
s = [input() for i in range(N)]
M = int(input())
t = [input() for i in range(M)]

# 別のインスタンスを作成する
s2 = s[:]
# 和集合をとる
set(s2)
ans = 0

for i in s2:
    if ans < s.count(i) - t.count(i):
        ans = s.count(i) - t.count(i)

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
main(){
  int i,j;
  char a[8][8];
  while(scanf("%s",a[0])!=EOF){
    for(i=1;i<8;i++){
      scanf("%s",a[i]);
    }
    for(i=0;i<8;i++){
      for(j=0;j<8;j++){
    if(a[i][j]=='1'&&a[i][j+1]=='1'&&a[i+1][j]=='1'&&a[i+1][j+1]=='1'){
      printf("A\n");
      break;
      break;
    }
    else if(a[i][j]=='1'&&a[i+1][j]=='1'&&a[i+2][j]=='1'&&a[i+3][j]=='1'){
      printf("B\n");
      break;
      break;
    }
    else if(a[i][j]=='1'&&a[i][j+1]=='1'&&a[i][j+2]=='1'&&a[i][j+3]=='1'){
      printf("C\n");
      break;
      break;
    }
    else if(a[i][j]=='1'&&a[i+1][j-1]=='1'&&a[i+1][j]=='1'&&a[i+2][j-1]=='1'){
      printf("D\n");
      break;
      break;
    }
    else if(a[i][j]=='1'&&a[i][j+1]=='1'&&a[i+1][j+1]=='1'&&a[i+1][j+2]=='1'){
      printf("E\n");
      break;
      break;
    }
    else if(a[i][j]=='1'&&a[i+1][j]=='1'&&a[i+1][j+1]=='1'&&a[i+2][j+1]=='1'){
      printf("F\n");
      break;
      break;
    }
    else if(a[i][j]=='1'&&a[i][j+1]=='1'&&a[i+1][j]=='1'&&a[i+1][j-1]=='1'){
      printf("G\n");
      break;
      break;
    }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 524
X = int(input())

c = 1
result = False


while not result:
    for i in range(c):
        a = c -i
        b = i
        if a**5 - b**5 == X:
            result = True
            A = a
            B = b
            break
    if result == True:
        break
    for i in range(c):
        b = c - i
        a = - i
        if a**5 - b**5 == X:
            result = True
            A = a
            B = b
            break
    if result == True:
        break
    for i in range(c):
        a = -c+i
        b = -i
        if a**5 - b**5 == X:
            result = True
            A = a
            B = b
            break
    if result == True:
        break
    for i in range(c):
        a = i
        b = -c + i
        if a**5 - b**5 == X:
            result = True
            A = a
            B = b
            break
    if result == True:
        break
    c += 1

print(A, B)

Measured memory_bytes: 9108
// https://atcoder.jp/contests/abc054/tasks/abc054_c

use itertools::Itertools as _;
use petgraph::graph::UnGraph;
use proconio::input;
use proconio::marker::Usize1;

fn main() {
    input! {
        n: usize,
        abs: [(Usize1, Usize1)],
    }

    let graph = UnGraph::<(), (), usize>::from_edges(abs);
    let ans = graph
        .node_indices()
        .permutations(n)
        .filter(|p| p[0].index() == 0 && p.windows(2).all(|w| graph.contains_edge(w[0], w[1])))
        .count();
    println!("{}", ans);
}


Measured memory_bytes: 2140
#include <iostream>
using namespace std;
#define rep(i,n) for(int (i)=0;(i) < (n); (i)++)
long long int a[100005],b[100005];

int main(){
  int n;
  cin >> n;
  rep(i,n) cin >> a[i] >> b[i];
  long long int ans = 0;
  rep(i,n){
    long long int r = (a[n-i-1]+ans) % b[n-i-1];
    ans += (b[n-i-1] - r) % b[n-i-1];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
vector<int>v;
const int N=2e5+9;
/*ll mod=998244353;
ll dp[N];
int x,k;
ll f (int i)
{
    if (i==x)
        return 1;
    if (dp[i]!=-1)
        return dp[i];
    ll ans=0;
    for (int j=0; j<v.size(); j++)
    {
        if (i+v[j]<=x)
        {
            ans+=f(i+v[j]);
            ans%=mod;
        }
        else
            break;
    }
    return dp[i]=ans;
}*/
int main()
{
    FASTINOUT;
    ll n,x,m;
    cin>>n>>x>>m;
    ll ans=0,i;
    bool zero=0;
    vector<ll>v;
    map<ll,bool>visited;
    for (i=1; i<=n; i++)
    {
        v.push_back(x);
        ans+=x;
        x*=x;
        x%=m;
        if (visited[x])
            break;
        visited[x]=1;
        if (!x)
        {
            zero=1;
            break;
        }
    }
    if (zero)
    {
        cout<<ans<<endl;
        return 0;
    }
    if (i==n+1)
        i--;
    n-=i;
    if (!n)
    {
        cout<<ans;
        return 0;
    }
    ll pos=0;
    for (int j=0; j<v.size(); j++)
    {
        if (v[j]==x)
        {
            pos=j;
        }
    }
    ll k=0;
    for (int j=pos; j<v.size(); j++)
    {
        k+=(v[j]);
    }
    ll num=v.size()-pos;
    ll o=n/num;
    ans+=(o*k);
    n%=num;
    for (int j=pos; j<pos+n; j++)
    {
        if (j==v.size())
            break;
        ans+=v[j];
    }
    cout<<ans;
    /* cin>>x>>k;
     int l,r;
     for (int i=0; i<k; i++)
     {
         cin>>l>>r;
         for (int j=l; j<=r; j++)
         {
             v.push_back(j);
         }
     }
     sort(v.begin(),v.end());
     memset(dp,-1,sizeof dp);*/

    return 0;
}


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

int main (){
	int a,num=0,N=0;
	cin>>a;
	int arr[220];
	for(int i=1;i<210;i++){
		for(int j=1;j<101;j+=2){
		if(i%j==0){
		num++;
		}
		
		}
		if(num==7){
		N++;
		}
		num=0;
		arr[i]=N;
	}
	cout<<arr[a]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
# define ll long long
# define pb push_back
# define mo 1000000009
using namespace std;

bool check(string &str1, string &str2, int m, int n) 
{ 
    // Base Cases 
    if (m == 0) return true; 
    if (n == 0) return false; 
  
    // If last characters of two strings are matching 
    if (str1[m-1] == str2[n-1]) 
        return check(str1, str2, m-1, n-1); 
  
    // If last characters are not matching 
    return check(str1, str2, m, n-1); 
} 
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ans=0;
    for(char i='0';i<='9';i++)
    {
    	for(char j='0';j<='9';j++)
    	{
    		for(char k='0';k<='9';k++)
    		{
    			string t="";
    			t+=i;t+=j;t+=k;
    			if(check(t,s,3,n))
    			ans++;
			}
		}
	}
	cout<<ans;
	return 0;
}

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

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

    int x;
    vector<int> v;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) { cin >> x; v.pb(x); }

    int m;
    cin >> m;
    for (int i = 0; i < m; i++) {
        cin >> x;
        x--;
        if (v[x] + 1 == 2020) continue;
        if (x == v.size() - 1) v[x]++;
        else if (v[x] + 1 != v[x + 1]) v[x]++;
    }

    for (auto a : v) cout << a << "\n";
    return 0;
}



Measured memory_bytes: 3212
import sys
sys.setrecursionlimit(1000000)
 
def colorize(current_node, adjacents, colors, from_color, k):
    
    # そのノードから繋がるエッジを辿っていく
    count = 0
    for edge, node in adjacents[current_node]:
 
        # 既に塗られていたら無視
        if colors[edge]!=None:
            continue
        
        count += 1
        colors[edge] = (from_color+count)%k
        colorize(node, adjacents, colors, colors[edge], k)
     
N = int(input())
adjacents = {i+1:[] for i in range(N)}
 
for i in range(N-1):
    a,b = [int(e) for e in input().split(" ")]
    
    adjacents[a].append( [i+1,b] )
    adjacents[b].append( [i+1,a] )
 
# 一番隣接エッジ数が多いノード
most_edge =sorted(adjacents, key=lambda d:len(adjacents[d]))[-1]
k = len(adjacents[most_edge])
 
colors = {i+1:None for i in range(N-1)}
colorize(1, adjacents, colors, -1, k)
 
print(k)
for color in colors.values():
    print(color+1)

Measured memory_bytes: 90884
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1; rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)(n),(int)(n))
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,result=0,dMin=-1;
  int a[LIMIT2]={0};
  char s[LIMIT1];

  scanf("%lld",&n);
  for(i=1;i<=sqrt(n);i++){
    if(n%i == 0){
      if(dMin==-1) dMin = i + n/i;
      else dMin = min(dMin, i + n/i);
    }
  }
  printf("%lld",dMin-2);
  return 0;
}



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

void print_rectangle(int h, int w)
{ 
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			if ((i+j)%2 == 0)
				cout << "#";
			else
				cout << ".";
		}
		cout << "\n";
	}
	cout << "\n";
}

int main()
{
	int a, b;
	vector<int> A, B;
	do 
	{
		cin >> a >> b;
		if (a == 0 && b == 0)
			break;
		A.push_back(a);
		B.push_back(b);
	} while (true);

	for (int i = 0; i < A.size(); i++)
		print_rectangle(A[i], B[i]);
	return 0;
}




Measured memory_bytes: 3112
#include <iostream>

#include <list>
#include <string>

#include <cstring>

using std::cin;
using std::cout;
using std::endl;

using std::list;
using std::string;

using std::memset;

static int const MAXSIZE = 20;
static char road[MAXSIZE][MAXSIZE] = {0};
static int distance[MAXSIZE][MAXSIZE] = {0};
static int y_last = 0;
static int x_last = 0;
static int d_max = 0;
static list<int> q;
static int H = 0;
static int W = 0;

static void
trial_yx(int y, int x, int d)
{
  if (0 <= y && y < H && 0 <= x && x < W && road[y][x] && distance[y][x] == 0)
  {
    distance[y][x] = d + 1;
    if (d_max < d + 1)
    {
      d_max = d + 1;
    }
    y_last = y;
    x_last = x;
    q.push_back(y);
    q.push_back(x);
  }
}

static void
trial(int y_start, int x_start)
{
  memset((void *)distance, 0, sizeof(distance));
  q.push_back(y_start);
  q.push_back(x_start);
  while (!q.empty())
  {
    int y = q.front();
    q.pop_front();
    int x = q.front();
    q.pop_front();
    int d = distance[y][x];
    distance[y][x] = -1;
    trial_yx(y - 1, x, d);
    trial_yx(y + 1, x, d);
    trial_yx(y, x - 1, d);
    trial_yx(y, x + 1, d);
  }
}

int
main()
{
  cin >> H >> W;
  string S;
  for (int y = 0; y < H; y++)
  {
    cin >> S;
    for (int x = 0; x < W; x++)
    {
      road[y][x] = (S[x] == '.' ? 1 : 0);
    }
  }
  for (int y = 0; y < H; y++)
  {
    for (int x = 0; x < W; x++)
    {
      if (road[y][x])
      {
        trial(y, x);
      }
    }
  }
  cout << d_max << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int n,x;
	scanf("%i %i",&n,&x);
	vector<ll> a(n);
	for(int i=0;i<n;i++) scanf("%i",&a[i]);
	sort(a.begin(),a.end());
	int ans=0;
	for(int i=0;i<n-1;i++) if(a[i]<=x) x-=a[i],ans++;
	if(x==a[n-1]) ans++;
	printf("%i\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


char S[105];

int main() {
	
	scanf("%s", &S);

	int size ;

	for (int i = 0; i < 104; i++) {
		if (S[i] == '\0') {
			size = i;
			break;
		}
	}

	bool good = true;

	for (int i = 0; i < size; i++) {
		if (i % 2 == 1) {
			if (S[i] == 'R') {
				good = false;
				break;
			}
		}
		else {
			if (S[i] == 'L') {
				good = false;
				break;
			}


		}

	}


	if (good) {
		printf("Yes");
	}
	else {
		printf("No");
	}


}






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

int main() {
    string S;
    cin >> S;
    int n = S.size();
    rep(i,n) {
        cout << 'x';
    }
    cout << endl;
    return 0;
}

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


int main(){

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



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

int main() {

	string S;
	cin >> S;
	int price = 700;

	for(int i = 0; i < 3; i++) {
		if (S[i] == 'o')price += 100;
	}
	cout << price;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

		while(true){
			int n = sc.nextInt();
			if(n == 0) break;

			String a[] = new String[n], b[] = new String[n];
			for(int i=0;i<n;i++){
				a[i] = sc.next();
				b[i] = sc.next();
			}
			String from=sc.next(), to=sc.next();

			HashMap<String,Integer> open = new HashMap<String,Integer>();
			HashMap<String,Integer> next = new HashMap<String,Integer>();
			HashMap<String,Integer> end = new HashMap<String,Integer>();

			open.put(from,0);
			while(!open.isEmpty()){
				for(String s : open.keySet()){
					int cost = open.get(s);
					for(int i=0;i<n;i++){
						String ns = s.replaceAll(a[i],b[i]);
						if(s.equals(ns)) continue;
						if(ns.length() >= 6){
							if(end.containsKey(ns)) continue;
							end.put(ns,cost+1);
							continue;
						}
						if(next.containsKey(ns)) continue;
						next.put(ns,cost+1);
					}
				}
				open = next;
				next = new HashMap<String,Integer>();
			}

			int min = Integer.MAX_VALUE;
			open.put(to,0);
			while(!open.isEmpty()){
				for(String s : open.keySet()){
					int cost = open.get(s);

					if(end.containsKey(s)){
						min = Math.min(min,cost+end.get(s));
						continue;
					}
					for(int i=0;i<n;i++){
						String ns = s.replaceAll(b[i],a[i]);
						if(s.equals(ns)) continue;
						if(next.containsKey(ns)) continue;
						next.put(ns,cost+1);
					}
				}
				open = next;
				next = new HashMap<String,Integer>();
			}

			System.out.println(min==Integer.MAX_VALUE ? -1 : min);
		}

	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>

using namespace std;

void ABC135B()
{
	string str;
	cin >> str;
	int n = stoi(str);
	vector<int> p(n);
	for (auto& x : p)
	{
		cin >> str;
		x = stoi(str);
	}
	int ct = 0;
	for (int i = 0; i < n; ++i)
	{
		if (p[i] != i + 1)
			++ct;
	}
	if (ct < 3)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

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

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

long count_char(const unsigned char target, const char* s)
{
    long count = 0;
    
    while(*s != 0){
        if(target == *s){
            count++;
        }
        s++;
    }
    return count;
}

int main()
{
    int n;
    char s[100001] = {0};

    if(scanf("%d", &n) < 1){
        return 0;
    }
    if(scanf("%s",s) < 1) {
        return 0;
    }

    long char_counts[26] = {0};
    for(unsigned char i = 0; i < sizeof(char_counts)/sizeof(char_counts[0]) ; i++){
        char_counts[i] = count_char(0x61 + i, s);
    }

    long patterns = 1;
    for(int i = 0; i < sizeof(char_counts)/sizeof(char_counts[0]) ; i++){
        patterns *= char_counts[i] + 1;
        patterns %= 1000000007L;
    }

    patterns--;

    printf("%ld\n", patterns);

    return 0;
}



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


int main() {
	int n;
	int a[100] = {0};
	int count = 0;
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++) {
		scanf("%d", &(a[i]));
	}

	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			if (a[i] % 2 == 1) {
				count++;
			}
		}
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  long long int a,b,c,d=0,f,g,h;
  cin>>a>>b;
  cout<<a-b+1;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int x, y, z, k;
    cin >> x >> y >> z >> k;

    long long int a[2000], b[2000], c[2000];
    for (int i = 0; i < x; i++)
        cin >> a[i];

    for (int i = 0; i < y; i++)
        cin >> b[i];

    for (int i = 0; i < z; i++)
        cin >> c[i];

    sort(a, a + x, greater<long long int>());
    sort(b, b + y, greater<long long int>());
    sort(c, c + z, greater<long long int>());
    
    vector<long long int> ans;
    for (int xx = 0; xx < x; xx++){
        for (int yy = 0; yy < y; yy++){
            for (int zz = 0; zz < z; zz++){
                if ((xx + 1) * (yy + 1) * (zz + 1) > k)
                    break;
                ans.push_back(a[xx] + b[yy] + c[zz]);
            }
        }
    }

    sort(ans.begin(), ans.end(), greater<long long int>());

    for (int i = 0; i < k; i++)
        cout << ans[i] << '\n';

    return 0;
}


Measured memory_bytes: 1400
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int p[n];
    for(int i=0;i<n;++i)
    {
        cin >> p[i];
    }

    int ret = 0;
    for(int i=1;i<n-1;++i)
    {
        if((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i+1] < p[i] && p[i] < p[i-1]))
        {
            ret++;
        }
    }

    cout << ret << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
int n, i;
unsigned long long factorial = 1 ;
scanf("%d",&n);
if (n < 0 )
printf("\n");
else
{
for(i= 1 ; i<=n; ++i)
{
factorial *= i;
}
printf("%llu\n",factorial);
}
return 0 ;
}

Measured memory_bytes: 596
S = input()

cnt1 = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == "0":
            cnt1 += 1
    else:
        if S[i] == "1":
            cnt1 += 1

cnt2 = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == "1":
            cnt2 += 1
    else:
        if S[i] == "0":
            cnt2 += 1

print(min(cnt1, cnt2))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll getm(vector<int> a)
{
	int mina = 1e6;
	for(int i=0;i<a.size();i++)
		mina = min(mina,a[i]);
	return mina;
}
ll sol(vector<int> a)
{
	int sum =0;
	int mina;
	if(a.size() == 1)
		return a[0];
	mina = getm(a);
	a.push_back(mina);
	sum+=mina;
	vector<int> tmp;
	vector<vector<int>> all;/*
	cout<<"\n\n";
	for(int i=0;i<a.size();i++)cout<<a[i];
	cout<<"\n\n";*/
	for(int i=0;i<a.size();i++)
	{
		a[i]-=mina;
		if(a[i]>0)
			tmp.push_back(a[i]);
		else if(i>0&&a[i-1]>0)
		{
			all.push_back(tmp);
			tmp.clear();
		}
	}
	for(int i=0;i<all.size();i++)
	{
		sum+=sol(all[i]); 
	}
	return sum;
}
int main()
{
	int n;
	cin>>n;
	vector<int> a;
	for(int i=0;i<n;i++)
	{
		int j;
		cin>>j;
		a.push_back(j);
	}
	int sum = sol(a);
	cout<<sum<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  int n,m,k;
  cin >> n >> m >> k;
  vi a(n,0);
  vi b(m,0);
  rep(i,n) cin >> a.at(i);
  rep(i,m) cin >> b.at(i);

  ll tot = 0;
  rep(i,m) {
    tot+=b.at(i);
  }

  ll ans = 0;
  ll bj=m;
  rep(i,n+1) {
    while(tot>k and bj - 1>= 0) {
      tot-=b.at(bj-1);
      bj--;
    }
    if(tot>k) break;
    ans=max(ans,i+bj);
    if(i==n) break;
    tot+=a.at(i);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4764
#include "bits/stdc++.h"
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	map<int, int> mp;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < n; i++) {
		if (mp[a[i]] >= 1) {
			cout << "NO" << endl;
			return 0;
		}else
		    mp[a[i]]++;
	}

	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 10368
N = int(input())
A = list(map(int, input().split()))
ans = 0
flg = "True"

while flg == "True":
    ans += 1
    for i in range(N):
        if A[i] % 2 == 0:
            A[i] = A[i] / 2
        else:
            flg = "False"

print(ans - 1)


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

int main() {
  int n;
  int num = 0;
  ll sum = 0;
  cin >> n;
  vector<int> a(n);
  unordered_map<int, int> b;
  rep(i,n){
    cin >> num;
    a[i] = num;
    //キーがすでに含まれていればインクリメント
    if (b.find(num) != b.end()) {
      b.at(num)++;
      sum += b.at(num) - 1;
    //キーが含まれていなければ新たにキーを入れて値は1に設定
    } else {
      b[num] = 1;
    }
  }
  rep(i,n){
    if(b.at(a[i]) > 0){
      cout << sum - b.at(a[i]) + 1 << endl;
    }else {
      cout << sum << endl;
    }
  }
}

Measured memory_bytes: 8392
#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 drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
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;}
int const INF = 1001001001;
ll const MOD = 1000000007;


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

string s;
cin >> s;

int N = s.size();
int ans = INF;

rep(i,N-2) {
    string t = s.substr(i,3);
    int cur = abs(stoi(t)-753);
    ans = min(ans, cur);
}

cout << ans << endl;

return 0;
}

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

using lli = long long int;
using Vint = vector<int>;
using Vlli = vector<lli>;
using Wint = vector<Vint>;
using Wlli = vector<Vlli>;
using pii = pair<int, int>;
using pll = pair<lli, lli>;

const int MOD = 1e9 + 7;
const int INFi = 2e9 + 1;
const lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {make_pair(1, 0), make_pair(-1, 0), make_pair(0, 1), make_pair(0, -1)};

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(i, vec) for(auto &(i) : (vec))


template <class T> inline int argmin(vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){a = max(a, b);}
template <class T> inline void chmin(T &a, T b){a = min(a, b);}
inline int toInt(string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline int toInt(const string s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res = "";
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


int main(void){
  lli res = 0;
  int a, n; cin >> n;
  map<int, int> data;
  REP(i, n){
    cin >> a;
    data[a]++;
  }
  vREP(pr, data){
    if(pr.first > pr.second) res += pr.second;
    else res += (pr.second - pr.first);
  }
  cout << res << '\n';
  return 0;
}

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

int main(void) {
  while (1) {
    int M,m; char D[410]; int d;
    scanf("%s\n", D); d=strlen(D);
    if (D[0] == '-') break;
    scanf("%d\n", &M);
    for (m=0;m<M;m++) {
      int n;
      scanf("%d\n", &n);
      strncat(D,D,n);
      memmove(D,D+n,d);
      D[d] = 0;
    }
    printf("%s\n",D);
  }
  return 0;
}

Measured memory_bytes: 612
from collections import deque
import copy
S=deque(list(input()))
ans=1
l=S.popleft()
while len(S)>=1:
    x=S.popleft()
    if l!=x:
        ans+=1
        l=copy.deepcopy(x)
    else:
        if len(S)>=1:
            ans+=1
            l=copy.deepcopy(x)+S.popleft()
        else:
            break
print(ans)



Measured memory_bytes: 68160
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=(int)1e9+7;
const llint big=(llint)(2.19e12+1);
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int main(void){
	int a,b;cin>>a>>b;cout<<a*b<<" "<<2*(a+b)<<endl;
	RE;
}


Measured memory_bytes: 3100
A, B, K = map(int, input().split())

def func(M, L, K):
    count = 0

    for ans in reversed(range(1,L+1)):
        if M % ans == 0 and L % ans == 0:

            count += 1

            if count == K:
                print(ans)

if A > B:
    func(A, B, K)
else:
    func(B, A, K)


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

int main() {
  int n;
  int flag=0;
  string color;
  
  cin >> n;
  
  for(int i=0; i<n; i++){
    cin >> color;
    if(color=="Y"){
      flag=1;
      break;
    }
  }
  if(flag==1){
  	cout << "Four" << endl;
  }else{
    cout << "Three" << endl;
  }
    
}




Measured memory_bytes: 256
n,k = map(int, input().split())
p = list(map(int, input().split()))

m = sum(p[:k])
index = 0
tmp = sum(p[:k])
for i in range(n-k):
    tmp -= p[i]
    tmp += p[i+k]
    if tmp > m:
        m = tmp
        index = i+1

def calc_exp(p):
    return ((p * (p+1)) / 2) / p
        
exp = 0
for i in range(index,index+k):
    exp += calc_exp(p[i])

print(exp)


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

int main(){
    ll n, m; cin >> n >> m;
    vector<ll> a(n);
    map<ll, ll> ma;
    ma[0]++;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    ma[a[0]%m]++;
    for(int i = 1; i < n; i++){
        a[i] = (a[i-1] + a[i]) % m;
        ma[a[i]]++;
    }
    ll ans = 0;
    for(const auto& p: ma){
        ans += (p.second * (p.second-1)) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stdio.h>
#include<cmath>
#include<string.h>

using namespace std;

int main(void)
{
	int a, b, c;
	int i;
	cin >> a >> b >> c;
	for (i = 1; i < 100; i++)
	{
		if (c == (a*i) % b)
		{
			cout << "YES";
			break;
		}
	}
	if (i == 100)
	{
		cout << "NO";
	}
	cout << endl;

		return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>

bool is_palindromic_number(int x) {
    auto s = std::to_string(x);
    std::reverse(s.begin(), s.end());
    return std::to_string(x) == s;
}

int main() {
    int A, B;
    std::cin >> A >> B;

    int ret = 0;
    for (int i = A; i <= B; ++i) {
        if (is_palindromic_number(i)) {
            ++ret;
        }
    }

    std::cout << ret << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define P pair<ll, ll>

using namespace std;

int main(void){
  ll n;
  cin >> n;
  ll k = n;

  if (n == 1){
    cout << 0 << endl;
    return 0;
  }
  
  vector<ll> div(0);
  for (ll i = 2; i*i <= k; i++){
    if (n % i == 0){
      ll t = 0;
      while (n % i == 0){
        n /= i;
        t++;
      }
      div.emplace_back(t);
    }
  }
  if (n == k || n != 1)
    div.emplace_back(1);


  ll ans = 0;
  for (int i = 0; i < div.size(); i++){
    ll t = 0;
    while ((t + 1) * (t + 2) <= 2*div[i])
      t++;
    ans += t;
  }
  cout << ans << endl;
  

  return 0;
}


Measured memory_bytes: 3632