akhauriyash/Code-Regression huggingface dataset:
// attr {{{
#![allow(
    dead_code,
    non_snake_case,
    unused_imports,
)]
// }}}

// use {{{
use std::fmt;
use std::io::{self,BufRead,Read,Write};
use std::str;
// }}}

const INF: i64 = 1_010_000_000_000_000_000;
const MOD: i64 = 1_000_000_007;
const EPS: f64 = 1e-9;

// util {{{
fn abs_diff(a: i64, b: i64) -> i64 {
    if a < b { b-a } else { a-b }
}

fn is_even(n: i64) -> bool { n % 2 == 0 }
fn is_odd (n: i64) -> bool { n % 2 != 0 }

fn div_ceil(a: i64, b: i64) -> i64 {
    let up = ((a<0) ^ (b>0)) && (a%b != 0);
    a/b + if up { 1 } else { 0 }
}

fn div_floor(a: i64, b: i64) -> i64 {
    let down = ((a>0) ^ (b>0)) && (a%b != 0);
    a/b - if down { 1 } else { 0 }
}

fn modulo(a: i64, b: i64) -> i64 {
    assert!(b > 0);
    let r = a % b;
    if r >= 0 { r } else { r+b }
}

fn chmax(xmax: &mut i64, x: i64) -> bool {
    if x > *xmax {
        *xmax = x;
        true
    }
    else {
        false
    }
}

fn chmin(xmin: &mut i64, x: i64) -> bool {
    if x < *xmin {
        *xmin = x;
        true
    }
    else {
        false
    }
}

fn _gcd(a: i64, b: i64) -> i64 {
    if b == 0 { a } else { _gcd(b, a%b) }
}

fn gcd(v: &[i64]) -> i64 {
    debug_assert!(v.len() >= 1);
    v.iter().fold(0, |a,&b| _gcd(a,b))
}

fn lcm(v: &[i64]) -> i64 {
    debug_assert!(v.len() >= 1);
    v.iter().fold(1, |a,&b| a / _gcd(a,b) * b)
}

fn _INPUT() -> String {
    let mut res = String::new();
    io::stdin().read_to_string(&mut res).expect("read_to_string()");
    res
}

struct Reader<'a> {
    input: &'a String,
    tokens: str::SplitWhitespace<'a>,
}

impl<'a> Reader<'a> {
    pub fn new(input: &'a String) -> Reader {
        Reader {
            input: input,
            tokens: input.split_whitespace(),
        }
    }

    pub fn RD<T>(&mut self) -> T
        where T: str::FromStr,
              <T as str::FromStr>::Err: fmt::Debug
    {
        self.tokens.next().unwrap().parse().unwrap()
    }

    pub fn RD_VEC<T>(&mut self, n: i64) -> Vec<T>
        where T: str::FromStr,
              <T as str::FromStr>::Err: fmt::Debug
    {
        let mut res: Vec<T> = Vec::with_capacity(n as usize);
        for _ in 0..n {
            res.push(self.RD());
        }
        res
    }
}
// }}}

fn main() {
    let input = _INPUT();
    let mut reader = Reader::new(&input);

    let N: i64 = reader.RD();
    let Y: i64 = reader.RD();

    for i in 0..N+1 {
        for j in 0..N-i+1 {
            let k = N-i-j;
            if 10000*i + 5000*j + 1000*k == Y {
                println!("{} {} {}", i, j, k);
                return;
            }
        }
    }

    println!("-1 -1 -1");
}


Measured memory_bytes: 4352
N, K = map(int, input().split())
d_list=[]
S_list=[]
j_list=[]
for i in range(K):
    d = int(input())
    d_list.append(d)
    S = list(map(int, input().split()))
    S_list.append(S)

    
for j in S_list:
    j_list=j_list+j

j_set=set(j_list)
print(N-len(j_set))

Measured memory_bytes: 9252
#include <bits/stdc++.h>
#define endl '\n'
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define x first
#define y second
#define pb push_back
#define ll long long
#define int ll
#define ld long double
#define ii pair<int, int>
#define iii pair<int, ii>
#define vi vector<int>
#define vii vector<ii>
#define pq priority_queue
using namespace std;
const int ms = 4000;
const int mod = 1e9+7;
const int inf = 1e9;
const int sigma = 30;
int n, m, k, t = 1;
string s;

int ele[ms];

bool seen[ms][ms][2];
int dp[ms][ms][2];

int sol(int i, int j, int p){
  if(i==j) return p==0? ele[i]: -ele[i];

  if(seen[i][j][p]) return dp[i][j][p];
  seen[i][j][p] = 1;

  if(p==0){
    int val1 = ele[i] + sol(i+1, j, 1);
    int val2 = ele[j] + sol(i, j-1, 1);
    return dp[i][j][p] = max(val1, val2);
  }else{
    int val1 = -ele[i] + sol(i+1, j, 0);
    int val2 = -ele[j] + sol(i, j-1, 0);
    return dp[i][j][p] = min(val1, val2);
  }
}

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

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  while(t--){
    solve();
  }
}

Measured memory_bytes: 212992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    int n;
    cin >> n;
    vector<vector<int>>a(2,vector<int>(n));
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++){
            cin >> a[i][j];
        }
    }
    int dp[2][n];
    dp[0][0]=a[0][0];
    dp[1][0]=a[0][0]+a[1][0];
    for(int i=1;i<n;i++){
        dp[0][i]=dp[0][i-1]+a[0][i];
        dp[1][i]=max(dp[1][i-1]+a[1][i],dp[0][i]+a[1][i]);
    }
    cout << dp[1][n-1] << endl;
}

Measured memory_bytes: 3576
#include<stdio.h>

int main(void){
  int sx,sy,tx,ty;
  int i,j;
  scanf("%d %d %d %d",&sx,&sy,&tx,&ty);
  for(i=sy;i<ty;i++){
    printf("U" );
  }
  for(j=sx;j<tx;j++){
    printf("R" );
  }
  for(i=sy;i<ty;i++){
    printf("D" );
  }

  for(j=sx;j<tx;j++){
    printf("L" );
  }
  printf("L");
  for(i=sy;i<ty+1;i++){
    printf("U" );
  }
  for(j=sx-1;j<tx;j++){
    printf("R" );
  }
  printf("D" );

  printf("R");
  for(i=sy;i<ty+1;i++){
    printf("D" );
  }
  for(j=sx-1;j<tx;j++){
    printf("L" );
  }
  printf("U\n");
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1LL<<60;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  int N;
  cin >> N;
  vector<int> x(N),y(N),h(N);
  for(int i=0; i<N; i++){
    cin >> x[i] >> y[i] >> h[i];
  }
  int H,X,Y;
  for(int i=0; i<=100; i++){
    bool ok = true;
    for(int j=0; j<=100; j++){
      ok = true;
      X = i;
      Y = j;
      for(int k=0; k<N; k++){
        if(h[k] != 0){
          H = h[k] + abs(i-x[k]) + abs(j - y[k]);
          break;
        }
      }
      for(int k=0; k<N; k++){
        if(h[k] == 0){
          if(H-abs(i-x[k])-abs(j-y[k]) > 0){
            ok = false;
          }
        }else{
          if(H-abs(i-x[k])-abs(j-y[k]) != h[k]){
            ok = false;
          }
        }
      }
      if(ok) break;
    }
    if(ok) break;
  }
  cout << X << " " << Y << " " << H << endl;
  return 0;
}


Measured memory_bytes: 256
n,l=map(int,input().split())
m=[]
k=[]
for i in range(1,n+1):
    m.append(l+i-1)

for j in range(len(m)):
    k.append(abs(sum(m)-(sum(m)-m[j])))

for d in range(len(k)):
    if min(k)==k[d]:
        print(sum(m)-m[d])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N, ans=1e13;
  cin >>N;
  for(int i=1; i<=sqrt(N); i++){
    long long a=N;
    if(a%i!=0) continue;
    a/=i;
    ans=min(ans, a+i-2);
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 256
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.06.09 20:55:32
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (ll i = 0; i < x; i++)
#define rep1(i, x) for (ll i = 1; i <= x; i++)
#define rrep(i, x) for (ll i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (ll i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const ll M = 1000000007;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

string s;
ll p3[100010];
ll p2[100010];

int main() {
    p3[0] = 1LL;
    rep1(i, 100009) {
        p3[i] = (p3[i - 1] * 3LL) % M;
    }
    p2[0] = 1LL;
    rep1(i, 100009) {
        p2[i] = (p2[i - 1] * 2LL) % M;
    }

    cin >> s;
    ll sl = s.size();

    // 1文字目
    ll ret = (p3[sl - 1] + 2) % M;
    ll cnt = 1LL;
    rep1(i, sl - 1) {
        if (s[i] == '1') {
            ret = (ret + (p3[sl - i - 1] + 1) * p2[cnt]) % M;
            cnt++;
        }
    }

    cout << ret << "\n";

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 2048
N, M = map(int, input().split())

a = []
for _ in range(M):
    a.append(int(input()))

val = [0,1]
for i in range(1, N + 1):
    ans = val[-2] + val[-1]
    val.append(ans)
    if len(a) > 0:
        if i == a[0]:
            val[-1] = 0
            a.pop(0)

print(ans % (10**9 +7))

Measured memory_bytes: 460020
import java.util.Scanner;

class Main {
	public static void main(String[] $) {
		Scanner sc = new Scanner(System.in);
		int x=sc.nextInt(),y=sc.nextInt(),res=0;
		if(x==3)res=100000;
		if(x==2)res=200000;
		if(x==1)res=300000;
		if(y==3)res+=100000;
		if(y==2)res+=200000;
		if(y==1)res+=300000;
		if(res==600000)res+=400000;
		System.out.println(res);
	}
}
/*各競技において，
3
 位の選手は
100000
 円，
2
 位の選手は
200000
 円，
1
 位の選手は
300000
 円の賞金を獲得します．また，コード部門と装置実装部門の両方で
1
 位となった選手は，さらに
400000
 円の賞金を獲得します．*/

Measured memory_bytes: 23764
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
            char[] c1 = sc.nextLine().toCharArray();
            char[] c2 = sc.nextLine().toCharArray();
            char[] c3 = sc.nextLine().toCharArray();

        System.out.println(c1[0]+""+c2[1]+""+c3[2]);
    }

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
int n,a,b,c,d;
bool lx[200005],ly[200005],rx[200005],ry[200005],p[200005];
int main(void){
    cin>>n>>a>>b>>c>>d;
    a--,b--,c--,d--;
    if(a>b){
		swap(a,b);
		swap(c,d);
	}
    for(int i=0;i<n;i++){
		char c;
		scanf(" %c",&c);
		if(c=='#')p[i]=true;
	}
	lx[a]=true;
	ly[b]=true;
	rx[c]=true;
	ry[d]=true;
	for(int i=0;i<n;i++){
		if(p[i])continue;
		if(i-1>=0&&lx[i-1])lx[i]=true;
		if(i-2>=0&&lx[i-2])lx[i]=true;
		if(i-1>=0&&ly[i-1])ly[i]=true;
		if(i-2>=0&&ly[i-2])ly[i]=true;
	}
	for(int i=n-1;i>=0;i--){
		if(p[i])continue;
		if(i+1<n&&rx[i+1])rx[i]=true;
		if(i+2<n&&rx[i+2])rx[i]=true;
		if(i+1<n&&ry[i+1])ry[i]=true;
		if(i+2<n&&ry[i+2])ry[i]=true;
	}
	if(c<d){
		if(lx[c]&&ly[d])cout<<"Yes\n";
		else cout<<"No\n";
	}else{
		bool ok=false;
		for(int i=b;i<=d;i++){
			if(lx[i-1]&&ly[i]&&!p[i+1]&&rx[i+1]&&ry[i])ok=true;
		}
		if(ok)cout<<"Yes\n";
		else cout<<"No\n";
	}
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main(){
    ll ans=0;
    ll n;
    cin>>n;
    vector<ll> a(n);
    ll minus=0,plus=0,zero=0;
    ll abssum = 0;
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
        abssum+=abs(a[i]);
        if(a[i]<0) minus++;
        else if(a[i]>0) plus++;
        else zero++;
    }
    sort(all(a));
    if(plus==0) plus+=zero;
    else minus+=zero;
    if(n==2)
    {
        cout<<a[1]-a[0]<<endl;
        cout<<a[1]<<" "<<a[0]<<endl;

    }
    else if(plus == n) // hitotsu dake minus
    {
        cout<<abssum-a[0]*2<<endl;
        ll tmp = a[0];
        for (int i = 1; i < n-1; i++)
        {
            cout<<tmp<<" "<<a[i]<<endl;
            tmp=tmp-a[i];
        }
        cout<<a[n-1]<<" "<<tmp<<endl;
    }
    else if(minus == n) // hitotsu dake sonomama
    {
        cout<<abssum+a[n-1]*2<<endl;
        ll tmp = a[n-1];
        for (int i = 0; i < n-1; i++)
        {
            cout<<tmp<<" "<<a[i]<<endl;
            tmp=tmp-a[i];
        }        
    }
    else // zenbu abs
    {
        cout<<abssum<<endl;
        ll tmp = a[0];
        for (int i = minus; i < n-1; i++)
        {
            cout<<tmp<<" "<<a[i]<<endl;
            tmp=tmp-a[i];
        }
        cout<<a[n-1]<<" "<<tmp<<endl;
        tmp=a[n-1]-tmp;
        for (int i = 1; i < minus; i++)
        {
            cout<<tmp<<" "<<a[i]<<endl;
            tmp=tmp-a[i];
        }
                
    }
    

    return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pub push_back
#define pob pop_back
#define loops(i, s, n) for (ll i = s; i < n; i++)
#define loop(i, n) for (ll i = 0; i < n; i++)
#define loopr(i, s, e) for (ll i = s; i >= e; i--)
#define eps 1e-9
#define loopitr(mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define pii pair<ll, ll>
#define vi vector<ll>
#define vll vector<ll>
#define vpii vector<pair<ll, ll>>
#define even_set 0xAAAAAAAA ... 1010101010
#define odd_set 0x55555555 ... 01010101
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vall(v) v.begin(), v.end()
#define mkp make_pair
#define ret return
#define cont continue
#define nl endl
#define ff first
#define ss second
#define cnt_bits __builtin_popcount
#define test  \
    ll T;     \
    cin >> T; \
    while (T)
#define arrinit        \
    ll n;              \
    cin >> n;          \
    ll arr[n];         \
    loop(i, n)         \
    {                  \
        cin >> arr[i]; \
    }
#define init(arr, n, val)      \
    for (ll i = 0; i < n; i++) \
        arr[i] = val;
const ll mod = 1000000007;

int main()
{

    fastio;
    ll n;
    cin >> n;
    ll dp[n][n];
    ll arr[n];
    loop(i, n)
    {
        cin >> arr[i];
    }

    loop(i, n)
    {
        dp[i][i] = 0;
    }

    ll ps[n];
    ps[0] = arr[0];
    loops(i, 1, n)
    {
        ps[i] = ps[i - 1] + arr[i];
    }

    loops(l, 2, n + 1)
    {
        loop(i, n - l + 1)
        {
            int j = i + l - 1;

            if (l == 2)
                dp[i][j] = arr[i] + arr[j];
            else
            {
                ll mn = INT64_MAX;
                for (int k = i; k < j; k++)
                {
                    mn = min(dp[i][k] + dp[k + 1][j], mn);
                }
                dp[i][j] = mn + ps[j] - ((i - 1 >= 0) ? ps[i - 1] : 0);
            }
        }
    }
    
    cout << dp[0][n - 1] << endl;
}

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

int main() {
    int64_t n, a, b;
    cin >> n >> a >> b;
    cout << n / (a + b) * a + min(n % (a + b), a) << endl;
    return 0;
}

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

int n, q;
int seg[1 << 18];

const int inf = (1ll << 31) - 1;

void init() {
	int _n = 1;
	while (_n < n) _n *= 2;
	n = _n;

	for (int i = 0; i < 2 * n; ++i) {
		seg[i] = inf;
	}
}

void update(int i, int x) {
	i += n - 1;
	seg[i] = x;
	
	while (i) {
		i = (i - 1) / 2;
		seg[i] = min(seg[2 * i + 1], seg[2 * i + 2]);
	}
}

int find(int s, int t, int k = 0, int l = 0, int r = n) {
	if (r <= s || t <= l) return inf;
	if (s <= l && r <= t) return seg[k];

	int m = (l + r) / 2;
	return min(find(s, t, 2 * k + 1, l, m), find(s, t, 2 * k + 2, m, r));
}

int main() {
	cin >> n >> q;
	
	init();
	
	for (int i = 0; i < q; ++i) {
		int com, x, y;
		cin >> com >> x >> y;

		if (com == 0) {
			update(x, y);
		} else {
			cout << find(x, y + 1) << endl;
		}
	}
}

Measured memory_bytes: 4028
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskA {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int k = in.nextInt();
			int gcd = 0;
			int max = 0;
			for (int i = 0; i < n; i++) {
				int x = in.nextInt();
				gcd = gcd(gcd, x);
				max = Math.max(max, x);
			}
			if (k % gcd == 0 && k <= max) {
				out.println("POSSIBLE");
			} else {
				out.println("IMPOSSIBLE");
			}
		}

		private int gcd(int a, int b) {
			return b == 0 ? a : gcd(b, a % b);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(in.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



Measured memory_bytes: 35856
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(long long (i)=(a); (i)<(long long)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 

const ll large_P = 1e9 + 7;

int main(){
  ll N, X, Y;
  cin >> N >> X >> Y;
  X--; Y--;
  
  Graph G(N);
  rep(i, N){
    if(i < N-1) G.at(i).push_back(i+1);
    if(i > 0) G.at(i).push_back(i-1);
  }
  
  G.at(X).push_back(Y);
  G.at(Y).push_back(X);
    
  vector<ll> distance_selection(N, 0); // 0 ~ N-1
  
  
  rep(i, N){
    for(ll j = i; j < N; j++){
      ll distance, temp; 
      if(j - i > abs(X-i) + 1 + abs(Y-j)) temp = abs(X-i) + 1 + abs(Y-j);
      else temp = j - i;
      
      if(temp > abs(Y-i) + 1 + abs(X-j)) distance = abs(Y-i) + 1 + abs(X-j);
      else distance = temp;
      
      distance_selection.at(distance) ++;
      //cout << i+1 << ", " << j+1 << ", " << distance << endl;
    }
  }
  
  
  for(int i=1; i<N; i++) cout << distance_selection.at(i) << endl;
  
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
typedef long long int ll;
ll u(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll d(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll gcd(ll a,ll b){
  if(!b)return a;
  return gcd(b,a%b);
}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
ll f(ll a){
  return a*(a+1)/2;
}
int main(void){
  int n;
  scanf("%d",&n);
  char s[n+1];
  scanf("%s",s);
  int l=strlen(s);
  if(l%2){
    PRS("No");
    return 0;
  }
  FOR(l/2){
    if(s[i]!=s[i+l/2]){
      PRS("No");
      return 0;
    }
  }
  PRS("Yes");
  return 0;
}


Measured memory_bytes: 128
import java.io.*;
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A  = sc.nextInt(), B = sc.nextInt();
    int opt1 = A + A - 1;
    int opt2 = B + B - 1;
    int opt3 = A + B;
    System.out.println(Math.max(opt1, Math.max(opt2, opt3)));
  }
}


Measured memory_bytes: 35888
# Aizu Problem 0285: Tennis

import sys, math, os, itertools

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")

def get_games(game):
    a, b = game.count('A'), game.count('B')
    if (a == 5 and b < 4) or (b == 5 and a < 4) or a == b == 5 or \
       (a == 6 and b == 4) or (b == 6 and a == 4):
        games.add(game)
    elif max(a, b) <= 4 or a == b == 4 or (a == 5 and b == 4) or (b == 5 and a == 4):
        games.add(game)
        if game + 'A' not in games:
            get_games(game + 'A')
        if game + 'B' not in games:
            get_games(game + 'B')

A, B = [int(_) for _ in input().split()]
games = set()
get_games("")

ans = []
for game in games:
    if game.count('A') == A and game.count('B') == B:
        ans.append(game)

for game in sorted(ans):
    print(game)

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

int main(void){
    long n;
    scanf("%ld", &n);
    long sum=0;
    bool same = true;
    long b_min=LONG_MAX;
    long a, b;
    for(long i=0; i<n; i++){
        scanf("%ld %ld", &a, &b);
        sum += a;
        if(a!=b){
            same=false;
        }
        if(a>b){
            if(b<b_min){
                b_min=b;
            }
        }
    }
    if(same){
        cout << 0 << endl;
    }else{
        cout << sum - b_min << endl;
    }
    return 0;
}


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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

template <unsigned long long mod> class modint {
public:
	unsigned long long v;
	modint(const long long x = 0) : v(x % mod) {}
	modint operator+(const modint rhs) { return modint(*this) += rhs; }
	modint operator-(const modint rhs) { return modint(*this) -= rhs; }
	modint operator*(const modint rhs) { return modint(*this) *= rhs; }
	modint operator/(const modint rhs) { return modint(*this) /= rhs; }
	modint operator-() { return modint(mod - this->v); }
	modint& operator+=(const modint rhs) {
		v += rhs.v;
		if (v >= mod) v -= mod;
		return *this;
	}
	modint& operator-=(const modint rhs) {
		if (v < rhs.v) v += mod;
		v -= rhs.v;
		return *this;
	}
	modint& operator*=(const modint rhs) {
		v = v * rhs.v % mod;
		return *this;
	}
	modint inverse(modint a) {
		unsigned long long exp = mod - 2;
		modint ret(1ULL);
		while (exp) {
			if (exp % 2) { ret *= a; }
			a *= a;
			exp >>= 1;
		}
		return ret;
	}
	modint& operator/=(modint rhs) {
		(*this) *= inverse(rhs);
		return *this;
	}
	friend ostream& operator<<(ostream& os, modint& u) {
		os << u.v;
		return (os);
	}
	friend istream& operator>>(istream& is, modint& u) {
		is >> u.v;
		return (is);
	}
};

const int MOD = 1000000007;
using mint = modint<MOD>;
template<class T>
T fastpow(T a, long long p){
	T tmp = a;
	T ret = 1;
	while(p){
		if(p & 1)ret *= tmp;
		p >>= 1;
		tmp = tmp * tmp;
	}
	return ret;
}

class Solution {
public:
	void solve() {
		int n;
		cin >> n;
		vector<int> a(n, 0);
		for(int i=0; i<n; i++)cin >> a[i];
		sort(a.begin(), a.end(), greater<int>());
		mint ans = 0;
		for(int i=0; i < n; i++)ans += mint{a[i]} * (i+2);
		ans *= fastpow(mint{2}, 2*n-2);
		cout << ans << endl;
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int m1, d1, m2, d2;
    cin>>m1>>d1>>m2>>d2;
    if (m1!=m2){
        cout <<"1\n";
    }else{
        cout<<"0\n";
    }
    return 0;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def add(a,b):
    return a+b

def sub(a,b):
    return a-b

funcs = [add, sub]
n,m = li()

xyz = [tuple(li()) for _ in range(n)]

ans = 0
for func1 in funcs:
    for func2 in funcs:
        for func3 in funcs:
            temp = []
            for x,y,z in xyz:
                temp.append(func1(0, func2(x, func3(y, z))))
            
            temp.sort(reverse=True)
            ans = max(ans, sum(temp[:m]))
            
print(ans)

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

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

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

int main() {
    int n;
    cin >> n;
    map<string, int> v;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        v[s]++;
    }
    vector<string> a{"AC", "WA", "TLE", "RE"};
    for (auto &&j : a) {
        cout << j << " x" << " " << v[j] << "\n";
    }
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef long double lld;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define cerr if(true)cerr
void print(){cout<<endl;}
template<typename T,typename... Args>
void print(T a, Args... args) {cout<<a<<" ";print(args...);}
lli llipowerp(lli x, lli y, lli p=LLONG_MAX)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli binarySearch(vector<int> arr, int l, int r, int x)
{
    if (r >= l)
    {
        lli mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
template <typename T>
inline void printvec(vector<T> inp){
    for(auto it:inp) cout<<it<<" ";
    cout << endl;
}
//---------------------------------------------------------------------------------
vector<vector<int>> h;


int dp[(int)1e5+5][3];
int fill(int n,int i){
    if(dp[n][i]!=-1) return dp[n][i];
    if(n==1){
        return h[1][i];
    }
    dp[n][i]= max(h[n][i]+fill(n-1,(i+1)%3),h[n][i]+fill(n-1,(i+2)%3));
    return dp[n][i];
}
int main(){
    int n;
    cin>>n;
    h.resize(n+1);
    fori(n+1) h[i].resize(3);
    fori(n) {
        cin >> h[i + 1][0] >> h[i + 1][1] >> h[i + 1][2];
    }
    memset(dp,-1,sizeof(dp));
    cout<<max({fill(n,0),fill(n,1),fill(n,2)})<<endl;

}


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

const ll INF = 1e18;

int main(){
    double N; cin >> N;
    cout << fixed << setprecision(6) <<   1 -  ((int)N / 2) / N << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{

    int n, q, i, j, cnt = 0;
    int a[10000], b[500];

    cin >> n;
    for (i = 0; i < n; i++)
        cin >> a[i];
    cin >> q;
    for (j = 0; j < q; j++)
        cin >> b[j];

    for (i = 0; i < q; i++)
    {
        for (j = 0; j < n; j++)
        {
            if (b[i] == a[j])
            {
                cnt++;
                break;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 3132
X = int(input())
num = [1]
for i in range(1, 33):
    b = i+1
    p = 2
    while b ** p <= 1000 and b ** p not in num:
        num.append(b ** p)
        p += 1
        
ans = sorted([num[i] for i in range(len(num)) if num[i] <= X])
print(ans[-1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
const int M = 2019;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    for(char& c : s) c -= '0';
    vector<int> counter1(2019), counter2(2019);
    ll ans = 0;
    for(char c : s) {
        for(int i = 0; i < 2019; i++) {
            counter2[(i * 10 + c) % 2019] = counter1[i];
        }
        counter2[c]++;
        ans += counter2[0];
        swap(counter1, counter2);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3748
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	char a, b;
	cin >> a >> b;
	if (a == 'H'&&b == 'H' || a == 'D'&&b == 'D')cout << "H" << endl;
	else cout << "D" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	int a, b; cin >> a >> b;
	if (b % a == 0)cout << a + b;
	else cout << b - a;

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
m1,m2 = 0,0
a = []
for i in range(n):
    a.append(int(input()))
    if a[i]>m1:
        m2=m1
        m1=a[i]
    elif a[i]>m2: m2=a[i]
for i in range(n):
    if a[i]==m1: print(m2)
    else: print(m1)

Measured memory_bytes: 12532
#include<stdio.h>
#include<limits.h>

int main(){
  int i,n,mx=INT_MIN,mn=INT_MAX;
  scanf("%d",&n);
  int h[n];
  for(i=0;i<n;i++){
    scanf("%d",&h[i]);
    if(i==0){
      mn=h[i];
      continue;
    }
    if(h[i]-mn>mx)mx=h[i]-mn;
    if(mn>h[i])mn=h[i];
    //printf("%d%d\n",mx,mn);
    
  }
  printf("%d\n",mx);
  return 0;
}



Measured memory_bytes: 3468
#include <stdio.h>
#define N 100
int main(){

  int i,j,num;
  int minj,count=0;
  int A[N],tmp;

  scanf("%d",&num);
  
  for(i=0;i<num;i++){
    scanf("%d",&A[i]);
  }

 
  for(i=0;i<num;i++){
    minj=i;
    for(j=i;j<num;j++){
      if(A[j]<A[minj]){
	minj=j;
      }
    }
    if(A[i]!=A[minj]){
      count++;
    }
    tmp=A[minj];
    A[minj]=A[i];
    A[i]=tmp;
     
  }


for(i=0;i<num-1;i++){
  printf("%d ",A[i]);
 }
printf("%d\n",A[num-1]);
printf("%d\n",count);



return 0;
}



Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define Rep(i,a,n) for (ll i = (a); i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)
using Graph = vector<vector<ll>>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll d;
  cin >> d;
  d = 25 - d;
  cout << "Christmas";
  rep(i,d) {
    cout << " Eve";
  }
  cout << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#define ll long long
#define si(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pi(n) prllf("%d",n)
#define pl(n) prllf("%d",n)
using namespace std;

ll solve(ll n){
  ll ans = 0;
  while(n){
    ans+=n%10;
    n/=10;
  }
  return ans;
}

int main(){
  ll n,a,b;
  cin >> n >> a >> b;
  ll ans = 0;
  for(ll i=1;i<=n;i++){
    ll k  = solve(i);
    if(k>=a && k<=b){
      ans+=i;
    }
  }
  cout << ans << endl;
}


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

using namespace std;

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

    vector<int> A(N);

    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        A[i] -= i+1;
    }

    sort(A.begin(), A.end());
    
    int med = A[N/2];
    long long ans = 0;

    for (int i = 0; i < N; ++i) {
        ans += abs(A[i] - med);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    char c;
   int n,k;
   cin>>n>>k;
   int p[n];
   for(int i=0;i<n;i++) cin>>p[i];
   sort(p,p+n);
   ll sum=0;
   for(int i=0;i<k;i++) sum+=p[i];
   cout<<sum<<"\n"; 
 }

Measured memory_bytes: 3648
fn read<T: std::str::FromStr>() -> T {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let n: u32 = read();
  let ps: Vec<u32> = read_vec();
  let ps2: Vec<u32> = (1..n + 1).collect();

  let is_asc = ps.iter().zip(ps2.iter())
    .filter(|x| x.0 != x.1)
    .collect::<Vec<(&u32, &u32)>>()
    .len();
  
  println!("{}", if is_asc <= 2 { "YES" } else { "NO" });
}


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

long long cnt = 0;
vector<int> g;

void insertionSort(int a[], int n, int g) {
  int v;
  for (int i = g; i < n; i++) {
    v = a[i];
    int j = i - g;
    while (j >= 0 && a[j] > v) {
      a[j + g] = a[j];
      j -= g;
      cnt++;
    }
    a[j + g] = v;
  }
}

void shellSort(int a[], int n) {
  for (int h = 1;;) {
    if (h > n) break;
    g.push_back(h);
    h = 3 * h + 1;
  }
  for (int i = g.size() - 1; 0 <= i; --i) {
    insertionSort(a, n, g[i]);
  }
}

int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  shellSort(a, n);
  cout << g.size() << endl;
  for (int i = g.size() - 1; 0 <= i; --i) {
    cout << g[i] << ((i == 0) ? '\n' : ' ');
  }
  cout << cnt << endl;
  for (int i = 0; i < n; ++i) {
    cout << a[i] << endl;
  }
}



Measured memory_bytes: 7004
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>
#include <random>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
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(a > b){a = b; return 1;} return 0;}


int main(int argc, char const* argv[])
{
  ll k, a, b;
  cin >> k >> a >> b;
  if(k < a + 1 || b < a + 2){
    cout << k + 1 << endl;
    return 0;
  }
  k -= a - 1;
  ll num = k / 2;
  ll res = num * (b - a) + a;
  if(k % 2 == 1)res += 1;
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#define mod 1000000007
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define srep(i,s,t) for (ll i = s; i < t; i++)
#define drep(i,n) for(ll i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long ll;
typedef vector<vector<char>> field_t;
typedef unsigned long long ull;
typedef pair<ll, ll> point_t;


int main()
{
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n,0);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n-k){
        if(a[i]<a[i+k]){
            cout << "Yes" <<endl;
        }else{
            cout << "No" <<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
#define int long long

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  string s; cin >> s;
  int ans = (int)s.size();
  for(int i = 1; i < (int)s.size(); i++){
    if(s[i-1] != s[i]){
      ans = min(ans,max(i,(int)s.size() - i));
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define maxn 100005
using namespace std;
int a[maxn];
int main()
{
    int n,k,q;
    scanf("%d%d%d",&n,&k,&q);
    for(int i=1;i<=n;i++) a[i]=k-q;
    for(int i=1;i<=q;i++){
        int num;
        scanf("%d",&num);
        a[num]++;
    }
    for(int i=1;i<=n;i++){
        if(a[i]>0) puts("Yes");
        else puts("No");
    }
    return 0;
}

Measured memory_bytes: 1024
def resolve():
    # P は [0, 1]
    N, P = map(int, input().split())
    A = list(map(int, input().split()))

    odds = sum([1 for a in A if a % 2 == 1])

    ans = 0
    if odds == 0:
        if P == 0:
            ans = 2 ** N
    else:
        ans = 2 ** (N - 1)

    print(ans)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int x;
    cin>>x;
    if(x)cout<<0<<endl;
    else cout<<1<<endl;
  
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1e5 + 50;
typedef pair<int,int> pi;
pi arr[MAXN];
bool cmp(pi a, pi b){
    return a.first < b.first;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int N, M; cin >> N >> M;
    for (int i=0; i<N; i++){
        int a, b; cin >> a >> b;
        arr[i] = {a,b};
    }
    sort(arr, arr+N, cmp);
    int cur = M;
    int ans = 0;
    for (int i=0; i<N; i++){
        if (cur <= 0) break;
        ans += min(cur, arr[i].second) * arr[i].first;
        cur -= min(cur, arr[i].second);
    }
    cout << ans;
}


Measured memory_bytes: 1792
/**
 * @Author: yujirotakahashi
 * @Date:   2020-05-17T20:21:41+09:00
 * @Last modified by:   yujirotakahashi
 * @Last modified time: 2020-05-23T00:13:28+09:00
 */

#include<bits/stdc++.h>
using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define Dcout(a) cout << setprecision(20) << a << endl
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
//const ll INF = (1LL << 60);
//const double pi=acos(-1.0);
using ll = long long;
using PAIR = pair<int, int>;
#define debug cout << "line : " << __LINE__ << " debug" << endl
/****** Template of some basic operations *****/
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; }
/**************************************/

/******** User-defined Function *******/
using Graph = vector<vector<int>>;
int w,h;
int c[55][55];
bool seen[55][55];
int dx[8] = {-1,0,1,-1,1,-1,0,1};
int dy[8] = {-1,-1,-1,0,0,1,1,1};
void dfs(int y,int x){
    seen[y][x] = true;

    rep(i,8){
        int nx = x + dx[i], ny = y + dy[i];
        if(nx<0 || nx>=w || ny<0 || ny>=h) continue;
        if(seen[ny][nx] == true) continue;
        if(c[ny][nx] == 0) continue;

        dfs(ny,nx);
    }

    return;
}
/**************************************/

/********** Main()  function **********/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  while(cin >> w >> h){
      if(w==0 && h==0) break;

      rep(i,h)rep(j,w) cin >> c[i][j];
      memset(seen, false, sizeof(seen));
      int cnt = 0;
      rep(i,h)rep(j,w){
          if(seen[i][j]==false && c[i][j] == 1){
              dfs(i,j);
              cnt++;
          }
      }

      cout << cnt << endl;
  }

  return 0;
}
/********  Main() Ends Here *************/



Measured memory_bytes: 3256
#pragma GCC optimize("Ofast")
#include <cstring>
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int main() {
    ll X, A, B;
    int i=0;

    cin >> X;

    for(A=-118; A<=119; A++) {
        for(B=-119; B<=118; B++) {
            if(pow(A, 5.0)-pow(B, 5.0) == X) {
                cout << A << " " << B << endl;
                i=1;
                break;
            }
        }
        if(i==1) {
            break;
        }
    }

}

Measured memory_bytes: 3664
package main
import "fmt"
func main(){
	var S string
	fmt.Scan(&S)
	ans := 0
	for _, c := range []rune(S){
		s := string(c)
		if s== "+"{
			ans+=1
		}else{
			ans-=1
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
#include <bits/stdc++.h> //g++-9で実行（gcc version 9.3.0），g++だとデフォルトのclang

using namespace std;

//#define int long long                         //intでオーバフローした時の切り替え用
#define debug(x) cerr << #x << ": " << x << endl //エラー出力として変数名と変数の中身表示
#define DEBUG_VEC(v)                   \
    cerr << #v << ":";                 \
    for (int i = 0; i < v.size(); i++) \
        cerr << " " << v[i];           \
    cerr << endl;
#define DEBUG_MAT(v)                          \
    cerr << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cerr << v[i][j] << " ";           \
        }                                     \
        cerr << endl;                         \
    }
#define Sp(p) cout << setprecision(25) << fixed << p << endl; //小数点以下を25桁で表示
#define all(obj) (obj).begin(), (obj).end()
#define pb push_back

//usingエイリアス（別名という意味，型定義のこと）
using ll = long long;
//template <class T> using Vec = std::vector<T>;//エイリアステンプレート

const ll MOD = (ll)1e9 + 7;
//const ll MOD = 998244353;
const ll INF = (ll)1e18 + 1;
const double EPS = 1e-9;
const long double pi = 3.1415926535897932384626433832795028841971L;

//マクロでintをlong longと定義したときはsinged
int main()
{
    cin.tie(0);                  //cinとcoutの同期を切る（高速化)
    ios::sync_with_stdio(false); //iostreamとstdioの同期を切る（高速化)

    ll n, k, c;
    cin >> n >> k;
    vector<ll> a(n);
    vector<ll> tmp;
    vector<bool> flag(n, false); //前に来たかどうかのflag
    for (ll i = 0; i < n; i++)
    {
        cin >> c;
        a[i] = c - 1; //配列の番号と合わせるため
    }

    tmp.pb(0);
    flag[0] = true;

    for (ll i = 0; i < n; i++)
    {
        tmp.pb(a[tmp[i]]);
        if (flag[a[tmp[i]]] == true)
            break;
        flag[a[tmp[i]]] = true;
    }

    auto loop_start_place_iter = find(tmp.begin(), tmp.end(), *(tmp.end() - 1));
    ll loop_num = distance(loop_start_place_iter, tmp.end()) - 1;
    ll before_num = tmp.size() - loop_num - 1;

    debug(loop_num);
    debug(before_num);

    debug(before_num + (k- before_num ) % loop_num);
    DEBUG_VEC(tmp);

    if (k > before_num)
    {
        cout << tmp[before_num + (k- before_num ) % loop_num] + 1 << endl;
    }
    else
    {
        cout << tmp[k] + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 6812