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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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

signed main()
{   
    gearup;
    ll n; cin >> n;
    ll max = 1000001;
    vl a(n), b(1000001);
    rep(i,n)cin>>a[i];
    sort(all(a));
    ll res = 0;
    ll pre_num = -1;
    rep(i,n){
        int num = a[i];
        if(pre_num == num){
            b[num]++;
            continue;
        }
        for(int j=num;j < max;j+=num){
            b[j]++;
        }
        pre_num = num;
    }
    rep(i,n)if(b[a[i]] == 1)res++;
    out(res);
}


Measured memory_bytes: 12680
import numpy as np
import math
x = int(input())
prime = True
while prime:
    flag = 0
    for j in range(2,math.ceil(np.sqrt(x))):
        if x%j == 0:
            flag = 1
            break
    if flag ==0:
        prime = False
        
    else:
        x+=1
            
print(x)

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int N, W, H;
	cin>>N>>W>>H;
	cout<<(N-W+1)*(N-H+1)<<'\n';
	return 0;
}

Measured memory_bytes: 256
n = int(input())
if n < 3*5*7:
    print("0")
elif n < 3*5*9:
    print("1")
elif n < 3*5*11:
    print("2")
elif n < 3*7*9:
    print("3")
elif n < 3*5*13:
    print("4")
else:
    print("5")


Measured memory_bytes: 2940
s = gets.chomp
if s == "SUN"
  puts 7
elsif s == "MON"
  puts 6
elsif s == "TUE"
  puts 5
elsif s == "WED"
  puts 4
elsif s == "THU"
  puts 3
elsif s == "FRI"
  puts 2
elsif s == "SAT"
  puts 1
end


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

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

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main() {
  int A,B;
  cin>>A>>B;
  cout<<max(0,A-B*2)<<endl;
}

Measured memory_bytes: 3476
// ITP1_7_C

#include <iostream>
using namespace std;

int main()
{
	int r, c;
	int table[101][101];

	cin >> r >> c;
	for (int i = 0; i <= r; i++) { table[r][i] = 0; }
	for (int i = 0; i <= c; i++) { table[i][c] = 0; }

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			cin >> table[i][j];
			table[i][c] += table[i][j];
			table[r][j] += table[i][j];
		}
		table[r][c] += table[i][c];
	}

	for (int i = 0; i <= r; i++) {
		for (int j = 0; j <= c; j++) {
			cout << table[i][j];
			if (j != c) {
				cout << " ";
			}
		}
		cout << endl;
	}
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
const int MN=3e3+4;
int slen,tlen,cnt,dp[MN][MN];
char S[MN],T[MN],ans[MN];
int main() {
    scanf("%s\n%s",S+1,T+1);
    slen=strlen(S+1);
    tlen=strlen(T+1);
    for(int i=1;i<=slen;++i)
        for(int j=1;j<=tlen;++j) {
            dp[i][j]=std::max(dp[i-1][j],dp[i][j-1]);
            if(S[i]==T[j])
                dp[i][j]=std::max(dp[i][j],dp[i-1][j-1]+1);
        }
    for(int i=slen,j=tlen;i&&j;) {
        if(S[i]==T[j]) {
            if(dp[i][j]==dp[i-1][j-1]+1) {
                ans[cnt++]=S[i];
                --i,--j;
                continue;
            }
        }
        if(dp[i-1][j]>dp[i][j-1]) --i;
        else --j;
    }
    for(;cnt;putchar(ans[--cnt]));
    putchar('\n');
}


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



int main() {
  int n,k;
  cin >> n>>k;
  vector<int>a;
  for(int i=0;i<k;i++){
    int b;
    cin >>b;
    a.push_back(b);
  }
  for(int i=n;;i++){
    int N=i;
    while(N!=0){
      int NN =N%10;
      bool out=false;
      for(int j:a){
        if(NN==j){
          out =true;
          break;
        }
      }
      if(out){
        break;
      }
      N/=10;
      if(N==0){
        cout << i;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
int main() {
	//input
	int K, N, Q;
	int h[100000];
	int point[100000];
	int A[100000];
	cin >> N >> K >> Q;
	for (int i = 1; i <= Q;i++) {
		cin >> A[i];
		point[A[i]]++;
	}

	//compute
	for (int i = 1; i <= N; i++) {
		point[i] = K -Q+ point[i];
    //cout<<point[i];
		if (point[i] > 0)cout << "Yes"<<endl;
		else cout << "No"<<endl;
	}


	//output

	return 0;
}


Measured memory_bytes: 1408
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B, C);

// ===

fn main() {
    let n: usize = read();
    let a: Vec<i32> = readnc();
    let b: Vec<i32> = readnc();
    let mut tbl = vec![];
    tbl.push(a);
    tbl.push(b);

    let mut dp = vec![vec![0; n]; 2];
    dp[0][0] = tbl[0][0];

    for i in 0..2 {
        for j in 0..n {
            if i >= 1 {
                dp[i][j] = max(dp[i][j], dp[i-1][j] + tbl[i][j]);
            }
            if j >= 1 {
                dp[i][j] = max(dp[i][j], dp[i][j-1] + tbl[i][j]);
            }
        }
    }
    println!("{}", dp[1][n-1]);
}


Measured memory_bytes: 4352
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#define Rint register int
#define Temp template<typename T>
#define mem(a,b) memset(a,(b),sizeof(a))
typedef long long LL;
using namespace std;
Temp inline void read(T &x){
    x=0;T w=1,ch=getchar();
    while(!isdigit(ch)&&ch!='-')ch=getchar();
    if(ch=='-')w=-1,ch=getchar();
    while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^'0'),ch=getchar();
    x=x*w;
}

LL n,k;
LL ans;

int main(){
	read(n);read(k);
	if(k==0){
		printf("%lld\n",n*n);
		return 0;
	}
	for(Rint i=k+1;i<=n;i++){
		ans+=(n/i)*(i-k);
		if(n%i>=k)ans+=(n%i-k+1);
//		cout<<i<<' '<<ans<<endl;
	}
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp make_pair
#define pin pair<int,int>
pin solve(V<pin>& ab, int ex) {
	if (!ex) { return mkp(0, 0); }
	V<V<pin>> qab(2);
	int sz = ab.size();
	qab[0].reserve(sz);
	qab[1].reserve(sz);
	for (pin& x : ab) {
		qab[x.second & 1].push_back(mkp(x.first / 2, x.second / 2));
		if (x.first & 1) { qab[(x.second + 1) & 1].push_back(mkp(x.first / 2, (x.second + 1) / 2)); }
	}
	rep(i, 2) {
		int c = 0;
		for (pin& x : qab[1 - i]) {
			int qc = (2 * x.first + x.second) % 3;
			c ^= (qc + 1);
		}
		if (!c) {
			pin ans = solve(qab[i], ex - 1);
			ans.first *= 2; ans.second *= 2; ans.second += i;
			return ans;
		}
	}
	pin ans = solve(qab[0], ex - 1);
	int c = 0;
	for (pin& x : qab[1]) {
		int w = ans.second - x.second-1;
		if ((w & x.first) == w) { c ^= 1; }
	}
	ans.first *= 2; ans.first++; ans.second *= 2; ans.second -= c;
	return ans;
}
signed main() {
	cin.tie(0); ios::sync_with_stdio(false);
	long long inf = 1e17;
	int n; cin >> n;
	V<pin> ab(n);
	rep(i, n) {
		long long a, b; cin >> a >> b;
		ab[i] = { a + inf,b + inf };
	}
	pin ret = solve(ab, 59);
	cout << ret.first - inf << " " << ret.second - inf << "\n";
}


Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
	ll N, M;
	cin >> N >> M;
	string S, T;
	cin >> S >> T;
	ll len = N / __gcd(N, M) * M;
	map<int, char> res;
	for (int i = 0; i < N; i++) {
		res[i * (len / N)] = S[i];
	}
	bool ng = false;
	for (int i = 0; i < M; i++) {
		if (res.count(i * (len / M)) && res[i * (len / M)] != T[i]) ng = true;
	}
	if (!ng) {
		cout << len << endl;
	}
	else {
		cout << -1 << endl;
	}
	return 0;
}


Measured memory_bytes: 4736
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N; cin.ignore();

  int min_a;
  int min_b;
  cin >> min_a >> min_b;

  for (int i=0; i<(N-1); i++){
    int a, b;
    cin >> a >> b;
    if (b < min_b) {
      min_a = a;
      min_b = b;
    }
  }

  cout << (min_a+min_b) << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline

def main():
    ans = 'Yes'
    N = int(input())
    h = list(map(int, input().split()))[::-1]
    for i in range(N-1):
        if h[i] < h[i+1]:
            if h[i+1]-h[i] > 1:
                ans='No'
                break
            else:
                h[i+1] -= 1

    print(ans)

if __name__ == '__main__':
    main()

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

using ll = long long;
using ul = unsigned long long;
using ld = long double;

int main()
{
    char ch; cin >> ch;

    if (('A' <= ch) && (ch <= 'Z')) {
        cout << "A" << endl;
    }
    else {
        cout << "a" << endl;
    }

    return 0;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <algorithm>
#include <complex>
#include <vector>
#include <cmath>
using namespace std;
typedef complex<double> P;

double cross(P a, P b) {
  return a.real()*b.imag() - a.imag()*b.real();
}

int main() {
  vector<P> g;
  double x, y;
  while(scanf("%lf,%lf", &x, &y) != EOF) {
    g.push_back(P(x,y));
  }
  int N = g.size();
  double S = 0;
  for(int i = 0; i < N; ++i) {
    S += cross(g[i], g[(i+1)%N]);
  }
  printf("%.10f\n", abs(S)/2.0);
  return 0;
}

Measured memory_bytes: 1088
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<utility>
#include<random>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-2;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

struct edge { int to, cost, id; };
bool exi[50000];
int cc[50000];

struct edge2 {
	int fr, to, cost;
	bool operator<(const edge2 &e)const {
		if (e.cost != cost)return cost < e.cost;
		if (e.fr != fr)return fr < e.fr;
		return to < e.to;
	}
};
vector<edge2> w;

vector<edge> G[500];
bool dfs(int id, int fr, int cost,int goal) {
	if (id == goal)return true;
	rep(j, G[id].size()) {
		int to = G[id][j].to;
		if (to == fr)continue;
		if (dfs(to, id, cost, goal)) {
			if (cost == G[id][j].cost) {
				exi[G[id][j].id] = false;
			}
			return true;
		}
	}
	return false;
}
int main() {
	int n, m; cin >> n >> m;
	w.resize(m);
	rep(i, m) {
		cin >> w[i].fr >> w[i].to >> w[i].cost;
		w[i].fr--; w[i].to--;
	}
	sort(w.begin(), w.end());
	rep(i, m) {
		int s = w[i].fr, t = w[i].to, c = w[i].cost;
		//cout << i << " " << s << " " << t << endl;
		cc[i] = c;
		if (!dfs(s,-1,c, t)) {
			exi[i] = true;
			G[s].push_back({ t,c,i });
			G[t].push_back({ s,c,i });
		}
	}
	int cnt = 0; int sum = 0;
	rep(i, m) {
		if (exi[i]) {
			cnt++; sum += w[i].cost;
			//cout << i << endl;
		}
	}
	cout << cnt << " " << sum << endl;
	//stop
	return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
 
int main()
{
	int a,b,c,count=0;
	std::cin >> a >> b >> c;
	int pointx[10000] = {};
	int pointy[10000] = {};
	for (int i = 0; i < c;i++)
	{
		std::cin >> pointx[i];
		std::cin >> pointy[i];
	}
	for (int i = 0; i < c-1;i++) 
	{
		count += abs(pointx[i + 1] - pointx[i]);
		count += abs(pointy[i + 1] - pointy[i]);
		//次が右上

		if (pointx[i + 1] - pointx[i] > 0 && pointy[i + 1] - pointy[i]>0) {
			count -= std::min(pointx[i + 1] - pointx[i], pointy[i + 1] - pointy[i]);

	
		}
		//次が左下
		else if (pointx[i] - pointx[i+1]>0 && pointy[i] - pointy[i+1]>0) {
			count -= std::min(pointx[i] - pointx[i + 1], pointy[i] - pointy[i + 1]);

		
			
		}
		else {
			count -= 0;
		
		
		}

	}

	std::cout << count << std::endl;

	return 0;
}




Measured memory_bytes: 3160
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var n,k int
    var s string
    fmt.Scan(&n,&k,&s)
    t := strings.ToLower(s)
    fmt.Printf("%s%c%s", s[0:k-1], t[k-1], s[k:])
}





func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func scanTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func SortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}


Measured memory_bytes: 640
n=int(input())
l=[]
for i in range(n):
    t,x,y=map(int,input().split())
    l.append([t,x,y])

if n==1:
    d=l[0][1]+l[0][2]
    tt=l[0][0]
    if tt%2==1:
        if d<=tt and d%2==1:
            print('Yes')
            exit()
        else:
            print('No')
            exit()
    elif tt%2==0:
        if d<=tt and d%2==0:
            print('Yes')
            exit()
        else:
            print('No')
            exit()

for i in range(n-1):
    d=abs(l[i+1][1]-l[i][1])+abs(l[i+1][2]-l[i][2])
    tt=l[i+1][0]-l[i][0]
    if tt%2==1:
        if d<=tt and d%2==1:
            continue
        else:
            print('No')
            exit()
    elif tt%2==0:
        if d<=tt and d%2==0:
            continue
        else:
            print('No')
            exit()
print('Yes')

Measured memory_bytes: 19572
//
// Created by yamunaku on 2019/07/20.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int n;
    cin >> n;
    cout << 3*n*n << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
 
N, M = (int(i) for i in input().split())
py_list = [[int(i) for i in input().split()] + [0] for i in range(M)] 
m_list = [[] for j in range(N+1)]
 
sorted_py_list = sorted(py_list, key=lambda x:x[1])

city_list = {}
for py in sorted_py_list:
    city_list[py[0]] = city_list[py[0]]+1 if py[0] in city_list else 1
    py[2] = city_list[py[0]]
 
for py in py_list:
    print(str(py[0]).zfill(6) + str(py[2]).zfill(6))

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

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    int cnt = 0;
    for (int i = min(A, B); i >= 1; i--) {
        if (A % i == 0 && B % i == 0) {
            cnt++;
            if (cnt == K) {
                cout << i << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
using System;
class Program{
	static void Main(){
		long[] s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
		long[][] h=new long[s[0]+1][];
		long[] a=new long[s[0]+1];
		long[] b=new long[s[0]+1];
		long[] c=new long[s[0]+1];
		long[] d=new long[s[0]+1];
		h[0]=new long[2];
		long ans=0,k=0;
		for(int i=1;i<=s[0];i++){
			h[i]=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
			a[i]=a[i-1]+h[i][1]-(h[i][0]-h[i-1][0]);
			c[i]=Math.Max(c[i-1],a[i]-h[i][0]);
		}
		for(int i=1;i<=s[0];i++){
			b[i]=b[i-1]+k-(s[1]-h[s[0]+1-i][0])+h[s[0]+1-i][1];
			k=s[1]-h[s[0]+1-i][0];
			d[i]=Math.Max(d[i-1],b[i]-k);
			ans=Math.Max(ans,Math.Max(a[i],Math.Max(d[i]+a[s[0]-i],Math.Max(b[i],b[i]+c[s[0]-i]))));
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 27452
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int D=365;
vector<int> c(26);
vector<vector<int>> s(365, vector<int>(26));

ll calc(const vector<int>& t, int d, int q){
  ll res = 0;
  vector<int> lst(26,-1);
  rep(i,D){
    if(i!=d){
      if(t[i]!=-1){
        res += s[i][t[i]];
        lst[t[i]] = i;
      }
    }
    else{
      res += s[i][q];
      lst[q]=i;
    }
    rep(j,26){
      res -= c[j]*(i-lst[j]);
    }
  }
  //cerr << res << '\n';
  return res;
}

ll calc2(const vector<int>& t, int d1, int d2){
  ll res = 0;
  vector<int> lst(26,-1);
  rep(i,D){
    if(i!=d1 && i!=d2){
      res += s[i][t[i]];
      lst[t[i]] = i;
    }
    else if(i==d1){
      res += s[i][t[d2]];
      lst[t[d2]]=i;
    }
    else if(i==d2){
      res += s[i][t[d1]];
      lst[t[d1]]=i;
    }
    rep(j,26){
      res -= c[j]*(i-lst[j]);
    }
  }
  //cerr << res << '\n';
  return res;
}

int main(){
  /*
  ifstream in("input.in");
  cin.rdbuf(in.rdbuf());
  ofstream ofs("output.txt");
  cout.rdbuf(ofs.rdbuf());
  //*/
  chrono::system_clock::time_point start, end;
  start = chrono::system_clock::now();
  mt19937 mt(184);
  cin >> D;
  rep(i,26) cin >> c[i];
  rep(y,D) rep(x,26) cin >> s[y][x];
  vector<int> t(D,-1);
  ll now = calc(t, -1, -1);
  rep(d,D){
    int k=-1;
    ll prenow=-1;
    rep(q,26){
      ll pre = calc(t,d,q);
      if(now < pre){
        if(mt()&1 || mt()&1 || mt()&1) {
          now = pre;
          t[d] = q;
        }
        if(k==-1) {k=q; prenow = pre;}
      }
      if(chmax(now,calc(t,d,q))){
        t[d]=q;
      }
      end = chrono::system_clock::now();
      double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
      if(ela>1900) break;
    }
    if(t[d]==-1) {
      t[d]=k;
      now = prenow;
    }
    // timer
    end = chrono::system_clock::now();
    double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
    if(ela>1900) break;
  }
  while(1){
    int d1=mt()%365, d2=mt()%365;
    if(d1==d2) continue;
    if(chmax(now,calc2(t,d1,d2))){
      int tmp = t[d1];
      t[d1]=t[d2];
      t[d2]=tmp;
    }
    end = chrono::system_clock::now();
    double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
    if(ela>1970) break;
  }
  rep(i,D) cout << t[i]+1 << '\n';
  return 0;
}


Measured memory_bytes: 3700
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	auto nq = readln.chomp.split.map!(to!int);
  BinaryHeap!(Array!(int[]), "a[0] == b[0] ? a[1] > b[1] : a[0] < b[0]") q;
  auto num = new int[](nq[0]+1);
  foreach (i; 1..nq[0]+1) {
    int a[2];
    a[0] = 0;
    a[1] = i;
    q.insert(a);
  }

  foreach (_; 0..nq[1]) {
    auto x = readln.chomp.split.map!(to!int);
    num[x[0]] += x[1];
    int a[2];
    a[0] = num[x[0]];
    a[1] = x[0];
    q.insert(a.dup);
    
    while (!q.empty) {
      a = q.front;
      if (a[0] == num[a[1]]) {
        writeln(a[1], " ", a[0]);
        break;
      }
      q.removeFront;
    }
  }
}

Measured memory_bytes: 49092
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T, typename U, typename V>
ostream &operator<<(ostream &os, const tuple<T, U, V> &t){
  os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef tuple<int, int, int> TT;
typedef pair<int, TT> PT;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);




signed main(){
  string str;cin >> str;
  int n = str.size();
  int ans = 1;
  rep(i,n-1){
    if(str[i] == str[i+1])ans = 0;
  }
  if(ans == 0)cout << "Bad" << endl;
  else cout << "Good" << endl;
  return 0;
}






Measured memory_bytes: 256
// Aizu 0263: Beat Panel
// 2017.9.9 bal4u@uu

#include <stdio.h>
#include <string.h>

#define max(a,b) ((a)>=(b)?(a):(b))
int a[32], b[32];
int p[2][0xffff+2];

int bits(int k)
{
	int s, i;

	for (s = i = 0; i < 16; i++, k >>= 1) if (k & 1) s++;
	return s;
}

int main()
{
	int n, c, i, j, k, v, t, k1, k2;

	while (scanf("%d%d", &n, &c) && n) {
		for (i = 0; i < n; i++) {
			for (a[i] = 0, j = 0; j < 16; j++) scanf("%d", &v), a[i] = (a[i] << 1) | v;
		}
		for (i = 0; i < c; i++) {
			for (b[i] = 0, j = 0; j < 16; j++) scanf("%d", &v), b[i] = (b[i] << 1) | v;
		}
		memset(p[0], -1, sizeof(p[0])), p[0][0] = 0;
		for (k1 = 0, k2 = 1, i = 0; i < n; i++, k1 = k2, k2 = !k2) {
			memset(p[k2], -1, sizeof(p[0]));
			for (k = 0; k <= 0xffff; k++) {
				if (p[k1][k] < 0) continue;
				for (j = 0; j < c; j++) {
					v = bits((k | a[i]) & b[j]);
					t = (k | a[i]) & ~b[j];
					p[k2][t] = max(p[k2][t], p[k1][k] + v);
				}
			}
		}
		for (v = 0, k = 0; k <= 0xffff; k++) if (p[k1][k] > v) v = p[k1][k];
		printf("%d\n", v);
	}
	return 0;
}

Measured memory_bytes: 2316
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 998244353

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

def use_divisors(n):
    l_divisors, r_divisors = [], []
    for i in range(1, int(n**0.5)+1):
        if n%i == 0:
            if (n//i)%2:
                l_divisors.append(i)
            if i != n//i:
                if (n//(n//i))%2:
                    r_divisors.append(n//i)
    return l_divisors + r_divisors[::-1]
 
N = I()
X = str(input())
Xr = ''.join('1' if c=='0' else '0' for c in X)

ans = 0
divisors = use_divisors(2*N)
C = dict.fromkeys(divisors,0)

for d in divisors:
    T = X[:d//2]
    Tr = Xr[:d//2]
    Tc = T+Tr
    count = int(T,2)
    if int(Tc*(N//d)+Tc[:N-d*(N//d)],2) <= int(X,2):
        count += 1
    C[d] = count
    for d1 in divisors:
        if d%d1==0 and d!=d1:
            C[d] -= C[d1]

ans = 0
for d in divisors:
    ans += d*C[d]
    ans %= mod

print(ans)

Measured memory_bytes: 118400
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

int main(void){
  ll x, k, d;
  cin >> x >> k >> d;
  
  x = abs(x);

  if (k <= x/d){
    cout << x - k*d << endl;
  }
  else {
    k -= x/d;
    x %= d;
    if (k % 2 == 0){
      cout << x << endl;
    }
    else
      cout << d - x << endl;
  }

  return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long  
#define f80 __float128
#define pii pair<int,int>
/////////////

signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int x,y,z;
	cin>>x>>y>>z;
	cout<<z<<" "<<x<<" "<<y;
	#ifdef ANIKET_GOYAL
		cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
	#endif
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>
#include <map>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint>> que;
//priority_queue<llint> q;

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

llint n,m;

void solve(){
  cin >> n;
  int a[n+1];
  for(int i=1;i<=n;i++)a[i]=0;
  int x;
  for(int i=0;i<n-1;i++){
    cin >> x;
    a[x]++;
  }
  for(int i=1;i<=n;i++)cout << a[i] << endl;
}

int main() {
  solve();
  return 0;
}


Measured memory_bytes: 4456
import sys
input = sys.stdin.readline
N = int(input())
if 50 >= N > 1:
  print(N)
  res = [N] * N
  print(*res)
elif N > 50:
  print(50)
  res = [49] * 50
  t = N // 50
  for i in range(50):
    res[i] += t
  u = N % 50
  if u:
    for i in range(u):
      res[i] += 50 - u + 1
    for i in range(u, 50):
      res[i] -= u
  print(*res)
elif N == 0:
  print(2)
  print(1, 1)
elif N == 1:
  print(2)
  print(2, 0)

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;


int main() {
    int n; cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    int ans = 1e8;
    rep(i,100){
        int tmp=0;
        rep(j,n){
            tmp += pow((v[j] - (i+1)), 2);
        }
        if(tmp <= ans) ans = tmp;
    }
    cout << ans;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
const int mod=1e9+7;

int main(){
  int A,B;
  cin>>A>>B;
  int sum=1,cnt=0;
  while(sum<B){
    cnt++;
    sum--;
    sum+=A;
  }
  cout<<cnt<<endl;
  return 0;                       
}

Measured memory_bytes: 3636
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int main()
{
  ll X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<ll> A(X);
  vector<ll> B(Y);
  vector<ll> C(Z);
  rep(i, X) cin >> A[i];
  rep(i, Y) cin >> B[i];
  rep(i, Z) cin >> C[i];
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  vector<ll> v(X * Y);
  int i = 0;
  foreach(a, A){
    foreach(b, B){
      v[i++] = a + b;
    }
  }
  sort(v.rbegin(), v.rend());
  ll v_size = min((int)v.size(), (int)K);
  vector<ll> ans(v_size * Z);
  int ii = 0;
  rep(i, v_size){
    foreach(c, C){
      ans[ii++] = v[i] + c;
    }
  }
  sort(ans.rbegin(), ans.rend());
  rep(i, K){
    cout << ans[i] << endl;
  }
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  string S = "";
  string A, B;
  cin >> A >> B;
  for (int i = 0; i < n; i++){
    S += A[i];
    S += B[i];
  }
  cout << S << endl;
  
}

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

long long my(long long x,int y){
  long long k=1;
  for(int i=0;i<y;i++){
    k=(k*x)%1000000007LL;
  }
  return k;
}
    
int main() {
  long long n;
  cin >> n;
  cout <<(my(10,n)+my(8,n)+2*(1000000007-my(9,n)))%1000000007 << endl;;
  return 0;
}

Measured memory_bytes: 3620
using System;

public class Program
{
    public static void Main()
	{
        var N = int.Parse(Console.ReadLine());

        var can = true;

        var cPos = 0;
        var cTime = 0;

        for (var i=0; i<N; i++)
        {
            var input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var tTime = input[0];
            var tPos = input[1] + input[2];

            var tDiv = tTime - cTime;
            var pDiv = tPos - cPos;

            if (pDiv > tDiv)
            {
                can = false;
            }
            else if ((tDiv - pDiv) % 2 == 1)
            {
                can = false;
            }
            cPos = tPos;
            cTime = tTime;
        }
        Console.WriteLine(can ? "Yes" : "No");
    }
}


Measured memory_bytes: 15284
#include <bits/stdc++.h>
using namespace std;
int main() {
	int h, w; cin >> h >> w;
	string s[55];
	for(int i=0;i<h;i++){
		cin >> s[i];
	}
	int di[4] = {1, 0, -1, 0}, dj[4] = {0, 1, 0, -1};
	int d[55][55];
	int cnt = 0;
	queue<pair<int, int>> q;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			d[i][j] = 10000;
			if(s[i][j]=='.'){
				cnt++;
			}
		}
	}
	q.push({0, 0});
	d[0][0] = 0;
	while(q.size()){
		auto p = q.front(); q.pop();
		if(p.first==h-1 && p.second==w-1){
			break;
		}
		for(int k=0;k<4;k++){
			int ni = p.first + di[k];
			int nj = p.second + dj[k];
			if(0<=ni && ni<h && 0<=nj && nj<w && s[ni][nj]!='#' && d[ni][nj]==10000){
				q.push({ni, nj});
				d[ni][nj] = d[p.first][p.second]+1;
			}
		}
	}
	if(d[h-1][w-1]==10000){
		cout << -1 << endl;
		return 0;
	}else{
		cout << cnt-d[h-1][w-1]-1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
from itertools import *
N,M,Q=[int(s) for s in input().split()]
Qls=[[int(s) for s in input().split()] for _ in range(Q)]
for i in range(Q):
  Qls[i][0]-=1
  Qls[i][1]-=1
iterable=range(1, M+1)
checkls=list(combinations_with_replacement(iterable, N))
ans=set()
for ls in checkls:
  score=0
  for a,b,c,d in Qls:
    if ls[b]-ls[a]==c:
      score+=d
  ans.add(score)
print(max(ans))

Measured memory_bytes: 21752
#include <iostream>
#include <cmath>
#include <string>

// https://github.com/rippro/lib/blob/master/util/date.cpp

using namespace std;
typedef long long ll;

string day[] = {
    "Sunday",
    "Monday",
    "Tuesday",
    "Wednesday",
    "Thursday",
    "Friday",
    "Saturday"
};

string month[] = {
    "January",
    "February",
    "March",
    "April",
    "May",
    "June",
    "July",
    "August",
    "September",
    "October",
    "November",
    "December"
};

ll zeller(long y, long m, long d){
    if (m <= 2){
        y--;
        m += 12;
    }
    return (365 * y) + (y / 4) - (y / 100) + (y / 400) + (306 * (m + 1)) / 10 + d - 429;
}

bool leap_year(int y){
    return y % 400 == 0 || (y % 4 == 0 && y % 100 != 0);
}

#define loop(i,a,b) for(ll i=(a); i<ll(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int m, d;
    while (cin >> m >> d && m){
        cout << day[(zeller(2004, m, d) + 1) % 7] << endl;
    }
}

Measured memory_bytes: 1200
#include<stdio.h>

int main()
{
    char a[3][3];
    int i,j;
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            scanf("%c",&a[i][j]);
        }
        getchar();
    }
    printf("%c%c%c",a[0][0],a[1][1],a[2][2]);
    return 0;
}


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

void print(vector<int> & V){
    for (auto it = V.begin(); it != V.end(); ++it){
        cout << *it << ((it == V.end() - 1) ? '\n' : ' ');
    }
}

bool solveM1(int N, int M, vector<int> & A){
    if (N == 1) {
        cout << 1 << endl;
        cout << 1 << endl;
        cout << 1 << endl;
    }else{
        cout << N << endl;
        cout << 2 << endl;
        cout << N - 1 << ' ' << 1 << endl;
    }
    return true;
}

bool solveM2(int N, int M, vector<int> & A){
    print(A);
    cout << 1 << endl;
    cout << N << endl;
    return true;
}

int count_odd(vector<int> &A){
    int c = 0;
    for (auto a : A) c += (a & 1);
    return c;
}

void solve0(int N, int M, vector<int> & A){
    print(A);
    cout << M << endl;
    --A[0];
    ++A[M - 1];
    print(A);
}

void solve1(int N, int M, vector<int> & A){
    int i = 0;
    while ((A[i] & 1) == 0) ++i;
    int tmp = A[i];
    A[i] = A[0];
    A[0] = tmp;
    print(A);
    cout << M << endl;
    ++A[0];
    --A[M - 1];
    print(A);
}

void solve2(int N, int M, vector<int> & A){
    int L = 0;
    while ((A[L] & 1) == 0) ++L;
    int tmp = A[L];
    A[L] = A[0];
    A[0] = tmp;
    int R = M - 1;
    while ((A[R] & 1) == 0) --R;
    tmp = A[R];
    A[R] = A[M - 1];
    A[M - 1] = tmp;
    print(A);
    ++A[0];
    --A[M - 1];
    if (A[M - 1] == 0) A.pop_back();
    cout << A.size() << endl;
    print(A);
}

bool solve(int N, int M, vector<int> &A){
    if (M == 1) return solveM1(N, M, A);
    if (M == 2 and (A[0] == 1 or A[1] == 1)) return solveM2(N, M, A);
    auto n_odd = count_odd(A);
    if (n_odd >= 3) return false;
    if (n_odd == 2) solve2(N, M, A);
    if (n_odd == 1) solve1(N, M, A);
    if (n_odd == 0) solve0(N, M, A);
    return true;
}


int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    for (auto & a : A) cin >> a;
    if (not solve(N, M, A)) cout << "Impossible" << endl;
    return 0;
}

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

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

#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T> void preview(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}

const int INF = 100000000;
const double PI = acos(-1.0), EPS = 1e-10;

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

inline int dic(P p) {
	return p.first * 100 + p.second;
}

int main() {
	for(int w,h; cin >> w >> h, w || h;) {
		P s, g;
		P ms, mg;
		memset(field, -1, sizeof field);
		int cnt = 0;
		vector<vector<P> > cry(10240);
		rep(y, h) {
			rep(x, w) {
				string c;
				cin >> c;

				if(c == "S") {
					s.first = y;
					s.second = x;
					field[y][x] = 0;
					ms = s;
				}
				else if(c == "G") {
					g.first = y;
					g.second = x;
					mg = g;
				}
				else if(c != ".") {
					int t = toInt(c);
					field[y][x] = t;
					cnt = max(cnt, t);
					cry[t].pb(mp(y, x));
				}
			}
		}
		cry[0].pb(ms);
		field[mg.first][mg.second] = ++cnt;

		vector<vector<P> > D(10240);

		for(int i = 0; i < cnt; i++) {
			rep(num, cry[i].size()) {
				int dist[128][128];
				int tms = 0;
				memset(dist, -1, sizeof dist);
				s = cry[i][num];
				dist[s.first][s.second] = 0;
				queue<P> que;
				que.push(s);
				while(!que.empty()) {
					P p = que.front(); que.pop();
					if(field[p.first][p.second] == i + 1) {
						int t = dist[p.first][p.second];
						D[dic(s)].pb(P(t, dic(p)));
						tms++;
						if(tms == cry[i+1].size()) break;
					}
					rep(j, 4) {
						int ny = p.first + dy[j];
						int nx = p.second + dx[j];
						if(0 <= ny && ny < h && 0 <= nx && nx < w && dist[ny][nx] == -1) {
							dist[ny][nx] = dist[p.first][p.second] + 1;
							que.push(P(ny, nx));
						}
					}
				}
			}
		}

		priority_queue<P, vector<P>, greater<P> > que;
		vector<int> fd(10240, INF);
		fd[dic(ms)] = 0;
		que.push(P(0, dic(ms)));
		while(!que.empty()) {
			P p = que.top(); que.pop();
			int v = p.second;
			if(fd[v] < p.first) continue;
			rep(i, D[v].size()) {
				P e = D[v][i];
				if(fd[e.second] > fd[v] + e.first) {
					fd[e.second] = fd[v] + e.first;
					que.push(P(fd[e.second], e.second));
				}
			}
		}
		cout << fd[dic(mg)] << endl;
	}
	return 0;
}

Measured memory_bytes: 4664
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        long N = s.nextLong();
        int M = s.nextInt();
        long[] a = new long[M];
        for (int i = 0; i < M; i++) {
            a[i] = s.nextLong();
        }

        long sum = 0;
        for (int i = 0; i < a.length; i++) {
            sum += a[i];
        }

        if(N >= sum) {
            System.out.println(N-sum);
        } else {
            System.out.println("-1");
        }
        // double ans = 2 * 3.14159 * q;
        // System.out.println(ans);
    }
}

Measured memory_bytes: 39164
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,x,cnt=0;
  cin>>a>>b>>c>>x;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(500*i+100*j+50*k==x) cnt++;
      }
    }
  }
  cout<<cnt;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n,m;
    cin >>n>>m;
    
    cout << (n-1)*(m-1) << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
#define MAX 2000001
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n, ll k) {
    if(n < k)
        return 0;
    if(n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll modpow(ll a, ll n, ll mod = MOD) {
    ll res = 1;
    while(n > 0) {
        if(n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main() {
    ll k;
    cin >> k;
    string s;
    cin >> s;
    ll n = s.size();
    ll ans = 0;
    COMinit();
    for(int i = 0; i <= k; i++) {
        ans += (COM(k + n - i - 1, n - 1) * modpow(25, k - i) % MOD) *
               modpow(26, i);
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 51204
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;



int main(){
    ll x, y;
    cin >> x >> y;
    int ans = 0;
    ll a = x;
    while(a <= y){
        a *= 2;
        ans++;
    }

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

Measured memory_bytes: 256
import Data.Char
import Data.List
import Control.Monad

step :: [Int] -> (Int, Int) -> Int
step ts (p,x) = sum ts - t + x
    where
        t = ts !! (p-1)

main = do
    n <- readLn :: IO Int
    ts <- map read . words <$> getLine :: IO [Int]
    m <- readLn :: IO Int
    ps <- replicateM m $ do
        [x,y] <- map read . words <$> getLine :: IO [Int]
        return (x,y)
    forM_ ps $ \px -> do
        print $ step ts px 

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define vl vector<ll>
#define pl pair<ll,ll>
#define mp make_pair
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) for(ll i=0;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(),(v).end()
using namespace std;
ll a,b,c,d;
vector<pl>x;
signed main() {
    cin>>a>>b>>c>>d;
    cout<<c+b-d<<" "<<d+c-a<<" "<<a+b-d<<" "<<b-a+c<<endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <set>
using namespace std;

#define N 105
#define ll long long int



int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int x, y, z;
    cin>>x>>y>>z;
    
    cout<<z<<" "<<x<<" "<<y<<endl;
    
    return 0;
}


Measured memory_bytes: 256