akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n;
  cin >> n;
  int pt = 0, px = 0, py = 0;

  rep(i,n) {
    int t, x, y;
    cin >> t >> x >> y;
    int dt = t - pt;
    int d = abs(x-px) + abs(y-py);
    if ( dt < d || dt%2 != d%2 ) {
      cout << "No" << endl;
      return 0;
    }
    px = x;
    py = y;
    pt = t;
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, a = 0, b = 0;
    string s;
    cin >> n >> s;
    for(int i = 0; i < n; i++){
        if(s[i] == 'R'){
            a++;
        }else{
            b++;
        }
    }
    cout << (a > b? "Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import itertools
import copy


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    xy = []
    for i in range(n):
        a = int(readline())
        for j in range(a):
            x, y = list(map(int, readline().split()))
            xy.append([i, x-1, y])
    ls = [v for v in itertools.product([True, False], repeat=n)]
    for i, x, y in xy:
        tls = []
        for j in range(len(ls)):
            lsv = ls.pop()
            if not lsv[i] or lsv[x] == bool(y):
                tls.append(lsv)
        ls = copy.deepcopy(tls)
    t = 0
    for i in range(len(ls)):
        t = max(t, ls[i].count(True))
    print(t)


if __name__ == '__main__':
    solve()


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

int main(){
    int N;
    cin >> N;
    int scores[N];
    int score_all = 0;
    for(int i = 0; i < N; i++){
        cin >> scores[i];
        score_all += scores[i];
    }
    if(score_all % 10){
        cout << score_all << endl;
    }else{
        sort(scores, scores + N);
        for(int i = 0; i < N; i++){
            if(scores[i] % 10){
                cout << score_all - scores[i] << endl;
                return 0;
            }
        }
        cout << 0 << endl;
    }
}


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

int main(int, char**) {
  int N, D;
  std::cin >> N >> D;
  int count = 0;
  double x, y;
  for (int i = 0; i < N; i++) {
  	std::cin >> x >> y;
    if (sqrt(x*x + y*y) <= D) {
        count++;
    }
  }
  std::cout << count << std::endl;
}

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

class Main{

  public static int n;
  public static int M[][];
  public static final int WHITE = 0;
  public static final int GRAY = 1;
  public static final int BLACK = 2;
  public static final int INF = (int)Double.POSITIVE_INFINITY;

  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int e=0;
    n = sc.nextInt();
    M = new int[n][n];
    // int color[] = new int[n];
    // int d[] = new int[n];
    // int p[] = new int[n];

    for(int i = 0; i<n; i++){
      for(int j = 0; j<n; j++){
        e = sc.nextInt();
        M[i][j] = (e == -1) ? INF : e;
      }
    }

    System.out.println(prim());

  }
  static int prim(){
    int u, minv =  INF;
    int d[] = new int[n];//Tに属する頂点とV-Tに属する頂点をつなぐ編の中で、重みが最小の編の重みを記録する。
    int p[] = new int[n];//MSTにおける頂点vの親を記録していく。
    int color[] = new int[n];

    for(int i = 0; i<n; i++){
      d[i] = INF;
      p[i] = -1;
      color[i] = WHITE;
    }
    d[0] = 0;

    while(true){
      minv = INF;
      u = -1;

      for(int i = 0; i<n; i++){
        if(minv > d[i] && color[i] != BLACK){//最小の辺を見つける。初めはd[0]=0の点が始点となる。すでに探索しておらず。一番小さいものかつINFになっていない、つまりグレイになっていないということ。
          u = i;
          minv = d[i];
        }
      }

      if( u == -1)break;//見つからなければループ終了。
      color[u] = BLACK;//見つかればその辺を黒にする。

      for(int v = 0; v <n; v++){
        if(color[v] !=BLACK && M[u][v] != INF){//黒くしたノードに繋がっているかつ黒じゃない//見つけた最小の辺の後続点につながる小さい辺を見つけ、親に見つけた最小の辺の後続点を記録し、GRAYにする。
          if(d[v] > M[u][v]){
            d[v] = M[u][v];
            p[v] = u;
            color[v] = GRAY;
          }
        }
      }

    }
    int sum = 0;
    for(int i = 0; i<n; i++){
      if(p[i] != -1) sum += M[i][p[i]];
    }
    return sum;
  }
}


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

int main(){
  int n,d;
  cin>>n>>d;
  if(n%(2*d+1)!=0){
  cout <<n/(2*d+1)+1<<endl;
  }
  else{
    cout <<n/(2*d+1)<<endl;
  }
}

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

int N,M,P,sum,win;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N >> M >> P,N){
        sum=0;
        for (int i=0;i<N;++i){
            int X; cin >> X;
            if (i==M-1) win=X;
            sum+=100*X;
        }
        sum=sum*(100-P)/100;
        cout << (win?sum/win:0) << endl;
    }
}


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

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


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

int main2() {
  int M = nextInt();
  int K = nextInt();

  if (M == 0) {
    if (K == 0) {
      cout << "0 0" << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }
  if (M == 1) {
    if (K == 0) {
      cout << "0 0 1 1" << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }
  if ((1 << M)-1 >= K) {
    vector<int> ans;
    ans.push_back(K);
    REP(i, 1 << M) if (i != K) ans.push_back(i);
    ans.push_back(K);
    for (int i = (1 << M)-1; i >= 0; i--) if (i != K) ans.push_back(i);

    REP(i, ans.size()) {
      if (i > 0) printf(" ");
      printf("%d", ans[i]);
    }
    printf("\n");
  } else {
    cout << -1 << endl;
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 2932
import java.util.*
import java.math.*;
fun main(args: Array<String>) {

    val N = readLine()!!.toInt()
    //val N = readLine()!!.split("").map{it.toInt()}
    val V = readLine()!!.split(" ").map{it.toInt()}
    val C = readLine()!!.split(" ").map{it.toInt()}
    var ans = 0

    for (i in 0 until N) {
        var vc = V[i]-C[i];
        if (vc > 0) ans += vc
    }

    println(ans)
}


Measured memory_bytes: 37872
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
	if a[i] > K:
		break
	while b[j] > K - a[i]:
		j -= 1
	ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47432
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>

using namespace std;

int main(){
  int H, W, i, j, semi;  
  
  while(cin >> H >> W) {
    int dp[51][51] = {};

    for(i = 0; i < 51; i++) {
      dp[0][i] = dp[i][0] = 1000000;
    }

    dp[0][0] = 0;
    
    for(i = 1; i <= H; i++) {
      for(j = 1; j <= W; j++) {
	scanf("%1d", &semi);
	if(i != 1 || j != 1) {
	  dp[i][j] = min(dp[i][j-1],  dp[i-1][j]) + semi;
	}
      }
    }
    cout << dp[H][W] << endl;
  }
}

  

Measured memory_bytes: 1264
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <sstream>
#include <vector>
using namespace std;

int num_divisors(const int n)
{
    int counter = 0;
    for (int i = 1; i <= n; i++)
    {
        if (n % i == 0)
        {
            counter++;
        }
    }
    //cout << n << " " << counter << endl;

    return counter;
}

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

    int N; // N > 0
    cin >> N;
    int counter = 0;

    for (int i = 1; i <= N; i++)
    {
        if (i % 2 == 0)
        {
            continue;
        }
        if (num_divisors(i) == 8)
        {
            counter++;
        }
    }

    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int bw[15], bh[15], aw[210000], ah[210000];
int n, m, dp[1 << 15], L[15][210000];
int main() {
	cin >> n >> m; for (int i = 0; i < n; i++)cin >> aw[i] >> ah[i];
	for (int i = 0; i < m; i++)cin >> bw[i] >> bh[i]; aw[n] = 999999999; ah[n] = 999999999;
	for (int i = 0; i < m; i++) {
		int V = 0, D1 = 0, D2 = 0;
		for (int j = 0; j < n; j++) {
			while (D1 + aw[V] <= bw[i] && D2 + ah[V] <= bh[i]) { D1 += aw[V]; D2 += ah[V]; V++; }
			L[i][j] = V; D1 -= aw[j]; D2 -= ah[j];
		}
	}
	for (int i = 0; i < (1 << m); i++) {
		for (int j = 0; j < m; j++) {
			if ((i / (1 << j)) % 2 == 1)continue;
			dp[i + (1 << j)] = max(dp[i + (1 << j)], L[j][dp[i]]);
		}
	}
	cout << dp[(1 << m) - 1] << endl;
	return 0;
}

Measured memory_bytes: 16480
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
//#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

#define ll long long
#define SZ(x) ((int)(x).size()) 
#define ALL(v) (v).begin(), (v).end()
#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define reveach(i, v) for (__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++ i) 
#define REP(i,a,n) for ( int i=a; i<int(n); i++ )
#define FOR(i,a,n) for ( int i=n-1; i>= int(a);i-- )
#define lson rt<<1, L, m
#define rson rt<<1|1, m, R
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define fi first
#define se second
#define CLR(a, b) memset(a, b, sizeof(a))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
const int N = 3;
int a[N];
int main(){
#ifdef ac
	freopen("in.txt","r",stdin);
#endif
	//freopen("out.txt","w",stdout);
    REP(i, 0, 3) scanf("%d",  &a[i]);
    REP(i, 0, 3){
        if(a[i] % 2 == 0){
            puts("0");
            return 0;
        }
    }
    sort(a, a + 3);
    printf("%lld\n", (ll) a[0] * a[1]);
    return 0;
}


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

using namespace std;

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b;
    cin >> a >> b;
    cout << a * b;
    return 0;
}


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

int main() {
    int32_t n;
    cin >> n;
    int32_t p[n];
    for (int32_t i = 0; i < n; i++) {
        cin >> p[i];
    }
    int32_t q[n + 1];
    for (int32_t i = 0; i < n; i++) {
        q[p[i] - 1] = i;
    }
    q[n] = -1;
    int32_t m = 0;
    int32_t j = 0;
    for (int32_t i = 0; i <= n; i++) {
        if (q[i + 1] - q[i] < 0) {
            m = j > m ? j : m;
            j = 0;
        } else {
            j++;
        }
    }

    cout << n - 1 - m << endl;

    return 0;
}


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

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

    string s;
    cin >> s;
    
    s[3] = '8';
    cout << s << endl;

    return 0;
}

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


using namespace std;

int main() {
    int N;
    bool isApprove = true;
    cin >> N;
    int A[N];
    for(int i = 0;i < N;i++) {
        cin >> A[i];
    }
    for(int i = 0;i < N; i++) {
        if(A[i] % 2 == 0) {
            if((A[i]%3)!=0&&(A[i]%5)!=0) {
                isApprove = false;
                break;
            }
        }
    }

    if (isApprove) {
        cout << "APPROVED" << endl;
    } else {
        cout << "DENIED" << endl;
    }
}

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

#define BUF_SIZE 13

int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int table[256] = {
    ['A'] = 1,
    ['T'] = 1,
    ['G'] = 1,
    ['C'] = 1,
};

#define max(a, b) ((a) > (b) ? (a) : (b))

int main(void) {
    char str[BUF_SIZE];
    get_str(str, BUF_SIZE);
    size_t len = strlen(str); // including null string
#ifdef DEBUG
    printf("%lu\n", len);
#endif

    int ans = 0;
    int count = 0;
    int i;
    for(i = 0; i < len; i++) {
        if(table[(int)str[i]]) {
            count++; continue;
        }
        // update otherwise
        ans = max(ans, count);
        count = 0;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

static int N = 100;

int main(){
  int n, i, j, k, l;
  int r[N+1], c[N+1], m[N+1][N+1];
  int minmatrix;

  scanf("%d",&n);

  for(i = 1 ; i <= n ; i++){
    scanf("%d%d",&r[i],&c[i]);
  }

  for(i = 1 ; i <= n ; i++) m[i][i] = 0;

  for(l = 2 ; l <= n ; l++){
    for(i = 1 ; i <= n - l + 1 ; i++){
      j = i + l - 1;
      m[i][j] = 10000000;
      for(k = i ; k <=  j - 1 ; k++){
	minmatrix = m[i][k] + m[k+1][j] + r[i] * c[k] * c[j];
	if(m[i][j] > minmatrix) m[i][j] = minmatrix;
      }
    }
  }

  printf("%d\n",m[1][n]);

  return 0;
}



Measured memory_bytes: 2104
#include <stdio.h>

int main(){
	int a,b,x;
	
	scanf("%d %d", &a, &b);
	
	x = 100*(10-a);
	
	if (a>=10){
		printf("%d", b);
	}
		else 
		printf ("%d", b + x);
	
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a,b;	cin>>a>>b;
	cout<<a*b<<endl;


    return 0;
}



Measured memory_bytes: 3652
#include <iostream> // cin, cout
#include <algorithm> // sort
#include <vector> // vector
#include <cstdio> // printf
#include <cmath> // M_PI
#include <numeric> // accumulate
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)

int		main(void)
{
	int h, w;
	cin >> h >> w;
	while (h || w) {
		rep(i, h) {
			rep(k, w) {
				if ((i + k) % 2 == 0)
					cout << '#';
				else
					cout << '.';
			}
			cout << endl;
		}
		cout << endl;
		cin >> h >> w;
	}
	return (0);
}



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

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

  string str;
  cin >> str;

  vector<int> nums(3);

  transform(str.begin(), str.end(), nums.begin(),
            [](char ch) { return ch - '0'; });

  int count = 0;
  for (int i = 0; i < 3; i++) {
    if (nums[i] == 1) {
      count++;
    }
  }

  cout << count << '\n';

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long int ll;

int main()
{
	int n,k;
	cin>>n>>k;
	int *snk = new int[n];
	rep(i,n) snk[i] = 0;
	for(int i = 0; i < k; i++){
		int d;
		cin>>d;
		for(int j = 0; j < d; j++){
			int index;
			cin>>index;
			snk[index-1] = 1;
		}
	}
	int ans = 0;
	rep(i,n){
		if(snk[i] == 0)ans++;
	}
	cout<<ans<<endl;
	return 0;
}



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

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

  int a, b;
  cin >> a >> b;
  int d = b - a;
  int depth = (1 + d) * d / 2 - b;
  cout << depth << '\n';
  return 0;
}

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

int main ()
{
	vector <int> v;
	int n,k;cin >> n >> k;
	for (int i = 0;i < n;i++)
	{
		int x;cin >> x;
		v.push_back(x);
	}
	sort(v.begin(),v.end());
	int sum = 0;
	for (int i = 0;i < k;i++)
	{
		sum+=v[i];
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)


int n, max_i = -1;
vector<int> a;

int main()
{
  cin >> n;
  REP(i, n) {
    int w;
    cin >> w;
    a.push_back(w);
  }
  sort(a.begin(), a.end());
  max_i = *(a.end() - 1);
  int mid_d = 1 << 30;
  int mid = 1 << 30;
  REP(i, n) {
    if (mid_d >= abs(a[i] - max_i / 2) && a[i] != max_i) {
      mid_d = abs(a[i] - max_i / 2);
      mid = a[i];
    }
  }
  cout << max_i << " " << mid << endl;
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string s1, s2, s3; cin >> s1 >> s2 >> s3;
  cout << s1[0] << s2[1] << s3[2] << endl;
}


Measured memory_bytes: 256
N=int(input())
a=list(map(int, input().split()))
c=[0]*8
count=0
for i in range(N):
  for j in range(8):
    if 400*j<=a[i]<400*(j+1):
      c[j]=1
  if a[i]>=3200:
    count+=1
    
ans=[sum(c), sum(c)+count]
if sum(c)==0 and count>0:
  ans[0]=1
print(*ans)

Measured memory_bytes: 3064
import java.util.Collections;
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	Scanner sc = new Scanner(System.in);
	public void run(){
		int n = sc.nextInt();
		calc(n);
	}
	public void calc(int n){
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i = 0; i < n; i++){
			list.add(sc.nextInt());
		}
		Collections.sort(list);
		
		int max = -1;
		
		for(int i = n -1; i >= 0; i--){
			for(int j = i-1; j >= 0; j--){
				int pro = list.get(i) * list.get(j);
				if(pro < max) break;
				else if(pro > max && check(pro/10, pro%10) == 1) {
					max = pro;
				}
			}
		}
		System.out.println(max);
	}
	
	public int check(int p, int b){
		if (p == 0) return 1;
		
		int nb = p % 10;
		int np = p / 10;
		if(nb == b-1){
			return check(np, nb);
		}
		else return 0;
	}
	
	public static void main(String[] args){
		new Main().run();
	}
	
}

Measured memory_bytes: 31332
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, k;
    cin >> n >> k;

    ll ans = k;
    rep(i, n-1) {
        ans *= k-1;
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 256
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> Q;
//ll longinf=1ll<<60;
int inf=1<<29;
int dh[4]={1,0,-1,0};
int dw[4]={0,1,0,-1};
ll longinf=(1ll<<31)-1;

int main(){
      int n;
      cin>>n;
      int a[n];
      rep0(i,n) cin>>a[i];
      int q;
      cin>>q;
      int cnt=0;
      while(q--){
            int b;
            cin>>b;
            int ok=n-1;
            int ng=0;
            while(ok-ng>1){
                  int mid=(ok+ng)/2;
                  if(a[mid]>=b){
                        ok=mid;
                  }
                  else{
                        ng=mid;
                  }
            }
            if(a[ok]==b) cnt++;
      }
      cout<<cnt<<endl;
      return 0;
}


Measured memory_bytes: 3408
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<iomanip>
using namespace std;

int main()
{
	int a, b, x;
	char op;
	cin >> a >> op >> b;
	while (op != '?') {
		if (op =='+') {
			x = a + b;
		}
		if (op == '-') {
			x = a - b;
		}
		if (op == '*') {
			x = a * b;
		}
		if (op == '/') {
			x = a / b;
		}
		cout << x << endl;
		cin >> a >> op >> b;
	}
}


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

int main(){
    int n;
    cin >> n;
    vector<int>vec(n);
    rep(i,n) cin >> vec[i];
    set<int> s;
    rep(i,n) s.insert(vec[i]);
    if(s.size() == n)cout << "YES" << endl;
    else cout << "NO" <<endl;
    return 0;

}

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

using namespace std;
using ll = long long;


int main() {
    int n;
    cin>>n;
    vector<int> x,a;
    for(int i=0;i<n;i++){
        int j;
        cin>>j;
        x.push_back(j);
        a.push_back(j);
    }
    sort(a.begin(),a.end());
    int ans1,ans2;
    ans1=a[n/2-1];
    ans2=a[n/2];
    for(int i=0;i<n;i++){
        if(x[i]<=ans1) cout<<ans2<<endl;
        else cout<<ans1<<endl;
    }
    return 0;
}


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

int comb(int n, int m) {
  int ret = 1;
  for (int i = 0; i < m; i++) {
    ret *= n - i;
  }
  for (int i = 1; i <= m; i++) {
    ret /= i;
  }
  return ret;
}

int main() {
  int n, m;
  while (cin >> n >> m) {
    cout << comb(m, 2) + comb(n, 2) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 1e-8;

long long int N, M, K, H, W, L, R;

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

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> H >> W;
		vector<string>s(H);
		for (int j = 0; j < H; j++) {
			cin >> s[j];
		}
		vector<int>l(26, MOD);
		vector<int>r(26, -1);
		vector<int>u(26, MOD);
		vector<int>d(26, -1);
		for (int j = 0; j < H; j++) {
			for (int k = 0; k < W; k++) {
				if (s[j][k] == '.')continue;
				int index = s[j][k] - 'A';
				l[index] = min(l[index], k);
				r[index] = max(r[index], k);
				u[index] = min(u[index], j);
				d[index] = max(d[index], j);
			}
		}
		vector<vector<int>>edge(26, vector<int>(26));
		bool flag = false;
		for (int j = 0; j < 26; j++) {
			if (l[j] == MOD)continue;
			for (int k = l[j]; k <= r[j]; k++) {
				for (int m = u[j]; m <= d[j]; m++) {
					if (s[m][k] == '.') {
						flag = true;
					}
					else {
						int index = s[m][k] - 'A';
						if (index != j) {
							edge[j][index] = 1;
						}
					}
				}
			}
		}
		for (int j = 0; j < 26; j++) {
			vector<bool>used(26, false);
			used[j] = true;
			queue<int>Q;
			Q.push(j);
			while (!Q.empty()) {
				int cn = Q.front();
				Q.pop();
				for (int k = 0; k < 26; k++) {
					if (edge[cn][k]) {
						if (k == j) {
							flag = true;
						}
						if (!used[k]) {
							Q.push(k);
							used[k] = true;
						}
					}
				}
			}
		}
		if (flag)cout << "SUSPICIOUS\n";
		else cout << "SAFE\n";
	}
	return 0;
}


Measured memory_bytes: 2984
// ToDo
// Link: https://atcoder.jp/contests/dp/tasks/dp_b
#include <iostream>
#include <climits>
#include <set>
#include <vector>
#include <stdio.h>
#include <map>
#include <stack>
#include <algorithm>
#include <unordered_map>
#define ll long long int
#define fastio ios_base::sync_with_stdio(false)
#define fastcin cin.tie(NULL)
using namespace std;
int main(){

	fastio;
	fastcin;	
	
    
    // freopen("small_input.txt", "r", stdin);
    
    // freopen("small_output.txt", "w", stdout);
    
	int n,k;
	cin>>n>>k;

	int* a=new int[n];
	int* dp=new int[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		dp[i] = 0;
	}

	for(int i=0;i<n;i++){
		int ans = INT_MAX;

		for(int j=i-k;j<i;j++){
			if(j>=0){
				ans = min(ans,dp[j]+abs(a[i]-a[j]));
			}
		}
		if(i == 0){
			dp[i] = 0;
		}else{
			dp[i] = ans;
		}
		
	}
	// for(int i=0;i<n;i++){
	// 	cout<<dp[i]<<" ";
	// }

	cout<<dp[n-1];

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main (){
    int N;
    double ans=0,pri;
    string cur;
    cin >> N;

    for(int i=0;i<N;i++){
        cin >> pri >> cur;
        if(cur == "JPY"){
            ans += pri;
        }
        else{
            ans += pri*380000.0;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

/**
 *  Name: Chris M. Perez
 *  University: Interamerican University Metro Campus
 *
**/

#define endl '\n'
#define MOD 10E9
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define gcd(x , y) __gcd(x , y)
#define all(x) (x).begin() , (x).end()
#define forn(i , a , b) for(int i=(a);i<(b);i++)
#define forrange(j , a , b) for(int j=(a);j<=(b);j++)
#define nestedforn(i , a , b , j , c , d) for(int i=(a);i<=(b);i++) for(int j=(c);j<=(d);j++)
#define sort_all(x) sort(all(x))
#define zeros_at_beginning(x) __builtin_clz(x)
#define zeros_at_end(x) __builtin_ctz(x)
#define ones(x) __builtin_popcount(x)
#define parity_even_or_odd_ones __builtin_parity(x)

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef tuple<int , int , int> tiii;
typedef vector<pii> vpii;
typedef vector<tiii> vtiii;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long long ll;
typedef long long int lli;

             
inline int input(){
  int n;
  scanf("%d" , &n);
  return n;
}
                             
                                                         
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;  

#ifdef LOCAL_DEFINE
  freopen("input.txt" , "rt" , stdin);
#endif
 
  int a; cin >> a;
  int b; cin >> b;
  cout << ((a == b) ? a + b : max(2 * max(a , b) - 1 , 2 * max(a , b) - 1 * min(a , b))) << endl;
 
                                                   
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif  
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
   
   static void bubbleSort(int[] arr) {  
        int n = arr.length;  
        int temp = 0;  
         for(int i=0; i < n; i++){  
                 for(int j=1; j < (n-i); j++){  
                          if(arr[j-1] > arr[j]){  
                                 //swap elements  
                                 temp = arr[j-1];  
                                 arr[j-1] = arr[j];  
                                 arr[j] = temp;  
                         }  
                          
                 }  
         }  
  
    }  

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

        arr[0] = sc.nextInt();
        arr[1] = sc.nextInt();
        arr[2] = sc.nextInt();

        bubbleSort(arr);
        if (arr[0]==5&&arr[1]==5&&arr[2]==7) {
        	System.out.println("YES");
        } else {
        	System.out.println("NO");
        }
    }
}	

Measured memory_bytes: 20820
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String[] vals = sc.nextLine().split("\\s+");
		Long a = Long.parseLong(vals[0]);
		Long b = Long.parseLong(vals[1]);
		Long g = gcd(a, b);
		a /= g;
		b /= g;
		Long res = a * b * g;
        System.out.println(res);
	}
	private static Long gcd(Long a, Long b) {
		if (b == 0) return a;
		else return gcd(b, a%b);
	}
}


Measured memory_bytes: 23124
# n = 5
# ss = ["abaaaaaaaa",
# "oneplustwo",
# "aaaaaaaaba",
# "twoplusone",
# "aaaabaaaaa"]

n = int(input())
ss = []
for i in range(n):
    ss.append(input())

newss = []
for s in ss:
    newss.append("".join(sorted(list(s))))
newss = sorted(newss)
newss.append("XXXXXXXXXX")

last = newss[0]
count = 1
res = 0
for i in range(1,n+1):
    if last == newss[i]:
        count +=1
#         print(newss[i])
    else:
        res += (count*(count-1))//2
#         print(newss[i], (count*(count-1))//2)
        count = 1
    last = newss[i]
print(res)

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    ll n;
    cin >> n;
    ll ans = n-1;
    for (ll i = 1;i*i <= n;++i) if (n%i == 0) ans = min(ans,i+n/i-2);
    cout << ans << endl;
}

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

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int H, W, N, cnt=0;
	cin >> H >> W >> N;
	if (N%max(H, W) == 0) cnt = N / max(H, W);
	else cnt = N / max(H, W) + 1;
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
w, h, n = map(int, input().split())
x = 0
y = 0

for i in range(n):
    xi, yi, ai = map(int, input().split())
    if ai == 1 and xi > x:
        x = xi
    elif ai == 2 and xi < w:
        w = xi
    elif ai == 3 and yi > y:
        y = yi
    elif ai == 4 and yi < h:
        h = yi

if w <= x or h <= y:
    res = 0
else:
    res = (w-x) * (h-y)
print(res)






Measured memory_bytes: 3060
n = int(input())
d = list(map(int,input().split()))
mod = 998244353

if d[0] != 0:
    print(0)
    exit()

if n == 1:
        print(1)
        exit()

if n == 2:
    if d[1] == 1:
        print(1)
        exit()
    else:
        print(0)
        exit()


a = [0]*n

while d:
    s = d.pop()
    a[s] += 1

if a[0] >= 2:
    print(0)
    exit()

ans = 1

for i in range(n-1):
        ans *= a[i]**a[i+1]
        ans %= mod

print(ans % mod)

Measured memory_bytes: 54180
import java.io.*;
import java.io.ObjectInputStream.*;
import java.util.*;
import java.util.regex.*;


public class Main {

	final static long MOD = 1000000007;
	//final static long MOD = 998244353;

	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		slove(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void slove(String[] args) throws Exception{

		int N = nextInt();
		int[][] p = new int[N][];
		for(int i=0;i<N;i++) {
			p[i]=nextInts();
		}


		Arrays.sort(p,(s1,s2)->s1[0]-s2[0]);

		int ans = 0;
		HashMap<String,Integer> map = new HashMap<String, Integer>();
		for(int i=0;i<N;i++) {
			for(int k=0;k<N;k++) {
				if(i==k) {
					continue;
				}
				String key = String.valueOf(p[k][0]-p[i][0])+","+String.valueOf(p[k][1]-p[i][1]);
				map.put(key,map.getOrDefault(key, 0)+1);
			}
		}
		for(int val:map.values()) {
			ans=Math.max(ans,val);
		}
		pw.println(N-ans);

	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}



Measured memory_bytes: 32028
# N = int(input())
# Hs = list(map(int, input().split(" ")))
s = input()

cnts = [0 for _ in range(len(s))]

# "LR"で分割
sarr = ["R" + tmp + "L" for tmp in s.split("LR")]
sarr[0] = sarr[0][1:]
sarr[-1] = sarr[-1][:-1]

# print(sarr)

# 島ごとに"RL"をさがす
loop_pnt = [tmp.find('RL') for tmp in sarr]

#print(loop_pnt)

csum = 0
res = ""
# カウント
# Rの位置と島の大きさでいけそう
for item in zip(loop_pnt, sarr):
	# edge
	if item[0] == -1:
		if item[1][0] == "L":
			cnts[0] = len(item[1])
		if item[1][0] == "R":
			cnts[-1] = len(item[1])
	
	# 
	if item[0] % 2 == 1:
		# gu
		# R
		cnts[csum + item[0]] = len(item[1]) // 2
		# L
		cnts[csum + item[0] + 1] = len(item[1]) // 2 + len(item[1]) % 2
	else :
		# R
		cnts[csum + item[0]] = len(item[1]) // 2 + len(item[1]) % 2
		# L
		cnts[csum + item[0] + 1] = len(item[1]) // 2

	csum += len(item[1])
	
res = str(cnts[0])
for i in cnts[1:]:
	res += " " + str(i) 

print(res)

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

int main(){
  int i,N,K,a,b,c,d,f=0,ns=0,mns=1;
  char ss[200001];
  scanf("%d",&N);
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&d);
  scanf("%s",ss);

  if(c<d){
    for(i=a-1;i<d;i++){
      if(ss[i]=='#'){
        if(f==1){
          printf("No\n");
          return 0;
        }else{
          f=1;
        }
      }else{
        f=0;
      }
    }
    printf("Yes\n");
  }else{
    for(i=a-1;i<c;i++){
      if(ss[i]=='#'){
        if(f==1){
          printf("No\n");
          return 0;
        }else{
          f=1;
        }
      }else{
        f=0;
      }
    }
    for(i=b-2;i<d+1;i++){
      if(ss[i]=='#'){
        ns=0;
      }else{
        ns++;
        if(mns<ns){
          if(ns>=3){
            printf("Yes\n");
            return 0;
          }
          mns=ns;
        }
      }
    }
    printf("No\n");
  }
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> blue(N);
  for (int i = 0; i < N; i++){
    cin >> blue.at(i);
  }
  int M;
  cin >> M;
  vector<string> red(M);
  for (int i = 0; i < M; i++){
    cin >> red.at(i);
  }
  
  int max = 0;
  
  for(int i = 0; i < N; i++){
    string x = blue.at(i);
    int pt = 0;
      for(int j = 0; j < N; j++){
        if (x == blue.at(j)) pt ++;
      }
      for(int k = 0; k < M; k++){
        if (x == red.at(k)) pt --;
      }
      if (max < pt) max = pt;
  }
  cout << max << endl;  
}

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

using namespace std;

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

	int buf = a;
	a = b;
	b = buf;
	buf = a;
	a = c;
	c = buf;
	cout << a << " " << b << " " << c;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  const long long INF = 1LL << 60;
  int N;cin>>N;
  long long H[N];
  for (int i=0;i<N;++i){
    cin>>H[i];
  }
  long long dp[N];
  dp[0]=0;
  for (int i=1;i<N;++i){
    dp[i]=INF;
  }
  for (int i=0;i<N;++i){
    if (dp[i+1]>dp[i]+abs(H[i]-H[i+1]))dp[i+1]=dp[i]+abs(H[i]-H[i+1]);
    if (dp[i+2]>dp[i]+abs(H[i]-H[i+2]))dp[i+2]=dp[i]+abs(H[i]-H[i+2]);
  }
  cout<<dp[N-1]<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <functional>
#include <cmath>
#define FAST ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX = 2e5 + 4;

set<string> s;

int main() {
	FAST;
	string t = "hi";
	for (int i = 0; i < 5; i++) {
		s.insert(t);
		t += "hi";
	}
	string inp; cin >> inp;
	if (s.count(inp)) cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 256
n, a, b = gets.strip.split.map { |v| v.to_i }

if (b - a) % 2 == 0
  puts (b - a) / 2
  exit
end

if a - 1 <= n - b
  puts (a + b - 1) / 2 # (a - 1) + 1 + (b - a - 1) / 2
  exit
end

puts n - (a + b - 1) / 2 # (n - b) + 1 + (b - a - 1) / 2


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
using namespace std;

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

  int N,D,ans=0;
  cin>>N>>D;
  int zahyo[N][D];
  REP(i,N){
    REP(j,D)cin>>zahyo[i][j];
  }
  double kyori[N][N];
  REP(i,N)REP(j,N)kyori[i][j]=0;
  REP(i,N){
    REP(j,N){
      if(i!=j){
        REP(k,D)kyori[i][j]+=(zahyo[i][k]-zahyo[j][k])*(zahyo[i][k]-zahyo[j][k]);
        kyori[i][j] = sqrt(kyori[i][j]);
        if(ceil(kyori[i][j])==floor(kyori[i][j]))ans++;
      }
    }
  }
  cout<<ans/2;
  
  return 0;
}

Measured memory_bytes: 256
import itertools

N, M, Q = map(int, input().split())
abcd = []
for i in range(Q):
    abcd += [list(map(int, input().split()))]

A = list(itertools.combinations_with_replacement(list(range(1,M+1)), N))
smax = 0
for i in range(len(A)):
    s = 0
    for j in range(Q):
        if A[i][abcd[j][1]-1]-A[i][abcd[j][0]-1] == abcd[j][2]:
            s += abcd[j][3]
    
    if s > smax:
        smax = s

print(smax)

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    set<int> mochi;
    int N;
    cin >> N;

    rep(i, N) {
        int a;
        cin >> a;
        mochi.insert(a);
    }

    cout << mochi.size() << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
const int MOD = 1000000007;

int main(){

    string s; cin >> s;
    int x, y; cin >> x >> y;
    int n = s.size();

    int const MAX_MOVE = 20000;

    vector<int> x_move;
    vector<int> y_move;
    int now = 0;
    int count = 0;
    rep(i,n){
        if (s[i] == 'F'){
            count++;
        }
        else{
            if (now % 2 == 0){
                x_move.push_back(count);
            }
            else{
                y_move.push_back(count);
            }
            count = 0;
            
            now = 1 - now;
        }

        if (i == n-1){
            if (now % 2 == 0){
                x_move.push_back(count);
            }
            else{
                y_move.push_back(count);
            }
        }
    }

    int xn = x_move.size();
    int yn = y_move.size();

    
    vector<vector<bool>> x_dp(xn+1, vector<bool>(MAX_MOVE, false));
    x_dp[0][8000] = true;
    vector<vector<bool>> y_dp(yn+1, vector<bool>(MAX_MOVE, false));
    y_dp[0][8000] = true;

    rep(i,xn){
        rep(j,MAX_MOVE){
            if (j+x_move[i] >= MAX_MOVE) continue;
            x_dp[i+1][j+x_move[i]] = x_dp[i+1][j+x_move[i]] || x_dp[i][j];
            // 初回はx軸にのみ移動可能
            if (i == 0) continue;
            if (0 > j-x_move[i]) continue;
            x_dp[i+1][j-x_move[i]] = x_dp[i+1][j-x_move[i]] || x_dp[i][j];
        }
    }

    rep(i,yn){
        rep(j,MAX_MOVE){
            if (j+y_move[i] >= MAX_MOVE) continue;
            y_dp[i+1][j+y_move[i]] = y_dp[i+1][j+y_move[i]] || y_dp[i][j];
            if (0 > j-y_move[i]) continue;
            y_dp[i+1][j-y_move[i]] = y_dp[i+1][j-y_move[i]] || y_dp[i][j];
        }
    }

    

    if (x_dp[xn][8000+x] && y_dp[yn][8000+y]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(int argc, const char * argv[]) {
  long long int Q, H, S, D, N;
  cin>>Q>>H>>S>>D;
  cin>>N;
  S = min(Q * 4, S);
  S = min(H * 2, S);
  D = min(S * 2, D);
  if (N % 2 == 0) {
    cout<< N / 2 * D;
    return 0;
  }
  else {
    cout<< N / 2 * D + S;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc  = new Scanner(System.in);
		int N = sc.nextInt();
		double[] A = new double[N];
		double sum=0;

		for(int i=0 ; i<N ; i++){
			A[i] = 1/sc.nextDouble();
		}

		for(int i=0;i<N;i++){
			sum = sum+A[i];
		}

		System.out.println(1/sum);
	}
}

Measured memory_bytes: 25172
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define f first
#define se second
#define pb push_back
#define ft fflush(stdout)
 
 
using namespace std;
 
 
const int N = 3e3 + 123;
const int PLS = 3e5 + 123;
const int mod = 1e9 + 7;
const ll inf = 1e16;


ll n, a[N], dp[N][N][2];
bool vis[N][N][2];


void rec(int l, int r, int vl) {
    if (vis[l][r][vl])
        return;
    vis[l][r][vl] = 1;
    if (l == r) {
        if (vl == 0)
            dp[l][r][vl] = a[l];
        else
            dp[l][r][vl] = -a[l];
        return;
    }
    rec(l + 1, r, 1 - vl);
    rec(l, r - 1, 1 - vl);
    if (vl == 0)
        dp[l][r][vl] = max(a[l] + dp[l + 1][r][1 - vl], dp[l][r - 1][1 - vl] + a[r]);
    else
        dp[l][r][vl] = min(dp[l + 1][r][1 - vl] - a[l], dp[l][r - 1][1 - vl] - a[r]);
}


int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
        for (int j = i; j <= n; j++)
            dp[i][j][0] = dp[i][j][1] = -inf;
    rec(1, n, 0);
    cout << dp[1][n][0];
}

Measured memory_bytes: 166528
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ":" << x << "\n"
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;

int main () {
	int N, W; cin >> N >> W;
	vector<ll> dp(W + 1); // dp[j] = 重さ合計jでの価値の最大値
	int w, v;
	rep(i, N) {
		cin >> w >> v;
		// debug(w); debug(v);
		for (int j = W; j >= w; j--) dp[j] = max(dp[j], dp[j - w] + v);
		// rep(j, W + 1) cout << dp[j] << " "; cout << endl;
	}
	ll ans = 0;
	rep(i, W + 1) ans = max(ans, dp[i]);
	cout << ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, c) for(int i = 0; i < (int)c; i++)
using namespace std;
int main()
{
    int N; cin >> N;
    vector<int> p(N);
    rep(i, N) cin >> p[i];
    int ans = 0;
    for (int i = 1; i < (N - 1); i++) 
        if (min(p[i - 1], p[i + 1]) < p[i] && max(p[i - 1], p[i + 1]) > p[i])
            ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
S = input().rstrip()
Q = int(input().rstrip())
a = -1
before =[]
after =[]
for _ in range(Q):
    stdin = input().rstrip()
    if int(stdin[0]) == 1:
        a = ~a
    else:
        T,F,C = stdin.split()
        if int(F) == 2+a:
            before.append(C)
        else:
            after.append(C)
S = ''.join(before)[::-1] + S + ''.join(after)
if a == 0:
    S = S[::-1]
print(S)

Measured memory_bytes: 11080
import java.io.IOException;
import java.util.Scanner;

public class Main{
	public static int n;
	public static int A[];
	public static int B[];
	public static int C[] = new int[10000];
	public static StringBuilder sb = new StringBuilder();

	public static void main(String[] args) throws NumberFormatException, IOException {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		A = new int[n];
		B = new int[n];

		for(int i = 0; i<n ;i++){
			A[i] = scan.nextInt();
			C[A[i]]++;
		}

		for(int i=1;i<10000;i++){
			C[i] = C[i-1]+C[i];
		}

		for(int i = n-1;i>=0;i--){
			B[C[A[i]]-1] = A[i];
			C[A[i]]--;
		}

		for(int i = 0; i < n-1 ;i++){
			sb.append(B[i]+" ");
		}
		System.out.println(sb.toString()+B[n-1]);

	}

}

Measured memory_bytes: 587496
#include<stdio.h>

int main(void){
  char s[200001] , t[200001];
  scanf("%s %s",s,t);

  int ans = 0;
  for(int i = 0;s[i] != '\0';i ++){
    if(s[i] != t[i]){
      ans ++;
    }
  }

  printf("%d\n",ans);
}

Measured memory_bytes: 2064
a=[]
for i in range(3):
    a.append(list(map(int,input().split())))

n=int(input())
b=[]
for i in range(n):
    b.append(int(input()))

ans=[[0 for i in range(3)] for i in range(3)]

for z in range(n):
    for i in range(3):
        for j in range(3):
            if a[i][j]==b[z]:
                ans[i][j]=1

#print(ans)
c=0
for i in range(3):
    if ans[0][i]==1:
        c+=1
if c==3:
    print("Yes")
    exit()
c=0
for i in range(3):
    if ans[1][i]==1:
        c+=1
if c==3:
    print("Yes")
    exit()
c=0 
for i in range(3):
    if ans[2][i]==1:
        c+=1
if c==3:
    print("Yes")
    exit()
c=0  
for i in range(3):
    if ans[i][0]==1:
        c+=1
if c==3:
    print("Yes")
    exit()
c=0  
for i in range(3):
    if ans[i][1]==1:
        c+=1
if c==3:
    print("Yes")
    exit()
c=0   
for i in range(3):
    if ans[i][2]==1:
        c+=1
if c==3:
    print("Yes")
    exit()
c=0  
for i in range(3):
    if ans[1][i]==1:
        c+=1
if c==3:
    print("Yes")
    exit()
c=0

for i in range(3):
    if ans[i][i]==1:
        c+=1
if c==3:
    print("Yes")
    exit()
c=0

for i in range(3):
    if ans[2-i][i]==1:
        c+=1
if c==3:
    print("Yes")
    exit()
c=0
print("No")

Measured memory_bytes: 38384