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

int main(){
   int N;
   cin >> N;
   map<string, int> S;
   for (int i=0; i<N; i++){
      string key;
      cin >> key;
      S[key]++;
   }
   int max = 0;
   for (auto x : S){
      if (x.second > max){
         max = x.second;
      }
   }
   for (auto i = S.begin(); i != S.end(); i++){
      if (i->second == max){
         cout << i->first << endl;
      }
   }
}



Measured memory_bytes: 25216
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> divisorList = new List<int>();
            List<int> countResult = new List<int>();

            var Input = Console.ReadLine().Split(' ');

            var divisor = int.Parse(Input[2]);

            //??\????????????C??????????´???°??????
            for (int i = 1; i <= divisor/2; i++)
            {

                if(divisor%i == 0)
                {
                    divisorList.Add(i);
                }
            }

            divisorList.Add(divisor);

            for(int x = int.Parse(Input[0]); x <= int.Parse(Input[1]); x++)
            {
                foreach(var find in divisorList)
                {
                    if(find == x)
                    {
                        countResult.Add(find);
                    }
                }

            }

            Console.WriteLine(countResult.Count);
        }

    }

}

Measured memory_bytes: 9232
#include <iostream>

using namespace std;


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

    int a[100];

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

    // sort
    for (int i=0; i<n; i++) {
        for (int j=i+1; j<n; j++) {
            if (a[i] < a[j]) {
                int tmp = a[j];
                a[j] = a[i];
                a[i] = tmp;
            }
        }
    }
    
    int total_vote = 0;
    for(int i=0; i<n; i++) {
        cerr << a[i] << " ";
        total_vote += a[i];
    }

    // m個えらぶ
    bool is_enough_vote = true;
    for(int i=0; i<m; i++) {
        if (a[i] < ( (double)total_vote / (4.0 * (double)m) ) ) {
            is_enough_vote = false;
        }
    }

    cout << (is_enough_vote ? "Yes" : "No") << endl;


    return 0;
}


Measured memory_bytes: 256
def main5():
    str = input("");
    #unk
    buf = str.split();
    num = [];
    for i in range(3):
        num.insert(i,int(buf[i]));
    if num[2] > int((num[1] - num[0])/2):
        for i in range(num[1]-num[0]+1):
            print(num[0] + i,end=' ');
    else:
        for i in range(num[2]):
            print(num[0] + i,end=' ');

        for i in range(num[2]):
            print(num[1] - (num[2]-1) + i,end=' ');

    #end


if __name__ == '__main__':
    #main4()
    main5()

Measured memory_bytes: 3064
let n = stdin.ReadLine() |> int
let vs = stdin.ReadLine().Split(' ') |> Array.map float |> Array.sort
let mutable cash = (vs.[0] + vs.[1]) / 2.
for i = 2 to n - 1 do
    cash <- (cash + vs.[i]) / 2.
printfn "%f" cash

Measured memory_bytes: 14940
def func(str)
  str=str.split(' ').map(&:to_i)
  hash={}
  str.each do |e|
    if hash.key?(e)
      hash[e] += 1
    else
      hash[e] = 1
    end
  end
  str.map!{|e|hash[e]}
  str.join(' ')
end

def main(str,before="",n = -1)
  buf=func(str)
  if buf == before
    puts n
    puts buf
  else
    main(buf,str,n+1)
  end
end

while gets.to_i != 0 do
  main(gets.chomp)
end

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	ll n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n)cin>>a[i];

	ll sum = 0;
	rep(i,n){
		if(i%2==0){
			sum += a[i];
		} else {
			sum -= a[i];
		}
	}
	vector<int> ans(n+10);
	ans[0] = sum;
	rep(i,n){
		ans[i+1] = 2 * a[i] - ans[i];
	}
	rep(i,n) cout << ans[i] << endl;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

#define MAX_N 50

ll N, M;
ll a[MAX_N];
ll b[MAX_N];

bool d[MAX_N][MAX_N];
bool seen[MAX_N];

void dfs(ll v) {
    seen[v] = true;
    rep (v2, N) {
        if (!d[v][v2] || seen[v2]) {
            continue;
        }
        dfs(v2);
    }
}

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> M;

    rep (i, M) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        d[a[i]][b[i]] = true;
        d[b[i]][a[i]] = true;
    }

    ll ans = 0;
    rep (i, M) {
        d[a[i]][b[i]] = false;
        d[b[i]][a[i]] = false;

        rep (j, N) {
            seen[j] = false;
        }

        dfs(0);

        rep (j, N) {
            if (!seen[j]) {
                ans++;
                break;
            }
        }
        d[a[i]][b[i]] = true;
        d[b[i]][a[i]] = true;
    }

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

Measured memory_bytes: 256
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int N, M;
	
	cin >> N >> M;

	ll a[N], b[N], c[M], d[M];
	
	rep(i, N)
	{
		cin >> a[i] >> b[i];
	}

	ll e[N][M];

	rep(i, M)
	{
		cin >> c[i] >> d[i];
		for(int j = 0; j < N; j++)
		{
			e[j][i] = abs(a[j] - c[i]) + abs(b[j] - d[i]);
		}
	}

	rep(i, N)
	{
		ll min = MOD;
		int idx = -1;
		rep(j, M)
		{
			if (e[i][j] < min)
			{
				min = e[i][j];
				idx = j;
			}
		}
		cout << idx + 1 << endl;
	}

	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 1e9+7;


int main(){
    ll N; cin >> N;
    vector<ll> V1(N), V2(N);
    for(int i = 0; i < N; i++){
        ll a, b; cin >> a >> b;
        V1[i] = a+b;
        V2[i] = a-b;
    }
    sort(V1.begin(), V1.end());
    sort(V2.begin(), V2.end());
    cout << max( V1[N-1]-V1[0], V2[N-1] - V2[0] ) << endl;


}



Measured memory_bytes: 6372
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {
    int N,K,p[1001];
    int sum=0;
    cin >> N >> K;
    for(int i=0;i<N;i++){
        cin>>p[i];
    }
    sort(p,p+N);
    for(int k=0;k<K;k++){
        sum+=p[k];
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
#define ll long long
#define f(i, a, b) for(ll i = a; i <= b; ++i)
#define ff(i, a, b) for(ll i = a; i < b; ++i)
#define F(i, a, b) for(ll i = a; i >= b; --i)
#define FF(i, a, b) for(ll i = a; i > b; --i)
#define x first
#define y second
#define X real()
#define Y imag()
using namespace std;
typedef complex<ll> P;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;

const ll N = 1e5+7;
ll n, a, dp[N][2];
vector<ii> odd, even;

signed main(){
//	freopen("PERFECT1.inp","r",stdin);
//	freopen("PERFECT1.out","w",stdout);
//	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	f(i,1,n){
		cin >> a;
		if(i%2 == 0){
			if(!dp[a][0]) even.push_back({a, -1});
			dp[a][0]++;
		}else{
			if(!dp[a][1]) odd.push_back({a, -1});
			dp[a][1]++;
		}
	}
	ff(i,0,odd.size()) odd[i] = {dp[odd[i].x][1], odd[i].x};
	ff(i,0,even.size()) even[i] = {dp[even[i].x][0], even[i].x};
	sort(odd.begin(), odd.end(), greater<ii>());
	sort(even.begin(), even.end(), greater<ii>());
//	cout << odd[0].y <<"\n";
	odd.push_back({0, N});
	even.push_back({0, N});
	if(odd[0].y != even[0].y){
		cout << n - odd[0].x - even[0].x;
	}else{
		cout << n-max(odd[0].x + even[1].x, odd[1].x + even[0].x);
	}
}



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


int main(void) {
  int H, W, K;
  cin >> H >> W >> K;
  vector<vector<char>> c(H, vector<char>(W));
  rep(i, H) {
    rep(j, W) {
      cin >> c[i][j];
    }
  }

  int ans = 0;

  for (int bitH = 0; bitH < (1<<H); ++bitH) {
    for (int bitW = 0; bitW < (1<<W); ++bitW) {
      int count = 0;
      for (int i = 0; i < H; ++i) {
        if (bitH & (1<<i)) {
          continue;
        }
        for (int j = 0; j < W; ++j) {
          if (bitW & (1<<j)) {
            continue;
          }
          if (c[i][j] == '#') {
            count++;
          }
        }
      }
      if (count == K) {
        ans++;
      }
    }
  }

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

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

using namespace std;

int main(int argc, char **argv)
{
	int n, o, h, t;
	string s;
	cin >> n;
	
	while(n--){
		o = h = t = 0;
		while(o < 3){
			cin >> s;
			if(s == "HIT"){
				if(h == 3){
					t++;
				} else {
					h++;
				}
			} else if(s == "HOMERUN"){
				t = t + h + 1;
				h = 0;
			} else {
				o++;
			}
		}
		cout << t << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

int32_t main()
{
	int n,x;
	cin>>n>>x;
	string s;
  	cin>>s;
  	if(s[x-1]=='A')
  		s[x-1]='a';
  	else if(s[x-1]=='B')
  		s[x-1]='b';
  	else
  		s[x-1]='c';
  	cout<<s<<endl;
}

Measured memory_bytes: 256
N = int(input())

def f(x):
  return x * (x+1) // 2

ans = 0
for x in range(1, N+1):
  if x * x > N:
    break
  # x = y
  ans += x * x
  # x < y の 2 倍
  y_high = N//x
  ans += 2 * x * (f(y_high) - f(x))

print(ans)

Measured memory_bytes: 9168
import java.util.*
import java.io.PrintWriter



fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val cout = PrintWriter(System.`out`)
    val n = cin.nextInt()
    val k = cin.nextInt()
    cin.nextLine()
    val s = "R" + cin.nextLine() + "L"

    // var cut = 0
    var unhappy = 0
    var ans : Int
    for (i in 1..n) {
        if ((s[i-1] == 'R' && s[i] == 'L') || (s[i] == 'R' && s[i+1] == 'L')) {
            unhappy += 1
        }
    }
    if (unhappy > k*2) {
        ans = n - (unhappy - k*2)
    } else {
        ans = n - 1
    }

    cout.println(ans)
    
    cout.flush()
}


fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

Measured memory_bytes: 34608
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
ll n,k,ans[200005]={0};
cin>>n>>k;

rep(i,k+1,n)
{
	for(int j=0;j<=n;j+=i)
	{
		ans[j+k]++;
		ans[j+i]--;
	}
}
ll a=0;
rep(i,1,n)ans[i]+=ans[i-1];
rep(i,1,n)a+=ans[i];
ol(a);
return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<queue>
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;

#define  N 15
int n;
int dis[N],maps[N][N];
int main()
{
    int i,a,b,c,j,k;
    while(scanf("%d",&n),n)
    {
        for(i=0;i<N;i++)
        {
            for(j=0;j<N;j++)
            {
                maps[i][j]=(i==j)?0:INF;
            }
        }

        int m=-1;
        for( i=0; i<n; i++)
        {
            scanf("%d%d%d",&a,&b,&c);
            m=max(a,m);
            m=max(b,m);
            maps[a][b]=maps[b][a]=c;
        }

        for(k=0;k<=m;k++)
        {
            for(i=0;i<=m;i++)
            {
                for(j=0;j<=m;j++)
                {
                    if(maps[i][j]>maps[i][k]+maps[k][j])
                        maps[i][j]=maps[i][k]+maps[k][j];
                }
            }
        }

        int  Min=INF;
        int index=-1;
        memset(dis,0,sizeof(dis));
        for(i=0;i<=m;i++)
        {
            for(j=0;j<=m;j++)
            {
                dis[i]=dis[i]+maps[i][j];
            }
            if(Min>dis[i])
            {
                index=i;
                Min=dis[i];
            }
        }
        printf("%d %d\n",index,Min);
    }
    return 0;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
#include<math.h>
#define N 100005
#define K 200005
#define MOD 998244353
#define ll long long int
using namespace std;
 ll min(ll a,ll b)
 {
     if(a<=b)
     {
         return a;
     }
     else
     {
         return b;
     }
     
 }
 ll max(ll a,ll b)
 {
     if(a>=b)
     {
         return a;
     }
     else
     {
         return b;
     }
 }
int main() {
ll n,W;
cin>>n>>W;
ll w[n],v[n];
ll size=0;
for(ll i=0;i<n;i++)
{
    cin>>w[i]>>v[i];
    size+=v[i];
}

vector<ll> dp(size+1,1e9+1);
dp[0]=0;
for(ll i=0;i<n;i++)
{
   for(ll j=size-v[i];j>=0;j--)
   {
       dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i]);
   }
}
ll ans=0;
for(ll i=0;i<size+1;i++)
{
   // cout<<dp[i]<<endl;
    if(dp[i]<=W)
    {
        ans=i;
    }
}
cout<<ans;

//ll ans=0;
/*for(ll i=0;i<=W;i++)
{
    ans=max(dp[i],ans);
}
//cout<<ans;*/
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 
 
 //1. x^x = 0
 //2. x^0 = x
 //3. xor(1,2,3..., 2^M - 1) = 0 for M >= 2
 //xor(1,2,3,4,5,,7) = 6

//(1 2 . . . 2^m-1 without k)  k (2^m-1 ... 2 1 ) k

void solve(){
	ll m,k; cin >> m >> k;
	if(k==0){
		FOR(i,pow(2,m)) cout << i << " " << i << " "; 
	} else if(m == 1){
		cout << -1;
	} else if(pow(2,m) <= k){
		cout << -1;
	} else{
		FOR(i,pow(2,m)){
			if(i==k) continue;
			else cout << i << " ";
		}
		cout << k << " ";
		for(int i = pow(2,m)-1; i>=0; --i){
			if(i == k) continue;
			else cout << i << " ";
		}
		cout << k;
	}
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 4096
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long LL;
const int N=1e6;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
char s[N];
int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1),i,l,r,mid,sum,R;
	s[0]='0';
	for (l=1,r=n;l!=r;) {
		mid=(l+r)>>1;
		R=mid*9;sum=0;
		for (i=n;i>=0;i--) {
			R+=(s[i]-'0')*9;
			sum+=R%10;
			R/=10;
		}
		if (sum<=9*mid) r=mid;
		else l=mid+1;
	}
	printf("%d\n",l);
	return 0;
}


Measured memory_bytes: 768
object Main {
  case class Line(string: String) {
    def strings: Seq[String] = string.split(' ')
    def ints: Seq[Int] = strings.map(_.toInt)
    def i(n: Int): Int = ints(n)
  }

  def readLine: Line = Line(io.StdIn.readLine())
  def readLines(n: Int): Seq[Line] = List.fill(n)(Line(io.StdIn.readLine()))

  def yesNo(b: Boolean): String = if (b) "Yes" else "No"

  def main(args: Array[String]) {
    println(readLine.ints.sorted.mkString(" "))
  }
}

Measured memory_bytes: 43716
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVVll = vector<VVll>;
using VVVld = vector<VVld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


int main() {
  int N; cin >> N;
  VVll a(N, Vll(3));
  rep(i, N) cin >> a[i][0] >> a[i][1] >> a[i][2];
  sort(all(a), [] (Vll x, Vll y) { return x[0]+x[1] > y[0]+y[1]; });

  const int S = 1e4;
  VVll dp(N+1, Vll(S+2));

  rep(i, N) rep(w, S+1) {
    int wi = a[i][0];
    int si = a[i][1];
    ll vi = a[i][2];
    dp[i+1][w] = dp[i][w];
    if (w <= si) chmax(dp[i+1][w], vi + dp[i][min(w+wi, S+1)]);
  }

  ll ans = dp[N][0];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 78592
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-8;
typedef int weight;
struct edge
{
	int to; weight cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
typedef vector<vector<edge>> Graph;
int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
int place(int x, int y, int w) { return w*x + y; }
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int h, w, s, sum;
pii dp[50][50][50][50];
int fld[50][50];

pii solve(int lx, int ly, int rx, int ry)
{
	if (dp[lx][ly][rx][ry].first >= 0) return dp[lx][ly][rx][ry];
	int cnt = 0;
	FOR(i, lx, rx)FOR(j, ly, ry) cnt += fld[i][j];
	if (cnt<sum - s) return dp[lx][ly][rx][ry] = pii(-INF, -INF);
	pii res = pii(1, cnt);
	if (rx - lx > 1)
	{
		FOR(i, lx+1, rx)
		{
			pii tmp;
			pii a = solve(lx, ly, i, ry);
			pii b = solve(i, ly, rx, ry);
			tmp.first = a.first + b.first;
			tmp.second = min(a.second, b.second);
			if (res.first < tmp.first || (res.first == tmp.first&&res.second<tmp.second)) res = tmp;
		}
	}
	if (ry - ly > 1)
	{
		FOR(i, ly+1, ry)
		{
			pii tmp;
			pii a = solve(lx, ly, rx, i);
			pii b = solve(lx, i, rx, ry);
			tmp.first = a.first + b.first;
			tmp.second = min(a.second, b.second);
			if (res.first < tmp.first || (res.first == tmp.first&&res.second<tmp.second)) res = tmp;
		}
	}
	return dp[lx][ly][rx][ry] = res;
}

int main()
{
	while (cin >> h >> w >> s, h)
	{
		sum = 0;
		REP(i, 50)REP(j, 50)REP(k, 50)REP(l, 50) dp[i][j][k][l] = pii(-1, -1);
		REP(i, h)REP(j, w)
		{
			cin >> fld[i][j];
			sum += fld[i][j];
		}
		pii ans = solve(0, 0, h, w);
		cout << ans.first <<" "<< ans.second - (sum - s) << endl;
	}
	return 0;
}

Measured memory_bytes: 50004
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)


using namespace std;
using ll = long long;

int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n,a,b;
    cin >> n >> a >> b;
    if((b-a)%2==1)cout << "Borys" << endl;
    else cout << "Alice" << endl; 

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    int n,m;
    while(cin>>n>>m&&n&&m){
        vector<int> v(100,0);
        rep(i,0,n){
            int x; cin>>x;
            rep(j,0,x){
                int t; cin>>t; t--;
                v[t]++;
            }
        }
        int ans=-1,num=-1;
        rep(i,0,100){
            if(v[i]>=m && num<v[i]){
                num=v[i];
                ans=i+1;
            }
        }
        cout<<((ans==-1)?0:ans)<<endl;
    }
    return 0;
}



Measured memory_bytes: 3068
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include<deque>
#include<stack>
#include <iterator>
using namespace std;




int main()
{
    
    string s;
    cin >> s;
    if (s.size() < 6) {
        cout << "No" << endl;
        return 0;
   }
    else if (s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }


}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int ok(int x,int y){
  return min(x,y)>0 || max(x,y)==0;
}

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  string str;
  cin>>str;
  vector<int> cnt(200);
  for(char c:str) ++cnt[c];
  cout<<(ok(cnt['N'],cnt['S'])&&ok(cnt['W'],cnt['E'])?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

def build(t,arr,v,tl,tr):
    if tl == tr:
        t[v] = arr[tl]
    else:
        tm = (tl+tr)//2
        build(t,arr,2*v,tl,tm)
        build(t,arr,2*v+1,tm+1,tr)
        t[v] = max(t[2*v],t[2*v+1])

def maxQuery(t,v,tl,tr,l,r):
    if l > r:
        return 0
    if l == tl and r == tr:
        return t[v]
    tm = (tl+tr)//2
    return max(maxQuery(t,2*v,tl,tm,l,min(r,tm)),maxQuery(t,2*v+1,tm+1,tr,max(l,tm+1),r))

def update(t,v,tl,tr,pos,new_val):
    if tl == tr:
        t[v] = new_val
    else:
        tm = (tl+tr)//2
        if pos <= tm:
            update(t,2*v,tl,tm,pos,new_val)
        else:
            update(t,2*v+1,tm+1,tr,pos,new_val)
        t[v] = max(t[2*v],t[2*v+1])

def create(n,arr):
    t = [0]*4*n
    build(t,arr,1,0,n-1)

    return t
    

def main():
    n = int(raw_input())
    hts = list(map(int,raw_input().split()))
    beauties = list(map(int,raw_input().split()))
    flowers = {}
    for i in range(n):
        flowers[hts[i]] = beauties[i]

    dp = [0]*n
    t = create(n,dp)
    for i in range(n-1,-1,-1):
        curr = hts[i]
        max_val = maxQuery(t,1,0,n-1,curr-1,n-1)
        dp[curr-1] += flowers[curr]+max_val
        update(t,1,0,n-1,curr-1,dp[curr-1])
        #print(t)

    print(max(t))


main()


Measured memory_bytes: 104312
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;


int main(void)
{
    int N, K;
    cin >> N >> K;

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

    cout << ceil( ((double)N-1)/(K-1) )<< endl;
}


Measured memory_bytes: 3788
n=int(input())
a=1
b=1
c=1
d=1000000007
if n==1:
  print(0)
elif n==2:
  print(2)
else:
  for i in range(n):
    a=(a*10)%d
    b=(b*9)%d
    c=(c*8)%d
  ans=(a+c-2*b)%d
  print(ans)

Measured memory_bytes: 8948
def main():
    n, m, X, Y = map(int, input().split())
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))

    x.sort(reverse=True)
    y.sort()

    x_max = max(X, x[0])
    y_min = min(Y, y[0])

    if x_max < y_min:
        print("No War")
    else:
        print("War")


if __name__=='__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;

int main(){
    string t;
    cin >> t;
    int a = 0;
    rep(i,t.size()){
        if(t[i]=='?'){
            t[i] = 'D';
        }
    }
    cout << t << endl;
    return 0;
}

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

int main () {
  char i;
  cin >> i;
  if(i == 'A') {
    cout << 'T' <<endl;
  }else if (i == 'T'){
    cout << 'A' <<endl;
  }else if (i == 'G'){
    cout << 'C' <<endl;
  }else {
    cout << 'G' <<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	string s; cin >> s;
	vector<char> a;
	a.push_back(s[0]);
	a.push_back(s[1]);
	a.push_back(s[2]);
	a.push_back(s[3]);
	sort( a.begin(), a.end() );
	if( a[0] == a[1] && a[2] == a[3] && a[0] != a[3] ) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include "stdio.h"

int main()
{
	int n,a,min,max,i;
	long sum;
	scanf("%d", &n);
	if(n!=0){
		scanf("%d", &a);
		min=a;max=a;sum=a;
		for(i=1;i<n;i++){
			scanf("%d", &a);
			if(min > a){min = a;}
			if(max < a){max = a;}
			sum += a;
		}
		printf("%d %d %ld\n", min, max, sum);
	}
	else {printf("     \n");}
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
using namespace std;
int main()
{
  int n=0,ans;
  cin >>n;
  while(n!=-1){
    ans=0;
    if(n>30){
      ans+=(n-30)*160;
      n=30;
    }
    if(n>20){
      ans+=(n-20)*140;
      n=20;
    }
    if(n>10)
      ans+=(n-10)*125;
    cout <<4280-(ans+1150)<<endl;
    cin>> n;
  }
  return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    ll n; cin >> n;
    print((1000 - n % 1000) % 1000)
    
    return 0;
}

Measured memory_bytes: 3584
using System;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var a = int.Parse(_[0]);
            var p = int.Parse(_[1]);

            var x = ((a * 3) + p) / 2;
            Console.WriteLine(x);
        }
    }
}


Measured memory_bytes: 11092
n=int(input())
s=input()
ss=s[::-1]
ans=10**7
front_bucket=[0,0]
back_bucket=[0,0]

for i in range(n):
  if s[i]=="E":
    front_bucket[0]+=1
  else:
    front_bucket[1]+=1

for i in range(n):
  if ss[i]=="E":
    front_bucket[0]-=1
    ans=min(ans, front_bucket[1]+back_bucket[0])
    back_bucket[0]+=1

  else:
    front_bucket[1]-=1    
    ans=min(ans, front_bucket[1]+back_bucket[0])
    back_bucket[1]+=1

print(ans)

Measured memory_bytes: 3828
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <limits.h>
#include <map>
#include <numeric>
 
namespace test {
  std::string to_string(char val) {
    return std::string(1, val);
    // return std::string{val};
  }
}
 
using namespace std;
 
int main(void) {
  int a, b , c;
  cin >> a >> b >>c;
 
  int result;
 
  result = b / a;
 
  cout << (result > c ? c : result) << endl;
 
  return 0;
}

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

int main(){
    char bw[2]={'B','W'};
    string s;
    cin>>s;
    int n=s.size();
    long long int res=1e15;
    for(int k=0;k<2;k++){
    int blef=-1;
    for(int i=0;i<n;i++){
        if(s[i]==bw[k])
            continue;
        blef=i;
        break;
    }
    if(blef==-1){
        cout<<0<<endl;
        return 0;
    }
    int brig=-1;
    for(int i=n-1;i>=0;i--){
        if(s[i]==bw[k])
            continue;
        brig=i;
        break;

    }
    long long int cnt=0;
    cnt+=int(blef!=0)+int(brig!=n-1);
    for(int i=blef;i<=brig;i++){
        if(s[i]==bw[k]){
            cnt+=2;
            for(;i<=brig && s[i]=='B';i++){}
        }


    }
    res=min(cnt,res);
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
using namespace std;
const int maxn = 100010;
int n; ll b[maxn], c[maxn];
struct epoch { int op; ll ave; } a[maxn];
int main() {
	scanf("%d", &n); char ch[10]; 
	scanf("%lld", &a[1].ave);
	rep(i, 2, n) {
		scanf("%s%lld", ch, &a[i].ave);
		if (ch[0] == '-') a[i].op = 1;
	}
	rep(i, 1, n) b[i] = b[i - 1] + a[i].ave; int las = 0;
	rep(i, 1, n) c[i] = c[i - 1] + ((a[i].op) ? - a[i].ave : a[i].ave);
	ll ans = c[n];
	rep(i, 1, n) if (a[i].op) {
		if (!las) {
			las = i;
			continue;
		}
		ans = max(ans, c[las] - (c[i - 1] - c[las]) + b[n] - b[i - 1]);
		las = i;
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 3456
program disco
  implicit none

  integer :: x, y, p

  read(*,*) x, y

  p = 0
  
  if( x == 1 ) then
     p = 300000
  else if( x == 2 ) then
     p = 200000
  else if( x == 3 ) then
     p = 100000
  end if

  if( y == 1 ) then
     p = p + 300000
  else if( y == 2 ) then
     p = p + 200000
  else if( y == 3 ) then
     p = p + 100000
  end if

  if ( x == 1 .and. y == 1 ) then
     p = p + 400000
  end if

  write(*,*) p
  
  stop
end program disco


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

int A[22][22];
int B[22];

int main() {
   int N, M, C;
   scanf("%d %d %d", &N, &M, &C);
   for (int i = 0; i < M; i++)
      scanf("%d", &B[i]);
   for (int i = 0; i < N; i++)
      for (int j = 0; j < M; j++)
         scanf("%d", &A[i][j]);
   int ans = 0;
   for (int i = 0; i < N; i++) {
      int curr = C;
      for (int j = 0; j < M; j++)
         curr += A[i][j] * B[j];
      if (curr > 0)
         ans++;
   }//for
   printf("%d\n", ans);
   return 0;
}//main


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

#define lli long long int

using namespace std;

const int mc = 1e9 + 7;

template<typename T>
void print(vector<T> v)
{
	for (size_t i=0;i<v.size();++i){
		cout << v[i] << " ";
	}
	cout << endl;
}

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

	vector<lli> v1(n), v2(n);
	vector<bool> e1(n), e2(n);

	lli last = 0;
	for (int i=0;i<n;++i){
		cin >> v1[i];
		if ( v1[i] != last){
			e1[i] = true;
		}
		else{
			e1[i] = false;
		}
		last = v1[i];
	}

	last = 0;
	for (int i=0;i<n;++i){
		e2[i] = true;
		cin >> v2[i];
		if (v2[i] == last){
			e2[i-1] = false;
		}
		last = v2[i];
	}

	/*
	print(v1);
	print(e1);
	print(v2);
	print(e2);
	*/

	int result = 1;
	bool flag = true;
	for (int i=0;i<n && flag;++i){
		if (e1[i] && e2[i]){
			if (v1[i] != v2[i]){
				flag = false;
			}
		}
		else if (e1[i] && !e2[i]){
			if (v2[i] < v1[i]){
				flag = false;
			}
		}
		else if (e2[i] && !e1[i]){
			if (v1[i] < v2[i]){
				flag = false;
			}
		}		
		else{
			result = (1LL * result * min(v1[i], v2[i]) ) % mc;
		}
	}

	if (!flag){
		cout << 0;
	}
	else{
		cout << result;
	}

	return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <string>
 
using namespace std;
 
void solve();
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}
 
void solve() {
    int x,a,b;
    cin >> x >> a >> b;
    cout << (x - a) % b << endl;

    

}

Measured memory_bytes: 256
# 二項係数を"やるだけ"にしてくれるライブラリ
MAX = 510000
MOD = 1000000007
factrial = [0]*MAX
inverse = [0]*MAX
factrial_inverse = [0]*MAX


# テーブルを作る前処理
def COMinit():
    global factrial, inverse, factrial_inverse
    factrial[0] = 1
    factrial[1] = 1
    inverse[1] = 1
    factrial_inverse[0] = 1
    factrial_inverse[1] = 1
    for i in range(2, MAX):
        factrial[i] = factrial[i-1] * i % MOD
        inverse[i] = MOD - inverse[MOD % i] * (MOD//i) % MOD
        factrial_inverse[i] = factrial_inverse[i-1] * inverse[i] % MOD


# 二項係数計算
def COM(n, k):
    global factrial, inverse, factrial_inverse
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return factrial[n] * (factrial_inverse[k] * factrial_inverse[n-k] % MOD) % MOD


# 前処理完了
COMinit()

N = int(input())
X = list(map(int, input().split()))
# expected_value = [1]
# for i in range(2, N):
#     expected_value.append(expected_value[-1]+(1/i))
ans = 0
f = factrial[N-1]
c = 0
for i in range(1, N):
    c += f * inverse[i]
    c %= MOD
    ans += c * (X[i] - X[i-1])
    ans %= MOD

print(ans % MOD)


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

int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size()-1;i++){
		if(s.at(i)==s.at(i+1)){
			cout<<"Bad"<<endl;
			return 0;
		}
	}
	cout<<"Good"<<endl;
	return 0;
}


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 s,w;
    cin >> s >> w;
    if(s <= w){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }
}

Measured memory_bytes: 3632
test_list = list()
while True:
    test = list(map(int,input().split()))
    if test == [-1,-1,-1]:
        break
    test_list.append(test)

for test in test_list:
    m = test[0]
    f = test[1]
    r = test[2]
    if m == -1 or f == -1:
        print('F')
    elif m + f >= 80:
        print('A')
    elif m + f >= 65 and m + f < 80:
        print('B')
    elif m + f >= 50 and m + f < 65:
        print('C')
    elif m + f >= 30 and m + f < 50:
        if r >= 50:
            print('C')
        else:
            print('D')
    elif m + f < 30:
        print('F')



Measured memory_bytes: 5600
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C: Base -2 Number
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef vector<int> vi;

/* global variables */

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  if (n == 0) {
    puts("0");
    return 0;
  }

  vi bs;
  while (n) {
    int b = (n & 1);
    bs.push_back(b);
    n = (-(n - b) >> 1);
  }

  for (int i = bs.size() - 1; i >= 0; i--) putchar('0' + bs[i]);
  putchar('\n');
  return 0;
}


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

int p[20][20][2];

int main() {
  int n;
  cin >> n;
  vector<int> alist(n);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    alist[i] = a;
    for (int j = 0; j < a; j++) {
      int x, y;
      cin >> x >> y;
      x--;
      p[i][j][0] = x;
      p[i][j][1] = y;
    }
  }
  vector<int> ans(n, -1);
  int z = 0;
  for (int bit = 0; bit < (1<<n); bit++) {
    for (int i = 0; i < n; i++) {
      ans[i] = -1;
    }
    int tmp = 0;
    bool flag = true;
    for (int i = 0; i < n; i++) {
      if (bit & (1<<i)) {
        ans[i] = 1;
        tmp++;
      }
      else {
        ans[i] = 0;
      }
    }
    for (int i = 0; i < n; i++) {
      if (ans[i] == 1) {
        for (int j = 0; j < alist[i]; j++) {
          if (p[i][j][1] == 0) {
            if (ans[p[i][j][0]] == 1) {
              flag = false;
            }
          }
          else {
            if (ans[p[i][j][0]] == 0) {
              flag = false;
            }
          }
        }
      }
    }
    if (flag) {
      if (z < tmp) {
        z = tmp;
      }
    }
  }
  cout << z << endl;
  return 0;
}

Measured memory_bytes: 256
#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 _LIBCPP_DEBUG 0
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define all(a) (a).begin(),(a),end()
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)	

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(){
	string s;
	cin >> s;

	if (s.at(2) == s.at(3) && s.at(4) == s.at(5)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
} 

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

#define fin stdin
#define fout stdout

int v[109];

inline int calc(int t, int n){
    int ans=0;
    for(int i = 1; i <= n; i ++)
        ans += (t - v[i]) * (t - v[i]);
    return ans;
}

int main(){
    int n;
    fscanf(fin, "%d", &n);

    for(int i = 1; i <= n; i ++)
        fscanf(fin, "%d", &v[i]);

    int best = calc(-100, n);
    for(int i = -99; i <= 100; i ++)
        best = std::min(best, calc(i, n));

    fprintf(fout, "%d\n", best);

    return 0;
}


Measured memory_bytes: 128
n,l = map(int,input().split())

r = []
for i in range(n):
    r.append(i+l)
    
r.sort()

if r[0]>0:
    print(sum(r[1:]))
elif r[-1]<0:
    print(sum(r[:-1]))
else:
    print(sum(r))

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>  // setprecision
// #include <string>
// #include <set>
// #include <algorithm>

using namespace std;
// typedef unsigned long long ull;

void p() {
    cout << "\n";
}
template<class Head, class... Body>
void p(Head head, Body... body) {
    cout << head << ",";
    p(body...);
}

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "[";
    for (const auto i : v) {
        os << i << " ";
    }
    os << "]";
    return os;
}

void p_precise(double v, int d) {
    cout << fixed << setprecision(d) << v;
}


int N;
vector<vector<double>> dist;

double dfs(int city, unsigned int visited) {
    if (city >= 0) {
        visited |= (1 << city);
    }

    double d_sum = 0;
    int visited_count = 0;
    for (int i = 0; i < N; i++) {
        if ((visited >> i) & 1) {
            visited_count += 1;
            continue;
        }
        double d = dfs(i, visited);
        if (city >= 0) {
            d += dist[city][i];
        }
        d_sum += d;
    }

    if (visited_count == N) {
        return 0.0;
    }
    // p("city out", city, " d_sum", d_sum);
    return d_sum / (N - visited_count);
}

double fact(int n) {
    if (n == 0) return 1;
    return n * fact(n-1);
}

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

    vector<int> x(N), y(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
    }

    dist.resize(N);
    for (int i = 0; i < N; i++) {
        dist[i].resize(N);
        for (int j = 0; j < N; j++) {
            dist[i][j] = sqrt(pow((double)x[i] - x[j], 2) + pow((double)y[i] - y[j], 2));
        }
    }

    double ans = dfs(-1, 0);
    p_precise(ans, 10);
    cout << endl;
    
    return 0;
}



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

using namespace std;

int N, K;
int ruisekiwa[1000 * 4 + 10][1000 * 4 + 10][2];

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		int x, y;
		char c;
		cin >> x >> y >> c;
		x %= (2 * K), y %= (2 * K);
		//累積和のために
		x++, y++;
		bool f = false;
		if (c == 'W')f = true;
		ruisekiwa[x][y][f]++;
		ruisekiwa[x + 2 * K][y][f]++;
		ruisekiwa[x][y + 2 * K][f]++;
		ruisekiwa[x + 2 * K][y + 2 * K][f]++;
	}

	//二次元累積和を計算
	for (int wb = 0; wb < 2; wb++) {
		for (int i = 1; i <= 4 * K; i++) {
			for (int j = 0; j <= 4 * K; j++) {
				ruisekiwa[i][j][wb] += ruisekiwa[i - 1][j][wb];
			}
		}
		for (int i = 1; i <= 4 * K; i++) {
			for (int j = 0; j <= 4 * K; j++) {
				ruisekiwa[j][i][wb] += ruisekiwa[j][i - 1][wb];
			}
		}

	}

	int ret = 0;
	for (int i = K; i <= 3 * K; i++) {
		for (int j = K; j <= 3 * K; j++) {
			//W1|B2
			//B1|W2
			int ans = 0;
			//B1
			ans += (ruisekiwa[i][j][0] - ruisekiwa[i][j - K][0] - ruisekiwa[i - K][j][0] + ruisekiwa[i - K][j - K][0]);
			//W1
			ans += (ruisekiwa[i][j + K][1] - ruisekiwa[i][j][1] - ruisekiwa[i - K][j + K][1] + ruisekiwa[i - K][j][1]);
			//B2
			ans += (ruisekiwa[i + K][j + K][0] - ruisekiwa[i + K][j][0] - ruisekiwa[i][j + K][0] + ruisekiwa[i][j][0]);
			//W2
			ans += (ruisekiwa[i + K][j][1] - ruisekiwa[i + K][j - K][1] - ruisekiwa[i][j][1] + ruisekiwa[i][j - K][1]);
			ret = max(ret, ans);
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 125568
#include<iostream>
#include<map>
#include<string>
#include<cstdlib>

int n, d;
std::map<int, int> cnt[2];
std::string s;

int main()
{
	bool f = false;
	while( std::getline( std::cin, s ) )
	{
		if( s == "" )
		{
			f = true;
			continue;
		}

		std::string::size_type i = s.find( "," );
		n = atoi( s.substr( 0, i ).c_str() );
		
		++cnt[f][n];
	}

	for( std::map<int, int>::iterator it = cnt[0].begin(); it != cnt[0].end(); ++it )
	{
		std::map<int, int>::iterator it2 = cnt[1].find( it->first );
		
		if( it2 != cnt[1].end() )
			std::cout << it->first << " " << it->second + it2->second << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1200
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i64,
        b: i64,
    }
    println!("{} {} {}", a/b, a%b, a as f64 / b as f64);
}
//nを入力後ctrl+Z


Measured memory_bytes: 5044