akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    static int n;
    static List<Tuple<int,int>>[] edges;
    static long[] d;
    
    public static void Main()
    {
	n = int.Parse(ReadLine());
	edges = new List<Tuple<int,int>>[n];
	for (int i = 0; i < n; i++) edges[i] = new List<Tuple<int,int>>();
	
	int[] tmp;
	for (int i = 0; i < n-1; i++)
	{
	    tmp = ReadIntArray();
	    int a = tmp[0] - 1, b = tmp[1] - 1, c = tmp[2];
	    edges[a].Add(Tuple.Create(b, c));
	    edges[b].Add(Tuple.Create(a, c));
	}
	tmp = ReadIntArray();
	int q = tmp[0], k = tmp[1] - 1;

	d = new long[n];
	dfs(k, 1); 
	
	for (int i = 0; i < q; i++)
	{
	    tmp = ReadIntArray();
	    int x = tmp[0] - 1, y = tmp[1] - 1;
	    long ans = d[x] + d[y];
	    WriteLine(ans-2);
	}
    }

    static void dfs(int x, long dist)
    {
	d[x] = dist;
	foreach (Tuple<int,int> t in edges[x])
	{
	    int y = t.Item1, c = t.Item2;
	    if (d[y] == 0) dfs(y, dist + c);
	}
    }
}



Measured memory_bytes: 50064
import java.util.Scanner;

public class Main {
    public static void main (String[] args){
        solve();
    }

    public static void solve(){
        Scanner sc = new Scanner(System.in);
        while(true) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            int min = 1000;
            int max = 0;
            int sum = 0;

            int[] tensuu = new int[n];
            for (int i = 0; i < tensuu.length; i++) {
                tensuu[i] = sc.nextInt();
                if(tensuu[i] <= min){
                    min = tensuu[i];
                }
                if(tensuu[i] >= max){
                    max = tensuu[i];
                }
                sum += tensuu[i];
            }
            System.out.println((sum - max - min)/(n - 2));
        }
    }
}

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

int main(){
    
    int A,B,Q;
    cin>>A>>B>>Q;
    vector<long long int> S(A),T(B);
    for(int i=0;i<A;i++){
        cin>>S[i];
    }
    for(int i=0;i<B;i++){
        cin>>T[i];
    }
    for(int i=0;i<Q;i++){
        long long int x;cin>>x;
        auto pos1 = lower_bound(S.begin(),S.end(),x);
        auto pos2 = lower_bound(T.begin(),T.end(),x);
        int idx1 =distance(S.begin(),pos1);
        int idx2 =distance(T.begin(),pos2);
        long long int ans=100000000000;
        if(idx1!=0&&idx2!=0){
            long long int a;
            a=x-min(S[idx1-1],T[idx2-1]);
            ans=min(a,ans);
        }
        if(idx1!=0&&idx2!=B){
            long long int a;
            a=min(((x-S[idx1-1])*2+T[idx2]-x),((T[idx2]-x)*2+x-S[idx1-1]));
            ans=min(a,ans);
        }
        if(idx1!=A&&idx2!=0){
            long long int a;
            a=min(((x-T[idx2-1])*2+S[idx1]-x),((S[idx1]-x)*2+x-T[idx2-1]));
            ans=min(a,ans);
        }
        if(idx1!=A&&idx2!=B){
            long long int a;
            a=max(S[idx1],T[idx2])-x;
            ans=min(a,ans);
        }
    cout<<ans<<endl;
    }
}
    


Measured memory_bytes: 2944
#include "bits/stdc++.h"

using namespace std;

struct Stack
{
    int max_size = 500;
    int top_idx = -1;
    int* data;

    Stack() {
        top_idx = -1;
        data = new int[max_size];
    }

    ~Stack() {
        if (data != NULL) {
            delete [] data;
        }
    }
    
    void push(int x) {
        if (top_idx + 1 < max_size) {
            top_idx++;
            data[top_idx] = x;
        } else {
            throw;
        }
    }

    int pop() {
        if (!isEmpty()) {
            int ret = data[top_idx];
            top_idx--;
            return ret;
        } else {
            throw;
        }
    }

    bool isEmpty() {
        if (top_idx == -1) {
            return true;
        } else {
            return false;
        }
    }

    bool isFull() {
        if (top_idx == max_size - 1) {
            return true;
        } else {
            return false;
        }
    }
};


int main() {
    string input_str;
    getline(cin, input_str);
    stringstream ss{input_str};

    Stack stack;
    string s;
    while (getline(ss, s, ' ')) {
        if (s == "+" || s == "-" || s == "*") {
            int op2 = stack.pop();
            int op1 = stack.pop();
            int v;
            if (s == "+") {
                v = op1 + op2;
            } else if (s == "-") {
                v = op1 - op2;
            } else {
                v = op1 * op2;
            }
            stack.push(v);
        } else {
            stack.push(stoi(s));
        }
    }
    int res = stack.pop();
    cout << res << endl;
    return 0;
}


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

using namespace std;

int main()
{
  string S;
  cin >> S;
  int a = 0;
  int b = 0;
  for(char c : S) {
    if(a == 0 && c == 'C') {
      a = 1;
    }
    if(a == 1 && c == 'F') {
      b = 1;
    }
  }
  if(b) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	double ans = 0;
	for (int i = 0; i < n; i++) {
		ans += (double) 1 / a[i];
	}

	printf("%.9f\n",  1 / ans);
}

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

int main(){
	int h1,m1,h2,m2;
	int k;
	cin>>h1>>m1>>h2>>m2;
	cin>>k;
	
	h1=h1*60+m1;
	h2=h2*60+m2;
	int ans=abs(h1-h2);
	ans = ans-k;
	cout<<ans;
}

Measured memory_bytes: 3552
L=input()
L_l=[]
for i in L:
     L_l.append(i)
L_l.sort()

if L_l[0]==L[1] and L_l[1]==L_l[2]:
     print("No")
elif L_l[0]==L_l[1] and L_l[2]==L_l[3]:
     print("Yes")
else:
     print("No")


Measured memory_bytes: 3060
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long a = Integer.parseInt(sc.next());
		long b= Integer.parseInt(sc.next());
		long r=0,x,tmp;
		x=a*b;
		if(a<b) {
			tmp=a;
			a=b;
			b=tmp;
		}
		r=a%b;
		while(r!=0) {
			a=b;
			b=r;
			r=a%b;
		}
		
		System.out.println(x/b);
	}
}

Measured memory_bytes: 23380
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <set>
#include<cstring>
#define ll long long
#define MODD 1000000007
#define  pii  pair<int,int>
#include<stdio.h>
#include <bits/stdc++.h>
using namespace std;
struct node{
    string name;
    double a,b,c;
    double sum;
    double avg;
}city[10000];
double cmd(node a, node b){
    return a.sum>b.sum;
}
int main(){
	int n;cin >>n;
	cout<<n*n<<endl;
}




Measured memory_bytes: 768
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back


typedef long long ll;

#ifdef IZI_KATKA
#define int ll
#else
#define int ll
#endif


const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}


main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
 	int N = readInt(), K = readInt();
 	int ans = 0;
 	if (K == 0) {
 		cout << N * N;
 		return 0;
 	}
 	for (int i = 1; i <= N; i++) {
 		if (i <= K) continue;
 		int bolingen = N / i;
 		int bolinbegen = N % i;
 		ans += bolingen * max(0ll, i - K);
 		ans += max(bolinbegen - K + 1, 0ll);
 	}
 	cout << ans;
    return 0;
}

Measured memory_bytes: 256
import bisect

N, D, A = map(int, input().split())
W = 2*D

XH = []
for i in range(N):
  x, h = map(int, input().split())
  XH.append([x, h])

XH.sort()

# 以下、1-based
# [0]はダミー
X = [-1]
H = [0]
for x, h in XH:
  X.append(x)
  H.append(h)


# J[i] = i番目のモンスターが左端で攻撃を受ける際に、
#最も右側で攻撃を受けるモンスターのインデックス
J = [0]
for x in X[1:]:
  J.append(bisect.bisect_left(X, x+W+1))


damage = [0]*(N+1)
ans = 0
for i in range(1, N+1):
  damage[i] += damage[i-1]
  H[i] -= damage[i]
  x, h = X[i], H[i]
  if h <= 0:
    continue
  
  count = -(-h//A)
  ans += count
  dmg = count*A
  damage[i] += dmg
  if J[i] <= N:
    damage[J[i]] -= dmg # 攻撃範囲外への影響をなくすために先に引いておく

print(ans)  

Measured memory_bytes: 61516
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1e+9;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

int main() {
  ll X;
  cin >> X;

  for(int a = -1000; a <= 1000; a++) {
    for(int b = -1000; b <= 1000; b++) {
      if(pow(a,5) - pow(b,5) == X) {
	cout << a << " " << b << endl;
	return 0;
      }
    }
  }
}


Measured memory_bytes: 3624
#include<iostream>
#include<math.h>
using namespace std;
 
int main(){
  long long int n;
  long long int i;
  cin>>n;
  long long int temp=sqrt(n);
  for(i=temp;i>=1;i--){
  	if(n%i==0){
  		n=n/i;
  		long long int t=i+n-2;
  		cout<<t;
  		break;
  	}
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<algorithm>
#define ll long long int

using namespace std;

int main()
{
    long long  int t,n,x,c=0,i,j,a[500];
    cin>>t>>x;
    for(i=0; i<t; i++){
        cin>>a[i];
    }
    sort(a,a+t);
    for(i=0; i<t; i++){
        x-=a[i];
        if(x>=0)
            c++;
        if(x<0)
            break;
        //cout<<c<<" ";
    }
    if(x>0)
        c--;

    cout<<c<<endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

void dfs(int n, int m, int pre_num, vector<int> now, vector<vector<int>> &num) {
    if ((int)now.size() == n) {
        num.push_back(now);
        return;
    }
    for (int i = pre_num; i <= m; ++i) {
        auto tmp_now = now;
        tmp_now.push_back(i);
        dfs(n, m, i, tmp_now, num);
    }
    return;
}

int main(){
    int n, m, q;
    cin >> n >> m >> q;
    vector<int> a(q);
    vector<int> b(q);
    vector<int> c(q);
    vector<int> d(q);
    rep(i, q) {
        int tmp_a, tmp_b;
        cin >> tmp_a >> tmp_b >> c[i] >> d[i];
        --tmp_a, --tmp_b;
        a[i] = tmp_a;
        b[i] = tmp_b;
    }
    vector<vector<int>> num;
    vector<int> now;
    dfs(n, m, 1, now, num);
    int ans = 0;
    //for (auto p: num) {
    //    for (auto v: p) {
    //        cout << v << " ";
    //    }
    //    cout << endl;
    //}
    rep(i, (int)num.size()) {
        int sum = 0;
        rep(j, q) {
            if (num[i][b[j]] - num[i][a[j]] == c[j]) sum += d[j];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
}


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

int main() {
	int a, b;
	char c;
	std::cin >> a >> c >> b;
	if (c == '+') {
		std::cout << (a + b) << std::endl;
	} else if (c == '-') {
		std::cout << (a - b) << std::endl;
	}
}



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

int main() {
  int a,b,c,d,e,ans;
  cin >> a >> b;
  c = a+b;
  d = a-b;
  e = a*b;
 vector<int> num(3);
  num = {c,d,e};
  sort(num.begin(),num.end());
  cout << num[2] << endl;
}

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

public class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        if (A.Contains(0))
        {
            Console.WriteLine(0);
            return;
        }

        long v = 1;
        foreach (var a in A)
        {
            checked
            {
                try
                {
                    v *= a;
                    if (v > 1000000000000000000)
                    {
                        v = -1;
                        break;
                    }
                }
                catch (OverflowException)
                {
                    v = -1;
                    break;
                }
            }
        }

        Console.WriteLine(v);
    }
}

Measured memory_bytes: 42896
#include<bits/stdc++.h>
using namespace std;
string maxn(string a,string b)
{
    if(a.size()>b.size()) return a;
    if(a.size()<b.size()) return b;
    return a>b?a:b;
}
int mp[11]={0,2,5,5,4,5,6,3,7,6},a[11];
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
        cin>>a[i];
    vector<string>dp(10100,"$");
    dp[0]="";
    for(int i=0;i<=n;i++)
	{
        if(dp[i]=="$") 
			continue;
        for(int j=1;j<=m;j++)
            if(i+mp[a[j]]<=n)
                dp[i+mp[a[j]]]=maxn(dp[i+mp[a[j]]],dp[i]+char(a[j]+'0'));
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 43648
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace contest_Csharp
{
    
    class Program
    {
        public static (long m,long s)[,] dp;

        static void Main(string[] args)
        {
            checked
            {
                var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
                Console.SetOut(sw);

                //var vals = Console.ReadLine().Split(' ').
                //    Select(x => int.Parse(x)).ToList();
                var S = Console.ReadLine();
                //var N = vals[0];
                //var K = vals[1];
                var ans = 0;
                var pre = 0;
                for (int i = 0; i < 3; i++)
                {
                    if (S[i] == 'R')
                    {
                        pre++;
                        ans = Math.Max(pre, ans);
                    }
                    else
                    {
                        pre = 0;
                    }
                }

                

                Console.WriteLine(ans);

                Console.Out.Flush();
            }




        }
    }
}




Measured memory_bytes: 25840
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iomanip>
#define faster       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define r(i,a,b) for(ll i=a;i>b;i--)
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){

faster;
ll n; cin>>n;
vector<ll> dp(3,0);
vector<ll> c(3);
vector<ll> newdp(3,0);

f(i,0,3){
  cin>>dp[i];
}

f(i,0,n-1){
  
  f(x,0,3){
    cin>>c[x];
  }

  f(y,0,3){
    f(z,0,3){
      if(y!=z){
        newdp[z]=max(newdp[z],dp[y]+c[z]);
      }
    }
  }

  dp=newdp;

}

ll f=max(dp[0],dp[1]);
cout << max(f,dp[2]) << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = n; i >= 0; i--)
#define INF 2e9

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

ll dp[10001];

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

    vector<P> AB(N);
    rep(i, N) cin >> AB[i].first >> AB[i].second;

    rep(i, H+1) dp[i] = INF;
    dp[H] = 0;

    rep(i, N) {
        int A = AB[i].first, B = AB[i].second;
        rrep(i, H) {
            int idx = max(0, i-A);
            dp[idx] = min(dp[idx], dp[i]+B);
        }
    }

    cout << dp[0] << endl;

    return 0;
}


Measured memory_bytes: 384
program abc163b
      implicit none
      integer::n,m
      integer,allocatable,dimension(:)::a
      integer::i,play

         read *, n,m
         allocate(a(m))
         read *, a(1:m)

         play=n
         do i=1,m
            play=play-a(i)
         end do

         if (play<0) then
            print *, '-1'
         else
            print *, play
         end if

   end program abc163b

Measured memory_bytes: 2964
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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 Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;

struct mint {
    ll x;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// 2項係数を求める
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

mint choose(int n, int a){
    mint x = 1, y = 1;
    rep(i,a){
        x *= n-i;
        y *= i+1;
    }
    return x/y;
}

int main(){
    
    ll n,a, b;
    cin >> n >> a >> b;

    mint ans = mint(2).pow(n);
    ans -= 1;
    ans -= choose(n,a);
    ans -= choose(n,b);
    cout << ans << endl;



}

Measured memory_bytes: 3584
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<iostream>
#include<string>
#include<set>
#include<queue>
#include<random>

using namespace std;

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> st;*/

#pragma GCC optimize("Ofast")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")

#define pb push_back
#define ld long double
#define int long long

mt19937 rnd(51);

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, m, x;
	cin >> n >> m >> x;
	vector<vector<int>> v(n);
	vector<int> cost(n);
	for (int i = 0; i < n; i++){
        cin >> cost[i];
        for (int j = 0; j < m; j++){
            int a;
            cin >> a;
            v[i].pb(a);
        }
	}
	int ff = 1e18;
	for (int i = 0; i < (1 << n); i++){
        int ans = 0;
        vector<int> a(m);
        for (int j = 0; j < n; j++){
            if (i & (1 << j)){
                ans += cost[j];
                for (int k = 0; k < m; k++){
                    a[k] += v[j][k];
                }
            }
        }
        bool x1 = 0;
        for (int j = 0; j < m; j++){
            if (a[j] < x){
               x1 = 1;
            }
        }
        if (!x1){
            ff = min(ff, ans);
        }
	}
	if (ff == 1e18){
        cout << -1;
        return 0;
	}
	cout << ff;
	return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll n,c,k;
  cin >> n >> c >> k;

  vll t(n);
  REP(i, n)
    cin >> t[i];

  sort(t.begin(), t.end());
  ll ans = 0;
  queue<ll> bus;

  REP(i, n){
    if(bus.empty())
      bus.push(t[i]);
    else if(bus.front()+k < t[i]){
      while(!bus.empty())
        bus.pop();
      ans++;
      bus.push(t[i]);
    }
    else
      bus.push(t[i]);

    if(bus.size() == c){
      while(!bus.empty())
        bus.pop();
      ans++;
    }
  }
  if(!bus.empty())
    ans++;


  cout << ans << endl;

}


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

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

using namespace std;

int main() {
  while(1){
    string n;
    cin>>n;
    if(n=="0")break;
    int sum = 0;
    vector<int> v(11);
    //v[0] = 1;
    int l=n.size();
    REP(i,l) {
      reverse(begin(v)+1,end(v));
      int c=n[i]-'0';
      if(c) ++v[0];
      vector<int> tmp(11);
      REP(j,11) tmp[(j+c)%11]=v[j];
      swap(tmp,v);
      sum += v[0];
    }
    cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
//#pragma GCC diagnostic error "-Wconversion"
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define mp(a, b) make_pair(a, b)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
ll dp[100010];
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
ll digits(ll x){
  ll length = 0;
  while (x > 0){
    x /= 10;
    length++;
  }
  return length;
  if (x == 0) return 0;
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}
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;
}

int main(){
  cout << fixed << setprecision(15);

  int n, k; cin >> n >> k;

  ll ans = 0;
  //string ans = "No";

  ans = 1;
  rep(i, n){
    if (ans <= k) ans *= 2;
    else ans += k;
  }
  
  cout << ans << endl;

  return 0;
}

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

int main(void)
{
	int a[2];
	int n;
	int cnt, tmp;

	cin >> n;
	rep(j, 2)
	{
		vector<int> p, q;
		rep(i, n)
		{
			cin >> tmp;
			p.push_back(tmp);
			q.push_back(tmp);
		}
		sort(q.begin(), q.end());
		cnt = 1;
		do{
			if (p == q)
			{
				a[j] = cnt;
				break;
			}
			cnt++;
		}while(next_permutation(q.begin(), q.end()));
	}
	cout << abs(a[0] - a[1]) << endl;
	return 0;
}


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

#define MAX_N 700
#define MAX_CULS 1

#define sqrInf 999999999

using namespace std;

int rez;
int n, m;

int comp;

int col[MAX_N + 1];
bool viz[MAX_N + 1];

int ap[MAX_N + 1][MAX_CULS + 1];

int dp[MAX_N + 1][MAX_N + 1];
bool are[MAX_N + 1][MAX_N + 1];

vector <int> g[MAX_N + 1];

void add(int a, int b)
{
    g[a].push_back(b);
}

void readFile()
{
    cin >> n >> m;

    int i;
    int a, b;
    for(i = 1; i <= m; i ++)
    {
        cin >> a >> b;
        are[a][b] = 1;
        are[b][a] = 1;
    }
}

void getComp()
{
    int i, j;
    for(i = 1; i <= n; i ++)
    {
        for(j = 1; j <= n; j ++)
        {
            if(j != i)
            {
                if(are[i][j] == 0)
                    add(i, j);
            }
        }
    }
}

void dfs(int a, int cul)
{
    col[a] = cul;
    viz[a] = 1;
    ap[comp][cul] ++;
    for(auto u : g[a])
    {
        if(viz[u] == 0)
            dfs(u, 1 - cul);

        if(col[u] != 1 - col[a])
        {
            cout << "-1\n";
            exit(0);
        }
    }
}

void getCols()
{
    int i;
    for(i = 1; i <= n; i ++)
    {
        if(viz[i] == 0)
        {
            ++ comp;
            dfs(i, 0);
        }
    }
}

void getDp()
{
    int i, j, h;
    dp[0][0] = 1;
    for(i = 1; i <= comp; i ++)
    {
        for(j = n; j >= 0; j --)
        {
            if(dp[i - 1][j] == 1)
            {
                for(h = 0; h <= 1; h ++)
                    dp[i][j + ap[i][h]] = 1;
            }
        }
    }
}

void getRez()
{
    rez = sqrInf;

    int i;
    for(i = 1; i <= n; i ++)
    {
        if(dp[comp][i] == 1)
            rez = min(rez, ((i * (i - 1)) >> 1) + (((n - i) * (n - i - 1)) >> 1));
    }
}

void solve()
{
    getComp();

    getCols();

    getDp();

    getRez();
}

void printFile()
{
    cout << rez << "\n";
}

int main()
{
    readFile();

    solve();

    printFile();

    return 0;
}


Measured memory_bytes: 3072
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

#define MAX_N 100
#define swap(x, y) {int t = x; x = y; y = t;}

int
main(int argc, char** argv)
{
	int a[MAX_N];
	int count;
	int n;
	bool f;
	int i, j;

	scanf("%d", &n);
	for (i = 0; i < n; ++i)
		scanf("%d", &a[i]);

	count = 0;
	f = true;
	for (i = 0; f; ++i)
	{
		f = false;
		for (j = n - 1; j >= i + 1; --j)
		{
			if (a[j - 1] > a[j])
			{
				swap(a[j - 1], a[j]);
				f = true;
				count++;
			}
		}
	}

	for (i = 0; i < n; ++i)
		printf("%d%c", a[i], (i != n - 1) ? ' ' : '\n');

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

Measured memory_bytes: 600
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashMap<Fish, Integer> posMap = new HashMap<>();
	    HashMap<Fish, Integer> negMap = new HashMap<>();
	    int zeos = 0;
	    for (int i = 0; i < n; i++) {
	        boolean isPos = true;
	        long a = sc.nextLong();
	        long b = sc.nextLong();
	        if (a == 0 && b == 0) {
	            zeos++;
	            continue;
	        }
	        if (a < 0) {
	            a = -a;
	            b = -b;
	        }
	        if (b < 0) {
	            isPos = false;
	            b = -b;
	        }
	        if (a == 0) {
	            isPos = true;
	            b = 1;
	        } else if (b == 0) {
	            isPos = false;
	            a = 1;
	        }
	        if (isPos) {
	            Fish f = new Fish(a, b);
	            if (posMap.containsKey(f)) {
	                posMap.put(f, posMap.get(f) + 1);
	            } else {
	                posMap.put(f, 1);
	            }
	        } else {
	            Fish f = new Fish(b, a);
	            if (negMap.containsKey(f)) {
	                negMap.put(f, negMap.get(f) + 1);
	            } else {
	                negMap.put(f, 1);
	            }
	        }
	    }
        long ans = 1;
        for (Map.Entry<Fish, Integer> entry : posMap.entrySet()) {
            if (negMap.containsKey(entry.getKey())) {
                int x = entry.getValue();
                int y = negMap.get(entry.getKey());
                ans *= (pow(2, x) - 1 + pow(2, y) - 1 + 1 + MOD) % MOD;
                ans %= MOD;
                negMap.remove(entry.getKey());
            } else {
                ans *= pow(2, entry.getValue());
                ans %= MOD;
            }
        }
        for (Map.Entry<Fish, Integer> entry : negMap.entrySet()) {
            ans *= pow(2, entry.getValue());
            ans %= MOD;
        }
        ans += zeos;
        ans += MOD - 1;
        ans %= MOD;
		System.out.println(ans);
	}
	
	static long pow(long x, long p) {
	    if (p == 0) {
	        return 1;
	    } else {
	        if (p % 2 == 0) {
	            return pow(x * x % MOD, p / 2);
	        } else {
	            return pow(x, p - 1) * x % MOD;
	        }
	    }
	}
	
	static class Fish {
	    long a;
	    long b;
	    
	    public Fish(long a, long b) {
	        this.a = a;
	        this.b = b;
	        if (a != 0 && b != 0) {
	            long gcd = getGCD(a, b);
	            this.a = a / gcd;
	            this.b = b / gcd;
	        } else if (a == 0) {
	            this.b = 1;
	        } else if (b == 0) {
	            this.a = 1;
	        }
	    }
	    
	    public int hashCode() {
	        return (int)(a + b);
	    }
	    
	    public boolean equals(Object o) {
	        Fish f = (Fish) o;
	        return a == f.a && b == f.b;
	    }
	    
	    public String toString() {
	        return a + ":" + b;
	    }
	    
	    private long getGCD(long x, long y) {
	        if (x % y == 0) {
	            return y;
	        } else {
	            return getGCD(y, x % y);
	        }
	    }
	}
}
 

Measured memory_bytes: 72544
a,b,x=map(int,input().split())
def water(a,b,x):
  import math
  if math.tan(math.radians(x))<=b/a:
    return (((a**2)*math.tan(math.radians(x))))/2+a*(b-a*math.tan(math.radians(x)))
  else:
    return b**2/(2*math.tan(math.radians(x)))

p=0
q=90
r=0
while r<=1000:
  if water(a,b,(p+q)/2)<=x/a:
    p=p
    q=(p+q)/2
    r=r+1
  else:
    p=(p+q)/2
    q=q
    r=r+1

print((p+q)/2)

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

using namespace std;

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

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(int i = (int)m; i < (int)n; i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPM(i,m,n) for(int i = (int)m; i >= (int)n; i--)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define Size(s) (int) s.size()
#define greater_queue  priority_queue <ll, vector<ll>, greater<ll> >

//------------------------------------------------------

int main() {
    int n;
    cin >> n;
    vector<int> v, v_sorted;

    rep(i, n) {
        int a;
        cin >> a;
        v.push_back(a);
        v_sorted.push_back(a);
    }

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

    set<int> set_odd;

    for (int i = 0; i < n; i += 2) {
        set_odd.insert(v[i]);
    }

    int cnt = 0;
    for (int i = 0; i < n; i += 2) {
        if (!set_odd.count(v_sorted[i])) cnt++;
    }

    cout << cnt << endl;

    return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct UnionFindTree{
    vector<int>par,sz;
    UnionFindTree(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        if(sz[x]<sz[y])swap(x,y);
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool areSame(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

int N,M;
int P[111111];

signed main(){
    cin>>N>>M;
    rep(i,N)cin>>P[i],P[i]--;
    UnionFindTree uf(N);
    rep(i,M){
        int a,b;
        cin>>a>>b;
        a--;b--;
        uf.unite(a,b);
    }

    int ans=0;
    rep(i,N)ans+=uf.areSame(i,P[i]);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

template<typename ...Ts>
void show(Ts... ts){
  cout<<"#:";
  auto print=[](auto v){cout<<v<<" ";};
  initializer_list<int>{(void(print(ts)),0)...};
  cout<<endl;
}

int f[101000];

int fact(int n){
    if (n==0){f[n]=1;return f[n];}
    if (f[n]>0)return f[n];
    f[n]=fact(n-1)*n;
    return f[n];
}


int main(void){
    ll n,m;
    ll ans=0;
    string s;
    cin>>n>>m;
    vll a(n,0);
    vll ac(n+1,0);
    map<ll,ll> mp;
    
    rep(i,n)cin>>a[i];
    rep(i,n)ac[i+1]=a[i]+ac[i];
    
    rep(i,n+1){
        ll rm=ac[i]%m;
        mp[rm]+=1;
    }
    for(auto i:mp){
        //cout<<i.first<<' '<<i.second<<endl;
        ll x=i.second;
        ans+=x*(x-1)/2;
    }
    cout<<ans<<endl;
    //solve(t);
}


Measured memory_bytes: 5760
// {{{ include
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
// }}}
#include <climits>

//{{{ uf.hpp
#ifndef INCLUDE_UF_HPP
#define INCLUDE_UF_HPP
#include <vector>
#include <algorithm>
namespace orliv {
//{{{ UF merge, same, root, size, count
struct UF {
  std::vector<int> data;
  int cnt;
  UF(int n) : data(n, -1), cnt(n) {}
  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if (a != b){
      cnt--;
      if (data[b] < data[a]) std::swap(a, b);
      data[a] += data[b];
      data[b] = a;
    }
    return a != b;
  }
  bool same(int a, int b){ return root(a) == root(b); }
  int root(int a){ return data[a] >= 0 ? data[a] = root(data[a]) : a; }
  int size(int a){ return -data[root(a)]; }
  int count(){ return cnt; }
};
//}}}
}
#endif
//}}}
//{{{ graph.hpp
#ifndef INCLUDE_GRAPH_HPP
#define INCLUDE_GRAPH_HPP
#include <vector>
namespace orliv {
struct Edge {
  typedef int weight_t;
  int from, to;
  weight_t w;
  Edge(int from, int to, weight_t w) : from(from), to(to), w(w) {}
  bool operator<(const Edge& e) const {
    return w != e.w ? w > e.w : from != e.from ? from < e.from : to < e.to;
  }
  static const weight_t INF;
};
const int Edge::INF=INT_MAX;
typedef std::vector<Edge> Edges;
typedef std::vector<Edges> Graph;
}
#endif
//}}}

using namespace std;
using namespace orliv;

//{{{ Edges kruskal(g)
Edges kruskal(const Graph& g){
  const int V = g.size();
  int E = 0;
  for (const auto& v : g) E += v.size();
  Edges es;
  es.reserve(E);
  for (const auto& v : g){
    for (const auto& e : v){
      es.emplace_back(e);
    }
  }
  sort(es.begin(), es.end());
  reverse(es.begin(), es.end());
  UF uf(V);
  Edges result;
  for (const auto& e : es){
    if (uf.same(e.from, e.to)) continue;
    uf.merge(e.from, e.to);
    result.emplace_back(e);
  }
  return result;
}
//}}}

typedef long long ll;
inline int in(){int x;scanf("%d",&x);return x;}

int main()
{
  int N, M;
  while (N = in(), M = in()){
    Graph G(N);
    for (int i = 0; i < M; i++){
      int s = in() - 1, t = in() - 1, c = in();
      G[s].emplace_back(s, t, c);
      G[t].emplace_back(t, s, c);
    }
    Edges stree = kruskal(G);
    cout << stree[N / 2 - 1].w << endl;
  }

  return 0;
}

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

int main() {
	// your code goes here
	int a,b,c,d,e,k; cin >> a >> b >> c >> d >> e >> k;
	if(e-a>k) cout << ":(" << endl;
	else cout << "Yay!" << endl;
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  if(s == "RRR") cout << 3 << endl;
  else if(s == "SSS") cout << 0 << endl;
  else if(s == "RRS" || s == "SRR") cout << 2 << endl;
  else cout << 1 << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e9+7;

ll mul(ll a,ll b){
  return (a*b)%mod;
}

ll fact[200000];
ll N,M;

int main(){
  cin>>N>>M;
  ll nn=1;
  for(ll i=1;i<=N;i++)
    nn=mul(nn,i);
  
  ll mm=1;
  for(ll i=1;i<=M;i++)
    mm=mul(mm,i);

  if( abs(N-M)>1 ){
    cout<<0<<endl;
  }else if(N==M){
    cout<<mul(2, mul(nn,mm) )<<endl;
  }else{
    cout<<mul(nn,mm)<<endl;    
  }
  return 0;
}


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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M,Q=MI()
    a=[0]*Q
    b=[0]*Q
    c=[0]*Q
    d=[0]*Q
    
    for i in range(Q):
        a[i],b[i],c[i],d[i]=MI()
        
    import itertools
    ans=0
    
    
    
    for ite in itertools.combinations_with_replacement(range(1,M+1), N):
        temp=0
        for i in range(Q):
            if ite[b[i]-1]-ite[a[i]-1] == c[i]:
                temp+=d[i]
        ans=max(ans,temp)
        
    print(ans)
    
    
    
main()


Measured memory_bytes: 68080
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans = 0;
    for (int i = 0; i < n; i += 2) {
        if (a[i] % 2 == 1) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3584
// Problem Code: abc176_d

#include <iostream>
#include <vector>
#include <string>
#include <deque>
#include <tuple>
#include <utility>

using namespace std;

int wizard_in_maze(int H, int W, pair<int, int>& C, pair<int, int>& D, vector<string>& S) {
	deque<pair<int, int>> q;
	vector<vector<int>> dist(H, vector<int>(W, 1e9));
	
	// traverse directions easily
	vector<int> xdir = {-1, 0, 1, 0};
	vector<int> ydir = {0, -1, 0, 1};
	
	// helper function
	auto valid = [&](int x, int y) {
		return x >= 0 && x < H 
			&& y >= 0 && y < W
			&& S[x][y] == '.';
	};
	
	// initialization
	q.push_front(C);
	dist[C.first][C.second] = 0;
	
	// 0/1 BFS
	while (!q.empty()) {
		int x, y;
		tie(x, y) = q.front();
		q.pop_front();
		
		// reached target
		if (x == D.first && y == D.second)
			return dist[x][y];
		
		// use move a
		for (int k = 0; k < xdir.size(); k++) {
			int nx = x + xdir[k], ny = y + ydir[k];
			if (valid(nx, ny) && dist[nx][ny] > dist[x][y]) {
				q.push_front({nx, ny});
				dist[nx][ny] = dist[x][y];
			}
		}
		
		// use move b
		for (int nx = -2 + x; nx <= 2 + x; nx++)
			for (int ny = -2 + y; ny <= 2 + y; ny++)
				if (valid(nx, ny) && dist[nx][ny] > dist[x][y] + 1) {
					q.push_back({nx, ny});
					dist[nx][ny] = dist[x][y] + 1;
				}
	}
	
	return -1;
}

int main() {
	int H, W;
	pair<int, int> C, D;
	cin >> H >> W >> C.first >> C.second >> D.first >> D.second;
	C.first--, C.second--, D.first--, D.second--;
	vector<string> S(H);
	for (int i = 0; i < H; i++)
		cin >> S[i];
	cout << wizard_in_maze(H, W, C, D, S);
	return 0;
}

Measured memory_bytes: 9532
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

int dx[] = {0, -1, 1, 0};
int dy[] = {-1, 0, 0, 1};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    sort( s.begin(), s.end() );
    if( s[0] == s[1] && s[2] == s[3] && s[1] != s[2] ) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T = int>inline T in() { T x; cin >> x; return x; }
#define REP(i,n) for(ll i=0;i<(n);++i)
#define REP1(i,n) for(ll i=1;i<=(n);++i)
#define REPI(i,ini,n) for(ll i=(ini);i<(n);++i)
#define REPC(i,obj) for(auto i:obj)
#define R_UP(a,b) (((a)+(b)-1)/(b))
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1e9
#define INFL static_cast<ll>(INF)
int main()
{
	while (true)
	{
		int r0 = in(), w0 = in(), c = in(), r = in();
		if (r0 == 0 && w0 == 0 && c == 0 && r == 0)break;
		int n = R_UP(w0 * c - r0, r);
		cout << (n < 0 ? 0 : n) << endl;
	}
}


Measured memory_bytes: 3040
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;

int main(){
	vector<int> a(10,0);
	rep(i,4){
		int x;
		cin>>x;
		a[x]++;
	}
	if(a[1]*a[9]*a[7]*a[4])cout<<"YES";
	else cout<<"NO";
}


Measured memory_bytes: 256
#include <cstdio>
#define MAXN 300005
using namespace std;

int n, x;
int sol[MAXN];

void printSol() {
    for(int i = 1; i < 2 * n; ++i)
        printf("%d\n", sol[i]);
}

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

    if(x == 1 || x == 2 * n - 1)
        return 0 * printf("No\n");

    printf("Yes\n");
    sol[n] = x;
    sol[n - 1] = x - 1;
    sol[n + 1] = x + 1;

    if(n == 2) {
        printSol();
        return 0;
    }

    if(x < 2 * n - 2) sol[n - 2] = x + 2;
    if(x > 2) sol[n + 2] = x - 2;

    int cnt = 1;
    for(int i = 1; i <= 2 * n - 1; ++i) {
        while(x - 2 <= cnt && cnt <= x + 2) ++cnt;
        if(!sol[i])
            sol[i] = (cnt++);
    }
    
    printSol();

    return 0;
}

Measured memory_bytes: 2304
#include <stdio.h>
#include <stdlib.h>

int q(const int *a,const int *b)
{
    return *a-*b;
}

int main(void)
{
    int n[3],s=1;
    scanf("%d%d%d",&n[0],&n[1],&n[2]);
    qsort(n,3,4,q);
    if(n[0]!=n[1])s++;
    if(n[1]!=n[2])s++;
    printf("%d",s);
    return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  if (a%3==0) cout << "Possible" << endl;
  else if (b%3==0) cout << "Possible" << endl;
  else if ((a+b)%3==0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}


Measured memory_bytes: 256
#include <queue>
#include <string>
#include <iostream>
using namespace std;
int n; string s;
bool solve(int x) {
	vector<int> vo;
	queue<int> que;
	vector<bool> used(n, false);
	for (int i = n - 1; i >= 0 && vo.size() < x; i--) {
		if (s[i] == 'I') que.push(i);
		if (s[i] == 'O' && que.size()) {
			vo.push_back(i);
			used[i] = true;
			used[que.front()] = true;
			que.pop();
		}
	}
	if (vo.size() < x) return false;
	int ptr = n - 1, cnt = 0;
	while (ptr >= 0 && cnt < x) {
		ptr = min(ptr, vo[cnt]);
		while (ptr >= 0 && (s[ptr] == 'O' || used[ptr])) ptr--;
		if (ptr < 0) break;
		used[ptr] = true;
		cnt++;
	}
	return (cnt == x);
}
int main() {
	cin >> n >> s;
	int l = 0, r = n / 3 + 1;
	while (r - l > 1) {
		int m = (l + r) / 2;
		if (solve(m)) l = m;
		else r = m;
	}
	cout << l << endl;
	return 0;
}

Measured memory_bytes: 7376