akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(void){
   double a, b, c, d, i1, j1, i2, j2, x1, y1, x2, y2;
   int n;
   scanf("%lf %lf %lf %lf", &a, &b, &c, &d);
   if(a != c && b != d){
       i1 = (d - b)/(c - a);
       j1 = b - i1 * a;
       i2 = -1 / i1;
       scanf("%d", &n);
       for(c = 0; c < n; c++){
           scanf("%lf %lf", &a, &b);
           j2 = b - i2 * a;
           x1 = (j1 - j2)/(i2 - i1);
           y1 = i2 * x1 + j2;
           x2 = 2*x1 - a;
           y2 = 2*y1 - b; 
           printf("%.10f %.10f\n", x2, y2);
       }
    }else if(a == c){
        scanf("%d", &n);
        for(d = 0; d < n; d++){
           scanf("%lf %lf", &a, &b);
           x2 = 2*c - a;
           printf("%.10f %.10f\n", x2, b);
       }
    }else{
        scanf("%d", &n);
        for(c = 0; c < n; c++){
           scanf("%lf %lf", &a, &b);
           y2 = 2*d - b; 
           printf("%.10f %.10f\n", a, y2);
       }
    }
    return 0;
}


Measured memory_bytes: 2144
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));

        boolean[][] is = new boolean[4][13];
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 13; j++) {
                is[i][j] = false;
            }
        }
        String input = br.readLine();
        int n = Integer.parseInt(input);
        for (int i = 0; i < n; i++) {
            input = br.readLine();
            String[] card = input.split(" ");
            if (card[0].equals("S")) {
                int k = Integer.parseInt(card[1]);
                is[0][k - 1] = true;
            } else if (card[0].equals("H")) {
                int k = Integer.parseInt(card[1]);
                is[1][k - 1] = true;
            } else if (card[0].equals("C")) {
                int k = Integer.parseInt(card[1]);
                is[2][k - 1] = true;
            } else {
                int k = Integer.parseInt(card[1]);
                is[3][k - 1] = true;
            }
        }
        String[] mark = {"S", "H", "C", "D"};
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 13; j++) {
                if (!is[i][j]) {
                    System.out.println(mark[i] + " " + (j + 1));
                }
            }
        }
    }
}

Measured memory_bytes: 24372
use std::vec::Vec;
use std::cmp::*;

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let (W, H, x, y) = {
    let v: Vec<f64> = read_vec();
    (v[0], v[1], v[2], v[3])
  };

  if x == W/2.0 && y == H/2.0 {
    println!("{} {}", H*W/2.0, 1);
  } else {
    println!("{} {}", H*W/2.0, 0);
  }

}


Measured memory_bytes: 4352
S=list(input())
l=len(S)
e=0
ki=["R","U","D"]
gu=["L","U","D"]
tmp=l//2
if l%2 ==0:
	for i in range(tmp):
		char1=S[2*i]
		char2=S[2*i+1]
		if char1 not in ki:
			e=1
		if char2 not in gu:
			e=1


else:
	charL=S[l-1]
	if charL not in ki:
		e=1	

	else:
		for i in range(tmp): 
			char1=S[2*i]
			char2=S[2*i+1]
			if char1 not in ki:
				e=1
			if char2 not in gu:
				e=1

if e==0:
	print("Yes")
else:
	print("No")



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

a = [int(x) for x in input().split()]

odd = 0
even = 1

for i in range(n):
    if a[i] % 2 == 0:
        odd, even = odd*2, even*2
    else:
        odd, even = odd+even, odd+even

if p == 0:
    print(even)
else:
    print(odd)

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

int main() {
  int i,t,n,m,pc,c,g,lt,lc,f,pk[2][10],pn[2][10],pt[100];
  queue<int> qu,st;
  while(cin >> m >> n ) {
	  if (m+n==0) break;
	  for (i=0;i<m;i++) { pk[0][i]=pk[1][i]=-1; pn[0][i]=pn[1][i]=-1;}
	  for (i=0;i<n;i++) cin >> pt[i];
	   	  t=0; pc=0;
	   	  qu.push(1);
	   	  while(!qu.empty() || pc>0) {
			  if (t % 10==0 && t/10<n && t>0) qu.push(t/10+1);  
	          for (i=0;i<m;i++) {
				  if (pk[0][i]==t) { 
					  pc--; st.push(pn[0][i]); pk[0][i]=pn[0][i]=-1;
					  if (pk[1][i]>0) { if (pk[1][i]<=t) { pc--; st.push(pn[1][i]); }
					   else { pk[0][i]=pk[1][i]; pn[0][i]=pn[1][i]; } }
					   pk[1][i]=pn[1][i]=-1;
				  }
			  }
			  f=1;
			  while(f==1 && pc<m*2 && !qu.empty()) {
			     f=0; lt=lc=9999; g=t+pt[qu.front()-1];
			     for (i=0;i<m;i++) if (pk[0][i]==-1) { lc=i; f=1; break; } 
				 if (f==0) for (i=0;i<m;i++) if (pk[0][i]>0 && pk[0][i]>=g && lt>pk[0][i]-g && pk[1][i]==-1) { lt=pk[0][i]-g; lc=i; f=1;}
				 if (f==0) for (i=0;i<m;i++) if (pk[0][i]>0 && pk[0][i]<g && lt>g-pk[0][i] && pk[1][i]==-1) { lt=g-pk[0][i]; lc=i; f=1;}
				 if (f==1) { c=qu.front(); qu.pop();
				             if (pk[0][lc]>0) { pk[1][lc]=pk[0][lc]; pn[1][lc]=pn[0][lc]; }
				             pc++; pk[0][lc]=g; pn[0][lc]=c;
						 }
					 }
					 t++;
				   }
			c=st.front(); cout << c; st.pop();
			while(!st.empty()) { cout << ' ' << st.front(); st.pop();}
			cout << endl;
		} 	                  		  
	return 0;
}

Measured memory_bytes: 1200
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			boolean[] flag=new boolean[11];
			int c1=sc.nextInt();
			int c2=sc.nextInt();
			int c3=sc.nextInt();
			flag[c1]=true;
			flag[c2]=true;
			flag[c3]=true;
			int limit=20-c1-c2;
			if(limit>10){
				System.out.println("YES");
			}else{
				int count=0;
				for(int i=limit;i>=1;i--){
					if(!flag[i]){
						count++;
					}
				}
				System.out.println(count>=4?"YES":"NO");
			}
		}
	}
}

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

zero = 0
minus = 0
for i in range(N):
    if A[i]<0:minus += 1
    elif A[i]==0:
        zero=1
    A[i] = abs(A[i])

if (minus%2==0)|(zero==1):
    print(sum(A))
else:
    print(sum(A)-2*min(A))

Measured memory_bytes: 19992
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main implements Closeable {

  private InputReader in = new InputReader(System.in);
  private PrintWriter out = new PrintWriter(System.out);

  public void solve() {
    int n = in.ni();
    int[] x = new int[n];
    for (int i = 0; i < n; i++) {
      x[i] = in.ni();
    }
    int result = Integer.MAX_VALUE;
    for (int target = -101; target <= 101; target++) {
      int cost = 0;
      for (int i = 0; i < n; i++) {
        cost += (target - x[i]) * (target - x[i]);
      }
      result = Math.min(result, cost);
    }
    out.println(result);
  }

  @Override
  public void close() throws IOException {
    in.close();
    out.close();
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

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

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

    public long nl() {
      return Long.parseLong(next());
    }

    public void close() throws IOException {
      reader.close();
    }
  }

  public static void main(String[] args) throws IOException {
    try (Main instance = new Main()) {
      instance.solve();
    }
  }
}


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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

vector<bool> isprime(55556, true);

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

    int N;
    cin >> N;

    isprime[0] = isprime[1] = false;
    for (int i = 2; i < isprime.size(); ++i)
    {
        if (isprime[i])
        {
            int j = i + i;
            for (; j < isprime.size(); j += i)
            {
                isprime[j] = false;
            }
        }
    }

    int j = 2;
    for (int i = 0; i < N; ++i)
    {
        while (j < isprime.size() && (j % 10 != 1 || !isprime[j])) ++j;
        cout << j << " ";
        ++j;
    }
    cout << "\n";
    return 0;
}



Measured memory_bytes: 256
<?php
  ini_set('memory_limit', '1G');
  $count=0;
  $prime=array();
  for($i=2;$i<=999999;$i++){
    $prime[$i]=1;
  }
  for($i=2;$i<=999999;$i++){
    if($prime[$i]==1){
      $count++;
      for($j=$i*2;$j<=999999;$j+=$i){
        $prime[$j]=0;
      }
    }
  }

  while($line=trim(fgets(STDIN))){
    $count=0;
    for($i=2;$i<=(int)$line;$i++){
      if($prime[$i]==1)
        $count++;
    }
    echo $count."\n";
  }

Measured memory_bytes: 158216
class DSU:
    def __init__(self, n):
        self._n = n
        self.parent_or_size = [-1] * n

    def merge(self, a, b):
        assert 0 <= a < self._n
        assert 0 <= b < self._n
        x, y = self.leader(a), self.leader(b)
        if x == y: return x
        if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x
        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x
        return x

    def same(self, a, b):
        assert 0 <= a < self._n
        assert 0 <= b < self._n
        return self.leader(a) == self.leader(b)

    def leader(self, a):
        assert 0 <= a < self._n
        if self.parent_or_size[a] < 0: return a
        self.parent_or_size[a] = self.leader(self.parent_or_size[a])
        return self.parent_or_size[a]

    def size(self, a):
        assert 0 <= a < self._n
        return -self.parent_or_size[self.leader(a)]

    def groups(self):
        leader_buf = [self.leader(i) for i in range(self._n)]
        result = [[] for _ in range(self._n)]
        for i in range(self._n): result[leader_buf[i]].append(i)
        return [r for r in result if r != []]# N = int(input())


N, M = map(int, input().split())

dsu = DSU(N)

for _ in range(M):
    A_M, B_M = tuple(map(int, input().split()))
    # 0始まりに合わせる
    A_M -= 1
    B_M -= 1
    leader_A_M = dsu.leader(A_M)
    leader_B_M = dsu.leader(B_M)
    dsu.merge(leader_A_M, leader_B_M)


# print(dsu.groups())
print(len(dsu.groups()) - 1)


Measured memory_bytes: 95652
#include  <stdio.h>
#include  <stdlib.h>
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int i;
	int p,q;
	p = n <= m ? n : m;
	q = n <= m ? m : n;
	for(i =0;i<q;i++)
		printf("%d",p);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {
  
  int a, b;
  cin >> a >> b;

  if(b >= a) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int X;
void input() {
  cin >> X;

  ;
}

void solve() {
  int ans = 0;

  rep(a, 1, X + 2) {
    int ss = a * (a + 1) / 2;
    if (ss >= X) {
      ans = a;
      break;
    }
  }

  // debug(ans);
  // ans--;

  // ans = ans + X - (ans * (ans + 1) / 2);
  cout << ans << endl;

  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

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

struct info {
    int y;
    int x;
    int dist;
};

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

int main() {
    int h, w;
    while (cin >> w >> h, h) {
        bool canThrough[h][w][h][w] = {};
        rep (i, h * 2 - 1) {
            //奇数、横向きの壁
            if (i % 2) {
                rep (j, w) {
                    bool in; cin >> in;
                    in = !in;
                    canThrough[i / 2][j][i / 2 + 1][j] = in;
                    canThrough[i / 2 + 1][j][i / 2][j] = in;
                }
            //偶数、縦向きの壁
            }
            else {
                rep (j, w - 1) {
                    bool in; cin >> in;
                    in = !in;
                    canThrough[i / 2][j][i / 2][j + 1] = in;
                    canThrough[i / 2][j + 1][i / 2][j] = in;
                }
            }
        }

        queue <info> que;
        que.push({0, 0, 1});
        vector <vector <int>> dist(h, vector <int> (w, 0));
        dist[0][0] = 1;
        while (!que.empty()) {
            info now = que.front();  que.pop();
            int y = now.y, x = now.x;
            rep (i, 4) {
                int toY = y + dy[i], toX = x + dx[i];
                if (toY < 0 || h <= toY || toX < 0 || w <= toX) continue;
                if (dist[toY][toX] != 0) continue;
                if (!canThrough[y][x][toY][toX]) continue;
                dist[toY][toX] = now.dist + 1;
                que.push({toY, toX, now.dist + 1});
            }
        }

        cout << dist[h - 1][w - 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3932
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    vi(h,N);
    rep(i,N) cin >> h[i];
    srt(h);
    int def = h[N-1] - h[0];
    rep(i,N-K+1){
        def = min(def,h[K+i-1] - h[i]);
    }
    cout << def << endl;
    return 0;
}

Measured memory_bytes: 640
#include<cstdio>

int main(){
	int a[82] = {};
	int b[82] = {};
	int c[82] = {};
	int n;
	int k,l,m,f;
	char t;
	int of;

	scanf("%d\n", &n);

	for(int i = 0; i < n; i++){
		for(int i = 0; i < 82; i++){
			c[i] = 0;
		}
		of = k = l = 0;
		scanf("%c", &t);
		while(t - 10){
			k++;
			a[k] = t - '0';
			scanf("%c", &t);
			if(k == 81){
				of = 1;
				while(t - 10){
					scanf("%c", &t);
				}
			}
		}
		scanf("%c", &t); 

		while(t - 10){
			l++;
			b[l] = t - '0';
			scanf("%c", &t);
			if(l == 81){
				of = 1;
				while(t - 10){
					scanf("%c", &t);
				}
			}

		}

		m = 0;
		f = 0;

		while(k - m){
			c[m] = a[k - m];
			m++;
		}
		m = 0;
		while(l - m){
			c[m] += b[l - m ] + f;
			f = 0;
			if(c[m] > 9){
				c[m] -= 10;
				f = 1;
			}
			m++;
		}

		while(f){
			c[m] += 1;
			f = 0;
			if(c[m] > 9){
				c[m] -= 10;
				f = 1;
			}
			m++;
		}

		if(k > m){
			m = k;
		}

		for(int i = 0; i < m; i++){
			if(m == 81 || of){
				printf("overflow");
				f = 1;
				i = m;
			}else{
				if((c[m - i -1]) || f){
					printf("%d", c[m - i - 1]);
					f = 1;
				}
			}
		}
		if(f - 1){
			printf("0");
		}
		printf("\n");
	}
	return 0;
}

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

int main() {
    string s, ret = "WA";
    cin >> s;
    int count_c = 0, count_not_small = 0;
    string abc = "abcdefghijklmnopqrstuvxyz";
    for (int i = 2; i < s.size() - 1; ++i) {
        if (s.at(i) == 'C') {count_c++;}
    }
    for (int i = 1; i < s.size(); ++i) {
        if (abc.find(s.at(i)) == string::npos) {count_not_small++;}
    }
    if (
        s.at(0) == 'A' &&
        count_c == 1 &&
        count_not_small == 1 /* 1 is C */
    ) {ret = "AC";}
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

template <typename T>
struct RectangleSum {
    vector<vector<T>> sum;

    RectangleSum(int h, int w) {
        init(h, w);
    }

    void init(int h, int w) {
        sum.resize(h + 1, vector<T>(w + 1, 0));
    }

    void add(int y, int x, T val) {
        y++;
        x++;
        sum[y][x] += val;
    }

    void build() {
        for (int i = 1; i < (int)sum.size(); i++) {
            for (int j = 1; j < (int)sum[i].size(); j++) {
                sum[i][j] += sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1];
            }
        }
    }

    T get(int top, int left, int bottom,
          int right) {  //[top, bottom), [left, right)
        return sum[bottom][right] - sum[bottom][left] - sum[top][right] +
               sum[top][left];
    }

    void print() {
        for (int y = 0; y < (int)sum.size() - 1; y++) {
            for (int x = 0; x < (int)sum[y].size() - 1; x++) {
                cout << get(y, x, y + 1, x + 1) << " ";
            }
            cout << endl;
        }
    }
};

signed main() {
    int n, k;
    cin >> n >> k;
    RectangleSum<int> rsb(2 * k, 2 * k);
    RectangleSum<int> rsw(2 * k, 2 * k);
    int cntb = 0, cntw = 0;
    int x, y;
    char c;
    rep(i, n) {
        cin >> x >> y >> c;
        x %= 2 * k;
        y %= 2 * k;
        rsb.add(y, x, c == 'B' ? 1 : -1);
        rsw.add(y, x, c == 'W' ? 1 : -1);
        cntb += c == 'B';
        cntw += c == 'W';
    }
    rsb.build();
    rsw.build();
    int ans = -INF;
    for (int y = 0; y < k; y++) {
        for (int x = 0; x < k; x++) {
            ans = max(ans, cntw + rsb.get(0, 0, y, x) +
                               rsb.get(y, x, y + k, x + k) +
                               rsb.get(y + k, x + k, 2 * k, 2 * k) +
                               rsb.get(y + k, 0, 2 * k, x) +
                               rsb.get(0, x + k, y, 2 * k));
            ans = max(ans, cntb + rsw.get(0, 0, y, x) +
                               rsw.get(y, x, y + k, x + k) +
                               rsw.get(y + k, x + k, 2 * k, 2 * k) +
                               rsw.get(y + k, 0, 2 * k, x) +
                               rsw.get(0, x + k, y, 2 * k));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 34688
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL long long
using namespace std;
LL read() {
    LL k = 0; char c = getchar();
    while(c < '0' || c > '9') c = getchar();
    while(c >= '0' && c <= '9')
        k = k * 10 + c - 48, c = getchar();
    return k;
}
int main() {
    int n = read(), m = read();
    cout << (n / m) + (n % m != 0);


    return 0;
}

Measured memory_bytes: 256
main=do
 getLine
 [a,b]<-map read.words<$>getLine
 p<-map read.words<$>getLine
 let x=length$filter(<=a+0)p
 let y=length$filter(\q->a<q&&q<=b)p
 let z=length$filter(b<)p
 print$minimum[x,y,z]

Measured memory_bytes: 1020
# C問題
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A, B, C, D = map(int, input().split())
E = lcm(C, D)
ac = A // C
bc = B // C
ad = A // D
bd = B // D
ae = A // E
be = B // E
if A % C == 0:
    ac -= 1
if A % D == 0:
    ad -= 1
if A % E == 0:
    ae -= 1
xx = bc - ac + bd - ad
yy = be - ae
print(B - A + 1 - xx + yy)

Measured memory_bytes: 5076
#include <cstdio>
#include <cmath>

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

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

typedef long long ll;

const int MAX = 100000 * 3;
const int mod = 1000000007;

int fact[MAX];
int rfact[MAX];

int mpow(int base, int exp){
  int ret = 1;

  while(exp){
    if(exp & 1)
      ret = ((ll)ret * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }

  return ret;
}

inline int nCm(int n, int m){
  return ((((ll)fact[n] * rfact[n - m]) % mod) * rfact[m]) % mod;
}

int main(){
  int n = getInt();
  int m = getInt();
  int k = getInt();

  fact[0] = 1;
  REP(i,MAX - 1) fact[i + 1] = ((ll)fact[i] * (i + 1)) % mod;
  REP(i,MAX) rfact[i] = mpow(fact[i], mod - 2);

  int ans = 0;
  for(int kk = 0; kk <= k; kk++){
    int tk = kk;
    int yk = k - kk;

    ll tate = nCm(n + tk + tk, tk);
    tate = (tate * (n + 1)) % mod;
    tate = (tate * mpow(n + tk + 1, mod - 2)) % mod;

    ll yoko = nCm(m + yk + yk, yk);
    yoko = (yoko * (m + 1)) % mod;
    yoko = (yoko * mpow(m + yk + 1, mod - 2)) % mod;

    const ll cmb = nCm(n + m + k + k, n + tk + tk);

    ans = (ans + (((tate * yoko) % mod) * cmb) % mod) % mod;
  }

  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll x, y;
    cin >> x >> y;
    ll cnt = abs(abs(x) - abs(y));
    if(y==0){
        cout << cnt + (x > y) << endl;
        return 0;
    }

    ll re = 0;
    bool xp = (x >= 0), yp = (y >= 0);
    if(xp&&yp){
        if (x > y) re = 2;
    }
    else if(xp^yp){
        re = 1;
    }
    else{
        if (x > y) re = 2;
    }
    cout << re + cnt << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long K, T;
bool arr[10005];

int main(){
	cin >> K >> T;
	long long maxi = 0;
	for(int i = 0; i < T; i++){
		long long tmp;
		cin >> tmp;
		maxi = max(maxi, tmp);
	}

	for(int i = 0; i < K; i += 2){
		if(maxi == 0){
			break;
		}
		arr[i] = true;
		maxi--;
	}

	int end;
	if(K % 2 == 0){
		end = K - 1;
	}else{
		end = K - 2;
	}

	for(int i = end; i >= 0 ; i -= 2){
		if(maxi == 0){
			break;
		}
		arr[i] = true;
		maxi--;
	}
	/*
	for(int i = 0; i < K; i++){
		if(arr[i]){
			cout << 1;
		}else{
			cout << 0;
		}
	}
	cout << endl;
	*/

	long long ret = 0;
	for(int i = 1; i < K; i++){
		if(arr[i] && arr[i-1]){
			ret++;
		}
	}
	cout << ret << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n,m;
int k;
int ans[105][105];
int X,Y;
int main(){
	cin>>n>>m;
	cin>>k;
	X=1;
	Y=1;
	for (int i=1;i<=k;i++){
		int x;
		cin>>x;
		for (int j=1;j<=x;j++){
			ans[X][Y]=i;
			if (X%2==1){
				Y++;
			}
			else{
				Y--;
			}
			if (Y>m){
				Y=m;
				X++;
			}
			if (Y<1){
				Y=1;
				X++;
			}
		}
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			cout<<ans[i][j]<<" ";
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S,T;
    cin >> S >> T;
   int n = S.size(); 
   int m = T.size();
   int count = 0;
    for(int i = 0; i < n;i++){
   if(S[i] == T[i] && n == m -1){ 
      count++; 
      }  
  }
  if(count == n){
      cout << "Yes" << endl;
  }
  else{
      cout << "No" <<endl;
  }
}

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

void chmax(int &a, int b) { if (a < b) a = b; }

int main() {
    int N; string S; cin >> N >> S;
    int res = 0;
    vector<vector<int> > dp(N+1, vector<int>(N+1, 0));
    for (int i = N-1; i >= 0; --i) {
        for (int j = N-1; j > i; --j) {
            if (S[i] == S[j]) chmax(dp[i][j], dp[i+1][j+1] + 1);
            chmax(res, min(dp[i][j], j-i));
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 98176
#include <iostream>

using namespace std;

int main() {
	int A, B, C;
	int K;

	cin >> A >> B >> C;
	cin >> K;

	int a = 0;

	while(B <= A) {
		B *= 2;
		a++;
	}

	while(C <= B) {
		C *= 2;
		a++;
	}

	if (a <= K)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int gcd(int a, int b){
  if (a%b==0){
    return(b);
  }
  else{
    return(gcd(b,a%b));
  }
}


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 2020; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j]);
//       }
//     }
//   }
//   return 0;
// }


// int factrial(int n){
//   if(n == 0) return 1;
//   return n*factrial(n-1);
// }

// int divisor(int a){
//   int cnt = 0;
//   for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
//   return cnt;
// }

// int comb(int n, int k){
//   return fact(n) / (fact(n-k)*fact(k));
// }

int answer(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

ll b[200010];
int main(){
  string s;
  cin >> s;
  int ans = 0;
  int num = 0;
  rep(i,s.size()){
    num += int(s[i] - '0');
  }
  int div = stoi(s);
  bool f = true;
  if(div % num != 0) f = false;
  answer(f);
}
  





Measured memory_bytes: 256
#include <stdio.h>

int gcd(int m, int n)
{
	int q;
	while (n != 0){
		q = n;
		n = m % n;
		m = q;
	}
	return (m);
}

int lcm(int m, int n)
{
	return (m / gcd(m, n) * n);
}

int main(void)
{
	int a, b;
	int c, d;
	
	while (scanf("%d %d", &a, &b) != EOF){
		printf("%d %d\n", gcd(a, b), lcm(a, b));
	}
	
	return (0);
}	

Measured memory_bytes: 596
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m, n;
    cin >> n >> m ;
    vs a(n), b(m);
    rep(i, n) {
        cin >> a[i];
    }
    rep(j, m) {
        cin >> b[j];
    }

    rep(i, n-m+1) {
        rep(j, n-m+1) {
            bool x = true;
            rep(k, m) {
                if(b[k] != a[i+k].substr(j, m)) x = false;
            }
            if(x) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
}

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

using namespace std;

int main() {
    int n, p[20], c[20], g;
    scanf("%d%d", &n, &g), g /= 100;
    for (int i = 0; i < n; i++)scanf("%d%d", p + i, c + i), c[i] /= 100;
    int ans = numeric_limits<int>::max();
    for (int i = 0; i < (1 << n); i++) {
        int cur = 0, curs = 0;
        for (int j = 0; j < n; j++)
            if (i >> j & 1)cur += p[j], curs += p[j] * (j + 1) + c[j];
        for (int j = n - 1; j >= 0; j--)
            if (curs < g)
                if (i >> j & 1 ^ 1) {
                    int res = (g - curs + j) / (j + 1);
                    if (res >= p[j]) cur += p[j], curs += p[j] * (j + 1) + c[j];
                    else cur += res, curs += p[j] * res;
                }
        ans = min(ans, cur);
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 256
#                          JAI SHREE RAM

import math; from collections import *
import sys; from functools import reduce

# sys.setrecursionlimit(10**6)
def get_ints(): return map(int, input().strip().split())
def get_list(): return list(get_ints())
def get_string(): return list(input().strip().split())
def printxsp(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")

UGLYMOD = int(1e9)+7; SEXYMOD = 998244353; MAXN = int(1e5)

# sys.stdin=open("input.txt","r");sys.stdout=open("output.txt","w")

# for _testcases_ in range(int(input())):
st = input()
n = s = e = w = False
if 'N' in st: n = True
if 'S' in st: s = True
if 'E' in st: e = True
if 'W' in st: w = True
print("Yes" if not(n^s) and not(e^w) else "No")


'''
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
THE LOGIC AND APPROACH IS MINE @luctivud ( UDIT GUPTA )
Link may be copy-pasted here if it's taken from other source.
DO NOT PLAGIARISE.
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
'''

Measured memory_bytes: 67752
#include<stdio.h>

int main(){
    int n,x=0,i,max=0;
    char s[101];
    char tmp;

    scanf("%d",&n);
    scanf("%s",s);

    for(i=0;i<n;i++){
        if(s[i]=='I'){
            x++;
            if(max<x){
                max = x;
            }
        }else{ x--;}
    }
    printf("%d",max);
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  vector<int> d(n);
  for(int i = 0; i < n; i++) {
    cin >> d.at(i);
  }
  
  int sum = 0;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      if (i == j) {
        continue;
      }
      sum += d.at(i) * d.at(j);
    }
  }
  cout << sum / 2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _LIBCPP_DEBUG 0
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 20;

int main(void){

    int K; cin>>K;
    int Vec[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    cout<<Vec[K-1]<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long a[1000000];
int main()
{
    int n,m;
    cin>>n>>m;
    long long sum=0;
    for (int i=0;i<n;i++)
        cin>>a[i],sum+=a[i];
    for (int i=0;i<n-1;i++)
    {
        if (a[i]+a[i+1]>=m)
        {
            int cur=i+1;
            cout<<"Possible"<<endl;
            for (int j=1;j<cur;j++)
                cout<<j<<endl;
            for (int j=n-1;j>=cur+1;j--)
                cout<<j<<endl;
            cout<<cur<<endl;
            return 0;
        }
    }
    cout<<"Impossible"<<endl;

}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>

using namespace std;

int main (int argc, char* argv[]) {
	int n, m;
	cin >> n >> m;

	vector<int> indices(m);
	for (int i = 0; i < m; i++) {
		cin >> indices[i];
	}
	sort(indices.begin(), indices.end());
	for (int i = 0; i < m - 1; i++) {
		indices[i] = indices[i + 1] - indices[i];
	}
	indices.erase(indices.end() - 1, indices.end());
	sort(indices.begin(), indices.end(), greater<int>());
	int total = 0;
	for (int i = n - 1; i < indices.size(); i++) {
		total += indices[i];
	}
	cout << total << endl;
}


Measured memory_bytes: 640
def solve(x):
    for b in xrange(-200, 200):
        a5 = (b ** 5) + x
        s = -1 if a5 < 0 else 1
        a = s * int(pow(abs(a5), 0.2) + 0.1)
        if a ** 5 == a5:
            return a, b

def test(x):
    a, b = solve(x)
    assert x == (a ** 5 - b ** 5)

test(33)
test(1)

from random import randint
for i in xrange(100):
    a = randint(-10 ** 3, 10 ** 3)
    b = randint(-10 ** 3, 10 ** 3)
    u = a ** 5 - b ** 5
    if abs(u) > 10 ** 9:
        continue
    test(a ** 5 - b ** 5)


x = int(raw_input())
a, b = solve(x)
print a, b


Measured memory_bytes: 95884
//Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define ff              first
#define ss              second
#define SZ(x)           ((int)(x).size())
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

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

int main() {
    cpp();
    double pi = 3.141592653589793238462643383279502884;
    double a, b, h, m;
    cin>>a>>b>>h>>m;
    double time = (h*60 + m);
    double thetha = ((2*pi)/60 - (2*pi)/(12*60))*time;
    double ans = a*a + b*b - 2*a*b*cos(thetha);
    ans = sqrt(ans);
    cout<<ps(ans, 9)<<endl;
    return 0;
}

Measured memory_bytes: 4248
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
class DirectedGraph {
    struct edge {
        int to;
        int cost;
    };

public:
    int V;
    vector<vector<edge>> G;

    DirectedGraph(int v) : G(v), V(v) {}

    void add_edge(int u, int v, int cost) {
        G[u].push_back({v, cost});
    }

    // O(E * logV)
    vector<int> dijkstra(int s) {
        vector<int> d(V, INF);
        d[s] = 0;

        priority_queue<P, vector<P>, greater<>> que;
        que.push({0, s});

        while (!que.empty()) {
            P  p = que.top(); que.pop();
            int v = p.second;
            if (d[v] < p.first) continue;

            for (edge e : G[v]) {
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push({d[e.to], e.to});
                }
            }
        }

        return move(d);
    }
};

signed main() {
    int N, M;
    cin >> N >> M;
    DirectedGraph dg = DirectedGraph(3 * N);

    for (int i = 0; i < M; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        dg.add_edge(u, v + N, 1);
        dg.add_edge(u + N, v + 2 * N, 1);
        dg.add_edge(u + 2 * N, v, 1);
    }

    int s, t;
    cin >> s >> t;
    s--; t--;

    vector<int> dis = dg.dijkstra(s);
    if (dis[t] == INF) cout << -1 << endl;
    else cout << dis[t] / 3 << endl;

    return 0;
}

Measured memory_bytes: 18944
#include <stdio.h>

int A[1000000],n;

int binarySearch(int);

int main(){
  int i,q,k,sum=0;

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

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&k);
    if(binarySearch(k)) sum++;
  }
  printf("%d\n",sum);

  return 0;
}

int binarySearch(int key){
  int left = 0;
  int right = n;
  int mid;
  while(left < right){
    mid = (left + right) / 2;
    if(key == A[mid]) return 1;
    if(key > A[mid]) left = mid + 1;
    else if(key < A[mid]) right = mid;
  }
  return 0;
}

Measured memory_bytes: 988
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <sstream>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

using ll = long long int;
using ii = pair<int, int>;
using iii = pair<int, ii>;

using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vvvi = vector<vi>;

bool res() {
	int a, b, c;
	cin >> a >> b >> c;
	if (!cin) return false;

	if (c < a - b) cout << 0 << '\n';
	else cout << c - (a - b) << '\n';

	return true;
}

int main() {
	while (res()) {}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=500,INF=1e18;
ll N,A[MAX_N][MAX_N],psm[MAX_N+1][MAX_N+1],trism[MAX_N+1][MAX_N+1],dp[MAX_N+1][MAX_N+1];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N;
	REP(i,N){
		REP(j,N-1){
			ll a;
			cin>>a;
			ll inx=j;
			if(j>=i){
				inx++;
			}
			A[i][inx]=a;
		}
	}
	REP(i,N){
		REP(j,N){
			psm[i+1][j+1]=A[i][j]+psm[i+1][j]+psm[i][j+1]-psm[i][j];
		}
	}
	REP(i,N+1){
		FOR(j,i+1,N+1){
			trism[i][j]=trism[i][j-1]+psm[j-1][j]-psm[i][j]-psm[j-1][j-1]+psm[i][j-1];
		}
	}
	REP(i,N+1){
		REP(j,N+1){
			dp[i][j]=INF;
		}
	}
	dp[0][0]=0;
	REP(i,N){
		FOR(j,i,N){
			FOR(x,j,N+1){
				dp[j][x]=min(dp[j][x],dp[i][j]+trism[j][x]+psm[x][i]-psm[j][i]);
			}
		}
	}
	ll ans=INF;
	REP(i,N+1){
		ans=min(ans,dp[i][N]);
	}
	REP(i,N+1){
		REP(j,N+1){
//			printf("dp[%lld][%lld]=%lld\n",i,j,dp[i][j]);
		}
	}		
	cout<<ans<<endl;
}

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

int main(){
int n,a[53];
int hantei[53];
char b[53];

for(int i=1;i<53;i++){
hantei[i]=0;
}

cin>>n;

for(int i=1;i<=n;i++){
cin>>b[i]>>a[i];

if(b[i]=='S'){
hantei[0+a[i]]=1;
}

if(b[i]=='H'){
hantei[13+a[i]]=1;
}

if(b[i]=='C'){
hantei[26+a[i]]=1;
}

if(b[i]=='D'){
hantei[39+a[i]]=1;
}

}

for(int i=1;i<53;i++){
if(hantei[i]==0){

if(i<=13){
cout<<"S "<<(i-1)%13+1<<endl;
}

else if(i<=26){
cout<<"H "<<(i-1)%13+1<<endl;
}

else if(i<=39){
cout<<"C "<<(i-1)%13+1<<endl;
}

else if(i<=52){
cout<<"D "<<(i-1)%13+1<<endl;
}

}
}

return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

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

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}


int main(){
    ll N,B,A;
    cin >> N >> A >> B;
    ll count = 0;
    ll sum = A+B;
    ll rep_num = N / (A+B);

    if(N - rep_num*sum < A) {
        cout << rep_num*A + (N - rep_num*sum) << endl;
    }else {
        cout << rep_num*A + A << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3608
object Main {

  import scala.io.StdIn

  def main(args: Array[String]): Unit = {
    val n = StdIn.readInt
    val hs = StdIn.readLine.split(" ").map(_.toInt)

    val dp = Array.fill(n)(0)
    for (i <- (0 until n).reverse) {
      i match {
        case _ if i == n-1 => ()
        case _ if i == n-2 => dp(i) = Math.abs(hs(i) - hs(i+1))
        case _ => dp(i) = Math.min(Math.abs(hs(i) - hs(i+1)) + dp(i+1), Math.abs(hs(i) - hs(i+2)) + dp(i+2))
      }
    }
    println(dp(0))
  }
}

Measured memory_bytes: 41440
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define END return 0
typedef int64_t ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a % b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size(),
        m = t.size(),
        ans = inf;
    rep(i, n - m + 1) {
        int rewrite = 0;
        rep(j, m)
            if (s[i + j] != t[j]) rewrite++;
        ans = min(ans, rewrite);
    }
    cout << ans << endl;
}

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

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

    if(K == 1){
        cout << 0 << endl;
    } else {
        cout << N - K << endl;
    }
}

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

int main() {
  int N, M, X;
  cin >> N >> M >> X;

  vector<int> row(N + 1, 0);
  rep(i, M) {
    int a;
    cin >> a;
    row[a] = 1;
  }

  int to_0 = 0;
  for (int i = X; i > 0; i--)
    to_0 += row[i];

  int to_N = 0;
  for (int i = X; i < N; i++)
    to_N += row[i];

  cout << min(to_0, to_N) << endl;
}

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

#define mambet wws_kai_rayon
#define FranXX Delphynium_Argentia_Genista_Chlorophytim

#define psn ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define mp make_pair
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define ll long long
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const long long MXN = 6e5 + 1;
const long long MNN = 3 * 1e3 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e16 + 1;
const long long OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

llong ans, cnt;

int main(){
	psn;
	string s;
	cin >> s;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'W'){
			ans += cnt;
		}else{
			cnt++;
		}
	}cout << ans;
	return 0;
}


Measured memory_bytes: 1356
#include <bits/stdc++.h>
using namespace std;
#define BIGINF (int) 4e18 + 7
#define MOD7 1000000007
#define MOD9 1e9 + 9
#define INF  (int)2e9 + 7
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
typedef long long ll;
typedef long double ld;
typedef string str;
typedef double d;
typedef unsigned u;
typedef unsigned long long ull;

int main () {
    //freopen("inputf.txt", "r", stdin);
    //freopen("outputf.txt", "w", stdout);
    int n, k;
    cin >> n >> k;
    int a[105];
    bool dp[100005];
    memset(dp, false, sizeof(dp));
    dp[0] = false;
    for (int i = 0; i < n; i++) {
    	cin >> a[i];
    }

    for (int i = 1; i <= k; i++) {
    	for(int j = 0; j < n; j++) {
    		if (i - a[j] >= 0) {
    			if (dp[i - a[j]] == false) {
    				dp[i] = true;
    				break;
    			}
    		}
    	}
    }
    if (dp[k]) printf("First");
    else printf("Second");

    return 0;
}



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

int main() {
    ll N; cin >> N;
    ll ans = 0;
    for (int i = 0; i < N; i++){
        ll k = (N-i)*(N+1-i) / 2;
        ans += k;
    }
    vector<vector<int>> to(N+1);
    rep(i, N-1){
        ll u, v; cin >> u >> v;
        if(u < v){
            ans -= u*(N-v+1);
        } else {
            ans -= v*(N-u+1);
        }
    }

    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 7948
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n, i, j, s;
		while(true) {
			s = 0;
			int m[] = {0, 0};
			n = sc.nextInt();
			if(n == 0)	break;
			int a[] = new int[n];
			for(i = 0; i < n; i ++) {
				a[i] = sc.nextInt();
				if(a[i] > s) s = a[i];
			}
			for(i = 0; i < n; i ++) {
				for(j = 0; j < n; j ++) {
					if(i == j) continue;
					if(a[j] - a[i] < 0) {
						m[0] = a[i];
						m[1] = a[j];
					}else {
						m[0] = a[j];
						m[1] = a[i];
					}
					if(s > m[0] - m[1]) {
						s = m[0] - m[1];
					}
				}
			}
			System.out.println(s);
		}
		sc.close();
	}

}


Measured memory_bytes: 47708
while(1):
    [n,m]=[int(x) for x in raw_input().split()]
    if n==0:
        break
    else:
        C=[[9999 for x in range(m+1)] for y in range (m+1)]
        T=[[9999 for x in range(m+1)] for y in range (m+1)]
        for i in range(n):
            [a,b,c,t]=[int(x) for x in raw_input().split()]
            C[a][b]=c
            C[b][a]=c
            T[a][b]=t
            T[b][a]=t
        for i in range(1,m+1):
            C[i][i]=0
            T[i][i]=0
        for k in range(1,m+1):
            for i in range(1,m+1):
                for j in range(i,m+1):
                    if C[i][j]>C[i][k]+C[k][j]:
                        C[i][j]=C[i][k]+C[k][j]
                        C[j][i]=C[i][k]+C[k][j]
                    if T[i][j]>T[i][k]+T[k][j]:
                        T[i][j]=T[i][k]+T[k][j]
                        T[j][i]=T[i][k]+T[k][j]
        Q=int(raw_input())
        for i in range(Q):
            [p,q,r]=[int(x) for x in raw_input().split()]
            if r:
                print T[p][q]
            else:
                print C[p][q]

Measured memory_bytes: 4836
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll n;
	scanf("%lld",&n);
	printf("Christmas ");
	rep(i,n,25)printf("Eve ");
}

Measured memory_bytes: 128