akhauriyash/Code-Regression huggingface dataset:
#include <stdint.h>
#include <stdio.h>
#include <algorithm>

unsigned N;
char s[512][512];
unsigned diag[512][512];
unsigned diag2[512][512];

bool isSolution(unsigned i, unsigned j) {
    for (unsigned a = 0; a < N; ++a) {
        if (diag[(i+a)%N][(j+a)%N] < std::min(a, N-a-1)) {
            return false;
        }
    }
    for (unsigned a = 0; a + 1 < N; ++a) {
        if (diag2[(i+a)%N][(j+a+1)%N] < std::min(a+1, N-a-1)) {
            return false;
        }
    }
    return true;
}

void initDiag(unsigned i, unsigned j) {
    diag[i][j] = 0;
    for (unsigned a = 1; a < N; ++a) {
        if (s[(i+N-a)%N][(j+a)%N] != s[(i+a)%N][(j+N-a)%N]) {
            break;
        }
        ++diag[i][j];
    }
    diag2[i][j] = 0;
    for (unsigned a = 1; a < N; ++a) {
        if (s[(i+N-a+1)%N][(j+a-1)%N] != s[(i+a)%N][(j+N-a)%N]) {
            break;
        }
        ++diag2[i][j];
    }
}

void init() {
    for (unsigned i = 0; i < N; ++i) {
        for (unsigned j = 0; j < N; ++j) {
            initDiag(i, j);
        }
    }
}

int main() {
    if (scanf("%u", &N) != 1) {
        return 1;
    }
    for (unsigned i = 0; i < N; ++i) {
        if (scanf("%s", s[i]) != 1) {
            return 1;
        }
    }

    init();

    unsigned result = 0;
    for (unsigned i = 0; i < N; ++i) {
        for (unsigned j = 0; j < N; ++j) {
            result += isSolution(i, j);
        }
    }
    printf("%u\n", result);
}


Measured memory_bytes: 1536
import math
def dig(i):
    dig = 0
    while i > 0:
        i //= 10
        dig += 1
    return dig

N = int(input())
lim = int(math.sqrt(N))
ans = 11
for i in range(1, lim+1):
    if N % i == 0:
        ans = min(ans, dig(N//i))
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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

typedef long long lint;

using namespace std;
int main(){
	set<int>s;
	rep(i,3){
		int tmp;
		cin>>tmp;
		s.insert(tmp);
	}
	cout<<SZ(s)<<endl;
}

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

int main(){
  int n;
  int num[101];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>num[i];
  }
  for(int i=0;i<n;i++){
    cout<<num[i];
    if(i==n-1)cout<<endl;
    else cout<<" ";
  }
  for(int i=1;i<n;i++){
    int v=num[i];
    int j=i-1;
    while(j>=0 && num[j]>v){
       num[j+1]=num[j];
      j--;
      num[j+1]=v;
    }
    for(int k=0;k<n;k++){
      cout<<num[k];
      if(k==n-1)cout<<endl;
      else cout<<" ";
    }
  }
}

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

int main()
{
  string n;
  cin >> n;
  string str = n;
  int count = 0;
  for (char c : str)
  {
    if (c == '7')
    {
      count += 1;
    }
  }
  if (count > 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
ll out[1000100]={0};
ll dp[1000100]={0};
#define MAX 1000100
int main(){
	out[1]=2;
	rep(i,MAX)dp[i]=i;
	for(int i=2;i<MAX;i++){
		if(dp[i]==i){
			for(int j=i;j<MAX;j+=i)dp[j]=dp[j]/i*(i-1);
		}
	}
	for(int i=2;i<MAX;i++)out[i]=out[i-1]+dp[i];
	int n;
	cin>>n;
	while(n--){
		int a;
		cin>>a;
		cout<<out[a]<<endl;
	}
}

Measured memory_bytes: 16780
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using lll = long long;
using ull = unsigned long long;
using namespace std;



int main(){
  lll ii,jj,kk;
  long n;
  string s;
  cin >> n;
  map<string,long> m;

  for(ii=0;ii<n;ii++){
    cin >> s;
    sort(s.begin(),s.end());
    if(m.find(s) == m.end()){
      m[s] = 1;   
    }
    else{
      m[s] = m[s] + 1;
    }
  }

  lll sum = 0;

  for(auto keyval = m.begin(); keyval != m.end(); keyval++){
    //cout << keyval->second << endl;
    if(keyval->second >= 2){
      sum += (keyval->second*(keyval->second-1))/2;
    }
  }
  cout << sum;
  return 0;
}


Measured memory_bytes: 11136
#include<stdio.h>

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

  scanf("%d %d %d", &a, &b, &c);

  if( a<=b && c<=b ) printf("%d\n", a+c);

  else if( b<=c && a<=c ) printf("%d\n", a+b);

  else printf("%d\n", b+c);
  
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int a = readInt();
        int b = readInt();

        int cnt = a-1;

        if(a <= b){
            cnt++;
        }


        System.out.println(cnt);

    }

    private static int readInt(){
        return Integer.parseInt(sc.next());
    }

    private static long readLong(){
        return Long.parseLong(sc.next());
    }

}

Measured memory_bytes: 22996
m=-1e9
n=int(raw_input())
N=range(n)
B=[[0]*(n+1) for _ in range(n+1)]
for _ in N:
  A=map(int,raw_input().split())
  for j in N:
    s=0
    b=B[j]
    for k in N[j:]:
      s+=A[k]
      b[k]=max(b[k],0)+s
      m=max(b[k],m)
print m

Measured memory_bytes: 4492
#include <iostream>

using namespace std;

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

	for (int X = 1; X <= N; ++X) {
		int Y = (int)(X * 1.08);
		if (Y == N) {
			cout << X << endl;
			return 0;
		}
	}
	cout << ":(" << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Arrays;

public class Main {

    private static Scanner sc;

    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            int n = sc.nextInt();
            int l = sc.nextInt();

            String[] array = new String[n];
            for (int i = 0; i < n; i++) {
              array[i] = sc.next();
            }

            Arrays.sort(array);
            
            System.out.println(String.join("", array));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}


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

int main(){
	int n, k;
    cin >> n >> k;
    vector<int> mo(n);
    rep(i, n) cin >> mo.at(i);
    sort(mo.begin(), mo.end());
    for(int i=n-1; i>max(n-1-k, -1); i--){
      mo.at(i) = 0;
    }
    ll ans = 0;
    rep(i, n) ans += mo.at(i);
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
using namespace std;
int main(void){
    int A,B;
    cin>>A>>B;
    int ans1 = A+B;
    if(ans1<(A-B)){
        ans1=A-B;
    }
    if(ans1<(A*B)){
        ans1=A*B;
    }
    cout << ans1 <<endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int  //comment for large arrays
#define pll pair<int,int>
#define dbl long double
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define eps 0.00000001
#define INF 10000000000000001
#define all(x) (x).begin(),(x).end()
#define LB(v,x) (lower_bound(all(v),x) - v.begin()) 
#define UB(v,x) (upper_bound(all(v),x) - v.begin())
#define size(x) (int)(x).size()
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define popb() pop_back()
#define popf() pop_front()
#define mp(x,y) make_pair((x),(y))
#define vec(dt) vector<dt>
#define vv(dt) vector<vector<dt>>
#define fastio(x) ios_base::sync_with_stdio(x); cin.tie(NULL)
#define init(v,s) memset(v,s,sizeof(v)) 
#define bug(x) cerr<<"LINE: "<<__LINE__<<" || click to see test details "<<#x<<" = "<<x<<endl
#define loop(i,s,n) for(int i=s;i<n;i++)
#define bugprint(v) for(auto it:v) cout<<it<<" "; cout<<endl 
using namespace std;


signed main()
{
	fastio(0);
	int n;
	cin>>n;
	int dp[2][3];
	cin>>dp[0][0]>>dp[0][1]>>dp[0][2];
	loop(i,1,n)
	{
		int score;
		loop(j,0,3)
		{
			cin>>score;
			dp[1][j] = score + max(dp[0][(j+1)%3], dp[0][(j+2)%3]);
		}
		loop(j,0,3) swap(dp[0][j],dp[1][j]);
	}
	int ans = 0;
	loop(j,0,3) ans = max(ans,dp[0][j]);
	cout<<ans<<endl;
	return 0;		
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int R = sc.nextInt();
		System.out.println(judgeSun(H, R));
		sc.close();

	}

	private static int judgeSun(int H, int R) {
		int x = 1;

		if (Math.abs(H) == R) {
			if (H < 0) {
				x = 0;
			} else {
				x = 1;
			}
		} else if (Math.abs(H) > R) {
			if (H < 0) {
				x = -1;
			} else {
				x = 1;
			}
		}

		return x;
	}

}


Measured memory_bytes: 26380
N=int(input())
A=list(map(int, input().split()))

dp = [[0 for i in range(2)] for j in range(N+1)]

if N in [2, 3]: print(max(A))
else:
  dp[2][0] = A[1]
  dp[2][1] = A[0]
  dp[3][0] = A[2]
  dp[3][1] = max(A[1], A[0])
  
  for i in range(4, N+1):
    if i % 2 == 0:
      dp[i][0] = max(max(dp[i-2][0], dp[i-2][1])+A[i-1], dp[i-1][1]+A[i-1])
      dp[i][1] = dp[i-2][1]+A[i-2]
    else:
      dp[i][0] = max(dp[i-2][0], dp[i-2][1])+A[i-1]
      dp[i][1] = max(dp[i-1][0], dp[i-1][1])

  print(max(dp[-1][0], dp[-1][1]))

Measured memory_bytes: 52108
N = int(input())
s = 'abcdefghijklmnopqrstuvwxyz'
ans = s[(N-1)%26]
N -= (N-1)%26
for i in range(25):
    if N < 26:
        break
    N = N//26
    ans = s[(N-1)%26] + ans
    N -= (N-1)%26

print(ans)

Measured memory_bytes: 9124
#include <iostream>
#include <array>
#include <algorithm>

auto read = [](auto &x){std::cin >>x;};
auto readSeq = [](auto *begin, auto *end){
                  std::for_each(begin, end, read);
                };
auto printSeq = [](auto *begin, auto *end){
                   std::for_each(begin, end-1, [](auto x){std::cout<<x<<" ";});
                   std::cout << *(end-1) <<  std::endl;
                 };

void insertionSort(int *begin, int *end);

int main ()
{
  int n;
  const int max_n = 100;
  std::array<int, max_n> arr;

  read(n);
  readSeq(arr.begin(), arr.begin()+n);

  insertionSort(arr.begin(), arr.begin()+n);


  printSeq(arr.begin(), arr.begin()+n);

  return 0;
}

void insertionSort(int *begin, int *end)
{
  auto n = std::distance(begin, end);
  auto itr = begin;

  for (int i=1; i<n; i++)
    {
      printSeq(begin, end);
      auto temp = itr[i];
      int j=i-1;

      while ((itr[j] > temp) && (j>=0))
        {
          itr[j+1] = itr[j];
          j--;
        }
      itr[j+1] = temp;
    }
}



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

int main() {
  int N; cin >> N;
  int c = 0;
  rep(i,N) {
    int a; cin >> a;
    if (i%2==0 && a%2==1) c++;
  }
  cout << c << endl;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int n, k;
  cin >> n >> k;
  vi x(n);
  rep(i,n) cin >> x[i];
  int ans = 0;
  rep(i,n) {
    ans += min(x[i], abs(k-x[i]));
  }
  ans *= 2;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<numeric>

using namespace std;

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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main () {
  int n,m,c,cnt = 0;
  cin >> n >> m;
  vector<int> k(n),c1(m+1);
  vector<vector<int>> a(n);
  for (int i = 0; i < n; i++){
    cin >> k[i];
    for (int j = 0; j < k[i]; j++){
      cin >> c;
      a[i].push_back(c);
    }
  }
  for (int i = 0; i < n; i++){
    for (int j = 0; j < k[i]; j++){
      c1[a[i][j]]++;
    }
  }
  for (int i = 1; i <= m; i++){
    if (c1[i] == n){
      cnt++;
    }
  }
  cout << cnt << '\n';
  return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define MOD 1000000007
typedef long long ll;
typedef long double ld;

int main(){
    int a,b,max;
    cin >> a >> b;
    max = (a+b);
    if(a-b > max) max = (a-b);
    if(a*b > max) max = (a*b);
    
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 3552
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i=0; i<N; i++) cin >> a[i];
  
  vector<int> kind(100000);
  for (int i=0; i<N; i++) {
    kind[a[i]]++;
  }
  int ans = -1;
  for (int i=2; i<=100000; i++) {
    ans = max(ans,kind[i]+kind[i-1]+kind[i-2]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int n;
int mon[100005];
int her[100005];
int32_t main(){
	cin>>n;
	for(int i=1;i<=n+1;i++){
		cin>>mon[i];
	}
	for(int i=1;i<=n;i++){
		cin>>her[i];
	}
	int ans = 0;
	for(int i=1;i<=n;i++){
		int delta = her[i]-mon[i];
		//cout<<delta<<" ";
		if(delta>0){
			her[i]=delta;
			ans += mon[i];
			mon[i]=0;
			ans += min(her[i],mon[i+1]);
			mon[i+1]-=min(her[i],mon[i+1]);
		}
		else {
			ans += her[i];
			mon[i]-=her[i];
			her[i]=0;
		}
	}
	cout<<ans;
}


Measured memory_bytes: 1792
N, A = map(int, input().split())
xs = map(lambda x: int(x) - A, input().split())

d = dict()
d[0] = 1
for x in xs:
    for s, v in list(d.items()):
        d[s + x] = d.get(s + x, 0) + v

print(d[0]-1)


Measured memory_bytes: 3188
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let mut iter = buf.split_whitespace();
	let a:i32 = match iter.next().unwrap().parse() {
		Ok(n) => n,
		_ => panic!(""),
	};
	let b:i32 = match iter.next().unwrap().parse() {
		Ok(n) => n,
		_ => panic!(""),
	};
	let mut ret = 1;
	let mut cnt = 0;
	while ret < b {
		ret = ret - 1 + a;
		cnt = cnt + 1;
	}
	println!("{}", cnt);
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i = 0 ; i < n ; i++) {
    cin >> a[i];
  }
  int alice = 0, bob = 0;
  sort(a, a + n);
  for(int i = n - 1 ; i >= 0 ; i--) {
    if ((n - 1 - i)  % 2 == 0) alice += a[i];
    else bob += a[i];
  }
  int res = alice - bob;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T>
using vec = vector<T>;

#define FOR(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define all(x) (x).begin(),(x).end()

int main(){
  int w,h,n;
  cin >>w >>h >>n;
  vec<int> x(n),y(n),a(n);
  REP(i,n) cin >>x[i] >>y[i] >>a[i];

  int x1=0,x2=w,y3=0,y4=h;
  REP(i,n){
    if(a[i] == 1){
      x1 = max(x1,x[i]);
    }else if(a[i] == 2){
      x2 = min(x2,x[i]);
    }else if(a[i] == 3){
      y3 = max(y3,y[i]);
    }else{
      y4 = min(y4,y[i]);
    }
  }

  int ans;
  if(x2-x1 <= 0 || y4-y3 <= 0){
    ans = 0;
  }else{
    ans = (x2-x1)*(y4-y3);
  }

  cout <<ans <<endl;
}


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

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    for (int i = min(A, B); i >= 1; --i) {
        if (A % i == 0 && B % i == 0) {
            --K;
            if (K == 0) {
                cout << i << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
def swap(s, t, n)
  ret = 0
  n.times do |i|
    if s[i] != t[i]
      k = s[i..-1].index(1 - s[i])
      s.slice!(i + k)
      s.insert(i, t[i])
      ret += k
    end
  end
  @ans << ret
end

def turn(t)
  t.map{|i| 1 - i}
end

n, m = gets.split.map(&:to_i)
s = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

t = []
bit = 0
b.each{ |i| i.times{ t << bit }; bit = 1 - bit }
@ans = []
swap(s.dup, t, n) if s.count(0) == t.count(0)
swap(s, turn(t), n) if s.count(0) == turn(t).count(0)
p @ans.min

Measured memory_bytes: 8712
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstring>
using namespace std;

const int B=999999937;
const int P=1000000007;

vector<long long> gen_hash(const string &s){
	vector<long long> hash(s.size());
	long long c=0;
	for(int i=0;i<s.size();i++){
		c=(c*B+s[i])%P;
		hash[i]=c;
	}
	return hash;
}
long long pow_binary_mod(long long x,long long y,long long mod){
	long long z=1;
	for(;y;y>>=1){
		if((y&1)!=0)z=z*x%mod;
		x=x*x%mod;
	}
	return z;
}

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

	string s;
	cin>>s;
	vector<long long> v=gen_hash(s);

	//int T;
	//for(cin>>T;T--;){
		string q;
		cin>>q;
		long long hash=gen_hash(q)[q.size()-1];
		long long Brev=pow_binary_mod(B,q.size(),P);
		vector<int> r;
		for(int i=q.size()-1;i<s.size();i++){
			long long h=((v[i]-(i==q.size()-1?0:v[i-q.size()])*Brev)%P+P)%P;
			if(h==hash)r.push_back(i-q.size()+1);
		}
		if(!r.empty()){
			for(int i=0;i<r.size();i++)printf("%d\n",r[i]);
			//puts("1");
		}else{
			//puts("0");
		}
	//}
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>s;
    a=(s[0]-'0')*10+(s[1]-'0');
    b=(s[2]-'0')*10+(s[3]-'0');
    if(1<=a&&a<=12&&1<=b&&b<=12)Cout("AMBIGUOUS");
    else if(1<=b&&b<=12)Cout("YYMM");
    else if(1<=a&&a<=12)Cout("MMYY");
    else Cout("NA");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, q;
    cin >> n >> q;
    n *= 2;
    VL a(n), b(n);
    REP(i,n) scanf("%lld", &a[i]);
    REP(i,n) scanf("%lld", &b[i]);

    ll suma = 0;
    REP(i,n) suma += a[i];

    multiset<ll> st;
    ll pos = 0;
    int c = 0;
    FOR(i,1,n-2){
        st.insert(b[i] - a[i]);
        if (b[i] > a[i]){
            pos += b[i] - a[i];
            c++;
        }
    }

    while (q--){
        int i;
        ll x, y;
        scanf("%d %lld %lld", &i, &x, &y);
        i--;
        if (i == 0 || i == n-1){
            suma += x - a[i];
        }else{
            suma += x - a[i];
            ll od = b[i] - a[i];
            ll nw = y - x;
            st.erase(st.find(od));
            st.insert(nw);
            if (od > 0){
                c--;
                pos -= od;
            }
            if (nw > 0){
                c++;
                pos += nw;
            }
        }
        a[i] = x;
        b[i] = y;

        // cout << "suma " << suma << endl;
        // cout << "c " << c << "  sumpos " << pos << endl;
        // for (ll x : st) cout << x << " ";
        // cout << endl;

        ll ans = suma;
        if (c % 2 == 0){
            ans += pos;
        }else{
            ll p, q;
            auto itr = st.upper_bound(0);
            p = *itr;
            itr--;
            q = *itr;
            ans += max(pos - p, pos + q);
        }
        printf("%lld\n", ans);
    }

    return 0;
}


Measured memory_bytes: 14208
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 1000000005
#define MOD 1000000007
#define N 100005
#define M 27000
#define LOG 1000000
#define KOK 650
#define EPS 0.000000001
using namespace std;

int n;
int a[17][17];
ll cost[pw(16)],dp[pw(16)];
int vis[pw(16)];

ll dfs(int mask) {

	if(vis[mask]) return dp[mask];

 	vis[mask]=1;

	for(int msk=mask;msk>0;msk=(msk-1)&mask) {

		umax(dp[mask],dfs(mask^msk)+cost[msk]);

	}

	return dp[mask];

} 

int main() {

	//freopen("input.txt","r",stdin);	
	
	scanf("%d",&n);

	for(int i=0;i<n;i++) {

		for(int j=0;j<n;j++) scanf("%d",&a[i][j]);

	}

	for(int mask=0;mask<pw(n);mask++) {

		vector<int> tut;

		for(int j=0;j<n;j++) {

			if(mask&pw(j)) tut.pb(j);

		}

		ll tot=0;

		for(int j=0;j<sz(tut);j++) {

			for(int k=j;k<sz(tut);k++) {

				tot+=a[tut[j]][tut[k]];

			}

		}

		cost[mask]=tot;

	}

	printf("%lld",dfs(pw(n)-1));

}


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

class Point_class():
    def __init__(self, x, y):
        self.x = x
        self.y = y

import sys

for line in sys.stdin:
    A = map(float, line.split())
    p = []
    for i in range(4):
        p.append(Point_class(A[2*i], A[2*i+1]))
    if abs((p[3].y-p[2].y)*(p[1].y-p[0].y) + (p[3].x-p[2].x)*(p[1].x-p[0].x)) < 1e-10:
        print "YES"
    else:
        print "NO"

Measured memory_bytes: 6320
import Foundation
func toTuple<T>(_ args: [T]) -> (T, T) { (args[0], args[1]) }
func toTuple<T>(_ args: [T]) -> (T, T, T) { (args[0], args[1], args[2]) }
func toTuple<T>(_ args: [T]) -> (T, T, T, T) { (args[0], args[1], args[2], args[3]) }
func readInts() -> [Int] { readLine()!.split(separator: " ").map { Int($0)! } }
func readDoubles() -> [Double] { readLine()!.split(separator: " ").map { Double($0)! } }
func readStrings() -> [String] { readLine()!.split(separator: " ").map { String($0) } }

let (_, k) = toTuple(readInts())
let pi = readInts().sorted()
var ans = 0
for i in 0..<k { ans += pi[i] }
print(ans)

Measured memory_bytes: 13792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n;
    cin>>n;
    vector<tuple<string,ll,ll>>a(n);
    rep(0,i,n){
        string s;
        ll p;
        cin>>s>>p;
        a[i]={s,-p,i};
    }
    sort(a.begin(),a.end());
    rep(0,i,n)cout<<get<2>(a[i])+1<<endl;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n),b(m);
  rep(i,n) cin >> a[i];
  rep(i,m) cin >> b[i];

  ll sum = 0;
  rep(i, m) sum += b[i];
  ll j = m, ans = 0;
  rep(i,n+1){
    while(j>0 && sum>k){
      j--;
      sum -= b[j];
    }
    if (sum > k) break;
    chmax(ans, i + j);
    if (i == n) break;
    sum += a[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6368
N = int(raw_input())
prime_in_N = {}
for n in range(2, N+1):
  while True:
    bn = n
    for p in (2, 3, 5, 7):
      if n % p == 0:
        n /= p
        if not p in list(prime_in_N.keys()):
          prime_in_N[p] = 0
        prime_in_N[p] += 1
    if bn == n:
      break
  if n > 7:
    if not n in list(prime_in_N.keys()):
      prime_in_N[n] = 0
    prime_in_N[n] += 1
ans = 0
for a in list(prime_in_N.keys()):
  if prime_in_N[a] >= 74:
	ans += 1
for a in list(prime_in_N.keys()):
  if prime_in_N[a] >= 2:
    for b in set(prime_in_N.keys())-set([a]):
      if prime_in_N[b] >= 24:
        ans += 1
for a in list(prime_in_N.keys()):
  if prime_in_N[a] >= 4:
    for b in set(prime_in_N.keys())-set([a]):
      if prime_in_N[b] >= 14:
        ans += 1
tmp_ans = 0
for a in list(prime_in_N.keys()):
  if prime_in_N[a] >= 2:
    for b in set(prime_in_N.keys())-set([a]):
      if prime_in_N[b] >= 4:
        for c in set(prime_in_N.keys())-set([a])-set([b]):
      		if prime_in_N[c] >= 4:
        		tmp_ans += 1
print ans+tmp_ans/2

Measured memory_bytes: 2696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
char c[100005];
int main(void){
    string s;
    cin>>s;
    ll k;
    cin>>k;
    ll ans=0;
    ll n=s.size();
    for(int i=0;i<n;i++){
        c[i]=s[i];
    }
    for(int i=0;i<n;i++){
        if(c[i]!='a'&&'z'-c[i]+1<=k){
            k-=('z'-c[i]+1);
            c[i]='a';
        }
        //cout<<c[i]<<" "<<k<<endl;
    }
    //cout<<k<<endl;
    k=k%26;
    if(k>0){
        int t=c[n-1]-'a'+k;
        //cout<<t<<endl;
        if(t>26){
            t-=26;
        }
        c[n-1]=t+'a';
    }
    for(int i=0;i<n;i++){
        cout<<c[i];
    }
    cout<<endl;
    
}


Measured memory_bytes: 3868
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define RG register
#define inf 0x7fffffff
#define mkp make_pair
#define maxn 100205
typedef unsigned int U;
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const  double eps = 1e-8;
const double pi = acos(-1);
inline ll read(){
    ll x = 0, f = 1;
    char ch = getchar();
    while(ch > '9' || ch < '0') {if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x *10 + ch -'0';ch = getchar();}
    return x * f;
}
int n,k;
int fac[4000005],inv[4000005];
int f[2005][2005];
int qpow(int a,int b){
	int ans=1,base=a;
	while(b){
		if(b&1) ans=1ll*ans*base%mod;
		base=1ll*base*base%mod;
		b>>=1;
	}
	return ans;
}
int C(int n,int m){return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;}
int main(){
	int i,j,u,v,e,w;
	//freopen("a.out","r",stdin);
	//freopen("a.ans","w",stdout);n
	n=read(),k=read();
	if(k==1) {puts("1");return 0;}
	fac[0]=1;
	for(i=1;i<=n*k;i++) fac[i]=1ll*fac[i-1]*i%mod;
	inv[n*k]=qpow(fac[n*k],mod-2);
	for(i=n*k-1;i>=0;i--) inv[i]=1ll*inv[i+1]*(i+1)%mod;
	f[0][0]=1;
	for(i=0;i<=n;i++){
		for(j=i;j<=n;j++){
			if(i+1<=j) f[i+1][j]=(f[i+1][j]+f[i][j])%mod;
			if(j+1<=n) f[i][j+1]=(f[i][j+1]+1ll*f[i][j]*C(i+(k-1)*j+k-2,k-2)%mod)%mod;
		}
	}
	printf("%d\n",1ll*f[n][n]*fac[n]%mod);
	return 0;
}
/*
8
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
*/

Measured memory_bytes: 48640
/*  Bismillahir Rahmanir Rahim  */

#include <bits/stdc++.h>

using namespace std;

long long n, A, B, C, D;

int main(){
	cin >> n >> A >> B >> C >> D;
	if(A > B) swap(A, B);
	long long diff = B - A;
	bool flag = false;
	for(long long i = 0; i <= n - 2; ++i){
		long long bl = A + i * C - (n - 2 - i) * C;
		long long aa = i * (D - C);
		long long bb = (n - 2 - i) * (D - C);
		if(bl >= B + C && bl <= B + D) flag = true;
		if(bl <= B + C && bl + aa >= B + C) flag = true;
		if(bl <= B - C && bl >= B - D) flag = true;
		if(bl >= B - C && bl - bb <= B - C) flag = true;
	}
	if(flag) cout << "YES\n";
	else cout << "NO\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <regex>
#include <cmath>

using namespace std;

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

    int ans = 1;

    for(int p = 2; p <= sqrt(x); p++) {
        int b = p;
        while ( b * p <= x ) {
            b *= p;
        }
        ans = max(ans, b);
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;

    cin.ignore();


    if(s[2]==s[3] and s[4]==s[5])
    {
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }



    return 0;

}


Measured memory_bytes: 256
import numpy as np

k, n = map(int, input().split())
a_list = [int(i) for i in input().split()]
a_list += [a_list[0]+k]

a_list = np.array(a_list)

dif = a_list[1:] - a_list[:-1]
dif_max = np.max(dif)

print(k-dif_max)

Measured memory_bytes: 41680
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
 
ll mod = 1e9+7;
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,k;
	cin >> n >> k;
	if (k == 1) cout << 0 << endl;
	else cout << n-k << endl;
	cin >> n;
}

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

typedef long long ll;
typedef string S;
typedef pair<int,int> P;
typedef vector<int> vi;
const int mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    S a,b,c;
    cin >> a >> b >> c;
    int ans=0;
    for(int i=0;i<a.size();i++){
        int tmp=0;
        if(a[i]!=b[i]&&b[i]!=c[i]&&a[i]!=c[i]){
            tmp=2;
        }else if(a[i]==b[i]||b[i]==c[i]||c[i]==a[i]){
            if(a[i]==b[i]&&b[i]==c[i]){
                tmp=0;
            }else{
                tmp=1;
            }
        }
        ans+=tmp;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);

		double a = scan.nextDouble();
		double b = scan.nextDouble();
		//	0<=h<=11
		double h = scan.nextDouble();
		//	0<=m<=59
		double m = scan.nextDouble();

		double zishinKakudo = (Math.PI * h / 6.0) + (Math.PI * m / 6.0 / 60.0);
		double hunshinKakudo = Math.PI * 2.0 * m / 60.0;

		double diffOfKakudo = Math.abs(zishinKakudo - hunshinKakudo);

//		if (diffOfKakudo > Math.PI) {
//			diffOfKakudo = diffOfKakudo - Math.PI;
//		}

		double L = Math.pow(a, 2) + Math.pow(b, 2) - (2.0 * a * b * Math.cos(diffOfKakudo));
		double l = Math.sqrt(L);
		System.out.println(l);

	}

}


Measured memory_bytes: 37336
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;
const ll mod = 1000000007;



int main() {
ll N,T;
  in(N>>T);
  ll ans =1001;
  rep(i,N){
    ll c,t;
    in(c>>t);
    if(t <= T) ans = min(ans,c);
  }
  if(ans ==1001)  out("TLE");
  else out(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,L,R;
  int Lmax = 0;
  int Rmin = 1000000;
  cin >> N >> M;
  for(int i=0;i<M;i++){
    cin >> L >> R;
    if(L>=Lmax){
      Lmax = L;
    }
    if(R<=Rmin){
      Rmin = R;
    }
  }
  if(Rmin >= Lmax){
      cout << Rmin-Lmax+1 << endl;
  }
  else{
    cout << "0" << endl;
  }
  return 0;
}

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


void solve(long long N, long long M, std::vector<long long> s, std::vector<long long> c){
    vector<ll> ans(N, -1);
    REP(i, M){
        const ll si = s.at(i) - 1;
        const ll ci = c.at(i);
        if(ans.at(si) != -1 && ans.at(si) != ci){
            cout << -1 << endl;
            return;
        }
        ans.at(si) = ci;
    }

    REP(i, N){
        if(ans.at(i) != -1){
            continue;
        }
        if(i == 0 && N > 1){
            ans.at(i) = 1;
        }else{
            ans.at(i) = 0;
        }
    }

    if(N > 1 && ans.at(0) == 0){
        cout << -1 << endl;
        return;
    }

    REP(i, N){
        cout << ans.at(i);
    }
    cout << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> s(M);
    std::vector<long long> c(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&s[i]);
        scanf("%lld",&c[i]);
    }
    solve(N, M, std::move(s), std::move(c));
    return 0;
}


Measured memory_bytes: 256
"""
    Template written to be used by Python Programmers.
    Use at your own risk!!!!
    Owned by enraged(rating - 5 star at CodeChef and Specialist at Codeforces).
"""
import sys
from functools import lru_cache
from collections import defaultdict as dd
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(str(var))
def outln(var): sys.stdout.write(str(var)+"\n")
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]


n, x, y = sp()
dp = dd(int)
for i in range(1, n):
    for j in range(i+1, n+1):
        answer = min(abs(j-i), abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(j-x))
        dp[answer] += 1
for i in range(1, n):
    outln(dp[i])

Measured memory_bytes: 48092
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
#include<numeric>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main()
{
  int n, x, t;
  cin >> n >> x >> t;
  int a = n /x;
  int b = n % x;

  if (b != 0) a++;

  cout << a * t << endl;
}



Measured memory_bytes: 3628
import java.io._
import scala.io.StdIn.{readInt, readLine}

object Main {
  val tree0 = new Array[Int](500001)
  val tree1 = new Array[Int](500001)
  val tree2 = new Array[Int](500001)
  val out:BufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512)
  var count = 0

  def insert(i:Int, j:Int):Unit =
    if(tree0(i) > tree0(j)) {
      if(tree1(i) == -1) tree1(i) = j
      else insert(tree1(i), j)
    } else {
      if(tree2(i) == -1) tree2(i) = j
      else insert(tree2(i), j)
    }

  def inOrder():Unit = {
    var stack:List[Int] = Nil
    var curr = 0
    var flg = true

    while(flg) {
      while(curr != -1) {
        stack = curr::stack
        curr = tree1(curr)
      }
      if(curr == -1 && stack != Nil) {
        val item = stack.head
        stack = stack.tail
        out.write(" ")
        out.write(tree0(item).toString)
        if(count<1000) count += 1
        else {
          out.flush
          count = 0
        }
        curr = tree2(item)
      } else {
        flg = false
      }
    }
  }

  def scan(list:List[Int]):Unit = {
    list match {
      case Nil => ()
      case hd::tl => {
        out.write(" ")
        out.write(tree0(hd).toString)
        if(count<1000) count += 1
        else {
          out.flush
          count = 0
        }
        val hd2 =
          if(tree2(hd) != -1 && tree1(hd) != -1) tree1(hd)::tree2(hd)::tl
          else if(tree2(hd) != -1 && tree1(hd) == -1) tree2(hd)::tl
          else if(tree2(hd) == -1 && tree1(hd) != -1) tree1(hd)::tl
          else tl
        scan(hd2)
      }
    }
  }

  def preOrder(i:Int):Unit =
    if(i == -1) return
    else scan(i::Nil)

  def main(args:Array[String]) = {
    val n = readInt
    var j = 0

    for(i<-0 until n) {
      val s = readLine.split(" ")
      s(0) match {
        case "insert" => {
          tree0(j) = s(1).toInt
          tree1(j) = -1
          tree2(j) = -1
          if(j!=0) insert(0, j)
          j+=1
        }
        case _ => {
          inOrder()
          out.write("\n")
          out.flush()
          preOrder(0)
          out.write("\n")
          out.flush()
        }
      }
    }
  }
}

Measured memory_bytes: 309260
#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;
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:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2382>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

struct UnionFind {
    vector<int> data;
    UnionFind(ll size) : data(size, -1) { }
    bool unionSet(int x, int 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(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

ll solve(){
    ll res = LINF;
    ll N,W,H; cin >> N >> W >> H;
    vector<ll> x(N),y(N);
    bool f = false;
    for(int i = 0; i < N;i++){
        cin >> x[i] >> y[i];
        f |= (x[i]==1|x[i]==W|y[i]==1|y[i]==H);
    }
    
    vector<vector<pll>> wG(W+2),hG(H+2);
    for(int i = 0; i < N;i++){
        wG[x[i]].push_back({y[i],i});
        hG[y[i]].push_back({x[i],i});
    }
    
    UnionFind uf(N);
    for(int i = 0; i < W+2;i++){
        if(wG[i].size() < 2) continue;
        for(int j = 0; j < wG[i].size()-1;j++){
            int idx1 = wG[i][j].second, idx2 = wG[i][j+1].second;
            uf.unionSet(idx1, idx2);
        }
    }
    for(int i = 0; i < H+2;i++){
        if(hG[i].size() < 2) continue;
        for(int j = 0; j < hG[i].size()-1;j++){
            int idx1 = hG[i][j].second, idx2 = hG[i][j+1].second;
            uf.unionSet(idx1, idx2);
        }
    }
    set<int> s;
    for(int i = 0; i < N;i++) s.insert(uf.root(i));
    if(s.size() == 1){
        res = N-1;
    }else{
        res = N-1+s.size()-f;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}



Measured memory_bytes: 11824
#include <stdio.h>

int N, X;
int L[128];

int main(void) {
	int i;
	int asumikana = 0;
	int igutiyuka = 0;
	if (scanf("%d%d", &N, &X) != 2) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &L[i]) != 1) return 1;
	}
	if (asumikana <= X) igutiyuka++;
	for (i = 0; i < N; i++) {
		asumikana += L[i];
		if (asumikana <= X) igutiyuka++;
	}
	printf("%d\n", igutiyuka);
	return 0;
}


Measured memory_bytes: 128
import scala.io.StdIn

object Main{
    def main(args: Array[String]) = {
        val n = StdIn.readInt
        val array = StdIn.readLine.split(" ").map(_.toInt)
        val (arr, count) = bubblesort(n, array)
        println(arr.mkString(" "))
        println(count)
    }
    
    def bubblesort(n: Int, array: Array[Int]) = {
        var count = 0
        for(i <- 0 to n-1){
            for(k <- n-1 to i+1 by -1){
                if(array(k) < array(k-1)){
                    var tmp = array(k-1)
                    array(k-1) = array(k)
                    array(k) = tmp
                    count = count + 1
                }
            }
        }
        (array, count)
    }
}


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

typedef long long ll;
#define rep(i, a, b) for(int i =a; i<=b; i++)

ll mod = 1000000007;

int n;
string s;
ll dp[5050][5050];


ll mp(ll x, ll y ){

if(y==0)return 1%mod;
ll u = mp(x, y/2);
u = (u*u)%mod;
if(y%2==1)u = u*x%mod;
return u;
}


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

int k = s.size();

dp[0][0]=1;

rep(i, 0, n){

rep(j, 0, i){

    dp[i+1][j+1] =  (dp[i+1][j+1] + dp[i][j]*2%mod)%mod;

    if(j>0){
    dp[i+1][j-1] =  (dp[i][j] + dp[i+1][j-1])%mod;
    }
   // dp[i+1][j-1] = (dp[i][j] + dp[i+1][j-1] )%mod;
    else {
        dp[i+1][0] = (dp[i][0] + dp[i+1][0])%mod;
    }


}


}

cout << dp[n][k]*mp( mp(2, k), mod-2)%mod << endl;

return 0;}


Measured memory_bytes: 197120
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  sort(p.begin(), p.end());
  int ans = 0;
  rep(i, k) {
    ans += p[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;
 
public class Main {    
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int[] a = new int[5];
        a[0] = sc.nextInt();
        a[1] = sc.nextInt();
        a[2] = sc.nextInt();
        a[3] = sc.nextInt();
        a[4] = sc.nextInt();
        for(int i=0;i<5;i++){
            if(a[i]==0){
                System.out.println(i+1);
                return;
            }
        }        
        sc.close();
    }

}

Measured memory_bytes: 35836
import java.util.*;

public class Main {


    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int time_1 = 4000;
        int time_2 = 100;

        int D = sc.nextInt();
        int[] c = new int[27];
        int[] t = new int[D + 1];
        int[] last_day = new int[27];
        Arrays.fill(last_day, 0);
        int[][] s = new int[D + 1][27];
        for (int i = 1; i <= 26; i++) {
            c[i] = sc.nextInt();
        }
        for (int i = 1; i <= D; i++) {
            for (int j = 1; j <= 26; j++) {
                s[i][j] = sc.nextInt();
            }
        }

        for (int i = 1; i <= D; i++) {
            Random random = new Random();
            t[i] = 1 + random.nextInt(26);
        }
        int[] last_array = t;

        long last_sum = 0;
        for (int j = 0; j < time_1; j++) {
            long tmp_sum = 0;
            for (int k = 0; k < time_2; k++) {
                Random random = new Random();
                int d = 1 + random.nextInt(D);
                int q = 1 + random.nextInt(D);
                int tmp = t[d];
                t[d] = t[q];
                t[q] = tmp;
            }
            for (int i = 1; i <= D; i++) {
                last_day[t[i]] = i;
                tmp_sum += calcS(c, s, t[i], i, last_day);
            }
            if (tmp_sum > last_sum) {
                last_array = t;
                last_sum = tmp_sum;
            } else {
                t = last_array;
            }
        }


        for (int i = 1; i <= D; i++) {
            System.out.println(t[i]);
        }

    }

    private static long calcS(int[] c, int[][] s, int kaisai, int day, int[] last_day) {

        long loss = 0;
        for (int i = 1; i <= 26; i++) {
            if (i == kaisai) {
                last_day[i] = day;
                continue;
            }
            loss -= c[i] * (day - last_day[i]);
        }

        long plus = s[day][kaisai];
        return plus + loss;
    }

}


Measured memory_bytes: 46328