akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
	string A,B;
  	cin >> A; 
    cin >> B;
  	int res = false;
  	if(A.size()>B.size())cout << "GREATER" << endl;
  	else if(A.size()==B.size()){
  		for(int i = 0;i<A.size();i++){
          	if(A[i] > B[i]){
            	cout << "GREATER" << endl;
               	res = false;
                break;
            }
          	if(A[i] < B[i]){
            	cout << "LESS" << endl;
              	res = false;
                break;
            }
          	if(A[i] == B[i])res = true;            
        }
    }
  	else if(A.size()<B.size())cout << "LESS" << endl;
  	if(res) cout << "EQUAL" << endl;
}

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

int main(){
    int x,y;
    cin >> x >> y;
    if(y%2 != 0){
        cout << "No" << endl;
        return 0;
    }

    for(int i=0; i<=100; i++){
        for(int j=0; j<= 100; j++){
            if(i+j == x && i*2 + j*4 == y){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define maxn 5005
#define mod 998244353
#define ll long long
using namespace std;

typedef pair<int, int> P;

int n, k;
char s[maxn];

int main()
{
    cin >> n >> k;
    scanf("%s", s);
    s[k - 1] = s[k - 1] - 'A' + 'a';
    cout << s;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<int,int> P;
const int MAX=1000000007;
 
int dp[(1<<18)][20];
 
int main() {
  int n,m,l,s,t;
  while(cin >> n >> m >> l >> s >> t && n) {
    int v[n+1][n+1];
    fill(v[0],v[n+1],MAX);
    for(int i=0; i<m; i++) {
      int x,y,z;
      cin >> x >> y >> z;
      v[x][y]=z;
      v[y][x]=z;
    }
    for(int i=1; i<=n; i++) v[i][i]=0;
    for(int k=1; k<=n; k++) {
      for(int i=1; i<=n; i++) {
    for(int j=1; j<=n; j++) {
      if(v[i][k]!=MAX && v[k][j]!=MAX) v[i][j]=min(v[i][j],v[i][k]+v[k][j]);
    }
      }
    }
    P r[l+1];
    for(int i=0; i<l; i++) cin >> r[i].F >> r[i].S;
    r[l].F=s;r[l].S=0;
    l++;
 
    fill(dp[0],dp[(1<<l)],MAX);
    dp[0][l-1]=0;
    /*
    for(int i=0; i<l; i++) {
      dp[(1<<i)][l-1]=v[r[i].F][s]+r[i].S;
      if(dp[(1<<i)][l-1]>t) dp[(1<<i)][l-1]=MAX;
    }
    */
    int ans=0;
    for(int p=0; p<(1<<l); p++) {
      for(int i=0; i<l; i++) {
    if(dp[p][i]!=MAX) {
      if(i==l-1) {
        int cnt=0;
        for(int j=0; j<l-1; j++) {
          if(p&(1<<j)) cnt++;
        }
        if(cnt>ans) ans=cnt;
      }
 
      for(int j=0; j<l; j++) {
        if(!(p&(1<<j))) {
          dp[p|(1<<j)][j]=min(dp[p|(1<<j)][j],dp[p][i]+v[r[j].F][r[i].F]+r[j].S);
          if(dp[p|(1<<j)][j]>t) dp[p|(1<<j)][j]=MAX;
        }
      }
    }
      }
    }  
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 13792
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    a: [[i32; 3]; 3],
    n: usize,
    b: [i32; n],
  }
  let mut fld = vec![vec![false; 3]; 3];
  for &x in &b {
    for i in 0 .. 3 {
      for j in 0 .. 3 {
        if a[i][j] == x {
          fld[i][j] = true;
        }
      }
    }
  }
  let mut ans = false;
  for i in 0 .. 3 {
    let mut bingo = true;
    for j in 0 .. 3 {
      bingo = bingo && fld[i][j];
    }
    ans = ans || bingo;
  }
  for j in 0 .. 3 {
    let mut bingo = true;
    for i in 0 .. 3 {
      bingo = bingo && fld[i][j];
    }
    ans = ans || bingo;
  }
  ans = ans || (fld[0][0] && fld[1][1] && fld[2][2]) || (fld[0][2] && fld[1][1] && fld[2][0]);

  puts!("{}\n", if ans { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <set>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define irep(i, n) for(int i=n-1;i>=0;i--)
#define lrep(i, n) for(long long i=0;i<n;i++)
typedef long long ll;
typedef vector<long long> llv;
typedef vector<vector<long long> > llvv;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n);
    rep(i,n) cin >> a[i] >> b[i];
    map<int, long long> M;
    rep(i,n){
        M[a[i]] += b[i];
    }
    ll cost = 0;
    for(auto shop:M){
        ll buy = min((ll)m, shop.second);
        cost += (ll)shop.first * buy;
        m -= buy;
    }
    cout << cost << endl;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
int MAX = 7368791;
int main(){
  vector<int> prime(MAX + 1, 0);
  prime[0] = -1;
  prime[1] = -1;
  for (int i = 2; i <= MAX; i++){
    if (prime[i] == 0){
      for (int j = i * 2; j <= MAX; j += i){
        if (prime[j] == 0){
          prime[j] = i;
        }
      }
    }
  }
  vector<int> sum(MAX + 1, 0);
  for (int i = 1; i <= MAX; i++){
    if (prime[i] == 0){
      sum[i] = sum[i - 1] + 1;
    } else {
      sum[i] = sum[i - 1];
    }
  }
  while (1){
    int m, n;
    cin >> m >> n;
    if (m == 0 && n == 0){
      break;
    }
    vector<bool> ok(20000, false);
    for (int i = m; i < 20000; i++){
      if (!ok[i]){
        if (n == 0){
          cout << i << endl;
          break;
        }
        n--;
        for (int j = i; j < 20000; j += i){
          ok[j] = true;
        }
      }
    }
    if (n > 0){
      cout << lower_bound(sum.begin(), sum.end(), n + sum[20000] + 1) - sum.begin() << endl;
    }
  }
}


Measured memory_bytes: 60136
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e8
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> p_ii;

struct union_find {
	vector<int> v;
	union_find(int n) : v(n, -1) {}
	int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y]; v[y] = x;
	}
	bool root(int x) { return v[x] < 0; }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};


vector<p_ii> all;

int main() {
	int n, k, l; cin >> n >> k >> l;
	union_find S(n+2), T(n+2);

	for (int i = 0; i < k; i++) {
		int a, b; cin >> a >> b;
		a--; b--;
		S.unite(a, b);
	}

	for (int i = 0; i < l; i++) {
		int a, b; cin >> a >> b;
		a--; b--;
		T.unite(a, b);
	}

	for (int i = 0; i < n; i++)all.push_back({ S.find(i),T.find(i) });
	sort(all.begin(), all.end());

	for (int i = 0; i < n; i++) {
		p_ii p = { S.find(i), T.find(i) };
		int ans = upper_bound(all.begin(), all.end(), p) - lower_bound(all.begin(), all.end(), p);
		if (i != 0)cout << " ";
		cout << ans;
	}
	cout << endl;

	return 0;
}

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

ll gcd(ll a, ll b){
    if(a<b) swap(a,b);
    if(a%b == 0) return b;
    else return gcd(b,a%b);
}

int main(){
    string s; cin >> s;
    int n=s.size();
    vector<bool> p(n,0);
    vector<char> c={'A','C','G','T'};
    rep(i,n){
        rep(j,4){
            if(s[i]==c[j]){
                p[i]=1;
            }
            if(p[i]==1) continue;
        }
    }

    int ans=0;
    int now=0;
    rep(i,n){
        if(p[i]) now++;
        else now=0;
        ans=max(now,ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
#include <iostream>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()
using ll = long long;

using namespace std;



int main() {
    int a,b;
    cin>>a>>b;
    if((a+b)%2){
        cout<<"IMPOSSIBLE"<<endl; 
        return 0;
    }
    cout<<(a+b)/2<<endl;

    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long int ll;
typedef pair<int, int> pr;
typedef priority_queue<int> p_int_max;
typedef priority_queue<int, vector<int>, greater<int>> p_int_min;
 
string s;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	cin >> s;
  	rep(i, s.length()) cout << "x";
  cout << "\n";
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  VL x(n);
  rep(i, n) cin >> x[i];
  ll ans = LINF;
  for(int i = 0; i + k <= n; ++i) {
    ans = min(ans, min(abs(x[i]) + abs(x[i+k-1]-x[i]), abs(x[i+k-1]) + abs(x[i]-x[i+k-1])));
  }
  out(ans);
  return 0;
}


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

int main(){
    int64_t a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    int64_t ans = a*x+b*y;
    /*
    if(a+b > 2*c){
        int buy_c = min(x,y) * 2;
        ans += buy_c * c;
        int add_a = x-buy_c/2;
        int add_b = y-buy_c/2;
        ans += min(add_a*a, ((add_a+1)/2)*c);
        ans += min(add_b*b, ((add_b+1)/2)*c);
    }
    else{
        ans += a*x + b*y;
    }
    */
    for (int i=0; i<=max(x,y);i++){
        int64_t price = 0;
        price += 2*c*i;
        if(x-i >0){
            price += (x-i) * a;
        }
        if(y-i > 0){
            price += (y-i) * b;
        }
        ans = min(ans,price);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define int long long
string s1,s2;
int dp[3001][3001];
int f(int x,int y)
{ 
  if(x==s1.length() || y==s2.length())
    return 0;
  if(dp[x][y]!=-1)
    return dp[x][y];  
  if(s1[x]==s2[y])
    return dp[x][y]=f(x+1,y+1)+1;
  else
  {
    dp[x][y]=max(f(x+1,y),f(x,y+1));
    return dp[x][y];
  }

}
void path(int x,int y)
{
  if(x==s1.length() || y==s2.length())
    return; 
  if(s1[x]==s2[y])
    {
      cout<<s1[x];
      path(x+1,y+1);
      return;
    }
  else
  {
    if(f(x+1,y)>f(x,y+1))
    {
      path(x+1,y);
      return;
    }
    else
    {
      path(x,y+1);
      return;
    }
  }
}
int32_t main()
{  
  cin>>s1>>s2;
  memset(dp,-1,sizeof(dp));
  f(0,0);
  path(0,0);
  
}


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

int main()
{
  string str;
  cin>>str;
  //入力完了
  
  vector<string> strVec;
  size_t count2=0;
  
  //><分割
  for(size_t i=0;i<str.size();i++)
  {
    if(str[i]=='>'&& str[i+1]=='<')
    {
      string s=str.substr(count2,i-count2+1);
      strVec.push_back(s);
      count2=i+1;
    }
    else if(i==str.size()-1)
    {
      string s=str.substr(count2,i-count2+1);
      strVec.push_back(s);
    }
  }
  
  //答え
  size_t val=0;
  
  //<>の数計算
  for(size_t i=0;i<strVec.size();i++)
  {
    //<カウント
    size_t countStr=count(strVec[i].cbegin(), strVec[i].cend(),'<');
    size_t countStr2=strVec[i].size()-countStr;
    //cout<<i<<" ";
    //cout<<countStr<<" ";
    //cout<<countStr2<<" ";
    //cout<<strVec[i].size()<<"=";

    if(countStr >= countStr2)
    {
      size_t sum=(countStr)*(countStr+1)/2 + (countStr2)*(countStr2-1)/2;
      //cout<<sum<<endl;
      val+=sum;
    }
    else
    {
      size_t sum=(countStr)*(countStr-1)/2 + (countStr2)*(countStr2+1)/2;
      val+=sum;
      //cout<<sum<<endl;
    }
  }
  cout<<val<<endl;
}

Measured memory_bytes: 7548
# coding:utf-8
n = input()
taro_cnt = 0
hanako_cnt = 0
taro = ["" for i in range(n)]
hanako = ["" for i in range(n)]
for i in range(n):
    split = raw_input().split()
    taro[i] = split[0]
    hanako[i] = split[1]
for i in range(n):
    if taro[i] > hanako[i]:
        taro_cnt += 3
    elif taro[i] < hanako[i]:
        hanako_cnt += 3
    else:
        taro_cnt += 1
        hanako_cnt += 1
else:
    print taro_cnt,hanako_cnt



Measured memory_bytes: 4704
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll n,a,b;cin>>n>>a>>b;
    cout<<min(a*n,b)<<"\n";
}


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

int main(){

    int n, x;
    cin >> n >> x;
    vector<int> m(n);

    int left_d = x;
    int cnt = 0;
    for (int i = 0; i < n; i++){
        cin >> m[i];
        left_d -= m[i];
        cnt++;
    }
    int min_d = *min_element(m.begin(), m.end());
    cnt += left_d / min_d;

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;
const int maxn=2e5+100;
typedef long long ll;
int n;
int a[maxn];

ll f(ll b)
{
	ll sum=0;
	for(int i=0;i<n;i++)
		sum+=abs(a[i]-b);
	return sum;
}

ll solve()
{
	for(int i=0;i<n;i++)
		a[i]-=i+1;
	sort(a,a+n);
	if(n%2==0) return f((a[n/2]+a[n/2-1])/2);
	else return f(a[n/2]);
}

int main()
{
    //freopen("102C.txt","r",stdin);
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	printf("%lld\n",solve());
	return 0;
}


Measured memory_bytes: 896
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		String S = sc.next();
		sc.close();
		
		boolean flag = true;
		for(int i = 0;i < A;++i)
			if(!('0' <= S.charAt(i) && S.charAt(i) <= '9'))
				flag = false;
		if(S.charAt(A) != '-')
			flag = false;
		for(int i = 0;i < B;++i)
			if(!('0' <= S.charAt(A + 1 + i) && S.charAt(A + 1 + i) <= '9'))
				flag = false;
		if(flag)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

ll k;

double f(ll x) {
    double y = 0;
    ll n = x;
    while (x) {
        y += x % 10;
        x /= 10;
    }
    return n / y;
}

int main() {
    cin >> k;
    ll now = 0;
    ll x = 1;
    ll tot = 0;
    while (tot<k) {
        if((now/x)%10!=9){
            now+=x;
            printf("%lld\n",now);tot++;
        }
        else{
            if(f(now+x)>f(now+10*x)){
                x=10*x;
            }
            now+=x;
            printf("%lld\n",now);tot++;
        }
    }

    return 0;
}


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

signed main()
{
    int N; cin>>N;
    int sum=0,Min=1e9;
    REP(i,N){
        int s; cin>>s;
        sum+=s;
        if(s%10!=0) Min=min(Min,s);
    }
    
    if(sum%10!=0) cout<<sum<<endl;
    else{
        if(Min!=1e9) cout<<sum-Min<<endl;
        else cout<<0<<endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<iostream>
using namespace std;
int dp[2048][2048];
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	vector < vector<int> > ja(13);
	for(int i = 0; i < n; i++){
		int a,b;
		scanf("%d%d",&a,&b);
		ja[b].push_back(a);
	}
	vector< vector<int> > books(13);
	int J=0;
	for(int i = 0; i < 11; i++){
		sort(ja[i].begin(),ja[i].end());
		reverse(ja[i].begin(),ja[i].end());
		if(ja[i].size()){
			books[i].push_back(ja[i][0]);
			J = i;
		}
		for(int j = 1; j < ja[i].size(); j++){
			if(j > k-1)break;
			ja[i][j] += ja[i][j-1];
			books[i].push_back(ja[i][j]+((j+1)*j));
		}
	}
	
	for(int i = 1 ; i <= J ; i++){
        for(int j = 1 ; j <= k ; j++){
            dp[i][j] = max(dp[i][j],dp[i-1][j]);
			int mi = min((int)books[i].size(),j);
            for(int l = 1 ; l <= mi; l++){
                dp[i][j] = max(dp[i][j],dp[i-1][j-l]+books[i][l-1]);
            }
        }
    }
	printf("%d\n",dp[J][k]);
	return 0;
}

Measured memory_bytes: 1316
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repi(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
int main() {
  int n,a1e,a1v,a2v=0;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  a1e=max_element(a.begin(),a.end())-a.begin();
  rep(i,n){
    if(i!=a1e) a2v=max(a2v,a[i]);
  }
  a1v=a[a1e];
  rep(i,n){
    if(i==a1e) cout<<a2v<<endl;
    else cout<<a1v<<endl;
  }
  return 0;
}


Measured memory_bytes: 2432
import java.util.Scanner;

public class Main{
		
	public static int[] cut(int[] a, int k){
		int[] result = new int[a.length];
		if( k == 0 ){
			for(int i = 0; i < a.length/2; i++){
				result[2*i] = a[i];
			}
			for(int i = a.length/2; i < a.length; i++){
				result[(i-a.length/2)*2+1] = a[i];
			}
		} else {
			for(int i = k; i < a.length; i++){
				result[i-k] = a[i];
			}
			for(int i = 0; i < k; i++){
				result[a.length-k+i] = a[i];
			}
		}
		return result;
	}

	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int[] deck = new int[2*n];
		for(int i = 0; i < 2*n; i++){
			deck[i] = i+1;
		}
		
		int m = stdIn.nextInt();
		int[] op = new int[m];
		
		for(int i = 0; i < m; i++){
			op[i] = stdIn.nextInt();
		}
		
		for(int i = 0; i < m; i++){
			deck = 	cut(deck, op[i]);
		}
		for(int i = 0; i < 2*n; i++){
			System.out.println(deck[i]);
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define ll long long
const int MOD = 1e9+7;
using namespace std;


int main(){
	map<string, int> mp;
	mp.insert(make_pair("SUN", 7));
	mp.insert(make_pair("MON", 6));
	mp.insert(make_pair("TUE", 5));
	mp.insert(make_pair("WED", 4));
	mp.insert(make_pair("THU", 3));
	mp.insert(make_pair("FRI", 2));
	mp.insert(make_pair("SAT", 1));
	string s;
	cin >> s;
	cout << mp.at(s) << endl;
	return 0;
}

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

int main(){
    int K, N, max = 0, num;
    cin >> K >> N;
    vector<int> A(N);
    
    rep(i, N){
        cin >> A.at(i);
    }

    rep(i, N-1){
        num = A.at(i+1) - A.at(i);
        if(num > max){
            max = num;
        }
    }
        num = K - (A.at(N - 1) - A.at(0));
        if (num > max)
        {
            max = num;
        }

        cout << K - max << endl;
    }

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

using namespace std;

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

    int n;
    cin >> n;
    string s;
    vector<string> seat(n, "?");
    cout << 0 << endl;
    cin >> s;
    if (s == "Vacant")
    {
        return 0;
    }
    seat[0] = s;

    cout << n - 1 << endl;
    cin >> s;
    if (s == "Vacant")
    {
        return 0;
    }
    seat[n - 1] = s;

    int st = 0, gt = n - 1, m;
    while (gt - st > 1)
    {
        m = (st + gt) / 2;
        cout << m << endl;
        cin >> s;
        if (s == "Vacant")
        {
            return 0;
        }
        else
        {
            seat[m] = s;
        }
        
        if ((gt - m) % 2 == 0 && seat[m] != seat[gt])
        {
            st = m;
        }
        else if ((gt - m) % 2 && seat[m] == seat[gt])
        {
            st = m;
        }
        else if ((m - st) % 2 == 0 && seat[st] != seat[m])
        {
            gt = m;
        }
        else if ((m - st) % 2 && seat[st] == seat[m])
        {
            gt = m;
        }
        else
        {
            assert(false);
        }
    }
    cout<<st<<endl;
    cin>>s;
    if(s=="Vacant"){
        return 0;
    }
    cout<<gt<<endl;
    cin>>s;
    if(s=="Vacant"){
        return 0;
    }
    assert(false);
}


Measured memory_bytes: 1648
#include <bits/stdc++.h>
using namespace std;
vector<int> dx= {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
const int INF=100000000;

int main(){
    int n;
    string s;
    cin>>n>>s;
    for(int i =0; i< s.size(); i++){
        int tmp = s.at(i) - 'A';
        tmp += n;
        tmp %=26;
        s.at(i) ='A'+tmp;
    }
    cout<<s<<endl;

}


Measured memory_bytes: 256
#include <cstdio>

int main(void)
{
    int a, b;
    char op;
    while(1)
    {
        scanf("%d %c %d", &a, &op, &b);
        if(op=='?') break;
        switch(op)
        {
            case '+':
                printf("%d\n", a+b);
                break;
            case '-':
                printf("%d\n", a-b);
                break;
            case '*':
                printf("%d\n", a*b);
                break;
            case '/':
                printf("%d\n", a/b);
                break;
        }
    }

    return 0;
}


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

using namespace std;

int main(){
    int x,y;
    cin >> x >> y;
    if(y%2 ==1){
        cout << "No" << endl;
        return 0;
    }
    if(2*x <= y && y<=4*x){
        cout << "Yes" << endl;
        return 0;

    }else{
        cout << "No" << endl;
        return 0;
        
    }
    return 0;
    
}

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

const bool DEBUG = false;

using Graph = vector<set<int>>;
using Query = vector<int>;

void propagate(const int node_id, const int parent_id, const int value,
               const Graph& graph, const Query& query, vector<int>& counter) {
  if (DEBUG)
    cout << "node_id: " << node_id << ", value: " << value
         << ", query: " << query[node_id] << endl;
  counter[node_id] += value + query[node_id];
  for (auto&& child : graph[node_id]) {
    if (child == parent_id) continue;
    propagate(child, node_id, value + query[node_id], graph, query, counter);
  }
}

int main(int argc, char const* argv[]) {
  int N, Q;
  cin >> N >> Q;

  Graph graph(N, set<int>());

  for (size_t i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    graph[a].insert(b);
    graph[b].insert(a);
  }

  Query query(N);
  for (size_t i = 0; i < Q; i++) {
    int p, x;
    cin >> p >> x;
    p--;
    query[p] += x;
  }

  vector<int> counter(N);
  propagate(0, -1, 0, graph, query, counter);

  for (auto&& c : counter) {
    cout << c << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 50816
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean index[]=new boolean[10000000];
		Arrays.fill(index, true);
		index[0]=false;index[1]=false;
		for(int i=0;i<index.length;i++){
			if(index[i]){
				for(int j=i+i;j<index.length;j+=i){
					index[j]=false;
				}
			}
		}
		while(true){
			int a=sc.nextInt();
			int d=sc.nextInt();
			int n=sc.nextInt();
			if(a+d+n==0)break;
			int x=0,i=0;
			for(i=0;i<index.length;i++){
				if(index[a+d*i])x++;
				if(x==n)break;
			}
			System.out.println(a+d*i);
		}

	}

}

Measured memory_bytes: 31568
#include<stdio.h>

int main(){
  int k, len = 0;
  scanf("%d", &k);
  char str[100];
  scanf("%s", str);
  for(int i = 0; str[i] != '\0'; i++){
    len++;
  }
  if(len <= k){
    printf("%s\n", str);
  }
  else{
    for(int i = k; i <= k + 3; i++){
      if(i < k + 3){
        str[i] = '.';
      }
      else{
        str[i] = '\0';
      }
    }
    printf("%s\n", str);
  }
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <stdio.h>
using namespace std;
#define ll long long
bool piyo[30000] = { false };

int main() {
	ll n, d, x[20][20], ans = 0, hoge;
	for (int i = 1; i < 130; i++) {
		piyo[i * i] = true;
	}
	cin >> n >> d;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			cin >> x[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			hoge = 0;
			for (int k = 0; k < d; k++) {
				hoge += abs((x[i][k] - x[j][k]) * (x[i][k] - x[j][k]));
			}
			if (piyo[hoge])ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for (ll i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (ll i = (begin)-1; i >= (end); i--)
#define IREP(i, n) IFOR(i, n, 0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(), greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v)                                                              \
  cout << #v << "=(" << v[0];                                                  \
  FOR(i_debug, 1, v.size()) { cout << "," << v[i_debug]; }                     \
  cout << ")" << endl;
#define mdebug(m)                                                              \
  cout << #m << "=" << endl;                                                   \
  REP(i_debug, m.size()) {                                                     \
    REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; }    \
    cout << endl;                                                              \
  }
#define Lower_bound(v, x)                                                      \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x)                                                      \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;

template <typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) {
  REP(i, a.size()) {
    cin >> a[i];
    a[i]--;
  }
}

ll mod = 1000000007;

int main() {

  ll N, T, A;
  cin >> N >> T >> A;
  ll h;

  ld mintemp = -1;
  ll minid = 0;
  cin >> h;
  mintemp = abs(A - (T - 0.006 * h));
  REP(i, N - 1) {
    cin >> h;
    if (abs(A - (T - 0.006 * h)) < mintemp) {
      mintemp = abs(A - (T - 0.006 * h));
      minid = i + 1;
    }
  }

  cout << minid + 1 << endl;

  return 0;
}

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

int main(){
  string N;
  cin>>N;
  
  for(int i=0;i<N.length();i++){
   if(N[i]=='7'){
     cout<<"Yes"<<endl;    
    return 0;
   }
  }
  
  cout<<"No"<<endl;       
  return 0;
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))


bool solve(vvi& c){
    repC2(i,j,3) {
        vi tmp(3);
        rep(k,3) tmp[k] = c[i][k] - c[j][k];
        if (tmp[0] != tmp[1] || tmp[1] != tmp[2] || tmp[2] != tmp[0]) return false;
    }
    repC2(i,j,3) {
        vi tmp(3);
        rep(k,3) tmp[k] = c[k][i] - c[k][j];
        if (tmp[0] != tmp[1] || tmp[1] != tmp[2] || tmp[2] != tmp[0]) return false;
    }
    return true;
}

int main() {
    vvi c(3, vi(3));
    rep(i,3) rep(j,3) cin >> c[i][j];

    cout << (solve(c) ? "Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>

using namespace std;

int main(){
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<long long> s(A), t(B), x(Q);
    for(int i = 0; i < A; i++){
        cin >> s[i];
    }
    for(int i = 0; i < B; i++){
        cin >> t[i];
    }
    for(int i = 0; i < Q; i++){
        cin >> x[i];
    }

    s.push_back(-1e18);
    s.push_back(1e18);
    t.push_back(-1e18);
    t.push_back(1e18);
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());

    long long ans;
    for(int i = 0; i < Q; i++){
        ans = LLONG_MAX;
        auto it_sr = lower_bound(s.begin(), s.end(), x[i]);
        auto it_tr = lower_bound(t.begin(), t.end(), x[i]);
        auto it_sl = it_sr--;
        auto it_tl = it_tr--;
        
        ans = min(
            {   ans,
                abs(x[i]-*it_sr) + abs(*it_sr-*it_tr),
                abs(x[i]-*it_sr) + abs(*it_sr-*it_tl),
                abs(x[i]-*it_sl) + abs(*it_sl-*it_tr),
                abs(x[i]-*it_sl) + abs(*it_sl-*it_tl),
                abs(x[i]-*it_tr) + abs(*it_tr-*it_sr),
                abs(x[i]-*it_tr) + abs(*it_tr-*it_sl),
                abs(x[i]-*it_tl) + abs(*it_tl-*it_sr),
                abs(x[i]-*it_tl) + abs(*it_tl-*it_sl)
            }
        );

        cout << ans << endl;
    }


    return 0;
}

Measured memory_bytes: 3680
#include<iostream>
using namespace std;
int main(){
    int n,x,count;
    while (true){
        cin>>n>>x;
        if(n==0 && x==0) break;
        else{
            count=0;
            for(int i=1;i<=n;i++){
                for(int j=i+1;j<=n;j++){
                    for(int k=j+1;k<=n;k++){
                        if(i+j+k==x) count+=1;
                        else{
                            continue;
                        }
                    }
                }
            }
            cout<<count<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3072
group=[[1,3,5,7,8,10],[4,6,9,11]\
	,[2]]

x = list(map(int, input().split()))


for i in group:
	for j in i:
		if (x[0]==j):
			for l in i:
				if(x[1]==l):
					print("Yes")
					
					quit()
					
print("No")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()

int main(){
    int n,k;
    string s;
    cin>>n>>s>>k;
    char p=s[k-1];
    REP(i,n){
        if(s[i]-p!=0) s[i]='*';
    }
    cout<<s<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define xx first
#define yy second
using namespace std;
typedef long long ll;
int n,m,q;
pair<pair<int,int>,int> a[300010];
int s[300010],ans[300010];
void upd(int x,int val){
    for(int i=x;i<=n;i+=i&-i) s[i]+=val;
}
ll sum(int x){
    ll ret=0;
    for(int i=x;i>0;i-=i&-i) ret+=(ll)s[i];
    return ret;
}
int main(){
    scanf("%d%d%d",&n,&m,&q);
    for(int i=0;i<m;i++){
        scanf("%d%d",&a[q+i].xx.xx,&a[q+i].xx.yy);
        a[q+i].xx.yy =-a[q+i].xx.yy;
        a[q+i].yy=q+i;
    }
    for(int i=0;i<q;i++){
        scanf("%d%d",&a[i].xx.xx,&a[i].xx.yy);
        a[i].xx.yy=-a[i].xx.yy;
        a[i].yy=i;
    }
    sort(a,a+m+q);
    for(int i=m+q-1;i>=0;i--){
        if(a[i].yy>=q){
            upd(-a[i].xx.yy,1);
        }
        else {
            ans[a[i].yy]=sum(-a[i].xx.yy);
        }
    }
    for(int i=0;i<q;i++) printf("%d\n",ans[i]);
    return 0;
}


Measured memory_bytes: 5120
h,w=gets.split.map(&:to_i)
n=gets.to_i
a=gets.split.map(&:to_i)
f=[[]]
i=0
j=0
while j<h
  s=w-f[j].size
  if s>a[i]
    a[i].times do
      f[j] << i+1
    end
    a[i]=0
    i+=1
  elsif s==a[i]
    a[i].times do
      f[j] << i+1
    end
    a[i]=0
    i+=1
    j+=1
    f << []
  else
    s.times do
      f[j] << i+1
    end
    a[i]-=s
    j+=1
    f << []
  end
end
h.times do |i|
  if i.even?
    puts f[i].join(" ")
  else
    puts f[i].reverse.join(" ")
  end
end


Measured memory_bytes: 2428
n = int(input())
a = list(map(int,input().split()))
tmp = [0] * 100001
ans = 0
for i in range(n):
    tmp[a[i]] += 1
    ans += a[i]
q = int(input())
for i in range(q):
    x,y = map(int,input().split())
    ans -= x * tmp[x]
    ans += y * tmp[x]
    tmp[y] += tmp[x]
    tmp[x] = 0
    print(ans)


Measured memory_bytes: 20980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;
const int MOD = 1000000007;
using pint = pair<ll, ll>;

int main() {
    ll N, M;
    cin >> N >> M;
    set<ll> out;
    ll cnt = 0;
    for (int i = 0; i < M; i++) {
      ll a, b;
      cin >> a >> b;
      if(a==1){
        out.insert(b);
        cnt++;
      }
      if (b == N){
          out.insert(a);
          cnt++;
      }
    }
    if(cnt==out.size()){
      cout << "IMPOSSIBLE" << endl;
    }
    else{
      cout << "POSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 12976
#include<stdio.h>
int main(void)
{
	int h,w,H, W;

	while (1) {
		scanf("%d %d", &H, &W);
		for (h = 1; h <= H; h++) {
			for (w = 1; w <= W; w++) {
				printf("#");
			}
			printf("\n");
		}
		if (H == 0 && W == 0) break;
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2100
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
int par[MAXN], sz[MAXN];

int qry(int x) { return x == par[x] ? x : par[x] = qry(par[x]); }
void join(int u, int v) { 
	if (qry(u) == qry(v)) return;
	par[qry(u)] = qry(v); 
	sz[qry(v)] += sz[qry(u)];
}

int main() {
	int n, q; ll m;
	scanf("%d %lld %d", &n, &m, &q);
	for (int i = 0; i < n; i++) par[i] = i, sz[i] = 1;
	vii edg;
	ll cnt = 0;
	for (int i = 0; i < q; i++) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		if (c == 0) {
			if (qry(a) != qry(b))
				cnt++;
			join(a, b);
		} else {
			if (m == n-1)
				return !printf("No\n");
			edg.pb(mp(a,b));
		}
	}
	if (m == n-1)
		return !printf("Yes\n");
	for (auto it: edg)
		if (qry(it.fi) == qry(it.se))
			return !printf("No\n");
	ll tmp = 0;
	for (int i = 0; i < n; i++)
		if (qry(i) == i)
			cnt++, tmp++;
	if (cnt <= m && cnt + (tmp*(tmp-1)) / 2 - tmp >= m && tmp > 2)
		return !printf("Yes\n");
	printf("No\n");
	return 0;
}


Measured memory_bytes: 5880
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 2019
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  vector<int> currsum(2020,0);
  vector<int> temp(2020,0);
  int ans = 0;
  int curr = 0;
  string input;
  cin >> input;
  for(int i=0;i<input.length();i++){
    curr *= 10;
    curr %= mod;
    curr += (input.at(i)-'0');
    curr %= mod;
    ans += currsum[curr];
    if(curr==0){
      ans++;
    }
    //cout << i << " " << curr << " " << currsum[curr] << "\n";
    currsum[curr]++;
    for(int j=0;j<2019;j++){
      temp[(j*10)%mod] += currsum[j];
    }
    for(int j=0;j<2019;j++){
      currsum[j] = temp[j];
      temp[j] = 0;
    }
  }
  cout << ans;
}

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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << (a) << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int N = 8080;

bool tmp[N];
void update(bool a[], int d) {
    memset(tmp, 0, sizeof tmp);
    forn(i,N) if (a[i]) {
        int x = i+d;
        int y = abs(i-d);
        if (x < N) tmp[x] = 1;
        if (y < N) tmp[y] = 1;
    }
    memcpy(a, tmp, N);
}

bool can[2][N];

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

    can[0][0] = can[1][0] = 1;
    string s; cin >> s; s += 'T';
    int x,y; cin >> x >> y;
    int axis = 0, cnt = 0;
    bool first = 1;
    for (char c : s) {
        if (c == 'T') {
            if (first) {
                x -= cnt;
                first = 0;
            }
            else if (cnt) update(can[axis], cnt);
            axis = 1-axis;
            cnt = 0;
        }
        else cnt++;
    }
    x = abs(x); y = abs(y); 

    bool ok = can[0][x] && can[1][y];
    cout << (ok ? "Yes" : "No") << endl;

    return 0;
}


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

using namespace std;

int main(){
  int n,k;
  cin >>n>>k;
  int a[n];
  vector<int> count(n,0);
  for(int i=0; i<n; i++){
    cin >> a[i];
    count[a[i]]++;
  }
  sort(count.begin(),count.end(),greater<int>());
  int res=0;
  for(int i=0;i<k;i++)
  res+=count[i];

  cout<<n-res<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
#include <bitset>
#include <queue>
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    string a[N];
    string b[M];
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    for(int i = 0; i < M; i++){
        cin >> b[i];
    }
    for(int i = 0; i <= N - M; i++){
        for(int j = 0; j <= N - M; j++){
            // check start
            int ok = 1;
            for(int k = 0; k < M; k++){
                for(int l = 0; l < M; l++){
                    if(a[i+k][j+l] != b[k][l]){
                        ok = 0;
                        break;
                    }
                }
                if(ok == 0){
                    break;
                }
            }
            if(ok == 1){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int count = 1;
        String prev = String.valueOf(s.charAt(0));
        String str = "";
        for(int i = 1; i < s.length();i++) {
            str += String.valueOf(s.charAt(i));
            if (!prev.equals(str)) {
                count++;
                prev = str;
                str = "";
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 47036
//やり直し
//参考 http://drken1215.hatenablog.com/entry/2019/02/24/230900
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,N) for (int i = 0; i < N; i++)

ll a, b, q;
vector<ll> s, t, x;
const ll INF = 1e18;

int main() {
    cin >> a >> b >> q;
    s.resize(a); t.resize(b); x.resize(q);
    rep(i,a) scanf("%Ld", &s[i]);
    rep(i,b) scanf("%Ld", &t[i]);
    s.push_back(INF); s.push_back(-INF); sort(s.begin(), s.end());
    t.push_back(INF); t.push_back(-INF); sort(t.begin(), t.end());

    rep(i,q) {
        ll x; cin >> x;
        ll res = INF;

        for (int i = 0; i < 2; i++) {
            auto iters = upper_bound(s.begin(), s.end(), x);
            ll first = i ? *iters : *(iters-1);
            for (int j = 0; j < 2; j++) {
                auto itert = upper_bound(t.begin(), t.end(), x);
                ll second = j ? *itert : *(itert-1);
                res = min(res, abs(first-x) + abs(second-first));
            }
        }

        for (int i = 0; i < 2; i++) {
            auto itert = upper_bound(t.begin(), t.end(), x);
            ll first = i ? *itert : *(itert-1);
            for (int j = 0; j < 2; j++) {
                auto iters = upper_bound(s.begin(), s.end(), x);
                ll second = j ? *iters : *(iters-1);
                res = min(res, abs(first-x) + abs(second-first));
            }
        }

        cout << res << endl;
    }
}

Measured memory_bytes: 3680
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
using static CS_Contest.Utils;

namespace CS_Contest {
	using Li = List<int>;
	using LLi = List<List<int>>;
	class Program {
        static void Main(string[] args) {
			new Calc().Solve();
			return;
        }

		private class Calc {
			public void Solve() {
				string S = ReadLine();
				string[] tag = new string[] { "dream", "dreamer", "erase", "eraser" };

				while (S.Length>=5) {
					var l = S.Length;
					if (S.Substring(l-5, 5) == tag[0] || S.Substring(l-5, 5) == tag[2]) {
						S = S.Remove(l-5, 5);
					}
					else if (l>=7&&S.Substring(l-7, 7) == tag[1]) S = S.Remove(l-7, 7);
					else if (l>=6&&S.Substring(l-6, 6) == tag[3]) S = S.Remove(l-6, 6);
					else break;
				}

				if (S.Length==0) YES();
				else NO();
				return;
			}
		}
    }

	
	
    public static class Utils {
		public static int INF = (int)(1e9);
        public static void WL(this object obj) => WriteLine(obj);
        public static void WL(this string obj) => WriteLine(obj);
        public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL());
		public static int ReadInt() => int.Parse(ReadLine());
		public static List<int> ReadInt(char s) => ReadLine().Split(s).Select(int.Parse).ToList();
		public static long ReadLong() => long.Parse(ReadLine());
		public static List<long> ReadLong(char s) => ReadLine().Split(s).Select(long.Parse).ToList();
		public static void REP(int n,Action<int> act) {
			for (int i = 0; i < n; i++) {
				act(i);
			}
		}
		public static void RREP(int n,Action<int> act) {
			for (int i = n-1; i >=0; i--) {
				act(i);
			}
		}
		public static void REP(long n, Action<int> act) => REP((int)n, act);
		public static void RREP(long n, Action<int> act) => RREP((int)n, act);

		public static void Yes() => "Yes".WL();
		public static void No() => "No".WL();
		public static void YES() => "YES".WL();
		public static void NO() => "NO".WL();


		public static int ManhattanDistance(int x1, int y1, int x2, int y2) => Abs(x2 - x1) + Abs(y2 - y1);

		public class Tree {
			public LLi Graph;
			public Tree(int nodes) {
				Graph = new LLi();
				REP(nodes, x => {
					Graph.Add(new Li());
				});
			}
			public void Add(int x,int y) {
				Graph[x].Add(y);
				Graph[y].Add(x);
			}
		}
    }
}


Measured memory_bytes: 29600
f 0 c _ _ = c
f _ _ _ [] = 1/0
f k c p (a:as)
  | p < a = f (k-1) c a as
  | otherwise = f k c p as `min` f (k-1) (c+p+1-a) (p+1) as
main = do
  [n,k] <- map read . words <$> getLine
  (a:as) <- map read . words <$> getLine
  print $ floor $ f (k-1) 0 a as

Measured memory_bytes: 1020
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

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

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

//vector<ll> G[500005];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(15)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}
ll gcd(ll number1,ll number2){
	if(number1 > number2){
		swap(number1,number2);
	}
	if(number1 == 0 || number1 == number2){
		return number2;
	}else{
		return gcd(number2 % number1,number1);
	}
}

ll i,j,k,ii,jj,r,l;
ll n,m,num,sum,ans;
ll a,b,c,d,e,g,h,w;
ll x[500005],y[500005],z[500005];
ll dp[2005][2005];
char s[2005][2005];

int main(){
	cin >> n;
	if((n%1000)%111 == 0){
		p("Yes");
	}else if((n/10)%111 == 0){
		p("Yes");
	}else{
		p("No");
	}
	return 0;
}

Measured memory_bytes: 256