akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF=1e18;
const int MAX=40;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,T; cin >> N >> T;
    vector<pair<ll,ll>> shop;
    vector<ll> a0;
    for (int i=0;i<N;++i){
        ll a,b; cin >> a >> b;
        if (a) shop.emplace_back(a,b);
        else a0.emplace_back(b);
    }
    sort(shop.begin(),shop.end(),[](auto p,auto q){
        return p.first*(q.second+1)>q.first*(p.second+1);
    });
    sort(a0.begin(),a0.end());
    int n=shop.size(),m=a0.size();
    vector<vector<ll>> dp(n+1,vector<ll>(MAX,INF));
    dp[0][0]=0;
    for (int i=0;i<n;++i){
        int a=shop[i].first,b=shop[i].second;
        for (int j=MAX-1;j>=0;--j){
            if (dp[i][j]>T) continue;
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
            if (j+1<MAX) dp[i+1][j+1]=min(dp[i+1][j+1],(a+1)*(dp[i][j]+1)+b);
        }
    }
    vector<ll> sum(m+1,0);
    for (int i=0;i<m;++i) sum[i+1]=sum[i]+a0[i]+1;
    int ans=0;
    for (int j=0;j<MAX;++j){
        if (dp[n][j]>T) continue;
        int add=upper_bound(sum.begin(),sum.end(),T-dp[n][j])-sum.begin()-1;
        ans=max(ans,j+add);
    }
    cout << ans << '\n';
}

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

int main() {
  string str ="ABCDEF";
  string X,Y;
  cin >> X >> Y;
  int x,y;
  
  if(X == "A"){
  x = 10;
  }
  if(Y == "A"){
  y = 10;
  }
  if(X == "B"){
  x = 11;  
  }
  if(Y == "B"){
  y =11;
  }
  if(X == "C"){
  x = 12;  
  }
  if(Y == "C"){
  y =12;
  }
  if(X == "D"){
  x = 13;  
  }
  if(Y == "D"){
  y =13;
  }
  if(X == "E"){
  x = 14;  
  }
  if(Y == "E"){
  y =14;
  }
  if(X == "F"){
  x = 15;  
  }
  if(Y == "F"){
  y =15;
  }
  
  if(x<y){
  cout << "<" << endl;
  }
  if(x == y){
  cout << "=" << endl;
  }
  if(x > y){
  cout << ">" << endl;
  }
}







Measured memory_bytes: 256
n, m = gets.chomp.split.map(&:to_i)
k_list_list = (1..m).map do
  gets.chomp.split.map(&:to_i)
end

p_list = gets.chomp.split.map(&:to_i)


def main(n, m, k_list_list, p_list)

  ans = 0;
  (0..2**n - 1).each do |n_ten|
    n_two = n_ten.to_s(2).rjust(n, '0')
    all_switch_statuses = n_two.chars.map(&:to_i)

    light_statuses = (0..m-1).map do |light_index|
      switch_indexes = k_list_list[light_index][1..]
      is_on = switch_indexes.map{ |index| 
        all_switch_statuses[index - 1] 
      }.sum % 2 === p_list[light_index]
    end

    unless light_statuses.include?(false)
      ans += 1
    end
  end
  ans
end

puts main(n, m, k_list_list, p_list)


# require 'minitest/autorun'

# class FooTest < Minitest::Test
#   def test_case1
#     assert_equal(1, main(2, 2, [[2, 1, 2], [1, 2]], [0, 1]))
#   end
# end





Measured memory_bytes: 14448
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int N, total = 0;
vector<vector<int>> visited( 100 + 1, vector<int>( 10000 + 1, -1 ) );
vector<int> vc;
bool dfs( int i, int sum )
{
    if( i == 0 )
    {
        if( sum % 10 != 0  )
        {
            total = max( total, sum );
        }
        return sum == 0;
    }
    if( visited[ i ][ sum ] >= 0 )
    {
        return visited[ i ][ sum ];
    }
    return ( visited[ i ][ sum ] = dfs( i - 1, sum ) || dfs( i - 1, sum - vc[ i - 1 ] ) );
}
int main()
{
    cin >> N;
    vc.resize( N );
    for( auto &x : vc )
    {
        cin >> x;
    }
    dfs( N, accumulate( ALL( vc ), 0 ) );
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 4860
from itertools import combinations_with_replacement as c

N, M, Q = map(int, input().split())
L = [tuple(map(int, input().split())) for _ in range(Q)]

print(max([sum(d if S[b-1] - S[a-1] == c else 0 for a, b, c, d in L) for S in c(range(1, M+1), N)]))

Measured memory_bytes: 12548
#include <iostream>
using namespace std;
int n, c[130], m[130];
string a;
int main() {
	int i;
	for(i=97; i<123; i++) m[i] = 55;
	cin>>n;
	while(n--) {
		cin>>a;
		for(i=0; a[i]; i++) c[a[i]]++;
		for(i=97; i<123; i++) m[i] = min(m[i], c[i]), c[i]=0;
	}
	for(i=97; i<123; i++) while(m[i]--) putchar(i);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int MAX = 1000005;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

vector<int> to[MAX];
bool check[MAX];

void dfs(int v){
  if(check[v]==0){
    check[v] = 1;
    for(auto &u : to[v]){
      dfs(u);
    }
  }
}  

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> x(m),y(m),z(m);
  rep(i,m){
    cin >> x[i] >> y[i] >> z[i];
    x[i]--;
    y[i]--;
    to[x[i]].push_back(y[i]);
    to[y[i]].push_back(x[i]);
  }
  int ans = 0;
  rep(i,n) check[i] = 0;
  rep(i,n){
    if(check[i] == 0){
      dfs(i);
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}




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

int main()
{
	int N, K, answer;

	cin >> N >> K;
		
	answer = K;

	for (int i = 2; i <= N; i++) {	
		answer *= (K-1);
	}
	
	cout << answer  << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
using std::cin;
using std::cout;
using std::endl;
using std::ios;
using vint = std::vector<int>;
using ll = long long;
using vll = std::vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = std::min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = std::max(a, b); }

int N;
int L[52];
int dp[52][52000];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int length[1001];
    length[0] = 0;
    FOR(i, 1, 1000) {
        length[i] = length[i - 1] + i;
    }
    int a, b;
    cin >> a >> b;
    int ans = 0;
    FOR(i, 1, 999) {
        if(length[i] - a > 0 && length[i + 1] - b > 0) {
            if((length[i] - a) == (length[i + 1] - b)) ans = (length[i] - a);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T> >;

static const int INTINF = (2147483647 >> 1); // 10^9 + 5000
static const ll LLINF = (9223372036854775807 >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Kunitaka{
    template<
        typename TYPE,
        std::size_t SIZE
    >
    std::size_t array_length(const TYPE (&array)[SIZE])
    {
        return SIZE;
    }

    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
}
using namespace Kunitaka;
namespace Printer{
    void br(){
        cout << endl;
    }

    void loop_cnt(int i){
        cout << "i = " << i << endl;
    }

    void loop_cnt(int i, int j){
        cout << "i = " << i << ", " << "j = " << j << endl;
    }

    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T, class S>
    void print(T x, S y){
        cout << x << "," << y << endl;
    }

    template<class T, class S, class U>
    void print(T x, S y, U z){
        cout << x << "," << y << "," << z << endl;
    }

    template<class T, class S>
    void print(pair<T, S> p){
        cout << p.first << ", " << p.second << endl;
    }

    template<
        typename TYPE,
        std::size_t SIZE
    >
    void print(const TYPE (&array)[SIZE]){
        int lim = array_length(array);
        for(int i=0; i<lim; i++){
            if(i) cout << " ";
            cout << array[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<S> v){
        for(int i=0; i<v.size(); i++){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<vector<S> > vv){
        for(int i=0; i<vv.size(); i++){
            for(int j=0; j<vv[i].size(); j++){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void yesno(bool x){
        if(x) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
};
using namespace Printer;

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//


    // input
    cout << fixed << setprecision(10);
    int a, b; cin >> a >> b;
    if(a <= 9 && b <= 9){
        cout << a * b << endl;
        return 0;
    }
    else{
        cout << -1 << endl;
        return 0;
    }
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

map<int, int> m;
vector<int> divisor(int n)
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n)
                ret.push_back(n / i);
        }
    }
    return (ret);
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i,n){
        cin >> a[i];
        m[a[i]]++;
    }
    int ans=0;
    REP(i,n){
        if(m[a[i]]>1){
            continue;
        }
        vector<int> ret=divisor(a[i]);
        bool flag=false;
        for(auto& j:ret){
            if(j==a[i]){
                continue;
            }
            if(m[j]>0){
                flag=true;
                break;
            }
        }
        if(flag){
            continue;
        }
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 33040
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N = 0;
  int64_t S = 2;
  int64_t B1, B2;
  
  cin >> N;
  
  for(int i = 0; i <= N; i++) {
    if (i == 0) {
      S = 2;
      B2 = 2;
    }  
    else if (i == 1) {
      S = 1;
      B1 = 1;
    }
    else {
      S = B1 + B2;
      B2 = B1;
      B1 = S;
    }  
  }  
  
  cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include<set> 
#include<math.h>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
#define ll long long;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int Alice=0, Bob=0;
  for(int i=0;i<n;i=i+2){
    Alice += a[i];
  }
  for(int i=1;i<n;i=i+2){
    Bob += a[i];
  }
  
  cout<<abs(Alice-Bob)<<endl;

}


Measured memory_bytes: 256
n, a, b, c, d = map(int, input().split())
s = list(input())
a -= 1
b -= 1
c -= 1
d -= 1
jump = True
if d < c:
    cnt = 0
    for i in range(b-1,d+2):
        if s[i] == '.':
            cnt += 1
        if cnt == 3:
            break
        if s[i] == '#':
            cnt = 0
    else:
        jump = False
cnt = 0
for i in range(a,c):
    if s[i] == '#':
        cnt += 1
    if s[i] == '.':
        cnt = 0
    if cnt == 2:
        jump = False
        break
for i in range(b,d):
    if s[i] == '#':
        cnt += 1
    if s[i] == '.':
        cnt = 0
    if cnt == 2:
        jump = False
        break
if jump:
    print('Yes')
else:
    print('No')

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

int main(){
  int n;
  string ans="APPROVED";
  cin >> n;
  vector<int> a(n);
  rep(i, n){
    cin >> a[i];
    if(a[i]%2==0){
      if(a[i]%3==0||a[i]%5==0){
        ans="APPROVED";
      }
      else{
        ans="DENIED";
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3576
s=input()
fi=''
la=''
a=0
b=0
n=len(s)
if(s[:]==s[::-1]):
    for i in range(0,((n-2)//2)+1):
        fi+=s[i]
#    print(fi)    
    for i in range((n+2)//2,n):
        la+=s[i]
#    print(la)    
    if(fi[:]==fi[::-1]):
        a=1
    if(la[:]==la[::-1]):
        b=1
    if(a==1 and b==1):
        print("Yes")
    else:
        print("No")
else:
    print("No")        

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int[] w = new int[10];
		int[] k = new int[10];
		
		for(int i = 0; i < 10; i++){
			w[i] = sc.nextInt();
		}
		
		for(int i = 0; i < 10; i++){
			k[i] = sc.nextInt();
		}
		
		Arrays.sort(w);
		Arrays.sort(k);
		
		System.out.println((w[9] + w[8] + w[7]) + " " + (k[9] + k[8] + k[7]));
	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

LL X, Y, x, y;

int main() {
	cin >> X >> Y >> x >> y;
	
	printf("%.12f %d\n", X * Y * 0.5, (2 * x == X && 2 * y == Y ? 1 : 0));
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
#define all(v) (v).begin(),(v).end()
typedef pair<ll,ll> P;
#define fi first
#define se second
set<string> c;
map<ll,ll> mp;
const ll inf=100000000000000000;
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}

int main(){
ll n,t;
cin>>n>>t;
vector<ll> a(n);
for(int i=0;i<n;i++)cin>>a.at(i);
ll ans=t,now=t;
for(int i=1;i<n;i++){
   ans+=min(a.at(i)-a.at(i-1),t);
}
cout<<ans<<endl;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int main(){
	cin.sync_with_stdio(false);
	int n;
	string s;
	cin >> n >> s;

	int max = 0, cnt = 0;
	rep(i,n){
		cnt += (s[i] == 'I') ? 1 : -1;
		if (max < cnt) {
			max = cnt;
		}
	}
	cout << max << endl;

	return 0;
}

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

using namespace std;

int main() {
   ll n,a,b;
   cin>>n>>a>>b;
   if((b-a)%2==0)cout<<(b-a)/2;
   else {
       cout<<min(a-1,n-b)+1+(b-a)/2;
   }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	ios_base::sync_with_stdio(false);
	long int w,h,x,y;
	bool flag=false;
	cin>>w>>h>>x>>y;
	if ((x*2==w)and(y*2==h))
	{
		flag=true;
	}
	cout<<fixed<<setprecision(10)<<((w*h)/2.0)<<" ";
	flag?cout<<1<<endl:cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 256
def main():

    N = int(input())
    A = []
    for _ in range(N):
        B = list(map(int, input().split()))
        A.append(B)
    A.sort(key=lambda x: x[1])
    time = 0
    for i in range(N):
        time += A[i][0]
        if time > A[i][1]:
            print("No")
            exit()
        else:
            continue
    print("Yes")

if __name__ == "__main__":
    main()

Measured memory_bytes: 53684
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>
#include <limits>
#include <iostream>

using namespace std;


map<long long, long long> dp;
long long a, b, c, d;

long long rec(long long n) {
  if (n == 0) return 0;
  if (n == 1) return d;
  auto I = dp.find(n);
  if (I != dp.end()) return I->second;
  long long best = LLONG_MAX;
  if (n % 2 == 0) {
    best = min(best, a + rec(n / 2));
  }
  if (n % 3 == 0) {
    best = min(best, b + rec(n / 3));
  }
  if (n % 5 == 0) {
    best = min(best, c + rec(n / 5));
  }
  if (LLONG_MAX / d > n) {
    best = min(best, d*n);
  }
  for (int i = -5; i <= 5; i++) {
    long long m = n + i;
    if (m < 0) continue;
    if (m % 2 == 0 && m / 2 < n) {
      best = min(best, abs(i) * d + a + rec(m/2));
    }
    if (m % 3 == 0 && m / 3 < n) {
      best = min(best, abs(i) * d + b + rec(m/3));
    }
    if (m % 5 == 0 && m / 5 < n) {
      best = min(best, abs(i) * d + c + rec(m/5));
    }
  }
  dp[n] = best;
  return best;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  while (T-- > 0) {
    long long n;
    cin >> n >> a >> b >> c >> d;
    dp.clear();
    long long ans = rec(n);
    cout << ans << "\n";
  }

  return 0;
}


Measured memory_bytes: 7084
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const long long MOD = 998244353;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())
constexpr auto PI = 3.14159265358979323846264338327950L;
int needleX[4] = { -1,0,1,0 };
int needleY[4] = { 0,1,0,-1 };


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a;
    for (int i = 0; i < 5; ++i) {
        cin >> a;
        if (!a) {
            cout << i + 1 << endl;
            return 0;
        }
    }
    

    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

const int N = 1e5 + 1;
vi adj[N];
bool vis[N];
int dp[N];

void dfs(int u) {
	if (vis[u]) return;
	vis[u] = true;
	dp[u] = 0;
	for (int v : adj[u]) {
		dfs(v);
		dp[u] = max(dp[u], dp[v] + 1);
	}

}

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		adj[u].push_back(v);
	}
	int ans = 0;
	for (int u = 1; u <= n; u++) {
		dfs(u);
		ans = max(ans, dp[u]);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,q;
  cin>>n>>q;
  string s;
  cin>>s;
  vector<int> ns(n);
  ns.at(0)=0;
  for(int i=1;i<n;i++){
    if(s.at(i-1)=='A'&&s.at(i)=='C'){ns.at(i)=ns.at(i-1)+1;}
    else{ns.at(i)=ns.at(i-1);}
  }
  for(int i=0;i<q;i++){
    int l,r;
    cin>>l>>r;
    l--;r--;
    if(l==0){cout<<ns.at(r)<<endl;continue;}
    else{cout<<ns.at(r)-ns.at(l)<<endl;continue;}
  }
}

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

using namespace std;

#define ll long long

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

  int t;
  cin >> t;
  int ac = 0, wa = 0, tle = 0, re = 0;
  while (t--) {
    string s;
    cin >> s;
    if (s == "AC")
      ac++;
    else if (s == "WA")
      wa++;
    else if (s == "TLE")
      tle++;
    else
      re++;
  }
  cout << "AC x " << ac << "\n";
  cout << "WA x " << wa << "\n";
  cout << "TLE x " << tle << "\n";
  cout << "RE x " << re << "\n";

  return 0;
}

Measured memory_bytes: 3608
N = int(input())
L = list(map(int, input().split()))

L.sort()
count = 0

for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):             
            if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]:
                continue
            if L[i] + L[j] > L[k]:
                count += 1

print(count)

Measured memory_bytes: 9112
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

template<typename V>
constexpr string join(const V &v, const string &sep) {
  stringstream ss;
  if (v.size()) ss << v[0];
  loop(i, 1, v.size()) ss << sep << v[i];
  return ss.str();
}

void solve() {
  vi t = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1};
  int n;
  cin >> n;
  while (n--) {
    int a, b;
    cin >> a >> b;
    int i = distance(t.begin(), find(all(t), a));
    vi v;
    for (;;) {
      v.pb(t[i]);
      i = (i + 1) % t.size();
      if (t[i] == b) break;
      if (t[i] == a) v.clear();
    }
    v.pb(t[i]);
    cout << join(v, " ") << endl;
  }
}

Measured memory_bytes: 3156
N, M, Q = map(int, input().split())
q_list = list()
for _ in range(Q):
     q_list.append( tuple( map(int, input().split()) ) )

from itertools import combinations_with_replacement
A_conbi = combinations_with_replacement(range(1,M+1), N)

max_v = 0
for A in A_conbi:
    sum_v = 0
    for a,b,c,d in q_list:
        if A[b-1]-A[a-1] == c:
            sum_v = sum_v + d
    max_v = max(max_v, sum_v)

print(max_v)


Measured memory_bytes: 9092
import std.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;

bool[11] vars;
string input;

bool check() {
    string[] eq = input.split("=");
    bool val(string s) {
        int index = 0;
        bool parse() {
            if (s[index] == 'T') {
                index++;
                return true;
            }
            if (s[index] == 'F') {
                index++;
                return false;
            }
            if ('a' <= s[index] && s[index] <= 'k') {
                bool x = vars[s[index] - 'a'];
                index++;
                return x;
            }
            if (s[index] == '-') {
                index++;
                return (!parse);
            }
            if (s[index] == '(') {
                index++;
                bool x = parse;
                if (s[index] == '*') {
                    index++;
                    bool y = parse;
                    assert(s[index] == ')');
                    index++;
                    return (x & y);
                } else if (s[index] == '+') {
                    index++;
                    bool y = parse;
                    assert(s[index] == ')');
                    index++;
                    return (x | y);
                } else { // 
                    assert(s[index] == '-' && s[index+1] == '>');
                    index += 2;
                    bool y = parse;
                    assert(s[index] == ')');
                    index++;
                    return (y | (!x));
                }
            }
            assert(0);
        }
        return parse;
    }
    return val(eq[0]) == val(eq[1]);
}

void main() {
test: while (true) {
        input = readln.chomp;
        if (input == "#") break;
        for (int i = 0; i < (1 << 11); i++) {
            for (int j = 0; j < 11; j++) {
                vars[j] = (i & (1 << j)) ? true : false;
            }
            if (!check) {
                "NO".writeln;
                continue test;
            }
        }
        "YES".writeln;
    }
}

Measured memory_bytes: 2288
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979
//const int64_t INF = 1LL << 60;
const int INF = 1 << 29;
const int64_t MOD = 1000000007;
//const int64_t INF = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
//#define P pair<int, int>
typedef pair<int, int> P;

int main(){
    int N, K;
    cin >> N >> K;
    int count = 0;
    rep(i, 0, N){
        int h;
        cin >> h;
        if(h>=K) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main (void)
{
 int n;
  cin>>n;
  n=n%10;
  if(n==3){cout<<"bon";}
  else if(n==2||n==4||n==5||n==7||n==9){cout<<"hon";}
  else cout<<"pon";
 
}
 

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

const long double EPS = 1e-9;

struct Line {
	long double x, y;
};
bool operator< (const Line &a1, const Line &a2) {
	if (fabs(a1.x - a2.x) > EPS && a1.x < a2.x) return true; if (fabs(a1.x - a2.x) > EPS && a1.x > a2.x) return false;
	if (fabs(a1.y - a2.y) > EPS && a1.y < a2.y) return true; if (fabs(a1.y - a2.y) > EPS && a1.y > a2.y) return false;
	return false;
}
bool operator== (const Line &a1, const Line &a2) {
	if (fabs(a1.x - a2.x) < EPS && fabs(a1.y - a2.y) < EPS) return true;
	return false;
}

long long n, x[209], y[209], power[209], mod = 998244353; vector<Line> vec;

long long calc(long long n) {
	return (power[n] - (n*(n - 1) / 2) - n - 1 + mod) % mod;
}

int main() {
	cin >> n;
	power[0] = 1; for (int i = 1; i <= 208; i++) power[i] = (power[i - 1] * 2) % mod;
	for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int X = (x[j] - x[i]), Y = (y[j] - y[i]); if (X < 0) { X *= -1; Y *= -1; }
			if (X == 0) { vec.push_back(Line{ 1.0L*x[j], 100000.0L }); }
			else {
				long double D = 1.0L*Y / X;
				long double E = 1.0L*y[i] - D*x[i];
				vec.push_back(Line{ E,D });
			}
		}
	}
	sort(vec.begin(), vec.end());
	int cx = 0; long long U = 0;
	while (cx < vec.size()) {
		int pos1 = upper_bound(vec.begin(), vec.end(), vec[cx]) - vec.begin();
		int V = pos1 - cx, VV = 0;
		for (int i = 2; i <= 200; i++) {
			if (V == i*(i - 1) / 2)VV = i;
		}
		U += calc(VV); U += mod; U %= mod;
		cx = pos1;
	}
	long long ans = calc(n);
	ans = (ans - U + mod) % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int N, M;
	cin >> N >> M;
	int ans = 0;
	if (N > 1) ans += N * (N - 1) / 2;
	if (M > 1) ans += M * (M - 1) / 2;

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


Measured memory_bytes: 256
N = int(raw_input())
A = map(int, raw_input().split())
c = [0, 0, 0]
for a in A:
  if a%4==0:
    c[2]+=1
  elif a%2==0:
    c[1]+=1
  else:
    c[0]+=1
while sum(c)>0:
  if c[0]==0:
    print 'Yes'
    break
  elif sum(c)==1:
    print 'Yes'
    break
  elif c[2]==0:
    print 'No'
    break
  else:
    c[0]-=1
    c[2]-=1

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
  gearup;
  int n;cin >> n;
  vl a(n);
  rep(i,n)cin>>a[i];
  vl c(n);
  //|a[i] - (b+(i+1))|
  //|a[i] - (i+1) - b|
  //c[i] = a[i] - (i+1)　とする iは 0-indexed
  rep(i,n){
    c[i] = a[i] - (i+1);
  }
  sort(all(c));
  
  ll res = 0;
  if(n & 1){
    ll b = c[n/2];
    rep(i,n){
      res += abs(c[i] - b);
    }
  }
  else{
      ll b = c[(n/2)-1]; //中央の左
      rep(i,n){
      res += abs(c[i] - b);
      }

      ll d = c[(n/2)]; //中央の右
      ll ans = 0;
      rep(i,n){
        ans += abs(c[i] - d);
      }
      res = min(res,ans);
  }
  out(res);
}


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

typedef complex<double> Point;
typedef vector<Point> VP;
#define X real()
#define Y imag()
const double INF = 1e9;

bool compX(const Point a, const Point b) {
    return a.X<b.X;
}

bool compY(const Point a, const Point b) {
    return a.Y<b.Y;
}

double closestPair(VP &a,int l,int r) {
    if(r-l<=1) return INF;
    int m = (l+r)/2;
    double x = a[m].X;
    double d = min(closestPair(a,l,m),closestPair(a,m,r));
    inplace_merge(a.begin()+l,a.begin()+m,a.begin()+r,compY);
    
    VP b;
    for(int i=l;i<r;i++){
        if(abs(a[i].X - x)>=d)continue;
        for(int j=b.size()-1;j>=0;j--){
            if((a[i]-b[j]).Y>=d)break;
            d = min(d,abs(a[i]-b[j]));
        }
        b.push_back(a[i]);
    }
    return d;
}

int main(void){
    int n;
    cin>>n;
    VP ps(n);
    rep(i,n){
        double x,y;
        cin>>x>>y;
        ps[i] = Point(x,y);
    }
    sort(all(ps),compX);
    printf("%.9f\n",closestPair(ps,0,n));
    return 0;
}

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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename L, typename R>
ostream& operator<<(ostream& out, const pair<L, R>& p) {
    out << "(" << p.first << ", " << p.second << ")";
    return out;
}

template <typename L, typename R>
istream& operator>>(istream& in, pair<L, R>& p) {
    in >> p.first >> p.second;
    return in;
}

const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;

#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--)
#define TR(X)                                                  \
    ({                                                         \
        if (1) cerr << "TR: " << (#X) << " = " << (X) << endl; \
    })
#define LL(name) \
    ll name;     \
    cin >> name;
#define VL(name, num) \
    vl name(num);     \
    FOR(INPUT_VL_I, 0, num) { cin >> name[INPUT_VL_I]; }

ll median(vl& vec) {
    nth_element(vec.begin(), vec.begin() + sz(vec) / 2, vec.end());
    nth_element(vec.begin(), vec.begin() + (sz(vec)-1) / 2, vec.end());

    ll res = vec[sz(vec) / 2];
    if (sz(vec) % 2 == 0) {
        res += vec[(sz(vec)-1) / 2];
    }
    return res;
}
int main() { cin.sync_with_stdio(0);
    LL(N);

    vl As(N), Bs(N);
    FOR(i, 0, N) {
        cin >> As[i] >> Bs[i];
    }

    const ll mA = median(As);
    const ll mB = median(Bs);

    cout << (mB - mA + 1) << endl;
}  // cin.tie(0) bei schnellem Wechseln


Measured memory_bytes: 6372
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 500005
#define PI 3.14159265358979323846264338327950
 
#define ll    long long int 
#define mod  1000000007

ll dp[205];

int main()
{
	FAST;
	ll n;
	cin >> n;
	ll a[MAXX] = {0};
	for(ll i = 1; i <= 100; i ++){
		for(ll j = 1; j <= 100; j ++){
			for(ll z = 1; z <= 100; z ++){
				a[i*i + j*j + z*z + i*j + i*z + j*z] ++;
			}
		}
	}
	for(ll i = 1; i <= n; i ++){
		cout << a[i] << endl;
	}
	
	
}

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

bool isHeisei(int y, int m, int d)
{
    if (y < 2019) return true;
    if (y > 2019) return false;
    if (m < 4) return true;
    if (m > 4) return false;
    if (d <= 30) return true;
    if (d > 30) return false;
}

int main()
{
    int y,m,d;
    scanf("%d/%d/%d", &y, &m, &d);
    if (isHeisei(y,m,d))
    {
        cout << "Heisei" << endl;
    }
    else
    {
        cout << "TBD" << endl;
    }
}

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

int main() {
  int H,W;
  cin>>H>>W;
  
  rep(i,W+2){
    cout<<"#";
  }
  
  cout<<endl;
  
  rep(i,H){
    string S;
    cin>>S;
    cout<<"#"<<S<<"#"<<endl;
  }
  
   rep(i,W+2){
    cout<<"#";
  }
  
  cout<<endl;
  
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

int main() {

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

	int ans = gcd(a, b);
	cout << ans << endl;

	return 0;
}





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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF 1e18
#define MOD 1e9 + 7

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main()
{
    ll n, a, b, x[112345];
    cin >> n >> a >> b;
    REP(i, n)
    cin >> x[i];

    ll ans = 0;

    REP(i, n - 1)
    {
        if ((x[i + 1] - x[i]) * a < b)
            ans += (x[i + 1] - x[i]) * a;
        else
            ans += b;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
O = list(input())
E = list(input())
password = []

while True:
    if len(O) == 0 and len(E) == 0:
        break;
    if len(O) > 0:
        password.append(O.pop(0))
    if len(E) > 0:
        password.append(E.pop(0))

print("".join(password))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int N; cin >> N;
  int sa = 0, ssa = 0;
  int a;
  rep(i,N){
    cin >> a;
    sa += a;
    ssa += a*a;
  } 

  int L = 100000000, retval;
  for (int x=-100;x<=100;x++){
    if (L > N*x*x - 2*x*sa + ssa){
      retval = x;
      L = N*x*x - 2*x*sa + ssa;
    }
  }
  cout << L << endl;




  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3552
import itertools,sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()
N = I()
s,t = S(),S()
ans = len(s)+len(t)
t_accumulate = list(itertools.accumulate(t))
for x in t_accumulate[::-1]:
    if x in s:
        ans -= len(x)
        break
print(ans)


Measured memory_bytes: 3060
import bisect

N = 5
ARR = [6, 9, 4, 2, 11]


N = 2
ARR = [100, 0]

N = int(input())
ARR = list(map(int, input().split()))


def calculate(n, arr):
    arr = sorted(arr)

    mid = arr[n - 1] / 2

    a1 = bisect.bisect_left(arr, mid)

    s1 = abs(arr[a1 - 1] - (arr[n - 1] / 2))
    s2 = abs(arr[a1] - (arr[n - 1] / 2))

    if s1 > s2:
        return arr[n - 1],arr[a1]
    else:
        return arr[n-1],arr[a1-1]


n, a = calculate(N, ARR)
print(n, a)


Measured memory_bytes: 14348
def fun(n, p):
        stone = p
        stone_list = [0]*n
        index = 0
        while True:
                if stone != 0:
                        stone -= 1
                        stone_list[index] += 1
                        if stone == 0 and stone_list[index] == p:
                                print(index)
                                break
                else:
                        if stone_list[index] != 0:
                                stone += stone_list[index]
                                stone_list[index] = 0
                index += 1
                if index == n:
                        index = 0

n, p = map(int, input().split())
while n != 0:
        fun(n, p)
        n, p = map(int, input().split())


Measured memory_bytes: 5596
from collections import deque
N, M = map(int, input().split())
A = []
B = []
G = [[-1] * N for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    G[a - 1][b - 1] = 1
    G[b - 1][a - 1] = 1
    A.append(a - 1)
    B.append(b - 1)


def BFS(G):  # 連結か判定する関数
    """
    >>> BFS([[-1, 1, 1], [1, -1, 1], [1, 1, -1]])
    True
    >>> BFS([[-1,1,-1], [1,-1,-1], [-1,-1,-1]])
    False
    >>> BFS([[-1,1,-1,-1], [1,-1,1,-1], [-1,1,-1,1], [-1,-1,1,-1]])
    True
    """
    q = deque()
    q.append(0)
    visited = [False] * len(G)
    while len(q) != 0:
        p = q.popleft()
        for j in range(len(G)):
            if G[p][j] == 1 and not visited[j]:
                q.append(j)
                visited[j] = True
    if False in visited:
        return False
    else:
        return True


count = 0
for i in range(M):
    G[A[i]][B[i]] = -1
    G[B[i]][A[i]] = -1
    if not BFS(G):
        count += 1
    G[A[i]][B[i]] = 1
    G[B[i]][A[i]] = 1
print(count)


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

using namespace std;

int main(){
  int A,B;
  cin >> A >> B;
  if(A == 1){
    A = 14;
  }
  if(B == 1){
    B = 14;
  }
  if(A == B){
    cout << "Draw" << endl;
  }else if(A > B ){
    cout << "Alice" << endl;
  }else if(A < B ){
    cout << "Bob" << endl;
  }


  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,m;
	cin>>n>>m;
	ll a[n+5];
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	}
	ll M= m;
	ll p,q;
	vector<ll> adj[n+5];
	while(M--)
	{
		cin>>p>>q;
		p--;q--;
		adj[p].push_back(q);
		adj[q].push_back(p);
	}
	ll ans = 0;
	for(ll i=0;i<n;i++)
	{
		bool flg = true;
		for(ll j=0;j<adj[i].size();j++)
		{
			ll v = adj[i][j];
			if (a[i]<=a[v])
				flg = false;
		}
		if (flg)
			ans++;
	}
	cout<<ans;
}

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


int main() {
	
	int x;
	cin >> x;
	int cnt=0;
	for(int i=1; i<=x; i++){
		cnt += i;
		if(cnt>=x){
			cout << i << endl;
			break;
		}
		
	}
	
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

int main()
{
    int a, b, k;
    cin >> a >> b >> k;
    vector<int> gcd;
    int mx = max(a,b);
    for(int i=1; i<=mx; i++)
    {
        if(a%i==0 && b%i==0)
        {
            gcd.push_back(i);
        }
    }
    sort(gcd.begin(),gcd.end(),greater<int>());
    cout << gcd[k-1] << endl;
    return 0;
}


Measured memory_bytes: 256
//Dragon_warrior7(IITK)
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#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 umap unordered_map
#define uset unordered_set
#define ll long long
#define lll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define ull unsigned ll
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define fo(i,a,b) for(int i=a;i<b;i++)
#define Lets_be_precise cout<<fixed<<setprecision(10)
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=100000+11;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
	cin>>v[i];
}
//#define cerr if(false)cerr//uncomment to remove cerr from program...
void solveforthiscase(const int & test)
{//deb(test);
cin>>n>>m;
vll v(n);
read(v);
int count=0;
ll sum=0;
for(int i=0;i<n;i++)
{
    sum+=v[i];
}
sum=((sum+(4*m)-1)/(4*m));
for(int i=0;i<n;i++)
if(v[i]>=sum)
count++;
if(count>=m)
cout<<"Yes";
else
cout<<"No";
return ;
}

int main()
{
	ios_base::sync_with_stdio(false);
	Lets_be_precise;
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

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

#define MAX 110
typedef pair<int, int> P;
int n, m;
char chair[MAX];
bool isZero;

bool isCanSit(int x){
  if(chair[x] == '#') return true;
  return false;
}

void A(){
  for(int i = 0 ; i < n ; i++){
    if(isCanSit(i)){
      chair[i] = 'A';
      isZero = false;
      return;
    }
  }
}

bool isNext(int x){
  if(chair[x-1] == 'A' || chair[x+1] == 'A') return true;
  return false;
}

void B(){
  for(int i = n-1 ; i >= 0 ; i--){
    if(isCanSit(i) && !isNext(i)){
      chair[i] = 'B';
      isZero = false;
      return;
    }
  }
  
  for(int i = 0 ; i < n ; i++){
    if(isCanSit(i)){
      chair[i] = 'B';
      isZero = false;
      return;
    }
  }
}

void C(){
  if(isZero){
    chair[n/2] = 'C';
    isZero = false;
    return;
  }
  
  for(int i = 0 ; i < n ; i++){
    if(!isCanSit(i)){
      if(isCanSit(i+1)){
	if(i+1 != n){
	  chair[i+1] = 'C';
	  isZero = false;
	  return;
	}
	else{
	  chair[i-1] = 'C';
	  isZero = false;
	  return;
	}
      }
      else if(isCanSit(i-1)){
	chair[i-1] = 'C';
	isZero = false;
	return;
      }
    }
  }
}

void D(){
  if(isZero){
    chair[0] = 'D';
    isZero = false;
    return;
  }
  
  int sit;
  int dis[MAX];
  fill(dis, dis+MAX, MAX);
  for(int i = 0 ; i < n ; i++){
    if(chair[i] != '#'){
      for(int j = 0 ; j < n ; j++){
	dis[j] = min(dis[j], abs(i-j));
      }
    }
  }  
  int d = 0;
  for(int i = 0 ; i < n ; i++){
    if(dis[i] > d){
      sit = i;
      d = dis[i];
    }
  }
  chair[sit] = 'D';
  return;
}
  
void init(){
  fill(chair, chair+MAX, '#');
  isZero = true;
}

void display(){
  for(int i = 0 ; i < n ; i++){
    cout << chair[i];
  }
  cout << endl;
}

int main(){
  char p;
  while(cin >> n >> m){
    if(n == 0 && m == 0) break;
    init();
    for(int i = 0 ; i < m ; i++){
      cin >> p;
      if(p == 'A') A();
      if(p == 'B') B();
      if(p == 'C') C();
      if(p == 'D') D();
      //      display();
    }
    display();
  }
  return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int main(){
  int n; cin >> n;
  vector<int> a(n);
  ll ans=0;
  int cnt=0, amin=inf;
  bool flag=false;
  rep(i,n){
    cin>>a[i];
    ans += abs(a[i]);
    if(a[i]<0){cnt++;}
    amin = min(amin,abs(a[i]));
    if(a[i]==0){flag=true;}
  }
  if(cnt%2 && !flag){ ans -= amin*2; }
  cout << ans << endl;
}


Measured memory_bytes: 640