akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int alpha[27] = {0};

int main() {
  string n;
  cin >> n;
  for (char a : n) {
    alpha[a-'a']++;
  }
  for (int i = 0; i < 26; i++) {
    if (alpha[i] == 0) {
      char found = i+'a';
      cout << found << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;


class Main{

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

        for ( int i = 0; i < N; i++ ){
            a[i] = sc.nextInt();
        }
        sortTheCards(N, a);
        System.out.println(dealTheCards(N, a));
    }
    private static void sortTheCards(int N, int[] a){
        Arrays.sort(a);
    }
    private static int dealTheCards(int N, int[] a){
        int sub = 0;
        int absSub = 0;
        int Alice = 0;
        int Bob = 0;
        for( int i = 0; i < N; i++){
            if( i % 2 == 0 ){
                Alice += a[i];
            }else{
                Bob += a[i];                
            }
        }
        sub = Alice - Bob;
        absSub = Math.abs(sub);
        return absSub;
    }
}

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

int main() {
    int k,a,b;cin>>k>>a>>b;
    int ans=0;
    for(int i=a;i<=b;++i){
        if(i%k==0){
            ans=1;
            break;
        }
    }
    if(ans==1)cout<<"OK"<<endl;
    else cout<<"NG"<<endl;

	return 0;
}

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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int x,a,b;

main() {
    cin >> x >> a >> b;
    if (abs(x-a) > abs (x-b)) ct("B")
    else ct("A")
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int a,b,x;
	scanf("%d %d %d",&a,&b,&x);

	if(x >= a && x <= a+b){

		printf("YES\n");

	}else{

		printf("NO\n");
	}

	return 0;
}


Measured memory_bytes: 3732
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import Data.List

main = do
  [n,a,b] <- map read . words <$> getLine :: IO [Int]
  city <- getIntListBC
  print $ solve city a b

bsToInt :: BC.ByteString -> Int
bsToInt = fst . fromJust . BC.readInt

getIntListBC :: IO [Int]
getIntListBC = map bsToInt . BC.words <$> BC.getLine

solve :: [Int] -> Int -> Int -> Int
solve (_:[])   _ _ = 0
solve (c:d:ds) a b
  | (d-c) * a > b = b + solve (d:ds) a b
  | otherwise     = (d-c) * a + solve (d:ds) a b


Measured memory_bytes: 5244
#include <iostream>
#include <iomanip>
#include <fstream>

#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>

#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>

#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */

long long gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

void solve(istream &cin) {
    ll N;
    cin >> N;
    if(!cin) return;
    int a;
    cin >> a;
    ll ans = a;
    for (int i = 1; i < N; ++i) {
        cin >> a;
        ans = gcd(a, ans);
    } // end i
    cout << ans << endl;
    
}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    cerr << "DEBUG MODE" << endl;
    string test_cases = "test.txt";
    auto fs = fstream(test_cases, fstream::in);
    while(fs) {
        solve(fs);
    }
#else
    solve(cin);
#endif
}


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

int main(){
    int m, f, r;
    while (1) {
    char score;
      cin >> m >> f >> r;
      if (m==-1 && f==-1 && r==-1) break;

      if (m==-1 | f==-1) score = 'F';
      else if (m+f >= 80) score = 'A';
      else if (m+f >= 65) score = 'B';
      else if (m+f >= 50) score = 'C';
      else if (m+f >= 30) {
        if (r >= 50) score = 'C';
        else score = 'D';
      }
      else if (m+f < 30) score = 'F';
      cout << score << endl;
    }
    return 0;
}


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

int main()
{
    int n,i,j,k;
    cin>>n;
    long long a[n],freq[100005];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        freq[a[i]]++;
    }
    sort(a,a+n,greater<int>());
    long long x=0,y=0;
    for(i=1;i<n;i++)
    {
        if(a[i]==a[i-1])
        {x=a[i];
        break;}
    }
    for(j=i+2;j<n;j++)
    {
        if(a[j]==a[j-1])
        {
            y=a[j];
            break;
        }
    }
    cout<<x*y<<endl;

}


Measured memory_bytes: 4388
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int d[n];
    for (int i = 0; i < n; i++)
    {
        cin >> d[i];
    }

    sort(d, d + n);
    cout << d[n / 2] - d[n / 2 - 1] << endl;
    return 0;
}


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

int main() {
	
	string s,t;
	cin>>s>>t;
	int k = 0;
	for(int i = 0; i < s.size(); i++)
	{
		if(s[i] != t[i])
		{
			k++;
		}
	}
	cout<<k;
	return 0;
}

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

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

using ll = long long;
#define INF 1e9

int main(){
  string S;
  cin >> S;
  S[3] = '8';
  cout << S << endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N;
map<string, llong> nums;

int main(int argc, char **argv) {
    cin >> N;

    for(int i = 0; i < N; ++i) {
        string s;
        cin >> s;
        
        sort(s.begin(), s.end());
        if(nums.find(s) == nums.end()) {
            nums[s] = 1;
        } else {
            nums[s]++;
        }
    }

    llong res = 0;
    for(map<string, llong>::iterator it = nums.begin(); it != nums.end(); ++it) {
        res += it->second * (it->second - 1) / 2;
    }
    
    cout << res << endl;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char S;
  cin >> S;
  
  if(S=='a'||S=='i'||S=='u'||S=='o'||S=='e'){
    cout<<"vowel"<<endl;
  }
  else{
    cout<<"consonant"<<endl;
  }
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
vector<int> v;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=9;i++)
	{
		for(int j=1;j<=9;j++)
		{
			v.push_back(i*j);
		}
	}
	bool b=false;
	for(int i=0;i<v.size();i++)
	{
		if(v[i]==n)
		{
			b=true;
			break;
		}
	}
	if(b)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	return 0;
}

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

typedef long long ll;

ll K;
string S;
ll N;

int main() {
  cin >> K >> S;
  N = S.size();
  if (N <= K)
    cout << S << endl;
  else
    cout << S.substr(0, K) << "..." << endl;
  return 0;
}


Measured memory_bytes: 3612
N, *W = open(0).read().split()

is_ok = True

if len(W) != len(set(W)):
    is_ok = False
else:
    for i, w in enumerate(W):
        if i > 0:
            if before_w != w[0]:
                is_ok = False
                break
        
        before_w = w[-1]
    
if is_ok:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9028
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
int x=0,y=0,z=0;
std::cin >> x;
std::cout << (x+1)/2 << '\n';
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(long long i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	LL l,r;
	cin>>l>>r;
	LL ans=mod;
	FOR(i,l,min(r+1,l+7000)){
		FOR(j,i+1,min(r+1,l+7000)){
			LL t=(1LL*i*j)%2019;
			if(t<ans){
				ans=t;
			}
		}
	}

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  vector<int>v(N);
  for(int& x:v)cin>>x;
  const int n=min(N,K);
  int ans=-2e9;
  for(int a=0;a<=n;a++){
    for(int b=0;a+b<=n;b++){
      const int c=K-a-b;
      vector<int>t;
      for(int i=0;i<a;i++)t.push_back(v[i]);
      for(int i=0;i<b;i++)t.push_back(v[N-i-1]);
      sort(t.begin(),t.end());
      int s=0;
      for(int&x:t)s+=x;
      for(int i=0;i<c&&i<t.size()&&t[i]<0;i++)s-=t[i];
      ans=max(ans,s);
    }
  }
  cout<<ans<<endl;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;

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

using edge=struct {int to,cap,cost,rev;};
using G=vector<vector<edge>>;
const int inf=1<<29;

void add_edge(G &graph,int a,int b,int c,int d){
	graph[a].push_back({b,c,d,int(graph[b].size())});
	graph[b].push_back({a,0,-d,int(graph[a].size()-1)});
}

int min_cost_flow(G &graph,int s,int t,int f){
	int res=0;
	while(f){
		int n=graph.size(),update;
		vector<int> dist(n,inf),pv(n,0),pe(n,0);
		dist[s]=0;

		rep(loop,n){
			update=false;
			rep(v,n)rep(i,graph[v].size()){
				edge &e=graph[v][i];
				if(e.cap>0 && chmin(dist[e.to],dist[v]+e.cost)){
					pv[e.to]=v,pe[e.to]=i;
					update=true;
				}
			}
			if(!update) break;
		}

		if(dist[t]==inf) return -1;

		int d=f;
		for(int v=t;v!=s;v=pv[v]) chmin(d,graph[pv[v]][pe[v]].cap);
		f-=d,res+=d*dist[t];

		for(int v=t;v!=s;v=pv[v]){
			edge &e=graph[pv[v]][pe[v]];
			e.cap-=d;
			graph[v][e.rev].cap+=d;
		}
	}
	return res;
}

int main(void){
	int n;
	while(cin >> n,n){
		const int all=366;
		G graph(all);

		rep(i,all-1) add_edge(graph,i,i+1,2,0); 

		rep(i,n){
			int s,t,w;
			cin >> s >> t >> w;
			s--;
			add_edge(graph,s,t,1,-w);
		}

		cout << -min_cost_flow(graph,0,all-1,2) << endl;
	}	
	return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)

void maximum(ll &a, ll b) {
	a = max(a,b);
}

int main() {
	ios::sync_with_stdio(false);

	ll N, M; cin >> N >> M;

	vl input_deg(N,0);
	vvl adj(N,vl());

	FOR(i,0,M) {
		ll x,y; cin >> x >> y;
		x--; y--;
		adj[x].pb(y);
		input_deg[y]++;
	}

	// knoten-nr., laenge bisher
	queue<pll> q;
	FOR(i,0,N) {
		if (input_deg[i] == 0) {
			q.push({i,0});
		}
	}

	ll maxi = -1;
	while (!q.empty()) {
		pll curr = q.front(); q.pop();

		maximum(maxi, curr.yy);
		FOR(i,0,sz(adj[curr.xx])) {
			input_deg[adj[curr.xx][i]] --;
			if (input_deg[adj[curr.xx][i]] == 0) {
				q.push({adj[curr.xx][i],curr.yy + 1});
			}
		}
	}
	cout << maxi << endl;
	return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){

int N,M,K,R;
double ave=0,S=0,aav=0;
while(1){
cin>>N;if(N==0)break;
for(int i=0;i<N;i++){
cin>>M>>R>>K;
S=M+R+K;ave=S/3;aav=(M+R)/2;
if(aav>=90)printf("A\n");
else if(ave>=80)printf("A\n");
else if(M==100||R==100||K==100)printf("A\n");
else if(ave>=70)printf("B\n");
else if(ave>=50){if(M>=80||R>=80)printf("B\n");
else printf("C\n");}
else printf("C\n");
}
ave=0,S=0,aav=0;
}
return 0;
}

Measured memory_bytes: 1116
n = gets.to_i

x1 = gets()
x2 = x1.split()
i = 1
min = x2[0].to_i
max = x2[0].to_i
sum = 0
while i <= n-1
 if min >= x2[i].to_i
  min = x2[i].to_i
 end
 i += 1
end

h = 1
while h <= n-1
 if max <= x2[h].to_i
  max = x2[h].to_i
 end
 h += 1
end

j = 0
while j <= n-1
 sum += x2[j].to_i
 j += 1
end
puts "#{min} #{max} #{sum}"


Measured memory_bytes: 7096
_ = gets
a = gets.chomp.split.map(&:to_i)
c = [399, 799, 1199, 1599, 1999, 2399, 2799, 3199]
d = Hash.new(0)
rc = 0

a.each do |r|
  rank = c.bsearch {|x| x >= r }
  d[rank] += 1 if !rank.nil?
  rc += 1 if rank.nil?
end

lb = d.size
ub = d.size + rc

lb += 1 if d.size == 0

puts [lb, ub].join(" ")

Measured memory_bytes: 1788
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &&i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())
#define pow2(n) (n * n)
#define int ll
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using p_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class F>
class FixPoint : private F {
public:
    explicit constexpr FixPoint(F &&f) : F(std::forward<F>(f)) {}
    template <class... Args>
    constexpr decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, std::forward<Args>(args)...); }
};
template <class F>
constexpr decltype(auto) funcs(F &&f) { return FixPoint<F>{std::forward<F>(f)}; }
template <class T>
std::vector<T> vecs(int n, T &&val) { return std::vector<T>(std::forward<int>(n), std::forward<T>(val)); }
template <class... Args>
decltype(auto) vecs(int n, Args &&... args) { return std::vector<decltype(vecs(std::forward<Args>(args)...))>(std::forward<int>(n), vecs(std::forward<Args>(args)...)); }
template <class V, class T>
void fill(V &x, const T &val) { x = val; }
template <class V, class T>
void fill(vector<V> &vec, const T &val) {
    for (auto &&v : vec)
        fill(v, val);
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    int ans = 0;
    rep(i, n) if (i % 2 == 0 && a[i] % 2 == 1)++ ans;
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3656
//AtCoder1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream> 
#include <algorithm>
#include <math.h> 
#include <vector>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
    double n;
    cin >> n;
    cout << fixed<< setprecision(10)<<ceil(n / 2) / n << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()
#define INF ((ll)(1e15))

using namespace std;

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

const int MAX_N = 1000;
vector<IL> G[MAX_N]; // P(to,cost)

ll dist[MAX_N];

int main()
{
	rep (i, MAX_N) G[i].clear();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int N, M; cin >> N >> M;
	rep (i, M){
		int a, b; ll c; cin >> a >> b >> c;
		--a, --b;
		G[a].push_back(IL(b,-c));
	} // end rep

	rep (i, N){
		dist[i] = INF;
	} // end rep

	bool negative = false;
	dist[0] = 0LL;
	rep (iter, 2 * N){
		rep (v, N){
 			if (dist[v] == INF) continue;
			for (int j = 0; j < (int)G[v].size(); ++j){
				int u = G[v][j].first;
				ll c = G[v][j].second;
				if (dist[u] > dist[v] + c){
					dist[u] = dist[v] + c;
					if (u == N - 1 && iter >= N){
						negative |= true;
					} // end if
				} // end if
			} // end for
		} // end rep
	} // end rep

	if (!negative){
		cout << -dist[N - 1] << endl;
	}else{
		cout << "inf" << endl;
	} // end if

	return 0;
}

Measured memory_bytes: 892
#include <stdio.h>

int main(){

    int A,B,C,D;

    scanf("%d %d %d %d",&A,&B,&C,&D);

    if(A*B>C*D){
        printf("%d",A*B);
    }
    else
    {
        printf("%d",C*D);
    }
    

    return 0;

}

Measured memory_bytes: 128
def main():
    K, S = map(int, input().split())
    ans = 0
    for X in range(K+1):
        Y_min = max(0, S-X-K)
        Y_max = min(K, S-X)
        ans += max(0, Y_max - Y_min + 1)
    print(ans)
if __name__ == "__main__":
    main()

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

int main() {
  string c;
  cin>> c;
  for(int i = 0; i < c.size(); i++){
    if(c.at(i) == 'a'){
      cout << "vowel" << endl;
    }
    else if(c.at(i) == 'i'){
      cout << "vowel" << endl;
    }
    else if(c.at(i) == 'u'){
      cout << "vowel" << endl;
    }
    else if(c.at(i) == 'e'){
      cout << "vowel" << endl;
    }
    else if(c.at(i) == 'o'){
      cout << "vowel" << endl;
    }
    else{
      cout << "consonant" <<endl;
    }
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// Macros for easier access
#define ll long long
#define endl '\n'
#define F first
#define S second
#define umap unordered_map
#define uset unordered_set
#define test ll cases; cin>>cases; for(ll testCase = 1; testCase <= cases; testCase++)   //test cases
#define fill(name, val) memset(name, val, sizeof(name));
#define mop(a, op, b)    (a%mod op b%mod)%mod
#define error(x) fixed<<setprecision(x) //cout<<error(5)<<someDouble    -> example - 3.14159
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll, ll>
#define get(a, n)    for(ll i = 0; i < n; i++)    cin>>a[i];
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug(x) cerr << #x << " : " << (x) << endl
// Constants
#define MX 100001
#define mod 1000000007LL
#define inf 1000000000000000000LL
void init(){
	boost;
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
}

/*	Author: 🆉🅴🅽🅾🅻🆄🆂	*/

int main(){
	init();
	ll x, k, d;	cin>>x>>k>>d;
	x = abs(x);
	ll dist = x/d;
	if(dist >= k)	cout<<(x - k*d);
	else{
		ll ans = x - dist*d;
		k -= dist;
		if(!(k&1))	cout<<ans;
		else	cout<<abs(ans-d);
	}
}

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

long long N, A[200009], B[200009], cnt;
queue<int>Q;

bool check(int pos) {
	int id1 = (pos + N - 1) % N, id2 = (pos + 1) % N;
	if (B[pos] - B[id1] - B[id2] >= A[pos]) return true;
	return false;
}

void sousa(int pos) {
	int id1 = (pos + N - 1) % N, id2 = (pos + 1) % N;
	long long rem = B[pos] - A[pos], rem2 = B[id1] + B[id2];
	long long K = rem / rem2;
	B[pos] -= B[id1] * K;
	B[pos] -= B[id2] * K;
	cnt += K;
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) cin >> B[i];

	for (int i = 0; i < N; i++) {
		if (check(i) == true) Q.push(i);
	}

	while (!Q.empty()) {
		int pos = Q.front(); Q.pop();
		sousa(pos);

		for (int i = -1; i <= 1; i++) {
			int v = (pos + N + i) % N;
			if (check(v) == true) Q.push(v);
		}
	}
	for (int i = 0; i < N; i++) {
		if (A[i] != B[i]) cnt = -1;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;
typedef long long ll;
typedef pair<double, double> P;

long double ans;

void dfs(vector<P> &length, vector<int> state, int node, int num, int& count, vector<int> pass){ 
    if(node != -1){
        state[node] = 1;
        pass.push_back(node);
    }
    if(num == length.size()){
        ++count;
        for(int i=0;i<pass.size()-1;++i){
            double dx = length[pass[i]].first - length[pass[i+1]].first;
            double dy = length[pass[i]].second - length[pass[i+1]].second;
            ans += pow(dx * dx + dy * dy, 0.5);
            //cout << pass[i] << " ";
        }
        //cout << endl;
        return;
    }
    for(int i=0;i<state.size();++i){
        if(state[i] == 0){
            /*if(node != -1){
                double dx = length[i].first - length[node].first;
                double dy = length[i].second - length[node].second;
                ans += pow(dx * dx + dy * dy, 0.5);
            }*/
            dfs(length, state, i, num+1, count, pass);
        }
    }
}

int main()
{
    int N;
    cin >> N;
    ans = 0;
    vector<P> length(N);
    vector<int> state(N, 0);
    vector<int> pass;
    for(int i=0;i<N;++i){
        cin >> length[i].first >> length[i].second;
    }

    int count = 0, c=1;
    dfs(length, state, -1, 0, count, pass);
    for(double i=2;i<N+1;++i){
        ans /= i;
        c *= i;
    }
    printf("%.10Lf\n", ans);
}


Measured memory_bytes: 256
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  H,W=LI()
  Ch,Cw=LI()
  Dh,Dw=LI()
  Ch-=1
  Cw-=1
  Dh-=1
  Dw-=1
  field=[S() for _ in range(H)]

  q=collections.deque()
  q2=collections.deque()
  q.append((Ch,Cw,0))
  ans=[[inf]*W for _ in range(H)]
  while True:
    if not q:
      if not q2:
        break
      else:
        q=q2
        q2=collections.deque()
    # for x in ans:
    #   print(x)
    # print()
    y,x,cnt=q.popleft()
    if ans[y][x]<=cnt:
      continue
    ans[y][x]=cnt
    if y==Dh and x==Dw:
      continue

    for dy,dx in dd:
      ny=y+dy
      nx=x+dx

      if 0<=ny<H and 0<=nx<W:
        if field[ny][nx]=='.':
          q.append((ny,nx,cnt))
        else:
          if dy==1 and dx==0:
            for i in range(0,2):
              for j in range(-2,3):
                nny=ny+i
                nnx=nx+j
                if 0<=nny<H and 0<=nnx<W:
                  if field[nny][nnx]=='.':
                    if ans[nny][nnx]>cnt+1:
                      q2.append((nny,nnx,cnt+1))
          elif dy==0 and dx==1:
            for i in range(-2,3):
              for j in range(0,2):
                nny=ny+i
                nnx=nx+j
                if 0<=nny<H and 0<=nnx<W:
                  if field[nny][nnx]=='.':
                    if ans[nny][nnx]>cnt+1:
                      q2.append((nny,nnx,cnt+1))
          elif dy==-1 and dx==0:
            for i in range(-1,1):
              for j in range(-2,3):
                nny=ny+i
                nnx=nx+j
                if 0<=nny<H and 0<=nnx<W:
                  if field[nny][nnx]=='.':
                    if ans[nny][nnx]>cnt+1:
                      q2.append((nny,nnx,cnt+1))
          elif dy==0 and dx==-1:
            for i in range(-2,3):
              for j in range(-1,1):
                nny=ny+i
                nnx=nx+j
                if 0<=nny<H and 0<=nnx<W:
                  if field[nny][nnx]=='.':
                    if ans[nny][nnx]>cnt+1:
                      q2.append((nny,nnx,cnt+1))

  x=ans[Dh][Dw]
  if x==inf:
    return -1
  return x

# main()
print(main())


Measured memory_bytes: 181256
$N=<>;
for$i(1..$N){${-$_}+=grep{$i%$'**$_<1}//..6for grep{(1x$_)!~/^(11+)\1+$/}2..$N}
for$a(-$N..0){
	$z+=$$a>73;
	for$b(-$N..0){
		if($a-$b){
			$z+=$$a>3&&$$b>13;
			$z+=$$a>1&&$$b>23;
			$z+=grep$a-$_&&$$a>1&&$$b>3&&$$_>3,$b+1..0
		}
	}
}
print$z


Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

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




int main(){
  ll a,b,c; cin >> a >> b >> c;
  if((a < b and a < c and c < b) or (a > b and a > c and c > b)){
    cout << "Yes" << endl;
  }
    
  else cout << "No" << endl;
  
  
}

Measured memory_bytes: 3608
/* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod (int)(1e9+7)
#define MAXI (int)(1e15+100)
#define N 200005




// Driver code to test above functions
int32_t main()
{
    
 
   
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++)
        cin >> a[i];

    int ans = 0;
    sort(a, a + n);  
  
    int count = 0; 
      
    for( int i = n-1; i >= 1; i--)
    { 
        int l = 0, r = i-1; 
        while( l < r)
        { 
            if( a[l] + a[r] > a[i])
            { 
                count += r - l ;  
                r--;   
            } 
            else  
                l++;   
        } 
    } 

    cout << count << endl;

    return 0;
    
} 

Measured memory_bytes: 256
from collections import deque


n = int(input())

info = [list(map(int, input().split())) for i in range(n - 1)]
tree = [[] for i in range(n)]
for i in range(n - 1):
    a, b = info[i]
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)


root = 0
visited = [-1] * n
def dfs(root):
    q = deque([root])
    visited[root] = 0
    while q:
        v = q.pop()
        for nxt_v in tree[v]:
            if visited[nxt_v] != -1:
                continue
            else:
                visited[nxt_v] = (visited[v] + 1) % 2
                q.append(nxt_v)
dfs(0)
cnt0 = 0
cnt1 = 0
for i in range(n):
    if visited[i] == 0:
        cnt0 += 1
    else:
        cnt1 += 1

num1 = n // 3 
num2 = n // 3
num3 = n // 3
if n % 3 >= 1:
   num1 += 1
if n % 3 >= 2:
   num2 += 1
    
ans = [0] * n

set1 = set()
set2 = set()
set3 = set()
for i in range(1, n + 1):
    if i % 3 == 0:
        set3.add(i)
    elif i % 3 == 1:
        set1.add(i)
    elif i % 3 == 2:
        set2.add(i)
        
if cnt0 <= num3:
    for i in range(n):
        if visited[i] == 0:
            ans[i] = set3.pop()
        else:
            if set1:
                ans[i] = set1.pop() 
            elif set2:
                ans[i] = set2.pop()         
            elif set3:
                ans[i] = set3.pop()  

elif cnt1 <= num3:
    for i in range(n):
        if visited[i] == 1:
            ans[i] = set3.pop()
        else:
            if set1:
                ans[i] = set1.pop() 
            elif set2:
                ans[i] = set2.pop()         
            elif set3:
                ans[i] = set3.pop()  
else:
    num147 = 0
    num258 = 0
    num369 = 0
    for i in range(n):
        if visited[i] == 0:
            num = num147 * 3 + 1
            if num > n:
                num = num369 * 3 + 3
                ans[i] = num
                if num > n:
                    error
                    exit()
                set3.remove(num)
                num369 += 1
                continue
            ans[i] = num # 1, 4, 7, 10, ...
            set1.remove(num)
            num147 += 1
        else:
            num = num258 * 3 + 2 
            if num > n:
                num = num369 * 3 + 3
                if num > n:
                    error
                    exit()
                ans[i] = num
                set3.remove(num)
                num369 += 1
                continue
            ans[i] = num # 2, 5, 8, 11, ...
            set2.remove(num)
            num258 += 1
     
    for i in range(n):
        if ans[i] == 0:
            if set1:
                ans[i] = set1.pop()
            elif set2:
                ans[i] = set2.pop()
            elif set3:
                ans[i] = set3.pop()
print(*ans)


Measured memory_bytes: 125676
N = input()
N = int(N)
l = [int(input()) for i in range(N)]
flg = 1
ma = 0
mi = 0
for i in range(1,len(l)):
    if(mi > l[i-1] or flg ==1):
        mi = l[i-1]
    if(ma < l[i] - mi or flg ==1):
        ma = l[i] - mi
        flg = 0
print(ma)


Measured memory_bytes: 13596
#include <iostream>

int main(){
    std::string str;
    std::cin >> str;

    std::string ans = "Good";
    for(int i = 0; i < 3; ++i){
        if(str.at(i) == str.at(i + 1)){
            ans = "Bad";
            break;
        }
    }

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

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
using namespace std;


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

  int ans = 0;
  sort(p,p+n,greater<int>());
  for(int i = 0;i<n;i++){
    if(i ==0) ans += p[i]/2;
    else ans += p[i];
  }

  std::cout << ans << '\n';
  return 0;
}


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

int dp[24][1 << 21];
int a[24][24];
int n;

const int mod = 1e9 + 7;

int find(int i, int mask) {
  if (dp[i][mask] == -1) {
    dp[i][mask] = 0;
    for (int j = 0; j < n; j++) {
      if ((mask & (1 << j)) && a[i][j] == 1) {
        dp[i][mask] = (dp[i][mask] + find(i + 1, mask ^ (1 << j))) % mod;
      }
    }
  }
  return dp[i][mask];
}

int main() {
  ios::sync_with_stdio(false);
  // cin.tie(NULL);
  memset(dp, -1, sizeof(dp));
  cin >> n;
  for (int i = 0; i < (1 << n); i++) dp[n][i] = 0;
  dp[n][0] = 1;
  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }

  cout << find(0, (1 << n) - 1) << '\n';

  return 0;
}

Measured memory_bytes: 196864
#include<bits/stdc++.h>
using namespace std;
string s, t;
int main()
{
    cin>> s>> t;
    for(int i=0; i<s.length(); i++){
        if(s[i]!=t[i]){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 3616
//https://beta.atcoder.jp/contests/abc087/tasks/arc090_a
#include <iostream>
#include <cstdlib>
using namespace std;

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

    int time, d;
    bool flag;
    for(int i = 1; i <= n; i++){
        d = abs( x[i] - x[i-1]) + abs( y[i] - y[i-1]); // 距離差分
        time = t[i] - t[i-1]; //時間差分
        //cout << d << ' ' << time << endl;
        if ( d <= time ){
            if ( (time % 2) == (d % 2) ) flag = true;
            else flag = false;
        }
        else flag = false;

        if ( flag == false ) break;
    }
    if ( flag ) cout << "Yes" << endl;
    else cout << "No" << endl;    


    return 0;
}

Measured memory_bytes: 1408
use proconio::input;

fn main() {
    input! {
        n: usize,
        mut a: [i64; n],
    };
    a.sort();
    let s = std::iter::once(0)
        .chain(a.iter().scan(0, |acc, a_i| {
            *acc += a_i;
            Some(*acc)
        }))
        .collect::<Vec<_>>();
    let mut c = 0;
    for (i, (&a_i, &s_i)) in a.iter().zip(s.iter()).enumerate() {
        if s_i * 2 < a_i {
            c = i;
        }
    }
    let ans = n - c;
    println!("{}", ans);
}


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

int main(void){

	int A,B,C,K,M;

	scanf("%d %d %d",&A,&B,&C);
	scanf("%d",&K);

	M = A;
	if (M<B){
		M = B;
	}
	if (M<C){
		M = C;
	}

	printf("%d\n",A+B+C+M*((int)pow((double)2,(double)K)-1));

	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
      
      Scanner scanner = new Scanner(System.in);
      int n = scanner.nextInt();
      int a;
      String[] d = new String[n];

      for (int i = 0;  i < n  ; i ++ ) {
          a = scanner.nextInt();
          d[a - 1] = Integer.toString(i + 1);
      }

      for (int i = 0;  i < n ; i ++ ) {
         System.out.print(d[i]);
         System.out.print(" ");
      }

      return;
    }
  }

Measured memory_bytes: 68712
using System;
using System.Linq;

namespace comp
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			var hoge = Console.ReadLine ().Split(' ').Select(x => int.Parse(x)).ToArray();

			string result = "";

			if (hoge [0] + hoge [1] == 15) {
				result = "+";
			} else if (hoge [0] * hoge [1] == 15) {
				result = "*";
			} else {
				result = "x";
			}

			Console.WriteLine (result);
		}
	}
}


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

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

  string s; int k; cin >> s >> k;
  REP(i, s.size()){
    if(s[i] == 'a') continue;
    if(26-(s[i]-'a') <= k){
      k -= 26-(s[i]-'a');
      s[i] = 'a';
    }
  }
  k %= 26;
  while(k > 0){
    if(s[s.size()-1] == 'z') s[s.size()-1] = 'a';
    else s[s.size()-1]++;
    k--;
  }
  cout << s << endl;

  return 0;
}


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

typedef long long ll;
const int N = 324, N2 = N * 2, mod = 1000000007;

int n;
int tag[N2];
int dp_[2][N][N], (*cur)[N] = *dp_, (*nxt)[N] = dp_[1];

inline void add(int &x, const int y) {x += y - mod, x += x >> 31 & mod;}

int main() {
	int i, c, u, v, unk = 0, ans;
	scanf("%d", &n);
	for (i = 1; i <= n; ++i)
		scanf("%d%d", &u, &v), ~u && ~v ? tag[u] = tag[v] = -1 : ~(u & v) ? tag[u & v] = 1 : ++unk;
	**nxt = 1;
	for (i = n * 2; i; --i) if (~tag[i]) {
		std::swap(cur, nxt), memset(nxt, 0, sizeof *dp_);
		for (u = 0; u <= n; ++u)
			for (v = 0; v <= n; ++v) if (c = cur[u][v]) {
				add(tag[i] ? nxt[u][v + 1] : nxt[u + 1][v], c);
				if (u) add(nxt[u - 1][v], c);
				if (!tag[i] && v) add(nxt[u][v - 1], (ll)c * v % mod);
			}
	}
	for (ans = **nxt; unk; --unk) ans = (ll)ans * unk % mod;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        for(int i=1;i<=B;i++){
        	if(A*i%B==C){
        		System.out.println("YES");
        		System.exit(0);
        	}
        }
        System.out.println("NO");
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int popcnt(int n) {
  return __builtin_popcount(n);
}

int f(int n) {
  if (n==0) return 0;
  return 1 + f(n % popcnt(n));
}

int main() {
  int n; string x; cin >> n >> x;
  // find x mod pc;
  int pc=0;
  rep(i,n) if(x[i] == '1') pc++;
  vi ans(n);
  rep(b, 2) {
    int npc = pc;
    if (b==0) npc++;
    else npc--;
    if (npc <= 0) continue;
    int num = 0;
    rep(i, n) {
      num = (num << 1) %npc;
      num += x[i] - '0';
    }
    int k = 1;
    for (int i=n-1; i>=0; --i) {
      if (x[i] - '0' == b) {
        int nx = num;
        if (b == 0) nx = (nx + k) % npc;
        else nx = (nx - k + npc) % npc;
        ans[i] = f(nx) + 1;
      }
      k = (k << 1) % npc;
    }
  }
  rep(i,n) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 4448
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<string>
#include<cmath>
#include<algorithm>
#include<ctime>
#include<fstream>
#include<sstream>
#include<vector>
#include<set>
#include<deque>
#include<cstring>
#include<queue>
#include<stdio.h>
#include<set>
#include<stack>
#include<numeric>
#include<map>
#include<cstdio>
#include<bitset>
#include<array>
#include<list>
using namespace std;
#define ll long long 
const ll mod = 1e9 + 7;

ifstream f1;
ofstream f2;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	f1.open("INP.txt");
	f2.open("OUT.txt");
	ll n, m;
	cin >> n >> m;
	m = m * 2 + 1;
	cout << n / m + (n % m > 0) << endl;
	//system("pause");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=5e3+10;

int n,k,a[N],s,f[N];

int main(){
	int i,j,jud;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;++i){
	   scanf("%d",&a[i]);
	   a[i]=min(a[i],5000);
	   s+=a[i];
	}
	f[0]=1;
	sort(a+1,a+n+1);
	for(i=n;i>=1;--i){
		jud=1;
		for(j=k-1;j>=k-s && j>=0 ;--j)
		 if(f[j]){jud=0;break;}
		if(jud){printf("%d\n",i);return 0;}
		for(j=a[i];j<=k;++j)
		 f[j]|=f[j-a[i]];
		s-=a[i];
	}
	puts("0");
}

Measured memory_bytes: 256
#include <stdint.h>
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <string>
#include <vector>

constexpr int kMaxItems = 100;
constexpr int kMaxWeightSum = 10000;

int dp[kMaxItems][kMaxWeightSum + 1];

struct {
  int w;
  int v;
} items[kMaxItems];

int main(int argc, char *argv[]) {
  int N, W;
  std::cin >> N >> W;

  for(int i = 0; i < N; i++){
    std::cin >> items[i].v >> items[i].w;
  }

  for(int i = 0; i < N; i++){
    // use up to ith item
    for(int w = 0; w <= W; w++){
      // within capacity w
      if(items[i].w > w) {
        // cannot put items[i] with this capacity
        if(i-1 < 0) {
          dp[i][w] = 0;
          continue;
        }
        dp[i][w] = dp[i-1][w];
        continue;
      }
      if(i-1 < 0) {
        dp[i][w] = items[i].v;
        continue;
      }
      dp[i][w] = std::max(dp[i-1][w], dp[i-1][w-items[i].w] + items[i].v);
      continue;
      
    }
  }
  std::cout << dp[N-1][W] << std::endl;

  return 0;
}



Measured memory_bytes: 7036
#include<stdio.h>
#include<algorithm>
using namespace std;

struct Card {
    char mark;
    char value;
};

void BubbleSort(struct Card A[], int N){
    for(int i=0; i<N; i++){
        for(int j=N-1; j>=i+1; j--){
            if(A[j].value < A[j-1].value){
                swap(A[j], A[j-1]);
            }
        }
    }
}

void SelectionSort(struct Card A[], int N){
    for(int i=0; i<N; i++){
        int min = i;
        for(int j=i; j<N; j++){
            if(A[j].value < A[min].value){
                min = j;
            }
        }
        if(i != min) swap(A[i], A[min]);
    }
}

int main(){

    int n;
    scanf("%d", &n);
    getchar();

    Card A[100], B[100];

    for(int i=0; i<n; i++){
        scanf("%c%c", &A[i].mark, &A[i].value);
        getchar();
        B[i] = A[i];
    }

    BubbleSort(A, n);
    SelectionSort(B, n);

    for(int i=0; i<n; i++){
        if(i==n-1) printf("%c%c\n", A[i].mark, A[i].value);
        else printf("%c%c ", A[i].mark, A[i].value);
    }
    printf("Stable\n");

    for(int i=0; i<n; i++){
        if(i==n-1) printf("%c%c\n", B[i].mark, B[i].value);
        else printf("%c%c ", B[i].mark, B[i].value);
    }

    bool flag = false;
    int i;
    for(i=0; i<n; i++){
        if(flag == true) break;
        if((A[i].mark != B[i].mark)||(A[i].value != B[i].value))
            flag = true; 
    }
    if(i==n) printf("Stable\n");
    else printf("Not stable\n");

    return 0;
}


Measured memory_bytes: 2736
def main():
  N = int(input())
  S = [input() for _ in range(N)]

  d = {}
  for i, s in enumerate(S):
    x = "".join(sorted(s))
    if x in d:
      d[x] += 1
    else:
      d[x] = 1
  
  cnt = 0
  for v in d.values():
    if v == 1:
      continue
    if v == 2:
      cnt += 1
    elif v == 3:
      cnt += v
    else:
      cnt += sum(list(range(1,v)))

  print(cnt)
if __name__ == "__main__":
  main()

Measured memory_bytes: 24980
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N),v(1000100), u(1000100);
    rep(i,N){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    ll ans = 0;
    rep(i,N){
        u[A[i]]++;
    }
    rep(i,N){
        if(v[A[i]] == 0 && u[A[i]] == 1){
            ans++;
        }else if(v[A[i]] != 0){
            continue;
        }
        REP(j,1,1000100){
            if(A[i]*j < 1000001){
                v[A[i]*j]++;
            }else{
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 20412
N = int(input())
A = [int(x) for x in input().split()]

money = 1000
s = 0
for i in range(N - 1):
    # begginig of i-th day
    # sell all of stocks
    money += s * A[i]
    s = 0

    if A[i] < A[i + 1]:
        s = money // A[i]
        money %= A[i]

    # print('end of {0}-th day, money: {1}, stock: {2}'.format(i, money, s))

money += s * A[-1]
print(money)

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

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

    int ma=0, now=0;
    rep(i, S.size()) {
        if (S[i] == 'I') now++;
        else now--;
        ma = max(ma, now);
    }

    cout << ma << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String[] sortedWords = new String[N];
        for (int i = 0; i < N; i++) {
            String word = sc.next();
            char[] tmp = word.toCharArray();
            Arrays.sort(tmp);
            String sortedWord = String.valueOf(tmp);
            sortedWords[i] = sortedWord;
        }

        Map<String, Integer> map = new HashMap();
        for (int i = 0; i < N; i++) {
            map.put(sortedWords[i], new Integer(0));
        }

        for (String sortedWord : sortedWords) {
            int currentCount = map.get(sortedWord);
            map.put(sortedWord, currentCount + 1);
        }
        long ans = 0;
        for (Integer count : map.values()) {
            ans += calcCombination(count, 2);
        }
        System.out.print(ans);
    }

    long calcCombination(int n, int r) {
        if (n < 0 || r < 0) {
            throw new IllegalArgumentException("Arguments must be 0 and over.");
        }
        else if (n == r || r == 0) {
            return 1;
        }
        else if (n < r) {
            return 0;
        }
        else {
            long result = 1;
            for (int i = 1; i <= r; i++) {
                result = result * (n - i + 1) / i;
            }
            return result;
        }
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
}

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

int main() {
  int N, L;
  cin >> N >> L;
  int S = N * (N + 1) / 2 + (L - 1) * N;
  if (L > 0) {
    cout << S - L << endl;
  }
  else if (L + N - 1 < 0) {
    cout << S - L - N + 1 << endl;
  }
  else {
    cout << S << endl;
  }
}


Measured memory_bytes: 256