akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;



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

	sort(a.begin(), a.end());
	cout << a.back() - a[0] << endl;
}

Measured memory_bytes: 3576
from numba import njit
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

@njit
def main(N):
    ans = 0

    for n in range(1,N+1):
        ans += (N // n) * n * (1 + (N // n)) // 2

    print(ans)


if __name__ == "__main__":
    N = int(readline())
    main(N)


Measured memory_bytes: 109172
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

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

    ll n;
    cin >> n;
    vector<ll> a(n), b(n), a_cnt(n + 1), b_cnt(n + 1);
    REP(i, 0, n)
    {
        cin >> a[i];
        a_cnt[a[i]]++;
    }
    REP(i, 0, n)
    {
        cin >> b[i];
        b_cnt[b[i]]++;
    }

    vector<int> idx(n + 1);
    iota(idx.begin(), idx.end(), 0);
    sort(idx.begin(), idx.end(), [&](int i, int j) { return a_cnt[i] > a_cnt[j]; });

    deque<pair<int, int>> dq;
    REP(i, 0, n + 1)
    {
        if (b_cnt[idx[i]] > 0)
            dq.emplace_back(idx[i], b_cnt[idx[i]]);
    }

    map<int, vector<int>> mp;
    REP(i, 0, n + 1)
    {
        if (a_cnt[idx[i]] == 0)
            break;
        int x = idx[i];
        if (!dq.empty() && dq.front().first == x)
        {
            dq.push_back(dq.front());
            dq.pop_front();
        }
        REP(_, 0, a_cnt[x])
        {
            if (dq.front().first == x)
            {
                cout << "No" << endl;
                return 0;
            }
            mp[x].emplace_back(dq.front().first);
            dq.front().second--;
            if (dq.front().second == 0)
                dq.pop_front();
        }
    }

    cout << "Yes\n";
    REP(i, 0, n)
    {
        cout << mp[a[i]].back() << " ";
        mp[a[i]].pop_back();
    }
    cout << endl;
}

Measured memory_bytes: 32164
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top, S[1000];


void push(int x){
    
    S[++top] = x;
    
}


int pop(){
    
    top--;
    return S[top+1];
}


int main()
{
    int a,b;
    top = 0;
    char s[100];
    
    while (scanf("%s", s) != EOF){
        
        if(s[0] == '+'){
            
            a = pop();
            b = pop();
            push(a+b);
            
        }else if (s[0]== '-'){
            
            b = pop();
            a = pop();
            push(a-b);
            
        }else if( s[0] == '*'){
            
            a = pop();
            b = pop();
            push(a*b);
            
        }else{
            
            push(atoi(s));
            
        }
        
    }
    
    printf("%d\n",pop());
    
    return 0;
}


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

using namespace std;

#define f0r(a, b) for (long long a = 0; a < b; a++)
#define f1r(a, b, c) for (long long a = b; a < c; a++)
#define f0rd(a, b) for (long long a = b; a >= 0; a--)
#define f1rd(a, b, c) for (long long a = b; a >= c; a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define f first
#define s second

#define ao(a, n) {for (int ele = 0; ele < n; ele++) { if (ele) cout << " "; cout << a[ele]; } cout << endl;}

typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

const ll inf = 1e12;
const ll mod = 1e9 + 7;


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

  int a, b;
  cin >> a >> b;

  if (b < a)
    swap(a, b);

  if (a == 1 && b == 2)
    cout << "3\n";
  else if (a == 2 && b == 3)
    cout << "1\n";
  else if (a == 1 && b == 3)
    cout << "2\n";

}

Measured memory_bytes: 3656
#include <stdio.h>
#define N 100000

int BS(int n,int *s,int key){
  int m;
  int l=0,r;
  r=n;
  while(r>l+1){
    m=(l+r)/2;
    if(s[m]>key)r=m;
    else l=m;
  }
  return s[l]==key;
}


int main(){
  int c=0,n,i;
  int s[N];
  int q,t;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&t);
    c+=BS(n,s,t);
  }
  printf("%d\n",c);
  return 0;
  
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 string S;
  cin>>S;
  ll ans=1000;
  for(ll i=0;i<S.size()-2;i++) {
  ll b=abs(('7'-S[i])*100+('5'-S[i+1])*10+'3'-S[i+2]);
    ans=min(ans,b);
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 3580
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int h = scanner.nextInt();
        final int w = scanner.nextInt();
        final int n = scanner.nextInt();

        System.out.println((n + Math.max(h, w) - 1) / Math.max(h, w));
    }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
 
#define mod 1000000007
typedef long long int LL;
const int MAX = 105;
const int INF = 1e9;


int main() {
	int n;
	string x;
	cin >> n >> x;
	for (int i = 0; i < x.length(); i++) {
		int cur = (int)(x[i] - 'A');
		cur = (cur + n) % 26;
		x[i] = (char)('A' + cur);
	}
	cout << x << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n, flag = 0, cnt = 0;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++) cin >> a[i];
  while(1){
    for(int i = 0; i < n; i++){
      if(a[i] % 2 != 0){
        flag = 1;
        break;
      }
      a[i] /= 2;
      cnt++;
    }
    if(flag == 1) break;
  }
  cout << cnt / n << endl;
  return 0;
}

Measured memory_bytes: 256
s = input()
t = input()
ls = len(s)
s += s[0:len(t)]
f = 0
i = 0
while i < ls:
    if t == s[i:i+len(t)]:
        f = 1
        break
    i += 1
if f == 0:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 5560
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    if((a == b && a != c) ||
       (a == c && a != b) ||
       (b == c && b != a)){
     	 System.out.println("Yes");
    }
    else
    {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

class union_find {
private:
    vector<ll> par;
    vector<ll> ran;
    vector<ll> m_size;
public:
    union_find(ll n);
    ll find(ll x);
    void unite(ll x, ll y);
    bool same(ll x, ll y);
    ll size(ll x);
};

union_find::union_find(ll n){
    par.resize(n);
    ran.resize(n, 0);
    m_size.resize(n, 1);
    REP(i,n) par[i] = i;
};

ll union_find::find(ll x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
};

void union_find::unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    ll t = size(x)+size(y);
    m_size[x] = m_size[y] = t;
    if (ran[x] < ran[y]) {
        par[x] = y;
        //size[y] += size[x];
    } else {
        par[y] = x;
        //ize[x] += size[y];
        if (ran[x]==ran[y]) ran[x]++;
    }
};

ll union_find::size(ll x) {
    if (par[x] == x) return m_size[x];
    return size(par[x] = find(par[x]));
}

bool union_find::same(ll x, ll y) {
    return (find(x) == find(y));
};

int main(int argc, char const *argv[]) {
    int n,m;
    cin >> n >> m;
    vector<vector<int>> l(n);
    union_find uf(222222);

    REP(i,n) {
        int k;
        cin >> k;
        REP(j,k) {
            int x;
            cin >> x;
            x += 100000;
            uf.unite(i,x);
        }
    }

    int root = uf.find(0);
    bool ok = true;
    for (int i = 1; i < n; ++i) {
        if (uf.find(i) != root) ok = false;
    }

    if (ok) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

class dice {
    public:
        int top, front, right, left, back, bottom;
        dice(int a, int b, int c, int d, int e, int f) {
            top = a; front = b;
            right = c; left = d;
            back = e; bottom = f;
        }
        int tp() {
            return top;
        }
        void E() {
            int tmp = top;
            top = left;
            left = bottom;
            bottom = right;
            right = tmp;
        }
        void N() {
            int tmp = top;
            top = front;
            front = bottom;
            bottom = back;
            back = tmp;
        }
        void R() {
            int tmp = front;
            front = left;
            left = back;
            back = right;
            right = tmp;
        }
};

bool cp(dice d1, dice d2) {
    string s = "NNNNRNNNNRNNNNRNNNNRENNNNRNNNNRNNNNRNNNNRENNNNRNNNNRNNNNRNNNNRENNNNRNNNNRNNNNRNNNNRE";
    for (int i = 0; i < s.size(); i++) {
        if (d1.top == d2.top && d1.front == d2.front && d1.right == d2.right && d1.left == d2.left && d1.back == d2.back && d1.bottom == d2.bottom)
            return true;
        switch (s[i]) {
            case 'E': d2.E(); 
            case 'N': d2.N();
            case 'R': d2.R();
        }
    }
    return false;
}

int main() {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    dice d1(a, b, c, d, e, f);
    cin >> a >> b >> c >> d >> e >> f;
    dice d2(a, b, c, d, e, f);
    if (cp(d1, d2))
        cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 3204
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[][] c = new int[10][10];
		int[][] A = new int[h][w];
		for(int i = 0 ; i < 10 ; i++) {
			for(int j = 0 ; j < 10 ; j++) {
				c[i][j] = sc.nextInt();
			}
		}
		for(int i = 0 ; i < h ; i++) {
			for(int j = 0 ; j < w ; j++) {
				A[i][j] = sc.nextInt();
			}
		}
		for(int k = 0 ; k < 10 ; k++) {
			for(int i = 0 ; i < 10 ; i++) {
				for(int j = 0 ; j < 10 ; j++) {
					c[i][j] = Math.min(c[i][j], c[i][k] + c[k][j]);
				}
			}
		}
		int ans = 0;
		for(int i = 0 ; i < h ; i++) {
			for(int j = 0 ; j < w ; j++) {
				if(A[i][j] >= 0) {
					ans += c[A[i][j]][1];
				}
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 47160
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

ll N;

int main() {
    cin >> N;

    ll ans = N - 1;

    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ans = min(ans, i - 1 + (N / i) - 1);
        }
    }

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


Measured memory_bytes: 256
n = int(input())
lst = [int(i) for i in input().split()]
c=lst[0]
for i in range(1,n):
#     考え方は前の番号より高さが高いとその分余分に水やる操作をやる感じ
    if lst[i]>lst[i-1]:
        c+=lst[i]-lst[i-1]
print(c)



Measured memory_bytes: 2940
#include<stdio.h>
main(){
long long n,i,j,k,l,x,y,z;
scanf("%lld",&n);
long long a[n+2];
for(i=1;i<=n;i++){scanf("%lld",&a[i]);}
x=0;
a[0]=0;a[n+1]=0;
for(i=1;i<n+2;i++){
if(a[i]<a[i-1]){x+=a[i-1]-a[i];}else{x+=a[i]-a[i-1];}
}
for(i=1;i<=n;i++){
if(a[i+1]<a[i-1]){y=a[i-1]-a[i+1];}else{y=a[i+1]-a[i-1];}
if(a[i]<a[i-1]){y-=a[i-1]-a[i];}else{y-=a[i]-a[i-1];}
if(a[i+1]<a[i]){y-=a[i]-a[i+1];}else{y-=a[i+1]-a[i];}
printf("%d\n",x+y);}
return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)
//std::sort(v.begin(), v.end(), std::greater<Type>());

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

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  int a;
  cin >> a;
  int l=a/100;
  int r=a%100;
  if(1<=l && l<=12){
    if(1<=r && r<=12) cout<<"AMBIGUOUS" <<endl;
    else cout<< "MMYY" <<endl;
  }
  else{
    if(1<=r && r<=12) cout<<"YYMM" <<endl;
    else cout<< "NA" <<endl;
  }
}


Measured memory_bytes: 256
enemmyCountN,killerTimeK = map(int,input().split())
enemyHp = input().split()

intEnemyHp = [int(i) for i in enemyHp]
intEnemyHp.sort()

resultEnemyCount = enemmyCountN - killerTimeK
countNormal = 0

if killerTimeK >= enemmyCountN:
    print(0)

else:
    for i in range(resultEnemyCount):
        countNormal += intEnemyHp[i]
    print(countNormal)

Measured memory_bytes: 26180
#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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 1000000009
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main(){
  ll N;
  ll K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, N){
    cin >> A.at(i);
  }
  A.push_back(-2000000000000000009);
  A.push_back(2000000000000000009);
  sort(all(A));
  ll l = -1000000000000000009;
  ll r = 1000000000000000009;
  while(r-l > 1){
    ll c = (l+r)/2;
    ll cnt = 0;
    rep2(i, 1, N+1){
      if(A.at(i) < 0){
        ll l2 = 0;
        ll r2 = N+1;
        while(r2-l2 > 1){
          if(A.at(i) * A.at((l2+r2)/2) > c){
            l2 = (l2+r2)/2;
          }
          else{
            r2 = (l2+r2)/2;
          }
        }
        if(i >= r2){
          cnt += N - r2 + 1;
          cnt -= i - r2 + 1;
        }
        else{
          cnt += N - r2 + 1;
        }
      }
      if(A.at(i) == 0){
        if(c >= 0){
          cnt += N-i;
        }
      }
      if(A.at(i) > 0){
        ll l2 = 0;
        ll r2 = N+1;
        while(r2-l2 > 1){
          if(A.at(i) * A.at((l2+r2)/2) <= c){
            l2 = (l2+r2)/2;
          }
          else{
            r2 = (l2+r2)/2;
          }
        }
        if(i <= l2){
          cnt += l2;
          cnt -= i;
        }
      }
    }
    if(cnt >= K){
      r = c;
    }
    else{
      l = c;
    }
  }
  cout << r << endl;
}

Measured memory_bytes: 4480
#include<iostream>
using namespace std;
int main(){
    int b,f,r,v,n,i,k,l,m,max[5][4][11]{0};
    cin>>n;
    for(i=0;i<n;i++){
        cin>>b>>f>>r>>v;
        if(r>0){
            max[b][f][r]=max[b][f][r]+v;
        }
    }
    for(k=1;k<=4;k++){
        if(k!=1){
        cout<<"####################"<<endl;
        }
        for(l=1;l<=3;l++){
            for(m=1;m<=10;m++){
                cout<<" "<<max[k][l][m];
            }
            cout<<endl;
        }
    }
    
    return 0;
}

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

typedef long long ll;
// const int INF = 1e8;
const ll INF = 1LL << 60;
typedef pair<int, int> P;

ll N, X, Y;
struct edge { ll to, cost; };
vector<edge> G[(int)1e5 + 10]; 
ll ddd[(int)1e5 + 10];
 
void dijkstra(ll s) {
    priority_queue<P, vector<P>, greater<P>> que;
    fill(ddd, ddd + N, INF);
    ddd[s] = 0;
    que.push(P(0, s));
 
    while (!que.empty()) {
        P p = que.top(); que.pop();
        ll v = p.second;
        if (ddd[v] < p.first) continue;
        for (int i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (ddd[e.to] > ddd[v] + e.cost) {
                ddd[e.to] = ddd[v] + e.cost;
                que.push(P(ddd[e.to], e.to));
            }
        }
    }
}

int main() {
    cin >> N >> X >> Y;
    rep(i, N - 1) {
        // cout << "i " << i << " j " << i + 1 << endl;
        edge e = {i + 1, 1};
        G[i].push_back(e);

        edge e_t = {i, 1};
        G[i + 1].push_back(e_t);
    }

    X--; Y--;
    edge e2 = {Y, 1};
    G[X].push_back(e2);

    edge e3 = {X, 1};
    G[Y].push_back(e3);
    
    // dijkstra(0);
    // cout << ddd[5] << endl;
    // return 0;

    // 距離の数
    map<ll, ll> mp;
    rep(i, N - 1) {
        dijkstra(i);

        // cout << "i" << " " << i << endl;
        for (int j = i + 1; j < N; j++) {
            // cout << "j: " << j << " dist: " << ddd[j] << " ";
            mp[ddd[j]]++;
        }
        // cout << endl;
    }


    // for (auto iter = mp.begin(); iter != mp.end(); iter++) {
    //     cout << iter->first << " " << iter->second << endl;
    // }
    for (ll i = 1; i <= N - 1; i++) {
        cout << mp[i] << endl;
    }
}

Measured memory_bytes: 2816
#include<cstdio>

using namespace std;

int main(){
    int a,b,c;
    scanf("%d %d %d", &a, &b, &c);
    if (a == b) printf("%d\n", c);
    else if (b == c) printf("%d\n", a);
    else if (c == a) printf("%d\n", b);
}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int solve() {
    int n, k;
    int x[110000];
    cin >> n >> k;
    rep(i, n) { cin >> x[i]; }
    if (n <= k) { return 0; }
    int ret = x[n - 1] - x[0];
    int diff[110000];
    rep(i, n - 1) { diff[i] = x[i + 1] - x[i]; }
    sort(diff, diff + n - 1);
    for (int i = n - k; i < n - 1; i++) { ret -= diff[i]; }
    return ret;
}

signed main() {
    int k;
    cin >> k;
    rep(i, k) { cout << solve() << endl; }
}



Measured memory_bytes: 4620
N, K = [int(_) for _ in input().split()]
xy = [tuple(int(_) for _ in input().split()) for _ in range(N)]

xy.sort()

result = (10**11)**2

for i in range(N):
    xl, _ = xy[i]
    for j in range(i + 1, N):
        xh, _ = xy[j]
        ys = sorted(y for x, y in xy if xl <= x <= xh)
        if len(ys) >= K:
            d = min(ys[i + K - 1] - ys[i] for i in range(len(ys) - K + 1))
            r = d * (xh - xl)
            result = min(result, r)
print(result)


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

const int MOD = 1e9 + 7;
ll dp[10005][2][100];

int main(){

	int n;
	cin >> n;
	string s;
	cin >> s;
	
	vector<vector<ll>> dp(n+1, vector<ll>(n));
	rep(j,n) dp[1][j] = 1;
	
	for(int i = 2; i <= n; i++){
		vector<ll> cumsum(n);
		cumsum[0] = dp[i-1][0];
		rep(j,n-1) cumsum[j+1] = ( cumsum[j] + dp[i-1][j+1] ) % MOD;
		
		for(int j = 0; j <= n-i; j++){
			if(s[i-2] == '>'){
				dp[i][j] = cumsum[ max(0,j) ];
			}
			else{
				dp[i][j] = ( cumsum[ max(j+1,n-i+1) ] - cumsum[j] + MOD ) % MOD;
			}
		}
	}
	
	cout << dp[n][0] << endl;
	
	return 0;
}

Measured memory_bytes: 70784
#include<stdio.h>
int main(void){
	int h,w,i,j;
	
	while(1){
		scanf("%d %d",&h,&w);
		if(h==0&&w==0){
			break;
		}
		for(i=1;i<=h;i++){
			for(j=1;j<=w;j++){
				if((i%2==1)&&(j%2==1)){
					printf("#");
				}
				else if((i%2==0)&&(j%2==1)){
					printf(".");
				}
				else if((i%2==1)&&(j%2==0)){
					printf(".");
				}
				else if((i%2==0)&&(j%2==0)){
					printf("#");
				}
			}
			printf("\n");
		}	
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 1812
import Data.List

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- fmap (map read . words) getLine :: IO [Int]
  print $ solve as

solve as = maximum $ zipWith gcd ls rs
  where
    ls = init $ scanl' gcd 0 as
    rs = tail $ scanr gcd 0 as


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

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

#define INF  (int)1e9
#define LINF (long long)1e18

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

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

    ll X, Y;
    std::cin >> X >> Y;

    int ans = 1;
    while(true) {
        if(X * 2 <= Y) {
            X *= 2;
            ans++;
        }
        else {
            break;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int[] prices = { 0, 6000, 4000, 3000, 2000 };
			StringTokenizer st = new StringTokenizer(line);
			int t = Integer.parseInt(st.nextToken());
			int n = Integer.parseInt(st.nextToken());
			System.out.println(prices[t] * n);
		}
	}
}

Measured memory_bytes: 16992
#include <ctype.h>
#include <stdio.h>

int stack[100];
int top;

void push(int a) {
  top++;
  stack[top] = a;
}

int pop() {
  top--;
  return stack[top + 1];
}

int main() {
  char s[100];
  int a;
  int b;

  while (scanf("%s", s) != EOF) {
    if (isdigit(s[0])) {
      push(atoi(s));
    } else {
      b = pop();
      a = pop();
      if (s[0] == '+') {
        push(a + b);
      } else if (s[0] == '-') {
        push(a - b);
      } else if (s[0] == '*') {
        push(a * b);
      }
    }
  }

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

  return 0;
}



Measured memory_bytes: 2144
N, M = map(int, input().split())
edge = dict()

for i in range(M):
    a, b = map(int, input().split())
    if a in edge:
        edge[a].append(b)
    else:
        edge[a] = [b]
    if b in edge:
        edge[b].append(a)
    else:
        edge[b] = [a]

def search(now, gone):
    if len(gone) == N - 1:
        return 1

    s = 0
    for i in edge[now]:
        if i not in gone:
            hoge = gone.copy()
            hoge.add(now)
            s += search(i, hoge)
    return s

print(search(1, set()))

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

int dig(int n){
    int sum2 =0;
    while(n>0){
        sum2 += n%10;
        n /=10;
    }
    return sum2;
}


int main(void){
    int n,a,b,sum=0;
    cin >> n >> a >>b;
    for(int i=0;i<=n;i++){
        int sum2 = dig(i);
        if(a <= sum2 && sum2 <=b ){
            sum +=i;
        }
    }
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

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

int H, W;
int c[1005][1005];
int cnt[1005][1005];

bool inside(int y, int x)
{
    return (0 <= y && y < H && 0 <= x && x < W);
}

int main()
{
    cin >> H >> W;

    rep(i, H) {
        rep(j, W) {
            char tmp; cin >> tmp;

            if (tmp == '.') {
                c[i][j] = 0;
            } else {
                c[i][j] = tmp - '0';
            }
        }
    }

    queue<pii> q;

    rep(i, H) {
        rep(j, W) {
            if (c[i][j] == 0) continue;

            rep(k, 8) {
                int ny = i + dy[k], nx = j + dx[k];
                if (!inside(ny, nx)) continue;

                if (c[ny][nx] == 0) {
                    cnt[i][j]++;
                }
            }

            if (cnt[i][j] >= c[i][j]) {
                q.push(pii(i, j));
            }
        }
    }

    if (q.empty()) {
        cout << 0 << endl;
        return 0;
    }

    int ans = 1;

    while (q.size()) {
        queue<pii> qq;
        while (q.size()) {
            pii p = q.front(); q.pop();

            rep(i, 8) {
                int ny = p.fst + dy[i], nx = p.scd + dx[i];

                if (!inside(ny, nx)) continue;

                if (cnt[ny][nx] >= c[ny][nx]) continue;

                cnt[ny][nx]++;

                if (cnt[ny][nx] >= c[ny][nx]) {
                    qq.push(pii(ny, nx));
                }
            }
        }

        if (qq.size()) {
            while (qq.size()) {
                q.push(qq.front());
                qq.pop();
            }

            ans++;
        } else {
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 10984
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ii pair<int, int>
#define iill pair <ii, ll>
#define ill pair<int, ll>
#define MAXN 100010
#define EPS 1e-9
#define MAXLOG 
#define MOD 
#define prt(a) printf("%d\n", a)
#define prt2(a, b) printf("%d %d\n", a, b)
#define prt3(a, b, c) printf("%d %d %d\n", a, b, c)
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d %d", &a, &b)
#define sc3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define readArr(arr, n) for (int i=0; i<n; i++) scanf("%d", &arr[i]);
#define EPS 1e-9
#define ll long long
using namespace std;

vector <int> pares[MAXN];

int main() {
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

	int n, m;
	scanf("%d %d", &n, &m);
	int res = 0;
	int temp, custo;
	for (int i=0; i<n; i++) {
		scanf("%d %d", &temp, &custo);
		pares[temp].emplace_back(custo);				
	}

	priority_queue < int, vector<int> > pq;
	for (int i=1; i<=m; i++) {
		for (int num : pares[i]) {
			pq.push(num);
		}

		if (!pq.empty()) {
			res += pq.top();
			pq.pop();
		}
	}

	printf("%d\n", res);
	return 0;
}





Measured memory_bytes: 5632
#include<iostream>
#include<ctype.h>
using namespace std;
int main(void){
  char a[11],b[11],c[11];
  cin>>a>>b>>c;
  cout<<(char)toupper(a[0])<<(char)toupper(b[0])<<(char)toupper(c[0])<<endl;
  return 0;
}


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

using namespace std;

#define ll long long




void solve() {

	int n, a, b;
	cin >> n >> a >> b;
	cout << min(n * a, b);

	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	solve();

	return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<map>
#include <cstdio>

#include <algorithm>
#define ll long long
#define mx 9*1000000000LL*1000000000

using namespace std;
    int n,m;
int main(){
    cin>>n>>m;
    vector<vector<pair<int, int> > > ed(n+1, vector<pair<int, int> >(0));
    map<pair<int, int>, int > pairs, pairs2;
    vector<ll> c(n+1, 0);
    for(int i=0; i<m; i++){
	int  l, r, d;
	cin>>l>>r>>d;
	ed[l].push_back({r,d});
	ed[r].push_back({l,-d});
	pairs[{l, r}] = d;
	pairs[{r, l}] = -d;
    }
    pairs2=pairs;
    bool yes = true;
    while(pairs.begin()!=pairs.end() && yes){
	int l,r;
	l = pairs.begin()->first.first;
	c[l]=1;
	queue<pair<int, int> > edgs;
	for(int i=0; i<ed[l].size(); i++){
	    if(pairs.count({l, ed[l][i].first})){
		edgs.push({l, ed[l][i].first});
		pairs.erase({l, ed[l][i].first});
		pairs.erase({ ed[l][i].first,l});
	    }
	}
	while(edgs.size()){
	    pair<int, int> p = edgs.front();
	    edgs.pop();
	    int d = pairs2[{p.first, p.second}];
	    if(c[p.first]){
		if(c[p.second]){
		    if(c[p.second]-c[p.first]!=d){yes=false;break;}
		}else{
		    c[p.second] = c[p.first]+d;
		}
	    }else{
		if(c[p.second]){
		    c[p.first] = c[p.second]-d;
		}else{
		}
	    }
	    if(!yes) break;
	    int l = p.second;
		for(int i=0; i<ed[l].size(); i++){
		    if(pairs.count({l, ed[l][i].first})){
			edgs.push({l, ed[l][i].first});
			pairs.erase({l, ed[l][i].first});
		pairs.erase({ ed[l][i].first,l});
		    }
		}
	    
	}
	
    }
    if(yes)cout<<"Yes\n"; else cout<<"No\n";
}

Measured memory_bytes: 60032
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n, l; scanf("%d%d", &n, &l); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);

	int p = -1;
	for(int i = 0; i < n - 1; i++) if(a[i] + a[i + 1] >= l) p = i;
	if(p == -1) {
		printf("Impossible\n");
		return 0;
	}

	printf("Possible\n");
	for(int i = 1; i <= p; i++) printf("%d\n", i);
	for(int i = n - 1; i >= p + 2; i--) printf("%d\n", i);
	printf("%d\n", p + 1);
	return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<stack>
#include<utility>
#include<algorithm>
 
using namespace std;

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

typedef vector<string> vs;
typedef vector<int> vi;

int solve(vs G){
    int w = G[0].size(), h = G.size();
    int res = 0;
    vi dp(w+1);
    rep(y,h){
        stack<pair<int,int> > s;
        rep(x,w+1){
            dp[x]= (G[y][x] == '.' /* free? */) ? dp[x] + 1 : 0;
            int l=x;
            while(!s.empty() && dp[x] < s.top().first){
                res = max(res,s.top().first*(x-s.top().second));
                l = s.top().second;
                s.pop();
            }
            s.push(make_pair(dp[x],l));
        }
    }
    return res;
}

int main(){
    for(int h,w;cin>>h>>w,h|w;){
        vs G(h);
        for(int y=0;y<h;y++) cin >> G[y];
        cout << solve(G) << endl;
    }
    return 0;
}

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

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define FI first
#define SE second
#define MP make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;
typedef pair < ll , ll > pll;

const double PI = acos(-1);
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;
const int INF = 1e9;
	

ll addMod(ll a, ll b){
	if(a + b >= MOD) return a + b - MOD;
	return a + b;
}

ll mulMod(ll a, ll b){
	return (a*b)%MOD;
}

ll fast(ll a, ll b){
	if(b == 0) return 1;
	ll tmp = fast(a,b/2);
	tmp = mulMod(tmp,tmp);
	if(b%2 == 1) tmp = mulMod(tmp,a);
	return tmp;
}

ll GCD(ll a, ll b){
	if(a > b) return GCD(b,a);
	if(a == 0) return b;
	return GCD(b%a,a);
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

//////////////////////////////////////////////

const int N = 1e5;

int n,m,q;
int cnt[N + 5];

void solve(){
	REP(i,1,n){
		if(cnt[i] + m - q > 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m >> q;
	int x;
	FOR(i,q){
		cin >> x;
		cnt[x]++;
	}
	solve();
	return 0;
}

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


int main() {
int h1,m1,h2,m2,K;
cin >> h1 >> m1 >> h2 >> m2 >> K;
int ans;
ans = (m2-m1) + (h2-h1) * 60;
ans -=K;
cout << ans << endl;


return 0;

}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX_V = 100;
const ll inf = 100100100100100100;
ll V,D[MAX_V][MAX_V];
bool WarshallFloyd(){//負の閉路があればtrue
  ll i,j,k;
  for(i=0;i<V;i++) D[i][i] = 0;
  for(k=0;k<V;k++){
    for(i=0;i<V;i++){
      for(j=0;j<V;j++){
        if(D[i][k] != inf && D[k][j] != inf){
          D[i][j] = min(D[i][j],D[i][k]+D[k][j]);
        }
      }
    }
  }
  for(i=0;i<V;i++){
    if(D[i][i]<0) return true;
  }
  return false;
}
int main(){
  ll E,i,j,s,t,d;scanf("%lld%lld",&V,&E);
  for(i=0;i<V;i++) fill(D[i],D[i]+V,inf);
  for(i=0;i<E;i++){
    scanf("%lld%lld%lld",&s,&t,&d);
    D[s][t] = d;
  }
  if(WarshallFloyd()) printf("NEGATIVE CYCLE\n");
  else{
    for(i=0;i<V;i++){
      for(j=0;j<V;j++){
        if(D[i][j]==inf) printf("INF");
        else printf("%lld",D[i][j]);
        if(j+1!=V) printf(" ");
      }
      printf("\n");
    }
  }
  return 0;
}


Measured memory_bytes: 3280
use std::cmp::{max, min};
use std::io::prelude::*;

fn gcd(x: u64, y: u64) -> u64 {
    if x == 0 || y == 0 {
        x + y
    } else {
        gcd(y, x % y)
    }
}

fn main() {
    let mut input_str = String::new();
    std::io::stdin().read_to_string(&mut input_str).unwrap();

    let input_parts = input_str.split_whitespace().collect::<Vec<_>>();
    let mut input_parts_it = input_parts.iter().cloned();

    let a: u64 = input_parts_it.next().unwrap().parse().unwrap();
    let b: u64 = input_parts_it.next().unwrap().parse().unwrap();
    let c: u64 = input_parts_it.next().unwrap().parse().unwrap();
    let d: u64 = input_parts_it.next().unwrap().parse().unwrap();

    let lcm = c * d / gcd(c, d);

    let count = b - a + 1 + ((b / lcm) - ((a + lcm - 1) / lcm) + 1)
        - ((b / c) - ((a + c - 1) / c) + 1)
        - ((b / d) - ((a + d - 1) / d) + 1);

    println!("{}", count);
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    ll a;
    cin >> a;
    cout << a + a*a + a* a *a << endl;
   return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
using namespace std;
string str;
int main(){
	cin>>str;
	for (int i=0;i<=str.length()-2;i++){
		if (str[i]=='A' && str[i+1]=='C'){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
import sys

# 関数 solve は，もちろん，問題に応じて書き換える
def solve(a,b,c):
    if len(c) == a+b+1:
        if  c.count("-")!=1:
            return "No"
        elif c[a]==("-"):
            return "Yes"
        else:
            return "No"
    else:
        return "No"
# ここから下は，入力・出力形式が同じであれば，変えなくて良い．
def readQuestion():
    line1 = sys.stdin.readline().rstrip()
    [str_n, str_i] = line1.split(' ')
    line2 = sys.stdin.readline().rstrip()
    return (int(str_n), int(str_i), line2)

def main():
    n, i, s = readQuestion()
    answer = solve(n, i, s)
    print(answer)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath> 
using namespace std;

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

    if(D==0){
        if(N == 100)
            cout << 101 << endl;
        else
            cout << N << endl;
    }else if(D==1){
        if(N == 100)
            cout << 10100 << endl;
        else
            cout << N*100 << endl;      
    }else{
        if(N == 100)
            cout << 1010000 << endl;
        else
            cout << N*10000 << endl;   
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define printV(v) for(int i=0;i<v.size();i++){cout << v[i]<< " ";} cout << endl
#define printRev(v) for(int i=v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
#define sortV(v) sort(v.begin(),v.end())
#define revV(v) reverse(v.begin(),v.end())
#define FOR(i,from,n) for(int i=from;i<n;i++)
#define FOL(i,from,n) for(int i=from;i >= n;i--)
    
    ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,q;
    ll mod = 1000000007;
    
    void solve(){
        int k;
        cin >> k;
        ll sum = 0;
        for(int i=1;i<=k;i++){
            if(i%3 && i%5) sum += i;
        }
        cout<<sum;
    }
        

  
   
    int main(){
    ios_base::sync_with_stdio(false);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int cases = 1;
    //cin >> cases;
  
    while(cases--){ 
        solve();
    }

    return 0;

    }

Measured memory_bytes: 3640
# 2019-11-28 02:28:10(JST)
import sys

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

def main():
    n, m = map(int, sys.stdin.readline().split())
    s, t = sys.stdin.read().split()

    g = gcd(n, m)
    l = lcm(n, m)

    if g == 1:
        if s[0] == t[0]:
            ans = l
        else:
            ans = -1
    else:
        for i in range(g):
            if s[i * n // g] == t[i * m // g]:
                continue
            else:
                ans = -1
                break
        else:
            ans = l
    
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int count= 0;
  
  vector<int> p(N);
  for (int i=0 ;i<N ;i++) {
    cin >> p[i];
  }
  
  for (int i=0 ;i<N ;i++) {
    if (p[i] != i+1){
      count++;
    }
  }
  if(count == 0 || count == 2){
    cout << "YES";
  }
  else{
    cout << "NO";
  }
}


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

const double PI=3.1415926535;
double a,b,x;

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

    double ans;
    if(x>=(a*b*a)/2){
        ans=atan(2/a*(b-x/(a*a)));
    }else{
        ans=atan((a*b*b)/(2*x));
    }

    ans*=360/(2*PI);

    cout<<setprecision(16)<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve()
{
    int n;
    cin>>n;
    ll a[n];
    ll sum=0;
  	ll m=1000000000+7;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        sum-=a[i];
        ans+=((a[i]%m)*(sum%m))%m;
    }
    cout<<ans%m;
}
int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 5180
//
//  main.c
//  procon
//
//  Created by L on 2017. 10. 17..
//  Copyright © 2017년 L. All rights reserved.
//

#include <stdio.h>
#include <string.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    
    char s[200];
    
    scanf("%s", s);
    
    int length = (int) strlen(s)-2;
    
    int i;
    
    while(length) {
        for (i=0; i<length/2; i++) {
            if (s[i] != s[i+(length/2)]) {
                break;
            }
        }
        
        if (i == length/2) {
            break;
        }
        else {
            length -= 2;
        }
    }
    
    printf("%d", length);
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    int N, A, B;
    cin >> N >> A >> B;

    int S = 0;
    for (int i = 1; i <= N; i++){
        int sum = 0;
        int j = i;
        while(j > 0){
            sum += j % 10;
            j /= 10;
        }
        //cout << "sum: " << sum << endl;
        if ((sum >= A) && (sum <= B)){
            S += i;
        }
    }
    cout << S << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int N,n;
	int a[10000];
	cin>>N;
	for(int i=0;i<N;i++) cin>>a[i];
	cin>>N;
	while(N--){
		int sign,b,e;
		cin>>sign>>b>>e;
		int Max=*max_element(a+b,a+e);
		int Min=*min_element(a+b,a+e);
		if(sign) cout<<Max<<endl;
		else cout<<Min<<endl;
		
	}
	return 0;
}



Measured memory_bytes: 3108
X, N = map(int, input().split())
if N ==0:
  print(X)
else:
  List = list(map(int, input().split()))
  res = X
  Flag =True
  for k in range(N):
    if List[k] == X:
      Flag = False
  if Flag:
    print(res)
  else:
    for i in range(1,103):
      med_p = X+i
      med_n = X-i
      Flag_p = False
      Flag_n = False
      for j in range(N):
        if List[j] == med_p:
          Flag_p = True
        elif List[j] == med_n:
          Flag_n = True
        else:
          pass
      if Flag_p and Flag_n:
        pass
      elif not Flag_p and Flag_n:
        res = med_p
        break
      elif Flag_p and not Flag_n:
        res = med_n
        break
      else:
        res = med_n
        break
    print(res)

Measured memory_bytes: 9232
A = []
for i in range(5):
  a = int(input())
  A.append(a)
B = []
for i in range(5):
  b = A[i]%10
  B.append(b)
C =[]
for i in range(5):
  if B[i] != 0:
    c = A[i]+10-B[i]
  else:
    c = A[i]
  C.append(c)
t = 0  
for i in range(5):
  t += C[i]
B.sort()
z = set(B)
if min(z) == 0:
  z.remove(0)
if len(z) ==0:
  print(t)
else:
  print(t-10+min(z))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#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 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 Next_permutation(vec) next_permutation(vec.begin(), vec.end())

int isPrime(int x) {
    int i;
    if (x < 2) return 0;
    else if (x == 2) return 1;
    if (x % 2 == 0) return 0;
    for (i = 3; i * i <= x; i++) {
        if (x % i == 0) return 0;
    }
    return 1;
}

int main() {
    int n, x, i;
    int cnt = 0;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &x);
        if (isPrime(x)) cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}


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

#define INF 1000000007


int main(){
	int t =1;
	//cin >> t;
	while(t--){
		unordered_map <string,int> M ;
		int n ;
		cin>>n ;
		for(int i=0 ;i<n;i++){
			string temp ;
			cin>>temp ;
			M[temp]++ ;}
		cout<<"AC x "<<M["AC"]<<endl ;
		cout<<"WA x "<<M["WA"]<<endl ;
		cout<<"TLE x "<<M["TLE"]<<endl ;
		cout<<"RE x "<<M["RE"]<<endl ;

}
	return 0 ;
	}
	





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

int64_t cnt = 0;
vector<int> G;

void insertionsort(int a[], int n, int g){
    for(int i = g; i < n; i++){
        int v = a[i];
        int j = i - g;
        while(j >= 0 && a[j] > v){
            a[j + g] = a[j];//ソート済みの場所の大きさを右側から調べる
            j -= g;
            cnt++;
        }
        a[j + g] = v;//空いたスペースに入れる
    }
}
void shellsort(int a[], int n){
    int h = 1;
    while(1){
        if(h > n) break;
        G.push_back(h);
        h = 3 * h + 1;
    }
    reverse(G.begin(), G.end());
    for(int i = 0; i < G.size(); i++){
        insertionsort(a, n, G[i]);
    }
}


int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    shellsort(a, n);

    cout << G.size() << endl;
    for(int i = 0; i < G.size(); i++){
        if(i > 0) cout << ' ';
        cout << G[i];
    }
    cout << endl << cnt << endl;
    for(int i = 0; i < n; i++){
        cout << a[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 7048
#include<cstdio>
#define N 100000
using namespace std;

int v[N+1];

int main(){
    int n,m,i;

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

    for(i=1;i<=m;i++){
        int a,b;
        scanf ("%d%d",&a,&b);

        v[a]++;
        v[b]++;
    }

    bool flag=false;
    for(i=1;i<=n;i++)
        flag|=(v[i]&1);

    if (flag==true) printf ("NO\n");
    else printf ("YES\n");

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <functional>

#define INF 100000
using namespace std;
typedef long long ll;

int main(){
	ll x;
	cin >> x;
	ll a1, a2;
	a1 = (x-1LL) / 11L+1LL;
	a2 = (x + 4LL) / 11L+1LL;
	if (a1 != a2) {
		cout << 2LL * a1 << endl;
	}
	else {
		cout << 2LL * a1-1LL << endl;
	}
	return 0;
}


Measured memory_bytes: 256
# E - Cell Distance
# https://atcoder.jp/contests/abc127/tasks/abc127_e

def comb(n,k,mod):
    if n<k:
        return 0
    if n<0 or k<0:
        return 0
    k=min(n-k,k)
    ans=1
    inv=[1]*(k+1)
    if k>=1:
        ans*=(n-k+1)%mod
    for i in range(2,k+1):
        inv[i]=mod-inv[mod%i]*(mod//i)%mod
        ans=ans*(n-k+i)*inv[i]%mod
    return ans

n, m, k = map(int, input().split())

MOD = 1000000007

distX = 0
for d in range(n):
    distX += d * (n - d) * m ** 2

distY = 0
for d in range(m):
    distY += d * (m - d) * n ** 2

ans = ((distX + distY) * comb(n * m - 2, k - 2, MOD)) % MOD

print(ans)

Measured memory_bytes: 5684