akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
const int INF = 1e9;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;

/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */

/** Problem1232 : Calling Extraterrestrial Intelligence Again **/
int main()
{
	const int MAX = 1e5;
	bool isPrime[MAX];
	memset(isPrime, 1, sizeof(isPrime));
	isPrime[0]=false, isPrime[1]=false;
	for (int i=2; i<MAX; i++) {
		if (isPrime[i]) {
			for (int j=2; i*j<MAX; j++) {
				isPrime[i*j]=false;
			}
		}
	}
	
	
	int m, a, b;
	while (cin>>m>>a>>b, m||a||b) {
		PII ans;
		
		for (int i=m; i>=0; i--) {
			for (int j=2; j*j<=m; j++) {
				if (i%j != 0) continue;
				if (isPrime[j] && isPrime[i/j]) {
					if ((double)a/b <= (double)j/(i/j)) {
						cout << j << " " << i/j << endl;
						goto end;
					}
				}
			}
		}
	end:;
	}
}

Measured memory_bytes: 1268
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (int i = a ; i > b ; i--)
 
typedef long long ll;
#define hahashad ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
ll f[10000010];
int main()
{
    hahashad
   	ll n,ans=0;
    cin>>n;
    FOR(i,1,n+1)
    {
        for(int j=i;j<=n;j+=i)
        {
            f[j]++;
        }
    }
    FOR(i,1,n+1)
        ans+=i*f[i];
    cout<<ans;
}

Measured memory_bytes: 81772
#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>

using namespace std;

#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); i++)
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define fill(x,y) memset(x,y,sizeof(x))
#define prev PREV
#define next NEXT
                         
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }
template<class T> inline T sqr (T x) { re x * x; }

#define filename ""

int n;
int m;
int p[100000];

int main () {
	scanf ("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf ("%d", &p[i]);
		p[i]--;
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
		if (p[p[i]] == i)
			ans++;
	printf ("%d\n", ans / 2);
	return 0;
}

Measured memory_bytes: 640
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import bisect
import heapq
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15

def main():
    s = input().strip()
    tmp = 0
    ans = 0
    for c in s:
        if c == "B":
            tmp += 1
        else:
            ans += tmp
            # tmp = 0

    print(ans)


if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

Measured memory_bytes: 40048
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {

		Scanner scan = new Scanner(System.in);
		String num = scan.next();

		String no1= num.substring(0,1);
		String no2 = num.substring(1,2);
		String no3 = num.substring(2,3);
		if(!no1.equals("1")) {
			no1="1";
		}else if(!no1.equals("9")) {
			no1 ="9";
		}

		if(!no2.equals("1")) {
			no2="1";
		}else if(!no2.equals("9")) {
			no2 ="9";
		}

		if(!no3.equals("1")) {
			no3="1";
		}else if(!no3.equals("9")) {
			no3 ="9";
		}


	System.out.println(no1+no2+no3);
	}
}


Measured memory_bytes: 22996
import math
def inpl(): return list(map(int, input().split()))
N, H = inpl()
ab = []
for i in range(N):
    a, b = inpl()
    ab.append([a, 'a'])
    ab.append([b, 'b'])

ans = 0
for i in sorted(ab)[::-1]:
    if H <= 0:
        break
    if i[1] == 'b':
        ans += 1
        H -= i[0]
    else:
        ans += math.ceil(H/i[0])
        H = 0
print(ans)

Measured memory_bytes: 33700
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,x;
    cin>>N>>x;
    
    vint a(N);
    REP(i,N)
        cin>>a[i];
    sort(ALL(a));

    int ans=0;
    REP(i,N){
        if(x>=a[i]){
            x-=a[i];
            ans++;
        }
    }

    if(ans==N and x>0)
        cout<<N-1<<endl;
    else
        cout<<ans<<endl;

}


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

#define int long long
#define INT int
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}
typedef long long ll;
const long long INF = 1LL << 60;

signed main()
{

    string s;
    cin>>s;

    int ans = 0;
    int temp = 0;
    for(auto x:s){
        if(x=='R'){
            temp++;
        }else{
            temp=0;
        }
        ans = max(ans,temp);
    }

    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 3620
#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)

int main(){
	
	int n;cin>>n;
	int cnt=0;
	while(n)
	{
		cnt+= n%10;
		n/=10;
	}
	cout<<cnt<<endl;
	return 0;
}

//cout << ans?"Yes":"No" << endl;

Measured memory_bytes: 256
from collections import deque

def bfs(maze, h, w, si, sj):
    q = deque([[si, sj]])
    score = [[-1] * w for i in range(h)]
    score[si][sj] = 0
    pattern = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    while len(q) > 0:
        i, j = q.popleft()
        for move in pattern:
            ni, nj= i + move[0], j + move[1]
            if ni < 0 or h <= ni or nj < 0 or w <= nj:
                continue
            p = maze[ni][nj]
            if p == '#':
                continue
            if p == '.' and score[ni][nj] == -1:
                score[ni][nj] = score[i][j] + 1
                q.append([ni, nj])
    return max(map(max, score))

h, w = map(int, input().split())
maze = [input() for i in range(h)]
scores = []
for si in range(h):
    for sj in range(w):
        if maze[si][sj] == "#":
            continue
        scores.append(bfs(maze, h, w, si, sj))
print(max(scores))

Measured memory_bytes: 3316
#include <stdio.h>

int main()
{
    int a,b,tmp,piece = 16;

    scanf("%d %d",&a,&b);

    if (b > a)
    {
        tmp = a;
        a = b;
        b = tmp;
    }
    piece -= (a + b);

    if (a - b > piece % 2)
    {
        puts(":(");
    }
    else
    {
        puts("Yay!");
    }
    
    
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
 
int main() {
    int a(0),b,c,ans(0),tmp(0);
  	string s;
  	//vector<>x();
  	cin >> s;
  	for(int i = 0;i < 3;i++){
  		if(s.at(i) == '1'){
          s.at(i) = '9';
        }else{
           s.at(i) = '1';
        }
    }
  	cout << s;
  
}
   


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll a,b;
  cin >> a >> b;
  if(a%3==0||b%3==0||(a+b)%3==0) {
    cout << "Possible" << endl;
  }
  else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<pair<ll, ll>> v(n);
    for (int i = 0; i < n; ++i) {
        scanf("%lld %lld", &v[i].first, &v[i].second);
    }
    sort(v.begin(),v.end());
    vector<ll> S(n+1), A(n+1);
    for (int i = 0; i < n; ++i) {
        S[i+1] = S[i] + v[i].second;
        A[i+1] = max(A[i], v[i].first);
    }
    ll ans = 0, M = S[n]-A[n];
    for (int i = n-1; i >= 0; --i) {
        ans = max(ans, M-S[i]+A[i+1]);
        M = max(M, S[i]-A[i]);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 18456
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		long n = Long.parseLong(sa[0]);
		long a = Long.parseLong(sa[1]);
		long b = Long.parseLong(sa[2]);
		br.close();

		long c = b - a;
		if (c % 2 == 0) {
			System.out.println(c / 2);
		} else {
			long a1 = a - 1;
			long b1 = b - a1;
			long ans1 = a1 + b1 / 2;

			long b2 = n - b;
			long a2 = a + b2;
			long ans2 = b2 + (n - a2 + 1) / 2;
			System.out.println(Math.min(ans1, ans2));
		}
	}
}


Measured memory_bytes: 21204
package main

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

func main() {
	var a, b, k int
	fmt.Scan(&a, &b, &k)

	wr := bufio.NewWriter(os.Stdout)
	if a+k > b-k {
		for i := a; i <= b; i++ {
			wr.WriteString(strconv.Itoa(i) + "\n")
		}
		wr.Flush()
		return
	}

	for i := a; i < a+k; i++ {
		wr.WriteString(strconv.Itoa(i) + "\n")
	}
	for i := b - k + 1; i <= b; i++ {
		wr.WriteString(strconv.Itoa(i) + "\n")
	}
	wr.Flush()
}


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

int main() {
  int n;
  int b[110];
  cin >> n;
  for(int i=0; i< n-1;i++) cin >> b[i];
  b[n] = 999999;

  int result =0;
  for(int i=0; i< n-2;i++) {
    result += min(b[i], b[i+1]);
  }
  cout << result + b[0] + b[n-2] << endl;
}



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

int main(){
    string h,w;
    cin >> h >> w;
    for(int i=0;i<h.size();i++){
        h.insert(h.begin(),h[h.size()-1]);
        h.erase(h.end()-1);
        if(h==w){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}

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

int table[10][10];

int calce(int const * const digits) {
  int ta = table[0][digits[0]];
  int tb = table[ta][digits[1]];
  int tc = table[tb][digits[2]];
  int td = table[tc][digits[3]];
  return td;
}

int main(void) {
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++)
      cin >> table[i][j];
  
  int digits[5];
  int ans = 0;
  for (int i = 0; i < 10000; i++) {
    digits[0] = i / 1000;
    digits[1] = i % 1000 / 100;
    digits[2] = i % 1000 % 100 / 10;
    digits[3] = i % 10;
    digits[4] = calce(digits);
  
    bool ng = false;
    // wrong case 1
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 10; k++) {
        if (k == digits[j]) continue;
        int bk = digits[j];
        digits[j] = k;
  
        int check = table[calce(digits)][digits[4]];
        if (check == 0) ng = true;
  
        digits[j] = bk;
      }
    }
  
    // wrong case 2
    for (int j = 0; j < 4; j++) {
      if (digits[j] == digits[j+1]) continue;

      swap(digits[j], digits[j+1]);
  
      int check = table[calce(digits)][digits[4]];
      if (check == 0) ng = true;
  
      swap(digits[j], digits[j+1]);
    }

    ans += ng;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3116
using System;

namespace _160abc
{
    class Program
    {
        static void Main(string[] args)
        {     
            long X = long.Parse(Console.ReadLine());
            long resfff = 0;
            long resf = 0;
            resfff = X/500;
            resf = (X-X/500*500)/5;
            Console.WriteLine(resfff*1000+resf*5);
            // string S = Console.ReadLine();
            // bool flag = true;
            // if(S[2]==S[3] && S[4]==S[5]){
            //     flag = true;
            // }else{
            //     flag = false;
            // }
            // Console.WriteLine(flag? "Yes":"No");
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
inline int nextInt(void){
    int res=0;char ch=getchar();
    while(ch<'0'||ch>'9')ch=getchar();
    while(ch<='9'&&ch>='0')(res*=10)+=ch-'0',ch=getchar();
    return res;
}
short stk[20],tail=0;
inline void putInt(int x){
    if(x==0){puts("0");return;}
    while(x)stk[++tail]=x%10,x/=10;
    while(tail)putchar('0'+stk[tail--]);
    puts("");
}
const int N=15,M=1005,INF=0x3f3f3f3f;
#define bitAt(x,y) ((x>>y)&1)
#define bitFill(x) ((1<<x)-1)
#define bitChg(x,y,z) (x&(~((1<<y)|(1<<z))))
int n,m,dis[N][N],dp[1<<16],cnt[N],que[N],tot=0,ans=0;
inline int DP(int bit){
    if(~dp[bit])return dp[bit];
    if(bit==0)return dp[bit]=0;
    dp[bit]=INF;
    for(int i=0;i<tot;i++)for(int j=0;j<tot;j++)
    if(i!=j&&bitAt(bit,i)&&bitAt(bit,j))
    dp[bit]=min(dp[bit],dis[que[i]][que[j]]+DP(bitChg(bit,i,j)));
    return dp[bit];
}
signed main(void){
    memset(dp,-1,sizeof(dp));
    memset(dis,0x3f,sizeof(dis));
    n=nextInt();m=nextInt();
    for(int i=1,x,y,w;i<=m;i++){
        cnt[x=nextInt()]++,cnt[y=nextInt()]++,ans+=(w=nextInt());
        dis[x][y]=dis[y][x]=min(dis[x][y],w);
    }
    for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)
    dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
    for(int i=0;i<n;i++)if(cnt[i]&1)que[tot++]=i;
    putInt(ans+DP(bitFill(tot)));
}


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

int main(){
  
  string a;
  cin >> a;
  
  if( (a.at(0) == a.at(1))&&(a.at(1)== a.at(2)) || (a.at(1) == a.at(2))&&(a.at(2)== a.at(3)) ){
    
    cout << "Yes" << endl;
    
  }
  
  else{
    
    cout << "No" << endl;
    
  }
  
}


Measured memory_bytes: 3580
N, M, C = gets.split.map &:to_i
B = gets.split.map &:to_i
A = N.times.map { gets.split.map &:to_i }

correct = 0
N.times do |n|
  sum = 0
  M.times do |m|
    sum += A[n][m] * B[m]
  end
  sum += C
  correct += 1 if sum > 0
end
puts correct

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

bool prime(int n) {
  if(n<2)return false;
  for (int i = 2; i*i <= n; ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

int main(int argc, char *argv[])
{
  int n, in, count = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin>>in;
    if(prime(in))count++;
  }
  cout<<count<<endl;
  return 0;
}



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

using namespace std;

int main(){
  string str;
  int a,leng;
  cin >> a;
  cin >> str;
  //A==65,Z==90
  leng=str.size();
  int lo=0;//ループ
  while(lo<leng){
    
    if(str[lo]+a<=90){
      str[lo]=str[lo]+a;
    }else{
      str[lo]=str[lo]+a-90+64;
    }
    
    lo++;
  }
  cout << str << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
	int n;
	cin >> n;
	v2 a(n, v1(n, 0));
	rep(i, n){
		int x, y, z;
		cin >> x;
		cin >> y;
		rep(j, y){
			cin >> z;
			a[x-1][z-1]++;
		}
	}
	rep(i, n){
		rep(j, n){
			cout << a[i][j];
			if(j != n-1) cout << " ";
			else cout << endl;
		}
	}
}



Measured memory_bytes: 3124
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String S = sc.next();
      	 if(S.charAt(0)==S.charAt(1)&&S.charAt(0)==S.charAt(2)&&S.charAt(1)==S.charAt(2)){
         System.out.println("No");
         }
      	else{
        System.out.println("Yes");
         }
	}
}

Measured memory_bytes: 21844
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int maxn=500001;
P a[maxn];
int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int tmp;
    cin>>tmp;
    a[i]=P(tmp,i);
  }
  sort(a,a+n);
  int b[maxn];
  for(int i=0;i<n/2;i++){

    b[a[i].second]=a[n/2].first;
  }
  for(int i=n/2;i<n;i++){
    b[a[i].second]=a[n/2-1].first;
  }
  for(int i=0;i<n;i++){
    cout<<b[i]<<endl;
  }
}


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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
#define INF (1ll<<60)

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<ll> S, T;
    S.pb(-LLONG_MAX / 10);
    T.pb(-LLONG_MAX / 9);
    ll y;
    REP(i, A) {
    	cin >> y;
    	S.pb(y);
    }
    REP(i, B) {
    	cin >> y;
    	T.pb(y);
    }
    S.pb(LLONG_MAX / 10);
    T.pb(LLONG_MAX / 9);
    vector<ll> V(Q);
    REP(i, Q) cin >> V[i];
    REP(i, Q) {
    	ll x = V[i];
    	ll ans = LLONG_MAX;
    	// going right first
    	auto itS = upper_bound(all(S), x);
    	auto itT = upper_bound(all(T), x);
    	if (*itS < *itT) { // get to a shrine first
    		ll cPos = *itS;
    		auto itT1 = upper_bound(all(T), cPos);
    		auto itT2 = prev(itT1);
    		ll q = min(abs(*itT1 - cPos), abs(*itT2 - cPos));
    		ans = min(ans, q + cPos - x);
    	}
        else if (*itT < *itS) { // get to a temple first
    		ll cPos = *itT;
    		auto itS1 = upper_bound(all(S), cPos);
    		auto itS2 = prev(itS1);
    		ll q = min(abs(*itS1 - cPos), abs(*itS2 - cPos));
    		ans = min(ans, q + cPos - x);
    	}
    	// going left
    	auto itSl = prev(itS);
    	auto itTl = prev(itT);
    	if (*itSl > *itTl) {
    		ll cPos = *itSl;
    		auto itT1 = upper_bound(all(T), cPos);
    		auto itT2 = prev(itT1);
    		ll q = min(abs(*itT1 - cPos), abs(*itT2 - cPos));
    		ans = min(ans, q + x - cPos);
    	}
        else if (*itTl > *itSl) { // get to a temple first
    		ll cPos = *itTl;
    		auto itS1 = upper_bound(all(S), cPos);
    		auto itS2 = prev(itS1);
    		ll q = min(abs(*itS1 - cPos), abs(*itS2 - cPos));
    		ans = min(ans, q + x - cPos);
    	}
    	cout << ans << '\n';
    }
}

Measured memory_bytes: 3828
#include<stdio.h>
int main(){
  int N,M;
  scanf("%d %d",&N,&M);
  int a[M];
  int i;
  for(i=0;i<M;i++){
    scanf("%d",&a[i]);
  }
  int num=0;
  for(i=0;i<M;i++){
    num+=a[i];
  }
  if(num<=N){
    printf("%d",N-num);
  }
  else{
    printf("%d",-1);
  }
}


Measured memory_bytes: 1740
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
typedef long double ld;
using namespace std;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ld t, x;
    cin >> t >> x;
    cout << setprecision(18);
    cout << fixed;
    cout << t / x;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    string a, b; cin >> a >> b;
    string s = a + b;
    int x = 0;
    rep(i,s.size()) {
        x += (s[i]-'0') * pow(10,s.size()-i-1);
    }
    bool ok = false;
    for (int i = 1; i * i <= 100100; i++) {
        if (x == i*i) {ok = true; break;}
    }
    printf(ok?"Yes\n":"No\n");
}

Measured memory_bytes: 256
from operator import itemgetter

N = int(input())
red = [(0,0) for i in range(N)]
blue = [(0,0) for i in range(N)]

for i in range(N):
  a, b = map(int, input().split())
  red[i] = (b,a)
for i in range(N):
  c, d = map(int, input().split())
  blue[i] = (c,d)
  
red.sort()
blue.sort()

for i in range(N):
  bx = blue[i][0]
  by = blue[i][1]
  R = len(red)
  for j in range(R):
    rx = red[R-j-1][1]
    ry = red[R-j-1][0]
    if rx < bx and ry < by:
      del red[R-j-1]
      break
      
print(N-len(red))

Measured memory_bytes: 38768
import itertools
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        xy = [list(map(int, input().split())) for _ in range(N)]

        total_distance = 0
        cnt = 0
        for p in itertools.permutations(xy):
            distance = 0
            cnt += 1
            for i in range(1, N):
                distance += ((p[i - 1][0] - p[i][0]) ** 2 + (p[i - 1][1] - p[i][1]) ** 2) ** 0.5
            total_distance += distance
        print(total_distance / cnt)


# Run main
if __name__ == '__main__':
    AtCoder().main()

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

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

    auto length = N;
    for (; length >= 0; length--)
        if (s.substr(N-length, length) == t.substr(0, length)) break;

    cout << 2*N-length << endl;
}


Measured memory_bytes: 256
//ITP1-11-A: Dice 1
//2019.05.21

#include <stdio.h>
#include <string.h>
#include <math.h>

void throwdice(char, int*);

typedef struct dice_ {
  int d[6];
} dice;

int main(void){
  int top;
  int num_throw;
  char throw[101];
  dice dice1;

  for (int i = 0; i < 6; i++) scanf("%d", &dice1.d[i]);
  top = dice1.d[0];

  scanf("%s\n", throw);
  num_throw = strlen(throw);
  for (int i = 0; i < num_throw; i++) {
    throwdice(throw[i], &dice1.d[0]);
    top = dice1.d[0];
  }

  printf("%d\n", top);
  return 0;
}

void throwdice(char c, int *d){
  int tmp[6];
  for (int i = 0; i < 6; i++) {
    tmp[i] = d[i];
  }

  if (c == 'N') {
    d[0] = tmp[1]; //top
    d[1] = tmp[5]; //south
    d[2] = tmp[2]; //east
    d[3] = tmp[3]; //west
    d[4] = tmp[0]; //north
    d[5] = tmp[4]; //bottom
  }else if (c == 'E') {
    d[0] = tmp[3]; //top
    d[1] = tmp[1]; //south
    d[2] = tmp[0]; //east
    d[3] = tmp[5]; //west
    d[4] = tmp[4]; //north
    d[5] = tmp[2]; //bottom
  }else if (c == 'W') {
    d[0] = tmp[2]; //top
    d[1] = tmp[1]; //south
    d[2] = tmp[5]; //east
    d[3] = tmp[0]; //west
    d[4] = tmp[4]; //north
    d[5] = tmp[3]; //bottom
  }else if (c == 'S') {
    d[0] = tmp[4]; //top
    d[1] = tmp[0]; //south
    d[2] = tmp[2]; //east
    d[3] = tmp[3]; //west
    d[4] = tmp[5]; //north
    d[5] = tmp[1]; //bottom
  }
}



Measured memory_bytes: 2048
def main():
    import sys
    input = sys.stdin.readline
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    V.insert(0, 0)
    ans = 0
    for i in range(min(N+1, K+1)):
        for j in range(min(N+1, K+1)):
            if i + j > min(N, K):
                break
            if i == j == 0:
                continue
            minus_l = []
            sum_v = 0
            for ii in range(i+1):
                v = V[ii]
                if v < 0:
                    minus_l.append(v)
                sum_v += v
            for jj in range(j+1):
                v = V[-jj]
                if v < 0:
                    minus_l.append(v)
                sum_v += v
            minus_l.sort(reverse=True)
            for x in range(K-i-j):
                if minus_l:
                    sum_v -= minus_l.pop()
                else:
                    break
            ans = max(ans, sum_v)
    print(ans)
if __name__ == '__main__':
    main()

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

const int N = 300233, mod = 1000000007;
int n, f[2][3][3], g[2][3][3];
char s[N];

int main() {
  scanf("%s", s + 1);
  int n = (int) strlen(s + 1);
  s[++n] = '1';
  f[1][0][0] = 1;
  for (int i = 1; i <= n; i++) {
    memset(g, 0, sizeof g);
    for (int a = 0; a < 2; a++) {
      for (int b = 0; b < 3; b++) {
        for (int c = 0; c < 3; c++) {
          if (s[i] != '0') {
            int na = a, nb = 0, nc = c;
            if (!(b & 1)) na ^= 1;
            if (a == 1 && b == 0 && c == 0) nc = 1;
            if (a == 0 && b == 0 && c == 1) nc = 2;
            (g[na][nb][nc] += f[a][b][c]) %= mod;
          }
          if (s[i] != '1') {
            int na = a, nb = b == 2 ? 1 : b + 1, nc = c;
            (g[na][nb][nc] += f[a][b][c]) %= mod;
          }
        }
      }
    }
    memcpy(f, g, sizeof g);
  }
  printf("%d\n", f[1][0][2]);
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
using namespace std;
int a,b,c,d;
int main(void){
	cin>>a>>b>>c>>d;
	a+=d-1;
	c+=b-1;
	int tk=c/b;
	int ao=a/d;
//	cout<<tk<<' '<<ao<<endl;
	if(ao>=tk)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define INF -2147483647
#define mod 1000000007
signed main(){
  int a,c;
  string b;
  cin>>a>>b>>c;
  for(int i=0;i<a;i++){
    if(b[c-1]!=b[i]) cout<<"*";
    else cout<<b[i];
  }
  cout<<"\n";
}


Measured memory_bytes: 256
n, l = [int(i) for i in input().split()]
ntaste = sum([l + i for i in range(n)])
ntastes = [ntaste - (l + i) for i in range(n)]
cand = ntastes[0]
diff = abs(ntaste - cand)
for i in range(n):
	if abs(ntaste - ntastes[i]) < diff:
		diff = abs(ntaste - ntastes[i])
		cand = ntastes[i]
print(cand)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string n;
  cin>>n;
  if(n[0]==n[1]&&n[1]==n[2]||n[3]==n[1]&&n[1]==n[2])
  cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

using namespace std;

class Counting {
	unsigned long long p, n;
	vector<long long> invMemo, facMemo, facInvMemo;
public:
	Counting(unsigned long long nn, unsigned long long np) {
		p = np;
		n = nn;
		invMemo.resize(n + 1);
		facMemo.resize(n + 1);
		facInvMemo.resize(n + 1);
		facMemo[0] = 1;
		facMemo[1] = 1;
		facInvMemo[0] = 1;
		facInvMemo[1] = 1;
		invMemo[0] = 0;
		invMemo[1] = 1;
		for (unsigned long long i = 2; i <= n; i++) {
			invMemo[i] = p - (p / i)*invMemo[p%i] % p;
			facMemo[i] = (facMemo[i - 1] * i) % p;
			facInvMemo[i] = (facInvMemo[i - 1] * invMemo[i]) % p;
		}
	}
	unsigned long long fac(unsigned long long k) {
		return facMemo[k];
	}
	unsigned long long facInv(unsigned long long k) {
		return facInvMemo[k];
	}
	unsigned long long choose(unsigned long long n, unsigned long long k) {
		if (!(0 <= k && k <= n))
			return 0;
		return (((facMemo[n] * facInvMemo[k]) % p)*facMemo[n - k]) % p;
	}
	unsigned long long divide(unsigned long long a, unsigned long long b) {
		return (a * invMemo[b]) % p;
	}
	unsigned long long mod(unsigned long long a) {
		a %= p;
		if (a < 0) a += p;
		return a;
	}
	unsigned long long power(unsigned long long a, unsigned long long e) {
		unsigned long long ans = 1;
		for (; e > 0; e /= 2) {
			if (e % 2 != 0)
				ans = ans * a % p;
			a = a*a%p;
		}
		return ans;
	}
};

string s;

int main() {
	cin >> s;
	string ss = "CODEFESTIVAL2016";
	int ans = 0;
	for (int i = 0; i < 16; i++)
		if (s[i] != ss[i])
			ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 764
#include <stdio.h>
#define n 36

struct Card{
  char suit;
  char value;
};

void BubbleSort(struct Card C[],int N){
  int i,j;
  struct Card a;

  for(i=0;i<N;i++){
    for(j=N-1;j>=i+1;j--){
      if(C[j].value < C[j-1].value){
        a = C[j];
        C[j] = C[j-1];
        C[j-1] = a;
      }
    }
  }
}
void SelectionSort(struct Card C[],int N){
  int i,j,minj;
  struct Card a;

  for(i=0;i<N;i++){
    minj = i;
    for(j=i;j<N;j++){
      if(C[j].value < C[minj].value){
        minj = j;
      }
    }
    a = C[i];
    C[i] = C[minj];
    C[minj] = a;
  }
}

int isStable(struct Card C1[],struct Card C2[],int N){
  int i,j;

  for(i=0;i<N;i++){
    if(C1[i].suit != C2[i].suit)return 0;
  }
  return 1;
}
/*for(i=0;i<N;i++){                                                           
    for(j=i+1;j<N;j++){                                                         
      for(a=0;a<N;a++){                                                         
        for(b=a+1;b<N;b++){                                                     
        if(in[i] == in[j] && )*/
int main(){
  struct Card C1[101],C2[101];
  int i,N;

  scanf("%d\n",&N);
  for(i=0;i<N;i++){
    if(i!=N-1)scanf("%c%c ",&C1[i].suit,&C1[i].value);
    else scanf("%c%c",&C1[i].suit,&C1[i].value);
  }

  for(i=0;i<N;i++)C2[i] = C1[i];

  BubbleSort(C1,N);
  SelectionSort(C2,N);

  for(i=0;i<N;i++){
    if(i)printf(" ");
    printf("%c%c",C1[i].suit,C1[i].value);
  }
  printf("\nStable\n");
  for(i=0;i<N;i++){
    if(i)printf(" ");
    printf("%c%c",C2[i].suit,C2[i].value);
  }
  if(isStable(C1,C2,N)){
    printf("\nStable\n");
  }
  else printf("\nNot stable\n");

  return 0;
}




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

public class Main {
  public static void main(String[] args) {
    final Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    Map<Integer, Integer> ypMap = new TreeMap<Integer, Integer>();
    List<Integer> yList = new ArrayList<Integer>();
    for (int i = 0; i < M; i++) {
      Integer p = sc.nextInt();
      Integer y = sc.nextInt();
      ypMap.put(y, p);
      yList.add(y);
    }
    sc.close();

    Map<Integer, Integer> pCntMap = new HashMap<Integer, Integer>();
    Map<Integer, String> yNumMap = new HashMap<Integer, String>();
    for (Map.Entry<Integer, Integer> entry : ypMap.entrySet()) {
      int p = entry.getValue();
      int cnt = pCntMap.getOrDefault(p, 1);
      yNumMap.put(entry.getKey(), getLast6Strings("00000" + String.valueOf(p))
          + getLast6Strings("00000" + String.valueOf(cnt)));
      pCntMap.put(p, ++cnt);
    }

    for (Integer integer : yList) {
      System.out.println(yNumMap.get(integer));
    }
  }

  private static String getLast6Strings(String str) {
    return str.substring(str.length() - 6);
  }
}


Measured memory_bytes: 123292
#include <bits/stdc++.h>
using namespace std;
int main(){
  unordered_map<char, int> mp;
  char letter;
  for (int i=0; i<4; i++){
    cin >> letter;
    mp[letter];
  }
  if (mp.size() == 2){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <utility>

#define MAX_N 100

void bubble_sort(int*,int);

int A[MAX_N];
int count = 0;

int main(){
    int n;
    scanf("%d",&n);
    for(int i = 0; i < n; i++){
        scanf("%d",&A[i]);
    }
    bubble_sort(A,n);
    for(int i = 0; i < n; i++){
        if(i<(n-1))printf("%d ",A[i]);
        if(i == (n-1)) printf("%d\n",A[i]);
    }
    printf("%d\n",count);

}

void bubble_sort(int* a,int n){
    for(int i = 0; i < n; i++){
        for(int j = (n - 1); j > i; j--){
            if(A[j] < A[j-1]){
                std::swap(A[j],A[j-1]);
                count++;
            }
        }
    }
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }


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

    ll N;
    cin >> N;
    vector<ll> A(N), sum(N+1);
    ll s = 0;
    rep(i, N) {
        cin >> A[i];
        sum[i+1] = sum[i] + A[i];
        s += A[i];
    }
    ll res = INF, l, r;
    rep(i, N) {
        l = sum[i];
        r = s - l;
        res = min(res, abs(r - l));
    }
    cout << res << endl;
}

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

int main(void)
{
  int r, g, m;
  cin >> r >> g;
  
  if(g <= 4500 && r >= 0)
  {
    m = 2 * g - r;
  }
  
  cout << m << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.io.*;

public class Main{

	public static void main(String args[]){

		
		try{
			BufferedReader r =
					new BufferedReader(new InputStreamReader(System.in));

			String s;

			while (( s = r.readLine() ) != null){

				int count = 0;
				for(int i=0; i<10; i++){
					for(int j=0; j<10; j++){
						for(int k=0; k<10; k++){
							for(int l=0; l<10; l++){
								if( (i+j+k+l)== Integer.parseInt(s)){
									count ++;
								}	
							}
						}
					}
				}
				
				System.out.println(count);
				
			}
			
			
			
		} catch(IOException e){
		}

	}


}

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

#define I inline
#define fi first
#define se second
#define R register
#define LL long long
#define mp make_pair
#define reg register int
#define pii pair<int,int>
#define fo(i, a, b) for(reg i = a; i <= b; i++)
#define fd(i, a, b) for(reg i = a; i >= b; i--)
#define cr const reg&
using namespace std;
const int inf = 2147483647;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

I int _max(cr x, cr y) {return x > y ? x : y;}
I int _min(cr x, cr y) {return x < y ? x : y;}
I int read() {
	reg x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return x * f;
}
I void ptt(cr x) {if(x >= 10) ptt(x / 10); putchar(x % 10 + '0');}
I void put(cr x) {x < 0 ? putchar('-'), ptt(-x) : ptt(x);}
I void pr1(cr x) {put(x), putchar(' ');}
I void pr2(cr x) {put(x), puts("");}

char ss[21][21];
int d[21][21];
queue<pii> q;

int main() {
	reg n = read(), m = read();
	fo(i, 1, n) scanf("%s", ss[i] + 1);
	reg ans = 0;
	fo(i, 1, n) fo(j, 1, m) if(ss[i][j] != '#'){
		memset(d, 0, sizeof(d));
		d[i][j] = 1;
		q.push(pii{i, j});
		while(!q.empty()) {
			pii now = q.front(); q.pop();
			reg x = now.fi, y = now.se;
			ans = _max(ans, d[x][y]);
			fo(k, 0, 3) {
				reg nx = x + dx[k], ny = y + dy[k];
				if(nx < 1 || ny < 1 || nx > n || ny > m) continue;
				if(ss[nx][ny] == '#') continue;
				if(!d[nx][ny]) {
					d[nx][ny] = d[x][y] + 1;
					q.push(pii{nx, ny});
				}
			}
		}
	} pr2(ans - 1);
	return 0;
}



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

int main() {

    int a, b;
    cin >> a >> b;
    
    int sum = a + b;

    if(sum % 2 == 0){
        cout << sum / 2 << endl;
    }
    else{
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
//#include <GOD>
#include <bits/stdc++.h>
# define M_PI   3.14159265358979323846
using namespace std;
typedef long long ll;
#define pb push_back
#define len length
ll n,x;
map <ll,ll> mp;
int main(){
	cin>>n;
	for(int i=0;i<n-1;i++){
		cin>>x;
		mp[x]++;
	}
	for(int i=1;i<=n;i++){
		cout<<mp[i]<<endl;
	}
}



Measured memory_bytes: 16100
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String ans = "Yes";
		String wo[] = new String[n];
		for (int i = 0; i < n; i++) {
			wo[i] = sc.next();

			for (int j = 0; j < i; j++) {
				if (wo[j].equals(wo[i])) {
					ans = "No";
				}
			}
		}
		for (int i = 1; i < n; i++) {
			if (wo[i - 1].charAt(wo[i - 1].length() - 1) != wo[i].charAt(0)) {
				ans = "No";
			}
		}
		System.out.println(ans);

	}
}

Measured memory_bytes: 23124
#include <iostream>
#include <string>
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;

char GetHead(string& s) {
    return s[0];
}
int main(void) {
    string a,b,c;
    cin >> a >> b >> c;
    char target = GetHead(a);
    a.erase(a.begin());
    while(1) {
        if (target == 'a') {
            if (a == "") {
                cout << "A" << endl;
                break;
            }
            target = GetHead(a);
            a.erase(a.begin());
        } else if (target == 'b') {
            if (b == "") {
                cout << "B" << endl;
                break;
            }
            target = GetHead(b);
            b.erase(b.begin());
        } else if (target == 'c') {
            if (c == "") {
                cout << "C" << endl;
                break;
            }
            target = GetHead(c);
            c.erase(c.begin());
        }
    }
    return 0;
}


Measured memory_bytes: 3612
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
#define mem(a,n) memset(a,n,sizeof(a,n,sizeof(a))
#define rep(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
const int mod=1e9+7;
const double eps=1e-6;
const int N=1e4+5;
const int w=20003;
char s[N];
bool flag[2][2][40009];
int main()
{
    int _x=0,x,y,p,q,sum,now=1;
    scanf("%s%d%d",s+1,&x,&y);
    int len=strlen(s+1);
    x+=w,y+=w;
    while(now<=len&&s[now]=='F') now++,_x++;
    flag[0][0][w+_x]=flag[1][0][w]=1;
    while(now<=len)
    {
        now++;
        sum=0;
        p^=1;
        q^=p;
        while(now<=len&&s[now]=='F') sum++,now++;
        for(int i=w-len;i<=w+len;i++)
            flag[p][q][i]=flag[p][q^1][i+sum]|flag[p][q^1][i-sum];
    }
    if(p==1&&flag[0][q^1][x]&&flag[1][q][y]||p==0&&flag[0][q][x]&&flag[1][q][y])
        puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 384
import java.util.*;
import javax.lang.model.util.ElementScanner6;
//import java.lang.Math;

public class Main {

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

        // 入力
        int n = sc.nextInt();
        int k = sc.nextInt();
        //String s = sc.next();

        // 処理
        int[] w = new int[n];
        for(int i = 0; i < k; i++){
            int d = sc.nextInt();
            for(int j = 0; j < d; j++){
                int a = sc.nextInt();
                w[a-1] = 1;
            }
        }
        int out = 0;
        for(int i = 0; i < n; i++){
            if (w[i] == 0) out++;
        }

        // 出力
        System.out.println(out);
    }
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  i64 N, H; cin >> N >> H;
  vi32 a(N), b(N);
  rep(i, N) cin >> a[i] >> b[i];
  sort(all(a)), sort(all(b));
  reverse(all(a)), reverse(all(b));

  int ans = 0;
  rep(i, N) {
    if (b[i] < a[0]) break;
    ans++;
    H -= b[i];
    if (H <= 0) {
      cout << ans << '\n';
      return;
    }
  }
  ans += (H + a[0] - 1) / a[0];
  cout << ans << '\n';
}


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

using std::cout;
using std::cin;
using std::endl;
using std::pow;
using std::vector;
using std::string;

int main(){
    int N,i,j,tmp,sum=0,out;
    cin >> N;
    vector<int> a(N);
    for(i=0;i<N;i++){
        cin >> tmp;
        a.at(i) = tmp;
        sum ^= tmp;
    }
    for(i=0;i<N;i++){
        out = sum ^ a.at(i);
        cout << out << ' ';
    }    
}

Measured memory_bytes: 3960
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        final int N = Integer.parseInt(sc.next());
        int[] a = IntStream.range(0, N).map(i -> Integer.parseInt(sc.next())).filter(i -> i % 2 == 0).toArray();
        int ans = 0;
        
        for (int i = 0; i < a.length; i++) {
            while (true) {
                a[i] /= 2;
                ans++;
                if (a[i] % 2 != 0) {
                    break;
                }
            }
        }
        
        out.println(ans);
        
        out.flush();
    }
}

Measured memory_bytes: 32824
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <cstdio>

using namespace std;

static const char DOWN = '\\';
static const char EVEN = '_';
static const char UP = '/';

struct AREA {
  int index;
  int area;
};

int main() {
  stack<int> input;
  vector<AREA> answer;

  int total = 0;
  string data;
  cin >> data;
  AREA current = {};
  int lastIndex = 0;
  for (int i = 0; i < data.length(); i++) {
    switch (data[i]) {
    case DOWN:
      input.push(i);
      break;
    case EVEN:
      break;
    case UP:
      if (input.empty()) {
        continue;
      }
      lastIndex = input.top();
      input.pop();
      current.area = i - lastIndex;
      current.index = lastIndex;
      total += current.area;
      while (answer.size() > 0 && answer[answer.size() - 1].index > lastIndex) {
        current.area += answer[answer.size() - 1].area;
        answer.pop_back();
      }
      answer.push_back(current);
      break;
    default:
      break;
    }
  }

  cout << total << endl;  
  cout << answer.size();
  for (AREA ans : answer) {
      cout << " " << ans.area;
  }  
  cout << endl;

  return 0;
}



Measured memory_bytes: 3308
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define vi vector<int>
#define pi pair<int, int>
#define pb push_back
#define ppb pop_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()


using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int N = 1e5 + 667;

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

    int w, h, n, cnt = 0;
    cin >> h >> w >> n;
    if(h >= w){
        while(n > 0){
            n -= h;
            cnt++;
        }
    }
    else{
        while(n > 0){
            n -= w;
            cnt++;
        }
    }
    cout << cnt;
    return 0;
}


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

#define ll long long
#define F first
#define S second

const int mod = 1000000007;
const int M = 100005;

ll dp[105][M];

int main() {
	int T = 1;
	// cin>>T;
	while(T--)
	{
		string a,b;	cin>>a>>b;
		
		string A = "#"+a;
		string B = "#"+b;
		
		int n = a.length();
		int m = b.length();
			
		int dp[n+1][m+1];
		
		for(int i=0; i<=n; i++)
		{
			for(int j=0; j<=m; j++)
			{
				if(i==0 || j==0)
				{
					dp[i][j] = 0;
				}
				else
				{
					if(A[i]==B[j])
					{
						dp[i][j] = dp[i-1][j-1] + 1;
					}
					else
						dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
				}
			}
		}
		int i=n,j=m;
		
		string ans = "";
		
		while(i>0 && j>0)
		{
			if(A[i]==B[j])
			{
				ans+= A[i];
				i--;	j--;
			}
			else
			{
				if(dp[i-1][j]>dp[i][j-1])
					i--;
				else
					j--;
			}
		}
		reverse(ans.begin(), ans.end());
		cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 35456