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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  n++;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  if (n == 1) {
    if (a[0] == 1) {
      cout << 1 << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }
  vector<ll> c_min(n), c_max(n);
  c_min[n - 1] = c_max[n - 1] = a[n - 1];
  c_min[0] = c_max[0] = 1;
  for (int i = n - 2; i > 0; i--) {
    c_min[i] = a[i] + (c_min[i + 1] + 1) / 2;
    c_max[i] = a[i] + c_max[i + 1];
  }
  ll ans = 1;
  vector<ll> c(n);
  c[0] = 1;
  for (int i = 1; i < n; i++) {
    if ((c[i - 1] - a[i - 1]) * 2 < c_min[i]) {
      cout << -1 << endl;
      return 0;
    }
    c[i] = min(c_max[i], (c[i - 1] - a[i - 1]) * 2);
    if (c[i] < a[i]) {
      cout << -1 << endl;
      return 0;
    }
    ans += c[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6316
#include <stdio.h>

int main(void){
  long i,j;

  long n;
  scanf("%ld",&n);

  long a,index_no[3]={-1,-1,-1},index[3]={0,0,0};
  for(i=0;i<n;i++){
    scanf("%ld",&a);
    if(index_no[0]==-1){
      index_no[0]=a;
      index[0]++;
    }else if(a==index_no[0]){
      index[0]++;
    }else if(index_no[1]==-1){
      index_no[1]=a;
      index[1]++;
    }else if(a==index_no[1]){
      index[1]++;
    }else if(index_no[2]==-1){
      index_no[2]=a;
      index[2]++;
    }else if(a==index_no[2]){
      index[2]++;
    }else{
      printf("No\n");
      return 0;
    }
  }

  if(((index_no[0]==0&&index[0]*2==index[1])||(index_no[1]==0&&index[1]*2==index[0]))&&index_no[2]==-1){
    printf("Yes\n");
  }else if(index_no[0]==0&&index[0]==n){
    printf("Yes\n");
  }else if(index[0]!=index[1]||index[1]!=index[2]){
    printf("No\n");
  }else if(index_no[0]!=(index_no[1]^index_no[2])){
    printf("No\n");
  }else{
    printf("Yes\n");
  }

  return 0;
}


Measured memory_bytes: 128
import scala.io.StdIn._

object Main {
  def transformation(s: String, n: Int, l: List[String] = Nil): List[String] = {
    if (n > 0) {
      val transformType = readLine().split(" ")
      val start = transformType(1).toInt
      val end = transformType(2).toInt + 1
      val to = transformType(2).toInt - start + 1
      transformType(0) match {
        case "print"   => transformation(s, n - 1, l :+ s.slice(start, end))
        case "replace" => transformation(s.patch(start, transformType(3), to), n - 1, l)
        case "reverse" =>
          val reverseText = s.slice(start, end).reverse
          val sReverse = s.patch(start, reverseText, to)
          transformation(sReverse, n - 1, l)
      }
    } else l
  }

  def main(args: Array[String]): Unit = {
    val originText = readLine()
    val transformNum = readInt()
    transformation(originText, transformNum).foreach(println)
  }
}

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

int main() {
		
	int n; cin >> n;
	map<string, int> mp;
	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		mp[s]++;
	}
	int maxCnt = 0;
	for (auto &u : mp) {
		maxCnt = max(maxCnt, u.second);
	}
	for (auto& u : mp) {
		if (u.second == maxCnt) {
			cout << u.first << endl;
		}
	}
	return 0;
}

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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n;
  cin >> n;
  vll l(n);
  rep(i, n) cin >> l[i];

  sort(all(l));

  ll ans = 0;

  rep(i, n) {
    FOR(j, i + 1, n) {
      FOR(k, j + 1, n) {
        if (l[i] + l[j] > l[k] && l[i] != l[j] && l[j] != l[k]) {
          ans++;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

typedef long long ll;
int main(){
    int K,S;
    cin >> K >> S;
    ll ans = 0;
    for(int i = 0; i <= K; i++){
        for(int j = 0; j <= K; j++){
            int k = S - i - j;
            if(k >= 0 && k <= K) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;


//stack<char> stk;
//set<ll> sll;
//map<string,ll> mp,mp1;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<char> deq;
//vector<ll> vll;
ll num[ten52];
ll num2[ten52];

int main(void)
{
    //double ans=0.0,d,d1,d2;
    //float f,g,h;
    long long int m,n,i,j,k=1;
    long long int a,a1,a2,a3,sum;
    string s,s1,s2;
    //char c,c1;
    sum=a=a1=a2=a3=0;
    cin>>s;
    cin>>s1;
    for(i=0;i<s.size();i++)
    {
        if(s[i]!=s1[i])
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}





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

int main(){
    int a;
    cin >> a;
    if(a==2){
        int A,B;
        cin >> A >> B;
        cout << A+B << endl;
    }
    if(a==1){
        cout << "Hello World" << endl;
    }

    return 0;
}

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

int main() {
    int num_cities, num_roads, orig, dest;
    cin >> num_cities;
    cin >> num_roads;
    vector<int> cities(num_cities, 0);

    for (int i=0; i < num_roads; i++) {
        cin >> orig;
        cities[orig-1] += 1;
        cin >> dest;
        cities[dest-1] += 1;
    }
    for (int n : cities) {
        cout << n << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{

string a[26][26];
int r,c,i,j,row,col;
cin>>r>>c;
for( i=0;i<r;i++)
{
  for( j=0;j<c;j++)
  {
    cin>> a[i][j];
    if(a[i][j]=="snuke")
    {
      row=i;
      col=j;
    }
  }

}
char aa=65+col;
cout<<aa<<row+1;

return 0;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

signed main()
{
  int N, D; cin >> N >> D;
  int K = 2*D+1;
  cout << N/K + (N%K == 0 ? 0 : 1) << endl;
  return 0;
}


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

int main() {
    int R, G, B, total;
    cin >> R >> G >> B;
    total = R * 100 + G * 10 + B;
    if (total % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
# C - One Quadrillion and One Dalmatians
def get_alphabet(mod):
	import string
	lower = string.ascii_lowercase
	
	if mod == 0 or mod == 26:
		return 'z'
	else:
		return lower[mod - 1]


n = int(input())

ans = ''

while n > 26:
	mod = n % 26
	s = get_alphabet(mod)
	ans = s + ans
	n //= 26
	
	if mod == 0:
		n -= 1
	
ans = get_alphabet(n) + ans
print(ans)

Measured memory_bytes: 9944
/*
  ∧,,∧
( 'ω' )つ ＜またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

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

#define all(x) (x).begin(),(x).end()

typedef long long LL;
typedef long double LD;

int main()
{
    int A, B;
    cin >> A >> B;

    if (B % A) {
        cout << B - A << endl;
    } else {
        cout << A + B << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int c[3][3];
    for (int i=0;i<3;i++) for (int j=0;j<3;j++) cin >> c[i][j];
    int x1 = c[0][0] + c[1][1] + c[2][2];
    int y1 = c[0][1] + c[1][2] + c[2][0];
    int z1 = c[0][2] + c[1][0] + c[2][1];
    int x2 = c[2][0] + c[1][1] + c[0][2];
    int y2 = c[2][1] + c[1][2] + c[0][0];
    int z2 = c[2][2] + c[1][0] + c[0][1];
    int w = 0;
    for (int i=0;i<3;i++) for (int j=0;j<3;j++) w += c[i][j];
    w /= 3;
    if (max({x1,y1,z1,x2,y2,z2,w}) != w || min({x1,y1,z1,x2,y2,z2,w}) != w) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int n,c=0;
    vector<pair<int,int>> p(100000),q(100000);
    cin>>n;
    for(int i=0;i<100000;i++){
        p[i].first = 0;
        p[i].second = i;
        q[i].first = 0;
        q[i].second = i;
    }
    for(int i=0;i<n;i++){
        int v;
        cin>>v;
        if(i%2==0){
            p[v-1].first++;
        }else{
            q[v-1].first++;
        }
    }
    sort(p.begin(),p.end(),greater<pair<int,int>>());
    sort(q.begin(),q.end(),greater<pair<int,int>>());
    if(p[0].second!=q[0].second){
        c=n-p[0].first-q[0].first;
    }else{
        c=n-max(p[0].first+q[1].first,p[1].first+q[0].first);
    }
    cout<<c<<endl;
    
    
}


Measured memory_bytes: 1792
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    readln.split.to!(int[]).reduce!"max(a-b, 0)".writeln;
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
import sys, copy
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def warshall_floyd(d):
    V = len(d)
    d = d
    for i in range(V):
        d[i][i] = 0
    for k in range(V):
        for i in range(V):
            for j in range(V):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d

def resolve():
    N = I()
    A = [LI() for _ in range(N)]

    min_cost = copy.deepcopy(A)
    min_cost = warshall_floyd(min_cost)
    ans = copy.deepcopy(min_cost)

    if A == min_cost:
        for i in range(N):
            for j in range(N):
                if i!=j:
                    for k in range(N):
                        if k!=i and k!=j:
                            if min_cost[i][j]==min_cost[i][k]+min_cost[k][j]:
                                ans[i][j] = 0
        print(sum([sum(i) for i in ans])//2)
    else:
        print(-1)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 64604
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
<url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0506>
?????????============================================================
0 ?????? 9 ?????§?????°???????????§?§??????????????????????????????????????????¨???,
??????????????????????¬??????????????????£?????°??????????????????????????????????????????.
???????????????????????????????????????1??????????????????????????§??????,????????°??? a ??? r ????¶???????????????´???,
?????° r ??¨??°???a ???????????§??????????????????????????§????????????.??????????????????????????????????????§??????,
????????????????????????????????£?????¨???????????§???????????????????????????????????£?????¨???????????¨??¨?????¨??????
??????1?????¨??????????????????.2????????\????????????????????????????????????????????????????????????????????????????????????
???????????¨??????????§?????????????????????????.????????° ???122244??? ??¨???????????????????????????????????´?????????
??????????????????1??????1, 3??????2,2??????4????????§????????????1?????§???????????????????????? ???113224??? ??§??????
,???44444444444??? (11 ??????4)?????´????????????????????????????????? ???114??? ??¨??????.

100 ????????\???????????????????????????????????????????????? n ???????????????????????????????????????????????°?????????????????????.
?????????, n ??? 20 ??¨??????.
=================================================================
??\???=============================================================
??\???????????°????????????????????????????????????n ??? 0 ?????¨?????\????????????????????????????????????????????°??? 5 ????¶?????????????
================================================================
??????=============================================================
???????????????????????¨??????????????????????????°?????????????????????????????? ???????????????????????????
================================================================
?§£??¬=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	ll n;
	while (cin >> n, n) {
		string s; cin >> s;
		for (int i = 0; i < n;i++) {
			char c;
			int cnt;
			string next;
			for (int j = 0; j <= s.length(); j++) {
				if (j == s.length()) {
					next += to_string(cnt) + c;
				}
				else {
					if (j == 0) {
						c = s[j]; cnt = 1;
						continue;
					}
					else {
						if (c == s[j])cnt++;
						else {
							next += to_string(cnt) + c;
							c = s[j];
							cnt = 1;
						}
					}
				}
			}
			s = next;
		}
		cout << s << endl;
	}
	return 0;
}

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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int s, w; gi(s), gi(w);
	if(w >= s) pstr("unsafe\n");
	else pstr("safe\n");
}


Measured memory_bytes: 3620
#include<stdio.h>

int selectionSort(int A[], int N) {
  int i, j, t, sw = 0, minj;
  for ( i = 0; i < N - 1; i++) {
    minj = i;
    for ( j = i; j < N; j++ ) {
      if ( A[j] < A[minj] ) minj = j;
    }
    t = A[i]; A[i] = A[minj]; A[minj] = t;
    if ( i != minj ) sw++;
  }
  return sw;
}

int main() {
  int A[100], N, i, sw;

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

  sw = selectionSort(A, N);

  for ( i = 0; i < N; i++ ) {
    if (i >0 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
  printf("%d\n", sw);

  return 0;
}


Measured memory_bytes: 2740
use proconio::{input, fastout};

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
  }

#[fastout]
fn main() {
    input!{
        n: usize,
        i: usize,
    }

    println!("{}", n-i+1);

}


Measured memory_bytes: 2120
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> field(h);
    rep(i,h) cin >> field[i];

    queue<int> queh;
    queue<int> quew;
    vvi dist(h, vi(w, -1));
    dist[0][0] = 0;
    queh.push(0);
    quew.push(0);

    vi dh = {0, -1, 0, 1};
    vi dw = {1, 0, -1, 0};
    while (!queh.empty() && !quew.empty()){
        int i = queh.front(); queh.pop();
        int j = quew.front(); quew.pop();
        rep(k,4){
            int ni = i + dh[k];
            int nj = j + dw[k];
            if (ni < 0 || ni >= h || nj < 0 || nj >=w) continue;
            if (dist[ni][nj] != -1) continue;
            if (field[ni][nj] == '#') continue;
            queh.push(ni);
            quew.push(nj);
            dist[ni][nj] = dist[i][j] + 1;
        }
    }

    int cnt = 0;
    rep(i,h)rep(j,w){
        if (field[i][j] == '.') cnt++;
    }
    int ans = cnt - dist[h-1][w-1] -1;
    cout << (dist[h-1][w-1] != -1? ans : -1) << endl;
}


Measured memory_bytes: 3600
// D - equeue

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

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

	int V[100];
	for (int i=0; i<N; i++) {
		cin >> V[i];
	}


	int max_value = 0;
	for (int i=0; i<=K && i<=N; i++) {
		for (int j=0; i+j<=K && i+j<=N; j++) {
			for (int k=0; i+j+k<=K && k<=i+j; k++) {
				int total_value = 0;

				deque<int> deq;
				for (int t=0; t<N; t++) {
					deq.push_back(V[t]);
				}

				priority_queue<int, vector<int>, greater<int>> pq;

				for (int t=0; t<i; t++) {
					int value = deq.front();
					//cout << "+ " << value << endl; // **** debug ****
					deq.pop_front();
					total_value += value;
					pq.push(value);
				}

				if (deq.empty()) break;
				for (int t=0; t<j; t++) {
					int value = deq.back();
					//cout << "+ " << value << endl; // **** debug ****
					deq.pop_back();
					total_value += value;
					pq.push(value);
				}

				for (int t=0; t<k; t++) {
					int value = pq.top();
					//cout << "- " << value << endl; // **** debug ****
					pq.pop();
					total_value -= value;
				}

				//cout << "i:" << i << " j:" << j << " k:" << k << " total_value:" << total_value << endl; // **** debug ****

				max_value = max(max_value, total_value);
			}
		}
	}

	cout << max_value << endl;

	return 0;
}

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

const static ll MOD = (1e+9)+7;

int main(){
    ll a,b,x;cin>>a>>b>>x;
    ll ans = 0;
    ans += b/x;
    ans -= a/x;
    if(a%x == 0)ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String... args) {
    Scanner sc = new Scanner(System.in);
    int size = sc.nextInt();
    int count = 0;

    for (int i = 0; i < size; i++) {
      if(checkPrime(sc.nextInt())) {
        count++;
      }
    }

    System.out.println(count);
  }

  public static boolean checkPrime(int num) {
    int count = 0;
    if (num == 1) {
      return false;
    } else if (num == 2) {
      return true;
    }

    if(num % 2 == 0) {
      return false;
    }

    for (int i = 3; i <= num / i; i+=2) {
      if (num % i == 0) {
        return false;
      }
    }
    return true;
  }
}



Measured memory_bytes: 41312
import sys
input1 = input().rstrip()
inputs = input().rstrip().split(' ')
inputs_list = list(inputs)
input1 = int(input1)

Alice = 0
Bob = 0

for i in range(input1):
    tmp = inputs_list[0]
    for j in range(len(inputs_list)):
        if (int(tmp) < int(inputs_list[j])):
            tmp = inputs_list[j]
    inputs_list.remove(tmp)
    if (i % 2 == 0):
        Alice += int(tmp)
    else:
        Bob += int(tmp)

print(Alice-Bob)


Measured memory_bytes: 3064
N = int(input())
INF = float("inf")
es = [[] for _ in range(N)]
for i in range(N-1):
    a,b,c = map(int, input().split())
    a,b = a-1, b-1
    es[a].append((b,c))
    es[b].append((a,c))

Q, K = map(int, input().split())
xy = []
for i in range(Q):
    x,y = map(int, input().split())
    xy.append([x-1, y-1])

checked = [False] * N
d = [INF] * N
d[K-1] = 0

next_check = []
next_check.append(K-1)
while len(next_check):
    now = next_check.pop()
    for next,cost in es[now]:
        if not checked[next]:
            d[next] = min(d[next], d[now] + cost)
            checked[next] = True
            next_check.append(next)
    


for x,y in xy:
    print(d[x] + d[y])


Measured memory_bytes: 60696
#define _CRT_SECURE_NO_WARNINGS 0
#include<stdio.h>

void prob_A(void);

int main(void) {

	prob_A();

	return 0;

}


//A問題
void prob_A() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);

	if ((a + b == c) || (b + c == a) || (c + a == b)) {
		printf("Yes");
	}
	else {
		printf("No");
	}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

signed main() {
  int h, w;
  cin >> h >> w;
  int a[h][w] = {};
  rep(i, h) rep(j, w) cin >> a[i][j];
  vector<int> prey, prex, y, x;
  rep(i, h) {
    if (i % 2) {
      for (int j = w - 1; 0 <= j; j--) {
        if (j == 0 && i == h - 1) break;
        if (j == 0) {
          if (a[i][j] % 2 == 1) {
            a[i][j]--;
            a[i + 1][j]++;
            prey.push_back(i);
            prex.push_back(j);
            y.push_back(i + 1);
            x.push_back(j);
          }
        } else if (a[i][j] % 2 == 1) {
          a[i][j]--;
          a[i][j - 1]++;
          prey.push_back(i);
          prex.push_back(j);
          y.push_back(i);
          x.push_back(j - 1);
        }
      }
    } else {
      for (int j = 0; j < w; j++) {
        if (j == w - 1 && i == h - 1) break;
        if (j == w - 1 && i < h - 1) {
          if (a[i][j] % 2 == 1) {
            a[i][j]--;
            a[i + 1][j]++;
            prey.push_back(i);
            prex.push_back(j);
            y.push_back(i + 1);
            x.push_back(j);
          }
        } else if (a[i][j] % 2 == 1) {
          a[i][j]--;
          a[i][j + 1]++;
          prey.push_back(i);
          prex.push_back(j);
          y.push_back(i);
          x.push_back(j + 1);
        }
      }
    }
  }
  cout << x.size() << endl;
  rep(i, x.size()) cout << prey[i] + 1 << ' ' << prex[i] + 1 << ' ' << y[i] + 1 << ' ' << x[i] + 1 << endl;
  return 0;
}


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

using namespace std;

int main(){
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;

  vector<long long> p(A), q(B), r(C);
  multiset<long long> s;
  int temp;
  for(int i=0; i<A; i++) cin >> p[i];
  for(int i=0; i<B; i++) cin >> q[i];
  for(int i=0; i<C; i++) {cin >> temp; s.emplace(temp);}

  std::sort(p.begin(), p.end());
  std::sort(q.begin(), q.end());

  for(int i=p.size()-X; i<p.size(); i++) s.emplace(p[i]);
  for(int i=q.size()-Y; i<q.size(); i++) s.emplace(q[i]);

  int count = 0;
  long long sum = 0;
  for(auto it=s.rbegin(); it!= s.rend(); it++){
    if (count == X + Y) break;
    sum += (*it);
    ++count;
  }

  cout << sum;
  return 0;
}


Measured memory_bytes: 15744
#include <utility>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <numeric>
#include <limits>
#include <queue>
#define ll long long int
#define rep(i,rept) for (ll i = 0; i < rept; i++)
#define Yes(b) std::cout<< (b ? "Yes" : "No")<<std::endl
#define YES(b) std::cout<< (b ? "YES" : "NO")<<std::endl
#define fr first
#define se second
#define se second
#define lolo 92233720368547757
#define susu 1000000007

using namespace std;
int main() {

	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		if (4 * i > N) {
			break;
		}
		if ((N - 4 * i) % 7 == 0) {
			Yes(true);
			return 0;
		}
	}
	Yes(false);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int h,w;
char field[101][101]={'a'};

int dfs(int x,int y){
  for(int dx=-1;dx<=1;dx+=2){
    int nx=x+dx;
    if(0<=nx && nx<h && field[nx][y]=='#')return 1;
  }
  for(int dy=-1;dy<=1;dy+=2){
    int ny=y+dy;
    if(0<=ny && ny<w && field[x][ny]=='#')return 1;
//        puts("yes");
  }
  return 0;
}


int main(){
  scanf("%d%d\n",&h,&w);
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      scanf(" %c",&field[i][j]);
    }
  }
//  int ans=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(field[i][j]=='#'){
        int flg = dfs(i,j);
        //printf("%d\n",flg);
        if(flg==0){
          puts("No");
          return 0;
        }
//        printf("%d\n",ans);
      }
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, ans = 0;
	string ss;
	cin >> nn >> ss;
	for(int64 ii = 0;ii < 1000;ii++)
	{
		int64 tmp = 100;
		for(int64 jj = 0;jj < nn;jj++)
		{
			if(ss[jj] == ((ii / tmp) % 10) + '0')
			{
				tmp /= 10;
				if(tmp == 0)
				{
					ans++;
					break;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main(){
    int N;
    cin>>N;
    vector<long> A(N);
    int cnt=0;
    for(int i=0; i<N; ++i){
        cin>>A[i];
        if(A[i]<0){
            A[i]*=-1;
            cnt++;
        }
    }
    sort(A.begin(), A.end());

    long sum=0;
    for(int i=1; i<N; i++){
        sum+=A[i];
    }

    if(cnt%2==1){
        cout<<sum - A[0]<<endl;
    }else{
        cout<<sum + A[0]<<endl;
    }

    return 0;
}

Measured memory_bytes: 1024
ans = "Yes"
l = []
N = int(input())
for _ in range(N):
  w = input()
  l.append(w)
for i in range(N-1):
  if l[i+1][0] != l[i][-1]:
    ans = "No"
  for j in range(i):
    if l[j] == l[i+1]:
      ans = "No"
print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;

bool does_satisfy_cond(int product) {
  for (; product >= 10; product /= 10) {
    int x = product % 10;
    int y = ((product - x) % 100) / 10;
    if (y + 1 != x) { return false; }
  }
  return true;
}

int main() {
  int N; cin >> N;
  vector<int> A(N);
  REP(i, N) { cin >> A[i]; }
  int ans = -1;
  REP(i, N) REP(j, N) {
    if (i == j) { continue; }
    int product = A[i] * A[j];
    if (does_satisfy_cond(product)) {
      ans = max(ans, product);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	string s;
	cin >> s;

	int n = s.size();
	int ans = 1e6;

	for (char c = '0'; c <= '1'; c++) {
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			if ((i % 2 == 0) ^ (s[i] != c)) cnt++;
		}
		chmin(ans, cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
    public static long divCeil(long a, long b){
        return (a+b-1)/b;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long tak = 1;
        long aok = 1;
        for(int n=0;n<N;n++){
        	long t = sc.nextLong();
        	long a = sc.nextLong();
        	long scale = Math.max(divCeil(tak,t), divCeil(aok,a));
        	tak = t*scale;
        	aok = a*scale;
        }
        System.out.println(tak+aok);
    }
}

Measured memory_bytes: 25300
package main

import "fmt"

func main() {
	var n, m, p, wc, ac int
	var s string
	wm := map[int]int{}

	fmt.Scan(&n, &m)
	for i := 0; i < m; i++ {
		fmt.Scan(&p, &s)
		if w, ok := wm[p]; ok {
			if w == -1 {
				continue
			}
			if s == "WA" {
				wm[p] = w + 1
			} else {
				wc += w
				ac++
				wm[p] = -1
			}
		} else {
			if s == "WA" {
				wm[p] = 1
			} else {
				ac++
				wm[p] = -1
			}
		}
	}
	fmt.Println(ac, wc)
}


Measured memory_bytes: 7936
fun main() {
    val k = readInt()
    val rems = mutableSetOf<Int>()
    var curr = 1
    var seven = 7 % k
    while (seven != 0 && seven !in rems) {
        rems.add(seven)
        seven = (seven * 10 + 7) % k
        curr++
    }
    println(if (seven == 0) curr else -1)
}

// Input Reader
private fun readLn() = readLine()!!

private fun readInt() = readLn().toInt()


Measured memory_bytes: 115272
def keisan(N,A):
     
     KAI = 0
     A.sort
 
     min = -100
     max = 101
     
     i = min
     
     while i <= max:
         kari = 0
         j = 0
         while j < N:
             kari += (A[j]-i)**2
             j += 1
        
         
         if kari <= KAI or i == min:
             KAI = kari
         i += 1
 
     
     return KAI
 
 
N = int(input())
 
A = input().split()
int_list = list(map(int,A))
 
print(keisan(N,int_list))

Measured memory_bytes: 9192
#include<stdio.h>
#include<math.h>

int main(void)
{
    double PI = acos(-1);
    int a, b;
    double C;
    scanf("%d %d %lf", &a, &b, &C);
    
    C = PI*C/180.0;
    printf("%lf\n", a*b * sin(C)/2.0);
    printf("%lf\n", a+b + sqrt( a*a + b*b - 2*a*b*cos(C)));
    printf("%lf\n", b*sin(C));
}


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

int main(void){
    int N;
    cin>>N;
    vector<char> s(N);
    for(int i=0;i<N;i++){
        cin>>s[i];
    }
    int ans=-1;
    for(int i=0;i<N;i++){
        int count=0;
        for(char c='a';c<='z';c++){
            bool right=false;
            bool left=false;
            for(int j=0;j<i;j++){
                if(s[j]==c) left=true;
                for(int k=i;k<N;k++){
                    if(s[k]==c) right=true;
                }
            }
            if(left==true&&right==true) count++;
        }
        ans=max(ans,count);
    }
    cout<<ans<<endl;
    return 0;
}



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

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

    //I don't care about anybody, and fuck ratings! I'll go to google!
    int n, k, x, ans = 0; cin>>n>>k;
    for(int i = 0; i<n; i++){
        cin>>x;
        if(x>=k) ans++;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int sum[100],touhyou[100],mato[100];int n,m,miss;
void game(int o){
	for(int p = 0;p<n;p++){
		cin >> touhyou[p];
		if (touhyou[p] == mato[o]){sum[p]++;}
		else{miss++;}
 
	}
	int k = mato[o]-1;
	sum[k]=sum[k]+miss;
}
int main() {
	cin >> n;
	cin>> m;
	for(int i = 0;i<m;i++){
		cin >> mato[i];
	}
	for(int i = 0;i<m;i++){
		miss = 0;
		game(i);
	}
	for(int i = 0;i<n;i++){
		cout << sum[i] << endl;
	}
	return 0;
}

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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  vector<ll> d(3);
  ll k;
  rep(i, 3) cin >> d[i];
  cin >> k;
  sort(d.rbegin(), d.rend());
  rep(i, k) d[0] *= 2;
  cout << d[0] + d[1] + d[2] << endl;
  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

const int mod = 1e9 + 7;
int dp[2][301][301];

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	dp[0][1][0] = 1;
	int next = 1, cur = 0;
	rep(i, m){
		memset(dp[next], 0, sizeof(dp[next]));
		rep(j, n + 1) rep(k, n + 1) if(dp[cur][j][k]){
			// back 0
			if(j + k <= n)
			(dp[next][j + k][0] += (ll)dp[cur][j][k] * j % mod) %= mod;
			// forward
			if(k + 1 <= n)
			(dp[next][j][k + 1] += (ll)dp[cur][j][k] * max(0, n - j - k) % mod) %= mod;
			// stay
			(dp[next][j    ][k] += (ll)dp[cur][j][k] * k % mod) %= mod;
		}
		swap(cur, next);
	}
	//dbg(dp[2][3][0]);
	
	cout << dp[cur][n][0] << endl;
	return 0;
}

Measured memory_bytes: 1024
# @oj: atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-05-10 20:03
# @url:
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
# region fastio

BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def main():
    abck=list(map(int,input().split()))
    a,b,c,k=abck[0],abck[1],abck[2],abck[3]
    if k<=a+b:
        if k<=a:
            print (k)
        else:
            print (a)
    else:
        x=k-(a+b)
        print (a-x)
if __name__ == "__main__":
    main()

Measured memory_bytes: 68380
#include<stdio.h>

long long N;
int num;

void DFS(long long nown,unsigned int flag){
	if(nown<=N){
		if(flag==7) num++;
		DFS(nown*10+3,flag|1);
		DFS(nown*10+5,flag|2);
		DFS(nown*10+7,flag|4);
	}
}

int main(){
	while(scanf("%d",&N)==1){
		num=0;
		DFS(0,0);
		printf("%d\n",num);
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m,c;
int b[50],a[50];
int ans=0;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
int main()
{
    scanf("%d%d%d",&n,&m,&c);
    for(int i=1;i<=m;i++) b[i]=read();
    for(int i=1;i<=n;i++)
    {
    	int sum=0;
		for(int j=1;j<=m;j++)
    	{
    		a[j]=read();
    		sum+=a[j]*b[j];
    	}
    	if(sum+c>0) ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = println(solve(new Scanner(System.in)))

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val A = sc.nextLong
    val B = sc.nextLong
    val C = sc.nextLong
    val K = sc.nextLong

    if (K % 2 == 0) {
      (A - B).toString
    } else {
      (B - A).toString
    }
  }
}


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

vector<bool> seen(200005,false);
vector<int> counter;
void dfs(vector<vector<int> > &vec, int v){
    seen.at(v) = true;
    for (int i = 0; i < vec.at(v).size(); i++){
        if (seen.at(vec.at(v).at(i))){
            continue;
        }
        counter[vec[v][i]] += counter[v];
        dfs(vec, vec.at(v).at(i));
    }
}

int main(){
    int N,Q;
    cin >> N >> Q;
    vector<vector<int> > to(N,vector<int> (0));
    
    for (int i = 0; i < N - 1; i++){
        int a,b;
        cin >> a >> b;
        to[a - 1].push_back(b - 1);
        to[b - 1].push_back(a - 1);
    }
    
    counter.assign(N,0);
    for (int i = 0; i < Q; i++){
        int p,x;
        cin >> p >> x;
        counter[p - 1] += x;
    }
    dfs(to, 0);
    
    for (int i = 0; i < N; i++){
        cout << counter[i] << " ";
    }
    
    
}


Measured memory_bytes: 29696
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <ext/pb_ds/priority_queue.hpp>
#define ll long long
#define MAXN 100005
using namespace std;
typedef pair<int,int> pii;
template <typename T>
inline void read(T& a)
{
	T ret(0),f(1);char ch(getchar());
	while(ch < '0' || ch > '9'){if(ch == '-') f = -1;ch = getchar();}
	while(ch >= '0' && ch <= '9'){ret = ret * 10 + (ch ^ 48);ch = getchar();}
	a = ret * f;
}
inline int Max(int x,int y){return x > y ? x : y;}
inline int Min(int x,int y){return x < y ? x : y;}
//优先队列，<里面记得反着写
struct nodel
{
	int x,id;
	nodel(int x = 0,int id = 0):x(x),id(id){}
	bool operator < (const nodel& t) const
	{
		return x < t.x;
	}
};
struct noder
{
	int x,id;
	noder(int x = 0,int id = 0):x(x),id(id){}
	bool operator < (const noder& t) const
	{
		return x > t.x;
	}
};
__gnu_pbds::priority_queue<nodel> q1,q2;
__gnu_pbds::priority_queue<noder> Q1,Q2;
int vis[MAXN];
int main()
{
	int n,l,r,now(0);ll ans1(0),ans2(0);
	read(n);
	for(int i(1);i <= n;i++)
	{
		read(l),read(r);
		q1.push(nodel(l,i)),q2.push(nodel(l,i));
		Q1.push(noder(r,i)),Q2.push(noder(r,i));
	}
	//跳了左端点相当于右端点也走过了。
	for(int i(1);i <= n;i++)
	{
		while(!q1.empty() && vis[q1.top().id]) q1.pop();
		while(!Q1.empty() && vis[Q1.top().id]) Q1.pop();
		if((i & 1) && now < q1.top().x) ans1 += q1.top().x - now,now = q1.top().x,vis[q1.top().id] = 1,q1.pop();
		else if(now > Q1.top().x) ans1 += now - Q1.top().x,now = Q1.top().x,vis[Q1.top().id] = 1,Q1.pop();
	}
	ans1 += now > 0 ? now : -now;
	memset(vis,now = 0,sizeof(vis));
	for(int i(1);i <= n;i++)
	{
		while(!q2.empty() && vis[q2.top().id]) q2.pop();
		while(!Q2.empty() && vis[Q2.top().id]) Q2.pop();
		if((!(i & 1)) && now < q2.top().x) ans2 += q2.top().x - now,now = q2.top().x,vis[q2.top().id] = 1,q2.pop();
		else if(now > Q2.top().x) ans2 += now - Q2.top().x,now = Q2.top().x,vis[Q2.top().id] = 1,Q2.pop();
	}
	ans2 += now > 0 ? now : -now;
	printf("%lld",max(ans1,ans2));
	return 0;
}


Measured memory_bytes: 19328
A[999][1000],I[1000],u[999];i,j;d;F=2;main(N){for(scanf("%d",&N);i<N;++i)for(j=0;j<N-1;)scanf("%d",A[j++]+i);for(;F&2;)for(F=1,i=!++d;i<N;++i)u[i]<d&I[i]<N-1&&I[F&=2,j=A[I[i]][i]-1]<N-1&&u[j]<d&A[I[j]][j]==i+1&&++I[u[i]=u[j]=d,++I[i],F=2,j];printf("%d",F*d-1);}

Measured memory_bytes: 4096
var i,n,t:Longint;s:String;
begin
readln(n);
readln(s);
for i:=1 to length(s)do begin
	t:=ord(s[i])+n;
	if t>90 then t:=t-26;
	s[i]:=chr(t);
end;
writeln(s);
end.

Measured memory_bytes: 128
//ID:computerbox --> Hajiyev Huseyn
#include <bits/stdc++.h>
#define FAST_READ ios_base::sync_with_stdio(0);/*cin.tie(0); cout.tie(0);*/
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define COUT(n, a) cout<< fixed << setprecision(a) << n<<endl
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
#define MAXN 200010

using namespace std;

ll massiv[MAXN];

ll n;


int main(){
FAST_READ;
cin>>n;
massiv[0]=2;
massiv[1]=1;
for(ll i=2;i<=n;i++)
{
	massiv[i]=massiv[i-1]+massiv[i-2];
}

cout<<massiv[n]<<endl;



return 0;
} 

Measured memory_bytes: 256
n = int(input())
S = [input() for i in range(n)]

ans = 0
start_b = 0
end_a = 0
ab = 0

for i in range(n):
    for j in range(len(S[i]) - 1):
        if S[i][j:j+2] == 'AB':
            ans += 1

    if S[i][0] == 'B' and S[i][-1] == 'A':
        ab += 1
        continue 
    if S[i][0] == 'B':
        start_b += 1
    if S[i][-1] == 'A':
        end_a += 1
    

if ab > 0:
    ans += ab - 1
    if start_b > 0:
        ans += 1
        start_b -= 1
    if end_a > 0:
        ans += 1
        end_a -= 1
        
ans += min(start_b, end_a)

print(ans)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n, a[252521];
	cin>>n;
	REP(i, n){
		cin>>a[i];
	}
	int now=0;
	ll ans=0;
	FORR(i, 0, n){
		if(a[i]>i || now>a[i]){
			cout<<-1<<'\n';
			return 0;
		}
		if(now<a[i]){
			ans+=a[i];
			now=a[i];
		}
		if(now){
			--now;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


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

#ifndef __TOPCYBERFLOWER
#define debug(...) 0
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif

#define INF (int)1e9+7
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
map<string,int> pre;
int main(void){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin>>n;
	int bef=0;
	for(int i=1;i<=n;i++){
		string s; cin>>s;
		int t; cin>>t;
		pre[s]=bef+t;
		bef+=t;
	}
	string x; cin>>x;
	cout<<bef-pre[x];
    return 0;
}

Measured memory_bytes: 256