akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int N = fs.nextInt();
        int D = fs.nextInt();
        int[][] matrix = new int[N][D];

        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < D; ++j) {
                matrix[i][j] = fs.nextInt();
            }
        }

        int ans = 0;
        for (int i = 0; i < N-1; ++i) {
            for (int j = i+1; j < N; ++j) {
                int tmp = 0;
                for (int k = 0; k < D; ++k) {
                    tmp += (matrix[i][k] - matrix[j][k]) * (matrix[i][k] - matrix[j][k]);
                }
                for (int k = 1; k <= Math.sqrt(tmp); ++k) {
//                    System.out.println(tmp);
                    if (k * k == tmp) {
                        ++ans;
                        break;
                    }
                }
            }
        }

        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}

    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() { return Double.parseDouble(next());}
}




Measured memory_bytes: 32508
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int a,b; cin >> a >> b;
    cout << max({a + b, a + a-1,b + b - 1}) << endl;
}




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

int main()
{
  string s;
  int n;
  cin >> n;
  int a[n];
  ll ans = 0;
  rep(i,n) cin >> a[i];
  rep(i,n){
    for(int j = i; j < n; j++){
      if(i == j) continue;
      ans += a[i] * a[j];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3608
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
//#define _LIBCPP_DEBUG 0
//#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)	
using namespace std;

int max(int a, int b) {
	int max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(int a, int b) {
	int min;
	if (a < b) min = a;
	else min = b;
	return min;
}


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

	int m = max(a, c);
	int mm = min(b, d);

	cout << max(0, mm - m) << endl;

}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int Grundy[100050];
int N;
vector<int> pathes[100500];
int parent[100050];

void bfs(int from) {
    Grundy[from] = 0;
    for(int i = 0; i < pathes[from].size(); i++) {
        int to = pathes[from][i];
        if(to == parent[from]) continue;
        parent[to] = from;
        bfs(to);
        Grundy[from] ^= (Grundy[to] + 1);
    }
    return;
}

int main() {
    //cout.precision(10);
    cin >> N;
    for(int i = 1; i < N; i++) {
        int x, y;
        cin >> x >> y;
        pathes[x].push_back(y);
        pathes[y].push_back(x);
    }
    parent[1] = -1;
    bfs(1);
    if(Grundy[1] == 0) cout << "Bob" << endl;
    else cout << "Alice" << endl;
    return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int digit_sum(int n) {
  int sum=n%10;
  while(n!=0) {
    n/=10;
    sum+=n%10;
  }
  return sum;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  vi ali(101,0),bob(101,0);
  REPD(i,a,b-1) {
    ali[i]=1;
  }
  REPD(i,c,d-1) {
    bob[i]=1;
  }
  int ans =0;
  REP(i,101) {
    if(ali[i]==1&&bob[i]==1) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3588
#include <stdio.h>
int main(void){
    int m,f,r;
	while(1){
		scanf("%d %d %d",&m,&f,&r);
		if(m==(-1)&&f==(-1)&&r==(-1)) break;
		if(m==(-1)||f==(-1))
			putchar('F');
		else if(m+f>=80)
			putchar('A');
		else if(m+f>=65&&m+f<80)
			putchar('B');
		else if(m+f>=50&&m+f<65)
			putchar('C');
		else if(m+f>=30&&m+f<50)
			if(r>=50) putchar('C');
			else putchar('D');
		else
			putchar('F');
		putchar('\n');
	}		
	return 0;
}


Measured memory_bytes: 2068
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

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

	vector<int64_t> a(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	
	vector<int64_t> pos_cumsum(n + 1), neg_cumsum(n + 1);
	
	for(int i = 0; i < n; ++i) {
		if(a[i] > 0) {
			pos_cumsum[i + 1] = pos_cumsum[i] + a[i];
			neg_cumsum[i + 1] = neg_cumsum[i];
		} else {
			pos_cumsum[i + 1] = pos_cumsum[i];
			neg_cumsum[i + 1] = neg_cumsum[i] + a[i];
		}
	}

	
	int64_t ans = 0;
	for(int i = k; i <= n; ++i) {
		int64_t l = pos_cumsum[i - k];
		int64_t m = pos_cumsum[i] - pos_cumsum[i - k] + neg_cumsum[i] - neg_cumsum[i - k];
		int64_t r = pos_cumsum[n] - pos_cumsum[i];
		
		ans = max(ans, l + r + max(int64_t(0), m));
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 2560
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


N = d_in()
A = s_in()
B = s_in()
C = s_in()

ans = 0
for i in range(N):
    s = set([A[i], B[i], C[i]])
    ans += len(s) - 1
print(ans)



Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<stdio.h>
#include<queue>
#include<map>
#include<stack>
using namespace std;
int dx[] = { -1,0,0,1,-1,-1,1,1,0 };
int dy[] = { 0,1,-1,0,1,-1,1,-1,0 };
/*
int main()
{
	int r, c;
	cin >> r >> c;
	int sy, sx, gy, gx;
	vector<vector<char>>field(r,vector<char>(c));
	sy--, sx--, gy--, gx--;
	for (int i = 0; i < r; i++)
	{
		for (int j = 0; j < c; j++)
		{
			cin >> field[i][j];
		}
	}
	queue<pair<int,int>>q;
	q.push({ sx,sy });
	vector<vector<int>>d(c, vector<int> (r, -1));
	d[sx][sy] = 0;

	while (!q.empty())
	{
		pair<int, int>p = q.front;
		q.pop();
		for (int i = 0; i < 4; i++)
		{
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if (nx < 0 || ny < 0 || nx >= c || ny >= r || d[nx][ny] != -1 || field[nx][ny] == '#')continue;
			q.push({ nx,ny });
			d[nx][ny] = d[p.first][p.second] + 1;
		}
	}

	cout << d[gx][gy] << endl;
}*/


int main() 
{
	int n;
	cin >> n;
	vector<int>x(n);
	for (int i = 0; i < n; i++)
	{
		cin >> x[i];
	}

	int ans = 0;
	int ans2 = 0;

	for (int i = 1; i <= 100; i++)
	{


		for (int j=0; j < n; j++)
		{
			int a;
			a = (x[j] - i)*(x[j] - i);
			ans = ans + a;

		}

		if (i == 1)
		{
			ans2 = ans;
		}
		else
		{
			if (ans2 > ans)
			{
				ans2 = ans;
			}
		}

		ans = 0;


		
		
	}

	cout << ans2 << endl;



}



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

const int N = (1e5) + 5;
int n, a[N];

// claudio van
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = n - 2; i >= 0; --i) {
    if (a[i] <= a[i + 1]) continue;
    a[i]--;
    if (a[i] <= a[i + 1]) {
      continue;
    } else {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

k=n_in()
s=s_in()

if len(s) <= k:
    print(s)
else:
    print(s[:k]+"...")
    


Measured memory_bytes: 61672
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int X, Y;
  int a,s;
 
  cin >> X;

  //500yen
  a = X/500;
  Y = X - a*500;

  s = Y/5;
  cout << 1000*a + 5*s << endl;
 
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main{
	
	static int[] alpha = new int[] {1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25};
	
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		for(int i = 0; i < n; i++){
			System.out.println(decode(sc.nextLine()));
		}
		sc.close();
	}
	
	static int charToInt(char c) {
		return c - 'a';
	}
	
	static char intToChar(int i) {
		return (char) ('a' + i);
	}
	
	static char shiftAffine(int alpha, int beta, char c) {
		int result = (alpha * charToInt(c) + beta) % 26;
		return intToChar(result);
	}
	
	static String shiftAffine(int alpha, int beta, String str) {
		char[] ca = str.toCharArray();
		char[] result = new char[ca.length];
		for(int i = 0; i < ca.length; i++) {
			if(ca[i] >= 'a' && ca[i] <= 'z')
				result[i] = shiftAffine(alpha, beta, ca[i]);
			else result[i] = ca[i];
		}
		return String.valueOf(result);
	}
	
	static String decode(String str) {
		for(int i = 0; i < alpha.length; i++) {
			for(int j = 0; j < 26; j++) {
				String result = shiftAffine(alpha[i], j, str);
				if(result.contains("that")) return result;
				if(result.contains("this")) return result;
			}
		}
		return null;
	}
}

Measured memory_bytes: 21340
N = int(input())
A = [None] * 2
for i in range(2):
  A[i] = list(map(int, input().split()))
  
ans = 0
for i in range(N):
  tmp = sum(A[0][0:i+1]) + sum(A[1][i:])
  if tmp > ans:
    ans = tmp
print(ans)

Measured memory_bytes: 3060
mod = 1000000000 + 7
 
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr
 
n = int(input())
dat = [0] * 2000 # 約数として求められたある数の合計
 
# N! の各要素の素因数分解をする
res = 1
for i in range(1, n + 1):
    d = factorization(i)
    for j in range(len(d)):
        dat[d[j][0]] += d[j][1]
 
for i in range(2, n + 1):
    res *= (dat[i] + 1)
    res %= mod
 
print(res)

Measured memory_bytes: 42220
def solve():
    N = int(input())
    A = map(int, input().split())
    mod_2 = 0
    mod_4 = 0
    mod_odd = 0
    for a in A:
        if a % 4 == 0: mod_4 += 1
        elif a%2 == 0: mod_2 += 1
        else: mod_odd += 1
    
    mod_2 = mod_2 % 2
    print('Yes' if mod_4 - (mod_2 + mod_odd) >= -1 else 'No')
    
solve()

Measured memory_bytes: 11096
n, m = map(int, input().split())
# n, m = map(int, "12 3".split())
# inputText2 = "4 56 78 901 2 345 67 890 123 45 6 789"
inputText2 = input()
input2List = list(map(int,inputText2.split()))
sortList = sorted(input2List, reverse=True)
# print(sortList) #380 19 1000
total = sum(sortList)
# print(total)
h = (1/(4*m)) * total
flg = False
for i in range(m):
    if sortList[i] < h:
        flg = True
        break


if  flg:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define all(a)  (a).begin(),(a).end()

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 gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  string s; cin >> s;
  int n = s.size();

  long ans = 0;
  for (int bit = 0; bit < (1<<n-1); bit++) {
    string t;
    t += s[0];
    for (int i = 0; i < n-1; i++) {
      if(bit & (1<<i)){
        ans += stol(t);
        t = s[i+1];
      }
      else t += s[i+1];
    }
    ans += stol(t);
  }

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


Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
	String S =sc.next();
	if(n%2!=0){
	    System.out.println("No");
	}else{
	    if(S.substring(0,n/2).equals(S.substring(n/2,n))){
		System.out.println("Yes");
	    }else{
		System.out.println("No");
	    }
	}
    }
}
	       


Measured memory_bytes: 22612
#!/usr/bin/env python3
import sys
import collections as cl


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    N = input()

    print("No" if N[0] == N[1] == N[2] else "Yes")


main()


Measured memory_bytes: 65048
#include <iostream>
#include <utility>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;

int main()
{
    int n;
    cin >> n;
    ll a[200002], b[200002];
    priority_queue<P> que;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++){
        cin >> b[i];
        que.push(P(b[i], i));
    }
    ll ans = 0;
    int count = 0;
    while(!que.empty()){
        P now = que.top();
        que.pop();
        int num = now.second;
        if(b[num] < a[num]){
            cout << -1 << endl;
            return 0;
        }
        if(b[num] == a[num]) continue;
        ll lr = b[(num + n - 1) % n] + b[(num + 1) % n];
        ans += ((b[num] - a[num]) / lr);
        b[num] -= ((b[num] - a[num]) / lr) * lr;
        now.first = b[num];
        que.push(P(b[num], num));
        count++;
        if(count > 5000000){
            cout << -1 << endl;
            return 0;
        }
    }
    bool able = true;
    for(int i = 0; i < n; i++){
        if(a[i] != b[i]) able = false;
    }
    if(able) cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 8944
#include <iostream>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <limits.h>
#include <math.h>
#include <utility>
#include <algorithm>
using namespace std;
 
#define mod 1000000007
#define ll long long
#define tc int t; cin >> t; for(int tt = 1; tt <= t; tt++)
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ERR
#ifdef ERR
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define deb(...)
#endif

// Dirty Fix
// #define int long long


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

signed main(void)
{
    ios;
    #ifndef ONLINE_JUDGE
    //  freopen("../in.txt","r",stdin);
    #endif
    string s,t;
    cin >> s >> t;
    vector<vector<int>> dp(t.length(),vector<int>(s.length()));
    for(int i = 0; i < (int)t.length(); i++){
        for(int j = 0; j < (int)s.length(); j++){
            if(t[i] == s[j]){
                if(i > 0 && j > 0){
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                }else
                    dp[i][j] = 1;
            }else{
                if(j > 0)
                    dp[i][j] = dp[i][j - 1];
                if(i > 0)
                    dp[i][j] = max(dp[i - 1][j],dp[i][j]);
            }
        //    cout <<  dp[i][j] << " ";      
        }
        // cout << endl;
    }
    string ans = "";
    int i = t.length() - 1,j = s.length() - 1;
    while(1){
        if(dp[i][j] == 0){
            break;
        }
        if(i > 0 && dp[i][j] == dp[i - 1][j]){
            i--;
        }else if(j > 0 && dp[i][j] == dp[i][j - 1]){
            j--;
        }
        else if(i > 0 && j > 0 && dp[i][j] == (1 + dp[i - 1][j - 1])){
            ans = t[i] + ans;
            i--,j--;
        }
        else{
            ans = t[i] + ans;
            break;
        }
    }
    cout << ans << " "<< endl;
    return 0;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;
ll gcd(ll a, ll b);
ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);


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

ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}

int main(void){
  ll n, m;
  cin >> n >> m;
  
  if (abs(n - m) >= 2){
    cout << 0 << endl;
  }
  else if (abs(n - m) == 1){
    cout << fact(n) * fact(m) % MOD << endl;
  }
  else {
    cout << 2 * fact(n) * fact(m) % MOD << endl;
  }
  

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int n,i,minv,maxv;
  int R[200000];

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

  minv = R[0];
  maxv = R[1] - R[0];

  for(i = 1;i < n;i++){
    if(maxv < R[i]-minv){
      maxv = R[i] - minv;
    }
    if(minv > R[i]) {
      minv = R[i];
    }
  }

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

  return 0;
}



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

int main()
{
  ll n, k, c; cin >> n >> k >> c;
  string s; cin >> s;
  vector<ll> a(n, -1);
  vector<ll> b(n, -1);

  {
    ll cnt = 0;
    for (int i=0; i<n&&cnt<k; i++) {
      if (s[i] == 'o') {
        cnt++;
        a[i] = cnt;
        i += c;
      }
    }
  }
  {
    ll cnt = 0;
    for (int i=n-1; i>=0&&cnt<k; i--) {
      if (s[i] == 'o') {
        cnt++;
        b[i] = k-cnt+1;
        i -= c;
      }
    }
  }
  vector<ll> ans;
  for (int i=0; i<n; i++) {
    if (a[i]>0&&a[i]==b[i]) ans.push_back(i+1);
  }
  if (ans.empty()) cout << endl;
  else for (auto v:ans) cout << v << endl;

  return 0;
}


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

using namespace std;

int main(){
    int time,ope,num;
    vector<int> in,out;

    cin>>time;
    for(int i=0;i<time;i++){
        cin>>ope;
        if(ope==0){
            cin>>num;
            in.push_back(num);
        }

        else if(ope==1){
            cin>>num;
            out.push_back(in[num]);
        }

        else in.pop_back();        
    }

    for(vector<int>::size_type i=0;i!=out.size();i++){
        cout<<out[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 4180
#include <iostream>

using namespace std;

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

const int MAX = 1e5 + 9;
int a[MAX];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i < n; i++) {
		a[i] = gcd(a[i-1], a[i]);
	}
	cout << a[n-1] << '\n';
	
	return 0;
}


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

int main() {
  ll h, n;
  cin >> h >> n;
  ll asum=0;
  for(int i=0;i<n;i++) {
    ll temp;
    cin >> temp;
    asum+=temp;
  }
  if(asum>=h) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	int N;
  	cin >> N;
  	int arr[N];
  	int average = 0;
  	for (int i = 0; i<N; i++) {
		cin >> arr[i];
      	average += arr[i];
    } average /= N;
  	int total = 0;
  	for (int i=0; i<N; i++) total += abs(average-arr[i]) * abs(average-arr[i]); 
  	int total2 = 0;
  	average++;
  	for (int i=0; i<N; i++) total2 += abs(average-arr[i]) * abs(average-arr[i]);
  	cout << min(total, total2);
}

Measured memory_bytes: 256
N = int(input())
S = list(map(int, input()))
r1 = { i: 0 for i in range(10) }
for i in range(N-2):
  c = S[i]
  if r1[c] > 0:
    continue
  r2 = { i: 0 for i in range(10) }
  for j in range(i+1, N-1):
    d = S[j]
    if r2[d] > 0:
      continue
    n = len(set(S[j+1:]))
    r2[d] = n
  for i in r2:
    r1[c] += r2[i]
r = 0
for i in r1:
  r += r1[i]
print(r)


Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
LL A[114514];
bool is_composite[114514];
vector<LL> ps;

vector<LL> Facts(LL x) {
  vector<LL> ret;
  for (LL p : ps) {
    if (x%p == 0) ret.eb(p);
  }

  if (ret.empty() && x > 1) ret.eb(x);
  return ret;
}

int main() {
  reps(i, 2, 114514) {
    if (is_composite[i]) continue;
    for (int j=i+i; j<114514; j+=i) is_composite[j] = true;
    ps.eb(i);
  }

  scanf("%d", &N);
  rrep(i, N+1) {
    scanf("%lld", &A[i]);
  }

  vector<LL> ans;
  auto qs = Facts(llabs(A[N]));
  if (A[0] != 0) {
    ps = qs = Facts(A[0]);
  }

  for (LL q : qs) {
    bool ok = true;
    //assert(A[N]%q == 0);
    rep(i, N+1) {
      if (A[i]%q != 0) {
        ok = false;
        break;
      }
    }
    if (ok) ans.eb(q);
  }
  
  for (LL p : ps) {
    bool out = false;
    rep(s, p-1) {
      if (s > N) break;
      LL sm = 0;
      for (int i=s; i<=N; i+=p-1) {
        sm += A[i];
        sm %= p;
      }

      if (sm != 0) {
        out = true;
        break;
      }
    }
    if (!out) ans.eb(p);
  }
  sort(all(ans));
  ans.erase(unique(all(ans)), ans.end());
  for (auto p : ans) {
    printf("%lld\n", p);
  }
}


Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#include<iomanip>
#include<set>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;

int main() {
    int n, x; cin >> n >> x;
    ll sum = 0; //can just?
    int a[n]; rep(i, n) {cin >> a[i]; sum += a[i];}
    if (sum == x) {cout << n << endl; return 0;}
    sort(a, a + n);
    sum = 0;
    int cnt = 0;
    rep(i, n - 1) {
        if (sum + a[i] > x) break;
        sum += a[i];
        cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<string.h>
#include<stdio.h>
int main(void)
{
    char s[100];
    scanf("%s",s);
    int i,a;
    a = strlen(s);
    for(i = 0 ; i < a ; i++)
    {
        s[i] = 'x';
    }
    printf("%s\n",s);
    return 0;
}

Measured memory_bytes: 1640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > piii;
#define pb push_back
#define NeedForSpeed ios_base::sync_with_stdio(0), cin.tie(0)
#define PI acos(-1)
#define all(c) c.begin(), c.end()
#define SET(x, y) memset((x), y, sizeof(x))
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const ll INF64 = 1e18;

template <typename T>
string to_string(const vector<T> &v) {
  string ret = "<";
  for (auto it : v)
    ret += to_string(it) + ", ";
  ret.pop_back(); ret.pop_back();
  ret += ">";
  return ret;
}

string to_string(const string &s) {
  return '"' + s + '"';
}

string to_string(bool b) {
  return b ? "true" : "false";
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

void debug_print() { cerr << endl; }

template <typename T, typename ...U>
void debug_print(T t, U... u) {
  cerr << " " << to_string(t);
  debug_print(u...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_print(__VA_ARGS__)
const int N = 1e5 + 5;

vector<ll> v;

int main() {
  ll n;
  cin >> n;
  v.resize(n);
  for (auto &it : v)
    cin >> it;
  ll ret = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int k = j + 1; k < n; k++) {
        if (v[i] + v[j] > v[k] && v[i] + v[k] > v[j] && v[j] + v[k] > v[i] && v[i] != v[j] && v[j] != v[k] && v[i] != v[k])
          ret++;
      }
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
	int n,t;	cin>>n>>t;
	vector<int> a(n);
	for(int i=0;i<n;i++)	cin>>a[i];
	int profit=0,sml=a[0],pattern=0;
	for(int i=1;i<n;i++){
		if(sml>a[i]){
			sml=a[i];
		}
		else if(a[i]-sml>profit){
			profit=a[i]-sml;
			pattern=1;
		}
		else if(a[i]-sml==profit){
			pattern++;
		}
	}
	cout<<pattern<<endl;
	return 0;
}


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

//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back


const int N = 2e5 + 51 + 51, MOD = 1e9 + 7, mod = 998244353, INF = 3e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

//gp_hash_table<int, int> table;

int a[N], dp[3000][3000];
bool ok[3000][3000];

signed main() {
    #ifdef Flash
     freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (n % 2 == 0) dp[i][i] = -a[i];
        else dp[i][i] = a[i];
    }
    for (int i = 1; i <= n; i++) {
        int len = n - i, kof = 1;
        if (len % 2 == 0) kof = -1;

        for (int j = 0; j < n; j++) {
            if (i + j >= n) break;
            if (kof == 1) dp[j][i + j] = max(dp[j + 1][i + j] + a[j], dp[j][i + j - 1] + a[i + j]);
            else dp[j][i + j] = min(dp[j + 1][i + j] - a[j], dp[j][i + j - 1] - a[i + j]);
        }
    }
    cout << dp[0][n - 1];
}


Measured memory_bytes: 71936
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

struct tri{
  ll f,s,t;
};

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;ll K;cin >> N >> K;
  if(2*K-1>N){
    cout << -1 << endl;
    return 0;
  }

  vector<PII> v(N);
  ll b;
  int index = 0;
  b = K+2*N-1-N/2;
  if(N%2==1 && K%2==1)--b;
  repp(x,K,K+N){
    if(x&1)continue;
    v[index].first = x+b;
    v[index].second = x;
    ++index;
    --b;
  }

  b = K+2*N-1;
  repp(x,K,K+N){
    if((x&1)==0)continue;
    v[index].first = x+b;
    v[index].second = x;
    ++index;
    --b;
  }

  //sort(all(v));
  ll c = K+2*N;
  queue<tri> que;
  rep(i,N){
    que.push({v[i].second,v[i].first-v[i].second,c});
    ++c;
  }
  while(!que.empty()){
    tri t = que.front();que.pop();
    printf("%d %d %d\n",t.f,t.s,t.t);
  }
  return 0;
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
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;}
// D[even or odd][max or 2nd max]
pair<int, int> D[2][2];
void Main(){
    int n = read();
    map<int, int> M[2];
    for (int i = 0; i < n; i++) M[i%2][read()]++;
    for (int i = 0; i < 2; i++){
        for (auto m:M[i]) {
            if (m.second > D[i][0].second) {
                D[i][1] = D[i][0];
                D[i][0] = m;
            }
            else if (m.second > D[i][1].second) {
                D[i][1] = m;
            }
        }
    }
    int ans;
    if (D[0][0].first != D[1][0].first) ans = n-D[0][0].second-D[1][0].second;
    else ans = n-max(D[0][0].second+D[1][1].second, D[1][0].second+D[0][1].second);
    printf("%d\n", ans);
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 4992
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>

using namespace std;


int main() {
  int a, b;
  scanf("%d %d", &a, &b);

  char bd[100][100];
  fill(&bd[0][0], &bd[50][0], '#');
  fill(&bd[50][0], &bd[100][0], '.');

  for(int i=0; i<a-1; ++i) {
    int y = i/50*2;
    int x = i%50*2;
    bd[y][x] = '.';
  }
  for(int i=0; i<b-1; ++i) {
    int y = i/50*2+51;
    int x = i%50*2;
    bd[y][x] = '#';
  }

  printf("100 100\n");
  for(auto&& r : bd) {
    for(auto&& c : r) {
      putc(c, stdout);
    }
    putc('\n', stdout);
  }
}


Measured memory_bytes: 128
#include <iostream>

int main(int argc, const char * argv[]) {
    std::string a;
    int n,s,w,e;
    n=s=w=e=0;
    std::cin>>a;
    for(int i=0;i<a.length();i++){
        if(a.at(i)=='N'){
            n++;
        }else if(a.at(i)=='S'){
            s++;
        }else if(a.at(i)=='W'){
            w++;
        }else if(a.at(i)=='E'){
            e++;
        }
    }
    if((n>0&&s>0) || (n==0&&s==0)){
        if((w>0&&e>0)||(w==0&&e==0)){
            std::cout<<"Yes"<<std::endl;
        }else std::cout<<"No"<<std::endl;
    }else std::cout<<"No"<<std::endl;
    return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n, m;cin >> n >> m;
    vector<LL> x(m);
    inc(i, 0, m) cin >> x[i];
    if(m == 1){
        cout << 0 << endl;
        return 0;
    }
    sort(x.begin(), x.end());
    vector<LL> d;
    inc(i, 1, m) d.pb(x[i]-x[i-1]);
    sort(d.begin(), d.end());
    reverse(d.begin(), d.end());
    if(n == 1){
        LL sum = 0;
        inc(i, 0, m-1){
            sum += d[i];
        }
        cout << sum << endl;
    }else{
        LL ans = 0;
        int nn = n-2;
        inc(i, 1, m-1){
            if(nn == 0){
                ans += d[i];
            }else{
                nn--;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) { return a/gcd(a,b)*b;}
// head
const int mxN = 1e5 + 1;
//dp[i]: 1:first win 0:second win
int n, k, a[mxN], dp[mxN];
int main() {
	ios::sync_with_stdio(0); 
	cin.tie(0); cout.tie(0);
	cin >> n >> k;
	rep(i, 0, n) cin >> a[i];
	sort(a, a+n);
	rep(i, 0, k + 1){
		if(i < a[0]){
			dp[i] = 0;
			continue;
		}
		rep(j, 0, n){
			if(i-a[j]<0) break;
			if(dp[i-a[j]] == 0){
				dp[i] = 1;
				break;
			}
		}
	}	
	if(dp[k]) cout << "First" << endl;
	else cout << "Second" << endl;
}




Measured memory_bytes: 640
#include<cstdio>
int cnt[100005];

int main(){
    int n;
    scanf("%d",&n);
    int upper = 100000;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        int u;
        scanf("%d",&u);
        if(u>upper) ans++;
        else cnt[u]++;
    }
    for(int i = 1; i <= upper; i++){
        if(cnt[i]!=i){
            if(cnt[i]<i) ans += cnt[i];
            else ans += (cnt[i]-i);
        }
    }
    printf("%d\n",ans);
    return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
    int N; cin >> N;
    cout << N / 3 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {return(b?gcd(b,a%b):a);}
ll lcm(ll a, ll b) {return(a/gcd(a,b)*b);}

int main() {
    int n, m; cin >> n >> m;
    string s, t; cin >> s >> t;
    ll g = lcm(n,m);
    ll h = lcm(g/n,g/m);
    bool ok = true;
    for (ll i = 0; i <= min((m-1)*(g/m),(n-1)*(g/n)); i += h) {
        if (s[i/(g/n)] != t[i/(g/m)]) ok = false;
    }
    if (ok) cout << g << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0;
            double sum=0;
            while ((line = br.readLine()) != null) {
            	n=Integer.parseInt(line);
            	sum=0;
            	double sum2=0;
            	double sum3=0;
            	String[] str1=br.readLine().split(" ");
            	String[] str2=br.readLine().split(" ");
            	double max=0;
            	for(int i=0;i<n;i++){
            		sum+=Math.abs(Integer.parseInt(str1[i])-Integer.parseInt(str2[i]));
            		sum2+=Math.pow(Integer.parseInt(str1[i])-Integer.parseInt(str2[i]), 2);
            		sum3+=Math.pow(Math.abs(Integer.parseInt(str1[i])-Integer.parseInt(str2[i])), 3);
            		if(max<Math.abs(Integer.parseInt(str1[i])-Integer.parseInt(str2[i]))){
            			max=Math.abs(Integer.parseInt(str1[i])-Integer.parseInt(str2[i]));
            		}
            	}
            	System.out.println(sum);
            	System.out.println(Math.sqrt(sum2));
            	System.out.println(Math.cbrt(sum3));
            	System.out.println(max);
            	break;
            }
        }
    }

}

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

int main(){
    vector<long long> polock;
    vector<long long> oddpolock;
    long long pol = 1;
    polock.push_back(1);
    oddpolock.push_back(1);
    
    for (int i=2; i<201; i++){
        pol += i;
        long long stack = polock.back() + pol;
        polock.push_back(stack);
        if (stack%2==1){
            oddpolock.push_back(stack);
        }
    }
    
    long long INF = pow(10,18);
    vector<long long> dp(pow(10,6), INF);
    vector<long long> dp2(pow(10,6), INF);
    dp[0] = 0;
    dp2[0] = 0;
    
    for (int i=1; i < pow(10,6); i++){
        for (int j = 0; j < polock.size(); j++){
            if (polock[j] > i) break;
            dp[i] = min(dp[i],dp[i-polock[j]] + 1);
        }
    }
    
    for (int i=1; i < pow(10,6); i++){
        for (int j = 0; j < oddpolock.size(); j++){
            if (oddpolock[j] > i) break;
            dp2[i] = min(dp2[i],dp2[i-oddpolock[j]] + 1);
        }
    }
    
    int n;
    cin >> n;
    while (n!=0){
        cout << dp[n] << ' ' << dp2[n] << endl;
        cin >> n;
    }
}


Measured memory_bytes: 18228
use std::io::BufRead;
fn main() {
    let stdin = std::io::stdin();
    let mut lines: Vec<Vec<i64>> = stdin
        .lock()
        .lines()
        .map(|l| {
            l.unwrap()
                .split_whitespace()
                .map(|w| w.parse().unwrap())
                .collect()
        })
        .collect();
    let (_n, k, mut al, mut fl) = (lines[0][0], lines[0][1], lines.remove(1), lines.remove(1));
    if al.iter().sum::<i64>() <= k {
        println!("0");
        return;
    } else {
        al.sort();
        al.reverse();
        fl.sort();
        let list: Vec<_> = al.iter().zip(fl.iter()).collect();
        let mut lp: i64 = 1;
        let mut rp: i64 = 1 << 60;
        let mut mp: i64;
        while rp - lp > 1 {
            mp = (lp + rp) / 2;
            let sum: i64 = list
                .iter()
                .filter(|x| (x.0 * x.1) > mp)
                .map(|x| x.0 - (mp / x.1))
                .sum();
            if sum <= k {
                rp = mp;
            } else {
                lp = mp;
            }
        }
        println!("{}", rp);
    }
}


Measured memory_bytes: 14536
/*
  AOJ 2273
  Title:Shiritori
  @kankichi573
*/
#include <stdio.h>
#include <string.h>

char memo[27];

main()
{
  int i,ret;
  char c0,c1,c2,str[3];

  memset(memo,0,26);
  c0='a';
  for(i=0;i<50;i++)
    {
      c1=i/26+'a';
      c2=i%26+'a';
      printf("?%c%c%ca\n",c0,c1,c2); fflush(stdout);
      scanf("%s", str);
      if(str[0]!='a' ||
	 (((str[1]=='\0') && (memo[0]))||
	  ((str[1] && memo[str[1]-'a'+1]))))
	{
	  printf("!OUT\n");
	  break;
	}
      if(str[1]=='\0')
	memo[0]=1;
      else
	memo[str[1]-'a'+1]=1;
	  
      if(str[1])
	c0=str[1];
      else
	c0=str[0];
    }
  return(0);
}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef pair<int, int>P;
typedef long long ll;

int cnt[26];
int main() {
	int n, k; scanf("%d%d", &n, &k);
	rep(i, n) {
		string p; cin >> p;
		cnt[(int)p[0] - 'A']++;
	}
	for (int i = 0;; i++) {
		sort(cnt, cnt + 26, greater<>());
		if (!cnt[k - 1]) {//k確保できない
			printf("%d\n", i);
			break;
		}
		rep(j, k) {
			cnt[j]--;
		}
	}
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		Scanner in= new Scanner(System.in);
		PrintWriter out= new PrintWriter(System.out);
		int n= in.nextInt();
		long res=0;
		for (int i = 0; i < n; i++) {
			int l= in.nextInt();
			int r= in.nextInt();
			res+= r-l+1;
		}
		System.out.println(res);
		
		
		
	}
	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer("");
		}

		public String next() throws IOException {
			if (!st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
				return next();
			}
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
		public double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 25004
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  ll N,K;
  cin>>N>>K;
  VI A(N),F(N);
  rep(i,N) cin>>A[i];
  rep(i,N) cin>>F[i];
  sort(all(A));
  sort(all(F));
  ll ok=1ll<<60,ng=-1;
  while(abs(ok-ng)>1){
    ll mid=(ok+ng)/2;
    vector<ll> B(N);
    rep(i,N) B[i]=mid/F[i];
    sort(all(B));
    ll X=1,sum=0;
    rep(i,N){
      if(A[i]>B[i]) sum+=(A[i]-B[i]);
    }
    if(sum>K) X=0;
    if(X){
      ok=mid;
    }else{
      ng=mid;
    }
  }
  cout<<ok<<endl;
}



Measured memory_bytes: 3428
#include<iostream>

using namespace std;

int main(void){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int ans = 0;
    if(C <= A && D <= A) ans = 0;
    else if(C <= A && D >= A && D <= B) ans = D-A;
    else if(C >= A && D <= B) ans = D-C;
    else if(C >= A && C <= B && D >= B) ans = B-C;
    else if(C >= B && D >= B) ans = 0;
    else ans = B-A;

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

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if (500*i + 100*j + 50*k) == X:
                count += 1

print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main() {
  	double A, B, H, M;
    cin >> A >> B >> H >> M;
  
    printf("%0.10f",sqrt(A*A + B*B - 2*A*B*cos(2*M_PI*((1.0/60 - 1.0/720)*(H*60 + M)))));

    return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back



int main(){
    int n;
    cin >> n;
    int x;
    vector<int> s;
    for(int i=0;i<n;i++){
        cin >> x;
        s.pb(x);
    }
    ll min;

    int y=s[0];

    for(int i=1;i<n;i++){
        if(s[i]>y){
            y=s[i];
        }
    }

    for(int i=1;i<=y;i++){
        ll a=0;
        for(int j=0;j<n;j++){
            a+=(s[j]-i)*(s[j]-i);
        }
        if(i==1){
            min=a;
        }
        if(min>a){
            min=a;
        }
    }

    cout << min << endl;
    
    return 0;
}

Measured memory_bytes: 256