akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>


int main()
{
	int a[1001] = {0}, b[2001] = { 0 }, c[3001] = { 0 }, d[4001] = { 0 }, n,i,j;


	
		for (i = 0; i < 1001; i++)
		{
			++a[i];
		}

		for (i = 0; i < 1001; i++)
		{
			for (j = 0; j < 1001; j++)
			{
				b[i + j] += a[i];
			}
		}

		for (i = 0; i < 2001; i++)
		{
			for (j = 0; j < 1001; j++)
			{
				c[i + j] += b[i];
			}
		}

		for (i = 0; i < 3001; i++)
		{
			for (j = 0; j < 1001; j++)
			{
				d[i + j] += c[i];
			}
		}

		while (scanf("%d", &n) != EOF)
		{
			printf("%d\n", d[n]);
		}


	return 0;
}


Measured memory_bytes: 644
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        ArrayList<String> a = new ArrayList<String>(h);
        for(int i = 0; i < h; i++){
            a.add(sc.next());
        }
        for(int i = 0; i < a.size(); i++){
            int n = 0;
            for(int j = 0; j < a.get(0).length(); j++){
                if (a.get(i).charAt(j) == '.') {
                    n++;
                }
            }
            if (n == w) {
                a.remove(i);
                i--;
            }
        }
        for(int j = 0; j < a.get(0).length(); j++){
            int n = 0;
            for(int i = 0; i < a.size(); i++){
                if (a.get(i).charAt(j) == '.') {
                    n++;
                }
            }
            if (n == a.size()) {
                for(int i = 0; i < a.size(); i++){
                    int l = a.get(i).length();
                    a.set(i, a.get(i).substring(0, j)+a.get(i).substring(j+1, l));
                }
                j--;
            }
        }
        for(int i = 0; i < a.size(); i++){
            System.out.println(a.get(i));
        }
    }
}

Measured memory_bytes: 25360
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9+1;
const ll LINF = 1e18+1;
const long double PI = acos(-1.0);

#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
 
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SORT(v) sort(ALL(v));
#define RSORT(v) sort(RALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;
 
#define HOGE COUT("HOGE")
 
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}
 
template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T& a, const T& b){if(a>b){a=b;return true;}return false;}
template<typename T> T gcd(T a,T b){if(b==0){return a;}else{return gcd(b, a%b);}}
template<typename T> T lcm(T a,T b){return a*b/gcd(a, b);}


const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
int main() {
    IN(ll, n);
    ll a = n;
    for (ll i = 2; i*i <= n; i++) {
        if (n%i==0) {
            a = n/i;
        }
    }
    ll ans = 0;
    while(a>0){
        ans++;
        a /= 10;
    }
    COUT(ans);
}


Measured memory_bytes: 3616
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
#define totori signed
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
ll dx[4]={0,1,-1,0};
ll dy[4]={1,0,0,-1};

class UnionFind{
    public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> parent;

    UnionFind(int N){
        parent = vector<int>(N,-1);
    }

    int root(int A){
        if(parent[A] < 0) return A;
        return parent[A]=root(parent[A]);
    }

    int size(int A){
        return -parent[root(A)];
    }

    bool unite(int A, int B) {
        A = root(A), B = root(B);
        if(A == B) return false; 

        if(size(A) < size(B)) swap(A,B);
        parent[A] += parent[B];
        parent[B] = A;
        return true;
    }

    bool same(int A, int B){
        return root(A)==root(B);
    } 
};


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

    int n,m;
    cin>>n>>m;
    UnionFind uni(n);
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        uni.unite(a,b);
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        if(i == uni.root(i))ans++;
    }
    ans--;
    cout << ans << endl;
}

Measured memory_bytes: 3728
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  int x[N], y[M];
  for (int i = 0; i < N; i++)
    cin >> x[i];
  for (int i = 0; i < M; i++)
    cin >> y[i];
  int xmax = -101;
  for (int i = 0; i < N; i++)
  {
    if (xmax < x[i])
      xmax = x[i];
  }
  int ymin = 101;
  for (int i = 0; i < M; i++)
  {
    if (y[i] < ymin)
      ymin = y[i];
  }
  string ans = "War";
  for (int z = xmax + 1; z <= ymin; z++)
  {
    if (X < z && z <= Y)
      ans = "No War";
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,X,Y; cin>>N>>M>>X>>Y;
  vector<int>A(N);
  vector<int>B(M);
  for(int i=0;i<N;i++)cin>>A[i];
  for(int i=0;i<M;i++)cin>>B[i];
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  if(A[N-1]>=B[0]){cout<<"War"<<endl; return 0;}
  if(B[0]>X&&A[N-1]<Y){cout<<"No War"<<endl; return 0;}
  cout<<"War"<<endl;
}

Measured memory_bytes: 3632
function main(input) {
  const inputs =input.split('\n')
  const [N, M] = inputs[0].split(' ').map(Number)
  console.log(
    (N + M) * (N + M -1) / 2 - (N * M)
  )
  
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LI()
    b = LI()
    t = 0
    for c,d in zip(a,b):
        s = c - d
        if s == 0:
            continue
        if s < 0:
            s += s%2
            t += s
        else:
            t += s * 2
    if t<=0:
        return 'Yes'

    return 'No'


print(main())




Measured memory_bytes: 7492
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {
	int A, B, C;
	scanf("%d%d%d%d", &A, &B, &C);
	
	if (A + B >= C)printf("Yes");
	else printf("No");



}

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

int main(){
  int d;
  cin >> d;
  vector<int> c(26);
  vector<vector<int>> s(d, vector<int>(26));
  for(int i = 0;i < d;i++){
    for(int j = 0;j < 26;j++){
      cin >> s.at(i).at(j);
    }
  }
  for(int i = 0;i < d;i++){
    cout << i%26+1 << endl;;
  }
} 

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

int main() {

    int N;
    int M;
    int X;
    int A[100];

    cin >> N >> M >> X;

    for (int i = 0; i < M; ++i) {
        cin >> A[i];
    }

    int masu[101];
    int cost = 0;
    int cost2 = 0;

    for (int i = 0; i < N + 1; ++i) {
        masu[i] = i + 1;
    }
    int x = max(X, N);
    int y = min(X, N);
    int length_0 = X;
    int length_N = x - y;

        if (X < N) {
            for (int j = X; j <= N; j++) {
                for (int i = 0; i < M; i++) if (j == A[i]) cost++;
            }
        }
        else {
            for (int j = N; j >= X; --j) {
                for (int i = 0; i < M; i++) if (j == A[i]) cost++;
            }
        }

        for (int j = 0; j <= X; ++j) {
            for (int i = 0; i < M; i++) if (j == A[i]) cost2++;
        }


    /*
       if (X < N) {
       for (int j = X; j <= N; j++) {
       for (int i = 0; i < M; i++) if (j == A[i]) cost++;
       }
       }
       }
       else {
       for (int j = N; j >= X; --j) {
       for (int i = 0; i < M; i++) if (j == A[i]) cost++;
       }
       }
       */
cout << min(cost, cost2) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long N,num,dig;
  long sum = 0;
  cin >> N;
    num = N;
  while(num){
    dig = num % 10;
      sum = sum + dig;
    num = num / 10;
  }
    if(N % sum == 0 ){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

  

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;
const int qq = 1e5 + 10;
long long num[qq];

int main(){
	int n;	scanf("%d", &n);
	long long sum;
	for(int i = 0; i < n; ++i)
		scanf("%lld", num + i);
	long long ans = 0;
	sum = 0;
	for(int i = 0; i < n; ++i){
		sum += num[i];
		if((i & 1) && sum >= 0)	ans += abs(sum + 1), sum = -1;
		else if(!(i & 1) && sum <= 0)	ans += abs(sum - 1), sum = 1;
	}
	long long cns = 0;
	sum = 0;
	for(int i = 0; i < n; ++i){
		sum += num[i];
		if((i & 1) && sum <= 0)	cns += abs(sum - 1), sum = 1;
		else if(!(i & 1) && sum >= 0)	cns += abs(sum + 1), sum = -1;
	}
	printf("%lld\n", min(ans, cns));
	return 0;
}


Measured memory_bytes: 896
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		int HM = 101;
		int ans = 0;
		for(int i=1;i<HM;i++){
			int c = 0;
			for(int j=0;j<N;j++){
				if(H[j] < i){
					if(c > 0){
						ans++;
					}
					c = 0;
				} else {
					c++;
				}
			}
			if(c > 0) ans++;
		}
		
		Console.WriteLine(ans);
		
	}
	int N;
	int[] H;
	public Sol(){
		N = ri();
		H = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13140
from collections import defaultdict
import bisect
s = input()
t = input()
dicta = defaultdict(list)
for a,b in enumerate(s):
    dicta[b] += [a]
snow = -1
count = 0
flag = True
for i in t:
    if not dicta[i]:
        flag = False
        break
    nowt = dicta[i]
    snowind = bisect.bisect_right(nowt,snow)
    if snowind == len(nowt):
        count += 1
        snow = nowt[0]
    else:
        snow = nowt[snowind]
if flag:
    print(len(s)*count+snow +1)
else:
    print(-1)
        

Measured memory_bytes: 7796
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n;
    cin >> n;
    vector<int>p(n);
    vector<int>q(n);
    rep(i,n)cin >> p[i];
    rep(i,n)cin >> q[i];
    vector<int>s(n);
    rep(i,n)s[i] = i+1;

    int x,y;
    int cnt = 1;
    do{
        bool pOk = true;
        bool qOk = true;
        rep(i,n){
            if(p[i] != s[i])pOk = false;
            if(q[i] != s[i])qOk = false;
        }
        if(pOk)x = cnt;
        if(qOk)y = cnt;
        cnt++;
    }while(next_permutation(all(s)));
    cout << abs(x-y) << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $N);
$L = array_map('intval', explode(' ', trim(fgets(STDIN))));
sort($L);
// var_dump($N);
// var_dump($L);

$ans = 0;
for ($i = 0; $i < $N - 2; $i++) {
    for ($j = $i + 1; $j < $N - 1; $j++) {
        if ($L[$i] === $L[$j]) continue;
        for ($k = $N - 1; $k > $j; $k--) {
            if ($L[$j] === $L[$k]) continue;
            if ($L[$i] + $L[$j] <= $L[$k]) continue;
            // printf("%d %d %d\n", $L[$i], $L[$j], $L[$k]);
            $ans++;
        }
    }
}
printf("%d", $ans);


Measured memory_bytes: 16208
using System;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine();
            var data = line.Split(' ');
            var a = int.Parse(data[0]);
            var b = int.Parse(data[1]);

            Console.WriteLine(a * b);
        }
    }
}
    

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

template<class T>
using Graph = std::vector<std::vector<int>>;

bool dfs(Graph<int> &G, int step, int u, int v,
         std::vector<bool> &visited)
{
    int n = G.size();
    int x = (step < n / 2 ? u : v);
    if (step == n - 1) {
        return true;
    }
    
    bool ret = false;
    for (int next : G[x]) {
        if (!visited[next]) {
            visited[next] = true;

            if (step < n / 2) {
                ret |= dfs(G, step + 1, next, v, visited);
            } else {
                ret |= dfs(G, step + 1, u, next, visited);
            }           
        }        
    }

    return ret;
}

bool solve(Graph<int> &G, int u, int v)
{
    int n = G.size();
    if (n & 1) {
        return false;
    }

    std::vector<bool> visited(n, false);
    visited[u] = visited[v] = true;
    return dfs(G, 1, u, v, visited);
}

int main()
{
    int n, u, v;
    std::cin >> n >> u >> v;
    u--; v--;
    
    Graph<int> G(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        std::cin >> a >> b;
        a--; b--;

        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    std::cout << (solve(G, u, v) ? "Yes" : "No") << std::endl;
    
    return 0;
}

Measured memory_bytes: 17584
S = input()
T = input()
def count(S):
    L = len(S)
    cA = [0]*(L+1)
    cB = [0]*(L+1)
    for i in range(L):
        cA[i+1] = cA[i] + (S[i] == 'A')
        cB[i+1] = cB[i] + (S[i] == 'B')
    return cA, cB

sA, sB = count(S)
tA, tB = count(T)
q = int(input())
ans = []
for i in range(q):
    a, b, c, d = map(int, input().split())
    dA = (sA[b] - sA[a-1]) - (tA[d] - tA[c-1])
    dB = (sB[b] - sB[a-1]) - (tB[d] - tB[c-1])
    if (2*dA + dB) % 3 == 0 and (dA + 2*dB) % 3 == 0:
        ans.append('YES')
    else:
        ans.append('NO')
print(*ans, sep='\n')


Measured memory_bytes: 22184
#include <iostream>
#include <cstring>
#include <cstdio>
#define MN 300
#define mod 998244353
using namespace std;
int n, K, sum[MN * 2 + 5], sum2[MN + 5];
char s[MN + 5];
int f[MN + 5][MN + 5][MN + 5]; // first i bit, use j operations and k '1' from the latter n-i bits
inline void R(int &x, int y) {
  (x += y) >= mod ? x -= mod : 0;
}
inline int IntevalSum2(int l, int r) {
  return (sum2[r] - (l ? sum2[l - 1] : 0) + mod) % mod;
}
int main() {
  scanf("%s%d", s + 1, &K);
  n = strlen(s + 1);
  K = min(n, K);
  f[0][0][0] = 1;
  int i = 0, num = 0;
  for (int pos = 1; pos <= n + 1; ++pos) {
    if (s[pos] == '1') {
      ++num; 
    } else {
      ++i;
      // f[i-1][j][k] -> f[i][j][k - t]   t = 0 - num
      // f[i-1][j][k] -> f[i][j + t][k + t]  t = 1 - inf
      memset(sum, 0 ,sizeof(sum));
      for (int j = 0; j <= K; ++j) {
        sum2[0] = f[i - 1][j][0];
        for (int k = 1; k <= j; ++k) { //prefix sum
          sum2[k] = (sum2[k - 1] + f[i - 1][j][k]) % mod;
        }
        for (int k = 0; k <= j; ++k) {
          f[i][j][k] = (IntevalSum2(k, min(k + num, j)) + sum[j - k + n]) % mod;
          R(sum[j - k + n], f[i - 1][j][k]);
        }
      }
      num = 0;
    }
  }
  int ans = 0;
  for (int k = 0; k <= K; ++k) {
    R(ans, f[i][k][0]);
  }
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 58312
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

type station struct {
	C, S, F int
}

func main() {
	sc.Split(bufio.ScanWords)

	N := scanInt()
	L := make([]station, N-1)
	for i := 0; i < N-1; i++ {
		L[i].C, L[i].S, L[i].F = scanInt(), scanInt(), scanInt()
	}

	for i := 0; i < N; i++ {
		ans := 0
		for _, l := range L[i:] {
			if ans < l.S {
				ans = l.S + l.C
			} else {
				q := ans / l.F
				if r := ans % l.F; r > 0 {
					q++
				}
				ans = q*l.F + l.C
			}
		}
		fmt.Println(ans)
	}
}


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

using namespace std;
using ll = long long;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for (auto &el : a) {
		cin >> el;
	}
	sort(a.rbegin(), a.rend());
	int cnt = n - 1;
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		int now = min(cnt, 1 + (i != 0));
		ans += (ll)now * a[i];
		cnt -= now;
	}
	cout << ans;
}

Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> a(3);
  for(int i; i<3; i++) cin >> a[i];
  sort( a.begin(), a.end() );
  int k; cin >> k;
  for(int i; i<k; i++){
    a[2] = a[2]*2;
  }
  cout << a[0]+a[1]+a[2] << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
import math

N, L, T = list(map(int, input().split()))
XW = []
for i in range(N):
	XW.append(list(map(int, input().split())))

after = []
rot = 0
for i in range(N):
	if XW[i][1] == 1:
		rot += 1
		after.append((XW[i][0] + T) % L)
	else:
		rot -= 1
		after.append((XW[i][0] - T) % L)
after.sort()
rot *= T
rot = rot % (L*N)
rot_base = 0
for i in range(N):
	rot_base += after[i] - XW[i][0]
rot_base = rot_base % (L*N)
rot_num = (rot - rot_base) // L
rot_num = rot_num % N
after=after*2
for i in range(N):
	print(after[i + rot_num])

Measured memory_bytes: 64092
#include <bits/stdc++.h>
#define ll long long
ll c;
ll ans=(ll)1<<(ll)60;
int main(){
	std::cin>>c;
	for(ll i=1;i*i<=c;++i){
		if (c%i)continue;
		ans=std::min(ans,i-1+c/i-1);
	}printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
// #include <fstream>
#define typeof(x) __typeof__(x)
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define SIZE(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (int)(UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());

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

using namespace std;

typedef pair<int,int> P;
struct edge {
  int to, cost;
};

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

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " ";
  }
  return s;
}


signed main()
{
  // string filename; cin >> filename;
  // ifstream in(filename);
  // cin.rdbuf(in.rdbuf());

  int N; cin >> N;
  vector<int> a(N);
  rep(i, 0, N) {
    cin >> a[i];
  }

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

  int m = INF;
  rep(i, 1, N) {
    m = min(m, abs(s[N] - 2*s[i]));
  }

  cout << m << endl;

  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9;

int main(){
  string S;
  ll K;
  cin>>S>>K;
  ll N=S.size();
  ll cnt(0);
  for (int i(0);i<N-1;i++){
    if (S[i]==S[i+1]) {
      cnt++;
      i++;
    }
  }
  ll hidari(1);
  ll migi(1);
  for (int i(0);i<N-1;i++){
    if (S[i]==S[i+1]) hidari++;
    else break;
  }
  for (int i(N-1);i>0;i--){
    if (S[i]==S[i-1]) migi++;
    else break;
  }
  if (hidari==N){
    cout << N*K/2 << endl;
    return 0;
  }
  if (hidari%2==1 && migi%2==1 && S[0]==S[N-1]){
    cout << cnt*K+(K-1) << endl;
  }else{
    cout << cnt * K << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
  #include <complex>
  #include <vector>
  #include <string>
  #include <algorithm>
  #include <cstdio>
  #include <numeric>
  #include <cstring>
  #include <ctime>
  #include <cstdlib>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <list>
  #include <cmath>
  #include <bitset>
  #include <cassert>
  #include <queue>
  #include <stack>
  #include <deque>
 #include <iomanip>
#include <fstream>
#include <climits>
 
  using namespace std;
   
 
//abcdefghijklmnopqrstuvwxyz
//ABCDEFGHIJKLMNOPQRSTUVWXYZ

  typedef long long ll;
  typedef long double lld;
  typedef unsigned long long ull;
  // int INF = INT_MAX;
  ll mod = 1000000007;
  // lld PI = 3.141592653;

ll power(ll a, ll b){
 ll result = 1;
 while (b>0){
   if (b%2==1) result = (a*result) % mod;
   a = (a*a) %mod;
   b/=2;
 }
 return result;
}

  int main()
  {
      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
     ll n;
     cin>>n;
     ll ans = (power(10, n) - power(9, n)*2 + power(8, n) + mod*5)%mod;
     cout<<ans<<"\n";


}

Measured memory_bytes: 3160
n,m,c = gets.split.map &:to_i
b = gets.split.map &:to_i

count = 0

n.times do |i|
  ai = gets.split.map &:to_i
  sum = 0
  m.times do |j|
    sum += b[j] * ai[j]
  end
  if sum + c > 0
    count += 1
  end
end

puts count

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define N 105
using namespace std;
long long lcm(long long a,long long b)
{
	if(a==b)
	{
		return a;
	}
	long long x=__gcd(a,b);
	a/=x;
	x=a*b;
	return x;
}
int main(){
	long long n,i,t[N],ans;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>t[i];
	}
	ans=t[0];
	for(i=1;i<n;i++)
	{
		ans=lcm(ans,t[i]);
	}
	cout<<ans<<endl;
	return 0;
}

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

int X, Y;

int main() {
    cin >> X >> Y;

    if(abs(X) == abs(Y)) {
        if(X == Y) printf("0");
        else printf("1");
        return 0;
    }
    if(abs(X) < abs(Y)) {
        int ans = 0;
        ans += (X < 0);
        ans += (abs(Y) - abs(X));
        ans += (Y < 0);
        printf("%d", ans);
        return 0;
    }
    if(abs(X) > abs(Y)) {
        int ans = 0;
        ans += (X > 0);
        ans += (abs(X) - abs(Y));
        ans += (Y > 0);
        printf("%d", ans);
        return 0;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        solve();
    }

    static void solve() {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int k = scanner.nextInt();

        if (k == 1) {
            System.out.println(0);
        } else {
            System.out.println((n - (k - 1) - 1));
        }

    }
}


Measured memory_bytes: 21844
using System;
using System.Linq;

namespace AtCoder20181124
{
    class Program
    {
        static void Main(string[] args)
        {

            int n = int.Parse(Console.ReadLine());
            var a_str = Console.ReadLine();
            string[] a_parse = a_str.Split(' ');
            int[] a_n = new int[a_parse.Length];
            for (int i = 0; i < a_n.Length; ++i)
            {
                a_n[i] = int.Parse(a_parse[i]);
            }
            double a_ave = a_n.Average();
            double min_abs = Math.Abs(a_n[0] - a_ave);
            int a_NearFrameNum = 0;

            for(int i = 1; i < a_n.Length; ++i)
            {
                double abs = Math.Abs(a_n[i] - a_ave);
                if(min_abs > abs){
                    min_abs = abs;
                    a_NearFrameNum = i;
                }
            }
            Console.Write(a_NearFrameNum.ToString());
        }
    }
}


Measured memory_bytes: 13268
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define INF 0X3F3F3F3F
#define N 100005
#define M 200005
#define LL long long
#define ULL unsigned long long
#define FF(i, a, b) for(int i = a; i <= b; ++i)
#define RR(i, a, b) for(int i = a; i >= b; --i)
#define FJ(i, a, b) for(int i = a; i < b; ++i)
#define SC(x) scanf("%d", &x)
#define SCC(x, y) scanf("%d%d", &x, &y)
#define SCCC(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define SS(x) scanf("%s", x)
#define PR(x) printf("%d\n", x)
#define CL(a, x) memset(a, x, sizeof(a))
#define _P fd[rt]
#define _L fd[rt << 1]
#define _R fd[rt << 1 | 1]
#define MID int mid = ((l + r) >> 1)
#define lson rt<<1 ,l, mid
#define rson rt<<1 | 1, mid + 1, r
#define VI vector<int>
#define db double
#define PII pair<int, int>
#define PLL pair<unsigned long long, unsigned long long>
#define MP make_pair
#define PB push_back
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
using namespace std;
inline void II(int &n){char ch = getchar(); n = 0; bool t = 0;
for(; ch < '0'; ch = getchar()) if(ch == '-') t = 1;
for(; ch >= '0'; n = n * 10 + ch - '0', ch = getchar()); if(t) n =- n;}
inline void OO(int a){if(a < 0) {putchar('-'); a = -a;}
if(a >= 10) OO(a / 10); putchar(a % 10 + '0');}
int n, a, b;
int main(){
    //IN;
    SC(n);
    SCC(a, b);
    int x = abs(a - b);
    --x;
    if(x & 1) puts("Alice");
    else puts("Borys");
    return 0;
}


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

int main() {
  int x1, y1, x2, y2, x3, y3, x4, y4, d1, d2;
  cin >> x1 >> y1 >> x2 >> y2;
  d1 = x2 - x1;
  d2 = y2 - y1;

  x3 = x2 - d2;
  y3 = y2 + d1;

  x4 = x3 - d1;
  y4 = y3 - d2;

  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

Measured memory_bytes: 256
key_list=[]
page_list=[]
while 1:
    try:
        key,page=map(str,input().split())
        if key in key_list:
            page_list[key_list.index(key)].append(int(page))
        else:
            key_list.append(key)
            page_list.append([int(page)])
    except:break
key_list_sort=key_list[:]
key_list_sort.sort()
for i in key_list_sort:
    print(i)
    ans=page_list[key_list.index(i)][:]
    ans.sort()
    print(' '.join(map(str,ans)))


Measured memory_bytes: 5604
def gcd(a, b):
    """Compute the greatest common divisor of a and b"""
    while b > 0:
        a, b = b, a % b
    return a


def lcm(a, b):
    """Compute the lowest common multiple of a and b"""
    return a * b / gcd(a, b)


N = int(raw_input())
A = [int(x) for x in raw_input().split()]

X = 1
for i in A:
    X = lcm(i, X)

sum = 0
X -= 1
for i in A:
    sum += X % i

print(sum)


Measured memory_bytes: 33000
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    string a,b,c;
    cin>>a>>b>>c;
    int i=0,j=0,k=0;
    int round=1;
    while(i<=a.length() && j<=b.length() && k<=c.length()){
        if(round==1){
            round=(a[i]-'a'+1);
            i++;
        }
        else if(round==2){
            round=(b[j]-'a'+1);
            j++;
        }
        else if(round==3){
            round=(c[k]-'a'+1);
            k++;
        }
    }
    if(i-1==a.length()){
        cout<<'A'<<endl;
    }
    else if(j-1==b.length()){
        cout<<'B'<<endl;
    }
    else if(k-1==c.length()){
        cout<<'C'<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <numeric>

using ll = long long;

using namespace std;

int main() {
    int n;
    cin >> n;
    int x[n];
    for (auto &xi:x) cin >> xi;
    vector<int> ids(n);
    iota(ids.begin(), ids.end(), 0);
    sort(ids.begin(), ids.end(), [&](int l, int r) {
        return x[l] < x[r];
    });
    queue<int> q;
    for (auto id:ids)
        for (int k=0; k<id; k++) 
            q.push(id);
    int i=0, cnt[n];
    fill(cnt, cnt+n, 0);
    vector<int> ans;
    while (!q.empty() || i < n && ans.size() == x[ids[i]] - 1) {
        int a;
        if (i < n && ans.size() == x[ids[i]] - 1) {
            a = ids[i];
            if (cnt[a] != a) break;
            for (int k=ids[i]+1; k<n; k++) q.push(ids[i]);
            i++;
        } else {
            a = q.front(); 
            q.pop();
        }
        ans.push_back(a+1);
        cnt[a]++;
    }
    if (ans.size() < n*n) {
        cout << "No" << '\n';
        return 0;
    }
    cout << "Yes" << '\n';
    for (int i=0; i<n*n; i++) cout << ans[i] << (i < n*n-1 ? ' ' : '\n');
    return 0;
}

Measured memory_bytes: 2932
#include<stdio.h>

int main(int argc, char *argv[]){
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);

  int y = 0;
  for(int i=1; i<=b; i++){
    if((a*i)%b == c){
      y = 1;
      break;
    }
  }

  if(y==1){
    printf("YES\n");
  }else{
    printf("NO\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>   
using namespace std;
int main()
{
    long long a,b;    
    string s;      
    scanf("%lld%lld",&a,&b);
    cin>>s;
    if(s[a]!='-')
    {
        printf("No\n");
        return 0;
    }
    for(int i=1;i<=a+b;i++)
    {
        if(i==a)
        {
            continue;
        }
        if(s[i]<'0'||s[i]>'9')
        {
            printf("No\n");
            return 0;
        }
    }
	printf("Yes\n");
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef long long ll;

int hikaku(const void *n1,const void *n2)
{
    return *(int*)n2-*(int*)n1;
}

int main()
{
    int n,m;
    double sum;
    scanf("%d %d",&n,&m);
    int a[n];

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

    qsort(a,n,sizeof(int),hikaku);
    sum=sum/(4*m);

    if(a[m-1]>=sum)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
}

Measured memory_bytes: 128
import heapq

N, H = map(int, input().split())
katana = [list(map(int, input().split())) for _ in range(N)]

TYPE_A = 0
TYPE_B = 1

powers = []
for i in range(N):
    heapq.heappush(powers, (-katana[i][1], i, TYPE_B))

ans = 0
while H > 0:
    power, idx, t = heapq.heappop(powers)
    power = -power
    if t == TYPE_A:
        ans += (H - 1) // power + 1
        break
    else:
        H -= power
        heapq.heappush(powers, (-katana[idx][0], idx, TYPE_A))
        ans += 1

print(ans)


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

ans = 0
flag = False
while True:
    for i in range(N):
        if A[i] % 2 == 0:
            A[i] = A[i] / 2
        else:
            flag = True
            break
    if flag:
        break
    ans += 1
print(ans)

Measured memory_bytes: 3060
n=int(input())
v=list(map(int,input().split()))
c=list(map(int,input().split()))
a=[]
for i in range(n):
    x=v[i]
    y=c[i]
    a.append(x-y)

def max_sum(N,a):
  dp=[0]*(N+1)
  for i in range(N):
    dp[i+1]=max(dp[i],dp[i]+a[i])
  return dp[N]

print(max_sum(n,a))


Measured memory_bytes: 3064
def main():
    x,y = map(int,input().split())
    if(( x==4  and y==6 ) or ( x==4 and y==9 ) or ( x==4 and y==11 ) or ( x==6 and y==9 ) or ( x==6 and y==11 ) or ( x==9 and y==11 )):
        print("Yes")
    elif(( x==1 and (y==3 or y==5 or y==7 or y==8 or y==10 or y==12)) or ( x==3 and (y==5 or y==7 or y==8 or y==10 or y==12)) or ( x==5 and (y==7 or y==8 or y==10 or y==12 )) or ( x==7 and (y==12 or y==8 or y==10 )) or ( x==8 and (y==10 or y==12) ) or ( x==10 and y==12 )):
        print("Yes")
    else:
        print("No")
    
main()

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

const lint MOD = pow(10, 9) + 7;

lint gcd(lint a, lint b) {
	//aとbの最大公約数を返す
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(a % b, b);
}

lint lcm(lint a, lint b) {
	//aとbの最小公倍数を返す
	return a / gcd(a, b) * b;
}

/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/


int main() {
	int N;
	string A, B, C;
	cin >> N >> A >> B >> C;
	int cnt = 0;
	rep(i, N) {
		if (A[i] == B[i] && B[i] == C[i]) {

		}
		else if (A[i] == B[i] && B[i] != C[i] ||
			B[i] == C[i] && C[i] != A[i] ||
			C[i] == A[i] && A[i] != B[i]) {
			cnt++;
		}
		else {
			cnt += 2;
		}
	}
	cout << cnt << endl;
}


Measured memory_bytes: 256
a, b, c = map(int, input().split())
K = int(input())

for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            x = a * 2**i
            y = b * 2**j
            z = c * 2**k
            if i+j+k<=K and y > x and z > y:
                print("Yes")
                exit()

print("No")



Measured memory_bytes: 9176
_ = readLine()
let inp = readLine()!.split(separator: " ").map { Int($0)! }

let As = inp.enumerated().map { i, n -> (Int, Int, Int, Int) in
    return (i+1, n, i+n, i-n)
}

let dic2 = Dictionary(grouping: As, by: \.2)
let dic3 = Dictionary(grouping: As, by: \.3)


var r = 0
for i in As {
    let r2 = (dic2[i.3] ?? []).count
    let r3 = (dic3[i.2] ?? []).count
    r += r2 + r3
}

print(r/2)


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

typedef long long ll;
const int maxn=1e5+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int ll
//#define endl '\n'

string s;
int n;
int dp[maxn][15];

int32_t main()
{
    IOS
    cin>>s;
    int n=s.length();
    dp[0][0]=1;
    for (int i=0;i<n;i++)
        for (int j=0;j<13;j++)
            for (int k=0;k<=9;k++)
                if (k==s[i]-'0'||s[i]=='?')
                    dp[i+1][(j*10+k)%13]=(dp[i+1][(j*10+k)%13]+dp[i][j])%mod;
    cout<<dp[n][5]<<endl;
}



Measured memory_bytes: 12240
#include <stdio.h>

int	main(void)
{
  	int	N;
  	int M;
  	int num;
  
  	num = scanf("%d %d", &N, &M);
  	if (num != 2)
      	return (0);
  
  	printf("%d", (N * (N - 1) / 2 + M * (M - 1) / 2));
  	return (0);
}

Measured memory_bytes: 128
#include<iostream>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int main() {
    int N, C, X;
    int D[30][30], t[3][30] = {0};
    cin >> N >> C;
    rep(i, C) rep(j, C) cin >> D[i][j];
    rep(i, N) rep(j, N) cin >> X, t[(i + j) % 3][X - 1]++;
    int res = 1 << 30;
    rep (i, C) rep(j, C) if (i != j) rep (k, C) if (i != k && j != k) {
        int tt = 0;
        rep (l, C) tt += D[l][i] * t[0][l];
        rep (l, C) tt += D[l][j] * t[1][l];
        rep (l, C) tt += D[l][k] * t[2][l];
        if (tt < res) res = tt;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a * b, c*d) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	long long int P = 1e9 + 7; 
	int N, M; 
	cin >> N >> M; 
    int A[1010] = {}, B[1010] = {}; 
    for(int i = 0; i < N; i++){
		cin >> A[i];	
	}
	for(int i = 0; i < M; i++){
		cin >> B[i]; 
	}
	sort(A, A+N); 
	sort(B, B+M); 
	long long int ans = 1; 
	for(int i = 0; i <= N-2; i++){
		if(A[i] == A[i+1]) ans = 0; 
	}
	for(int i = 0; i <= M-2; i++){
		if(B[i] == B[i+1]) ans = 0; 
	}
	for(int i = M * N; i >= 1; i--){
		int p = N; int q = M; 
		int a = lower_bound(A, A+p, i) - A; 
		int b = lower_bound(B, B+q, i) - B; 
		if(A[a] == i && B[b] == i){ans *= 1;}
		else if(A[a] == i){
			ans *= (M - b); 
			ans = ans % P; 
		}
		else if(B[b] == i){
			ans *= (N - a); 
			ans = ans % P; 
		}
		else{
			ans *= max((M - b) * (N - a) - (N * M - i), 0); 
            ans = ans % P;
		}
		p = a+1, q = b+1; 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define E 1e-6;
void open()
{
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
}

int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        printf("%d\n",(n-1)*(m-1));
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#include<set>
#include<vector>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
    string s,t;
    cin >> s >> t;
    int ans= 0;
    rep(i,3){
        if(s[i]==t[i]){
            ans += 1;
        }
    }
    cout << ans << endl;
    return 0;

}

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


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll i,j,n,w;
    cin>>n>>w;
    
    ll dp[n+1][w+1];
    vector<ll> a(n),p(n);
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>p[i];
    }
    
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=w;j++)
        {
            if(i==0 && j==0)
                dp[i][j]=0;
            
            else if(i==0)
                dp[i][j]=0;
            
            else if(j==0)
                dp[i][j]=0;
                
                
            else if(a[i-1]<=j)
            {
                dp[i][j]=max(dp[i-1][j],p[i-1]+dp[i-1][j-a[i-1]]);
            }
            else
                dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][w];
    
    return 0;
}

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

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

  A = a * n;
  cout << min(A,b) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int gcd(int x,int y){
	
	if(x%y==0){
		return y;
	}else{
		return gcd(y,x%y);
	}
	
}

int main() {
	
	int N,K;
	cin>>N>>K;
	int ans=0;
	for(int x=1;x<=N;x+=2){
		ans++;
	}
	if(ans>=K){
		ce("YES")
	}else{
		ce("NO")
	}
	
}


Measured memory_bytes: 256
#include<bits//stdc++.h>
using namespace std;
int t[110];
int p[110];
int x[110];
int main(){
    int n;
    cin>>n;
    int sum=0;
    for(int i=0;i<n;i++){
        cin>>t[i];
    }
    int m;
    cin>>m;
    for(int l=0;l<m;l++){
        cin>>p[l];
        cin>>x[l];
    }
    for(int j=0;j<n;j++){
        sum+=t[j];
    }
    for(int k=0;k<m;k++){
        cout<<sum+x[k]-t[p[k]-1]<<endl;
    }
}

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


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
LL s[100001];

bool check(int a,int b,int k){
	if(a==b)return true;
	if((a-b)==k)return true;
	if(b<=k)return true;
	return false;
}

int main(){
	cin>>N;
	REP(i,N){
		cin>>s[i];
	}
	LL ans=0;
	for(int i=1;i<N;i++){
		LL now=0;
		int a=0;
		int b=N-1;
		REP(j,N+1){
			if(a>N-1||b<0)break;
			now+=(s[a]+s[b]);
			//溺れる判定
			if(check(a,b,i)){
				break;
			}
			ans=max(ans,now);
			a+=i;
			b-=i;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1152
import fractions
a,b,c,d = map(int,input().split())
N = b-a+1
s = fractions.gcd(c,d)
t = c*d // s
lcm_div = b//t - (a-1)//t
divc = b//c - (a-1)//c
divd = b//d - (a-1)//d
if c%d==0 or d%c==0:
    w = min(c,d)
    print(N-(b//w-(a-1)//w))
else:
    print(N-(divc+divd-lcm_div))

Measured memory_bytes: 65516
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    vector<int> x(n, 0);
    rep(i, n) cin >> x[i];

    int s = 0;

    int res = INF;
    rep(i, n - k + 1) {
        if (x[i + k - 1] <= 0) chmin(res, abs(x[i]));
        else if (x[i] >= 0) chmin(res, x[i + k - 1]);
        else {
            chmin(res, abs(x[i]) * 2 + x[i + k - 1]);
            chmin(res, abs(x[i]) + x[i + k - 1] * 2);
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a>b){
		printf("a > b\n");
	}
	else if(a<b){
		printf("a < b\n");
	}
	else if(a==b){
		printf("a == b\n");
	}
	
	return 0;
}

Measured memory_bytes: 580