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

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

struct E{
	int u,v,w;

	E() = default;
	E(int u_, int v_, int w_):u(u_),v(v_),w(w_){}

	E rev(){return E(v, u, w);}

	bool operator<(const E& rhs)const{
		return w == rhs.w ? u == rhs.u ? v < rhs.v : u < rhs.u : w < rhs.w;
	}
};

struct UF{
	vector<int> par;
	UF(size_t n): par(n,-1){}
	bool unite(int x, int y){
		x = root(x), y = root(y);
		if(x != y){
			if(par[y] < par[x]) swap(x,y);
			par[x] += par[y]; par[y] = x;
		}
		return x != y;
	}
	bool isSame(int x, int y){
		return root(x) == root(y);
	}

	int root(int x){
		if(par[x] < 0)return x;
		par[x] = root(par[x]);
		return par[x];
	}
	int size(int x){
		return -par[root(x)];
	}
	int rootnum(){
		int ret = 0;
		for(auto e : par){
			if(e < 0)ret += 1;
		}
		return ret;
	}
	void print(){
		for(auto e : par)cerr << e << " ";
		cerr << endl;
	}
};

signed main(){
	int n,m; cin >> n >> m;
	vector<vector<E>> adj(n+1);
	for(int i = 0; i < m; i++){
		E tmp;
		cin >> tmp.u >> tmp.v >> tmp.w;
		adj[tmp.u].push_back(tmp);
		adj[tmp.v].push_back(tmp.rev());
	}
	UF uf(n+1);
	for(auto a : adj)for(auto e : a){
		uf.unite(e.u, e.v);
	}
	for(int i = 1; i <= n; i++)
		uf.root(i);
	cout << (uf.rootnum()-1) << endl;




	return 0;
}



Measured memory_bytes: 8500
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N, X,R,S,P,A;
  cin >> N;
  P = N;
  S=0;
for(int i=0; i < 8; i++){
    R=1;
  for(int r=1; r<8-i; r++){
    R *=10; }
  X = P/R;
  S = S+X;
  P -= X*R;
}
  A = N/S;
if(A*S==N){
  cout << "Yes" << endl;
}
  else{
    cout << "No" << endl;
  }
}

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

// clang-format off
using ll = long long;
#define forn(i, N) for (int i = 0; i < N; i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// clang-format on

const long long INF = 1LL << 60;

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  forn(i, N) cin >> H[i];

  vector<ll> dp(N, INF);
  dp[0] = 0;

  forn(i, N)
  {
    for (int k = 1; k <= K && i + k < N; k++)
      chmin(dp[i + k], dp[i] + abs(H[i] - H[i + k]));
  }
  cout << dp[N - 1] << endl;

  return 0;
}


Measured memory_bytes: 4292
package main

import (
	"fmt"
)

func main() {
	var N string
	fmt.Scanf("%s", &N)
	var sum int
	for _, v := range N {
		sum = (sum + int(v-'0')) % 9
	}

	if sum%9 == 0 {
		fmt.Println("Yes")
		return
	}

	fmt.Println("No")

}


Measured memory_bytes: 3268
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
    char s[30] ;
    scanf("%s",s) ;
    for (int i=0; i<strlen(s); i++) {
        for (int j=i+1; j<strlen(s); j++) {
            if (s[i]==s[j]) {
                printf ("no\n") ;
                exit (0) ;
            }
        }
    }
    printf ("yes\n") ;
    return 0 ;
}

Measured memory_bytes: 128
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll n, a, b;
	cin>>n>>a>>b;
	if((b-a)%2==0) cout<<"Alice"<<endl;
	else cout<<"Borys"<<endl;
	return 0;
}


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

typedef pair<int, int> P;

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

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

signed main(){
    int n, p;
    while( cin >> n >> p, n | p ){
        vector<int> cand( n );
        int win = -1, stone = p;
        for( int i = 0; ; i++ ){
            if( stone > 0 ){
                cand[i % n]++;
                stone--;
            }else{
                FOR( j, i, n + i  ){
                    if( cand[j % n] ){
                        stone = cand[j % n];
                        if( stone == p ) win = j % n;
                        cand[j % n] = 0;
                        i = j;
                        break;
                    }
                }
            }
            if( win != -1 ){
                cout << win << endl;
                break;
            }
        }
    }
}



Measured memory_bytes: 3000
n = int(input())
B = list(map(int,input().split()))
L = [0 for i in range(n)]
k = n-1
for i in range(n):
    for j in range(len(B)):
        if B[-1-j]==len(B)-j:
            L[k] = len(B)-j
            B.pop(-1-j)
            k -= 1
            break
if B:
    print(-1)
else:
    for l in L:
        print(l)

Measured memory_bytes: 38512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define all(v) (v).begin(), (v).end()
using namespace std;
typedef long long LL;
const int INF = 999999999;
const LL mod = 1000000007;

LL modpow(LL a, LL b, LL p){
    if(b==0) return 1;
    else if(b%2==0){
        LL d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a*modpow(a, b-1, p)) % p;
    }
}

LL dv(LL x, LL a){
    return (x*modpow(a, mod-2, mod)) % mod;
}

int main(){
    LL a,b,x;
    cin >> a >> b >> x;
    LL ans = 0;
    if(x < a){
        cout << x%mod << endl;
        return 0;
    }
    LL t = (x-a)/(a-b);
    ans = (t%mod*(a%mod))%mod;
    x -= (a-b)*t;
    (ans += x-x%a) %= mod;
    x = x/a*b + x%a;
    (ans += x) %= mod;
    cout << ans << endl;

}



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

int main(void)
{
    int h, a, ans;
    scanf("%d%d", &h, &a);

    if(h%a==0) ans = h/a;
    else ans = (h-h%a)/a + 1;
    printf("%d", ans);
    return 0;    
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
string s;int a,b;
int main()
{
	cin>>s;b=s.size()-1;
	if(s[0]!='A'){cout<<"WA";return 0;}
	if(s[1]<'a'||s[1]>'z')
	{cout<<"WA";return 0;}
	for(int i=2;i<b;i++)
	{
		if(s[i]=='C')a++;
		else
		if(s[i]<'a'||s[i]>'z')
		{cout<<"WA";return 0;}
	}
	if(s[b]<'a'||s[b]>'z')
	{cout<<"WA";return 0;}
	if(a!=1)cout<<"WA";
	else cout<<"AC";
	return 0;
}

Measured memory_bytes: 256
using System;

namespace AOJ
{
  class Program
  {
    static void Main(string[] args)
    {
      int a, b;
      string[] ary;

      while (true)
      {
        ary = Console.ReadLine().Split(' ');
        a = int.Parse(ary[0]);
        b = int.Parse(ary[1]);

        if (a == 0 && b == 0) break;

        if (a <= b) Console.WriteLine("{0} {1}", a, b);
        else Console.WriteLine("{0} {1}", b, a);

      }
    }
  }
}

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

int main(){
	string s;
	while(getline(cin, s)) {
		if(s == ".") break;
		vector<int> v(2);
		vector<int> tmp[2];
		bool f = true;
		for(auto& c: s) {
			if(c == '(') {
				v[0]++;
				tmp[0].push_back(v[1]);
			}
			if(c == ')') {
				if(v[0] == 0 || tmp[0].back() != v[1]) {
					f = false;
					break;
				}
				else {
					v[0]--;
					tmp[0].pop_back();
				}
			}
			if(c == '[') {
				v[1]++;
				tmp[1].push_back(v[0]);
			}
			if(c == ']') {
				if(v[1] == 0 || tmp[1].back() != v[0]) {
					f = false;
					break;
				}
				else {
					v[1]--;
					tmp[1].pop_back();
				}
			}
		}
		if(v[0] != 0 || v[1] != 0) f = false;
		cout << (f ? "yes" : "no") << endl;
	}
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=3.14159265358979323846;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n,c;
    cin>>n>>c;
    vector<int> time(100100);
    vector<tuple<int,int,int>> vec(n);
    rep(i,n) {
        int s,t,c;
        cin>>s>>t>>c;
        vec[i]=make_tuple(c,s,t);
    }
    vec.emplace_back(-1,-1,-1);
    vec.emplace_back(INF,INF,INF);
    
    sort(all(vec));
    
    FOR(i,1,n) {
        int pc,ps,pt,c,s,t,nc,ns,nt;
        tie(pc,ps,pt)=vec[i-1];
        tie(c,s,t)=vec[i];
        tie(nc,ns,nt)=vec[i+1];
        if(!(pc==c && pt==s)) time[s-1]++;
        if(!(c==nc && t==ns)) time[t]--;
    }
    
    int ans=time[0];
    rep(i,100099) {
        time[i+1] += time[i];
        ans=max(ans,time[i+1]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3840
H,W,A,B=map(int,input().split())
ans = [['0'] * W for _ in range(H)]
for y in range(H):
    for x in range(W):
        if x < A and y < B:
            ans[y][x] = '1'
        elif x >= A and y >= B:
            ans[y][x] = '1'
for a in ans:
    print(''.join(a))

Measured memory_bytes: 11892
import sys
from itertools import accumulate
input = sys.stdin.readline
def main():
    N, K = map( int ,input().split())
    TK = K*2
    B = [[0]*(K*2) for _ in range(TK)]
    for _ in range(N):
        x, y, c = input().split()
        x, y = int(x), int(y)
        if c == "B":
            B[x%TK][y%TK] += 1
        else:
            B[x%TK][(y+K)%TK] += 1
    C = [[0]*(TK+1)] + [[0] + list( accumulate(B[i])) for i in range(TK)]
    for i in range(TK):
        for j in range(TK+1):
            C[i+1][j] += C[i][j]
    def get(i1, j1, i2, j2):
        return C[i2][j2] - C[i1][j2] - C[i2][j1] + C[i1][j1]
    ans = 0
    for i in range(K+1):
        for j in range(K+1):
            if ans < get(0,0,i,j) + get(i+K, 0, TK, j) + get(i, j, i+K, j+K) + get(0, j+K, i, TK) + get(K+i, K+j, TK, TK):
                ans = get(0,0,i,j) + get(i+K, 0, TK, j) + get(i, j, i+K, j+K) + get(0, j+K, i, TK) + get(K+i, K+j, TK, TK)
            if ans < get(i, 0, i+K, j) + get(0, j, i, j+K) + get(i+K, j, TK, j+K) + get(i, j+K, i+K, TK):
                ans = get(i, 0, i+K, j) + get(0, j, i, j+K) + get(i+K, j, TK, j+K) + get(i, j+K, i+K, TK)
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 112732
#include<iostream>

int main(void)
{
	int a, b, c;
	std::cin >> a >> b >> c;
	int x;
	std::cin >> x;

	int sum = 0;
	int ans = 0;
	for (int k = 0; k <= c; k++) {
		for (int j = 0; j <= b; j++) {
			for (int i = 0; i <= a; i++) {
				sum = 500 * i + 100 * j + 50 * k;
				if (sum == x) {
					ans++;
				}
			}
		}
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
		String[] number = line.split(" ");
		int a = Integer.parseInt(number[0]);
		int b = Integer.parseInt(number[1]);
		int c = Integer.parseInt(number[2]);
		int d = Integer.parseInt(number[3]);
		int r = 0;
		if(a <= c) {
			if(c < b) {
			    if(b <= d) {
				    r = b - c;
				    System.out.println(r);
			    } else if(d < b) {
			        r = d - c;
			        System.out.println(r);
			    }
			} else if(b <= c) {
				System.out.println(r);
			}
		} else if(c < a) {
			if(a < d) {
				if(d <= b) {
				    r = d - a;
				    System.out.println(r);
			    } else if(b < d) {
			        r = b - a;
			        System.out.println(r);
			    }
			} else if(d <= a) {
				System.out.println(r);
			}
		}
	}
}

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

public class P
{
    public int id { get; set; }
    public int s { get; set; }
}

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var ps = new P[n];
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ');
                var a = Array.ConvertAll(line, int.Parse);
                ps[i] = new P { id = a[0], s = getScore(a) };
            }
            foreach (var x in ps.OrderByDescending(y => y.s).ThenBy(y => y.id))
                Console.WriteLine("{0} {1}", x.id, x.s);
        }
    }
    static int getScore(int[] a)
    {
        var p = 1; var s = 0; var f = 1;
        while (f < 10)
        {
            if (a[p] == 10) { s += 10 + a[p + 1] + a[p + 2]; p++; }
            else if (a[p] + a[p + 1] == 10) { s += 10 + a[p + 2]; p += 2; }
            else { s += a[p] + a[p + 1]; p += 2; }
            f++;
        }
        for (int i = p; i < a.Length; i++) s += a[i];
        return s;
    }
}



Measured memory_bytes: 18316
#include<iostream>
int main() {
	int X,A,B;
	std::cin >> X >> A >> B;
	
	if(B-A>=X+1) {
	std::cout << "dangerous" << std::endl;
	}
	else {
		if(B-A<=0) {
			std::cout << "delicious" << std::endl;
		}
		else {
			std::cout << "safe" << std::endl;
		}
	}
	return 0;
}
		

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  int b;
  int count=0;

   
  cin >> a >>b;
  
  for (int i = a; i <=b; i++) {
 
   int c;
   int d;
   int e;
   int f;
   int g;
   g=i;
   c=g%10;
   g/=10;
   d=g%10;
   g/=100;
   e=g%10;
   g/=10;
   f=g%10;
        if(c==f&&d==e){
       count++;
   }
 
  }
  cout <<count<<endl;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define RREP(i,n) for(long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define llINF (long long) 9223372036854775807
#define loINF (long) 2147483647
#define shINF (short) 32767
#define SORT(c) sort((c).begin(),(c).end())
#define DEBUG

using namespace std;
typedef vector<long> VI;
typedef vector<VI> VVI;
typedef pair<long,long> pr;
typedef map<double,pr> mp;
short A,B,C,D,E,F;
mp ans;

double dfs(long water){
	if (water >= F) return 0.0;
	long limit = min((water*E)/100,F-water);
	
	long remain,salt = loINF;
	REP(i,(limit / D)+1){
		remain = ((limit - (D * i)) % C);
		if (salt > remain) salt = remain;
	}
	salt = limit - salt;
	double val = ((double)salt*100)/((double)(water+salt));
	ans[val] = make_pair(water+salt,salt);
	if (salt == limit) return val;
	else return max({val,dfs(water+100*A),dfs(water+100*B)});
}

int main(void){
	cin >> A >> B >> C >> D >> E >> F;
	double percent = max(dfs(100*A),dfs(100*B));
	cout << ans[percent].first << " "<< ans[percent].second << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(size_t i=0;i<(n);i++)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const &auto s, const &auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main() {
  int n,k;
  cin>>n>>k;
  long long s=n-k+1;
  FOR(i,k){
    if(i!=0){
      s*=(k-i)*(n-k+1-i);s%=1000000007;
      s*=modinv(i*(i+1),1000000007);s%=1000000007;
      s%=1000000007;
    }
    cout<<s<<endl;
  }
}

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

int main(){
  int N;
  cin >> N;
  int i;
  vector<int64_t> vec(N+1,0);
  vec.at(0)=2;
  vec.at(1)=1;
  for(i=2;i<N+1;i++){
    vec.at(i)=vec.at(i-1)+vec.at(i-2);
  }
  cout << vec.at(N) << endl;
  
}
    


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

def Bellman_Ford(g,start):
    n = len(g)    
    dist = [float("inf")]*n
    dist[start] = 0
    a0 = float("inf")
    negative = [False]*n
    for i in range((2*n)):
        updated = False
        for v in range(n):
            for to, cost in g[v]:
                if negative[v]: negative[to] = True
                if dist[to] <= dist[v] + cost: continue
                dist[to] = dist[v] + cost
                updated = True
                if i >= n:
                    negative[to] = True
        if not updated: break
    if negative[-1]: return None, False
    return dist, True


import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,m = [int(i) for i in readline().split()]
g = [[] for _ in range(n)]
for i in range(m):
    a,b,c = [int(i) for i in readline().split()]
    g[a-1].append((b-1,-c))
#    g[b-1].append((a-1,c))

dist, TF = Bellman_Ford(g, 0)

if TF: print(-dist[-1])
else: print("inf")




Measured memory_bytes: 3316
# -*- coding: utf-8 -*-
"""
Kongo Type
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0268

"""
import sys


def solve():
    bits = f'{int(input(), 16):032b}'
    sign = '-' if bits[0] == '1' else ''
    integer = sum([2**i for i, b in enumerate(bits[1:25][::-1]) if b == '1'])
    fraction = sum([0.5**i for i, b in enumerate(bits[25:], start=1) if b == '1'])
    return sign + str(float(integer + fraction))


def main(args):
    Q = int(input())
    for _ in range(Q):
        ans = solve()
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])



Measured memory_bytes: 5708
import sys
sys.setrecursionlimit(1000000)


def dfs(h, w, field, seen, dhw):
    seen[h][w] = True
    for dh, dw in dhw:
        nh = h + dh
        nw = w + dw

        if field[nh][nw] == 0:
            continue
        if seen[nh][nw]:
            continue

        dfs(nh, nw, field, seen, dhw)


def main():
    res = []
    while True:
        w, h = map(int, input().split())
        if w == 0 and h == 0:
            break

        field = []
        field.append([0] * (w + 2))
        for i in range(h):
            line = list(map(int, input().split()))
            field.append([0] + line + [0])
        field.append([0] * (w + 2))

        seen = [[False] * (w + 2) for x in range(h + 2)]
        dhw = [(1, 0), (-1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (-1, 1), (1, -1)]

        count = 0
        for ih in range(1, h+2):
            for iw in range(1, w+2):
                if seen[ih][iw]:
                    continue
                if field[ih][iw] == 1:
                    dfs(ih, iw, field, seen, dhw)
                    count += 1
        res.append(count)

    for i in res:
        print(i)


main()



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

using namespace std;

int x, y, ans;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();

    cin >> x >> y;

    ans = abs(abs(x) - abs(y));

    if ((x > 0 && y > 0 || x < 0 && y < 0) && x > y) {
        ans += 2;
    }

    if (x >= 0 && y <= 0 || x < 0 && y > 0) {
        ans += 1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
a=[]
while True:
    a.append(list(map(int,input().split(" "))))
    if a[-1]==[0,0]:
        a=a[:-1]
        break

def DrawRectangle(lst):
    drawn=[("#"*lst[1])for i in range(lst[0])]
    for i in drawn:
        print (i)
    print("")

for i in a:
    DrawRectangle(i)


Measured memory_bytes: 5632
//============================================================================
// Name        : test.cpp
// Author      : Qihan
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
using namespace std;
typedef long long int LLI;
typedef pair<int,int> PII;
const int maxn = (100000 + 10);

int vis[maxn];
int a[maxn],p = 0;

int main() {
    //	freopen("/home/qihan/Documents/in","r",stdin);
    int n;
    scanf("%d",&n);
    for(int i = 1; i <= n; i ++) {
        int temp;
        scanf("%d",&temp);
        vis[temp] ++;
    }
    for(int i = 1; i <= 100000; i ++) {
        if(vis[i] != 0)	a[p ++] = vis[i];
    }
    int l = 0,r = p - 1;
    ////	printf("%d\n",p);
    //    for(int i = 0;i < p;i ++){
    //        printf("%d ",a[i]);
    //    }
    //    printf("\n");
    while(l < r) {
        if(a[l] <= 1)	l ++;
        if(a[r] <= 1)	r --;
        if(a[l] > 1 && a[r] > 1 && l < r) {
            int x = min(a[l],a[r]);
            a[l] = a[l] - x + 1;
            a[r] = a[r] - x + 1;
        }
    }
    int ans = p;
    //	printf("%d %d %d\n",l,r,a[l]);
    if(a[l] > 1 || a[r] > 1) {
        if(a[l] > 1)		ans = ans - (a[l] % 2 == 0 ? 1 : 0);
        else if(a[r] > 1)	ans = ans - (a[r] % 2 == 0 ? 1 : 0);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define MP make_pair
#define PB push_back
#define PII pair<int,int>
#define ll long long
#define quick ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int N=INT_MAX;
ll INF1=1e9 + 5;
ll INF2=1e18L + 5;
map<int ,int>my;
int h[10005];

int main(){
	quick;
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	int x=0;
	for(int i=0;i<n;i++){
		if(s[i]==s[i+1]){
			x++;
		}
	}
	cout<<min(n-1,2*k+x);
}


Measured memory_bytes: 640
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]

AB.sort(key = lambda x:x[1])
ans = 'Yes'
time = 0

for n in range(N):
    time += AB[n][0]
    if time>AB[n][1]:
        ans = 'No'
        
print(ans)

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

using namespace std;

#define MOD 1000000007
#define ll long long int
#define ld long double
#define pb push_back
#define mkp make_pair
#define pii pair<int, int> 
#define pll pair<long long int, long long int>
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define fi first
#define sc second
#define deb 0

struct node {
	ll x, y;
	string s;
} A[100001];
ll M[2005][2005], X[2005], Y[2005];
string tmps[] = {"W", "B"};

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

	ll n, k, i, j, x, y, a, b;
	cin >> n >> k;
	for (i = 0; i < n; ++i) {
		cin >> A[i].x >> A[i].y >> A[i].s;
	}
	ll ans = 0, tmp = 0;
	for (i = 0; i < n; ++i) {
		ll gr = (A[i].x + k - 1) / k;
		ll gc = (A[i].y + k - 1) / k;
		ll c = (gr & 1) ^ (gc & 1);
		tmp += (A[i].s == tmps[c]);
		ll x1 = (gr-1) * k;
		ll y1 = (gc-1) * k;
		if (A[i].s != tmps[c]) {
			M[A[i].x-x1][A[i].y-y1] += 2;
			X[A[i].x-x1] += 1;
			Y[A[i].y-y1] += 1;
		} else {
			M[A[i].x-x1][A[i].y-y1] -= 2;
			X[A[i].x-x1] -= 1;
			Y[A[i].y-y1] -= 1;
		}
	}
	for (i = 0; i <= k; ++i) {
		if (i) X[i] += X[i-1];
		if (i) Y[i] += Y[i-1];
		for (j = 0; j <= k; ++j) {
			if (j) M[i][j] += M[i][j-1];
		}
		for (j = 0; j <= k; ++j) {
			if (i) M[i][j] += M[i-1][j];
		}
	}
	ans = max(tmp, n-tmp);
	for (i = 0; i <= k; ++i) {
		for (j = 0; j <= k; ++j) {
			ll ntmp = tmp + X[i] + Y[j] - M[i][j];
			ans = max(ans, max(ntmp, n-ntmp));
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 23936
N,T = map(int,input().split())
A = list(map(int,input().split()))

minA = A[0]
profit = 0
cnt = 0
for i in range(1,N):
    # A[i] で min(A[0..i-1])を売る場合の利益
    p = A[i]-minA
    if p==profit:
        cnt += 1 
    elif p>profit:
        profit = p
        cnt = 1
    # min(A[0..i]) の更新
    minA = min(minA,A[i])
    
print(cnt)


Measured memory_bytes: 14252
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
const ll mod=1000000007;
ll gcd(ll a,ll b){if(a<b)swap(a,b);while((a%b)!=0){a=b;b=a%b;}return b;}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

ll dp[105][4][2];

int main(){
  string s; cin>>s;
  int k,n; cin>>k;
  n=s.size();
  // rep(i,3){
  //   rep(j,2) dp[0][i][j]=0;
  // }
  dp[0][0][0]=1;
  // dp[0][0][1]=1;

  rep(i,n){
    rep(j,k+1){
      rep(l,2){
        int c=s[i]-'0';
        if(l==0){
          if(j-1>=0&&c>0) dp[i+1][j][0]=dp[i][j-1][0];
          else if(c==0) dp[i+1][j][0]=dp[i][j][0];
          else dp[i+1][j][0]=0;
        }else{
          if(j==0){
            dp[i+1][j][1]=1;
          }else{
            if(c>0) dp[i+1][j][1]+=dp[i][j][0];
            if(c-1>0) dp[i+1][j][1]+=dp[i][j-1][0]*(c-1);
            dp[i+1][j][1]+=dp[i][j-1][1]*9+dp[i][j][1];
          }
        }
      }
    }
  }
  /*cout<<"0dayo"<<endl;
  rep(i,n+1){
    rep(j,k+1)
    cout<<dp[i][j][0]<<" ";
    cout<<endl;
  }
  cout<<"1dayo"<<endl;
  rep(i,n+1){
    rep(j,k+1)
    cout<<dp[i][j][1]<<" ";
    cout<<endl;
  }*/

  cout<<dp[n][k][0]+dp[n][k][1]<<endl;
  return 0;
}


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

int main(){
    int t;
    cin >> t;
    int h, m, s;
    h = t / (60 * 60);
    m = (t - (h * 60 * 60)) / 60;
    s = t - (h * 60 * 60) - (m * 60);
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 2e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

#define N 100010
vii G(N, vi());
vi p(N);
vii child(N, vi());
vector<pii> mM(N, pii(-inf, inf));
vi ans(N);

void make_family(int parent, int now) {
	int i;
	for (i = 0; i < G[now].size(); i++) {
		if (G[now][i] == parent) {
			continue;
		}
		child[now].push_back(G[now][i]);
		make_family(now, G[now][i]);
	}
}

void dfs(int now) {
	if (child[now].size() == 0) {
		return;
	}
	int i;
	for (i = 0; i < child[now].size(); i++) {
		dfs(child[now][i]);
	}
	int m = -inf, M = inf;
	for (i = 0; i < child[now].size(); i++) {
		int u = child[now][i];
		if (mM[u].first == -inf) {
			continue;
		}
		else if (m == -inf) {
			m = mM[u].first - 1;
			M = mM[u].second + 1;
		}
		else {
			if (abs(m % 2) != abs((mM[u].first - 1) % 2)) {
				cout << "No" << endl;
				exit(0);
			}
			else {
				m = max(m, mM[u].first - 1);
				M = min(M, mM[u].second + 1);
			}
		}
		
	}
	if (m > M) {
		cout << "No" << endl;
		exit(0);
	}
	else if (mM[now].first == -inf) {
		mM[now].first = m;
		mM[now].second = M;
	}
	else if (m == -inf) {
		return;
	}
	else {
		if (abs(m % 2) != abs(mM[now].first % 2)) {
			cout << "No" << endl;
			exit(0);
		}
		else {
			if (m <= mM[now].first && mM[now].second <= M) {
				return;
			}
			else {
				cout << "No" << endl;
				exit(0);
			}
		}
	}
}

void solve(int now, int a) {
	for (int i = 0; i < child[now].size(); i++) {
		if (mM[child[now][i]].first <= a - 1) {
			ans[child[now][i]] = a - 1;
			solve(child[now][i], a - 1);
		}
		else {
			ans[child[now][i]] = a + 1;
			solve(child[now][i], a + 1);
		}
	}
	return;
}

int main() {
	int n, i, j;
	cin >> n;
	vi a(n), b(n);
	for (i = 0; i < n - 1; i++) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		G[a[i]].push_back(b[i]);
		G[b[i]].push_back(a[i]);
	}
	p[0] = -1;
	make_family(-1, 0);
	int k;
	cin >> k;
	vi v(k), p(k);
	for (i = 0; i < k; i++) {
		cin >> v[i] >> p[i];
		v[i]--;
		mM[v[i]].first = mM[v[i]].second = p[i];
	}

	dfs(0);
	cout << "Yes" << endl;
	ans[0] = mM[0].first;
	solve(0, ans[0]);
	for (i = 0; i < n; i++) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 20352
#include <bits/stdc++.h>
using namespace std;
vector<int> abc(3, 0);
int main() {
    for(int i = 0; i < 3; ++i) {
        cin >> abc.at(i);
    }
    sort(abc.begin(), abc.end());

    cout << abc.at(0) + abc.at(1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll power(ll x,ll y,ll p) 
{ 
    ll res = 1;      
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	cin >> x >> y;
	if(y>=x)
		cout<<"unsafe"<<endl;
	else
		cout<<"safe"<<endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

queue<int> two,three,six;

int pop(queue<int>& que){
  int temp = que.front();
  que.pop();
  return temp;
}
int n;
int main(){
  cin >> n;
  vector<int> ans;
  if(n == 3){
    cout << "2 5 63" << endl;
    return 0;
  }
  else{
    for(int i = 2;i <= 30000;i++){
      if(i % 6 == 0) six.push(i);
      else if(i % 2 == 0) two.push(i);
      else if(i % 3 == 0) three.push(i);
    }

    n-=4;
    ans.push_back(pop(two));
    ans.push_back(pop(two));
    ans.push_back(pop(three));
    ans.push_back(pop(three));
    while(n - 2 >= 0 && !two.empty()){
      ans.push_back(pop(two));
      ans.push_back(pop(two));
      n-=2;
    }
    while(n - 2 >= 0 && !three.empty()){
      ans.push_back(pop(three));
      ans.push_back(pop(three));
      n-=2;
    }
    while(n - 1 >= 0){
      ans.push_back(pop(six));
      n--;
    }

    for(int an : ans){
      cout << an << " ";
    }
    cout << endl;
  }

}

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

using namespace std;

int main(void)
{
  string str;
  cin >> str;
  int max = 0;
  int cnt = 0;
  for(int i = 0; i < str.size(); i++){
    char s = str[i];
    if(s == 'A' || s == 'C' || s == 'G' || s == 'T'){
      //cout << s << endl;
      cnt++;
    }else{
      if(max < cnt){
        max = cnt;
      }
      cnt = 0;
    }
  }
  if(max < cnt ){
    max = cnt;
  }
  cout << max << endl;
}


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

int R, C, sx, sy, gx, gy;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int INF = 1 << 28;
const int MAX_V = 30 * 30;
int cost[MAX_V][MAX_V];
int d[MAX_V];
bool used[MAX_V];
int V;

void dijkstra(int s) {
	fill(d, d + V, INF);
	fill(used, used + V, false);
	d[s] = 0;

	while (true) {
		int v = -1;
		for (int u = 0; u < V; u++) {
			if (!used[u] && (v == -1 || d[u] < d[v])) v = u;
		}
		if (v == -1) break;

		used[v] = true;
		for (int u = 0; u < V; u++) {
			d[u] = min(d[u], d[v] + cost[v][u]);
		}
	}
}

int toV(int x, int y) {
	return C * y + x;
}

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

	cin >> R >> C;
	V = R * C;
	char field[30][30];
	for (int y = 0; y < R; y++) {
		for (int x = 0; x < C; x++) {
			cin >> field[y][x];
			if (field[y][x] == 'S') {
				sx = x , sy = y;
				field[y][x] = '.';
			}
			if (field[y][x] == 'G') {
				gx = x , gy = y;
				field[y][x] = '.';
			}
		}
	}

	for (int v = 0; v < V; v++) {
		for (int u = 0; u < V; u++) {
			cost[v][u] = (v == u) ? 0 : INF;
		}
	}

	for (int y = 0; y < R; y++) {
		for (int x = 0; x < C; x++) {
			if (field[y][x] == '#') continue;
			int v = toV(x, y);
			for (int i = 0; i < 4; i++) {
				for (int j = 1; j <= 3; j++) {
					int nx = x + dx[i] * j, ny = y + dy[i] * j;
					if (nx < 0 || C <= nx || ny < 0 || R <= ny || field[ny][nx] == '#') break;
					int u = toV(nx, ny);
					if (j == 1) {
						if (field[ny][nx] == 'o')
							cost[v][u] = 1;
						if (field[ny][nx] == '.')
							cost[v][u] = 2;
						if(field[ny][nx] == 'x')
							cost[v][u] = 3;
					}
					else {
						cost[v][u] = 2 + j;
					}
				}
			}
		}
	}

	dijkstra(toV(sx, sy));
	cout << d[toV(gx, gy)] << endl;
}

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

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A = new long[N];
        long[] B = new long[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextLong();
            B[i] = sc.nextLong();
        }
        Arrays.sort(A);
        Arrays.sort(B);
        long ans;
        if(N % 2 == 1){
            ans = B[N/2] - A[N/2] + 1;
        }else{
            long ai = A[N/2] + A[N/2-1];
            long bi = B[N/2] + B[N/2-1];
            ans = bi-ai+1;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 62896
#include<iostream>
#include<iomanip>
#include<cstring>
using namespace std;
double dp[301][301][301];
double solve(int x,int y,int z,int n)
{  if(x<0||y<0||z<0)
    return 0;
	if(x==0&&y==0&&z==0)
	  return 0;
	  if(dp[x][y][z]>-0.9)
	  return dp[x][y][z];
	  	double exp=n+x*solve(x-1,y,z,n)+y*solve(x+1,y-1,z,n)+z*solve(x,y+1,z-1,n);
	return dp[x][y][z]=exp/(x+y+z);
	
}
int main()
{ memset(dp,-1,sizeof(dp));
	int n;
	cin>>n;
	int one=0,two=0,three=0;
	int x;
	for(int i=0;i<n;i++)
	 { cin>>x;
	  if(x==1)
	 	one++;
	 	else if(x==2)
	 	 two++;
	 	 else 
		  three++;
	 }
	 cout<<fixed<<setprecision(12)<<solve(one,two,three,n);
	
}

Measured memory_bytes: 213376
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C3Or2 solver = new C3Or2();
        solver.solve(1, in, out);
        out.close();
    }

    static class C3Or2 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int answer = 0;

            for (int i = 0; i < n; i++) {
                int x = in.nextInt();
                answer += Integer.numberOfTrailingZeros(x);
            }

            out.println(answer);
        }

    }

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

    }
}



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

int mod=1000000009;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    int a[n+10],dp[n+10];
    for(int i=1;i<=n;i++)cin>>a[i];
    dp[0] = 0;
    dp[1] = 0;
    dp[2] = abs(a[1]-a[2]);
    for(int i=3;i<=n;i++){
        int ans=mod;
        for(int j=i-1;j>=max(i-k,1);j--){ans = min(ans,dp[j]+abs(a[i]-a[j]));}
        dp[i] = ans;
    }
    cout<<dp[n];
    return 0;
}    

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
typedef long long ll;

const int N = 1e9 ;
const int P = 1e9 + 7;

ll quickPower(ll a, ll b) {
    ll res = 1;
    a %= P;
    while (b) {
        if (b & 1)res = (res % P) * (a % P) % P;
        a = (a % P) * (a % P) % P;
        b >>= 1;
    }
    return res;
}
ll inv(ll x) {//x关于p的逆元，p为素数
    return quickPower(x, P - 2);
}
ll qpow(ll x, ll n) {
    ll res = 1;
    x %= P;
    while (n) {
        if (n & 1) res = res * x % P;
        x = x * x % P;
        n >>= 1;
    }
    return res;
}
ll C(ll n, ll m) {
    if (m > n)return 0;
    ll up = 1, down = 1;//分子分母;
    for (int i = n - m + 1; i <= n; i++)
        up = up * i % P;
    for (int i = 1; i <= m; i++)
        down = down * i % P;
    return up * inv(down) % P;
}
ll Lucas(ll n, ll m) {
    if (m == 0)return 1;
    return C(n % P, m % P) * Lucas(n / P, m / P) % P;
}
int main(){
    IOS;
    ll n,a,b;
    cin>>n>>a>>b;
    ll res=0;
    res+=qpow(2,n);
    res=(res-1+P+P+P-Lucas(n,a)-Lucas(n,b)+P)%P;
    cout<<res;
}

Measured memory_bytes: 256
#include <stdio.h>

int a[6];

int main(void)
{
	int n;
	int i;
	int j;
	double high;
	
	scanf("%d", &n);
	
	for (i = 0;i < n;i++){
		scanf("%lf", &high);
		if (high < 165.0){
			a[0]++;
		}
		else if (high < 170.0){
			a[1]++;
		}
		else if (high < 175.0){
			a[2]++;
		}
		else if (high < 180.0){
			a[3]++;
		}
		else if (high < 185.0){
			a[4]++;
		}
		else {
			a[5]++;
		}
	}
	for (i = 1;i <= 6; i++){
		printf("%d:", i);
		for (j = 0; j < a[i - 1]; j++){
			printf("*");
		}
		printf("\n");
	}
	
	return (0);
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main() {
	int X;
	cin >> X;
	
	int ans = 0;
	int sum = 0;
	int cnt= 0;
	while (sum < X) {
		cnt++;
		sum += cnt;
		ans++;
	}


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

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

using namespace std;
typedef unsigned long long u64;

string s;
char S[101010];
int top = 0;
int main()
{
	// Which to pick does NOT matter.
	cin >> s;
	int n = s.length();
	int turn = 0;
	for (int i = 0; i < n; ++i) {
		S[top++] = s[i];
		while (top >= 3 && S[top-1] != S[top-3]) {
			S[top-2] = S[top-1];
			top--;
			turn ^= 1;
		}
	}
	cout << (turn ? "First" : "Second") << endl;
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    ll A, B;
    scanf("%lld %lld", &A, &B);
    A+=B;
    if(A>=10)printf("error\n");
    else printf("%lld\n", A);
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


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

long long n, ans = 1;
vector<int> ex;
vector<long long> fs;

int main() {
	cin >> n;
	long long m = n - 1;
	for (int i = 2, c; (long long) i * i <= m; i++) {
		c = 0;
		while (!(m % i)) {
			c++;
			m /= i;
		}
		ex.push_back(c);
	}
	if (m > 1)
		ex.push_back(1);
	for (int i = 0; i < (int) ex.size(); i++) {
		ans *= ex[i] + 1;
	}
	for (int i = 2; (long long) i * i <= n; i++) {
		if (!(n % i)) {
			fs.push_back(i);
			if (n / i != i)
				fs.push_back(n / i);
		}
	}

	for (long long f : fs) {
		m = n;
		while (!(m % f))
			m /= f;
		if (m % f == 1)
			ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 6256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())[:-1]
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [list(input())[:-1] for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
num = []
for i in range(N-1):
    for j in range(i+1,N):
        a = 0
        li1 = X[i]
        li2 = X[j]
        for k in range(D):
            a += (li1[k]-li2[k]) ** 2
        num.append(a)
count = 0
co = Counter(num)
ans = 0
for i in range(10000):
    ans += co[i*i]
print(ans)

Measured memory_bytes: 5084
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>

#define WM 1e5
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;

    cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;

    
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<vector<long long>> v(N + 1, vector<long long>(N + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]) % 1000000007;
    }
  }
  for (int k = 1; k <= K; ++k) {
    long long pattern = (v[K - 1][k - 1] * v[N - K + 1][k]) % 1000000007;
    cout << pattern << endl;
  }
  return 0;
}


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

#define HEAP priority_queue
#define rep(i, n) for(int i = 0, _end_ = (n); i < _end_; ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l), _end_ = (r); i <= _end_; ++i)
#define nrof(i, r, l) for(int i = (r), _end_ = (l); i >= _end_; --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;

const int iinf = 1e9 + 7;
const int oo = 0x3f3f3f3f;
const LL linf = 1ll << 60;
const flt dinf = 1e60;

template <typename T> inline void scf(T &x)
{
	bool f = 0;
	x = 0;
	char c = getchar();
	while(c != '-' && (c < '0' || c > '9')) c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	if(f) x = -x;
	return;
}

template <typename T1, typename T2> void scf(T1 &x, T2 &y)
{
	scf(x);
	return scf(y);
}

template <typename T1, typename T2, typename T3> void scf(T1 &x, T2 &y, T3 &z)
{
	scf(x);
	scf(y);
	return scf(z);
}

template <typename T1, typename T2, typename T3, typename T4> void scf(T1 &x, T2 &y, T3 &z, T4 &w)
{
	scf(x);
	scf(y);
	scf(z);
	return scf(w);
}

inline char mygetchar()
{
	char c = getchar();
	while(c == ' ' || c == '\n') c = getchar();
	return c;
}

template <typename T> inline bool chkmax(T &x, const T &y)
{
	return y > x ? x = y, 1 : 0;
}

template <typename T> inline bool chkmin(T &x, const T &y)
{
	return y < x ? x = y, 1 : 0;
}

#ifdef King_George
#define DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

//---------------------------------------------------------head----------------------------------------------------

const int maxn = 55;

const LL FUCK = 1e18;

const LL GAP = 1e5;

LL n;
LL a[maxn];

bool check(LL mid)
{
	LL cnt = 0, bnd = (n - 1) - mid, z = n + 1;
	forn(i, 1, n)
	{
		LL x = a[i] - bnd;
		LL k = x / z;
		if(k * z < x) ++k;
		cnt += k;
	}
	return cnt <= mid;
}

int main()
{
	scf(n);
	forn(i, 1, n) scf(a[i]);
	LL lb = 0, rb = FUCK;
	while(rb - lb >= GAP)
	{
		LL mid = lb + rb >> 1;
		bool f = 0;
		for(LL i = 0; i < GAP; ++i) if(check(mid + i)){ f = 1; break; }
		if(f) rb = mid - 1;
		else lb = mid + 1;
	}
	while(!check(lb)) ++lb;
	printf("%lld\n", lb);
	return 0;
}

Measured memory_bytes: 256
cnt = 0
n = int(raw_input())
A = [int(raw_input()) for _ in range(n)]
G = [1] if n < 5 else [1, 4]
while G[-1]*3+1 <= n/3: G.append(G[-1]*3+1)
if n > 256: G.append(n/10*9+G[-1]%2+(n/10*9-1)%2)
G.reverse()

def insersionSort(g):
	global cnt
	for i in range(g, n):
		v = A[i]
		j = i - g
		while j >= 0 and A[j] > v:
			A[j+g] = A[j]
			j = j - g
			cnt += 1
		A[j+g] = v

def shellSort():
	for g in G:
		insersionSort(g)

shellSort()
print len(G)
print " ".join(map(str, G))
print cnt
print "\n".join(map(str, A))

Measured memory_bytes: 126972
n, m, x = map(int, input().split())
text = [list(map(int, input().split())) for _ in range(n)]
minmoney = float('inf')
for i in range(2 ** n):
    money = 0
    rikai = [0 for _ in range(m)]
    B = True
    for j in range(n):
        if ((i >> j) & 1):
            money += text[j][0]
            for k in range(m):
                rikai[k] += text[j][k + 1]
    for k in range(m):
        if rikai[k] < x:
            B = False
            break
    if B == True:
        if minmoney >= money:
            minmoney = money
if minmoney == float('inf'):
    print('-1')
    exit()
print(minmoney)

Measured memory_bytes: 9236