akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppiii;

const int MOD = 1000000007;

map<int, int> dp;
int tot;

int currMedian;
ll currLessCount;
ll lessSum, greaterSum;

ll shift;

void update(int a, int b) {
  shift += b;
  dp[a]++; tot++;
  if(tot == 1) currMedian = a;
  if(a <= currMedian) {
    currLessCount++;
    lessSum += currMedian - a;
  }
  else {
    greaterSum += a - currMedian;
  }
  while(2*currLessCount >= tot) {
    if(2*(currLessCount-dp[currMedian]) >= tot) {
      int cand;
      {
        auto x = dp.find(currMedian);
        x--;
        cand = x->first;
      }
      currLessCount -= dp[currMedian];
      lessSum -= currLessCount * (currMedian - cand);
      greaterSum += (tot - currLessCount) * (currMedian - cand);
      currMedian = cand;
    }
    else {
      break;
    }
  }
  while(2*currLessCount < tot) {
    int cand = dp.upper_bound(currMedian)->first;
    lessSum += currLessCount * (cand - currMedian);
    greaterSum -= (tot - currLessCount) * (cand - currMedian);
    currLessCount += dp[cand];
    currMedian = cand;
  }
}

void query() {
  cout << currMedian << " " << lessSum + greaterSum + shift << "\n";
}

void solve() {
  int n;
  cin >> n;
  while(n--) {
    int t;
    cin >> t;
    if(t == 2) query();
    else {
      int a, b;
      cin >> a >> b;
      update(a, b);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


Measured memory_bytes: 7296
import java.util.*;

public class Main {
    static class Task {
        public int a, b;

        public Task(int a, int b) {
            this.a = a;
            this.b = b;
        }

        public String toString() {
            return String.format("Task(%d, %d)", this.a, this.b);
        }

    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Task[] lis = new Task[n];

        for (int i = 0; i < n; ++i) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            lis[i] = new Task(a, b);
        }

        Arrays.sort(lis, new Comparator<Task>() {
            public int compare(Task x, Task y) {
                return x.b - y.b;
            }
        });

        int now = 0;
        for (int i = 0; i < n; ++i) {
            now += lis[i].a;
            if (now <= lis[i].b) {
                continue;
            } else {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}


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

public class Main
{
  static class FastScanner
  {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    String next() {
      while(!st.hasMoreTokens()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {}
      }
      return st.nextToken();
    }
    
    int nextInt() {
      return Integer.parseInt(next());
    }
    
    long nextLong() {
      return Long.parseLong(next());
    }
    
  }
  
  public static void main(String[] args) {
    FastScanner fs = new FastScanner();
    int N = fs.nextInt();
    long W = fs.nextLong();
    long[][] arr = new long[N][2];
    for(int i = 0; i < N; ++i) {
      arr[i][0] = fs.nextLong();
      arr[i][1] = fs.nextLong();
    }
    PrintWriter out = new PrintWriter(System.out);
    bubbleSort(arr);
    out.println(solve(arr, W));
    out.close();
  }
  
  public static void bubbleSort(long[][] arr) 
  { 
      int n = arr.length; 
      for (int i = 0; i < n-1; i++) 
          for (int j = 0; j < n-i-1; j++) 
              if (arr[j][0] > arr[j+1][0]) 
              { 
                  long[] temp = arr[j]; 
                  arr[j] = arr[j+1]; 
                  arr[j+1] = temp; 
              } 
  }
  
  
  public static long solve(long[][] arr, long W) {
    long[][] dp = new long[arr.length][(int) (W+1)];
    for(int i = 0; i < dp[0].length; ++i) {
      if(i >= arr[0][0]) {
        dp[0][i] = arr[0][1];
      }
    }
    for(int r = 1; r < dp.length; ++r) {
      for(int c = 1; c < dp[0].length; ++c) {
        long val = Long.MIN_VALUE;
        if(c-arr[r][0] >= 0) {
          val = dp[r-1][(int) (c-arr[r][0])] + arr[r][1];
        }
        dp[r][c] = Math.max(val, dp[r-1][c]);
      }
    }
    return dp[arr.length - 1][(int)W];
  }

}

Measured memory_bytes: 137616
#include <iostream>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int n,l[10],ans=1000000000,i;
int x[4],X[4];
int main(){
    cin>>n>>X[1]>>X[2]>>X[3];
    for(i=0;i<n;i++) cin>>l[i];
    for(i=0;i<1<<(2*n);i++){
        int tmp=0;
        for(int j=0;j<4;j++)x[j]=0;
        for(int j=0;j<2*n;j+=2){
            x[(i>>j)&3]+=l[j/2];
            if((i>>j)&3)tmp+=10;
        }
        if(!(x[1]&&x[2]&&x[3])) continue;
        for(int j=1;j<4;j++)tmp+=abs(X[j]-x[j]);
        ans=min(ans,tmp-30);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	p := make([]int, n)
	sum := 0
	max := 99
	for i := range p {
		fmt.Scan(&p[i])
		sum += p[i]
		if p[i] > max {
			max = p[i]
		}
	}
	fmt.Println(sum - max/2)
}


Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    ll a[n];
    ll h = 0 , w = 0;
    for( ll i = 0 ; i < n ; i++ ) {
        cin >> a[i];
    }
    sort( a , a + n );
    for( ll i = n - 1 ; i >= 0 ; i-- ) {
        if( a[i] == a[i + 1] ) {
            if( h == 0 ) {
                h = a[i];
                i--;
            } else {
                w = a[i];
                cout << h * w;
                return 0;
            }
        }
    }
    cout << 0;
}


Measured memory_bytes: 4392
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p = sorted(p)[::-1]
q = sorted(q)[::-1]
r = sorted(r)[::-1]
ans = sorted(p[:X] + q[:Y] + r)[::-1]
print(sum(ans[:X + Y]))


Measured memory_bytes: 23328
#include <bits/stdc++.h>
//#pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned short us;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ll infll=(1ull<<63)-1,mod=1e9+7;
const int inf=(1ull<<31)-1;
ll n,a[100001],ans=0;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(18);
	cin>>n;
	n++;
	for (int i=0;i<n;i++)
		cin>>a[i];
	n--;
	ll t,x;
	for (int i=0;i<n;i++){
		cin>>t;
		ans+=min(a[i],t);
		t-=a[i];
		if (t>0)
			x=min(a[i+1],t),
			a[i+1]-=x,
			ans+=x;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;  
long long int Fac[1000010]; 
long long int Pow(long long int a, long long int n, long long int m) {
  long long int powa[65];
  	powa[0] = a; 
  	for(int j = 0; j < 64; ++j){
     		powa[j+1] = (powa[j] * powa[j]) % m; 
  	}
	long long int c = n; 
  	long long int Q = 1; int k = 0; 
	while(c > 0){
  		if(c & 1) Q = (Q * powa[k]) % m; 
		c = c >> 1; k++; 
	}
	return Q;
}
long long int Inv(long long int a, long long int m) {
	return Pow(a, m-2, m); 
}
long long int Comb(int N, int R, long long int m){
	if(R > N) return 0; 
	else return (((Fac[N] * Inv(Fac[N-R], m)) % m) * Inv(Fac[R], m)) % m; 
}
int main(){
	long long int P = 1000003; 
	Fac[0] = 1; 
	for(int i = 1; i <= 1000007; i++){
		Fac[i] = (Fac[i-1] * i) % P; 
	}
	int Q; 
	cin >> Q; 
	for(int q = 0; q < Q; q++){
		long long int X, D, N; cin >> X >> D >> N; 
		if(D == 0) cout << Pow(X, N, P) << endl; 
		else{
			long long int shokou = (Inv(D, P) * X) % P; 
			if(X == 0 || shokou + N - 1 >= P) cout << 0 << endl; 
			else cout << (((Fac[shokou + N - 1] * Inv(Fac[shokou - 1], P)) % P) * Pow(D, N, P)) % P<< endl; 
		}
	}
}

Measured memory_bytes: 8704
using System;using System.Linq;using static System.Console;class P{static void Main(){ReadLine();var x=ReadLine().Split().Select(int.Parse);var y=ReadLine().Split().Select(int.Parse);var d=x.Zip(y,(a,b)=>Math.Abs(a-b));for(int i=1;i<4;i++)WriteLine(Math.Pow(d.Select(z=>Math.Pow(z,i)).Sum(),1.0/i));WriteLine(d.Max());}}


Measured memory_bytes: 16556
#include <bits/stdc++.h>
 
#define pb push_back 
#define x first 
#define y second 
#define MOD 1000081
 
using namespace std;
typedef long long ll;
typedef pair< int , int > PII;
const int dirx[] = {-2,-1,1,2, 1, -1};
const int diry[] = {0,1,1,0, -1, -1};
inline void debugMode() {
    #ifndef ONLINE_JUDGE
    freopen("eqs.in", "r", stdin);
    freopen("eqs.out", "w", stdout);
    #endif
}
 
int n, m;
PII a[100100];
vector < int > V, R;
 
int main(){ 
    //debugMode();
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++){
		cin >> a[i].x >> a[i].y;
		V.pb(a[i].x);
		R.pb(a[i].y);
	}
	sort(V.begin(), V.end(), [&](int a, int b){return a > b;});
	sort(R.begin(), R.end(), [&](int a, int b){return a > b;});
	int nr = 0;
	for (auto it : R){
		if (it <= V[0]) break;
		nr++;
		m -= it;
		if (m <= 0) return cout << nr, 0;
	}
	nr += m / V[0] + bool(m % V[0]);
	cout << nr;
    return 0;
}


Measured memory_bytes: 2036
class Tree:
    def __init__(self, v: int):
        self.value = v
        self.size = 1
        self.depth = 1
        self.parent = None
        self.friends = set()
        self.blocked = 0

    def get_root(self):
        t = self
        while(t.parent != None):
            t = t.parent
        return t

    def merge(self, t):
        p, c = (self, t) if self.depth > t.depth else (t, self)
        c.parent = p
        p.depth = max(p.size, c.size + 1)
        p.size += c.size

def main():
    n, m, k = [int(s) for s in input().split()]
    forest = [Tree(i+1) for i in range(n)]

    for i in range(m):
        a, b = [int(s) for s in input().split()]
        ta, tb = forest[a-1], forest[b-1]
        ta.friends.add(b)
        tb.friends.add(a)
        ra = ta.get_root()
        rb = tb.get_root()
        if ra != rb:
            ra.merge(rb)

    roots = [t.get_root() for t in forest]
    for i in range(k):
        c, d = [int(s) for s in input().split()]
        tc, td = forest[c-1], forest[d-1]
        rc = roots[c-1]
        rd = roots[d-1]
        if rc == rd:
            tc.blocked +=1
            td.blocked +=1

    cands = []
    for t in forest:
        root = roots[t.value - 1]
        cand = root.size - len(t.friends) - t.blocked - 1
        cands.append(str(cand))
    print(" ".join(cands))

if __name__ == '__main__':
    main()


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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int sum=a+b+c;
  cout << min(a,min(b,c)) << " "<<sum-min(a,min(b,c))-max(a,max(b,c)) << " " <<max(a,max(b,c))<< endl;
  return 0;
}


Measured memory_bytes: 3092
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: i32 = read();
    let m: i32 = read();
    println!("{}", (n - 1) * (m - 1));
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

#define int long long

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
 
using namespace std;

int32_t main(){
    string str;
    cin >> str;
    int n=str.length();

    int v[26];
    v['N'-'A']=1;
    v['S'-'A']=-1;
    v['E'-'A']=1;
    v['W'-'A']=-1;
    int cnt_h=0, cnt_w=0;
    REP(i, n){
        if(v[str[i]-'A']!=INF){
            if(str[i]=='N' || str[i]=='S'){
                cnt_h+=v[str[i]-'A'];
                v[str[i]-'A']=INF;
            }
            else{
                cnt_w+=v[str[i]-'A'];
                v[str[i]-'A']=INF;
            }
        }
    }

    if(cnt_h==0 && cnt_w==0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
x = list(map(int, input().split()))
m = max(x)
ans = [] 
for i in range(101):
    sum_dis = 0
    for j in range(len(x)):
        sum_dis += (x[j]-i)**2
    ans.append(sum_dis)
print(min(ans))
    


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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define inf 1000000100

int main()
{
    int n;
    cin >> n;
    int x = 800*n;
    int y = (n/15)*200;
    cout << x - y << endl;
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  string s;
  cin >> s;

  int ans = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '1') {
      ans++;
    }
  }

  cout << ans << '\n';
}

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

main()
{

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

    long long i,j,k,l,m,n,p;

    while(cin>>n)
    {
        int x[n];
        for(i=0; i<n; i++)
            cin>>x[i];
        sort(x,x+n);
        l=0;
        for(i=0; i<n; i++)
        {
            for(j=i+1; j<n; j++)
            {
                for(k=j+1; k<n; k++)
                {
                    if(x[i]+x[j]>x[k]&&x[i]!=x[j]&&x[j]!=x[k]){
                        l++;
                      //  cout<<x[i]<<" "<<x[j]<<" "<<x[k]<<endl;
                        }
                }
            }
        }
        cout<<l<<endl;

    }

    return 0;
}


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

typedef long long ll;

int main(){
    int K; cin >> K;
    if(K<=9){
        cout << K << endl;
        return 0;
    }
    priority_queue<ll,vector<ll>,greater<ll> > que;
    for(int i=1;i<=9;i++) que.push(i);

    int cnt=9;
    ll ans;
    while(cnt<K){
        ll res=que.top(); que.pop();
        int mod=res%10;
        ll tmp1=10*res+max(0,mod-1);
        ll tmp=10*res+mod;
        ll tmp2=10*res+min(9,mod+1);
        que.push(tmp1);
        cnt++;
        if(cnt==K) ans=tmp1;
        if(tmp!=tmp1){
            que.push(tmp);
            cnt++;
            if(cnt==K) ans=tmp;
        }
        if(tmp!=tmp2){
            que.push(tmp2);
            cnt++;
            if(cnt==K) ans=tmp2;
        } 
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

a,b,c = li()

a,b,c = sorted([a,b,c])

cnt = 0
while a != b or b != c:
    if a != b:
        a += 2
        
    else:
        a += 1
        b += 1
        
    a,b,c = sorted([a,b,c])
        
    cnt += 1
    
    
print(cnt)

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

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

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

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

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

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

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

// ===

fn main() {
    let n: usize = read();
    let s: Vec<u8> = read::<String>().into_bytes();

    let mut facing_west = vec![0; n];
    let mut facing_east = vec![0; n];

    for i in 1..n {
        facing_west[i] = facing_west[i-1];
        if s[i-1] == 'W' as u8 {
            facing_west[i] += 1;
        }
    }
    for i in (0..n-1).rev() {
        facing_east[i] = facing_east[i+1];
        if s[i+1] == 'E' as u8 {
            facing_east[i] += 1;
        }
    }

    let mut best = n;
    for i in 0..n {
        best = min(best, facing_west[i] + facing_east[i]);
    }
    println!("{}", best);
}


Measured memory_bytes: 12540
k, a, b = map(int, input().split())

# 答えがk + 1以上であることは保証される
ans = k + 1

if (b - a) >= 2 and k > a:
    ans = max(ans, a + (b - a) * ((k - a + 1) // 2) + (k - a + 1) % 2)

print(ans)

Measured memory_bytes: 38256
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
    	FastIO sc = new FastIO(System.in);
    	PrintWriter out = new PrintWriter(System.out);
    	long a = sc.nextLong();
    	long b = sc.nextLong();
    	long n = sc.nextLong();
    	long x = Math.min(n, b-1);
    	System.out.println(((a*x)/b));
    	out.close();
    }
    static class FastIO {
		 
		// Is your Fast I/O being bad?
 
		InputStream dis;
		byte[] buffer = new byte[1 << 17];
		int pointer = 0;
 
		public FastIO(String fileName) throws IOException {
			dis = new FileInputStream(fileName);
		}
 
		public FastIO(InputStream is) throws IOException {
			dis = is;
		}
 
		int nextInt() throws IOException {
			int ret = 0;
 
			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}
 
			return (negative) ? -ret : ret;
		}
 
		long nextLong() throws IOException {
			long ret = 0;
 
			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}
 
			return (negative) ? -ret : ret;
		}
 
		byte nextByte() throws IOException {
			if (pointer == buffer.length) {
				dis.read(buffer, 0, buffer.length);
				pointer = 0;
			}
			return buffer[pointer++];
		}
 
		String next() throws IOException {
			StringBuffer ret = new StringBuffer();
 
			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			while (b > ' ') {
				ret.appendCodePoint(b);
				b = nextByte();
			}
 
			return ret.toString();
		}
 
	}
}

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

int main()
{
    int N,M;//人数N,種類M
    cin >> N >> M;

    int food[100];
    memset(food, 0, sizeof(food));
    int tmp,f_tmp;

    for (int i=0; i<N; i++){
        cin >> tmp;
        for (int j=0; j<tmp; j++){
            cin >> f_tmp;
            food[f_tmp]++;
        }
    }
    int count=0;
    for (int i=0; i<100; i++){
        if(food[i]==N){
            count++;
        }
    }
    cout << count;
    return 0;
}

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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define MOD 998244353

int main()
{
  int n,s;cin>>n>>s;
  vector<int> a(n);
  int i,j,k;
  rep(i,n)cin>>a[i];
  vector<vector<vector<ll>>> dp(n+1,vector<vector<ll>>(s+1,vector<ll>(3,0)));
  dp[0][0][0]=1;
  for(i=1;i<=n;i++)
  {
    for(j=0;j<=s;j++)
    {
      dp[i][j][0]=dp[i-1][j][0]%MOD;
      for(k=0;k<3;k++)
      {
        dp[i][j][k]=dp[i-1][j][k];
      }
      dp[i][j][1]=(dp[i-1][j][0]+dp[i-1][j][1])%MOD;
      if(j-a[i-1]>=0)dp[i][j][1]=(dp[i][j][1]+dp[i-1][j-a[i-1]][0]+dp[i-1][j-a[i-1]][1])%MOD;
      dp[i][j][2]=(dp[i-1][j][0]+dp[i-1][j][1]+dp[i-1][j][2])%MOD;
      if(j-a[i-1]>=0)dp[i][j][2]=(dp[i][j][2]+dp[i-1][j-a[i-1]][0]+dp[i-1][j-a[i-1]][1])%MOD;
    }
  }
  cout<<dp[n][s][2]<<endl;
}


Measured memory_bytes: 493056
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

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

int main() {
	int m; cin >> m;
	while (m--) {
		string s; cin >> s;
		set<string> st;
		for (int i = 1; i < s.length(); i++) {
			string a = s.substr(0, i), b = s.substr(i);
			st.insert(a + b); st.insert(b + a);
			reverse(a.begin(), a.end());
			st.insert(a + b); st.insert(b + a);
			reverse(b.begin(), b.end());
			st.insert(a + b); st.insert(b + a);
			reverse(a.begin(), a.end());
			st.insert(a + b); st.insert(b + a);
		}
		cout << st.size() << endl;
	}
}

Measured memory_bytes: 1292
#include<bits/stdc++.h>
#define MIN -1000000
using namespace std;
typedef long long ll;
typedef pair <int,ll> pii;
const int max_N=1e5+10;
const int inf=1e9+5;
vector <pii> G[max_N],rg[max_N];
vector<int>p(105,0);
string s,t;
int main()
{
  cin >> s;
  cin >> t;
  int n=int(s.size());
  int m=int(t.size());
  string ans="";
  vector<vector<int> >dp(3005,vector<int>(3005,0));
  dp[0][0]=0;
  for(int i=0;i<n;i++)
    {
      for(int j=0;j<m;j++)
	{
	  if(s[i]==t[j])
	    {
	      dp[i+1][j+1]=dp[i][j]+1;
	    }
	  else
	    {
	      dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
	    }
	}
    }
  while(n&&m)
    {
      if(s[n-1]==t[m-1])
	{
	  ans+=s[n-1];
	  n--;
	  m--;
	}
      else if(dp[n-1][m]>dp[n][m-1]) n--;
      else m--;
    }
  reverse(ans.begin(),ans.end());
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 40320
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mk make_pair
#define pi pair<int, int>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;

constexpr int N = 1e6+6;
int n;
int cnt[N];

void fenjie(int x)
{
    for(int i=2;i*i<=x;++i)
    {
        if(x%i == 0)
        {
            ++cnt[i];//因子含有i的数有cnt[i]个
            while(x%i == 0)x/=i;
        }
    }
    if(x > 1) ++cnt[x];
}


int main()
{
   //IOS;
   int n;
   int a;
   scanf("%d%d",&n,&a);
   int k = a;
   int mxa = 0;
   rep(i,2,n)
   {
       scanf("%d",&a);
       mxa = max(mxa,a);
       k = __gcd(k,a);
       fenjie(a);
   }
   bool p1 = 1;
   rep(i,2,mxa)
   {
       if(cnt[i] >= 2)
       {
           p1 = 0;
           break;//说明不是两两互质了
       }
   }
   if(p1)puts("pairwise coprime");
   else if(p1 == 0 && k == 1) puts("setwise coprime");
   else puts("not coprime");
}


Measured memory_bytes: 7576
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

N, Y = na()
found = False

for i in range(N, -1, -1):
  if(i*10000 > Y):
    continue
  for j in range(N-i, -1, -1):
    if(found):
      break
    if(i*10000 + j*5000 + (N-i-j)*1000 == Y):
      found = True
      print(str(i) + ' ' + str(j) + ' ' + str(N-i-j))
      break

if(not found):
  print('-1 -1 -1')

Measured memory_bytes: 3064
import fractions

def judge(A, B, C, D):
    if A < B:   # そもそも買えない
        return False
    if D < B:   # 補充が間に合わないのでいずれ在庫が尽きる
        return False
    if B <= C:  # 補充が間に合う状況で、必ず0個以上の在庫がある
        return True
    G = fractions.gcd(B, D)   # 昼の買い物の後に残る在庫数の候補のステップ数
    R = A % G       # 例えば A = 3, G = 2の場合、必ず1個あまる
    if C + G - R - B  < 0:
        # C + G - R: 在庫の最小数
        return False
    else:
        return True

T = int(input())
data = []
for _ in range(T):
    data.append([int(xi) for xi in input().split()])
for A, B, C, D in data:
    print('Yes') if judge(A, B, C, D) else print('No')


Measured memory_bytes: 5084
#include <bits/stdc++.h>
using namespace std;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
 
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;
 
const int MAX = 1000000;
const int MOD = 1000000007;
 
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll modPow(ll a, ll n, ll p) {
  if (n == 0) return 1;
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  ll t = modPow(a, n / 2, p);
  return (t * t) % p;
}
 
int main(){
  ll n;
  cin >> n;
  ll p = modPow(10,n,mod),q = modPow(9,n,mod),r = modPow(8,n,mod);
  ll ans = ((p+4*mod+r)-(2*q))%mod;
  cout << ans << endl;
}

Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
"""
http://abc076.contest.atcoder.jp/tasks/abc076_c
WA
"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    S = input().strip()
    T = input().strip()

    s_len = len(S)
    t_len = len(T)
    gap = s_len - t_len

    ans = 'UNRESTORABLE'
    while gap >= 0:
        matched = True
        for i in range(t_len):
            if S[gap + i] != T[i] and S[gap + i] != '?':
                matched = False
                break
        if matched is True:
            ans = S[:gap] + T + S[gap+t_len:]
            ans = ans.replace('?', 'a')
            break
        gap -= 1

    print(ans)



if __name__ == '__main__':
    main(sys.argv[1:])
    


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

int main(void) {
    int r,D,x;cin>>r>>D>>x;
    int before = x;
    for (int i = 1; i <= 10; i++) {
        int result = r * before - D;
        cout << result << endl;
        before = result;
    }
    return 0;
}

Measured memory_bytes: 256
from operator import itemgetter
n = int(input())
lst1 = []
for i in range(n):
    x,l = map(int,input().split())
    lst1.append([x-l,x+l])

lst1.sort(key=itemgetter(1)) #終点についてソート

ans = 1
start = lst1[0][1]

for i in range(1,n):
    if lst1[i][0] >= start:
        start = lst1[i][1]
        ans += 1

print(ans)

Measured memory_bytes: 63576
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
int main(){
	int a,b;
	bool first=1;
	while(cin>>a>>b,a||b){
	if(first==0)cout<<endl;
	first=0;
	bool f=0;
	for(int i=a;i<=b;i++){
	if( i%4==0&&i%100!=0 ||i%400==0  ){cout<<i<<endl;f=1;}
	}
	if(f==0)cout<<"NA"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int w = sc.nextInt();
            int n = sc.nextInt();
            int[] values = new int[w];
            for (int i = 0; i < values.length; i++) {
                values[i] = i + 1;
            }
            for (int i = 0; i < n; i++) {
                String str = sc.next();
                String[] ab = str.split(",");
                int a = Integer.parseInt(ab[0]) - 1;
                int b = Integer.parseInt(ab[1]) - 1;
                int c;
                c = values[a];
                values[a] = values[b];
                values[b] = c;
            }
            for (int i = 0; i < n; i++) {
                System.out.printf("%d\n", values[i]);
            }
        }
    }
}



Measured memory_bytes: 26212
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 2000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool debug=false;
/*---------------------------------------------------*/

int main(){
  int n,m;
  char a,b;
  map<char,char>c;
  
  while(1){
    c.clear();
    cin>>n;
    if(n==0)break;
    rep(i,n){
      cin>>a>>b;
      c[a]=b;
    }
    
    cin>>m;
    rep(i,m){
      cin>>a;
      if(c.find(a)==c.end())cout<<a;
      else cout<<c[a];
    }
    cout<<endl;
  }
  return 0;
}

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

int main(){
    int n,d;
    cin >> n >> d;
    int cnt = 0;
    for(int m = 4; m <= n; m++){
        for(int j = 10; j <= d; j++){
            if(m == (j/10)*(j%10) && (j/10) >= 2 && (j%10) >= 2){
                cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

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

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, s, e) for (int i = (s); i < (e); i++)
#define all(x) x.begin(), x.end()

#define endl "\n"

void use_cio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto x : V) os << x << ", ";
  return os << "]";
}
//--------------------------------------------------//

int main() {
  use_cio();
  string s;
  cin >> s;
  int n = s.size();
  int win = 0;
  for (auto x : s) win += (x == 'o');
  if (15 - n + win >= 8)
    cout << "YES\n";
  else
    cout << "NO\n";
}


Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append((i, n//i))

    divisors.sort()
    return divisors

from math import log10
N = int(input())
div = make_divisors(N)

def F(A, B):
    return max(int(log10(A))+1, int(log10(B))+1)
ans = 10**9
for a, b in div:
    ans = min(ans, F(a, b))
print(ans)


Measured memory_bytes: 3188
a,b=map(int,input().split())
if a>2 and b>2:
    cnt=a*b-(a*2+b*2-4)
elif (a==1 and b>2) or (a>2 and b==1):
    cnt=a*b-2
elif (a==2 or b==2):
    cnt=0
elif a==1 and b==1:
    cnt=1
print(cnt)

Measured memory_bytes: 3064
HL=list()
WL=list()
while True:
    H,W=map(int,input().split())
    HL.append(H)
    WL.append(W)
    if H==0 and W==0:
        break
for i in range(len(HL)):
    for j in range(HL[i]):
        for k in range(WL[i]):
            print("#",end="")
        print("")
        if j==HL[i]-1:
            print("")


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

using namespace std;

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;

#define rep(i,a,b) for(int i =(a);i<(int)(b);i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

typedef long long ll;

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

    int n; int W; 
    cin>>n>>W; 

    int weight[n], value[n];

    rep(i, 0, n){
        cin>>weight[i]>>value[i];
    }

    ll dp[W+1]= {0};

    rep(k,0, n){
        for(int wal = W- weight[k]; wal >= 0; wal--){
            dp[wal+weight[k]] = max(dp[wal+weight[k]], dp[wal]+value[k]);
        }
    }

    ll ans = *max_element(dp, dp+W+1);
    
    cout<<ans<<endl;

    return 0 ;
}



Measured memory_bytes: 4432
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()


int main(){
    string s;
    cin >> s;
    if(s == "Sunny") puts("Cloudy");
    else if(s == "Cloudy") puts("Rainy");
    else puts("Sunny");
}


Measured memory_bytes: 3532
#include <iostream>
#include <map>
#include <set>

using namespace std;

string::iterator it;
map<char, set<int>> elements;

set<int> term();
set<int> expr();

set<int> difference(const set<int> a, const set<int> b)
{
    set<int> res;
    for(auto x : elements['U']){
        if(a.count(x) > 0 and b.count(x) == 0){
            res.insert(x);
        }
    }
    return res;
}

set<int> complement(const set<int> a)
{
    return difference(elements['U'], a);
}
    
set<int> intersection(const set<int> a, const set<int> b)
{
    set<int> res;
    for(auto x : elements['U']){
        if(a.count(x) > 0 and b.count(x) > 0){
            res.insert(x);
        }
    }            
    return res;
}

set<int> union_(const set<int> a, const set<int> b)
{
    set<int> res;
    for(auto x : elements['U']){
        if(a.count(x) > 0 or b.count(x) > 0){
            res.insert(x);
        }
    }            
    return res;
}

set<int> sym_difference(const set<int> a, const set<int> b)
{
    return (union_(difference(a, b), difference(b, a)));
}

set<int> term()
{
    set<int> a;
    if(*it == '('){
        ++it;
        a = expr();
        ++it;
    }else if(*it == 'c'){
        ++it;
        a = term();
        a = complement(a);
    }else{
        a = elements[*it];
        ++it;
    }
    return a;
}
    
set<int> expr()
{
    set<int> a = term(), b;
    while(*it == 'd' ||
          *it == 'i' ||
          *it == 's' ||
          *it == 'u')
    {
        char ch = *it; ++it;
        b = term();
        switch(ch)
        {
            case 'd':
                a = difference(a, b);
                break;
            case 'i':
                a = intersection(a, b);
                break;
            case 's':
                a = sym_difference(a, b);
                break;
            case 'u':
                a = union_(a, b);
                break;
        }
    }
    return a;
}

int main()
{
    char ch;
    int N, x;
    while(cin >> ch >> N)
    {
        elements.clear();
        set<int> U = {};

        do{
            if(ch == 'R') break;
            set<int> st;
            for(int i = 0 ; i < N ; i++){
                cin >> x;
                st.insert(x);
                U.insert(x);
            }                    
            elements[ch] = st;
        }while(cin >> ch >> N);

        elements['U'] = U;
        
        string str;
        cin >> str;
        it = str.begin();
        set<int> res = expr();
        if(res.size() == 0){
            cout << "NULL" << endl;
        }else{
            bool sp = 0;
            for(auto r : res){
                if(sp) cout << " ";
                sp = 1;
                cout << r;
            }
            cout << endl;
        }
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }

#define pii pair<int,int>

bool func1(pii a,pii b){
    return a.first<b.first;
}
bool func2(pii a,pii b){
    return a.second>b.second;
}

int main(){
    int N; cin>>N;
    vector<pii> r(N),b(N);
    
    REP(i,N){
        int x,y; cin>>x>>y;
        r[i] = make_pair(x,y);
    }
    REP(i,N){
        int x,y; cin>>x>>y;
        b[i] = make_pair(x,y);
    }
    sort(ALL(r),func2);
    sort(ALL(b),func1);
    int ans = 0;
    for(pii p:b){
        vector<pii>::iterator itr = r.begin();
        while(itr != r.end()){
            pii q = *itr;
            if(p.first>q.first && p.second>q.second){
                ++ans;
                r.erase(itr);
                break;
            }
            ++itr;
        }
    }
    cout << ans <<"\n";
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

public class AtCoder
{

    public static int[] ReadArray()
    {
        return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt32(m));
    }

    public static int ReadInt()
    {
        return Convert.ToInt32(Console.ReadLine());
    }

    public static string ReadStr()
    {
        return Console.ReadLine();
    }

    public static long ReadLong()
    {
        return Convert.ToInt64(Console.ReadLine());
    }

    public static long[] ReadLongArray()
    {
        return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt64(m));

    }


    public static void Main()
    {
        var arr = ReadArray();

        var n = arr[0];
        var m = arr[1];

        if(n == m)
        {
            Console.WriteLine(n + m);
        }
        else 
        {

            Console.WriteLine(2 * Math.Max(n,m) - 1);
        }
       


    }


}

Measured memory_bytes: 11092
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<functional>
#include<algorithm>
using namespace std;
bool d[10001];
int a[10000];
int main() {
	fill(d,d+10001,true);
	d[0]=false;d[1]=false;
	int sum=0;
	for(int i=0;i<=10000;i++){
		if(d[i]){
			a[sum]=i;
			sum++;
			int j=2;
			while(i*j<=10000){
				d[i*j]=false;
				j++;
			}
		}
	}
	int n;
	while(cin>>n&&n!=0){
		int i=0;
		int sum2=0;
		while(a[i]<=n&&i<sum){
			int k=a[i];
			int j=i+1;
			while(k<n){
				k+=a[j];
				j++;
			}
			if(k==n) sum2++;
			i++;
		}
		cout<<sum2<<endl;
	}
}

Measured memory_bytes: 3012
n = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)

from collections import deque
ans = 0
q = deque([A[0]])
for a in A[1:]:
   ans += q.popleft()
   q.append(a)
   q.append(a)

print(ans)

Measured memory_bytes: 31612
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define BITF(n, i) (((n) >> i) & 1)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= x; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define REPZ(i, x) for (int i = 0; i <= x; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
using namespace std;
#define DUMPOUT cerr
// vector
template < typename T > istream &operator>>(istream &is, vector< T > &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}
// pair
template < typename T, typename U >
ostream &operator<<(ostream &os, pair< T, U > &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template < typename T >
ostream &operator<<(ostream &os, const vector< T > &vec) {
  os << "{";
  REP(i, (int)vec.size())
  os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", ");
  os << "}";
  return os;
}
// map
template < typename T, typename U >
ostream &operator<<(ostream &os, map< T, U > &map_var) {
  os << "{";
  FORA(itr, map_var) {
    os << *itr;
    itr++;
    if (itr != map_var.end())
      os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template < typename T > ostream &operator<<(ostream &os, set< T > &set_var) {
  os << "{";
  FORA(itr, set_var) {
    os << *itr;
    itr++;
    if (itr != set_var.end())
      os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
void dump_func() { DUMPOUT << endl; }
template < class Head, class... Tail >
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if (sizeof...(Tail) > 0)
    DUMPOUT << ", ";
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define DUMP(...)                                                              \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                              \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl  \
          << "    ",                                                           \
      dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define DUMP(...)
#endif

#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair< int, int >
#define ld long double
using namespace std;
template < class T > bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
#define MAXN
//----//
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  print((N - 1) / 2);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
#include<string>
#include<stdio.h>
#include<cmath>
#include<map>
#include<bitset>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define repr(i, n) for(int i = n-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define lint long long

int main(){
    int d, g; cin >> d >> g; g /= 100;
    vector<int> p, c;
    rep(i, d){
        int xp, xc; cin >> xp >> xc;
        p.push_back(xp); c.push_back(xc/100);
    }
    int ans = 1e5;
    int M = (1 << d);
    rep(i, M){
        bitset<10> bs(i);
        int sum = 0; int cnt = 0;
        rep(j, d){
            if(bs[j] == 1){
                sum += (j+1) * p[j] + c[j];
                cnt += p[j];
            }
        }
        if (sum >= g){
            ans = min(ans, cnt);
        }
        else{
            repr(j, d){
                if(bs[j] == 0){
                    int necessary = (g - sum + (j+1) - 1) / (j+1);
                    if(necessary <= p[j]){
                        cnt += necessary;
                        ans = min(ans, cnt);
                    }
                    else{
                        break;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
fun main(args:Array<String>) {
    val a = readLine()!!.toInt()
    val b = readLine()!!.toInt()
    val c = readLine()!!.toInt()
    val d = readLine()!!.toInt()
    val e = readLine()!!.toInt()
    val k = readLine()!!.toInt()

    println(if (e-a>k)":("
        else "Yay!")
}


Measured memory_bytes: 29700
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pii;
#define sf(x) scanf("%d",&x)
#define sfl(x) scanf("%lld",&x)
#define lli long long int
#define ll64 int64_t
#define pb push_back
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define frr(i,a) for(int i=0;i<a;i++)
#define frl(i,a) for(lli i=0;i<a;i++)
int main()
{
    lli n;
    cin>>n;
    lli a[n];
    frr(i,n)
    {
        cin>>a[i];
    }
    lli s=0;
    for(int i=1;i<n;i++)
    {
        if(a[i]<a[i-1])
        {
            s+=a[i-1]-a[i];
            a[i]=a[i-1];
        }
    }
    cout<<s<<endl;
}


Measured memory_bytes: 5128
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    constexpr i64 mod = 998244353;
    int n, s;
    std::cin >> n >> s;
    std::vector<int> a(n);
    for (auto &e : a) std::cin >> e;

    i64 ret = 0;
    std::vector<i64> dp(3001);
    for (int i = 0; i < n; i++) {
        auto next(dp);
        next[a[i]] = (next[a[i]] + i + 1) % mod;
        for (int j = 1; j + a[i] <= s; j++) {
            next[j + a[i]] = (next[j + a[i]] + dp[j]) % mod;
        }
        ret = (ret + next[s]) % mod;
        std::swap(dp, next);
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };



signed main() {
	ll a, b;

	cin >> a >> b;

	if (b%a == 0) {
		cout << a + b << endl;
	}
	else {
		cout << b - a << endl;
	}

	return 0;
}

Measured memory_bytes: 256