akhauriyash/Code-Regression huggingface dataset:
//dhruv
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define ffor(i,n) for(int i = 0;i < (n); ++i)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
#define ff first
#define ss second

struct dsu{
	vi par,sz;
	void init(int n){
		par.resize(n);
		sz.resize(n);
		ffor(i,n){
			par[i] = i;
			sz[i] = 1;
		}
	}

	int getPar(int i){
		return (par[i] == i ? i : par[i] = getPar(par[i]));
	}

	void unite(int x,int y){
		x = getPar(x);
		y = getPar(y);
		if(x == y) return;
		if(sz[x] < sz[y]){
			swap(x,y);
		}
		par[y] = x;
		sz[x] += sz[y];
	}

};

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    int n,m,k;
    cin >> n >> m >> k;
    dsu d;
    d.init(n);
    vi ans(n);
    vpii fr(m);
  	ffor(i,m){
  		int x,y;
  		cin >> x >> y;
  		--x,--y;
  		d.unite(x,y);
  		fr[i].ff = x;
  		fr[i].ss = y;
  	}
  	ffor(i,n){
  		ans[i] = d.sz[d.getPar(i)] - 1;
  		// cout << ans[i] << ' ';
  	}
  	ffor(i,m){
  		ans[fr[i].ff]--;
  		ans[fr[i].ss]--;
  	}
  	ffor(i,k){
  		int x,y;
  		cin >> x >> y;
  		--x,--y;
  		if(d.getPar(x) == d.getPar(y)){
  			ans[x]--;
  			ans[y]--;
  		}
  	}
  	ffor(i,n){
  		cout << ans[i] << ' ';
  	}
}		

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+7;
int f[N];
int main()
{
    int n;
    f[0] = 1;
    scanf("%d", &n);
    for(int i = 0; i+4 <= n; i++)
    {
        f[i+4] += f[i];
    }
    for(int i = 0; i+7 <= n; i++)
    {
        f[i+7] += f[i];
    }
    printf("%s\n", f[n]?"Yes":"No");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;
int main()
{
	int m,n,i,t;
	scanf("%d",&n);
	int flag=0;
	if(n%2!=0) flag=1;
	n=n/2;
	printf("%d",n+flag);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#define N (1000000000+7)
using namespace std;
typedef long long ll;
typedef pair<int,ll> P;

int c[20];
int a[20][20];

int main(void){
    int n,m,x;
    cin>>n>>m>>x;
    for(int i=0;i<n;i++){
        cin>>c[i];
        for(int j=0;j<m;j++)cin>>a[i][j];
    }
    int ans = 100000000;
    for(int i=0;i<(1<<n);i++){
        vector<int>tmp(m);
        int num = 0;
        for(int j=0;j<n;j++){
            if((i>>j)&1){
                num+=c[j];
                for(int k=0;k<m;k++)tmp[k]+=a[j][k];
            }
        }
        bool flag = true;
        for(int j=0;j<m;j++){
            if(tmp[j]<x)flag = false;
        }
        if(flag)ans = min(ans,num);
    }
    if(ans == 100000000)cout<<-1<<endl;
    else cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3652
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

//const long long int MOD = 1000000007;
const int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
int N, M, K, H, W, L, R;

long long int power(long long int x, long long int n, long long int M) {
	long long int ret = 1;
	long long int by = x;
	while (n) {
		if (n & 1) {
			ret *= by;
			ret %= M;
		}
		by *= by;
		by %= M;
		n >>= 1;
	}
	return ret;
}

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

	cin >> N >> M >> K >> L;
	vector<long long int>ans(N * 2);
	long long int st = 100;
	st *= power(M + K, MOD - 2, MOD);
	vector<long long int>by(N * 2, 1);
	vector<long long int>rev(N * 2, 1);
	vector<long long int>expf(N + 1, 1);
	vector<long long int>exps(N + 1, 1);
	vector<long long int>two_by(2 * N, 1);
	long long int rev100 = power(M+K, MOD - 2, MOD);
	for (int i = 1; i <= N; i++) {
		expf[i] = expf[i - 1] * M;
		expf[i] %= MOD;
		expf[i] *= rev100;
		expf[i] %= MOD;
		exps[i] = exps[i - 1] * K;
		exps[i] %= MOD;
		exps[i] *= rev100;
		exps[i] %= MOD;
	}
	two_by[1] = 2;
	for (int i = 2; i < N * 2; i++) {
		by[i] = by[i - 1] * i;
		by[i] %= MOD;
		rev[i] = power(by[i], MOD - 2, MOD);
		two_by[i] = two_by[i - 1] * 2;
		two_by[i] %= MOD;
	}
	long long int ret = 0;
	for (int i = N; i < N * 2; i++) {
		ans[i] = st * i;
		ans[i] %= MOD;
		ans[i] *= by[i - 1];
		ans[i] %= MOD;
		ans[i] *= rev[N - 1];
		ans[i] %= MOD;
		ans[i] *= rev[i - N];
		ans[i] %= MOD;
		long long int box = ((expf[N - 1] * exps[i - N]) % MOD)*expf[1] + ((expf[i - N] * exps[N - 1]) % MOD) * exps[1];
		box %= MOD;
		ans[i] *= box;
		ans[i] %= MOD;

		ret += ans[i];
		ret %= MOD;
	}
	cout << ret << endl;
}

Measured memory_bytes: 8064
#include<stdio.h>
 
int main(void){
  
  long long N,sum = 0;
  scanf("%ld",&N);
  
  for(int i=1; i<=N; i++){
    if( (i%3 != 0) && (i%5 != 0) ){
      sum += i;
    }else{
      /*何もしない*/
    }
  }
  
  printf("%ld",sum);

  return 0;
}

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

int main(){
    vector<int> result;
    string input;

    input += '\0';
    while(getline(cin, input), input !="END OF INPUT"){
        result.clear();
        int i = 0;
        int begin = 0;
        while(i<=input.size()){
            if(input[i] == ' ' || input[i] == '\0'){
                result.push_back(i-begin);
                begin = i + 1;
                i = begin;
            }
            else{
                i++;
            }
        }
        for(int i=0; i<result.size(); i++){
            cout << result[i];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 0
import java.util.BitSet;
import java.util.Scanner;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s1 = sc.nextLine();
        String s1arr[] = s1.split(" ");
        int n = Integer.parseInt(s1arr[0]);
        int m = Integer.parseInt(s1arr[1]);
        String a[] = new String[n];
        String b[] = new String[m];
        BitSet bs = new BitSet(n * n);

        for (int i = 0; i < n; i++) {
            String str = sc.nextLine();
            a[i] = str;
        }

        for (int i = 0; i < m; i++) {
            String str = sc.nextLine();
            b[i] = str;
        }

        for (int i = 0; i <= n - m; i++) {
            for (int j = 0; j <= n - m; j++) {
                for (int k = 0; k < m; k++) {
                    for (int l = 0; l < m; l++) {
                        if (b[k].charAt(l) == (a[i + k].charAt(j + l))) {
                            bs.set(k + m * l);
                        }
                    }
                }
                if (bs.cardinality() == m * m) {
                    System.out.println("Yes");
                    System.exit(0);
                }
                bs.clear();
            }
        }
        System.out.println("No");
    }

}

Measured memory_bytes: 10576
#include <stdio.h>
#include <string.h>
int main() {
  char s[4];
  
  scanf("%s",s);
 
 
  int i=0;
  if ((s[i]=='A' && s[i+1]=='A' && s[i+2]=='A') ||(s[i]=='B' && s[i+1]=='B' && s[i+2]=='B'))
   printf("No");
  else
   printf("Yes");
}
  

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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(int i=0; i<(n); i++)
#define REPj(n) for(int j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/* 
	add utility Algorithm
*/

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;

    map<string, bool> apperaW;
    string W, prevW;

    cin >> prevW;
    apperaW[prevW] = true;
    REPinit(i, 1, N) {
        cin >> W;
        if(W.at(0) != prevW.back() || apperaW[W]) {
            cout << "No\n";
            return 0;
        }
        apperaW[W] = true;
        prevW = W;
    }

    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 3656
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int main()
{

  //cout << fixed << setprecision(10);

  int x,a,b; cin >> x >> a >> b;
  if (abs(x-a)<abs(x-b)){cout<<"A";}
  else {cout << "B";}

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        int[] a = new int[5];
        for(int i=0;i<5;i++){
            a[i]=scn.nextInt();
            if(a[i]==0){
                System.out.println(i+1);
                return;
            }
        }

        scn.close();

    }

}

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

int main(){
    int N;
    cin >> N;
    
    int B[N-1];
    rep(i,N-1) cin >> B[i];
    
    int A[N];
    int i, ans, buff = B[0];
    for(i=0; i< N-1; i++){
        if(B[i] <= buff) {
            A[i] = B[i];
        }
        A[i+1] = B[i];
        buff = B[i];
    }
    for(i=0; i< N; i++){
        ans += A[i];
    }
    
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
int main(){
  string w;
  cin>>w;
  map<char,int> cnt;

  for(int i=0;i<w.size();i++){
    auto itr = cnt.find(w[i]);
    if(itr == cnt.end()){
      cnt.insert(make_pair(w[i],1));
    }else{
      cnt[w[i]]++;
    }
  }
  bool flag = true;
  for(auto itr = cnt.begin();itr != cnt.end();++itr){
    if(itr->second%2!=0){
      flag = false;
      break;
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int X;
  cin >> X;

  for(int i=1;i<1000;i++){
    if(i*X%360==0){
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;



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

    REP(i,1000) {
        if (A * (i + 1) % B == C) {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll n = 1;
    ll ans = INF;
    while (n * n <= N) {
        if (N % n == 0) {
            ans = std::min(ans, n - 1 + N / n - 1);
        }
        n++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
  int h, w;
  
  while(1){
    scanf("%d %d", &h, &w);
    if(h==0 && w==0){
      break;
    }

    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	if((i+j)%2 == 0){
	  printf("#");
	}else{
	  printf(".");
	}
      }
      printf("\n");
    }
    printf("\n");
  }
} 


Measured memory_bytes: 3140
import java.util.Scanner;

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

		for(int i = 0; i < n; i++){
			if(ans < k){
				ans *= 2;
			}else {
				ans += k;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include <vector>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <set>
#include <map>
using namespace std;
typedef long long ll;


int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  vector<ll> f(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int j = 0; j < n; ++j) cin >> f[j];

  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());

  ll r = 0;
  for (int i = 0; i < n; ++i) {
    r = max(r, a[i] * f[i]);
  }

  ll l = -1;
  r += 10;
  while (l + 1 < r) {
    ll mid = (l + r) / 2;
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
      sum += max(a[i] - mid / f[i], 0LL);
    }
    if (sum <= k) {
      r = mid;
    } else {
      l = mid;
    }
  }
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 3328
use std::io::Write;

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let (n, k): (usize, usize) = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        let mut ws = s.split_whitespace();
        let a = ws.next().unwrap().parse().unwrap();
        let b = ws.next().unwrap().parse().unwrap();
        (a, b)
    };

    let s: String = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        s
    };

    let chars: Vec<_> = s.chars().collect();

    let mut prev = 'a';
    let mut happiness = 0;
    let mut groups = 0;
    for &c in chars.iter() {
        if prev == c {
            happiness += 1;
        } else {
            prev = c;
            groups += 1;
        }
    }
    debugln!("{}", happiness);
    debugln!("{}", groups);

    let tmp = std::cmp::min(k, groups / 2);
    if groups % 2 == 0 && tmp == groups / 2 {
        println!("{}", happiness + tmp * 2 - 1);
    } else {
        println!("{}", happiness + tmp * 2);
    }
    // if tmp % 2 == 0 && tmp == k {
    //     debugln!("!!if");
    //     println!("{}", happiness + ((tmp - 1) / 2) * 2 + 1);
    // } else {
    //     debugln!("!!else");
    //     println!("{}", happiness + (tmp / 2) * 2);
    // }
}


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

#define LL long long
#define DD long double

#define M 1000000007
#define INF 1e18

void setIO(string s = "") { 
  cin.sync_with_stdio(0); cin.tie(0);
  if (s.size()) s += ".in", freopen(s.c_str(), "r", stdin);
}

int tt = 1;
void solve() {
  int n, a, c = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    if (i % 2 != 0 && a % 2 != 0) c++;
  }
  cout << c << endl;
}

int main() {
  setIO();
  while (tt--) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 3588
N, M = int(input()), pow(10,9)+7
memo = [{} for i in range(N+1)]

def ok(last4):
  for i in range(4):
    t = list(last4)
    if i >= 1:
      t[i-1], t[i] = t[i], t[i-1]
    if ''.join(t).count('AGC') >= 1:
      return False
  return True

def dfs(cur, last3):
  if last3 in memo[cur]:
    return memo[cur][last3]
  if cur == N:
    return 1
  ret = 0
  for c in 'ACGT':
    if ok(last3+c):
      ret = (ret + dfs(cur + 1, last3[1:] + c)) % M
  memo[cur][last3] = ret
  return ret

print(dfs(0, 'TTT'))
    

Measured memory_bytes: 3872
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;

  if (a1 + a2 + a3 >= 22) cout << "bust" << endl;
  else cout << "win" << endl;

  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;


#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;

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

    ll ansa, ansb;
    ansa = max(a - k, (ll)0);

    k = max(k - a, (ll)0);

    ansb = max(b - k, (ll)0);

    cout << ansa << ' ' << ansb << endl;


}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll f(ll N, ll X, vector<ll> a, vector<ll> p){
    if (N == 0){if (X <= 0){return 0;} else {return 1;}}
    else if (X <= (1 + a.at(N-1))){
        return f(N-1, X-1, a, p);
    } else {
        return p.at(N-1) + 1 + f(N-1, X - 2 - a.at(N-1), a, p);
    }
}

void Main() {
    ll N, X; cin >> N >> X;

    // 厚さ a_{i}: a_{0} = 1, a_{i} = 2 * a_{i-1} + 3
    // パティ p_{i}: p_{0} = 1, p_{i} = 2 * p_{i-1} + 1
    // レベルNバーガーの下層からX層に含まれるパティの枚数 f(N,X)
    vector<ll> a(N+1), p(N+1);
    a.at(0) = 1; p.at(0) = 1;
    rep(i, N){a.at(i+1) = 2 * a.at(i) + 3; p.at(i+1) = 2 * p.at(i) + 1;}
    cout << f(N, X, a, p) << endl;
}

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


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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << x2 - (y2 - y1) << " " << y2 + (x2 - x1) << " " << + x1 - (y2 - y1) << " " << y1 + (x2 - x1) << endl;
}


Measured memory_bytes: 256
X,N=input().split()
P=list(map(int, input().split()))
X=int(X)
N=int(N)
a1=X
a2=X
while (a1 in P)and(a2 in P):
    a1-=1
    a2+=1
if a1 in P:
    print(a2)
elif a2 in P:
    print(a1)
else:
    print(a1)

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

int main() {
  int a[2];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a+3);
  int count, temp;
  
  count = a[2] - a[1];
  temp = a[1] - a[0];
  count += temp / 2 + (temp%2) * 2;
  
  cout << count << endl;
}


Measured memory_bytes: 256
import collections
n=int(input())
l=[]
for i in range(n):
  l1=list(map(int,input().split()))
  l2=[]
  if l1[1]==0:
    l2=["0" for j in range(n)]
  else:
    for j in range(n):
      if j+1 in l1[2:]:
        l2.append("1")
      else:
        l2.append("0")
  l.append(l2)
D=[-1 for i in range(n)]
D[0]=0
q=collections.deque()
q.append(0)
while len(q)!=0:
  cur=q.popleft()
  for d in range(n):
    if l[cur][d]=="1" and D[d]==-1:
      D[d]=D[cur]+1
      q.append(d)
for i in range(n):
  print(i+1,D[i])


Measured memory_bytes: 6104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
int n, k, s;
int ans[maxx];

int main() {
	scanf("%d %d %d", &n, &k, &s);
	for(int i = 1; i <= n; i++) ans[i] = s;
	if(s != 1e9) {
		for(int i = k + 1; i <= n; i++) ans[i] = 1e9;
	}
	else {
		for(int i = k + 1; i <= n; i++) ans[i] = 1e9 - 1;
	}
	for(int i = 1; i <= n; i++) {
		if(i < n) printf("%d ", ans[i]);
		else printf("%d\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 1664
import java.util.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		long r=s.nextInt(),d=s.nextInt(),x=s.nextInt();
		for(int i=0;i<10;++i) {
			x=x*r-d;
			System.out.println(x);
		}
	}
}

Measured memory_bytes: 22228
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
int n,k,m,a[200005],sum,num;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&m);
		a[m]++;
		if(a[m]==1)sum++;
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i]==0)a[i]=99999999;
	}
	sort(a+1,a+n+1);
	for(int i=1;;i++)
	{
		if(sum<=k)break;
		num+=a[i];
		sum--;
	}
	cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 1000005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 998244353;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll ans = 0;
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll c[3] = {};
    for (auto &i : s) {
        if (i == 'R') {
            c[0]++;
        }
        else if(i=='G') {
            c[1]++;
        }
        else {
            c[2]++;
        }
    }
    ans = c[0] * c[1] * c[2];
    for (int i = 0 ; i < n ; i++) {
        for (int j = 1 ; ;j++) {
            if (i - j < 0 || i + j >= n) {
                break;
            }
            if (s[i] != s[i-j] && s[i] != s[i+j] && s[i-j] != s[i+j]) {
                ans--;
            } 
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3652
a, b, c, x, y = gets.split.map(&:to_i)

  if a+b < c*2
    p (a * x) + (b * y)
  else
    if x==y
      p (x * 2 * c)
    elsif x>y
      if a < c*2
        p (x-y) * a + (y * 2 * c)
      else
        p (x-y) * 2 * c + (y * 2 * c)
      end
    else
      if b < c*2
        p (y-x) * b + (x * 2 * c)
      else
        p (y-x) * 2 * c + (x * 2 * c)
      end
    end
  end



Measured memory_bytes: 1916
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
#define int long long
//#define double long double
signed main() {
	while (true) {
		int N;
		cin >> N;
		if (N == 0)break;
		vector<double> X(N);
		vector<double> Y(N);
		vector<double> Z(N);
		vector<double> VX(N);
		vector<double> VY(N);
		vector<double> VZ(N);
		vector<double> R(N);
		vector<double> VR(N);
		for (int i = 0; i < N; i++) {
			cin >> X[i] >> Y[i] >> Z[i] >> VX[i] >> VY[i] >> VZ[i] >> R[i] >> VR[i];
		}
		vector <pair<double, pair<int, int > > >vp;
		vector<int> exist(N, 1);
		vector<double> res(N);
		for (int i = 0; i < N; i++) {
			res[i] = R[i] / VR[i];
		}
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				double a, b, c;
				a = 0;
				a += (VX[i] - VX[j]) * (VX[i] - VX[j]);
				a += (VY[i] - VY[j]) * (VY[i] - VY[j]);
				a += (VZ[i] - VZ[j]) * (VZ[i] - VZ[j]);
				a -= (VR[i] + VR[j]) * (VR[i] + VR[j]);
				b = 0;
				b += 2 * (VX[i] - VX[j]) * (X[i] - X[j]);
				b += 2 * (VY[i] - VY[j]) * (Y[i] - Y[j]);
				b += 2 * (VZ[i] - VZ[j]) * (Z[i] - Z[j]);
				b += 2 * (VR[i] + VR[j]) * (R[i] + R[j]);
				c = 0;
				c += (X[i] - X[j]) * (X[i] - X[j]);
				c += (Y[i] - Y[j]) * (Y[i] - Y[j]);
				c += (Z[i] - Z[j]) * (Z[i] - Z[j]);
				c -= (R[i] + R[j]) * (R[i] + R[j]);
				
				double t0, t1;
				if (b*b - 4 * a*c < 1e-9)continue;
				if (abs(a) < 1e-9) {
					if (abs(b) < 1e-9) {
						continue;
					}
					t0 = t1 = -c / b;
				}
				else {
					t0 = (-b - sqrt(b*b - 4 * a * c)) / (2 * a);
					t1 = (-b + sqrt(b*b - 4 * a * c)) / (2 * a);
				}
				double mx = min(res[i], res[j]);
				//cerr << i << " " << j << " " << t0 << " " << t1 << endl;
				if (t1 < 1e-9)continue;
				if (t0 > mx)continue;
				vp.push_back(make_pair(max((double)0, t0), make_pair(i, j)));
				
			}
		}
		sort(vp.begin(), vp.end());
		for (int i = 0; i < vp.size(); i++) {
			if (exist[vp[i].second.first] == 1 && exist[vp[i].second.second] == 1) {
				res[vp[i].second.first] = min(res[vp[i].second.first], vp[i].first);
				res[vp[i].second.second] = min(res[vp[i].second.second], vp[i].first);
				exist[vp[i].second.first] = 0;
				exist[vp[i].second.second] = 0;
			}
		}
		for (int i = 0; i < N; i++) {
			cout << fixed << setprecision(30) << res[i] << endl;
		}
	}
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, d, ans = 0;
  cin >> n >> d;
  while(n--) {
    long long x, y;
    cin >> x >> y;
    long long dd = x*x + y*y;
    if(dd <= d*d) ans++;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
    }

    vector<ll> rui(n+1);  // rui[i+1] : a[i]までの和
    rep(i, n) {
        rui[i+1] = rui[i] + a[i];
    }
    
    map<ll, ll> mp;
    ll ans = 0;
    rep(i, n+1) {
        ans += mp[rui[i]];
        mp[rui[i]]++;
    }

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

Measured memory_bytes: 15872
import itertools
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
lis=[x for x in range(1,n+1)]
permutation=itertools.permutations(lis)
cnt=0
a=0
b=0
for  case in permutation:
  case=list(case)
  cnt+=1
  if case == p:
    a=cnt
  if case == q:
    b=cnt
 
    
print(abs(a-b))

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

#define sc second
#define fr first
#define mk make_pair
#define pb push_back
#define int long long

using namespace std;

const int N = (1e6 + 5);
const int inf = (1e9 + 7);

int n;
int a[N];
int cn = 1;
int last;
int ans;

main () {
    cin >> n;

    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
        if (a[i] == cn) {
            cn ++;
            ans += (i - last - 1);
            last = i;
        }
    }
    if (cn == 1) puts("-1");
    else  cout << ans + (n - last) << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
int max(int a,int b)
{
    return a>b?a:b;
}
int main()
{
    int n,i,k;
    while(scanf("%d",&n)==1)
    {
        int a[2][n],b[2][n];
        for(k=0; k<2; k++)
            for(i=0; i<n; i++)
                scanf("%d",&a[k][i]);
                b[0][0]=a[0][0];
        for(i=1; i<n; i++)
            b[0][i]=b[0][i-1]+a[0][i];
        b[1][0]=a[0][0]+a[1][0];
        for(i=1; i<n; i++)
            b[1][i]=max(b[1][i-1],b[0][i])+a[1][i];
        printf("%d\n",b[1][n-1]);
    }
    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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

    int N;
    cin >> N;
    int n = (1 << N);
    vector<ll> A(n);
    rep(i, 0, n) cin >> A[i];

    using P = pair<ll, ll>;
    vector<vector<P> > vv(n);

    rep(i, 0, n) {
        vv[i].emplace_back(A[i], i);
        for (int bit = 0; (1 << bit) <= i; bit++) {
            if ((i >> bit) & 1) {
                for (auto e : vv[i ^ (1 << bit)]) {
                    vv[i].push_back(e);
                }
            }
        }
        sort(vv[i].rbegin(), vv[i].rend());
        vv[i].erase(unique(vv[i].begin(), vv[i].end()), vv[i].end());
        if (vv[i].size() > 2u) vv[i].resize(2);

    }

    ll ans = 0;
    rep(i, 1, n) {
        chmax(ans, vv[i][0].first + vv[i][1].first);
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 130944
S = input()

if S == "SAT":
    print(1)
elif S == "FRI":
    print(2)
elif S == "THU":
    print(3)
elif S == "WED":
    print(4)
elif S == "TUE":
    print(5)
elif S == "MON":
    print(6)
else:
    print(7)

Measured memory_bytes: 38384
n = int(input())
*A, = map(int, input().split())
ans = [0] * n
ans[0] = sum(A)-2*sum([a for i, a in enumerate(A) if i % 2 != 0])
for i in range(1, n):
    ans[i] = 2*A[i-1]-ans[i-1]
print(*ans)


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

int main(){
    stack<int> s;
    string expr;   
    getline(cin, expr); // 1行読み込み
    istringstream is(expr); // 文字列ストリーム
while(!is.eof()){ 
            string a;
        is >> a;
        int tmp1,tmp2;
        if(a[0]=='+'){
            tmp1=s.top();
            s.pop();
            tmp2=s.top();
            s.pop();
            s.push(tmp1+tmp2);
        }
        else if(a[0]=='-'){
            tmp1=s.top();
            s.pop();
            tmp2=s.top();
            s.pop();
            s.push(tmp2-tmp1);
        }
        else if(a[0]=='*'){
            tmp1=s.top();
            s.pop();
            tmp2=s.top();
            s.pop();
            s.push(tmp2*tmp1);
        }
        else{
            istringstream is2(a);
            is2 >> tmp1;
            s.push(tmp1);
        }
}
cout << s.top() << endl;
return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    if (abs(c-a)<=d){
        cout << "Yes" << endl;
        return 0;
    }
    if (abs(b-a)<=d && abs(c-b)<=d){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = 0; i < (a); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

template<typename T>
void warshall_floyd(std::vector<std::vector<T>> &distance, const T INF) {
  for(int k = 0; k < distance.size(); ++k) {
    for(int i = 0; i < distance.size(); ++i) {
      for(int j = 0; j < distance.size(); ++j) {
        if(distance[i][k] == INF || distance[k][j] == INF) continue;
        else distance[i][j] = std::min(distance[i][j], distance[i][k] + distance[k][j]);
      }
    }
  }
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  VVI c(10, VI(10));
  rep(i, 10) {
    rep(j, 10) cin >> c[i][j];
  }
  VVI a(h, VI(w));
  rep(i, h) {
    rep(j, w) cin >> a[i][j];
  }
  warshall_floyd<int>(c, INF);
  int ans = 0;
  rep(i, h) {
    rep(j, w) {
      if(a[i][j] != -1) ans += c[a[i][j]][1];
    }
  }
  out(ans);
  return 0;
}


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

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

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

    for(int i = 0 ; i < n ; i++){
        if(b[i] >= a[i]){
            cnt += a[i];
            b[i] -= a[i];
        }else{
            cnt +=b[i];
            b[i] = 0;
        }

        if(b[i] >= a[i+1]){
            cnt += a[i+1];
            a[i+1] = 0;
        }else{
            cnt += b[i];
            a[i+1] -= b[i];
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let a:Vec<u64> = (0..n).map(|_| read()).collect();
    let mut map = HashMap::new();
    let mut ans_flag = true;

    //集計処理
    for i in a.into_iter(){
        let count = map.entry(i).or_insert(0);
        *count += 1;
    }

    //答えが存在するか判定
    for k in 0..(n/2){
        if map.get(&((n-1-2*k) as u64)).unwrap_or(&0) != &2 {
            ans_flag = false;
        }
    }
    //nが奇数の場合、0が1個あるか判定
    if n % 2 == 1{
        if map.get(&0).unwrap_or(&0) != &1{
            ans_flag = false;
        }
    }

    if ans_flag {
        //並び方が何通りあるか求める
        let mut ans = 1;
        for _ in 0..(n/2){
            ans *= 2;
            ans %= 1000_000_000 + 7;
        }
        println!("{}",ans);
    }else{
        println!("0");
    }
}


Measured memory_bytes: 6204
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll a,b;
    cin >> a >> b;
    cout << a * b << endl;
}

Measured memory_bytes: 3652
#include<stdio.h>

int main(void){
	int N,i,j;
	scanf("%d",&N);
	int a[N],W=0;
	for(i=0;i<N;i++){
		scanf("%d",&a[i]);
		W=W^a[i];
	}
	for(i=0;i<N;i++){
		printf("%d ",W^a[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
#define maxn 2020
#define rep(i,l,r) for(register int i = l ; i <= r ; i++)
#define repd(i,r,l) for(register int i = r ; i >= l ; i--)
#define rvc(i,S) for(register int i = 0 ; i < (int)S.size() ; i++)
#define rvcd(i,S) for(register int i = ((int)S.size()) - 1 ; i >= 0 ; i--)
#define fore(i,x)for (register int i = head[x] ; i ; i = e[i].next)
#define pb push_back
#define prev prev_
#define stack stack_
#define mp make_pair
#define fi first
#define se second
#define inf 0x3f3f3f3f
typedef long long ll;
typedef pair<int,int> pr;

int g[maxn][maxn],f[2][maxn * 2],tmp = 2000;
int n,m,col[maxn],t,bl = 1;

void dfs(int x,int &s1,int &s2){
	if ( col[x] == 2 ) s2++;
	else s1++;
	rep(i,1,n){
		if ( !g[x][i] && x != i ){
			if ( !col[i] ){
			   	col[i] = col[x] ^ 1 , dfs(i,s1,s2);
			}
			else if ( col[i] == col[x] ){ bl = 0; return; }
		}
	}
}
bool check(){
	f[0][tmp] = 1;
	rep(i,1,n){
		if ( !col[i] ){
			col[i] = 2;
			int b = 0,a = 0;
			dfs(i,b,a);
			if ( !bl ) return 0;
			memset(f[t ^ 1],0,sizeof(f[t ^ 1]));
			rep(j,-n + tmp,n + tmp){
			   	f[t ^ 1][j] |= f[t][j + b - a];
				f[t ^ 1][j] |= f[t][j - b + a];
			}
			t ^= 1;
		}
	}
	return 1;
}
int main(){
	scanf("%d %d",&n,&m);
	rep(i,1,m){
		int x,y;
		scanf("%d %d",&x,&y);
		g[x][y] = g[y][x] = 1;
	}
	if ( check() ){
	   	int mn = inf;
		rep(i,-n + tmp,n + tmp) if ( f[t][i] ) mn = min(mn,abs(i - tmp));
		int a = (mn + n) / 2 , b = (n - mn) / 2;
		printf("%d\n",(a * (a - 1) + b * (b - 1)) / 2);
	}
	else printf("-1\n");
}



Measured memory_bytes: 6144
# -*- coding: utf-8 -*-

#整数値入力 1文字の入力
def input_one_number():
    return int(input())

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

#整数値龍力　複数の入力(配列)
def input_multiple_number_as_list():
    return list(map(int, input().split()))

#整数値龍力　複数の入力(配列で1つずつ渡される)
def input_multiple_number_as_list_sep(N):
    ins = []
    for i in range(N):
        ins.append(input())
    return ins

#2次元配列入力
def input_map():
    return [list(map(int,list(input()))) for i in range(h)]

#リスト出力
def print_list(list):
    print(*list)
    return

#2次元配列出力
def print_map(maplist):
    for i in maplist:print(*i, sep='')
    return

#素数生成
def generate_primenums():
    n = 100
    primes = set(range(2, n+1))
    for i in range(2, int(n**0.5+1)):
        primes.difference_update(range(i*2, n+1, i))
    primes=list(primes)
    return primes

def memo():
    a=[0]*5
    b=a  #良くない配列のコピー
    b2=a[:]  #1次元のときはコピーはこれで良い
    a[1]=3
    print('b:{}, b2:{}'.format(b,b2))  #b:[0, 3, 0, 0, 0], b2:[0, 0, 0, 0, 0]
    
    import copy
    a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
    b=copy.deepcopy(a)  #2次元配列はこうコピーする
    
    #内包表記奇数のみ
    odd=[i for i in range(100) if i%2==1] #[1, 3, 5, 7, 9, 11, 13, 15, 17, 19]

    #二部探索
    import bisect
    a = [1, 2, 3, 5, 6, 7, 8, 9]
    b=bisect.bisect_left(a, 8)

    #combinations、組み合わせ、順列
    from itertools import permutations, combinations,combinations_with_replacement,product
    a=['a','b','C']
    print(list(permutations(a)))
    print(list(combinations(a,2)))
    print(list(combinations_with_replacement(a,3)))


#階乗
def kaijo(n):
    import math
    return math.factorial(n)

#選び方（コンビネーション nCr）
def num_combination(n,r):
    import math
    return math.factorial(n) // math.factorial(n - r)


#最大公約数、最小公倍数
def calc_gcd(a,b):
    import fractions
    GCD=fractions.gcd(a,b)
    lcm=a*b//gcd
    return gcd,lcm

#複数の最大公約数
def calc_gcd_list(l):
    gcd = l[0]
    for i in range(1, N):
        gcd = fractions.gcd(gcd, l[i])
    return gcd

#各桁の和
def sum_digit(n):
    sum = 0
    while n > 0:
        sum += n%10
        n //= 10
    return sum

N = input_one_number()
lst_d = input_multiple_number_as_list_sep(N)

lst_d.sort()

dan = len(lst_d)

before = 100000
for i in lst_d:
    if before == i:
        dan -= 1
    before = i

print(dan)


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

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

    if ((4 * X - Y) % 2 != 0 || (Y - 2 * X) % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }
    if (4 * X - Y < 0 || Y - 2 * X < 0) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
}

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

int main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    double w,h,x,y;
    cin >> w >> h >> x >> y;
    int o = 0;

    if(x*2 == w && y*2 == h){
        o = 1;
    }

    cout << w*h/2.0 << " " << o << endl;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#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 <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

  string lstr = "qwertazsxdcfvgb";
  set<char> left;
  for(int i=0;i<SZ(lstr);++i) left.insert(lstr[i]);
  while(true){
	string str; cin >> str; if(str=="#") break;
	int ans = 0;
	bool flag = (left.find(str[0]) != left.end());
	for(int i=0;i<SZ(str);++i)
	  if(flag != (left.find(str[i]) != left.end())){
		flag = !flag;
		++ans;
	  }
	cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,x[101],X[101],cnt=0,i,j,flg[101],S,s,w=0;
	scanf("%d",&a);
	for(i=1;i<=a;i++){
		x[i]=0;
		X[i]=i;
		flg[i]=0;
	}
	for(i=0;i<a*(a-1)/2;i++){
		scanf("%d%d%d%d",&b,&c,&d,&e);
		if(d>e){
			x[b]+=3;
		}
		else if(e>d){
			x[c]+=3;
		}
		else{
			x[b]++;
			x[c]++;
		}
	}
	for(i=1;i<=a;i++){
		s=-1;
		S=0;
		for(j=1;j<=a;j++){
			if(flg[j]==0){
				if(s<x[j]){
					s=x[j];
					S=j;
				}
			}
		}
		flg[S]=1;
		if(w==s){
			cnt++;
			X[S]=i-cnt;
		}
		else{
			cnt=0;
			X[S]=i;
		}
		w=s;
	}
	for(i=1;i<=a;i++){
		printf("%d\n",X[i]);
	}
	return 0;
}

Measured memory_bytes: 2724
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
template <class T>
void setmax(T &a, T const &b) {
    if (a < b) a = b;
}

template <class T>
void setmin(T &a, T const &b) {
    if (a > b) a = b;
}

template <typename T, typename X>
auto vectors(T a, X x) { return vector<T>(x, a); }

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
    auto cont = vectors(a, y, zs...);
    return vector<decltype(cont)>(x, cont);
}

const long long mod = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    vector<long long> B(N + 1, 0);
    for (int i = 0; i < N; ++i) {
        B[i + 1] = (A[i] + B[i]) % mod;
    }
    long long res = 0LL;
    for (int i = 0; i < N; ++i) {
        res += A[i] * B[i] % mod;
        res %= mod;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6404
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 H = sc.nextInt();
		int M = sc.nextInt();
		
		double akakudo = (H * 30 + M * 0.5) % 360 ;
		double bkakudo = (M * 6) % 360 ;
		double ckakudo = Math.abs(akakudo-bkakudo);
		
		if (ckakudo>=180){
			ckakudo = 360 - ckakudo; 
		} else  {
			ckakudo = ckakudo;
		}
		
		double a = (double) A;
		double b = (double) B;
		
		double c = Math.sqrt(( Math.pow(a,2) + Math.pow(b,2) - 2*a*b*(Math.cos(Math.toRadians(ckakudo)) )));
		System.out.println(c);
		
		
	}
}

Measured memory_bytes: 36076
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	int a[10][10];
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> a[i][j];
		}
	}
	vector<vector<int>> b(h, vector<int>(w));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> b[i][j];
		}
	}

	for (int k = 0; k < 10; k++) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
			}
		}
	}
	
	long long ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (b[i][j] != -1) {
				ans += a[b[i][j]][1];
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python3

A = [list(map(int, input().split())) for i in range(3)]
N = int(input())

for i in range(N):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k] == b:
                A[j][k] = 0

ans = "No"

for i in range(3):
    if A[i][0] == A[i][1] == A[i][2] == 0:
        ans = "Yes"
    if A[0][i] == A[1][i] == A[2][i] == 0:
        ans = "Yes"
if A[0][0] == A[1][1] == A[2][2] == 0:
    ans = "Yes"
if A[2][0] == A[1][1] == A[0][2] == 0:
    ans = "Yes"
print(ans)

Measured memory_bytes: 3064
// 2012/12/14 Tazoe

#include <iostream>
#include <string>
using namespace std;

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

if(cin.eof())
break;

	int J = 0;
	int I = 0;

	string::size_type index = 0;
	while(true){
		index = S.find("JOI", index);

		if(index==string::npos)
			break;

		J++;
		index++;
	}

	index = 0;
	while(true){
		index = S.find("IOI", index);

		if(index==string::npos)
			break;

		I++;
		index++;
	}

	cout << J << '\n';
	cout << I << '\n';
}

	return 0;
}

Measured memory_bytes: 1200
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

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

mp = [[100000 for i in range(N)] for j in range(N)]
mp2 = []
for i in range(M):
  a,b,c = map(int, input().split())
  mp[a-1][b-1] = c
  mp[b-1][a-1] = c
  mp2.append([a,b,c])
  
D = shortest_path(np.array(mp))

ans = [1 for i in range(M)]
for i,edge in enumerate(mp2):
  #print("{} {}".format(D[edge[0]-1, edge[1]-1], edge[2]))
  if D[edge[0]-1, edge[1]-1] >= edge[2]:
    ans[i] = 0
    
print(sum(ans))

Measured memory_bytes: 14176