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

const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

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

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

struct segtree {
    int size;
    vector<ll> dat;
    ll init = 0;

    segtree(int N)
    {
        size = 1;
        while (size < N)
            size *= 2;
        dat = vector<ll>(2 * size - 1, init);
    }

    ll op(ll a, ll b)
    {
        return max(a, b);
    }

    void update(int i, ll x)
    {
        i += size - 1;
        dat[i] = x;
        while (i > 0) {
            i = (i - 1) / 2;
            dat[i] = op(dat[2 * i + 1], dat[2 * i + 2]);
        }
        return;
    }

    ll value(int i)
    {
        return dat[i + size - 1];
    }

    ll query(int a, int b) //[a,b)
    {
        return query(a, b, 0, 0, size);
    }

    ll query(int a, int b, int k, int l, int r)
    {
        if (r <= a || b <= l)
            return init;
        if (a <= l && r <= b)
            return dat[k];
        ll lv, rv;
        lv = query(a, b, 2 * k + 1, l, (l + r) / 2);
        rv = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return op(lv, rv);
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    segtree st(300001);
    REP(i, n)
    {
        int a;
        cin >> a;
        st.update(a, st.query(max(0, a - m), min(a + m, 300000) + 1) + 1);
    }
    cout << st.query(0, 300001) << endl;
}

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

int main() {
    ll n;
    cin >> n;
    ll sum = 0;
    REP(i, n) {
        if(i % 3 != 0 && i % 5 != 0) {
            sum += i;
        }
    }
    cout << sum << endl;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>v(n,1);
	int ans=1;
	for(int i=2;i<=n;++i){
		int num=i;
		for(int j=2;j<=i;++j){
			while(num&&num%j==0){
				num/=j;
				++v.at(j-1);
			}
		}
	}
	for(auto&i:v)ans=(int64_t)ans*i%(int64_t)(1e9+7);
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String s = sc.next();
		
		// 計算
	    int result = Integer.MAX_VALUE;
	    for(int i = 0; i < s.length() - 2; i++){
	        String now = s.substring(i, i + 3);
	        int n = Integer.valueOf(now);
	        result = min(result, abs(n - 753));
	    }

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

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
vector<int> dy = {1, 1, 0, -1, -1, -1, 0, 1};
vector<int> dx = {0, 1, 1, 1, 0, -1, -1, -1};
vector<vector<char>> place(vector<vector<char>> s, char c, int y, int x){
  char c2;
  if (c == 'o'){
    c2 = 'x';
  }
  if (c == 'x'){
    c2 = 'o';
  }
  s[y][x] = c;
  for (int i = 0; i < 8; i++){
    if (s[y + dy[i]][x + dx[i]] == c2){
      int y2 = y + dy[i];
      int x2 = x + dx[i];
      while (s[y2][x2] == c2){
        y2 += dy[i];
        x2 += dx[i];
      }
      if (s[y2][x2] == c){
        int y2 = y + dy[i];
        int x2 = x + dx[i];
        while (s[y2][x2] == c2){
          s[y2][x2] = c;
          y2 += dy[i];
          x2 += dx[i];
        }
      }
    }
  }
  return s;
}
int main(){
  vector<vector<char>> s(10, vector<char>(10, '#'));
  for (int i = 1; i <= 8; i++){
    for (int j = 1; j <= 8; j++){
      cin >> s[i][j];
    }
  }
  bool prev = false;
  char c = 'o';
  while (1){
    int cnt = 0;
    for (int i = 1; i <= 8; i++){
      for (int j = 1; j <= 8; j++){
        if (s[i][j] == c){
          cnt++;
        }
      }
    }
    vector<vector<char>> next;
    int mx = -1;
    if (c == 'o'){
      for (int i = 1; i <= 8; i++){
        for (int j = 1; j <= 8; j++){
          if (s[i][j] == '.'){
            vector<vector<char>> s2 = place(s, c, i, j);
            int cnt2 = 0;
            for (int k = 1; k <= 8; k++){
              for (int l = 1; l <= 8; l++){
                if (s2[k][l] == c){
                  cnt2++;
                }
              }
            }
            if (cnt2 > cnt + 1 && cnt2 > mx){
              mx = cnt2;
              next = s2;
            }
          }
        }
      }
      c = 'x';
    } else {
      for (int i = 8; i >= 1; i--){
        for (int j = 8; j >= 1; j--){
          if (s[i][j] == '.'){
            vector<vector<char>> s2 = place(s, c, i, j);
            int cnt2 = 0;
            for (int k = 1; k <= 8; k++){
              for (int l = 1; l <= 8; l++){
                if (s2[k][l] == c){
                  cnt2++;
                }
              }
            }
            if (cnt2 > cnt + 1 && cnt2 > mx){
              mx = cnt2;
              next = s2;
            }
          }
        }
      }
      c = 'o';
    }
    if (mx == -1){
      if (prev){
        break;
      } else {
        prev = true;
      }
    } else {
      prev = false;
      swap(s, next);
    }
  }
  for (int i = 1; i <= 8; i++){
    for (int j = 1; j <= 8; j++){
      cout << s[i][j];
    }
    cout << endl;
  }
}


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

int main() {
  	long long int X;
  	cin >> X;
  
  	long long int a_, b_;
  
  	for (long long int a = -3000; a < 3000; a++){
      	for (long long int b = -3000; b < 3000; b++){
          	if (a * a * a * a * a - b * b * b * b * b == X) {
              	a_ = a;
              	b_ = b;
            }
        }
    }
  
  	cout << a_ << " " << b_ << endl;
}

Measured memory_bytes: 3596
import copy
h,w,k=map(int,input().split())
mylist=[list(input()) for i in range(h)]
ans=0

for i in range(2**h):
    l=copy.deepcopy(mylist)
    for j in range(h):
        if (i>>j&1):
            for q in range(w):
                l[j][q]="!"
    for m in range(2**w):
        l2=copy.deepcopy(l)
        for n in range(w):
            if (m>>n&1):
                for o in range(h):
                    l2[o][n]="!"
        cnt=0
        for p in range(h):
            cnt+=l2[p].count("#")
        if cnt==k:
            ans+=1
print(ans)

Measured memory_bytes: 9284
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

typedef long long ll;

// state(sum, i, #elements)
ll memo[2501][51][51];

long long dp(int i, long long sum, int elements, int A, vector<int> arr) {
  long ans;
  if(i == (arr.size()-1)){
    if(elements == 0)
       memo[sum][i][elements] = 0;
    else
      memo[sum][i][elements] = (sum/(float)elements == A)? 1 : 0;
    return memo[sum][i][elements];
  }
  
  if (memo[sum][i+1][elements] == -1)
    memo[sum][i+1][elements] = dp(i+1, sum, elements, A, arr);
  
  if (memo[sum+arr[i+1]][i+1][elements+1] == -1)
    memo[sum+arr[i+1]][i+1][elements+1] = dp(i+1, sum+arr[i+1], elements + 1, A, arr);

  ans = memo[sum][i+1][elements] + memo[sum+arr[i+1]][i+1][elements+1];
  return ans;  
}

int main(){
  int N, A;
  memset(memo, -1, sizeof memo); 
  cin>>N>>A;
  vector<int> arr(N);
  for(int i=0; i<N; i++)
    cin>>arr[i];
  cout<<dp(-1,0,0,A,arr)<<endl;
  return 0;
}


Measured memory_bytes: 51200
#include<stdio.h>
 
#define MAXLEN 20000
 
int garea,gareas[(MAXLEN/2)+1],gcnt,gend;
 
 
int getArea( char *inputs, int start, int end )
{
    int i;
    int ravine,water;
    
    gareas[gcnt]=ravine=water=0;
    for( i=start; i!=end; i++ ) {
        if( '\\'== *(inputs+i) ) {
           	water+=(ravine*2);
            ravine++;
            water++;
        } else if( 0 != ravine && '/' == *(inputs+i) ) {
        	ravine--;
        } else {
	     	water+=ravine;
        }       
    }
	gareas[gcnt]+=water;
    
    return gareas[gcnt];
}
  
int checkRavine( char *inputs, int start )
{
    int i;
    int ravine, minh, tmpi;
    
    ravine=0;
    tmpi=minh=MAXLEN;
    for( i=start; i<=gend && '\0'!=*(inputs+i); i++ ) {
        if( 0 <= ravine && '\\'== *(inputs+i) ) {
            ravine++;
        } else if( 0 != ravine && '/' == *(inputs+i) ) {
            ravine--;
            if( ravine < minh ) {
        		minh=ravine;
        		tmpi=i;
            }
            if( 0 == ravine ) {
            	garea+=getArea( inputs, start, i+1 );
            	gcnt++;
			    gend=MAXLEN;           	
                return i-start;
            }
        }
    }
	gend=tmpi;
    return 0;
}
 
 
void getAreas( char *inputs )
{
    int i,next;
     
    next=0;
    for( i=0; '\0'!=inputs[i]; i++ ) {
    	if( '_' !=inputs[i] && '/' !=inputs[i] ) {
	        next=checkRavine( inputs, i );
	        i+=next;
        }
    }
 
    return;
}
 
int main( void ) 
{
    char inputs[MAXLEN+1];
    int i;
 
    scanf( "%s", inputs );
    garea=gcnt=0;
    gend=MAXLEN;
    getAreas( inputs );
     
    printf( "%d\n", garea );
    
    if( gcnt ) {
        printf( "%d ", gcnt );
        for( i=0; i<gcnt; i++ ) {
            printf( "%d", gareas[i] );
            if( i < gcnt-1 ) {
            	printf( " " );  
            }
        }
        printf( "\n" );
       
    } else {
        printf( "0\n" );
    }
     
    return 0;
}

Measured memory_bytes: 576
#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

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

    int d;
    cin >> d;
    if (d == 22) cout << "Christmas Eve Eve Eve";
    if (d == 23) cout << "Christmas Eve Eve";
    if (d == 24) cout << "Christmas Eve";
    if (d == 25) cout << "Christmas";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef pair<int,int>P;
typedef long long ll;

char s[400];
ll dp[300][300];

int main(){
	int n;cin>>n;
	rep(i,n)cin>>s[i];
	dp[0][0]=1;
	rep(i,n)rep(j,i+1){
		if(dp[i][j]==0)continue;
		if(s[i]=='U'){
			(dp[i+1][j+1]+=dp[i][j])%=MOD;
			if(j)(dp[i+1][j]+=dp[i][j]*j)%=MOD;
		}
		if(s[i]=='D'){
			if(j){
				(dp[i+1][j-1]+=dp[i][j]*j*j)%=MOD;
				(dp[i+1][j]+=dp[i][j]*j)%=MOD;
			}
		}
		if(s[i]=='-'){
			(dp[i+1][j]+=dp[i][j])%=MOD;
		}
	}
	cout<<dp[n][0]<<endl;
}


Measured memory_bytes: 3596
n=int(input())
A=list(map(int,input().split()))
q=int(input())
M=list(map(int,input().split()))

pattern=[]

for i in range(2**n):
    s=0
    for j in range(n):
        if i >> j & 1:
            s+=A[j]
    pattern.append(s)
P=set(pattern)

for m in M:
    print('yes' if m in P else 'no')


Measured memory_bytes: 43076
#include <iostream>
#include <cstring>

using namespace std;

const int N = 100, W = 10000;
int values[N], weights[N];
int dp[N + 1][W + 1];

int main(){
	int n,w;
	memset(dp, 0, sizeof(dp));
	cin >> n >> w;
	for(int i = 0;i < n;++i){
		cin >> values[i] >> weights[i];
	}
	for(int i = n;0 <= i;--i){
		for(int j = 0;j <= w;++j){
			if(i == N) dp[i][j] = 0;
			else if(j < weights[i]) dp[i][j] = dp[i + 1][j];
			else dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - weights[i]] + values[i]);
		}
	}
	cout << dp[0][w] << endl;
	return 0;
}

Measured memory_bytes: 5116
n,m,x,y=map(int,input().split())
xl=list(map(int,input().split()))
yl=list(map(int,input().split()))
 
xl.append(x)
yl.append(y)
if max(xl) < min(yl) and x < y:
    print('No War')
else:
    print('War')

Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	N := nextInt()
	ans := (N - 1) * N / 2
	fmt.Fprintln(out, ans)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// Genericsがないので筋肉で...
// interfaceでの取扱がようわからんし
func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// mapからkeysとvaluesを返す感じのやつ
// なんかしらんけどmap[interface{}]interface{}しか受け付けない。なんのためのinterface{}やねん
// なので呼ぶときのmapはmap[int]stringとかじゃダメ
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
	return
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef long long ll;
typedef double D;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }



double solve(double a0) {
	D ret = a0, a_ = a0;
	for_(i, 2, 11) {
		if (i%2 == 0) {
			a_ *= 2.0;
		} else {
			a_ /= 3.0;
		}
		ret += a_;
	}
	return ret;
}

int main() {
	D a0;
	
	while (cin >> a0) {
		printf("%.8f\n", solve(a0));
	}	
	
	return 0;
}

Measured memory_bytes: 1236
#include<iostream>
using namespace std;
int t,n,s,f,sum=0;
int main(void){
  while(cin >> t && t){
    cin >> n;
    sum = 0;
    for(int i = 0; i < n; i++){
      cin >> s >> f;
      sum += (f - s);
    }
    if(sum >= t){
      cout << "OK" << endl;
    }
    else{
      cout << t - sum << endl;
    }
  }
}


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

int main(){
  string s1, s2, s3;
  cin>>s1;
  cin>>s2;
  cin>>s3;
  int c1 = 0, c2 = 0, c3 = 0;
  int j = 1;
  while(true){
    if(j == 1){
      if(c1 <= s1.length() - 1){
        if(s1[c1] == 'a')
          j = 1;
        else if (s1[c1] == 'b')
          j = 2;
        else
          j = 3;
        //j = (s1[c1] == 'a'? 1:(s1[c1] == 'b'? 2 : 3) );
        c1++;
      }else
        break;
    }
    if(j == 2){
      if(c2 <= s2.length() - 1){
        if(s2[c2] == 'a')
          j = 1;
        else if (s2[c2] == 'b')
          j = 2;
        else
          j = 3;
        //j = (s2[c2] == 'a'? 1:(s2[c2] == 'b'? 2 : 3) );
        c2++;
      }else
        break;
    }
    if(j == 3){
      if(c3 <= s3.length() - 1){
        if(s3[c3] == 'a')
          j = 1;
        else if (s3[c3] == 'b')
          j = 2;
        else
          j = 3;
        //j = (s3[c3] == 'a'? 1:(s3[c3] == 'b'? 2 : 3) );
        c3++;
      }else
        break;
    }
  }
  if(j == 1)
    cout<<"A"<<endl;
  else if(j == 2)
    cout<<"B"<<endl;
  else
    cout<<"C"<<endl;
  //cout<<(j == 1? "A":(j == 2? "B" : "C") )<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;

int cnt[26];

int main()
{
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	memset(cnt, 63, sizeof cnt);
	while (n--)
	{
		int tmp[26] = {0};
		string s;
		cin >> s;
		for (auto x : s)
			tmp[x - 'a']++;
		for (int i=0; i<26; i++)
			cnt[i] = min(cnt[i], tmp[i]);
	}
	for (int i=0; i<26; i++)
		for (int j=0; j<cnt[i]; j++)
			cout << (char)(i + 'a');
	cout << "\n";
		

	return 0;
}

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

int main() {
  ll x; cin >> x;
  for (ll b=-1500; b<=1500; b++) {
    ll a5=x+(ll)pow(b,5);
    if ((ll)pow((ll)pow(a5, 0.2), 5) == a5) {
      cout << (ll)pow(a5, 0.2) << " " << b;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 4064
//SkGeN
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstring>
#include<climits>
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<chrono>
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> p64;
typedef vector<ll> v64;
const int N = 2 * 1e5 + 10;
const ll inf = 1e18 + 100;
const ll mod = 1e9 + 7;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(long long i=s;i<=e;i++)
#define brep(i,s,e) for(long long i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
void solve() {
    ll n, k;
    cin>>n>>k;
    ll q = n / k;
    ll rem = n - q*k;
    cout<<min(rem , abs(rem - k))<<"\n";
}
int main()
{
    DANGER;
    ll t = 1;
    //cin>>t;
    while(t--) {
        solve();
    }
return 0;
}
//---->O ,,

Measured memory_bytes: 256
N,A,B,C,D=map(int,input().split())
S=input()
s=list(S.split("#"))

answer="Yes"


if "##" in S[min(A,C):max(B,D)]:
    answer="No"
if C<D:
    pass
else:
    if "..." not in S[B-2:D+1]:
        answer="No"
    
print(answer)
    
            
    

Measured memory_bytes: 6904
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <string>
#include <cmath>
#include <cassert>
#define SIZE 2005
#define INF 1000000005

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

vector <int> vec[SIZE];
int dep[SIZE],dp[SIZE];
int nd[SIZE],sum[SIZE];
char str[SIZE];

void dfs(int v=0,int p=-1,int d=0)
{
	dep[v]=d;
	for(int i=0;i<vec[v].size();i++)
	{
		int to=vec[v][i];
		if(to!=p) dfs(to,v,d+1);
	}
}
int getsum(int v,int p)
{
	int ret=str[v]=='1'?dep[v]:0;
	for(int i=0;i<vec[v].size();i++)
	{
		int to=vec[v][i];
		if(to!=p) ret+=getsum(to,v);
	}
	return ret;
}
void check(int v=0,int p=-1)
{
	nd[v]=(str[v]-'0');
	sum[v]=0;
	vector <P> vx;
	for(int i=0;i<vec[v].size();i++)
	{
		int to=vec[v][i];
		if(to!=p)
		{
			check(to,v);
			vx.push_back(P(sum[to]+nd[to],dp[to]+nd[to]));
			nd[v]+=nd[to];
			sum[v]+=sum[to]+nd[to];
		}
	}
	sort(vx.begin(),vx.end());
	int all=0,mx=0;
	for(int i=0;i<vx.size();i++)
	{
		P p=vx[i];
		all+=p.first;
		mx=p.first;
	}
	if(all>=2*mx) dp[v]=all%2;
	else
	{
		P p=vx[vx.size()-1];
		if(p.second<=all-p.first) dp[v]=all%2;
		else dp[v]=p.second+p.first-all;
	}
}
int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",&str);
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);a--,b--;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	int ret=INF;
	for(int i=0;i<n;i++)
	{
		dfs(i,-1,0);
		check(i,-1);/*
		if(dp[i]==0)
		{
			printf("%d\n",i);
			for(int j=0;j<n;j++) printf("%d %d : %d\n",nd[j],sum[j],dp[j]);
			return 0;
		}*/
		if(dp[i]==0) ret=min(ret,sum[i]/2);
	}
	if(ret==INF) ret=-1;
	printf("%d\n",ret);
	return 0;
}


Measured memory_bytes: 640
M, F, R = map(int, input().split())
while not (M == -1 and F == -1 and R == -1):
 if M == -1 or F == -1: print("F")
 elif M+F >= 80: print("A")
 elif M+F >= 65: print("B")
 elif M+F >= 50 or (M+F >= 30 and R >= 50): print("C")
 elif M+F >= 30: print("D")
 else: print("F")

 M, F, R = map(int, input().split())

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

int main(){
    int H,R;
    cin >> H >> R;
    if(H+R<0){
        cout << -1 << endl;
    }
    else if(H+R>0){
        cout << 1 <<endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}


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



main()
{
	int n;
	cin >> n;
	long long ar[n];
	
	for(int i=0;i<n;i++)
	{
		cin >> ar[i];
	}
	for(int i=1;i<n;i++)
	{
		ar[i]=ar[i]/__gcd(ar[i],ar[i-1]) * ar[i-1];
	}
	cout << ar[n-1];
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String [] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//??£?¨?
		String line ="";
		char temp; //char????????????????????´???
		int [] table = new int[26]; //??¢?????????????????????26???????????¨?????????
		//??°?????????
		while(sc.hasNext()){
			//?????????(??±???)?????????
			line = sc.nextLine();
			//??¨???????????????????°???????????????´
			String lower = line.toLowerCase();
			//?????????????????????
			for(int i =0; i < lower.length(); i++){
				//?°??????????char????????????
				temp = lower.charAt(i);
				//System.out.print(temp+ " ");
				//??¢??????????????????????°???????????????°????????????
				if('a' <= temp  && temp  <= 'z'){
					table[temp - 'a']++;
				}
			}
		}
		//????????????????????????
		for(int i = 0; i < table.length; i++){
			System.out.println( (char )('a' + i)+ " : "+ table[i]);
		}
	}
}

Measured memory_bytes: 26212
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
#include<map>
#include <limits>
# include <iomanip>
#include<queue>
#define INF 1000000009;
#define inl long long
using namespace std;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}
int kaizyo(int a) {
	long long ans = 1;
	for (int i = a; i > 0; i--) {
		ans *= i;
		ans = ans % 1000000007;
		//cout << ans << endl;
	}
	ans = ans % 1000000007;
	return ans;
}
int main() {
	int a = 0, b = 0;
	cin >> a >> b;
	cout << max(a + b, max(a - b, a * b)) << endl;
	return 0;
}






Measured memory_bytes: 256
def insert_sort(a, n, g)
  cnt = 0
  g.upto(n-1){|i|
    v = a[i]
    j = i - g
    while j >= 0 && a[j] > v
      a[j+g] = a[j]
      j = j - g
      cnt += 1
    end
    a[j+g] = v
  }
  cnt
end

def shell_sort(a, n)
  cnt = 0
  g = []
  h = 1
  loop do
    break if h > n
    g.unshift(h)
    h = h * 3 + 1
  end
  p g.size
  puts g*" "
  g.size.times{|i|
    cnt += insert_sort(a, n, g[i])
  }
  p cnt
end

n=gets.to_i
a=$<.read.split.map &:to_i

shell_sort(a, n)
puts a



Measured memory_bytes: 103088
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        Map<String, Integer> map = new HashMap<>();
        for(int i=0; i<a; i++){
            String str = sc.next();
            if(map.containsKey(str)){
                map.put(str, map.get(str) + 1);
            } else {
                map.put(str, 1);
            }
        }

        int b = sc.nextInt();

        for(int i=0; i<b; i++){
            String str = sc.next();
            if(map.containsKey(str)){
                map.put(str, map.get(str) - 1);
            }
        }

        int max = 0;

        for(int i: map.values()){
            if(i>max){
                max=i;
            }
        }

        System.out.println(max);
    }

    public static void printListOneLine(List list){
        for(int i=0; i<list.size(); i++){
            System.out.println(list.get(i));
        }
    }

    public static void printList(List list){
        for(int i=0; i<list.size(); i++){
            if(i == list.size()){
                System.out.println(list.get(i));
            } else {
                System.out.print(String.format("%d ", list.get(i)));
            }
        }
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }

    public static int gcd(int a, int b){
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static int lcm(int a, int b){
        return a * b / gcd(a, b);
    }
}


Measured memory_bytes: 21076
#include <iostream>
#include <map>

using namespace std;

int main(void) {
  std::map<std::string, std::string> enki;
  enki["A"] = "T";
  enki["T"] = "A";
  enki["C"] = "G";
  enki["G"] = "C";

  std::string s;
  cin >> s;
  cout << enki[s] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n, mx, mi, ans, a[55];
int main() {
	ll i, t;
	cin>>n;
	for(i=0; i<n; i++) {
		cin>>a[i];
		if(a[i]>mx) mx=a[i], mi=i;
	}
	while(mx>=n) {
		t = mx / n;
		ans += t;
		for(i=0; i<n; i++) a[i] += t;
		a[mi] = mx%n;
		mx = -1;
		for(i=0; i<n; i++) if(a[i]>mx) mx=a[i], mi=i;
	}
	cout<<ans;
	return 0;
}

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


int main(){
		#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("myin.txt", "r", stdin);
    // for writing output to output.txt
    freopen("myout.txt", "w", stdout);
#endif

int x;
cin>>x;
if(x>=30) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}


Measured memory_bytes: 3544
#include<iostream>
#include<cmath>
using namespace std;
int find(int a[],int n,int k)
{
	int dp[n];
	dp[0]=0;
	for(int i=1;i<min(n,k);i++)
	dp[i]=abs(a[i]-a[0]);
	for(int i=k;i<n;i++)
	{
	    dp[i]=dp[i-1]+abs(a[i]-a[i-1]); 
	    for(int j=i-1;j>=0&&i-j<=k;j--)
	    {
		if(dp[j]+abs(a[i]-a[j])<dp[i])
	        dp[i]=dp[j]+abs(a[i]-a[j]);
	    }
	}
	return dp[n-1];
}

int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	cout<<find(a,n,k);
}

Measured memory_bytes: 1024
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353



r = int(sys.stdin.buffer.readline())
a = r * 2 * math.pi
print(a)


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;

    double res = 0.;
    for(int i = 1; i <= n; ++i){
        int cnt = 0;
        int score = i;
        while(score < k){
            score *= 2;
            cnt++;
        }
        res +=  1./(n*(1<<cnt));
    }
    printf("%.10f\n", res);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
  
typedef long long ll; 
typedef pair<ll, ll> pll;
typedef vector<ll> vl; 
typedef vector<vl> vvl; 
 
#define MOD 1000000007  
#define ffor(a, b, c) for (ll(a) = (b); (a) < (c); ++(a))  
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL)); 
#define rep(i, n) ffor(i, 0, n) 
#define ff first 
#define ss second  
#define pb push_back 
#define ALL(v) v.begin(), v.end()  
#define TC(t) while (t--) 
#define N 200005
#define inf 1e18
#define modd 998244353
#define pp(var) cout<<var<<"\n";
#define pm(var1, var2) cout<<var1<<" "<<var2<<"\n"; 


int main(){
    fast;
    ll l,r,i,j,m,k,a,b,c,q,t,x,y,d,n;
    cin>>k;
    cin>>a>>b;
    x = a/k;
    if(x*k == a){ pp("OK"); return 0; }
    x++;
    if(x*k <= b) { pp("OK"); return 0; }
    else { pp("NG"); return 0; }
}

Measured memory_bytes: 3652
#include<stdio.h>

int main(void)
{
 	int a, b, c;
	int i;
	int count = 0;
 	
	scanf("%d %d %d", &a, &b, &c);
	
	//c????´???°
	for (i = a; i <= b; i++){
		if(0 == (c % i))
		count++;
		
	}
	printf("%d\n", count);
	
	return 0;
   
}

Measured memory_bytes: 2696
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define t(x) cerr<<#x<<":"<<x<<'\n';
#define t2(a,n) { cerr<<#a<<" = "; for(int i=0; i<n; ++i){ cerr << a[i] << ' '; } ; cerr <<'\n'; }
#define t3(a){ cerr<<#a<<" = "; for(auto i: a){ cerr<<i<<" "; } cerr<<'\n'; }

struct dsu{
  int n;
  vector<int> parent, size;
  dsu(int x) : n(x) {
    parent.resize(n);
    size.resize(n);
    this->init();
  };

  void init(){
    for(int i=0; i<n; ++i){
      parent[i] = i;
      size[i] = 1;
    }
  }

  int get_set(int x){
    if( parent[x] == x ){
      return x;
    }
    return parent[x] = get_set(parent[x]);
  }

  void unite(int a, int b){
    int aa = get_set(a);
    int bb = get_set(b);
    if( aa == bb ){ return ;}

    if( size[bb] > size[aa] ){
      swap(aa,bb);
    }
    size[aa] += size[bb];
    parent[bb] = aa;
  }
  void verify(){
    cout<<"ELEMENT |  PARENT  | SIZE \n";
    for(int i=0; i<n; ++i){
      cout<<i<<" "<<parent[i]<<" "<<size[i]<<"\n";
    }
  }
};
typedef struct dsu ds;


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

	int n,k,l;
	cin>>n>>k>>l;
	ds a(n) , b(n);
	for(int i=0; i<k; ++i){
		int p,q; cin>>p>>q; p--; q--;
		a.unite(p,q);
	}
	for(int i=0; i<l; ++i){
		int p,q; cin>>p>>q; p--; q--;
		b.unite(p,q);
	}
	map<pair<int,int>,int> cnt;
	for(int i=0; i<n; ++i){
		cnt[{a.get_set(i),b.get_set(i)}]++;
	}
	for(int i=0; i<n; ++i){
		cout<<cnt[{a.get_set(i),b.get_set(i)}]<<" ";
	}
	cout<<endl;


	#ifdef LOL
	    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	#endif
	return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    ios_();
    int n;
    cin >> n;
    vector<ll> v(n);
    for(auto& i : v) cin >> i;

    multiset<ll> st;
    st.insert(INF);

    REP(i, n){
        auto itr = st.upper_bound(-v[i]);
        if(*itr < INF){
            st.erase(itr);
        }
        st.insert(-v[i]);
    }

    cout << st.size() - 1 << endl;
    return 0;
}


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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> ball(n+1);
	for (int i = 0; i < n; i++)cin >> ball.at(i);
	sort(ball.begin(), ball.end());
	int type = 0;
	int i = 0;
	vector<int> dif(200000);
	while(i<n){
		if (ball.at(i) != ball.at(i + 1)) {
			dif.at(type) = i;
			type++;
		}
		i++;
	}
	dif.at(type) = n;
	vector<int> num(type);
	for (int j = 0; j < type; j++) num.at(j) = dif.at(j + 1) - dif.at(j);
	sort(num.begin(), num.end());
	int ans = 0;
	for (int j = 0; j < type - k; j++)ans += num.at(j);
	cout<<ans<<endl;
}

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

int main(){
//srandom((unsigned long)time(NULL));
long long n;
cin>>n;
long long ans=0;
long long p[n];
for(long long i=0;i<n;i++){
    cin>>p[i];
}
long long mn=p[0];
for(long long i=0;i<n;i++){
    if(p[i]<=mn){
        mn=p[i];
        ans++;
    }
    

}
cout<<ans<<endl;


return 0;
}

Measured memory_bytes: 1792
def main():
    import itertools
    n = int(input())
    spot = []
    for i in range(n):
        x,y = map(int,input().split())
        spot.append([x,y])
    s = 0
    cnt = 0
    for i in itertools.permutations([i for i in range(n)]):
        cnt += 1
        for j in range(len(i)-1):
            s += ((spot[i[j+1]][0]-spot[i[j]][0])**2+(spot[i[j+1]][1]-spot[i[j]][1])**2)**0.5
    print(s/cnt)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

H, W = ISI()
a = [[j for j in IS()] for i in range(H)]
b = []
for x in a:
    if "#" in x:
        b.append(x)
c = []
for y in zip(*b):
    if "#" in y:
        c.append(y)
for a in zip(*c):
    print("".join(a))

Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a+b == 15){
		cout<<"+"<<endl;
	}else if(a*b == 15){
		cout<<"*"<<endl;
	}else {
		cout<<"x"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>

using namespace std;

vector<bool> eratosthenes(long long n){
    vector <bool> IsPrime;
    if (n+1 > IsPrime.size()){
        IsPrime.resize(n+1, true);
    }
    IsPrime[0] = false;
    IsPrime[1] = false;

    for (long long i = 2;i*i<=n;i++){
        if (IsPrime[i]){
            for (long long j=2; i*j <= n;j++){
                IsPrime[i*j] = false;
            }
        }
    }
    return IsPrime;
}

int main() {
    
    long long Q;
    cin >> Q;
    vector<bool> IsPrime = eratosthenes(100000);
    long long ans[100001];
    ans[0] = 0;
    long x=0;
    for (long i=1;i<=100000;i++){
        if(i%2 == 1 and IsPrime[i] == true and IsPrime[(i+1)/2] == true){
            x++;
        }
        ans[i] = x;
    }
    for (long i = 0;i<Q;i++){
        long l,r;
        cin >> l >> r;
        cout << ans[r] - ans[l-1] << endl;
    }

}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

vector<int>v[200000];
signed main(){
	int n,m;scanf("%d%d",&n,&m);
	rep(i,m){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		v[b].push_back(a);
	}
	int d=0;
	int cnt=0;
	for(int i=1;i<n;i++){
		bool flag=false;
		for(int j:v[i]){
			if(d<=j){
				flag=true;
			}
		}
		if(flag)cnt++,d=i;
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 7296
#include <iostream>
#include <list>
#include <vector>

using namespace std;

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

    vector<list<int>> left(n - 1);
    vector<int> cnt_right(n - 1, 0);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        left[a - 1].push_back(b - 2);
        cnt_right[b - 2]++;
    }

    int res = 0;
    list<int> l;
    for (int i = 0; i < n - 1; i++) {
        for (list<int>::iterator j = left[i].begin(); j != left[i].end(); j++) {
            l.push_back(*j);
        }

        if (cnt_right[i] > 0) {
            res++;

            for (list<int>::iterator j = l.begin(); j != l.end(); j++) {
                cnt_right[*j]--;
            }

            l.clear();
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 6400
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(new BufferedOutputStream(System.out));
		
		
		int numA = sc.nextInt(), numB=sc.nextInt(),numK=sc.nextInt();
		int subtraction = numB - numA;
		if (subtraction<numK*2){
			for (int i = numA; i <= numB; i++) {
				out.println(i);
			}
			
		}else {
			for (int i = numA; i < numA+numK; i++) {
				out.println(i);
			}
			for (int i = numB-numK+1; i <= numB; i++) {
				out.println(i);
			}
		}
		out.close();
	}

	//-----------http://codeforces.com/blog/entry/7018---------------------------------
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			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;
		}

	}
	//--------------------------------------------------------

}



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

int main()
{
  string s;
  int count = 0;
  cin >> s;
  for(int i = 0; i < 3; i++)
  {
    if(s[i] == '1')count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <deque>
#include <iomanip>
#include <bitset>
#include <complex>
#include <sstream>
#include <algorithm>
#include <limits>
#include <cmath>
#include <utility>
#include <tuple>
using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr int mod = 1e9+7;
constexpr ld eps = 1e-10;
constexpr ld pi = acos(-1.0);

#define DUMP(a) cout << #a << ": " << (a) << endl


int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; ++i) {
        cin >> a[i];
    }
    int x = 2;
    ll res = 0;
    for(int i=0; i<N; ++i) {
        if(i == 0) {
            res += a[i] - 1;
        } else {
            if(a[i] == x) {
                x++;
            } else if(a[i] > x) {
                res += 1 + (a[i] - x - 1)/x;
            }
        }
    }
    cout << res << endl;
}



Measured memory_bytes: 768
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

S = input()
X,Y=LI()

while S and S[0] == 'F':
    S = S[1:]
    X -= 1

isX = True
cur = 0
xs = []
ys = []
for i in range(len(S)):
    if S[i] == 'T':
        if cur:
            if isX:
                xs.append(cur)
            else:
                ys.append(cur)
        isX = not isX
        cur = 0
    elif S[i] == 'F':
        cur += 1

if cur:
    if isX:
        xs.append(cur)
    else:
        ys.append(cur)

X=abs(X)
Y=abs(Y)
xs.sort()
ys.sort()
xss = [0]
yss = [0]
for i in xs:
    xss.append(xss[-1]+i)
for i in ys:
    yss.append(yss[-1]+i)

memo1 = {}
def dp1(x, i):
    if abs(x) > xss[i+1]: return False
    if i < 0: return x == 0
    if (x, i) in memo1: return memo1[(x,i)]
    res = dp1(x - xs[i], i-1) or dp1(x + xs[i], i-1)
    memo1[(x,i)] = res
    return res

memo2 = {}
def dp2(x, i):
    if abs(x) > yss[i+1]: return False
    if i < 0: return x == 0
    if (x, i) in memo2: return memo2[(x,i)]
    res = dp2(x - ys[i], i-1) or dp2(x + ys[i], i-1)
    memo2[(x,i)] = res
    return res


# print(xs, ys)
print('Yes' if dp1(X, len(xs)-1) and dp2(Y, len(ys)-1) else 'No')


Measured memory_bytes: 111484
#define $ for(i=0;i<n;i++)for(j=0;j<n;j++)
#define _(a)$ for(b[i][j]=l=0;l<n;)b[i][j]=(b[i][j]+a[i][l]*p[l++][j])%m;$ a[i][j]=b[i][j];
long m=1e9+7,p[50][50],a[50][50],b[50][50],k,s;i,j,l;main(n){scanf("%d%ld",&n,&k);$ a[i][i]=1;$ scanf("%d",p[i]+j);for(;k;k/=2){if(k&1){_(a)}_(p)}$ s+=a[i][j];printf("%d",s%m);}

Measured memory_bytes: 256
#b1:マス目の初期状態
H,W = map(int,input().split())
b = [[0 for i in range(W)] for j in range(H)]
for i in range(0,H):
    line = input()
    for j in range(0,W):
        b[i][j] = line[j]
        
#全て白の行を見つける
x = []
for k in range(0,H):
    flag = True
    for k2 in range(W):
        if b[k][k2] is '#':
            flag = False
    if flag:
        x.append(k)
#全て白の列を見つける
y = []
for l in range(W):
    flag = True
    for m in range(H):
        if b[m][l] is '#':
            flag = False
    if flag:
        y.append(l)

#全て白の行と列を除いたマス目を作る
b2 = [[0 for i in range(W-len(y))] for j in range(H-len(x))]
c1,c2 = 0,0
for i in range(H):
    c2 = 0
    if i not in x:
        for j in range(W):
            if j not in y:
                b2[c1][c2]=b[i][j]
                c2 += 1
        c1 += 1

#表示
for i in range(H-len(x)):
    s = ""
    for j in range(W-len(y)):
        s += b2[i][j]
    print(s)
        

Measured memory_bytes: 3316
#include <stdio.h>

inline static void put_int(int x) {
    int s = 0;
    char f[6] = {'0', '0', '0', '0', '0', '0'};
    if (!x) {
        putchar_unlocked('0');
        return;
    }
    while (x) {
        f[s++] += x % 10;
        x /= 10;
    }

    while (s--) putchar_unlocked(f[s]);
}

int main() {
    int flag = 0, l = 0, r = 0, i = 0, tmp;

    for (;(tmp = getchar_unlocked() - 'L') >= 0; i++) {
        if (tmp) {
            // if c is R
            if (flag) {
                flag = 0;

                if ((tmp = r + 1) < l) {
                    if (r) {
                        putchar_unlocked(' ');
                    }
                    putchar_unlocked('0');

                    for (tmp++; tmp < l; tmp++) {
                        putchar_unlocked(' ');
                        putchar_unlocked('0');
                    }
                }

                if (l > 1 || r) {
                    putchar_unlocked(' ');
                }
                tmp = (l - r + 1) / 2 + (i - l) / 2;
                put_int(tmp);
                putchar_unlocked(' ');
                tmp = (i - r) - tmp;
                put_int(tmp);

                for (tmp = l + 1; tmp < i; tmp++) {
                    putchar_unlocked(' ');
                    putchar_unlocked('0');
                }
                r = i;
            }
        } else {
            // if c is L
            if (!flag) {
                flag = 1;
                l = i;
            }
        }
    }

    if ((tmp = r + 1) < l) {
        if (r) {
            putchar_unlocked(' ');
        }
        putchar_unlocked('0');

        for (tmp++; tmp < l; tmp++) {
            putchar_unlocked(' ');
            putchar_unlocked('0');
        }
    }

    if (l > 1 || r) {
        putchar_unlocked(' ');
    }
    tmp = (l - r + 1) / 2 + (i - l) / 2;
    put_int(tmp);
    putchar_unlocked(' ');
    tmp = (i - r) - tmp;
    put_int(tmp);

    for (tmp = l + 1; tmp < i; tmp++) {
        putchar_unlocked(' ');
        putchar_unlocked('0');
    }

    putchar_unlocked('\n');
}


Measured memory_bytes: 1904
#include<iostream>
#include<cstring>

using namespace std;
int main()
{
    int n;
    char str1[200],str2[100];
    std::cin >> str1;
    cin >> n;
    int cnt2=0;
    for(int i=0;i<n;i++){
        std::cin >> str2;
        int len=strlen(str2);
        int cnt=0;
        for(int i=0;i<len;i++){
            if(str2[i]==str1[0]){
                cnt++;
                break;
            }
        }

        if(cnt!=0){
            strcat(str2,str2);
            if(strstr(str2,str1)!=NULL){
                cnt2++;
            }
        }
        
    }
    cout << cnt2 << endl;

    return 0;
}



Measured memory_bytes: 3108
//  PDF 解法2.横に切って、その後縦に切る
import java.util.*;

public class Main {

    public static void main(String[] args) {

    	Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();   
        String S = sc.next();
        String ans = "";

        for (int i = 0; i < S.length(); i++) {
            char c = S.charAt(i);
            if ((int)c+N > 90) {
                int x = (int)c - 26 + N;
                ans += (char)x;
            } else {
                int x = (int)c + N;
                ans += (char)x;
            }
        }
        System.out.println(ans);
    }  
}

Measured memory_bytes: 146900
/*      Abhijith    */
#include<bits/stdc++.h>
#include<iomanip>
#define lld long long int
#define ld long double
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
using namespace std;

int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
     lld n,q;
     cin>>n>>q;
     string s;
     cin>>s;
     vector<lld> ans(n+1,0);
     rep(i,0,n-2)
     {
         if(s.substr(i,2)=="AC")
            ans[i+2]=ans[i+1]+1;
         else
            ans[i+2]=ans[i+1];
     }
     while(q--)
     {
         lld l,r;
         cin>>l>>r;
         cout<<ans[r]-ans[l]<<endl;
     }
    return 0;
}


Measured memory_bytes: 1872
a,b,c,x,y = map(int, input().split())

ans = a*x + b*y
for i in range(1, max(x,y)+1):
    C = 2*i*c + a*max(0,x-i) + b*max(0,y-i)
    ans = min(ans, C)
print(ans)


Measured memory_bytes: 9124
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> val(n);
	vector<int> dp(n+1,INT_MAX);
	dp[0]=0;
	for(int &i:val) cin>>i;
	for(int i = 0; i < n ; i++) {
		for(int j=i+1;j<=k+i;j++){
			if(j<n){
				//cout<<i<<" "<<j<<endl;
				dp[j]=min(dp[i]+abs(val[i]-val[j]),dp[j]);
			}
		}
	}
	cout<<dp[n-1]<<'\n';
}


Measured memory_bytes: 1024