akhauriyash/Code-Regression huggingface dataset:
a_num = int(input())
b_num = int(input())
c_num = int(input())
x = int(input())

count = 0

for a in range(a_num + 1):
	a *= 500
	if a == x:
		count += 1
		continue
    
	for b in range(b_num + 1):
		b *= 100
		if (a + b) == x:
			count+=1
			continue
      
		for c in range(c_num + 1):
			c *= 50
			if (a + b + c) == x:
				count+=1
				continue

print(count)

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll f(ll x) {
  ll ret = 0;
  while (x % 2 == 0) x /= 2, ret++;
  return ret;
}

int main() {
  ll n, m;
  bool flg = true;
  cin >> n >> m;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  rep(i, n) a[i] /= 2;  // a->a'

  ll t = f(a[0]);

  rep(i, n) {
    if (f(a[i]) != t) {
      cout << 0 << endl;
      return 0;
    }
    a[i] >>= t;  // a[i] /=2^t
  }

  m >>= t;

  ll l = 1;
  rep(i, n) l = lcm(l, a[i]);
  if (l > m) {
    cout << 0 << endl;
    return 0;
  }

  m /= l;
  ll ans = (m + 1) / 2;

  cout << (flg ? ans : 0) << endl;
  return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> bool max_self(T & a, const T & b){ 
  return b > a ? a = b, true : false; 
}
template<class T> bool min_self(T & a, const T & b){ 
  return b < a ? a = b, true : false;    
}
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

int H, W, h, w;

int main(){
  FAST_IO
  cin >> H >> W >> h >> w;
  cout << H * W - (h * W + w * H - h * w);
  return 0;
}


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

#define endl '\n'

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

    int a,b; cin >> a >> b;
    if (a < b) for (int i=0; i<b; i++) cout << a;
    else for (int i=0; i<a; i++) cout << b;
    cout << endl;
}

Measured memory_bytes: 256
#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)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;




int main(){
  ll n;
  cin >>n;
  vector<ll> div1,div2;//約数
  
  ll ans=0;
  // n-1の約数を求める．
  for(ll k=2; k*k<= n; k++){
    if((n-1)%k==0 && k*k<=n-1){
      div1.emplace_back(k);
      if (k!=(n-1)/k){
        div1.emplace_back((n-1)/k);
        ans+=2;
      }else{
        ans++;
      }
    }
    
    if(n%k==0){
      div2.emplace_back(k);
      
      if (k!=n/k){
      	div2.emplace_back(n/k);
      }
    }
  }
  if (n>2){
  	div1.emplace_back(n-1);
	ans++;
  }
  
  div2.emplace_back(n);
  
  
  
  for(ll k: div2){
    bool so=false;
    ll n1=n;
    while(!so){
      if(n1%k==0){
        n1 /=k;
      }else{
        so=true;
      }
    }
    if (n1%k==1) ans++;
    
  }
  

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


Measured memory_bytes: 3640
#include <stdio.h>

int main()
{
  int map[10][10] = {};
  int x, y, ren;
  int i, j;
  int max, sum;

  while(scanf("%d,%d,%d", &x, &y, &ren) != EOF)
    {
      map[x][y]++;
      if(y > 0) map[x][y - 1]++;
      if(x > 0) map[x - 1][y]++;
      if(y < 9) map[x][y + 1]++;
      if(x < 9) map[x + 1][y]++;
      if(ren == 1) continue;

      if(x > 0 && y > 0) map[x - 1][y - 1]++;
      if(x > 0 && y < 9) map[x - 1][y + 1]++;
      if(x < 9 && y > 0) map[x + 1][y - 1]++;
      if(x < 9 && y < 9) map[x + 1][y + 1]++;
      if(ren == 2) continue;

      if(y > 1) map[x][y - 2]++;
      if(x > 1) map[x - 2][y]++;
      if(y < 8) map[x][y + 2]++;
      if(x < 8) map[x + 2][y]++;
    }
  

  for(i = 0, sum = 0; i < 10; i++)
    for(j = 0;  j < 10; j++)
      {
	if(map[j][i] == 0)
	  sum++;
	if(map[j][i] > max)
	  max = map[j][i];
      }

  printf("%d\n%d\n", sum, max);

  return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<algorithm>
using namespace std;
int a[3];
int main()
{
	for(int i=0;i<3;i++) cin>>a[i];
	sort(a,a+3);
	if(a[0]+a[1]==a[2]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

using namespace std;

#define ll long long 
#define Coming ios_base :: sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#define mod 1000000007

int main()
{
    Coming
     
    int s;
    
    cin >> s;
    
    map<int,int>m;
    
    m[s]++;
    
    int coun = 1;
    
    while(1)
    {
		if(s%2 == 0)
		{
			s /= 2;
		}
		else 
		{
			s = 3*s + 1;
		}
		
		m[s]++;
		coun++;
		
		if(m[s] == 2) break; 
	}
	
	cout << coun << endl;
    
	return 0;
}


Measured memory_bytes: 256
from collections import Counter

A = list(input())
S = A
MIN = 2000
for t in set(A):
    count = 0
    S = A
    while count <= MIN:
        if len(set(S)) == 1:
            MIN = min(count,MIN)
            break
        T = [None] * (len(S)-1)
        for i in range(len(T)):
            if S[i] == t or S[i+1] == t:
                T[i] = t
            else:
                T[i] = S[i]

        S = T
        count += 1


print(MIN)


Measured memory_bytes: 9276
from itertools import product
h,w,k=map(int,input().split())
f=0
c=[]
for i in range(h):
  tmp=list(input())
  c.append(tmp)
  f+=tmp.count("#")
ans=0
for i in product([0,1],repeat=h):
  for j in product([0,1],repeat=w):
    cnt=0
    for x in range(h):
      for y in range(w):
        if i[x]==1 or j[y]==1:
          if c[x][y]=="#":cnt+=1
    if f-cnt==k:
      ans+=1
print(ans)

Measured memory_bytes: 68192
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    ll n, k; cin>>n>>k;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

    vector<ll> m, p;
    for(int i=0; i<n; i++){
        if(a[i] < 0) m.emplace_back(a[i]);
        else if(a[i] > 0) p.emplace_back(a[i]);
    }

    sort(m.begin(), m.end());
    sort(p.begin(), p.end());

    ll msz = m.size(), psz = p.size();
    ll zero = n - msz - psz;

    ll mcnt = msz * psz;

    if(k <= mcnt){
        // k 番目の数がマイナス
        // (ng, ok]
        ll ng = -INF - 1, ok = -1;
        while(ok - ng > 1){
            ll mid = (ng + ok) / 2;
            ll sum = 0;
            int l = 0;
            for(int r=0; r<psz; r++){
                while(l < msz && m[l] * p[r] <= mid) l++;
                sum += l;
            }

            if(sum < k) ng = mid;
            else ok = mid;
        }

        cout << ok << endl;
        return 0;
    }

    k -= mcnt;
    ll zerocnt = 0;
    for(int i=0; i<zero; i++){
        zerocnt += (n - (i + 1));
    }

    if(k <= zerocnt){
        // k 番目の数が 0
        cout << 0 << endl;
        return 0;
    }

    k -= zerocnt;

    for(int i=0; i<msz; i++) m[i] = -m[i];
    sort(m.begin(), m.end());

    // k 番目の数がプラス
    // (ng, ok]
    ll ng = 0, ok = INF;
    while(ok - ng > 1){
        ll mid = (ng + ok) / 2;
        ll sum = 0;
        for(int i=0; i<psz; i++){
            ll target = mid / p[i];
            ll cnt = (upper_bound(p.begin(), p.end(), target) - p.begin()) - (i + 1);
            sum += max(0LL, cnt);
        }

        for(int i=0; i<msz; i++){
            ll target = mid / m[i];
            ll cnt = (upper_bound(m.begin(), m.end(), target) - m.begin()) - (i + 1);
            sum += max(0LL, cnt);
        }

        if(sum < k) ng = mid;
        else ok = mid;
    }

    cout << ok << endl;

    return 0;
}

Measured memory_bytes: 3956
N = int(input().rstrip())

ac = 0
wa = 0
tle = 0
re = 0
for i in range(N):
  data = input().rstrip()
  if data == 'AC':
    ac += 1
  elif data == 'WA':
    wa += 1
  elif data == 'TLE':
    tle += 1
  elif data == 'RE':
    re += 1

print('AC x ' + str(ac))
print('WA x ' + str(wa))
print('TLE x ' + str(tle))
print('RE x ' + str(re))

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

typedef long long ll;

ll F(ll A, ll B){
    ll cntA=1, cntB=1;
    while(1){
        if(A/10==0) break;
        A /= 10;
        cntA++;
    }
    while(1){
        if(B/10==0) break;
        B /= 10;
        cntB++;
    }
    
    return max(cntA,cntB);
}

int main(){
    ll N;
    cin >> N;
    
    ll mi=100;
    for(ll A=1; A<=sqrt(N); A++){
        if(N%A==0){
            mi = min(mi,F(A,N/A));
        }
    }
    cout << mi << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define PI 3.1415926535897932384626
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define Rep(i, a, b) for (int i=a; i<(b); i++)
#define rep(i, a) for (int i=0; i<(a); i++)
#define Dep(i,a,b) for (int i = (b)-1; i >= a; i--)
#define dep(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for(auto& a : x)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // Random No.

const int MOD = 1000000007;
const char nl = '\n';

void sol() {

    int n ; cin >> n;

    if (n >= 30) {cout << "Yes\n";}
    else {cout <<  "No\n";}

}


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

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("outputA.txt", "w", stdout);
#endif

    int T = 1;
    while (T--) {
        sol();
    }

    return 0;
}



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

bool is_prime(int x) {
  if (x <= 1) {
    return false;
  }

  for (int i = 2; i*i <= x; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

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

  int p = x;
  while (!is_prime(p)) {
    p++;
  }

  cout << p << endl;
  return 0;
}

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

using namespace std;

#define int long long

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()

int N;

int num(int x)
{

    int res = 0;
    int y = x;
    bool c3 = false, c5 = false, c7 = false;
    while (y != 0)
    {
        if (y % 10 == 3)
            c3 = true;
        if (y % 10 == 5)
            c5 = true;
        if (y % 10 == 7)
            c7 = true;

        y /= 10;
    }

    if (c3 && c5 && c7)
    {
        res++;
    }

    if (x * 10 + 3 <= N)
        res += num(x * 10 + 3);
    if (x * 10 + 5 <= N)
        res += num(x * 10 + 5);
    if (x * 10 + 7 <= N)
        res += num(x * 10 + 7);

    return res;
}

signed main()
{

    cin >> N;

    cout << num(0) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define M   1000000007 // 1e9 + 7
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

const int N = 15;
int c[N];
int a[N][N];
int h[N];
int32_t main(){
  fastio;
  int n,m,x;
  cin>>n>>m>>x;
  for(int i=0;i<n;i++){
    cin>>c[i];
    for(int j=0;j<m;j++){
      cin>>a[i][j];
    }
  }



  int best = -1;
  for(int msk = 1;msk<(1<<n);msk++){
    for(int j=0;j<m;j++)h[j]=0;
      int cost=0;
     for(int i=0;i<n;i++){
        if((1LL<<i)&msk){
          cost+=c[i];
          for(int j=0;j<m;j++){
            h[j]+=a[i][j];
          }
        }
     }


     int ok = 1;
     for(int j=0;j<m;j++){
      if(h[j]<x)ok=0;
     } 
     if(ok){
      if(best == -1)best = cost;
      else best = min(best,cost);
     }


  }
  cout << best << endl;
  // Math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ll K;
  cin >> K;
  ll A, B;
  cin >> A >> B;
  for (ll i = A; i <= B; ++i) {
    if (i % K == 0) {
      cout << "OK" << "\n";
      return 0;
    }
  }
  cout << "NG" << "\n";
}


Measured memory_bytes: 3568
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
Q = [-A[i] for i in range(N)]
heapq.heapify(Q)

for i in range(M):
    Q_max = heapq.heappop(Q)
    Q_max = -(-Q_max//2)
    heapq.heappush(Q, Q_max)

print(-sum(Q))


Measured memory_bytes: 14204
import math

N = int(input())
A, B = [], []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


ans = 0

for a, b in zip(A[::-1], B[::-1]):
    a += ans
    ans += math.ceil(a / b) * b - a

print(ans)

Measured memory_bytes: 12644
n, y = map(int, input().split())

f = False
for i in range(n, -1, -1):
    if f:
        break
    for j in range(n-i, -1, -1):
        if f:
            break
        if (n - i - j >= 0) & (10000 * i + 5000 * j + 1000 * (n - i - j) == y):
            print(i, j, (n - i - j))
            f = True

if f is False:
    print(-1, -1, -1)


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

#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define T() int tt; cin >> tt; rep1(qq,1,tt)
#define rep(i,start,lim) for(int i=start;i<lim;i++)
#define rep1(i,start,lim) for(int i=start; i<=lim; ++i)
#define repd(i,start,lim) for(int i=start;i>=lim;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define br cout<<"\n"
#define MOD (1000000007LL)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define eps (1e-6)
#define what_is(x) cerr << #x << " is " << x << "\n";
#define int long long int
#define infll 9e18
#define inf 1e12

#define lnode (2 * node + 1)
#define rnode (2 * node + 2)

using namespace std;

typedef pair<int, int> pii;

const int N = 300005;

int x;

int32_t main(){

  FIO
  //cout << fixed << setprecision(10);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  cin >> x;
  int res = 0;
  res += 1000 * (x / 500);
  x %= 500;
  res += 5 * (x / 5);
  cout << res << '\n';



	return 0;
}




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

int main(void){
    int N,ans=0;
    cin>>N;

    for(int i=1;i<=N;i++){
        int a=i;
        if(N>=i*i)
            ans=i*i;
        else if(N<i*i)
            break;
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
K,X=map(int,input().split())
smallest=X-(K-1)
biggest=X+(K-1)

if smallest<-100000:

    biggest+=smallest+100000
    smallest=-100000

elif biggest>100000:
    smallest+=biggest-100000
    biggest=100000



nums=[i for i in range(smallest,biggest+1)]




ans=str("")
for n in nums:
    ans+=str(n)+" "
print(ans)


Measured memory_bytes: 3060
n = int(input())
a = list(input().split())
b = [0]*n
ans = ""
if(n%2 == 0) :
  for i in range(n//2) :
    b[n//2+i] = a[2*i]
    b[n//2-(i+1)] = a[2*i+1]
else :
  b[n//2] = a[0]
  for i in range(n//2) :
    b[n//2+i+1] = a[2*i+1]
    b[n//2-(i+1)] = a[2*i+2]

print(' '.join(map(str, b)))

Measured memory_bytes: 27328
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 2048;

int N, K;
int b[2][MAX][MAX];

int calc(int i, int x, int y) {
	return b[i][x][y] + b[!i][x+K][y] + b[!i][x][y+K] + b[i][x+K][y+K];
}

void solve(void){

	cin >> N >> K;
	rep(N, i) {
		int x, y; char c;
		cin >> x >> y >> c;
		bool isblack = c == 'B';
		x %= 2*K;
		y %= 2*K;
		if (x >= K) {
			x -= K;
			isblack = !isblack;
		}
		if (y >= K) {
			y -= K;
			isblack = !isblack;
		}
		b[isblack][y][x]++;
		b[isblack][y+K][x]--;
		b[isblack][y][x+K]--;
		b[isblack][y+K][x+K]++;
	}
	rep(2, x) rep(2*K, i) rep(2*K, j) {
		b[x][i][j+1] += b[x][i][j];
	}
	rep(2, x) rep(2*K, j) rep(2*K, i) {
		b[x][i+1][j] += b[x][i][j];
	}
	int ans = 0;
	rep(2, x) rep(K, i) rep(K, j) {
		ans = max(ans, calc(x, i, j));
	}
	cout << ans << endl;
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 33024
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdlib>
#include<cstdio>
#include<utility>
#include<list>
using namespace std;
int main(){
	int n,K; cin>>n>>K;
	int x[n]; for(int i=0;i<n;i++)x[i]=0;
	for(int i=0;i<n;i++)cin>>x[i];
	int dis=0;

	for(int i=0;i<n;i++){
		int disa = x[i], disb = K - x[i];
		if(disa < disb){
			dis += 2*disa;
		}
		else{
			dis += 2*disb;
		}
	}

	cout<< dis <<endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String args[]){	
		Scanner scan = new Scanner(System.in);

		int m, n;
		
		n = scan.nextInt();
		String[] c ={"S", "H", "C", "D"}; 
		
		int a[][];
		a = new int[4][13];
		
		for(int i = 0;i < n;i++){
			String s = scan.next();
			m = scan.nextInt();
			
			for(int j = 0; j < 4; j++) {
				if(c[j].equals(s)) a[j][m - 1] = 1;
			}
		}
			
		for(int i = 0;i < 4;i++){
			for(int j = 0; j < 13;j++){
				if(a[i][j] == 0){
					System.out.println(c[i] + " " + (j + 1));
				}
			}
		}
	}	
}

Measured memory_bytes: 26136
class Dice
	attr_reader :top, :right, :front

  def initialize(ary)
    @top, @front, @right, @left, @back, @bottom = ary
  end

  def roll(way)
    case way.downcase
    when 'e'
      tmp = @top
      @top = @left
			@left = @bottom
			@bottom = @right
			@right = tmp
    when 'w'
			tmp = @top
			@top = @right
			@right = @bottom
			@bottom = @left
			@left = tmp
    when 's'
			tmp = @top
			@top = @back
			@back = @bottom
			@bottom = @front
			@front = tmp
    when 'n'
			tmp = @top
			@top = @front
			@front = @bottom
			@bottom = @back
			@back = tmp
    end
  end
end

dice = Dice.new(gets.chomp.split(/\s/).map(&:to_i))
q = gets.chomp.to_i
q.times do
  top, front = gets.chomp.split(/\s/).map(&:to_i)
  way = ['N', 'E', 'S', 'W']
  loop do
    dice.roll(way.sample)
		if dice.top == top && dice.front == front
      puts dice.right
			break
		end
  end
end

Measured memory_bytes: 8752
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#define Maxn 100000;
using namespace std;
int n,k,d,x,a,ans = 0;
int main()
{
    cin>>n;
    cin>>d>>x;
    while(n--)
    {
        cin>>a;
        k = 0;
        for (int i = 1; i <= d; i+=a)
            k++;
        ans += k;
    }
    cout<<ans+x<<endl;
    return 0;
}

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

int coin[6] = {1,5,10,50,100,500};

int main() {

    int c,ans=0;

    for(int i=0;i<6;i++){
        cin >> c;
        ans += c*coin[i];
    }

    ans = ans>=1000 ? 1 : 0;

    cout << ans << endl;

    return 0;
}

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

int main(){
  int n,count=0;
  cin>>n;
  vector<int> num(n),base(n);
  for(int i=0;i<n;i++){
    cin>>num[i];
    base[i]=num[i];
  }
  sort(num.begin(),num.end());
  for(int i=0;i<n;i++){
    if(num[i]!=base[i]) count++;
  }
  if(count<3)cout<<"YES";
  else cout<<"NO";
  cout<<endl;
}


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

int main(){
    while(1){
        long long int n;
        cin >> n;
        if(n == 0) break;
        long long int ans = n*n*n;
        for(long long int i=1; i*i*i<n*n*n; i++){
            for(long long int j=i; i*i*i+j*j*j<n*n*n; j++){
                ans = min(ans, n*n*n -i*i*i -j*j*j);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


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

int main(void){
  string S;
  cin >> S;
  bool n = false;
  bool w = false;
  bool s = false;
  bool e = false;
  for(int i = 0; i < S.length(); i++){
    if(S[i] == 'N') n = true;
    if(S[i] == 'W') w = true;
    if(S[i] == 'S') s = true;
    if(S[i] == 'E') e = true;
  }
  if(n == s && w == e) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main()
{
	int i,j,k,n;
	string tab[110];
	cin>>n>>k;
	for (i=1;i<=n;i++)
	{
		cin>>tab[i];
	}
	sort(tab+1,tab+n+1);
	string ans;
	ans="";
	for (i=1;i<=n;i++)
	 ans+=tab[i];
	cout<<ans<<"\n";
}

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

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

//つよいせぐつりー！(RUQ+RAQ) ばぐってるかも
struct LazySegTree { //参照は + sz - 1;
	ll sz;
	vector<ll> node, lazy;
	vector<bool> lazyFlag;
	LazySegTree(ll n) {
		sz = 1;
		while (sz < n) sz *= 2;
		node.resize(2 * sz - 1);//
		lazy.resize(2 * sz - 1);//
		lazyFlag.resize(2 * sz);
	}
	void eval(ll k, ll l, ll r) {
		if (lazyFlag[k]) {
			node[k] = lazy[k];//
			if (r - l > 1) {
				lazy[2 * k + 1] = lazy[k] / 2;//
				lazy[2 * k + 2] = lazy[k] / 2;//
				lazyFlag[2 * k + 1] = lazyFlag[2 * k + 2] = true;
			}
			lazyFlag[k] = false;
			lazy[k] = 0;//
		}
		else {
			if (lazy[k] == 0)return;
			node[k] += lazy[k];//
			if (r - l > 1) {
				lazy[2 * k + 1] += lazy[k] / 2;//
				lazy[2 * k + 2] += lazy[k] / 2;//
			}
			lazy[k] = 0;//
		}
	}
	void add(ll a, ll b, ll x, ll k = 0, ll l = 0, ll r = -1) {
		if (r < 0) r = sz;
		eval(k, l, r);
		if (b <= l || r <= a) return;
		if (a <= l && r <= b) {
			lazy[k] += (r - l) * x;//
			eval(k, l, r);

		}
		else {
			add(a, b, x, 2 * k + 1, l, (l + r) / 2);
			add(a, b, x, 2 * k + 2, (l + r) / 2, r);
			node[k] = node[2 * k + 1] + node[2 * k + 2];//
		}
	}
	void update(ll a, ll b, ll x, ll k = 0, ll l = 0, ll r = -1) {
		if (r < 0) r = sz;
		eval(k, l, r);
		if (b <= l || r <= a) return;
		if (a <= l && r <= b) {
			lazy[k] = x;//	
			lazyFlag[k] = true;
			eval(k, l, r);

		}
		else {
			update(a, b, 2 * k + 1, l, (l + r) / 2);
			update(a, b, 2 * k + 2, (l + r) / 2, r);
			node[k] = node[2 * k + 1] + node[2 * k + 2];//
		}
	}
	void update(ll a, ll x) {
		update(a, a + 1, x);
	}
	ll query(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {
		if (r < 0) r = sz;
		eval(k, l, r);
		if (b <= l || r <= a) return 0;//
		if (a <= l && r <= b) return node[k];
		ll vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
		ll vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
		return vl + vr;//
	}
	void init() {
		REPR(i, sz - 2) node[i] = node[2 * i + 1] + node[2 * i + 2];//
	}
};

int main() {
    ll n, q;
    cin >> n >> q;
    LazySegTree seg(n);
    REP(i, q){
        ll t;
        cin >> t;
        if(t == 0){
            ll a, b, c;
            cin >> a >> b >> c;
            seg.add(a - 1, b, c);
        }
        else{
            ll a, b;
            cin >> a >> b;
            cout << seg.query(a - 1, b) << endl;
        }
    }
}


Measured memory_bytes: 7048
#1+2+2+2=7
K=input()
keta=len(K)
#print(K,keta)

for i in range(1<<(keta-1)):#探索数
  ANS=K[0]
  for j in range(keta-1):#調査桁数
    if (i>>j) &1 == 1:#bitがある、つまりプラスが入る場合
      ANS+="+"
    else:
      ANS+="-"
    ANS+=K[j+1]
#  print(ANS)
  if eval(ANS)==7:
    print(ANS+"=7")
    break
  

Measured memory_bytes: 38384
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect
INF = 10**18
def judge(li_tate,li_yoko,li2):
    for i in range(len(li_tate)):
        if li_tate[i]:
            for j in range(len(li2[i])):
                li2[i][j] = "red"
    for i in range(len(li_yoko)):
        if li_yoko[i]:
            for j in range(h):
                li2[j][i] = "red"
    cnt = 0
    for i in range(len(li_tate)):
        for j in range(len(li_yoko)):
            if li2[i][j] == "#":
                cnt+=1
    return cnt


if __name__ == "__main__":
    h,w,k = map(int,input().split())
    li = []
    for i in range(h):
        s = list(input())
        li.append(s)
    
    ans = 0
    for i in range(2**h):
        li_tate = [False]*(h)
        for j in range(h):
            if (i>>j)&1:
                li_tate[h-j-1] = True
        for j in range(2**w):
            li_yoko = [False]*(w)
            for l in range(w):
                if (j>>l)&1:
                    li_yoko[w-l-1] = True
            li2 = copy.deepcopy(li)
            a = judge(li_tate,li_yoko,li2)
            if a == k:
                ans += 1
    print(ans)

Measured memory_bytes: 9616
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main(){
    int a, b;
    cin >> a >> b;
    int s = 0;
    if(a >= b) {
        s+= a;
        a--;
    }
    else{
        s += b;
        b--;
    }
    cout << s + max(a, b);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin >> a;
  char s[a+1];
  cin >> s;
  if(a%2==1){
    cout << "No" << endl;
    return 0;
  }
  int b=a/2;
  for(int i=0;i<b;i++){
    if(s[i]!=s[i+b]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = input()
T = input()
ans = 0
for i in range(3):
	if S[i] == T[i]:
		ans += 1
print(ans)

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

int main() {
    int a, b, c; cin >> a >> b >> c;
    printf("%d %d %d\n", c, a, b);
    
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N,0);
  for(int i=0; i<N-1; i++){
    int A;
    cin >> A;
    vec.at(A-1)++;
  }
  
  for(int i=0; i<N; i++){
    cout << vec.at(i) << endl;
  }
}

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

int main(){
    // あとで消す
    //std::ifstream in("ain3.txt");
    //std::cin.rdbuf(in.rdbuf());

    string S,T;
    cin >> S >> T;

    int counter=0;

    if(S[0]==T[0])
        counter++;
    if(S[1]==T[1])
        counter++;
    if(S[2]==T[2])
        counter++;

    cout << counter << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int32_t main()
{
    ios::sync_with_stdio(0);
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    if (a[0] != 5 || a[1] != 5 || a[2] != 7)
        cout << "NO\n";
    else
        cout << "YES\n";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int solve(int, int *, int, int);

int main(){

  int i, j, n1, n2;

  scanf("%d", &n1);

  int A[n1];

  for(i=0;i<n1;i++) scanf("%d", &A[i]);

  scanf("%d", &n2);

  int B[n2];

  for(i=0;i<n2;i++) scanf("%d", &B[i]);

  for(i=0;i<n2;i++){

    if(solve(n1, A, 0, B[i])) printf("yes\n");

    else printf("no\n");

  }

  return 0;

}

int solve(int n, int A[], int i, int m){

  int res;

  if(m==0) return 1;

  if(i==n) return 0;

  res=(solve(n, A, i+1, m) || solve(n, A, i+1, m-A[i]));

  return res;

}



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

int main() {
  int D;
  cin >> D;
  if (D == 25) cout << "Christmas" << endl;
  else if (D == 24) cout << "Christmas Eve" << endl;
  else if (D == 23) cout << "Christmas Eve Eve" << endl;
  else if (D == 22) cout << "Christmas Eve Eve Eve" << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#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 ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int N, K;
    cin >> N >> K;

    vi s(N, 0);
    REP(i, K) {
        int d;
        cin >> d;
        REP(j, d) {
            int a;
            cin >> a;
            a--;
            s[a]++;
        }
    }

    int ans = 0;
    for (auto x : s) {
        if (x == 0) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3660
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
const int M = 100005 ;
using namespace std ;

int n ;
int v[M] , tmin = M , tmax ;
int l[M] , r[M] ;
int Num , tot ;
int main() {
    scanf("%d",&n) ;
    for(int i = 1 ; i <= n ; i ++) {
        scanf("%d",&v[i]) ;
        tmin = min(tmin , v[i]) ;
        tmax = max(tmax , v[i]) ;
    }
    if(tmin < tmax - 1) { printf("No\n") ; return 0 ; }
    sort(v + 1 , v + n + 1) ;
    for(int i = 1 ; i <= n ; i ++)
        if(v[i] == tmin)
            ++Num ;
//  有num个只出现一次
    if(tmax == tmin) {
	    if((tmin == n - 1 || tmin * 2 <= n)) printf("Yes\n") ;
        else printf("No\n") ;
	}
	else if(tmin >= Num && tmax <= Num + (n - Num) / 2) printf("Yes\n") ;
    else printf("No\n") ;
    return 0 ;	
}

Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<math.h>
#include<set>
using namespace std;
int a[105][105];
int b[10005];
int k,h,w;
void paint(int i,int j,int bb)
{
	if(i>h)
		return;
	
	
	if(b[k]>0)
	{
	a[i][j] = k;
	b[k]--;
	}
	else
	{ 
		k++;
	 a[i][j] = k;
	 b[k]--;
	
	}
	if(bb == 1)
	{
     if(j>=w)
		paint(i+1,w,0);
	 else
		 paint(i,j+1,1);
	}
	else
	{
		if(j<=1)
		paint(i+1,1,1);
		else
			paint(i,j-1,0);
	
	}
	
}
int main()
{
	int t,i,j;
	while(~scanf("%d%d",&h,&w))
	{
		scanf("%d",&t);
	  for(i = 1;i<=t;i++)
	  {
	    scanf("%d",&b[i]);
	  }
	  
	  
	  k = 1;
	  
	  paint(1,1,1);
	 
	  for(i = 1;i<=h;i++)
	  {
		  for(j = 1;j<=w;j++)
		  {
		    if(j==w)
				printf("%d\n",a[i][j]);
			else
				printf("%d ",a[i][j]);
		  }
	  }
	}
	
  
  
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";

string vow = "aeiou";
const ld pie = 3.14159265358979 ;

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};
const ll mod = 1e9 + 7 ;

vvi g ;
vb vis ;
vi v , ans ;

void dfs ( int node , int cost )
{
    vis[node] = true ;
    ans[node] += v[node] + cost ;

    cost = ans[node] ;
    for ( auto j : g[node] )
    {
        if ( !vis[j] )
            dfs ( j , cost ) ;
    }
}

void solve ( int test_case )
{
    int n , q ;
    cin >> n >> q ;

    g.resize ( n ) ;
    vis.resize ( n ) ;
    v.resize ( n ) ;
    ans.resize ( n ) ;

    for ( int i=0 ; i < n-1 ; i++ )
    {
        int a , b ;
        cin >> a >> b ;

        a-- ; b-- ;
        g[a].pb ( b ) ;
        g[b].pb ( a ) ;
    }

    while ( q-- )
    {
        int u , val ;
        cin >> u >> val ;

        u-- ;

        v[u] += val ;
    }

    dfs ( 0 , 0 ) ;
    for ( auto i : ans ) cout << i << " " ;

}

int main()
{fast
    int t = 1;
    //cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 24320
#include <stdio.h>
int main(void){
  int n,f=1,i,st=0;
  char s[5];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",s);
    if(s[0]=='A')
      st++;
    else if(st)
      st--;
    else
      f=0;
  }
  if(f&&st==0)
    puts("YES");
  else
    puts("NO");
  return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

ll mod = 1e9+7;
  
// 検索タグ
int main() {
	// 入力
	double L;cin>>L;
	
	// 解法
	double ans = pow(L/3, 3);
	
	//出力
	printf("%.16f\n", ans);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f;
const int maxn=505;
int n,m,ans=inf,a[maxn][maxn],p[maxn],d[maxn],vis[maxn];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>a[i][j];
		}
	}
	for(int i=1;i<=n;i++)
	{
		p[i]=1;
		d[a[i][1]]++;
	}
	for(int i=1;i<=m;i++)
	{
		int nd=0;
		for(int j=1;j<=m;j++)
		{
			if(!vis[j])
			{
				if(d[j]>d[nd])
				{
					nd=j;
				}
			}
		}
		ans=min(ans,d[nd]);
		vis[nd]=1;
		for(int j=1;j<=n;j++)
		{
			d[a[j][p[j]]]--;
			while(vis[a[j][p[j]]])
			{
				p[j]++;
			}
			d[a[j][p[j]]]++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 896
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

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

ll beki(ll a, ll b) {
	ll tmp = 1;
	REP(i, b) tmp *= a;
	return tmp;
}

int r;

int main() {
	cin >> r;
	cout << 3 * r * r << endl;
}

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

int N;
int G[101][101];
int visited[101];

int start[101], complete[101];

int dfs(int v, int t) {
    visited[v] = 1;
    start[v] = t;
    int nt = t+1;
    for (int j = 0; j <= N; ++j) {
        if (!visited[j] && G[v][j]) {
            nt = dfs(j, nt);
        }
    }
    complete[v] = nt;
    return nt+1;
}

int main() {
    cin >> N;
    for (int j = 0; j <= N; ++j) for (int k = 0; k <= N; ++k) G[j][k] = 0;
    for (int j = 0; j <= N; ++j) visited[j] = 0;
    for (int _ = 0; _ < N; ++_) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; ++j) {
            int v; cin >> v;
            G[u][v] = 1;
        }
    }

    int tt = 1;
    for (int j = 1; j <= N; ++j) {
        if (!visited[j]) tt = dfs(j, tt);
    }

    for (int j = 1; j <= N; ++j) {
        cout << j << " " << start[j] << " " << complete[j] << endl;
    }

    return 0;
}

Measured memory_bytes: 3132
import java.util.Arrays

const val MOD: Long = (1e9+7).toLong()

fun main(args: Array<String>) {
    val (sx, sy, tx, ty) = readLine()!!.split(" ").map{it.toInt()}

    var yd = if (ty > sy) listOf('U', 'D') else listOf('D', 'U')
    var xd = if (tx > sx) listOf('R', 'L') else listOf('L', 'R')

    for (i in 1..Math.abs(tx-sx)) {
        print(xd[0])
    }
    for (i in 1..Math.abs(ty-sy)) {
        print(yd[0])
    }
    for (i in 1..Math.abs(tx-sx)) {
        print(xd[1])
    }
    for (i in 1..Math.abs(ty-sy)) {
        print(yd[1])
    }
    print(yd[1])
    for (i in 1..Math.abs(tx-sx)+1) {
        print(xd[0])
    }
    for (i in 1..Math.abs(ty-sy)+1) {
        print(yd[0])
    }
    print(xd[1])
    print(yd[0])
    for (i in 1..Math.abs(tx-sx)+1) {
        print(xd[1])
    }
    for (i in 1..Math.abs(ty-sy)+1) {
        print(yd[1])
    }
    println(xd[0])
}


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

void Main() {
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  sort(a.begin(), a.end());
  vector<int> dp(K + 1, 0);
  for (int i = 1; i <= K; ++i) rep(j, N) if (i >= a[j]) dp[i] |= !dp[i - a[j]];
  cout << ( dp[K] ? "First" : "Second" ) << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int q[4]={0,1,-1,0};
int w[4]={1,0,0,-1};
int main(){
  ll n;
  cin>>n;
  vll a(n);
  ll ans=0;
  ans-=n;
  rep(i,n){
    cin>>a[i];
    ans+=a[i];
  }
  COUT(ans);
}


Measured memory_bytes: 256
S = input()

from collections import defaultdict
def unbalance(S):
    D = defaultdict(lambda:0)
    for s in S:
        D[s] += 1
    if max(D.values()) > len(S)//2:
        return True
    else:
        return False

lenS =len(S)
for i in range(lenS-1):
    if unbalance(S[i:i+2]):
        print(f'{i+1} {i+2}'); break
    if i < lenS-2 and unbalance(S[i:i+3]):
        print(f'{i+1} {i+3}'); break
else:
    print('-1 -1')

Measured memory_bytes: 9448
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 5000 + 100;
const int MAXM = 200 + 10;
const long long INF = 0x1f1f1f1f1f1f1f1fll;

int n, m;
long long a[MAXN];
int b[MAXM][MAXN];
long long s[MAXN][MAXN];

void add(int x1, int x2, int y1, int y2, int v)
{
	// cerr << x1 << ' ' << x2 << ' ' << y1 << ' ' << y2 << ' ' << v << endl;
	s[x1][y1] += v;
	s[x1][y2 + 1] -= v;
	s[x2 + 1][y1] -= v;
	s[x2 + 1][y2 + 1] += v;
}

void calc_s()
{
	for(int i = 1; i <= n; i++)
		s[i][0] += s[i - 1][0];
	for(int j = 1; j <= n; j++)
		s[0][j] += s[0][j - 1];
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + s[i][j];
}

void calc(int *b)
{
	static int lef[MAXN], rig[MAXN];
	stack<int> sta1, sta2;
	for(int i = 1; i <= n; i++)
	{
		while(!sta1.empty() && b[sta1.top()] <= b[i])
			sta1.pop();
		lef[i] = sta1.empty() ? 0 : sta1.top();
		sta1.push(i);
	}
	for(int i = n; i >= 1; i--)
	{
		while(!sta2.empty() && b[sta2.top()] < b[i])
			sta2.pop();
		rig[i] = sta2.empty() ? n + 1 : sta2.top();
		sta2.push(i);
	}
	for(int i = 1; i <= n; i++)
		add(lef[i] + 1, i, i, rig[i] - 1, b[i]);
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n >> m;
	for(int i = 1; i <= n - 1; i++)
		cin >> a[i], a[i] += a[i - 1];
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			cin >> b[j][i];
	for(int i = 1; i <= m; i++)
		calc(b[i]);
	calc_s();
	// for(int i = 1; i <= n; i++)
	// {
	// 	for(int j = i; j <= n; j++)
	// 		cerr << s[i][j] << ' ';
	// 	cerr << endl;
	// }
	long long ans = -INF;
	for(int i = 1; i <= n; i++)
		for(int j = i; j <= n; j++)
			ans = max(ans, s[i][j] - (a[j - 1] - a[i - 1]));
	cout << ans << endl;


	return 0;
}


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

using namespace std;
int main(void){
    // Your code here!
    int N;
    map <string,int> buffer;
    
    cin >> N;
    
    for(int i = 0 ; i < N; i++){
        string tmp;
        cin >> tmp;
        
        buffer[tmp]++;
        
    }
    
    int maxValue = 0;
    // 上の時点でbuffer内は、文字列(key)で文字がソートされている
    // 最大値を取り出す
    for (const auto localMap : buffer){
        if(localMap.second > maxValue){
            maxValue = localMap.second;
        }
    }
    
    for (const auto localMap : buffer){
        if(maxValue == localMap.second){
            cout << localMap.first << endl;
        }
    }

}


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

int main(){
	char ar[105];
	cin >> ar;
	int l = strlen(ar);
	int i,j,count=0;

	if(l%2!=0)
	{
		for(i=(l/2)+1,j=(l/2)-1; i<=l-1,j>=0; i++,j--)
		{
			if(ar[i] != ar[j])
			{
				count++;
			}
		}
	}
	else
	{
		for(i=l/2,j=(l/2)-1; i<=l-1,j>=0; i++,j--)
		{
			if(ar[i] != ar[j])
			{
				count++;
			}
		}
	}
	cout<< count << endl;


	return 0;
}

Measured memory_bytes: 256
from collections import deque

H, W = map(int, input().split())
C_h, C_w = map(int, input().split())
D_h, D_w = map(int, input().split())

S = [input() for _ in range(H)]
dist = [[float("inf") for i in range(W)] for j in range(H)]
dist[C_h-1][C_w-1] = 0

d = deque([[C_h-1, C_w-1, 0]])

def check_movable(h, w):
    if h < 0 or h >= H or w < 0 or w >= W:
        return False
    if S[h][w] == "#":
        return False
    else:
        return True

def check_appnendable(h, w, cost):
    if not check_movable(h,w):
        return False
    if dist[h][w] > cost:
        return True
    else:
        return False

dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
while d:
    h, w, cost = d.pop()
    for dh, dw in zip(dx, dy):
        if check_appnendable(h+dh, w+dw, cost):
            d.append([h+dh, w+dw, cost])
            dist[h+dh][w+dw] = cost
    for dh in range(-2, 3):
        for dw in range(-2, 3):
            if check_appnendable(h+dh, w+dw, cost+1):
                d.appendleft([h+dh, w+dw, cost+1])
                dist[h+dh][w+dw] =cost+1

if dist[D_h-1][D_w-1] < float("inf"):
    print(dist[D_h-1][D_w-1])
else:
    print(-1)

Measured memory_bytes: 117116
import collections
n=int(input())
A=[int(i) for i in input().split()]
a=collections.Counter(A).most_common()[0][0]
AA=[i for i, x in enumerate(A) if x==a]
a1,a2,d=AA[0],AA[1],AA[1]-AA[0]

mod=10**9+7
n_max=2*10**5
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
  FI[i+1]=pow(F[i+1],mod-2,mod)
def comb(x,y):
  return (F[x]*FI[x-y]*FI[y])%mod

for i in range(n+1):
  ans=comb(n+1,i+1)%mod
  if 0<=i<=a1+n-a2:
    ans-=comb(a1+n-a2,i)
  print(ans%mod)



Measured memory_bytes: 24864