akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define dump(x) cerr << #x << " : " << x << '\n'
#define MOD(x, y) (((y) + (x) % (y)) % (y))

int N, Y;

int main(int argc, char* argv[])
{
	scanf("%d%d", &N, &Y);
	/*
	for (int i = 0; i <= 2000; i++) {
		for (int j = 0; j <= 2000; j++) {
			int k = N - i - j;
			if (i < 0 || j < 0 || k < 0) continue;
			if (10000 * i + 5000 * j + 1000 * k == Y) {
				printf("%d %d %d\n", i, j, k);
				return 0;
			}
		}
	}
	printf("-1 -1 -1\n");
	*/

	Y /= 1000;
	int K = Y - N;
	/*
	for (int x = K / 9; x >= max(K / 9 - 4, 0); x--) {
		int A = K - 9 * x;
		if (A % 4 != 0) continue;
		int y = A / 4;
		int z = N - x - y;
		if (z < 0) continue;
		printf("%d %d %d\n", x, y, z);
		return 0;
	}
	*/
	int x = K / 9 - (K / 9 * 9 % 4 - K % 4 + 4) % 4;
	int y = (K - 9 * x) / 4;
	int z = N - x - y;
	if (x < 0 || y < 0 || z < 0) printf("-1 -1 -1\n");
	else printf("%d %d %d\n", x, y, z);

	return 0;
}


Measured memory_bytes: 256
using System;
class Program
{
    static void Main()
    {
        int k = int.Parse(Console.ReadLine());
        string s = Console.ReadLine();
        if (s.Length <= k)
        {
            Console.WriteLine(s);
        }
        else
        {
            for (int i = 0; i < k; i++)
            {
                Console.Write(s[i]);
            }
            Console.WriteLine("...");   
        }
    }
}

Measured memory_bytes: 27472
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	if (a == b) cout << c << endl;
	else if (a == c) cout << b << endl;
	else if (b == c) cout << a << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int H, W;
    int i, j;
    while(1){
        scanf("%d %d", &H, &W);
        if(H==0&&W==0){
            break;
        }
        for(i=0;i<H;i++){
            for(j=0;j<W;j++){
                    printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2044
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

//Jigsaw Puzzle
public class Main{

	int h, w, n;
	int[] puzzle;
	List<R>[] piece;
	boolean[] res;
	
	class R{
		int H, W;
		int[] p;
		String str;
		public R(int h, int w, char[][] m) {
			H = h;
			W = w;
			p = new int[H];
			str = "";
			for(int i=0;i<H;i++)for(int j=0;j<W;j++){
				p[i] = (p[i]<<1) + (m[i][j]=='#'?1:0);
				str+=m[i][j];
			}
		}
		boolean eq(R r){
			if(H!=r.H || W!=r.W)return false;
			return str.equals(r.str);
		}
	}
	
	char[][] rot(char[][] a){
		int H = a.length, W = a[0].length;
		char[][] res = new char[W][H];
		for(int i=0;i<H;i++)for(int j=0;j<W;j++)res[W-j-1][i] = a[i][j];
		return res;
	}
	
	void dfs(int i, int j, int U, int idx){
		if(j==w){
			dfs(i+1, 0, U, 0); return;
		}
		if(i==h){
			res[U] = true; return;
		}
		for(int u=idx;u<n;u++)if(((U>>u)&1)==0){
			for(R r:piece[u]){
				if(h < i+r.H || w < j+r.W)continue;
				boolean ok = true;
				for(int y=0;y<r.H;y++)if( (puzzle[i+y] & (r.p[y]<<(w-r.W-j))) != (r.p[y]<<(w-r.W-j))){
					ok = false; break;
				}
				if(!ok)continue;
				for(int y=0;y<r.H;y++){
					puzzle[i+y] -= (r.p[y]<<(w-r.W-j));
				}
				if(((puzzle[i]>>(w-j-1))&1)==0){
					dfs(i, j, U + (1<<u), u+1);
				}
				for(int y=0;y<r.H;y++){
					puzzle[i+y] |= (r.p[y]<<(w-r.W-j));
				}
				
			}
		}
		if(((puzzle[i]>>(w-j-1))&1)==0)
			dfs(i, j+1, U, 0);
	}
	
	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		piece = new List[10];
		res = new boolean[1024];
		for(;;){
			h = sc.nextInt(); w = sc.nextInt();
			if((h|w)==0)break;
			puzzle = new int[h];
			for(int i=0;i<h;i++){
				char[] s = sc.next().toCharArray();
				for(char c:s)puzzle[i] = (puzzle[i]<<1) + (c=='#'?0:1);
			}
			n = sc.nextInt();
			for(int i=0;i<n;i++){
				piece[i] = new ArrayList<R>();
				int H = sc.nextInt(), W = sc.nextInt();
				char[][] m = new char[H][];
				for(int j=0;j<H;j++)m[j]=sc.next().toCharArray();
				piece[i].add(new R(H, W, m));
				for(int k=0;k<3;k++){
					m = rot(m);
					int t = H;
					H = W; W = t;
					piece[i].add(new R(H, W, m));
				}
				for(int j=0;j<piece[i].size();j++)for(int k=j+1;k<piece[i].size();k++)if(piece[i].get(j).eq(piece[i].get(k))){
					piece[i].remove(k--);
				}
			}
			Arrays.fill(res, false);
			dfs(0, 0, 0, 0);
			int Q = sc.nextInt();
			while(Q--!=0){
				int k = sc.nextInt(), S = 0;
				while(k--!=0)S+=(1<<(sc.nextInt()-1));
				System.out.println(res[S]?"YES":"NO");
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
def gcd(x, y)
  if y > x
    tmp = x
    x = y
    y = tmp
  end
  return x if y == 0
  gcd(y, x % y)
end
     
x,y=gets.split.map &:to_i
#p gcd(x, y)

if y > x
  tmp = x
  x = y
  y = tmp
end
while y > 0
  r = x % y
  x = y
  y = r
end
p x



Measured memory_bytes: 6868
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

const int s_max = 3010;
const int t_max = 3010;

int dp[s_max][t_max];


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s,t;cin>> s >> t;
    rep(i,s_max) rep(j,t_max) dp[i][j] = 0;

    // dp[i][j] = dp[i-1][j], dp[i][j-1], dp[i-1][j-1]+1 if s[i]==t[j]
    
    rep(i,s.length()+1) rep(j,t.length()+1)
    {
        if (s[i]==t[j])
        {
            dp[i+1][j+1] = dp[i][j]+1;
        }
        else
        {
            dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
        }
    }

    // 復元する
    string ans = "";
    int n = s.length();
    int m = t.length();
    int ans_length = dp[n][m];
    int now_n = s.length();
    int now_m = t.length();
    rep(i,ans_length)
    {
        while(true)
        {
            if (dp[now_n][now_m]==dp[now_n-1][now_m])
            {
                now_n--;
            }
            else break;
        }
        while(true)
        {
            if (dp[now_n][now_m] == dp[now_n][now_m-1]) now_m--;
            else break;
        }
        ans += s[now_n-1];
        now_n--;
        now_m--;
        // cout << ans << endl;
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl; 
}


Measured memory_bytes: 35712
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

typedef long long ll;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;
        if (a == b) {
            cout << 2 * a - 2 << endl;
            continue;
        }
        ll l = 0, r = 1000000000;
        while (l < r) {
            ll m = (l + r + 1) / 2;
            if (m * m >= a * b) {
                r = m - 1;
            } else {
                l = m;
            }
        }
        if (l * (l + 1) < a * b) {
            cout << 2 * l - 1 << endl;
        } else {
            cout << 2 * l - 2 << endl;
        }
    }
}


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

int main() {
    int n;
    cin >> n;
    string s = "No";

    for(int i=1; i<=9; i++) {
        for(int j=1; j<=9; j++) {
            if(i*j == n) {
                s = "Yes";
                break;
            }
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 256
///...................SUBHASHIS MOLLICK...................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///....................SESSION-(14-15)....................///
#include<bits/stdc++.h>
using namespace std;
#define sf(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d",&a,&b)
#define sf3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pf2(a,b) printf("%d %d",a,b)
#define pf3(a,b,c) printf("%d %d %d",a,b,c)
#define sfl(a) scanf("%lld",&a)
#define sfl2(a,b) scanf("%lld %lld",&a,&b)
#define sfl3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pfl(a) printf("%lld",a)
#define pfl2(a,b) printf("%lld %lld",a,b)
#define pfl3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define MPI map<int,int>mp;
#define fr(i,n) for(i=0;i<n;i++)
#define fr1(i,n) for(i=1;i<=n;i++)
#define frl(i,a,b) for(i=a;i<=b;i++)
#define tz 100000
#define clr0(a) memset(a,0,sizeof(a))
#define clr1(a) memset(a,-1,sizeof(a))
/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697
*/
//freopen("Input.txt","r",stdin);
//freopen("Output.txt","w",stdout);
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
int main()
{
    timesave;
    ll n,k;
    cin>>n>>k;
    ll total=(n*(n+1)/2),x,xx,xxx,i,ans=0,mod=1000000007;
    for(i=k;i<=n+1;i++)
    {
        x=i*(i-1)/2;
        xxx=((n-i)*(n-i+1))/2;
        xx=(total-xxx)%mod;
        ll pls=((xx-x+1)%mod+mod)%mod;
        ans=((ans+pls)%mod+mod)%mod;
        ans%=mod;
    }
    cout<<ans%mod<<endl;
}






Measured memory_bytes: 3640
//Compete against Yourself.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 80;

int n, m, a[N][N], b[N][N];
gp_hash_table<int, int> dp[N][N];

void add(int x, int y, int red, int blue){
   if(x-1 >= 0){
      for(auto it: dp[x-1][y]){
         dp[x][y][abs(it.F+(red-blue))] = 1;
         dp[x][y][abs(it.F-(red-blue))] = 1;
      }
   }
   if(y-1 >= 0){
      for(auto it: dp[x][y-1]){
         dp[x][y][abs(it.F+(red-blue))] = 1;
         dp[x][y][abs(it.F-(red-blue))] = 1;
      }
   }
   if(x-1 < 0 and y-1 < 0){
      dp[x][y][abs(red-blue)] = 1;
   }
}


int32_t main(){_

   cin>>n>>m;

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

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

   for (int i = 0; i < n; ++i)
   {
      for (int j = 0; j < m; ++j)
      {
         add(i, j, a[i][j], b[i][j]);
      }  
   }
   
   int ans = 2e9;
   for(auto it: dp[n-1][m-1]){
      smin(ans, it.F);
   }

   cout<<ans;

   return 0;
}


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

int main() {
  int n, cnt = 0;
  ll d;
  cin >> n >> d;
  rep(i,n) {
    ll x, y;
    cin >> x >> y;
    if (d*d >= x*x + y*y) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3672
#include <iostream>
using namespace std;
int main(void){
    
    int a,b,c,d,e,count;
    int h1[101]={};
    int h2[101]={};
    int h3[101]={};
    count=0;
    cin>>a>>b;
    for(int i=0;i<b;i++){
        cin>>c;
        h1[c-1]=1;
    }
    cin>>d;
    for(int y=0;y<d; y++){
        cin>>c;
        h2[c-1]=1;
    }
    cin>>e;
    for(int u=0;u<e;u++){
        cin>>c;
        h3[c-1]=1;
    }
    for(int o=0;o<a;o++){
        if(h1[o]==0&&h2[o]==1&&h3[o]==1){
            count++;
        }else if(h1[o]==0&&h3[o]==1){
            count++;
        }else if(h2[o]==1&&h3[o]==1){
            count++;
        }
    }
    cout<<count<<endl;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define ALL(x) begin(x),end(x)
using namespace std;
typedef long long ll;
vector<pair<ll, ll>> factorize(ll n){
    vector<pair<ll, ll> > ret;
    for(ll p = 2 ; p <= n/p ; ++p){
        int e = 0;
        while(n%p == 0){
            n /= p;
            ++e;
        }
        if(e)   ret.push_back({p, e});
    }
    if(n > 1)   ret.push_back({n, 1});
    return ret;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k;
    cin >> n >> k;
    if(n == 1 || k == 1)
        cout << 1 << endl;
    else
    {
        vector<pair<ll, ll>> ans = factorize(__gcd(n, k));
        cout << ans.size() + 1 << endl;
    }
    return 0;
}






Measured memory_bytes: 256
n = input()    
m = n.split()
p = [int(i) for i in m] 
n = input()    
m = n.split()
q = [int(i) for i in m] 
q.sort(reverse=True)
A = 0
for i, value in enumerate(q):
    if i < p[1]:
        pass
    else:
        A = A + value
print(A)


Measured memory_bytes: 28444
import Control.Applicative ((<$>))
import Control.Monad (unless)

import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B

import Data.List (unfoldr, foldl')
import Data.Char (isSpace)

main :: IO ()
main = do
  n <- readLn
  unless (n == 0) $ do
    solve <$> readil B.readInt <$> B.getLine >>= putStrLn
    main

solve :: [Int] -> String
solve = g . foldl' f (0 , False)
  where f (ct, gt1) x = (ct + if x == 0 then 0 else 1, gt1 || x > 1)
        g (ct, gt1) | gt1 = show $ ct + 1
                    | otherwise = "NA"
readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr g
  where
    g s = do
      (n, s') <- f s
      return (n, B.dropWhile isSpace s')



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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int mod = 1000000007;

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

string S;
vector<int> cnt(2020, 0);

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

    cin >> S;

    ll N = S.size();
    reverse(ALL(S));

    ll total = 0;
    int ten = 1;

    cnt.at(0) = 1;

    REP(i, N) {
        total = (total + (S.at(i) - '0') * ten) % 2019;
        cnt.at(total)++;

        ten = (ten * 10) % 2019;    
    }

    ll ans = 0;

    REP(i, 2020) {
        ans += cnt.at(i) * (cnt.at(i) - 1) / 2;
    }

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

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

bool IsPrime[1000000];
int PrimeNum[1000000];

int main()
{
    for (int i = 0; i < 1000000; i++)
    {
        IsPrime[i] = true;
    }
    int count = 0;
    PrimeNum[0] = PrimeNum[1] = 0;
    for (int i = 2; i < 1000000; i++) {
        if (IsPrime[i]) {
            count++;
            PrimeNum[i] = count;
            for (int j = 2 * i; j < 1000000; j += i) {
                IsPrime[j] = false;
            }
        }
        else
        {
            PrimeNum[i] = PrimeNum[i - 1];
        }
    }
    int n;
    while (cin >> n)
    {
        cout << PrimeNum[n] << endl;
    }
    return 0;
}

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

int main() {
  ll x,y;
  cin>>x>>y;
  ll a=y/x;
  int ans=0;
  while(a>0){
    a/=2;
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}

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

#define MAX_N 108
#define MAX_M 216000
#define EPS (1e-13)
#define INF (1LL << 28)
template<typename T>
class MaxFlow{
private:
  struct Edge{
      int to, rev;
      T cap;
      Edge(int t, int r, T c){
        to = t;
        rev = r;
        cap = c;
      }
  };

  vector<Edge> edges[MAX_N];
  bool done[MAX_N];
public:
  void add_edge(int from, int to, T f){
    edges[from].push_back(Edge(to, edges[to].size(), f));
    edges[to].push_back(Edge(from, edges[from].size()-1, 0));
  }

  T dfs(int now, int t, T f){
    if(done[now])return 0;
    done[now] = true;
    if(now == t)return f;
    for(int i = 0;i < edges[now].size();i++){
      Edge &e = edges[now][i];
      if(e.cap < EPS)continue;
      T tmp = dfs(e.to, t, min(e.cap, f));
      if(tmp < EPS)continue;
      e.cap -= tmp;
      edges[e.to][e.rev].cap += tmp;
      return tmp;
    }
    return 0;
  }

  T max_flow(int s, int t){
    T res = 0;
    while(true){
      fill(done, done + MAX_N, false);
      T tmp = dfs(s, t, INF);
      if(tmp < EPS)return res;
      res += tmp;
    }
  }
};

int main(){
    int n, m, s, t, u, v, f;
    MaxFlow<int> mf;
    cin >> n >> m;
    s = 0;
    t = n-1;
    for(int i = 0;i < m;i++){
      cin >> u >> v >> f;
      mf.add_edge(u, v, f);
    }
    int tmp = mf.max_flow(s, t);
    cout << tmp << endl;
    return 0;
}



Measured memory_bytes: 3128
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
using namespace std;

const int N = 5000;
int n, m;
map<string, int> a;
int x[N], vstd[N];

typedef pair<int, int> P;

typedef struct edge_def {
  int from; int to; int cost;
  edge_def(int _from, int _to, int _cost) {
   from = _from; to = _to; cost =_cost;
  }
} edge;

vector<edge> es[N];

int dijkstra(int s) {
  priority_queue<int, vector<int>, greater<int> > q;
  
  int cnt = 1;
  int mx  = x[s];

  vstd[s] = 1;
  q.push(s);
  while(q.size()) {
    int v = q.top(); q.pop();
    for (int i=0; i<(int)es[v].size(); i++) {
      edge e = es[v][i];
      if (!vstd[e.to]) {
        mx = min(mx, x[e.to]);
        q.push(e.to);
        vstd[e.to] = 1;
        cnt++;
      }
    }
  }
  return mx * cnt;
}

int main() {
  int i;
  for (i=0; i<N; i++) es[i].clear();
  scanf("%d ", &n);
  for (i=0; i<n; i++) {
    string s; int v;
    cin >> s >> v;
    a[s] = i;
    x[i] = v;
  }
  
  scanf("%d ", &m);
  for (i=0; i<m;i++) {
    string f, t;
    cin >> f >> t;
    int fidx = a[f];
    int tidx = a[t];
    es[fidx].push_back(edge(fidx, tidx, 0));
    es[tidx].push_back(edge(tidx, fidx, 0));
  }
  
  memset(vstd, 0, sizeof(vstd));
  int res = 0;
  for (i=0; i<n; i++)
    if (!vstd[i]) res += dijkstra(i);
 
  printf("%d\n", res);

  return 0;
}

Measured memory_bytes: 2060
#include <stdio.h>
#define mod 1000000007
#define ll long long int

int c[2001][2001];

int main(void) {
    int n, k;
    scanf("%d%d", &n, &k);
    
    for (int i = 0; i <= 2000; i++) {
        for (int j = 0; j <= i; j++) {
            if (i == 0 || j == 0) c[i][j] = 1;
            else c[i][j] = (c[i-1][j-1] + c[i-1][j]) % mod;
        }
    }
    
    int r = n-k;
    for (int i = 1; i <= k; i++) {
        int rc = c[r+1][i];
        int bc = c[k-1][i-1];
        printf("%lld\n", ((ll) rc * bc) % mod);
    }
}



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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
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 (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

int main(){

    ll N, Q;
    cin >> N >> Q;
    dsu d(N);
    while(Q--){
        ll t, u, v;
        cin >> t >> u >> v;
        if(t) cout << d.same(u, v) << "\n";
        else d.merge(u, v);
    }

    return 0;
}

Measured memory_bytes: 3996
ans = input()
n = int(input())
for _ in range(n):
    o = input().split()
    a, b = map(int, o[1:3])
    b += 1
    c = o[0][2]
    if c == "p":
        ans = ans[:a] + o[3] + ans[b:]
    elif c == 'i':
        print(ans[a:b])
    else:
        ans = ans[:a] + ans[a:b][::-1] + ans[b:]


Measured memory_bytes: 5612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderTest
{
    class ABC163C
    {
        public static int readLineAsInt()
        {
            var line = Console.ReadLine();
            return int.Parse(line);
        }

        public static List<int> readLineAsListOfInt()
        {
            var line = Console.ReadLine();
            return line.Split(' ').Select(x => int.Parse(x)).ToList();
        }

        public static List<List<int>> readLinesAsTableOfInt(int N)
        {
            var ret = new List<List<int>>();
            for (int i = 0; i < N; ++i)
                ret.Add(readLineAsListOfInt());

            return ret;
        }

        public static List<int> readLinesAsListOfIntFromColumn(int N)
        {
            var ret = new List<int>();
            for (int i = 0; i < N; ++i)
                ret.Add(readLineAsListOfInt()[0]);

            return ret;
        }

        static void Main(string[] args)
        {
            var N = readLineAsInt();
            var As = readLineAsListOfInt();
            var res = core(N, As);

            for (int i = 0; i < N; ++i)
                Console.WriteLine(res[i].ToString());
        }

        static List<int> core(int N, List<int> As)
        {
            var table = new int[N];
            for (int i = 0; i < N; ++i)
                table[i] = 0;

            for (int i = 1; i < N; ++i)
                table[As[i - 1] - 1]++;

            return table.ToList();
        }
    }
}


Measured memory_bytes: 40868
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
#include<map>
#include <limits>
# include <iomanip>
#define INF 1000000009;
using namespace std;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}
int  miti[205][205];
int main() {
	int N = 0, M = 0, R = 0, r[9];
	int a = 0, b = 0, c = 0, sum = 0, ans = 1e9;
	vector<int> manji[201];
	cin >> N >> M >> R;
	for (int i = 0; i < R; i++) {
		cin >> r[i];
		//manji.push_back(r[i]);
	}
	sort(r, r + R);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (i == j) {
				miti[i][j] = 0;
			}
			else {
				miti[i][j] = INF;
			}
		}
	}
	for (int i = 0; i < M; i++) {
		cin >> a >> b >> c;
		miti[a - 1][b - 1] = c;
		miti[b - 1][a - 1] = c;

	}

	for (int j = 0; j < N; j++) {
		for (int i = 0; i < N; i++) {
			for (int k = 0; k < N; k++) {
					miti[i][k] = min(miti[i][k], miti[i][j] + miti[j][k]);
					//cout << i + 1 << ' ' <<j+1<<' '<< k + 1 << ' ' << miti[i][k] << endl;
				
			}
		}
	}
	do{
		sum = 0;
		for (int i = 0; i < R-1; i++) {
			sum+=miti[r[i]-1][r[i + 1]-1];
		}
		ans = min(ans, sum);
	} while (next_permutation(r, r + R));
	
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
X,N = gets.split.map &:to_i
if N==0 then
    puts X
    exit
end

p = gets.split.map &:to_i
unless p.include? X then
    puts X
    exit
end

d = 1
c = X
while true
    c = X - d
    break unless p.include? c
    p.delete c

    c = X + d
    break unless p.include? c
    p.delete c

    d+=1
end

puts c

Measured memory_bytes: 14388
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n;i++)
int main(void) {
	int n, A[100000], o = 0,ans =0;
	cin >> n;
	rep(i, n) cin >> A[i];
	rep(i, n - 1) {
        if (A[i] > A[i + 1]) {
            if (o == 2) {
                ans++;
                o = 0;
            }
            else o = 1;
        }
        else if (A[i] < A[i + 1]) {
            if (o == 1) {
                ans++;
                o = 0;
            }
            else o = 2;
        }
	}
	cout << ans + 1 << endl;
}

Measured memory_bytes: 640
n,t=[int(j) for j in input().split()]
ab=[]
ans=[]
dp=[0]*t
for i in range(n):
    tmp=[int(j) for j in input().split()]
    ab.append(tmp)
ab.sort()
for a,b in ab:
    for i in range(t)[::-1]:
        if dp[i]!=0 or i==0:
            if i+a>=t:
                ans.append(dp[i]+b)
            else:
                dp[i+a]=max(dp[i+a],dp[i]+b)
if ans:
    print(max(ans))
else:
    print(max(dp))

Measured memory_bytes: 139532
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int boxes = sc.nextInt();
        int operations = sc.nextInt();
        boolean[] redPossible = new boolean[boxes+1];
        redPossible[1]= true;
        int[] boxBalls = new int[boxes+1];
        int possibility = 0;
        for(int i = 1; i < boxBalls.length; i++){
                boxBalls[i] = 1;
            }
        for(int i = 0; i < operations; i++){
            int pick = sc.nextInt();
            int put = sc.nextInt();
            if(redPossible[pick]==true){
                    redPossible[put]=true;
            }
            boxBalls[pick] = boxBalls[pick]-1;
            boxBalls[put] = boxBalls[put]+1;
            if(boxBalls[pick]==0){
                    redPossible[pick]=false;
            }
            }
            for(int i = 0; i < redPossible.length; i++){
                if(redPossible[i]!=false){
                    possibility++;
                }
            }

            System.out.println(possibility);
    }
}


Measured memory_bytes: 65288
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>

using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

const ll INF = 1e15;
const double eps = 1e-6;
const ll MOD = 1000000007;

typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
	Edge(int src, int dst, Weight weight) :
		src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
ll N;
Graph g;
vector<int> visited;
vector<ll> d;
vector<ll> cnt;

void push(int now) {
	if (d[now] >= 3) {
		cnt[now]++;
		return;
	}
	visited[now] = true;
	for (auto &&e : g[now]) {
		if (!visited[e.dst])
			push(e.dst);
	}
}

int main() {
	ll N, K;
	cin >> N >> K;
	vector<vector<ll>> w(2 * K + 1, vector<ll>(2 * K + 1));
	vector<vector<ll>> b(2 * K + 1, vector<ll>(2 * K + 1));
	for (int i = 0;i < N;i++) {
		ll x, y; char c;
		cin >> x >> y >> c;
		if (c == 'W')
			w[y % (2 * K) + 1][x % (2 * K) + 1] += 1;
		else
			b[y % (2 * K) + 1][x % (2 * K) + 1] += 1;
	}
	for (int y = 1;y <= 2 * K;y++)
		for (int x = 1;x <= 2 * K;x++) {
			w[y][x] += w[y - 1][x] + w[y][x - 1] - w[y - 1][x - 1];
			b[y][x] += b[y - 1][x] + b[y][x - 1] - b[y - 1][x - 1];
		}
	ll answer = 0;
	for (ll bx = -2;bx <= 2 * K + 2;bx++)
		for (ll by = -2;by <= 2 * K + 2;by++) {
			ll ans = 0;
			for (ll yy = -3;yy <= 2;yy++)
				for (ll xx = -3; xx <= 2;xx++) {
					ll l = bx + xx * K;
					ll t = by + yy * K;
					ll tt = max(0LL, min(t + K, 2 * K));
					ll ll1 = max(0LL, min(l + K, 2 * K));
					int mt = max(min(t, 2*K), 0LL);
					int ml = max(min(l, 2*K), 0LL);
					if((yy + xx + 10) % 2)
						ans += b[tt][ll1] - b[tt][ml] - b[mt][ll1] + b[mt][ml];
					else
						ans += w[tt][ll1] - w[tt][ml] - w[mt][ll1] + w[mt][ml];
				}
			answer = max(ans, answer);
		}
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 62976
#include <bits/stdc++.h>
using namespace std;
#define testing 1
#define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i)
#define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <int, int> pi;
typedef tuple<int,int,int> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> void chmax(T& a, T b) { a = max(a, b); }
template <typename T> void chmin(T& a, T b) { a = min(a, b); }
const int MAXN = -1;
#if !testing
#define cerr if(0)cout
#endif

int32_t main() 
{
	IAMSPEED
	ll k; cin >> k;
	queue<ll>q;
	FOR(i,1,9){
		q.push(i);
	}
	ll lun;
	FOR(i,1,k){
		lun = q.front();q.pop();
		ll rem = lun % 10;
		if(rem!=0) {
			q.push(lun*10+rem-1);
		}
		q.push(lun*10+rem);
		if(rem!=9) {
			q.push(lun*10+rem+1);
		}
	}
	cout<<lun;
}



Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>
int main()
{
  char s[12];
  scanf("%s", &s);
  int f=0;
  if(!strcmp(s, "hi")) f=1;
  if(!strcmp(s, "hihi")) f=1;
  if(!strcmp(s, "hihihi")) f=1;
  if(!strcmp(s, "hihihihi")) f=1;
  if(!strcmp(s, "hihihihihi")) f=1;

  if(f==1) printf("Yes");
  else printf("No");
  return 0;
}
    

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>

using namespace std;

const double PI = acos(-1.0);

int main() {
	while (1) {
		int h, w;
		cin >> h >> w;

		if (h == 0 && w == 0) {
			return 0;
		}

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

	return 0;
}



Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;  cin >> n;
  char s[8] = {'1','2','3','4','5','6','7','8'};
  char p[n], q[n];
  for(int i=0 ; i<n ; i++){
    cin >> p[i];
  }
  for(int i=0 ; i<n ; i++){
    cin >> q[i];
  }
  int a=1,b=1;
  int count = 1;
  do{
    bool ok1=true, ok2 = true;
    for(int i=0 ; i<n ; i++){
      if(p[i]!=s[i]){
        ok1 = false;
        break;
      }
    }
    if(ok1) a = count;
    for(int i=0 ; i<n ; i++){
      if(q[i]!=s[i]){
        ok2 = false;
        break;
      }
    }
    if(ok2) b = count;
    count++;
  }while(next_permutation(s, s+n));
  cout << abs(a-b) << endl;
  return 0;
}


Measured memory_bytes: 256
h,w = map(int,input().split())
ma = []
count = 0
for _ in range(h):
    tmp_li = list(input())
    for t in tmp_li:
        if t == '#':
            count += 1
    ma.append(tmp_li)
if count != w+h-1:
    print('Impossible')
    exit()
if ma[0][0]!= '#':
    print('Impossible')
    exit()

li = [[0,0]]
def che(lis):
    lll = lis.pop(0)
    x = lll[0]
    y = lll[1]
    tmp = []
    if x+1 < w:
        #print(x+1,y,w,h,ma)
        if ma[y][x+1] == '#':
            tmp.append([x+1,y])
        if x+1 == w -1 and y == h -1:
            print('Possible')
            exit()
    if y+1 < h:
        if ma[y+1][x] == '#':
            tmp.append([x,y+1])
        if x == w -1 and y+1 == h -1:
            print('Possible')
            exit()
    if len(tmp) == 0:
        print('Impossible')
        exit()
    else:
        lis += tmp
    tmp = []
    #print(lis)
while len(li)>0:
    che(li)

Measured memory_bytes: 3064
a , b , c  = list(map(int ,input().split()))
if a ** 2  + b ** 2 + c ** 2 - 2 * ( a * b ) - 2 * (b * c) - 2 * (c * a) > 0 and c - a - b > 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007ll
//作者:中国江苏南京丁天行
using namespace std;
ll f[2005][2005],b[2005];
int n,k;
int main(){
    scanf("%d%d",&n,&k);
    b[0]=b[1]=1;
    for(int i=2;i<=n;++i)b[i]=b[i-1]*2ll%orz;
    for(int i=1;i<=n;++i)f[1][i]=1;
    for(int i=2;i<=k;++i){
        f[i][i]=f[i-1][i];
        for(int j=i+1;j<=n;++j)f[i][j]=(f[i-1][j]+f[i][j-1])%orz;
    }
    printf("%lld\n",f[k][n]*b[n-k]%orz);
	//system("pause");
	return 0;
}


Measured memory_bytes: 31104
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    int K,S;
    int cnt = 0;

//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());
    
    cin >> K >> S;

    for(int i = 0; i <= K; i++)
    {
        for(int j = 0; j <= K; j++)
        {
            if(S >= (i + j) && S - (i + j) <= K)cnt++;
        } 
    }

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



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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  
  ll ans = max({a * c, a * d, b * c, b * d});
  cout << ans << '\n';
}

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

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

using namespace std;

int main(){
	int n,k;
	string s; cin>>n>>k>>s;
	s[k-1]=tolower(s[k-1]);
	cout<<s<<endl;

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Text.RegularExpressions;
 
namespace SortingThreeNumbers{
    class class1{
        static void Main(string[] args){
            string input = "";
            int[] val = new int[3];
            var rx= new Regex(@"(?<a>\d+) (?<b>\d+) (?<c>\d+)$");
            while(!rx.IsMatch(input)){
                input = Console.ReadLine();
            }
            var m = rx.Match(input);
            val[0] = int.Parse(m.Groups["a"].Value);
            val[1] = int.Parse(m.Groups["b"].Value);
            val[2] = int.Parse(m.Groups["c"].Value);
             
            int tmp;
            for(int i=0;i<3;i++){
                for(int j=0;j<2;j++){
                    if(val[j]>val[j+1]){
                        tmp = val[j];
                        val[j] = val[j+1];
                        val[j+1] = tmp;
                    }
                }
            }
             
            Console.Write(val[0]+" "+val[1]+" "+val[2]+"\n");
             
        }
    }
}

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

int main(void){
    vector<int> n(110),x(110);
    for(int i=0;i<110;i++){
        cin>>n.at(i)>>x.at(i);
        if(n.at(i)==0 && x.at(i)==0)break;
    }
    int cnt=0;
    
    for(int I=0;I<110;I++){
        if(n.at(I)==0 && x.at(I)==0)break;
    for(int i=0;i<n.at(I);i++){
        for(int j=0;j<n.at(I);j++){
            for(int k=0;k<n.at(I);k++){
                if(i+k+j+3==x.at(I) && i!=j && i!=k && j!=k)cnt++;
            }
        }
    }
        cout<<cnt/6<<endl;
        cnt=0;
    }
}



Measured memory_bytes: 3072
n = int(input())
s = input()

def loop():
    for i in range(1, n-1):
        if ans[i] == 'S':
            if s[i] == 'x':
                if ans[i-1] == 'S':         
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
            else:
                if ans[i-1] == 'W':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
        else:
            if s[i] == 'o':
                if ans[i-1] == 'S':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'
            else:
                if ans[i-1] == 'W':
                    ans[i+1] = 'W'
                else:
                    ans[i+1] = 'S'

ans = ['S'] * n
if s[0]  == 'x':
    ans[1] = 'W'
else:
    ans[1] = 'S'
loop()
if ans[n-1] == 'S':
    if (s[n-1] == 'o' and ans[n-2] == 'S') or (s[n-1] == 'x' and ans[n-2] == 'W'):
        print(''.join(ans))
        exit()

ans = ['W'] * n
if s[0]  == 'x':
    ans[1] = 'W'
else:
    ans[1] = 'S'
loop()
if ans[n-1] == 'W':
    if (s[n-1] == 'x' and ans[n-2] == 'W') or (s[n-1] == 'o' and ans[n-2] == 'S'):
        print(''.join(ans))
        exit()

ans = ['W'] * (n-1) + ['S']
if s[0]  == 'x':
    ans[1] = 'S'
else:
    ans[1] = 'W'
loop()
if ans[n-1] == 'S':
    if (s[n-1] == 'x' and ans[n-2] == 'S') or (s[n-1] == 'o' and ans[n-2] == 'W'):
        print(''.join(ans))
        exit()

ans = ['S'] * (n-1) + ['W']
if s[0]  == 'x':
    ans[1] = 'S'
else:
    ans[1] = 'W'
loop()
if ans[n-1] == 'W':
    if (s[n-1] == 'x' and ans[n-2] == 'S') or (s[n-1] == 'o' and ans[n-2] == 'W'):
        print(''.join(ans))
        exit()

print(-1)


Measured memory_bytes: 5604
def find(A,B,C):
    A=[x-1 for x in A]
    ans=B[A[len(A)-1]]
    for i in range(len(A)-1):
        now=A[i]
        next_one=A[i+1]
        if next_one==now+1:
            ans+=C[now]
        ans+=B[A[i]]
    return ans

N=int(input())
A=list(map(int,input().strip().split(" ")))
B=list(map(int,input().strip().split(" ")))
C=list(map(int,input().strip().split(" ")))

print(find(A,B,C))
        

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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr ll mod = static_cast<ll>(1e9 + 7);
constexpr long long MOD(long long in) {
	return in % mod;
}

int n, k;
std::vector<int> g[100005];
bool used[100005];
int one[100005], two[100005];
int main()
{
	std::cin >> n >> k;
	std::fill(used, used + n, false);

	int f;
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		std::cin >> a >> b;
		a--, b--;

		if (i == 0)
			f = a;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	std::queue<int> que;
	que.push(f);
	ll ans = 1;
	while (!que.empty()) {
		auto p = que.front();
		que.pop();

		if (!used[p]) {
			used[p] = true;
			ans = MOD(ans * (k - one[p] - two[p]));

			for (int i = 0; i < (int)g[p].size(); i++) {
				auto v = g[p][i];

				if (used[v])
					continue;

				one[p]++;
				one[v] = 1;
				two[v] = std::max(0, one[p] - 1);
				que.push(v);
			}
		}
	}

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


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

int main(){
  while(1){
    long int a,b,dab,count=0;
    cin >> a >> b;
    if(a==0 && b == 0) break;
    if(a<b) swap(a,b);
    while(1){
      dab=a%b;
      a=b;
      b=dab;
      count++;
      if(dab==0) break;
    }
    cout << a << " " << count << endl;
  }
  return 0;
}

Measured memory_bytes: 3076
#include<iostream>
#include <bits/stdc++.h>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;


int main(){
    int S,W;
    cin >>S >> W;
    if(S<=W){
        cout << "unsafe"<< endl;
    }
    else{
        cout << "safe" <<endl;
    }
    return 0;
}

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

using namespace std;

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

const int MM = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 2e5 + 10;

int n, m;
int a[MAXN];

void read(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)	
		scanf("%d", &a[i]);
	scanf("%d", &m);
}

int fa[20][MAXN];

void solve(){
	a[n + 1] = 2e9 + 10;
	for(int i = 1; i <= n; i++){
		fa[0][i] = lower_bound(a + i + 1, a + n + 2, a[i] + m + 1) - a - 1;
	}
	int cnt = 0;
	for(int j = 0, k = 1; k <= n; j++, k *= 2){
		for(int i = 1; i <= n; i++)
			fa[j+1][i] = fa[j][fa[j][i]];//fa[fa[i][j]][j];
		cnt++;
	}
	assert(cnt < 20);
	int Q;
	scanf("%d", &Q);
	for(int o = 1; o <= Q; o++){
		int x, y;
		scanf("%d%d", &x, &y);
		if (x > y) swap(x, y);
		int ans = 0;
		for(int i = cnt; i >= 0; i--){
			if (fa[i][x] < y){
				ans += (1 << i);
				x = fa[i][x];
			}
		}
		while(x < y){
			ans++;
			x = fa[0][x];
		}
		printf("%d\n", ans);
	}
}

void printans(){

}
	

int main(){
	int T = 1;
//	cin>>T;
	while(T--){
		read();
		solve();
		printans();
	}
	return 0;
} 


Measured memory_bytes: 8320
#!/usr/bin/env python
H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]
ds = [(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)]
for i in range(H):
    for j, c in enumerate(A[i]):
        if c == '.':
            cnt = 0
            for d in ds:
                x = j + d[0]
                y = i + d[1]
                if 0 <= x <= W - 1 and 0 <= y <= H - 1 and A[y][x] == '#':
                    cnt += 1
            A[i][j] = str(cnt)

for i in range(H):
    print(''.join(A[i]))


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

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back
#define DEBUG(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> inline T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

inline void proc_status ()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) << endl;
}

const int Maxn = 2e5 + 100;

int N, Sum[Maxn];
char S[Maxn];

inline void Solve ()
{
	LL ans = 0;
	for (int i = 1; i <= N; ++i) if (S[i] == 'W') ans += Sum[i];
	cout << ans << endl;
}

inline void Input ()
{
	scanf("%s", S + 1);
	N = strlen (S + 1);
	for (int i = 1; i <= N; ++i) Sum[i] = Sum[i - 1] + (S[i] == 'B'); 
}

int main()
{

#ifdef hk_cnyali
	freopen("A.in", "r", stdin);
	freopen("A.out", "w", stdout);
#endif

	Input ();
	Solve ();

	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
const int maxn = 2e5 + 10;
typedef pair<int,int> pii;
int n,k,l;
int f1[maxn],f2[maxn];
int fd(int fa,int f[]){
	if(f[fa] == fa)return fa;
	else return f[fa] = fd(f[fa],f);
}
int main(){
	scanf("%d%d%d",&n,&k,&l);
	map<pii,int> cnt;
	rep(i,1,n)f1[i] = f2[i] = i;
	rep(i,1,k){
		int u,v;
		scanf("%d%d",&u,&v);
		u = fd(u,f1); v = fd(v,f1);
		if(u != v)f1[u] = v;
	}
	rep(i,1,l){
		int u,v;
		scanf("%d%d",&u,&v);
		int tu = fd(u,f2), tv = fd(v,f2);
		if(tu != tv)f2[tu] = tv;
	}
	rep(i,1,n){
		int a = fd(i,f1), b = fd(i,f2);
		cnt[make_pair(a,b)]++;
	}
	rep(i,1,n){
		int a = fd(i,f1), b = fd(i,f2);
		printf("%d", cnt[make_pair(a,b)]);
		printf(i==n?"\n":" ");
	}
	return 0;
}

Measured memory_bytes: 13568
// In the name of God
#include <bits/stdc++.h>

using namespace std;
#define Size(x) ((int)(x).size())
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int INF = 1e9 + 10;

ll a,b;

bool check(ll val)
{
	ll lft = max(0ll , val-a);
	if(lft*2 + 2*val <= b) return true;
	return false;
}

int main()
{
	ios_base :: sync_with_stdio(false) ,cin.tie(0) , cout.tie(0);
	cin >> a >> b;
	ll L = 0 , R = (ll)1e12 + 10;
	while(L != R){
		ll mid = (L+R+1)/2;
		if(check(mid)) L = mid;
		else R = mid-1;
	}
	cout << L << '\n';
	return 0;
}


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

int main(){
  int N;
  cin>>N;
  if(N%10==N/10%10&&N/10%10==N/100%10)
    cout<<"Yes"<<endl;
  else{
    if(N/10%10==N/100%10&&N/100%10==N/1000)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    }
  }

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int A[110][110],i,j,a,b,B[10010],n,k=1;
	cin>>a>>b;
	cin>>n;
	for(i=1;i<=n;i++) cin>>B[i];
	for(i=1;i<=a;i++){
		if(i%2!=0){
			for(j=1;j<=b;j++){
				A[i][j]=k;
				B[k]--;
				if(B[k]==0) k++;
			}
		}
		else{
			for(j=b;j>=1;j--){
				A[i][j]=k;
				B[k]--;
				if(B[k]==0) k++;
			}
		}
	}
	for(i=1;i<=a;i++){
		for(j=1;j<b;j++){
			cout<<A[i][j]<<" ";
		}
		cout<<A[i][b]<<endl;
	}
	return 0;
}

Measured memory_bytes: 384