akhauriyash/Code-Regression huggingface dataset:
/* 
   AOJ 1155
   How can I satisfy thee? Let me count the ways...
   2016/5/26
*/

#include<stdio.h>
#define MAX_STR 100
char instr[MAX_STR];
char not[3] = {'2', '1', '0'};
char and[3][3] = {{'0', '0', '0'}, {'0', '1', '1'}, {'0', '1', '2'}};
char or[3][3] = {{'0', '1', '2'}, {'1', '1', '2'}, {'2', '2', '2'}};
int pp, p, q, r;

  

char interpreter(void)
{
  char c = instr[pp];
  switch(c)
    {
    case '0':
    case '1':
    case '2':
      return instr[pp++];
    case 'P':
      pp++;
      return p + '0';
    case 'Q':
      pp++;
      return q + '0';
    case 'R':
      pp++;
      return r + '0';
    case '-':
      pp++;
      return not[interpreter() - '0'];
    case '(':
      pp++;
      char f0 = interpreter();
      char op = instr[pp++];
      char f1 = interpreter();
      pp++;
      if(op == '*')
	return and[f0 - '0'][f1 - '0'];
      else
	return or[f0 - '0'][f1 - '0'];
    }
}

int main(void)
{
  int ans = 0, i;
  while(scanf("%s", instr), instr[0] != '.')
    {
      for(p = 0; p < 3; p++)
	for(q = 0; q < 3; q++)
	  for(r = 0; r < 3; r++)
	    {
	      if(interpreter() == '2')
		ans++;
	      pp = 0;
	    }
      printf("%d\n", ans);
      ans = 0;
      for(i = 0; i < MAX_STR; i++)
	instr[i] = '\0';
    }
  return 0;
}

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

int main(){
  string s1,s2,s3;
  cin >> s1 >> s2 >> s3;
  cout << s1[0] << s2[0] << s3[0] << endl;
}

Measured memory_bytes: 256
// Author :mastermindevil/mdragneell
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define pi  pair< int,int >
#define pl  pair< ll,ll >
#define f first
#define s second
#define endl '\n'
 
 
ll const mod=1e9+7;
ll const N=1e5+5;
ll fact[N];
ll min(ll x,ll y) { if(x < y) return x; else return y; }
ll max(ll x,ll y) { if(x > y) return x; else return y; }
ll gcd(ll x,ll y) { if(x == 0) return (y>0?y:1); else return gcd(y%x,x);}
ll powmod(ll x,ll y){ll res=1;while(y>0){if(y%2==1)res=(res*x)%mod;y>>=1;if(y<=0)break;x=(x*x)%mod;}return res;}
ll factorial () { fact[0]=1; fact[1]=1; for(int i=2;i<N;i++) fact[i]=(fact[i-1]*i)%mod;}ll
 
 
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);}
    size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);}
};
struct compare {
    bool operator()(const pair<ll, ll>& value,  const ll& key){ return (value.first < key); }
    bool operator()(const ll& key, const pair<ll, ll>& value) { return (key < value.first); }
};
 
bool compare1(const pair<ll,ll> &a,const pair<ll,ll> &b)
{   
    if(a.f==b.f)
    {
        if(a.s<=0 && b.s<=0) return (a.s>b.s);
        return (a.s<b.s);
    }
    else if(a.f<=0 && b.f<=0 ) return (a.f > b.f);
    else return (a.f<b.f);
}


int main()
{

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

        

        string s;
        cin>>s;

        deque<char>v;

        for(int i=0;i<s.length();i++)
            v.pb(s[i]);

        ll q;
        cin>>q;

        ll c=0;

        while(q--)
        {
            ll x;
            cin>>x;

            if(x==1)
            {
                c^=1;
                continue;
            }
            else
            {
                char y;
                cin>>x>>y;

                if(c==0){

                    if(x==1)
                        v.push_front(y);
                    else
                        v.pb(y);
                }
                else
                {
                    if(x==2)
                        v.push_front(y);
                    else
                        v.pb(y);

                }


            }
        }

        if(c)
            reverse(v.begin(),v.end());

        for(auto it:v)
            cout<<it;


}

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

int main(){
  long long int n; cin >> n;
  vector<char> ans;
  --n;
  while(n >= 0){
    ans.push_back('a'+n%26);
    n /= 26ll;
    --n;
  }
  reverse(ans.begin() , ans.end());
  for(auto it : ans)
    cout << it;
  cout << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <iomanip>
#include <math.h>
#include <fstream>

using namespace std;

class pqComp
{
public:
    bool operator()(pair<int, int> &a, pair<int, int> &b)
    {
        return a.second < b.second;
    }
};

bool sorting(pair<int, int> a, pair<int, int> b)
{
    return a.second < b.second;
}

int main()
{
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cin.tie();
    cout.tie();
    // ifstream cin("in.txt");
    // ofstream cout("out.txt");
    
    
    // int t;
    // cin >> t;
    // for (int qwe = 0; qwe < t; qwe++)
    // {
    //     cout << "Case #" << qwe + 1 << ": ";
    // }


    int n;
    cin >> n;
    string s;
    vector<pair<int, int>> v, v1;
    int total = 0;
    for (int i = 0; i < n; i++)
    {
        int x = 0, y = 0, z = 0;
        cin >> s;
        for (int j = 0; j < s.size(); j++)
        {
            if (s[j] == '(')
            {
                x++;
            }
            else
            {
                x--;
                y = min(y, x);
            }
        }
        total += x;
        if (x >= 0)
        {
            v.push_back({ x, y });
        }
        else
        {
            x = 0;
            for (int j = 0; j < s.size(); j++)
            {
                if (s[s.size() - j - 1] == ')')
                {
                    x++;
                }
                else
                {
                    x--;
                    z = min(x, z);
                }
            }
            v1.push_back({ x, z });
        }
    }
    if (total != 0)
    {
        cout << "No\n";
        return 0;
    }
    sort(v.rbegin(), v.rend());
    priority_queue<pair<int, int>, vector<pair<int, int>>, pqComp> pq;
    int curr = 0;
    for (int i = 0; i < v.size(); i++)
    {
        pq.push(v[i]);
        while (!pq.empty() && pq.top().second + curr >= 0)
        {
            curr += pq.top().first;
            pq.pop();
        }
    }
    if (!pq.empty())
    {
        cout << "No\n";
        return 0;
    }
    sort(v1.rbegin(), v1.rend());
    int curr1 = 0;
    for (int i = 0; i < v1.size(); i++)
    {
        pq.push(v1[i]);
        while (!pq.empty() && pq.top().second + curr1 >= 0)
        {
            curr1 += pq.top().first;
            pq.pop();
        }
    }
    if (!pq.empty())
    {
        cout << "No\n";
        return 0;
    }
    cout << "Yes\n";


    return 0;
}


Measured memory_bytes: 10916
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
l=[]
for i in range(n):
 for j in range(a[i]):
  l.append(i+1)
for i in range(h):
 c=l[i*w:i*w+w]
 if i%2==0:
  print(*c)
 else:
  print(*c[::-1])

Measured memory_bytes: 3884
/**
*    created: 30.05.2020 20:59:22
**/
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

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

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

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
#define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb(x) push_back(x)
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp()//true for a before b
{
	bool ans = 0;
	return ans;
}

const int N = (2e5) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 650;

int a[N], b[N], p2[30], tempa[N], tempb[N], cnta, cntb, presum[N];

int binsea(int l, int r, int val)
{
	if(l > r)
		return 0;
	int mid = (l+r)>>1;
	if(tempb[mid] < val)
		return max(mid, binsea(mid+1,r,val));
	return binsea(l,mid-1,val);
}

int cnt_bits(int l, int r)
{
	if(l > r)
		return 0;
	return (presum[r]-presum[l-1]);
}

int cnt_not_bits(int l, int r)
{
	if(l > r)
		return 0;
	return (r-l+1-cnt_bits(l,r));
}

bool func(int n, int ind)
{
	int i, ans = 0, j;
	fo(i,1,n+1)
	{
		tempa[i] = a[i]%p2[ind];
		tempb[i] = b[i]%p2[ind];
		presum[i] = presum[i-1];
		if(b[i]&p2[ind])
			presum[i]++;
	}
	sort(tempb+1,tempb+n+1);
	fo(i,1,n+1)
	{
		j = binsea(1,n,p2[ind]-tempa[i]);
		if(a[i]&p2[ind])
			ans = (ans + cnt_not_bits(1,j) + cnt_bits(j+1,n))&1;
		else
			ans = (ans + cnt_bits(1,j) + cnt_not_bits(j+1,n))&1;
	}
	return (ans&1);
}

void solve()
{
	int n, ans = 0, i, x0, x1, y0, y1;
	p2[0] = 1;
	fo(i,1,30)
		p2[i] = p2[i-1]<<1;
	cin >> n;
	fo(i,1,n+1)
		cin >> a[i];
	fo(i,1,n+1)
		cin >> b[i];
	cnta = cntb = 0;
	fo(i,1,n+1)
	{
		if(a[i]&1)
			cnta++;
		if(b[i]&1)
			cntb++;
	}
	x1 = cnta&1;
	y1 = cntb&1;
	x0 = (n-cnta)&1;
	y0 = (n-cntb)&1;
	if((x1*y0 + x0*y1) % 2 == 1)
		ans++;
	fo(i,1,29)
		if(func(n,i))
			ans += p2[i];
	cout << ans;
	return;
}

int main()
{
	sws;
	// clock_t clk;
	// clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1;
	// cout << fixed << setprecision(9);
	// cin >> t;
	while(t--)
		solve();
	// Code ends here

	// clk = clock() - clk;
	// cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int A[3];
    REP(i, 3) cin >> A[i];
    sort(A, A + 3);
    cout << A[2] - A[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
typedef long long int ll;

void input(){
   int n, q;
   cin >> n >> q;
   vector<int>adj[n];
   f(i, n - 1){
     int s, d;
     cin >> s >> d;
     --s; --d;
     adj[s].pb(d);
     adj[d].pb(s);
   }
   vector<int>val(n, 0);
   while(q--){
    int p, x; cin >> p >> x; --p;
    val[p] += x;
   }
   vector<int>ans(n);
   function<void(int, int,int)> dfs = [&](int u, int p, int prev){
      ans[u] = prev + val[u];
      for(auto &it: adj[u]){
        int v = it;
        if(v == p)continue;
        dfs(v, u, prev + val[u]);
      }
   };
   dfs(0, -1, 0);
   for(auto &it : ans)cout << it << " ";cout <<"\n";
}
int main()
{
 input();
 return 0;
}


Measured memory_bytes: 33664
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
const ll N = 300030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;

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

int a,b;
cin>>a>>b;
int z=a^b;
cout<<z;

}

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

const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int n;
	cin >> n;
	string ans = "No";
	REP(i,10) REP(j,10) if(i*j==n) ans = "Yes";
  cout << ans << endl;
}


Measured memory_bytes: 3632
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();
            var strs = str.Split(' ');

            var a = int.Parse(strs[0]);
            var b = int.Parse(strs[1]);

            if (b % a == 0)
            {
                Console.WriteLine(a + b);
            }
            else
            {
                Console.WriteLine(b - a);
            }
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n;
int a[1000100];

int main(){
	ll ans = 0;
	cin >> n;
	REP(i, n){
		cin >> a[i];
	}
	REP(i, n){
		if (a[i] % 2 == 1){
			if (a[i + 1] != 0){
				a[i + 1]--;
				a[i]++;
			}
		}
	}
	REP(i, n){
		ans += a[i] / 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
/*
    @uthor: Amit Kumar
    user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define ll    long long
#define ld    long double
#define ull   unsigned long long
#define all(vec) vec.begin(),vec.end()
#define endl "\n"
ll google_itr = 1;
#define google(x) cout<<"Case #"<<x<<":"
#define pi 3.14159265358979323846264338327950L

const ll mod = 1e9+7;
const ll inf = 1e18;


void virus(){
          ll a;
          cin>>a;
          (a == 0)? cout<<"1\n":cout<<"0\n";
}


int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

    ll t = 1;
    //cin>>t;
    while(t--){
           auto start = high_resolution_clock::now();
           virus();
           auto stop = high_resolution_clock::now();
           auto duration = duration_cast<seconds>(stop - start);
           cerr << "\n Time: "<<duration.count()<<endl;
        //your code goes here
    }
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>

using namespace std;

int main() {
    int ways, n, x;
    while (1) {
        ways = 0;
        scanf("%d %d", &n, &x);
        if (n == 0 && x == 0) break;

        for (int i = 1; i <= n - 2; ++i) {
            for (int j = i + 1; j <= n - 1; ++j) {
                for (int k = j + 1; k <= n; ++k) {
                    if (i + j + k == x) {
                        ++ways;
                        break;
                    }
                }
            }
        }

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


Measured memory_bytes: 2744
using System;
using System.Text;
class aoj{
	static void Main(){
		string a=Console.ReadLine();
		StringBuilder sb=new StringBuilder(a);
		for(int i=0;i<a.Length-4;i++){
			string b=a.Substring(i,5);
			if(b=="apple")
				sb.Replace("apple","peach",i,5);
			else if(b=="peach")
				sb.Replace("peach","apple",i,5);
		}
		Console.WriteLine(sb);
	}
}

Measured memory_bytes: 8656
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int K = stdIn.nextInt();
		int A = stdIn.nextInt();
		int B = stdIn.nextInt();
		
		int ans = K;
		
		for(int i = 1; ; i++) {
			if(A <= ans) {
				break;
			}else {
				ans += K;
			}
		}
		
		if(ans <= B) {
			System.out.println("OK");
		}else {
			System.out.println("NG");
		}
	}

}

Measured memory_bytes: 35808
#include <cstdio>
#include <iostream>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <set>
#include <cstdlib>
#define INT long long
using namespace std;

int n, k, ans;
int main()
{
    cin>>n>>k;
    ans = k;
    for(int i = 1 ; i < n ; i++ )
        ans *= k-1;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include <algorithm>
using namespace::std;
int main(){
 
int count;
cin>>count;

int *N =new int[count];
		
for(int i=0;i<count;i++){
	cin>>N[i];
}
int T;
int Fs=0;
int Ls=0;
int min=256*256*256-1;
int p;
for(int i=1;i<count-1;i++){
T=i;


for(int x=0;x<=T;x++){
Fs=Fs+N[x]; 	
}
for(int y=T+1;y<count;y++){
Ls=Ls+N[y];
}
p=abs(Fs-Ls);

if(p<min){
min=p;
}
Fs=0;
Ls=0;
}
cout<<min;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int siz=1e5;
const long inf=1e9;
int main(){
	long A,V,B,W,T; cin>>A>>V>>B>>W>>T;
	if(V <= W) cout<<"NO"<<endl;
	else if((V-W)*T < abs(A-B)) cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

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;}

const ll mod = 1000000007;
const int INF = 1<<29;

double sum_n(int n){
  return n * (n + 1) / 2;
}
int main(){
  int N, K; cin >> N >> K;
  vector<int> p(N);
  rep(i, N) cin >> p[i];

  //それぞれの期待値
  vector<double> x(N);
  rep(i, N) x[i] = sum_n(p[i]) / p[i];
  //期待値の累積和
  vector<double> s(N + 1, 0);
  rep(i, N) s[i + 1] = s[i] + x[i];

  double res = 0;
  for (int i = 0; i < N; ++i){
    if (i + K >= N + 1) break;
    res = max(res, s[i + K] - s[i]);
  }
  printf("%.8f\n", res);
}


Measured memory_bytes: 4096
fun main(args: Array<String>) {
    var a = mutableListOf<String>()
    val (n,l) = readLine()!!.split(" ").map(String::toInt)
    for (i in 0 until n){
        a.add(readLine()!!.toString())
    }
    println(a.sorted().reduce{x, y -> x + y})
}

Measured memory_bytes: 40592
#include <iostream>

using namespace std;

int main() {
  int n, c[25], v[25], ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> v[i];
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    if (v[i] - c[i] > 0)
      ans += v[i] - c[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
   
  int i, j, n, s, t, u, G[101][101] = {{},{}};
 
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d%d", &s, &t);
    for(j = 0; j < t; j++){
      scanf("%d", &u);
      G[s][u] = 1;
    }
  }
   
  for(i = 1; i <= n; i++){
    for(j = 1; j <= n; j++){
      if(j != 1) printf(" ");
      printf("%d",G[i][j]);
    }
    printf("\n");
  }
  return 0;
}

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

const int DIM = 1e2 + 5;

int cnt[DIM];

int main( void ) {
    
    int n;
    cin >> n;
    
    for( int i = 1; i <= n; i ++ ) {
        int x;
        cin >> x;
        
        cnt[x] ++;
    }
    
    int mxm = n;
    while( cnt[mxm] == 0 )
        mxm --;
    
    bool ok = true;
    if( (mxm + 1) % 2 == 1 ) {
        if( cnt[mxm / 2] != 1 )
            ok = false;
        
        for( int i = mxm / 2 + 1; i <= mxm; i ++ ) {
            if( cnt[i] <= 1 )
                ok = false;
        }
        
        for( int i = 1; i <= mxm / 2 - 1; i ++ ) {
            if( cnt[i] >= 1 )
                ok = false;
        }
    }
    else {
        if( cnt[(mxm + 1) / 2] != 2 )
            ok = false;
        
        for( int i = (mxm + 1) / 2 + 1; i <= mxm; i ++ ) {
            if( cnt[i] <= 1 )
                ok = false;
        }
        
        for( int i = 1; i <= mxm / 2; i ++ ) {
            if( cnt[i] >= 1 )
                ok = false;
        }
    }
    
    cout << ( (ok == true) ? "Possible" : "Impossible" ) << endl;
    return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.rbegin(), a.rend());
  int t = n, idx = 0;
  ll ans = 0;
  bool one = true;
  while (t-- > 0) {
    ans += a[idx];
    one ^= 1;
    if (one) ++idx;
  }
  cout << ans-a[0] << endl;
}

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

int main() 
{

  int N,M;
  cin>>N>>M;
  
  vector<bool> AC(N,false);
  vector<int> WA(N,false);
  int penalty=0;
  int correct=0;
  for(int i=0;i<M;i++){
    int Pi;
    string Si;
    cin>>Pi>>Si;
    
    if(Si=="AC"&&AC.at(Pi-1)==false){
	  AC.at(Pi-1)=true;
      correct++;
      penalty+=WA.at(Pi-1);
    }
    else if(Si=="WA"&&AC.at(Pi-1)==false)
      WA.at(Pi-1)++;
  }
  
  cout<<correct<<" "<<penalty<<endl;
  
    return 0;
}

Measured memory_bytes: 640
module Memoizable
	def memoize(name)
		original = "__original_#{name}__"
		([Class, Module].include?(self.class) ? self : self.class).class_eval {
			alias_method(original, name)
			private(original)
			cache = {}
			define_method(name){|*args|
				cache[args] ||= send(original, *args)
			}
		}
	end 
end

include Memoizable

def f(a, b)
	return 0 if a.empty?
	d = b[0] - a[0]
	return f(a[1..-1], b[1..-1]) if d == 0
	min = Float::INFINITY
	(0..a.size-1).each do |i|
		c = a[0..i].map {|x| (x + d) % 10} + a[i+1..-1]
		r = f(c, b)
		min = r if r < min
	end
	min + 1
end

memoize :f

loop do
	n = gets.to_i
	break if n == 0
	x, y = gets.chomp.split
	p f(*[x, y].map{|s| s.split("").map(&:to_i)})
end

Measured memory_bytes: 34100
//package com.karancp;

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.InputStream;


 class Main {
    public static void main(String args[])
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader z = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        task solver =new task();
        solver.solve(z,out);
        out.close();
    }

    static class task
    {

        static long gcd(long a,long b)
        {
            if(b==0)return a;
            else return gcd(b,a%b);
        }
        static long lcm(long a,long b)
        {
            long pp=a*b;
            long bb=gcd(a,b);
            long res =pp/bb;
            return res;
        }
        static int max(int a,int b)
        {
            return Math.max(a,b);
        }
        static int min(int a,int b)
        {
            return Math.min(a,b);
        }





        public static void solve(InputReader z, PrintWriter out) {
           int n=z.nextInt();
           int k=z.nextInt();
           char ar[]=z.next().toCharArray();
           ar[k-1]=(char)(ar[k-1]+32);
           int i;
           for(i=0;i<n;i++)out.print(ar[i]);
        }
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }

    }



}

Measured memory_bytes: 22868
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())

LL C[2020][2020];
const LL MOD = 1000000007;

void makepas(){
  MSET(C, 0);
  REP(i, 2020){
    C[i][0] = C[i][i] = 1;
    for(int j = 1; j < i; j++) C[i][j] = (C[i-1][j-1] + C[i-1][j]) % MOD;
  }
}

int n, k;

void solve() {
  makepas();
  cin >> n  >> k;
  FOR(i, 1, k+1) {
    cout << C[n-k+1][i] * C[k-1][i-1] % MOD << endl;
  }
}

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


Measured memory_bytes: 32128
"""
マッピングに配列を使った場合、配列の大きさが大きすぎて無駄が多かったから
辞書型に変更。
"""
n, m = map(int, input().split())
a = list(map(int, input().split()))

num_map = dict()
for i in range(n):
    num = a[i]
    if num not in num_map:
        num_map[num] = 1
    else:
        num_map[num] += 1

for i in range(m):
    card_num, num = map(int, input().split())
    if num not in num_map:
        num_map[num] = card_num
    else:
        num_map[num] += card_num

num_map_list = list(num_map.keys())
num_map_list.sort(reverse=True)

rest_card = n
res_sum = 0
for i in range(len(num_map_list)):
    num = num_map_list[i]
    some_num = num_map[num]
    can_use = min(some_num, rest_card)
    rest_card -= can_use
    res_sum += num * can_use

    if rest_card == 0:
        break

print(res_sum)



Measured memory_bytes: 34444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  long long h,w,n,cnt=0;
  cin >> h >> w >> n;
  long long x[n],y[n],ans=h;
  pair<long long, long long> p[n];
  for(int i=0;i<n;i++){
    cin >> x[i] >> y[i];
    p[i]=make_pair(x[i], y[i]);
  }
  sort(p,p+n);
  map<pair<ll, ll> ,int> mp;
  for(int i=0;i<n;i++){
    if(p[i].first-cnt==p[i].second){
      cnt++;
    }else if(p[i].first-cnt>p[i].second){
      if(mp[{p[i].first-1ll, p[i].second-1ll}]==0){
        ans=min(ans, p[i].first-1);
      }
    }
    mp[{p[i].first, p[i].second}]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 21120
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    //fast_io();

    int N, K; std::cin >> N >> K;
    std::vector<int> A;
    for(int i=0; i<N; i++){
        int b; std::cin >> b; A.push_back(b);
    }

    for(int k=0; k<K; k++){
        std::vector<int> B(N,0);
        for(int i=0; i<N; i++){
            int l=std::max(0,i-A[i]), r=std::min(N-1,i+A[i]);
            B[l]++;
            if(r+1<N) B[r+1]--;
        }
        for(int i=1; i<N; i++) B[i] += B[i-1];
        if(A == B){
            break;
        }else{
            A = B;
        }
    }

    for(int i=0; i<N; i++){
        std::cout << A[i] << " ";
    }
    return 0;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    int k,a,b;cin>>k>>a>>b;

    repa(i,a,b+1){
        if(i%k==0){
            cout<<"OK\n";
            return 0;
        }
    }

    cout<<"NG\n";

    return 0;

}

Measured memory_bytes: 3636
import sys
input = sys.stdin.readline

x,y = map(int,input().split())
if y>4*x or y<2*x:
    print('No')
    sys.exit()
if y == 2*x or y == 4*x:
    print('Yes')
    sys.exit()
if y%2==0:
    print('Yes')
    sys.exit()
else:
    print('No')
    sys.exit()


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

int darks[16];
int edges[110][110];
int dp[1<<16];
int darksinv[110];

int main() {
    int n,m,k;

    cin >> n >> m >> k;
    for (int i=0; i<m; i++) { cin >> darks[i]; darks[i]--; }
    for (int i=0; i<n; i++) for (int j=0; j<k; j++) { cin >> edges[i][j]; edges[i][j]--; }

    // darks inverse
    for (int i=0; i<n; i++) darksinv[i] = -1;
    for (int i=0; i<m; i++) darksinv[darks[i]] = i;

    for (int i=0; i<(1<<m); i++) dp[i] = -1;
    dp[ (1<<m) - 1] = 0;
    queue<pair<int, int> > q;
    q.push( make_pair( (1<<m) - 1, 0 ) );

    int ans = -1;
    while (!q.empty()) {
        pair<int,int> p = q.front(); q.pop();
        int state = p.first;
        int cost  = p.second;

        for (int i=0; i<k; i++) {
            int next_state = 0;
            for (int j=0; j<m; j++) {
                if (!(state & (1<<j))) continue;
                if (darksinv[edges[darks[j]][i]] != -1) {
                    next_state |= (1 << darksinv[edges[darks[j]][i]]);
                }
            }
            if (next_state == 0) {
                ans = cost + 1;
                break;
            }
            if (dp[next_state] == -1) {
                dp[next_state] = cost + 1;
                q.push( make_pair(next_state, cost + 1) );
            }
        }

        if (ans != -1) break;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3540
// Problem : B - Multiplication 2
// Contest : AtCoder - AtCoder Beginner Contest 169
// URL : https://atcoder.jp/contests/abc169/tasks/abc169_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using namespace std;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define nl cout<<"\n"
#define endl "\n"
#define all(c) (c).begin(),(c).end()
#define trav(a,x) for(auto a = x.begin() ; a != x.end() ; a++)
#define rep(i,n) for(ull (i) = 0 ; i < (n) ; i++)
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
typedef long long ll;
typedef unsigned long long ull ;
typedef long double ld;
inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b) {if(b==0) return a;a%=b;return gcd(b,a);}
ll power(ll x, ll y) { if (y == 0) return 1;  ll a = power(x,y/2);if (y % 2 == 0) return a * a; else return x * a * a; }
ll powermod(ll x, ll ex , ll md) {ll ans = 1ll;while (ex > 0) {    if (ex & 1ll) ans = (ans * x) % md;    ex >>= 1ll;x = (x * x) % md;}return ans;}
const ll inf = 1e18 + 9;
const ll mod = 1e9 + 7;
const long double eps = 1e-9;
const ll N = 1e6 + 1;
const ull b = power(10 , 18);
void solve(){
	int n;
	cin >> n;
	ull p = 1;
	ull a[n] = {0};
	bool flag = 1;
	for(int i =0 ; i < n ; i++) {
		cin >>a[i];
		if(a[i] > b) flag = 0;
	}
	sort(a , a + n);
	if(a[0] == 0) {
		cout << 0 << endl;
		return ;
	}
	if(flag){
		for(int i =0 ; i < n ; i++){
			if(a[i] > (b)/p){
				flag = 0;
				break ;
			}
			p =p*a[i];
			if(p > b){
				flag = 0;
				break;
			}
	
		}
	}
	if(flag == 0) cout << -1 << endl;
	else cout << p << endl;
}
int main(){
    IOS;
    cout<<fixed<<setprecision(20);
    ll T=1;
    // cin>>T;
    ll t=0;
    while(t++<T){
        // cout<<"Case #"<<t<<":"<<' ';
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 4588
import sys
from pprint import pprint

def solve(n, a):
    pre = 0
    count = 0
    for a_i in a:
        if a_i == pre + 1:
            pre = a_i
            count += 1

    if count == 0:
        print(-1)
    else:
        print(n - count)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    a = map(int, sys.stdin.readline().strip().split(" "))
    
    solve(n, a)

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


int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  int N; cin >> N;
  string S, T; cin >> S >> T;
  for (int i = 0; i < N; i++) {
    cout << S.at(i) << T.at(i);
  }
  cout << endl;

  return 0;
}



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



int main() {
  int d, s, t;
  cin >> d >> s >> t;
  string ans = "No";
  if((d+s-1)/s <= t) ans="Yes";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3592
//-------------
//include
//-------------
#include <map>
#include <list>
#include <cmath>
#include <vector>
#include <string>
#include <cctype>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
//-------------
//typedef
//-------------
typedef  long long LL;
typedef  vector<int> VI;
typedef  string STR;
typedef  pair<int, int> PII;
typedef  vector<int, int> VII;
typedef  map<string, int> MSI;
//-------------
//utillty
//-------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MK make_pair
#define PB push_back
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(a) cout<<a<<endl
//-------------
//repetition
//-------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//-------------
//debug
//-------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumpl(c) REP(i,SZ(c))cerr<<#c<<i<<"="<<(c[i])<<endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const int MOD = 1000000007;
int main()
{
	int x;
	cin >> x;
	COUT(x*x*x);
#ifdef _DEBUG
	while (1);
#endif // _DEBUG

	return 0;
}

Measured memory_bytes: 3052
#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-1; i >= 0; i--)
#define all(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
const int mod = 1e9+7;

int main() {
    int n, T;
    cin >> n >> T;
    int t[n];
    rep(i, n) {
        cin >> t[i];
    }
    ll ans = 0;
    rep(i, n) {
        if (i+1 < n) {
            ans += min(T, t[i+1] - t[i]);
        } else {
            ans += T;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4248
import heapq


class UnionFind:
    from collections import deque

    def __init__(self, v):
        self.v = v
        self._tree = list(range(v + 1))

    def _root(self, a):
        queue = self.deque()
        while self._tree[a] != a:
            queue.append(a)
            a = self._tree[a]
        while queue:
            index = queue.popleft()
            self._tree[index] = a
        return a

    def union(self, a, b):
        root_a = self._root(a)
        root_b = self._root(b)
        self._tree[root_b] = root_a

    def find(self, a, b):
        return self._root(a) == self._root(b)


N = int(input())
V = []
for i in range(N):
    s, t = map(int, input().split(' '))
    V.append((i, s, t))

E = []
vx = sorted(V, key=lambda v: v[1])
for v1, v2 in zip(vx, vx[1:]):
    i, x1, y1 = v1
    j, x2, y2 = v2
    heapq.heappush(E, (abs(x1 - x2), i, j))

vy = sorted(V, key=lambda v: v[2])
for v1, v2 in zip(vy, vy[1:]):
    i, x1, y1 = v1
    j, x2, y2 = v2
    heapq.heappush(E, (abs(y1 - y2), i, j))

uf = UnionFind(N)
cost = 0
while E:
    c, i, j = heapq.heappop(E)
    if not uf.find(i, j):
        uf.union(i, j)
        cost += c

print(cost)


Measured memory_bytes: 50096
N,M=map(int,input().split())
PY=list(list(map(int,input().split()))+[i] for i in range(M))
PY.sort(key=lambda x:x[1])
PY.sort(key=lambda x:x[0])
for j,J in enumerate(PY):
    if j!=0 and PY[j-1][0]==PY[j][0]:
        PY[j].append(PY[j-1][3]+1)
    elif j!=0 and PY[j-1][0]!=PY[j][0]:
        PY[j].append(1)
    else:
        PY[j].append(1)
PY.sort(key=lambda x :x[2])
for k in range(M):
    print('{0:06d}{1:06d}'.format(PY[k][0],PY[k][3]))


Measured memory_bytes: 31352
N,M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))
mod = 10**9+7

dp = [[0]*(M+1) for i in range(N+1)]
for n in range(N):
    for m in range(M):
        if S[n] == T[m]:
            dp[n+1][m+1] = dp[n+1][m]+dp[n][m+1]+1
        else:
            dp[n+1][m+1] = dp[n+1][m]+dp[n][m+1]-dp[n][m]
        dp[n+1][m+1] %= mod

print(dp[-1][-1]+1)


Measured memory_bytes: 98696
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;
const int BG = 1000000007;

int main()
{
    int N;
    cin >> N;
    cout << "ABC" << N << endl;
}


Measured memory_bytes: 256
import math
def S(a,b,c):
	s = (a+b+c)/2
	return math.sqrt(s*(s-a)*(s-b)*(s-c))
	
while True:
	try:
		x1,y1,x2,y2,x3,y3,xp,yp = map(float, raw_input().split())
		a = math.sqrt((x1-x2)**2+(y1-y2)**2)
		b = math.sqrt((x1-x3)**2+(y1-y3)**2)
		c = math.sqrt((x2-x3)**2+(y2-y3)**2)
		xa = math.sqrt((x3-xp)**2+(y3-yp)**2)
		xb = math.sqrt((x2-xp)**2+(y2-yp)**2)
		xc = math.sqrt((x1-xp)**2+(y1-yp)**2)
		if S(a,xb,xc)+S(b,xc,xa)+S(c,xa,xb)-S(a,b,c) > 0.0000001:
			print "NO"
		else:
			print "YES"
	except:
		break

Measured memory_bytes: 4444
#include<stdio.h>

int map[50][50];
int x[8] = {1,0,-1,0,1,-1,-1,1};
int y[8] = {1,1,-1,-1,0,1,0,-1};
int w,h;


void land(int a,int b){
  int i;
  for(i=0;i<8;i++){
    if(a+x[i]<h && a+x[i]>=0 && b+y[i]<w && b+y[i]>=0){
      if(map[a+x[i]][b+y[i]]){
	map[a+x[i]][b+y[i]]=0;
	land(a+x[i],b+y[i]);
      }
    }
  }
}

int main(void)
{

  int i,j;
  int count;
    
  while(1){
    scanf("%d %d",&w,&h);
    if(!w && !h)break;

    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	scanf("%d ",&map[i][j]);
      }
    }

    count = 0;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if(map[i][j]){
	  map[i][j] = 0;
	  count++;
	  land(i,j);
	}
      }
    }

    printf("%d\n",count);
  }
  return 0;
}

Measured memory_bytes: 0
from sys import stdin
N=int(stdin.readline().rstrip())
data=[]
for i in range(N):
    data.append([(x) for x in stdin.readline().rstrip().split()])

ans=0.0
for j in data:
    if j[1] == "BTC":
        ans+=(float(j[0])*380000.0)
    else:
        ans+=float(j[0])
print(ans)

Measured memory_bytes: 3060
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
#define LL long long 
const int MaxN = 1e5 + 7;
LL a[MaxN], b[MaxN];  
LL x[MaxN], v[MaxN];

int main()
{
	LL n, c;
	scanf("%lld %lld", &n, &c);
	for(int i = 1; i <= n; i++) 
		scanf("%lld %lld", &x[i], &v[i]);
	
	for(LL i = 1; i <= n; i++) 
		a[i] = a[i - 1] + v[i] - (x[i] - x[i - 1]);  // 顺时针走到i点时的能量
	x[n + 1] = c;
	for(LL i = n; i >= 1; i--) 
		b[i] = b[i + 1] + v[i] - (x[i+1] - x[i]);  // 逆时针走到i点时的能量

	for(LL i = 2; i <= n; i++) 
		a[i] = max(a[i-1], a[i]);  //走或者不走（和走之前的值进行比较）
	for(LL i = n-1; i >= 1; i--) 
		b[i] = max(b[i], b[i + 1]);

	LL ans = 0;
	for(LL i = 1; i <= n; i++) {
		ans = max(ans, a[i] - x[i] + b[i + 1]);  // 顺时针走后并返回一次的值
		ans = max(ans, b[i] - (c - x[i]) + a[i - 1]);  // 逆时针走后返回一次的值
		ans = max(ans, a[i]);  // 顺时针的最大值
		ans = max(ans, b[i]); //逆时针的最大值
	}

	printf("%lld\n", ans);
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

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

    int n;
    cin >> n;

    int p[4] = {};
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        p[a % 4]++;
    }
    p[1] += p[3];

    bool b = p[0] * 2 + p[2] >= n;
    if (p[2] <= 1) b = p[0] * 2 + 1 >= n;
    if (p[0] == 0) b = p[2] == n;
    cout << (b ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    if (args.length > 0 && args(0) == "TEST") {
      println(test())
    } else {
      val input = io.Source.stdin.getLines().mkString("\n")
      println(solve(input).trim())
    }
  }

  def solve(input: String): String = {
    val sc: Scanner = new Scanner(input)
    val k, s = sc.nextInt
    var cnt = 0
    for (x <- 0 to k if x <= s;
         y <- 0 to k if x + y <= s) {
      if (s - (x + y) <= k) cnt += 1
    }
    cnt.toString
  }

  val tests = List(
    """2 2""".stripMargin -> """6""",
    """5 15""".stripMargin -> """1"""
  )

  def test(): String = tests.map { case (i, o) => (i.trim(), o.trim()) }
    .zipWithIndex.map {
    case ((input, outputExpect), i) =>
      val output = solve(input).trim()
      val tnum = i + 1
      s"test$tnum:" + (
        if (output == outputExpect) "Passed"
        else s"Failed\nexpect:\n$outputExpect\noutput:\n$output")
  }
    .mkString("\n")
}

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

using namespace std;

const int NMAX = 7368792;

int main() {
  int n, m;
  while (true) {
    cin >> m >> n;
    if (m == 0 && n == 0) break;
    vector<bool> primes(NMAX, false);
    int id = m;
    while (n--) {
      while (primes[id]) id++;
      for (int j = id; j <= NMAX; j += id) primes[j] = true;
    }
    while (primes[id]) id++;
    cout << id << endl;
  }

  return 0;
}


Measured memory_bytes: 3976
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n, m;
vvi to;
vi deg;
int dp[100100]; // 各頂点の入次数

int main () {
  cin >> n >> m;
  to = vvi(n,vi());
  deg = vi(n,0);
  rep(i,m) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    to[x].pb(y);
    deg[y]++;
  }

  queue<int> q;
  rep(v,n)  if (deg[v] == 0) q.push(v);

  // BFS
  while (!q.empty()) {
    int v = q.front(); q.pop();
    for (auto nv : to[v]) {
      deg[nv]--; // エッジ(v,nv)を破壊する
      if (deg[nv] == 0) {
        q.push(nv); // それによって入次数が0になったならキューに突っ込む
        chmax(dp[nv], dp[v]+1); // さらにソースからnvまでの最長距離が確定する
      }
    }
  }

  int ans = 0;
  rep(v,n) chmax(ans, dp[v]);
  cout << ans << endl;
  return 0;
}

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

int main()
{
    int n;
    string s;
    int j = 0;
    int a = 0, b = 0;
    cin >> s;
    n = s.length();
    for(int i = 0; i < n; i++){
        if(s[i] == '0'){
            a++;
        }else{
            b++;
        }
    }
    if(a == b){
        cout << a*2;
    }else if(a < b){
        cout << a*2; 
    }else{
        cout << b*2;
    }
    
    return 0;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<char> c(N);
    for (int i = 0; i < N; ++i) {
        cin >> c[i];
    }
    int W = 0;
    for (int i = 0; i < N; ++i) {
        if (c[i] == 'W') {
            ++W;
        }
    }
    int ans = 0;
    for (int i = 0; i < W; ++i) {
        if (c[N - 1 - i] != 'W') {
            ++ans;
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3644