akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
using namespace std;

int main(){
  string str;
  while(getline(cin,str) && str != "0"){
    int ans = 0, one = 0;
    for(int i = 0 ; i < str.size() ; i++){
      if(str[i] == ' ') continue;
      else{
	if(str[i] == '1'){
	  if(str[i+1] >= '0'){
	    ans += 10;
	    i++;
	  }
else one++, ans++;
	}
	else ans += str[i] - '0';
      }
    }
    for(int i = 0 ; i < one ; i++){
      if(ans + 10 <= 21) ans += 10;
    }
    if(ans > 21) ans = 0;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;

public class Main {

    static class FastReader{
        BufferedReader br;
        StringTokenizer st;

        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next(){
            while(st==null || !st.hasMoreElements()){
                try{
                    st=new StringTokenizer(br.readLine());
                }
                catch(IOException e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt(){
            return Integer.parseInt(next());
        }

        Long nextLong(){
            return Long.parseLong(next());
        }

        double nextDouble(){
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str="";
            try{
                str=br.readLine();
            }
            catch(IOException e){
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args) {
        FastReader in = new FastReader();
     int n=in.nextInt();
     HashSet<String> my=new HashSet<>();

     for(int i=0;i<n;i++){
         my.add(in.next());
     }
        System.out.println(my.size());
    }
}



Measured memory_bytes: 71972
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r,g,b,a;
  cin >> r >> g >> b;
  a = 100*r+10*g+b;
  if(a%4==0) cout << "YES" <<endl;
  else cout << "NO" << endl;
  
}

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

int main(){
	int n, s;
	double m, t;
	while(1){
		t = 0;
		m = 0;
		cin >> n;
		if(n == 0) break;
		for(int i = 0; i < n; i++){
			cin >> s;
			m += s;
			t += s*s;
		}
		m /= n;
		t /= n;
		printf("%.8lf\n", sqrt(t - m*m));
	}
	return 0;
}

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

int test(double x1, double y1, double x2, double y2, double x3, double y3, double xp, double yp)
{
    double xa = (x2 - x1);
    double ya = (y2 - y1);
    double xb = (x3 - x1);
    double yb = (y3 - y1);
    double xc = (xp - x1);
    double yc = (yp - y1);
    double d = 1.0 / (xa*yb - xb*ya);
    double k = d * (yb * xc - xb * yc);
    double m = d * (-ya * xc + xa * yc);
    return (k >= 0.0 && m >= 0.0)? 1 : 0;
}

int main(void)
{
    double x1, y1, x2, y2, x3, y3, xp, yp;
    while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) {
        int tmp = 1;
        tmp *= test(x1, y1, x2, y2, x3, y3, xp, yp);
        tmp *= test(x2, y2, x1, y1, x3, y3, xp, yp);
        tmp *= test(x3, y3, x1, y1, x2, y2, xp, yp);
        cout << ((tmp ==1)? "YES" : "NO") << endl;
    }
    return 0;
}






Measured memory_bytes: 3176
#include <stdio.h>

int main(void)
{
	int money;
	int i;
	int n;
	
	money = 100000;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		money *= 1.05;
		if (money % 1000 > 0){
			money += 1000 - (money % 1000);
		}
	}
	printf("%d\n", money);
	
	return (0);
}

Measured memory_bytes: 592
N, K = map(int, input().split())
A = list(map(int, input().split()))
max_a = max(A)
MOD = 10**9 + 7

memo = [0] * (max_a + 1)
num = 0
for a in A:
    memo[a] += 1
    num += sum(memo[a+1:])

num_larger = 0
for a in A:
    num_larger += sum(memo[a+1:])

ans = ((num*K % MOD) + ((K*(K-1)//2)*num_larger) % MOD) % MOD
print(ans)

Measured memory_bytes: 3188
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
        string[] input = ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int m = int.Parse(input[1]);
//        int b = int.Parse(input[2]);
//        string temp = ReadLine();
//        int a = int.Parse(ReadLine());
        WriteLine((n-1)*(m-1));
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
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>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,k;cin>>n>>k;
    vint v(n);
    rep(i, n)cin>>v[i];

    ll ans = 0;
    rep(a, min(n, k)+1){
        rep(b, min(n, k) - a+1){
            vint mi;
            ll sum = 0;
            rep(i, a){
                sum += v[i];
                if(v[i]<0){
                    mi.push_back(v[i]);
                }
            }
            rep(i, b){
                sum += v[n-1-i];
                if(v[n-1-i]<0){
                    mi.push_back(v[n-1-i]);
                }
            }
            sort(all(mi));
            ll res = 0;
            rep(i, min((int)mi.size(), k-a-b)){
                res  += mi[i];
            }
            debug("a%d b%d sum%d res%d\n", a, b, sum, res);
            chmax(ans, sum - res);
        }

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


Measured memory_bytes: 256
n=int(input())

sumall=0
s_list=[]
for i in range(n):
    s=int(input())
    sumall+=s
    s_list.append(s)

if sumall%10!=0:
    print(sumall)
    exit()

s_list.sort()

for s in s_list:
    if s%10!=0:
        print(sumall-s)
        exit()
print(0)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll N,M;
  cin >> N >> M;
  ll ans;
  ll time = 1900*M+100*(N-M);
  ll atk = pow(2,M);
  ans = time * atk;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> a(H, vector<char>(W));
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      cin >> a.at(i).at(j);
    }
  }
  
  vector<bool> gyo(H, false);
  vector<bool> retsu(W, false);

  //行のマーク
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(a.at(i).at(j) == '#') {
        gyo.at(i) = true;
        break;
      }
    }
  }
  //列のマーク
  for(int i = 0; i < W; i++) {
    for(int j = 0; j < H; j++) {
      if(a.at(j).at(i) == '#') {
        retsu.at(i) = true;
        break;
      }
    }
  }
  
  //出力
  for(int i = 0; i < H; i++) {
    if(gyo.at(i)) {
      for(int j = 0; j < W; j++) {
        if(retsu.at(j)) {
          cout << a.at(i).at(j);
        }
      }
      cout << endl;
    } else {
      continue;
    }
  }

  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  vector<int>a(5);
  rep(i,5)cin>>a[i];
  rep(i,5){
    if(a[i]==0)cout<<i+1<<endl;
  }
  return(0);
}


Measured memory_bytes: 3584
n,m = map(int,input().split())
AB = []
ans = [0] * (n-1)

edge = [[] for _ in range(n+1)] #edge[i] := 頂点iから伸びてる辺の行き先のリスト

for i in range(m):
    a,b = map(int,input().split())
    edge[a].append(b)    
    edge[b].append(a)    
    
import collections
que = collections.deque()
que.append(1)
    
while que:
    x = que.popleft()
    
    for to in edge[x]:
        a = x
        b = to
        
        if b!=1 and ans[b-2] == 0:
            ans[b-2] = x
            que.append(b)
            
if 0 in ans:
    print("No")
else:
    print("Yes")
    
    for i in ans:
        print(i)


Measured memory_bytes: 95160
#include <iostream>
#include <cmath>

using namespace std;

long N,K;

int main ()
{
	cin>>N>>K;
	long nr=0, x=1;
	while(x/2<K && nr<=N){
		x=x*2;
		nr++;
	}
	cout<<x/2+(N-nr+1)*K;
	return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,d,i,ans=0;
    cin>>n>>d;
    for(i=0;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        int p=(x*x)+(y*y);
        if(d*d>=p)
        ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3640
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long



using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
const int N=5e5+5,M=2e6+5,MOD=1e9+7,OO=1e9;


int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();	
 	
 	int h,n;

 	scanf("%d %d",&h,&n);

 	std::vector<int> a(n);

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

 	for(auto x : a)h-=x;

 	if(h>0)printf("No\n");
 	else	printf("Yes\n");

}		


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

using namespace std;

const int maxn = 2e2 + 10;
int n, a[maxn], ans;

int main(){
	cin >> n; n <<= 1;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	sort(a, a + n);
	for (int i = 0; i < n; i += 2)
		ans += a[i];
	cout << ans << '\n';
	return 0;
}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second

Int INF = 1e18;
//Int mod = 1e9+7;
Int mod = 998244353;

int main() {
    Int n;
    cin >> n;
    vector<Int> d(n, 0);
    Int ma = 0;
    for (Int i = 0; i < n; i++) {
        Int x;
        cin >> x;
        ma = max(ma, x);
        d[x]++;
        if (i == 0 && x != 0) {
            dump(0);
            return 0;
        }
    }
    for (Int i = 0; i <= ma; i++) {
        if (d[i] == 0) {
            dump(0);
            return 0;
        }
    }
    if (d[0] >= 2) {
        dump(0);
        return 0;
    }
    Int res = 1;
    for (Int i = 1; i <= ma; i++) {
        Int add = 1;
        for (Int j = 0; j < d[i]; j++) {
            add *= d[i - 1];
            add %= mod;
        }
        res *= add;
        res %= mod;
    }
    dump(res);
    return 0;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

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

	ans := 0
	for n := A; n <= B; n++ {
		str := strconv.Itoa(n)
		if str[0] == str[4] && str[1] == str[3] {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n,k,x,y;cin>>n>>k>>x>>y;
  int ans=n*x;
  if(n>k)ans-=(x-y)*(n-k);
  cout(ans);
  return 0;
}

Measured memory_bytes: 125568
// g++ -std=c++11 temp.cpp
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define EACH(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3

#define MAX_N 1000

int a,b,c;

int main(){
	cin>>a>>b>>c;
	if(a+b+c==17)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}




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

using namespace std;

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

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

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int n;
	cin>>n;
	vector<int> p(n);
	rep(i,n) cin>>p[i],p[i]--;
	int cnt=0;
	rep(i,n)if(p[i]!=i)cnt++;
	cout<<(cnt==2||cnt==0?"YES":"NO")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    long long N,M,i,j,k,count,S;
    k=0;
    S=1;
    cin >> N >> M;
    long long a[20];
    for(i=0;i<20;i++){
        a[i]=0;
    }
    for(i=2;i<1000000000;i++){
        count=0;
        for(j=0;j<100;j++){
            if(M%i==0){
                M=M/i;
                count++;
            }else{
                break;
            }
        }
        if(count>0){
            a[k]=count;
            k++;
        }
        if(M==1){
            break;
        }
    }
    long long kaijou=1;
    for(i=0;i<20;i++){
        if(a[i]==0){
            break;
        }else{
            long long nPr=1;
            for(j=N+a[i]-1;j>N-1;j--){
                nPr=(nPr*j)%1000000007;
            }
            for(j=1;j<a[i]+1;j++){
                kaijou=(kaijou*j)%1000000007;
            }
            S=(S*nPr)%1000000007;
        }
    }
    for(i=0;i<1000000007;i++){
        if((kaijou*i)%1000000007==1){
            kaijou=i;
            break;
        }
    }
    S=(S*kaijou)%1000000007;
    cout << S << endl;
}

Measured memory_bytes: 256
n=gets.to_i
as=gets.split.map(&:to_i)

def calc(as_)
  l = 0
  r = 1
  ret = []
  while r < as_.length - 2
    while (as_[r]/2 - as_[l]).abs > (as_[r]/2 - as_[l+1]).abs
      l += 1
    end
    ret << l
    r += 1
  end
  ret
end

tmp = 0
as_ = as.map {|a| tmp += a }
ls = calc(as_)

tmp = 0
bs_ = as.reverse.map {|a| tmp += a }
rs = calc(bs_).map{|r| as.length - 1 - r - 1}.reverse

min = nil
1.upto(ls.length) do |i|
  l = ls[i-1]
  c = i
  r = rs[i-1]

  tmp = [
    as_[l] - 0,
    as_[c] - as_[l],
    as_[r] - as_[c],
    as_[-1] - as_[r],
  ]

  t = tmp.max - tmp.min
  min = t if !min || t < min
end

p min

Measured memory_bytes: 30788
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>
#include<iomanip>
#include<functional>

using namespace std;

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

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

	if (a <= c&&c <= b)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

 

Measured memory_bytes: 256
N = int(input())
S = input()

B_sum = [0]*(N+1)
for i in range(N):
  if S[i] == "#":
    B_sum[i+1] = B_sum[i] + 1
  else:
    B_sum[i+1] = B_sum[i]

ans = float("INF")
for i in range(N+1):
  b_cnt = B_sum[i]
  w_cnt = N - i - (B_sum[N] - B_sum[i])
  tmp = b_cnt + w_cnt
  ans = min(ans, tmp)
  
print(ans)

Measured memory_bytes: 11144
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;

signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  VI l(n), r(n);
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
  }
  sort(l.begin(), l.end());
  sort(r.begin(), r.end());
  auto f = [&](bool isr) {
    lint res = 0;
    int x = 0;
    auto itrl = --l.end(), itrr = r.begin();
    while (true) {
      if (isr) {
        if (*itrl > x) {
          res += *itrl - x;
          x = *itrl;
          itrl--;
        } else {
          break;
        }
      } else {
        if (x > *itrr) {
          res += x - *itrr;
          x = *itrr;
          itrr++;
        } else {
          break;
        }
      }
      isr = not isr;
    }
    return res + abs(x);
  };
  cout << max(f(true), f(false)) << '\n';
  return 0;
}

Measured memory_bytes: 1024
{-# LANGUAGE FlexibleContexts #-}

module Main where

-- import Debug.Trace
import Data.List
import qualified Data.Sequence as S
import qualified Data.ByteString.Char8 as B
import Data.Int
import Data.Char
import Data.Array
-- import Data.Array.IO
import Data.Maybe
import qualified Data.Map as M
import Control.Monad.ST
import Data.STRef
import Data.Ord
import Data.Functor
import Control.Applicative
import Control.Monad
import Text.Printf
    
solve :: Int -> [[Int]] -> [(Int, Int)]
solve n lst = assocs (bfs 1 [[1]] verticesTable) where
    bfs _ [] tbl = tbl
    bfs d ps tbl = bfs (d+1) ps' (tbl // updates) where
        (ps', updates) = iter [] [] ps where
            iter ac bc [] = (ac, bc)
            iter ac bc (el@(e:es):ps) = iter ac' bc' ps where
                newVertices = filter (\x -> tbl!x < 0) (adjacentsList!e)
                ac' = (map (:el) newVertices) ++ ac
                bc' = [(x, d) | x <- newVertices] ++ bc

    adjacentsList = array (1, n) [(x, xs)| (x:_:xs) <- lst]
    verticesTable = accumArray (+) (-1) (1, n) [(1,1)]

readIntLn:: IO Int
readIntLn = (fst . fromJust . B.readInt) <$> B.getLine

readIntList:: IO [Int]
readIntList = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

print' :: (Int, Int) -> IO ()
print' (v, d)= printf "%d %d\n" v d

main :: IO() 
main = do
    n <- readIntLn
    l <- replicateM n readIntList
    mapM_ print' $ solve n l



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

using namespace std;

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


struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

UnionFind uni(110000);
ll n, m, ans;
bool used[110000];
int main() {
	cin >> n >> m;
	REP(i, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		uni.unionSet(a, b);
	}
	REP(i, n) {
		if (!used[uni.root(i)]) {
			ans++;
			used[uni.root(i)] = true;
		}
	}
	cout << ans << endl;
}

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

using namespace std;
typedef long long int ll;
int main(){
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	ll res1 = max(a * d , b * c);
	ll res2 = max(a * c, b * d);
	ll res = max(res1,res2);
	if(a <= 0 && b >= 0){
		res = max(res,0ll);
	}
	if(c <= 0 && d >= 0){
		res = max(res,0ll);
	}
	cout << res;
	return 0;
}


Measured memory_bytes: 3588
N, K = map(int, input().split())
h = [int(_) for _ in input().split()]
dp = [float('inf')]*(N)
dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2, N):
    for j in range(1, K+1):
        if i >= j:
            dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i])

print(dp[N-1])

Measured memory_bytes: 55392
from math import pi, cos, sin
a, b, h, m = list(map(int, input().split()))
ang1 = h * pi / 6 + m * pi / 360
ang2 = m * pi / 30
vec1 = (a * cos(ang1), a * sin(ang1))
vec2 = (b * cos(ang2), b * sin(ang2))
vec3 = (vec2[0] - vec1[0], vec2[1] - vec1[1])
size = (vec3[0] * vec3[0] + vec3[1] * vec3[1]) ** 0.5
print(size)

Measured memory_bytes: 9484
def gcd(a, b):
  while b != 0:
    a, b = b, a % b

  return a


def lcm(a, b):
  return a * b // gcd(a, b)


def count(v, x, y):
  v_x = v // x
  v_y = v // y
  v_xy = v // lcm(x, y)

  return v_x + v_y - v_xy


def main():
  a, b, c, d = map(int, input().split())

  print(b - a + 1 - (count(b, c, d) - count(a - 1, c, d)))


if __name__ == '__main__':
  main()


Measured memory_bytes: 39856
N = int(input())
cnt = 0
ok = False
for _ in range(N):
    D1, D2 = [int(x) for x in input().split()]
    if D1 == D2:
        cnt += 1
    else:
        cnt = 0
    if cnt >= 3:
        ok = True

if ok:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9172
#include<iostream>
#include<string>

int main() {
	std::string s[3];
	for (int i = 0; i < 3; i++)std::cin >> s[i];
	char turn = 0;
	int idx[3] = { 0,0,0 };
	while (true) {
		if (s[turn].length() == idx[turn]) {
			printf("%c\n", turn + 'A');
			return 0;
		}
		idx[turn]++;
		turn = s[turn][idx[turn] - 1]-'a';
	}
}

Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Applicative
import Control.Monad
import Control.Monad.State
import Control.DeepSeq
import Data.Array
import Data.Bits
import Data.Char
import Data.Functor.Identity
import Data.List
import Data.Ord
import Data.Maybe
import Data.Tree
import Data.Tuple
import qualified System.IO
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Sequence as Q
import qualified Data.ByteString.Char8 as B
import Data.Array.IO

main = do
  n <- getInt
  as <- (reverse . sort) <$> getInts
  let bs = [(i,a) | (i,a,aNext) <- zip3 [1..] as (tail as ++ [-9]), a/=aNext]
  let xs = init $ map fst bs
  let ys = tail $ map snd bs
  let xys = zip xs ys
  let ok1 = [True] ++ [x<=y | (x,y) <- xys]
  let ok2 = [x>=y | (x,y) <- xys] ++ [True]
  let
    ok = zipWith (&&) ok1 ok2
  let wins = [odd (x+y) | ((x,y),f) <- zip bs ok, f]
  -- print wins
  putStrLn $
    if or wins
    then "First"
    else "Second"


 
type Z = Int
type Q = Rational
type R = Double
type S = String

fint :: (Integral a, Num b) => a -> b
fint = fromIntegral

getInt = fst . fromJust . B.readInt <$> B.getLine
getIntPair = (\[a,b]->(a,b)) <$> getInts
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine
getStr = B.unpack <$> B.getLine

yesNo :: Bool -> String
yesNo True = "YES"
yesNo False = "NO"

printList :: (Show a) => [a] -> IO ()
printList = putStrLn . unwords . map show

readLnList :: (Read a) => IO [a]
readLnList = map read . words <$> getLine


-----  Union-find
type UnionFindT v m a = StateT (M.Map v (UnionFindVal v)) m a
newtype UnionFindVal v = UnionFindVal v

runUnionFindT :: (Monad m) => UnionFindT v m a -> m a
runUnionFindT = flip evalStateT $ M.empty

runUnionFind = runIdentity . runUnionFindT

ufFresh :: (Monad m, Ord v) => v -> UnionFindT v m ()
ufFresh v = modify $ M.insert v (UnionFindVal v)

ufClass :: (Monad m, Ord v) => v -> UnionFindT v m v
ufClass v = do
  (UnionFindVal pv) <- gets (M.! v)
  if v == pv
    then return v
    else do
      c <- ufClass pv
      modify $ M.insert v (UnionFindVal c)
      return c

ufUnify v w = do
  cv <- ufClass v
  cw <- ufClass w
  modify $ M.insert cw (UnionFindVal cv)
  return $ cv /= cw


Measured memory_bytes: 16764
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n; cin >> n;
  vector<int> v(n-1);
  vector<int> a(n, 0);
  for (int i=0; i<(n-1); i++) {
    cin >> v[i];
  }
  
  for (int i=0; i<(n-1); i++) {
    a[v[i]-1]++;
  }
  
  for (int i=0; i<n; i++) {
    cout << a[i] << endl;
  }
  return 0;
}

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

int main() {
  float n; cin >> n;
  if((int)n%2 == 0) cout <<  0.5 << endl;
  else{
    printf("%20.25f\n" , ((n+1)/2) / n);
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	ll N, K;
	cin >> N >> K;
	int ans = 0;
	while (N > 0) {
		N /= K;
		++ans;
	}
	cout << ans << endl;
	
	return 0;
}


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

using namespace std;

typedef long long ll;

ll f(ll a, ll b) {
	if (b==0) return a;
	return f(b, a%b);
}

int main() {
	ll a, b; scanf("%lld%lld",&a,&b);
	printf("%lld",a>b?a*b/f(a,b):a*b/f(b,a));
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define ff first 
#define ss second
#define len(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define MAXN 100010

int count(int n){
	int ans = 0;
	for(int i=0; i<19; ++i)
		if(n&(1<<i)) ++ans;
	return ans;
}
int main(){
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<vector<ii>> mt(n);
	for(int i=0; i<n; ++i){
		int m; cin >> m;
		mt[i] = vector<ii>(m);
		for(auto &x:mt[i])
			cin >> x.ff >> x.ss, x.ff-=1;
	}
	int res = 0;
	for(int w=0; w<(1<<n); ++w){
		bool can = true;
		for(int i=0; i<n; ++i){
			if(w&(1<<i)){
				for(auto y:mt[i]){
					if(y.ss == 1 and !(w&(1<<y.ff))) can = false;
					if(y.ss == 0 and  (w&(1<<y.ff))) can = false;
				}
			}
		}
		if(can)
			res = max(res, count(w));
	}
	cout << res << endl;
}


Measured memory_bytes: 384
using System;
using System.Linq;

class A
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var d = new int[n].Select(_ => Factorize(Console.ReadLine())).GroupBy(x => x).ToDictionary(g => g.Key, g => g.LongCount());

		(int p2, int p5) Factorize(string s)
		{
			var i = s.IndexOf('.');
			var d1 = long.Parse(s.Replace(".", ""));
			var d2 = i == -1 ? 1 : long.Parse($"1{new string('0', s.Length - 1 - i)}");

			int p2 = 0, p5 = 0;
			while (d1 % 2 == 0)
			{
				d1 /= 2; p2++;
			}
			while (d1 % 5 == 0)
			{
				d1 /= 5; p5++;
			}
			while (d2 % 2 == 0)
			{
				d2 /= 2; p2--;
			}
			while (d2 % 5 == 0)
			{
				d2 /= 5; p5--;
			}
			return (p2, p5);
		}

		var r = 0L;
		foreach (var (x, cx) in d)
			foreach (var (y, cy) in d)
			{
				if (x.p2 + y.p2 < 0 || x.p5 + y.p5 < 0) continue;
				r += cx * cy;
				if (x == y) r -= cx;
			}
		Console.WriteLine(r / 2);
	}
}


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

int main(){
  int h, w;
  while(1){
    cin >> h >> w;
    if(h==0 && w==0){ break; }
    for(int i=0; i<h; i++){
      for(int j=0; j<w; j++){
	if((i+j)%2==0){
	  cout << "#";
	}else{
	  cout << ".";
	}
      }
      cout << "\n";
    }
    cout << "\n";
  }
  return 0;
}

Measured memory_bytes: 1120
using System;
using System.Collections.Generic;
using System.Linq;

namespace Joyeuse
{
	class Program
	{
		#region Reserve
		static int cin() { return cin(-1); }
		static int cin(int D) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return D;
			return int.Parse(s);
		}
		static int[] cins(char spliter) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return new int[] { };
			string[] ss = s.Split(spliter);
			var Res = new int[ss.Length];
			for (int i = 0; i < ss.Length; i++)
				Res[i] = int.Parse(ss[i]);
			return Res;
		}
		static int[] cins() { return cins(' '); }
		static void print(object j) { Console.WriteLine(j.ToString()); }
		static void print(string j) { Console.WriteLine(j); }
		static string read() { return Console.ReadLine(); }
		#endregion
		
		static void Main(string[] args) {
			var I = cins();
			int N = I[0],M=I[1];
			var arrive = new List<int>();
			var depart = new List<int>();
			for(int i=0;i<M;i++){
				I=cins();
				if(I[0]==1)arrive.Add(I[1]);
				if(I[1]==1)arrive.Add(I[0]);
				if(I[0]==N)depart.Add(I[1]);
				if(I[1]==N)depart.Add(I[0]);
			}
			bool res = arrive.Intersect(depart).Count()>0;
			print(res?"POSSIBLE":"IMPOSSIBLE");
		}
	}
}

Measured memory_bytes: 21156
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<vector<int>> v(2, vector<int>(n));
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < n; j++) {
			cin >> v[i][j];
		}
	}
	int m = 0;
	for (int i = 0; i < n; i++) {
		int sum = 0;
		for (int j = 0; j <= i; j++) {
			sum += v[0][j];
		}
		for (int j = i; j < n; j++) {
			sum += v[1][j];
		}
		m = max(m, sum);
	}
	cout << m << endl;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
dp = [float('inf')]*2 ** N
dp[0] = 0
for _ in range(M):
  a, b = map(int, input().split())
  c = sum([2**(int(i)-1) for i in input().split()])
  for s in range(2**N):
    t = s|c
    if dp[t] > dp[s] + a:
      dp[t] = dp[s] +a
ans = dp[-1]
if dp[-1] == float('inf'):
  print(-1)
else:
  print(ans)

Measured memory_bytes: 3188
#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>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, a, b; cin >> n >> a >> b;

    if((b - a) % 2 == 0){
        cout << (b - a) / 2;
    }
    else{
        ll cand1 = b - 1;
        ll cand2 = n - a;
        ll cand3 = n - b + 1 + (b - a - 1) / 2;
        ll cand4 = a + (b - a) / 2;

        cout << min(min(cand1, cand2), min(cand3, cand4)) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		int n = sc.nextInt();
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = sc.nextInt();
		
		//偶数項を正としたときの操作回数minA
		long minA = 0;
		long sumA = 0;
		for (int i=0; i<n; i++) {
			sumA += ar[i];
			if (i%2 == 0) {
				if (sumA <= 0) {
					minA += Math.abs(sumA) + 1;
					sumA += Math.abs(sumA) + 1;
				}
			}
			else { //sumA -
				if (sumA >= 0) {
					minA += Math.abs(sumA) + 1;
					sumA -= Math.abs(sumA) + 1;
				}
			}
		}
		
		//奇数項を正としたときの操作回数minB
		long minB = 0;
		long sumB = 0;
		for (int i=0; i<n; i++) {
			sumB += ar[i];
			if (i%2 != 0) {
				if (sumB <= 0) {
					minB += Math.abs(sumB) + 1;
					sumB += Math.abs(sumB) + 1;
				}
			}
			else {
				if (sumB >= 0) {
					minB += Math.abs(sumB) + 1;
					sumB -= Math.abs(sumB) + 1;
				}
			}
		}
		
		System.out.println(Math.min(minA, minB));
		
	}
}

Measured memory_bytes: 59420
h,w=map(int,input().split())

grid=[[0 for j in range(w)] for i in range(h)]
tate=[]
ans=[]
for i in range(h):
    b=input()
    for j in range(w):
        grid[i][j]=b[j]

for j in range(w):
    cnt=0
    for i in range(h):
        if grid[i][j]=='.':
            cnt+=1
        
        if cnt==h:
            tate.append(j)

if len(tate)>1:
    tate=[n-i for i,n in enumerate(tate)]

for j in tate:
    for i in grid:
        i.pop(j)

for i in grid:
    if i.count('.')!=len(i):
        ans.append(i)

for i in ans:
    print(''.join(i))

Measured memory_bytes: 3188
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

//xの約数を列挙、vectorにまとめて返す
//計算量はO(logN)
vector<LL> divisor(LL x){
	vector<LL> ret;
	for(LL i=1LL;i*i<=x;i++){
		if(x%i==0){
			ret.push_back(i);
			if((x/i)!=i) ret.push_back(x/i);
		}
	}
	return ret;
}

LL gcd(LL a,LL b) { return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b) { return a/gcd(a,b)*b;}

LL N;

LL ans = 0;

void solve(){
	//ある整数n,mに対し
	//N = (n*K+1)*K^m
	//が成立するようなKが存在すれば
	//それが条件を満たすK

	//m=0の時 N = n*K+1 より
	//N - 1 = n*K が成立
	//これはKがN-1の約数であることを表す
	//よってm=0の時はans+=(N-1の約数の個数)とする
	vector<LL> div_n_1 = divisor(N-1);
	ans += div_n_1.size()-1LL;//-1は約数のうち1を除外した分
	//m>=1の時は全探索
	vector<LL> div_n = divisor(N);
	for(LL div : div_n){
		if(div==1) continue;
		LL target = N;
		//Nをdで割れるだけ割って
        while (target % div == 0) target/=div;
        //さらにその数からdを引けるだけ引いたら
        //1が残るかどうかを調べる
        if ((target-1) % div == 0) ans++;
	}
}

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

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

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int Q = scanner.nextInt();
    int[][] cum = new int[N + 1][N + 1];
    for (int i = 0; i < M; i++) {
      int left = scanner.nextInt();
      int right = scanner.nextInt();
      cum[left][right] += 1;
    }
    for (int i = 1; i <= N; i++) {
      int sum = 0;
      for (int j = 1; j <= N; j++) {
        sum += cum[i][j];
        cum[i][j] = sum + cum[i - 1][j];
      }
    }
    for (int i = 0; i < Q; i++) {
      int p = scanner.nextInt();
      int q = scanner.nextInt();
      System.out.println(cum[q][q] - cum[p - 1][q] - cum[q][p - 1] + cum[p - 1][p - 1]);
    }
  }
}


Measured memory_bytes: 163948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_que<int> pque;//これは大きい順
//typedef priority_que<int, vector<int>, greater<int>> pque;//これは小さい順


int main(){
  ll h;
  cin >> h;
  vector<ll> p;

  ll x=1;
  ll ct=0;
  while(1){
    x *= 2;
    if(h<x) break;
    ct ++;
  }
  x = 0;
  p.push_back(0);//p[0]
  p.push_back(1);//p[1]
  p.push_back(3);//p[2]
  FOR(i, 3, ct+2){
    p.push_back(p[i-1]*2+1);
  }
  cout << p[ct+1] << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n; i++)
#define all(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

int main(){
    int n;
    cin >> n;
    char now, next;
    cin >> now;
    rep(i, n-1){
        cin >> next;
        if(now == 'T' && next == 'F') now = 'F';
        else now = 'T';
    }
    cout << now << endl;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef pair<double,int>Q;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m;
map<int,int>M;
bool ok = 1;
int main(){
	cin>>n;
	rep(i,n){
		int a;cin>>a;M[a]++;
	}
	cin>>m;
	rep(i,m){
		int t;cin>>t;M[t]--;
		if(M[t] == -1) ok = 0;
	}
	puts(ok?"YES":"NO");
}

Measured memory_bytes: 9600
#include <cstdio>
#include <cstring>
#include <cassert>
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <iterator>
#include <queue>
#include <utility>

using namespace std;

int N, M;
#define MN 20000
#define MM 16
int C[MN];
int X[MM];
bool input() {
    cin >> N >> M;
    if (N == 0 && M == 0) return false;
    for (int i = 0; i < M; i++) cin >> X[i];
    for (int i = 0; i < N; i++) cin >> C[i];
    return true;
}

#define INF (1<<28)
#define SQ(x) ((x) * (x))

int F(int x) {
    if (x < 0) return 0;
    if (x > 255) return 255;
    return x;
}

int Cache[MN][256];
int dfs(int index, int x) {
    if (index == N) return 0;
    if (Cache[index][x] >= 0) return Cache[index][x];
    int Ret = INF;
    for (int i = 0; i < M; i++) {
        Ret = min(Ret, dfs(index + 1, F(x + X[i])) + SQ(C[index] - x));
    }
    return Cache[index][x] = Ret;
}

void solve() {
    memset(Cache, -1, sizeof(Cache));
    int Ans = INF;
    for (int i = 0; i < M; i++) {
        Ans = min(Ans, dfs(0, F(128 + X[i])));
    }
    cout << Ans << endl;
}

int main() {
    while (input()) solve();
    return 0;
}

Measured memory_bytes: 22800
#include<bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define INF (ll)1e18
#define pii pair<ll,ll>
#define mod 1000000007 //998244353
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fb(i,a,b) for(ll i=a;i>b;i--)
#define ff first
#define ss second
#define srt(v)  if(!v.empty())sort(v.begin(),v.end())
#define PI 3.141592653589793238
#define pq priority_queue<ll>
#define pqr priority_queue<ll,vector<ll>,greater<ll>()>
using namespace std;
ll pow_mod(ll a,ll b)
{
	ll res=1;
	while(b!=0)
	{
		if(b&1)
		{
			res=(res*a)%mod;
		}
		a=(a*a)%mod;
		b/=2;
	}
	return res;
}
void solve()
{
 ll n,m;
 
 cin>>n>>m;
 
 vector<ll>adj[n+1];
 
 for(ll i=0;i<m;i++){
     ll x,y;
     cin>>x>>y;
     
     adj[x].pb(y);
     adj[y].pb(x);
 }
 
 
 bool mark[n+1];
 memset(mark,false,sizeof(mark));
 
 ll cnt=0;
 
 

 for(ll i=1;i<=n;i++){
     if(!mark[i]){
         cnt++;
         queue<ll>q;
         
         q.push(i);
         
         mark[i]=true;
         
         while(!q.empty()){
             ll x=q.front();
             mark[x]=true;
             q.pop();
             
             for(auto a:adj[x]){
                 if(!mark[a]){
                     mark[a]=true;
                     q.push(a);
                 }
             }
         }
     }
 }
 
 cnt--;
 
 cout<<cnt<<endl;
}
int32_t main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     
//Start from Here.

  ll t;
  t=1;
 // cin>>t;
  while(t--)
  solve();
  
//Good Bye!
    return 0;
}

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

ll N, M;

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

    if (N >= 2 && M >= 2) {
        cout << (N-2)*(M-2) << endl;
    }
    else if (N < 2 && M >= 2) {
        cout << M-2 << endl;
    }
    else if (N >= 2 && M < 2) {
        cout << N-2 << endl;
    }
    else {
        cout << 1 << endl;
    }

    return 0;
}


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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const ll MOD = 1e9+7;

int main() {
    ios_base::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    n++;
    vector<ll> v(n+1);
    for(ll i = 1; i <= n; i++) v[i] = (v[i-1]+i)%MOD;
    ll ans = 0;
    for(ll i = k; i <= n; i++) {
        ll mini = v[i];
        ll maxi = (v[n]-v[n-i]+MOD)%MOD;
        ll tmp = (maxi-mini+1+MOD)%MOD;
        ans = (ans+tmp)%MOD;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4780
import math
def prime_numbers(x):
    if x < 2:
        return []
    prime_numbers = [i for i in range(x)]
    prime_numbers[1] = 0
    for prime_number in prime_numbers:
        if prime_number > math.sqrt(x):
            break
        if prime_number == 0:
            continue
        for composite_number in range(2 * prime_number, x, prime_number):
            prime_numbers[composite_number] = 0
    return [prime_number for prime_number in prime_numbers if prime_number != 0]
n = int(input())
primes = prime_numbers(55555)
ans = []
cnt = 0
for i in primes:
    if i % 5 == 1:
        ans.append(i)
        cnt += 1
    if cnt == n:
        exit(print(*ans))

Measured memory_bytes: 11208
def main():
    n, m = map(int, input().split())
    
    INF = float('inf')
    dp = [[INF for i in range(n+1)] for j in range(m+1)]
    
    for i, c in enumerate(list(map(int, input().split()))):
        i += 1
        for j in range(1, n+1):
            if c == j:
                dp[i][j] = 1
            else:
                dp[i][j] = min(dp[i][j], dp[i-1][j])
                if j - c >= 0: dp[i][j] = min(dp[i][j], dp[i][j-c]+1)
    print(dp[-1][-1])

if __name__ == '__main__':
    main()


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

int main()
{
	char s[201];

	scanf("%s",s);

	int len=strlen(s);
	int i,j;
	for(i=1;i<len/2;i++){
		int k=len-i*2;
		int count=0;
		for(j=0;j<k/2;j++){
			if(s[j]==s[j+k/2])count++;
		}
		if(count==k/2){
			printf("%d\n",count*2);
			break;
		}
	}
	return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    vector<int> arr({a, b, c, d, e});

    bool ok(true);
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            if (i != j) {
                int one = arr[i];
                int other = arr[j];
                if (abs(one - other) > k) {
                    ok = false;
                }
            }
        }
    }

    cout << ((ok) ? "Yay!" : ":(") << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = list(input() for i in range(n))
m = int(input())
t = list(input() for i in range(m))
r = list(set(s+t))
ans = 0
for i in r:
    a = s.count(i)
    b = t.count(i)
    ans = max(ans,a-b)
print(ans)

Measured memory_bytes: 9156
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int t = sc.nextInt();

        int times;
        if(n%x == 0) times = n / x;
        else times = n / x + 1;

        System.out.println(t * times);
    }
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long int lli;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    
    int ans = n*n*n;
    cout << ans << endl;
}


Measured memory_bytes: 256