akhauriyash/Code-Regression huggingface dataset:
// Last Change: 03/03/2019 22:18:05.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

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

  ll N = S.size();
  ll zero, one;
  zero = one = 0;
  for (ll i = 0; i < N; ++i) {
    if (S[i] == '0') {
      ++zero;
    } else {
      ++one;
    }
  }
  ll ans = abs(zero - one);
  ans = N - ans;
  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define db long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
 
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define EB emplace_back
#define fi first
#define se second
 
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?x-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
 
#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
 
#define INF ((1ll<<60)-233)
#define sqr(x) ((x)*(x))
#define debug puts("wzpkking")
using namespace std;
int n,a[300005];
int main(){
	scanf("%d",&n);
	For(i,1,n) scanf("%d",&a[i]);
	For(l,1,n) if (a[l]!=l){
		int r=l;
		for (;r<=n;r+=2){
			if (r+1>n||a[r+1]!=r+1) break;
			if (r+2>n||a[r+2]==r+2) break;
		}
		For(i,l,r)
			if (a[i]<l||a[i]>r)
				return puts("No"),0;
		int lv=0,rv=0;
		For(i,l,r)
			if (a[i]<i){
				if (a[i]<lv) return puts("No"),0;
				lv=a[i];
			}
			else if (a[i]>i){
				if (a[i]<rv) return puts("No"),0;
				rv=a[i];
			}
		l=r;
	}
	puts("Yes");
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;
#define ar array 

void test_case() {
	int n , count = 0;
	cin >> n;
	int p = 3;
	vector<int> t(n);
	for(auto &x : t)
		cin >> x;
	set<ar<int,3>> s;
	for(int i = 0 ; i < n  ; i++){
		for(int j = i+1 ; j < n  ; j++){
			for(int k = j+1 ; k < n ; k++){
				vector<int> r = {t[i],t[j],t[k]};
				if(r[0] == r[1] || r[1] == r[2] || r[0] == r[2])
        				continue;
        			sort(r.begin(),r.end());
        			if(r[0] + r[1] > r[2]){
						count++;
					}
			}
		}
	}
	cout<<count;
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T = 1;
	//~ cin >> T;
	while(T--){
		test_case();
	}
}


Measured memory_bytes: 3660
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#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)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

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

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int total=0;
    int i;
    for(i=0;i<=n;i++){
      total = total+i;
    }
    System.out.println(total);
  }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007

using namespace std;

typedef long long ll;

int n, m;
int add(int a, int b)
{
    int x = a+b;
    if(x >= mod)
        x -= mod;
    if(x < 0)
        x += mod;
    return x;
}
int dp[3002][3002][2];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    for(int i = 0; i <= n; ++i)
        dp[0][i][(i == 0)] = 1;
    for(int i = 0; i < m; ++i)
        for(int j = 0; j <= n; ++j)
            for(int k = 0; k <= 1; ++k)
            {
                if(j > 0)
                {
                    dp[i + 1][j - 1][k | (j == 1)] = add(dp[i + 1][j - 1][k | (j == 1)], dp[i][j][k]);
                    dp[i + 1][j][k | (j == 1)] = add(dp[i + 1][j][k | (j == 1)], dp[i][j][k]);
                }
                if(j < n)
                {
                    dp[i + 1][j + 1][k] = add(dp[i + 1][j + 1][k], dp[i][j][k]);
                    dp[i + 1][j][k] = add(dp[i + 1][j][k], dp[i][j][k]);
                }
            }
    int ans = 0;
    for(int i = 0; i <= n; ++i)
        ans = add(ans, dp[m][i][1]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 70656
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static void Main(string[] args) {
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                Console.WriteLine(i + "x" + j + "=" + i * j);
            }
        }
    }
}

Measured memory_bytes: 8768
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;
#define FOR(i, a, b) for (ll i = (ll)(a); i<(ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

TPL<TNM K, TNM V> using umap = unordered_map<K, V>;
TPL<TNM K, TNM V> using uset = unordered_set<K, V>;

TPL <class T = int> inline T IN() { T x; cin >> x; return x; }
TPL<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
void bOUT(bool c, string s, string t) { OUT(c ? s : t); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }
TPL<TNM T> vector<T> make_v(size_t a) { return vector<T>(a); }
TPL<TNM T, TNM... Ts> auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }

TPL<TNM T> using vec2 = decltype(make_v<T>(0, 0));
TPL<TNM T> using vec3 = decltype(make_v<T>(0, 0, 0));
TPL<TNM T> using vec4 = decltype(make_v<T>(0, 0, 0, 0));
TPL<TNM T> using vec5 = decltype(make_v<T>(0, 0, 0, 0, 0));

int main(void) {
	int A, B, X;
	cin >> A >> B >> X;
	YESNO(A <= X && X <= A + B);
	return 0;
}

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

namespace agc004_a
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
            if (x[0] % 2 == 0 || x[1] % 2 == 0 || x[2] % 2 == 0)
            {
                Console.WriteLine(0);
            }
            else
            {
                Array.Sort(x);
                Console.WriteLine(x[0] * x[1]);
            }
        }
    }
}

Measured memory_bytes: 3288
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int area = a*b;
        int length = a*2 + b*2;
        System.out.println(area + " " + length);
        sc.close();
    }
}


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

using namespace std;
vector<vector<int> > g;


pair<int, int> findFarthest(int cur, int par, int dist){
	pair<int, int> ans = {dist, cur};
	for(int adj: g[cur]){
		if(adj == par) continue;
		ans = max(ans, findFarthest(adj, cur, dist+1));
	}
	return ans;
}

int main(){
	int n; cin>>n;
	g.resize(n);
	for(int i = 0; i < n-1; i++){
		int a, b; cin>>a>>b; a--, b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int a = findFarthest(0, -1, 0).second;
	int dia = findFarthest(a, -1, 0).first+1;
	vector<bool> rec(dia+1, 0);
	rec[1] = true;
	rec[2] = false;
	for(int i = 3; i <= dia; i++) rec[i] = (!rec[i-1]) || ( !rec[i-2]);
	if(rec[dia]){
		cout<<"First"<<endl;
	}else{
		cout<<"Second"<<endl;
	}
	
}

Measured memory_bytes: 26880
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define mod 1000000007
int main() { 
    int n;
    cin >> n;
    string s;
    cin >> s;
    int red = 0, white = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') red++;
        else white++;
    }
    int p = 0;
    int ret = 0;
    while ((white != 0) && (red != 0)) {
        if (s[p] == 'W') {
            white--;
            red--;
            ret++;
        }
        else {
            red--;
        }
        p++;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3744
#include <iostream>
using namespace std;
int main()
{int N;
 cin>>N;
 bool can=false;
 for (int a=0;a<=25;a++){
   for (int b=0;b<=14;b++){
     int sum=4*a+7*b;
     if (sum==N) can=true;}
 }
 if (can==true) cout <<"Yes";
 else cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int x;
	for(int i = 0; i < 10000; i++){
		cin >> x;
		if(x){
			cout << "Case " << i+1 << ": " << x << endl;
		}else{
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3080
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int n = Integer.parseInt(br.readLine());
            HashMap<String, Integer> map = new HashMap<String, Integer>();
            for (int i = 0; i < n; i++) {
                String str = br.readLine();
                if (map.containsKey(str)) {
                    int val = map.get(str) + 1;
                    map.put(str, val);
                } else {
                    map.put(str, 1);
                }
            }
            int m = Integer.parseInt(br.readLine());
            for (int j = 0; j < m; j++) {
                String str = br.readLine();
                if (map.containsKey(str)) {
                    int val = map.get(str) - 1;
                    map.put(str, val);
                } else {
                    map.put(str, -1);
                }
            }
            String ansKey = "";
            int max = 0;
            boolean flag = false;
            for (Map.Entry<String, Integer> entry : map.entrySet()) {
                String key = entry.getKey();
                int val = entry.getValue();
                if (flag) {
                    if (max < val) {
                        ansKey = key;
                        max = val;
                    }
                } else {
                    ansKey = key;
                    max = val;
                    flag = true;
                }
            }
            if (max < 0) {
                System.out.println(0);
            } else {
                System.out.println(max);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}


Measured memory_bytes: 21204
#include<stdio.h>

int main(void)
{
	int a,b,c,N,i,d[1000];
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d %d %d",&a,&b,&c);
		if(a*a==b*b+c*c||b*b==a*a+c*c||c*c==a*a+b*b){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}	
	}
	
			
	return 0;
}

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

int main() {
    int a, b, c, k, ans;
    cin >> a >> b >> c >> k;
    if(k>=a+b) ans=min(a, k)-min(c,k-a-b);
    else ans=min(a,k);
    cout << ans;
}

Measured memory_bytes: 3676
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        char[] ch = sc.next().toCharArray();
        pw.println(ch[2]==ch[3] && ch[4]==ch[5] ? "Yes" : "No");
        pw.flush();
    }
}

Measured memory_bytes: 21844
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vc = vector<char>; using vvc = vector<vc>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;


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

  int N; cin>>N;
  string S,T; cin>>S>>T;

  string ans = "";
  REP(i,N) {
    ans += {S[i], T[i]};
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<ll,ll> P;

int main(void){
	          int i;

	          ll K;
	          int N;
	          cin >> N >> K;

	          vector<P> v;
	          for(i=0;i<N;i++){
	        	  ll a,b;
	        	  cin >> a >> b;
	        	  v.push_back(P(a,b));
	          }

	          sort(v.begin(),v.end());

	          int p=-1;
	          ll s=0;
	          for(i=0;i<N;i++){
	        	  s+=v[i].second;
	        	  if(s>=K){
	        		  p=i;
	        		  break;
	        	  }
	          }

	          cout << v[p].first << endl;



	          return 0;
}


Measured memory_bytes: 2420
package main

import ("fmt")

func main(){
  var (
      A int
      B int
      C int
      X int
      y int
      
      
      
      )    
  fmt.Scan(&A)
  fmt.Scan(&B)
  fmt.Scan(&C)
  fmt.Scan(&X)
  y=0
  for i:=0;i<=A;i++{
    for j:=0;j<=B;j++{
      for k:=0;k<=C;k++{
        if 500*i+100*j+50*k==X{
          y = y+1
        }
      }
    }
  }
  fmt.Println(y)
}

Measured memory_bytes: 1768
import qualified Control.Applicative as A

main = do
    _ <- getLine
    p <- map read . words A.<$> getLine
    i <- map read . words A.<$> getLine
    putStrLn $ unwords $ map show $ solve p i

type Node = Int
type Nodes = [Node]
data Tree = Branch Nodes Tree Tree | Empty

solve :: Nodes -> Nodes -> Nodes
solve p i = postOrder t
    where (_, t) = reconstruct p (Branch i Empty Empty)

postOrder :: Tree -> Nodes
postOrder Empty = []
postOrder (Branch n l r) = postOrder l ++ postOrder r ++ n

reconstruct :: Nodes -> Tree -> (Nodes, Tree)
reconstruct [] t = ([], t)
reconstruct (p:ps) t = reconstruct ps (splitBranch p t)

splitBranch :: Node -> Tree -> Tree
splitBranch p t@(Branch n Empty Empty) =
    if p `elem` n
       then let (l, r) = splitNodes n p
                in (Branch [p] (Branch l Empty Empty) (Branch r Empty Empty))
       else t
splitBranch p (Branch n l r) = (Branch n (splitBranch p l) (splitBranch p r))

splitNodes :: Nodes -> Node -> (Nodes, Nodes)
splitNodes [] p = ([], [])
splitNodes (n:ns) p =
    if n == p
       then ([], ns)
       else let (l, r) = splitNodes ns p in ((n:l), r)


Measured memory_bytes: 4140
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var abc = ReadSplitInt();
            if (abc[1] - abc[0] == abc[2] - abc[1])
                Println("YES");
            else
                Println("NO");
        }


        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, k;
    cin >> n >> k;
    vector<lint> a(n + 1);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<lint> imos(n + 1, 0);

    for (int i = 0; i < k; ++i) {
        imos.assign(n + 1, 0);
        for (int i = 0; i < n; ++i) {
            imos[max(0LL, i - a[i])]++;
            imos[min(n, i + a[i] + 1)]--;
        }
        for (int i = 1; i <= n; ++i) {
            imos[i] += imos[i - 1];
        }
        swap(a, imos);
        bool ok = true;
        for (int i = 0; i < n; ++i) {
            if (a[i] != n) {
                ok = false;
                break;
            }
        }
        if (ok)
            break;
    }
    for (int i = 0; i < n; ++i) {
        if (i)
            cout << " ";
        cout << a[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 6364
n=int(input())
a=list(map(int,input().split()))
dp=[0]#dp[i]=左からi番目までで(i//2)個選んだときの最大値
sum_odd=a[0]

dp.append(0)
for i in range(2,n+1):
  if i%2==1:
    sum_odd+=a[i-1]
    dp.append(max(dp[i-1],dp[i-2]+a[i-1]))
  else:
    dp.append(max(sum_odd,a[i-1]+dp[i-2]))
print(dp[n])


Measured memory_bytes: 31688
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstdint>
#include<unordered_map>
#include<sstream>
#include<boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

typedef pair<int, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}


int main()
{
	int n;
	cin >> n;
	vector<int>w(n),sum(n);
	rep(i, n) {
		cin >> w[i];
	}
	int s = 0;
	rep(i, n) {
		s += w[i];
		sum[i] = s;
	}
	int ans = 1e9;
	rep(i, n-1) {
		int s1 = sum[i];
		int s2 = sum[n - 1] - sum[i];
		ans = min(ans, abs(s1-s2));
		//cout << ans << endl;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
n=int(input())
s=input()
ans=0
dpE=[0]*n #その人より右で、Eを向いている人
dpW=[0]*n #その人より左で、Wを向いている人
for i in range(1,n):
    if s[i-1]=="W":
        dpE[i]=dpE[i-1]+1
    else:
        dpE[i]=dpE[i-1]
    if s[n-i]=="E":
        dpW[n-i-1]=dpW[n-i]+1
    else:
        dpW[n-i-1]=dpW[n-i]
print(min([dpE[i]+dpW[i] for i in range(n)]))

Measured memory_bytes: 68188
#include<bits/stdc++.h>
 #define ll long long
 #define ii pair<int,int>
 #define endl '\n'
using namespace std;

void solve()
{ 
    int n, t, cnt = 0;
    cin >> n;
    for(int i=1; i<=n; i++)
    {
        cin >> t;
        if(i%2==1 && t%2==1)
            cnt++;
    }
    cout << cnt << endl;
}

int main(){
    std::ios_base::sync_with_stdio(false); 
    std::cin.tie(nullptr); std::cout.tie(nullptr);
    solve();
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    if(n%10==3) cout<<"bon";
    else if(n%10==0^n%10==1^n%10==6^n%10==8)
        cout<<"pon";
    else cout<<"hon";
    return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>
#define EGARA 4
#define MAISUU 13

int main(void){

  int n;
  int i, j;
  int cards[4][14];
  char egara;
  int rank;

  //initialize

  for(i=0;i<EGARA;i++){
    for(j=1;j<=MAISUU;j++){
      cards[i][j]=0;
    }
  }

  //input

  scanf("%d\n", &n);
  for(i=0;i<n;i++){
    scanf("%c %d\n", &egara, &rank);
    switch(egara){
    case 'S' : cards[0][rank]=1; break;
    case 'H' : cards[1][rank]=1; break;
    case 'C' : cards[2][rank]=1; break;
    case 'D' : cards[3][rank]=1; break;
    default : return(1);
    }
  }
    

  //output

  for(j=1;j<=MAISUU;j++){
    if(cards[0][j]==0){
      printf("%c %d\n", 'S', j);
    }
  }
  for(j=1;j<=MAISUU;j++){
    if(cards[1][j]==0){
      printf("%c %d\n", 'H', j);
    }
  }
  for(j=1;j<=MAISUU;j++){
    if(cards[2][j]==0){
      printf("%c %d\n", 'C', j);
    }
  }
  for(j=1;j<=MAISUU;j++){
    if(cards[3][j]==0){
      printf("%c %d\n", 'D', j);
    }
  }

  return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
int main(void){
  int i,count;
  char a[4];
  scanf("%s",&a);
  count=0;
  for(i=0;i<3;i++){
    //printf("%c\n",a[i]);
    //printf("%d\n",a[i]);
  	if(a[i]=='1'){
      count+=1;
    }
  }
  printf("%d",count);
  return 0;
}

Measured memory_bytes: 128
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto rgbn = readln.split.to!(int[]);
    auto R = rgbn[0];
    auto G = rgbn[1];
    auto B = rgbn[2];
    auto N = rgbn[3];

    int ret;
    foreach (r; 0..3001) {
        foreach (g; 0..3001) {
            auto rest = N - R*r - G*g;
            if (rest == 0 || (rest > 0 && rest%B == 0)) ++ret;
        }
    }
    writeln(ret);
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
A = [a,b,c,d,e]
ind = 0
for i in range(4):
    for j in range(i+1,5):
        if A[j]-A[i]>k:
            ind = 1
            break
    if ind==1:break
if ind==1:
    print(":(")
else:
    print("Yay!")

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

bool acceptable(const vector<int> w, int i) {
  const vector<int> tanku = {5, 7, 5, 7, 7};
  for (int ku : tanku) {
    int sum = 0;
    while (sum < ku) {
      sum += w[i++];
    }
    if (sum != ku) {
      return false;
    }
  }
  return true;
}

int main() {
  int N;
  while (cin >> N && N) {
    vector<int> W(N);
    for (int i = 0; i < N; ++i) {
      string str;
      cin >> str;
      W[i] = str.length();
    }
    for (int i = 1; i <= N; ++i) {
      if (acceptable(W, i - 1)) {
        cout << i << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 3152
n = int(input())
lst_x = list(map(int, input().split()))
lst = lst_x[:]
lst.sort()
b1 = lst[n//2 - 1]
b2 = lst[n//2]


for x in lst_x:
    if x <= b1:
        ans = b2
    else:
        ans = b1
    print(ans)

Measured memory_bytes: 25220
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000
int MOD=1000000007;
struct edge {
    int to, cost;
};

int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}

map<int,int> factor(int n){
  map<int,int>res;
  for(int i=2;i*i<=n;i++){
      for(; n%i==0;n/=i) res[i]++;
  }
  if(n>1)res[n]++;
  return res;
}
////////////////////////////////////////////////////////////

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

  vector<int>u(n);
  int onaji=0;
  rep(i,n-1){
    if(onaji>=1){
      if(a[i]==a[i+1])continue;
      else if(a[i]>a[i+1]){u[onaji-1]=1;onaji=0;}
      else {u[onaji-1]=-1;onaji=0;}
    }
    else{
    if(a[i]<a[i+1]){u[i]=-1;}
    if(a[i]==a[i+1]){onaji=i+1;}
    if(a[i]>a[i+1]){u[i]=1;};
  }
}
  int motikabu=0,gold=1000;
  rep(i,n-1){
    if(u[i]==1){gold+=motikabu*a[i];motikabu=0;}
    else if(u[i]==-1){motikabu+=gold/a[i];gold-=gold/a[i]*a[i];}
  //  cout<<gold<<' '<<motikabu<<endl;

}
gold+=motikabu*a[n-1];
cout<<gold<<endl;
}


Measured memory_bytes: 3368
using System;
using System.Collections.Generic;

namespace abc129_b
{
  class Program
  {
    static void Main(string[] args)
    {
      var n = CIn.ReadInt();
      var w = CIn.ReadIntArray(n);

      var sum = new int[n + 1];

      for (var i = 1; i <= n; i++)
      {
        sum[i] = sum[i - 1] + w[i - 1];
      }

      var diff = new int[n - 1];

      for (var i = 1; i < n; i++)
      {
        diff[i - 1] = Math.Abs(sum[n] - sum[i] - sum[i]);
      }

      Array.Sort(diff);

      Console.WriteLine(diff[0]);
    }
  }


  class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }

      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }

      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }

      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }

      return array;
    }
    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }

      return array;
    }
  }
}

Measured memory_bytes: 13268
#define _USE_MATH_DEFINES

#include <iostream>
#include <iterator>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <unordered_set>
#include <climits>
#include <ctime>

using namespace std;
using ll = long long;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;

const int S = 26;

void solve() {
	string s;
	getline(cin, s);
	vector<int> dp(s.size() + 1, inf);
	dp[0] = 0;
	vector<int> match((1 << S), inf);
	match[0] = 0;
	int curr_mask = 0;
	for (int i = 1; i <= s.size(); ++i) {
		char c = s[i - 1];
		curr_mask ^= (1 << int(c - 'a'));
		for (int j = 0; j < 26; ++j)
			dp[i] = min(dp[i], match[curr_mask ^ (1 << j)] + 1);
		dp[i] = min(dp[i], match[curr_mask] + 1);
		match[curr_mask] = min(match[curr_mask], dp[i]);
	}
	cout << dp[s.size()];
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	solve();

#ifdef LOCAL
	cerr << double(clock()) / CLOCKS_PER_SEC << " sec" << endl;
#endif
	return 0;
}

Measured memory_bytes: 263556
program ABC154_D
  integer::N,K
  double precision,allocatable::p(:),a(:),b(:),c(:)
  read(*,*)N,K
  allocate(p(N),a(N),b(N),c(N))
  read(*,*)p
  do i=1,N
     a(i)=(p(i)+1.0)/2.0
  end do
  b(1)=a(1)
  do i=2,N
     b(i)=b(i-1)+a(i)
  end do
  c(1)=sum(a(1:K))
  do i=1,N-K
     c(i)=b(K+i)-b(i)
  end do
  ans=maxval(c)
  write(*,*)ans
end program ABC154_D

Measured memory_bytes: 7040
n = input()

if n[len(n)-1] == "0" or n[len(n)-1] == "1" or n[len(n)-1] == "6" or n[len(n)-1] == "8":
	print("pon")
elif n[len(n)-1] == "3":
	print("bon")
else:
	print("hon")

Measured memory_bytes: 9056
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
ll maxl(ll a, ll b){ return ((a<b)?b:a);}
ll minl(ll a, ll b){ return ((a>b)?b:a);}
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin >> s >> t;
    int n = s.length();
    int m = t.length();
    int ans = INT_MAX;
    for (int i=0;i<=n-m;i++){
        int count = 0;
        for (int j=0;j<m;j++){
            if (s[i+j]!=t[j]){
                count++;
            }
        }
        ans = min(ans,count);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3656
N,M = map(int,input().split())
data =[[] for i in range(N+1)]
for i in range(M):
  a,b = map(int,input().split())
  data[a].append(b)
  data[b].append(a)

def dfs(cur,*a): #現在地、通った場所→
  if cur in a:
    return 0
  else:
    if len(a) == N-1:
      return 1
    else:
      a = list(a)
      a.append(cur)
      count = 0
      for i in data[cur]:
        count += dfs(i,*a)
      return count
print(dfs(1,*[]))

Measured memory_bytes: 3188
parseLs :: IO [Int]
parseLs = (fmap read . words) <$> getLine

main = do
    [n,m,c] <- parseLs
    bs <- parseLs
    rs <- sequence $ replicate n (solve c bs)
    print $ length $ filter (>0) rs

solve :: Int -> [Int] -> IO Int
solve c bs = do
    xs <- parseLs
    return $ calc c bs xs

calc :: Int -> [Int] -> [Int] -> Int
calc c bs xs = foldl (+) c $ zipWith (*) bs xs

Measured memory_bytes: 1020
#include <iostream>
using namespace std;
int main()
{
	int N,i;
	cin>>N;
	long long str[N];
	str[0]=2;str[1]=1;
	for(i=2;i<=N;i++){
		str[i]=str[i-1]+str[i-2];
	}
	cout<<str[N]<<endl;
	return 0;
} 

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;
  vector<unsigned long long> lucas(n + 1);
  lucas[0] = 2ull;
  lucas[1] = 1ull;
  for (int i = 2; i < lucas.size(); ++i) {
    lucas[i] = lucas[i - 1] + lucas[i - 2];
  }

  cout << lucas[n] << '\n';
  return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s[1]=='B')
    {
        cout<<"ARC"<<endl;
    }
    else if(s[1]=='R')
    {
        cout<<"ABC"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3588
#include <cstdio>
#include <string>
#include <iostream>
#include <math.h>

using namespace std;



int main(void){

    

    long n,k;
    cin >>n>>k;
    string ans;

    int *a = new int[n];

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

    int d,t;
    for(int i = 0; i < k; i++) {
        cin>>d;
        for(int j = 0; j < d; j++) {
            cin>>t;
            a[t-1] = 0;
        }
    }
    int sum = 0;
    for(int i = 0 ; i < n; i++) {
        sum+=a[i];
    }


    cout<< sum;


    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define P pair<int,int>
#define ll long long
const int N = 505;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    for(int i=1;i<=n;i++)
    {
        cout<<"x";
    }
    return 0;
}


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

using namespace std;
#define ll long long

int n, f[10][10];
ll ans;
int main() {
	scanf("%d", &n);
	for(int i=1; i<=n; ++i){
		int x=i;
		while(x>=10) x/=10;
		++f[x][i%10];
	}
	for(int i=1; i<=n; ++i){
		int x=i;
		while(x>=10) x/=10;
		ans+=f[i%10][x];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
include Math

n = gets.to_i
p = n.times.map{|i|gets.split.map(&:to_f).push(i)}.sort
ans = Array.new(n,0.0)

l = []
a = p[0]
while a != l[0]
    l.push(a)
    b = p[0]
    for i in 1..n-1
        if b == a
            b = p[i]
        else
            v = (b[0]-a[0])*(p[i][1]-a[1])-(p[i][0]-a[0])*(b[1]-a[1])
            if v > 0 || (v == 0 && (p[i][0]-a[0])**2+(p[i][1]-a[1])**2 > (b[0]-a[0])**2+(b[1]-a[1])**2)
                b = p[i]
            end
        end
    end
    a = b
end

s = l.size
s.times do |i|
    u = atan(-(l[i-1][0]-l[i][0])/(l[i-1][1]-l[i][1]))
    v = atan(-(l[(i+1)%s][0]-l[i][0])/(l[(i+1)%s][1]-l[i][1]))
    u += PI if u-v <= 0
    ans[l[i][2]] = (u-v)/2/PI
end
puts ans

Measured memory_bytes: 1788
import java.util.Scanner;

class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    for(int i = 0; i < m; i++){
      n -= sc.nextInt();
    }
    if(n<0){
      System.out.println(-1);
    } else {
      System.out.println(n);
    }
  }
}

Measured memory_bytes: 46304
#include <stdio.h>

int main(void) {
	int N,A, B;
	scanf("%d%d%d",&N, &A, &B);
	if (N*A <= B) {
		printf("%d\n", N*A);
	}
	else {
		printf("%d\n", B);
	}

	return 0;

}

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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define REP(i,n) for(int i=0; i < (n); ++i)
#define SIZE(c) (int) (c).size()
#define ALL(c) (c).begin(), (c).end()
#define PB push_back
#define MP make_pair
#define ST first
#define ND second
#define FWD(i,a,b) for (int i=(a); i<(b); ++i)
#define BCK(i,a,b) for (int i=(a); i>(b); --i)
#define PI 3.14159265358979311600
#define pb push_back
#define mp make_pair
#define st first
#define nd second

using namespace std;

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

typedef vector < int > VI;
typedef vector<ll> VL;

typedef long double K;

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

	string s;
	cin >> s;
	int found = 0;
	REP(i, SIZE(s)-1) {
		if (s[i] == 'A' && s[i+1] == 'C') found = 1;
	}
	cout << (found ? "Yes" : "No") << '\n';

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

const int inf=1e9+10;
const int maxn=25;
const ll mod=1e9+7;

ll dp[maxn][1<<21];
int n,a[maxn][maxn];

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++) for(int j=0;j<n;j++)
		scanf("%d",&a[i][j]);
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		for(int mask=0;mask<(1<<n);mask++){
			if(dp[i][mask]<=0) continue;
		//	cout<<i<<" "<<mask<<" "<<dp[i][mask]<<endl;
			for(int j=0;j<n;j++){
				if((!(mask&(1<<j)))&&a[i][j]==1){
					ll &t=dp[i+1][mask|(1<<j)];
					t+=dp[i][mask];
					if(t>=mod) t-=mod;
				//	cout<<i<<" "<<j<<" "<<t<<endl;
				}
			}
		}
	}
	printf("%d\n",dp[n][(1<<n)-1]);
}

Measured memory_bytes: 311552
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    ll num = x / d;
    if(k <= num){
        cout << x - k*d << endl;
        return 0;
    }

    x -= num * d;
    k -= num;
    if(k % 2 == 1){
        x -= d;
        x = abs(x);
    }
    cout << x << endl;
    return 0;
}




Measured memory_bytes: 3628
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        m: usize,
        a: [usize; n],
        mut bc: [(usize, usize); m]
    }
    for x in a {
        bc.push((1, x));
    }
    bc.sort_by(|x, y| y.1.cmp(&x.1));
    let mut ans = 0;
    let mut rest = n;
    for (b, c) in bc {
        if b <= rest {
            ans += b * c;
            rest -= b;
        } else {
            ans += rest * c;
            break;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 14588
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>

int main() {
	int n;
	std::cin >> n;
	std::vector<int>a(n);
	for (int i = 0;i < n;i++) {
		std::cin >> a[i];
	}
	std::sort(a.rbegin(), a.rend());
	int ans = 1;
	for (int i = 0;i < n-1;i++) {
		if (a[i] != a[i + 1])
			ans += 1;
	}
	std::cout << ans << std::endl;
	return 0;
}



Measured memory_bytes: 256
#include<algorithm>
#include<queue>
#include<stdio.h>
#include<stdlib.h>
#include<vector>

using namespace std;

int main(void){
	int N = 0, M = 0;
	int a[55] = { 0 };
	int b[55] = { 0 };
	int ans = 0;

	scanf("%d%d", &N,&M);
	for (int i = 0; i < M; i++)
		scanf("%d%d", &a[i], &b[i]);

	for (int i = 0; i < M; i++){
		bool frag[55] = { false };
		queue<int> q;
		q.push(b[i]);
		frag[b[i]] = true;
		while (!q.empty()){
			for (int j = 0; j < M; j++){
				if (q.front() == a[j] && frag[b[j]] == false && j != i){
					q.push(b[j]);
					frag[b[j]] = true;
				}
				if (q.front() == b[j] && frag[a[j]] == false && j != i){
					q.push(a[j]);
					frag[a[j]] = true;
				}
			}
			q.pop();
		}

		bool tf = true;
		for (int k = 1; k < N; k++){
			if (frag[k] == false)
				tf = false;
		}
		if (!tf)
			ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
const int mod=1e9+7;
/* 
UnionFind：素集合系管理の構造体(union by size)
isSame(x, y): x と y が同じ集合にいるか。 計算量はならし O(α(n))
unite(x, y): x と y を同じ集合にする。計算量はならし O(α(n))
treeSize(x): x を含む集合の要素数。
*/
struct UnionFind{
 vector<int>size,parents;
 UnionFind(){}
 UnionFind(int n){//make n trees.
  size.resize(n,0);
  parents.resize(n,0);
  for(int i=0;i<n;i++)makeTree(i);
 }
 void makeTree(int x){
   parents[x]=x;//the parent of x is x
   size[x]=1;
  }
 bool isSame(int x,int y){return findRoot(x)==findRoot(y);}
 bool unite(int x,int y){
  x = findRoot(x);
  y = findRoot(y);
  if(x==y)return false;
  if(size[x]>size[y]){
   parents[y]=x;
   size[x]+=size[y];
  } 
  else{
   parents[x]=y;
   size[y]+=size[x];
  }
  return true;
 }
 int findRoot(int x){//木の根を探す,計算量削減のため低く
  if(x!=parents[x])parents[x]=findRoot(parents[x]);
  return parents[x];
 }
 int treeSize(int x){return size[findRoot(x)];}
};
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*迷路移動*/const int dx[4]={1,0,-1,0};const int dy[4]={0,1,0,-1};
llfor;////////////////////////////////////////////////////////////
int main(){
 ll n,score=0;
 vector<ll>vc;
 cin>>n;
 ll ed=cei(n,2);
 ll a,b;
 rep(i,0,n){
  cin>>a>>b;
  score-=b;
  vc.push_back(a+b);
 }
 sort(all(vc));
 reverse(all(vc));
  
 ll cnt=0;
 for(i=0;cnt<ed;++i){
  score+=vc[i];
  cnt++;
  i++;
 }
 pr(score);
 return 0;}

Measured memory_bytes: 4316
#include <bits/stdc++.h>
using namespace std;
const int N=110;
int a[N];
int n,m,sum=0,ans=0;
int main(){
	
	scanf("%d%d",&n,&m); 
	for(int i=1;i<=n;++i){
		scanf("%d",a+i);
		sum+=a[i];
	}
	
	int k=sum/(4*m);
	if(k*4*m!=sum)k+=1;
	
	for(int i=1;i<=n;++i)
		if(a[i]>=k)++ans;
	
	if(ans>=m)printf("Yes\n");
	else printf("No\n");
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,p;
  while(cin>>n>>p, n){
    int vi[51]={};
    int i=0;
    while(1){
      int flag = 0;
      if(p){
        vi[i]++;
        p--;
      }
      else{
        p=vi[i];
        vi[i]=0;
      }
      for(int j=0;j<n;++j)
        if(j!=i && vi[j]) flag=1;
      if(flag==0 && p==0){
        cout<<i<<endl;
        break;
      }
      i++;
      if(i==n) i=0;
    }
  }
  return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int solve(int n, int d){
    vector<vector<int>> v(n);
    vector<int> u(n);
    for (int i = 0; i < n; ++i) {
        int m;
        cin >> m;
        vector<int> tmp(m);
        for (auto &&j : tmp) scanf("%d", &j);
        v[i] = tmp;
        u[i] = accumulate(tmp.begin(),tmp.end(), 0);
    }
    int ok = 1;
    while(ok){
        ok = 0;
        for (int i = 0; i < n; ++i) {
            if(!v[i].empty()){
                u[i] -= v[i].back();
                auto p = minmax_element(u.begin(),u.end());
                if(*p.second-*p.first <= d){
                    ok = 1;
                    v[i].pop_back();
                }else {
                    u[i] += v[i].back();
                }
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        if(!v[i].empty()) return 0;
    }
    return 1;
}

int main() {
    int n, d;
    while(cin >> n >> d, n){
        puts(solve(n, d) ? "Yes" : "No");
    }
    return 0;
}


Measured memory_bytes: 3204