akhauriyash/Code-Regression huggingface dataset:
// --------------
// Tejas Pandey  |
// 21 - 03 - 20  |
// AtCoder GC 043|
// --------------

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

#define mod 998244353
#define lim 10000000
#define vi vector<int>
typedef long long int ll;

int main (void)
{
  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);
  int h,w;
  cin >> h >> w;
  int dp[h][w];
  char s[h][w];
  for(int i = 0;i < h;i++)
	for(int j = 0;j < w;j++)
		cin >> s[i][j];
  for(int i = 0;i < h;i++)
	for(int j = 0;j < w;j++)
		dp[i][j] = lim;
  dp[0][0] = 0;
  if(s[0][0] == '#') dp[0][0]++;
  for(int i = 0;i < h;i++)
	for(int j = 0;j < w;j++){
		if(i || j){
			if(j - 1 > -1 && (s[i][j] == s[i][j - 1] || s[i][j] == '.'))
				dp[i][j] = min(dp[i][j],dp[i][j - 1]);
			else if(j)
				dp[i][j] = min(dp[i][j],dp[i][j - 1] + 1);
			if(i - 1 > -1 && (s[i][j] == s[i - 1][j] || s[i][j] == '.'))
				dp[i][j] = min(dp[i][j],dp[i - 1][j]);
			else if(i)
				dp[i][j] = min(dp[i][j],dp[i - 1][j] + 1);
		}
	}
	cout << dp[h - 1][w - 1];
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

const ll inf=998244353;

inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}

int a[1005];
int b[4];

int main()
{
    int n;
    scanf("%d",&n);
    int ans=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            for(int o=j+1;o<n;o++)
            {
                if(a[i]!=a[j]&&a[i]!=a[o]&&a[o]!=a[j])
                {
                    b[0]=a[i];
                    b[1]=a[j];
                    b[2]=a[o];
                    sort(b,b+3);
                    if(b[0]+b[1]>b[2])
                    {
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3768
# -*- coding: utf-8 -*-
"""
A - Circle
https://atcoder.jp/contests/abc145/tasks/abc145_a

"""
import sys


def solve(r):
    return r ** 2


def main(args):
    r = int(input())
    ans = solve(r)
    print(ans)


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


Measured memory_bytes: 2940
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
int main(){
  int N , M;

  cin >> N  >> M;

  vector<pair<long int,long int> > v;

  for(int i = 0; i < N; ++i){
    int a,b;
    cin >> a >> b;
    v.push_back(make_pair(a,b));
  }

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

  int k = 0,s = 0;
  long int min = 0;
  while(M > 0){
    min += v[k].first;
    --M;
    ++s;
    if(s == v[k].second){
      s = 0;
      ++k;
    }
  }

  cout << min << endl;
}


Measured memory_bytes: 2420
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>

using namespace std;

template<typename T>
istream& operator >> (istream& is, vector<T>& v) {
    for (auto& x : v) {
        is >> x;
    }
    return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v) {
    for (auto& x : v) {
        os << x << " ";
    }
    os << "\n";
    return os;
}

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

#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    uint64_t x;
    cin >> n >> x;
    vector<uint64_t> a(n);
    cin >> a;

    uint64_t min_ans = 0;
    for (auto i : a) min_ans += i;

    for (auto max_j = 1; max_j < n; ++max_j) {
        vector<uint64_t> b = a;
        multiset<uint64_t> w;
        for (int j = 1; j <= max_j; ++j) w.insert(a[n - j]);
        for (int i = 0; i < n; ++i) {
            uint64_t cur = *w.begin();
            if (cur < b[i]) b[i] = cur;
            w.erase(w.find(a[(n + i - max_j) % n]));
            w.insert(a[i]);
        }
        uint64_t cur_ans = max_j * x;
        for (auto i : b) cur_ans += i;
        if (cur_ans < min_ans) min_ans = cur_ans;
    }



    cout << min_ans << "\n";
}


Measured memory_bytes: 3744
#include<stdio.h>

#define MAX 5000

int a[MAX],n;
int dp[MAX];

int max(int a,int b){
	if(a>=b)
		return a;
	else
		return b;
}
void solve(void){
	int res=dp[0]=a[0];
	int i;

	for(i=1;i<n;i++){
		dp[i]=max(dp[i-1]+a[i],a[i]);
		res=max(dp[i],res);
	}
	printf("%d\n",res);
	return;
}
int main(void){
	int i;
	while(1){
		scanf("%d",&n);
		if(n==0)return 0;
		for(i=0;i<n;i++)scanf("%d",&a[i]);
		solve();
	}
}

Measured memory_bytes: 0
// ABC 055 D
#include<bits/stdc++.h>
 
using namespace std;
//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())

#define PB(a) push_back(a)

#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------
  int a,b,k,ans;
  int j=0;
  VI is;
  
  cin >> a >> b >> k;
  FOR(i,1,101){
    if(a%i==0&&b%i==0) is.PB(i) ; 
  }
  auto itr = is.end();
  itr -= k;
  //VI l(N);
  cout << *itr << endl;
  return 0;
}


Measured memory_bytes: 256
//from PKU1125
double dist[1001][1001],x[1001],y[1001],d;
next[1001][1001];
main(){
	
	int a,b,k,n,i,j;
	for(;scanf("%d",&n),n;){
		/*initialize*/
		for(i=1;i<=n;i++)scanf("%d",&a),scanf("%lf%lf",x+a,y+a);
		for(i=1;i<=n;i++)for(j=1;j<=n;next[i][j]=j,j++)
			dist[i][j]=(d=hypot(x[i]-x[j],y[i]-y[j]))<50.001?d:99999;

		{/*warshall-floyd*/
			int k,i,j;
			for(k=1;k<=n;k++)
				for(i=1;i<=n;i++)
					for(j=1;j<=n;j++){
						if(dist[i][j]>dist[i][k]+dist[k][j])
							dist[i][j]=dist[i][k]+dist[k][j],next[i][j]=next[i][k];
					}
		}

		{/*query*/
			for(scanf("%d",&k);k;k--){
				scanf("%d%d",&a,&b);
				if(dist[a][b]>99990)puts("NA");
				else{
					for(j=a;j!=b;j=next[j][b])printf("%d ",j);
					printf("%d\n",b);
				}
			}
		}
	}exit(0);
}

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

int main(){
  int n;
  cin >> n;
  vector<int> l(n);
  for(int i = 0; i < n; i++) cin >> l[i];
  sort(l.begin(), l.end());
  
  int ans = 0;
  
  for(int i = 0; i < n; i++){
    for(int j = 0; j < i; j++){
      for(int k = 0; k < j; k++){
        if(l[k] != l[j] and l[i] != l[j] and l[k] + l[j] > l[i]){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3584
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N, M = map(int, input().split())
to_y = [[] for _ in range(N)]
deg = [0] * N
stack = []
dp = [0] * N

for _ in range(M):
	x, y = map(int, input().split())
	to_y[x - 1].append(y - 1)
	deg[y - 1] += 1
	
for i in range(N):
	if deg[i] == 0:
		stack.append(i)
		
while stack:
	x = stack.pop(-1)
	for y in to_y[x]:
		dp[y] = max(dp[y], dp[x] + 1)
		deg[y] -= 1
		if deg[y] == 0:
			stack.append(y)
			
print(max(dp))

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

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) { 
        cin >> a.at(i);
    }
    rep(i, n) {
        int num = a.at(i);
         
        if (!(num % 2)) {
            if (!( (!(num % 3) || !(num % 5)) )) {
                cout << "DENIED" << endl;
                exit(0);
            }
        }
    }   
    
    cout << "APPROVED" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>

int testcase_ends() {
  size_t N;
  int T;
  size_t L, B;
  std::cin >> N >> T >> L >> B;
  if (N == 0) return 1;

  std::vector<bool> lose(N+1), back(N+1);
  for (size_t i=0; i<L; ++i) {
    size_t tmp;
    std::cin >> tmp;
    lose[tmp] = true;
  }
  for (size_t i=0; i<B; ++i) {
    size_t tmp;
    std::cin >> tmp;
    back[tmp] = true;
  }

  std::vector<std::vector<double>> dp(T+2, std::vector<double>(N+2));
  dp[0][0] = 1.0;

  for (int i=0; i<T; ++i) {
    for (size_t j=0; j<N; ++j) {
      for (int k=1; k<=6; ++k) {
        size_t nj=j+k;
        if (nj > N) {
          nj = N-(nj-N);
        }

        if (lose[nj]) {
          dp[i+2][nj] += dp[i][j]/6.0;
        } else if (back[nj]) {
          dp[i+1][0] += dp[i][j]/6.0;
        } else {
          dp[i+1][nj] += dp[i][j]/6.0;
        }
      }
    }
  }

  double res=0.0;
  for (int i=1; i<=T; ++i)
    res += dp[i][N];

  std::cout << std::fixed << std::setprecision(12);
  std::cout << res << std::endl;
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 3336
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>

using namespace std;

typedef long long ll;
const ll nmax = 1e9 + 7;
const ll mod = 998244353;
const long long INF = 1e18;
const double PI = 2 * asin(1);

int main(){
  int H, W; cin >> H >> W;
  int A[H][W];
  queue < pair<int, int> > que;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      char C; cin >> C;
      if (C == '.'){
        A[i][j] = 0;
      }else{
        A[i][j] = 1;
        que.push(make_pair(i, j));
      }
    }
  }

  int ans = 0;
  int di[4] = {-1, 0, 1, 0}, dj[4] = {0, 1, 0, -1};
  while (!que.empty()){
    pair <int, int> P = que.front(); que.pop();
    for (int k = 0; k < 4; k++){
      int I = P.first + di[k], J = P.second + dj[k];
      if (0 <= I && I < H && 0 <= J && J < W){
        if (A[I][J] == 0){
          A[I][J] = A[P.first][P.second] + 1;
          ans = A[I][J] - 1;
          que.push(make_pair(I, J));
        }
      }
    }
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 12304
#define _GLIBCXX_DEBUG
#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;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;

int main(){
  int x, y, z;
  cin >> x >> y >> z;
  int ans = (x - z) / (y + z);
  cout << ans << endl;
}

Measured memory_bytes: 256
fun main() {
    val n = nextInt()
    val a = nextIntList()
    println(res(n, a))
}

fun res(n: Int, a: List<Int>): Long {
    var tmp = a[0]
    var result = 0L
    for (i in 1 until n) {
        if (a[i] >= tmp) {
            tmp = a[i]
        } else {
            result += tmp - a[i]
        }
    }
    return result
}


fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(' ')
fun nextIntList() = nextList().map { it.toInt() }
fun nextLongList() = nextList().map { it.toLong() }
fun nextDoubleList() = nextList().map { it.toDouble() }


Measured memory_bytes: 65004
import java.util.*;

public class Main {
	static int H,W;
	static char[][] c;
	static int[][] num;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		H = sc.nextInt();
		W = sc.nextInt();
		int K = sc.nextInt();
		c = new char[H][];
		for(int i=0; i<H; i++)
			c[i] = sc.next().toCharArray();
		num = new int[H+1][W+1];
		for(int i=0; i<H; i++) {
			for(int j=0; j<W; j++) {
				num[i+1][j+1] = num[i+1][j] + num[i][j+1] - num[i][j] + (c[i][j]=='1' ? 1: 0);
			}
		}
		
		int ans = H*W;
		for(int i=0; i<1<<(H-1); i++) {
			ArrayList<Integer> cut = new ArrayList<>();
			cut.add(0);
			for(int j=0; (1<<j)<=i; j++) {
				if((i&(1<<j)) != 0)
					cut.add(j+1);
			}
			cut.add(H);
			
			int vercut = 0;
			int idx=0;
			boolean noSolution = false;
			for(int j=1; j<=W; j++) {
				boolean ok = true;
				for(int k=1; k<cut.size(); k++) {
					if(count(cut.get(k-1), idx, cut.get(k), j)>K) {
						ok = false;
						break;
					}
				}
				if(!ok) {
					if(j==idx+1) {
						noSolution = true;
						break;
					}
					vercut++;
					idx=j-1;
					j--;
				}
			}
			if(!noSolution)
				ans = Math.min(ans, cut.size()-2 + vercut);
		}
		
		System.out.println(ans);
		sc.close();
	}

	static int count(int y0, int x0, int y1, int x1) {
		return num[y1][x1] - num[y1][x0] - num[y0][x1] + num[y0][x0];
	}
}



Measured memory_bytes: 24104
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <inttypes.h>

int main(void){
	int n;
	long long int t;
	long long int T;
	int i;
	long long int ans=0;
	long long int temp=0;

	scanf("%d %lld",&n,&t);
	for(i=0;i<n;i++){
		scanf("%lld",&T);
		if(i==0){
			temp=T;
		}else{
			if(t<=T-temp){
				ans+=t;
			}else{
				ans+=T-temp;
			}
			temp=T;
		}
	}
	ans+=t;
	printf("%lld",ans);

	return 0;
}


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

int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> L(n);
    int d = 0;
    for(int i=0; i<n; i++) {
        cin >> L[i];
    }
    for(int i=0; i<n+1; i++){
        d += L[i];
        if (x<d) {
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << n+1 << endl;
    return 0;
}

Measured memory_bytes: 256
public class Main {

	public void run(java.util.Scanner sc, java.io.PrintWriter out) {
		boolean first = true;
		for (;;) {
			final int s = sc.nextInt();
			if (s == 0) break ;
			final int ba = sc.nextInt();
			final int bb = sc.nextInt();
			final int bc = sc.nextInt();
			final int bd = sc.nextInt();
			int r = 10 * ba + 50 * bb + 100 * bc + 500 * bd - s;
			final int ad = r / 500;
			r %= 500;
			final int ac = r / 100;
			r %= 100;
			final int ab = r / 50;
			r %= 50;
			final int aa = r / 10;
			r %= 10;
			
			if (!first)
				out.println();
			first = false;
			
			if (ba - aa > 0)
				out.println("10 " + (ba - aa));
			if (bb - ab > 0)
				out.println("50 " + (bb - ab));
			if (bc - ac > 0)
				out.println("100 " + (bc - ac));
			if (bd - ad > 0)
				out.println("500 " + (bd - ad));
		}
	}
	
	public static void main(String[] args) {
		final java.util.Scanner sc = new java.util.Scanner(System.in);
		final java.io.PrintWriter out = new java.io.PrintWriter(System.out);
		(new Main()).run(sc, out);
		out.flush();
		out.close();
		sc.close();
	}

}

Measured memory_bytes: 41428
s = list(input())

for i in range(2**3):
    ans = ""
    ans += s[0]
    tmp = int(s[0])
    for j in range(3):
        if (i >> j)&1:
            ans += "+" + s[j+1]
            tmp += int(s[j+1])
        else:
            ans += "-" + s[j+1]
            tmp -= int(s[j+1])
    if tmp == 7:
        print(ans+"=7")
        exit()


Measured memory_bytes: 9192
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define PI acos(-1)

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

int main() {
    int N;
    cin >> N;
    int ans;
    cin >> ans;
    Rep(i, N - 1) {
        int a;
        cin >> a;
        ans = gcd(ans, a);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
const int N=4e5+10;
int n,m,c[N],ans;
void Modify(int x)
{
	for (;x<=n;x+=x&(-x)) c[x]++;
}
int Query(int x)
{
	int sum=0;
	for (;x;x-=x&(-x)) sum+=c[x];
	return sum;
}
int main()
{
	scanf("%d",&n);
	for (int i=1,a;i<=n;i++)
	{
		scanf("%d",&a);
		Modify(a);
		if (Query(n)-Query(a-1)==i) ans++;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#define MAX 100
using namespace std;

int m, n;
int w[MAX];

bool c(int x) {
    bool used[n];
    fill(used, used + n, false);
    for (int i = 0; i < m; i++) {
        int sum = 0;
        for (int j = 0; j < n; j++) {
            if (used[j]) continue;
            if (sum + w[j] <= x) {
                sum += w[j];
                used[j] = true;
            } else {
                break;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (!used[i]) return false;
    }
    return true;
}

int main() {
    while (true) {
        cin >> m >> n;
        if (m == 0 && n == 0) return 0;
        for (int i = 0; i < n; i++) {
            cin >> w[i];
        }
        
        int l = 0, r = 1500001;
        while (r - l > 1) {
            int mid = (l + r) / 2;
            if (c(mid)) r = mid;
            else l = mid;
        }
        cout << r << endl;
    }
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)
#define deg_to_rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad_to_deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)

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

int main() {
    int n;
    cin >> n;
    cout << (n - 1) / 2 << endl;
};


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    string s;
    cin >> s;
    int sum = 700;
    for(auto c:s){
        if(c == 'o')sum += 100;
    }
    cout << sum << endl;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n,0);
	int sm=0;
	for(int i=0;i<n;i++)
	{
		cin >> a.at(i);
		sm+=a.at(i);
	}
    cout << sm - n << endl;
	return 0;
}


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

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

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

#define INF 2123456789
#define IINF 9123456789123456789
#define endl "\n"

void use_cio() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}
/*
template <typename... Args>
void dbg(Args... args) {
    ((cout << args << " "), ...);
    cout << "\n";
}
*/
//--------------------------------------------------//
int N;
int a[100010];
ll ans;
int main() {
    use_cio();
    cin >> N;
    rep(i, N) cin >> a[i];
    sort(a, a + N);
    int s = 1;
    int e = N - 2;
    deque<int> deq;
    deq.push_back(a[0]);
    deq.push_back(a[N - 1]);
    ans += abs(a[0] - a[N - 1]);
    while (s <= e) {
        ll frs = abs(deq.front() - a[s]);
        ll fre = abs(deq.front() - a[e]);
        ll bae = abs(deq.back() - a[e]);
        ll bas = abs(deq.back() - a[s]);
        ll mx = max({frs, fre, bae, bas});
        if (mx == frs) {
            deq.push_front(a[s]);
            s++;
        } else if (mx == fre) {
            deq.push_front(a[e]);
            e--;
        } else if (mx == bae) {
            deq.push_back(a[e]);
            e--;
        } else {
            deq.push_back(a[s]);
            s++;
        }
        ans += mx;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class B
{
	public static void Main()
	{
		string[] args = Console.ReadLine().Split(' ');
		int A = Int32.Parse(args[0]);
		int B = Int32.Parse(args[1]);
		int K = Int32.Parse(args[2]);

		int ans = Math.Max(A,B) + 1;
		int counter = 0;
		while(counter < K)
		{
			ans--;
			if((A % ans == 0) && (B % ans == 0))
				counter++;
		}
			
		Console.WriteLine(ans);
	}	
}





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

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

  
    int sum = 0;
    for(int i=0;i<N;i++){
        int tmp;
        cin >> tmp;
        sum += tmp;
    }
    cout << sum - N << endl;

    return 0;
}


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

using namespace std;

int main() {
	int n;
	cin >> n;
	int sum = 0;
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		sum += x;
	}
	cout << sum - n << endl;
	return 0;
} 

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W,M;
int R[303030];
int C[303030];
set<pair<int,int>> S;
pair<int,int> PR[303030],PC[303030];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>M;
	FOR(i,M) {
		cin>>y>>x;
		y--,x--;
		R[y]++;
		C[x]++;
		S.insert({y,x});
	}
	
	FOR(i,H) PR[i]={-R[i],i};
	FOR(i,W) PC[i]={-C[i],i};
	
	sort(PR,PR+H);
	sort(PC,PC+W);
	
	int ma=0;
	FOR(y,H) if(PR[y].first) {
		FOR(x,W) {
			int ty=-PR[y].first;
			int tx=-PC[x].first;
			if(ty+tx<=ma) break;
			if(tx==0) break;
			int cnt=ty+tx-(S.count({PR[y].second,PC[x].second}));
			ma=max(ma,cnt);
		}
	}
	
	cout<<ma<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 24764
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		int tmp;
		for(int i = 0; i < n; i++) {
			for(int k = i + 1; k < n; k++) {
				if(a[i] < a[k]) {
					tmp = a[i];
					a[i] = a[k];
					a[k] = tmp;
				}
			}
		}
		int count = 1;
		for(int i = 0; i < n - 1; i++) {
			if(a[i] > a[i + 1]) {
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 23764
#include <stdio.h>
int main(void)
{
  int v[5];
  int i;
  int k;
  for(i=0;i<5;i++){
  scanf("%d", &v[i]);
  if(v[i] == 0){
  k = i+1;
  break;
}
}

printf("%d",k);
  return 0;
}


Measured memory_bytes: 1732
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    double[] v = new double[n];
    for(int i = 0; i < n; i++) {
      v[i] = sc.nextDouble();
    }
    Arrays.sort(v);
    double ans = v[0];
    for(int i = 1; i < n; i++) {
      ans = (ans + v[i]) / 2; 
    }
    System.out.println(ans);
  }
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;

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

	int diff = b - a;

	int ans = 0;

	for (int i = 1; i < diff; i++) ans += i;

	cout << ans - a << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int q;
	scanf("%d",&q);
	while(q--)
	{
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		int k;
		if(a<b)
		{
			k=(a+b)/(a+1);
		}
		else
		{
			k=(a+b)/(b+1);
		}
		if(k==1)
		{
			for(int i=c;i<=d;i++)
			{
				if(b>a)
				{
					putchar('A'+(i&1));
				}
				else
				{
					putchar('B'-(i&1));
				}
			}
			putchar('\n');
			continue;
		}
		long long rm=(long long)k*(a+1)-b;
		int wz=0;
		if(rm)
		{
			int tim=0;
			if(rm>=(long long)k*k)
			{
				tim=(rm-1)/((long long)k*k-1);
			}
			wz+=tim*(k+1);
			rm-=tim*((long long)k*k-1);
			wz+=rm/k;
			rm-=rm/k*k;
		}
		for(int i=c;i<=d;i++)
		{
			if(i<=wz)
			{
				putchar('A'+(i%(k+1)==0));
			}
			else
			{
				putchar('A'+((i-wz+rm)%(k+1)!=0));
			}
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
using namespace std;

long long calc(long long A) {

	if (A <= 0) return 0;

	//4の時に、0,1,2,3,4までになるので、これは5つの整数まで
	//なので帳尻合わせで１足してあげる。
	A++;
	//10^3 <= 2^10
	//1000 <= 1024
	//10^12 <= 2^40
	//10^12 <= 2進数 40桁くらい

	long long ans = 0;
	//i桁目の偶奇を調べる
	for (int i = 0; i < 50; i++)
	{
		//0桁目 → 周期2
		//1				4
		//2				8
		long long loop = (1LL << (i + 1));
		long long cnt = (A / loop) * (loop / 2);
		//00000.....0011111.....11
		cnt += max(0LL, (A % loop) - (loop / 2));

		//その桁の1の数が奇数だったら足し算
		if (cnt % 2 == 1) {
			ans += 1LL << i;
		}
	}

	return ans;
}

int main() {
	long long A, B;
	cin >> A >> B;
	long long ans = calc(B) ^ calc(A - 1);
	cout << ans << endl;
}



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

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string a;
    cin >> n >> a;
    int count = 0;
    for (int i = 0; i < n-2; ++i) {
        if (a[i] == 'A' && a[i+1] == 'B' && a[i+2] == 'C') count++;
    }
    cout << count << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

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

	while(true) {
		string x;
		getline(cin, x);
		if(x == "0") break;
		int sum = 0;
		while(x != "") {
			sum += x[0] - '0';
			x = x.substr(1);
		}
		cout << sum << endl;
	}
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;

 
int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if (a==c) cout << b << endl;
    else if (a==b) cout << c  << endl;
    else cout << a << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(P: int, Q: int, R: int):
    print(P + Q + R - max(P, Q, R))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    P = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    solve(P, Q, R)


if __name__ == '__main__':
    main()


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n,m,v,p;
int a[125252];
ll s[125252];

int main(){
    scanf("%d%d%d%d", &n, &m, &v, &p);
    REP(i,n)scanf("%d", a+i);
    sort(a,a+n);
    REP(i,n)s[i+1] = s[i] + a[i];
    int ans = 0;
    REP(i,n){
        {
            int u = upper_bound(a,a+n,a[i])-a-1;
            if(u >= n - p){
                ans++; continue;
            }
        }

        ll vote = 1ll * m * (v-1);
        int o = upper_bound(a,a+n,a[i]+m)-a;
        int d = upper_bound(a,a+n,a[i]-1)-a;

        int over = n-o;
        if(over >= p)continue;

        vote -= 1ll * (p-1) * m;
        vote -= 1ll * d * m;
        vote -= 1ll * (n - (p-1) - d) * (a[i]+m) - (s[n-(p-1)] - s[d]) - m;
        // printf("i=%d: vote=%lld\n",i,vote);
        if(vote <= 0){
            ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1408
import math
N,D=map(int,input().split(" "))
X=[input().split(" ") for _ in range(N)]

Ans_List=[]
for i in range(N):
    for j in range(i+1,N):
        Sum=0
        for k in range(D):
            Sum+=(int(X[i][k])-int(X[j][k]))**2
        Ans_List.append(math.sqrt(Sum))
        
count=0
for i in Ans_List:
    if int(i)==i:
        count+=1
        
print(count)

Measured memory_bytes: 3064
def can_win_without_repeated_move(health, special_moves_damages) -> str:
    """
    Given a monster's health and a number of special moves with differ damages, 
    can we deplete the monster's health without repeating the same move twice?
    :param health: int
    :param special_moves_damages: list[int] 
    :return: str
    """
    return 'Yes' if health - sum(special_moves_damages) <= 0 else 'No'


if __name__ == '__main__':
    print(can_win_without_repeated_move(list(map(int, input().split()))[0], list(map(int, input().split()))))


Measured memory_bytes: 13964
#include<stdio.h>

int main(){
  char str[200] = {};
  long n = 0;
  long hofu[100] = {};
  long hofucnt = 0;
  long k = 0;
  long i = 0;
  long kaburi = 0;
  long ryotan = 0;
  long hoge = 0;
  long long count = 0;
  
  scanf(" %s",str);
  scanf("%ld",&k);
  //printf("%s",str);
  for(i=0;i<100;i++){
    if(str[i] != '\0'){
      n++;
    }else{
      break;
    }
  }
  //printf("%ld/",n);
  if(str[0] == str[n-1]){
    ryotan = 1;
  }
  
  hofu[0] = 1;
  hofucnt = 0;
  str[n] = str[0];
  for(i=1;i<n;i++){
    if(str[i-1] == str[i]){
      hofu[hofucnt]++;
    }else{
      hofucnt++;
      hofu[hofucnt]++;
    }
  }
  
  /*for(i=0;i<=hofucnt;i++){
    printf("%ld.",hofu[i]);
  } */
  if((!ryotan || hofucnt == 0)&&(n!=1)&&(hofucnt!=0)){
    for(i=0;i<=hofucnt;i++){
      kaburi += hofu[i]/2;
    }
    count = k * kaburi;
  }else if(n==1){
    count = k / 2;
  }else if(hofucnt==0){
    count = (n * k)/2;
  }else{
    for(i=1;i<=hofucnt-1;i++){
      kaburi += hofu[i]/2;
    }
    //printf("%ld/%ld/%ld/",kaburi,hofucnt,hofu[hofucnt] + hofu[0]);
    kaburi += (hofu[hofucnt] + hofu[0])/2;
    count = kaburi * (k) -((hofu[hofucnt] + hofu[0])/2)+ (hofu[0] / 2) + (hofu[hofucnt] / 2);
  }
  printf("%lld",count);
  return 0;
  //ssllsssssllsssssllsss
  //issiiissii
}
    

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

int N, M;
int A[301][301];
int current[301];
int selected[301];
int cnt[301];

inline int solve() {
    int ans = N;
    for(int k = 0; k < M - 1; k++) {
        for(int i = 0; i < M; i++) cnt[i] = 0;
        for(int i = 0; i < N; i++) {
            while(selected[A[i][current[i]]]) current[i]++;
            cnt[A[i][current[i]]]++;
        }
        int tmp = 0, max_id;
        for(int i = 0; i < M; i++) {
            if(tmp < cnt[i]) {
                tmp = cnt[i];
                max_id = i;
            }
        }
        ans = min(ans, tmp);
        selected[max_id] = 1;
    }
    return ans;
}

int main() {
    fastio();
    cin >> N >> M;
    REP(i, N) REP(j, M) {
        cin >> A[i][j];
        A[i][j]--;
    }
    cout << solve() << "\n";
	return 0;
}

Measured memory_bytes: 640
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var mod = 1e9 + 7;
function abmod(){for(var a=arguments,r=a[0],i=1;i<a.length;)r=((r>>16)*a[i]%mod*65536+(r&65535)*a[i++])%mod;return r;}
var fact=[1,1];
function factmod(n){for(var i=fact.length;i<=n;i++)fact[i]=abmod(fact[i-1],i);return fact[n];}
function nCrmod(n,r){return abmod(factmod(n),modinv(factmod(r)),modinv(factmod(n-r)));}
function modinv(a){for(var b=mod,u=1,v=0,t;b;v=t)t=a/b|0,a-=t*b,u-=t*v,t=a,a=b,b=t,t=u,u=v;u%=mod;return u<0?u+mod:u;}

console.log(main());
function main(){
  var n = o.a();
  var m = o.a();
  var k = o.a();
  var a = xArray(0,n,m);
  for(var x = 0; x < m; x++){
    for(var y = 0; y < n; y++){
      a[y][x] = (f(x+1) + f(m-x)) * n;
      a[y][x] += (f(y+1) + f(n-y)) * m;
    }
  }
  var ans = 0;
  for(var x = 0; x < m; x++){
    for(var y = 0; y < n; y++){
      ans += a[y][x];
    }
  }
  ans %= mod;
  return abmod(ans,nCrmod(n*m-2,k-2),modinv(2));
}
function f(a){
  return a*(a-1)/2;
}

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

int main()
{
    int n, b, r, f, v;
    cin >> n;
    int info[4][3][10]={0};
    for(int i=0; i<n; ++i)
    {
        cin >> b >> r >> f >> v;
        info[b-1][r-1][f-1] += v;
    }
    for(int i=0; i<4; ++i){
        for(int j=0; j<3; ++j){
            for(int k=0; k<10; ++k){
                cout << " " << info[i][j][k];
            }
            cout << endl;
        }
        if(i != 3) cout << "####################" << endl;
    }
    return 0;
}


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

int main(){
    int n;
    string s;
    cin>>n>>s;
    int count=0;
    for(int i=0;i<n-2;i++){
        if(s.substr(i,3)=="ABC"){
            count+=1;
        }
        else int unko=0;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int t = sc.nextInt();
        int s = sc.nextInt();
      
        double m = (double)d/s;
        if(m <= t){
          System.out.println("Yes");
        }else{
          System.out.println("No");
        }
		
	}
}

Measured memory_bytes: 35680
#include<bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define m_p make_pair
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef vector<vector<ll>> vvl;
int main()
{
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	if(a>=k)
	{
		cout<<k<<endl;
	}
	else if(b+a>=k)
	{
		cout<<a<<endl;
	}
	else if(b+a+c>=k)
	{
		ll he = a;
		ll cha = k-(a+b);
		he-=cha;
		cout<<he<<endl;
	}
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const string YES = "Yes";
const string NO  = "No";

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

    string s, new_s;
    bool flg = false;

    cin >> s;

    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'C' || s[i] == 'F') {
            new_s += s[i];
        }
    }

    for (int i = 0; i < new_s.size(); ++i) {
        if (new_s.substr(i, 2) == "CF") {
            flg = true;
            break;
        }
    }

    cout << (flg ? YES : NO) << endl;

    return 0;
}



Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (L, R) = listOfLong()
    var ans = Long.MAX_VALUE
    for (i in L .. R-1) {
        if (i > L + 2019) break
        for (j in i+1 .. R) {
            if (j > i + 2019) break
            ans = Math.min(ans, (i * j) % 2019)
        }
    }
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfLong(delta: Long = 0L) = listOfString().map { it.toLong() + delta }


Measured memory_bytes: 37680
#include <stdio.h>
int main() {
    int A, B, C, D;
    scanf("%d%d%d%d", &A, &B, &C, &D);
    while(1){
        C -= B;
        if(C<1){
          printf("Yes\n");
          break;
        }
        A -= D;
        if(A<1){
          printf("No\n");
          break;
        }
    } return 0;
}

Measured memory_bytes: 1620
open System

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f

    let readInts() =
        read string
        |> Seq.toArray
        |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<EntryPoint>]
let main _ =
    let [| H; W |] = reada int
    let S = Array.zeroCreate H
    for y in 0 .. H - 1 do
        S.[y] <- reada string

    for y in 0 .. H - 1 do
        for x in 0 .. W - 1 do
            if S.[y].[x] = "snuke" then
                let a = sprintf "%c%d" (65 + x |> fun b -> Convert.ToChar(b)) (y + 1)
                printfn "%s" a

    0 // return an integer exit code


Measured memory_bytes: 14288
//==========================Head files==========================
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<iostream>
#include<map>
#define LL long long
#define db double
#define mp make_pair
#define pr pair<int, int>
#define fir first
#define sec second
#define pb push_back
#define ms(i, j) memset(i, j, sizeof i)
using namespace std;
//==========================Templates==========================
inline int read() {
    int x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
inline LL readl() {
    LL x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
int power(int a, int b) {
	int ans = 1;
	while (b) {
		if(b & 1) ans = ans * a;
		b >>= 1; a = a * a;
	}
	return ans;
}
int power_mod(int a, int b, int mod) {
	a %= mod;
	int ans = 1;
	while (b) {
		if(b & 1) ans = (ans * a) % mod;
		b >>= 1, a = (a * a) % mod;
	}
	return ans;
}
LL powerl(LL a, LL b) {
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = ans * a;
		b >>= 1ll;a = a * a;
	}
	return ans;
}
LL power_modl(LL a, LL b, LL mod) {
	a %= mod;
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = (ans * a) % mod;
		b >>= 1ll, a = (a * a) % mod;
	}
	return ans;
}
LL gcdl(LL a, LL b) {return b == 0 ? a : gcdl(b, a % b);}
LL abssl(LL a) {return a > 0 ? a : -a;}
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
int abss(int a) {return a > 0 ? a : -a;}
//==========================Main body==========================
#define LD "%I64d"
#define D "%d"
#define pt printf
#define sn scanf
#define pty printf("YES\n")
#define ptn printf("NO\n")
//==========================Code here==========================
int n, d, vis[100000 + 5];
int x[15][15];
int main() {
	cin >> n >> d;
	for (int i = 1; i <= 100000; ++i) {
		if (i * i <= 100000) vis[i * i] = 1;
		else break ;
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= d; ++j) {
			scanf("%d", &x[i][j]);
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			LL tmp = 0;
			for (int k = 1; k <= d; ++k) tmp += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
			if (vis[tmp]) ++ans;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll ; 
typedef long double ld ;
typedef pair<ll , ll> pll ;

const ll N = 2e5 + 30 , Mod = 1e9 + 7 ;
const ll SQ = 330 ;

ll dp[40][40]  , n;
string s ;
ll calc(ll mask) {
	for (int i =0 ; i < 20 ; i ++) for (int j = 0 ; j < 20  ; j ++) dp[i][j]= 0 ;
	dp[0][0] = 1 ;
	string a = "" , b= "" ;
	for (int i = 0 ; i < n ; i ++) {
		if (mask & (1 << i)) a += s[i] ;
		else b += s[i] ;
	}
	for (int i = 0 ; i <= n  ; i ++) {
		for (int j = 0 ; j <= n ; j ++) {
			if (s[n + n - i - j  - 1] == b[j ]) dp[i][j + 1] += dp[i][j] ;
			if (s[n + n - i - j  - 1] == a[i]) dp[i + 1][j] += dp[i][j] ;
		}
	}
	return  dp[a.size()][b.size()] ;
}
int main () {
    ios::sync_with_stdio(0), cin.tie(0) ;
    
    cin >> n ;
    
    cin >> s ;
	ll ans = 0 ;
    for (int mask = 0 ; mask < (1 << n) ; mask ++) 
    	ans += calc(mask) ;
    cout << ans ;
    
    return (0) ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int,int>;
const int INF = 1e9+7;

int main() {
  int n;
  cin >> n;
  vector<vector<bool> > b(n);
  rep (i,n) {
    int a; cin >> a;
    b[i] = vector<bool>(32, false);

    int j = 0;
    rep(j,32) {
      if (a % 2 == 1) b[i][j] = true;
      a /= 2;
    }
  }

  vector<bool> f(32);
  rep(j,32) {
    rep(i,n) {
      if (b[i][j]) f[j] = !f[j];
    }
  }

  rep(i,n) {
    int d = 1;
    int sum = 0;
    rep(j,32) {
      if (f[j]) b[i][j] = !b[i][j];
      if (b[i][j]) sum += d;
      d *= 2;
    }
    printf("%d ", sum);
  }
}


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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    vector<int> a(m+5);
    vector<int> b(m+5);
    vector<vector<int>> c(m+5, vector<int> (n+5, -1));

    for (int i=1; i<=m; i++){
        cin >> a.at(i) >> b.at(i);
        for (int j=1; j<=b.at(i); j++){
            cin >> c.at(i).at(j);
        }
    }

    int bit_n;
    bit_n = 1 << n;
    int INT = 1e9;
    vector<int> dp(bit_n, INT); // bit_n >> i & 1 = 1 の箱を開けたときの最小費用

    dp.at(0) = 0; // 箱を開けないときは 費用0

 
    for (int i=1; i<=m; i++){
        int op = 0;
        for (int j=1; j<=b.at(i); j++){
            op |= (1 << (c.at(i).at(j) - 1));
        }
        // 動的計画法の漸化式
        for (int bit=0; bit < (1 << n); bit++){
            chmin(dp.at(bit|op), dp.at(bit)+a.at(i));
        }
    }

    if (dp.at(bit_n-1) == INT){
        cout << -1 << endl;
    }else{
        cout << dp.at(bit_n-1) << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

int v[20];

bool dfs(const int cur, const int lv, const int rv) {
  bool ret = false;
  if (cur == 10) return true;
  // left
  if (v[cur] > lv) ret |= dfs(cur+1, v[cur], rv);
  // right
  if (v[cur] > rv) ret |= dfs(cur+1, lv, v[cur]);
  return ret;
}

int solve() {
  return dfs(0, 0, 0);
}

int main() {
  int N;
  cin >> N;
  while (N--) {
    for (int i = 0; i < 10; ++i)
      cin >> v[i];
    printf("%s\n", solve() ? "YES" : "NO");
  }
  return 0;
}

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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

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

  ll a, b, c;
  cin >> a >> b >> c;
  cout << ((a + b >= c) ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 3588
#include<stdio.h>
#include<stdlib.h>

int main(void){
  int a,b,c,k;
  
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&k);
  
  if(k <= a){
    printf("%d",k);
  }else if(k <= a+b){
    printf("%d",a);
  }else{
    printf("%d",a-(k-a-b));
  }
  
 return 0;
  
}

Measured memory_bytes: 1696
import java.util.HashMap;
import java.util.Scanner;

public class Main {

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

		int N = sc.nextInt();

		HashMap<Integer, Integer> kamikire = new HashMap<Integer, Integer>();
		for (int i = 0; i < N; i++) {
			int num = sc.nextInt();
			if (kamikire.containsKey(num)) {
				int value = kamikire.get(num);
				kamikire.put(num, ++value);
			} else {
				kamikire.put(num, 1);
			}
		}
		int counter = 0;
		for (Integer i : kamikire.keySet()) {
			if (kamikire.get(i) % 2 != 0)
				counter++;
		}
		System.out.println(counter);
	}
}


Measured memory_bytes: 64624