akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll,ll>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.14159265359
using namespace std;



int main()
{
    SYNC
    //clock_t tStart = clock();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string n;
    in(n);
    ll sum=0;
    l(i,0, n.size())
    {
        ll temp = n[i] - '0';
        sum+=temp;
    }
    if(sum%9==0)
        o("Yes");
    else
        o("No");








    //printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);   
}


Measured memory_bytes: 3768
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <queue>
#include <iomanip>
#include <iterator>

#define MOD 1000000007
#define INF 1000000001

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


template <class T>
ostream &operator<<(ostream &o, const vector<T>&obj) {
    o << "["; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U>&obj) {
    o << "(" << obj.first << ", " << obj.second << ")"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const set<T>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const queue<T>&obj) {
    queue<T> obj_cp = obj;
    bool first = true;
    o << "{";
    while (!obj_cp.empty()) { o << (!first ? ", " : "") << obj_cp.front(); obj_cp.pop(); first = false; }
    o << "}"; return o;
}

void print() {
    cout << "\n";
}
template<class Head, class... Body>
void print(Head head, Body... body) {
    cout << head << " ";
    print(body...);
}


int N, M, Q;
vector<int> a, b, c, d;

int calc(const vector<int>& A) {
    int ret = 0;
    for (int i = 0; i < Q; ++i) {
        if (A[b[i]] - A[a[i]] == c[i]) {
            ret += d[i];
        }
    }
    return ret;
}

int search(int depth, vector<int> A) {
    if (depth == N) {
        // print(A, calc(A));
        return calc(A);
    }

    int ret = 0;
    int start = 1;
    if (depth > 0) {
        start = A[depth-1];
    }
    for (int i = start; i <= M; ++i) {
        A[depth] = i;
        ret = max(search(depth + 1, A), ret);
    }
    return ret;
}

int main(int argc, char const *argv[]) {
    cin >> N >> M >> Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i] -= 1;
        b[i] -= 1;
    }

    vector<int> A(N, 0);
    int ans = search(0, A);
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3632
def sub():
    N = int(input())
    S = input()

    black_count = S.count('#')
    white_count = S.count('.')
    # 右側がクロ #, 左を .
    rh_cost = white_count
    lh_cost = 0
    min_cost = rh_cost
    for i in range(N):
        s = S[i]
        if s == '#':
            lh_cost = lh_cost + 1
        else:  # .
            rh_cost = rh_cost - 1

        cost = lh_cost + rh_cost
        if min_cost > cost:
            min_cost = cost
    return min_cost


def main():
    res = sub()
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<P> v;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(begin(v), end(v), [&](P x, P y) { return x.second < y.second; });
  int num = 1;
  int t = v[0].second;
  for (int i = 1; i < m; i++) {
    if (v[i].first >= t) {
      t = v[i].second;
      num++;
    }
  }
  cout << num << endl;
}

Measured memory_bytes: 1400
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    a=list(map(int,input().split()))
    a.sort(reverse=1)
    print(sum(a[::2])-sum(a[1::2]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i,n) for((i)=1;(i)<=(n);(i)++)
using namespace std;
int n,m,a,b,i,j;
char ans[1005][1005];
int main(){
	cin>>n>>m>>a>>b;
	rep(i,n)rep(j,m)ans[i][j]='.';
	if(n&1){
		for(i=1;i+1<=m;i+=2){
			if(!a) continue;
			a--;
			ans[n][i]='<';
			ans[n][i+1]='>';
		}
	}
	if(m&1){
		for(i=1;i+1<=n;i+=2){
			if(!b) continue;
			b--;
			ans[i][m]='^';
			ans[i+1][m]='v';
		}
	}
	if((n&1)&&(m&1)&&(a&1)&&(b&1)){
		a--;b--;
		ans[n-2][m-2]='<';ans[n-2][m-1]='>';ans[n-2][m]='^';
		ans[n-1][m-2]='^';ans[n-1][m-1]='.';ans[n-1][m]='v';
		ans[n-0][m-2]='v';ans[n-0][m-1]='<';ans[n-0][m]='>';
	}
	for(i=1;i+1<=n;i+=2){
		for(j=1;j+1<=m;j+=2){
			if(ans[i][j]=='.'&&ans[i+1][j]=='.'&&ans[i][j+1]=='.'&&ans[i+1][j+1]=='.'){
				if(a){
					if(a){
						ans[i][j]='<';
						ans[i][j+1]='>';
						a--;
					}
					if(a){
						ans[i+1][j]='<';
						ans[i+1][j+1]='>';
						a--;
					}
					continue;
				}
				if(b){
					if(b){
						ans[i][j]='^';
						ans[i+1][j]='v';
						b--;
					}
					if(b){
						ans[i][j+1]='^';
						ans[i+1][j+1]='v';
						b--;
					}
					continue;
				}
			}
		}
	}
	if(a||b) puts("NO");
	else{
		puts("YES");
		rep(i,n){
			rep(j,m){
				putchar(ans[i][j]);
			}
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

int main() {
	int n;
	vector<int> v(100);

	fill(v.begin(), v.end(), 114514);

	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> v[i];

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

	cout << v[n - 1] - v[0] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (ll i = 0; i < (o);i++)
#define rep_s(i, o) for (int i = 1; i <= (o);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }


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

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

int main() {
    ll w, h, n; 
    cin >> w >> h >> n;

    vector<pair<ll, ll>> coords(n); vector<ll> a(n);
    rep(i, n) cin >> coords[i].first >> coords[i].second >> a[i];

    ll min_w = 0; ll min_h = 0;
    rep(i, n) {
        if (w == 0 || h == 0) { cout << 0 << endl; return 0; }
        if (a[i] == 1) min_w = max(coords[i].first, min_w);
        if (a[i] == 2) w = min(coords[i].first, w);
        if (a[i] == 3) min_h = max(coords[i].second, min_h);
        if (a[i] == 4) h = min(coords[i].second, h);

        if (w-min_w <= 0 || h-min_h <= 0) { cout << 0 << endl; return 0; }
    }
    
    cout <<  (w-min_w)*(h-min_h) << endl;
    return 0;
}

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

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int m = scan.nextInt();
    int[] r = new int[2*m];
    int[] rr = new int[n+1];

    for(int i = 0; i < 2*m; i++){r[i] = scan.nextInt();}
    //for(int i = 0; i < 2*m; i++){System.out.println(r[i]);}

    for(int i = 0; i < n+1; i++){rr[i] = 0;}

    for(int i = 0; i < 2*m; i++){
      rr[r[i]]++;
    }

    for(int i = 1; i <= n; i++){
      System.out.println(rr[i]);
    }

  }
}


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

int main(){
    int N;
    cin>>N;
    vector<int> a(N);
    rep(i, N){
        cin>>a.at(i);
    }
    int count=0;
    int m;
    int r;
    rep(i, N){
        m=0;
        r=0;
        rep(j, N){
            if(m<a.at(j)){
                r=j;
            }
            m=max(m, a.at(j));
        }
        if(i%2==0){
            count+=m;
        }
        else{
            count-=m;
        }
        a.at(r)=0;
    }
    cout<<count<<endl;
}

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

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

        long long H, x;
        cin >> H;
        x = log2(H);
        cout << fixed << (long long)(2 * (pow(2, x) - 1) + 1) << endl;
        return 0;
}

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

vector<vector<int> > v(100010);
int dp[100010];

int solver(int i){
	if(dp[i] != -1) return dp[i];
	int res = 0;
	for(auto next: v[i]) {
		res = max(res, solver(next) + 1);
	}
	return dp[i] = res;
}

int main(){
	int n, m, x, y;
	scanf("%d%d", &n, &m);
	for(int i=0; i < m; i++) {
		scanf("%d%d", &x, &y);
		v.at(x-1).push_back(y-1);
	}
	for(int i=0; i < n; i++) dp[i] = -1;
	int ans = 0;
	for(int i=0; i < n; i++)
		ans = max(ans, solver(i));
	printf("%d\n", ans);
}


Measured memory_bytes: 8192
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
//#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;
using pis = std::pair<int, std::string>;

const long long INF = 1000000000000000001;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
//namespace mp = boost::multiprecision;

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

	int n, m;
	cin >> n >> m;
	int* x = new int[m];
	rep(i, m) cin >> x[i];
	sort(x, x + m);

	if (n >= m) {
		cout << 0 << "\n";
	}
	else {
		ll* dif = new ll[m - 1];
		REP(i, 1, m) dif[i-1] = x[i] - x[i - 1];
		sort(dif, dif + m - 1);

		ll ans = 0;
		rep(i, m - n) ans += dif[i];

		cout << ans << "\n";
	}

	return 0;
}


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

using namespace std;

struct city {
	int i, p, x;
};

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

	vector<vector<city>> ps;
	ps.resize(N);

	for (auto i = 1; i <= M; ++i) {
		int P, Y;
		scanf("%d %d", &P, &Y);

		auto &p = ps[P-1];
		p.push_back({i, P, Y});
	}

	vector<city> ps2;
	ps2.reserve(M);

	for (auto &p: ps) {
		sort(p.begin(), p.end(), [](city &a, city &b) {
			return a.x < b.x;
		});
		for (auto ci = 0; ci < p.size(); ++ci) {
			auto &c = p[ci];
			ps2.push_back({c.i, c.p, ci + 1});
		}
	}
	
	sort(ps2.begin(), ps2.end(), [](city &a, city &b) {
		return a.i < b.i;
	});

	for (auto &c: ps2) {
		printf("%06d%06d\n", c.p, c.x);
	}
}

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

struct Dice{
         int n[6];
         void move_n(int r){
             r=n[0];
             n[0]=n[1];
             n[1]=n[5];
             n[5]=n[4];
             n[4]=r;
         }
         void move_s(int r){
             r=n[0];
             n[0]=n[4];
             n[4]=n[5];
             n[5]=n[1];
             n[1]=r;
         }
         void move_w(int r){
             r=n[0];
             n[0]=n[2];
             n[2]=n[5];
             n[5]=n[3];
             n[3]=r;
         }
         void move_e(int r){
             r=n[0];
             n[0]=n[3];
             n[3]=n[5];
             n[5]=n[2];
             n[2]=r;
         }
    };
int main(){
    Dice x;
    string ch;
    for(int i=0;i<6;i++)cin>>x.n[i];
    cin>>ch;
    for(int i=0;i<ch.size();i++){
        if(ch[i]=='N'){
            x.move_n(i);
        }else if(ch[i]=='S'){
            x.move_s(i);
        }else if(ch[i]=='W'){
            x.move_w(i);
        }else if(ch[i]=='E'){
            x.move_e(i);
        }
    }cout<<x.n[0]<<endl;
    return 0;
}


Measured memory_bytes: 3216
import sys
#import time
import copy
#from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
#import time

input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def find(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def same(self, x, y):
        return self.find(x) == self.find(y)
    # ノードxが属する木のサイズを返す
    def size(self, x):
        return -self.root[self.find(x)]


n = ri()
d=[tuple(rl())+tuple((i,)) for i in range(n)]

d.sort(key=lambda x: x[0])
edge=[]
for i in range(n-1):
    edge.append((d[i+1][2], d[i][2],d[i+1][0]-d[i][0]))
d.sort(key=lambda x:x[1])
for i in range(n-1):
    edge.append((d[i+1][2], d[i][2],d[i+1][1]-d[i][1]))
edge.sort(key=lambda x: x[2])
res=0
uf = UnionFind(n)
for e in edge:
    if uf.same(e[0], e[1]):
        continue
    uf.unite(e[0], e[1])
    res+=e[2]
print(res)

Measured memory_bytes: 123816
n = int(input())
#k(2~n)について、2~kの素数までで割り切れる回数をカウント

if n==1:
    print(1)
    import sys
    sys.exit()

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

prime_list = primes(n)
prime_cnt = dict([(k,0) for k in prime_list])
from decimal import Decimal

for k in range(2,n+1):
    k = Decimal(k)
    for j in prime_list:
        j=Decimal(j)
        while k%j==0:
            prime_cnt[j]+=1
            k = k/j
        if k==1:
            break

import functools
import operator


print(functools.reduce(operator.mul, [v+1 for v in prime_cnt.values()])%(10**9+7))


Measured memory_bytes: 5204
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

const int MAXT = 30;
const int MAXN = 100;
const int MAXD = 110;
int t[MAXT];
int d[MAXN];
int m[MAXN];

int dp[MAXD][MAXT];

int main(){
  int T, N;
  while(cin >> T && T){
    REP(i, T) cin >> t[i];
    cin >> N;
    REP(i, N){
      cin >> d[i] >> m[i];
      d[i]--;
    }
  
    REP(i, N)REP(j, N - 1){
      if(d[j] > d[j+1] || (d[j] == d[j+1] && m[j] > m[j+1])){
        swap(d[j], d[j+1]);
        swap(m[j], m[j+1]);
      }
    }
  
  
    fill(&dp[0][0], &dp[0][0] + MAXD * MAXT, INF);

    dp[0][0] = 0;
    REP(i, MAXD-1){
      REP(j, T){

        if(dp[i][j] == INF) continue;
        bool use = false;
        REP(k, N) if(d[k] == i && t[j] > m[k]) use = true;
      
        dp[i+1][1] = min(dp[i+1][1], dp[i][j] + 1);
      
        if(!use) {
          dp[i+1][(j+1)%T] = min(dp[i+1][(j+1)%T], dp[i][j]);
        }
      }
    }
    int res = INF;
    REP(i, T) res = min(res, dp[MAXD-1][i]);
  
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#define ff first
#define ss second
#define forn(i,n) for (int i=0;i<int(n);i++)
#define nfor(i,n) for (int i=int(n)-1;i>=0;i--)
#define rep(i,a,b)for (int i=a;i<=int(b);i++)
#define rev(i,a,b)for (int i=a;i>=int(b);i--)
#define hell 2000000000
#define fuck 2000000000000000000
using namespace std;
const int N = 100010;
const int M = 1000010;
const double PI = acos(-1.0);
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int gcd(int a,int b){return (b==0)?a:gcd(b,a%b);}
 
int main() {
 
	string s;
	cin>>s;
	if (s.size()<4)
		puts("No");
	else if (s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I')
		puts("Yes");
	else
		puts("No");
 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

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

    if (in_num == 0) {
        cout << "Undefined." << endl;
    } else {
        int in_1;
        cin >> in_1;

        int min, max;
        long sum;
        min = max = sum = in_1;

        int i;
        for (i = 2; i <= in_num; i++) {
            int in_i;
            cin >> in_i;

            if (min > in_i) {
                min = in_i;
            }

            if (max < in_i) {
                max = in_i;
            }

            sum += in_i;
        }

        cout << min << " " << max << " " << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 1164
/**
 *   @FileName	b.cpp
 *   @Author	kanpurin
 *   @Created	2020.05.17 23:28:18
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    int k;
    string s;
    cin >> k >> s;
    if (s.size() <= k) {
        cout << s << endl;
    } else {
        for (int i = 0; i < k; i++) {
            cout << s[i];
        }
        cout << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3568
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
int A, B;
int main() {
	cin >> A >> B;
	if (A == 1) A = 14;
	if (B == 1) B = 14;
	if (A > B) puts("Alice");
	if (A < B) puts("Bob");
	if (A == B) puts("Draw");
	return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int n;
    while (cin >> n, n) {
        V a(n);
        rep(i, n) cin >> a[i];

        int ans = -1e9;
        rep(i, n) {
            int t = 0;
            rep2(j, i, n) {
                t += a[j];
                ans = max(ans, t);
            }
        }

        cout << ans << endl;
    }
}

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

s_list=[-1]*N

ss=""
for i in range(M):
    s,c=map(int,input().split())
    s-=1
    if s==0 and c==0 and N!=1:
        ss="-1"
    if s_list[s]==-1:
        s_list[s]=c
    else:
        if s_list[s] ==c:
            pass
        elif s_list[s]!=c:
            ss="-1"


if ss=="-1":
    pass
else:
    for i,s in enumerate(s_list):
        if s !=-1:
            ss+=str(s)
        else:
            if i==0 and M==0 and N==1:
                ss=str(0)
            elif i==0:
                ss+=str(1) 
            else:
                ss+=str(0)

print(int(ss))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repp(i,a,b)	for(ll int i=b-1;i>=a;i--)
#define tr(container,it) for(__typeof__(container.begin()) it = container.begin(); it != container.end(); it++)
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define mpi         map<pair<ll int,ll int>,ll int>
#define vii         vector<pair<ll,pair<ll,ll> > >
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;
#define N  100005
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";



void solve(){
	ll k;
	cin>>k;
	ll an=0;
	k++;
	rep(i,1,k)
	rep(j,1,k)
	rep(l,1,k){
		an+=(__gcd(i,__gcd(j,l)));
	}
	cout<<an;
	time;

}	

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll TESTS=1,an=1;
	// cin>>TESTS;
	while(TESTS--){
		// cout<<"Case #"<<an<<": ";
		an++;
		solve();

	}
	return 0;
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int h,w;cin>>h>>w;
    VS s(h);
    REP(i,h){
        cin>>s[i];
    }
    VVI r(h);
    REP(i,h){
        r[i].resize(w,-1);
    }

    queue<VI> q;
    q.push({0,0,0});
    s[0][0]='x';
    r[0][0]=0;

    while(!q.empty()){
        int x=q.front()[0];
        int y=q.front()[1];
        int d=q.front()[2];
        q.pop();

        if(x==h-1 && y==w-1){
            break;
        }

        VI dx={1,-1,0,0};
        VI dy={0,0,1,-1};

        REP(i,4){
            int nx=x+dx[i];
            int ny=y+dy[i];
            int nd=d+1;

            if(nx<0 || nx>=h || ny<0 || ny>=w){
                continue;
            }
            if(s[nx][ny] != '.'){
                continue;
            }
            s[nx][ny] = 'x';
            r[nx][ny] = nd;
            q.push({nx, ny, nd});
        }
    }

    int m = r[h-1][w-1];
    if(m==-1){
        cout<<-1<<endl;
        return;
    }
    vector<bool> f(m+1,false);
    int result=0;
    REP(i,h){
        REP(j,w){
            if(s[i][j] == '#'){
                continue;
            }
            if(r[i][j] == -1){
                result++;
                continue;
            }

            if(r[i][j]<=m && !f[r[i][j]]){
                f[r[i][j]]=true;
            }
            else{
                result++;
            }

        }
    }

    cout<<result<<endl;



	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
//Self-control leads to consistency.
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
int main()
{
  //flash;
  ll n,d;
  cin>>n>>d;
  ll ans=0;
  for (int i = 0; i < n; ++i)
  {
    ll x,y;
    cin>>x>>y;
    if(x*x+y*y<=d*d)ans++;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
	ll N, K, Q;
	cin >> N >> K >> Q;
	vector<ll> A(Q);
	vector<ll> P(N,0);

	for(ll i=0;i<Q;i++){
		cin >> A[i];
		P[A[i]-1]++;
	}

	ll ans;
	for(ll i=0;i<N;i++){
		ans = K-Q+P[i];
		if(ans > 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	return 0;

}

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

int main(){
	long long a,ans;
    double b;
    cin >> a;
    cin >> b;
    
    //Bを100倍する際に微小な数を足して切り捨ててもらう
    ans = (a * (long long)(b * 100.0 + 0.001)) / 100;
    
    cout << ans << endl;
}

Measured memory_bytes: 3688
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int a, b, d;

bool cmp(int ax, int ay, int bx, int by){
  if(ax+ay != bx+by) return ax+ay < bx+by;
  return a*ax+b*ay < a*bx+b*by;
}

int main(){
  while(scanf("%d%d%d", &a, &b, &d) && a+b+d){
    int resx = (INF)/2, resy = (INF)/2, r, l, y;
    rep(x, 50000){
      r = a*x + d;
      //      printf("%d\n", r);
      if(!(r%b)){
	y = r/b;
	if(cmp(x,y,resx,resy)) resx = x, resy = y;
      }
      l = a*x - d;
      if(l >= 0 && !(l%b)){
	y = l/b;
	if(cmp(x,y,resx,resy)) resx = x, resy = y;
      }
      l = d - a*x;
      if(l >= 0 && !(l%b)){
	y = l/b;
	if(cmp(x,y,resx,resy)) resx = x, resy = y;
      }
    }

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

Measured memory_bytes: 1188
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <array>
#include <bitset>

using namespace std;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REPM(i,n,a) for(int i = ((n) - 1); i >= (a); --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
#define FLOAT setprecision(16)
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

template <class T, class U>
istream& operator >> (istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }

#if 1
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

int N;
vector<int> G[100000];
int F[100000], S[100000];
bool used[100000];

void bfs(int i, int* a) {
	Fill(used, false);
	queue<PP> Q;
	Q.push(PP(i, 0));
	while (!Q.empty()) {
		PP p = Q.front(); Q.pop();
		int from = p.first;
		int d = p.second;
		if (used[from]) continue;
		used[from] = true;
		a[from] = d;
		for (int to : G[from]) {
			Q.push(PP(to, d + 1));
		}
	}
}

int main() {
	cin >> N;
	REP(i, 0, N - 1) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	bfs(0, F);
	bfs(N - 1, S);
	int f = 0, s = 0;
	REP(i, 0, N) {
		++(F[i] <= S[i] ? f : s);
	}
	cout << (f > s ? "Fennec" : "Snuke") << endl;
	return 0;
}

Measured memory_bytes: 7388
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define co(x) cout << (x) << "\n"
#define pb push_back
#define Never
#define To

using namespace std;

int main(){

	cin.tie(0);
	ios::sync_with_stdio(false);

	long long N, K, Q;

	cin >> N >> K >> Q;

	long long A[N];
	
	for(long long ll = 0; ll < N; ll++){
		A[ll] = K - Q;
	}

	for(long long ll = 0; ll < Q; ll++){
		long long q;
		cin >> q;
		A[q-1]++;
	}

	for(long long ll = 0; ll < N; ll++){
		if(A[ll] > 0){
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}

	Never To return 0;
}


Measured memory_bytes: 1408
#include <iostream>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i = 0; i < n; i++)
int memo[100010];

int main(void)
{
    int s, i = 1;
    REP(ii, 100000) memo[ii] = 0;
    cin >> s;
    while(1) {
        if(memo[s] == 1) {

            cout << i << endl;
            return 0;
        }
        memo[s] ++;
        if(s%2==0) {
            s=s/2;
        } else {
            s = 3 * s + 1;
        }
        i++;
    }
}


Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int,int>;
using psi = pair<string,int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define repdown(i,n) for(in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

int main() {
  kyun;
  int a,b;
  cin >> a >> b;
  cout << max(a+b,max(a-b,a*b));
  hinata;
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    vi table(101000, 0);
    vi funami(101000, 0);
    int cnt = 0;
    Rep(i, 101000) {
        cnt += i;
        if (cnt >= table.size()) break;
        table[cnt] = 1;
        funami[cnt] = i;
//        cout << cnt << endl;
    }

    Int(n);
    if (!table[n]) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
        int k = funami[n]+1;
        cout << k << endl;
        int sum = 1;
        vi yui;
        rep(i, k) {
            int tmp = sum;
            cout << k-1 << " ";
            rep(j, (k-1)-i) {
                cout << sum++ << " ";
            }
            rep(j, yui.size()) {
                cout << yui[j]++ << " ";
            }
            cout << endl;
            yui.pb(tmp);
        }
    }

    return 0;
}


Measured memory_bytes: 2944
package main

import (
	"fmt"
)

func main() {
	var word string
	fmt.Scan(&word)
	palindromeHugger(word)
}

func palindromeHugger(word string) int {
	incidences := 0
	wordLenght := len(word) - 1

	for _, letter := range word {
		if letter != rune(word[wordLenght]) {
			incidences++
		}
		wordLenght--
	}

	fmt.Println(incidences / 2)
	return incidences / 2
}


Measured memory_bytes: 1772
while True:
    a,op,b=(input().split())
    if op=='?':
       break
    a=(int(a))
    b=(int(b))
    if op=='+':
        print((a+b))
    elif op=='-':
        print(a-b)
    elif op=='*':
        print(a*b)
    elif op=='/':
        print (int(a/b))


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  for(int i=0; i<3; i++){
    if(s[i]=='1'){
      s[i]='9';
    }
    else s[i]='1';
  }
  cout<<s<<endl;
}

Measured memory_bytes: 256
import sys
p,t='+X'
for e in sys.stdin:
 for i in'0123456789'[(e[0]==t)*(e[1]!=p)or('+X'in e)*('+X='not in e):]:
  l,r=e.replace(t,i).split('=')
  if sum(map(int,l.split(p)))==int(r):print(i);break
 else:print('NA')


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

int main() {
	
	int n;
	cin >> n;
	vector<int> p(n), q(n);
	rep(i, n) cin >> p[i];
	rep(i, n) cin >> q[i];
	int ans = 0;
	if(p > q) swap(p, q);
	do{
		// rep(i, n) cout << p[i] << " ";
		// cout << endl;
		if(p == q) break;
		ans++;
    }while(next_permutation(p.begin(), p.end()));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define repd(i,x,y) for(int i=x; i>=y; --i)

using namespace std;
typedef long long LL;
LL n;
int ans[1000],cnt[1000],tot;

int main()
{
	scanf("%lld",&n),++n;
	while(n)
	{
		cnt[++*cnt]=n&1;
		n>>=1;
	}
	int l=100,r=99;
	ans[++r]=++tot;
	repd(i,*cnt-1,1)
	{
		if(cnt[i]) ans[--l]=++tot;
		if(i>1) ans[++r]=++tot;
	}
	printf("%d\n",tot*2);
	rep(i,l,r) printf("%d ",ans[i]);
	rep(i,1,tot) printf("%d ",i);
	puts("");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int d[200];

bool isOnlyStartAndEndOdd(){
    if(d[0] % 2 != 1 || d[1] % 2 != 1){return false;}
    FOR(i, 2, 200){
        if(d[i] % 2 != 0){return false;}
    }
    return true;
}

int main(){
    int s, t;
    while(std::cin >> s >> t, !std::cin.eof()){
        if(!s && !t){
            if(isOnlyStartAndEndOdd()){
                puts("OK");
            }else{
                puts("NG");
            }
            std::fill(d, d+200, 0);
        }
        
        s -= 1; t -= 1;

        d[s] += 1;
        d[t] += 1;
    }
}

Measured memory_bytes: 1116
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

def swap(l):
    cnt = 0
    for i in range(n):
        for j in range(i,n):
            if l[i]>l[j]:
                cnt += 1
    return cnt
n = inp()
a = inpl()
b = inpl()
card = []
res = INF
for i in range(n):
    card.append([a[i],b[i],i])
for flag in itertools.combinations(range(n),(n+1)//2):
    f = True
    odd_li = []
    odd_ind = [False] * n
    for i,bit in enumerate(flag):
        c = 1 if bit%2 else 0
        odd_li.append([card[bit][c],bit])
        odd_ind[bit] = True
    if not f:
        continue
    odd_li.sort()
    even_li = []
    for i in range(n):
        c = 0 if i%2 else 1
        if not odd_ind[i]:
            even_li.append([card[i][c],i])
    even_li.sort()
    if n%2:
        for i in range(n//2):
            if odd_li[i][0] <= even_li[i][0] <= odd_li[i+1][0]:
                continue
            else:
                f = False; break
    else:
        for i in range(n//2):
            if i != n//2-1:
                if odd_li[i][0] <= even_li[i][0] <= odd_li[i+1][0]:
                    continue
                else:
                    f = False; break
            else:
                if odd_li[-1][0] <= even_li[-1][0]:
                    continue
                else:
                    f = False; break
    if f:
        after_ind = []
        for i in range(n//2):
            after_ind.append(odd_li[i][1])
            after_ind.append(even_li[i][1])
        if n%2:
            after_ind.append(odd_li[-1][1])
        res = min(res,swap(after_ind))
print(-1 if res == INF else res)

Measured memory_bytes: 80988
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define reps(i, n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define repi(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main(){
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    cout<<(k%2==0 ? a-b : b-a)<<endl;
}


Measured memory_bytes: 256
# MOD下での階乗とその逆元を求める関数
# O(nlogn + n) ?
def prepare(n):
    global mod
    modFacts = [0] * (n + 1)
    modFacts[0] = 1
    for i in range(n):
        modFacts[i + 1] = (modFacts[i] * (i + 1)) % mod

    invs = [1] * (n + 1)
    invs[n] = pow(modFacts[n], mod - 2, mod)
    for i in range(n, 1, -1):
        invs[i - 1] = (invs[i] * i) % mod

    return modFacts, invs

n,m = map(int,input().split())
mod = 10**9+7
modFacts,invs = prepare(m)
ans = 0
nci = 0
for i in range(n+1):
    nci = (modFacts[n]*invs[n-i]*invs[i]) % mod
    mpi = (modFacts[m]*invs[m-i]) % mod
    mipni = (modFacts[m-i]*invs[m-n]) % mod
    ans += ((nci * mpi * mipni**2) % mod )* (-1)**i
    ans %= mod
    # print(i,nci,mpi,mipni)
print(ans)


Measured memory_bytes: 48316
/*
 * src.cpp
 *
 *  Created on: 2016/07/31
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){
	ll a,b;
	cin>>a>>b;
	if (a>0){
		cout<<"Positive"<<endl;
	}else{
		if (a==0 || b>=0){
			cout<<"Zero"<<endl;
		}else{
			if ((b-a)%2==0){
				cout<<"Negative"<<endl;
			}else{
				cout<<"Positive"<<endl;
			}
		}
	}
	return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
  int a,b,n,x,i;
 
  for(;;){
    i=0;
    scanf("%d%d",&n,&x);
    if(n+x == 0) break;
 
    for(a=1;a<=n;a++)
      for(b=a+1;b<=n;b++)
        if(b < x-a-b && x-a-b <= n)
          i++;
 
    printf("%d\n", i);
  }
 
  return 0;
}


Measured memory_bytes: 2108
#include <iostream>
using namespace std;
int main(void){
    int n,a,c[100],m=0,l;
    cin>>n;
    fill(c, c+n, 0);
    for(int i=0;i<n;i++){
        cin>>a;
        c[a]++;
        m=max(m, a);
    }
    if(n==2){
        cout<<"Possible"<<endl;
        return 0;
    }
    l=(m+1)/2;
    for(int i=m;i>0;i--){
        int d=c[i];
        if(m==n-1){
            if(d>2||(i>l&&d!=2)||(i==l&&d==0)||(i<l&&d!=0)){
                cout<<"Impossible"<<endl;
                return 0;
            }
        }else{
            if((i>l&&d<2)||(i==l&&d!=1+m%2)||(i<l&&d!=0)){
                cout<<"Impossible"<<endl;
                return 0;
            }
        }
    }
    cout << "Possible" << endl;
}


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

	int n,w;
	cin >> n >> w;

	vector <int> W (n,0);
	vector <int> V (n,0);

	for (int i=0; i<n; i++){

		cin >> W[i] >> V[i];
	}

	vector <vector <long long>> dp (n, vector <long long> (w+1, 0));

	dp[0][0]=0;

	for (int i=W[0]; i<=w; i++) dp[0][i]=V[0];

	for (int i=1; i<n; i++){

		for (int k=0; k<=w; k++){

			dp[i][k] = dp[i-1][k];

			if (k-W[i] > 0) dp[i][k]=max(dp[i][k], V[i]+dp[i-1][k-W[i]]);
		
			//cout << dp[i][k] << " ";
		}

		//cout << endl;
	}

	cout << dp[n-1][w] << endl;
 
	return 0;
}

Measured memory_bytes: 79360
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]", B: "List[int]"):
    tmp = []
    for i in range(N):
        tmp.append([A[i], B[i], A[i] + B[i]])
    tmp.sort(reverse=True, key=lambda x: x[2])
    ret = 0
    for i in range(N):
        t = tmp[i][0] if i % 2 == 0 else -tmp[i][1]
        ret += t
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]" 
    B = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 26004
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/

#define MAX_V 200000

vector<pair<ll, ll>> G[MAX_V];

// ダイクストラ法
vector<vector<ll>> dijkstra(ll start) {
	vector<vector<ll>> dist(MAX_V, vector<ll>(3,infll));
	dist[start][0] = 0; // dist[i] := start->iまでの最短距離
	priority_queue < pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>, greater<pair<ll, pair<ll, ll>>>> que;
	que.push({ 0, {start, 0} });
	while (!que.empty()) {
		ll cost, u; // 今までにかかった時間　現在の頂点
		cost = que.top().first, u = que.top().second.first;
		ll d = que.top().second.second;
		que.pop();
		if (dist[u][d] < cost) continue;
		for (auto tmp : G[u]) {
			ll v = tmp.first; // 隣接する頂点、その頂点まで行く時間

			if (dist[v][(d + 1) % 3] > dist[u][d] + 1) {
				dist[v][(d + 1) % 3] = dist[u][d] + 1;
				que.push({ dist[v][(d + 1) % 3], make_pair(v, (d + 1) % 3)});
			}
		}
	}
	return dist;
}

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

	int n, m;
	cin >> n >> m;
	rep(i, m) {
		int u, v;
		cin >> u >> v;
		G[u - 1].push_back({ v - 1, infll });
	}
	int s, t;
	cin >> s >> t;

	// 3回連続ってのが肝

	// 各頂点に何歩残しでいけるか
	// 拡張ダイクストラ
	// dikstra[i][j] j = 0,1,2 j歩で着いた時の最短距離

	auto dist = dijkstra(s - 1);
	//ll ans = 0;
	ll ans = dist[t - 1][0];

	if (ans == infll) cout << -1 << endl;
	else cout << ans / 3 << endl;

	return 0;
}


Measured memory_bytes: 21120
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;

int main()
{
	IO;
	ll n;
	cin>>n;
	ll cnt=n/500;
	n-=cnt*500;
	ll ans=cnt*1000+n/5*5;
	cout<<ans<<endl;
 	return 0;
}







Measured memory_bytes: 256