akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

void swap(void *x, void *y, size_t size);

int n;
int dat[100005];

int main()
{
	int ans = 0;

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

	for (int i = 1; i < n; i++) {
		if (dat[i] == i) {
			ans++;
			swap(dat + i, dat + i + 1, sizeof(int));
		}
	}

	if (dat[n] == n) {
		ans++;
	}

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

	return 0;
}

void swap(void *x, void *y, size_t size)
{
	if (x == y) {
		return;
	} else {
		while(size--) {
			*((unsigned char *)x + size) ^= *((unsigned char *)y + size);
			*((unsigned char *)y + size) ^= *((unsigned char *)x + size);
			*((unsigned char *)x + size) ^= *((unsigned char *)y + size);
		}
	}
}


Measured memory_bytes: 512
#include<stdio.h>
int main()
{
    int a,y;
    scanf("%d",&a);
    if(a%2==0){
        y=a/2;

    }
    else {
        y=(a-1)/2;
        y++;
    }
    printf("%lf\n",(double)y/a);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
int n,w;
vector<ll> cost(101);
vector<ll> weight(101);
ll mp[1000001][101];
ll solve(ll curr_w,int i)
{
    if(i==n)
        return 0;
    ll an;
    if(mp[curr_w][i]!=-1)
        return mp[curr_w][i];
    if(weight[i]+curr_w>w)
        an = solve(curr_w,i+1);
    else
        an = max(solve(curr_w+weight[i],i+1)+cost[i],solve(curr_w,i+1));
    mp[curr_w][i] = an;
    return an;
}
int main(){
    memset(mp,-1,sizeof(mp));
    cin>>n>>w;
    int i;
    for(i=0;i<n;i++)
        cin>>weight[i]>>cost[i];
    cout<<solve(0LL,0);
}




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

int main(){
  int a, b;
  cin >> a >> b;
  int loop = 20 * min(a, b);
  for(int i=1;i<=loop;i++){
    if(floor(i*0.08)==a && floor(i*0.1)==b){
      cout << i << endl;
      break;
    }
    if(i==loop){
      cout << -1 << endl;
    }
  }
}


Measured memory_bytes: 256
N  = gets.to_i
An = [nil] + gets.split.map(&:to_i)

Bn = [nil] + [0]*N
N.downto(1){|i|
	rem_sofar = i.step(N, i).inject(0){|acc,i| (acc+Bn[i])&1 }
	Bn[i] = 1 if An[i] != rem_sofar
}

p Bn.count(1)
puts (1..N).select{|i| Bn[i] == 1 }.join(' ')


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

using namespace std;

typedef long long ll;

int main(int, char**)
{
	ll k, a, b, an1, ans = 0;
	cin >> k >> a >> b;

	an1 = 1 + k;
	if ((b - a) > 2) {
		k -= a - 1;
		ans = a;
		ans += (b - a)*(k / 2);
		if (k % 2 > 0) ans++;
	}

	ans = max(an1, ans); 
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

#define sp ' '
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define forn(YY, yy) for(long long int yy = 0; yy < YY; ++yy)
#define prn(XX) cout << XX << endl
#define prs(XX) cout << XX << " "

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

const int MOD = 1e9 + 7;
const int INF = 2e9 + 13;
const int mINF = -2e9 - 13;
const double PI = 3.14159265358979;
const double EPS = 1e-9;

const int MAXN = 103;
const int MAXG = 100003;

ll dp[MAXG], v[MAXN], w[MAXN];
ll N, W;

int main(int argc, char **argv){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    memset(dp, INF, sizeof dp);
    dp[0] = 0;

    cin >> N >> W;
    for(int i = 1; i <= N; ++i)
        cin >> w[i] >> v[i];

    int maxv = 0;

    for(int i = 1; i <= N; ++i){
        for(int j = MAXG; j >= v[i]; --j){
            if(dp[j-v[i]] + w[i] <= W){
                dp[j] = min(dp[j], dp[j-v[i]] + w[i]);
                maxv = max(maxv, j);
            }
        }
    }
    cout << maxv << endl;

    return 0;
}

//cikisir



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

int main()
{
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }

    vector<int> bucket(202020);
    for (int i = 0; i < N; i++)
    {
        bucket[A[i]]++;
    }
    sort(bucket.begin(), bucket.end());
    reverse(bucket.begin(), bucket.end());

    int count = 0;
    for (int i = K; i < 202020; i++)
    {
        if (!bucket[i])
            break;
        count += bucket[i];
    }
    cout << count << endl;
}


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

int main(){
  int n,W;cin>>n>>W;
  vector<int> w(n);
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>w[i]>>v[i];
  
  vector<vector<ll>> dp(n,vector<ll>(W+1,0));
  
  //初期条件？
  for(int i=0;i<W+1;i++){
    if(i<w[0])dp[0][i]=0;
    else dp[0][i]=v[0];
  }
  
  for(int i=1;i<n;i++)
    for(int j=0;j<W+1;j++){
      if(j<w[i])dp[i][j]=dp[i-1][j];
      else dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
    }
  
  cout<<dp[n-1][W]<<endl;
}

Measured memory_bytes: 82344
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
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; }
using namespace std;

int main(){

    int N, K;
    cin >> N >> K;
    string s;
    cin >> s;
    s += '*';
    int ans = 0;
    int now = 0;
    int cnt = 0;
    rep(i, (int)s.size() - 1){
        now++;
        if(s[i] != s[i + 1]){
            ans += now - 1;
            now = 0;
            cnt++;
        }
    }

    rep(loop, K){
        if(cnt >= 3){
            ans += 2;
            cnt -= 2;
        } else if(cnt >= 2){
            ans++;
            cnt--;
        }
    }

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

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

int main() 
{
    int h,w; cin >> h >> w;
    vector<vector<int> > data(h, vector<int>(w));
    vector<int> low(h,0);
    vector<int> col(w,0);

    rep(i,h) {
        string tmp;
        cin >> tmp;
        low[i] = i;
        rep(j,tmp.size()) {
            col[j] = j;
            if(tmp[j] == '#') { data[i][j] = 1; };
        }
    }
#if 0
    rep(i,h){ 
        rep(j,w) {
            cout << data[i][j] << ",";
        }
        cout << endl;
    }
#endif
    for(int cnt = 0; cnt < 100; cnt++) { 
        rep(i,low.size()) {

            int low_check = 0;
            rep(j,col.size()) {
                if(data[low[i]][col[j]]) { low_check++; }
            }    
            if(low_check == 0) { low.erase(low.begin()+i); }
        }

        rep(j,col.size()) {

            int col_check = 0;
            rep(i,low.size()) {
                if(data[low[i]][col[j]]) { col_check++; }
            }    
            if(col_check == 0) { col.erase(col.begin()+j); }
        }
    }
    rep(i,low.size()){ 
        rep(j,col.size()) {
            if(data[low[i]][col[j]]) { cout << '#'; }
            else                     { cout << '.'; }
        }
        cout << endl;
    }
    return 0;
}



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

// これだとなぜかwaになる
int main() {
    int N, K;
    int R, S, P;
    string T;
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;

    long long score = 0;
    vector<bool> winList(N, false);
    for (int i = 0; i < N; i++) {
        if (i >= K) {
            // cout << i << ":" << T[i - K] << "," << T[K] << endl;
            // cout << i - K << ":" << winList[i - K] << endl;
            if (T[i - K] == T[i] && winList[i - K]) {
                winList[i] = false;
                // cout << i << endl; // debug
                continue;
            }
        }

        switch (T[i]) {
            case 'r': {
                score += P;
                break;
            }
            case 's': {
                score += R;
                break;
            }
            case 'p': {
                score += S;
                break;
            }
        }
        // cout << score << endl; // debug
        winList[i] = true;
    }
    cout << score;
}

Measured memory_bytes: 3776
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
	long long a,b,n;
	cin >> a >> b >> n;
	if(n>=b-1)
		cout << a-(a+b-1)/b << endl;
	else
		cout << (a*n)/b - a*(n/b) << endl;
}


Measured memory_bytes: 3636
#include <iostream>

struct Card
{
  char suit, num;
};

using namespace std;
void bubblesort(Card c[], int n);
void selectionsort(Card c[], int n);
void print(Card c[], int n);
bool isStable(Card c1[], Card c2[], int n);

int main(int argc, char const *argv[])
{
  Card c1[36], c2[36];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> c1[i].suit >> c1[i].num;
    c2[i] = c1[i];
  }
  bubblesort(c1, n);
  selectionsort(c2, n);
  print(c1, n);
  cout << "Stable" << endl;
  print(c2, n);
  if(isStable(c1, c2, n))
  {
    cout << "Stable" << endl;
  }
  else
  {
    cout << "Not stable" << endl;
  }
  return 0;
}

void bubblesort(Card c[], int n)
{
  for (int i = 0; i < n; i++)
  {
    for (int j = n - 1; j > i; j--)
    {
      if (c[j].num < c[j - 1].num)
      {
        swap(c[j], c[j - 1]);
      }
    }
  }
}

void selectionsort(Card c[], int n)
{
  for (int i = 0; i < n; i++)
  {
    int minj = i;
    for (int j = i; j < n; j++)
    {
      minj = c[minj].num <= c[j].num ? minj : j;
    }
    if (c[i].num > c[minj].num)
    {
      swap(c[i], c[minj]);
    }
  }
}

bool isStable(Card c1[], Card c2[], int n)
{
  for (int i = 0; i < n; i++)
  {
    if (c1[i].suit != c2[i].suit)
    {
      return false;
    }
  }
  return true;
}

void print(Card c[], int n)
{
  for (int i = 0; i < n - 1; i++)
  {
    cout << c[i].suit << c[i].num << ' ';
  }
  cout << c[n - 1].suit << c[n - 1].num << endl;
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005
int main(){
    int n,x;
    scanf("%d %d",&n,&x);
    n=2*n-1;
    if(x==1||x==n){
        printf("No\n");
    }
    else{
        printf("Yes\n");
        if(n==3){
            printf("1\n2\n3\n");
            return 0;
        }
        int ans[200005];
        fill(ans,ans+n,0);
        set<int> s;
        for(int i = 1;i<=n;i++)
        s.insert(i);
        ans[n/2]=x;
        s.erase(x);
        if(x==n-1){
            ans[n/2+1]=n;
            s.erase(n);
            ans[n/2+2]=n-2;
            s.erase(n-2);
            ans[n/2-1]=n-3;
            s.erase(n-3);
        }
        else{
            ans[n/2+1]=x-1;
            s.erase(x-1);
            ans[n/2+2]=x+1;
            s.erase(x+1);
            ans[n/2-1]=x+2;
            s.erase(x+2);
        }
        for(int i = 0;i<n;i++){
            if(ans[i]==0){
                printf("%d\n",*s.begin());
                s.erase(s.begin());
            }
            else{
                printf("%d\n",ans[i]);
            }
        }
        //printf("\n");
    }
}
/*

b[i]*K!/(i)!*(K-i)!
*/

Measured memory_bytes: 11648
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
  int N; cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  unsigned long long total = 0, odd = 0;
  for (int i = 0; i < N; i++) {
    total += A[i];
    if (i%2) {
      odd += A[i];
    }
  }

  unsigned long long m = total-2*odd;
  cout << m << ' ';
  for (int i = 0; i < N-1; i++) {
    m = 2*A[i] - m;
    cout << m << ' ';
  }
  cout << endl;
  return 0;
}


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (int)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

int main()
{
    ll n,m;
    cin >> n >> m;
    vll l(m),r(m),tmp(n+1,0);
    rep(i,m){
        cin >> l[i] >> r[i];
        l[i]--;

        tmp[l[i]]++;
        tmp[r[i]]--;
    }

    ll ans=0;
    rep(i,n+1){
        if(i > 0)tmp[i] += tmp[i-1];
        if(tmp[i] == m)ans++;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;
static const int MAX = 1e9;
ll H, W, N;

signed main()
{
    cin >> H >> W >> N;
    map<pair<ll, ll>, ll> mp;
    rep(i, N)
    {
        ll a, b;
        cin >> a >> b;
        --a, --b;
        for (ll da = -1; da <= 1; ++da) {
            for (ll db = -1; db <= 1; ++db) {
                ll na = a + da;
                ll nb = b + db;
                if (na < 1 || H - 1 <= na || nb < 1 || W - 1 <= nb) {
                    continue;
                }
                mp[make_pair(na, nb)]++;
            }
        }
    }
    vector<ll> res(10);
    res[0] = (H - 2) * (W - 2);
    for (auto& kv : mp) {
        res[kv.second]++;
        res[0]--;
    }

    for (auto x : res) {
        cout << x << endl;
    }

    return 0;
}

Measured memory_bytes: 56448
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n) ; ++i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define all(x) x.begin(),x.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

template<typename T>
void printVec(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << v << ",";
  }
  cout << "]" << endl;
}

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

  int l = s.length();

  string ans(l,'x');

  cout << ans;


  return 0;
}


Measured memory_bytes: 256
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return set([i for i in range(n + 1) if is_prime[i]])
 
p_set = primes(10 ** 5)
sum_list = [0] * ((10 ** 5) + 1)
 
for i in range(len(sum_list) - 1):
    ret = 0
    if (i+1) in p_set and ((i+2) // 2) in p_set:
        ret = 1
    else:
        ret = 0
    sum_list[i+1] = sum_list[i] + ret

q = int(input())
 
for i in range(q):
    l, r = map(int, input().split())
    print(sum_list[r] - sum_list[l-1])


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

int main() {
  ll x, ans = 0;
  cin >> x;
  for (ll i = 1; i <= x; i ++) {
    ll t = x / i;
    ans += t * (t + 1) / 2 * i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
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);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

vector<string> res;

void func(int num,string s){
    if(num == 4){ res.pb(s); return;}
    if(num == 1) s += "KIH";
    else if(num == 2) s += "B";
    else if(num == 3) s += "R";
    
    func(num+1,s+"A");
    func(num+1,s);
}

int main(){
    string S;
    cin >> S;
    func(0,"");
    if(find(ALL(res),S) != res.end()) pr("YES");
    else pr("NO");
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

class UnionFind {
    public:
    //親の番号を格納する。親だった場合は-1
    vector<int> Parent;

    //作るときはParentの値をすべて-1にする
    //こうすると全てバラバラになる
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }

    //Aがどのグループに属しているか調べる
    int root(int A) {
        if(Parent[A] < 0) {
            return A;
        }
        return Parent[A] = root(Parent[A]);
    }

    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//親をとっていきたい
    }

    //AとBをくっつける
    bool connect(int A, int B) {
         //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
         A = root(A);
         B = root(B);
         if(A == B) {
             //すでにくっついているからくっつけない
             return false;
         }

         //大きい方(A)に小さい方(B)をくっつけたい
         //大小が逆だったらひっくり返しちゃう
         if(size(A) < size(B)) {
             swap(A, B);
         }

         //Aのサイズを更新する
         Parent[A] += Parent[B];
         //Bの親をAに変更する
         Parent[B] = A;

         return true;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> A(m), B(m);
    rep(i, m) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }

    vector<ll> ans(m);
    ans[m-1] = (ll)n*(n-1)/2;

    UnionFind Uni(n);

    for(int i = m-1; i >= 1; i--) {
        ans[i-1] = ans[i];

        if(Uni.root(A[i]) != Uni.root(B[i])) {
            ans[i-1] -= (ll)Uni.size(A[i])*Uni.size(B[i]);
            Uni.connect(A[i], B[i]);
        }
    }

    rep(i, m) {
        cout << ans[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 3328
#include<iostream>

using namespace std;

int dfs(int ABCD, int op){	
	int abcd = ABCD;
	if(op >= 8) return -1;
	int A, B, C, D;

	D = abcd % 10; abcd /= 10;
	C = abcd % 10; abcd /= 10;
	B = abcd % 10; abcd /= 10;
	A = abcd % 10;

	int op1 = op & 1;
	int op2 = op & 2;
	int op3 = op & 4;

	int ans = A;
	ans += (op1) ? -1 * D : D;
	ans += (op2) ? -1 * C : C;
	ans += (op3) ? -1 * B : B;

	if(ans == 7) return op;
	else return dfs(ABCD, op+1);
}


int main(){
	int ABCD; cin >> ABCD;
	int abcd = ABCD, A, B, C, D;
	D = abcd % 10; abcd /= 10;
	C = abcd % 10; abcd /= 10;
	B = abcd % 10; abcd /= 10;
	A = abcd % 10;

	int op = dfs(ABCD, 0);

	if(op != -1) {
		cout << A;
		if((op&4) == 0){ cout << "+"; }else cout << "-";
		cout << B;
		if((op&2) == 0){ cout << "+"; }else cout << "-";
		cout << C;
		if((op&1) == 0){ cout << "+"; }else cout << "-";
		cout << D;
		cout << "=7" << endl;
	}

	return 0;
}	



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

using namespace std;
#define int long long int
int32_t main() {
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    int max=0,s=0;
    for(int i=0;i<n;i++)
    {
       if(a[i]>=max)
       max=a[i];
       s=s+max-a[i];
    }
       cout<<s; 
    return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

bool used[30];

int main() {
    string s;
    cin >> s;
    rep(i, s.size()) used[s[i]-'a'] = true;
    if (s.size() < 26) {
        rep(j, 26) {
            if (!used[j]) {
                s += char('a'+j);
                break;
            }
        }
        cout << s << endl;
        return 0;
    }
    for (int i=s.size()-1; i>=0; --i) {
        //cout << s[i] << ", " << (s[i]<s[i+1]) << ", " << char(s[i]+1) << endl;
        if (i < 25 and s[i] < s[i+1]) {
            for (int j=s[i]-'a'+1; j<26; ++j) {
                if (!used[j]) {
                    s[i] = char('a'+j);
                    break;
                }
            }
            cout << s.substr(0, i+1) << endl;
            return 0;
        }
        used[s[i]-'a'] = false;
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>

int x,y;

int main()
{
	scanf("%d %d",&x,&y);
	if(x == 2 || y == 2) {
		printf("No\n");
		return 0;
	}
	if(x == 4 || x == 6 || x == 9 || x == 11){
		if(y == 4 || y == 6 || y == 9 || y == 11) {
			printf("Yes\n");
		}
		else printf("No\n");
	}
	else{
		if(y == 4 || y == 6 || y == 9 || y == 11){
			printf("No\n");
		}
		else printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
struct Item 
{
    int v;
    int delay;
    bool operator<(const Item&o)const
    {
        return o.v < v;
    }
};
bool cmp_dealy(const Item &a,const Item &b)
{
    return a.delay > b.delay;
}
int main()
{
    int n,m;
    cin>>n>>m;
    vector<Item> vec(n);
    for(int i=0;i<n;++i)
    {
        cin>>vec[i].delay>>vec[i].v;
    }
    sort(vec.begin(),vec.end(),cmp_dealy);
    auto p = vec.begin();
    priority_queue<Item> q;
    for(int i=1;i<=m;++i)
    {
        int capacity = i;
        while(p != vec.end())
        {
            if(p->delay + i - 1 < m)
            {
                break;
            }
            if(p->delay + i - 1 > m)
            {
                p++;
                continue;
            }
            if(q.size() < capacity)
            {
                q.push(*p);
            }else
            {
                if(q.top().v < p->v)
                {
                    q.pop();
                    q.push(*p);
                }
            }
            p++;
        }
    }
    long long ans = 0;
    while(!q.empty())
    {
        ans+=q.top().v;
        q.pop();
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2168
#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long ll;

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


int main() {
	string s, t;
	cin >> t >> s;
	ll ans = 1001;
	for (int i = 0; i < t.size() - s.size() + 1; i++) {
		ll count = 0;
		for (int j = 0; j < s.size(); j++) {
			if(s.substr(j,1)!=t.substr(j+i,1)) count++;
		}
		ans = min(ans,count);
	}
	cout << ans << endl;
	return 0;
}

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

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

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

    ll N,T; cin >> N >> T;

    ll ans = 0;
    ll t1, t2;
    cin >> t2;

    for (int i = 0;i < N-1;i++){
        t1 = t2;
        cin >> t2;
        ans += min(T,t2-t1);
    }

    cout << ans+T << endl; 

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector <ll> v[100001];
ll dp[100001];
ll dfs(ll i,ll vis[])
{

      if(vis[i]!=0)
      	return dp[i];

      vis[i]=1;
      ll mx=0;
   for(auto it=v[i].begin();it!=v[i].end();it++)
   {
      mx=max(mx,dfs((*it),vis)+1);
      
   }

   return dp[i]=mx;
}

int main()
{
   
    
// 	freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
	ll vis[100001]={0};
   for(ll i=0;i<100001;i++)
   	dp[i]=0;
    ll n,m;
    cin>>n>>m;

    ll x,y;
    ll d[100001]={0};
    for(ll i=1;i<=m;i++)
    {
    	
    	cin>>x>>y;
    	v[x].push_back(y);
    }
    ll mx=INT_MIN;
    for(ll i=1;i<=n;i++)
    {
          
        mx=max(dfs(i,vis),mx);
    	
    }

    cout<<mx;


    
    
}

Measured memory_bytes: 9344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;

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

    vector<ll> c(n, 0), s(n, 0), f(n, 0);
    for(int i=0; i<n-1; i++)
        cin >> c[i] >> s[i] >> f[i];
        
    for(int i=0; i<n; i++){
        ll sum = 0;
        for(int j=i; j<n-1; j++){
           if(sum<s[j]) sum = s[j];
           else if((sum-s[j])%f[j]>0) sum += f[j]-(sum-s[j])%f[j];
            sum += c[j]; 
        }
        
        cout << sum << endl;
    }
    
    
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
int main(){
    int n;
    scanf("%d",&n);
    std::vector<std::string> vs;
    for(int i=0;i<n;i++){
        std::string s;
        std::cin >> s;
        std::sort(s.begin(),s.end());
        vs.push_back(s);
    }
    std::sort(vs.begin(),vs.end());
    long long cnt=0;
    int conti=0;
    for(int i=1;i<n;i++){
        if(vs[i]==vs[i-1]){
            ++conti;
            cnt+=conti;
        }else{
            conti=0;
        }
    }
    std::cout << cnt << std::endl;
    return 0;
}

Measured memory_bytes: 5748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);

const int N = 2e5+5, M = 1e6+6, OO = 0x3f3f3f3f;
int tc;

int main()
{
    FIO
    string s; cin>>s;
    if(s[s.length() -1 ] == 's')
        return cout<<s+"es", 0;
    cout<<s+"s";
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    double a[n];
    for(int i; i < n; i++)
        cin >> a[i];
    double mix = 0;
    for(int i = 0; i < n; i++) {
        mix += 1 / a[i];
    }
    cout << 1 / mix << endl;
}

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

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

    int d[n];
    for (int i = 0; i < n; i++)
    {
        cin >> d[i];
    }
    
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i+1; j < n; j++)
        {
            sum += d[i] * d[j];
        }
    }

    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
struct mint {
    int x;
    mint(int x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(int t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return *this *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    mint ans = 0;
    REP(i, K, N + 1) {
        int r = N - i;
        int lower = i * (i - 1) / 2;
        int upper = N * (N + 1) / 2 - r * (r + 1) / 2;
        //cout << i << " " << lower  << " " << upper << endl;
        ans += upper - lower + 1;
    }
    cout << ans.x << endl;

    return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
  s << vv[i] << endl;
  }
  return s;
}

int N,M,X,Y;
vector<int> x;
vector<int> y;
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> N >> M >> X >> Y;
  x.resize(N);
  y.resize(M);

  rep(i,N){
    cin >> x[i];
  }
  x.emplace_back(X);
  rep(i,M){
    cin >> y[i];
  }
  y.emplace_back(Y);

  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  if(x[N] >= y[0]){
    cout << "War" << endl;
  }
  else{
    cout << "No War" << endl;
  }


  return 0;
}


Measured memory_bytes: 256
def calc(s):
    r = "Yes"
    for i in range(len(s)):
        c = s[i]
        if (i+1) % 2 == 0:
            if c not in ["L", "U", "D"]:
                r = "No"
                break
        else:
            if c not in ["R", "U", "D"]:
                r = "No"
                break
    return r


s = input()

r = calc(s)
print(r)


Measured memory_bytes: 3060
def isLoop(s)
  s.reverse == s
end

s = gets.chomp
n = s.length
l = s[0..(n-1)/2-1]
r = s[(n+3)/2-1..n-1]
if isLoop(l) && isLoop(r) && isLoop(s)
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1788
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N,K;
	string S;
	cin >> N >> S >> K;
	
	char a = S[K - 1];
	REP(i, N) {
		if (S[i] != a) {
			S[i] = '*';
		}
	}

	cout << S << endl;
	return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	if(s[1] == 'B') s[1] = 'R';
	else s[1] = 'B';
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 3612
#include<iostream>
using namespace std;                           
int main()                                     
{                                              
  int W,H,x,y,r;                               
  cin >> W >> H >> x >> y >> r;                
  if((x>=0 && y>=0) && ((W-r)>=x && (H-r)>=y))                                                         
    cout << "Yes" << endl;                     
  else                                         
    cout << "No" << endl;                      
  return 0;                                    
}

Measured memory_bytes: 1156
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int 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
#include<bits/stdc++.h>
using namespace std;
#define M 998244353
int main(){
  long N;cin>>N;
  vector<long>D(N,0);long ans=true; bool c=true; 
  for(int i=0;i<N;i++){long a;cin>>a;D[a]++;if(i==0&&a!=0)ans=0;}
  ans*=(D[0]==1);
  for(int i=1;i<N;i++){//D[i-1]^D[i]
    if(D[i]==0)c=false;
    for(int _=0;_<D[i];_++)ans=(ans*D[i-1])%M;
    if(c==false && D[i]!=0)ans=0;
  }
  cout<<ans;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  string s;
  cin >> s;
  if (s == "Sunny") cout << "Cloudy" << endl;
  if (s == "Cloudy") cout << "Rainy" << endl;
  if (s == "Rainy") cout << "Sunny" << endl;
}


Measured memory_bytes: 764
def c_together(N, A):
    from collections import defaultdict
    count = defaultdict(int)
    for i in A:
        count[i] += 1
    ans = 0
    for i in range(max(A) + 1):
        # ある整数iにするには、i-1に+1する、何もしない、i+1に-1する3パターン
        tmp = count[i - 1] + count[i] + count[i + 1]
        ans = max(ans, tmp)
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(c_together(N, A))

Measured memory_bytes: 20084
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {

    int sx,sy,tx,ty; cin >>sx>>sy>>tx>>ty;

    string s = "L";
    for (int i = 0; i < ty - sy + 1; i++) {
        s += "U";
    }
    for (int i = 0; i < tx - sx + 1; i++) {
        s += "R";
    }
    for (int i = 0; i < ty - sy + 1; i++) {
        s += "D";
    }
    for (int i = 0; i < tx - sx; i++) {
        s += "L";
    }

    for (int i = 0; i < ty - sy; i++) {
        s += "U";
    }
    for (int i = 0; i < tx - sx + 1; i++) {
        s += "R";
    }
    for (int i = 0; i < ty - sy + 1; i++) {
        s += "D";
    }
    for (int i = 0; i < tx - sx + 1; i++) {
        s += "L";
    }

    s += "U";


    cout << s << endl;
    return 0;
}




Measured memory_bytes: 256
n = int(input())
l = [0]+list(map(int,input().split()))+[0]
s = 0
for j in range(len(l)-1):
    s += abs(l[j+1]-l[j])
for i in range(1,n+1):
  a = l[i-1]
  b = l[i]
  c = l[i+1]
  if a<=b<=c:
    print(s)
  elif a<=c<=b:
    print(s-2*(b-c))
  elif b<=a<=c:
    print(s-2*(a-b))
  elif b<=c<=a:
    print(s-2*(c-b))
  elif c<=a<=b:
    print(s-2*(b-a))
  elif c<=b<=a:
    print(s)

Measured memory_bytes: 13920
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>n;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int a, b;
  cin >> a >> b;
  cout << (a-1) * (b-1) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  long long a,b,n,x;
  scanf("%lld %lld %lld",&a,&b,&n);
  if(b>n){
    x=n;
  }else{
    x=b-1;
  }
  printf("%lld\n",((a*x)/b)-(a*(x/b)));
  return 0;
}


Measured memory_bytes: 1660
N, W = list(map(lambda x: int(x), input().split()))
w = []
v = []
for i in range(N):
  line = input().split()
  w.append(int(line[0]))
  v.append(int(line[1]))
  
inf = 10**10
M = sum(v)+1
dp = [ [0] + [inf]*(M-1) for i in range(N) ]
dp[0][v[0]] = w[0] #最初の行

lim = v[0]+1
for i in range(1, N):
  lim += v[i]
  for val in range(1, lim):
    if val-v[i]>=0:
      dp[i][val] = dp[i-1][val-v[i]] + w[i]
    dp[i][val] = min(dp[i][val], dp[i-1][val])
    
#許されるvの最大値を見つける
for val in reversed(range(M)):
  if dp[N-1][val]<=W:
    print(val)
    break


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N, K; cin >> N >> K;
    vi x(N+1); REP1(i, N) cin >> x[i];

    int ans = 0;
    REP1(i, N)
    {
        ans += 2 * min(abs(x[i]), abs(K-x[i]));
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    solve();

    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int num[] = new int[9];
		int color[] = new int[9];
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		// 回数counter入力
		int counter = scanner.nextInt();

		// カードの配列numとcolorの定義と入力、格納
		for (int trial = 0; trial < counter; trial++) {
			int rednum = 0;
			int greennum = 0;
			int bluenum = 0;

			for (int hand = 0; hand < 9; hand++) {
				num[hand] = scanner.nextInt();
			}
			for (int hand = 0; hand < 9; hand++) {
				String input = scanner.next();
				if ("R".equals(input)) {
					color[hand] = 1;
					rednum++;
				} else if ("G".equals(input)) {
					color[hand] = 2;
					greennum++;
				} else if ("B".equals(input)) {
					color[hand] = 3;
					bluenum++;
				}
			}
			// 色R,G,Bの配列の定義
			int[] red = new int[rednum];
			int[] green = new int[greennum];
			int[] blue = new int[bluenum];
			int redindex = 0;
			int greenindex = 0;
			int blueindex = 0;

			// 色配列にnumの要素を格納
			for (int i = 0; i < 9; i++) {
				if (color[i] == 1) {
					red[redindex] = num[i];
					redindex++;
				} else if (color[i] == 2) {
					green[greenindex] = num[i];
					greenindex++;
				} else if (color[i] == 3) {
					blue[blueindex] = num[i];
					blueindex++;
				}
			}
			// 色配列をソート
			Arrays.sort(red);
			Arrays.sort(green);
			Arrays.sort(blue);

			// カードの合計セット数setcountとcountメソッドの宣言、初期化
			int setcount = 0;
			setcount += count(red);
			setcount += count(green);
			setcount += count(blue);

			// setcountが3なら1、それ以外なら0を出力
			if (setcount == 3) {
				System.out.println(1);
			} else {
				System.out.println(0);
			}
			//System.out.println(setcount);

		}

	}

	public static int count(int a[]) {
		List<Integer> list = new LinkedList<Integer>();
		for (int i = 0; i < a.length; i++) {
			list.add(a[i]);
		}

		int setcounter = 0;
		int listsize = a.length;
		// 総当たりで判定
		for (int i1 = 0; i1 < listsize - 2; i1++) {
			for (int i2 = i1 + 1; i2 < listsize - 1; i2++) {
				for (int i3 = i2 + 1; i3 < listsize; i3++) {
					if (i1 != i2 && i1 != i3 && i2 != i3) {
						if (list.get(i1) + 1 == list.get(i2)
								&& list.get(i1) + 2 == list.get(i3)) {
							list.remove(i3);
							list.remove(i2);
							list.remove(i1);
							setcounter++;
							listsize = list.size();
							i2 = i1 + 1;
							i3 = i2;
						} else if (list.get(i1) == list.get(i2) && list.get(i1) == list.get(i3)) {
							list.remove(i3);
							list.remove(i2);
							list.remove(i1);
							setcounter++;
							listsize = list.size();
							i2 = i1 + 1;
							i3 = i2;
						}
					}
				}
			}
		}
		//for (int s : list) {
		//	System.out.println(s);
		//}
		return setcounter;
	}
}



Measured memory_bytes: 28816
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 1e3+5;

int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n;
	cin >> n;
	int dp[n][3];
	for (int i = 0; i < n; i++)
	{
		int x, y, z;
		cin >> x >> y >> z;
		if (i == 0)
		{
			dp[i][0] = x;
			dp[i][1] = y;
			dp[i][2] = z;
		}
		else
		{
			dp[i][0] = x + max(dp[i-1][1], dp[i-1][2]);
			dp[i][1] = y + max(dp[i-1][0], dp[i-1][2]);
			dp[i][2] = z + max(dp[i-1][0], dp[i-1][1]);
		}
	}
	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main() {
    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int dp[n];
    dp[n-1]=0; 
    for(int i=n-2;i>=0;i--){
        int l=INT_MAX;
        for(int j=i+1;j<=i+k && j<=n-1;j++){
            l=min(l,min(abs(a[j]-a[i])+dp[j],abs(a[j]-a[i])+dp[j]));
        }
        dp[i]=l;
    }
    cout<<dp[0];
}

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

const int N = 2e5 + 10;

int n, m, f[N];

struct edge {
	int u, v, w;
}e[N << 1];

int find(int x) {
	if(f[x] == x) return x;
	return f[x] = find(f[x]);
}

bool cmp(edge a, edge b) {
	return a.w < b.w;
}

int main() {
	scanf("%d%d", &n, &m);
	int cnt = 0;
	for(int i = 1; i <= m; ++i) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		e[++cnt] = (edge) {a, b, 0};
	}
	for(int i = 1; i <= n; ++i) {
		e[++cnt] = (edge) {n + 1, i, 1};
	}
	++n;
	for(int i = 1; i <= n; ++i) f[i] = i;
	int ans = 0;
	sort(e + 1, e + cnt + 1, cmp);
	for(int i = 1; i <= cnt; ++i) {
		int x = find(e[i].u), y = find(e[i].v);
		if(x != y) {
			ans += e[i].w;
			f[y] = x;
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 4992
#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-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b) {if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b) {if(a<b) a=b;}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w; cin >> h >> w;
    vector<string> s(h);
    REP(i,h) cin >> s[i];
    int ans = 0;
    REP(i,h) REP(j,w) {
        if(s[i][j]=='.') ++ ans;
    }
    vector<vector<int>> used(h, vector<int>(w,-1));
    using P = pair<int,int>;
    queue<P> que;
    que.push({0,0});
    used[0][0] = 0;
    while(!que.empty()) {
        P cur = que.front(); que.pop();
        for(int d = 0; d < 4; ++ d) {
            int x = cur.second + dx[d], y = cur.first + dy[d];
            if(x<0 || x>=w || y<0 || y>=h) continue;
            if(used[y][x]!=-1 || s[y][x]=='#') continue;
            used[y][x] = used[cur.first][cur.second]+1;
            que.push({y,x});
        }
    }
    ans -= used[h-1][w-1] + 1;
    cout << (used[h-1][w-1]==-1 ? -1 : ans) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define MM(i, n, m) for (int i = m; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;

/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 * pair<型, 型> 変数名
 * map<型, 型> 変数名  // 連想配列
 * priority_queue<型> 変数名  // 最大値から出てくるヒープ
*/
int main()
{
    string a, b;
    cin >> a >> b;
    if (a < b) {
        cout << "<" << endl;
    } else if(a > b) {
        cout << ">" << endl;
    } else {
        cout << "=" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

int main() {

	int N = 0;
	cin >> N;

	vector<int> X(N, 0);
	double ave = 0.0;

	for (int i = 0; i < N; i++) {
		cin >> X[i];
		ave += (double)X[i];
	}

	ave = ave / (double)N;
	
	int P = round(ave);

	unsigned long long ans = 0.0;
	int val = 0;
	for (int i = 0; i < N; i++) {
		val = P - X[i];
		ans += pow(val, 2);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256