akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
vi ans(222222);
ll uk[222222];//1 kakutei 2 wakaranai
vvi E(222222);
void dfs(ll now,ll one){
  for(int i=0;i<E[now].size();i++){
    ll to=E[now][i];
    if(uk[to]==1)continue;
    ll nx;
    if(one==1)nx=2;
    else nx=1;
    uk[to]=1;
    ans[to]=one;
    dfs(to,nx);
  }
}
struct UF
{
  vector<int> par; // 親のインデックスを記憶する配列
  vector<int> sz; // サイズを記憶する。
  vector<int> rank;
  // 初期化
  UF(int n):par(n),sz(n),rank(n){
    for(int i = 0; i < n; i++){
      par[i] = i;sz[i] = 1;rank[i] = 0;
    }
  }
  // 親を求める
  int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
  }
  // xとyの属する集合を併合
  void merge(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return;
    if(rank[x] < rank[y]){
      par[x] = y;
      sz[y] += sz[x];
    }
    else{
      par[y] = x;
      sz[x] += sz[y];
      if(rank[x] == rank[y])rank[x]++;
    }
  }
  // xとyが同じ集合ならtrue
  bool same(int x, int y) { return find(x) == find(y); }
  // 素の集合のサイズを求める
  int size(int n){return sz[find(n)];}
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;cin>>n>>m;
  UF uni(111111);
  for(int i=0;i<m;i++){
    ll x,y,z;cin>>x>>y>>z;
    if(z%2==0){
      if(uk[x]==1){
	if(ans[x]==1)ans[y]=1;
	else ans[y]=2;
      }else if(uk[y]==1){
	if(ans[y]==1)ans[x]=1;
	else ans[x]=2;
      }else{
	uk[x]=2;
	uk[y]=2;
	E[x].pb(y);
	E[y].pb(x);
	uni.merge(x,y);
      }
    }else{
      if(uk[x]==1){
	if(ans[x]==1)ans[y]=2;
	else ans[y]=1;
      }else if(uk[y]==1){
	if(ans[y]==1)ans[x]=2;
	else ans[x]=1;
      }else{
	uk[x]=2;
	uk[y]=2;
	E[x].pb(y);
	E[y].pb(x);
	uni.merge(x,y);
      }
    }
  }
  ll cnt=0;
  for(int i=1;i<=n;i++){
    if(uk[i]==0){cnt++;uk[i]=1;}
    else if(uk[uni.find(i)]==2){
      cnt++;
      uk[uni.find(i)]=1;
    }
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 13172
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<(ll)n;i++)
#define repf(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repr(i,a,b) for(ll i=(ll)a-1;i>=(ll)b;i--)
#define Fi first
#define Se second
typedef pair<ll, ll> pll;
const ll MAX = 1000;
const char END = '\n';

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

	ll N;
	cin >> N;
	ll Ans = N;

	rep(i, N + 1) {
		ll sub = 0;
		ll t = i;
		while (t > 0) {
			sub += t % 6;
			t /= 6;
		}
		t = N - i;
		while (t > 0) {
			sub += t % 9;
			t /= 9;
		}
		if (Ans > sub)
			Ans = sub;
	}

	cout << Ans << END;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n,a[100010],ans=0,num=0;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    scanf("%d",&a[i]);
    for(int i=1;i<=n;++i)
    {
        if(a[i]==i)
            num++;
        else
        {
            ans+=(num+1)/2;
            num=0;
        }
    }
    ans+=(num+1)/2;
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

using int64 = long long;
using vi = vector< int64 >;
const int64 INF = 1LL << 59;

vi operator*(const vi &a, const vi &b)
{
  vi c(a.size(), -INF);
  for(int i = 0; i < a.size(); i++) {
    for(int j = 0; j < b.size(); j++) {
      c[(i + j) % a.size()] = max(c[(i + j) % a.size()], a[i] + b[j]);
    }
  }
  return (c);
}

int main()
{
  int N, M, T, Q;
  scanf("%d %d %d", &N, &M, &T);
  vi V(T, -INF), dp(T, -INF);
  V[0] = dp[0] = 0;
  for(int i = 0; i < N; i++) {
    int64 x;
    scanf("%lld", &x);
    V[x % T] = max(V[x % T], x);
  }
  for(int i = 0; i < 20; i++) {
    if((M >> i) & 1) dp = dp * V;
    V = V * V;
  }
  for(int i = T - 2; i >= 0; i--) {
    dp[i] = max(dp[i], dp[i + 1]);
  }
  scanf("%d", &Q);
  while(Q--) {
    int A, B;
    scanf("%d %d", &A, &B);
    puts(dp[A % T] >= 1LL * B * T ? "yes" : "no");
  }
}

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

namespace Sample
{
	class Program
	{
		static void Main(string[] args)
		{
			var r = double.Parse(Console.ReadLine());

			var S = r *r * Math.PI;
			var L = 2 * r * Math.PI;

			Console.WriteLine("{0:0.######} {1:0.######}", S, L);
		}
	}
}



Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, -1, 0, 1 , 1,  1, -1, -1 };
 
 
string a;
stack<string> s;
 
int main() {
    while ( !!( getline( cin, a ) ) && a != "." ) {
        bool is_yes = true;
        for ( int i = 0; i < a.size(); i++ ) {
            if ( a[ i ] == '(' ) {
                s.push( "(" );
            }
            if ( a[ i ] == '[' ) {
                s.push( "[" );
            }
            if ( a[ i ] == ')' ) {
                if ( !s.size() || s.top() != "(" ) {
                    is_yes = false;
                    break;
                }
                s.pop();
            }
            if ( a[ i ] == ']' ) {
                if ( !s.size() || s.top() != "[" ) {
                    is_yes = false;
                    break;
                }
                s.pop();
            }
        }
        if ( is_yes && !s.size() ) {
            printf( "yes\n" );
        }
        else {
            printf( "no\n" );
        }
        while ( s.size() ) {
            s.pop();
        }
    }
    return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    string s;
    cin >> s;
    int a = s.size()+1;
    int z = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'A'){
            a = min(a, i);
        }
        if(s[i] == 'Z'){
            z = max(z, i);
        }
    }
    cout << z - a + 1 << endl;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<ctype.h>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<utility>
#define For(a,b) for(int i=(a);i<(b);i++)
#define Rep(n) for(int i=0; i<(n); ++i)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
//----------program from here----------

int main(){
    int ans=0,N=0;
    cin >> N;
    int V[N],C[N];
    Rep(N) cin >> V[i];
    Rep(N) cin >> C[i];
    Rep(N) if(V[i]>C[i]) ans+=V[i]-C[i];
    cout << ans << endl;
}

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

long long w, h, x, y, r;

int main() {
  cin >> w >> h >> x >> y >> r;
  if(0 <= x - r && 0 <= y - r && x + r <= w && y + r <= h)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3104
N = gets.chomp.to_i
A = gets.chomp.split(' ').map(&:to_i)

A.sort!.reverse!
alice = 0
bob = 0

N.times.each do |n|
  if n % 2 == 0
    alice += A.shift
  else
    bob += A.shift
  end
end

p alice - bob

Measured memory_bytes: 1788
#include <iostream>
#include <cmath>
using namespace std;
long long mod = 1000000007;
long long mysum(long long N, long long K){
    long long sum = K * (N - K + 1) + 1;
    return sum;
}

int main(){
    long long N;
    long long  K;
    cin >> N >> K;
    long long  pat = 0;
    for (long long i = K; i < N + 2; i++)
    {
        pat += mysum(N, i) % mod;
    }
    pat = pat % mod;
    cout << pat << endl;

    return 0;
}


Measured memory_bytes: 3192
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c;
	for(c= 1; c <=3000;c++){
	cin>>a>>b;
	if(a>b&&a>=0&&b>0){
	swap(a,b);
	cout<<a<<" "<<b<<endl;
	}else if(a>b&&a>0&&b>=0){
	swap(a,b);
	cout<<a<<" "<<b<<endl;
	}else  if(a<b&&a>0&&b>=0){
    cout<<a<<" "<<b<<endl;
	}else if(a<b&&a>=0&&b>0){
	cout<<a<<" "<<b<<endl;
	}else if(a==0&&b==0){
	}else if(a==b&&a>0&&b>=0){
	cout<<a<<" "<<b<<endl;
	}else if(a==b&&b>0&&a>=0){
		cout<<a<<" "<<b<<endl;}}
	return 0;
}



Measured memory_bytes: 3036
import java.util.Scanner;
class Main {
 public static void main(String[] args){
  Scanner in = new Scanner(System.in);
  int a = in.nextInt();
  int b = in.nextInt();
  int c = in.nextInt();
  int tmp = 0;
  int[] ary = {a, b, c};
  while(ary[0] > ary[1] || ary[1] > ary[2]){
   if(ary[0] > ary[1]){
    tmp = ary[0];
    ary[0] = ary[1];
    ary[1] = tmp;
   }
   if(ary[1] > ary[2]){
    tmp = ary[1];
    ary[1] = ary[2];
    ary[2] = tmp;
   }
  }
  System.out.println(ary[0] + " " + ary[1] + " " + ary[2]);
 }
}

Measured memory_bytes: 17332
# nまでの自然数が素数かどうかを表すリストを返す
def makePrimeChecker(n):
	isPrime = [True] * (n + 1)
	isPrime[0] = False
	isPrime[1] = False
	for i in range(2, int(n ** 0.5) + 1):
		if isPrime[i]:
			for j in range(i * i, n + 1, i):
				isPrime[j] = False
	return isPrime




#2017nunberの累積和
Q = int(input())
L = [0]
isPrime = makePrimeChecker(100000)
for i in range(1, 100000):
    if i&1==1 and isPrime[i] and isPrime[(i+1)//2]:
        L.append(L[-1] + 1)
    else:
        L.append(L[-1])
for i in range(Q):
    l, r = map(int, input().split())
    print(L[r] - L[l-1])

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

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

	int p, q, r;
	scanf("%d %d %d", &p, &q, &r);
	printf("%d\n", p + q + r - max({p, q, r}));
	return 0;
}

Measured memory_bytes: 3812
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};
/*
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
*/

int main(){
    ll A,B,Q; cin >> A >> B >> Q;
    vector<ll> s(A+2),t(B+2);
    ll x;
    s[0] = -INF; s[A+1] = INF; t[0] = -INF; t[B+1] = INF;
    for (int i = 1; i <= A; i++) cin >> s[i];
    for (int i = 1; i <= B; i++) cin >> t[i];
    vector<ll> v(0);
    for (int i = 0; i < Q; i++){
        cin >> x;
        ll mn = INF;
        ll sr = lower_bound(s.begin(),s.end(),x) - s.begin();
        ll sl = sr-1;
        ll tr = lower_bound(t.begin(),t.end(),x) - t.begin();
        ll tl = tr-1;
        mn = min(mn,max(s[sr],t[tr]) - x);
        mn = min(mn,x - min(s[sl],t[tl]));
        mn = min(mn,s[sr]-t[tl] + min(abs(s[sr]-x), abs(x-t[tl])));
        mn = min(mn,t[tr]-s[sl] + min(abs(t[tr]-x), abs(x-s[sl])));
        v.push_back(mn);
    }
    for (auto e : v){
        cout << e << endl;
    }
}

Measured memory_bytes: 3828
#include<iostream>
 
using namespace std;
 
int main() {
    int n[10000], c10[10000], c50[10000], c100[10000], c500[10000],i=0;
 
    while (1) {
        cin >> n[i];
        if (n[i] == 0)break;
        cin >> c10[i] >> c50[i] >> c100[i] >> c500[i];
        i++;
    }
     
    for (int j = 0; j < i; j++) {
        int m, k10, k50, k100, k500;
        m = c10[j] * 10 + c50[j] * 50 + c100[j] * 100 + c500[j] * 500 - n[j];
 
        k500 = c500[j] - m / 500;
        if (k500 < 0)k500 = 0;
        m -= 500 * (m / 500);
 
        k100 = c100[j] - m / 100;
        if (k100 < 0)k100 = 0;
        m -= 100 * (m / 100);
 
        k50 = c50[j] - m / 50;
        if (k50 < 0)k50 = 0;
        m -= 50 * (m / 50);
 
        k10 = c10[j] - m / 10;
        if (k10 < 0)k10 = 0;
        m -= 10 * (m / 10);
 
        if (k10 > 0)cout << 10 << " " << k10 << endl;
        if (k50 > 0)cout << 50 << " " << k50 << endl;
        if (k100 > 0)cout << 100 << " " << k100 << endl;
        if (k500 > 0)cout << 500 << " " << k500 << endl;
        if(j<i-1)cout << endl;
    }
 
    return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool change(T& a, T b) { if (a != b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;

int c[1000];
int s[1000][1000];
int t[1000];
int last[1000];

int d,n;

void calc(){
    ll hpn=0;
    for(int i=1;i<=d;i++){
        hpn+=s[i][t[i]];
        last[t[i]]=i;
        for(int j=1;j<=n;j++){
            hpn-=c[j]*(i-last[j]);
        }
        cout << max(1000000+hpn,0LL) << endl;
    }
    
}

void solve(){
    //方針:それぞれの日に関して(得る得点)-(失う得点)を最大化する
    for(int i=1;i<=d;i++){
        //hpn+=s[i][t[i]];
        //last[t[i]]=i;
        int maxt=-1,maxsc=-10000000;
        for(int j=1;j<=n;j++){
            if(chmax(maxsc,s[i][j]+c[j]*(i-last[j]))) maxt=j;
        }
        t[i]=maxt;
    }
    
}

void input(){
    cin >> d;
    n=26;
    for(int i=1;i<=n;i++) cin >> c[i];
    for(int i=1;i<=d;i++)
        for(int j=1;j<=n;j++){cin >> s[i][j];}    
    for(int i=1;i<=d;i++) cin >> t[i];
    //cout << calc() << endl;
}

void puts(){
    for(int i=1;i<=d;i++) cout << t[i] << endl;
}

int main(){
    input();
    solve();
    //calc();
    puts();
    return 0;
}

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


int main(){
    int x;
    cin >> x;
    int c = x / 100;
    if (c * 100 <= x && x <= c * 105) cout << 1 << endl;
    else cout << 0 << endl;
}

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

#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, MOD = 1e9 + 7, N = 1e5 + 5, LG = 20;
const int INF = INT_MAX;
const db PI = acos(-1), EPS = 1 / db(1e6);


int main() {
   int n, k; cin >> n >> k;
    int h[n + 1];
    for (int i = 1; i <= n; ++i) cin >> h[i];
    int dp[n + 1];
    dp[1] = 0, dp[2] = abs(h[2] - h[1]);
    for (int i = 3; i <= n; ++i) {
        dp[i] = 1e9;
        for (int j = 1; j <= k and j < i; ++j) {
            dp[i] = min(dp[i], abs(h[i] - h[i - j]) + dp[i - j]);
        }
    }
    // debug(arr(dp, n + 1));
    cout << dp[n] << "\n";
      return 0;
}


Measured memory_bytes: 4404
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int maxCount = 0;
    int ans = 1;
    for (int i = 1; i <= N; i++) {
      int count = 0;
      int n = i;
      while (n % 2 == 0) {
        n /= 2;
        count++;
      }
      if (maxCount < count) {
        maxCount = count;
        ans = i;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include<algorithm>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(void){
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b==c||a+c==b||b+c==a) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define add push_back
#define inf 2147000000

using namespace std;

int main(void){
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			printf("%dx%d=%d\n",i,j,i*j);
		}
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int n,m;
int main(){
    cin>>n>>m;
    if(n%2!=0){
        for(int i=1;i<=m;i++)
            cout<<i<<" "<<n-i+1<<endl;
        return 0;
    }
    int n2=n/2,n1=n-n2;
    for(int i=1;i<=min(m,n1/2);i++)
        cout<<i<<" "<<n1-i+1<<endl;
    for(int i=1;i<=m-n1/2;i++)
        cout<<i+n1+1<<" "<<n2-i+1+n1<<endl;
    return 0;
}

Measured memory_bytes: 3688
w = input()
A = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
a = 0
k = []
for i in range(len(w)):
  k.append(w[i])
for i in range(26):
  if k.count(A[i])%2 == 0 or k.count(A[i]) == 0:
      continue
  else:
    a += 1
    print("No")
    break
if a == 0:
  print("Yes")

Measured memory_bytes: 3064
from collections import Counter
H, W = list(map(int, input().split()))
board = [list(input()) for _ in range(H)]
board = [b for b in board if b.count('.') < W]

b_r = []

for i in range(len(board[0])):
    r = [b[i] for b in board]
    b_r.append(r.count('.'))

idx = [i for i, x in enumerate(b_r) if x == len(board)]

for n in idx[::-1]:
    for b in board:
        b.pop(n)

for b in board:
    print(*b, sep='')


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

int main(void){
    int x,i,kyu;
    cin >> x;

    for(kyu=10;kyu>=1;kyu--){
        for(i=0; i<=199; i++){
            if((10 - kyu) * 200 + i  == x){
                cout << kyu << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353

vector<ll> a(110000,0);
vector<ll> maxlist(110000,-1);

bool isOK(ll index, ll key) {
    if (maxlist.at(index) < key) return true;
    else return false;
}

ll binse(ll key, ll sizem){
	ll left = -1;
	ll right = sizem;
	while (right-left>1){
		ll mid = left+(right-left)/2;
		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	return right;
}


int main(){
	ll n; cin >> n;
	REP(i,n) cin >> a[i];
	maxlist.at(0) = a.at(0);
	ll size0 = 1;
	FOR(i,1,n-1){
		if (binse(a.at(i),size0) == size0){
			maxlist.at(size0) = a.at(i);
			size0++;
		}
		else {
			maxlist.at(binse(a.at(i),size0)) = a.at(i);
		}
	}
	cout << size0 << endl;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n,q;
ll a[200010],b[200010];
vector<ll> g[200010];

void dfs(ll v,ll pre,ll sum){
  sum+=a[v];
  b[v]+=sum;
  for(ll nv : g[v]){
    if(nv==pre)continue;
    dfs(nv,v,sum);
  }
}

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

  cin>>n>>q;
  rep(i,n-1){
    ll u,v;
    cin>>u>>v;
    u--;v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  while(q--){
    ll v,x;
    cin>>v>>x;
    v--;
    a[v]+=x;
  }

  dfs(0,-1,0);
  rep(i,n)cout<<b[i]<<endl;

  return 0;
}


Measured memory_bytes: 25600
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}

signed main(){
	int n;cin>>n;
	vector<int> a(n);
	rep(i,n) cin>>a[i];
	list<int> b;
	rep(i,n){
		if(i&1) b.push_back(a[i]);
		else b.push_front(a[i]);
	}
	if(n%2==0) reverse(All(b));
	itr(i,b) cout<<*i<<" \n"[i==--b.end()];
}

Measured memory_bytes: 9984
lcm' m n = 
  let modulo = m `mod` n
  in if modulo == 0
    then n
    else lcm' n modulo

main = do
  [a,b] <- (map read) . words <$> getLine
  let m = max a b 
  let n = min a b 
  print $ a * b `div` (lcm' m n)


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;

int main(){
    int N;
    cin >> N;
    vector<int> v[N];
    for(int i=0;i<N;i++){
        int u;
        cin >> u;
        v[i].push_back(u-1);
    }
    int ans=0;
    for(int i=0;i<N;i++){
        int t=v[i][0];
        if(v[t][0]==i) ans++; 
    }
    cout << ans/2 << endl;
    return 0;
}


Measured memory_bytes: 5760
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int N,X,T;
    cin>>N>>X>>T;
    int cou=0,ans=0;
    while(1){
        cou+=X;
        ans+=T;
        if(N<=cou){
            cout<<ans<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3192
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */

#include <bits/stdc++.h>
//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

/*
PROG:
LANG: C++
*/

class B {
public:
    void solve(std::istream &in, std::ostream &out) {
        long long a, b, k;
        in >> a >> b >> k;
        long long x = min(a, k);
        a -= x;
        k -= x;
        long long y = min(b, k);
        b -= y;
        k -= y;
        out << a << ' ' << b << "\n";
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    B solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
data=sorted([tuple(map(int,input().split())) for i in range(m)],reverse=True)
ans=0
last=-1
for d in data:
    if d[0]<=last<d[1]:
        pass
    else:
        ans+=1
        last=d[0]
print(ans)


Measured memory_bytes: 17784
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
    int h, n;
    cin >> h >> n;
    vector<int> a(n);
    for(int i = 0; i<n; i++){
        cin >> a[i];
        h = h-a[i];
    }
    if(h <=0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define repr(i, n, a) for (int i = (n)-1; i >= (a); i--)
#define each(it, v) for (auto(it) = (v).begin(); (it) != (v).end(); (it)++)
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>
#define vd vector<double>
#define vvd vector<vd>
#define co(x) cout << (x)
#define con(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define out(x) rep(i, 0, x.size()) cout << x[i] << ((i != x.size() - 1) ? " " : "\n")
const double PI = 3.14159265;
const int MAXN = 1 << 15;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
#define Pr(a) (#a) << "=" << (a) << " "
#define pr(a) cout << Pr(a) << '\n'
///////////////////////////////////////////////////////
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int m;
  cin >> m;
  vector<int> b(m);
  for (int i = 0; i < m; ++i) cin >> b[i];
  cout << lexicographical_compare(a.begin(), a.end(), b.begin(), b.end()) << endl;
  return 0;
}


Measured memory_bytes: 3080
#include"bits/stdc++.h"
using namespace std;

int main()
{
    long long  a,b,k;cin>>a>>b>>k;

    long long xx=a+b;
    if(k>=xx) cout<<0<<' '<<0;
    else if(k>=a) cout<<0<<' '<<b-(k-a);
    else if(k<a) cout<<a-k<<' '<<b;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int                     long long   
#define double                  long double
#define endl                    "\n"
#define pb                      push_back
#define PI                      3.1415926535897932384626433832795l
#define F                       first
#define S                       second
#define mp                      make_pair
#define f(i,n)                  for(int i=0;i<n;i++)
#define fastio                  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)                  (v).begin(),(v).end()
#define rall(v)                 (v).rbegin(),(v).rend()
#define gcd(a,b)                __gcd((a),(b))
#define fill(a,value)           memset(a,value,sizeof(a));
#define minn(v)                 *min_element(v.begin(), v.end());
#define maxx(v)                 *max_element(v.begin(), v.end());
#define print(x)                cout<<(x)<<endl;
#define sum(v)+x                accumulate(v.begin(), v.end(),x);
#define debug(x)                cout<<#x<<'='<<(x)<<endl;
typedef pair<int,int>           pii;
typedef vector<int>             vi;


signed main() 
{
    fastio;
    cout << fixed << setprecision(12);
    int n,k;
    cin>>n>>k;
    int ans=0;
    int mod=1e9+7;
    for(int i=k;i<=n+1;i++)
    {
        ans+=(i*(n-(i-1)))%mod;
        ans++;
        ans%=mod;
        
    }
    print(ans)
    
    
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	auto f1 = [](int x){return x*x*x;};
	auto f2 = [](int x){return x*(x + 1)*(x + 2) / 6; };

	int n;
	while (cin >> n, n){
		int x = 0;
		for (int i = 0; i < 55; ++i){
			for (int j = 0; j < 100; ++j){
				int tmp = f1(i) + f2(j);
				if (tmp <= n) x = max(x, tmp);
			}
		}
		cout << x << '\n';
	}

	return 0;
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;


void solve()
{
  ll H;
  scanf("%lld",&H);
  ll W;
  scanf("%lld",&W);
  int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
  int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
  vector<string> S(H);
  for(int i = 0 ; i < H ; i++){
    cin >> S[i];
  }
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      if (S[i][j]=='#') {
        cout<<'#';
        continue;
      }
      int c=0;
      for (int k=0; k<8; k++) {
        int x = j+dx[k];
        int y = i+dy[k];
        if (0<=x&&x<W&&0<=y&&y<H&&S[y][x]=='#') c++;
      }
      cout<<c;
    }
    cout<<"\n";
  }
}

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


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int i,k,l,r,d;
  k=0;
  scanf("%d%d%d",&l,&r,&d);
  for(i=l;i<=r;i++)
  {
	if(i%d==0)
    {
      k++;
    }
  }
  printf("%d",k);
  return 0;
}
  

Measured memory_bytes: 2140
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n;cin>>n;
  string s,t;cin>>s>>t;
  string ans = "";
  rep(i,n){
    ans += (s[i]);
    ans += (t[i]);
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d %d",&a,&b);
    if((a==1&&b==2)||(a==2&&b==1))
        printf("3\n");
    else if((a==2&&b==3)||(a==3&&b==2))
        printf("1\n");
    else
        printf("2\n");
    return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(A: int, B: int, C: int):
    if A == B and B == C:
        ret = YES
    else:
        ret = NO
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()


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

int f(int x) {
  int k = 0;
  int t = x;
  while (t >= 1) {
    k++;
    t /= 10;
  }
  int y = 0;
  while (k > 1) {
    if (x/(int)pow(10,k-1) == x%10) {
      x = (x%(int)pow(10,k-1) - x%10) / 10;
      k -= 2;
    } else {
      y = 1;
      break;
    }
  }
  return y;
}

int main() {
  int A, B;
  cin >> A >> B;
  int count = 0;
  for (int i = A; i <= B; i++) {
    if (f(i) == 0) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
void bubbleSort(int* N, int len);
int gcd(int a, int b);

int main(void){

  int N, X;
  scanf("%d %d\n", &N, &X);

  int a;
  int *dist;
  dist = (int*)malloc(N*sizeof(int));
  for(int i=0; i<N; i++){
    scanf("%d", &a);
    dist[i] = a-X;
    if(dist[i]<0) dist[i] = -dist[i];
  }

  if(N==1){
    printf("%d\n",dist[0]);
    return 0;
  }

  //bubbleSort(dist,N);

  a=dist[0];
  int b;

  for(int i=1; i<N; i++){

    b = gcd(dist[i],a);
   if(b==1){
      printf("1\n");
      return 0;
    }
   a=b;

  }

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

void bubbleSort(int* N, int len){
  int i,j,temp;

  for(i=0; i<len; i++){
    for(j=len-1; j>i; j--){
      if(N[j] < N[j-1]){
        temp = N[j];
        N[j] = N[j-1];
        N[j-1] = temp;
      }
    }
  }
}

int gcd(int a, int b){
  int r,tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  r = a % b;

  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }

  return b;

}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
using namespace std;
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define VREP(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())

int main(int argc, const char * argv[]) {
	int d;
	cin >> d;
	string s = "Christmas";
	for (int i = 0; i < 25-d; ++i) {
		s += " Eve";

	}
	cout << s << endl;
}


Measured memory_bytes: 256
n=int(input())
a= list(map(int, input().split()))
li=[0 for _ in range(n)]
for i in range(n-1,-1,-1):
    check=0
    for j in range(n//(i+1)):
        check^=li[(i+1)*(j+1)-1]
    if check!=a[i]:
        li[i]+=1
ans=[i+1 for i, x in enumerate(li) if x == 1]
print(len(ans))
print(" ".join(map(str,ans)))

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

int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0)break;
		int dt[n+1][n+1];
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>dt[i][j];
			}
		}
		for(int x=0;x<n+1;x++){
			dt[x][n]=0;
		}
		for(int y=0;y<n;y++){
			dt[n][y]=0;
		}
		for(int k=0;k<n;k++){
			for(int l=0;l<n;l++){
				dt[k][n]+=dt[k][l];
			}
		}
		for(int x=0;x<=n;x++){
			for(int y=0;y<n;y++){
				dt[n][x]+=dt[y][x];
			}
		}
		for(int a=0;a<=n;a++){
			for(int b=0;b<=n;b++){
				if(dt[a][b]/10==0)cout<<"    "<<dt[a][b];
				else if(dt[a][b]/100==0)cout<<"   "<<dt[a][b];
				else if(dt[a][b]/1000==0)cout<<"  "<<dt[a][b];
				else if(dt[a][b]/10000==0)cout<<" "<<dt[a][b];
				else if(dt[a][b]/100000==0)cout<<dt[a][b];
			}
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
N = int(input())

memo = {}

def luca(N):
    if N in memo:
        return memo[N]
    else:
        memo[N] = 0
    if N == 0:
        memo[N] = 2
        return 2
    if N == 1:
        memo[N] = 1
        return 1
    memo[N] = luca(N-1) + luca(N-2)
    return memo[N]

print(luca(N))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i = 0;i < (n); ++i)
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    for(ll i = 1; i <= b; i++){
        if((a*i) % b == c){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

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

void leave(string message) {
  cout << message << endl;
  exit(0);
}

bool eq(string x, string y) {
  lint n = x.length();
  lint m = y.length();
  if(n != m) return false;
  bool res = true;
  for(lint i=0; i<n; i++) {
    res &= (x[i] == y[i]) || (x[i] == '?');
  }
  return res;
}

int main() {
  string S, T;
  cin >> S >> T;

  lint N = S.length();
  lint M = T.length();
  lint ans = -1;
  for(lint i=0; i<N; i++) {
    if(eq(S.substr(i,M), T)) ans = i;
  }

  if(ans == -1) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  for(lint i=ans; i<ans+M; i++) S[i] = T[i-ans];
  for(lint i=0; i<N; i++) if(S[i] == '?') S[i] = 'a';
  
  cout << S << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPP(i, n) for(int i = 1; i <= n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const ll MOD = 1000000007;

int main() {
    int n;cin >> n;
    vector<int> p(n);
    REP(i,n) cin >> p[i];
    int ans = 0;
    FOR(i,1,n-1) {
        ans += (p[i-1]<p[i] && p[i]<p[i+1] || p[i-1]>p[i] && p[i]>p[i+1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  for(int i=0;i<1<<3;i++){
    int c=s[0]-'0';
    string t;
    for(int j=0;j<3;j++){
      if(i&1<<j){
        c+=s[j+1]-'0';
        t.push_back('+');
      }else{
        c-=s[j+1]-'0';
        t.push_back('-');
      }
    }
    if(c==7){
      for(int j=0;j<3;j++){
        cout<<s[j]<<t[j];
      }
      cout<<s[3]<<"=7"<<endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#include <deque>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a)%MOD)+((b)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using MCI = std::map<char, int>;
using namespace std;


signed main(){
	int R;
	cin >> R;

	if(R < 1200) cout << "ABC" << endl;
	else if(R < 2800) cout << "ARC" << endl;
	else cout << "AGC" << endl;

	return 0;
}

Measured memory_bytes: 256
from math import factorial
N = int(input())
S = input()
MOD = 10 ** 9 + 7

LR = [True]  # Left is True
for i in range(N*2-1):
    LR += [LR[-1]] if S[i+1] != S[i] else [not LR[-1]]

valid = S[0] == S[-1] == 'B' and not LR[-1] and LR.count(True) == N

if valid:
    # calc lr combination
    cmb = 1
    cr = 0
    for i in range(N*2-1, -1, -1):
        if not LR[i]:
            cr += 1
        else:
            cmb *= cr
            cmb %= MOD
            cr -= 1

    print((factorial(N) * cmb) % MOD)
else:
    print(0)


Measured memory_bytes: 5892
#include<cstdio>
#include<iostream>
#include<vector>
#include<tuple>
#include<queue>
#include<algorithm>
#include<string.h>

using namespace std;



int main(int argc, char* argv[]){
  int n;
  scanf("%d",&n);
  long long int ans = 100000000000;
  for(int i=1;i<=n/2;i++){
    int a=i;
    int b=n-a;
    long long int temp=0;
    for(int j=0;;j++){
      temp+=a%10;
      a=a/10;
      if(a==0)break;
    }
    for(int j=0;;j++){
      temp+=b%10;
      b=b/10;
      if(b==0)break;
    }
    if(temp<ans)ans=temp;
  }

  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int arr[100][100];

int main(void)
{
    int n;
    cin >> n;
    fill(arr[0], arr[0] + 100 * 100, -1);

    REP(i, n)
    {
        int a;
        cin >> a;
        // 1 - > 2 etc
        REP(j, a)
        {
            int x, y;
            cin >> x >> y;
            arr[i + 1][x] = y;
        }
    }

    int ans = 0;
    for (int x = 0; x < (1 << n); x++)
    {
        int honest = 0;
        int check[n + 1];

        REP(i, n)
        {
            if (((x >> i) & 1) == 1)
            {
                honest++;
                check[i + 1] = 1;
            }
            else
            {
                check[i + 1] = 0;
            }
        }

        bool flag = true;
        for (int i = 1; i <= n; i++)
        {
            if (check[i] == 0)
                continue;
            for (int j = 1; j <= n; j++)
            {
                if (arr[i][j] == -1)
                    continue;
                if (arr[i][j] != check[j])
                    flag = false;
            }
        }
        if (flag)
            ans = max(ans, honest);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int INF = 1 << 30;

/* typedef */

typedef deque<int> di;

struct Stat {
  int sum, nxt, i;

  Stat() {}
  Stat(int _sum, int _nxt, int _i): sum(_sum), nxt(_nxt), i(_i) {}

  bool operator<(const Stat& s0) const {
    return sum > s0.sum || (sum == s0.sum && nxt > s0.nxt);
  }
};

typedef set<Stat> ss;

/* global variables */

int n, d;
di msls[MAX_N];

/* subroutines */

/* main */

int main() {
  for (;;) {
    cin >> n >> d;
    if (n == 0) break;
    //printf("n=%d, d=%d\n", n, d);
    
    ss q;
    int min_sum = INF;
    
    for (int i = 0; i < n; i++) {
      di& mslsi = msls[i];
      int mn, mj, sum = 0;
      cin >> mn;
      //printf("  i=%d,mn=%d\n", i, mn);

      mslsi.clear();
      for (int j = 0; j < mn; j++) {
	cin >> mj;
	mslsi.push_back(mj);
	sum += mj;
      }

      if (sum > 0)
	q.insert(Stat(sum, sum - mslsi.back(), i));
      if (min_sum > sum) min_sum = sum;
    }

    bool ok = true;
    
    while (ok && q.size() > 1) {
      ok = false;

      for (ss::iterator sit = q.begin(); sit != q.end(); sit++) {
	Stat u = *sit;
	//printf("u(sum=%d,nxt=%d,i=%d),min_sum=%d\n",u.sum,u.nxt,u.i,min_sum);

	int max_sum0 = q.begin()->sum;
	if (sit == q.begin()) {
	  ss::iterator sit0 = sit;
	  max_sum0 = (++sit0)->sum;
	}

	int min_sum0 = min(min_sum, u.nxt);

	if (max_sum0 - min_sum0 <= d) {
	  ok = true;
	  q.erase(sit);
	  
	  di& mslsu = msls[u.i];
	  mslsu.pop_back();
	  u.sum = u.nxt;
	  if (u.nxt > 0) u.nxt -= mslsu.back();
	  if (u.sum > 0) q.insert(u);

	  min_sum = min_sum0;
	  break;
	}
      }
    }

    cout << (ok ? "Yes" : "No") << endl;
  }

  return 0;
}

Measured memory_bytes: 1312