akhauriyash/Code-Regression huggingface dataset:
h, w = map(int, input().split())

def cl(sx, sy, m):
    Z = -1
    x_len = len(m[0])
    y_len = len(m)
    dist = [[Z for i in range(x_len)]
                for j in range(y_len)]
    for i in range(y_len):
        for j in range(x_len):
            if m[i][j] == '#':
                dist[i][j] = -1

    def bfs():
        q = []
        q.insert(0, (sx, sy))
        dist[sy][sx] = 0
        while len(q):
            x, y = q.pop()
            for i in range(0, 4):
                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]
                if (0 <= nx < x_len and 0 <= ny < y_len and m[ny][nx] != '#' and dist[ny][nx] == Z):
                    q.insert(0, (nx, ny))
                    dist[ny][nx] = dist[y][x] + 1
        
        return dist
    return bfs()

S = [list(input()) for _ in range(h)]
ans = 0
for y in range(h):
    for x in range(w):
        start = S[y][x]
        if start != '#':
            num = cl(x, y, S)
            for k in range(h):
                ans = max(ans, max(num[k]))
print(ans)


Measured memory_bytes: 48476
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  while(n!=0){
    int i;
    double s[1000]={},sum=0,a=0;
    for(i=0;i<n;i++){
      cin >> s[i];
      sum+=s[i];
    }
    for(i=0;i<n;i++){
      a+=((sum/n)-s[i])*((sum/n)-s[i])/n;
    }
    printf("%.5f\n",sqrt(a));
    cin >> n;
  }
  
  return 0;
}


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

const ll mod = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  if (s[0] == s[(int)s.size() - 1]) {
    if (s.size() % 2 == 0) {
      cout << "First" << endl;
    } else {
      cout << "Second" << endl;
    }
  } else {
    if (s.size() % 2 == 0) {
      cout << "Second" << endl;
    } else {
      cout << "First" << endl;
    }
  }
  return 0;
}


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

namespace ConsoleApp15
{
    class Class16
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            long[] march = new long[5];
            for (int i = 0; i < 5; i++) march[i] = 0;

            for (int i = 0; i < N; i++)
            {
                var r = Console.ReadLine();
                if (r[0] == 'M')
                    march[0]++;
                else if (r[0] == 'A')
                    march[1]++;
                else if (r[0] == 'R')
                    march[2]++;
                else if (r[0] == 'C')
                    march[3]++;
                else if (r[0] == 'H')
                    march[4]++;
            }

            long count = 0;
            for(int i = 0; i <= 2; i++)
            {
                for(int j = i + 1; j <= 3; j++)
                {
                    for(int k = j + 1; k <= 4; k++)
                    {
                        count += march[i] * march[j] * march[k];
                    }
                }
            }
            Console.WriteLine(count);
        }
    }
}


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

int main()
{
    int n;
    cin>>n;
    long long int a[n+1],c[n+1],b[n];
    for(int i=0;i<=n;i++)
    {
        cin>>a[i];
        //c[i]=a[i];
    }
    for(int i=0;i<n;i++)
        cin>>b[i];
    long long int x=0;
    if(a[0]<=b[0])
    {
        x+=a[0];
        b[0]-=a[0];
        a[0]=0;
    }
    else
    {
        x+=b[0];
        a[0]-=b[0];
        b[0]=0;
    }
    //cout<<x;
    for(int i=1;i<=n;i++)
    {
        if(a[i]<=b[i-1])
        {
            b[i-1]-=a[i];
            x+=a[i];
            a[i]=0;

        }
        else
        {
            a[i]-=b[i-1];
            x+=b[i-1];
            b[i-1]=0;
        }
        if(a[i]>0 && i<n)
        {
            if(a[i]<=b[i])
            {
                b[i]-=a[i];
                x+=a[i];
                a[i]=0;
            }
            else
            {
                a[i]-=b[i];
                x+=b[i];
                b[i]=0;
            }
        }
    }
    cout<<x;
}


Measured memory_bytes: 1792
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Collections;

public class Main{
	static class Data{
		int t1,t2;
		Data(int T1,int T2){ t1=T1; t2=T2; }
	};

	static class Cmp implements Comparator<Data>{
		public int compare(Data d1,Data d2){
			if(d1.t1!=d2.t1) return d1.t1-d2.t1;
			return d1.t2-d2.t2;
		}
	}

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

		while(true){
			int n=sc.nextInt();
			int m=sc.nextInt();
			if(n==0) break;

			List<List<Data>> A=new ArrayList<List<Data>>();
			for(int i=0;i<m;i++) A.add(new ArrayList<Data>());

			int r=sc.nextInt();
			{
				int[] last=new int[n];
				for(int i=0;i<r;i++){
					int t=sc.nextInt();
					int a=sc.nextInt()-1;
					int b=sc.nextInt()-1;
					int s=sc.nextInt();
					if(s==1) last[a]=t;
					else     A.get(b).add(new Data(last[a],t));
				}
			}

			for(int i=0;i<m;i++) Collections.sort(A.get(i),new Cmp());

			int q=sc.nextInt();
			for(int i=0;i<q;i++){
				int t1=sc.nextInt();
				int t2=sc.nextInt();
				int b=sc.nextInt()-1;

				int ans=0,last=t1;
				for(Data D:A.get(b)){
					last=Math.max(last,D.t1);
					ans+=Math.max(Math.min(D.t2,t2)-last,0);
					last=Math.max(last,D.t2);
				}
				System.out.println(ans);
			}
		}

		return;
	}
}

Measured memory_bytes: 71760
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl;
#define INF 1ll<<60;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main(){
    int n; cin >> n;
    int w[n];
    int all=0;
    rep(i, n){
        cin >> w[i];
        all+=w[i];
    }

    int ans=100100, s1=0, s2=0;
    rep(i, n){
        s1+=w[i];
        s2 = all-s1;
        if(ans>abs(s1-s2)){
            ans = abs(s1-s2);
        }
    }
    out(ans);
}

Measured memory_bytes: 3584
def resolve():
    k, a, b = map(int, input().split())
    if b - a > 1:
        n = max(0, int((k - (a - 1)) // 2))
        ans = 1 + (k - 2 * n) + (b - a) * n
        print(ans)
        return 0
    else:
        print(k + 1)
        return 0


if __name__ == "__main__":
    resolve()


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

int main(){
	int N;
	cin >> N;
	if (N < 105) {
		puts("0");
	}
	else if (N < 135) {
		puts("1");
	}
	else if (N < 165) {
		puts("2");
	}
	else if (N < 189) {
		puts("3");
	}
	else if (N < 195) {
		puts("4");
	}
	else {
		puts("5");
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 5000000
int H[MAX],n;

void maxHeapify(int h){
  int r,l,big,temp;
  r = (h*2)+1;
  l = h*2;
  
  if(H[l] > H[h] && l <= n)
    big = l;
  else
    big = h;
  if(n >= r && H[r] > H[big])
    big = r;
  
  if(big != h){
    temp = H[h];
    H[h] = H[big];
    H[big] = temp;
    maxHeapify(big);
  }
}

void buildMaxHeap(void){
  int i;
  for(i=n/2;i>=1;i--) {
    maxHeapify(i);
  }
}
    
int main(){
  int i;
  
  scanf("%d",&n);

  for(i=1;i<=n;i++)
    scanf("%d",&H[i]);

  buildMaxHeap();

  for(i=1;i<=n;i++)
    printf(" %d",H[i]);
  printf("\n");

  return 0;
}



Measured memory_bytes: 3808
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;


int main(){
	int n, k;
	int hate[10];
	scanf("%d%d", &n, &k);
	fill(hate, hate + 10, 10);
	for (int i = 0; i < k; i++){
		scanf("%d", &hate[i]);
	}
	int i;
	for (i = n;; i++){
		string s = to_string(i);
		bool flag = true;
		for (int j = 0; j < k; j++){
			if ((int)s.find(to_string(hate[j])) >= 0)flag = false;
		}
		if (flag)break;
	}
	printf("%d\n", i);
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a, d = gets.split.map(&:to_i)
m = gets.to_i
ops = (1..m).map { gets.split.map(&:to_i) }
k = gets.to_i
until ops.empty?
    x, y, z = ops.pop
    if x == 0
        if y == k
            k = z
        elsif z == k
            k = y
        end
    else
        k = z if y == k
    end
end
p a + (k - 1) * d


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

int main (){
string a,b;
cin>>a>>b;
if(a=="H"&&b=="D") cout <<"D";
if(a=="H"&&b=="H") cout <<"H";
if(a=="D"&&b=="D") cout <<"H";
if(a=="D"&&b=="H") cout <<"D";
return 0;
}


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

int main() {
	char c[100]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
	ll n;
	string s;
	cin>>n>>s;
	for(int i=0;i<s.size();i++){
		for(int j=0;j<30;j++)if(s[i]==c[j]){
			s[i]=c[j+n];
			break;
		}
	}
	cout<<s;
	return 0;
}


Measured memory_bytes: 256
import           Data.Char
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed   as U

main :: IO ()
main = do
  n <- readLn
  ws <- U.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
  print $ solve ws

solve :: U.Vector Int -> Int
solve = U.minimum . U.map abs . (U.zipWith (-) <$> U.scanl' (+) 0 <*> U.scanr (+) 0)

Measured memory_bytes: 508
import numpy as np
N, M, C = map(int, input().split(" "))
lis_b = np.array(input().split(" "), dtype=np.int)
num_correct = 0

for i in range(N):
  lis_a = np.array(input().split(" "), dtype=np.int)
  if ((lis_a * lis_b).sum() + C) > 0:
    num_correct += 1

print(num_correct)

Measured memory_bytes: 12500
n,A,B,C = map(int,input().split())
l = [int(input()) for _ in range(n)]

# まず深さ優先探索で扱い方の全通りを列挙する
# 引数depth本分の竹を選んど時の、A,B,Cでそれぞれ扱う竹の総和を引数a,b,cで表す。
def dfs(depth,a,b,c,):
  # 全部の竹の配分が完了したら、A,B,Cに合わせるのに何MP必要か計算する
  if depth == n:
    if min(a,b,c) > 0:
      return abs(a-A) + abs(b-B) + abs(c-C) - 30
    else:
      return 10**9
  # 分岐は４つに別れるためdfsも4つ再帰する
  # 適用する場合 = 合成する場合となるので+10する
  # 初回に余分な+10はreturn時に-30で打ち消す
  # l[depth]の竹をaに適用する場合
  numA = dfs(depth+1,a+l[depth],b,c) + 10
  # l[depth]の竹をbに適用する場合
  numB = dfs(depth+1,a,b+l[depth],c) + 10
  # l[depth]の竹をcに適用する場合
  numC = dfs(depth+1,a,b,c+l[depth]) + 10
  # l[depth]の竹を適用しない場合
  numX = dfs(depth+1,a,b,c)
  return min(numA,numB,numC,numX)
print(dfs(0,0,0,0))


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }



void solve(void)
{
  string str;
  cin>>str;
  int K;cin>>K;
  int N = str.size();
  int MODE = 1;
  for (int i = 0; i < N-1; i++)
  {
    if(str[i] == 'a')continue;
    if(K >= 'z' - str[i] +1)
    {
      K -= (int)('z' + 1 - str[i]);
      str[i] = 'a';
      // DEBUG(K);
    }
  }
  str[N-1] = (int)(str[N-1] - 'a' + K)%26 + char('a');
  cout<<str<<endl;
  return;
}




int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
const int maxn=405;
int n,Size,head[maxn],dis[maxn][maxn];
struct edge
{
	int to,next;
}E[maxn*maxn*2];
inline void add(int u,int v)
{
	E[++Size].to=v;
	E[Size].next=head[u];
	head[u]=Size;
	dis[u][v]=dis[v][u]=1;
}
bool color[maxn],vis[maxn];
inline bool check()
{
	queue<int>Q;
	Q.push(1);
	vis[1]=1;
	while(!Q.empty())
	{
		int u=Q.front();
		Q.pop();
		for(int i=head[u];i;i=E[i].next)
		{
			int v=E[i].to;
			if(vis[v]&&color[u]==color[v])
				return false;
			else if(!vis[v])
			{
				vis[v]=1,color[v]=1-color[u];
				Q.push(v);
			}
		}
	}
	return true;
}
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
			dis[i][j]=dis[j][i]=n+1;
	for(int i=1;i<=n;++i)
	{
		string s;
		cin>>s;
		for(int j=0;j<n;++j)
			if(s[j]=='1')
				add(i,j+1),add(j+1,i);
	}
	if(!check())
	{
		cout<<-1<<endl;
		return 0;
	}
	for(int k=1;k<=n;++k)
		for(int i=1;i<=n;++i)
			for(int j=1;j<=n;++j)
				dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
	int ans=0;
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
			ans=max(ans,dis[i][j]);
	cout<<ans+1<<endl;
	return 0;
}


Measured memory_bytes: 4496
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define fi first
#define se second

using Graph = vector<vector<int>>;




int main() {
    ll n;
    cin>>n;
    queue<ll>que;
    for(ll i=1;i<=9;i++){
        que.push(i);
    }
    ll tmp=0;
    for(ll i=0;i<n;i++){
        tmp=que.front();
        que.pop();
        ll t=tmp%10;
        // cout<<"tmp="<<tmp<<endl;
        if(t==0){
            que.push(10*tmp);
            que.push(10*tmp+1);
        }
        else if(t==9){
            que.push(10*tmp+t-1);
            que.push(10*tmp+t);
        }
        else{
            que.push(10*tmp+t-1);
            que.push(10*tmp+t);
            que.push(10*tmp+t+1);
        }
        // cout<<que.size()<<endl;
    }
    cout<<tmp<<endl;



    return 0;
}


Measured memory_bytes: 1792
N = int(input())
A = list(map(int, input().split()))
count = 0

for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      if A[i] != A[j] and A[j] != A[k] and A[k] != A[i] and (A[i] + A[j]>A[k]) and (A[j] + A[k]>A[i]) and (A[k] + A[i]>A[j]):
        count = count + 1

print(count)



Measured memory_bytes: 9200
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep2(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)

int main(){

    int n; cin >> n;
    int a[n], b[n], c[n-1];
    rep(i, n){
        cin >> a[i];
        a[i]--;
    }
    rep(i, n){
        cin >> b[i];
    }
    rep(i, n-1){
        cin >> c[i];
    }


    int ans = 0;
    rep(i, n){
        ans += b[a[i]];
        if(i != 0){
            if(a[i] == a[i-1]+1){
                ans += c[a[i-1]];
            }
        }
    }
    
    cout << ans;
}

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

using namespace std;

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

	int h, w, k;
	cin >> h >> w >> k;
	char arr[h][w];
	for(int i=0; i<h; i++)
        for(int j=0; j<w; j++)
            cin >> arr[i][j];
    int ans=0;
    for(int i=0; i<(1<<h); i++){
        for(int j=0; j<(1<<w); j++){
            int cnt=0;
            for(int m=0; m<h; m++){
                for(int n=0; n<w; n++){
                    if(((i>>m)&1)>0 || ((j>>n)&1)>0)
                        continue;
                    if(arr[m][n]=='#')
                        cnt++;
                }
            }
            if(cnt==k)
                ans++;
        }
    }
    cout << ans << endl;

	return 0;
}


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

int main(){
	int N=0,W=0,H=0,S=0,T=0;
	bool tree_exist[100][100];
	int cnt,max;

	while(1){

		cin >> N;
		if(N==0) break;

		cin >> W >> H;
		for(int i=0;i<W;i++) for(int j=0;j<H;j++) tree_exist[i][j]=false;

		int x,y;
		for(int i=0;i<N;i++){
			cin >> x >> y;
			tree_exist[x-1][y-1] = true;
		}

		cin >> S >> T;

		for(int i=0;i<W-S+1;i++){ // ðÚ®³¹é
			for(int j=0;j<H-T+1;j++){
				for(int k=0;k<S;k++){ // ÌÌØÌ{ð²×é
					for(int l=0;l<T;l++){
						if(tree_exist[i+k][j+l]) cnt++;
					}
				}
				if(cnt>max) max = cnt;
				cnt=0;
			}
		}

		cout << max << endl;
		max=0;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(void){

	vector< bool > isP( 60000, true );
	isP[0] = false;
	isP[1] = false;
	for( int i = 2; i < 60000; i++ ) {
		if( !isP[i] ) continue;
		for( int j = 2 * i; j < 60000; j+=i ) {
			isP[j] = false;
		}
	}

	int n;
	while( scanf("%d", &n) != EOF ) {
		int min, max;
		for( int i = n + 1;;i++ ) {
			if( isP[i] ) {
				max = i;
				break;
			}
		}
		for( int i = n - 1;; i-- ) {
			if( isP[i] ) {
				min = i;
				break;
			}
		}
		cout << min << " " << max << endl;
	}

    return 0;
}

Measured memory_bytes: 1212
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Ans = sum(B)
AT = []
for i in range(N//2+1):
  AT+=[[i,i],[i+1,i]]
  AT+=[[N-i,N-i-1],[N-i-1,N-i-1]]
AT = AT[:2*N]
for i in AT:
  X = min(A[i[0]],B[i[1]])
  A[i[0]]=A[i[0]]-X
  B[i[1]]=B[i[1]]-X
Ans = Ans - sum(B)
print(Ans) 

Measured memory_bytes: 42560
N = int(input())
A = [0]+[int(input()) for _ in range(N)]

v = set()
v.add(1)
x = 1
a = 0
while True:
  x = A[x]
  a += 1
  if x in v:
    print(-1)
    break
  if x == 2:
    print(a)
    break
  v.add(x)  

Measured memory_bytes: 13724
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
bool kebalik=0;
ll q, rivers=0;
string s;

int main(){
	IOS
	cin >> s >> q;
	while(q--){
		string a, b, c;
		cin >> a;
		if(a=="1"){
			rivers++;
			if(kebalik){
				kebalik=0;
			}
			else{
				if(s.size()>1) kebalik=1;
			}
		}
		else{
			cin >> b >> c;
			if(b=="1"){
				if(!kebalik){
					s.insert(0, c);
				}
				else{
					s+=c;
				}
			}
			else{
				if(!kebalik){
					s+=c;
				}
				else{
					s.insert(0, c);
				}
			}
		}
	}
	if(rivers&1){
		reverse(s.begin(), s.end());
	}
	cout << s << '\n';
}


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

typedef vector<int> vi;

// Union-Find Disjoint Sets Library written in OOP manner, using both path compression and union by rank heuristics
class UnionFind {                                              // OOP style
	private:
		vi p, rank, setSize;                       // remember: vi is vector<int>
		int numSets;
	public:
		UnionFind(int N) {
			setSize.assign(N, 1); numSets = N; rank.assign(N, 0);
			p.assign(N, 0); for (int i = 0; i < N; i++) p[i] = i; }
		int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
		bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
		void unionSet(int i, int j) { 
			if (!isSameSet(i, j)) { numSets--; 
				int x = findSet(i), y = findSet(j);
				// rank is used to keep the tree short
				if (rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; }
				else                   { p[x] = y; setSize[y] += setSize[x];
					if (rank[x] == rank[y]) rank[y]++; } } }
		int numDisjointSets() { return numSets; }
		int sizeOfSet(int i) { return setSize[findSet(i)]; }
};

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N,M; cin>>N>>M;
	UnionFind uf(N);
	int ret=1;
	for (int i=0; i<M; i++) {
		int A,B; cin>>A>>B; A--; B--;
		uf.unionSet(A,B);
		ret=max(ret,uf.sizeOfSet(A));
	}
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 5540
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double w = sc.nextDouble(),h = sc.nextDouble();
		double x = sc.nextDouble(),y = sc.nextDouble();
		if(x == w / 2 && y == h / 2) {
			System.out.print((w*h)/2+" ");
			System.out.println(1);
		}else {
			System.out.print((w*h)/2+" ");
			System.out.println(0);
		}
	}
	
}

Measured memory_bytes: 23252
n = gets.to_i
s = Hash.new(0)
n.times do 
 ss = gets.to_s
 s[ss] += 1
end

m = gets.to_i
t = Hash.new(0)
m.times do
    tt = gets.to_s
    t[tt] += 1
end

a = s.keys
ans = 0
a.each do |i|
    if ans < s[i] - t[i]
        ans = s[i] - t[i]
    end
end
puts ans 

Measured memory_bytes: 1788
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let k = read(&mut stdin_lock, &mut buf, b'\n');
    println!("{}", solve(k));
}

fn solve(a: i32) -> i32 {
    (a / 2) * (a / 2 + if a % 2 == 0 { 0 } else { 1 })
}

#[test]
fn example1() {
    assert_eq!(2, solve(3))
}

#[test]
fn example2() {
    assert_eq!(9, solve(6))
}

#[test]
fn example3() {
    assert_eq!(30, solve(11))
}

#[test]
fn example4() {
    assert_eq!(625, solve(50))
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A=sc.nextInt(),B=sc.nextInt(),C=sc.nextInt();
		if((A-B) < C) {
			System.out.println(C - (A - B));
		}else{
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 23124
// https://atcoder.jp/contests/abc018/tasks/abc018_4

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e18;

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
// 入力
// int H, W;
vector<vector<char>> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int main() {

  int N, K;
  string S;

  cin >> N >> K;
  cin >> S;

  int count = 0;
  REP(i, N){
    if(S[i-1]==S[i]){
      count++;
    }
  }

  int maxnum = N-1;
  if( count + 2 * K < maxnum ){
    maxnum = count + 2 * K;
  }
  cout << maxnum << endl;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N, M; long long int P; 
	cin >> N >> M >> P;
	int A[5010] = {}, B[5010] = {};
	long long int C[5010] = {}; 
	long long int D[2510] = {}; 
	long long int INF = 1e15; 
	for(int i = 0; i < M; i++){
		cin >> A[i] >> B[i] >> C[i]; 
		C[i] -= P; C[i] *= -1; 
	}
	for(int i = 2; i <= N; i++){
		D[i] = INF; 
	}
	long long int x, y; 
	for(int i = 0; i < N * 8; i++){
		for(int j = 0; j < M; j++){
			if(D[A[j]] != INF && D[B[j]] > D[A[j]] + C[j]){
				D[B[j]] = D[A[j]] + C[j];
			}
		}
		if(i == N - 1) x = D[N]; 
		if(i == N * 8 - 1) y = D[N]; 
	}
	if(x != y) cout << -1 << endl; 
	else cout << max(- y, 0LL) << endl; 
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 212345;
ll H[MAX_N];

struct Line {
  ll a, b;
  ll f(ll x) {
    return a*x + b;
  }
};
bool check(Line l1, Line l2, Line l3) {
  return (l2.a-l1.a)*(l3.b-l2.b) >= (l2.b-l1.b)*(l3.a-l2.a);
}
Line deq[MAX_N];
ll dp[MAX_N];

int main2() {
  int N;
  ll C;
  cin >> N >> C;
  REP(i, N) cin >> H[i];
  int s = 0, t = 0;
  dp[0] = 0;
  for (int i = 1; i < N; i++) {
    int j = i-1;
    Line line = (Line){ -2*H[j], dp[j] + H[j] * H[j] + C };
    while (t - s >= 2 && check(deq[t-2], deq[t-1], line)) t--;
    deq[t++] = line;

    ll x = H[i];
    while (t - s >= 2 && deq[s].f(x) >= deq[s+1].f(x))
      s++;
    dp[i] = deq[s].f(x) + H[i]*H[i];
  }

  ll ans = dp[N-1];
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

int main() {
  int h,w;
  for (int i = 0;; i++) {
    cin>>h>>w;
    if (h==0 && w==0) break;
    else {
      for (int i=0;i<w;i++) cout<<"#";
      cout<<endl;
      
      for (int i = 1; i < h-1; i++) {
        cout<<"#";
        for (int j = 1; j < w-1; j++) {
          cout<<".";
        }
        cout<<"#"<<endl;
      }
      
      for (int i=0;i<w;i++) cout<<"#";
      cout<<endl;

      cout<<endl;
    }
  }
}



Measured memory_bytes: 3088
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.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; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n;

main(){
	while(cin >> n){
		vector<int> im(100003);
		REP(i, n){
			int x, y;
			cin >> x >> y;
			im[x] ++;
			im[++y] --;
		}
		int ans = 0;
		REP(i, n+1){
			im[i+1] += im[i];
			if(im[i+1] >= i) ans = i;
		}
//		cout << im << endl;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1524
import           Control.Applicative
import           Data.Functor
import qualified Data.List           as L
import qualified Data.Set            as S

main :: IO ()
main = do
  n <- readLn
  cards <- solve n allCards
  mapM_ (putStrLn . show) cards

solve :: Int -> S.Set Card -> IO [Card]
solve 0 s = pure $ L.sort $ S.toList s
solve n s = do
  ws <- words <$> getLine
  let card = parseCard ws
  solve (n-1) (S.delete card s)

data CardKind
  = Spade
  | Heart
  | Club
  | Diamond
  deriving (Eq, Ord)

instance Show CardKind where
  show Spade   = "S"
  show Heart   = "H"
  show Club    = "C"
  show Diamond = "D"

data Card
  = Card CardKind Int
  deriving (Eq)

instance Ord Card where
  Card ck1 n1 `compare` Card ck2 n2 =
    case ck1 `compare` ck2 of
      EQ -> n1 `compare` n2
      _  -> ck1 `compare` ck2

instance Show Card where
  show (Card ck n) = show ck ++ " " ++ show n

allCards :: S.Set Card
allCards = S.fromList $ do
  cardKind <- [Spade, Heart, Club, Diamond]
  number <- [1..13]
  pure $ Card cardKind number

parseCard :: [String] -> Card
parseCard [c',n'] = Card c (read n')
  where
    c = case c' of
      "S" -> Spade
      "H" -> Heart
      "C" -> Club
      "D" -> Diamond



Measured memory_bytes: 4108
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    String c1 = sc.next();
    String c2 = sc.next();
    String c3 = sc.next();
    
    String c11 = c1.substring(0, 1);
    String c22 = c2.substring(1, 2);
    String c33 = c3.substring(2, 3);
    
    System.out.println(c11 + c22 + c33);
  }
}

Measured memory_bytes: 22100
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

map<ll, int> prime_factorize(ll m){
	map<ll, int> ret;
	for(ll i = 2; i * i <= m; ++i){
		while(m % i == 0){			
			++ret[i];
			m /= i;
		}
	}
	if(m != 1)ret[m] = 1;
	return ret;
}

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

  int ans = 0;
  auto factors = prime_factorize(n);
  for(auto f : factors){
  	int c = f.second;
  	int i = 1;
  	while(i <= c){
  		c -= i;
  		++i;
  		++ans;
  	}
  }

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


Measured memory_bytes: 3604
N,M = map(int,input().split())

if abs(M-N) > 1:
    print(0)
    exit()

L = 0
if N == M:
    cnt = 1
    for i in range(1,N+1):
        cnt *= i
        cnt %= 1000000007
    ccnt = cnt
else:
    mi = min([N,M])
    ma = max([N,M])
    cnt = 1
    for i in range(1,mi+1):
        cnt *= i
        cnt %= 1000000007

    ccnt = cnt * ma


nn = N%2
mm = M%2
if (nn == 0 and mm == 0) or (nn == 1 and mm == 1):
    print((cnt * ccnt * 2) % 1000000007)
else:
    print((cnt * ccnt) % 1000000007)

Measured memory_bytes: 3064
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

ULL n;

int main(){
    cin >> n;
    if(n % 2 == 1){
        cout << 0 << endl;
        return 0;
    }
    LL ans = 0;
    LL zyo = 10LL;
    while(zyo <= n){
        ans += n / zyo;
        zyo *= 5LL;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;


void main() {
    auto s = readln.split.map!(to!int);
    auto v = s[0];
    auto e = s[1];
    auto r = s[2];
    auto g = new Edge!(long)[][](v);
    foreach (_; 0..e) {
        s = readln.split.map!(to!int);
        auto x = s[0];
        auto y = s[1];
        auto cost = s[2];
        g[x] ~= Edge!(long)(y, cost);
    }

    auto dist = dijkstra!(long, 1L<<59)(g, r);
    v.iota.map!(i => dist[i] == 1L<<59 ? "INF" : to!string(dist[i])).each!writeln;
}

struct Edge(T) {
    int to;
    T cost;
}

T[] dijkstra(T, T inf)(Edge!(T)[][] graph, int start) {
    import std.typecons : Tuple, tuple;
    import std.conv : to;
    import std.container : BinaryHeap;

    int n = graph.length.to!int;
    auto dist = new T[](n);
    dist[] = inf;
    dist[start] = 0;

    auto pq = new BinaryHeap!(Array!(Edge!(T)), "a.cost > b.cost");
    pq.insert(Edge!(T)(start, 0));

    while (!pq.empty) {
        auto u = pq.front.to;
        auto cost = pq.front.cost;
        pq.removeFront;
        foreach (const e; graph[u]) {
            auto v = e.to;
            auto next_cost = cost + e.cost;
            if (dist[v] <= next_cost) continue;
            dist[v] = next_cost;
            pq.insert(Edge!(T)(v, next_cost));
        }
    }

    return dist;
}



Measured memory_bytes: 44788
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int N = 1e3+10;

struct point {
    double x,y;
    point(double x=0,double y=0):x(x),y(y){}
    bool operator < (const point &rhs)const{
        return atan2(y,x) < atan2(rhs.y, rhs.x);
    }
}p[N];

int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        scanf("%lf%lf",&p[i].x,&p[i].y);
    }
    sort(p,p+n);
    double ans = 0;
    for(int i=0;i<n;++i){
        double x = 0,y = 0;
        int j = i;
        do{
            x += p[j].x, y += p[j].y;
            ans = max(ans,x*x+y*y);
            j = (j+1)%n;
        }while(i!=j);
    }
    printf("%.15lf\n",sqrt(ans));
    return 0;
}

Measured memory_bytes: 256
import Control.Applicative ((<$>))
import Control.Monad (forM_, when)
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List (unfoldr)
import Data.Char (isSpace)
import Data.Vector.Mutable (IOVector)
import qualified Data.Vector.Mutable as VM

main :: IO ()
main = do
  [n, m] <- readil B.readInt <$> B.getLine
  solve n m

solve :: Int -> Int -> IO ()
solve n m = do
  gd <- VM.replicate n []
  forM_ [1..m] $ \_ -> do
    [u, v] <- readil B.readInt <$> B.getLine
    ul <- VM.read gd u
    VM.write gd u (v:ul)
    vl <- VM.read gd v
    VM.write gd v (u:vl)
  idv <- VM.replicate n 0
  forM_ [0..n-1] $ \i -> do
    ii <- VM.read idv i
    when (ii == 0) $ do
      VM.write idv i (i+1)
      dfs gd idv (i+1) [i]
  q <- readi B.readInt <$> B.getLine
  forM_ [1..q] $ \_ -> do
    [s, t] <- readil B.readInt <$> B.getLine
    si <- VM.read idv s
    ti <- VM.read idv t
    putStrLn $ if si == ti then "yes" else "no"
  where dfs :: IOVector [Int] -> IOVector Int -> Int -> [Int] -> IO ()
        dfs gd idv idt [] = return ()
        dfs gd idv idt (u:st) = do
          nbl <- VM.read gd u
          mv <- findM (\j -> do
                          jid <- VM.read idv j
                          return (jid == 0)) nbl
          case mv of
           (Just v) -> do
             VM.write idv v idt
             dfs gd idv idt (v:u:st)
           Nothing -> dfs gd idv idt st

readi :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> a
readi f s = let Just (n, _) = f s in n

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')

findM :: Monad m => (a -> m Bool) -> [a] -> m (Maybe a)
findM p [] = return Nothing
findM p (x:xs) = do
  b <- p x
  if b then return $ Just x
    else findM p xs



Measured memory_bytes: 25736
#include <bits/stdc++.h>
using namespace std;
#define x_ real()
#define y_ imag()
#define cross(a, b) (conj(a)*(b)).imag()
#define dot(a, b) (conj(a)*(b)).real()
#define PI acos(-1)
#define F first
#define S second
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define fileIO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<ld> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
typedef pair<double, double> pd;
pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };



int main() {
	fastIO;
	int n;
	cin >> n;
	ll mn = 1e9;
	for (int i = 0; i < n; i++) {
		ll x;
		cin >> x;
		ll curr = 0;
		while (!(x&1)) {
			x /= 2;
			curr++;
		}
		mn = min(mn, curr);
	}
	cout << mn;






}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    int ans;
    ans = b / a;
    
    if(ans > c){
        cout << c << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int N;
  char S[101];
  string str;
  str = "Three";
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> S[i];
    if(S[i] == 'Y'){
      str = "Four";
      break;
    }
  }
    cout << str;
}


Measured memory_bytes: 256
#include<stdio.h>
 
#define MAX 10000
#define NIL -1
 
typedef struct{
  int p,l,r;
}Node;
 
Node T[MAX];
int n,D[MAX],H[MAX];
 
void setDepth(int,int);
int setHeight(int);
int getSibling(int);
void print(int);
 
int main(){
  int i,v,l,r,root = 0;
 
  scanf("%d",&n);
  for(i=0;i<n;i++)
    T[i].p = NIL;
 
  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL)T[l].p = v;
    if(r != NIL)T[r].p = v;
  }
 
  for(i=0;i<n;i++)
    if(T[i].p == NIL)root = i;
 
  setDepth(root,0);
  setHeight(root);
 
  for(i=0;i<n;i++)
    print(i);
 
  return 0;
}
 
void setDepth(int u, int d){
 
  if(u == NIL)return;
  D[u] = d;
  setDepth(T[u].l,d+1);
  setDepth(T[u].r,d+1);
}
 
int setHeight(int u){
  int h1,h2;
 
  h1 = h2 = 0;
  if(T[u].l != NIL)h1 = setHeight(T[u].l) + 1;
  if(T[u].r != NIL)h2 = setHeight(T[u].r) + 1;
  return H[u] = (h1 > h2 ? h1 : h2); 
}
 
int getSibling(int u){
 
  if(T[u].p == NIL)return NIL;
  if(T[T[u].p].l != u && T[T[u].p].l != NIL)
    return T[T[u].p].l;
  if(T[T[u].p].r != u && T[T[u].p].r != NIL)
    return T[T[u].p].r;
  return NIL;
}
 
void print(int u){
  int deg;
 
  printf("node %d: parent = %d, sibling = %d, ",u,T[u].p,getSibling(u));
 
  deg = 0;
 
  if(T[u].l != NIL)deg++;
  if(T[u].r != NIL)deg++;
 
  printf("degree = %d, depth = %d, height = %d, ",deg,D[u],H[u]);
 
  if(T[u].p == NIL)printf("root\n");
  else if(T[u].l == NIL && T[u].r == NIL)printf("leaf\n");
  else printf("internal node\n");
}

Measured memory_bytes: 624
import Data.List
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import qualified Data.IntMap as IM

type Map = IM.IntMap Int

toTuple [a, b] = (a, b)

readIntsLines :: IO [(Int, Int)]
readIntsLines = map (toTuple . map (fst . fromJust . BC.readInt) . BC.words) . BC.lines <$> BC.getContents

solve :: [(Int, Int)] -> Int -> Map -> Bool
solve [] _ _ = False
solve ((a, b):xs) n m
  | a == 1 = solve xs n $ IM.insert b 1 m
  | b == n = IM.member a m || solve xs n m
  | otherwise = solve xs n m

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  ls <- sortOn fst <$> readIntsLines
  putStrLn $ if solve ls n IM.empty then "POSSIBLE" else "IMPOSSIBLE"

Measured memory_bytes: 83324
iter :: [Int] -> (Bool,Int,[Int])
iter []     = (False,0,[])
iter (x:[]) = (False,0,(x:[]))
iter (x0:x1:xs) =
  let (f,n,x) = if x0 < x1
                then iter (x0:xs)
                else iter (x1:xs)
  in
    if x0 < x1
    then (True,n+1,x1:x)
    else (f,   n  ,x0:x)
    

ans n x = 
  let (f,n',x') = iter x
  in 
    if f
    then ans (n'+n) x'
    else (n'+n,x')

main = do
  n <- getLine
  c <- getLine
  let i = reverse $ map read $ words c :: [Int]
      (n,x) = ans 0 i
  putStrLn $ unwords $ map show $ reverse x
  print n

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

int n, m, t1, a[105][105], b[105];

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    for (int i = 0; i < m; i++) {
        scanf("%d", &b[i]);
    }
    for (int i = 0; i < n; i++) {
        t1 = 0;
        for (int j = 0; j < m; j++) {
            t1 += a[i][j] * b[j];
        }
        printf("%d\n", t1);
    }
}


Measured memory_bytes: 2108
x,y=map(int,input().split())
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
if a.count(x)==1 and a.count(y)==1:
    print("Yes")
elif b.count(x)==1 and b.count(y)==1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
S = str(input())
T = str(input())

max_equal_count = 0

for i in range(len(S) - len(T) + 1):
    equal_count = 0
    
    for j in range(len(T)):
        if S[i + j] == T[j]:
            equal_count = equal_count + 1

    if max_equal_count < equal_count:
        max_equal_count = equal_count

print(len(T) - max_equal_count)


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if( a + b >= c ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
/*
問題文
今、日本は 9 月 9 日です。 二桁の整数 N が与えられるので、十進法で N に 9 が含まれるか答えてください。
*/

//#9月9日はチルノの日


#include<iostream>

const int digit = 2; //今回は2桁なので　digit=2; 何桁でも対応するプログラムが書きたい

int main() {
	bool flag=false;
	int num;
	std::cin >> num;

	for (int i = 0; i < digit; i++) {
		if ((num % 10) % 9 == 0 && num%10) {
			flag = true;
			break;
		}
		num /= 10;
	}

	std::cout << (flag ? "Yes" : "No") << std::endl;

	return 0;
}

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

using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

int n;
string s;

int match_num(string a,string b){
  set<char> seta(a.begin(),a.end());
  set<char> setb(b.begin(),b.end());

  vector<char> veca(seta.begin(),seta.end());
  int num = 0;

  for(int i = 0 ; i < veca.size();i++){
    if (setb.count(veca[i]) != 0) {
      num += 1;
    }
  }

  return num;
}

int main(){
  cin >> n >> s;
  string x,y;
  int m = 0;

  for(int i=1;i<n;i++){
    x = s.substr(0,i);
    y = s.substr(i);
    m = max(m,match_num(x,y));
  }

  cout << m << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#define INF (1000000000)
#define MOD (1000000007)
using namespace std;

typedef vector<int> VI;
typedef vector<int>::iterator VII;
typedef vector<double> VD;
typedef vector<double>::iterator VDI;
typedef vector<long>::iterator VL;
typedef vector<long>::iterator VLI;
typedef pair<int, int> P;

int n, k;
int head[100];
int next[10000];
int to[10000];
int cost[10000];
int d[100];


void Search(int s)
{
	fill(d, d + 100, INF);
	d[s] = 0;
	
	priority_queue<P, vector<P>, greater<P> > que;
	que.push(P(0, s));
	
	while (que.size()){
		P p = que.top();
		que.pop();
		
		int v = p.second;
		if (d[v] < p.first) continue;
		for (int e = head[v]; e != -1; e = next[e]){
			if (d[to[e]] > d[v] + cost[e]){
				d[to[e]] = d[v] + cost[e];
				que.push(P(d[to[e]], to[e]));
			}
		}
	}
}

int main()
{
	while (scanf("%d %d", &n, &k), n + k){
		memset(head, -1, sizeof(head));
		memset(next, 0, sizeof(next));
		memset(to, 0, sizeof(to));
		memset(cost, 0, sizeof(cost));
		int m = 0;
		
		for (int i = 0; i < k; i++){
			int q;
			scanf("%d", &q);
			
			if (q == 0){
				int a, b;
				scanf("%d %d", &a, &b);
				a--; b--;
				
				Search(a);
				if (d[b] != INF) printf("%d\n", d[b]);
				else puts("-1");
			}
			else {
				int c, d, e;
				scanf("%d %d %d", &c, &d, &e);
				c--; d--;
				
				next[m] = head[c];
				head[c] = m;
				to[m] = d;
				cost[m] = e;
				m++;
				
				next[m] = head[d];
				head[d] = m;
				to[m] = c;
				cost[m] = e;
				m++;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 1328
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		vector<UL> A(N); rep(i, N) cin >> A[i];
		if (A[0]) { cout << -1 << endl; return; }
		ULL ans = 0;
		for (UL i = 1; i < N; i++) {
			if (A[i] > A[i - 1] + 1) { cout << -1 << endl; return; }
			if (A[i] == A[i - 1] + 1) { ans++; continue; }
			else { ans += A[i]; }
		}
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

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

int main()
{
    vector<int> prev(5);
    int ans;

    for (int i = 0; i < 5; i++)
    {
        cin >> prev[i];
        if (prev[i] == 0)
            ans = ++i;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3568