akhauriyash/Code-Regression huggingface dataset:
// ????????¨using
using System;
using System.Linq;
using System.Collections.Generic;

public class DFS
{
	public static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var u = Enumerable.Range(0, n)
			.Select(_ => Console.ReadLine());
		
		var builtupNodes = Build(u);
		var explorer = new Explorer();
		while (builtupNodes.Any(x => x.FoundTime == 0))
		{
			explorer.Explore(builtupNodes.First(x => x.FoundTime == 0));
		}
		
		// ????????¨ ForEach??¨???ToList()
		builtupNodes.ToList()
			.ForEach(x => Console.WriteLine(x.Id + " " + x.FoundTime + " " + x.FinishedTime));
	}
	
	static IEnumerable<Node> Build(IEnumerable<string> u)
	{
		var nodeAndInputs = u.Select(x => x.Split(' '))
			.Select(x => x.Select(int.Parse))
			.Select(x => new 
			{ 
				node = new Node
				{
					Id = x.First(),
					Children = new Node[0]
				},
				input = x
			})
			.ToList();
		// Node?????????????????£????????????????????\????????????????????????2????????????????????????????????????????????§??????
		return nodeAndInputs.Select(nodeinput => 
		{
			nodeinput.node.Children = nodeAndInputs
				.Select(x => x.node)
				.Where(x => nodeinput.input.Skip(2).Contains(x.Id));
			return nodeinput.node;
		})
		.OrderBy(x => x.Id);
	}
	
	class Explorer
	{
		private int time = 0;
		public void Explore(Node node)
		{
			node.FoundTime = ++time;
			foreach (var n in node.Children.Where(x => x.FoundTime == 0))
			{
				Explore(n);
			}
			node.FinishedTime = ++time;
		}
	}
	
	class Node
	{
		public int Id { get; set; }
		public IEnumerable<Node> Children { get; set; }
		public int FoundTime { get; set; }
		public int FinishedTime { get; set; }
	}
}

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

n, m = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(m)]
A.sort(key=lambda x: x[1])

count = 0
start = -1
for a in A:
    if a[0] >= start:
        count += 1
        start = a[1]
print(count)


Measured memory_bytes: 29084
S = input()

ans=0
for i in range(1<<(len(S)-1)):
    num = int(S[0])
    cur=0
    for j in range(len(S)-1):
        if i & (1<<j):
            cur+=num
            num=0
        num=num*10+int(S[j+1])
    cur += num
    ans+=cur
print(ans)

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int mod = 1e9+7;

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    while (cin >> n >> k) {
        VI A(n);
        FOR(i,0,n)
            cin >> A[i];
        LL cnt1 = 0;
        FOR(i,0,n) FOR(j,i+1,n) if (A[i] > A[j])
            cnt1++;
        LL cnt2 = 0;
        FOR(i,0,n) FOR(j,0,n) if (A[i] > A[j])
            cnt2++;
        const LL a = cnt1 * k % mod;
        const LL b = cnt2 * (k-1) % mod;
        LL ans = (a + b) % mod;
        if (k > 2) {
            const LL x = k-2;
            ans += x*(x+1)/2 % mod * cnt2 % mod;
            ans %= mod;
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	string s(4,' ');
	cin >> s;
	for (int i = 0; i < 3; i++) {
		if (s[i] == s[i + 1]) {
			cout << "Bad" << endl;
			break;
		}
		if (i == 2)cout << "Good" << endl;
	}
}

Measured memory_bytes: 256
w, h, n = map(int, input().split())
l = 0
r = w
u = h
d = 0
for i in range(n):
  x, y, a = map(int, input().split())
  if a == 1:
    l = max(l,x)
  elif a == 2:
    r = min(r,x)
  elif a == 3:
    d = max(d,y)
  elif a == 4:
    u = min(u,y)
print(max(r-l,0)*max(u-d,0))

Measured memory_bytes: 9208
#B
s = input()

def palindrome(start,end):
    isT = True
    for i in range(start, int((start+end+1)/2)):
        if s[i] != s[end-i]:
            isT = False
    return (isT)


final = palindrome(0,len(s)-1) and palindrome(0,((len(s)-1)//2)-1) and palindrome(((len(s)+3)//2)-1, len(s)-1)

if final:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

#define MAX_V 10000
#define INF 1e9

struct edge{ int to,cost; };
typedef pair<int,int> P;

int V;
vector<edge> G[MAX_V];
int dist[MAX_V];

void dijkstra(){
  priority_queue<P, vector<P>, greater<P> > Q;
  fill(dist,dist+V,INF);
  dist[0] = 0;
  Q.push(P(0,0));

  while(!Q.empty()){
    P p = Q.top(); Q.pop();
    int v = p.second;

    if(dist[v] < p.first){
      continue;
    }

    for(int i = 0 ; i < (int)G[v].size() ; i++){
      edge e = G[v][i];
      
      if(dist[e.to] > dist[v] + e.cost){
	dist[e.to] = dist[v] + e.cost;
	Q.push(P(dist[e.to],e.to));
      }
    }

  }
}

int main(){
  cin >> V;
 
  for(int i = 0 ; i < V ; i++){
    int u,k;

    cin >> u >> k;
    for(int j = 0 ; j < k ; j++){
      int v,c;

      cin >> v >> c;

      edge e = {v,c};
      G[u].push_back(e);
    }
  }

  dijkstra();
  for(int i = 0 ; i < V ; i++){
    cout << i << " " << dist[i] << endl;
  }

  return 0;
}

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

int D, G;
int mod = 1e9 + 7;

int main() {
    cin >> D >> G;
    vector<int> p(D), c(G);
    for (int i = 0; i < D; i++) {
        cin >> p[i] >> c[i];
    }
    
    int ans = 1e9;
    for (int i = 0; i < (1 << D); i++) {
        int rest = -1, count = 0, sum = 0;
        for (int j = 0; j < D; j++) {
            if(i >> j & 1) {
                sum += p[j] * (j + 1) + c[j] / 100;
                count += p[j];
            } else {
                rest = j;
            }
        }
        if (rest < 0) {
          ans = min(ans, count);
          continue;
        }
      
        int c = (G > sum * 100)? (G / 100 - sum + rest) / (rest + 1): 0;
        if (c < p[rest]) {
            ans = min(ans, count + c);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 41472
import sys
import random

def rd():
        return sys.stdin.readline().rstrip()

def rdi():
        return [ int(x) for x in rd().split() ]

N, K = rdi()
A = rdi()

#c = (N+K-3) / (K-1)
x = (N-1) / (K-1)
y = (N-1) % (K-1)
if y:
        x += 1

print x


Measured memory_bytes: 11912
s=input()
k=int(input())
n=len(s)
ans=""
for i in range(n):
    if i<n-1:
        if s[i]=="a":
            ans+="a"
        else:
            t=123-ord(s[i])
            if k>=t:
                ans+="a"
                k-=t
            else:
                ans+=s[i]
    if i==n-1:
        tt=(ord(s[i])-97+k)%26
        ans+=chr(tt+97)
print(ans)                

Measured memory_bytes: 9472
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

int n, A, B, C;
vector<int> l(10);

int dfs(int a, int b, int c, int i) {
  if (i == n) {
    return min({a, b, c}) > 0 ? abs(a - A) + abs(b - B) + abs(c - C) : INF;
  }

  int r0 = dfs(a, b, c, i + 1);
  int r1 = dfs(a + l[i], b, c, i + 1) + 10;
  int r2 = dfs(a, b + l[i], c, i + 1) + 10;
  int r3 = dfs(a, b, c + l[i], i + 1) + 10;

  return min({r0, r1, r2, r3});
}

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

  cin >> n >> A >> B >> C;
  for (int i = 0; i < n; i++) {
    cin >> l[i];
  }

  cout << dfs(0, 0, 0, 0) - 30 << ln;

  return 0;
}

Measured memory_bytes: 256
using namespace std;
#include <iostream>
#include <vector>
long knapsack1(vector<int>& w, vector<int>& p, int n, int c){
  long* prow = new long[c+1];
  long* crow = new long[c+1];
  for (size_t i = 0; i < c; i++)
    crow[i] = 0;
  for (size_t i = 1; i <=n ; i++) {
    long* temp = prow;
    prow = crow;
    crow = temp;
    for (size_t j = 1; j <= c; j++)
      if(w[i-1] <= j)
        crow[j] = max(prow[j], p[i-1] + prow[j-w[i-1]]);
      else
        crow[j] = prow[j];
  }
  return crow[c];

}
int main(){
  int c, n;
  cin >> n >> c;
  vector<int> w(n);
  vector<int> p(n);

  for (size_t i = 0; i < n; i++) {
    cin >> w[i];
    cin >> p[i];
  }

  cout << knapsack1(w, p, n, c) << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair <ll,ll>
#define vl vector <ll>
#define vp vector <pair<ll,ll>>
#define sort(x) sort(x.begin(), x.end())
#define N 1000000007
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b;
    cin>>a>>b;
    cout<<(a*b)/__gcd(a,b);
    return 0;
}


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

#pragma region
typedef long long ll;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define rep(i, begin, end)                              \
    for (__typeof(end) i = (begin) - ((begin) > (end)); \
         i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define REP(i, j) rep(i, 0, j)
#define testcase \
    int _;       \
    cin >> _;    \
    while (_--)
#define io                            \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    if (fopen("./input.txt", "r")) freopen("./input.txt", "r", stdin);
#define en '\n'
#pragma endregion

int main() {
    io;
    int n;
    cin >> n;
    cout << n + n * n + n * n * n << en;
    return 0;
}

Measured memory_bytes: 3540
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		
		int arr[]=new int[N+1];
		for(int n=1;n<=N;n++)
			arr[n]=in.nextInt();
		
		
		
		int ans = 0;
		for(int n=1;n<=N;n++){
			if(arr[arr[n]]==n){
				arr[n]=0;
				arr[arr[n]]=0;
				ans++;
			}
		}
		System.out.println(ans);
	}

}


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

int main(){
  
	string s,t;
	cin >> s >> t;
  	int ans;
  for(int i=0;i<3;i++){
    if(s[i]==t[i]){
    	ans++;
    }
  }
  cout << ans << endl;
	return 0;
}

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

int main() {
  string x;
  cin >> x;

  if (x[1]!=x[2]) {
    cout << "No" << endl;
  }else if(x[0]!=x[1] && x[2]!=x[3]){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
   }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define scan(n) scanf("%d",&n)
#define lscan(n) scanf("%lld",&n)
#define print(n) printf("%d ",n)
#define lprint(n) printf("%lld\n",n)
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rev(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define pi pair<int,int>
#define pll pair<ll,ll>
#define tc           ll t1; cin>>t1; while(t1--)
#define inp         ll n; cin>>n; ll arr[n]; rep(i,0,n) cin>>arr[i];
#define vect vector<ll>
#define sortv(v)       sort(v.begin(),v.end())
#define lower(v,n)    lower_bound(v.begin(),v.end(),n)-v.begin()
#define upper(v,n)    upper_bound(v.begin(),v.end(),n)-v.begin()
#define all(v)        v.begin(),v.end()
#define bitcount(n) __builtin_popcount(n)
#define ln <<endl
#define inf          INT_MAX
#define ninf         LONG_MIN
#define fast()         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
const   ll mod=1e9+7;
const ll N=5e5+5;

int main() 
{ 
          fast();
          
         int x;
         cin >>x;
         cout<<!x;
           return 0; 

} 

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

int n,l;
int a[100005];
int ans[100005];

int dfs(int x){
	if(ans[x]!=0)return ans[x];
	if(a[x]<a[x-1])ans[x]+=dfs(x-1);
	if(a[x]<a[x+1])ans[x]=max(ans[x],dfs(x+1));
	ans[x]+=l-a[x];
	return ans[x];
}

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

	int ret=0;
	for(int i=1;i<=n;i++){
		ret=max(ret,dfs(i));
	}

	printf("%d\n",ret);
}

Measured memory_bytes: 3128
using System;
using System.Linq;
namespace Program
{
	class test
    {
		        static void Main()
        {
            int ans1 = 0;
            int ans2 = 0;
            string[] s = Console.ReadLine().Split();
            int[] intArray = s.Select(int.Parse).ToArray();
            for (int i = 1;i<=intArray[0];i++)
            {
                ans1 = 0;
                if (i >= 10 && i <100)
                {
                    var aaa = i % 10;
                    var bbb = i / 10;
                    ans1 = aaa + bbb;
                    if (intArray[1] <= ans1 && ans1 <= intArray[2])
                    {
                        ans2 += i;
                    }
                }
                if (i >= 100 && i<1000)
                {
                    var aaa = i % 10;
                    var bbb = i / 10;
                    var ccc = bbb % 10;
                    var ddd = bbb / 10;
                    ans1 = aaa + ccc + ddd;
                    if (intArray[1] <= ans1 && ans1 <= intArray[2])
                    {
                        ans2 += i;
                    }
                }
                if (i >= 1000 && i <10000)
                {
                    var aaa = i % 10;//4
                    var bbb = i / 10;
                    var ccc = bbb % 10;//3
                    var ddd = bbb / 10;
                    var eee = ddd % 10;//2
                    var fff = ddd / 10;//1
                    ans1 = aaa + ccc + eee + fff;
                    if (intArray[1] <= ans1 && ans1 <= intArray[2])
                    {
                        ans2 += i;
                    }
                }
                if (i == 10000)
                {
                    ans1 = 1;
                    if (intArray[1] <= ans1 && ans1 <= intArray[2])
                    {
                        ans2 += i;
                    }
                }
                if (i < 10)
                {
                    ans1 = i;
                    if (intArray[1] <= ans1 && ans1 <= intArray[2])
                    {
                        ans2 += i;
                    }
                }
            }
            Console.WriteLine(ans2);
        }
    }
}

Measured memory_bytes: 13268
import numpy as np
H, W = map(int, input().split())
a = []
for i in range(H):
    ai = input()
    if len(set(ai)) == 1 and ai[0] == '.':
        continue
    else:
        a.append([ai[j] for j in range(len(ai))])
a = np.asarray(a).T
indices = []
for i in range(len(a)):
    if len(set(a[i])) == 1 and a[i][0] == '.':
        continue
    else:
        indices.append(i)
a = a[indices]
for ai in a.T:
    for aij in ai:
        print(aij, end='')
    print()

Measured memory_bytes: 13776
N, D = map(int,input().split())

XY = [list(map(int,input().split())) for _ in range(N)]

ans = 0

for n in range(N):
  x = XY[n][0]
  y = XY[n][1]
  
  if (x**2 + y ** 2 )**(1/2) <= D:
    ans +=1 
print(ans)

Measured memory_bytes: 45832
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
using ll=long long;
using ld=long double; 
using namespace std;
//const int INF = 7+(1e+9);
ll GCD(ll x, ll y)
{
    if (y == 0)
    {
        return x;
    }
    else
    {
        return GCD(y, x % y);
    }
}
ll LCM(ll x, ll y)
{
    return x / GCD(x, y) * y;
}
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll MOD=1e9+7;

int main(){
    int n;
    cin>>n;
    map<int,int> mp;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        int x;cin>>x;
        mp[x]++;
        vec[i]=x;
    }
    ll c=0;
    for(int i=0;i<n;i++){
      //  cout<<mp[vec[i]]<<" "<<vec[i]<<endl;
        if(mp[vec[i]]!=0){
            if(mp[vec[i]]>vec[i]){
                c+=mp[vec[i]]-vec[i];
                mp[vec[i]]=0;
             //   cout<<"jlksdf"<<endl;
            }
            if(vec[i]>mp[vec[i]]){
                c+=mp[vec[i]];
                mp[vec[i]]=0;
              //  cout<<"nsd"<<endl;
            }
        }
     //   cout<<c<<endl;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 5120
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int main()
{
	int a,b,c;cin>>a>>b>>c;
	if(a==b) cout<<c<<endl;
	else if(a==c) cout<<b<<endl;
	else cout<<a<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <complex>
#include <cmath>

using namespace std;
typedef complex<double> Vector;

double dot(const Vector &v1, const Vector &v2) {
    return v1.real()*v2.real() + v1.imag()*v2.imag();
}

int main() {
    double X1, Y1, X2, Y2, XQ, YQ;
    while(scanf("%lf,%lf,%lf,%lf,%lf,%lf", &X1, &Y1, &X2, &Y2, &XQ, &YQ) != EOF) {
        const Vector p1(X1, Y1), p2(X2, Y2), q(XQ, YQ);
        const Vector l(p2-p1);
        const Vector perp(l * Vector(0, -1));
        const double beta = dot(p1 - q, perp) / norm(perp);
        const Vector r(q + perp * (beta * 2));
        printf("%.6f %.6f\n", r.real(), r.imag());
    }
    return 0;
}

Measured memory_bytes: 1108
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)

    def add(self, i, x=1):
        i += 1
        while i <= self.n:
            self.data[i] += x
            i += i & -i

    def get_sum(self, i):
        i += 1
        x = 0
        while i > 0:
            x += self.data[i]
            i -= i & -i
        return x

    # Return sum for [l, r)
    def get_sum_range(self, l, r):
        return self.get_sum(r - 1) - self.get_sum(l - 1)


def main():
    N, Q = map(int, readline().split())
    C = list(map(int, readline().split()))
    LR = map(int, read().split())

    prev = [-1] * (N + 1)
    ps = [[] for _ in range(N)]
    for i, c in enumerate(C):
        if prev[c] != -1:
            ps[prev[c]].append(i)
        prev[c] = i

    qs = [[] for _ in range(N)]
    for i, (l, r) in enumerate(zip(*[iter(LR)] * 2)):
        qs[l - 1].append((r - 1, i))

    ans = [0] * Q
    bit = BIT(N)

    for l in range(N - 1, -1, -1):
        for r in ps[l]:
            bit.add(r)
        for r, i in qs[l]:
            ans[i] = (r - l + 1) - bit.get_sum(r)

    print('\n'.join(map(str, ans)), sep='\n')

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 298124
#include<bits/stdc++.h>
using namespace std;
#define INF (1LL<<30)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long

int hah(string s){
	while(1){
		int check=0;
		if(s.size()<4)break;
		lp(i,s.size()-4){
			if(s[i]=='['&&s[i+4]==']'){
				char op=s[i+1];
				int x=s[i+2]-'0';
				int y=s[i+3]-'0';
				int ref;
				if(op=='+'){
					ref=(x|y);
				}
				if(op=='*'){
					ref=(x&y);
				}
				if(op=='^'){
					ref=(x^y);
				}
				check=1;
				string sbef=s.substr(0,i);
				char c=ref+'0';
				string scen{c};
				string saf=s.substr(i+5,s.size()-i-4);
				s=sbef+scen+saf;
				/*
				cout<<sbef<<" "<<saf<<" "<<scen<<endl;
				cout<<op<<" "<<x<<" "<<y<<" "<<ref<<endl;
				cout<<s<<endl;
				int hoge;
				cin>>hoge;
	*/
				break;
			}
		}
		if(check==0)break;
	}
	return s[0]-'0';
}

signed main(){
	while(1){
		string s;
		cin>>s;
		if(s==".")break;
		int n;
		cin>>n;
		int tx[100000];
		lp(i,100000)tx[i]=0;
		int memo;
		lp(z,10000){
			string x=s;
			lp(i,x.size()){
				if(x[i]=='a'){
					x[i]=(z/1000)+'0';
				}
				if(x[i]=='b'){
					x[i]=(z%1000/100)+'0';
					
				}
				if(x[i]=='c'){
					x[i]=(z%100/10)+'0';
					
				}
				if(x[i]=='d'){
					x[i]=(z%10)+'0';
				}
			}
			int zx=hah(x);
			tx[zx]++;
			if(n==z)memo=zx;
		}
		cout<<memo<<" "<<tx[memo]<<endl;
	}
	return 0;
}


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

using namespace std;

const int N=2e3+5;
vector<int>g[N];
int ans[N];
int n,x,y;

void solve(int i){
	vector<int> used(n),dist(n,0);
	queue<int>q;
	q.push(i);
	used[i]=1;
	while(q.size()>0){
		int v=q.front();
		q.pop();
		if(v>i){
			ans[dist[v]]++;
		}
		for(auto to : g[v]){
			if(!used[to]){
				used[to]=1;
				dist[to]=dist[v]+1;
				q.push(to);
			}
		}
	}
}

int main(){
	cin>>n>>x>>y;
	--x,--y;
	for(int i=0;i<n-1;i++){
		g[i].push_back(i+1);
		g[i+1].push_back(i);
	}
	g[x].push_back(y);
	g[y].push_back(x);
	
	for(int i=0;i<n;i++){
		solve(i);
	}
	for(int i=1;i<n;i++){
		cout<<ans[i]<<'\n';
	}



}

Measured memory_bytes: 384
#include<cstdio>
#include<cmath>
int main( ) {
    double r;
    scanf ("%lf",&r);

    double area = M_PI * r * r;
    double circunfernce = 2.0 * M_PI * r;

    printf("%.5f %.5f\n",area,circunfernce);
    return 0;
}


Measured memory_bytes: 2748
#include <stdio.h>
int main(){
  long n,m,all;
  scanf("%ld %ld",&n,&m);
  if(n==1&&m==1){
    printf("1");
  } else if(n==1||m==1){
    printf("%ld",n*m-2);
  } else if(n==2||m==2){
    printf("0");
  } else {
    all=n*m;
    printf("%ld",all-2*(m+n)+4);
  }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int K, A, B;
  cin >> K >> A >> B;
  bool a = false;
  for(int i = A; i <= B; i++){
    if(i % K == 0) a = true;
  }
  if(a) cout << "OK" << endl;
  else cout << "NG" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(s) s.begin(),s.end()
#define uniq(a) a.erase(unique(all(a)),a.end())

int main(void){
    int n;
    while(cin>>n, n){
        vector<string> s(n);
        int a[256] = {};
        bool not_zero[256] = {};
        string c;
        rep(i,n){
            cin>>s[i];
            int k = s[i].size();
            if(k>1) not_zero[s[i][0]] = true;
            reverse(all(s[i]));
            rep(j,k){
                a[s[i][j]] += pow(10,j)*(i==n-1 ? -1 : 1);
                c += s[i][j];
            }
        }
        
        sort(all(c));
        uniq(c);
        c += string(10-(int)c.size(), '-');
        sort(all(c));
        int res = 0;
        do{
            if(not_zero[c[0]]) continue;
            int sum = 0;
            rep(i,10) sum += i*a[c[i]];
            if(sum == 0) res++;
        }while(next_permutation(all(c)));
        cout<<res<<endl;
    }

    return 0;
}



Measured memory_bytes: 3192
n,m = gets.chomp.split(' ').map(&:to_i)
h = gets.chomp.split(' ').map(&:to_i)
i = 0
hs = []
while i < n
  hs << [h[i], true]
  i += 1
end
# p hs
i = 0
while i < m
  a,b = gets.chomp.split(' ').map(&:to_i)
  hs[a-1][1] = false if h[a-1] <= h[b-1]
  hs[b-1][1] = false if h[b-1] <= h[a-1]
  i += 1
end
# p hs
ans = 0
i = 0
while i < n
  ans += 1 if hs[i][1] == true
  i += 1
end
p ans 

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

int main() {
  int n,k;
  cin >> n >> k;
  double ans = 0.0;
  
  for (int i = 1; i <= (n); ++i){
    double p = 1.0;
    int x = i;
    while(x<k){
      p *= 0.5;
      x *= 2;
    }
    ans += p/n;
  }
  printf("%.10f\n",ans);
  return 0;
}

Measured memory_bytes: 256
n = int(input())
S = [0 for i in range(13)]
H = [0 for i in range(13)]
C = [0 for i in range(13)]
D = [0 for i in range(13)]
for i in range(n):
	data = input().split()
	num = int(data[1])
	if data[0]=='S':
		S[num-1] = 1
	elif data[0]=='H':
		H[num-1] = 1
	elif data[0]=='C':
		C[num-1] = 1
	else:
		D[num-1] = 1
for j in range(13):
	if S[j]==0:
		print('S %d' % (j+1))
for j in range(13):
	if H[j]==0:
		print('H %d' % (j+1))
for j in range(13):
	if C[j]==0:
		print('C %d' % (j+1))
for j in range(13):
	if D[j]==0:
		print('D %d' % (j+1))


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
template <typename Val,typename Number>
//use ll or int for gcd
Val gcd(Val a, Val b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
//count vector and return pair (count,vector item)
template <typename Val,typename Number>
void count_vector(vector<Val>* A,vector<pair<Number,Val>>*R){
  sort(A->begin(),A->end());
  int count = 1;
  rep(i,A->size()){
    if(i<A->size()-1){
      if(A->at(i)==A->at(i+1))count++;
      else{
        R->emplace_back(count,A->at(i));
        count = 1;
      }
    }else{
      R->emplace_back(count,A->at(i));
      count = 1;
    }
  }
}



//---------------------------------------------------------------

int main(){
  int N;
  cin>>N;
  vector<ll> a(N);
  vector<ll> b;
  ll s = 0;
  rep(i,N){
    cin>>a.at(i);
    s+=a.at(i);
    b.push_back(s);
  }

  ll ans = 2000000001;
  rep(i,N-1){
    if(abs(s - 2*b.at(i))<ans)ans = abs(s - 2*b.at(i));

  }

cout<<ans<<endl;

}


Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






string S, T;
int N;
//---------------------------------------------------------------------------------------------------
#define yes "Yes"
#define no "No"
string solve() {
    rep(i, 0, N) {
        if (S == T) return yes;
        S = S.substr(N - 1) + S.substr(0, N - 1);
    }
    return no;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> S >> T;
    N = S.length();
    cout << solve() << endl;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define all(x) (x).begin(), (x).end()
#define lint long long

int main(){
    lint n, m; cin>>n>>m;
    vector<lint> a;
    rep(i, n){
        lint x; cin>>x;
        a.push_back(x);
    }

    vector<lint> b;
    b.push_back(0);
    rep(i, n){
        b.push_back((b[i] + a[i]) % m);
    }

    map<lint, lint> M;
    rep(i, n+1){
        M[b[i]]++;
    }

    lint ans = 0;
    for(auto itr = M.begin(); itr != M.end(); ++itr){
        lint val = itr->second;
        ans += val * (val-1) / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5748
#include<bits/stdc++.h>
using namespace std;
#define INF 1e15
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef long long ll;
typedef pair<int, int> P;
#define END system("PAUSE");return 0
string s;
bool S, E, N, W;
signed main() {
	cin >> s;
	
	rep(i, s.size()) {
		if (s[i] == 'S')S = 1;
		if (s[i] == 'E')E = 1;
		if (s[i] == 'N')N = 1;
		if (s[i] == 'W')W = 1;
	}
	if (S != N || E != W)puts("No");
	else puts("Yes");
	END;
}


Measured memory_bytes: 504
#include <iostream>
#include <vector>
#include<math.h>
#include<numeric>
#include<algorithm>
using namespace std;

int gcd (int n1, int n2) {
    return (n2 == 0) ? n1 : gcd (n2, n1 % n2);
}

int main()
{

    int K;
    cin >> K;
    int ans = 0;
    for(int a = 1; a <= K; a++){
        for (int b = 1; b <= K; b++){
            for (int c = 1; c <= K; c++){
                ans += gcd(a, gcd(b, c));
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3636
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <set>
#include <ctime>
#include <map>
#include <cstring>
#include <iterator>
#include <queue>
#include <assert.h>
#include <bitset>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <functional>

//#pragma comment(linker, "/STACK:512000000")

using namespace std;

#define pb emplace_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define forab(i, a, b) for (int i = (a); i < (b); ++i)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int infi = 1e9 + 7;
const ll infl = (ll)1e18 + (ll)7;

ll ar[100500];
ll sum1[100500];
ll sum2[100500];
int get1(int n, int x, int d) {
    int l = lower_bound(ar, ar + n, x - d) - ar;
    int r = lower_bound(ar, ar + n, x + d) - ar - 1;
    return max(r - l + 1, 0);
}
int32_t main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    //srand(time(NULL));
   // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    //freopen("customs.in", "r", stdin); freopen("customs.out", "w", stdout);
    int n, q;
    cin >> n >> q;
    forn(i, n)
        cin >> ar[i];
    sort(ar, ar + n);
    forn(i, n) {
        sum1[i] = ar[i];
        if (i)
            sum1[i] += sum1[i - 1];
        sum2[i] = ar[i];
        if (i > 1)
            sum2[i] += sum2[i - 2];
    }
    while (q--) {
        int x;
        cin >> x;
        if (x >= ar[n - 1]) {
            cout << sum2[n - 1] << '\n';
            continue;
        }
        int l = 1, r = n, ans = 0;
        while (l <= r) {
            int mid = (l + r) / 2;
            int i = n - mid;
            if (ar[i] < x) {
                r = mid - 1;
                continue;
            }
            int cnt = get1(n, x, abs(x - ar[i]));
            if (cnt + 1 >= mid) {
                ans = mid;
                l = mid + 1;
            } else
                r = mid - 1;
        }
        ll sum = 0;
        int i = n - ans;
        sum = sum1[n - 1];
        if (i)
            sum -= sum1[i - 1];
        i -= ans + 1;
        if (i >= 0)
            sum += sum2[i];
        cout << sum << '\n';
    }

    return 0;
}

Measured memory_bytes: 4096
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int num = Integer.parseInt(sc.nextLine());
        int new_num = num;
        int hundreds = num / 100;
        int tens = ((num / 10) % 10);
        int ones = num % 10;
        if(tens < hundreds){
            new_num = new_num + ((hundreds - tens) * 10);
            if(ones > hundreds){
                new_num = new_num - (ones - hundreds);
            }else{
                new_num = new_num + (hundreds - ones);
            }
        }else if((tens == hundreds) && (ones < hundreds)){
            new_num = new_num + (hundreds - ones);
        }else{
            new_num = ((hundreds + 1) * 100) + ((hundreds + 1) * 10) + (hundreds + 1);
        }
        
        if((hundreds == tens) && (tens == ones)){
            new_num = num;
        }
        
        System.out.println(String.valueOf(new_num));

    }
}


Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int n;
vector<pair<int,int> >v;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int num;
		cin>>num;
		v.push_back(make_pair(num,i));
	}
	sort(v.begin(),v.begin()+v.size());
	for(int i=0;i<n;i++)
	{
		cout<<v[i].second<<" ";
	}
	puts("");
}

Measured memory_bytes: 1780
// God put a smile upon your face <3

#include <bits/stdc++.h>`

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 958585860497

#define base 2001487

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    slld(n);

    __int128 mul = 1;

    for(i = 1; i <= n; i++)
    {
		slld(input);

		if(input == 0) mul = 0;

		if(mul == -1) continue;

		mul *= input;

		__int128 lim =1e18;

//		cout << (long long) mul << " " << (long long) lim << '\n';
		if(mul > lim) mul = -1;
    }

    cout << (long long)mul << '\n';


}




Measured memory_bytes: 3764
n, k = map(int,input().split())
s = input()

pt = 0
sak = 0

mae = s[0]
for i in range(1,n):
    if s[i] == mae:
        pt += 1
    else:
        sak += 1
    mae = s[i]

print(pt + min(sak, k * 2))

Measured memory_bytes: 39792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define forn(i,a,b) for (int i = a; i <= b; i++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
#define er erase
#define in insert
#define pi pair <int, int>
# define sz(x) (int)((x).size())
#define int long long

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

const ll inf = 0x3f3f3f3f3f3f3f;
const ll mod = 1000000007;
const int N = 2e6 + 11;
const int W = 1e4 + 11;
const long long INF64 = 3e18 + 1;


int n;

struct yes{
    int w,s,v;
};

bool cmp(yes x,yes y){
    return (x.s + x.w < y.s + y.w);
}

yes a[N];

int dp[N];

int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0); cerr.tie(0); cout.tie(0);

    cin >> n;

    for(int i = 1; i <= n; i++){
        cin >> a[i].w >> a[i].s >> a[i].v;
    }

    sort(a + 1, a + n + 1, cmp);

    for(int i = 1; i <= n; i++){
        for(int j = a[i].s + a[i].w; j >= a[i].w; j--){
            dp[j] = max(dp[j] , dp[j - a[i].w] + a[i].v);
        }
    }

    int ans = 0;

    for(int i = 1; i <= 2e6; i++)ans = max(ans , dp[i]);

    rc(ans);

}


Measured memory_bytes: 2432
a, b, c, k = map(int, input().split())

total = 0
if k-a>0:
    total += a
    k = k-a
else:
    total += k
    k = 0

if k-b>0:
    k = k- b
else:
    k = 0 

if k>0:
    total -= k 



print(total)



Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
int main(){
  string b;
  cin>>b;
  if(b=="A"){
    cout<<"T";
    return 0;
  }if(b=="G"){
    cout<<"C";
    return 0;
  }if(b=="T"){
    cout<<"A";
    return 0;
  }else{
    cout<<"G";
    return 0;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;
int v[100005];
int main()
{
    int i,n,s=0,e,nr=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%d",&v[i]);
    sort(v+1,v+n+1);
    e=v[1];
    nr=1;
    v[n+1]=v[n]+1;
    for(i=2;i<=n+1;i++)
    {
        if(v[i]!=e)
        {
            if(nr%2==1)
                s++;
            nr=1;
            e=v[i];
        }
        else
            nr++;
    }
    if(n==1)
        printf("1");
    else
        printf("%d",s);
    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    string S;
    cin >> S;

    ll counter = 0;
    ll ans = 0;
    rep(i, S.size()){
        if(S[i] == 'A' || S[i] == 'T' || S[i] == 'G' || S[i] == 'C'){
            counter++;
            ans = max(ans, counter);
        }else{
            counter = 0;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3492
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
#define INT_MAX 2147483647
#define _LIBCPP_DEBUG 0
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)	
using namespace std;


int max(int a,int b) {
	int max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(int a, int b) {
	int min;
	if (a < b) min = a;
	else min = b;
	return min;
}


int main() {
	int n;
	cin >> n;
	int t, a;
	cin >> t >> a;

	vector<int> h(n);

	int INF = INT_MAX;
	int res = INF;
	int findID = -1;

	rep(i, n) {
		cin >> h[i];
		int temp = (t*1000 - h[i] * 6) - a *1000;
		if (res > abs(temp)) {
			res = abs(temp);
			findID = i;
		}
	}

	cout << findID + 1 << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main()
{
	for(int n,d;cin>>n>>d,n|d;){
		vector<vector<int>> c(n);
		for(int i=0;i<n;i++){
			int m; cin>>m;
			c[i].resize(m);
			for(int j=0;j<m;j++)
				cin>>c[i][j];
		}
		
		vector<int> s(n);
		for(int i=0;i<n;i++)
			s[i]=accumulate(begin(c[i]),end(c[i]),0);
		
		for(;;){
			int end=true;
			for(int i=0;i<n;i++)
				end&=c[i].empty();
			if(end){
				cout<<"Yes"<<endl;
				break;
			}
			
			bool update=false;
			for(int i=0;i<n;i++) if(c[i].size()){
				bool ok=true;
				for(int j=0;j<n;j++)
					if(j!=i && abs(s[i]-c[i].back()-s[j])>d)
						ok=false;
				if(ok){
					s[i]-=c[i].back();
					c[i].pop_back();
					update=true;
				}
			}
			if(!update){
				cout<<"No"<<endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 1224
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(long long I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
ll f(ll b, ll n){
  if(n<b)return n;
  else return f(b,n/b)+n%b;
}
  int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,s;
  cin>>n>>s;
  if(n==s){
    cout<<n+1<<endl;
    return 0;
  }
  // b<sqrt(n)
  FOR(b,2,sqrt(n)+1){
    //cout<<b<<" "<<f(b,n)<<endl;
    if(f(b,n)==s){
      cout<<b<<endl;
      return 0;
    }
  }
  ll ans = 1e18;
  // b>sqrt(n)
  FOR(p,1,sqrt(n)+1){
    ll q=s-p;
    if((n-q)%p==0){
      ll b=(n-q)/p;
      if(q>=0&&q<b&&b>1&&f(b,n)==s) ans=min(ans,b);
    }
  }
  cout<<(ans==1e18?-1:ans)<<endl;
  return 0;
}

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

bool need_mizuyari(int h[], int n) {
  for ( int i = 0; i < n; i++ ) {
    if ( h[i] > 0 ) { return true; }
  }
  return false;
}

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

  int ans = 0;
  while ( need_mizuyari(h, n) ) {
    bool mizuyari = false;
    for ( int i = 0; i < n; i++ ) {
      if ( h[i] == 0 ) {
        if ( mizuyari ) { ans++; }
        mizuyari = false;
      } else {
        h[i]--;
        mizuyari = true;
      }
    }
    if ( mizuyari ) { ans++; }
  }

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


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int N;
vi dist;
vi even;
vi odd;
vector<vi> AdjList;
void bfs(int s) {
	dist[s]=0;
	queue<int> q;
	q.push(s);
	while(q.size()) {
		int tmp=q.front();
		//cout<<tmp<<" ";
		q.pop();
		for(int i=0 ; i<AdjList[tmp].size() ; i++) {
			int u=AdjList[tmp][i];
			if(dist[u]==-1) {
				dist[u]=dist[tmp]+1;
				q.push(u);
			}
		}
	}
}
int main() {
	cin>>N;
	int ans[N];
	bool used[N+1];
	AdjList.assign(N,vi());
	dist.assign(N,-1);
	used[N]=false;
	for(int i=1 ; i<N ; i++) {
		used[i]=false;
		int u,v;
		cin>>u>>v;
		u--; v--;
		AdjList[u].push_back(v);
		AdjList[v].push_back(u);
	}
	bfs(0);
	int cnt0=N/3;
	int cnt1=N/3;
	int cnt2=N/3;
	if(N%3==1) {
		cnt1++;
	}
	if(N%3==2) {
		cnt1++;
		cnt2++;
	}
	for(int i=0 ; i<N ; i++) {
		if(dist[i]%2==0) even.push_back(i);
		else odd.push_back(i);
	}
	if(even.size()<=cnt0) {
		for(int i=0 ; i<even.size() ; i++) {
			ans[even[i]]=3*(i+1);
			used[3*(i+1)]=true;
		}
		int tmp=1;
		for(int i=0 ; i<odd.size() ; i++) {
			if(used[tmp]) tmp++;
			ans[odd[i]]=tmp;
		}
	}
	//cout<<even.size()<<" "<<odd.size()<<endl;
//	cout<<cnt0<<" "<<cnt1<<" "<<cnt2<<endl;
	if(odd.size()<=cnt0) {
		for(int i=0 ; i<odd.size() ; i++) {
			ans[odd[i]]=3*(i+1);
			used[3*(i+1)]=true;
		}
		int tmp=1;
		for(int i=0 ; i<even.size() ; i++) {
			while(used[tmp]) tmp++;
			ans[even[i]]=tmp;
			used[tmp]=true;
		}
	}
	else if(even.size()<=cnt0) {
		for(int i=0 ; i<even.size() ; i++) {
			ans[even[i]]=3*(i+1);
			used[3*(i+1)]=true;
		}
		int tmp=1;
		for(int i=0 ; i<odd.size() ; i++) {
			while(used[tmp]) tmp++;
			ans[odd[i]]=tmp;
			used[tmp]=true;
		}
	}
	else {
		int tmp=1;
		for(int i=0 ; i<odd.size() ; i++) {
			if(3*i+1<=N) {
				ans[odd[i]]=3*i+1;
			}
			else {
				ans[odd[i]]=3*tmp;
				tmp++;
			}
		}
		for(int i=0 ; i<even.size() ; i++) {
			if(3*i+2<=N) {
				ans[even[i]]=3*i+2;
			}
			else {
				ans[even[i]]=3*tmp;
				tmp++;
			}
		}
	}
	for(int i=0 ; i<N ; i++) {
		cout<<ans[i]<<" ";
	}
}

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

long n, k;
long w[100000];

//????????????k??°????????§????????????a?????¨???????????????????????°
long check(long a){
	long ret=0;
	for(long i=0; i<k; ++i){
		long s=0;
		while(s+w[ret]<=a){
			s+=w[ret++];
			if(ret==n) return n;	
		}	
	}
	return ret;
}


int main(){
	scanf(" %ld %ld", &n, &k);
	for(long i=0; i<n; ++i) scanf(" %ld", &w[i]);
	
	long left=0, right=100000*10000;
	long p;
	
	//????????¢?´¢
	while(right-left>1){
		p=(left+right)/2;	
		long v=check(p);
		
		if(v>=n) right=p;
		else left=p;
	}
	
	printf("%ld\n", right);
}

Measured memory_bytes: 1972
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <functional>

using namespace std; using ll=long long; using ld=long double; using P=pair<ll,ll>; const int INF=1e9; const ll LINF=1e18;

int main(){
  int k; cin>>k;
  string s; cin>>s;
  if (s.size() > k) {
    cout<<s.substr(0,k)<<"..."<<endl;
  } else {
    cout<<s<<endl;
  }
}

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

using namespace std;

const int mod=1000000007;

int main(){
  long n;
  cin >> n;
  
  vector<long> num(1001,0);
  
  for(int i=2;i<=n;i++){
     long x=i;
     for(int j=2;j<=x;j++){
       while(!(x%j)) {
         num[j]++; 
         x/=j;
       }
     }
  }
  
  long res=1;
  
  for(int i=2;i<=n;i++){
    res*=(num[i]+1);
    res%=mod;
  }
  
  cout << res << endl;
}


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

int main()
{
    int x;
    cin>>x;
    vector<int> a(x);
   for(int i=0;i<x;i++)
   {
       cin>>a[i];
   }
   sort(a.begin(),a.end());
   cout<<a[x-1]-a[0];


  return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
#ifdef LOCAL_TEST
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    string yes = "Yes", no = "No";
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    map<char, int> mp;
    rep(i, h) rep(j, w) mp[s[i][j]]++;
    int cnt = 0;
    int one = 0;
    int two = 0;
    for(auto& p : mp) {
        p.se %= 4;
        if(p.se == 0);
        else if(p.se == 1) one += 1;
        else if(p.se == 2) two += 1;
        else if(p.se == 3) one += 1, two += 1;
    }
    if(one >= 2) {
        cout << no << endl;
        return 0;
    }
    if(one == 1) {
        if(h%2 == 1 && w % 2 == 1);
        else {
            cout << no << endl;
            return 0;
        }
    }
    int ma = 0;
    if(h & 1) ma += w/2;
    if(w & 1) ma += h/2;
    if(two <= ma) {
        cout << yes << endl;
    }
    else cout << no << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#define INF 500005
int arr[INF] ;
using namespace std;
int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	int ci = a * b;
	int ans = min(ci,c);
	cout << ans;
	
	
	
	return 0;
}

Measured memory_bytes: 256