akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace AOJ
{
  class Program
  {
    static void Main()
    {
      int[] data = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
      int r = data[0];
      int c = data[1];
      int row_sum, col_sum, i, j;
      int[] cols = new int[c];
      for (i = 0; i < c; i++) cols[i] = 0;

      col_sum = 0;
      for (i = 0; i < r; i++)
      {
        data = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        row_sum = 0;
        for (j = 0; j < c; j++)
        {
          Console.Write("{0} ", data[j]);
          row_sum += data[j];
          cols[j] += data[j];
        }
        Console.WriteLine(row_sum);
        col_sum += row_sum;
      }

      for (i = 0; i < c; i++)
        Console.Write("{0} ", cols[i]);
      Console.WriteLine(col_sum);
    }
  }
}

Measured memory_bytes: 9732
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define oset tree < int ,  null_type ,  less ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define endl '\n'
#define int long long int
#define db long double
#define str string
#define mod 1000000007
#define ff first
#define ss second
#define PQi priority_queue<int>
#define Vi vector<int>
#define Si set<int>
#define Li list<int>
#define mk make_pair
#define pii pair<int,int>
#define all(x) (x.begin(),x.end())
#define pb(x) push_back(x)
#define For(i,n,s) for(int i=s;i<n;i++)
#define mat2D(T,r,c) vector<vector<int> > T(r,vector<int>(c))
#define vec2D vector<vector<int> >
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define getVal(x) {int val;cin>>val;x.pb(val);}
#define debug(x) {for(auto i :x) cout << i << " ";cout << endl;}

void solve() {
    int w, a, b;
    cin >> w >> a >> b;
    int ans1 = b - (a + w) >= 0 ? b - (a + w) : INT_MAX;
    int ans2 = a - (b + w) >= 0 ? a - (b + w) : INT_MAX;
    cout << (min(ans2, ans1) == INT_MAX ? 0 : min(ans1, ans2));
}

int32_t main() {
    fastIO;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
# endif
    solve();
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> ii;

ll n, k;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    n = n % k;
    if (n == 0) {
      cout << 0 << endl;
      return 0;
    }
    ll m = min(n, k - n);
    cout << m << endl;

    return 0;
}


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

using namespace std;

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  unsigned long long int num;
  char c;
  string ans;
  cin >> num;
  while (num){
    c = ('a' + (num - 1) % 26);
    num -= ((num - 1) % 26 + 1);
    num /= 26;
    ans.insert(0, 1, c);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define rrep1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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; }

int n, q;
string s;
int bit[26][1000010];

int sum(int i, int j) {
    int s = 0;
    while (j > 0) {
        s += bit[i][j];
        j -= j & -j;
    }
    return s;
}

void add(char c, int i, int x) {
    while (i <= n) {
        bit[c - 'a'][i] += x;
        i += i & -i;
    }
}

int main() {
    cin >> n >> s >> q;
    rep(i, n) {
        add(s[i], i+1, 1);
    }
    rep(i, q) {
        int t; cin >> t;
        if (t == 1) {
            int iq; char cq;
            cin >> iq >> cq;
            add(s[iq-1], iq, -1);
            s[iq-1] = cq;
            add(cq, iq, 1);
        } else {
            int l, r;
            cin >> l >> r;
            int cnt = 0;
            rep(j, 26) {
                if (sum(j, r) - sum(j, l-1) > 0) cnt++;
            }
            cout << cnt << endl;
        }
    }
}


Measured memory_bytes: 101124
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int n,m;
    cin >> n >> m;
    vector<int> l(m);
    vector<int> r(m);

    int r_min = n;
    int l_max = 1;
    for(int i=0;i<m;++i){
        cin >> l[i] >> r[i];
        if( r[i] < r_min ){
            r_min = r[i];
        }
        if( l_max < l[i] ){
            l_max = l[i];
        }
    }

    // cerr << r_min << l_max << endl;

    if( l_max <= r_min ){
        cout << r_min - l_max + 1 << endl;
    }
    else {
        cout << 0 << endl;
    }


	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <climits>
#include <algorithm>
using namespace std;

const int INF = 1<<29;

int main() {
  
  int N;
  cin >> N;
  
  int h[100010];
  int dp[100010];
  
  for(int i=0; i<N; i++){
    cin >> h[i];
  }
  
  for(int i=0; i<N; i++){
    dp[i] = INF;
  }
  dp[0] = 0;
  dp[1] = abs(h[1]-h[0]);
  for(int i=0; i<N; i++){
    dp[i+2] = min(dp[i+1]+abs(h[i+2]-h[i+1]), dp[i]+abs(h[i+2]-h[i]));
  }
  
  cout << dp[N-1] <<endl;
  
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <complex>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

typedef complex<double> C;

const double PI = acos(-1.);

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, l;
  cin >> n >> l;
  vector<int> t(n);
  cin >> t;
  vector<double> theta(n);
  transform(t.begin(), t.end(), theta.begin(), [&](int t) { return 2 * PI * t / l; });
  function<C(double)> unit = [](double theta) {
    return C(cos(theta), sin(theta));
  };
  C ans = 0;
  C sum = 0;
  for (int i = 1; i < n - 1; ++i) {
    sum += unit(theta[i - 1] * .5);
    for (int j = i + 1; j < n; ++j) {
      C center = unit((theta[i] + theta[j]) * .5);
      double r = sin((theta[j] - theta[i]) * .25) * 2;
      C relative = sum * unit((theta[i] + theta[j]) * .25 - PI * .5);
      ans += center * (double)i + r * relative;
    }
  }
  ans /= n * (n - 1) * (n - 2LL) / 6;
  printf("%.15f %.15f\n", ans.real(), ans.imag());

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 256
N, S, T = map(int, input().split())
S -= 1
T -= 1

edges = [[] for _ in range(N)]
for _ in range(N - 1):
    fr, to = map(lambda a: int(a) - 1, input().split())
    edges[fr].append(to)
    edges[to].append(fr)

def calc(s):
    minDist = [10**18] * N
    minDist[s] = 0
    st = [s]
    while st:
        now = st.pop()
        d = minDist[now] + 1
        for to in edges[now]:
            if minDist[to] > d:
                minDist[to] = d
                st.append(to)

    return minDist

minDistS = calc(S)
minDistT = calc(T)

ans = 0
for s, t in zip(minDistS, minDistT):
    if s <= t:
        ans = max(ans, t - 1)
print(ans)


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

int main() {
  int a,b,c;
  cin >> a>>b>>c;


  int ans=0;
  //偶奇を一致させる
  int resa= a%2;
  int resb= b%2;
  int resc= c%2;
  if(resa==1 && resb==0 && resc ==0){
    ans ++;
    b ++;
    c ++;
  }
  if(resa==0 && resb==1 && resc ==0){
    ans ++;
    a ++;
    c ++;
  }
  if(resa==0 && resb==0 && resc ==1){
    ans ++;
    a ++;
    b ++;
  }
  if(resa==0 && resb==1 && resc ==1){
    ans ++;
    b ++;
    c ++;
  }
  if(resa==1 && resb==0 && resc ==1){
    ans ++;
    a ++;
    c ++;
  }
  if(resa==1 && resb==1 && resc ==0){
    ans ++;
    a ++;
    b ++;
  }
  int m = max(a,max(b,c));
  ans += (m-a)/2 + (m-b)/2 + (m-c)/2;
  cout<<ans<<endl;

  }


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a, b;
	scanf("%d %d", &a, &b);
	if(a < b){
		printf("a < b\n");
	}
	else if(a > b){
		printf("a > b\n");
	}
	else{
		printf("a == b\n");
	}
	return 0;
}

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

int main() {
 long long n,ans;
  cin>>n;
  ans=0;
 if(n%2==1)cout<<0<<endl;
  else {
    n/=2;
    while(n!=0){
      n/=5;
      ans+=n;
    }
    cout<<ans<<endl;
  }
}


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

int main()
{
    string s,ans;

    cin >> s;
    if (s >= "a" && s <= "z")
        ans = "a";
    if (s >= "A" && s <= "Z")
        ans = "A";

    cout << ans << endl;
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int a,b; cin >> a >> b;
  int c,d; cin >> c >> d;

  int ans = a*b>=c*d ? a*b:c*d;

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


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

using namespace std;

#define REPN(n) for(int _i = 0; _i < (n); _i++)
#define YES_OR_NO(x) (cout << ((x) ? "YES" : "NO") << endl)

void test_case() {
  int x;
  cin >> x;
  cout << !x << endl;
}

int main(void) {
  int t = 1;
  // cin >> t;
  while (t--) {
    test_case();
  }
  return 0;
}


Measured memory_bytes: 3632
use std::io::*;
use std::str::FromStr;
 
/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
 
//main function
fn main() {
    let h: i32 = read();
    let n: i32 = read();
    let mut sum: i32 = 0;
    for _i in 0..n{
	let a: i32 = read();
	sum += a;
	if sum>=h{
	    println!("Yes");
	    return;
	}
    }
    if sum>=h{
	println!("Yes");
    }else{
	println!("No");
    }
    
}


Measured memory_bytes: 4352
#include<iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
#define cDefNum (10)

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

	int S[3] = { cDefNum,cDefNum,cDefNum };

	for (size_t i = 0; i < M; ++i)
	{
		int si, ci;
		cin >> si>> ci;
		if (S[si - 1] != cDefNum && S[si - 1] != ci)
		{
			cout << -1 << endl;
			return 0;
		}
		S[si - 1] = ci;
	}

	if ( S[0] == 0 && N > 1)
	{
		cout << -1 << endl;
		return 0;
	}

	if (S[0] == cDefNum && N == 1)//N==1
	{
		cout << 0 << endl;
		return 0;
	}
	
	if (S[0] == cDefNum)
	{
		S[0] = 1;
	}
	for (size_t i = 0; i < N; ++i)
	{
		cout << (S[i] == cDefNum ? 0 : S[i]);
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 3184
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };





signed main() {
	int l, m, n, cnt = 0, maxn=-19999999, minn=199999999;
	string s;
	vector<int>listb;
	vector<int>list;
	vector<string>slist;
	int h, w, c;
	vector<vector<int>>mat(100005, vector<int>(2, 0));
	//vector<pair<int, int>>pmat(100005);
	vector<pair<int, int>>pmat;
	
	cin >> n >> m;

	for (int i = 0; i < n; i++) {  //num1 金額        num2 個数
		int num1, num2;
		cin >> num1 >> num2;

		pmat.push_back(make_pair(num1, num2));
		//pmat[i].first = num1;
		//pmat[i].second = num2;
		
	}

	sort(pmat.begin(), pmat.end());
	int sum = 0;

	for (int i = 0; i < n; i++) {
		sum += pmat[i].first * pmat[i].second;
		cnt += pmat[i].second; //個数

		if (cnt >= m) {
			sum -= (cnt - m) * pmat[i].first;
			break;
		}
	}

	cout << sum << endl;




	return 0;
}

Measured memory_bytes: 7924
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))
kaiteki = 1000
for i in range(n):
        heikin = abs(a - (t - h[i] * 0.006))
        if kaiteki > heikin:
                basho = i + 1
                kaiteki = heikin
print(basho)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long lnt;
int n, k;	lnt ans = 4e18;
struct node {int x, y;} p[100];
bool cmp(const node &a, const node &b) {return a.x < b.x;}
int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++)	scanf("%d%d", &p[i].x, &p[i].y);
	sort(p+1, p+n+1, cmp);
	for (int i = 1; i <= n; i++)	for (int j = i+k-1; j <= n; j++) {
		vector <int> tmp;
		for (int t = i; t <= j; t++)	tmp.push_back(p[t].y);
		sort(tmp.begin(), tmp.end());
		for (int t = 0; t <= tmp.size()-k; t++)	ans = min(ans, (lnt)(p[j].x-p[i].x)*(tmp[t+k-1]-tmp[t]));
	}
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void)
{
	int i,a;
	char s[100001];
	scanf("%s",s);
	a=strlen(s);
	for(i=0; i<a; i=i+2){
		printf("%c",s[i]);
	}
	printf("\n");
	return 0;
}

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

int main(){
	int k,n,i,len=0;
	cin >> k;
	cin >> n;
	int a[n],dis[n];
	for(i = 0; i < n; i++){
		cin >> a[i];
	}
	for(i = 0; i < n-1; i++){
		dis[i] = a[i+1] - a[i];
		if(dis[i] > len){
			len = dis[i];
		}
	}
	dis[n-1] = k + a[0] - a[n-1];
	if(dis[n-1] > len){
		len = dis[n-1];
	}
	cout << k - len;

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main() {
    int n; char m; int x;
    cin >> n;
    char mark[4] = {'S', 'H', 'C', 'D'};
    bool card[4][14] = {{false}};
    for(int i = 0; i < n; ++i) {
        cin >> m >> x;
        if(m == 'S') card[0][x] = true;
        else if(m == 'H') card[1][x] = true;
        else if(m == 'C') card[2][x] = true;
        else card[3][x] = true;
    }
    for(int i = 0; i < 4; ++i) {
        for(int j = 1; j < 14; ++j) {
            if(!card[i][j]) {
                cout << mark[i] << " ";
                cout << j << endl;
            }
        }
    }
    return 0;
}


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

int main(){
	vector<int> A(9);
    rep(i,9) cin >> A[i];
    vector<bool> C(9, false);
    
    int N;
    cin >> N;
    vector<int> B(N);
    rep(i,N) cin >> B[i];
    
    rep(i,N) {
    	rep(j,9) {
          if (B[i] == A[j]) C[j] = true;
        }
    }
  
  	bool flag = false;
  
  	if (C[1] && C[2] && C[0]) flag = true;
  	if (C[4] && C[5] && C[3]) flag = true;
  	if (C[7] && C[8] && C[6]) flag = true;
  	if (C[1] && C[4] && C[7]) flag = true;
  	if (C[2] && C[5] && C[8]) flag = true;
  	if (C[0] && C[3] && C[6]) flag = true;
  	if (C[0] && C[4] && C[8]) flag = true;
  	if (C[2] && C[4] && C[6]) flag = true;
  
    if (flag) cout << "Yes" << endl;
  	else cout << "No" << endl;
    	
  

}

Measured memory_bytes: 256
open System

// prelude
let readStr () = stdin.ReadLine()

let readInt () = stdin.ReadLine() |> int
let readInts () = stdin.ReadLine().Split() |> Array.map int

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let inc n = n + 1
let dec n = n - 1

let inline flip f a b = f b a
let rec fix f = fun x -> (f (fix f)) x

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

module Array =
  let modify (arr: _ []) i f =
    arr.[i] <- f arr.[i]

module Array2D =
  let modify (arr: _ [,]) i j f =
    arr.[i, j] <- f arr.[i, j]

// start
let N = readInt()
let Ss = readStr()
let S = Ss.ToCharArray()

let rec left s i =
  if i>=N then 0
  elif S.[i]='(' then left (s+1) (i+1)
  else if s=0 then 1+left s (i+1) else left (s-1) (i+1)

let rec right s i =
  if i<0 then 0
  elif S.[i]=')' then right (s+1) (i-1)
  else if s=0 then 1+right s (i-1) else right (s-1) (i-1)

let l=left 0 0
let r=right 0 (N-1)

("(" |> String.replicate l)+Ss+(")" |> String.replicate r)
|> printfn "%s"

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

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

    long long *L = (long long *) malloc(sizeof(long long) * N);
    L[0] = 2;
    L[1] = 1;

    for (int i = 2; i <= N; i++) {
        long long tmp_sum = 0;
        for (int j = i - 2; j < i; j++) {
            tmp_sum += L[j];
        }
        L[i] = tmp_sum;
    }

    printf("%lld\n", L[N]);
    return 0;
}


Measured memory_bytes: 128
L = input()
n = 1
p = (1, 0)  # 3 ** 0 = 1
mod = 10 ** 9 + 7

for i in range(len(L)):
    if L[len(L) - 1 - i] == '1':
        k = (p[0] * (3 ** (i - p[1]))) % mod
        n = (n * 2 + k) % mod
        p = (k, i)

print(n)


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;

using Graph = vector<vector<int>>;

int main()
{
    ll l, r;
    cin >> l >> r;
    ll MIN = 1001001001;
    if (r - l >= 2019)
    {
        cout << 0 << endl;
        return 0;
    }
    else
    {
        for (ll i = l; i < r; i++)
        {
            for (ll j = i + 1; j <= r; j++)
            {
                MIN = min(MIN, (i * j) % 2019);
            }
        }
        cout << MIN << endl;
    }

    return 0;
}


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

using namespace std;

#define ll long long

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

int main() {
    string str, com, w;
    int    n, a, b;
    cin >> str;
    cin >> n;
    rep(i, n) {
        cin >> com >> a >> b;
        if (com == "print") {
            cout << str.substr(a, b - a + 1) << "\n";
        } else if (com == "reverse") {
            string tmp = str.substr(a, b - a + 1);
            int    k   = tmp.size();
            int    u   = 0;
            repr(i, k - 1) {
                tmp[u] = str[a + i];
                u++;
            }
            str = str.replace(a, b - a + 1, tmp);
        } else if (com == "replace") {
            cin >> w;
            str = str.replace(a, b - a + 1, w);
        }
    }

    return 0;
}



Measured memory_bytes: 3220
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class227
    {
        static void Main()
        {
            var NP = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long N = NP[0], P = NP[1];
            long ans = 1;
            if (N == 1) { Console.WriteLine(P);return; }
            for(int i = 2; Math.Pow(i,N)<=P+1; i++)
            {
                if (P % Math.Pow(i, N) == 0) ans = i;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  ll t=1;
  while(t--)
  {
    string s,t;
    cin>>s>>t;
    int count=0;
    REP(i,s.length())
    {
        if(s[i]!=t[i])
        count++;
    }
    if(count==0)
    cout<<"Yes\n";
    else cout<<"No\n";
  }  
  return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
int kai(int n){
	if(n==0) return 1;
	int ans;
	ans=n*kai(n-1);
	return ans;
}
int main(){
	int max,x=0,n;
	string s;
	cin>>n;
	cin>>s;
	max=x;
    for(int i=0;i<n;i++){
		if(s[i]=='I'){
			x+=1;
			if(max<x) max=x;
		}else x-=1;
	}
	cout<<max<<endl;
	return 0;
}

Measured memory_bytes: 4352
#include<stdio.h>
int n,a,i,x,max,min;
long long s;
int main(void)
{
	
	
	max=-1000000;
	min=1000000;
	s=0;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d",&a);
		s+=a;
		if(max<a) max=a;
		if(min>a) min=a;
/*		s=s+a;
		if(a==0) printf("AA\n");
		if(s==5019101515) printf("AA\n");*/
	}
	
	printf("%d %d %lld\n",min,max,s);
	
	return 0;
}


Measured memory_bytes: 2744
// AOJ NTL_1- B Elementary Number Theory - Power
// 2017.10.31 bal4u@uu

#include <stdio.h>

int big_mod(int b, int p, int m)
{
   long long s = 1;
   long long d;

   d = b % m;
   while (p > 0) {
      if (p & 1) s = (s * d) % m;
      p >>= 1;
      d = (d * d) % m;
   }
   return (int)s;
}


int main()
{
	int m, n;

	scanf("%d%d", &m, &n);
	printf("%d\n", big_mod(m, n, 1000000007));
	return 0;
}

Measured memory_bytes: 1840
#include<stdio.h>
#include<math.h>
int main()
{
    int a[101],j,n,i,t,al,bo;
    while(~scanf("%d",&n))
    {
        al=0,bo=0;
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
        for(i=0;i<n-1;i++)
            for(j=0;j<n-1-i;j++)
            if(a[j]<a[j+1])
        {
            t=a[j];
            a[j]=a[j+1];
            a[j+1]=t;
        }
        for(i=0;i<n;i++)
        {
            if(i%2==0)
                al=al+a[i];
            else
                bo=bo+a[i];
        }
        printf("%d\n",al-bo);
    }
    return 0;
}


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


int main()
{
    long long int a,b,c,A=0,B=0,C=0,sum=0,i;
    int flag1=0;
    int flag2=0;
    int flag3=0;
    cin>>a>>b>>c;
    //cout<<a<<b<<c;

    for(i=0;;i++)
    {
        if(a==b && b==c )
        {
            if((a%2==0) && (b%2==0) && (c%2==0))
            {
                flag1=1;
                break;
            }
        }
        if(a%2 !=0 || b%2 !=0 || c%2 !=0)
        {
            //flag2=1;
            break;
        }

        A=a/2;
        B=b/2;
        C=c/2;
        a=0;
        b=0;
        c=0;
        a=B+C;
        b=A+C;
        c=A+B;
    }
    if(flag1==1)
    {
        cout<<"-1";
    }
    else
    {
        cout<<i;
    }

    return 0;
}


Measured memory_bytes: 256
def main() -> None:
    N = int(input())
    A = [[int(x) for x in input().split()] for _ in range(N)]

    dp = [0] * (1 << N)
    dp[0] = 1
    for state in range(1 << N):
        for i in range(N):
            for j in range(i, N):
                if (state >> i & 1) and (state >> j & 1):
                    dp[state] += A[i][j]
        sub_state = state & (state - 1)
        while sub_state > 0:
            not_sub = state & ~sub_state
            if sub_state < not_sub:
                break
            dp[state] = max(dp[state], dp[sub_state] + dp[not_sub])
            sub_state = state & (sub_state - 1)
    print(dp[-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 74412
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll x,ll y){
    if(y==0)return x;
    return gcd(y,x%y);
}
ll a,n,m,ans=1;
int main(void){
    cin>>a>>m;
    n=gcd(a,m);
    for(ll i=2;i<=1e6;i++){
        if(n%i==0)ans++;
        while(n%i==0){
            n/=i;
            //cout<<i<<endl;
        }
    }
    if(n!=1)ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
K,N = map(int,input().split())
A = list(map(int,input().split()))
B = [0]*N
for i in range(N-1):
    B[i] = A[i+1] - A[i]
B[-1] = K-A[-1]+A[0]
B.sort()
print(sum(B[:-1]))


Measured memory_bytes: 26420
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

#[allow(dead_code)]
fn chmin<T>(x: &mut T, y: T) -> bool
where
    T: PartialOrd + Copy,
{
    *x > y && {
        *x = y;
        true
    }
}

#[allow(dead_code)]
fn chmax<T>(x: &mut T, y: T) -> bool
where
    T: PartialOrd + Copy,
{
    *x < y && {
        *x = y;
        true
    }
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque};

fn main() {
    input!(n:usize, dams:[usize;n]);

    let mut mts = vec![0usize;n];
    let mut even_d = 0;
    let mut odd_d = 0;
    for i in 0..n {
        if i % 2 == 0 {
            even_d += dams[i];
        } else {
            odd_d += dams[i];
        }
    }
    mts[0] = even_d - odd_d;
    mts[n-1] = 2*dams[n-1] - mts[0];
    for i in (1..n-1).rev() {
        mts[i] = 2 * dams[i] - mts[i+1];
    }

    for i in 0..n {
        if i == n - 1 {
            println!("{}", mts[i]);
        } else {
            print!("{} ", mts[i]);
        }
    }
}


Measured memory_bytes: 7420
#include <bits/stdc++.h>
#define boost ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define M 1000000007
#define eb emplace_back
#define watch(x) cout << (#x) <<" is "<< x <<"\n";


using namespace std;
//const int N = 1e6;

int32_t main(){
  boost;
  int tc = 1; //cin >> tc;
  while(tc--)
  {
    int n; cin >> n;
    int arr[n];
    for(int i=0; i<n; i++)
      cin >> arr[i];
    sort(arr, arr+n);
    int ans = arr[n-1];
    int cnt = 1;
    for(int i=n-2; cnt<n-1; i--)
    {
      ans += arr[i];
      cnt++;
      if(cnt < n-1)
      {
        ans += arr[i];
        cnt++;
      }
    }
    cout << ans <<"\n";
  }
}



Measured memory_bytes: 5220
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		int i, j, m, h, length;
		String str1, str2;
		char c1[], c2[];
		Scanner sc = new Scanner(System.in);
		while (true) {
			str1 = sc.next();
			if (str1.equals("-")) {
				break;
			}
			length = str1.length();
			m = sc.nextInt();
			for (i = 0; i < m; ++i) {
				h = sc.nextInt();
				c1 = new char[h];
				for (j = 0; j < h; ++j) {
					c1[j] = str1.charAt(j);
				}
				str2 = String.valueOf(c1);
				c2 = new char[length - h];
				int k = 0;
				for (j = h; j < length; ++j) {
					c2[k] = str1.charAt(j);
					++k;
				}
				str1 = String.valueOf(c2);
				str1 = str1 + str2;
			}
			System.out.println(str1);
		}
		sc.close();
	}
}


Measured memory_bytes: 26300
def max2(x,y):
    return x if x > y else y

def divisors(n):
    i = 1
    table = set()
    while i * i <= n:
        if not n % i:
            table.add(i)
            table.add(n//i)
        i += 1
    table = list(table)
    return table

import numpy as np
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
S = sum(A)
D = divisors(S)
D.sort()
res = 0
for k in D:
    B = A%k
    B.sort()
    cnt = sum(B)//k
    if k*cnt - sum(B[-cnt:]) <= K:
        res = max2(res, k)

print(res)

Measured memory_bytes: 27240
#include <stdio.h>
#include <string.h>
#include <string>
#include <algorithm>
#include <vector>


int main()
{
    int cas;
    scanf("%d", &cas);
    while (cas--) {
        int a, b, c, d;
        scanf("%d%d%d%d", &a, &b, &c, &d); -- c;
        int k = (a + b) / (std::min(a, b) + 1);
        int l = 0, r = a + 1;
        while (l + 1 < r) {
            int mid = l + r >> 1;
            int ra = a - mid, rb = b - std::max(0, (mid - 1) / k);
            if ((long long)(ra + 1) * k < rb)
                r = mid;
            else
                l = mid;
        }
        std::string s;
        for (int i = c; i < d; ++ i) {
            int na = l;
            int nb = std::max(0, (na - 1) / k);
            if (i < (long long)nb * (k + 1)) {
                s += "AB"[i % (k + 1) == k];
            } else if (i < na + nb) {
                s += 'A';
            } else {
                int j = a + b - i - 1;
                nb = b - nb;
                na = std::max(0, (nb - 1) / k);
                if (j < (long long)na * (k + 1))
                    s += "BA"[j % (k + 1) == k];
                else
                    s += 'B';
            }
        }
        printf("%s\n", s.c_str());
    }
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,a;
    int k,c=0;
    vector<char>v;
    vector<char>::iterator it;
    cin>>k;
    cin>>s;
    //cout<<s.length();
    if(s.length()<=k)
    {
        cout<<s<<endl;
    }
    else
    {
        for(int i=0; i<s.length(); i++)
        {
            v.push_back(s[i]);
            if(c==k-1){
                break;}

            c++;
        }
        for(it=v.begin(); it!=v.end(); it++)
        {
            cout<<*it;
        }
        cout<<"...";
    }
}


Measured memory_bytes: 3628
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>

int main() {
  int N, M;
  scanf("%d %d", &N, &M);

  std::vector<std::map<int, int>> A(M);
  std::vector<int> B(M);
  for (int i=0; i<N; ++i) {
    int X;
    scanf("%d", &X);
    ++A[X%M][X];
    ++B[X%M];
  }

  int res=0;
  for (int i=0; i<=M/2; ++i) {
    if (i == M-i || i == 0) {
      res += B[i]/2;
      continue;
    }

    int cur = std::min(B[i], B[M-i]);
    res += cur;

    if (B[i] == B[M-i])
      continue;

    int k=i;
    if (B[i] < B[M-i])
      k = M-i;

    //int rest=B[k]-B[i^(M-i)^k];
    int rest=cur;
    int pairs=0;
    for (std::pair<const int, int> &p: A[k]) {
      if (rest > 0 && p.second % 2) {
        --p.second;
        --rest;
      }

      pairs += p.second / 2;
      //fprintf(stderr, "%d: %d\n", p.first, p.second/2);
    }

    while (rest > 0) {
      --pairs;
      rest -= 2;
    }

    res += pairs;
  }

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


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

using namespace std;
using ll = long long;

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

    map<int, int> M;
    int Max = 0;
    for (int i = 0; i < N; ++i) {
        int x;
        cin >> x;
        Max = max(Max, x);
        M[x] += 1;
    }

    int ans = 0;
    for (int i = 0; i <= Max; ++i)
        ans = max(ans, M[i] + M[i + 1] + M[i + 2]);
    cout << ans << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>


using namespace std;

int main(){
    
    int A, B;
    
    cin >> A >> B;
    
    if ((A+B) % 2 == 0) {
        cout << (A+B)/2 << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
    
    
    return 0;
    
}


Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

l,r,d = I()
for i in range(l,r+1):
    if i % d == 0:
        cnt += 1

print(cnt)


Measured memory_bytes: 10200
#include <stdio.h>
#include <vector>
#include <math.h>
#include <iostream>
int main(){

    using namespace std;

    int a, b, ans1, ans2, ans3, ans4;
    int ans = 0;

    int c, d;
    bool aFlag = false;
    bool bFlag = false;

    cin >> a >> b;


         for(int i=0;i<=1250 ; i++)
         {
             //if(i * 8 / 100 == a && i / 10 == b)
             
             if( i * 0.08 == a) aFlag = true;
             if(i * 8 / 100 == a) bFlag = true;
             
             //cout << aFlag << " " << bFlag << endl;
                 if(int(i * 0.08) == a && int(i * 0.1) == b)
             {
                 cout << i << endl;
                     return  0;

             }



         }
    
    //cout << int(991 * 0.08) << " " << int(991 * 8 / 100) << endl;
    
    cout << -1 << endl;

    //cout << c << endl;


    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[100005][2];
int f(int k, int* a, int n, bool p)
{
    for(int i=0;i<=k;i++)
    {
        for(int j=0;j<n;j++)
        {
             if(i>=a[j])
            {
                if( dp[i-a[j]][0]==1)dp[i][1]=1;
                if( dp[i-a[j]][1]==0)dp[i][0]=0;
            }
        }
        if(dp[i][1]==-1)dp[i][1]=0;
        if(dp[i][0]==-1)dp[i][0]=1;
    }
    return dp[k][1];
}
int main()
{
    int n,k;
    cin>>n>>k;
    int* a=new int[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<100004;i++)
    {
        dp[i][0]=-1;
        dp[i][1]=-1;
    }
    if(f(k,a,n,true))cout<<"First";
    else cout<<"Second";
}

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

struct node{
    struct node *right;
    struct node *left;
    struct node *parent;
    int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

/*Node treeMinimum(Node x){
    
}

Node treeMaximum(Node x){
    
}

 */Node treeSearch(Node u,int k){
     while(u!=NIL && k!=u->key){
         if(k<u->key)u=u->left;
         else u=u->right;
     }
     return u;
}

/*Node treeSuccessor(Node x){
    
}
*/
void insert(int k){
    Node y=NIL;
    Node x=root;
    Node z;
    
    z=malloc(sizeof(struct node));
    z->key=k;
    z->left=NIL;
    z->right=NIL;
    
    while(x!=NIL){
        y=x;
        if(z->key<x->key)x=x->left;
        else x=x->right;
    }
    z->parent=y;
    
    if(y==NIL)root=z;
    else if(z->key<y->key)y->left=z;
    else y->right=z;
}

void inorder(Node u){
    if(u==NIL)return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node u){
    if(u==NIL)return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}


int main(){
    int n, i, x;
    char com[20];
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
        scanf("%s", com);
        if ( com[0] == 'f' ){
            scanf("%d", &x);
            Node t = treeSearch(root, x);
            if ( t != NIL ) printf("yes\n");
            else printf("no\n");
        } else if ( com[0] == 'i' ){
            scanf("%d", &x);
            insert(x);
        } else if ( com[0] == 'p' ){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        } /*else if ( com[0] == 'd' ){
            scanf("%d", &x);
            treeDelete(treeSearch(root, x));
        }*/
    }
    
    return 0;
}



Measured memory_bytes: 20496
n = gets.to_i
l = gets.chop.split.map(&:to_i)

maxi = 0

cnt = 0
(n-1).times do |i|
    if l[i] >= l[i+1]
        cnt += 1
    else
        cnt = 0
    end
    maxi = [cnt,maxi].max
end

puts maxi

Measured memory_bytes: 21760
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>

#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#include <utility>
#include <list>

#include <cmath>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <complex>
#include <climits>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
#define mp make_pair
#define pb push_back

#define debug(x) cerr << #x << " = " << x << " "

int main()
{
  int ret = 0;
  map<int, int> rev_lb;
  const int N = 31;
  vector<bool> v(N, false);
  vector<bool> vis(N, false);
  for (int i = 0; i < N; ++i)
    rev_lb[1<<i] = i;
  int n; scanf("%d", &n);
  for (int i = 0; i < n; ++i)
    {
      int x; scanf("%d", &x);
      int lb = x & -x;
      int tar = rev_lb[lb];
      v[tar] = !v[tar];
      vis[tar] = true;
      ret ^= (x ^ lb);
    }
  int ans = -1;
  if (true)
    {
      ans = 0;
      bool mask = 0;
      for (int i = N-1; i >= 0; --i)
	{
	  bool fixed = (ret >> i) & 1;
	  bool tmp = v[i] ^ mask ^ fixed;
	  if (tmp)
	    {
	      if (vis[i])
		{
		  ++ans;
		  mask = !mask;
		}
	      else 
		{
		  ans = -1;
		  break;
		}
	    }
	}
    }
  printf("%d\n", ans);
}


Measured memory_bytes: 256
def get_int
  gets.chop.to_i
end

def get_ints
  gets.chop.split.map(&:to_i)
end

def get_double
  gets.chop.to_f
end

def get_str
  gets.chop
end

def get_strs
  gets.chop.split
end

def main
  n = get_int
  1.upto(n) do |i|
    if n % i == 0
      j = n / i
      if i <= 9 and j <= 9
        puts "Yes"
        exit 0
      end
    end
  end
  puts "No"
end

if __FILE__ == $0
  main
end

Measured memory_bytes: 1788
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	Scanner sc = new Scanner(System.in);

	int INF = 1 << 28;
	double EPS = 1e-9;

	int t;
	int m0, year;
	int n;
	int[] a, cost;
	double[] rate;

	void run() {
		t = sc.nextInt();
		for (int j = 0; j < t; j++) {
			m0 = sc.nextInt();
			year = sc.nextInt();
			n = sc.nextInt();
			a = new int[n];
			rate = new double[n];
			cost = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
				rate[i] = sc.nextDouble();
				cost[i] = sc.nextInt();
			}
			solve();
		}
	}

	void solve() {
		int max = 0;
		for (int j = 0; j < n; j++) {
			if (a[j] == 0) {
				int m = m0;
				int r = 0;
				for (int i = 0; i < year; i++) {
					r += (int) (m * rate[j]);
					m -= cost[j];
				}
				max = max(max, m + r);
			} else {
				int m = m0;
				for (int i = 0; i < year; i++) {
					m += (int) (m * rate[j]) - cost[j];
				}
				max = max(max, m);
			}
		}
		println(max + "");
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s) {
		System.out.print(s);
	}

	void println(String s) {
		System.out.println(s);
	}

	public static void main(String[] args) {
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream& operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream& operator<<(ostream &os, vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream& operator<<(ostream &os, set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream& operator<<(ostream &os, pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

int N;
vector<lint> a(40);
void solve(lint xpy, lint xmy)
{
    for (auto d : a)
    {
        if (xpy > 0 && xmy > 0)
        {
            xpy -= d; xmy -= d;
            cout << "R";
        }
        else if (xpy > 0 && xmy <= 0)
        {
            xpy -= d; xmy += d;
            cout << "U";
        }
        else if (xpy <= 0 && xmy > 0)
        {
            xpy += d; xmy -= d;
            cout << "D";
        }
        else if (xpy <= 0 && xmy <= 0)
        {
            xpy += d; xmy += d;
            cout << "L";
        }
    }
    cout << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<pint> R(N);
    REP(i, N) cin >> R[i].first >> R[i].second;

    bool isOdd;
    {
        map<int, int> ma;
        REP(i, N) ma[abs(R[i].first + R[i].second) % 2]++;
        if (ma.size() > 1) cout << -1 << endl, exit(0);
        isOdd = abs(R[0].first + R[0].second) % 2;
    }

    REP(i, 40) a[i] = 1LL << (i + 1);
    reverse(a.begin(), a.begin() + 38);
    a[38] = a[39] = 1;
    if (isOdd) a.pop_back();
    cout << a.size() << endl;
    REP(i, a.size()) cout << a[i] << " ";
    cout << endl;

    REP(i, N) solve(R[i].first + R[i].second, R[i].first - R[i].second);
}


Measured memory_bytes: 256
def ex_euclid(a, b):
  x0, x1 = 1, 0
  y0, y1 = 0, 1
  z0, z1 = a, b
  
  while z1 != 0:
    q = z0 // z1
    z0, z1 = z1, z0 % z1
    x0, x1 = x1, x0 - q * x1
    y0, y1 = y1, y0 - q * y1
  
  return z0, x0, y0
 
def mod_inv(a, n):
  g, x, _ = ex_euclid(a, n)
  if g != 1:
    print("modular inverse does not exist")
  else:
    return x % n

N = int(input())
A = list(map(int, input().split()))
M = 10**9 + 7
normal = 0
squared = 0
ans = 0
for a in A:
  normal = normal + a % M
  squared = squared + a*a % M
ans = (ans + normal * normal) % M
ans = (ans - squared) % M
ans = ans * mod_inv(2, M) % M
print(ans)

Measured memory_bytes: 31656
#include <iostream>
using namespace std;
int main()
{
  int N;
  cin >> N;
  string ans = "No";
  for (int i = 0; i <= 100; i++)
  {
    for (int j = 0; j <= 100; j++)
    {
      if (4 * i + 7 * j == N)
        ans = "Yes";
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long n,k,h[100010];
    cin>>n>>k;
    for(int i=0;i<n;i++) cin>>h[i];
    sort(h,h+n);
    long long ans=1e10;
    for(int i=0;i+k-1<n;i++){
        ans=min(ans,h[i+k-1]-h[i]);
    }
    cout<<ans;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    ll l,r;
    ll m = 2e9;
    cin >> l >> r;

    if(r-l >= 2500){
        cout << 0 << endl;
        return 0;
    }else{

        for(ll i = l; i < r+1;i++){
            for(ll j = i+1; j < r+1; j++){
                ll tmp = (i*j)%2019;
                m = min(m,tmp);
            }
        }

        // reps(i,l,r+1){
        //     reps(j,i+1,r+1){
        //         ll tmp = i*j;
        //         tmp %= 2019;
        //         m = min(m,tmp);
        //         //cout << i << " " << j << endl;
        //     }
        // }
    }

    cout << m << endl;
    return 0;
}


Measured memory_bytes: 256