akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <stack>
using namespace std;
#define ll long long
#define maxn 105
#define angel 0x3f3f3f3f
#define eps 1e-9
#define my_angel main
#define ull unsigned long long
const ull mod=212370440130137957ll;
const int maxnode = 1000 * 100 + 10;
const int sigma_size = 28;
const ull base=1e9+7;
int occur[maxn*maxn];
int num[maxn];
int my_angel()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&num[i]),occur[num[i]]=1;
    int ans=0,now=1;
    for(int i=1;i<n;i++)
    {
        if(num[i]==num[i+1])
        {
            int key;
            while(now<=10000)
            {
                if(occur[now]==0)
                {
                    occur[now]=1;
                    key=now;
                    now++;
                    break;
                }
                now++;
            }
            ans++;
            num[i+1]=now;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

m = 1000000000
s = 0
f = 0

for i in range(N):
    if A[i] < 0:
        f += 1
    if m > abs(A[i]):
        m = abs(A[i])
    s += abs(A[i])
if f % 2 == 0:
    print(s)
else:
    print(s - m * 2)



Measured memory_bytes: 14412
n = int(input())
p = list(map(int, input().split()))

count = 0
for i in range(1, n-1):
    if p[i] != max([p[i-1], p[i], p[i+1]]) and p[i] != min([p[i-1], p[i], p[i+1]]):
        count += 1

print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

int keta(ll n){
    int cnt = 0;
    while(n >= 10){
        cnt++;
        n = n / 10;
    }
    return cnt;
}

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

    set<ll> s;
    for(int i=1; i<=sqrt(N); i++){
        if(N % i != 0) continue;
        s.insert(i);
    }

    ll b = *(--s.end());
    int tb = keta(b);

    ll a = N / b;
    int ta = keta(a);

    cout << max(ta, tb)+1 << endl;

    return 0;
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int N, L;
  cin >> N >> L;
  vector <int> taste(N);
  for(int i=0; i<N; i++) taste[i] = L + i;
  long long sum = 0;
  for(int i=0; i<N; i++) sum += taste[i];
  int diff = 1e9;
  for(int i=0; i<N; i++) {
    if(abs(taste[i]) < abs(diff)) diff = taste[i];
  }
  cout << sum - diff << "\n";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define F(i,a,n) for(int i=a; i<n; i++)

int main(){
    int tmp,min=100,max=0;
    F(i,0,3){
        scanf("%d",&tmp);
        if(max<tmp) max=tmp;
        if(min>tmp) min=tmp;
    }
    printf("%d\n",max-min);
    return 0;
}

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

using namespace std;

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

  int n, m, obs1, obs2, num_good = 0;
  cin >> n >> m;

  vector<pair<int, bool>> obs(n, pair<int, bool>(0, true));

  for (int i = 0; i < n; i++)
    cin >> obs[i].first;

  for (int i = 0; i < m; i++) {
    cin >> obs1 >> obs2;
    obs1--;
    obs2--;
    if (obs[obs1].first > obs[obs2].first) {
      obs[obs2].second = false;
    } else if (obs[obs1].first < obs[obs2].first) {
      obs[obs1].second = false;
    } else {
      obs[obs1].second = false;
      obs[obs2].second = false;
    }
  }

  for (int i = 0; i < n; i++)
    if (obs[i].second == true)
      num_good++;

  cout << num_good << endl;

  return EXIT_SUCCESS;
}

Measured memory_bytes: 3992
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
const int INF = 1 << 25;

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

	int n, m, query;
	while (cin >> n >> m , n) {
		int cost[101][101], time[101][101];
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < m; j++) {
				cost[i][j] = (i == j) ? 0 : INF;
				time[i][j] = (i == j) ? 0 : INF;
			}
		}

		while (n--) {
			int a, b, c, t;
			cin >> a >> b >> c >> t;
			cost[a - 1][b - 1] = cost[b - 1][a - 1] = c;
			time[a - 1][b - 1] = time[b - 1][a - 1] = t;
		}

		for (int k = 0; k < m; k++) {
			for (int i = 0; i < m; i++) {
				for (int j = 0; j < m; j++) {
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
					time[i][j] = min(time[i][j], time[i][k] + time[k][j]);
				}
			}
		}

		cin >> query;
		while (query--) {
			int p, q, r;
			cin >> p >> q >> r;
			if (r == 0) {
				cout << cost[p - 1][q - 1] << endl;
			}
			else {
				cout << time[p - 1][q - 1] << endl;
			}
		}
	}
}

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

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

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int n; cin>>n;
    vector<ll> a(n);
    ll amax=0;
    for(int i=0; i<n; i++){
        cin>>a[i];
        amax=max(amax, a[i]);
    }
    
    ll amax2=0, num;
    for(int i=0; i<n; i++){
        if(amax2<=a[i]*(amax-a[i]) && a[i]!=amax){
            amax2=a[i]*(amax-a[i]);
            num=a[i];
        }
    }
    cout << amax << " " << num << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<map>

using namespace std;

int main(void){
	int a,n;
	while(1){
		map<int,string> str;
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++){
			int b;
			cin >> b;
			str[b].push_back('*');
		}
		for(a=0;a<=9;a++){
			if(str.size()>0)cout << str[a] << endl;
			else cout << "-" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
n,k = map(int,input().split())
h = list(map(int, input().split()))

# 無限大の値
INF = 10**10

# DP テーブル
# DP テーブル全体を初期化 (最小化問題なので INF に初期化)
dp = [INF] * n

# 初期条件
dp[0] = 0
dp[1] = abs(h[0] - h[1])

# ループ
for i in range(2,n):
    # ...
    for j in range(1,min(k,i)+1):
        hk = dp[i-j] + abs(h[i-j] - h[i])
        dp[i] = min(hk,dp[i])
    
# 解を得て出力
print(dp[n-1])

Measured memory_bytes: 84668
<?php
define("TOP",1);
define("FRONT",2);
define("RIGHT",3);
define("LEFT",4);
define("BEHIND",5);
define("BOTTOM",6);
class Dice{
    private $numbers;
    // before => after
    private $directions = [
        "E" => [TOP => RIGHT,RIGHT => BOTTOM,LEFT => TOP,BOTTOM => LEFT],
        "N" => [TOP => BEHIND,FRONT => TOP,BEHIND => BOTTOM,BOTTOM => FRONT],
        "S" => [TOP => FRONT,FRONT => BOTTOM,BEHIND => TOP,BOTTOM => BEHIND],
        "W" => [TOP => LEFT,RIGHT => TOP,LEFT => BOTTOM,BOTTOM => RIGHT],
        "Z" => [FRONT => LEFT,RIGHT => FRONT,LEFT => BEHIND,BEHIND => RIGHT]
    ];
    public function __construct($numbers){
        $this->numbers = $numbers;
    }
    public function roll($direction){
        $pos = $this->numbers;
        foreach($this->directions[$direction] as $before => $after){
            $this->numbers[$after] = $pos[$before];
        }
    }
    public function getRightNumber($top,$front){
        $cnt = 0;
        while($this->numbers[TOP] !== $top){
            if($cnt % 2) $this->roll("W");
            else $this->roll("N");
            $cnt++;
        }
        for($j = 0; $j < 4; $j++){
            if($this->numbers[FRONT] == $front){
                return $this->numbers[RIGHT];
            }
            $this->roll("Z");
        }
    }
}
$numbers = explode(" ",getStdin());
$numbers = array_combine(range(1,6),$numbers);
$q = getStdin();
$dice = new Dice($numbers);
for($i = 0; $i < $q; $i++){
    list($top,$front) = explode(" ",getStdin());
    echo $dice->getRightNumber($top,$front)."\n";
}

function getStdin(){
    return trim(fgets(STDIN));
}

Measured memory_bytes: 15564
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;

int n;
string s;

string w[4] = {"dream","dreamer","erase","eraser"};

int main()
{
    cin >> s;
    n = s.size();

    reverse(s.begin(),s.end());
    for(string& a : w)
    {
        reverse(a.begin(),a.end());
    }

    int i = 0;

    while(i < n)
    {
        bool update = false;
        for(int j = 0;j < 4;j++)
        {
            bool same = true;
            for(int k = 0;k < w[j].size() && same;k++)
            {
                if(s[i + k] != w[j][k])
                {
                    same = false;
                }
            }
            if(same)
            {
                i += w[j].size();
                update = true;
                break;
            }
        }

        if(!update)
        {
            cout << "NO";
            return 0;
        }
    }

    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <cstdio>

typedef long long LL;
const int Mod = 1000000007;
const int MN = 2005;

inline void Sub(int &x, int y) { x -= y; x += x >> 31 & Mod; }
inline void Add(int &x, int y) { Sub(x, Mod - y); }

int N, M, K, Lim;
int _f[2][MN], Ans;

int main() {
	scanf("%d%d%d", &N, &M, &K);
	Lim = (N + M - 1) / (K - 1);
	int o = 0;
	_f[o][0] = 1;
	for (int i = 1; i <= Lim; ++i) {
		int *g = _f[o], *f = _f[o ^= 1];
		for (int j = 0; j <= N; ++j) f[j] = g[j];
		for (int j = 1; j <= N; ++j) Add(f[j], f[j - 1]);
		for (int j = N; j >= K; --j) Sub(f[j], f[j - K]);
		for (int j = 0; j <= N; ++j) {
			if (i * (K - 1) - j + 1 > M) continue;
			if (j % (K - 1) != N % (K - 1)) continue;
			if ((i * (K - 1) - j + 1) % (K - 1) != M % (K - 1)) continue;
			Add(Ans, f[j]), Sub(Ans, g[j]);
		}
	}
	printf("%d\n", Ans);
	return 0;
}

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,m,root,deg[100005],vis[100005],par[100005];
vii a[100005];
vi stk;
void dfs(int node){
    vis[node]=1;
    for(auto i:a[node]){
        if(!vis[i.x]){
            dfs(i.x);
        }
    }
    stk.pb(node);
}
void solve(){
    cin>>n>>m;
    rep(i,0,n+m-1){
        int x,y;
        cin>>x>>y;
        a[x].pb({y,i});
        deg[y]++;
    }
    rep(i,1,n+1){
        if(deg[i]==0) root=i;
    }
    dfs(root);
    memset(vis,0,sizeof vis);
    rep(i,0,sz(stk)){
        for(auto j:a[stk[i]]){
            if(!vis[j.x]){
                par[j.x]=stk[i];
                vis[j.x]=1;
            }
        }
    }
    rep(i,1,n+1) cout<<par[i]<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 12664
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<ll,ll>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):0;}

    const int INF=0x3f3f3f3f;
    const int MOD=998244353;
    inline int mm(const int x){return x>=MOD?x-MOD:x;}
    inline ll qpower(ll x,ll e)
    {
        ll ans=1;
        while(e){if(e&1)ans=ans*x%MOD;x=x*x%MOD;e>>=1;}
        return ans;
    }
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e6+10;

	
	void main()
	{
		ll a=qread(),b=qread(),c=qread();
		if(a%2+b%2+c%2<3) puts("0");
		else write(min(min(a*b,a*c),b*c));
	}
};
int main()
{
//	freopen("z.txt","r",stdin); 
	srand(time(0));
	mine::main();
}

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

int digit_cnt(int N){
    int N_digit_cnt = 0;
    for(int i=1;i<=N;i++){
        string T = to_string(i);
        if(T.size()%2==1){
            N_digit_cnt++;
        }
    }
    return N_digit_cnt;
}

int main(){
    int N; cin >> N;
    cout << digit_cnt(N) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
vector<ll> v;
ll w=0,x=0,y=0,z=0;
string s;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t,n,temp,c=0;
  cin>>s;
  if(s=="ABC")
    cout<<"ARC"<<endl;
  else if(s=="ARC")
    cout<<"ABC"<<endl;
    return 0;
}

Measured memory_bytes: 3648
h, w = map(int,input().split())

squares = []
for i in range(h):
    row = list(input())
    squares.append(row)

while True:
    continue_judge = False

    for i,l in enumerate(squares): # 横を消す
        if "#" not in l:
            squares.pop(i)
            h -= 1

    for i in range(w): # 縦を消す
        delete_judge = True

        for l in squares:
            if l[i] == "#":
                delete_judge = False
                break

        if delete_judge == True:
            for l in squares:
                l.pop(i)
            w -= 1
            continue_judge = True
            break

    if continue_judge == False:
        break


for l in squares:
    for i in l:
        print(i, end = "")
    print("")

Measured memory_bytes: 4596
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        int count = 1;
        if (a != b) count++;
        if (a != c && b != c) count++;

        System.out.println(count);
    }
}


Measured memory_bytes: 21716
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    while (true) {
      int h = scanner.nextInt();
      int w = scanner.nextInt();
      int last_h = h - 1;
      int last_w = w - 1;

      if (h == 0 && w == 0) break;

      String edge = "";
      String line = "";

      for (int j = 0; j < w; j++) {
        edge += "#";
        if (j == 0 || j == last_w) {
          line += "#";
        } else {
          line += ".";
        }
      }

      for (int i = 0; i < h; i++) {
        if (i == 0 || i == last_h) {
          System.out.println(edge);
        } else {
          System.out.println(line);
        }
      }
      System.out.println();
    }

    scanner.close();
  }
}

Measured memory_bytes: 21236
import sys

K = int(raw_input())
A = [int(val) for val in raw_input().split(" ")]

if A[-1] > 2:
    print "-1"
    sys.exit()

MIN, MAX = 2, 2
for k in range(1, K)[::-1]:
    if MIN%A[k-1]==0:
        pass
    else:
        MIN = (MIN/A[k-1]+1)*A[k-1]
    MAX_ = MAX + A[k] - 1
    if MAX_%A[k-1]==0:
        MAX = MAX_
    else:
        MAX = (MAX_/A[k-1])*A[k-1]
    if MIN > MAX:
        print "-1"
        sys.exit()
MAX = MAX + A[0] - 1

print "%d %d"%(MIN, MAX)

Measured memory_bytes: 11868
s = input()
q = int(input())
for _ in range(q):
    data = input().split()
    method = data[0]
    a, b = map(int, data[1:3])
    if method == 'print':
        print(s[a:b + 1])
        continue
    if method == 'reverse':
        p = s[a:b + 1]
        p = p[::-1]
    elif method == 'replace':
        p = data[3]
    s = s[:a] + p + s[b + 1:]


Measured memory_bytes: 5608
# n,m = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(sys.stdin.readline() for _ in range(n)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# n = int(sys.stdin.readline())
# INF = float("inf")
import sys,collections
N,E = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
#sdw = [[src1 dist1 d1][src1 dist1 d1]...]# vect source1 -> distance1 distances
INF = float("inf")
ALL = set(range(N))

distances = [[INF]*N for _ in range(N)]
for i in range(N):
  distances[i][i] = 0

for i in range(E):
  s,d,w = (map(int,sys.stdin.readline().rstrip().split()))
  distances[s][d] = w

#print(distances)
def warshallFloyd():
  for k in range(N):
    for i in range(N):
      for j in range(N):
        distances[i][j] = min(distances[i][j], distances[i][k] + distances[k][j])

warshallFloyd()

for i in range(N):
  if distances[i][i] < 0:
    print("NEGATIVE CYCLE")
    exit()

for i in range(N):
  s = []
  for j in range(N):
    if distances[i][j] == INF:
      s.append("INF")
    else:
      s.append(str(distances[i][j]))
  print(" ".join(s))


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

int main(){
    int a[3];
    int b=0,c=0;
    for(int i=0;i<3;i++){
        cin>>a[i];
        if(a[i]==5) b++;
        if(a[i]==7) c++;
    } 
    if(b==2 && c==1) cout<<"YES";
    else cout<<"NO";
    
return 0;
}

Measured memory_bytes: 3608
#include <iostream>

using namespace std;

int main ()
{
  ios :: sync_with_stdio (false);
  cin.tie (NULL);
  cout.tie (NULL);
  
  int n;
  cin >> n;
  
  long double s = 0;
  for (long double x; n; --n)
  {
    cin >> x;
    s += 1 / x;
  }
  
  cout << 1 / s;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p=p*a%mod;a=a*a%mod;n>>=1;}return p;}



int main()
{
        ll N;
        cin >> N;
        vll A(N);
        rep(i, 0, N) cin >> A[i];
        map<ll, ll> mp;
        rep(i, 0, N) mp[A[i]]++;

        if (N & 1) {
                for (int i = 0; i < N; i += 2) {
                        if (i == 0 and ! (mp[0] == 1))  {
                                cout << 0 << endl;
                                return 0;
                        }
                        if(i != 0 and ! (mp[i] == 2)) {
                                cout << 0 << endl;
                                return 0;
                        }
                } 
                cout << intpow(2, len(mp)-1);
        } else {
                for (int i = 1; i < N; i += 2) {
                        if (i == 1 and ! (mp[1] == 2)) {
                                cout << 0 << endl;
                                return 0;
                        }
                        if (i != 0 and ! (mp[i] == 2)) {
                                cout << 0 << endl;
                                return 0;
                        }
                }
                cout << intpow(2, len(mp));
        }
}

Measured memory_bytes: 4992
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    n: usize,
    csf:[(usize, usize, usize); n - 1]
    }
    for i in 0..n {
        let mut ans = 0;
        for j in i..n - 1 {
            let (c, s, f) = csf[j];
            if ans <= s {
                ans = s;
            }
            ans += (f - ans % f) % f + c;
        }
        println!("{}", ans);
    }
}


Measured memory_bytes: 2116
#include <iostream>
#include <algorithm>
 using namespace std;
 int X, Y, S;
 
 int tax(int A, int a) {
	 return  a * (100 + A)/100;
 }
 
 int solve() {
	 int maximum = 0;
	 for (int i = 1; i < S; ++i) {
	   for (int j = i; j < S; ++j) {
	    if (tax(X, i) + tax(X, j) == S) {
		 maximum = max(maximum, tax(Y, i) + tax(Y, j));
	    }
       }
     }
	 return maximum;
 } 
 int main() { 
	 while (cin >> X >> Y >> S && X>0) {
		 cout << solve() << endl; 
		 }
	 
	 }



Measured memory_bytes: 3076
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
//ll a[Max];
ll n;
void solve(){
	int a,b,c;
	cin>>a>>b;
	rep(i,1,4){
		if(i!=a&&i!=b){
			cout<<i;
			return ;
		}
	}
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





Measured memory_bytes: 256
h,n = map(int,input().split())
A,B = [0],[0]
for i in range(n):
  a,b = map(int,input().split())
  A.append(a)
  B.append(b)
dp = [0]+[float('inf')]*(h)
for j in range(1,h+1):
  for i in range(1,n+1):
    dp[j] = min(dp[j],dp[max(0,j-A[i])]+B[i])
print(dp[-1])

Measured memory_bytes: 42476
#include<stdio.h>
int main(void)
{
    int A, B, T, H, K, D;
    scanf("%d%d", &A, &B);

    T = A + B;
    H = A - B;
    K = A * B;

    if((T >= H) && (T >= K))
      D = T;
    else if((H >= T) && (H >= K))
      D = H;
    else if((K >= T) && (K >= H))
      D = K;
    printf("%d\n", D);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
int n,m,T,dp[3001],a[3001],b[3001],ans;
int main(){
    cin>>n>>m>>T;
    r(i,n)cin>>b[i]>>a[i];
    r(i,n){for(int j=m-a[i];j>=0;j--)
        if(T<=j||j+a[i]<=T)dp[j+a[i]]=max(dp[j+a[i]],dp[j]+b[i]);
        r(i,m)dp[i+1]=max(dp[i+1],dp[i]);
    }
    r(i,m+1)ans=max(ans,dp[i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;

typedef pair<int, int> P;

int main() {
	int h, w, k;
	cin >> h >> w >> k;

	vector< vector<int> > mp(h, vector<int>(w, 0));
	vector< vector<int> > d3(h, vector<int>(w, -1));

	char c;

	P p;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> c;
			if (c == '#') {
				mp[i][j] = 1;
			}
			else if (c == 'S') {
				mp[i][j] = 0;
				p.first = i;
				p.second = j;
			}
			else {
				mp[i][j] = 0;
			}
		}
	}
	
	queue<P> qq;
	qq.push(p);
	d3[p.first][p.second] = 0;

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

	vector<P> d4;
	d4.push_back(p);

	for (int i = 0; i < k; i++) {
		queue<P> q3;
		while (!qq.empty()) {
			P rr = qq.front();
			int y = rr.first;
			int x = rr.second;
			qq.pop();
			for (int j = 0; j < 4; j++) {
				if (0 <= y + dy[j] && y + dy[j] < h && 0 <= x + dx[j] && x + dx[j] < w && mp[y + dy[j]][x + dx[j]] == 0 && d3[y + dy[j]][x + dx[j]] == -1) {
					d3[y + dy[j]][x + dx[j]] = 0;
					q3.push(P(y + dy[j], x + dx[j]));
					d4.push_back(P(y + dy[j], x + dx[j]));
				}
			}
		}
		qq = q3;
	}

	int ans = 10000;
	for (int i = 0; i < d4.size(); i++) {
		int dist = min(d4[i].first, min(h - d4[i].first - 1, min(d4[i].second, w - d4[i].second-1)));
		if (dist == 0) {
			ans = 1;
		}
		else {
			int aa = dist / k;
			if (dist % k != 0) {
				aa++;
			}
			aa++;
			ans = min(ans, aa);
		}
	}

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

Measured memory_bytes: 14708
#include <iostream>
#include <string>
#include <bitset>
#include <vector>

using namespace std;
int main(void)
{
    string S;
    cin >> S;
    unsigned long long ans = 0;
    unsigned long long term;
    int n = S.size() - 1;
    int bit, i;
    vector<int> num(S.size());
    for (i = 0; i <= n; i++) num[i] = S[i] - '0';
    for(bit = (1 << n) - 1; bit >= 0; bit--)
    {
        term = num[0];
        for (i = 1; i <= n; i++)
        {
            if (bit & (1 << (i - 1)))
            {
                ans += term;
                term = num[i];
            }
            else term = (term * 10 + num[i]);
        }
        ans += term;
    }
    cout << ans << endl;
    return 0;
}

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

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

  int answer;
  for (answer = 1; answer < 20; answer++) {
    if ((D * 2 + 1) * answer >= N) {
      break;
    }
  }

  cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 0x3f3f3f
#define PB push_back
#define F first
#define S second
#define FOR(i,k) for(int i=0; i<k; i++)
#define RFOR(i,k) for(int i=k; i>=0; i--)
#define ALL(x) x.begin(), x.end()
#define INS(x) inserter(x, x.begin())
#define DEB(x) cout<<#x<<": "<<(x)<<endl
#define DEBV(x) cout<<#x<<": "; for(auto &d:x) cout<<d<<" "; cout<<endl
#define DEBM(x) for(auto &p:x) cout<<p.F<<":"<<p.S<<" "; cout<<endl;
#define OUT(x) cout<<(x)<<endl

using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VPII;
typedef vector<VI> VVI;
typedef map<char,int> MC;
typedef map<int,int> MI;
typedef map<string,int> MS;

template<typename T, typename U> void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> void amax(T &x, U y) { if(x < y) x = y; }

VPII neighbors = {{0,1}, {1,0}, {0,-1}, {-1,0}};
PII operator+(PII &l, PII &r) { return {l.F+r.F, l.S+r.S}; }
bool IsValid(PII p, int Y, int X) { return p.F >=0 && p.F < Y && p.S >=0 && p.S 
< X; }
bool IsPrime(int n) { if (n <= 1)  return false; if (n <= 3)  return true; if (n
%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || 
n%(i+2) == 0) return false; return true; }

int main() {
  int n;
  cin>>n;
  
  while(n--) {
    ll a,b;
    cin>>a>>b;
    if(a > b)
      swap(a,b);

    if(a==b)
      OUT(2*a-2);
    else {
      ll c = sqrt(a*b);
      if(c*c==a*b) c--;
      if(c*(c+1) >= a*b)
	OUT(2*c-2);
      else
	OUT(2*c-1);
    }
    
  }
}

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

int main(void) {
	long long n, m, log5n;

	cin >> n;
	if (n % 2 == 1) {
		cout << 0;
		return 0;
	}
	log5n = 0;
	for(m = 5; m <= n; m *= 5)
		log5n++;
	long long s = 0;
	m = 5;
	for(long long i = 0; i < log5n; i++) {
		s += n / m;
		s -= (n / m + 1)/2;
		m *= 5;
	}
	cout << s;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>

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

using namespace std;

inline int max(int a, int b) {
	if (b > a) swap(a, b);
	return a;
}

inline int min(int a, int b) {
	if (a > b) swap(a, b);
	return a;
}




int main() {
	int n, a ,b;
	cin >> n >> a >> b;
	cout << min(n * a, b) << endl;

	return 0;
}

Measured memory_bytes: 256
#coding: utf-8
a = input()

b = []
w = []
for i in range(len(a)):
    b.append(a[i])

for i in  range(len(a)):
    if (b[i] == 'W') :
        w.append(i)

n = 0
for i in range(len(w)):
    n += w[i] - i

print(n)


Measured memory_bytes: 13032
#include <iostream>
#include <vector>

using namespace std;

int pow(int x, int y){
    if(y == 0) return 1;
    int a = x;
    for(int i=1;i<y;++i){
        x *= a;
    }
    return x;
}

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

    int num;
    int i;
    for(i=0;i<(1 << 3);++i){
        num = (value / (pow(10, 3))) % 10;
        for(int j=0;j<3;++j){
            if((i >> j) & 1) {
                num += (value / (pow(10, (2-j)))) % 10;
            }
            else{
                num -= (value / (pow(10, (2-j)))) % 10;
            }
        }
        if(num == 7) break;
    }

    for(int j=0;j<3;++j){
        cout << (value / (pow(10, (3-j)))) % 10;
        if((i >> j) & 1) cout << "+";
        else cout << "-";
    }
    cout << value % 10 << "=7" << endl;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define endl "\n"
# define int unsigned long long
using namespace std;

void solve() {

	int n;
	cin >> n;

	vector <int> arr(n);
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}

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

	if (arr[0] == 0) {
		cout << 0 << endl;
		return;
	}

	int ans = 1;
	int Max = 1e18;
	for (int i = 0; i < n; i++) {

		ans *= arr[i];
		if (ans > Max || ans <= 0) {
			cout << -1 << endl;
			return;
		}

	}
	cout << ans << endl;
	return;


}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
# ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
# endif
	// int t;
	// cin >> t;
	// while (t--)
	solve();
	return 0;
}

Measured memory_bytes: 3992
def divisor(i):
    s = []
    for j in range(1, int(i ** (1 / 2)) + 1):
        if i % j == 0:
            s.append(i // j)
            s.append(j)
    return sorted(set(s))

n = int(input())
s = divisor(n)
ans = 0
for i in s:
    if n > i * (i + 1):
        ans += n // i - 1
print(ans)

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

int main() {
	int N;
	cin >> N;
	int ans=0, count;

	for(int i=1; i<=N; i+=2){
	    count=0;
	    for(int j=1; j<=N; j+=2){
		if(i%j==0)
		    count++;
	    }
	    if(count==8)
		ans++;	    
	}
	cout << ans << endl;
}



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

int main() {
  	int A, B, tapkosuu;
  	int ans=0;	
  
  	cin >> A >> B;
  	if(B==1){
    	ans=0;
    }else{
      tapkosuu=A;
      ans++;
      while(B>tapkosuu){
      	tapkosuu += (A - 1);
        ans++;
      }
    }
  
  	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long N,W;
    cin >> N >> W;
    vector<long long> weight(N+1);
    vector<long long> value(N+1);
    weight.at(0) = 0;
    value.at(0) = 0;
    for (int i = 1; i < N + 1; i++){
        cin >> weight.at(i) >> value.at(i);
    }
    vector<vector<long long>> dp(N + 1, vector<long long> (100001, 1000000000000));
    for (int i = 0; i < N + 1; i++){
        dp.at(i).at(0) = 0;
    }
    for (int i = 1; i < N + 1; i++){
        for(int v = 0; v < 100001; v++){
            if( value.at(i) > v ){
                dp.at(i).at(v) = dp.at(i-1).at(v);
            }
            else {
                if (dp.at(i-1).at(v) >= dp.at(i-1).at( v - value.at(i) ) + weight.at(i) ){
                    dp.at(i).at(v) = dp.at(i-1).at( v - value.at(i) ) + weight.at(i);
                }
                else {
                    dp.at(i).at(v) = dp.at(i-1).at(v);
                }
            }
        }
    }
    for (int v = 100000; v >= 0; v -= 1){
        if ( dp.at(N).at(v) <= W ){
            printf("%lld\n", v);
            break;
        }
    }
    
}


Measured memory_bytes: 80256
/*#include<bits/stdc++.h>
using namespace std;
set<int>G[100000];
int main(){
	int n,m;
	cin>>n>>m;
	if(m%2!=0){
		cout<<-1<<endl;
		return 0;
	}
	*/
	#include<bits/stdc++.h>
	using namespace std;
	int main(){
		int n,a[100000];
		bool f=true;
		cin>>n;
		for(int i=0;i<n;i++){
			cin>>a[i];
			f&=a[i]==0;
		}
		if(n%3!=0){
			cout<<(f?"Yes":"No")<<endl;
			return 0;
		}
		sort(a,a+n);
		f=true;
		for(int i=0;i<3;i++)
			for(int j=0;j<n/3;j++)
				f&=a[n/3*i]==a[n/3*i+j];
		cout<<(f&&(a[0]^a[n/3])==a[n/3*2]?"Yes":"No")<<endl;
	}

//}


Measured memory_bytes: 640
s=input()
n=len(s)-1
tot=0

for i in range(2**n):
    tmp=0
    for j in range(n):
        if ((i << j) & 2**(n-1)):  #上位からbit全探索
            tot+=int(s[tmp:j+1])
            tmp=j+1
        if j==n-1:
            tot+=int(s[tmp:])
if n==0:
    tot=int(s)
print(tot)

Measured memory_bytes: 3060
#include <iostream>

int main() {
  while (1) {
    int x,y;

    std::cin >> x >> y;

    if (x == 0 && y == 0) break;

    if (x < y || x == y) {
      std::cout << x << " " << y << '\n';
    } else {
      std::cout << y << " " << x << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 2992
#include<stdio.h>
#define MAX 10000
int n;
int primes[MAX];
int isPrime(int m){
	int i;
	if(m<=1 || m!=2&&m%2==0)return 0;
	for(i=3;i*i<=m;i+=2){
		if(m%i==0)return 0;
	}
	return 1;
}

int main(){
	int i,j;
	int num, sum,ans;
	int head,tail;
	n=0;
	for(i=2;i<=MAX;i++){
		if(isPrime(i))primes[n++]=i;
	}
	while(scanf("%d",&num)==1&&num){
		ans=0;
		head=0;
		tail=0;
		sum=0;
		while(tail<n){
			while(sum < num && tail<n)sum += primes[tail++];
			while(num < sum && head<tail)sum -= primes[head++];
			if(num < sum)break;
			if(sum==num){
				ans++;
				sum -= primes[head++];
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) {
		ConsoleScanner cin = new ConsoleScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(ConsoleScanner cin, PrintWriter cout) {
		int n = cin.nextInt();
		int k = cin.nextInt();

		int[] a = new int[n];
		for (int i = 0; i < a.length; i++)
			a[i] = cin.nextInt();

		boolean ans = possible(n, k, a);
		if (ans)
			cout.println("POSSIBLE");
		else
			cout.println("IMPOSSIBLE");
	}

	private static boolean possible(int n, int k, int[] a) {
		int gcd = a[0];
		int m = 0;
		for (int aa : a) {
			gcd = gcd(aa, gcd);
			m = Math.max(m, aa);
		}
		boolean ans = true;
		ans &= k <= m;
		ans &= k % gcd == 0;
		return ans;
	}

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

	static class ConsoleScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			try {
				while (!st.hasMoreElements())
					st = new StringTokenizer(br.readLine());
				return st.nextToken();
			} catch (IOException e) {
				throw new AssertionError(e);
			}
		}

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

}


Measured memory_bytes: 35868
#include<bits/stdc++.h>
using namespace std;
int n;
long long k,cl,cr,cm,l,r,m,tot,a[2000100],INF=1e9+1;
long long Get(){
	for(int i=0;i<n;i++){
		if(a[i]<0){
			l=-1,r=n;
			while(l+1<r){
				m=(l+r)/2LL;
				if(a[i]*a[m]<cm) r=m;
				else l=m;
			}
			tot+=(long long)(n)-r;
		}
		else{
			l=-1,r=n;
			while(l+1<r){
				m=(l+r)/2LL;
				if(a[i]*a[m]<cm) l=m;
				else r=m;
			}
			tot+=r;
		}
		if((a[i]*a[i])<cm) tot-=1LL;
	}
	tot/=2LL;
}
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n),INF*=INF,cl=-INF,cr=INF;
	while(cl+1<cr){
		cm=(cl+cr)/2LL,tot=0LL;
		if(Get()<k) cl=cm;
		else cr=cm;
		if(tot<k) cl=cm;
		else cr=cm;
	}
	cout<<cl<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main(){
	int a,b,n;
	while(cin >> a >> b >> n){
        int ans = 0;
        for(int i = 0; i < n; i++){
            a = (a%b)*10;
            ans += a/b;
        }
        cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
    public static void main (String[] args) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	Node root = new Node();
	TreeWalker walker = new TreeWalker();
	int n = Integer.parseInt(br.readLine());
	String[] input;
	for (int i = 0; i < n; i++) {
	    input = br.readLine().split(" ");
	    if (input.length == 1) {
		walker.runPrintInorder(root.right);
		walker.runPrintPreorder(root.right);
	    } else if (input.length == 2) {
		root.insert (root, Integer.parseInt(input[1]));
	    }
	}
	
    }
}
class Node {
    int key;
    Node left;
    Node right;
    Node () {
	key = 2000000001 * (-1);
	left = null;
	right = null;
    }
    Node (int key) {
	this.key = key;
	left = null;
	right = null;
    }
    void insert (Node root, int key) {
	Node node = root;
	Node parent = null;
	while (node != null) {
	    parent = node;
	    if (key < node.key) {
		node = node.left;
	    } else {
		node = node.right;
	    }
	}
	if (parent == null) {
	    parent = new Node (key);
	} else if (key < parent.key) {
	    parent.left = new Node (key);
	} else {
	    parent.right = new Node (key);
	}
    }
}
class TreeWalker {
    void runPrintInorder (Node root) {
	StringBuilder sb = new StringBuilder();
	printInorder(root, sb);
	System.out.println(sb);
    }
    void printInorder (Node node, StringBuilder sb) {
	if (node == null) {
	    return;
	}
	printInorder(node.left, sb);
	sb.append(" " + node.key);
	printInorder(node.right, sb);
    }
    void runPrintPreorder (Node root) {
	StringBuilder sb = new StringBuilder();
	printPreorder(root, sb);
	System.out.println(sb);
    }
    void printPreorder (Node node, StringBuilder sb) {
	if (node == null) {
	    return;
	}
	sb.append(" " + node.key);
	printPreorder(node.left, sb);
	printPreorder(node.right, sb);
    }
}

Measured memory_bytes: 136540
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

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

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n;
    cin >> n;
    vector<ll> z(n);
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> z[i];
    }
    sort(z.begin(), z.end());
    if (n % 2 == 0) {
        for (int i = 0; i < n/2-1; i++) {
            ans -= z[i] * 2;
        }
        ans -= z[n / 2 - 1];
        ans += z[n / 2];
        for (int i = 0; i < n / 2 - 1; i++) {
            ans += z[n-i-1] * 2;
        }
        cout << ans << endl;
    }
    else {
        for (int i = 0; i < n / 2; i++) {
            ans -= z[i] * 2;
        }
        for (int i = 0; i < n / 2; i++) {
            ans += z[n - i - 1] * 2;
        }
        
        ans = max(ans+z[n/2]-z[n/2+1], ans - z[n / 2] + z[n / 2 - 1]);
        cout << ans << endl;
    }
}

Measured memory_bytes: 4044
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        if(B % A == 0) System.out.println(A + B);
        else System.out.println(B - A);
        sc.close();


    }

}


Measured memory_bytes: 23252
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
  int n;

  while(1)
    {
      double a2=0, m=0;
      cin >> n;
      if(n==0)
	break;
      double s[n];
      for(int i=0;i<n;i++)
	cin >> s[i];
      for(int i=0;i<n;i++)
	m += s[i];
      m /= n;
      for(int i=0;i<n;i++)
	a2 += (s[i]-m)*(s[i]-m);
      a2 /= n;
      cout << fixed << setprecision(5)
	   << sqrt(a2) << endl;
    }
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string S;

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

	ll N; cin >> N >> S;

	ll cnt[30];

	ll mod = 1e9+7;

	memset(cnt,0,sizeof(cnt));

	ll ans = 1;

	for (int i = 0;i < N;i++){
		cnt[S[i]-'a']++;
	}

	for (int i = 0;i < 26;i++){
		ans *= cnt[i]+1;
		ans %= mod;
	}

	cout << ans-1 << endl;

	return 0;

}


Measured memory_bytes: 512
package main

import (
	"bufio"
	"strconv"
	"fmt"
	"strings"
	"os"
)

func partation(A []int, p, r int) int {
	x := A[r]
	tmp := A[:r]
	i := p - 1
	j := p
	for j < len(tmp) {
		if tmp[j] <= x {
			i++
			tmp[j], tmp[i] = tmp[i], tmp[j] // swap
		}
		j++
	}
	A[r], A[i+1] = A[i+1], x
	return i+1
}

func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	n, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return n
}

func printArray(Array []int, partation int) {
	tmp := make([]string, len(Array))
	for index, value := range Array {
		if index == partation {
			tmp[index] = "[" + strconv.Itoa(value) + "]"
		} else {
			tmp[index] =  strconv.Itoa(value)
		}
	}
	fmt.Println(strings.Join(tmp, " "))
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	n := nextInt(scanner)
	A := make([]int, n)
	for i := range A {
		A[i] = nextInt(scanner)
	}
	partationIndex := partation(A, 0, n-1)
	printArray(A, partationIndex)
}


Measured memory_bytes: 5524
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;

//import dp.Main.PrimsPair;

public class Main {

	public static int lowerBound(long[] array, int length, long value) {
		int low = 0;
		int high = length;
		while (low < high) {
			final int mid = (low + high) / 2;
			if (value <= array[mid]) {
				high = mid;
			} else {
				low = mid + 1;
			}
		}
		return low;
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	// method to return LCM of two numbers
	static long lcm(long a, long b) {
		return (a * b) / gcd(a, b);
	}

	public static void sortbyColumn(int arr[][], int col) {
		// Using built-in sort function Arrays.sort
		Arrays.sort(arr, new Comparator<int[]>() {

			@Override
			// Compare values according to columns
			public int compare(final int[] entry1, final int[] entry2) {

				// To sort in descending order revert
				// the '>' Operator
				// if (entry1[col] > entry2[col])
				// return 1;
				// else //(entry1[col] >= entry2[col])
				// return -1;
				return new Integer(entry1[col]).compareTo(entry2[col]);
				// return entry1[col].
			}
		}); // End of function call sort().
	}
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		FastReader sc = new FastReader();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scn = new Scanner(System.in);
		// PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		String s=sc.next();
		for(int i=0;i<s.length()-1;i++)
			
			
		{
			if(s.charAt(i)==s.charAt(i+1))
			{
				System.out.println("Bad");return;
			}
		}
		System.out.println("Good");
		
		
	}
}


Measured memory_bytes: 21712
/*************************
author : coldbeer
2019-06-01 9:54:11 pm IST
*************************/
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"

const int N = 1e4 + 5;
int n;
vector<int> graph[N], deg(N, 0), c(N, 0);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n - 1; i++)
    {
        int u, v;
        cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
        deg[u]++;
        deg[v]++;
    }
    for (int i = 1; i < n + 1; i++)
        cin >> c[i];
    sort(c.begin() + 1, c.begin() + n + 1);
    int idx = 1;
    queue<int> Q;
    for (int i = 1; i < n + 1; i++)
        if (deg[i] == 1)
            Q.push(i);
    vector<int> d(n + 1, 0), visited(n + 1, 0);
    while (!Q.empty())
    {
        int node = Q.front();
        Q.pop();
        d[node] = c[idx++];
        visited[node] = 1;
        for (int child : graph[node])
        {
            if (!visited[child])
            {
                deg[child]--;
                if (deg[child] == 1)
                {
                    Q.push(child);
                    visited[child] = 1;
                }
            }
        }
    }
    int ans = 0;
    for (int i = 1; i < n + 1; i++)
    {
        if (graph[i].size())
        {
            for (int child : graph[i])
                ans += min(d[i], d[child]);
        }
    }
    ans /= 2;
    cout << ans << endl;
    for (int i = 1; i < n + 1; i++)
        cout << d[i] << " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 1152