akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i < (n); ++i)
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; }
template<class T> inline bool change(T& a, T b) { if (a != b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;

ll a[300000];

int main(){
    int n,k; cin >> n >> k;
    for(int i=1;i<=n;i++) cin >> a[i];
    for(int i=k+1;i<=n;i++){
        if(a[i]>a[i-k]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 5180
import math

a,b,h,m = map(int,input().split())


h = h + m /60
h_sin = math.sin(math.radians(h/12*360))
h_cos = math.cos(math.radians(h/12*360))
m_sin = math.sin(math.radians(m/60*360))
m_cos = math.cos(math.radians(m/60*360))

ans = math.sqrt((h_sin*a-m_sin*b)**2+(h_cos*a-m_cos*b)**2)

print(ans)

Measured memory_bytes: 9580
#include <bits/stdc++.h>
#include <set>  
using namespace std;
 
int main() {
  int n;
  cin >>n;
  long ans =0;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    while(a%2==0){
      a /=2;
      ans++;
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
import java.io.*;

public class Main {
	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder out = new StringBuilder();
		String line;
		try {
			while (!(line = reader.readLine()).equals("0")) {
				int sum = 0;
				for (int i = 0; i < line.length(); ++i)
					sum += Character.digit(line.charAt(i), 10);
				out.append(sum + "\n");
			}
			System.out.print(out);
		} catch (Exception e) {
		}
	}
}


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

string res,s;
bool solve(int pos, int sum){
    if(pos == 4)
        return (sum == 7);
    res += '+';
    if(solve(pos+1, sum + s[pos]-'0'))
        return true;
    res.pop_back();
    res += '-';
    if(solve(pos+1, sum - (s[pos]-'0') ))
        return true;
    res.pop_back();
    return false;
}

int main() {
    cin >> s;
    bool found = solve(1,s[0]-'0');
    printf("%c%c%c%c%c%c%c=7\n", s[0], res[0], s[1], res[1], s[2], res[2], s[3]);
    return 0;
}


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

using namespace std;
using namespace atcoder;

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

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
  os << "[";
  REP(i, SZ(v)) {
    if (i) os << ", ";
    os << v[i];
  }
  return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
  return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 998244353;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;

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

  int n, m; cin >> n >> m;
  vll a(n), b(m);
  REP(i, n) {
    cin >> a[i];
  }
  REP(i, m) {
    cin >> b[i];
  }

  auto v = convolution(a, b);

  REP(i, n + m - 1) {
    cout << v[i] << " ";
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 27308
package main

import "fmt"

func main() {
  var N, M, Q int
  
  fmt.Scanf("%d %d %d\n", &N, &M, &Q)
  a := make([]int, Q)
  b := make([]int, Q)
  c := make([]int, Q)
  d := make([]int, Q)
  for i := 0 ; i < Q; i++ {
    fmt.Scanf("%d %d %d %d\n",  &a[i], &b[i], &c[i], &d[i])
  }
  A := make([]int, N)
  for i := 0; i < N; i++ {
    A[i] = 1
  }
  
  mx := 0
  for {
    tmp := 0
    for i := 0; i < Q; i++ {
      if A[b[i]-1] - A[a[i]-1] == c[i] {
        tmp += d[i]
      }
    }
    if tmp > mx {
      mx = tmp
    }
    
    A[N-1]++
      for i := 0; i < N; i++ {
        if A[N-i-1] / (M+1) == 0 {
          break
        }
        A[N-i-1] = 0
        if i == N-1 {
          fmt.Println(mx)
          return
        }
        A[N-i-2]++
      }
    for i := 1; i < N; i++ {
      if A[i] == 0 {
        A[i] = A[i-1]
      }
    }
  }
}

Measured memory_bytes: 1856
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t,u;
  int a,b;
  cin >> s >> t >> a >> b >> u;
  if(u==s){
    cout << a-1 << " " << b << endl;
  }else{
    cout << a << " " << b-1 << endl;
  }
}
  

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

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

struct edge{int to, cost;};

int n, d[100010];
vector<edge> g[100010];

void dijkstra(int s) {
  priority_queue<PII, vector<PII>, greater<PII>> que;
  fill(d, d+n, INF);
  d[s] = 0;
  que.push(PII{0, s});

  while(que.size()) {
    PII p = que.top(); que.pop();
    // cout << p.first << "," << p.second << endl;
    int v = p.second;
    if(d[v] < p.first) continue;
    for(edge e: g[v]) {
      // cout << d[e.to] << ":" << d[v] << ":" << e.cost << endl;
      if(d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(PII{d[e.to], e.to});
      }
    }
  }
}

int cnt1[300010], cnt2[300010];
signed main(void)
{
  int m, s, t;
  cin >> n >> m >> s >> t;
  s--, t--;
  REP(i, m) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    g[x].PB({y, 1});
    g[y].PB({x, 1});
  }

  dijkstra(s);
  // REP(i, n) cout << d[i] << " "; cout << endl;
  int dist = d[t]-1;
  REP(i, n) if(d[i] != INF) cnt1[d[i]]++;
  dijkstra(t);
  REP(i, n) if(d[i] != INF) cnt2[d[i]]++;

  // cout << dist << endl;
  ll ret = 0;
  REP(i, dist) {
    // cout << i << "," << cnt1[i] << " " << dist-i-1 << "," << cnt2[dist-i-1] << endl;
    ret += cnt1[i] * cnt2[dist-i-1];
  }
  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 16256
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    static final BigInteger MOD = BigInteger.valueOf(1000000007);

    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        BigInteger[] a = new BigInteger[k + 1];

        for (int i = 1; i <= k; i++) {
            if (n - k - i + 1 < 0) {
                System.out.println(0);
                continue;
            }
            a[i] = nCr(n - k + 1, i).multiply(nCr(k - 1, i - 1)).mod(MOD);
            System.out.println(a[i]);
        }
    }

    private static BigInteger nCr(int a, int b) {
        BigInteger ret = BigInteger.ONE;
        for (int i=a; i > a-b; i--) {
            ret = ret.multiply(BigInteger.valueOf(i));
        }
        for (int i=1; i <= b; i++) {
            ret = ret.divide(BigInteger.valueOf(i));
        }
        return ret;
    }

//    public static BigInteger nCr(int n, int r) {
//        BigInteger num = BigInteger.ONE;
//        for (int i = 1; i <= r; i++) {
//            num = num.multiply(BigInteger.valueOf(n - i + 1)).divide(BigInteger.valueOf(i)).mod(MOD);
//        }
//        return num;
//    }
}

Measured memory_bytes: 275372
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int H = sc.nextInt();
        int W = sc.nextInt();
        System.out.println((N - H + 1) * (N - W + 1));
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep1c(i, n) for (int i = 1; i <= (int)(n); i++)
#define repc0(n, i) for (int i = (int)(n); i >= 0; i--)

using namespace std;
typedef long long ll;

ll A, B;

ll f(ll a) {
  int r = a%4;
  if(r==0) return a;
  else if(r==1) return 1ll;
  else if(r==2) return a | 1ll;
  else return 0ll;
}

void solve() {
  ll res = 0ll;
  if(A==B) res = B;
  else if(A==0) res = f(B);
  else res = f(A-1) ^ f(B);
  cout << res << endl;
}

int main() {
  cin >> A >> B;
  solve();
  return 0;
}

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

signed main() {
  char a, b, c, d;
  cin >> a >> b >> c >> d;
  bool ok = false;
  for (int i = 0; i < 1; i++) {
    if (a==b && a==c) {
      cout << "No" << endl;
      break;
    }
    if (a==b && c==d) {
      cout << "Yes" << endl;
      ok = true;
    }
    
    if (a==c && b==d) {
      cout << "Yes" << endl;
      ok = true;
    }
  
    if (a==d && b==c) {
      cout << "Yes" << endl;
      ok = true;
    }
  
    if (ok == false) cout << "No" << endl;
  }
}

Measured memory_bytes: 256
// Problem : D - Dice in Line
// Contest : AtCoder Beginner Contest 154
// URL : https://atcoder.jp/contests/abc154/tasks/abc154_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

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

#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);
#define endl "\n"

const int N = (int)2e5+5;
int a[N], pre[N];

int32_t main()
{
	IOS;
	int t = 1;
	//cin >> t;	
	for(int msi = 1; msi <= t; msi++)
	{
		int n, k;
		cin >> n >> k;
		for(int i = 1; i <= n; i++)
			cin >> a[i];
		for(int i = 1; i <= n; i++)
			pre[i] = pre[i-1] + a[i];
		int maxs = -1;
		for(int i = 1; i+k - 1<= n; i++)
		{
			if(maxs < pre[i+k-1]-pre[i-1])
				maxs = pre[i+k-1]-pre[i-1];
		}
		double ans = (maxs+k)/2.0000;
		cout << fixed << setprecision(20) << ans << endl;
	}	
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 100100;
string code;
int bal[maxn], suf_bal[maxn];
 
int main() {
    cin>>code;
    int n = code.length();
    code = "$" + code;
    for(int i=1;i<=n;i++) {
        int c = -1;
        if(code[i] == 'g') c = 1;
        bal[i] = bal[i-1] + c;
    }
    suf_bal[n] = bal[n];
    suf_bal[n+1] = 10000000;
    for(int i=n-1;i>=1;i--) {
        suf_bal[i] = min(bal[i], suf_bal[i+1]);
    }
 
    int my_bal = 0, carry = 0;
    int br = 0;
 
    for(int i=1;i<=n;i++) {
        if(my_bal && code[i] == 'g' && suf_bal[i] - carry > 0) {
            br++;
            carry += 2;
            my_bal--;
        }
        else if(code[i] == 'p') {
            my_bal --;
        }
        else if(code[i] == 'g') {
            my_bal++;
        }
    }
    cout<<br;
 
    return 0;
}

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

int n, Head[M], Next[M], Go[M], Cnt = 0, len = 0, v;

void addedge(int x, int y) {
	Go[++Cnt] = y;
	Next[Cnt] = Head[x];
	Head[x] = Cnt;
}

void DFS(int x, int f = 0, int dep = 0) {
	if(len < dep) len = dep, v = x;
	for(int T = Head[x]; T; T = Next[T]) if(Go[T] != f) DFS(Go[T], x, dep + 1);
}

int main() {
	scanf("%d", &n);
	for(int i = 1; i < n; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		addedge(a, b);
		addedge(b, a);
	}
	DFS(1);
	DFS(v);
	if(len % 3 == 1) puts("Second"); else puts("First");
	return 0;
}

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

int gcd(int u, int v) {
  int r;
  while(v != 0) {
    r = u % v;
    u = v;
    v = r;
  }
  return u;
}

int main() {
  int N;
  cin >> N;
  vector<int> vec(N), left(N), right(N);
  for (int i = 0; i < N; i++) cin >> vec.at(i);
  
  // left.at(i)はvec.at(0)からvec.at(i - 1)までのgcdを求める関数
  // left.at(0) = 0
  // left.at(1) = gcd(vec.at(0), vec.at(0)) = vec.at(0)
  // left.at(2) = gcd(left.at(1), vec.at(1))
  // left.at(N - 1) = gcd(left.at(N - 2), vec.at(N - 2))
  
  // right.at(i)はvec.at(i + 1)からvec.at(N - 1)までのgcdを求める関数
  // right.at(0) = gcd(vec.at(1), right.at(1))
  // right.at(N - 3) = gcd(vec.at(N - 2), right.at(N - 2))
  // right.at(N - 2) = gcd(vec.at(N - 1), vec.at(N - 1)) = vec.at(N - 1)
  // right.at(N - 1) = 0
  
  left.at(1) = vec.at(0);
  right.at(N - 2) = vec.at(N - 1);
  for(int i = 1; i < N - 1; i++) {
    left.at(i + 1) = gcd(left.at(i), vec.at(i));
    right.at(N - 2 - i) = gcd(right.at(N - 1 - i), vec.at(N - 1 - i));
  }
  int ans = max(left.at(N - 1), right.at(0));
  for(int i = 1; i < N - 1; i++) {
    if (ans < gcd(left.at(i), right.at(i))) ans = gcd(left.at(i), right.at(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <algorithm>

using namespace std;

const long long mod = 1000000007;
long long n , x;
long long a[210];
long long dp[210][120000];
long long ans;
bool cmp ( long long x1 , long long x2 ) {
	return x1 > x2;
}
void work () {
	long long i , j;
	scanf ( "%lld%lld" , &n , &x );
	for ( i = 1 ; i <= n ; i++ ) {
		scanf ( "%lld" , &a[i] );
	}
	sort ( a + 1 , a + 1 + n , cmp );
	dp[0][x] = 1;
	for ( i = 0 ; i < n ; i++ ) {
		for ( j = 0 ; j <= x ; j++ ) {
			dp[i+1][j] = (dp[i+1][j] + dp[i][j] * (n-i-1)) % mod;
			dp[i+1][j%a[i+1]] = (dp[i+1][j%a[i+1]] + dp[i][j]) % mod;
		}
	}
	for ( i = 0 ; i <= x ; i++ ) {
		ans = (ans + dp[n][i] * i) % mod;
		//printf ( "%lld\n" , dp[n][i] );
	}
	printf ( "%lld\n" , ans );
}
int main () {
	work ();
	return 0;
}


Measured memory_bytes: 187520
package main


import (
    "fmt"
)

func main() {
  var N,K,X int
  var S   int = 0

  fmt.Scan(&N, &K)

  for i := 0; i < N; i++ {
    fmt.Scan(&X)

    if X * 2 < 2*(K - X) {
      S += X * 2
    } else {
      S += (K - X) * 2

    }
  }


  fmt.Println(S)


}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to));
#define sort(a) sort(a.begin(), a.end())

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

int main() {
  int H, W, h, w;
  cin >> H >> W;
  cin >> h >> w;

  cout << H * W - h * W - w * H + w * h << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    float arr[n];
    float sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        sum+=(1/arr[i]);
    }
    cout<<(1/sum)<<endl;
    return 0;
}


Measured memory_bytes: 256
H,W,M = map(int,input().rstrip().split(" "))
B = set()
Hc = [0 for i in range(H)]
Wc = [0 for i in range(W)]
Hl = []
Wl = []
for i in range(M):
    h,w = map(int,input().rstrip().split(" "))
    Hc[h-1] += 1
    Wc[w-1] += 1
    B.add((h-1) * W + w-1)
Hm = max(Hc)
Wm = max(Wc)
ans = 0
for i in range(H):
    if Hc[i] == Hm:
        Hl.append(i)
for i in range(W):
    if Wc[i] == Wm:
        Wl.append(i)
if len(Hl) * len(Wl) > M:
    ans = Hm + Wm
else:
    for h in Hl:
        for w in Wl:
            if not h * W + w in B:
                ans = Hm + Wm
                break
    if ans == 0:
        ans = Hm + Wm - 1
print(ans)

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

int main() {
  int k;
  string op = "";
  priority_queue<int> que;
  do {
    cin >> op;
    if (op == "insert") {
      cin >> k;
      que.push(k);
    } else if (op == "extract") {
      cout << que.top() << endl;
      que.pop();
    }
  } while (op != "end");
}



Measured memory_bytes: 7072
import java.io.*;
import java.math.*;
import java.util.*;


public class Main{
    static long MOD = 998244353 ;
    static long [] fac;
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        // Start writing your solution here. -------------------------------------
        //int t = sc.nextInt();
        int t = 1;
        while(t-- > 0)
        {
            long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong();
            long x = Math.min(b - 1, c);
            out.println(a * x / b);
        }
        out.close();
    }
    public static long C(int n, int m)
    {
        if(m == 0 || m == n) return 1l;
        if(m > n || m < 0) return 0l;
        long res = fac[n] * quickPOW((fac[m] * fac[n - m]) % MOD, MOD - 2) % MOD;

        return res;
    }
    public static long quickPOW(long n, long m)
    {
        long ans = 1l;
        while(m > 0)
        {
            if(m % 2 == 1)
                ans = (ans * n) % MOD;
            n = (n * n) % MOD;
            m >>= 1;
        }
        return ans;
    }
    public static int gcd(int a, int b)
    {
        if(a % b == 0) return b;
        return gcd(b, a % b);
    }
    public static long solve(long x, long[] res){
        int n = res.length;
        long a = x / n;
        int b = (int)(x % n);
        return res[n - 1] * a + res[b];
    }
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    //--------------------------------------------------------
}

Measured memory_bytes: 32932
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;*/
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
typedef long long ll;
typedef pair<ll, ll> Pa;

/*
template <std::int_fast64_t Modulus> class modint {
	using u64 = std::int_fast64_t;
public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept {
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept {
		u64 exp = Modulus - 2;
		while (exp) {
			if (exp % 2) {
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
#pragma endregion

typedef modint<MOD> m;
m func[400001];
void funcinit(int N)
{
	func[0] = 1;
	for (int i = 1; i <= N; i++)
	{
		func[i] = func[i - 1] * i;
	}
}
m comb(m n, m r)
{
	if (n.a <= 0 || n.a < r.a)
	{
		return 0;
	}
	return func[n.a] / (func[r.a] * func[(n - r).a]);
}*/

string s;
int main() {
	cin >> N >> A >> B;
	if (A == 0 && B == 0) cout << 0;
	else cout << ((N / (A + B)) * A) + min((N % (A + B)), A);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int min(int a, int b)
{
    return a < b ? a : b;
}
int main()
{
    int n;
    scanf("%d", &n);
    int a[n];
    int dp[n];
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    dp[0] = 0;
    dp[1] = abs(a[0] - a[1]);
    for (int i = 2; i < n; i++)
    {
        dp[i] = min((dp[i - 1] + abs(a[i] - a[i - 1])), (dp[i - 2] + abs(a[i] - a[i - 2])));
    }
    printf("%d\n", dp[n - 1]);
}

Measured memory_bytes: 1024
x,y=map(int,input().split())
if x==y:
    print(0)
    exit()
def solve(x,y):
    if x>=0 and y>=0:
        if x<=y:
            return y-x
        elif y==0:
            return x+1
        else:
            return x-y+2
    elif x<0 and y<0:
        if x>y:
            return x-y+2
        else:
            return y-x
    elif x>=0 and y<0:
        return x-y+1
    else:
        return y-x

if x*y>=0:
    print(solve(x,y))
else:
    print(min(solve(-x,y)+1,solve(x,-y)+1,solve(x,y)))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;

int main(){
    int a,b;
    cin >> a >> b;
    if((a*b)%2==0) puts("Even");
    else puts("Odd");
    return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;


class UnionFind{
private:
  vector<int> par, rank;
public:
  UnionFind(int n){
	par.assign(n, 0);
	rank.assign(n, 0);
	for(int i=0;i<n;++i)
	  par[i] = i;
  }

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

  void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;

	if(rank[x] < rank[y])
	  par[x] = y;
	else{
	  par[y] = x;
	  if(rank[x] == rank[y])
		++rank[x];
	}
  }

  bool same(int x, int y){
	return find(x) == find(y);
  }
};

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

  int N;
  cin >> N;
  int X = 0, Y = 0;
  VI xs(N), ys(N);
  REP(i,N){
	cin >> xs[i];
	X ^= xs[i];
  }
  REP(i,N){
	cin >> ys[i];
	Y ^= ys[i];
  }
  xs.PB(X);
  ys.PB(Y);

  map<int,int> xmemo;
  REP(i,N+1) xmemo[xs[i]]++;
  REP(i,N+1) xmemo[ys[i]]--;
  bool ok = true;
  for(auto&& p: xmemo){
	if(p.SS != 0)
	  ok = false;
  }
  if(!ok){
	cout << -1 << endl;
	return 0;
  }

  int ids = 0, e = 0;
  map<int,int> id;
  REP(i,N+1){
	if(i == N || xs[i] != ys[i]){
	  if(i < N) ++e;
	  if(!id.count(xs[i]))
		id[xs[i]] = ids++;
	  if(!id.count(ys[i]))
		id[ys[i]] = ids++;
	}
  }

  UnionFind uf(ids);
  REP(i,N+1)
	if(xs[i] != ys[i] || i == N)
	  uf.unite(id[xs[i]], id[ys[i]]);

  int c = 0;
  REP(i,ids){
	if(uf.find(i) == i)
	  ++c;
  }
  //cout <<e<<","<<c<<endl;
  cout << e+c-1 << endl;

  return 0;
}


Measured memory_bytes: 11248
#include <bits/stdc++.h>
#define int long long 
#define pb push_back
#define fr first
#define sc second
#define sz(v) ((int)(v).size())
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repd(i,a,p) for(int i=a-1;i>=p;i--) 
#define M 1000000007
#define vi vector<int>
#define vp vector<pair<int,int> >
#define ml map<int,int>
#define MPI 3.1415926536
using namespace std;
int temp=0,r,l,w,k=0,m1,e,p,q,ans,k1=0,k2=0,d=0,a=0,b=0,s=0,x,y,min1=1000000010,max1=0,m,c=0,t=0,i,n,c1=0,tot=0,t1,k4=0,c2=0,j=0,k3=0;char ch,ch1,ch2;string s1,s2,s3;
signed main()
{
cin>>s1>>s2;
n=s1.size();
m=s2.size();
int dp[n+1][m+1];
rep(i,0,n+1)
{
	rep(j,0,m+1)
	{
		if(i==0||j==0)
		dp[i][j]=0;
	}
}
rep(i,1,n+1)
{
	rep(j,1,m+1)
	{
		if(s1[i-1]==s2[j-1])
		dp[i][j]=1+dp[i-1][j-1];
		else
		dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	}
}
while(n>0&&m>0)
{
	if(s1[n-1]==s2[m-1])
	s3+=s1[n-1],n--,m--;
	else if(dp[n][m]==dp[n-1][m])
	n--;
	else
	m--;
}
reverse(all(s3));
cout<<s3;
}

Measured memory_bytes: 70656
#include <stdio.h>

int main(void){
    int i,j,n;float m[8],e;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        for(j=0;j<8;j++){scanf("%f",&m[j]);}
	m[2] -= m[0];
	m[3] -= m[1];
	m[6] -= m[4];
	m[7] -= m[5];
        //e=(m[3]-m[1])*(m[6]-m[4])-(m[7]-m[5])*(m[2]-m[0]);
	if(m[7] * m[2] == m[6] * m[3]) printf("YES\n");
	else printf("NO\n");
        //printf("%s\n",(e==0)?"YES":"NO");
    }
    return 0;
}
/*
int main(){
      
    int n;
      
    float x[4], y[4];
      
    scanf("%d",&n);
      int i, loop;
    for(loop = 0; loop < n; loop++){
        for(i = 0; i < 4; i++){
		scanf("%f",&x[i]);
		scanf("%f",&y[i]);
        }
        x[1] -= x[0];
        y[1] -= y[0];
        x[3] -= x[2];
        y[3] -= y[2];
        if(x[3] * y[1] == y[3] * x[1]){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
      
    return 0;
}
*/



Measured memory_bytes: 2028
n, m = map(int, input().split())

MOD = 10**9 + 7

if abs(n - m) >= 2:
    print(0)
else:    
    f1 = 1
    for i in range(n):
        f1 = f1*(n-i)%MOD
    f2 = 1
    for i in range(m):
        f2 = f2*(m-i)%MOD
        
    if abs(n - m) == 1:
        print(f1*f2%MOD)
        
    elif n == m:
        print(f1*f2*2%MOD)

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

int main()
{
  int n, k;
  cin >> n >> k;

  int x = (n - 1) * (n - 2) / 2;
  if (k > x) {
    cout << -1 << endl;
    return 0;
  }

  vector<pair<int, int>> ans;
  for (int i = 1; i < n; i++) {
    ans.emplace_back(i, n);
  }

  vector<pair<int, int>> edge;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < i; j++) {
      edge.emplace_back(i, j);
    }
  }
  for (int i = 0; i < x - k; i++) {
    ans.push_back(edge[i]);
  }
  cout << ans.size() << endl;
  for (int i = 0; i < int(ans.size()); i++) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
}


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

using namespace std;
int main(int argc, char *argv[]) {
	string s;
	cin >> s;
	
	string ans = "Yes";
	for (int i = 0; i < s.size(); i++) {
		if ((i + 1) % 2 == 1) {
			if (s[i] == 'L') {
				ans = "No";
				break;
			}
		} else {
			if (s[i] == 'R') {
				ans = "No";
				break;
			}
		}
	}
	
	cout << ans << endl;
}

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

int sod(long a) {
  int b = 0;
  while (a > 0) b += a % 10, a /= 10;
  return b;
}

int main() {
  string S;
  cin >> S;
  cout << max(sod(stol(S)), 9 * ((int)S.size() - 1) + (S.front() - '1')) << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>
#include <bitset>
#include <queue>

using namespace std;

int main(){
    int N;
    char S[100];

    cin >> N;
    for(int i = 0; i < N; i++) cin >> S[i];

    bool flag = false;
    for(int i = 0; i < N; i++){
        if(S[i] == 'Y') flag = true;
    }

    if(flag) cout << "Four" << endl;
    else cout << "Three" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;

    int ans = 0;
    int x = 0;
    rep(i, n) {
        if (s[i] == 'I') x++;
        else x--;
        ans = max(ans, x);
    }

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

Measured memory_bytes: 256
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!();
    let a = get!();
    let b = get!();
    
    let mut ans = std::cmp::min(b - 1, n - a);
    let x = (b - a) / 2;
    if a + x == b - x {
        ans = std::cmp::min(ans, x);
    }
    let u = ((b - a) - 1) / 2;
    if 1 + u == b - a - u {
        ans = std::cmp::min(ans, a + u);
    }
    let v = (n - (a + (n - b + 1))) / 2;
    if a + (n - b + 1) + v == n - v {
    	ans = std::cmp::min(ans, (n - b + 1) + v);
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
using System;
using System.Web;
using System.IO;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using static System.Math;
 

class P
{
    static void Main()
    {
        int[] nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        List<int>[] revedge = Enumerable.Repeat(0, nm[0]).Select(_ => new List<int>()).ToArray();
        List<int>[] edge = Enumerable.Repeat(0, nm[0]).Select(_ => new List<int>()).ToArray();

        int all = nm[0] - 1 + nm[1];
        for (int i = 0; i < all; i++)
        {
            int[] ab =Console.ReadLine().Split().Select(int.Parse).ToArray();
            revedge[ab[1] - 1].Add(ab[0] - 1);
            edge[ab[0] - 1].Add(ab[1] - 1);
        }
        //根の方から確定させていくと強い?
        //BFSした時に一番遅く到達した奴が勝ち
        int root = 0;
        while (revedge[root].Count != 0)
        {
            root = revedge[root][0];
        }
        Debug.WriteLine($"root : {root}");
        int[] updateCount = new int[nm[0]];
        int[] allparents = new int[nm[0]];
        Queue<int> queue = new Queue<int>();
        //距離を振って、長い距離の方を勝たせる
        //枝刈り
        //
        queue.Enqueue(root);
        while (queue.Count != 0)
        {
            var elem = queue.Dequeue();
            foreach (var child in edge[elem])
            {
                if (child == elem) continue;
                allparents[child] = elem + 1;
                updateCount[child]++;
                if (updateCount[child] < revedge[child].Count) continue;
                queue.Enqueue(child);
            }
        }
        Console.WriteLine(string.Join("\n", allparents));
    }
}


Measured memory_bytes: 40040
s=list(input())
dp=[[0,0] for i in range(len(s)+1)]
dp[0][1] = 1
for i in range( len(s)-1 ):
  if s[i] == s[i+1]:
    dp[i+1][0] = dp[i][1]
    dp[i+1][1] = dp[i][0]+1
  else:
    dp[i+1][0] = dp[i][0]
    dp[i+1][1] = dp[i][1]+1
print(min(dp[len(s)-1]))  

Measured memory_bytes: 17288
c = [list(map(int, input().split())) for _ in range(3)]
ans = 'Yes'
values = [0, 0, 0, 0, 0 ,0]
values[3] = c[0][0]
values[4] = c[0][1]
values[5] = c[0][2]
values[0] = 0
values[1] = c[1][1] - values[4]
values[2] = c[2][2] - values[5]
for i in range(3):
	for j in range(3):
		if c[i][j] != values[i] + values[j+3]:
			ans = 'No'
print(ans)

Measured memory_bytes: 3064
def hit(str1, str2)
  n = 0
  
  4.times do |i|
    n += 1 if str1[i] == str2[i]
  end
  
  return n
end

def blow(str1, str2)
  n = 0
  
  4.times do |i|
    n += 1 if str1.include?(str2[i])
  end
  
  return n
end

loop do
  str = gets.split
  
  break if str == ["0", "0"]
  
  h, b = hit(str[0], str[1]), blow(str[0], str[1])
  
  puts "#{h} #{b - h}"
end

Measured memory_bytes: 6116
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int ans = 0;
  for (int c=1; c<=N; c+=2){
    int div = 0;
    for (int i=1; i<=c; i++){
      if(c%i==0){
        div++;
      }
    }
    if(div==8){
      ans++;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3540
#include<stdio.h>
int main()
{
	int n,i,cnt=0;
	int a[100]={};
	while(~scanf("%d",&n)){
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}for(i=0;i<n-2;i++){
			if(a[i+1]>a[i]&&a[i+1]<a[i+2]||a[i+1]<a[i]&&a[i+1]>a[i+2]){
				cnt++;
			}
		}printf("%d\n",cnt);
		cnt=0;
	}
} 

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define d long double
#define pii pair<int,int>
#define pb push_back
#define cases int tc;cin>>tc;while(tc--)
#define N 100003
#define M 1003
int mod=1e9+7;
//int mod=998244353;

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

    int n,m,c;
    cin>>n>>m>>c;
    int b[m+1],i,j,a[n+1][m+1];
    for(i=1;i<=m;++i)
        cin>>b[i];
    for(i=1;i<=n;++i)
    {
        for(j=1;j<=m;++j)
            cin>>a[i][j];
    }
    int ans=0,ct=0;
    for(i=1;i<=n;++i)
    {
        ct=0;
        for(j=1;j<=m;++j)
        {
            ct+=(a[i][j]*b[j]);
        }
        ct+=c;
        if(ct>0)
            ++ans;
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
 
using namespace std;
 
int main(){
    long long N;
    cin>>N;
    double ans = 100;
    double logo;
    vector<long long> divisor;
    for(int i=1;i<=sqrt(N);i++){
        if(N%i==0){
            divisor.push_back(i);
            divisor.push_back(N/i);
        }
    }
    for(int i = 0;i<divisor.size();i=i+2){
        logo  = max(log10(divisor.at(i)),log10(divisor.at(i+1)));
        ans = min(floor(logo)+1,ans);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;

int bitcount(int n){
    n = (n & 0x55555555) + (n >> 1 & 0x55555555);
    n = (n & 0x33333333) + (n >> 2 & 0x33333333);
    n = (n & 0x0f0f0f0f) + (n >> 4 & 0x0f0f0f0f);
    n = (n & 0x00ff00ff) + (n >> 8 & 0x00ff00ff);
    return (n & 0x0000ffff) + (n >>16 & 0x0000ffff);
}

int main(){
    while(1){
        int n,m,l,s,t;
        cin >> n >> m >> l >> s >> t;
        s--;
        if(n==0) break;
        
        vector<vector<int> > adj(n, vector<int>(n, inf));
        for(int i=0; i<m; i++){
            int a,b,c;
            cin >> a >> b >> c;
            a--; b--;
            adj[a][b] = adj[b][a] = c;
        }
        for(int k=0; k<n; k++){
            for(int i=0; i<n; i++){
                for(int j=0; j<n; j++){
                    adj[i][j] = min(adj[i][j], adj[i][k] +adj[k][j]);
                }
            }
        }
        
        vector<int> pos(l), time(l);
        for(int i=0; i<l; i++){
            cin >> pos[i] >> time[i];
            pos[i]--;
        }
        
        vector<vector<int> > dp(l, vector<int>(1<<l, 0));
        int ans = 0;
        for(int i=0; i<l; i++){
            int rem = t - (adj[s][pos[i]] +time[i]);
            if(rem > 0){
                 dp[i][1<<i] = rem;
            }
        }
        for(int i=0; i<(1<<l); i++){
            for(int j=0; j<l; j++){
            	int rest = dp[j][i];
                if(rest <= 0) continue;
                if(adj[s][pos[j]] <= rest){
                	ans = max(ans, bitcount(i));
                }
                for(int k=0; k<l; k++){
                	if((i & 1<<k) == 0 && adj[pos[j]][pos[k]]+time[k] < rest){
                		dp[k][i|(1<<k)] = max(dp[k][i|(1<<k)], rest-(adj[pos[j]][pos[k]]+time[k]));
                	}
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 7640
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	/* 1st line */
	scanner.Scan()
	strs := strings.Split(scanner.Text(), " ")
	var n, m, c int
	n, _ = strconv.Atoi(strs[0])
	m, _ = strconv.Atoi(strs[1])
	c, _ = strconv.Atoi(strs[2])

	/* 2nd line */
	scanner.Scan()
	strs = strings.Split(scanner.Text(), " ")
	b := make([]int, m)
	for i := 0; i < m; i++ {
		b[i], _ = strconv.Atoi(strs[i])
	}

	ret := 0
	for i := 0; i < n; i++ {
		scanner.Scan()
		strs := strings.Split(scanner.Text(), " ")
		score := 0
		for j := 0; j < m; j++ {
			a, _ := strconv.Atoi(strs[j])
			score += a * b[j]
		}
		if score+c > 0 {
			ret++
		}
	}

	fmt.Println(ret)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n;
    cin >> n;
    vector <int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    vector <int> pref(n + 1), post(n + 1);
    for (int i = 0; i < n; ++i) {
        pref[i + 1] = pref[i] + a[i];
    }
    for (int i = n - 1; i >= 0; --i) {
        post[i] = post[i + 1] + a[i];
    }   

    int ans = 5e18;
    for (int i = 1; i < n; ++i) {
        int l = pref[i];
        int r = post[i];
        ans = min(ans, abs(r-l));
    }   
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(void) {
  int64_t N, M, V, P;
  cin >> N >> M >> V >> P;
  vector<int64_t> A(N);
  rep(i, N) { cin >> A[i]; }
  sort(A.begin(), A.end(), greater<int>());

  int left = P - 1;
  int right = N;
  while (left + 1 < right) {
    int mid = left + (right - left) / 2;
    if ((A[mid] + M) < A[P - 1]) {
      right = mid;
      continue;
    }
    int64_t score = 0;
    score += M * (1 + (P - 1) + (N - mid - 1));
    for (int j = P - 1; j < mid; ++j) {
      if (A[j] < (A[mid] + M)) {
        score += (A[mid] + M - A[j]);
      }
    }
    if (M * V <= score) {
      left = mid;
    } else {
      right = mid;
    }
  }
  int answer = left + 1;
  cout << answer << endl;
  return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<long long int> a;
  for (int i = 0; i < n; ++i) {
    long long int b;
    cin >> b;
    a.push_back(b);
  }
  long long int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (i % 2 == 0)
      ans += a[i];
    else 
      ans -= a[i];
  }
  cout << ans << endl;
  ans /= 2;

  for (int i = 0; i < n-1; ++i) {
    ans = a[i] - ans;
    cout << 2 * ans << endl;
  }
}


Measured memory_bytes: 2292
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long N, K;
	cin >> N >> K;
	map<long long, long long>mp;
	for (int i = 0; i < N; ++i) {
		int x, y;
		cin >> x >> y;
		mp[x] += y;
	}
	for (auto p : mp) {
		//cout << p.first<<"_"<<p.second << endl;
		if (p.second < K) {
			K -= p.second;
		}
		else {
			cout << p.first << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 7548
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=1e9+7;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int inc(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=2e5+5;
struct eg{int v,nx;}e[N<<1];int head[N],tot;
inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;}
int fac[N],ifac[N],sz[N],f[N],ans[N],n;
void dfs(int u,int fa){
	sz[u]=1,f[u]=1;
	go(u)if(v!=fa){
		dfs(v,u),f[u]=mul(f[u],f[v]),
		f[u]=mul(f[u],ifac[sz[v]]),sz[u]+=sz[v];
	}
	f[u]=mul(f[u],fac[sz[u]-1]);
}
void fsd(int u,int fa,int g){
//	printf("%d %d %d\n",u,f[u],g);
	f[u]=1ll*f[u]*ifac[sz[u]-1]%P*g%P*ifac[n-sz[u]]%P;
	ans[u]=mul(f[u],fac[n-1]);
	go(u)if(v!=fa)fsd(v,u,1ll*f[u]*ksm(f[v],P-2)%P*fac[sz[v]]%P*fac[n-sz[v]-1]%P);
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d",&n);
	for(R int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),add(u,v),add(v,u);
	fac[0]=ifac[0]=1;fp(i,1,n)fac[i]=mul(fac[i-1],i);
	ifac[n]=ksm(fac[n],P-2);fd(i,n-1,1)ifac[i]=mul(ifac[i+1],i+1);
	dfs(1,0),fsd(1,0,1);
	fp(i,1,n)printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

int H, W,K;
vector<string> fi;

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

int main() {
    int x,y,ans = 0;
    cin >> x >> y;
    if(x == 1){
        ans += 300000;
    }
    if(y == 1){
        ans += 300000;
    }
    if(x == 1 && y == 1){
        ans += 400000;
    }
    if(x == 2){
        ans += 200000;
    }
    if(y == 2){
        ans += 200000;
    }
    if(x == 3){
        ans += 100000;
    }
    if(y == 3){
        ans += 100000;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
# include <stdio.h>

int main(){
  char S[4];
  int i,sum = 0;
  scanf("%s",S);
  for(i=0;i<4;i++){
    if(S[i]==43) sum+=1;
    else sum-=1;
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long X, long long Y){
    if(X % Y == 0){
        cout << -1 << endl;
    }
    else{
        cout << X << endl;
    }
}

int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(X, Y);
    return 0;
}


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

int count(int n, int x){
    int cnt=0;
    for(int i=1; i<=n-2; i++){
        for(int j=i+1; j<=n-1; j++){
            for(int k=j+1; k<=n; k++){
                if(i+j+k==x) cnt++;
            }
        }
    }
    
    return cnt;
}

int main(){
    int n,x;
    while(1){
        cin>>n>>x;
        if(n==0&&x==0) break;
        cout<<count(n,x)<<endl;
    }
    
    return 0;
}


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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int,string> Pis;

int main(){
  int n,k;
  cin>>n>>k;
  int seki=1;
  int ans=0;
  while(seki<=n){
    ans++;
    seki*=k;
  }
  cout<<ans<<endl;
}


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

using namespace std;

int main(){

	vector<long long int>v(1,0);
	long long int n,k,cont,menor,maior;
	long long int resp=1;

	cin >> n >> k;
	cont=k;
	for(int i=1;i<200010;i++){
		v.push_back(v[i-1]+i);
	}
	
	while(n>=cont){
		menor = v[cont-1]-1;
		maior = v[n] - v[n-cont];
		resp+=maior-menor;
		resp%=1000000007;
		cont++;
	}

		cout << resp << endl;		
	return 0;

}

Measured memory_bytes: 5360