akhauriyash/Code-Regression huggingface dataset:
n,k=map(int,input().split())
x=list(map(int,input().split()))
k-=1
ans=float('inf')

for i in range(n-k):
  l,r=x[i],x[i+k]
  if l==0:
      ans=min(ans,r)
  
  elif r==0:
      ans=min(ans,abs(l))
  
  elif l<0 and r>0:
      ans=min(ans,abs(l)*2+r)
      ans=min(ans,abs(l)+2*r)
  
  elif l<0 and r<0:
      ans=min(ans,abs(l))
  
  elif l>0 and r>0:
      ans=min(ans,r)



print(ans)

Measured memory_bytes: 85136
#include<bits/stdc++.h>
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define w(x) scanf("%d",&x);while(x--)
#define ws(x) scanf("%d",&x);getchar();while(x--)
#define rep(i,b) for(i=0;i<=b;i++)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi 2*acos(0.0)
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const int N=1e6+2;
long long  mod=1e9+9;
int t,j,cs=0,n,a,b,i;
string s;

int main()
{
    cin>>n>>s;
    bool bl[26]={};
    int ans=0,cnt;
    for(i=0;i<n-1;i++){
        for(j=0;j<=i;j++)
            bl[s[j]-'a']=true;
        cnt=0;
        for(j=i+1;j<n;j++){
            if(bl[s[j]-'a']){
                cnt++;
                bl[s[j]-'a']=false;
            }
        }
        ans=max(cnt,ans);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3572
#include<iostream> 
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <vector>
#include<math.h>


using namespace std;
#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++)

int main() {
	int n, i = 0, j = 0, k = 0, p = 0, m, x, y, z;
	cin >> n;
	vector<int>l(n);

	rep(i, n) {
		cin >> l.at(i);
	}
	sort(l.begin(), l.end());

	rep(i, n) {
		rep2(j, i + 1, n) {
			rep2(k, j + 1, n) {

				x = l.at(i);
				y = l.at(j);
				z = l.at(k);

				if (x == y || y == z || z == x)
					continue;

				if (x + y > z ) 
					p++;
				

			}

		}

	}

	cout << p << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <math.h>

uint32_t primeNumList[10000];

static bool isPrimeNum(const uint32_t num) {
	if (num % 2 == 0) {
		return false;
	}

	const uint32_t limit = (uint32_t)sqrt((double)num);

	for (uint32_t divisor = 3; divisor <= limit; divisor += 2) {
		if (num % divisor == 0) {
			return false;
		}
	}

	return true;
}

static uint32_t listPrimeNum(void) {
	const uint32_t limit = 55555;
	uint32_t numPrimeNum = 0;

	for (uint32_t num = 3; num <= limit; num += 2) {
		if (isPrimeNum(num) && num%5 == 1) {
			primeNumList[numPrimeNum] = num;
			numPrimeNum++;
		}
	}

	return numPrimeNum;
}

int main(void) {
	uint32_t n;
	uint32_t numPrimeNum;

	numPrimeNum = listPrimeNum();

	scanf("%"PRIu32, &n);

	for (uint32_t idx = 0; idx < n - 1; idx++) {
		printf("%"PRIu32" ", primeNumList[idx]);
	}
	printf("%"PRIu32, primeNumList[n - 1]);

	return 0;
}


Measured memory_bytes: 128
require 'scanf'
a=STDIN.gets.scanf("%d %d %d %d")
b=STDIN.gets.scanf("%d %d %d %d")
t=a[0]+a[1]+a[2]+a[3]
s=b[0]+b[1]+b[2]+b[3]
if t>s then
    print t,"\n"
else
    print s,"\n"
end

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

int main() {
    int D, N;
    cin >> D >> N;
    int ans = N;
    rep(i, D) ans *= 100;
    if(N == 100) ans += ans / 100;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN

ll shin(ll n,ll b){
	ll sum=0;
	while(n>=b){
		sum += n%b;
		n /= b;
	}
	sum += n;
	return sum;
}


int main(void){
	ll n,s,small=1e13;
	scanf("%lld%lld",&n,&s);
	if(n-s<0){
		printf("-1\n");
		return 0;
	}
	if(n==s){
		printf("%lld\n",n+1);
		return 0;
	}
	reg(b,2,sqrt(n)){//始まりを1にすると無限ループ
		if(shin(n,b)==s && small>b){
			small=b;
			break;
		}
	}
	if(small==1e13){
		ireg(p,1,sqrt(n)){
			if((n-s)%p!=0)continue;
			ll b = (n-s)/p + 1;
			if(shin(n,b)==s && small>b){
				small=b;
				break;
			}
		}
	}
	if(small==1e13)small=-1;
	printf("%lld\n",small);
	return 0;
}

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

int main() {
  int A, B, C, D, E, k;
  cin >> A >> B>> C>> D>> E>> k;
  if (E-A > k) {
    cout << ":(" << endl;
  } else {
    cout << "Yay!" << endl;
  }
  return 0;
}





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

using namespace std;

#define PI (3.14159265358979323846)
#define MP make_pair
#define n1 first
#define n2 second
#define ALL(x) (x).begin(), (x).end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MS multiset
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define SZ(x) ((int)x.size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;

const db eps = 0.00001;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 550555;
const int M = 1125;

int a[N];
void solve() {
    int n;
    cin >> n;

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

    ll money = 1000, soc = 0;
    for (int i = 1; i <= n; i++){
        int x = i, mx = a[i];
        for (int j = i+1; j <= n; j++){
            if (a[j-1] > a[j]) break;
            x = j;
            mx = max(mx, a[j]);
        }
        if (mx > a[i]){
            soc += money / a[i];
            money %= a[i];
            money += soc * mx;
            soc = 0;
        }
        i = x;
    }

    cout << money;

}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define yokuwaruprime (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int gcd(int a,int b){
  if(a<b){
    int tmp=a; a=b; b=tmp;
  }
  int r=a%b;
  while(r!=0){
    a=b;
    b=r;
    r=a%b;
  }
  return b;
}

int main(){
  int n,k,d,m;
  cin>>n>>k;
  int a[n];
  rep(i,n){
    cin>>a[i];
  }
  d=a[0]; m=d;
  rep(i,n){
    d=gcd(d,a[i]);
    m=max(m,a[i]);
  }
  if(k%d==0 && k<=m){
    cout<<"POSSIBLE";
  }else{
    cout<<"IMPOSSIBLE";
  }
}

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

#define INF 1000000

int n;
int cost[110][110], d[110];
bool used[110];

void dijkstra(int s){

  for(int i = 0;i < n;i++) d[i] = INF;
  for(int i = 0;i < n;i++) used[i] = false;
  
  d[s] = 0;
  
  while(true){
    int v = -1;
    
    for(int u = 0;u < n;u++){
      if(!used[u] && (v == -1 || d[u] < d[v])) v = u;
    }
    
    if(v == -1) break;
    used[v] = true;
    
    for(int u = 0;u < n;u++){
      d[u] = min(d[u], d[v] + cost[v][u]);
    }
  }
}

int main(){
  
  int u, k, v, c;
  
  cin >> n;
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      cost[i][j] = INF;
    }
  }
  for(int i = 0;i < n;i++){
    cin >> u >> k;
    for(int j = 0;j < k;j++){
      cin >> v >> c;
      cost[u][v] = min(cost[u][v], c);
    }
  }
  
  dijkstra(0);
  
  for(int i = 0;i < n;i++) cout << i << " " << d[i] << endl;
  
  return 0;
}


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

using namespace std;

main(){
	int n;
	cin >> n;
	int s=0;
	int a=100000;
	while (s<n){
		s++;
		a=a+a*0.05;
		a=((a+999)/1000)*1000;
	}
	printf("%d\n",a);
}


Measured memory_bytes: 3120
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int max=0,K,n=0;
        int [] num = new int[3];
        for(int a=0;a<3;a++){
            num[a] = sc.nextInt();
            if(num[a]>max) {
                max =num[a];
                n=a;
            }
        }
        K=sc.nextInt();
        for(int b=0;b<K;b++){
            num[n] *=2;
        }
        int sum=0;
        for(int a=0;a<3;a++) {
            sum += num[a];
        }
        System.out.println(sum);

    }
}


Measured memory_bytes: 19924
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())

    dp = [defaultdict(int) for _ in range(N)]
    for c in 'ACGT':
        dp[0][c + 'XX'] = 1

    for i in range(1, N):
        for s, v in dp[i - 1].items():
            t = s[:2]
            for c in 'AT':
                dp[i][c + t] = (dp[i][c + t] + v) % MOD
            if not (s[1] == 'A' and s[0] == 'C'):
                dp[i]['G' + t] = (dp[i]['G' + t] + v) % MOD
            if (
                not (s[1] == 'A' and s[0] == 'G')
                and not (s[1] == 'G' and s[0] == 'A')
                and not (s[2] == 'A' and s[1] == 'G')
                and not (s[2] == 'A' and s[0] == 'G')
            ):
                dp[i]['C' + t] = (dp[i]['C' + t] + v) % MOD

    ans = sum(dp[N - 1].values()) % MOD
    print(ans)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9920
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	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 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());
		}

	}

	public static void main(String[] args) {
		new Main().run();
	}

	ArrayList<Integer>[] div;

	void run() {
		FastScanner sc = new FastScanner();
		PrintWriter pw = new PrintWriter(System.out);
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextInt();
		}
		long ans = 0;
		for (int i = 0; i < N; ++i) {
			int j = i;
			while (j + 1 < N && A[i] == A[j + 1])
				++j;
			ans += (j - i + 1) / 2;
			i = j;
		}
		pw.println(ans);
		pw.close();
	}

	long lcm(long a, long b) {
		return a / gcd(a, b) * b;
	}

	long gcd(long a, long b, long c) {
		return gcd(a, gcd(b, c));
	}

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

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

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

const int N = 220;

int dp[10][10];

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

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> dp[i][j];
        }
    }

    for (int k = 0; k < 10; k++) {
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int x;
            cin >> x;
            if(x == -1) continue;
            ans += dp[x][1];
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
def a():
    mod = 998244353
    o = [0] * 63

    def bi(x):
        i = 0
        while x != 0:
            o[i] = x%2
            x //= 2
            i += 1

    bi(mod-2)

    def modinv(m):
        b = 1
        p = m
        for i in range(63):
            if i:
                p = (p * p)%mod
            if o[i]:
                b *= p
                b %= mod
        return b

    N,M,K = map(int,input().split())

    C = [1]*(K+1)
    for i in range(1,K+1):
        C[i] = (C[i-1] * (N-i) * modinv(i))%mod

    M1 = [1]*N
    for i in range(1,N):
        M1[i] = M1[i-1] * (M-1)
        M1[i] %= mod

    ans = 0
    for k in range(0,K+1):
        ans += C[k] * M * M1[N-k-1]
        ans %= mod

    print(ans)

a()


Measured memory_bytes: 94288
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repa(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define COUT(x) cout << (x) << endl
#define _GLIBCXX_DEBUG

int main(){
  
  int n, m;
  cin >> n >> m;
  cout << (n - 1) * (m - 1) << endl;

}

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

int main()
{
    int n;
    cin >> n;
    int t[102], v[102];
    t[0] = 0;
    for(int i = 0; i < n; i++){
        cin >> t[i + 1];
        t[i + 1] *= 2;
        t[i + 1] += t[i];
    }
    for(int i = 0; i < n; i++){
        cin >> v[i];
        v[i] *= 2;
    }
    int b[50000];
    for(int i = 0; i <= t[n]; i++) b[i] = min(i, t[n] - i);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < t[i]; j++) b[j] = min(b[j], v[i] + t[i] - j);
        for(int j = t[i]; j < t[i + 1]; j++) b[j] = min(b[j], v[i]);
        for(int j = t[i + 1]; j <= t[n]; j++) b[j] = min(b[j], v[i] + j - t[i + 1]);
    }
    int ans = 0;
    for(int i = 0; i < t[n]; i++) ans += b[i] + b[i + 1];
    cout << fixed << setprecision(15) << ans / 8.0 << endl;
}


Measured memory_bytes: 3884
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int x=0,y=0,tmp=0;
    for(int i=0;;i++){
        scanf("%d %d",&x,&y);
        if(x==0&&y==0){
            break;
        }
        if(x>y){
            tmp=x;
            x=y;
            y=tmp;
        }
        printf("%d %d\n",x,y);
    }
    return 0;
}



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

const int N = 200000;
char s[N+5];

long long fastpow(int n, long long P){
    long long res = 1, x = 2;
    while (n){ if (n & 1) res = res * x % P; x = x * x % P; n >>= 1; }
    return res;
}

int main(){
    int n;
    scanf("%d", &n);
    scanf("%s", s);
    reverse(s, s + n);
    int mod = 0;
    for (int i = 0; i < n; ++i){
        if (s[i] == '1') ++mod;
    }
    int res0 = 0;
    for (int i = 0; i < n; ++i){
        if (s[i] == '1'){
            res0 = (res0 + fastpow(i, mod + 1)) % (mod + 1);
        }
    }
    int res1 = 0;
    if (mod > 1){
        for (int i = 0; i < n; ++i){
            if (s[i] == '1'){
                res1 = (res1 + fastpow(i, mod - 1)) % (mod - 1);
            }
        }
    }
    for (int i = n-1; i >= 0; --i){
        int ans = 0, res = 0;
        if (s[i] == '0'){
            ans = 1;
            res = (res0 + fastpow(i, mod + 1)) % (mod + 1);
        }
        else if (mod > 1){
            ans = 1;
            res = (res1 - fastpow(i, mod - 1) + mod - 1) % (mod - 1);
        }
        while (res){
            ++ans;
            res = res % __builtin_popcount(res);
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 3916
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    string s2;
    for(auto e : s){
        if(e != 'x'){
            s2 += e;
        }
    }
    for(size_t i = 0; i < s2.size(); i++){
        if(s2[i] != s2[s2.size() - 1 - i]){
            cout << -1 << '\n';
            return 0;
        }
    }
    int l = 0, r = s.size() - 1;
    int ans = 0;
    while(l < r){
        while(l < r && s[l] == s[r]){
            l++; r--;
        }
        if(l >= r){ break; }
        if(s[l] == 'x'){
            l++;
            ans++;
        }
        if(s[r] == 'x'){
            r--;
            ans++;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 760
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

int main() {

    string S, T;
    cin >> S >> T;

    vector<int> from(26, -1);
    vector<int> to(26, -1);

    for (int i = 0; i < S.size(); i++) {
        int f = S[i] - 'a';
        int t = T[i] - 'a';

        if (from[f] != -1 || to[t] != -1) {
            bool good = true;
            if (from[f] != t) good = false;
            if (to[t] != f) good = false;
            if(!good){
                cout << "No";
                return 0;
            }
        }

        from[f] = t;
        to[t] = f;
    }

    cout << "Yes";

    return 0;
}

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

int main()
{
ll h , w , m ;
cin >> h >> w >> m ;
map<ll, ll> ma{},maa{};
set<pair<ll,ll>>s;
vector<ll> va(300001,0);
vector<ll> vb(300001,0);

rep(i,m){
  ll x , y ;
  cin >> x >> y ;
  s.insert({x,y});
  ma[x]++;maa[y]++;
  va[x]++;
  vb[y]++;
}
vector<pair<int, int>> p;
for (auto i = ma.begin(); i != ma.end(); ++i)
{
  p.push_back(make_pair(i->second, i->first));
}
sort(p.rbegin(), p.rend());
vector<ll> a,b;

//first-個数 second-val
ll mx;
for (int i = 0; i < p.size(); ++i)
{
  if(i!=0&&mx!=p[i].first)break;
  if(i==0)mx=p[i].first;
  a.push_back(p[i].second);
}
vector<pair<int, int>> pp;
for (auto i = maa.begin(); i != maa.end(); ++i)
{
  pp.push_back(make_pair(i->second, i->first));
}
sort(pp.rbegin(), pp.rend());
ll mxx;
//first-個数 second-val
for (int i = 0; i < pp.size(); ++i)
{
  if(i!=0&&mxx!=pp[i].first)break;
  if(i==0)mxx=pp[i].first;
  b.push_back(pp[i].second);
}
ans=mx+mxx;
ll cnt=0;
for(auto au:s){
  if(mx+mxx==va[au.first]+vb[au.second])cnt++;
}
if(cnt==a.size()*b.size())ans--;
cout << ans << endl;
return 0;
}

Measured memory_bytes: 77280
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }

int main(){
    INT(h,r);
    if(h==-r)out(0);
    else if(h<-r)out(-1);
    else out(1);
}


Measured memory_bytes: 3236
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include <cstring>
#include <iomanip>
#include<queue>

using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1000000000
typedef long long  ll;

#define MOD 1000000007


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

    if((A-B)>C){
        cout << 0 << endl;
    }else{
        cout <<  C-(A-B)<< endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
using ll=long long;

int n;
vector<ll> T(100);

ll gcl(ll x,ll y){
    if(x<y) swap(x,y);
    while(y>0){
        ll t=x%y;
        x=y;
        y=t;
    }
    return x;
}

int main(){
    cin>>n;
    int count0=0,count2=0,count4=0;
    rep(i,0,n){
        int a;cin>>a;
        if(a%2==1) count0++;
        if(a%4==0) count4++;
        if(a%4==2) count2++;
    }
    if(count0<=count4||(n%2==1&&count4==n/2&&count0==n/2+1)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
abcd = input() #4つの数字をstr型で入力
l = len(abcd)  # l=4

for bit in range(1 << l-1):
    N = abcd[0]
    for i in range(3):
        N += ' '
        if ((bit >> i) & 1):
            N += '-'
        else:
            N += '+'
        N += abcd[i+1]
        N += ' '
    #print(N)
    N_int = sum(map(int, N.split()))
    #print(N_int)
    if N_int == 7:
        #ans = list(map(str, N.split()))
        ans = N.replace(' ', '')
        print('{}=7'.format(ans))
        break

Measured memory_bytes: 9124
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using ll = long long;
using namespace std;

int main() {
    string S;
    cin >> S;

    int x = stoi(S);
    string ans;
    int up = x / 100;
    int down = x % 100;
    bool up_in = up <= 12 && up >= 1;
    bool down_in = down <= 12 && down >= 1;

    if (up_in && down_in) {
        ans = "AMBIGUOUS";
    } else if (up_in && !down_in) {
        ans = "MMYY";
    } else if (!up_in && down_in) {
        ans = "YYMM";
    } else if (!up_in && !down_in) {
        ans = "NA";
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int l;cin>>l;
    double x = l/3.0;
    double ans = x*x*x;
    printf("%lf\n",ans);
    return 0;
}

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

int N;
set<string> SE;

void dfs(string s) {
  if (s.size() && stol(s) > N) return;
  if (s.size()) {
    string t = s;
    sort(t.begin(), t.end());
    t.erase(unique(t.begin(), t.end()), t.end());
    if (t.size() == 3) SE.insert(s);
  }
  dfs('7' + s);
  dfs('5' + s);
  dfs('3' + s);
}

int main() {
  cin >> N;
  string start;
  dfs(start);
  cout << SE.size() << "\n";
}

Measured memory_bytes: 2688
#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " << str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
    int N,K;
    cin>>N>>K;
    vector<int> a(N);
    vector<bool> win(K+1, false);
    REP(i,N)cin>>a[i];    

    FOR(i,1,K+1)
    {
        for(auto num: a)
        {
            int pos = i-num;
            if(pos>=0 && win[pos]==false)
            {
                win[i]=true;
                break;
            }
        }
    }
    //for(auto num:win)DEBUGING(num);

    cout << (win.back() ? "First" : "Second") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define ull unsigned long long int
#define ll long long
#define rep(x) for(A[x]=A[x-1];A[x]<=M;A[x]++)

int main(){
  ll A,N,B;
  scanf("%lld%lld%lld",&A,&B,&N);
  if(N>=B)N=B-1;
  printf("%lld",A*N/B);
};

Measured memory_bytes: 1732
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <random>

using namespace std;
using namespace __gnu_pbds;

typedef
tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()

#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)

#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))
#define relaxMax(a, b) a = max(a, b)
#define relaxMin(a, b) a = min(a, b)

typedef long long ll;
typedef long double ld;
#define ui unsigned int
#define ull unsigned long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;

typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;

typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;

#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first

#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(16);
    //freopen("amusing.in", "r", stdin);
    //freopen("amusing.out", "w", stdout);
}

void solve() {
    set<int> s;
    forn(i, 5){
        int x;
        cin >> x;
        s.insert(x);
    }
    for2(i, 1, 5){
        if (!s.count(i)){
            cout << i << '\n';
            return;
        }
    }
}

bool multitest = false;

int main() {
    init();
    int t = 1;
    if (multitest) cin >> t;
    forn(i, t) solve();
}

Measured memory_bytes: 3568
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;

struct pairs{
  int price;
  int num;
};
int main(int argc, char *argv[]) {
  /*
  cin>>x;
  cout<<x<<endl;
  
  int i,j,n,m,a,b=0,c;
  double ans=0,tmp;
  cin>>n>>m;
  vector<struct pairs> A(n);
  for(i=0;i<n;i++){
    cin>>A[i].price>>A[i].num;
  }
  sort(A.begin(),A.end(),[](const pairs& x, const pairs& y) { return x.price < y.price;});
  for(i=0;i<n;i++){
    if(A[i].num<=m){
      tmp=double(A[i].price)*A[i].num;
      ans=ans+tmp;
      m-=A[i].num;
    }else{
      tmp=double(A[i].price)*m;
      ans=ans+tmp;
      m=0;
    }
    if(m==0)
      break;
  }
  cout<<ans<<endl;
  */

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

  cout<<ans<<endl;

}


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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    unsigned long ans{1};
    vector<unsigned long> a(N);
    for(auto&& i : a)cin >> i;
    sort(begin(a), end(a));
    for(const auto& i : a){
        if(i && ans > 1000000000000000000 / i)return 0 & puts("-1");
        ans *= i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3996
#include<iostream>
#include<vector>
#define int long long
using namespace std;
signed main() {
  int n, k;
  cin >> n >> k;
  const int mod = 1e9 + 7;
  vector<int> fac(n + 1), inv(n + 1), finv(n + 1);
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i <= n; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - (mod / i) * inv[mod % i] % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
  auto comb = [&](int n, int k){
    if (n < k || n < 0 || k < 0) return 0LL;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
  };
  
  for (int i = 1; i <= k; i++) {
    cout << comb(n - k + 1, i) * comb(k - 1, i - 1) % mod << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	vector<int> c;
	for (int i = 6; i <= N; i *= 6) c.push_back(i);
	for (int i = 9; i <= N; i *= 9) c.push_back(i);
	sort(c.begin(), c.end());

	vector<int> dp(N + 1);
	for (int i = 0; i <= N; i++) {
		dp.at(i) = i;
		for (int j = 0; j < c.size(); j++) {
			if (i < c.at(j)) break;
			dp.at(i) = min(dp.at(i), dp.at(i - c.at(j)) + 1);
		}
	}

	cout << dp.at(N) << endl;
}

Measured memory_bytes: 3720
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <utility>
#include <set>
#include <numeric>
#include <queue>
#include <sstream>
#include <map>
#include <unordered_map>
#include <cmath>
using namespace std;
using LLI = long long int;

#define Rep(i, N) for (int i = 0; i < N; i++)

int main(int argc, char *argv[])
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> v(M, vector<int>());
    Rep(i, N) {
        int a, b;
        cin >> a >> b;
        if (a <= M) {
            v[a-1].push_back(b);
        }
    }

    priority_queue<int> pq;

    int total = 0;
    for (int i=0; i<M; i++) {
        for (int k : v[i]) {
            pq.push(k);
        }

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

    cout << total << endl;

    return 0;
}

Measured memory_bytes: 5632
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

template<class T>
struct SegTree {
    typedef T int_type;
    static const size_t MAX_N = 1 << 17;
    static const int_type INIT_VAL = (int_type(1)<<31)-1;
    int_type data[2 * MAX_N - 1];
    size_t n;
    SegTree(size_t n__) {
        n=1;
        while(n < n__) n*=2;
        rep(i,2*n-1) data[i]=INIT_VAL;
    }
    void update(size_t k,int_type a) {
        k+=n-1;
        data[k]=a;
        while(k>0) {
            k=(k-1)/2;
            data[k]=min(data[k*2+1],data[k*2+2]);
        }
    }

    int_type query(size_t a,size_t b,size_t k,size_t l,size_t r) {
        if(r<=a || b<=l) return INIT_VAL;
        if(a<=l && r<=b) return data[k];
        else {
            int_type vl = query(a,b,k*2+1,l,(l+r)/2);
            int_type vr = query(a,b,k*2+2,(l+r)/2,r);
            return min(vl,vr);
        }
    }
    int_type query(size_t a,size_t b) {
        return query(a,b,0,0,n);
    }
};
int main() {
    int n,q;
    cin>>n>>q;
    SegTree<ll> segTree(n);
    int a,b,c;
    rep(i,q) {
        cin>>a>>b>>c;
        if(a==0) {
            segTree.update(b,c);
        }
        else {
            cout<<segTree.query(b,c+1)<<endl;
        }
    }
    return 0;
}

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

using namespace std;
using ll = long long;

const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 20, BL = 400;
const double EPS = 3e-16;

int main(){
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
	long long n, c; cin >> n >> c;
                                                   
    vector<long long> a(n), dp(c + 1);
    for(long long &i : a) cin >> i;

    dp[0] = 1;

    for(long long i = 0; i < n; i++){
    	vector<long long> p(c + 1);
    	for(long long j = c; j >= 0; j--){
    		long long tmp = dp[j], L = j + 1, R = j + min(a[i], c - j);
    		if(L <= R){
				p[L] += tmp;
				if(R + 1 <= c){
					p[R + 1] -= tmp;
				}					
    		}
    	}
    	long long pref = 0;
    	for(long long i = 0; i <= c; i++){
    		pref += p[i];
    		(dp[i] += pref) %= MOD;
    	}
    }

	cout << dp[c];
    return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "cycle"

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

const int MAXN = 2e5 + 5;

ll pow_mod(ll a, ll st){
	ll ans = 1ll;
	for(; st; st >>= 1){
		if (st & 1){
			ans = (ans * a) % MOD;
		}
		a = (a * a) % MOD;
	}
	return ans;
}

ll f[MAXN], f_inv[MAXN];

ll get_c(int n, int k){
	if (n < 0 || k < 0 || k > n || n >= MAXN){
		return 0ll;
	}
	ll ans = (f[n] * f_inv[k]) % MOD;
	ans = (ans * f_inv[n - k]) % MOD;
	return ans;
}

void solve(){
	f[0] = 1;
	REP(i, 1, MAXN){
		f[i] = (f[i - 1] * i) % MOD;
	}
	f_inv[MAXN - 1] = pow_mod(f[MAXN - 1], MOD - 2);
	for(int i = MAXN - 2; i >= 0; i--){
		f_inv[i] = (f_inv[i + 1] * (i + 1)) % MOD;
	}	
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	h--, w--, a--, b--;
	ll ans = get_c(h + w, h);
	for(int x = b, y = h - a; x >= 0 && y <= h; x--, y++){
		ll tmp = (get_c(x + y, x) * get_c(h - y + w - x, h - y)) % MOD;
		ans = (ans - tmp + MOD) % MOD;
	}
	cout << ans << endl;
}	

int main(){

	//freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();	
	}
}

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


def solve(A: int, B: int, C: int, X: int):
    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)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    solve(A, B, C, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<stdio.h>

int n, A[50];

int solve(int i, int m){
  if( m == 0 ) return 1;
  if(i >= n ) return 0;
  int res = solve(i + 1,m) || solve(i + 1,m - A[i]);
  return res;
}

int main(){
  int q, M, i;

  scanf("%d",&n);
  for( i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d",&M);
    if( solve(0, M)) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <utility>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

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

pair<int, int> rotate(pair<int, int> p) {
  return pair<int, int>( p.second, -p.first );
}

pair<int, int> diff(pair<int, int> a, pair<int, int> b) {
  return pair<int, int>( a.first - b.first, a.second - b.second );
}

int main()
{
  int n;
  while(cin >> n, n) {
    vector<vector<pair<int, int>>> list;
    rep(i, n + 1) {
      vector<pair<int, int>> lines;
      int m;
      cin >> m;
      rep(j, m) {
        int x, y;
        cin >> x >> y;
        lines.push_back(pair<int, int>(x, y));
      }
      list.push_back(lines);
    }

    vector<vector<pair<int, int>>> keys;
    vector<pair<int, int>> key = list[0];
    rep(i, 4) {
      keys.push_back(key);
      rep(j, key.size()) {
        key[j] = rotate(key[j]);
      }
    }

    for(int i = 1; i <= n; ++i) {
      bool ok = false;
      if( list[0].size() != list[i].size() ) continue;
      int len = list[0].size();
      rep(j, 4) {
        bool flag = true;
        pair<int, int> atom = diff(list[i][0], keys[j][0]);
        rep(k, len) {
          flag &= atom == diff(list[i][k], keys[j][k]);
        }
        ok |= flag;
        flag = true;
        atom = diff(list[i][len - 1], keys[j][0]);
        rep(k, len) {
          flag &= atom == diff(list[i][len - 1 - k], keys[j][k]);
        }
        ok |= flag;
      }
      if(ok) {
        cout << i << endl;
      }
    }

    cout << "+++++" << endl;
  }

  return 0;
}

Measured memory_bytes: 1208
#include<stdio.h>

int main(void){
    int n,m,i,cnt=0,sum=0,num;
    scanf("%d%d",&n,&m);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        sum += a[i];
    }
    num = 4*m;
    if(sum%num==0){
        sum /= num;
    }else{
        sum /= num;
        sum++;
    }
    
    for(i=0;i<n;i++){
        if(a[i]>=sum){
            cnt++;
        }
    }
        if(cnt>=m){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
        return 0;
        
}


Measured memory_bytes: 128
A, B = map(int, input().split())


def prime_factorization(n):
    from collections import Counter
    counter = Counter()

    if n < 2:
        return counter

    for i in range(2, int(n ** 0.5) + 1):
        if i * i > n:
            break

        while n % i == 0:
            counter[i] += 1
            n //= i

    if n > 1:
        counter[n] += 1

    return counter


x = prime_factorization(A)
y = prime_factorization(B)

z = set(x.keys()) & set(y.keys())
print(len(z) + 1)


Measured memory_bytes: 3444
from math import gcd
from functools import reduce


def factor(n):
    res = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            res.append(i)
            n //= i
    if n > 1:
        return res + [n]
    else:
        return res


def solve():
    PC = "pairwise coprime"
    SC = "setwise coprime"
    NC = "not coprime"
    is_PC = True
    is_SC = True

    N, *A = map(int, open(0).read().split())

    primes = set()
    for a in A:
        if a == 1:
            continue
        new_primes = set(factor(a))
        if new_primes & primes:
            is_PC = False
            break
        primes |= set(factor(a))

    if reduce(gcd, A) != 1:
        is_SC = False

    if is_PC:
        print(PC)
    elif is_SC:
        print(SC)
    else:
        print(NC)


solve()


Measured memory_bytes: 207888
n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)

c0 = a.select { |m| m % 2 == 1 }.count
c1 = a.select { |m| m % 4 == 2 }.count
c2 = a.select { |m| m % 4 == 0 }.count

if c2 >= n / 2 || c1 + c2 * 2 >= n
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 10372
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	final int _intMax = Integer.MAX_VALUE; // =2147483647>10^9
	final int _intMin = Integer.MIN_VALUE;
	final long _longMax = Long.MAX_VALUE; // =9223372036854775807L>10^18
	final long _longMin = Long.MIN_VALUE;
	static boolean bElapsed = false;

	void solve() {
		int n = readNum();
		int[] ia = readNums();
		int d = ia[0];
		int x = ia[1];
		int[] ib = new int[n];
		for (int i = 0; i < n; i++) {
			ib[i] = readNum();
		}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			ans += 1 + (d - 1) / ib[i];
		}
		ans += x;
		pln(ans);
	}

	int pint(String s) {
		return Integer.parseInt(s);
	}

	long plong(String s) {
		return Long.parseLong(s);
	}

	String readLine() {
		try {
			return _in.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int readNum() {
		String line = readLine();
		return pint(line);
	}

	String[] readFlds() {
		String line = readLine();
		return line.split(" ");
	}

	int[] readNums() {
		String[] flds = readFlds();
		int[] nums = new int[flds.length];
		for (int i = 0; i < flds.length; i++) {
			nums[i] = pint(flds[i]);
		}
		return nums;
	}

	void p(char c) {
		_out.print(c);
	}

	void pln(char c) {
		_out.println(c);
	}

	void p(double d) {
		_out.print(d);
	}

	void pln(double d) {
		_out.println(d);
	}

	void p(long l) {
		_out.print(l);
	}

	void pln(long l) {
		_out.println(l);
	}

	void p(String s) {
		_out.print(s);
	}

	void pln(String s) {
		_out.println(s);
	}

	static BufferedReader _in;
	static PrintWriter _out;

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		_in = new BufferedReader(new InputStreamReader(System.in));
		_out = new PrintWriter(System.out);
		new Main().solve();
		_out.flush();
		long end = System.currentTimeMillis();
		if (bElapsed) {
			System.err.println((end - start) + "ms");
		}
	}
}


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

int main(){
    ll l, r; cin >> l >> r;
    if(l/2019 == r/2019) {
        ll ans=3000;
        for(ll i=l; i<=r; i++) {
            for(ll j=l; j<=r; j++) {
                if(i == j) continue;
                ll res = i * j % 2019;
                ans = min(ans, res);
            }
        }
        cout << ans << endl;
    }
    else cout << 0 << endl;
}
   

Measured memory_bytes: 256
a = [list(map(int, input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
flag = False
for i in range(3):
    if all(a[i][j] in b for j in range(3)):
        flag = True
    if all(a[j][i] in b for j in range(3)):
        flag = True
if all(a[i][i] in b for i in range(3)) or all(a[i][2-i] in b for i in range(3)):
    flag = True

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

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

const int N = 2e5 + 9;

int r, c, n, tot, s[N], t;
bool v[N];

struct Point {
	int x, y, d, id;
	void init () {
		if (y == 0) d = x;
		else if (x == r) d = r + y;
		else if (y == c) d = r + c + r - x;
		else d = r + c + r + c - y;
	}
}p[N];

bool operator < (const Point &A, const Point &B) { return A.d < B.d; }

bool Judge (int x, int y) { return (x == 0 || x == r) || (y == 0 || y == c); }

int main () {
	scanf("%d%d%d", &r, &c, &n);
	for (int i = 0, x1, y1, x2, y2; i < n; ++i) {
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		if (Judge(x1, y1) && Judge(x2, y2)) {
			p[tot].x = x1, p[tot].y = y1, p[tot].id = i, p[tot++].init();
			p[tot].x = x2, p[tot].y = y2, p[tot].id = i, p[tot++].init();
		}
	}
	sort(p, p + tot);
	for (int i = 0; i < tot; ++i) {
		if (v[p[i].id]) {
			if (s[t] == p[i].id) --t;
			else return puts("NO"), 0;
		} else {
			s[++t] = p[i].id;
			v[p[i].id] ^= 1;
		}
	}
	return puts("YES"), 0;
}
/*
2 2 4
0 0 2 2
2 0 0 1
0 2 1 2
1 1 2 1
*/

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

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	for(int i = 0;i < s.size();i++){
		printf("%c",(s[i]-'A'+n)%26+'A');
	}
	printf("\n");
	return 0;
}

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

int main(){
	double x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	double d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
	printf("%lf\n",d);
	return 0;
}


Measured memory_bytes: 3212