akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

void tmp(int &x, int &y){
  int tmp;
  tmp = x;
  x = y;
  y = tmp;

}

int main(void){
  int a, b, c;

  cin >> a >> b >> c;

  while( !(a <= b && b <= c) ){
    if(a > b){
      tmp(a, b);

    }
    if (b > c){
      tmp(b, c);

    }
  }

  cout << a << " " << b << " " << c << "\n";

  return 0;
}

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

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

	int a = 1;
	while(a <= n){
		a *= 2;
	}
	cout << a/2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repf(i, a, b) for(ll i = (a); i < (b) ; i++ )
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;
struct UnionFind {
  vector<ll> data;
  UnionFind(ll size) : data(size, -1) { }
  bool unionSet(ll x, ll y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(ll x, ll y) {
    return root(x) == root(y);
  }
  ll root(ll x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  ll size(ll x) {
    return -data[root(x)];
  }
};
int main()
{
ll n;
cin >> n;
pair<ll, ll> px[n];
pair<ll, ll> py[n];
rep(i, n){
    ll x,y;
    cin >>x>>y;
    px[i].first=x;
    py[i].first=y;
    px[i].second=i;
    py[i].second=i;
}
sort(px,px+n);
sort(py,py+n);
pair<ll, pair<ll,ll>> p[n*2];
rep(i,n-1){
    p[i*2].first=px[i+1].first-px[i].first;
    p[i*2].second.first=(px[i+1].second);
    p[i*2].second.second=(px[i].second);

    p[i*2+1].first=py[i+1].first-py[i].first;
    p[i*2+1].second.first=(py[i+1].second);
    p[i*2+1].second.second=(py[i].second);
}
sort(p,p+2*n);

UnionFind arr(n);
ll cnt=0;
rep(i,2*n){
    if(!arr.findSet(p[i].second.first,p[i].second.second)){
        ans+=p[i].first;
        //cout << p[i].first << endl;
        cnt++;
        arr.unionSet(p[i].second.first,p[i].second.second);
    }
    if(cnt==n-1)break;
}

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

Measured memory_bytes: 8832
import std.stdio, std.array, std.string, std.conv, std.algorithm;
    import std.typecons, std.range, std.random, std.math, std.container;
    import std.numeric, std.bigint, core.bitop, core.stdc.string;
     
     
    void main() {
        auto S = readln.split.map!(to!int);
        auto K = S[1];
        auto A = readln.split.map!(to!int).filter!(a => a < K).array;
        A.sort();
        auto N = A.length.to!int;
     
        if (N == 0) {
            writeln(0);
            return;
        }
        
        if (N == 1) {
            writeln(A[0] >= K ? 1 : 0);
            return;
        }
     
     
        bool[5001] used;
        
        auto dp1 = new int[][](N);
        dp1[0] = [0, A[0]];
        foreach (i; 1..N) {
            memset(used.ptr, 0, used.sizeof);
            foreach (j; dp1[i-1]) {
                if (!used[j]) {
                    dp1[i] ~= j;
                    used[j] = true;
                }
                if (A[i] + j < K && !used[A[i]+j]) {
                    dp1[i] ~= A[i] + j;
                    used[A[i]+j] = true; 
                }
            }
            dp1[i].sort();
        }
     
        auto dp2 = new int[][](N);
        dp2[N-1] = [0, A[N-1]];
        foreach (i; iota(N-2, -1, -1)) {
            memset(used.ptr, 0, used.sizeof);
            foreach (j; dp2[i+1]) {
                if (!used[j]) {
                    dp2[i] ~= j;
                    used[j] = true;
                }
                if (A[i] + j < K && !used[A[i]+j]) {
                    dp2[i] ~= A[i] + j;
                    used[A[i]+j] = true;
                }
            }
            dp2[i].sort();
        }
     
     
        int ans = 0;
        
        foreach (i; 0..N) {
            bool required = false;
            int lb = K - A[i];
            
            if (i == 0) {
                if (dp2[1][$-1] >= lb) {
                    required = true;
                }
            }
            
            else if (i == N-1) {
                if (dp1[N-2][$-1] >= lb) {
                    required = true;
                }
            }
     
            else {
                int n = dp1[i-1].length.to!int;
                int m = dp2[i+1].length.to!int;
                int p1 = 0;
                int p2 = m-1;
                while (p1 < n && p2 >= 0) {
                    int s = dp1[i-1][p1] + dp2[i+1][p2];
                    if (s >= K) p2 -= 1;
                    else if (s < lb) p1 += 1;
                    else {required = true; break;}
                }
            }
     
            if (!required) ans += 1;
        }
     
        
        ans.writeln;
    }

Measured memory_bytes: 209904
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i, N) for (int i = 0; i < N; ++i)
typedef long long int LL;

int H, W;
char S[100][100];
int res[112][112];

int main()
{
	memset(S, '.', sizeof(S));
	in >> H >> W;
	rep(i, H) { in >> (S[i + 1] + 1); }

	rep(i, H)
	{
		rep(j, W)
		{
			if (S[i + 1][j + 1] == '.')
			{
				int cou = 0;
				if (S[i][j] == '#')
				{
					++cou;
				}
				if (S[i][j + 1] == '#')
				{
					++cou;
				}
				if (S[i][j + 2] == '#')
				{
					++cou;
				}
				if (S[i + 1][j] == '#')
				{
					++cou;
				}
				if (S[i + 1][j + 2] == '#')
				{
					++cou;
				}
				if (S[i + 2][j] == '#')
				{
					++cou;
				}
				if (S[i + 2][j + 1] == '#')
				{
					++cou;
				}
				if (S[i + 2][j + 2] == '#')
				{
					++cou;
				}
				res[i][j] = cou;
			}
		}
	}

	rep(i, H)
	{
		rep(j, W)
		{
			if (S[i + 1][j + 1] == '.')
			{
				out << res[i][j];
			}
			else
			{
				out << S[i + 1][j + 1];
			}
		}
		out << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

int main () {
    int n;
    scanf("%d" , &n);
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        int cmt = 0;
        if(i % 2 == 0)
          continue;
        for(int j = 1; j <= i; j++){
            if(i % j == 0)
                cmt++;
        }
        if(cmt == 8)
            cnt++;
    }
    printf("%d\n" , cnt);
}


Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;
int main() {
  int l, r, d, cunt = 0;
  cin >> l >> r >> d;
  for (int i = l; i <= r; i++) {
    if (i % d == 0) {
      cunt++;
      // cout << i << endl;
    }
  }
  cout << cunt << endl;
}

Measured memory_bytes: 3632
A, B, C, D =map(int,input().split())

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

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

ans =(B-A+1)-(B//(C)-(A-1)//C+B//(D)-(A-1)//D-B//lcm(C,D)+(A-1)//lcm(C,D))
print(ans)

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			if(n==0)
				return;
			ArrayList<Integer> Al=new ArrayList<Integer>();
			int ans=0;
			for(int i=0;i<=n;i++)
				Al.add(in.nextInt());

			for(int i=0;i<=n;i++) //i番目の数字を抜いて考える
			{
				ArrayList<Integer> Al2=new ArrayList<Integer>(Al);
				Al2.remove(i);
				if(judge(Al2))
				{
					ans=i;
					break;
				}
			}
			System.out.println(Al.get(ans));
		}
	}
	static boolean judge(ArrayList<Integer> AL)
	{
		int diff=AL.get(1)-AL.get(0);
		for(int i=1;i<AL.size();i++)
		{
			if(AL.get(i)-AL.get(i-1)!=diff)
			return false;
		}
		return true;
	}
}

Measured memory_bytes: 41592
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int, int> pi;
#define PI 3.14159265359
long long mod=1000000007;
//int count=INT_MAX;

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    //cin>>t;
    //scanf("%d",&t);
    
    for(int l=0;l<t;l++){
        int n;
        cin>>n;
        int d=n%10;
        if(d==2||d==4||d==5||d==7||d==9){
            cout<<"hon";
        }    
        else if(d==3){
            cout<<"bon";
        }
        else cout<<"pon";
    }
    
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <cmath>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i, k, N) for (int i = k; i < N; i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(), (x).end()

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

int main()
{
    ll N;
    cin >> N;
    v a(N);
    rep(i, 0, N) cin >> a[i];
    priority_queue<ll> pq;
    rep(i, 0, N){
        pq.push(a[i]);
    }


    ll ans = 0;
    while (pq.top() + ans > N - 1){
        ll now = pq.top();pq.pop();
        ll t = (now+ans-N-2) > 0 ? (now+ans-N-2) / N + 1 : 1;
        ans += t;
        now -= t * (N+1);
        pq.push(now);
    }

    cout<<ans;
    return 0;
}

Measured memory_bytes: 3564
import sys

for row in sys.stdin:
    row = row.strip().split(',')
    ls = list(map(int, row[:-2]))
    v1 = int(row[-2])
    v2 = int(row[-1])
    p = sum(ls) * v1 / (v1+v2)
    s = 0
    for i, l in enumerate(list(ls)):
        s += l
        if s>=p:
            print(i+1)
            break



Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const long long INFL = 1LL<<60;

int main() {
  int X;
  cin >> X;
  int ans = 0;
  for (int x = 1; x <= X; x++) {
    for (int i = 1; i <= int(sqrt(x)); i++) {
      for (int j = 1; j < 10; j++) {
        int po = pow(i, j);
        if (x == po) {
          chmax(ans, x);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

const int mod = 1e5;

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N, M, S;
	while (cin >> N >> M >> S, N | M | S) {
		N *= N;
		vector<vector<int>> dp(S + 1, vector<int>(N + 1));
		dp[0][0] = 1;
		for (int i = 1; i <= M; i++) {
			for (int j = S; j >= i; j--) {
				for (int k = N; k > 0; k--) {
					(dp[j][k] += dp[j - i][k - 1]) %= mod;
				}
			}
		}
		printf("%d\n", dp[S][N]);
	}
	return 0;
}



Measured memory_bytes: 3708
import scala.io.StdIn.readLine

object Main {

  def main(args: Array[String]): Unit = {

    val Array(n, x) = readLine().split(' ').map(_.toLong)
    val ls: Vector[Long] = (1 to n.toInt)
      .foldLeft(Vector(1): Vector[Long])((acc, i) =>
        acc :+ (acc(i - 1) * 2 + 3))
    val ps: Vector[Long] = (1 to n.toInt)
      .foldLeft(Vector(1): Vector[Long])((acc, i) =>
        acc :+ (acc(i - 1) * 2 + 1))
    println(patty(n.toInt, x, ls, ps))

  }

  def patty(n: Int, x: Long, ls: Vector[Long], ps: Vector[Long]): Long = {

    if (x == 0) {
      0
    } else if (n == 0) {
      1
    } else if (x <= (ls(n) - 1) / 2) {
      patty(n - 1, x - 1, ls, ps)
    } else if (x == (ls(n) - 1) / 2) {
      patty(n - 1, x - 1, ls, ps) + 1
    } else {
      ps(n - 1) + 1 + patty(n - 1, x - ls(n - 1) - 2, ls, ps)
    }

  }

}


Measured memory_bytes: 27336
// clang-format off
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort(all(x), greater<>())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
#define INF 1e9;
#define LINF 1e18;
template<class T>bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;}
// clang-format on

void solve(std::string s) {
  rep(i, s.size()) {
    if (i % 2 == 0)
      cout << s[i];
  }
  cout << endl;
}

// clang-format off
int main() {
  std::string s;
  std::cin >> s;
  solve(s);
  return 0;
}


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



// ABC130C - Rectangle Cutting
// https://atcoder.jp/contests/abc130/tasks/abc130_c
void ABC130C() {

	int W, H, x, y;
	cin >> W >> H >> x >> y;

	double s = double(W) * double(H);


	if (x*2 == W && y*2 == H) { //(x, y)が図形の中心のとき、切り方は2つ
		printf("%lf 1", s/2);
	}
	else { //(x, y)が中心以外のとき、切り方は1つ
		printf("%lf 0", s/2);
	}

}

int main() {
	ABC130C();

	return 0;
}


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

int main()
{
  int tower[1010]={};
  tower[0] = 0;
  for(int i=1;i <= 999;i++){
    tower[i] = i + tower[i-1];
  }
  int a,b;
  cin >> a >> b;
  cout << tower[b-a]-b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Vec  =vector<int>;

int		main(void)
{	
	int n;
	cin >> n;
	ll sum = 0;
	for (int i = 1; i < n; i++)
		sum += i;
	cout << sum << endl;
}



 	


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

using namespace std;

#define _for(i,j,N) for(int i = (j); i < (N);i++)

const int maxn = 100;
char G[maxn][maxn];

void print(){
    printf("100 100\n");
    _for(i,0,maxn){
        _for(j,0,maxn){
            printf("%c",G[i][j]);
        }
        printf("\n");
    }
}

int main()
{
    int A,B;
    scanf("%d %d",&A,&B);
    _for(i,0,maxn){
        _for(j,0,100){
            if(j < 50) G[i][j] = '.';
            else G[i][j] = '#';
        }
    }

    int r = 0,l = 0;
    _for(i,1,B){
        G[r][l] = '#';
        l+=2;
        if(l >= 48){
            l = 0;
            r+=2;
        }
    }

    r = 0,l = 51;
    _for(i,1,A){
        G[r][l] = '.';
        l+=2;
        if(l >= 99){
            l = 51;
            r+=2;
        }
    }

    print();
    return 0;
}

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

#define MOD_1_000_000_007 (1000000007LL)
#define LINF (1LL<<60)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep2(i, n)  for (long long i = 2; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)
#define REP(i, n, m) for (long long i = (long long)(n); i < (long long)(m); i++)

namespace solver {
  using namespace std;
  typedef long long ll;

  static const ll MAX = 100010LL;
  ll Q, L[MAX], R[MAX], sum[MAX];

  void init() {
    scanf("%lld", &Q);
    rep(i, Q) scanf("%lld %lld", L+i, R+i);
  }

  bool is_prime(ll n) {
    if(n<=1) return false;
    if(n==2) return true;
    ll limit = (ll)ceil(sqrt(n));
    rep2c(i, limit) if(n%i==0) return false;
    return true;
  }

  void solve() {
    rep(i, MAX) {
      if(is_prime(i) && is_prime((i+1)/2)) sum[i+1] = sum[i] + 1;
      else sum[i+1] = sum[i];
    }
    rep(i, Q) {
      printf("%lld\n", sum[R[i]+1] - sum[L[i]]);
    }
  }
}

int main() {
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 2944
#include "bits/stdc++.h"
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
#define SZ(x) ((int)(x).size())
#define int ll
#define el '\n'
template<class T> bool inline rmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool inline rmx(T &a, T b) { return a < b ? (a = b, true) : false; }
typedef long long ll; typedef long double ld; typedef double dd; typedef pair<int, int> pii;
const ll INFLL=0x7f7f7f7f7f7f7f7f, MOD=1e9+7; const int INF=0x7f7f7f7f;

//////////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is:\t"<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are:\t"<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are:\t"<<x<<' '<<y<<' '<<z<<'\n';

/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<int>> adj; vv<int> vis, color; 
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m=MOD){ll res=1;x%=m;while(n){if(n&1)res=(res*x)%m;n>>=1;x=(x*x)%m;}return res;}
inline ll gcd(ll a, ll b){if(a<0) a=-a; if(b<0) b=-b; while (a>0 && b>0){if(a>b)a%=b;else b%=a;}return a+b;}


///////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);
mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());

int n,m; cin>>n>>m;
vv<int> dp(1<<n, INFLL);
dp[0]=0;
while(m--){
	int a,b; cin>>a>>b;
	int mask=0;
	for(int i=0;i<b;++i){
		int l; cin>>l;
		mask|=1<<(l-1);
	}
	for(int i=0;i<(1<<n);++i){
		rmn(dp[i|mask],dp[i]+a);
	}
}
cout<<(dp.back()==INFLL?-1:dp.back())<<el;

return 0;
}


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

bool is[110];
bool js[110];

int main(){
    int h, w;
    char a[110][110];
    cin >> h >> w;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a[i][j];
        }
    }
    
    for(int i = 0; i < h; i++){
        bool omit = true;
        for(int j = 0; j < w; j++){
            if(a[i][j] == '#'){
                omit = false;
                break;
            }
        }
        if(!omit){
            is[i] = true;
        }
    }
    for(int j = 0; j < w; j++){
        bool omit = true;
        for(int i = 0; i < h; i++){
            if(a[i][j] == '#'){
                omit = false;
                break;
            }
        }
        if(!omit){
            js[j] = true;
        }
    }
    
    
    for(int i = 0; i < h; i++){
        if(!is[i]){
            continue;
        }
        for(int j = 0; j < w; j++){
            if(!js[j]){
                continue;
            }
            cout << a[i][j];
        }
        cout << '\n';
    }
}

Measured memory_bytes: 3600
#include <iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>

#define MOD 1000000007
#define DEBUG 0


using namespace std;

long long int modpow(long long int a, int n) {

	if (n == 0)return 1;
	if (n == 1) return a;

	long long int wk = modpow(a, n / 2);

	long long int ret = 0;
	if (n % 2 == 0) {
		ret = 1;
	}
	else {
		ret = a;
	}

	return (((ret * wk) % MOD) * wk) % MOD;

}

long long int gcd(long long int a, long long int b) {
	long long int tmp;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	long long int r = a % b;

	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

long long int lcm(long long int a, long long int b) {

	long long int wk_int;

	wk_int = (a * b) % MOD;
	
	long long int ret;

	ret = (wk_int * modpow(gcd(a, b), MOD - 2)) % MOD;

	return ret;

}

bool isPrime(int n) {
	if (n == 1)return false;
	if (n == 2)return true;

	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}

	return true;
}




int dis[10][10];






int main()
{

	int x;
	cin >> x;

	while (!isPrime(x)) {
		x++;
	}

	cout << x << endl;
	
	return 0;

}



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

using namespace std;

#define MAX_N 501
#define MAX_M 501
typedef long long ll;
const ll MOD = 10000LL;

int M;
ll dp[MAX_N][MAX_M][10][2][3];

ll dfs(int idx, int m, int d, bool lt, int up, string &s)
{
    if (idx == (int)s.size()) {
        return (m == 0);
    }
    ll &res = dp[idx][m][d][lt][up];
    if (res != -1) return res;
    
    res = 0;    
    int num = s[idx] - '0';
    for (int i = 0; i < 10; i++) {
        int nup = -1;
        if (lt || i <= num) {
            if (up == 0 && d < i) {
                nup = 1;
            } else if (up == 1 && d > i) {
                nup = 0;
            } else if (up == 2) {
                if (d == 0) {
                    nup = 2;
                } else if (d > i) {
                    nup = 0;
                } else if (d < i) {
                    nup = 1;
                }
            }
            if (nup != -1) {
                res += dfs(idx + 1, (10*m + i) % M, i, lt || (i < num), nup, s);
            }            
            res %= MOD;
        }            
    }
    return res;
}

void sub(string &A)
{
    for (int i = (int)A.size()-1; i >= 0; i--) {
        int num = (A[i] - '0'); num--;
        if (num == -1) {
            A[i] = '9';
        } else {
            A[i] = num + '0';
            return;
        }
    }
}

int main()
{
    string A, B;
    cin >> A >> B >> M;

    sub(A);    
    memset(dp, -1, sizeof(dp));
    ll va = dfs(0, 0, 0, 0, 2, A);
    
    memset(dp, -1, sizeof(dp));    
    ll vb = dfs(0, 0, 0, 0, 2, B);

    cout << (vb - va + MOD) % MOD << endl;
    return 0;
}

Measured memory_bytes: 118948
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;
using Complex = complex<double>;
const double PI = acos(-1);

int main() {
    int N, cnt = 0;
    string S;
    cin >> N >> S;
    for (int i = 0; i < N - 2; ++i) {
        if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
            cnt++;
            i += 2;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int a[26];
int main(){
string s;
cin>> s;
sort(s.begin(),s.end());
for(int i=0;i<s.size();i++) a[s[i]-'a']++;
for(int i=0;i<26;i++){
  if(a[i]==0) {
    cout << (char)(i+'a')<<endl;
    return 0;
  }
}
cout << "None"<<endl;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
const int N=100007,P=1000000007;
char str[N];int a[N],f[N],las[3];
int main()
{
    scanf("%s",str+1);int n=strlen(str+1),flg=0;
    for(int i=1;i<=n;++i) if(a[i]=(a[i-1]+str[i]-'a'+1)%3,str[i]==str[i-1]) flg=1;
    if(!flg) return puts("1"),0;;
    for(int i=1;i<=n;++i) f[i]=(1ll*f[las[0]]+f[las[1]]+f[las[2]]+(a[i]>=1)-f[las[a[i]]]+P)%P,las[a[i]]=i;
    printf("%d",f[n]);
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
#define MOD 1000000007

ll modpow(ll x, ll n) { 
  ll ans = 1;
  while(n > 0){
    if(n % 2 == 1){
      ans *= x;
      ans %= MOD;
    }
    x *= x;
    x %= MOD;
    n >>= 1;
  }
  return ans;
}

int main() {
  int n, k;
  cin >> n >> k;
  ll sum = 0;
  ll tmp = 1;

  vector<ll> a(k + 1, 0);
  for(int i = k; i > 0; i--) {
    int cnt = 0;
    cnt = k / i;
    
    tmp = modpow(cnt, n);
    //cout << tmp << endl;
    for(int j = i * 2; j <= k; j += i){
      if(j > k + 1){
        break;
      }
      tmp -= (ll)a[j];
      if(tmp < 0){
        tmp += MOD;
      }
    }
    a[i] = tmp;
    sum += tmp * i % MOD;
    sum %= MOD;
  }
  
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 4052
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const long long INF = 1LL<<60;

typedef pair<ll,ll> Pair;

int main(){

ll i = 0,j = 0;

//char henkan[27] = "abcdefghijklmnopqrstuvwxyz";
char answer[16];

ll N;

cin >> N;

  while(N > 0) {
    // 入力した数値を26で割り、その余りと商をだす
    N--;
    j = N % 26;
    N = N / 26;
    answer[i] = 'a' + j;
    i++;
  }

  i--;

  for(j=i; j>=0; j--) {
    printf("%c",answer[j]);
  }
  printf("\n");


return 0;

}   


Measured memory_bytes: 3656
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);

		ArrayList<Integer> array = new ArrayList<Integer>();

		for(int i=0;i<10000;i++) {
			int tmp = sc.nextInt();
			if(tmp==0) {
				break;
			}
			array.add(tmp);
		}

		for(int i=0;i<array.size();i++) {
			System.out.println("Case " + (i+1) + ": " + array.get(i));
		}

		sc.close();
	}
}


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

int main() {
  int R, G, B, n;
  cin >> R >> G >> B >> n;
  int cnt = 0;
  for(int i=0; n-R*i>=0; i++) {
    for(int j = 0; n-R*i-G*j>=0; j++) {
      if((n-R*i-G*j)%B==0) cnt++;
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 256
n=int(input())

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

ans=num2alpha(n).lower()
print(ans)

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

using namespace std;

signed main(){
    string s;
    cin >> s;
    int m[2019];
    memset(m,0,sizeof m);
    int c = s[0]-'0';
    m[c]++;
    int res = 0;
    for(int i = 1;i<s.size();i++){
        int x = s[i]-'0';
        int t[2019];
        memset(t,0,sizeof t);
        t[x] = 1;
        for(int z = 0;z<2019;z++){
            if(m[z] > 0){
                int cc = (z*10+x)%2019;
                if(cc%2019==0) res += m[z];
                t[cc%2019] += m[z];
            }
        }
        memset(m,0,sizeof m);
        for(int i= 0;i<2019;i++) m[i] = t[i];
    }
    cout << res;
}


Measured memory_bytes: 3676
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    string s;
    cin>>s;
    string res="";
    res += s[0];
    int cnt=0;
    for(int i=1;i<s.length();i++){
        if(s[i]==res[i-1]){
            cnt++;
            if(s[i]=='0')   res += '1';
            else            res += '0';
        }
        else{
            res += s[i];
        }
    }
    //cout<<res<<endl;
    cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 592
N,M=map(int,input().split())
AB=[[] for _ in range(N)]
for i in  range(N):
    a,b=map(int,input().split())
    AB[i]=[a,b]

AB.sort()

ans=0
cnt=0
for i in range(N):
    if cnt+AB[i][1]<M:
        cnt+=AB[i][1]
        ans+=AB[i][0]*AB[i][1]
    else:
        ans+=(M-cnt)*AB[i][0]
        break
        
print(ans)

Measured memory_bytes: 56736
A = int(input())
B = int(input())
C = int(input())
Y = int(input())

ra = min(A,int(Y//500+1))
rb = min(B,int(Y//100+1))
rc = min(C,int(Y//50+1))
#print(ra,rb,rc)

cnt = 0
for a in range(0,ra+1):
  for b in range(0,rb+1):
    for c in range(0,rc+1):
      if 500*a + 100*b + 50*c == Y:
        cnt += 1
        
print(cnt)

Measured memory_bytes: 9152
#include<bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed<<setprecision(x)
#define pii pair<ll,ll>
#define vint vector<ll>
#define pb push_back
using namespace std;
void Freopen(){
	freopen(title".in","r",stdin);
	freopen(title".out","w",stdout);
}
ll read(){
	ll g=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){g=g*10+ch-'0';ch=getchar();}
	return g*f;
}
const ll N=3005;
ll c[N][N],s[N][N],ci[N][N],n,ans,mod;
ll ksm(ll x,ll y,ll Mod){
	ll re=1;
	while(y){
		if(y&1)re=re*x%Mod;
		x=x*x%Mod;y>>=1;
	}return re;
}
ll solve(ll k){
	ll re=0;
	for(ll i=0;i<=k;i++)re=(re+s[k+1][i+1]%mod*ci[n-k][i]%mod)%mod;
	return re*c[n][k]%mod*ksm(2,ksm(2,n-k,mod-1),mod)%mod;
}
void init(ll n){
	for(ll i=0;i<=n;i++)c[i][0]=1;
	for(ll i=1;i<=n;i++)for(ll j=1;j<=i;j++)c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
	s[0][0]=1;
	for(ll i=1;i<=n;i++)for(ll j=1;j<=i;j++)s[i][j]=(s[i-1][j-1]+s[i-1][j]*j)%mod;
	for(ll i=0;i<=n;i++){
		ci[i][0]=1,ci[i][1]=ksm(2,i,mod);
		for(ll j=2;j<=n;j++)ci[i][j]=ci[i][j-1]*ci[i][1]%mod;
	}
}
signed main(){
	n=read(),mod=read(),init(3e3+1);
	for(ll i=0;i<=n;i++)ans=(ans+(i&1?mod-1:1)*solve(i)%mod)%mod;
	return cout<<ans,signed();
}
/*
2 1000000007
3 1000000009
50 111111113
3000 123456791
*/

Measured memory_bytes: 166492
<?php
    fscanf(STDIN, "%d", $n);
    $numbers = array();
    for ($i = 0; $i < $n; $i++ ) {
        fscanf(STDIN, "%d", $a);
        $numbers[] = $a;
    }
    $times = array_count_values($numbers);
    foreach ($times as $key => $value) {
        if ($value % 2 == 0) { unset($times[$key]); }
    }
    echo count($times) . "\n";
?>


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

const int MAX = 100010;

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

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

	COMinit();

	int N;
	int l, r;
	int A;
	map<int, int> pmap;
	cin >> N;
	rep(i, 0, N + 1)
	{
		cin >> A;
		if (pmap.find(A) != pmap.end())
		{
			l = pmap[A];
			r = N - i;
		}
		else
		{
			pmap[A] = i;
		}
	}

	cout << N << endl;
	rep(i, 2, N + 2)
	{
		int res = COM(N + 1, i);
		int exc = 0;
		if (l + r >= i - 1)exc += COM(l + r, i - 1);
		int ans = (res - exc + MOD) % MOD;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 9856
c=[[int(i) for i in input().split()] for j in range(3)]

ans=True
for i in range(2):
    check=c[i+1][0]-c[i][0]
    for j in range(1,3):
        if check !=c[i+1][j]-c[i][j]:
            ans=False
            break
for i in range(2):
    check=c[0][i+1]-c[0][i]
    for j in range(1,3):
        if check !=c[j][i+1]-c[j][i]:
            ans=False
            break

print('Yes' if ans else 'No')

        

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

int main() {
  int n;
  cin >> n;
  vector<int> b(n-1);
  for(int i=0;i<n-1;i++){
    cin >> b.at(i);
  }
  vector<int> a(n);
  a.at(0)=b.at(0);
  a.at(n-1)=b.at(n-2);
  for(int i=1;i<n-1;i++){
    a.at(i)=min(b.at(i),b.at(i-1));
  }
  ll sum=0;
  for(int i=0;i<n;i++){
    sum=sum+a.at(i);
  }
  cout << sum << endl;
}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimization ("unroll-loops")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using pii = pair<int, int>;

int f = 1;
double d[10][10];
double x[10], y[10];
int32_t main()
{
	int n;
	cin >> n;
	for (int i = 1; i<=n; i++) f*= i;
	for (int i = 0; i<n; i++)
	{
		cin >> x[i] >> y[i];
	}
	double u = 0;
	for (int i = 0; i<n; i++)
	{
		for (int j = i+1; j<n; j++)
		{
			d[i][j] = (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]);
			d[i][j] = sqrt(d[i][j]);
			u += d[i][j];
		}
	}
	cout << fixed << setprecision(10) << u*2.0/n << '\n';
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */


ll solve(){
    ll res = 0;
    ll N,K; cin >> N >> K;
    vector<ll> l(N); for(auto& in :l) cin >> in;
    sort(l.rbegin(),l.rend());
    res = accumulate(l.begin(),l.begin()+K,0LL);
    return res;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)


def dfs(p):
    result = True
    for np, D in edge[p]:
        if pos[np] is None:
            pos[np] = pos[p] + D
            result &= dfs(np)
        else:
            if pos[p] + D != pos[np]:
                result &= False
    return result


N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for q in sys.stdin.readlines():
    L, R, D = map(int, q.split())
    L -= 1; R -= 1
    edge[L].append((R, D))
    edge[R].append((L, -D))

pos = [None] * N
result = True
for i in range(N):
    if pos[i] is None:
        pos[i] = 0
        result &= dfs(i)

ans = 'Yes' if result else 'No'
print(ans)


Measured memory_bytes: 128908
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

ll A, B;
bool prm[1000010];
map<ll, int> mp1, mp2;
void prime(ll n){
    for(ll i = 2; i * i <= n; i++){
        prm[i] = true;
    }
    for(ll i = 1; i * i <= n; i++){
        if(!prm[i]) continue;
        for(ll j = i * 2; j * j <= n; j += i){
            prm[j] =false;
        }
    }
}

void prime_cnt(ll n, map<ll,int>& mp){
    for(ll i = 2; i * i <= n; i++){
        if(!prm[i]) continue;
        while(n % i == 0){
            n /= i;
            mp[i]++;
        }
    }
    if(n != 1) mp[n]++;
}

int main(){
    cin >> A >> B;
    prime(max(A, B));
    prime_cnt(A, mp1);
    prime_cnt(B, mp2);
    int ans = 1;
    for(auto& u :mp1){
        if(mp2[u.first] != 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1280
s = input()
a, b, c, d = map(str, s)
for op1 in '+-':
    for op2 in '+-':
        for op3 in '+-':
            if eval(a+op1+b+op2+c+op3+d) == 7:
                print(a+op1+b+op2+c+op3+d+'=7')
                exit()

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

int main()
{
		int n, i;
		cin >> n;
		for (i=1; i<=n; i++) {
				if (i%3==0) cout << " " << i;
				else {
						int x = i;
						while (1) {
								if (x%10==3) { 
										cout << " " << i;
										break;
								}
								if (x/10==0) break;
								x/=10;
						}
				}
		}
		cout << "\n";
}

Measured memory_bytes: 3072
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<vs> vvs;

typedef vector<pair<int, int>> vpi;
typedef vector<pair<ll, ll>> vpl;
typedef vector<tuple<int, int, int>> vti;


int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int a, p;
    cin >> a >> p;
    a *= 3;
    int ans = (a+p) / 2;
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = [list(map(int, list(input()))) for _ in range(N)]
graph = csr_matrix(S)
dist_matrix = floyd_warshall(graph, directed=False)
ans = np.array(dist_matrix, dtype=np.int64).max()+1

g = [[] for _ in range(N)]
for i in range(N):
	for j in range(N):
		if S[i][j]:
			g[i].append(j)

color = [0]*N
def f(v, c):
    color[v] = c
    for node in g[v]:
        if color[node] == c:
            return False
        elif color[node] == 0 and not f(node, -c):
            return False
    return True

k = 1
for i in range(N):
	if color[i] == 0 and not f(i, 1):
		k = -1
		break

if k == 1:
	print(ans)
else:
	print(-1)


Measured memory_bytes: 19056
#include <algorithm>
#include <functional>
#include <iostream>
#include <set>
#include<iomanip>
#include<queue>
using namespace std;
int comp(const void* a,const void *b){
	if(*((long *)a)>*(long *)b){
		return 1;
	}else if(*((long *)a)==*(long *)b){
		return 0;
	}else{
		return -1;
	}
}
int main() {
	long n,m;
	cin>>n>>m;
	if(m<=n){
		cout<<0<<endl;
	}else{
		long *ptr = new long[m];
		for(int i=0;i<m;i++){
			cin>>ptr[i];
		}
		qsort(ptr,m,sizeof(long),comp);
		long *distance = new long[m-1];
		for(int i=0;i<m-1;i++){
			distance[i]=ptr[i+1]-ptr[i];
		}
		qsort(distance,m-1,sizeof(long),comp);
		long sum=0;
		for(int i=0;i<(m-n);i++){
			sum+=distance[i];
		}
		cout<<sum<<endl;
		delete[] ptr;
		delete[] distance;
	}
	return 0;

}


Measured memory_bytes: 2540
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int answer = 0;
 vector<int> l(N);
  vector<int> r(N);
  for (int i = 0; i < N; i++) {
  cin >> l.at(i);
    cin >> r.at(i);
    answer += r.at(i) - l.at(i) + 1;
}
  cout << answer << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def main():
    N, M, Q = map(int, input().split())
    r_list = []
    for i in range(Q):
        r_list.append(list(map(int, input().split())))
    max_score = 0
    a1 = 1
    for a2 in range(a1, M+1):
        for a3 in range(a2, M+1):
            for a4 in range(a3, M+1):
                for a5 in range(a4, M+1):
                    for a6 in range(a5, M+1):
                        for a7 in range(a6, M+1):
                            for a8 in range(a7, M+1):
                                for a9 in range(a8, M+1):
                                    for a10 in range(a9, M+1):
                                        a_list = [a1,a2,a3,a4,a5,a6,a7,a8,a9,a10]
                                        score = 0
                                        for r in r_list:
                                            if a_list[r[1]-1] - a_list[r[0]-1] == r[2]:
                                                score += r[3]
                                        max_score = max(score, max_score)
    print(max_score)

if __name__ == "__main__":
    main()




Measured memory_bytes: 9272
# -*- coding: utf-8 -*-
from math import sin, cos, radians

def main():
    N  = int(input())
    s = [input() for i in range(N)]
    if len(set(s)) == N -1: 
        print("No")
        exit()
    for i in range(N-1):
        if s[i][-1] != s[i+1][0]:
            print("No")
            exit()
    print("Yes")
                

    

if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <bits/stdc++.h>
#include <stdio.h>
#include <string.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORD(i,a,b) for(int i=(a);i>(b);i--)
typedef long long ll;
const ll mod =1e9 +7;

int main(){
    int n;
    cin>>n;
    vector<int> arr(n);
    ll sum=0;
    FOR(i,0,n){
        cin>>arr[i];
        sum=(sum+arr[i])%mod;
    }
    
    ll to=0;
    ll d=0;

    ll ans=0;
    FOR(i,0,n){
        d=(d+arr[i])%mod;
       to=(sum-d)%mod;
        if(to<0) to=(to+mod)%mod;
        ans=(ans+(arr[i]%mod*to%mod)%mod)%mod;
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 4032
h, w = map(int, input().split())
mass = [list(map(int, input().split())) for _ in range(h)]
ans = []
for i in range(h):
    for j in range(w):
        if mass[i][j] % 2 == 0:
            pass
        elif i == h-1 and j == w-1:
            pass
        else:
            mass[i][j] -= 1
            if j != w-1:
                mass[i][j+1] += 1
                ans.append([i+1, j+1, i+1, j+2])
            elif i != h-1:
                mass[i+1][j] += 1
                ans.append([i+1, j+1, i+2, j+1])
print(len(ans))
for i in ans:
    print(*i)



Measured memory_bytes: 30276
import java.util.Scanner;

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

		int game = sc.nextInt();

		int tarouPoint = 0;
		int hanakoPoint = 0;

		String tarou;
		String hanako;


		for (int j = 0; j < game; j++) {
			tarou = sc.next();
			hanako = sc.next();

			if (tarou.equals(hanako)) {
				tarouPoint++;
				hanakoPoint++;
				continue;
			}

			char[] tarouChar = tarou.toCharArray();
			char[] hanakoChar = hanako.toCharArray();

			int wordLength = (Math.min(tarouChar.length, hanakoChar.length));

			boolean equal = true;
			for (int i = 0; i < wordLength; i++) {
				if (tarouChar[i] > hanakoChar[i]) {
					tarouPoint += 3;
					equal = false;
					break;
				} else if (tarouChar[i] < hanakoChar[i]) {
					hanakoPoint += 3;
					equal = false;
					break;
				}
			}
			if (equal) {
				if (tarouChar.length > hanakoChar.length) {
					tarouPoint += 3;
				} else {
					hanakoPoint += 3;
				}
			}


		}
		System.out.println(tarouPoint +" "+ hanakoPoint);
	}
}


Measured memory_bytes: 30272
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
vector<long long>v, w; int n;
long long gcd(long long a, long long b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}
int main() {
	while (true) {
		cin >> n; if (n == 0)break; v.clear(); w.clear();
		for (int i = 0; i < (n + 1)*n / 2; i++) {
			long long r; cin >> r; v.push_back(r);
			if (r % 2 == 1)w.push_back(r);
		}
		sort(v.begin(), v.end()); sort(w.begin(), w.end()); long long H = -1;
		for (int i = 0; i < v.size(); i++) {
			if (v[i] % 2 == 0) {
				if (H == -1)H = v[i];
				else H = gcd(H, v[i]);
			}
		}
		vector<long long>J;
		for (int i = 0; i < v.size(); i++) {
			if (v[i] % 2 == 0) { J.push_back(v[i] / H); }
		}
		sort(J.begin(), J.end());
		long long U1 = J[0] * J[1];
		long long U2 = sqrtl(w[0] / U1);
		H /= U2; cout << H << endl;
		for (int i = 0; i < J.size(); i++) { if (i)cout << ' '; cout << J[i] * U2; }cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3320
import java.io.IOException;
import java.util.Scanner;

class Main {
    public static void main (String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int[] a = new int[h];
        for (int i = 0; i < h; i++) {
            a[i] = sc.nextInt();
        }

        StringBuilder sb = new StringBuilder("");
        int parent, left, right;
        for (int i = 0; i < h; i++) {
            sb.append("node ").append(i + 1);
            sb.append(": key = ").append(a[i]);
            parent = (i + 1) / 2 - 1;
            if (parent >= 0) {
                sb.append(", parent key = ").append(a[parent]);
            }
            left = i * 2 + 1;
            if (left < h) {
                sb.append(", left key = ").append(a[left]);
            }
            right = left + 1;
            if (right < h) {
                sb.append(", right key = ").append(a[right]);
            }
            sb.append(", \n");
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 26320
N = gets.to_i
S = gets.chomp.split('')

l, r = 0, S.count('.')
ans = [l+r]
for i in 1..N do
    l += 1 if S[i-1] == "#"
    r -= 1 if S[i-1] == "."
    ans << l+r
end
puts ans.min

Measured memory_bytes: 20476