akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <complex>
#include <stdio.h>

using namespace std;

typedef complex<int> P;

double getWidth(vector<P> &g, int x){
	double m = 1e10, M = -1e10;
	for(int i=0;i<g.size();i++){
		P a = g[i], b = g[(i+1)%g.size()];
		if(real(a) > real(b)) swap(a, b);
		if(real(a) != real(b) && real(a) <= x && x <= real(b)){
			double mid = (double)(x-real(a))/(real(b)-real(a));
			double d = imag(a)*(1-mid)+imag(b)*mid;
			m = min(d, m);
			M = max(d, M);
		}
	}
	return max(0.0, M-m);
}

int main(){
	int n, m;
	while(cin >> m >> n, m){
		vector<P> gy(m), gz(n);
		int sy = 100, ey = -100, sz = 100, ez = -100; 
		for(int i=0;i<m;i++){
			cin >> real(gy[i]) >> imag(gy[i]);
			sy = min(sy, real(gy[i]));
			ey = max(ey, real(gy[i]));
		}
		for(int i=0;i<n;i++){
			cin >> real(gz[i]) >> imag(gz[i]);
			sz = min(sz, real(gz[i]));
			ez = max(ez, real(gz[i]));
		}
		double res = 0.0;
		for(int i=max(sy, sz);i+1<=min(ey, ez);i++){
			double py = getWidth(gy, i), cy = getWidth(gy, i+1), pz = getWidth(gz, i), cz = getWidth(gz, i+1);
			res += (cy*cz+(cy+py)*(cz+pz)+py*pz)/6.0;
		}
		printf("%.4lf\n", res);
	}
}

Measured memory_bytes: 0
N = int(input())
S = list(input())

ans = 0
for i in range(10**3):
    mm = 0
    num = str(i).zfill(3)
    for j in range(N):
        if num[mm]==S[j]:
            mm += 1
        if mm==3:
            ans += 1
            break
print(ans)

Measured memory_bytes: 42732
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
int dist[10][10];
int a[201][201];
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif

	int h,w;
	cin>>h>>w;

	for(int i=0;i<=9;i++)
		for(int j=0;j<=9;j++)
			cin>>dist[i][j];

	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)cin>>a[i][j];


	for(int k=0;k<=9;k++)
		for(int j=0;j<=9;j++)
			for(int i=0;i<=9;i++)
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);

	int ans=0;
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			if(a[i][j]!=-1)
			ans+=dist[a[i][j]][1];
	cout<<ans;

	
}

Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const ll mod=1000000007;
int main(void){
    int x;
    for(int i=0;i<5;i++){
        cin>>x;
        if(x==0) cout<<i+1<<endl;
    }
}

Measured memory_bytes: 3636
# 閉路検出を繰り返し, 閉路の長さを減らしていく

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

    n,m = map(int, input().split())
    adj = [[] for _ in range(n)] #頂点数, 場合によって変える
    for _ in range(m):
        a,b = map(int, input().split())
        adj[a-1].append(b-1)



    def bfs(start):
        pre = [-1]*n
        d = deque([start])

        while d:
            v = d.popleft()
            for nv in adj[v]:
                if nv == start:
                    path = []
                    while v != -1:
                        path.append(v+1)
                        v = pre[v]
                    return path

                if pre[nv] != -1:
                    continue
                pre[nv] = v
                d.append(nv)

        return -1
    
    res = [0]*(n+1)
    for i in range(n):
        temp = bfs(i)
        if temp != -1 and len(res) > len(temp):
            res = temp
    if len(res) <= n:
        print(len(res))
        print(*res, sep='\n')
    else:
        print(-1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 43628
#include <iostream>
#include <stdint.h>
using namespace std;

#define REP(var, start, count) for(int var=start; var<count; var++)

int N, A[10010];

int main(void) {

	cin >> N;
	
	int min =  2000000;
	int max = -2000000;
	int64_t sum = 0;
	REP(i, 0, N) {
		int a;
		cin >> a;
		if ( a < min ) { min = a; }
		if ( a > max ) { max = a; }
		sum += a;
	}
	
	cout << min << " " << max << " " << sum << endl;

}

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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  if(A==5 && B==7 && C==5 || A==5 && B==5 && C==7 || A==7 && B==5 && C==5) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def area(x1, y1, x2, y2):
    return abs(x1*y2-x2*y1)

MOD = 10**9
def main():
    s = ri()
    if s % MOD == 0:
        x1 = s // MOD
        y1 = 0
    else:
        x1 = 1+s // MOD
        y1 = MOD - s % MOD
    y2 = MOD
    x2 = 1
    x3 = 0
    y3 = 0
    assert(x1 <= MOD)
    print(x1, y1, x2, y2, x3, y3)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define speed(); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    speed();
    int a, b;
    cin >> a >> b;
    string s = to_string(a) + to_string(b);
    (int)sqrt(stoi(s))*(int)sqrt(stoi(s)) == stoi(s) ? cout << "Yes" << endl : cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
using namespace std;

const int inf = 1 << 30;
char s[55][55];
int dis[55][55];
typedef struct X{
	int x;
	int y;
}node;

queue<node> seq;
int vis[55][55];

void BFS(){
	node p;
	p.x = 1;
	p.y = 1;
	seq.push(p);
	vis[p.x][p.y] = 1;
	dis[p.x][p.y] = 0;
	while(!seq.empty()){
		node k;
		p = seq.front();
		for(int i = -1;i <= 1;i++){
			for(int j = -1;j <= 1;j++){
				k.x = p.x + i,k.y = p.y + j;
				if(i * j == 0 && s[k.x][k.y] == '.'){
					if(dis[p.x][p.y] + 1 < dis[k.x][k.y]){
						dis[k.x][k.y] = dis[p.x][p.y] + 1;
						if(!vis[k.x][k.y]){
							seq.push(k);
							vis[k.x][k.y] = 1;
						}
					}
				}
			}
		}
		if(!seq.empty()) seq.pop(),vis[p.x][p.y] = 0;
	}
}

int main(){
	int n,m,sum1 = 0,sum2 = 0;
	cin >> n >> m;
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			cin >> s[i][j];
			if(s[i][j] == '.') sum1++;
			else sum2++;
			dis[i][j] = inf;
		}
	}
	BFS();
	if(dis[n][m] == inf) cout << "-1" << endl;
	else cout << sum1 - dis[n][m] - 1 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int N, M, par[200100];

int find(int x)
{
    return (par[x]==x)?(x):(par[x] = find(par[x]));
}

int main(void)
{
    int i, j, k, x, y;

    scanf("%d %d", &N, &M);

    for (i = 0; i < N+M; i++)
        par[i] = i;

    for (i = 0; i < N; i++) {
        scanf("%d", &x);
        while (x--) {
            scanf("%d", &y);
            y = y - 1 + N;
            par[find(i)] = find(y);
        }
    }

    for (i = 1; i < N; i++)
        if (find(0) != find(i)) {
            printf("NO");
            return 0;
        }

    printf("YES");
    return 0;
}


Measured memory_bytes: 1280
s = input()
s = s + "1"
k = int(input())
ans = 0
lis = []
tem = 1
for i in range(len(s)-1):
  if s[i] == s[i+1]:
    tem += 1
  else:
    lis.append(tem)
    tem = 1
if s[0] == s[-2]:
  t = lis[0]+lis[-1]
  for i in range(1,len(lis)-1):
    if lis[i] % 2 == 0:
      ans += lis[i]//2
    else:
      ans += (lis[i]-1)//2
  ans*= k
  if t%2 == 0:
    ans += (k-1)*t//2
  else:
    ans += (k-1)*(t-1)//2
  if lis[0]%2 == 0:
    ans += lis[0]//2
  else:
    ans += (lis[0]-1)//2
  if lis[-1]%2 == 0:
    ans += lis[-1]//2
  else:
    ans += (lis[-1]-1)//2
else:
  for item in lis:
    if item % 2 == 0:
      ans += item//2
    else:
      ans += (item-1)//2
  ans *= k
if len(lis) == 1:
  anse = (len(s)-1)*k
  if anse%2 == 0:
    ans = anse//2
  else:
    ans =(anse-1)//2
print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//整数型を宣言して読み込む
		int A = sc.nextInt();
		int B = sc.nextInt();			
		int ans=0;

		if(A>=13){		
		ans = B;	
		}
		if(6<=A &&A<=12){		
		ans = B/2;	
		}	 
		System.out.println(ans);
	}
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i], b[i] = a[i];

    if (a[0] == 0) {
        ll sum = a[0];
        ll ans = 0;
        sum++;
        ans++;

        for (int i=1; i<n; ++i) {
            if ( (sum > 0 and sum+a[i] < 0) or (sum < 0 and sum+a[i] > 0) ) {
                sum += a[i];
            }
            else {
                if (sum > 0) {
                    sum += a[i];
                    for (; sum>=0; --sum) {
                        ++ans;
                    }
                }
                else {
                    sum += a[i];
                    for (; sum<=0; ++sum) {
                        ++ans;
                    }
                }
            }
        }

        sum = a[0];
        ll ans2 = 0;
        sum--;
        ans2++;

        for (int i=1; i<n; ++i) {
            if ( (sum > 0 and sum+a[i] < 0) or (sum < 0 and sum+a[i] > 0) ) {
                sum += a[i];
            }
            else {
                if (sum > 0) {
                    sum += a[i];
                    for (; sum>=0; --sum) {
                        ++ans2;
                    }
                }
                else {
                    sum += a[i];
                    for (; sum<=0; ++sum) {
                        ++ans2;
                    }
                }
            }
        }

        cout << min(ans, ans2) << endl;
    }
    else {
        ll sum = a[0];
        ll ans = 0;

        for (int i=1; i<n; ++i) {
            if ( (sum > 0 and sum+a[i] < 0) or (sum < 0 and sum+a[i] > 0) ) {
                sum += a[i];
            }
            else {
                if (sum > 0) {
                    sum += a[i];
                    for (; sum>=0; --sum) {
                        ++ans;
                    }
                }
                else {
                    sum += a[i];
                    for (; sum<=0; ++sum) {
                        ++ans;
                    }
                }
            }
        }

        ll ans2 = 0;
        sum = a[0];
        if (sum > 0) {
            for (; sum>=0; --sum) {
                ++ans2;
            }
        }
        else {
            for (; sum<=0; ++sum) {
                ++ans2;
            }
        }

        for (int i=1; i<n; ++i) {
            if ( (sum > 0 and sum+a[i] < 0) or (sum < 0 and sum+a[i] > 0) ) {
                sum += a[i];
            }
            else {
                if (sum > 0) {
                    sum += a[i];
                    for (; sum>=0; --sum) {
                        ++ans2;
                    }
                }
                else {
                    sum += a[i];
                    for (; sum<=0; ++sum) {
                        ++ans2;
                    }
                }
            }
        }
        cout << min(ans, ans2) << endl;
    }
}


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

//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("Ofast")

#define F first
#define S second
#define MT make_tuple
#define SZ(a) ((int)(a).size())
#define PB push_back
#define LBS 20
#define MOD ((long long)1e9+7) //1e9+9
#define LEFT(i) (2*(i))
#define RIGHT(i) (2*(i)+1)
#define PAR(i) ((i)/2)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

typedef long long ll;
typedef double rat;
typedef long long bi;
typedef pair<int, int> ii;
typedef std::vector<ii> vii;
typedef std::map<int, int> mii;
typedef bitset<LBS> bis;
typedef std::vector<bis> vbs;

template<class T>
void in(T &a){
  for(auto &x: a)
    cin >> x;
}

template<class T>
void out(T &a, string sep=" "){
  for(auto x: a)
    cout << x<<sep;
  cout << '\n';
}

template<class T>
void err(T &a, string sep=" "){
  for(auto x: a)
    cerr << x <<sep;
  cerr << '\n';
}


int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n; cin >> n;
  string s; cin >> s;
  int cc=1;
  for(int i=1; i<n; i++)
    if(s[i]!=s[i-1])
      cc++;
  cout << cc <<"\n";
}


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

#define NODE_NUM 100


int wght[NODE_NUM];
int visited[NODE_NUM];

typedef struct VERTEX{
    int idx;
    int w;
}VERTEX;

void search(int node_idx, int w, VERTEX ** A, int* num, int n){
    
    int i, weight, next;
    
    if (visited[node_idx] == 1) {
        return;
    }
    
    for (i=0; i < num[node_idx]; i++) {
        
        next = A[node_idx][i].idx;
        
        if ( visited[next]) {
            continue;
        }
        
        weight = A[node_idx][i].w;
        
        if( wght[next] > w + weight )
        {
            wght[next] = w + weight;
            visited[node_idx] = 1;
            search(next, w + weight, A, num, n);
            visited[node_idx] = 0;
        }
    }

    return;

}


int main( ){
    
    int i, j, k, v, c, u, n , *num;
    VERTEX ** A;
    
    scanf("%d", &n);
    A = malloc(sizeof(VERTEX) * n);
    num = malloc(sizeof(int) * n);
    
    for (i=0; i <n; i++) {
        wght[i] = 300000000;
    }
    wght[0] = 0;
    
    
    
    for (i=0; i<n; i++){
        
        scanf("%d", &u);
        scanf("%d", &k);
        A[u] = malloc(sizeof(VERTEX) * k);
        num[u] = k;
        
        for (j = 0; j < k; j++) {
            scanf("%d %d", &v, &c);
            A[u][j].idx = v;
            A[u][j].w = c;
        }
    }
    
    search(0, 0, A, num, n);
    
    for (i=0; i<n; i++) {
        printf("%d %d\n", i, wght[i]);
    }
    
    
    return 0;
}

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

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
  int i,j,x,y,size,mx,my,res=0,depth=0;
  int map[10][10];
  int dx[] = {0,1,0,-1}, dy[] = {1,0,-1,0};

  memset(map,0,sizeof(map));

  while(scanf("%d,%d,%d\n",&x,&y,&size) != EOF){
    if(size == 1){
      map[x][y]++;
      rep(i,4){
        mx = x + dx[i]; my = y + dy[i];
        if(mx < 10 && my < 10 && 0 <= mx && 0 <= my) map[mx][my]++;
      }
    }

    if(size == 2){
      REP(i,-1,2) REP(j,-1,2){
        mx = x + i; my = y + j;
        if(mx < 10 && my < 10 && 0 <= mx && 0 <= my) map[mx][my]++;
      }
    }

    if(size == 3){
      REP(i,-1,2) REP(j,-1,2){
        mx = x + i; my = y + j;
        if(mx < 10 && my < 10 && 0 <= mx && 0 <= my) map[mx][my]++;
      }
      rep(i,4){
        mx = x + 2*dx[i]; my = y + 2*dy[i];
        if(mx < 10 && my < 10 && 0 <= mx && 0 <= my) map[mx][my]++;
      }
    }
  }

  rep(i,10) rep(j,10){
      if(map[i][j] != 0 && depth < map[i][j]) depth = map[i][j];
      if(map[i][j] == 0) res++;
  }

  printf("%d\n%d\n",res,depth);

  return 0;
}

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

#define ll unsigned long long
#define INF 1234567890
#define N (int)(2e5 + 5)
#define pi acos(-1)

void solve()
{
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes";else
        cout << "No";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)

int main() {
	struct Task {
		ll L;
		ll R;
		static Task intersect(Task lhs, Task rhs) {
			return Task{max(lhs.L, rhs.L), min(lhs.R, rhs.R)};
		}
		static Task whole() {
			return Task{0, numeric_limits<ll>::max()};
		}
		ll len() {
			return max((ll)0, R-L);
		}
	};
	ll N;
	cin >> N;
	vector<Task> tasks(N);
	rep(i,0,N) {
		cin >> tasks[i].L;
		cin >> tasks[i].R;
		tasks[i].R++;
	}
	ll ans = 0;
	sort(tasks.begin(), tasks.end(), [](Task lhs, Task rhs){
		return lhs.L < rhs.L;
	});
	vector<Task> int_l(N+1, Task::whole());
	vector<Task> int_r(N+1, Task::whole());
	rep(i,0,N) {
		int_l[i+1] = Task::intersect(int_l[i], tasks[i]);
		int_r[i+1] = Task::intersect(int_r[i], tasks[N-1-i]);
	}
	rep(i,0,N) {
		ans = max(ans, tasks[i].len()
				+ Task::intersect(int_l[i], int_r[N-(i+1)]).len());
	}
	vector<Task> reduced;
	rep(i,0,N) {
		if (reduced.empty() || reduced.back().R < tasks[i].R) {
			reduced.push_back(tasks[i]);
		} else {
			reduced.pop_back();
		}
	}
	ll M = reduced.size();
	vector<Task> int_l_red(M+1, Task::whole());
	vector<Task> int_r_red(M+1, Task::whole());
	rep(i,0,M) {
		int_l_red[i+1] = Task::intersect(int_l_red[i], reduced[i]);
		int_r_red[i+1] = Task::intersect(int_r_red[i], reduced[M-1-i]);
	}
	rep(i,1,M) {
		ans = max(ans, int_l_red[i].len() + int_r_red[M-i].len());
	}
	cout << ans << endl;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<ld,ld> id;
typedef tuple<ll,ll,ll> tl;
typedef tuple<ll,ll,ll,ll> ql;

#define FOR(i, a, b) for(ll i=(a); i<=(b); i++)
#define ROF(i, a, b) for(ll i=(a); i>=(b); i--)
#define MEM(x, v) memset(x, v, sizeof(x))
#define FILL(x, n, v) fill(x, x+n, v);
#define ALL(x) x.begin(), x.end()
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define f first
#define s second
#define ins insert
#define e emplace
#define eb emplace_back
#define ef emplace_front
#define p push
#define pf push_front
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ft front
#define bk back
#define pp pop
#define ppb pop_back
#define ppf pop_front

#define db cout<<"YEET\n";
#define ct(x) cout<<x<<'\n';

const ll MOD = 1e9+7; //998244353
const ll MAXN = 10+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);

int main(){
    FAST
    ll k, a, b;
    cin >> k >> a >> b;
    bool yes=0;
    FOR(i,a,b){
        if (i%k==0) yes=1;
    }
    if (yes) cout << "OK";
    else cout << "NG";
}

Measured memory_bytes: 3636
// https://atcoder.jp/contests/abc139/tasks/abc139_b

#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    cout << (b - 1 + a - 2) / (a - 1) << '\n';
    return 0;
}


Measured memory_bytes: 3620
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin.bytes().map(|c| c.expect("failed to read char") as char).skip_while(|c| c.is_whitespace()).take_while(|c| !c.is_whitespace()).collect();
    token.parse().ok().expect("failed to parse token")
}

fn s(n: u32) -> u32 {
    let mut sum: u32 = 0;
    for b in format!("{}", n).chars() { sum += b as u32 - 48; }
    sum
}

fn main() {
    let n: u32 = read();
    println!("{}", if n % s(n) == 0 { "Yes" } else { "No" });
}

Measured memory_bytes: 4352
//BadWaper gg
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define fr first
#define sd second
#define N 200010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
int n;
struct edge
{
	int next,to;
}e[N<<1];
int head[N],cnt;
ll ans;
inline void add_edge(int from,int to){e[++cnt]=(edge){head[from],to};head[from]=cnt;}
inline ll solve(int x,int y)
{
	if(!y)return n;
	if(x<y)
	{
		return 1LL*x*(y-x);
	}
	else return 1LL*(n-x+1)*(x-y);
}
void dfs(int now,int father)
{
	ans+=solve(now,father);
	for(register int i=head[now];i;i=e[i].next)
	{
		if(e[i].to==father)continue;
		dfs(e[i].to,now);
	}
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();
	for(register int i=1;i<n;i++)
	{
		int x=read(),y=read();
		add_edge(x,y);add_edge(y,x);
	}
	dfs(1,0);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 16832
#include<bits/stdc++.h>
using namespace std;
long gcd(long m,long n){
  if(n)return gcd(n,m%n);
  return (m>0?m:-m);
}
int main(){
  long n,m,l;
  string s,t;
  cin>>n>>m>>s>>t;
  l=n*m/gcd(n,m);
  for(long i=0;i<l;i+=l/n){
    cerr<<i*n/l<<"("<<s[i*n/l]<<") "<<i*m/l<<"("<<t[i*m/l]<<") ["<<(i*m)%l<<endl;
    if((i*m)%l==0&&s[i*n/l]!=t[i*m/l]){
      cout<<-1;
      return 0;
    }
  }
  cout<<l;
  return 0;
}


Measured memory_bytes: 512
H,W=map(int,input().split())
S=[input() for i in range(H)]
from collections import deque
q=deque([(0,0,0)])
v=[[-1]*W for i in range(H)]
v[0][0]=0
x=[(0,1),(1,0)]
while q:
    i,j,d=q.popleft()
    for a,b in x:
        if 0<=i+a<H and 0<=j+b<W and v[i+a][j+b]<0:
            if S[i+a][j+b]==S[i][j]:
                q.appendleft((i+a,j+b,d))
                v[i+a][j+b]=d
            else:
                q.append((i+a,j+b,d+1))
                v[i+a][j+b]=d+1
print(v[-1][-1]//2+(S[0][0]=='#' or S[-1][-1]=='#'))

Measured memory_bytes: 3380
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> P(N + 1);
    vector<pair<ll, ll>> V;
    REP(i, N) {
        cin >> P.at(i + 1);
        V.push_back(make_pair(P[i + 1], i + 1));
    }
    sort(ALL(V), greater<pair<ll, ll>>());

    multiset<ll> s;
    s.insert(0);
    s.insert(0);
    s.insert(N + 1);
    s.insert(N + 1);
    ll ans = 0;
    for (auto v : V) {  // x < y < v.second < z < w
        auto it = s.lower_bound(v.second);
        ll z = *it;
        it++;
        ll w = *it;
        it--;
        it--;
        ll y = *it;
        it--;
        ll x = *it;
        ans += ((w - z) * (v.second - y) + (z - v.second) * (y - x)) * v.first;
        // prllf("x:%d, y:%d, id:%d, z:%d, w:%d ,plus:%d\n", x, y, v.second, z, w,(w - z) * (v.second - y) + (z -
        // v.second) * (y - x));
        s.insert(v.second);
    }

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


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  
  bool ans=true;
  
  for(int i=0;i<N;i++){
    if(A[i]%2==0&&A[i]%3!=0&&A[i]%5!=0){
      ans=false;
    }
  }
  
  if(ans==true){
    cout << "APPROVED" << endl;
  }
  else{
    cout << "DENIED" << endl;
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    int dp[2][3]; memset(dp,0,sizeof(dp));
    for (int i = 0; i < n; i++){
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        dp[i%2][0] = a+max(dp[1-i%2][1],dp[1-i%2][2]);
        dp[i%2][1] = b+max(dp[1-i%2][0],dp[1-i%2][2]);
        dp[i%2][2] = c+max(dp[1-i%2][0],dp[1-i%2][1]);
    }
    printf("%d",max(dp[1-n%2][0],max(dp[1-n%2][1],dp[1-n%2][2])));
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, k = map(int, readline().split())
    a = list(map(int, readline().split()))

    ok = max(a)
    ng = 0

    while abs(ng - ok) > 1:
        mid = (ok + ng) // 2
        cnt = 0
        for x in a:
            cnt += (x + mid - 1) // mid - 1
        if cnt <= k:
            ok = mid
        else:
            ng = mid

    print(ok)


if __name__ == '__main__':
    main()


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

int n, s;

int dfs(int i, int sum, int rest) {
	if (rest < 0) return 0;
	if (i == 10) return (sum == s && rest == 0) ? 1 : 0;
	return dfs(i + 1, sum, rest) + dfs(i + 1, sum + i, rest - 1);
}

int main() {
	while (true) {
		cin >> n >> s;
		if (n == 0 && s == 0)
			break;
		cout << dfs(0, 0, n) << '\n';
	}
}


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

public class Main {
	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		int INF = 1 << 28;
		int n = sc.nextInt();
		int[][] root = new int[n + 1][n + 1];
		for (int i = 0; i <= n; i++) {
			Arrays.fill(root[i], INF);
			root[i][i] = 0;
		}
		for (int i = 0; i < n; i++) {
			int r = sc.nextInt();
			int k = sc.nextInt();
			for (int j = 0; j < k; j++) {
				root[r][sc.nextInt()] = 1;
			}
		}
		for (int k = 1; k <= n; k++) {
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					root[i][j] = Math.min(root[i][j], root[i][k] + root[k][j]);
				}
			}
		}
		int p = sc.nextInt();
		for (int i = 0; i < p; i++) {
			int s = sc.nextInt();
			int d = sc.nextInt();
			int v = sc.nextInt();
			int dis = root[s][d];
			if (dis == INF) {
				System.out.println("NA");
			} else if (dis < v) {
				System.out.println(dis+1);
			} else {
				System.out.println("NA");
			}
		}
	}

}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    int N;
    cin >> N;
    vector<int>A(N);
    vector<int>B(N+1);
    B[0] = 0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        B[i+1] = B[i]+A[i];
    }
    int ans = 0;
    int cnt = 1;
    sort(B.begin(),B.end());
    for(int i = 1; i <= N; i++) {
        if(B[i] == B[i-1]) {
            cnt++;
        }
        else {
            ans+=(cnt*(cnt-1))/2;
            cnt = 1;
        }
    }
    ans+=(cnt*(cnt-1))/2;
    cout << ans << endl;
}

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

int dp[101][100001];
int val[100];
int weight[100];

long long maxValue(int val[], int weight[], int capacity, int n)
{
	if(n<0)
		return 0;

	if(dp[n][capacity]!=-1)
	{
		return dp[n][capacity];
	}

	if(capacity-weight[n]<0)
		return dp[n][capacity] = maxValue(val, weight, capacity,n-1);

	return dp[n][capacity] = max( maxValue(val, weight, capacity,n-1), val[n] + maxValue(val, weight, capacity-weight[n], n-1));
}



int32_t main()
{
	int N,W;
	cin >> N >> W;
	vector<int> w,v;

	for(int i=0; i<101; i++)
	{
		for(int j=0; j< 100001; j++)
		{
			dp[i][j]=-1;	
		}
	}

	for(int i=0;i<N;i++)
	{
		cin >> weight[i] >> val[i];
	}
	cout << maxValue(val,weight,W,N-1);
	
	return 0;
}

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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll MOD = 1e9 + 7;
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))

int main() {
    ll n;
    cin >> n;
    map<ll , ll>m;
    for ( ll i = 0; i< n; i++) {
        ll x;
        cin >> x;
        m[x]++;
    }
    ll d = 0;
    for (auto i = m.begin(); i != m.end(); i++) {
        ll h = i->second;
        if(h % 2 != 0) {
           d++;
        }
    }
    cout << d << endl;
    return 0;
}


Measured memory_bytes: 6528
n,*s=open(0).read().split()
w=''
b=[]
a=[]
e=""
for i in s:
    if i[-1]=='A' and i[0]=="B":
        w+=i
    elif i[-1]=='A':
        a.append(i)
    elif i[0]=='B':
        b.append(i)
    else:
        e+=i
#print(w)
a=iter(a)
b=iter(b)
if len(w)!=0:
    w=next(a,'')+w+next(b,'')
i,j=next(a,''),next(b,'')
while i!='' or j!='':
    w+=i+j
    i,j=next(a,''),next(b,'')
w+=e
print(w.count('AB'))

Measured memory_bytes: 9664
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	lint N;
	cin >> N;
	vector<lint>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	set<lint>S;
	rep(i, N) {
		S.insert(A[i]);
	}
	lint M = N-S.size();
	if (M % 2) {
		M++;
	}
	cout << N - M << endl;
}

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

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

int main() {
	int a,b;
	cin>>a>>b;
	if(a*b%2==0) cout<<"Even"<<endl;
	else cout<<"Odd"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int maxn=0x7fffff;

int main(){
	ll n,c,ans=0;
	cin>>n>>c;
	if(c>=n*2){
		ans+=n;
		c-=n*2;
		ans+=c/4;
		cout<<ans;
		return 0;
	}
	else {
		c/=2;
		ans+=c;
		cout<<ans;
		return 0;
	}
	return 0;
}


Measured memory_bytes: 256
N = int(input())
w = list(map(int, input().split()))
val0, val1 = 0, sum(w)
diff = val1

for i in range(N):
    val0 += w[i]
    val1 -= w[i]
    if diff <= abs(val1 - val0):
        print(diff)
        break
    else:
        diff = abs(val1 - val0)


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

int main() 
{
    int h, n;
    cin >> h >> n;
    int sum = 0;
    while (n--)
    {
        int a; cin >> a; 
        sum += a;
    }
    cout << (sum>=h?"Yes":"No");    
    return 0;
}

Measured memory_bytes: 256
import math
import time
def py():
    print("Yes")
def pn():
    print("No")
def iin():
    x = int(input())
    return x

neko = 1000
nya = 0
nuko = 0

s = input()
for i in range(len(s)-2):
    if abs(int(s[i]+s[i+1]+s[i+2])-753) < neko:
        neko = abs(int(s[i]+s[i+1]+s[i+2])-753)

print(neko)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
using namespace std;
vector<int> A[4],B[4];
signed main(){
  int N,W,n;
  cin>>N>>W;
  for(int i=0;i<N;i++){
    int a,b;
    cin>>a>>b;
    if(i==0)n=a;
    A[a-n].push_back(b);
  }
  for(int i=0;i<4;i++){
    sort(A[i].rbegin(),A[i].rend());
    B[i].push_back(0);
    for(int j:A[i])B[i].push_back(B[i].back()+j);
  }
  int ans=0;
  for(int i=0;i<B[0].size();i++)
    for(int j=0;j<B[1].size();j++)
      for(int k=0;k<B[2].size();k++)
        for(int l=0;l<B[3].size();l++)
          if(i*n+j*(n+1)+k*(n+2)+l*(n+3)<=W)ans=max(ans,B[0][i]+B[1][j]+B[2][k]+B[3][l]);
  cout<<ans<<endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <complex>
#include <bitset>
#include <numeric>
using namespace std;

typedef long long LL; typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define OUT(a) cout<<(a)<<endl;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >>s;
    int l=s.size();

    REP(i,l-1){
        if(s[i]==s[i+1]){
            cout << i+1 << ' ' << i+2 << endl;
            return 0;
        }
    }
    REP(i,l-2){
        if(s[i]==s[i+2]){
            cout << i+1 <<  ' ' << i+3 <<endl;
            return 0;
        }
    }
    cout << -1  <<' ' <<-1 <<endl;

    return 0;
}


Measured memory_bytes: 512
#include<iostream>

int main(){
	int n;
	while(std::cin>>n,n){
		int count=0,money=1000-n;
		while(money>=500)money-=500,count++;
		while(money>=100)money-=100,count++;
		while(money>=50)money-=50,count++;
		while(money>=10)money-=10,count++;
		while(money>=5)money-=5,count++;
		while(money>=1)money-=1,count++;
		std::cout<<count<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int64_t x, k, d; cin >> x >> k >> d;
	x = abs(x);
	if(x / d > k) {
		cout << x - d * k << '\n';
		return 0;
	}
	k -= x / d;
	x = x % d;
	if(k % 2 == 0) {
		cout << x << '\n';
	} else {
		cout << abs(x - d) << '\n';
	}
	return 0;
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    ll n,m;
    cin >> n >> m;
    vector<ll> a(n);
    vector<pair<ll, ll> > bc(m);
    ll ans = 0;
    rep(i,n)
    {
        cin >> a[i];
        ans += a[i];
    }
    rep(i,m) cin >> bc[i].second >> bc[i].first;
    sort(all(bc),greater<pair<ll, ll> >());
    sort(all(a));
    ll tmp= 0;
    ll tmp_n = 0;
    rep(i,n)
    {
        if(a[i] < bc[tmp].first)
        {
            ans += (bc[tmp].first - a[i]);
            bc[tmp].second--;
            if(bc[tmp].second == 0) tmp++;
            if(tmp == m) break;
        }
        else break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <queue>
#include <string>
#include <set>

using namespace std;

int main() {

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

	int n,k; cin >> n >> k;

	int arr[26] = {0};
	set<string> buff;
		
	string inp;

	for(int i = 0; i < n; i++) {
		cin >> inp;
		buff.insert(inp);
	}

	for(auto &it : buff) {
		arr[it[0]-'A']++;
	}

	priority_queue<int> pq;

	for(int i = 0; i < 26; i++){
		if(arr[i])pq.push(arr[i]);
	}

	int ans = 0;
	
	while(!pq.empty()) {
		vector<int> member;

		for(int i = 0; i < k; i++) {
			if(pq.empty())break;
			else {
				member.push_back(pq.top()-1);
				pq.pop();
			}
		}

		if(member.size() < k)break;
		else {
			ans++;
			for(int i = 0; i < k; i++) {
				if(member[i])pq.push(member[i]);
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1016
import java.util.*;
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        long[] A = new long[N];
        long[] B = new long[N];
        for (int i = 0; i < N; i++) {
        	A[i] = sc.nextLong();
        	B[i] = sc.nextLong();
        }
        
        long[] map = new long[N];
    	map[N-1] =  A[N-1] % B[N-1] == 0 ? 0 : B[N-1] - (A[N-1]  % B[N-1]);
        for (int i = N-2; 0 <= i; i--) {
        	long a = A[i];
        	long b = B[i];
        	map[i] = (A[i] + map[i+1]) % B[i] == 0 ? map[i+1] : (B[i] - (A[i] + map[i+1]) % B[i]) + map[i+1];
        }
        
        System.out.println(map[0]);
    }
}

Measured memory_bytes: 91604
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N,x;
ll a[2010];
int main(){
    cin>>N>>x;
    for(ll i=0;i<N;i++){
        cin>>a[i];
    }
    multiset<ll> st;
    ll ans=INF;
    for(ll m=0;m<N;m++){
        for(ll i=N-m;i<N;i++){
            st.insert(a[i]);
        }
        ll cnt=0;
        ll deleteIndex=N-m;
        if(m==0)deleteIndex=0;
        for(ll i=0;i<N;i++){
            st.insert(a[i]);
            auto minIt=st.begin();
            cnt+=*minIt;
            st.erase(a[deleteIndex]);
            deleteIndex++;
            if(deleteIndex>=N)deleteIndex=0;
        }
        ans=min(ans,cnt+x*m);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#define N 100

int n, M[N+1][N+1];
int d[N+1];
int Q[N+1];
int head = 1, tail;

void enqueue(int x) {
  Q[tail] = x;
  if((tail +1) == N + 1) tail = 0;
  else tail++;
}

int dequeue() {
  int x;
  x = Q[head];
  if((head + 1) == N + 1) head = 0;
  else head++;
 return x;
}

int Q_empty() {
  int i;
  for(i = 0;i<N+1;i++)
  if(Q[i] != -111) return 111;
  return 0;
}

void BFS(int x) {
  int i,u,v,flag = 1,count=0;

  enqueue(x);
  for(i = 0;i<n;i++) d[i] = (1<<21);
  d[x] = 0;

  while(1) {
    if(Q_empty() == 0)break;

    for(i=count;i<N+1;i++) {
      u = dequeue();
      if(u!= -777) break;
    }
    if(u== -777)break;
    count = i;
    for(v = 0;v<n;v++) {
      if(M[u][v] == 0) continue;
      if(d[v] != (1<<21))continue;
      d[v] = d[u]+1;
      enqueue(v);
    }
  }

  for(i=0;i<n;i++){
    printf("%d",i+1);
    if(d[i]== (1<<21)) printf(" %d\n", -1 );
    else printf(" %d\n", d[i]);
  }
}

int main() {
  int i,j,u,k,v;

  for(i=0;i<N+1;i++) {
    Q[i]= -777;
  }

  scanf("%d\n", &n );
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]= 0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d\n",&v );
      v--;
      M[u][v]= 1;
    }
  }
  BFS(0);
  return 0;
}

Measured memory_bytes: 640
n=int(input())
a_n=list(map(int,input().split()))
count=0
ans=0
for i in a_n:
  if i <0:
    count +=1

if count%2==0:
  for i in a_n:
    if i<0:
      ans += -1*i
    else:
      ans += i
else:
  tmp=abs(a_n[0])
  for i in a_n:
    if tmp > abs(i):
      tmp = abs(i)
  for i in a_n:
    if i <0:
      ans +=-1*i
    else:
      ans +=i
  ans -=2*tmp
print(ans)

Measured memory_bytes: 14332
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

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

#include <iostream>

int main()
{
	int N,K;
	string S;
	cin >> N >> K;
	cin >> S;

	if (S[K - 1] == 'A') {
		string L = S.replace(K - 1, 1, "a");
		cout << L << endl;
	}
	else if (S[K - 1] == 'B') {
		string L = S.replace(K - 1, 1, "b");
		cout << L << endl;
	}
	else if (S[K - 1] == 'C') {
		string L = S.replace(K - 1, 1, "c");
		cout << L << endl;
	}

}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<map>
#include<unordered_map>
#include<stack>
using namespace std;
int gcd(int a,int b);
long long int bign=1000000007;
int main(){
    int x;
    cin >> x;
    int y=x;
    while(y%360!=0){
        y+=x;
    }
    cout << y/x << endl;
    // int gcdx=gcd(x,360);
    
    // int gdd=360*x/gcdx;
    // cout << gdd/x<< endl;
return 0;

}

int gcd(int a,int b){
    int c=b%a;
    if(c==0){
        return a;
    }else{
        return gcd(b,c);
    }
}

Measured memory_bytes: 3156
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);
	string x;
	cin >> x;
	if (x[0] == '7' || x[1] == '7' || x[2] == '7') {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

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

		if (A % 2 == 0 || B % 2 == 0) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 23252
//🔴
//Longest Increasing Subsequence
//最長部分増加列
//任意の　i < j　で　a[i] < a[j]を満たす部分列
// 1 <= n <= 1000
// 0 <= a[i] <= 1000000

//O(nlogn 解法)


#include<bits/stdc++.h>
using namespace std;
const int INF = 1000*1000*1000;
int main(){

    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<int> dp(n + 1, INF);
    for(int i = 0; i < n; i++){
        *lower_bound(dp.begin(), dp.end(), a[i]) = a[i];
    }

    cout << lower_bound(dp.begin(), dp.end(), INF) - dp.begin() << endl;

    return 0;

}



Measured memory_bytes: 3588
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n;
    string s; cin >> s;
    int init = 0;
    for(int i = 0; i < n; i++) if(s[i] == '#') init++;
    int best = init;
    for(int i = n - 1; i > -1; i--)
    {
        if(s[i] == '#') init--;
        else init++;
        best = min(best, init);
    }
    cout << best;

    return 0;
}


Measured memory_bytes: 720
#include <stdio.h>
int main(){
    int a;
    scanf("%d", &a);
    // printf("%d\n", (1000 - (a - a/1000*1000)) % 1000);
    while(a > 0){
        a -= 1000;
    }
    printf("%d\n", a * -1);
    return 0;
}

Measured memory_bytes: 1696
import collections

N = int(input())
A = map(int, input().split())
CA = collections.Counter(A)

ans = CA[0]+CA[1]+CA[2]
tmp = 0
for i in range(2, 10**5):
    tmp = CA[i-1]+CA[i]+CA[i+1]
    ans = max(tmp, ans)
print(ans)


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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
int n, m, r; const int W(1), B(0);
vector<vector<pair<int, int>>>adj; // dist, cost
void dijkstra() {
	vector<int>d(n, INF), color(n, W);
	d[r] = 0;
	priority_queue<pair<int, int>>pq; // d[v], v
	pq.push(make_pair(0, r));
	while (!pq.empty()) {
		pair<int, int>f(pq.top()); pq.pop();
		color[f.second] = B;
		if (d[f.second] < (-1)*f.first)continue;
		rep(i, 0, adj[f.second].size()) {
			pair<int, int>u(adj[f.second][i]);
			if (color[u.first] != B&&d[f.second] + u.second < d[u.first]) {
				d[u.first] = d[f.second] + u.second;
				pq.push(make_pair((-1)*d[u.first], u.first));
			}
		}
	}
	rep(i, 0, n) {
		if (d[i] == INF)cout << "INF" << endl;
		else cout << d[i] << endl;
	}
}
signed main() {
	cin >> n >> m >> r; adj = vector<vector<pair<int, int>>>(n, vector<pair<int,int>>());
	rep(i, 0, m) {
		int s, t, d; cin >> s >> t >> d;
		adj[s].push_back(make_pair(t, d));
	}
	dijkstra();
	return 0;
}

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

#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define SIZE(array) (sizeof(array) / sizeof(array[0]))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MAX_V 100000

#define MOD 1000000007L
#define INF 100000000000

signed main() {
	int n, k;
	cin >> n >> k;
	int sum = 0;
	for (size_t i = 0; i < n; i++) {
		int x;
		cin >> x;
		sum += min(x, k - x);
	}
	cout << (sum * 2) << endl;
}


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

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/

int main(){
    double pai=3.141592653589;
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a<b && b<c){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

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

using i64 = long long;

int main() {
#ifdef HOME
	freopen("agc15a.in", "r", stdin);
	freopen("agc15a.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	i64 n, a, b;

	cin >> n >> a >> b;

	n-= 1 + int(a != b);
	if (a > b || n < 0) {
		cout << 0 << endl;
		return 0; }

	cout << 1 + (a + b + n * b) - (a + b + n * a) << endl;

	return 0; }


Measured memory_bytes: 256