akhauriyash/Code-Regression huggingface dataset:
program main
  implicit none
  integer i,N,ans
  integer,allocatable :: p(:)
  integer,allocatable :: q(:)
  read(*, *) N
  allocate(p(N))
  allocate(q(N))
  read(*, *) (p(i), i = 1,N)
  do i = 1,N
    q(i) = p(i)
  end do
  call qsort(q)
  ans = 0
  do i = 1,N
    if (p(i) /= q(i)) then
      ans = ans + 1
    end if
  end do
  if (ans < 3) then
    write(*, *) 'YES'
  else
    write(*, *) 'NO'
  end if
  
contains

recursive subroutine qsort(a)
implicit none
!integer(8),intent(in) :: n
integer,intent(inout) :: a(:)
integer::i,j,toobig,toosmall,pv,n
n = size(a)
i = 1
j = n
pv = a((i+j)/2)
do
   do
     if (a(i) < pv) then
       i = i+1
     else
       exit
     end if
   end do
   do
     if(a(j) > pv) then
       j = j-1
     else
       exit
     end if
   end do
   if (i>=j) then
     exit
   else
     toobig = a(j)
     toosmall = a(i)
     a(i) = toobig
     a(j) = toosmall
     i = i+1
     j = j-1
   end if
 end do
 if (i > 2) then
   call qsort(a(1:i-1))
 end if
 if (j < n-1) then
   call qsort(a(j+1:n))
 end if
end subroutine qsort
end program main


Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def SS(): return map(str,sys.stdin.readline().rstrip().split())
def II(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N,x = II()
a = LI()
a.sort()
cnt = 0
for ai in a:
  if x > ai:
    x -= ai
    cnt += 1
  elif x == ai:
    cnt += 1
    x -= ai
    break
  else:
    cnt += 1
    break
if x != 0:
  cnt -= 1
print(cnt)

Measured memory_bytes: 12756
dx, dy = [-1, 0, 1, 0], [0, -1, 0, 1]
while True:
    ans = 0
    try:
        m = ['0'*14] + ['0'+raw_input()+'0' for i in xrange(12)] + ['0'*14]
        f = [[False for i in xrange(14)] for j in xrange(14)]
        for y in xrange(1, 13):
            for x in xrange(1, 13):
                if m[y][x]=='1' and f[y][x]==False:
                    q = [[x, y]]
                    f[y][x] = True
                    while len(q)>0:
                        px, py = q.pop(0)
                        for k in xrange(4):
                            nx = px + dx[k]; ny = py + dy[k];
                            if m[ny][nx]=='1' and f[ny][nx]==False:
                                f[ny][nx] = True
                                q.append([nx, ny])
                    ans += 1
        print ans
        raw_input()
    except EOFError:
        break

Measured memory_bytes: 4280
#include <iostream>

#define MAX_NUM 100

using namespace std;

int main(void){
  int r, c;
  int table[MAX_NUM + 1][MAX_NUM + 1], sum, low_total[MAX_NUM];
  
  for(int i = 0; i < MAX_NUM + 1; i++){
    for(int j = 0; j < MAX_NUM + 1; j++){
      table[i][j] = 0;
    }
  }

  cin >> r >> c;

  for(int i = 0; i < r; i++){
    for(int j = 0; j < c; j++){
      cin >> table[i][j];
      table[r][j] += table[i][j];
      table[i][c] += table[i][j];
    }
  }

 
  sum = 0;
  for(int i = 0; i < r + 1 ; i++){
    for(int j = 0; j < c; j++){
      cout << table[i][j] << " ";
      if(i == r){
	table[r][c] += table[i][j];
      }
    }
    cout << table[i][c] << endl;
  }

  return 0;
}

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

#define ll long long

ll n,l,r;
ll tot;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>l>>r;
		tot+=r-l+1;
	}
	cout<<tot<<endl;
	return 0;	
}

Measured memory_bytes: 256
/*
        Author: Prokash
                CSE48, JU

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int main()
{
    FAST;
    ll n;
    cin>>n;
    ll ara[2][n+2];
    for(int i=0; i<2; i++)
    {
        for(int j=0; j<n; j++)
        {
            cin>>ara[i][j];
        }
    }
    int ans=-10;
    for(int i=0; i<n; i++)
    {
        int sum = 0;
        for(int j=0; j<=i; j++)
            sum += ara[0][j];
        for(int j=i; j<n; j++)
            sum += ara[1][j];
        ans  = max(ans, sum);
    }
    cout<<ans<<endl;
    return  0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    char c[3];
    {
        scanf("%s",c);
        if(c[0]=='R' && c[1]=='R' && c[2]=='R')
        {
            printf("3\n");
        }
        if(c[0]=='R' && c[1]=='R' && c[2]=='S')
        {
            printf("2\n");
        }
        if(c[0]=='S' && c[1]=='R' && c[2]=='R')
        {
            printf("2\n");
        }
        if(c[0]=='R' && c[1]=='S' && c[2]=='R')
        {
            printf("1\n");
        }
        if(c[0]=='S' && c[1]=='R' && c[2]=='S')
        {
            printf("1\n");
        }
        if(c[0]=='S' && c[1]=='S' && c[2]=='S')
        {
            printf("0\n");
        }
        if(c[0]=='R' && c[1]=='S' && c[2]=='S')
        {
            printf("1\n");
        }
        if(c[0]=='S' && c[1]=='S' && c[2]=='R')
        {
            printf("1\n");
        }
    }
    return 0;
}

Measured memory_bytes: 1644
#include <bits/stdc++.h>
using namespace std;
#define loop(i,a,n) for (ll i=a;i<n;i++)
#define loopm(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define Graph(n) vector < vector < ll > > (n,vector < ll >(0,0))
#define tr(container,it)\
for(auto it=container.begin();it!=container.end();it++)
#define SZ(x) ((int)(x).size())
typedef vector<long long> VI;
typedef long long ll;
typedef vector < vector < ll > > VII;
typedef pair<ll,ll> PII;
typedef double db;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll ans=0;
    ll x;
    cin>>x;
    ll amt=100;
    while(amt<x)
    {
        amt=amt+(amt*1)/100;
        ans++;
    }
    cout<<ans<<"\n";
}


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

using namespace std;

typedef long long ll;

int main(){
	int n;
	cin >> n;
	int h[n];
	for(int i = 0; i < n; i++)cin >> h[i];
	ll ans = 0;
	while(1){
		bool ch = true;
		bool pre = true;
		for(int i = 0; i < n; i++){
			if(h[i]){
				if(pre)ans++, pre = false;
				h[i]--;
				ch = false;
			}
			else{
				pre = true;
			}
		}
		if(ch)break;
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void checkStone(String S, int first, int last) {
		for (int i = first; i < last - 2; i++) {
			// System.out.println(S.charAt(i));
			if ('#' == S.charAt(i) && '#' == S.charAt(i + 1)) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
		return;
	}

	public static void checkAvoid(String S, int first, int last, int anotherStart, int anotherTarget) {
		Boolean clear = false;
		for (int i = first; i < last - 2; i++) {
			//System.out.println(S.charAt(i));
			if ('#' == S.charAt(i) && '#' == S.charAt(i + 1)) {
				System.out.println("No");
				return;
			}
			if (clear == false && '.' == S.charAt(i) && '.' == S.charAt(i + 1) && '.' == S.charAt(i + 2)) {
				if (i + 1 <= anotherTarget - 1 && i + 1 >= anotherStart - 1)
					clear = true;
			}
		}
		if (clear == true) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		return;
	}
	// 13 1 2 11 13
	// ..#.#..#.#...

	// 4 1 2 4 3
	// ....
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.nextInt(); // N
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		String S = sc.next();
		sc.close();

		// 岩が最初から2個連なっている場合（そもそも到達不能）でなければ、
		// CDのうち奥の方（大きい方）に到達できた時点でクリア可能（小さい方はその道を辿れる）
		// ＝CDのうち奥の方に対応するAかBが到達可能か。
		// ＝例えばCが奥としてAからみてBが邪魔にならないか。（AがBより左ならそもそも邪魔にならない）
		// ＝Bを動かして石2連続にならない位置に移動できるか。（できればクリア可能）
		// まとめて確認できる部分はあるか？

		if (C > D) {
			checkAvoid(S, A, C, B, D);
			return;
		} else {
			checkStone(S, A, D);
			return;
		}
	}
}

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

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int n,m,p,a,b;
int t[8];
int d[32][32];

double dp[1<<8][32];

int main(){

  while(scanf("%d%d%d%d%d", &n,&m,&p,&a,&b) && n||m||p||a||b){
    a--; b--;
  memset(d,-1,sizeof(d));
  rep(i,n) scanf("%d",&t[i]);
  rep(i,p){
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z); x--;y--;
    d[x][y] = d[y][x] = z;
  }

  rep(i,(1<<n)) fill(dp[i], dp[i]+m, INF);
  dp[(1<<n)-1][a] = 0;
  double res = INF;
  for(int S=(1<<n)-1;S>=0;S--){
    res = min(res, dp[S][b]);
    //    cout << res << endl;    
    rep(v,m) rep(i,n){
      if(S>>i&1){
	rep(u,m){
	  if(d[v][u] >= 0){
	    dp[S&~(1<<i)][u] = min(dp[S&~(1<<i)][u], dp[S][v]+(double)d[v][u]/t[i]);
	  }
	}
      }
    }
  }
  if(res == INF){
    puts("Impossible");    
  }else{
    printf("%.12lf\n", res);
  }
  }
  return 0;
}

Measured memory_bytes: 1296
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <cmath>
using namespace std;

typedef long long ll;
const ll inf = 1e15;

int main() {
    ll n; cin >> n;
    vector<double> x(n+1),y(n+1);
    for (int i = 1 ; i <= n ; i++) {
        cin >> x[i] >> y[i];
    }
    vector<int> v(n);
    for (int i = 0; i < n; i++) v[i] = i + 1;
    double ans = 0;
    do {
        for (int i = 0; i < n - 1; i++){
            double dx = x[v[i]] - x[v[i+1]];
            double dy = y[v[i]] - y[v[i+1]];
            ans += pow(dx * dx + dy * dy, 0.5);
        } 
    } while (next_permutation(v.begin(), v.end()));
    int Factorial = 1;
    for (int i = 2; i <= n; i++) Factorial *= i;
    cout << fixed << setprecision(8) << ans / Factorial << "\n";

}

Measured memory_bytes: 256
#include <cstdio>
#include <string.h>

using namespace std;

char S[1005];
int len, num[4];

int main() {
    scanf("%s", S);
    len = strlen(S);
    for (int i = 0; i < len; i++) {
        if (S[i] == 'N') num[0]++;
        if (S[i] == 'S') num[1]++;
        if (S[i] == 'E') num[2]++;
        if (S[i] == 'W') num[3]++;
    }
    if (num[0] == 0 && num[1]) puts("No");
    else if (num[0] && num[1] == 0) puts("No");
    else if (num[2] == 0 && num[3]) puts("No");
    else if (num[2] && num[3] == 0) puts("No");
    else puts("Yes");
    return 0;
}

Measured memory_bytes: 128
# frozen_string_literal: true

n = gets.to_i
h = gets.split.map(&:to_i)

1.upto(n - 1) do |i|
  if h[i] < h[i - 1] - 1
    puts 'No'
    exit
  elsif h[i] < h[i - 1]
    h[i] += 1
  end
end
puts 'Yes'


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

typedef complex<long double> point;
typedef pair<point,point> line;
point polar(const long double &r, const long double &th) { return point(r*cosl(th),r*sinl(th)); }
bool equal(const long double x1,const long double x2){ return abs(x1-x2)<eps; }
bool equal(const point& a,const point& b){ return equal(a.real(),b.real()) and equal(a.imag(),b.imag()); }
long double length(const point& a){ return abs(a); }
long double distance(const point& a,const point& b){ return abs(a-b); }
long double dot(const point& a,const point& b){ return a.real()*b.real()+a.imag()*b.imag(); }
long double cross(const point& a,const point& b){ return a.real()*b.imag()-a.imag()*b.real(); }
int ccw(point a,point b,point c) {
    b-=a; c-=a;
    if(cross(b, c) > 0)   return +1;       // counter clockwise
    if(cross(b, c) < 0)   return -1;       // clockwise
    if(dot(b, c) < 0)     return +2;       // c--a--b on line
    if(norm(b) < norm(c)) return -2;       // a--b--c on line
    return 0;
}
bool intersectSS(const line& s, const line& t){
    return ccw(s.first,s.second,t.first)*ccw(s.first,s.second,t.second) <= 0 &&
           ccw(t.first,t.second,s.first)*ccw(t.first,t.second,s.second) <= 0;
}

long double sub(int na,int nb,vector<long double> &xa,vector<long double> &ya,vector<long double> &xb,vector<long double> &yb){
    vector<long double> dist(nb,inf);
    vector<bool> done(nb);
    dist[0]=0;
    for(;;){
        int u=-1;
        rep(v,0,nb){
            if(!done[v] and (u==-1 or dist[u]>dist[v])) u=v;
        }
        if(u==-1) break;
        done[u]=true;
        rep(v,0,nb){
            if(intersectSS(line(point(xa[0],ya[0]),point(xa[1],ya[1])),line(point(xb[u],yb[u]),point(xb[v],yb[v])))) continue;
            long double d=dist[u]+abs(point(xb[u]-xb[v],yb[u]-yb[v]));
            if(d<dist[v]) dist[v]=d;
        }
    }
    return abs(point(xa[0]-xa[1],ya[0]-ya[1]))+dist[1];
}

void solve(){
    int na,nb;
    cin >> na >> nb;
    vector<long double> xa(na),ya(na),xb(nb),yb(nb);
    rep(i,0,na) cin >> xa[i] >> ya[i];
    rep(i,0,nb) cin >> xb[i] >> yb[i];
    long double ans=min(sub(na,nb,xa,ya,xb,yb),sub(nb,na,xb,yb,xa,ya));
    if(ans<inf) cout << ans << endl;
    else cout << -1 << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

Measured memory_bytes: 3412
n=gets.to_i
cnt=Hash.new(0)
e = {}
(n-1).times do
  a,b=gets.chomp.split.map(&:to_i)
  cnt[a]+=1
  cnt[b]+=1
  e[a] = [] if !(e.has_key?(a))
  e[b] = [] if !(e.has_key?(b))
  e[a] << b
  e[b] << a
end
c=gets.chomp.split.map(&:to_i)
c.sort!

list = []
cnt.keys.each do |k|
  list << k if cnt[k] == 1
end

ans = Array.new(n)

n.times do |i|
  k = list.shift
  ans[k-1] = c[i]

  e[k].each do |l|
    cnt[l] -= 1
    list << l if cnt[l] == 1
  end
end

puts c.inject(:+) - c[-1]

puts ans.join(" ")


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

int main(){
  int N;
  cin >> N;
  vector<ll> x(N),y(N);
  REP(i,N) {
    cin >> x[i] >> y[i];
  }
  ll xymax[4] = {-2000000005,-2000000005,-2000000005,-2000000005};
  ll xymin[4] = {2000000005,2000000005,2000000005,2000000005};
  REP(i,N) {
    xymax[0] = max( xymax[0], x[i] + y[i] );
    xymin[0] = min( xymin[0], x[i] + y[i] );
    xymax[1] = max( xymax[1], x[i] - y[i] );
    xymin[1] = min( xymin[1], x[i] - y[i] );
    xymax[2] = max( xymax[2], - x[i] + y[i] );
    xymin[2] = min( xymin[2], - x[i] + y[i] );
    xymax[3] = max( xymax[3], - x[i] - y[i] );
    xymin[3] = min( xymin[3], - x[i] - y[i] );
  }
  ll ans = 0;
  REP(i,4) {
    ans = max( ans, xymax[i] - xymin[i] );
  }
  cout << ans << endl;

}


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

using namespace std;

bitset <5000000> bs;

int main()
{
    int n;
    cin >> n;
    vector <int> arr(n);
    int sum=0;
    bs[0]=1;
    for(int i=0;i<n;i++)
    {
        cin >> arr[i];
        bs|=bs<<arr[i];
        sum+=arr[i];
    }
    for(int i=(sum+1)>>1;;i++)
    {
        if(bs[i])
        {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 2176
n,a,b = map(int,input().split())

def modComb(n,r,mod):
    tmp = 1
    r = min(r,n-r)
    for i in range(1,r+1):
        tmp = tmp * (n-i+1) % mod
        tmp = tmp * pow(i,mod-2,mod)
    
    return tmp % mod


mod = 10**9+7
ans = pow(2,n,mod) - 1

print((ans-modComb(n,a,mod)-modComb(n,b,mod)) % mod)



Measured memory_bytes: 40172
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int K = sc.nextInt();
		int buf = Math.min(A,B);
		int count = 0;
		int ans = 0;
		for(int i = 0;i < buf;i++){
			if(A % (buf - i) == 0 && B % (buf - i) == 0){
				count++;
			}
			if(count == K){
				ans = buf - i;
				break;
			}
		}
		System.out.println(ans);
	}
}

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

using namespace std;

const long long int MAX_N = 100000;

int main(int argc, char const *argv[]) {
  long long int n;
  vector<long long int> a(MAX_N,0), b(MAX_N,0), c(MAX_N,0);
  cin >> n;
  a.resize(n);
  b.resize(n);
  c.resize(n);
  for (size_t i = 0; i < n; i++) cin >> a[i];
  for (size_t i = 0; i < n; i++) cin >> b[i];
  for (size_t i = 0; i < n; i++) cin >> c[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  long long int ans = 0;
  for (size_t i = 0; i < n; i++) {
    vector<long long int>::iterator lba = lower_bound(a.begin(), a.end(), b[i]), lbc = upper_bound(c.begin(), c.end(),b[i]);
    ans += (lba-a.begin())*(n - (lbc-c.begin()));
  }

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


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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer a;
  a = nil->next;
  while(a != nil && a->key != key){
    a = a->next;
  }
  return a;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if ( t == nil ) return;
  deleteNode(t);
}

void delete(int key){
  NodePointer k;
  k=listSearch(key);
  if(k == nil) return;
  
  deleteNode(k);
  
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
  
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }
  
  printList();
  return 0;
}

Measured memory_bytes: 31788
import scala.io.StdIn._
import scala.annotation.tailrec
import scala.collection._

object Main {

  def sieve(top: Int): Iterator[Int] = {
    val topId = (top - 3) / 2 + 1
    val (cmpsts, sqrtLmtNdx) = (new Array[Int]((topId >>> 5) + 1), (Math.sqrt(top).toInt - 3) / 2)

    def isCmpst(ci: Int): Boolean = (cmpsts(ci >>> 5) & (1 << (ci & 31))) != 0
    def setCmpst(ci: Int): Unit = cmpsts(ci >>> 5) |= 1 << (ci & 31)

    @tailrec
    def get(cndId: Int): Unit = {
      if(cndId <= sqrtLmtNdx){
        if(!isCmpst(cndId)){
          val p = 2 * cndId + 3

          @tailrec
          def cull(cmpstId: Int): Unit =
            if(cmpstId <= topId){
              setCmpst(cmpstId)
              cull(cmpstId + p)
            }

          cull((p * p - 3) >>> 1)
        }
        get(cndId + 1)
      }
    }

    get(0)

    @tailrec def next(cndId: Int): Int =
      if ((cndId > topId) || !isCmpst(cndId)) 2 * cndId + 3
      else next(cndId + 1)

    Iterator.single(2) ++ Iterator.iterate(3)(p => next((p - 1) >>> 1)).takeWhile(_ <= top)
  }

  @tailrec
  def loop(s: String){
    if(s != null){
       val Array(n,_*) = s.split(" ").map(_.toInt)
       if(n<2) println(0)
       else println(sieve(n).size)
       loop(readLine)
    }
  }

  def main(args: Array[String]): Unit = loop(readLine)
}

Measured memory_bytes: 65400
import sys
from math import factorial
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
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()))
MOD = 10**9 + 7

n, a, b = MAP()

if (a-b)%2 == 0:
    print((b-a)//2)
else:
    k = min(n-b, a-1)
    print((b-a-1)//2 + k+1)

Measured memory_bytes: 66028
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	var N, M int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &N)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &M)

	nums := make(map[int]struct{})
	tmp_as := make([]int, M)
	for i := 0; i < M; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &tmp_as[i])
		nums[tmp_as[i]] = struct{}{}
	}
	sort.Sort(sort.IntSlice(tmp_as))

	as := make([]int, 0)
	for _, a := range tmp_as {
		if a == 2 || a == 3 {
			if _, e := nums[5]; e {
				continue
			}
		}
		if a == 6 {
			if _, e := nums[9]; e {
				continue
			}
		}
		as = append(as, a)
	}

	costs := make(map[int]int)
	costs[1] = 2
	costs[2] = 5
	costs[3] = 5
	costs[4] = 4
	costs[5] = 5
	costs[6] = 6
	costs[7] = 3
	costs[8] = 7
	costs[9] = 6

	dp := make([][]int, len(as)+1)
	usedCnt := make([][]int, len(as)+1)
	for i := 0; i < len(dp); i++ {
		dp[i] = make([]int, N+1)
		usedCnt[i] = make([]int, N+1)
	}
	//fmt.Println("as=", as)

	dp[0][0] = 0
	for n := 1; n <= N; n++ {
		dp[0][n] = math.MinInt64
	}
	//	counts := make([]int, len(as))
	for i := 1; i <= len(as); i++ {
		cost := costs[as[i-1]]
		for n := 1; n <= N; n++ {
			cst := 0
			count := 0
			m := math.MinInt64
			for cst <= n {
				if m <= dp[i-1][n-cst]+count {
					m = dp[i-1][n-cst] + count
					usedCnt[i][n] = count
				}
				count++
				cst = count * cost
			}
			//			fmt.Println(i, n, ", use:", as[i-1], ", count=", mcount)
			dp[i][n] = m
		}
	}

	result := make([]int, 0)
	index := N
	for i := len(as); i > 0; i-- {
		cnt := usedCnt[i][index]
		index = index - cnt*costs[as[i-1]]
		//		fmt.Println(cnt)
		for n := 0; n < cnt; n++ {
			result = append(result, as[i-1])
		}
	}
	sort.Sort(sort.Reverse(sort.IntSlice(result)))
	//fmt.Println(result)

	for _, d := range result {
		fmt.Print(d)
	}
	fmt.Println()

	// for debug
	/*
		fmt.Println("----")
		for i := 1; i <= len(as); i++ {
			for n := 1; n <= N; n++ {
				fmt.Print(dp[i][n], ", ")
			}
			fmt.Println()
		}

		fmt.Println("----used-----")
		for i := 1; i <= len(as); i++ {
			for n := 1; n <= N; n++ {
				fmt.Print(usedCnt[i][n], ", ")
			}
			fmt.Println()
		}
	*/
}

func max(ns ...int) int {
	ret := math.MinInt64
	for _, n := range ns {
		if n > ret {
			ret = n
		}
	}
	return ret
}


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

int main(){
	int n;
	cin >> n;
	int cnt = 0;
	while(true){
		cnt++;
		if(n <= 3) break;
		if(n%3 == 0) n /= 3;
		else n = n/3+1;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<ll>a(n);
    REP(i,n)cin>>a[i];
    sort(a.rbegin(),a.rend());
    ll length=0,height=0;
    REP(i,n-1){
        if(length&&height) break;
        if(a[i]==a[i+1]){
            if(length) height=a[i];
            else length = a[i];
            i++;
        }
    }
    (length&&height)? cout<<length*height : cout<<0;
    cout<<endl;
}

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

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> a(N);
	for(int i = 0; i < N; i++){
		cin >> A[i];
		a.at(i) = A.at(i);
	}
	sort(a.begin(), a.end());
	int X = a.at(N - 1);
	int Y = a.at(N - 2);
	for(int i = 0; i  < N; i++){
		if(A.at(i) != X) cout << X << endl;
		else cout << Y << endl;
	}
}

Measured memory_bytes: 3200
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, K = map(int, input().split())
    d = defaultdict(int)
    for _ in range(N):
        a, b = map(int, input().split())
        d[a] += b

    total = 0
    for k, v in sorted(d.items()):
        total += v
        if K <= total:
            print(k)
            return


if __name__ == '__main__':
    main()


Measured memory_bytes: 15324
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <queue>

int main() {
	int N;
	std::cin>>N;
	int M;
	std::cin>>M;
	std::vector<int> G[N+1];
	std::vector<int> in(N+1);
	std::vector<int> dp(N+1);
	for (int i = 0; i <= N; ++i) {
		in[i] = 0;
	}
	// load graph
	for (int i = 0; i < M; ++i) {
		int a, b;
		std::cin>>a;
		std::cin>>b;
		G[a].push_back(b);
		in[b] += 1;
	}
	int ans = 0;
	std::queue<int> q;
	for (int i = 1; i <= N; ++i) {
		if (!in[i]) {
			q.push(i);
		}
	}
	if (q.empty()) {
		printf("%d\n", ans);
		return 0;
	}
	while (!q.empty()) {
		int now = q.front();
		q.pop();
		for (int i = 0; i < G[now].size(); ++i) {
			int to = G[now][i];
			in[to]--;
			if (!in[to]) {
				dp[to] = dp[now] + 1;
				q.push(to);
			}
		}
	}
	for (int i = 1; i <= N; ++i) {
		ans = std::max(ans, dp[i]);
	}
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 6528
N = int(input())
A = [int(x) for x in input().split()]
D = [0]*5
for a in A:
    if a % 4 == 0:
        D[4] += 1
    elif a % 2 == 0:
        D[2] += 1
    else:
        D[1] += 1

if D[2] > 0:
    if D[4] >= D[1]:
        print("Yes")
    else:
        print("No")
else:
    if D[4] + 1 >= D[1]:
        print("Yes")
    else:
        print("No")



# any 4 any
# (2,4) 4 (,4)
# 4 1 4


Measured memory_bytes: 14252
A, B, C = map(int, input().split(" "))
K = int(input())
if max(A, B, C) == A:
    print(A*(2**K) + B + C)
elif max(A, B, C) == B:
    print(A + B*(2**K) + C)
else:
    print(A + B + C*(2**K))

Measured memory_bytes: 3060
#include <algorithm>
#include <functional>
#include <iostream>

using namespace std;

int main() {
  int ns[5];
  for (int i = 0; i < 5; i++)
    cin >> ns[i];
  sort(ns, ns+5, greater<int>());
  for (int i = 0; i < 4; i++)
    cout << ns[i] << ' ';
  cout << ns[4] << endl;
  return 0;
}

Measured memory_bytes: 0
N,M = [int(i) for i in input().split()]
ablist = []
nodelist = [[0 for i in range(N)] for j in range(N)]
for i in range(M):
    a,b = [int(i)-1 for i in input().split()]
    ablist.append([a,b])
    nodelist[a][b] = 1
    nodelist[b][a] = 1

#print(nodelist)

ans = 0

for a,b in ablist:
    #print(a,b)
    newnodelist = [[nodelist[i][j] for i in range(N)] for j in range(N)]
    newnodelist[a][b]=0
    newnodelist[b][a]=0
    #print(newnodelist)
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if newnodelist[i][k]&newnodelist[k][j]==1:
                    newnodelist[i][j]=1
    #print(newnodelist)
    a = sum([sum(i) for i in newnodelist])
    #print(a)
    if a!= N*N:
        ans+=1
        
print(ans)


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main() {
  int N;
  long long D;
  cin >> N >> D;
  D = D*D;
  int cnt = 0;
  int i;
  long long x,y;
  for(i=0;i<N;i++) {
    cin >> x >> y;
    if(x*x+y*y <= D)cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  map<string, int> M;
  while (q--) {
    int op;
    cin >> op;
    if (op == 0) {
      string k;
      int x;
      cin >> k >> x;
      M[k] = x;
    } else if (op == 1) {
      string k;
      cin >> k;
      cout << M[k] << endl;
    } else if (op == 2) {
      string k;
      cin >> k;
      M[k] = 0;
    } else {
      string l, r;
      cin >> l >> r;
      auto left = M.lower_bound(l);
      auto right = M.upper_bound(r);
      for (auto it = left; it != right; it++) {
        if (it->second)
          cout << it->first << " " << it->second << endl;
      }
    }
  }
}


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

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

  int c = 0;
  int j = n;
  while(j > 0){
    c += j % 10;
    j /= 10;
  }
  if(n % c == 0)
      cout << "Yes" << endl;
  else
      cout << "No" << endl;
}


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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  string s;
  cin >> s;

  if (s == "keyence") {
    cout << "YES" << endl;
    return 0;
  }

  FOR(i, 1, s.size() - 1) FOR(j, 1, s.size() - i) {
    int k = s.size() - i - j;
    // cout << i + j + k << " " << i << " " << j << " " << k << endl;
    // cout << s.substr(0, i);
    // cout << s.substr(i, j);
    // cout << s.substr(i + j, k) << endl;
    string s1 = s.substr(0, i);
    string s2 = s.substr(i, j);
    string s3 = s.substr(i + j, k);

    if (s1 + s2 == "keyence" or s2 + s3 == "keyence" or s1 + s3 == "keyence") {
      cout << "YES" << endl;
      return 0;
    }
  }

  cout << "NO" << endl;

  return 0;
}


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

#define lpsbd(i, s, b, d) for(size_t i = (s); i < (b); i+=(d))
#define lpsb(i, s, b) for(size_t i = (s); i < (b); i++)
#define lpn(i, n) for(size_t i = 0; i < (n); i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

int main(void)
{
    int A, B;
    cin >> A >> B;
    double di;
    lpsb(i, 1, 2000)
    {
        di = (double)i;
        if (int(i * 0.08) == A && int(i * 0.1) == B)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int a;
	while(cin>>a)
	{
		if(a<1200)
		cout<<"ABC"<<endl;
		else
		{
			if(a<2800)
			cout<<"ARC"<<endl;
			else
			cout<<"AGC"<<endl;
		}
		
	}
	return 0;
}

Measured memory_bytes: 256
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    IN(ll, P);
    IN(string, S);
    ll ans = 0;
    if (P == 2 or P == 5)
    {
        ans = 0;
        REP(i, N)
        {
            ans += ((S[i] - '0') % P == 0) * (i + 1);
        }
    }
    else
    {
        vi mod(P);
        ll k = 1;
        ll s = 0;
        ++mod[0];
        for (ll i = N - 1; i >= 0; --i)
        {
            s = (s + (S[i] - '0') * k) % P;
            ++mod[s];
            k = (k * 10) % P;
        }
        REP(i, P)
        {
            ans += mod[i] * (mod[i] - 1) / 2;
        }
    }
    OUT(ans);
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <set>
#include <map>
#include <random>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }

int h, w, n, md;
bool g[51][51] = {};
 
void answer() {
    ll res = 0;
    ll base = 1;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (g[i][j]) res = (res+base) % md;
            base = 2*base % md;
        }
    }
    cout << "! " << res << endl;
}

using T = tuple<int, int, int, int>;
map<T, int> buf;
int que(int ax, int ay, int bx, int by) {
    bx--; by--;
    if (buf.count(T(ax, ay, bx, by))) return buf[T(ax, ay, bx, by)];
    cout << "? " << ay << " " << ax << " " << by << " " << bx << endl;
    int p;
    cin >> p;
    return buf[T(ax, ay, bx, by)] = p;
}

using R = double;

R fact[100000];
void first() {
    fact[0] = 1;
    for (int i = 1; i < 100000; i++) {
        fact[i] = i * fact[i-1];
    }
}
R C(int n, int k) {
    if (n < k || n < 0) return 0;
    return fact[n] / fact[k] / fact[n-k];
}

R dp[100][100];
int nxdp[100][100];
bool used[100][100] = {};
R calc(int x, int c) {
    if (c == 0 || c == x) {
        dp[x][c] = 0;
        nxdp[x][c] = -1;
        return 0;
    }
    if (used[x][c]) return dp[x][c];
    used[x][c] = true;
    R ma = 1e9; int nx;
    for (int i = 1; i < x; i++) {
        //divide [i, x-i]
        R buf = 1;
        for (int j = 0; j <= min(c, i); j++) {
            //divided [j, c-j]
            buf += (calc(i, j) + calc(x-i, c-j)) * C(i, j) * C(x-i, c-j) / C(x, c);
        }
        if (buf < ma) {
            ma = buf;
            nx = i;
        }
    }
    dp[x][c] = ma;
    nxdp[x][c] = nx;
    return ma;
}
 

ll rand_int(ll l, ll r) { //[l, r]
    using D = uniform_int_distribution<ll>;
    static random_device rd;
    static mt19937 gen(rd());
    return D(l, r)(gen);
}
 
void dfs(int y, int l, int r, int nm = -1) {
    if (nm == -1) {
        nm = que(l, y, r, y+1);
    }
    if (nm == 0) return;
    if (nm == r-l) {
        for (int i = l; i < r; i++) {
            g[y][i] = true;
        }
        return;
    }
    if (l+1 == r) {
        g[y][l] = true;
        return;
    }
    calc(r-l, nm);
    int md = l + nxdp[r-l][nm];
    int buf = que(l, y, md, y+1);
    dfs(y, l, md, buf);
    dfs(y, md, r, nm-buf);
}

void main_calc() {
    for (int i = 0; i < h; i++) {
        dfs(i, 0, w);
    }
}

int main() {
    cin >> h >> w >> n >> md;
    first();
    main_calc();
    answer();
/*    for (int i = 1; i <= 100; i++) {
        printf("%d: ", i);
        for (int c = 0; c <= i; c++) {
            calc(i, c);
            printf("(%.2lf, %d), ", dp[i][c], nxdp[i][c]);
        }
        cout << endl;
    }*/
    return 0;
}


Measured memory_bytes: 1620
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    int2(n, m);
    n--, m--;
    vi x(n), y(m);

    Int(bef);
    rep(i, n) {
        Int(tmp);
        x[i] = tmp - bef;
        bef = tmp;
    }
    cin >> bef;
    rep(i, m) {
        Int(tmp);
        y[i] = tmp - bef;
        bef = tmp;
    }

     /*{{{
    rep(i, n) {
        cout << x[i] << " ";
    }cout << endl;
    rep(i, m) {
        cout << y[i] << " ";
    }cout << endl;
     }}}*/

    int xsum = 0;
    if (n % 2) {
        int pos = n;
        rep(i, n / 2) {
            xsum += (pos * x[i]) % MOD;
            pos += (n - (i+1) * 2);
            xsum %= MOD;
        }
        xsum += (pos * x[n/2]);
        xsum %= MOD;

        pos = n;
        rep(i, n / 2) {
            xsum += (pos * x[n - i - 1]) % MOD;
            pos += (n - (i+1) * 2);
            xsum %= MOD;
        }

       // cout << xsum << endl;
    } else {
        int pos = n;
        rep(i, n / 2) {
            xsum += (pos * x[i]) % MOD;
            pos += (n - (i+1) * 2);
            xsum %= MOD;
        }

        pos = n;
        rep(i, n / 2) {
            xsum += (pos * x[n - i - 1]) % MOD;
            pos += (n - (i+1) * 2);
            xsum %= MOD;
        }
        //cout << xsum << endl;
    }

    int ysum = 0;
    if (m % 2) {
        int pos = m;
        rep(i, m / 2) {
            ysum += (pos * y[i]) % MOD;
            pos += (m - (i+1) * 2);
            ysum %= MOD;
        }
        ysum += (pos * y[m/2]);
        ysum %= MOD;

        pos = m;
        rep(i, m / 2) {
            ysum += (pos * y[m - i - 1]) % MOD;
            pos += (m - (i+1) * 2);
            ysum %= MOD;
        }

        //cout << xsum << endl;
    } else {
        int pos = m;
        rep(i, m / 2) {
            ysum += (pos * y[i]) % MOD;
            pos += (m - (i+1) * 2);
            ysum %= MOD;
        }

        pos = m;
        rep(i, m / 2) {
            ysum += (pos * y[m - i - 1]) % MOD;
            pos += (m - (i+1) * 2);
            ysum %= MOD;
        }
//        cout << ysum << endl;
    }
    cout << (xsum * ysum) % MOD << endl;

    return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<vector>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n+2);
	a[0] = 0;
	a[n + 1] = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	vector<int> sum(n + 2);
	int entire = 0;
	for (int i = 0; i <= n; i++) {
		entire += abs(a[i] - a[i + 1]);
	}
	for (int i = 1; i <= n; i++) {
		sum[i] = entire + abs(a[i - 1] - a[i + 1]) - (abs(a[i] - a[i + 1]) + abs(a[i] - a[i - 1]));
		cout << sum[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 2048
// 最長増加部分列
// 問題URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_D&lang=jp
// 
// アルゴリズムがシンプルで良いと思いました。
// std:lower_boundという便利な関数を知り驚きました。

#include <iostream>

using namespace std;

int LIS[100000 + 5], a[100000 + 5];
int N, ans;

#define INF 1000000000

int main(){
    cin >> N;
    fill(LIS, LIS + N, INF); //DP表の初期化

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

    for(int i = 0; i < N; ++i){
        *lower_bound(LIS, LIS+N, a[i]) = a[i];
    }

    for(int i = 0;i < N; ++i){
        if(LIS[i]==INF){
            break;
        }
        ans++;
    }
    cout << ans << endl;
}




Measured memory_bytes: 3872
# -*- coding: utf-8 -*-
"""
C - One-stroke Path
https://atcoder.jp/contests/abc054/tasks/abc054_c

"""
import sys


from itertools import permutations

def solve(N, M, path):
    ans = 0
    for p in permutations(range(2, N+1)):
        p = [1] + list(p)
        for f, t in zip(p, p[1:]):
            if not [f, t] in path and not [t, f] in path:
                break
        else:
            ans += 1
    return ans


def main(args):
    N, M = map(int, input().split())
    path = [[int(i) for i in input().split()] for _ in range(M)]
    ans = solve(N, M, path)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3188
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            map.merge(a, 1, Integer::sum);
        }
        if (map.size() <= k) {
            System.out.println(0);
        } else {
            int sub = map.size() - k;
            List<Integer> list = new ArrayList<>();
            map.entrySet().stream()
                    .sorted(java.util.Map.Entry.comparingByValue())
                    .forEach(s -> list.add(s.getValue()));
            int ans = 0;
            for (int i = 0; i < sub; i++) {
                ans += list.get(i);
            }
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 69632
import sys

w = [512,256,128,64,32,16,8,4,2,1]
ans = []
for x in sys.stdin:
    for i in range(10) :
        if int(x) % w[i] == 0:
            ans.append(w[i])
            ans.reverse()
            print(*ans)
            ans = []
            break
        else:
            if int(x) // w[i] == 1 :
                ans.append(w[i])
                x = int(x) % w[i]


Measured memory_bytes: 5616
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int max1=0,num=0;
    for(int i=0; i<s.length(); i++)
    {
        if(s[i]=='R')
            num++;
        if(s[i]=='S')
        {
            max1=max(max1,num);
            num=0;
        }
    }
    cout<<max(max1,num);
}


Measured memory_bytes: 3624
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int a,b,l,c;
cin>>a>>b;
    c=log10(b)+1;
    a=a*pow(10,c)+b;
    if(round(sqrt(a))==sqrt(a)) cout<<"Yes";
else cout<<"No";
}

Measured memory_bytes: 384
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
ll sum[510000][26];
ll tmp[26];
signed main(){
  init_io();
  ll n,q;
  string s;
  cin >> n >> s >> q;
  for(int i=0;i<26;i++){
    sum[0][i]=0;
    for(int j=0;j<n;j++){
      sum[j+1][i] = sum[j][i] + (('a'+i)==s[j]);
    }
  }
  ll t[q];
  map<ll,char> que;
  for(int i=0;i<q;i++){
    cin >> t[i];
    if(t[i]==1){
      ll ti;
      char tc;
      cin >>ti >> tc;
      que[ti] = tc;
    }else{
      ll l,r,ans=0;
      cin >> l >> r;
      fill(tmp,tmp+26,0);
      for(int j=0;j<26;j++){
        tmp[j] = sum[r][j] - sum[l-1][j];
      }
      for(auto p:que){
        if(l<=p.first&&p.first<=r){
          tmp[p.second-'a']++;
          tmp[s[p.first-1]-'a']--;
        }
      }
      for(int j=0;j<26;j++){
        if(tmp[j]>0) ans++;
      }
      cout << ans << endl;
    }
  }
}


Measured memory_bytes: 104476
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;

typedef pair <int, int> pii;

int main()
{

	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll n;
	ll x[100005] = {};
	ll y[100005] = {};
	ll z[100005] = {};
	cin >> a;
	cin >> b;
	cin >> c;
	ans = b + min(a + b, c);
	if (c>a+b)
	{
		ans++;
	}
	cout << ans << endl;


	return 0;


	//cout << ans << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <atcoder/all>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, M;
ll cnt[100010];

int main() {
  std::cin >> N >> M;

  atcoder::dsu d( N+10 );

  rep( i, M ) {
    ll A, B;
    std::cin >> A >> B;
    --A; --B;

    d.merge( A, B );
  }

  rep( i, N )
    ++cnt[d.leader(i)];

  ll ans = 0;

  rep( i, N ) if( cnt[i] )
    ++ans;

  --ans;

  std::cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4444