akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

const int N = 200010;
const int MOD = 1e9 + 7;
int inv[N], invfact[N], fact[N];

void add(int &a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
int mul(int a, int b) {
  return (a * 1LL * b) % MOD;
}

int c(int n, int k) {
  return mul(fact[n], mul(invfact[k], invfact[n - k]));
}

void solve() {
  int h, w, a, b; cin >> h >> w >> a >> b;
  int ans = 0;
  for (int stopcolumn = b + 1; stopcolumn <= w; stopcolumn++) {
    int n1 = h - a, m1 = stopcolumn;
    int n2 = a, m2 = w - stopcolumn + 1;
    add(ans, mul(c(n1 + m1 - 2, n1 - 1), c(n2 + m2 - 2, n2 - 1)));
  }
  cout << ans;
}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES (n == 1)

int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(20);
  //cout << 1.0 * clock() / CLOCKS_PER_SEC << endl;
  inv[1] = invfact[0] = fact[0] = invfact[1] = fact[1] = 1;
  for (int i = 2; i < N; i++) {
    inv[i] = MOD - mul(MOD / i, inv[MOD % i]);
    invfact[i] = mul(inv[i], invfact[i - 1]);
    fact[i] = mul(i, fact[i - 1]);
  }
  solve();
}


Measured memory_bytes: 5960
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

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

int main() {
    string S; cin >> S;
    int N = (int)S.size();

    bool ok = true;
    repp(i,0,N/2) ok &= S[i] == S[N-i-1];
    repp(i,0,(N-1)/2) ok &= S[i] == S[N-i-1 - (N+1)/2];
    repp(i,0,(N-1)/2) ok &= S[i+(N+1)/2] == S[N-i-1];

    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
n, m = input().split()
count = 0
n = int(n)
flag = [1]*n
ml = list(map(int, input().split()))
for i in range(int(m)):
    a, b = input().split()
    a = int(a)
    b = int(b)
    if ml[a-1] <= ml[b-1]:
        flag[a-1] = 0
    if ml[a-1] >= ml[b-1]:
        flag[b-1] = 0
print(flag.count(1))


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

using namespace std;

int main()
{
    vector<int> a(3);
    int N;
    cin >> N;
    while (N--) {
        for (int i = 0; i < 3; i++) {
            cin >> a[i];
        }
        sort(a.begin(), a.end());
        cout << (a[0]*a[0] + a[1]*a[1] == a[2]*a[2] ? "YES" : "NO") << endl;
    }
    return 0;
}

Measured memory_bytes: 3112
from collections import deque

k = int(input())
q = deque(range(1, 10))

for _ in range(k - 1):
    x = q.popleft()
    m = x % 10
    if m != 0:
        q.append(x * 10 + m - 1)
    q.append(x * 10 + m)
    if m != 9:
        q.append(x * 10 + m + 1)

ans = q.popleft()
print(ans)

Measured memory_bytes: 18692
import collections
n = int(input())
a = list(map(int, input().split()))
l = collections.Counter(a)
#print(l)
v = list(l.keys())
#print(v)
ans = 0
for i in v:
    if (l.get(i)>=i):
        ans += (l.get(i)-i)
    else:
        ans += l.get(i)
print(ans)

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SZ(x) (int)(x).size()
#define ZERO(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<": "<<(x)<<"\n"
#define pb push_back
#define eb emplace_back
#define mp make_pair

int n,m;
int box[100020];
bool p[100020];

void init() {
    ZERO(box); ZERO(p);
}

int main() {
    while(cin>>n>>m) {
        init();
        FOR(i,1,n+1) box[i] = 1;
        p[1] = true;

        rep(i,m) {
            int x,y; scanf("%d%d",&x,&y);
            if(p[x]) p[y] = true;
            if(box[x] == 1) {
                p[x] = false;
            }
            box[x]--; box[y]++;
        }
        int ans=0;
        FOR(i,1,n+1) ans += p[i];
        cout<< ans << "\n";
    }

    return 0;
}


Measured memory_bytes: 768
#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 h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    vector<vector<int>> cnt(h, vector<int>(w));
    rep(i,h) {
      vector<int> done(w);
      rep(j,w) {
        if (s[i][j] == '#') continue;
        if (done[j]) continue;
        int l = 0;
        while (j+l < w) {
          if (s[i][j+l] == '#') break;
          l++;
        }
        rep(k,l) {
          cnt[i][j+k] += l;
          done[j+k] = 1;
        }
      }
    }
    rep(j,w) {
      vector<int> done(h);
      rep(i,h) {
        if (s[i][j] == '#') continue;
        if (done[i]) continue;
        int l = 0;
        while (i+l < h) {
          if (s[i+l][j] == '#') break;
          l++;
        }
        rep(k,l) {
          cnt[i+k][j] += l;
          done[i+k] = 1;
        }
      }
    }
    int ans = 0;
    rep(i,h)rep(j,w) {
      ans = max(ans, cnt[i][j]-1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 26420
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define mod 1000000007
#define fi first
#define se second
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
    ll n,i;
    cin>>n;
    ll j,k;
    ll ans=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            for(k=1;k<=n;k++)
            {
                ll x = __gcd(i,j);
                ll y = __gcd(x,k);
                ans+=y;
            }
        }
    }

    cout<<ans<<endl;
}


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

int comb(int max,int target){
	int comb = 0;
	for(int i = 3; i <= max; i++){
		for(int j = 2; j < i; j++){
			for(int k = 1; k < j ; k++){
				if( i + j + k == target){
					comb++;
				}
			}
		}
	}
	return comb;
}


int main()
{
	int n,x;
	cin>>n>>x;
	while((n!=0)||(x!=0)){
		int result = comb(n,x);
		cout<<result<<endl;
		cin>>n>>x;
	}
	return 0;
}

Measured memory_bytes: 3052
import java.util.*;
// warm-up
// Solution ripped from editorial. Knew the solution. Just couldnt know what the bounds were.
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt(), n=B, i=1;
		while (n-->0) {
			if ((C%B==((i*A)%B))) {
				System.out.println("YES"); System.exit(0);
			}
			i++;
		}
		System.out.println("NO");
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 35616
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
t = [[0, -1], [-1, 0], [1, 0], [0, 1]]

ans = "Yes"
for i, m in enumerate(s):
    for j, n in enumerate(m):
        if n == "#":
            flg = 0
            for x, y in t:
                if 0 <= x + i < h and 0 <= y + j < w:
                    if s[x+i][y+j] == "#":
                        flg = 1
            if flg == 0:
                ans = "No"

print(ans)


Measured memory_bytes: 40304
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  int N,M,X,Y;
  cin >>N>>M>>X>>Y;
  vi x(N), y(M);
  rep(i,N) cin >> x[i];
  rep(i,M) cin >> y[i];
  int xmax = *max_element(all(x));
  int ymin = *min_element(all(y));
  xmax = max(xmax,X);
  ymin = min(ymin,Y);
  dump(xmax,ymin);
  if(xmax>=ymin) {
    cout << "War" << endl;
  } else {
    cout << "No War" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}

const double EPS = 1e-9;
double R;

bool equal( double a, double b ) {
    return fabs( a-b ) < EPS;
}

bool lessthan( double a, double b ) {
    return a < b;
}

bool lessthan_equal( double a, double b ) {
    return lessthan( a, b ) || equal( a, b );
}

void solve() {
    for ( int i = 1; i <= 10000000; ++ i ) {
        int j = floor( (M_PI + R) * i );
        double r = (double)j / i;
        if ( lessthan_equal( fabs(M_PI-r), R ) ) {
            cout << j << "/" << i << endl;
            return;
        }
    }
}

int main() {
    while ( cin >> R && ! equal( R, 0.0 ) ) {
        solve();
    }
    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
    
  if (a*b%2 == 1) {
    cout << "Odd" << endl;
  }
  else if (a*b%2 == 0){
    cout << "Even" << endl;
  }
  // ここにプログラムを追記
}

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

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

    int K;
    std::cin >> K;

    std::vector<std::string> memo;
    for (int i = 0; i < S.length(); i++) {
        for (int d = 1; d <= std::min(K, (int)S.length() - i); d++) {
            memo.emplace_back(S.substr(i, d));
        }
    }

    std::sort(memo.begin(), memo.end());
    memo.erase(std::unique(memo.begin(), memo.end()), memo.end());

    std::cout << memo[K - 1] << '\n';
}

Measured memory_bytes: 4324
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
	let n = get!();
    let mut ts = vec![];
    for _ in 0..5 {
    	ts.push(get!());
    }
    let mut ans = (n + ts[0] - 1) / ts[0];
    let mut fst = 1;
    let mut min = ts[0];
    for i in 1..5 {
        // println!("{}", ans);
    	if ts[i] >= min {
        	ans += 1;
        } else {
        	let tmp = (n + ts[i] - 1) / ts[i];
            ans = fst + tmp;
        }
        min = std::cmp::min(min, ts[i]);
        fst += 1;
    }
    
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    int x , n ;
    cin >> x >> n;
    unordered_map <int , int> mp;
    for(int i = 0 ; i < n ; i++){
        int y;
        cin >>y;
        mp[y] = 1;
    }
    int i = 0;
    
    while(true){
        if(mp.find((x - i)) == mp.end()){
            cout << x - i << endl;
            break;
        }else if(mp.find((x + i)) == mp.end()){
            cout << x + i << endl;
            break;
        }
        i++;
    }
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

ll n, dp[500][500], s[500];

int main() {
	REP(i, 500)REP(j, 500) if (abs(i - j) > 1) dp[i][j] = INF64;
	cin >> n;
	REPO(i, n) {
		ll a; cin >> a;
		s[i] += a;
		s[i + 1] += s[i];
	}
	REPO(i, n) {
		REP(j, n - i + 1) {
			REP(k, i) {
				dp[j][j + i] = min(dp[j][j + i], dp[j][j + k] + dp[j + k][j + i] + s[j + i] - s[j]);
			}
		}
	}
	cout << dp[0][n] << endl;
}



Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <regex>
using namespace std;

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)

typedef long long ll;

int main()
{
    int N,K;
    cin >>N>>K;
    ll h[100001];
    FOR(i,0,N) cin >>h[i];

    sort(h,h+N, greater<int>());
    ll ans = 9999999999;
    FOR(i,0,N-K+1){
        int range = h[i] - h[i+K-1];
        if (ans>=range)ans=range;
    }
    cout << ans << endl;
}



Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstdint>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <climits>
#include <numeric>
#include <algorithm>

using namespace std;


int main()
{
    string s;  
    cin >> s;
    int q;
    cin >> q;
  
    string front;
    string back;
    bool reversed = false;
   
    
    for(int i = 0; i < q; ++i){
        int t;
        cin >> t;
        if(t == 1){
            reversed = !reversed;
            swap(front, back);
        }
        else{
            int f;
            char c;
            cin >> f >> c;
            if(f == 1){
                front += c;
            }
            else{
                back += c;
            }
        }
    }
    if(reversed){
        reverse(s.begin(), s.end());
    }
    reverse(front.begin(), front.end());
    cout << front << s << back << '\n';   
    
    return 0;
}


Measured memory_bytes: 1088
#include<bits/stdc++.h>
using namespace std;
struct leg{int x,y,rl,cost;
  bool operator<(const leg& r)const{
    return cost>r.cost;
  }
};
int dp[60][30][2];

int main(){
  int h,w;
  while(cin>>w>>h,w){
    char ma[60][30];
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	cin>>ma[i][j];

    priority_queue<leg> que;
    for(int i=0;i<w;i++){
      if(ma[h-1][i]!='S')continue;
      que.push((leg){h-1,i,0,0});
      que.push((leg){h-1,i,1,0});
    }
    fill_n(**dp,60*30*2,-1);

    int f=1;
    while(!que.empty()){
    
      leg tmp=que.top();
      que.pop();
      int x=tmp.x;
      int y=tmp.y;
      int cost=tmp.cost;
      int rl=tmp.rl;
    
      //cout<<x<<" "<<y<<" "<<rl<<" "<<cost<<endl;
    
      if(ma[x][y]=='X')continue;
      if(ma[x][y]=='T'){
	cout<<cost<<endl;
	f=0;
	break;
      }
      if(dp[x][y][rl]!=-1)continue;
    
      dp[x][y][rl]=cost;
    
      if(ma[x][y]!='S')cost+=ma[x][y]-'0';
      if(rl){
      
	for(int i=-2;i<=2;i++){
	  for(int j=1;j<=3;j++){
	    int nx=x+i;
	    int ny=y+j;
	    if(abs(y+1-ny)+abs(x-nx)>=3)continue;
	    if(nx<0||h<=nx||ny<0||w<=ny)continue;
	    if(ma[nx][ny]=='X')continue;
	    que.push((leg){nx,ny,!rl,cost});
	  }
	}
      
      }else{
      
	for(int i=-2;i<=2;i++){
	  for(int j=-3;j<=-1;j++){
	    int nx=x+i;
	    int ny=y+j;
	    if(abs(y-1-ny)+abs(x-nx)>=3)continue;
	    if(nx<0||h<=nx||ny<0||w<=ny)continue;
	    if(ma[nx][ny]=='X')continue;
	    que.push((leg){nx,ny,!rl,cost});
	  }
	}
      
      }
    
    }
    if(f)cout<<-1<<endl;
  }
  return 0;
}



Measured memory_bytes: 3216
import java.util.*;
class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int n = stdIn.nextInt();
			if(n == 0) break;
			int[] s = new int[n];
			int sum = 0;
			for(int i = 0; i < n; i++) {
				s[i] = stdIn.nextInt();
				sum += s[i];
			}
			double m = sum/(double)n;
			double a = 0.0;
			for(int i = 0; i < n; i++) {
				a += (s[i] - m)*(s[i] - m);
			}
			a= a/(double)n;
			
			System.out.println(Math.sqrt(a));
			
		}
	}
}

Measured memory_bytes: 23916
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        while(scn.hasNextInt()) {
            int[] a = createArray(), b = createArray();
            System.out.println(searchHit(a, b) + " " + searchBlow(a, b));
        }
    }
    
    private static int[] createArray() {
        int[] ary = new int[4];
        for(int i = 0; i < 4; i++) {
            ary[i] = scn.nextInt();
        }
        return ary;
    }
    
    private static int searchHit(int[] a, int[] b) {
        int hit = 0;
        for(int i = 0; i < a.length; i++) {
            if(a[i] == b[i]) {
                hit++;
            }
        }
        return hit;
    }
    
    private static int searchBlow(int[] a, int[] b) {
        int blow = 0;
        for(int i = 0; i < a.length; i++) {
            for(int j = 0; j < b.length; j++) {
                if(i != j && a[i] == b[j]) {
                    blow++;
                }
            }
        }
        return blow;
    }
}

Measured memory_bytes: 26416
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        String p = sc.next();
         
        s += s;
        if(s.indexOf(p)!=-1) System.out.println("Yes");
        else System.out.println("No");
    }
}



Measured memory_bytes: 26276
# coding:utf-8
def show(a,b):
    global str
    print str[a:b+1]
def reverse(a,b):
    global str
    t = str[:a]
    t += str[-(len(str)-b):-(len(str)-a+1):-1]
    t += str[b+1:]
    str = t
def replace(a,b,p):
    global str
    t = str[:a]
    t += p
    t += str[b+1:]
    str = t

str = raw_input()
n = input()

for i in range(n):
    command = raw_input().split()
    if command[0] == "replace":
        replace(int(command[1]),int(command[2]),command[3])
    elif command[0] == "reverse":
        reverse(int(command[1]),int(command[2]))
    elif command[0] == "print":
        show(int(command[1]),int(command[2]))




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

int main(void)
{
  int a, b;
  cin >> a >> b;
  int tasu = a + b;
  int hiku = a - b;
  int kakeru = a * b;
  if(tasu >= hiku && tasu >= kakeru)
    cout << tasu << endl;
  else if(hiku >= tasu && hiku >= kakeru)
    cout << hiku << endl;
  else
    cout << kakeru << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
  int i, num;
  double xa, ya, ra, xb, yb, rb;

  scanf("%d", &num);
  
  for(i = 0; i < num; i++)
    {
      double len;

      scanf("%lf %lf %lf %lf %lf %lf", &xa, &ya, &ra, &xb, &yb, &rb);
      
      len = sqrt(fabs((xb - xa)*(xb - xa) + (yb - ya)*(yb - ya)));

      if(len > ra + rb)
	printf("0\n");
      else
	{
	  if(fabs(ra - rb) <= len)
	    printf("1\n");
	  else
	    {
	      if(ra > rb)
		printf("2\n");
	      else
		printf("-2\n");
	    }
	}
    }

  return 0;
}

Measured memory_bytes: 620
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N; string S;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> S;
	int ans = 0;
	rep(i, 0, N - 2) if (S.substr(i, 3) == "ABC") ans++;
	cout << ans << endl;
}







Measured memory_bytes: 256
# https://atcoder.jp/contests/abc149/tasks/abc149_b


def main():
    (a, b, k) = map(int, input().split(" "))
    if a > k:
        print("%d %d" % (a - k, b))
    elif a + b > k:
        r = k - a
        print("%d %d" % (0, b - r))
    else:
        print("0 0")


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
/*
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_B&lang=jp
 */
import java.util.*;

public class Main {
	
	int[] A;
	int nSwap = 0;
	
	void printArray(int[] a) {
		System.out.print(a[0]);
		for (int i = 1; i < a.length; i++) {
			System.out.print(" " + a[i]);
		}
		System.out.println();
	}
	
	void merge(int left, int mid, int right) {
		//System.out.println("#: " + left + ", " + mid + ", " + right);
		//printArray(A);
		int n1 = mid - left;
		int n2 = right - mid;
		int[] L = new int[n1+1];
		int[] R = new int[n2+1];
		for (int i = 0; i < n1; i++) L[i] = A[left + i];
		for (int i = 0; i < n2; i++) R[i] = A[mid + i];
		L[n1] = Integer.MAX_VALUE;
		R[n2] = Integer.MAX_VALUE;
		int i = 0, j = 0;
		for (int k = left; k < right; k++) {
			nSwap++;
			if (L[i] <= R[j]) {
				A[k] = L[i];
				i++;
			} else {
				A[k] = R[j];
				j++;
			}
		}
		//printArray(A);
		//System.out.println();
	}
	
	void mergeSort(int left, int right) {
		if (left + 1 < right) {
			int mid = (left + right) / 2;
			mergeSort(left, mid);
			mergeSort(mid, right);
			merge(left, mid, right);
		}
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		A = new int[n];
		for (int i = 0; i < n; i++) {
			A[i] = sc.nextInt();
		}
		mergeSort(0, A.length);
		printArray(A);
		System.out.println(nSwap);
	}

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

}



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

int h, w, dx[] = { -1,0,1,0 }, dy[] = { 0,-1,0,1 };
vector<string>m;

int main() {
	cin >> h >> w;
	m.resize(h);
	int sum = 0;
	for (int i = 0; i < h; i++) {
		cin >> m[i];
		for (int j = 0; j < w; j++) {
			if (m[i][j] == '.')sum++;
		}
	}
	
	vector<vector<int>>d(h, vector<int>(w, 0));
	queue<pair<int, int>>q;
	q.push({ 0,0 });
	while (!q.empty()) {
		int x = q.front().first, y = q.front().second; q.pop();
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i], ny = y + dy[i];
			if (nx < 0 || nx >= h || ny < 0 || ny >= w)continue;
			if (m[nx][ny] == '#'||d[nx][ny])continue;
			q.push({ nx,ny });
			d[nx][ny] = d[x][y] + 1;
		}
	}
	if (d[h - 1][w - 1]) {
		cout << sum - (d[h - 1][w - 1] + 1) << endl;
	}
	else cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 3640
#!usr/bim/python
#! -*- coding: utf-8 -*-

n = int(raw_input())
before = [0,0,0]
status = 0
for i in range(n):
    line = map(int,raw_input().split())
    if status == 1:
        pass
    else:
        kyori = abs(line[1]-before[1])+abs(line[2]-before[2])
        time = line[0]-before[0]
        if kyori>time:
            status = 1
        elif (time - kyori)%2 == 1:
            status = 1
        before = line

if status == 0:
    ans = "Yes"
else:
    ans = "No"

print ans


Measured memory_bytes: 5764
n=int(input())
s=input()
s_=[]
for i in range(n):
  if s[i]=='E':
    s_.append(0)
  else:
    s_.append(1)    
rui=[]
rui.append(s_[0])
for i in range(1,n):
  rui.append(rui[-1]+s_[i])
ans=n+1  
for j in range(1,n-2):
  ans=min(ans,rui[j-1]+n-1-j-rui[n-1]+rui[j])
ans_=n-1-rui[n-1]+rui[0]
ans=min(ans,ans_)
ans_=rui[n-1]
ans=min(ans,ans_)
print(ans)

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

int main(){
  int K , S;
  cin >> K >> S;
  //Sの最大値は3K
  int x = 0;
  int y = 0;
  int z = 0;
  int count = 0;
  
  for(int i = 0; i<= K ; i++){
    x = i;
    for(int j = 0; j <= K; j++){
      y = j;
      z = S - i - j;
      if(0 <= z && z <= K)count++;
    }
  }
  cout << count << endl;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(2e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int n, m, s, t;
vector<vector<int> > g;

ll dmin[MAX_N][3];

void dijkstra(){
    REP(i,n+1) fill(dmin[i], dmin[i]+3, LLINF/3);
    priority_queue<P3, vector<P3>, greater<P3> > que;
    que.push({0,{s,0}});
    dmin[s][0] = 0;
    while(!que.empty()){
        P3 p = que.top();
        que.pop();
        ll now = p.second.first, r = p.second.second;
        //cout << now << " " << r << endl;
        if(dmin[now][r] < p.first)continue;
        for(auto to : g[now]){
            if(dmin[to][(r+1)%3] > dmin[now][r] + 1){
                dmin[to][(r+1)%3] = dmin[now][r] + 1;
                que.push({dmin[to][(r+1)%3],{to, (r+1)%3}});
            }
        }
    }
}

int main() {
    cin >> n >> m;
    g.resize(n);
    REP(i,m){
        int u, v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
    }
    cin >> s >> t;
    s--; t--;
    dijkstra();
    if(dmin[t][0] != LLINF/3){
        cout << dmin[t][0]/3 << endl;
    }
    else {
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 9856
# 同じ種類だと、点数が高いやつを選ぶ
# 違う種類を選ぶと、ボーナス点が入るので、それをどうするか
# d  = sum(di) + x**x
# 種類xを固定すると？ O(log(N))でいける？
# ※※ 種類が増えるかどうかを降順で見ながらboolで置き換えるという発想。強い。

from collections import defaultdict

di = defaultdict(list)
n, k = map(int, input().split())

sushi = []
kinds = []
for i in range(n):
    t,d = map(int, input().split())
    sushi.append((d,t))
    kinds.append(t)
sushi.sort(reverse=True)
sushidict = defaultdict(int)
n_kind_all = len(set(kinds))

cnt = 0
import heapq
sushiq = []
# まずは上からK個貪欲に取る
for i in range(k):
    d,t = sushi[i]
    heapq.heappush(sushiq,(d,t)) 
    sushidict[t] += 1
    cnt += d

n_kind = len(sushidict)
res = []
res.append(cnt+n_kind**2)

for i in range(k,n):
    d,t = sushi[i]
    # すでにある種類の場合は大丈夫
    if sushidict[t] > 0 : continue
    # 種類が増える時、小さいものから入れ替えていく
    d_min,t_min = heapq.heappop(sushiq)
    # popして消えるようなものはNG
    while sushidict[t_min] == 1 and sushiq:
        d_min, t_min = heapq.heappop(sushiq)
    # popするものがなくなったら終了
    if not sushiq:
        break
    sushidict[t_min] -= 1
    sushidict[t] += 1
    n_kind += 1
    cnt  = cnt - d_min + d
    res.append(cnt+n_kind**2)
    if n_kind == n_kind_all:
        break

print(max(res))
# print(res)

Measured memory_bytes: 29804
#include <stdio.h>

int main(void)
{
	int i , j;
	
	for (i = 0; i < 9; i++){
		for (j = 0; j < 9; j++){
			printf("%dx%d=%d\n", i + 1, j + 1, (i + 1) * (j + 1));
		}
	}
	
	return (0);
}

Measured memory_bytes: 924
#include<stdio.h>
int main()
{
int a,b,d,j;
  d=0;
scanf("%d %d",&a,&b);
int c[b];
  for(j=0;j<b;++j)
  {
  scanf("%d",&c[j]);
  d=d+c[j];
  }
if(a<d) printf("-1");
  else printf("%d",a-d);
return 0;
}

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

#define N 100000*2
#define INF 1LL << 60

int n, m;
string s;
vector<int> g[N];

int numA[N];
int numB[N];
bool deleted[N];

void del( int i )
{
	if( deleted[i] ) {
		return;
	}
	deleted[i] = true;
	for( auto j : g[i] ) {
		if( deleted[j] ) {
			continue;
		}
		if( s[i] == 'A' ) {
			numA[j]--;
		}
		else {
			numB[j]--;
		}
		if( numA[j] == 0 || numB[j] == 0 ) {
			del( j );
		}
	}
}

int main()
{
	int a, b;

	cin >> n >> m;
	cin >> s;
	for( int i = 0; i < m; i++ ) {
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back( b );
		g[b].push_back( a );
		if( s[b] == 'A' ) {
			numA[a]++;
		}
		else {
			numB[a]++;
		}
		if( s[a] == 'A' ) {
			numA[b]++;
		}
		else {
			numB[b]++;
		}
	}

	for( int i = 0; i < n; i++ ) {
		if( numA[i] == 0 || numB[i] == 0 ) {
			del( i );
		}
	}
	int flag = 0;
	for( int i = 0; i < n; i++ ) {
		if( !deleted[i] ) {
			flag = 1;
		}
	}

	if( flag ) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 15492
#include <cstdio>

int matrix[12][12];
int n;

int main() {
  while(scanf("%d", &n), n) {
    for (int i=0; i<n; i++) {
      for (int j=0; j<n; j++) {
	scanf("%d", &matrix[i][j]);
      }
    }

    // output
    for (int i=0; i<n; i++) {
      int sum = 0;
      for (int j=0; j<n; j++) {
	sum += matrix[i][j];
	printf("%5d", matrix[i][j]);
      }
      matrix[i][n] = sum; 
      printf("%5d\n", sum);
    }

    for (int j=0; j<=n; j++) {
      int sum = 0;
      for (int k=0; k<n; k++) {
	sum += matrix[k][j];
      }
      printf("%5d", sum);
    }
    printf("\n");
  }
}

Measured memory_bytes: 2616
#include<stdio.h>
#include<stdbool.h>

int main(void){

  int N;
  bool judge = false;
  scanf("%d", &N);

  for(int i = 0 ; i < 25 ; i++){
    for(int j = 0 ; j < 15 ; j++){

      if(4*i + 7*j == N)   judge = true;

    }
  }

  if(judge)   puts("Yes");
  else        puts("No");

 return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
  cin.tie(0);
  int a,b,ans;
  while(cin>>a>>b){
    ans=a+b;
    if(ans<=9){
      cout<<"1"<<endl;
    }else if(ans<=99){
      cout<<"2"<<endl;
    }else if(ans<=999){
      cout<<"3"<<endl;
    }else if(ans<=9999){
      cout<<"4"<<endl;
    }else if(ans<=99999){
      cout<<"5"<<endl;
    }else if(ans<=999999){
      cout<<"6"<<endl;
    }else if(ans<=9999999){
      cout<<"7"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3048
#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;

/*
<url:https://agc008.contest.atcoder.jp/tasks/agc008_a>
問題文============================================================
 すぬけ君は電卓を持っています。 この電卓にはディスプレイと 2 個のボタンが付いています。
 
 最初、ディスプレイの値は整数 x です。
 すぬけ君の目標は、ディスプレイの値を整数 y にすることです。
 そのために、すぬけ君は次の 2 個のボタンを好きな順番で何回か押すことができます。
 
 ボタン A : ディスプレイの値を 1 増やす。
 ボタン B : ディスプレイの値の符号を反転する。
 目標を達成するためにすぬけ君がボタンを押す回数の最小値を求めてください。
 なお、整数 x, y の値によらず、必ず目標を達成できることが示せます。
=================================================================

解説=============================================================

================================================================
*/
ll F(ll x,ll y){
    if(y - x >= 0) return y - x;
    else return LINF;
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll x,y; cin >> x >> y;
    cout << min({F(x,y),F(x,-y)+1,F(-x,y)+1,F(-x,-y)+2}) << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import deque

def BFS(path, start, goal):
  que = deque()
  for uv in path[start]:
    que.append(uv)
  visited=[-1 for i in range(3*N)]
  visited[start] = 0
  i = 0
  while que:
    uv = que.popleft()
    
    if visited[uv[1]] == -1:#未到達
      visited[uv[1]] = visited[uv[0]] + 1
      for vw in path[uv[1]]:
        que.append(vw)
    if i >3*N:break
  return visited[goal]

N,M = map(int,input().split())
edge = [[] for i in range(3*N)]
for i in range(M):
  u,v = map(int,input().split())
  edge[0*N + u - 1] += [[0*N + u - 1,1*N + v - 1]]
  edge[1*N + u - 1] += [[1*N + u - 1,2*N + v - 1]]
  edge[2*N + u - 1] += [[2*N + u - 1,0*N + v - 1]]
  
S, T = map(int,input().split())
print(BFS(edge, S-1, T-1)//3)

Measured memory_bytes: 98252
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n; cin >> n;
	vi v(n);
	REP(i, n)
	{
		cin >> v[i];
		v[i]--;
	}
	int ans = 0;
	REP(i, n)
	{
		if (i == v[v[i]]) ans++;
	}
	cout << ans / 2 << endl;
	return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline


N, M = map(int, input().split())
INF = 10**9
dp = [INF] * (2**N)
dp[0] = 0

for _ in range(M):
  a, b = map(int, input().split())
  c = list(map(int, input().split()))
  bit = 0
  for i in c:
    bit |= 1 << (i-1)
  for i in range(2**N):
    if dp[i|bit] > dp[i] + a:
      dp[i|bit] = dp[i] + a
if dp[-1] >= INF:
  print(-1)
else:
  print(dp[-1])

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

ll g1(ll n, int p) {
    if (n == 0) return 0;
    return n/p + g1(n/p,p);
}

ll g2(ll n, int p) {
    if (n % 2 == 1) {
        return g1(n,p) - g2(n-1,p);
    }
    ll res = g1(n/2,p);
    if (p == 2) res += n/2;
    return res;
}

int main() {
    ll n;
    cin >> n;
    ll ans = min(g2(n,2), g2(n,5));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

ll conv(string num) { stringstream ss; ss << num << flush; ll n; ss>>n; return n; }
string conv(ll n) { stringstream ss; ss << n << flush; return ss.str(); }

int main() {
    int a,b; cin>>a>>b;
    int res = 0;
    for (int i = a; i <= b; ++i) {
        string str = conv(i);
        int n = str.size();
        bool ok = true;
        for(int j = 0; j < n/2; ++j) {
            if(str[j] != str[n-1-j]) {
                ok = false;
                break;
            }
        }
        if(ok) ++res;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define repr(i, n, a) for (int i = (n)-1; i >= (a); i--)
#define each(it, v) for (auto(it) = (v).begin(); (it) != (v).end(); (it)++)
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>
#define vd vector<double>
#define vvd vector<vd>
#define co(x) cout << (x)
#define con(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
const double PI = 3.14159265;
const int MAXN = 2e5 + 9;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
///////////////////////////////////////////////////////////
typedef complex<double> Pos;

void Koch(vector<Pos>& v) {
  vector<Pos> res;
  Pos s(1.0 / 3, 0), u(0.5, sqrt(3.0) / 6), t(2.0 / 3, 0);

  res.push_back(v[0]);
  for (size_t i = 1; i < v.size(); i++) {
    Pos sta = v[i - 1], vec = v[i] - v[i - 1];
    res.push_back(sta + vec * s);
    res.push_back(sta + vec * u);
    res.push_back(sta + vec * t);
    res.push_back(sta + vec);
  }
  v = res;
}

int main() {
  int n;
  vector<Pos> v;
  v.push_back(Pos(0, 0));
  v.push_back(Pos(100, 0));
  cin >> n;
  while (n--) {
    Koch(v);
  }
  for_each(v.begin(), v.end(), [](const Pos& p) {
    cout << fixed << setprecision(5) << p.real() << ' ' << p.imag() << endl;
  });
  return 0;
}


Measured memory_bytes: 3388
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>

using namespace std;

typedef long long LL;

int n;
const int maxn = 405;

LL dp[maxn][maxn];
int a[maxn];
LL pre[maxn];

int main(){
    cin >> n;
    for(int i = 1;i <= n;i++){
        scanf("%d", &a[i]);
        pre[i] = pre[i - 1] + a[i];
    }
    for(int i = 1;i <= n;i++){
        dp[i][i] = 0;
    } 
    for(int len = 2;len <= n;len++){
        for(int i = 1;i + len - 1 <= n;i++){
            int j = i + len - 1;
            dp[i][j] = 1e18;
            for(int k = i;k < j;k++){
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + pre[j] - pre[i - 1]);
            }
        }
    }
    cout << dp[1][n] << endl;
    return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<string>
#include<algorithm>

#define MAX_N 1000005

using namespace std;


int n,k;
int rank[MAX_N + 1];
int tmp[MAX_N + 1];
int sa[MAX_N + 1];


bool compare_sa(int i, int j)
{
	if(rank[i] != rank[j]) 
	{
		return rank[i] < rank[j];
	}
	else
	{
	int ri =( i + k <= n )? rank[i + k] : -1;
	int rj =( j + k <= n )? rank[j + k] : -1;
	return ri < rj;
	}
}

void construct_sa(string s,int* sa)
{
	n = s.length();
	
	for(int i = 0; i <= n;i++)
	{
		sa[i] = i;
		rank[i] = i < n ? s[i] : -1;
	}
	
	for(k = 1;k <= n ; k *= 2)
	{
		sort(sa,sa + n + 1,compare_sa);
		
		tmp[sa[0]] = 0;
		for(int i = 1; i <= n; i++)
		{
			tmp[sa[i]] = tmp[sa[i -1]] + (compare_sa(sa[i - 1],sa[i]) ? 1 : 0);
		}
		for(int i = 0;i <= n;i++)
		{
			rank[i] = tmp[i];
		}
	}
}

bool contain(string s,int* sa, string t)
{
	int a = 0,b = s.length();
	while(b - a > 1)
	{
		int c = (a + b) / 2;
		
		if(s.compare(sa[c],t.length(),t) < 0) a = c;
		else b = c;
	}
	
	return (s.compare(sa[b], t.length(),t) == 0);
	
}


int main()
{
	string S;
	int N;
	
	
	cin >> S; 
	cin >> N;
	
	construct_sa(S,sa);
	
	for(int i = 0 ;i < N;i++)
	{
		string T;
		cin >> T;
		if(contain(S,sa,T)) cout << 1 << endl;
		else cout << 0 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 16576
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <deque>
#include <math.h>
#include <map>
#include <bitset>
#include <queue>
#include <list>1
#include <utility>

//#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using p = pair<int, int>;
using Graph = vector<vector<char>>;
#define rep(i,n)  for(int i = 0; i < n ; i++)
#define chmax(x,y) x = max(x,y);
int dx[4]{ -1,0,1,0 };
int dy[4]{ 0,1,0,-1 };
const ll INF = 1e18;
ll dp[200005][4]; // i番目までの個数でj個余分な×を選んだ際の和の最大値

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

    vector<ll> worker(n);
    rep(i, n -1) {
        int boss;
        cin >> boss;
        worker[boss -1] ++;
    }
    rep(i, n) {
        cout << worker[i] << endl;
    }
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll INF=1LL<<60;
const int MOD=1e9+7;

int main(){
    int n; cin >> n;
    vector<vi> G(n, vi(n));
    for(int i=0; i<n; i++){
        int u, k; cin >> u >> k;
        for(int j=0; j<k; j++){
            int v; cin >> v;
            G[u-1].push_back(v-1);
        }
    }
    queue<int> que;
    que.push(0);
    vi dist(n, -1);
    dist[0]=0;
    while(!que.empty()){
        int v=que.front();
        que.pop();
        for(auto &nv: G[v]){
            if(dist[nv] != -1) continue;
            dist[nv]=dist[v]+1;
            que.push(nv);
        }
    }
    for(int i=0; i<n; i++){
        cout << i+1 << " " << dist[i] << endl;
    }
    return 0;
}




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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<string> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  int sum = 0;
  int a = 0, b = 0, ba = 0;
  for (int i = 0; i < n; i++) {
    if (v[i][0] == 'B') b++;
    if (v[i][v[i].size() - 1] == 'A') a++;
    if (v[i][0] == 'B' && v[i][v[i].size() - 1] == 'A') {
      ba++;
      b--;
      a--;
    }
    for (int j = 0; j < v[i].size() - 1; j++) {
      if (v[i][j] == 'A' && v[i][j + 1] == 'B') sum++;
    }
  }
  if (a) {
    int ans = sum + ba + min(a, b);
    cout << ans << endl;
  } else {
    if (ba) {
      int ans = sum + ba - 1 + min(1, b);
      cout << ans << endl;
    } else {
      cout << sum << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 768
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, K, C = map(int, rl().split())
    S = input()
    
    left_greedy = [False] * N
    right_greedy = [False] * N
    
    i, cnt = 0, 0
    while i < N:
        if S[i] == 'o':
            cnt += 1
            left_greedy[i] = True
            i += C + 1
        else:
            i += 1
    
    if K < cnt:
        exit()
    
    i = N - 1
    while 0 <= i:
        if S[i] == 'o':
            right_greedy[i] = True
            i -= C + 1
        else:
            i -= 1
    
    for i in range(N):
        if left_greedy[i] and right_greedy[i]:
            print(i + 1)


if __name__ == '__main__':
    solve()


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

int main() {
  int N;
  scanf("%d", &N);

  vector<pair<int, int>> A(N, make_pair(0, 0));

  for (int i = 0; i < N; i++) {
    int point;
    scanf("%d", &point);
    pair<int, int> p = make_pair(point, i);
    A.at(i) = p;
  }

  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());

  int max_point = A.at(0).first;
  int max_index = A.at(0).second;
  int second_point = A.at(1).first;

  for (int i = 0; i < N; i++) {
    if (i == max_index) {
      printf("%d\n", second_point);
    } else {
      printf("%d\n", max_point);
    }
  }
}

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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    reverse(s.begin(), s.end());
    vector<int> cnt(2019);
    int sum = 0;
    int kurai = 1;
    rep(i,n){
        int si = s[i]-'0';
        (sum += si*kurai) %= 2019;
        cnt[sum]++;
        (kurai *= 10) %= 2019;
    }
    cnt[0]++;

    ll ans = 0;
    rep(i,2019){
        ans += (ll)cnt[i]*(cnt[i]-1)/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3744
import java.io.*;

public class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] strArray = str.split(" ");
		
		int a = Integer.parseInt(strArray[0]);
		int b = Integer.parseInt(strArray[1]);
		int c = Integer.parseInt(strArray[2]);
		
		if(a < b && b < c){
		System.out.println("Yes");
	    }
		else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 24276
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  long long n, m, k;
  cin >> n >> m >> k;
  long long ans = 0, best = m;
  vector<long long> a(n+1), b(m+1);
  a[0] = 0;
  b[0] = 0;
  for (long long i = 1; i < n+1; i++)
  {
    cin >> a[i];
  }
  for (long long i = 1; i < m+1; i++)
  {
    cin >> b[i];
  }
  for (long long i = 1; i <= n; i++)
  {
    a[i]+=a[i-1];
  }
  for (long long i = 1; i <= m; i++)
  {
    b[i]+=b[i-1];
  }
  long long j = m;
  for (long long i = 0; i <= n; i++)
  {
    if (a[i]>k) break;
    while(b[j]>k-a[i]) {
      j-=1;
    }
    ans = max(ans, i+j);
  }
  cout << ans << endl;
}



Measured memory_bytes: 5992
n,k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]

dp = [float("inf")]*(n+k)
dp[0] = 0
for i in range(n):
    for j in range(i+1,i+k+1):
        dp[j] = min(dp[j],dp[i]+abs(h[i]-h[min(j,n-1)]))
print(dp[n-1])

Measured memory_bytes: 55560
package main

import (
	"fmt"
)

func main() {
	var N int
	var S, T string
	fmt.Scan(&N)
	fmt.Scan(&S, &T)

	for i := 0; i < N; i++ {
		fmt.Print(S[i : i+1])
		fmt.Print(T[i : i+1])
	}
	fmt.Println()
}


Measured memory_bytes: 512
#include <stdio.h>
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if (a>b)
		printf("a > b\n",a,b);
	if (a<b)
		printf("a < b\n",a,b);
	if (a==b)
		printf("a == b\n",a,b);
	return 0;
}

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

int main()
{
	string game[3];
	cin >> game[0] >> game[1] >> game[2];
	int turn = 0;
	int length[] = {game[0].length(), game[1].length(), game[2].length()};
	int indices[] = {0, 0, 0};
	while(true) {
		int curr = indices[turn]++;
		if(indices[turn] > length[turn]) break;
		turn = game[turn][curr] - 'a';
	}
	cout << char(turn + 'A');
}


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

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

    bool ease = true;
    for (int i = 0; i < s.size(); ++i) {
        if (i % 2 == 0) {
            if (s[i] == 'L') {
                ease = false;
                break;
            }
        } else {
            if (s[i] == 'R') {
                ease = false;
                break;
            }
        }
    }

    cout << (ease ? "Yes" : "No");

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define PI 3.141592653589793
int main(void)
{
  int a,b;
  double C,c, S, L, h;
  scanf("%d%d%lf", &a, &b, &C);
  C = C*PI/180.0;
  S = (double)a * (double)b * sin(C) / 2;
  c = sqrt(a*a+b*b-2*a*b*cos(C));
  L = a + b + c;
  h = b*sin(C);
  printf("%lf\n%lf\n%lf\n",S,L,h);


  return 0;
}

Measured memory_bytes: 2948
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(void){
  ll n;
  cin>>n;
  vector<ll> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  map<ll,ll> ma;
  ll ans=0;
  for(int i=0;i<n;i++){
    if(ma.find(i-a[i]) != ma.end()){
      ans+=ma[i-a[i]];
    }
    ma[i+a[i]]++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 17252