akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

typedef struct{
  char name[15];
  int time;

} process;

int main(void){
  int n;
  int q;
  int i, j, k;
  int p_time = 0;
  process *processes;
  int head = 0;
  int tail = 0;
  int size;

  scanf("%d%d", &n, &q);
  size = n + 2;
  processes = (process *)malloc(sizeof(process) * size);
  tail = n;

  for(i = 0; i < n; i++){
    scanf("%s", processes[i].name);
    scanf("%d", &processes[i].time);
  }

  while(head != tail){
    if(processes[head].time <= q){
      p_time += processes[head].time;
      printf("%s %d\n", processes[head].name, p_time);
      head = (head + 1) % size;
    }else {
      p_time += q;
      processes[head].time -= q;
      processes[tail] = processes[head];
      tail = (tail + 1) % size;
      head = (head + 1) % size;
    }
  }

  free(processes);
  return 0;
}

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

void merge(int A[],int left,int mid,int right, int flg,int count);
void mergeSort(int A[],int left,int mid,int right, int flg,int count);

void mergeSort(int A[],int left,int right, int flg, int count){
  int i,mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid,flg,count);
    mergeSort(A,mid,right,flg,count);
    merge(A,left,mid,right,flg,count);
  }
}

void merge(int A[],int left,int mid,int right, int flg, int count){
  int n1,n2,i,j,k;
  int *L,*R;
  n1=mid-left;
  n2=right-mid;
  L=(int *)malloc(sizeof(int)*(n1+1));
  R=(int *)malloc(sizeof(int)*(n2+1));
  for(i=0;i<=n1-1;i++){
    L[i]=A[left+i];
  }
  for(j=0;j<=n2-1;j++){
    R[j]=A[mid+j];
  }
  L[n1]=SENTINEL;
  R[n2]=SENTINEL;
  i=0;
  j=0;
  for(k=left;k<=right-1;k++){
   if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
      count++;
    }
    else{
      A[k]=R[j];
      j++;
      count++;
    }
  }
  free(L);
  free(R);
}

int main(){
  int count=0;
  int n;
  cin>>n;
  int A[n+1];
  for(int i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  int flg = 0;
  mergeSort(A,0,n,flg,count);
  // for(int i=0;i<n;i++){
  //   printf("%d",A[i]);
  // }
  for(int i=0;i<n-1;i++) if(A[i]==A[i+1]) flg = 1;
  (flg==0) ? printf("YES\n") : printf("NO\n");
  return 0;

}


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

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

const int INF = 1000000007;

int n, m;
bool flag[50];
int G[50][50];
int cnt;
void dfs(int now) {
	cnt++;
	flag[now] = true;
	for(int i=0;i<n;i++) {
		if(flag[i] == false && G[now][i]) dfs(i);
	}

	return;
}

int main(void){
 cin>>n>>m;

	int a[50] ={0}, b[50]={0};
	for(int i=0;i<m;i++){
		cin>>a[i]>>b[i];
		a[i]--; b[i]--;
		G[a[i]][b[i]] = 1;
		G[b[i]][a[i]] = 1;
	}

	int ans=0;
	for(int i=0;i<m;i++) {
		cnt = 0;
		for(int j=0;j<n;j++) flag[j] = false;

		G[a[i]][b[i]] = 0;
		G[b[i]][a[i]] = 0;

		dfs(0);

		G[a[i]][b[i]] = 1;
		G[b[i]][a[i]] = 1;
		if(n != cnt) ans++;
	}

	cout<< ans <<endl;

	return 0;
}

Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
int N, acnt, bcnt;
int x[10], A[10], B[10];

bool dfs(int cnt) {
    if (cnt == 10) return true;
    // Aに入れる
    if (A[acnt] < x[cnt]) {
        A[++acnt] = x[cnt];
        return dfs(cnt+1);
    }
    // Bに入れる
    else if (B[bcnt] < x[cnt]) {
        B[++bcnt] = x[cnt];
        return dfs(cnt+1);
    }
    return false;
}

int main(void) {
    cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 10; j++) {
            A[j] = 0; B[j] = 0;
        }
        acnt = 0; bcnt = 0;
        for (int j = 0; j < 10; j++) cin >> x[j];
        if (dfs(0)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7
    #epsilon = 10**-9

    n = int(input())
    if n%1000 == 0:
        print(0)
    else:
        print(1000-n%1000)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9468
#include <iostream>
#include <cmath>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
int coinCount[50001];
int coin[21];
int getMinCount (int val,int m) {
	int tmp = 100000;
	if(coinCount[val] == -1){
		for(int i = 0; i < m; i ++){
			if((val - coin[i] > 0)){
				if(tmp > (getMinCount(val - coin[i],m) + 1)){
					tmp = getMinCount(val - coin[i],m) + 1;
				}
			}
		}
		coinCount[val] = tmp;
	}else{
		tmp = coinCount[val];
	}
	return tmp;
}
int main () {
	int n,m;
	cin >> n >> m;
	for(int i =0; i < m; i++) cin >> coin[i];
	for(int i = 0; i <= n; i++){
		coinCount[i] = -1;
	}
	for(int i = 0; i < m; i++){
		coinCount[coin[i]] = 1;
	}
	cout << getMinCount(n,m) << endl;
}


Measured memory_bytes: 5616
from collections import deque
n=int(input())
l=[[]for i in range(n+1)]
for i in range(n-1):
 a,b=map(int,input().split())
 l[a-1].append(b-1)
 l[b-1].append(a-1)
def bfs(j):
 dl=[-1]*n
 dl[j]=0
 que=deque([j])
 while que:
  p=que.popleft();d=dl[p]+1
  for u in l[p]:
   if dl[u]>=0:continue
   dl[u]=d;que.append(u)
 return dl.index(max(dl)),max(dl)
m,_=bfs(0)
_,L=bfs(m)
print("Second"if L%3==1else"First")

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, ll> mp;
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += mp[i - a[i]];
        mp[i + a[i]]++;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 26660
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int a,b,c,d=0,f=0;
	cin>>a>>b>>c;
	if(b>=a)
	cout<<c<<endl;
	else
	{
	for(int i=1;i<=1000;i++)
	{
	if(i*b>=a)
	{
	d=i*c;
	f=1;
	break;
}
}
if(f==1)
cout<<d<<endl;
}
	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#define ll                  long long int
#define ull                 unsigned long long int
#define ld                  long double
#define fi                  first
#define se                  second
#define pb                  push_back
#define pbb                 pop_back
#define mp                  make_pair
#define pii     	        pair<int,int>
#define all(x)              x.begin(), x.end()
#define uniq(x)             x.erase(unique(x.begin(),x.end()),x.end())
#define mem(array, value)   memset(array, value, sizeof(array))
#define lcm(a,b)            (abs(a)/gcd(a,b))*abs(b)
#define PI      	        2*acos(0.0)
#define INF     	        1e9
#define EPS     	        1e-8
#define line                cout << "\n==========\n"
#define fastRead 	        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet; 

const int N = 1e5+9;
int ara[N];
int dp[N];

int main ()
{
    #ifdef Lollipop
    //freopen ("input.txt", "r", stdin);
    //freopen ("output.txt", "w", stdout);
    #endif
    
    int n, k;
    cin >> n >> k;
    for (int i = 0; i<n; i++){
        cin >> ara[i];
    }
    dp[0] = 0;
    for (int i = 1; i<n; i++){
        dp[i] = dp[i-1] + abs(ara[i] - ara[i-1]);
        for (int j = 2; j<=k; j++){
            if (i-j >= 0){
                dp[i] = min(dp[i], dp[i-j] + abs(ara[i] - ara[i-j]));
            }
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}



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

int main(){
    string S;
    int o = 0, e = 0;
    bool flag = true;
    cin >> S;
    repc(i, S.begin(), S.end()){
        if(flag){
            if(*i == '0'){
                o++;
            }else{
                e++;
            }
            flag = false;
        }else{
            if(*i == '0'){
                e++;
            }else{
                o++;
            }
            flag = true;
        }
    }
    cout << min(e, o) << endl;
    return 0;
}

Measured memory_bytes: 512
fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    val A = sc.next().toInt()
    val B = sc.next().toInt()
    val C = sc.next().toInt()
    val D = sc.next().toInt()
    println( (if (A < B) A else B ) + (if (C < D) C else D ) )
}

Measured memory_bytes: 29596
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
    int main(){
      int n;
      cin >> n;
      int a[n];
      rep(i,n)cin >> a[i];
      int sum=abs(a[0]);
      rep(i,n-1)sum+=abs(a[i+1]-a[i]);
      sum+=abs(a[n-1]);
      rep(i,n){
        if(i==0){
         cout << sum+abs(a[1])-abs(a[0])-abs(a[0]-a[1]) << endl; 
        }
        else if (0<i && i<n-1){
         cout << sum+abs(a[i-1]-a[i+1])-abs(a[i-1]-a[i])-abs(a[i]-a[i+1]) << endl; 
        }
        else{
         cout << sum+abs(a[n-2])-abs(a[n-1])-abs(a[n-1]-a[n-2]) <<endl; 
        }
      }
      return 0;}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> V(N);
  REP(i, N) cin >> V[i];
  int ans = 0;
  for (int A = 0; A <= min(N, K); ++A) {
    for (int B = 0; A + B <= min(N, K); ++B) {
      vector<int> vc;
      REP(i, A) vc.push_back(V[i]);
      REP(i, B) vc.push_back(V[N - 1 - i]);
      sort(ALL(vc));
      int cnt = K - (A + B);
      REP(i, vc.size()) {
        if (vc[i] < 0 && 0 < cnt) {
          cnt--;
          vc[i] = 0;
        }
      }
      int sum = 0;
      REP(i, vc.size()) sum += vc[i];
      ans = max(ans, sum);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1)/*v1の後ろにv2を入れる*/)
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);

pair<int, int>wake(int h, int w) {
	int ans = h*w;
	if ((ans % 2) == 0)return make_pair(ans / 2, ans / 2);
	int p = max(h, w), x = min(h, w);
	assert(ans == x*(p / 2) + x*(p / 2 + 1));
	return make_pair(x*(p / 2), x*(p / 2 + 1));
}

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

	int H, W;
	cin >> H >> W;

	int ans = intmax;
	REP(i, 1, H) {
		int p1 = i*W;
		auto p2 = wake(H - i, W);
		int a = min(p1, min(p2.first, p2.second));
		int b = max(p1, max(p2.first, p2.second));
		ans = min(ans, b - a);
	}
	REP(i, 1, W) {
		int p1 = i*H;
		auto p2 = wake(W - i, H);
		int a = min(p1, min(p2.first, p2.second));
		int b = max(p1, max(p2.first, p2.second));
		ans = min(ans, b - a);
	}
	cout << ans << endl;

	return 0;
}

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

int main(){
    int N,W;
    cin>>N>>W;
    int V[110];
    int O[110];
    for(int i = 0;i < N;i++){
        cin >> V[i] >> O[i];
    }
    int dp[110][10010];
    for(int i = 0;i < N;i++){
        for(int j = 0;j <= W;j++){
            if(O[i] <= j){
                dp[i+1][j] = max(dp[i][j - O[i]] + V[i],dp[i][j]);
            }else{
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    cout << dp[N][W] << endl;
}



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

int main() {
  int N;
  cin >> N;
  // int型の2次元配列(3×4要素の)の宣言
  vector<vector<int>> data(N, vector<int>(3));

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> data.at(i).at(j);
    }
  }

  //cout << data.at(1).at(2) << endl;
  int x =0, y=0, t=0;
  bool pos=true;
  for(int i=0;i<N;i++){
    int time = data.at(i).at(0) - t;
    int dist = abs( data.at(i).at(1) - x) +abs( data.at(i).at(2) - y);
    if(dist<= time && dist%2 == time%2){
      //cout << i << endl;
        x =data.at(i).at(1);
        y =data.at(i).at(2);
        t=data.at(i).at(0);
        continue;
      }
    else{
      pos=false;
      break;
    }
  }
  if(pos==true) cout << "Yes" << endl;
  else cout << "No" << endl;
  }


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

int main()
{
    long long n, m, a, ans = 0;


    cin >> n >> m;

    for (int i = 0; i < m; i++) {
        cin >> a;
        ans += a;
    }

    if (n >= ans) {
        cout << n - ans << endl;
    }
    else {
        cout << -1 << endl;
    }

    return 0;
}

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

int main() {
  int r;
  scanf("%d", &r);
  if (r<1200) printf("ABC\n");
  else if (r<2800) printf("ARC\n");
  else printf("AGC\n");
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
 
#define W 0
#define G 1
#define B 2
#define N 100
 

 
int d[N], f[N], c[N];
int time, n;
int g[N][N];

void dv(int b){
    int k;
     
    c[b]=G;
    d[b]=++time;
     
    for(k=0;k<n;k++){
        if(g[b][k]==0) continue;
        if(c[k]==W) dv(k);
    }
     
    c[b]=B;
    f[b]=++time;
}

void dfs(){
  int a;
  for(a=0;a<n;a++){
    c[a]=W;
    }
  time=0;
  
  for(a=0;a<n;a++){
    if(c[a]==W) dv(a);
  }
  
  for(a=0;a<n;a++){
      printf("%d %d %d\n",a+1,d[a],f[a]);
  }
}


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

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

int main() {
  string s, w;
  cin >> s;
  
  for(int i=0; i<s.size(); i++){
    if(i % 2 == 0){
      w += s.at(i);
    }
  }
  
  cout << w << endl;
  
  return 0;
}

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

int main(void)
{
    int N;
    bool is_seven_contain = false;

    cin >> N;

    while( N != 0 )
    {
        if( (N % 10) == 7) is_seven_contain += true;
        N /= 10;
    }

    if(is_seven_contain)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
import sys
A = int(input())
B = int(input())
C = int(input())
D = int(input())
if not (1 <= A and B and C and D <= 1000):
    sys.exit()

result = 0
if A >= B:
    result += B
else:
    result += A
if C >= D:
    result += D
else:
    result += C
print(result)

Measured memory_bytes: 9148
#include<bits/stdc++.h>
using namespace std;
//extgcd(a, b, x, y): a と b の最大公約数を返す。 
//x,y には ax+by=gcd(a,b) なる x,y が格納される。
template< typename T >
T extgcd(T a, T b, T &x, T &y) {
  T d = a;
  if(b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}
int main(){
  int a,b,x,y;
  cin>>a>>b;
  extgcd(a,b,x,y);
  cout<<x<<' '<<y<<'\n';
  return(0);
}


Measured memory_bytes: 3096
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    N = n * 2
    for i in range(1, int(pow(N, 0.5)) + 1):
        if N % i == 0 and abs(N // i - i) == 1:
            x, y = i, N // i
            print("Yes")
            print(y)
            break
    else:
        print("No")
        exit()

    res = [[0] * x for _ in range(y)]
    num = 1
    left = 0
    while left < y:
        for i in range(left, x):
            res[left][i] = num
            res[i + 1][left] = num
            num += 1
        left += 1

    for i in res:
        print(x, *i)


if __name__ == '__main__':
    resolve()


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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 200010, M = 45;

int n;
int cnt[N][M];
LL a[N];

bool check(int l, int r)
{
	for (int i = 0; i < M; i ++ )
		if (cnt[r][i] - cnt[l][i] >= 2)
			return false;
	return true;
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++ )
	{
		scanf("%lld", &a[i]);
		for (int j = 0; j < M; j ++ )
		{
			cnt[i][j] += (a[i] >> j) & 1;
			cnt[i][j] += cnt[i - 1][j];
		}
	}
	
	LL res = 0;
	for (int i = 1; i <= n; i ++ )
	{
		int l = 0, r = i - 1;
		while (l < r)
		{
			int mid = l + r >> 1;
			if (check(mid, i)) r = mid;
			else l = mid + 1;
		}
		res += i - r - 1;
	}
	
	printf("%lld\n", res + n);
	return 0;
}

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

int main() {
    std::string S, T;
    std::cin >> S >> T;

    int ans = 0;
    for (size_t i = 0; i < S.size(); ++i) {
        if (S[i] != T[i]) {
            ++ans;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653

int main(){
	string s; cin >> s;
	if (s=="ABC"){
		cout << "ARC" << endl;
	}
	else{
		cout << "ABC" << endl;
	}
}

Measured memory_bytes: 3624
package main
 
import (
  "fmt"
)
 
func main() {
  var S string
  fmt.Scan(&S)
  
  str := make(map[string]int)
  for i := 0; i < len(S); i++ {
    str[S[i:i+1]]++
  }
  
  ans := "yes"
  for _, v := range str {
    if v > 1 {
      ans = "no"
      break
    }
  }
  fmt.Printf("%s\n", ans)
}

Measured memory_bytes: 1832
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int n,a[205],ans;
bool cmp(int a,int b){
	return a<b;
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	in(n);
	for(int i=1;i<=2*n;i++){
		in(a[i]);
	}
	sort(a+1,a+(2*n)+1,cmp);
	for(int i=1;i<=n;i++)
	ans+=a[2*i-1];
	printf("%d\n",ans);
	return 0;
}
//https://www.bilibili.com/video/av38965436/?p=4


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

int main() {
   int N;
   cin>>N;
  int f=0,a=N;
  for(int i=0; ;i++){ 
    f+=a%10;
    a/=10;
    if(a==0)break;
  }
  if(N%f==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using Lint=long long;
const Lint INF=1e18;

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

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

    vector<Lint> sum(N+1);
    for(int i=0;i<N;i++) sum[i+1]=sum[i]+a[i];

    Lint ans=INF;
    for(int i=1;i<=N-1;i++){
        Lint a=sum[i],b=sum[N]-sum[i];
        chmin(ans,abs(a-b));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3456
N=int(input())
L=[]
n=0

for i in range(N):
    L.append(int(input()))
    Lsort=sorted(L)
# print(Lsort)

for j in range(N-1):
    if Lsort[j]==Lsort[j+1]:
        n-=1

print(N+n)

Measured memory_bytes: 3060
#include"bits/stdc++.h"

using namespace std;

int main() {
	int a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k;

	if (abs(a - b) <= k&& abs(a - c) <= k&& abs(a - d) <= k&& abs(a - e) <= k&& abs(b - c) <= k&& abs(b - d) <= k&& abs(b - e) <= k&& abs(c - d) <= k &&abs(c - e) <= k&&abs(d - e) <= k) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
A, B = [int(x) for x in input().strip().split()]

def gcd(a,b):
    while b!=0:
        a, b = b, a % b
    return a

def lcm(a,b):
    return a * b // gcd(a, b)

print(lcm(A, B))

Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
	int h,m,s,h2,m2,s2,i;
	int z,zz,zzz,h3,m3,s3,m4;
	for(i=0;i<3;i++){
		scanf("%d %d %d %d %d %d ",&h,&m,&s,&h2,&m2,&s2);
		z=h*3600+m*60+s;
		zz=h2*3600+m2*60+s2;
		zzz=zz-z;
		s3=zzz%60;
		m3=zzz/60;
		m4=m3%60;
		h3=m3/60;
		printf("%d %d %d\n",h3,m4,s3);
	}
	return 0;
}
		
		
		

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

class edge{
public:
	Int cost;
	size_t from, to;
	edge(Int c, size_t f, size_t t){
		cost = c;
		from = f;
		to = t;
	}
};
using edges = vector<edge>;
using graph = vector<edges>;
void readgraph(graph &g, size_t E, bool D, bool C, bool Z){ // E:num_of_edges, D:directed, C:costed, Z:already 0-indexed
	for(size_t i=0; i<E; ++i){
		edge e(1, 0, 0);
		if(!C) cin >> e.from >> e.to;
		else cin >> e.from >> e.to >> e.cost;
		if(!Z){
			--e.from;
			--e.to;
		}
		g[e.from].push_back(e);
		if(!D){
			swap(e.from, e.to);
			g[e.from].push_back(e);
		}
	}
}

void dfs(Int v, Int p, Int d, graph &g, vector<vector<Int>> &parent, vector<Int> &depth){
	parent[0][v] = p;
	depth[v] = d;
	for(auto e:g[v])
		if((Int)e.to != p)
			dfs(e.to, v, d+1, g, parent, depth);
}

void init(Int v, graph &g, vector<vector<Int>> &parent, vector<Int> &depth){
	dfs(v, -1, 0, g, parent, depth);
	for(Int k=0; k+1<20; ++k)
		for(Int i=0; i<(Int)g.size(); ++i){
			if(parent[k][i] < 0) parent[k+1][i] = -1;
			else parent[k+1][i] = parent[k][parent[k][i]];
		}
}

Int lca(Int a, Int b, vector<vector<Int>> &parent, vector<Int> &depth){
	if(depth[a] > depth[b]) swap(a, b);
	for(Int k=0; k<20; ++k)
		if((depth[b] - depth[a]) >> k & 1)
			b = parent[k][b];
	if(a == b) return a;
	for(Int k=19; k>=0; --k)
		if(parent[k][a] != parent[k][b]){
			a = parent[k][a];
			b = parent[k][b];
		}
	return parent[0][a];
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Int n, u, v; cin >> n >> u >> v; --u; --v;
	graph g(n);
	readgraph(g, n-1, false, false, false);
	vector<vector<Int>> parent(20, vector<Int>(n, -1));
	vector<Int> depth(n);
	init(v, g, parent, depth);
	Int ans = 0;
	for(Int i=0; i<n; ++i)
		if(g[i].size() == 1){
			Int x = lca(u, i, parent, depth);
			if(x == v || depth[u] - depth[x] >= depth[x]){
				ans = max(ans, depth[u]/2);
			}else{
//				cerr << i << " " << x << "\n";
				ans = max(ans, depth[i]-1);
			}
		}
	cout << ans << "\n";
}

Measured memory_bytes: 32240
#include <iostream>

typedef long long ll;

const ll MOD = ll(1e9) + 7;

int main()
{
	int n, m;
	while(std::cin >> n >> m)
	{
		ll ans = 1;
		int a = std::min(n, m);
		int b = std::max(n, m);
		for(int i = 1; i <= a; i++)
			ans = ans * i % MOD;
		for(int i = 1; i <= b; i++)
			ans = ans * i % MOD;
		if(a == b - 1)
			ans = ans;
		else if(a == b)
			ans = ans * 2 % MOD;
		else
			ans = 0;
		std::cout << ans << '\n';
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
    char s[105];
    scanf("%s",s);
    int n = strlen(s),i;
    for(i=0;i<n;i++)
    {
        if((i+1)%2==1 && s[i]=='L')
        {
            printf("No");
            return 0;
        }
        if((i+1)%2==0 && s[i]=='R')
        {
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}


Measured memory_bytes: 128
use std::cmp::max;

// remainder-reminder.rs --- Remainder Reminder
// author: Seong Yong-ju <sei40kr@gmail.com>

// tanakah's input macro
// cf https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
      n: i64,
      k: i64,
    };

    let ans = (k + 1..(n + 1))
        .map(|b| (b - k) * (n / b) + max(0, (n % b) - max(0, k - 1)))
        .sum::<i64>();
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false),cin.tie(0);
#define F first
#define S second
using namespace std;
typedef long long ll;
ll a,b,c,d;
const ll maxn=200005;
const ll mod=1e9+7;
typedef pair<ll,ll> pii;
ll num[100005];
ll n,k,x,y;
string s;
int main()
{
    IOS
    while(cin>>n)
    {
        vector<pii> v;
        rep(i,n)
        {
            cin>>a>>b;
            v.pb({b,a});
        }
        sort(v.begin(),v.end());
        ll now=0;
        bool flag=true;
        rep(i,n)
        {
            now=now+v[i].S;
            if(now>v[i].F) {flag=false; break;}
        }
        if(flag) cout<<"Yes\n";
        else cout<<"No\n";
    }


}


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

using namespace std;
using ll = long long;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

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


const int mod = 1e9 + 7;

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    string s;
    cin >> s;
    char t;

    vector<char> v, u;
    int ab[26] = {};
    rep(i, s.length())
    {
        v.push_back(s[i]);
        ab[s[i] - 'a']++;
    }
    u = v;
    if (v.size() == 26)
    {
        if (!next_permutation(v.begin(), v.end()))
            cout << -1 << endl;
        else
        {
            rep(i, 26)
            {
                cout << v[i];
                if (v[i] != u[i])
                    break;
            }
        }
    }

    else
    {
        rep(i, 26)
        {
            if (!ab[i])
            {
                t = i + 'a';
                break;
            }
        }
        cout << s << t << endl;
    }

    return 0;
}


Measured memory_bytes: 256
n=int(input())
a= [ list(map(int,input().split(" "))) for i in range(2)]
up=[0]*n
down=[0]*n
up[0]=a[0][0]
sum_down=0
for i in range(n):
    sum_down+=a[1][i]
down[0]=sum_down
for i in range(1,n):
    up[i]=a[0][i]+up[i-1]
    down[i]=down[i-1]-a[1][i-1]
ans=[]
for i in range(n):
    pre=0
    pre+=up[i]+down[i]
    ans.append(pre)
print(max(ans))

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

vector <pair<ll,ll>>prime_factorize(ll n){
    vector<pair<ll,ll>> res;
    for(ll i=2;i*i<n;++i) {
        ll num=0;
        if(n%i!=0) continue;
        while(n%i==0) {
            ++num;
            n/=i;
        }
        res.push_back(make_pair(i,num));
    }
    if(n!=1) res.push_back(make_pair(n,1));
    return res;
}

ll gcd(ll x, ll y) {
    if(x%y==0) return y;
    else return gcd(y,x%y);
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll x=gcd(a,b);
    auto pf=prime_factorize(x);
    cout << pf.size()+1 << endl;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
l=[list(map(int,input().split())) for i in range(k)]
x=[0]*(n+1)
x[0]=1
l.sort()
t=0
for i in range(1,n+1):
    for j in range(k):
        if i-l[j][1]>0:
            t+=x[i-l[j][0]]-x[i-l[j][1]-1]
        elif i-l[j][0]>=0:
            t+=x[i-l[j][0]]
        t=t%998244353
        x[i]=t
print(x[n-1])

Measured memory_bytes: 69716
var lines =[];

var readline = require("readline");
var rl = readline.createInterface({
  input:  process.stdin,
  output: process.stdout
});

rl.on('line',function(x){
  lines.push(x);
});

rl.on('close',function(){
  var a = [];
  var n = Number(lines[0].split(" "));
  var tmp = lines[1].split(" ");
  var result = 0;

  for(var i=0;i<n;i++){
    a[i]=Number(tmp[i]);
  }

  a.sort(function(a,b){return(a-b )});
  result = a[0];
  var result_before = 0;
  var damage = 0;
  var atack = a[0];

  while(1){
    result_before = result;
    for(var i=0;i<n;i++){
      damage = a[i]
      damage = damage%atack;
      if(damage < result && damage !== 0){result = damage;}
    }
    if(result < atack){atack = result;}
    if(result_before === result){break;}
  }
  console.log(result);
});


Measured memory_bytes: 30648
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

int main(){

  long long int A, P;
  scanf("%lld%lld", &A, &P);

  std::cerr << "Answre: " << std::endl;
  std::cout << (3*A+P)/2 << std::endl;

  return 0;
  
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define ASSERT(expr...) assert((expr))

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;
using ll = long long;

constexpr i64 INF = 1010000000000000017LL;

constexpr i64 MOD = 1000000007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

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

ll mod_pow_r(ll x, ll n) {
    if (x == 0) return 0;
    if (n == 0) return 1;

    ll ret = 1;
    while (n) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n /= 2;
    }
    return ret;
}

ll factorial(ll n) {
    ll ret = 1;
    REP(i, n) {
        ret *= (i + 1);
        ret %= MOD;
    }
    return ret;
}

ll combination(ll n, ll r) {
    if (n < 0 || n < r || r < 0) return 0;
    ll fn = factorial(n);
    ll fr = factorial(r);
    ll fn_r = factorial(n-r);

    ll d = (mod_pow(fr, MOD - 2) * mod_pow(fn_r, MOD - 2)) % MOD;
    ll u = fn % MOD;
    return u * d % MOD;
}

void solve() {
    int N; cin >> N;
    string S; cin >> S;
    string SS = "";
    for (auto i = 0; i < S.size(); ++i) {
        int x = S[i] - 'A';
        x = (x + N) % 26;
        SS += ('A' + x);
    }
    cout << SS;
}

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

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

int main(void) {

	int R;
	std::string s;
	std::cin >> R;
	if (R < 1200) {
		s = "ABC";
	} else if (R < 2800) {
		s = "ARC";
	} else {
		s = "AGC";
	}

	std::cout << s << std::endl;

	return 0;
}


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

std::string s;
int ans[2] = { -1,-1 };

int main()
{
	std::cin >> s;

	for (int i = 0; i <= s.length() - 2; ++i)
	{
		if (s[i] == s[i + 1])
		{
			ans[0] = i + 1, ans[1] = i + 2;
			break;
		}
		if (s[i] == s[i + 2])
		{
			ans[0] = i + 1, ans[1] = i + 3;
			break;
		}
	}

	printf("%d %d\n", ans[0], ans[1]);
	return 0;
}

Measured memory_bytes: 512
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#define l(x) (x<<1)
#define r(x) ((x<<1)+1)
#define IL inline
#define reg register
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;

int n,i,x;
int p[5],u[5],s[2][200010];
char c[200010];

IL int Abs(int x){return (x<0)?-x:x;}
IL void Swap(int &a,int &b){a^=b^=a^=b;}
IL int Min(int a,int b){return (a<b)?a:b;}
IL int Max(int a,int b){return (a>b)?a:b;}

IL int read(){
	int p=0,f=1;	char	c=getchar();
	while (c<48||c>57)	{if (c=='-')	f=-1;	c=getchar();}
	while (c>=48&&c<=57)	p=(p<<1)+(p<<3)+c-48,c=getchar();
	return p*f;
}

IL int Cal(int x){
	int cnt=0,y=0,t=0;
	while (x){
		y=0;	t=x;
		while (x){y+=(x&1);	x/=2;}
		cnt++;	x=t%y;
	}
	return cnt;
}

IL void Ready(){
	int i=0,j=0;
	p[0]=x-1;	p[1]=x+1;
	if (p[0]>0)
	for (i=0,j=1;i<n;i++,j=(j<<1)%p[0]){
		s[0][i]=j;
		if (c[i]=='1')	u[0]=(u[0]+j)%p[0];
	}
	if (p[1]>0)
	for (i=0,j=1;i<n;i++,j=(j<<1)%p[1]){
		s[1][i]=j;
		if (c[i]=='1')	u[1]=(u[1]+j)%p[1];
	}
}

IL int Work(int no,int f){
	if (!f){
		return 1+Cal((u[1]+s[1][no])%p[1]);
	}	else {
		if (p[0]==0)	return 0;
		else return 1+Cal((u[0]-s[0][no]+p[0])%p[0]);
	}
}

int main(){
	#ifdef __Marvolo
	freopen("zht.in","r",stdin);
	freopen("zht.out","w",stdout);
	#endif
	n=read();
	scanf("%s",&c);
	char s=0;
	for (i=0;i<n;i++)	x+=c[i]-48;
	for (i=0;n-i-1>i;i++){
		s=c[i];	c[i]=c[n-i-1];	c[n-i-1]=s;
	}
	if (x==0){
		for (i=1;i<=n;i++)	puts("1");
		return 0;
	}
	Ready();
	for (i=n-1;i>=0;i--){
		if (c[i]=='0')	printf("%d\n",Work(i,0));
		else printf("%d\n",Work(i,1));
	}
	return 0;
}

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

int main(){

    string s;
    int K;
    set<string> substring;

    cin >> s;
    cin >> K;

    for(int i = 0; i < s.size(); i++){
        for(int j = 0; j <= K; j++){
            substring.insert(s.substr(i, j));
        }
    }

    auto itr = substring.begin();
    for(int i = 0; i < K; i++) itr++;
    cout << *itr << endl;
    
    return 0;
}

Measured memory_bytes: 1664
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;



string tt(string, int);
string countChar(string);

int main(){
  int c;
  string text;
  while(true){
    cin >> c;
    if(!c)
      break;
    cin >> text;
    cout << tt(text, c) << endl;
  }
  return 0;
}

string tt(string text, int cnt){
  int index = 0;
  string s = text;
  if(cnt){
    //cout << "tt "<< text << " " << cnt << endl;                                                                                                                                     
    s = tt(countChar(text), cnt - 1);
    //cout << "s " << s << endl;                                                                                                                                                      
  }
  return s;
}

string countChar(string text){
  string ntext ="";
  int index = 0;

  while(text[index] != '\0'){
    char count[10] = {0};
    int i = 0;
    while(text[index] == text[index + i]){
      i++;
    }
    sprintf(count, "%d%c", i, text[index]);
    ntext += string(count);
    index += i;
  }
  //cout << "cc " << ntext << endl;                                                                                                                                                   
  return ntext;
}

Measured memory_bytes: 1532
#include<bits/stdc++.h>
using namespace std;
using pll = pair<long long, long long>;

int main(){
    int N, M; cin >> N >> M; 
    vector<pll> v;
    for(int i = 0; i < N; i++){
        int a; cin >> a;
        v.push_back({a, 1});
    }
    for(int i = 0; i < M; i++){
        int b, c; cin >> b >> c;
        v.push_back({c, b});
    }
    sort(v.begin(), v.end(), greater<pll>());

    long long num = 0;
    long long res = 0;
    for(auto p : v){
        if(num + p.second <= N){
            res += p.first *= p.second;
            num += p.second;
        }else{
            res += p.first * (N - num);
            num = N;
            break;
        }
    }
    cout<< res << endl;
}

Measured memory_bytes: 6256
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.SplitInt();
            var H = line[0];
            var W = line[1];

            var a = consoleReader.Repeat(H).ToArray();
            a = a.Where(w => w.Any(c=>c=='#')).ToArray();
            H = a.Length;

            var res = new System.Text.StringBuilder[H];
            for (int i = 0; i < H; i++)
                res[i] = new System.Text.StringBuilder(W);

            for (int i = 0; i < W; i++)
            {
                bool all = true;
                for (int j = 0; j < H; j++)
                {
                    res[j].Append(a[j][i]);
                    if (a[j][i] != '.')
                        all = false;
                }
                if (all)
                    for (int j = 0; j < H; j++)
                        res[j].Remove(res[j].Length - 1, 1);
            }

            return MultiLine(res);
        }

        public const int mod = 1000000007;
        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc()); static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

    #region Console
    public class ConsoleReader { public virtual string String() => Console.ReadLine(); public int Int() => int.Parse(String()); public long Long() => long.Parse(String()); public ulong ULong() => ulong.Parse(String()); public double Double() => double.Parse(String()); public string[] Split() => String().Split().ToArray(); public int[] SplitInt() => String().Split().Select(int.Parse).ToArray(); public long[] SplitLong() => String().Split().Select(long.Parse).ToArray(); public ulong[] SplitULong() => String().Split().Select(ulong.Parse).ToArray(); public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray(); public IEnumerable<string> Repeat(int count) { for (int i = 0; i < count; i++) yield return String(); } public IEnumerable<int> RepeatInt(int count) { for (int i = 0; i < count; i++) yield return Int(); } public IEnumerable<long> RepeatLong(int count) { for (int i = 0; i < count; i++) yield return Long(); } public IEnumerable<string[]> RepeatSplit(int count) { for (int i = 0; i < count; i++) yield return Split(); } public IEnumerable<int[]> RepeatSplitInt(int count) { for (int i = 0; i < count; i++) yield return SplitInt(); } }
    #endregion
}

Measured memory_bytes: 13524
#include<bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
 
ll fast_pow( ll a , ll b , ll m )
{
 
    ll res=1;
    while(b>0)
    {
        if(b&1) res =  (res*a)%m;
        a=(a*a)%m;
        b=b/2;
    }
    return res;
}
 
template <typename T,typename U>                                                   
std::pair<T,U> operator-(const std::pair<T,U> & l,const std::pair<T,U> & r) {   
    return {l.first-r.first,l.second-r.second};                                    
} 
 
template <typename T,typename U>                                                   
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {   
    return {l.first+r.first,l.second+r.second};                                    
} 
 
const ll maxn = 1000000;
const int inf = 0x3f3f3f;
const ll MOD = 1e9+7LL;
int ns;

ll lcm(ll a , ll b)
{
    return (a*b)/__gcd(a ,b);
}

/*
    java implementation of highestOneBit and NumberOfTrailingZeroes
*/

ll highestOnebit(ll x)
{
    x |= (x>>1);
    x |= (x>>2);
    x |= (x>>4);
    x |= (x>>8);
    x |= (x>>16);
    x |= (x>>32);
    
    return x-((unsigned ll)x>>1);
}   

int numberOfTrailingZeros(ll i)
{
    if (i == 0) return 64;
    ll x = i;
    ll y;
    int n = 63;
    y = x << 32; if (y != 0) { n -= 32; x = y; }
    y = x << 16; if (y != 0) { n -= 16; x = y; }
    y = x <<  8; if (y != 0) { n -=  8; x = y; }
    y = x <<  4; if (y != 0) { n -=  4; x = y; }
    y = x <<  2; if (y != 0) { n -=  2; x = y; }
    return (int) (n - ((unsigned ll)(x << 1) >> 63));
}


vector<int> parent;
vector<int> depth;
vector<vector<int>> adj;
vector<bool> vis;
vector<int> tin;
vector<int> tout;
int T = 0;

void dfs(int u , int d)
{
    tin[u] = T++;
    depth[u]=d;
    vis[u]=true;
    for(auto v : adj[u])
    {
        if(!vis[v])
        {
            dfs(v , d+1);
            parent[v]=u;
        }
    }    
    tout[u]=T++;
}


int main()
{
    // freopen( "input.txt" , "w" , stdout );
    
   
 
    srand(time(0));
    // Using time point and system_clock 
    std::chrono::time_point<std::chrono::system_clock> start, end; 
  
    start = std::chrono::system_clock::now(); 
 
 
    //------- INPUT GENERATION ------
 
    // cout<<200000<<endl;
 
    //------- /INPUT GENERATION ------

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

    ll x;
    cin>>x;
    ll hap=0;
    hap += (x/500)*1000;
    x = x%500;
    hap += (x/5)*5;
    cout<<hap<<endl;


    

   
    // cout<<endl;
    // end = std::chrono::system_clock::now(); 
  
    // std::chrono::duration<double> elapsed_seconds = end - start; 
    // std::time_t end_time = std::chrono::system_clock::to_time_t(end); 
  
    // std::cout << "finished computation at " << std::ctime(&end_time) 
    //           << "elapsed time: " << elapsed_seconds.count() << "s\n"; 
 
 
 
 
}

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

vector<vector<int>> g(100000);
int dp[100000];

int f(int i) {
	if (dp[i] != -1) return dp[i];
	if (g[i].empty()) {dp[i] = 0; return 0;}
	int ret = 0;
	for (int j : g[i]) ret = max(ret, f(j));
	ret++;
	dp[i] = ret;
	return dp[i];
}

int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		g[x].push_back(y);
	}
	for (int i = 0; i < n; i++) dp[i] = -1;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans = max(ans, f(i));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8192
S = list(input())
words = []
remain = []
for i in range(len(S)-2):
    words.append(S[i] + S[i+1] + S[i+2])
for j in range(len(words)):
    if int(words[j]) >= 753:
        remain.append(int(words[j]) - 753)
    else:
        remain.append(753 - int(words[j]))
ans = remain.index(min(remain))
print(remain[ans])
  
  


Measured memory_bytes: 3064
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;


int main(){

	int Q,N,count,tmp,max,S;
	bool FLG;
	scanf("%d",&Q);
	bool* table = new bool[1000001];

	for(int loop = 0; loop < Q; loop++){
		for(int i = 0; i <= 1000000;i++)table[i] = false;

		count = 0;
		scanf("%d",&N);
		table[N] = true;

		FLG = false;
		while(true){
			if(N/10 == 0)break;

			max = 0;

			for(S = 10;N/S != 0; S *= 10){
				tmp = (N/S)*(N%S);
				max = (max >= tmp)?max:tmp;
			}
			N = max;
			if(table[N] == true){
				FLG = true;
				break;
			}else{
				table[N] = true;
				count++;
			}
		}

		if(FLG){
			printf("-1\n");
		}else{
			printf("%d\n",count);
		}

	}

	return 0;
}

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

int n, m, k, a[200];

void rif() {
	int b[2*n];
	rep(i,n) b[i*2] = a[i];
	rep(i,n) b[i*2+1] = a[n+i];
	rep(i,2*n) a[i] = b[i];
}

void cut(int k) {
	int b[2*n];
	int z = 2*n - k;
	rep(i,z) b[i] = a[k+i];
	for (int i = z; i < 2*n; ++i) b[i] = a[i-z];
	rep(i,2*n) a[i] = b[i];
}

int main() {
	scanf("%d %d",&n,&m);
	rep(i,2*n) a[i] = i+1;
	rep(i,m) {
		scanf("%d",&k);
		if (k) cut(k);
		else rif();
	}
	rep(i,2*n) printf("%d\n",a[i]);
}


Measured memory_bytes: 3124