akhauriyash/Code-Regression huggingface dataset:
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n,k;
    cin>>n>>k;
    vi v(n+1);
    rep(i,1,n) cin>>v[i];
    ll pre[101][N];
    ll dp[101][N];
    rep(i,0,k) pre[0][i]=1;
    // dp[0][0]=1;
    rep(i,1,n){
        rep(j,0,k){
            dp[i][j]=(pre[i-1][j]-(j-v[i]-1>=0?pre[i-1][j-v[i]-1]:0)+hell)%hell;
            pre[i][j]=dp[i][j]+(j?pre[i][j-1]:0);
        }
    }
    cout<<dp[n][k];
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 158080
(defn abs [x]
  (if (neg? x)
    (- x)
    x))

(-> (loop [lines (map #(clojure.string/split % #"\s")
                      (rest (line-seq (clojure.java.io/reader *in*))))
           [curr-t curr-x curr-y] [0 0 0]]
      (if-let [line (first lines)]
        (let [[t x y :as next-dest] (map #(Integer/parseInt %) line)
              d-t (- t curr-t)
              d-x (abs (- x curr-x))
              d-y (abs (- y curr-y))
              d-x+y (+ d-x d-y)]
          (if (zero? (mod d-t d-x+y))
            (recur (rest lines) next-dest)
            false))
        true))
    (if "Yes" "No")
    println)


Measured memory_bytes: 119552
N, K = map(int, input().split())
h = [0]
h[1:] = list(map(int, input().split()))
inf = 1 << 60
dp = [inf] * (N + 1)
dp[0] = 0
dp[1] = 0
for i in range(2, N + 1):
    for k in range(1, min(i, K + 1)):
        dp[i] = min(dp[i], dp[i - k] + abs(h[i - k] - h[i]))

print(dp[N])


Measured memory_bytes: 53216
#include<iostream>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<string>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<set>
#include<queue>
#include<cmath>

using namespace std;
#define LL long long

int Q,ispr[111111]={};

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

void solve(){
	for(int i=1;i*4+1<100000;i++)
		if(isprime(i*4+1)&&isprime(i*2+1))ispr[i*4+1]++;
	ispr[3]++;
	for(int i=1;i<100000;i++)ispr[i]+=ispr[i-1];

	return;
}

int main() {
	solve();
	cin>>Q;
	for(int i=0;i<Q;i++){
		int r,l;
		cin>>l>>r;
		cout<<ispr[r]-ispr[l-1]<<endl;
	}

	return 0;
}



Measured memory_bytes: 1024
function Main(input) {
    var input = input.split('\n');
    var n = parseInt(input[0]);
    var Int = input[1].split(' ').map(n =>parseInt(n));
    var count = 0;
    function hoge(arr) {
        return arr.every(x => x % 2 === 0);
    }
    while(hoge(Int)) {
        count++;
        Int = Int.map((n) => {return n/2});
    }
    console.log(count);
    }
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
#include <iostream>
#include <algorithm>
using namespace std;
 
bool judge(string x){
    string y;
    y = x;
    reverse(x.begin(), x.end());
    if(x == y){
        return true;
    }
    else{
        return false;
    }
}
 
int main(){
 
    string S, S_1, S_2;
    cin >> S;
 
    int div_1, div_2;
    div_1 = (S.size() - 1) / 2;
    div_2 = (S.size() + 1) / 2;
 
    S_1 = S.substr(0, div_1);
    S_2 = S.substr(div_2);
    
 
    if(judge(S) && judge(S_1) && judge(S_2)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
 
    return 0;
}

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

int main(){
    /*input*/
    char n[4];
    rep(i, 4)	cin >> n[i];
    /*calculation*/
    bool ok = false;	//true:Yes false:No
    if(n[0] == n[1] && n[0] == n[2])ok = true;
    if(n[1] == n[2] && n[1] == n[3])ok = true;
    /*output*/
    if(ok){
	cout << "Yes" << endl;
    }else{
	cout << "No" << endl;
    }
}


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

/**
 * @author Azuz
 * 
 */
public class Main {

    void solve(Scanner in, PrintWriter out) {
      int X = in.nextInt();
      System.out.println(X >= 30 ? "Yes" : "No");
    }

    public static void main(String[] args) {
        try(Scanner in = new Scanner(System.in);
            PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
        }
    }
}


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

using namespace std;

#define int long long

const int   N   = 102;
const int   mod = 1e9 + 7;

void add(int &a,int b)  {
    a += b;
    if(a >= mod)a -= mod;
    if(a < 0)   a += mod;
}

int qpow(int a,int exp) {
    int ans = 1;
    while (exp) {
        if(exp & 1) ans = ans * a % mod;
        a = a * a % mod;  exp >>= 1;
    }
    return ans;
}

int f[N][N * N];

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

    int n, k;   cin >> n >> k;

    f[n + 1][0] = 1;

    int lim = 0;

    for(int i = n ; i >= 1 ; --i)   {
        for(int p = 0 ; p <= lim ; ++p)
            for(int j = 0 ; j <= k ; ++j)   {
                if(j > i)   add(f[i][p],f[i + 1][p]);
                else        add(f[i][p + (j + p) / i],f[i + 1][p]);
            }
        lim = lim + lim / i + 1;
        while(!f[i][lim])   --lim;
    }

    int ans = qpow(k + 1,n - 1) * k * (k + 1) * n / 2;
        ans %= mod;

    for(int p = 0 ; p <= lim ; ++p)
        add(ans,-p * f[1][p] % mod);

    cout << (ans + mod) % mod << endl;
}


Measured memory_bytes: 6656
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <utility>
using namespace std;
#define REP(I,N) for (I=0;I<N;I++)
#define rREP(I,N) for (I=N-1;I>=0;I--)
#define rep(I,S,N) for (I=S;I<N;I++)
#define rrep(I,S,N) for (I=N-1;I>=S;I--)
#define FOR(I,S,N) for (I=S;I<=N;I++)
#define rFOR(I,S,N) for (I=N;I>=S;I--)
typedef unsigned long long ull;
typedef long long ll;
//const int INF=0x3f3f3f3f;
const int INF=1e9;
const ll INFF=0x3f3f3f3f3f3f3f3fll;
const ll M=1e9+7;
const ll maxn=1e5+7;
const int MAXN=1005;
const int MAX=1e5+5;
const int MAX_N=MAX;
const ll MOD=1e9+7;
//const double eps=0.00000001;
//ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
inline ll powMM(ll a,ll b){
    ll ret=1;
    a%=M;
//    b%=M;
    while (b){
        if (b&1) ret=ret*a%M;
        b>>=1;
        a=a*a%M;
    }
    return ret;
}
int h,w,n,a[MAX];
int an[105][105];
int main()
{
    scanf("%d%d%d",&h,&w,&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int cnt=0,now=1;
    for(int i=1;i<=h;i++)
    {
        if(i%2)
        {
            for(int j=1;j<=w;j++)
            {
                an[i][j]=now;
                ++cnt;
                if(cnt>=a[now])
                {
                    now++;cnt=0;
                }
            }
        }
        else
        {
            for(int j=w;j>=1;j--)
            {
                an[i][j]=now;
                ++cnt;
                if(cnt>=a[now])
                {
                    now++;cnt=0;
                }
            }
        }
    }
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(j!=1)
                printf(" ");
            printf("%d",an[i][j]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

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

#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;
const int MOD = 1000000007;


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

    if(n%2==1) cout << n/2+1 << endl;
    else cout << n/2 << endl;

    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
l = [0 for i in range(N)]
cnt = [0 for i in range(N)]
for i in range(M):
    p,s = map(str, input().split())
    p = int(p)-1
    if s == "AC":
        l[p] = 1
    elif s == "WA":
        if l[p] == 0:
            cnt[p] += 1

mis = 0
for i in range(N):
    if l[i] == 1:
        mis += cnt[i]
print(sum(l), mis)

Measured memory_bytes: 4760
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
  string S;
  cin>>S;
  int count=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='o'){count++;}
  }
  if(count+15-S.size()>=8){cout<<"YES"<<endl;}
  else{cout<<"NO"<<endl;}
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int i;
    vector<int> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    sort(a.begin(),a.end());
    cout << a.at(n-1) - a.at(0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

int main() {
  string s; cin >> s;
  string out = "";
  for(int i=0;i<s.size();++i) out += "x";
  cout << out << endl;
  return 0;
}


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

int main(){
    int x,y;
    cin >> x >> y;
    string arr[x];
    for(int i=0;i<x;i++){
        cin >> arr[i];
    }
    sort(arr,arr+x);
    for(int i=0;i<x;i++){
        cout << arr[i];
    }
}


Measured memory_bytes: 3080
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main
{

  final static int[] WEIGHT =
  { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 };

  public static void main(String[] args) throws NumberFormatException, IOException
  {
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    while (input.ready())
    {
      final int num = Integer.parseInt(input.readLine());

      System.out.println(solver(num));
    }

  }


  private static String solver(int num)
  {
    final char[] bitFlag = Integer.toBinaryString(num).toCharArray();
    List<String> stringList = new ArrayList<>(10);

    int count = 0;
    for (int i = bitFlag.length - 1; i >= 0; i--)
    {
      if (bitFlag[i] == '1')
      {
        stringList.add(String.valueOf(WEIGHT[count]));
      }
      count++;
    }
    return String.join(" ", stringList);
  }
}

Measured memory_bytes: 24364
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
typedef long long ll;

#define MAX_N 100000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

//--------------------------

int main() {

  ll a, b;
  cin >> a >> b;

  cout << lcm(a, b) << endl;

  return 0;
}


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

int main(void)
{
  while (true)
  {
    int n;
    cin >> n;
    if (n == 0) break;

    vector<int> point(2);
    vector<int> buf_point(2);
    for (int i = 0; i < n; ++i)
    {
      cin >> buf_point[0] >> buf_point[1];
      if (buf_point[0] > buf_point[1])
      {
        point[0] += buf_point[0] + buf_point[1];
      }
      else if (buf_point[1] > buf_point[0])
      {
        point[1] += buf_point[0] + buf_point[1];
      }
      else
      {
        point[0] += buf_point[0];
        point[1] += buf_point[1];
      }
    }
    cout << point[0] << " " << point[1] << endl;
  }
  return 0;
}

Measured memory_bytes: 1192
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,K;
	while(cin>>K>>N) {
		VI A(N);
		REP(i, N) cin>>A[i];
		ll all = 0, ma = 0;
		REP(i, N) {
			ll v = 0;
			if(i<N-1) v = A[i+1] - A[i];
			else v = A[0]+K-A[i];
			all+=v;
			maxUpdate(ma, v);
		}
		
		cout<<all-ma<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 2424
#[allow(unused_imports)]
use proconio::{input, marker::*};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

fn eratosthenes(n: usize) -> Vec<usize> {
    let mut set = (2..n + 1).collect::<BTreeSet<_>>();
    let mut vec = Vec::new();
    loop {
        let p = set.iter().next().cloned().unwrap();
        if p * p > n {
            vec.extend(&set.into_iter().collect::<Vec<_>>());
            break vec;
        }
        let mut i = p;
        while i <= n {
            set.remove(&i);
            i += p;
        }
        set.remove(&p);
        vec.push(p);
    }
}

fn gcd(a: usize, b: usize) -> usize {
    if a == usize::default() {
        b
    } else {
        gcd(b % a, a)
    }
}

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let mut g = a[0];
    for &e in &a {
        g = gcd(e, g);
    }

    if g > 1 {
        println!("not coprime");
        return;
    }

    let vec = eratosthenes(1000);

    let mut set = BTreeSet::new();
    for mut e in a {
        for &p in &vec {
            if e % p == 0 {
                if set.contains(&p) {
                    println!("setwise coprime");
                    return;
                }
                set.insert(p);
                if p * p == e {
                    break;
                }
                e /= p;
                if e == 1 {
                    break;
                }
            }
        }
        if e > 1 && set.contains(&e) {
            println!("setwise coprime");
            return;
        }
        set.insert(e);
    }
    println!("pairwise coprime");
}


Measured memory_bytes: 17592
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int a=0,b=0;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='A')
		{
			a++;
		}
		else
		{
			b++;
		}
	}
	if((a==1&&b==2)||(a==2&&b==1))
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	return 0;
}

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

int main(void){
    int n,c=0;
    cin >> n ;
    for (int i=0; i<n; i++){
        int x ;
        cin >> x ;
        if (x!=i+1){
            c++ ;
        }
    }
    if (c==0 || c==2){
        cout << "YES" << endl ;
    } else {
        cout << "NO" << endl ;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int H,W,i,j;
  while(1){
    scanf("%d %d",&H,&W);
    if(H==0&&W==0){
      break;
    }
    for(i=0; i<H; i++){
      for(j=0; j<W; j++){
        if((i%2==0&&j%2==0)||(i%2==1&&j%2==1))
        printf("#");
        else printf(".");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
num = int(input())
data_value = list(map(int, input().split()))
data_cost = list(map(int, input().split()))
ans = 0

def ans_check(all_cost):
    global ans
    if ans < all_cost:
        ans = all_cost


def calc_ans(ind, all_cost, in_out_flg):
    if ind == num:
        ans_check(all_cost)
        return
    if in_out_flg:
        all_cost = all_cost + data_value[ind] - data_cost[ind]

    calc_ans(ind + 1, all_cost, 0)
    calc_ans(ind + 1, all_cost, 1)



def main():
    calc_ans(0, 0, 0)
    calc_ans(0, 0, 1)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
/*
テ」ツ?ソテ」ツつ凝」ツ?凝」ツつ嘉」ツ?ォDP
テ」ツ??p[テ、ツスツ陛ヲツ猟・テァツ崢ョ][テ・ツ可催ヲツ猟・テ」ツ?ョテ・ツ渉づ・ツ環?」ツδ。テ」ツδウテ」ツδ静」ツδシ] = テ、ツスツ陛ゥツ?堙」ツつ甘」ツ?づ」ツつ凝」ツ??


テ・ツ可催ヲツ猟・テ」ツ?ョテ・ツ渉づ・ツ環?」ツδ。テ」ツδウテ」ツδ静」ツδシテ」ツ?ョテ・ツ??」ツ??ィツェツーテ」ツ?凝」ツ?療」ツつ嘉ゥツ債オテ」ツつ津」ツつづ」ツ?」テ」ツ?ヲテ」ツ??」ツつ?
テヲツャツ。テ」ツ?ョテヲツ猟・テ」ツ?ョテ・ツ渉づ・ツ環?」ツδ。テ」ツδウテ」ツδ静」ツδシテ」ツつ津ヲツアツコテ」ツつ?」ツつ凝・ツ?エテ・ツ青暗」ツ??」ツ?敕」ツ?ョテヲツ猟・テ」ツ?ョテ・ツスツ禿ァツ閉ェテ」ツ?ッテヲツ慊?、ツスツ偲ゥツ卍静」ツ??」ツつ凝」ツつ暗」ツ??」ツ?ォテ」ツ?療」ツ?ヲテ」ツ??・ツ可催ヲツ猟・テ」ツ?ィANDテ」ツつ津」ツ?ィテ」ツ?」テ」ツ?ヲ0テ」ツ?ァテ」ツ?ェテ」ツ?妥」ツつ古」ツ?ーテ」ツ??」ツ??」ツ??
 */
#include <iostream>
#include <cstring>
using namespace std;

#define MOD 10007

int N;
int t[1002];
int dp[1002][1 << 3];

void solve(){
  memset(dp, 0, sizeof(dp));
  dp[0][1] = 1;

  for(int i = 0; i < N; i++){
    for(int j = 0; j < (1 << 3); j++){
      if(dp[i][j] == 0) continue;

      for(int nj = 1; nj < (1 << 3); nj++){
        if(!(nj & (1 << t[i]))) continue;
        if(!(j & nj)) continue;

        dp[i + 1][nj] += dp[i][j];
        dp[i + 1][nj] %= MOD;
      }
    }
  }

  int ans = 0;
  for(int i = 0; i < (1 << 3); i++){
    ans += dp[N][i];
    ans %= MOD;
  }
  cout << ans << endl;
}

int main(){
  while(cin >> N){
    for(int i = 0; i < N; i++){
      char ch;
      cin >> ch;
      if(ch == 'J')      t[i] = 0;
      else if(ch == 'O') t[i] = 1;
      else if(ch == 'I') t[i] = 2;
    }
    solve();
  }
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    long long int x;
    std::deque<long long int> deq;
    for (int i=0;i<n;i++) {
        cin>>x;
        deq.emplace_back(x);
    }
    long long int now=deq[0];
    long long int max_count=0;
    long long int count=0;
    for (int j=1;j<n;j++) {
        if (now>=deq[j]) {
            count++;
            if (j==n-1) {
                if (count>max_count) {
                    max_count=count;
                }
            }
        } else {
            if (count>max_count) {
                max_count=count;
            }
            count=0;
        }
        now=deq[j];
    }
    cout<<max_count<<endl;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int x;
    cin >> x;
    rep1(i, 8) {
        if (x >= 2000-i*200) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}


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

typedef long long ll;

ll a[100100];
ll b[100100];

int main() {
	ll n, t;
	cin >> n >> t;
	vector<ll> h(n);
	for(int i = 0; i < n; i++) cin >> h[i];
	for(int i = 0; i < n; i++) {
		a[i+1] = max(a[i], h[i]);
		b[i+1] = b[i] + h[i];
	}
	for(int i = 0; i < n; i++) {
		ll q, r;
		q = (t-b[i]) / a[i+1];
		r = (t-b[i]) % a[i+1];

		if(q < 0) {
			cout << 1 << endl;
		}
		else {
			cout << q+1 + (r >= h[i]) << endl;
		}
	}
}

Measured memory_bytes: 5196
#include <iostream>

using namespace std;

int dp[10001];

int main() {
    int n, v;
    cin >> n;
    dp[0] = 1;
    while (n--) {
        cin >> v;
        for (int i = 10000; i >= 0; --i) {
            if (dp[i]) {
                dp[i + v] = 1;
            }
        }
    }
    for (int i = 10000; i >= 0; --i) {
        if (dp[i] && i % 10 != 0 || i == 0) {
            cout << i << endl;
            break;
        }
    }

    return 0;
}

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

#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define for1(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define clr(x) memset((x), 0, sizeof((x)));
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long i64;
typedef unsigned long long ull;

template<class T>
bool remin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool remax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

ll gcd(ll a, ll b) {
    a = abs(a);
    b = abs(b);
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

typedef ll ptdata;

struct pt {
    ptdata x, y;

    pt() {}

    pt(ptdata x, ptdata y) : x(x), y(y) {}

    inline pt operator-(const pt &r) const {
        return pt(x - r.x, y - r.y);
    }

    inline pt operator+(const pt &r) const {
        return pt(x + r.x, y + r.y);
    }

    inline pt operator*(const ld &r) const {
        return pt(x * r, y * r);
    }

    inline ptdata sqlen() const {
        return abs(x * x + y * y);
    }

    inline bool operator<(const pt &r) const {
        if (x != r.x) return x < r.x;
        return y < r.y;
    }

    inline bool operator==(const pt &r) const {
        return x == r.x && y == r.y;
    }
};

ostream &operator<<(ostream &os, const pt &p) {
    return os << "(" << p.x << "," << p.y << ")";
}

inline ptdata cross(const pt &l, const pt &r) {
    return l.x * r.y - l.y * r.x;
}

inline ptdata dot(const pt &l, const pt &r) {
    return l.x * r.x + l.y * r.y;
}


ll pwmod(ll a, ll n, ll mod) {
    ll ret = 1;
    while (n) {
        if (n & 1) ret = ret * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return ret;
}

template<typename T>
inline T sqr(T x) {
    return x * x;
}



void solve() {
    int n = nxt();
    vector<int> a(n);
    forn(i, n) {
        a[i] = nxt() - 1;
    }
    int ans = 0;
    forn(i, n) {
        if (a[a[i]] == i) {
            ++ans;
        }
    }
    cout << ans / 2 << "\n";
}

void prepare() {

}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    prepare();

    int t = 1;
    //t = nxt();
    forn(i, t) {
        solve();
    }

    //cerr << "Time " << clock() / (double) CLOCKS_PER_SEC << endl;
    return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
using namespace std;
#define MAX 200000
int A[MAX];
int k,n;
int main(){
    int largest = 0;
    int ans =0;
    cin >> k >> n;
    for(int i=0;i<n;i++){
        cin >> A[i];
    }
    for(int i=0;i<n-1;i++){
        if(largest < A[i+1]-A[i])
        largest = A[i+1]-A[i];
    }
    if(largest < k-A[n-1]+A[0]){
        largest =k-A[n-1]+A[0];
    }
    ans = k - largest;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <tuple>
#include <numeric>
using namespace std;


int main(int argc, char* argv[]){
	int N;
	scanf("%d",&N);
	char str[N+100];
	scanf("%s", str);
//	printf("%s", str);

	int r_count = 0;
	for(int i=0;i<N;i++){
		if(str[i]=='R'){
			r_count++;
		}
	}
	int w_count = 0;
	for(int i=0; i<r_count;i++){
		if(str[i]=='W'){
			w_count++;
		}
	}
	printf("%d\n", w_count);




}


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

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class B1 {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      ll x; cin >> x;
      ll now = 100;
      ll ans = 0;
      while(now < x) {
        now += now/100;
        ans++;
      }
      cout << ans << endl;

    }
};

signed main() {
  B1 solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

int main() {
  int N,K;
  cin >> N >> K;
  vector<double> p(N);
    for (int i = 0; i < N; i++) {
    cin >> p.at(i);
   }

  for (int i = 0; i < N; i++) {
    p.at(i) = (p.at(i)+1)/2;
  }

  vector<double> s(N+1, 0); // s[0] = 0 になる
    for (int i = 0; i < N; ++i) s[i+1] = s[i] + p[i];
  
  double answer = 0;
  for (int i = 0; i < N - (K-1); i++) {
    answer = max(answer , s[i+K] - s[i]);
  }

  printf("%.6lf\n", answer);
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
using vvi = vector< vector<int> >;
using vi = vector<int>;
using vvb = vector< vector<bool> >;
using vb = vector<bool> ;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define ar array
#define endl '\n'
#define all(x) x.begin(), x.end()
#define sz(x) ((long long)x.size())


const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

ll fast(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        y >>= 1;
    }
    return res;
}

ll inv(ll n){
    return fast(n,mod-2);
}


void pre(){


}


void solve(){    

    int n;
    cin >> n;
    int lim = min(512,n);
    const int MAX = 100003;
    vector<int> v(n+1),w(n+1);
    for(ll i=1;i<=n;i++){
        cin >> v[i] >> w[i];
    }
    vector<vector<int>> dp(lim+1,vector<int>(MAX,0));
    for(int i=w[1];i<MAX;i++){
        dp[1][i] = v[1];
    }
    for(int i=2;i<=lim;i++){
        ll p = i/2;
        for(int j=0;j<MAX;j++){
            dp[i][j] = dp[p][j];
            if(j >= w[i]){
                dp[i][j] = max(dp[i][j] , dp[p][j-w[i]] + v[i]);
            }
        }
    }
    int q;
    cin >> q;
    while(q--){
        ll node,L;
        cin >> node >> L;
        vector<int> ids;
        while(node > lim){
            ids.pb(node);
            node /= 2;
        }
        int sz = ids.size();
        int ans=0 ;
        for(int i=0;i<(1<<sz);i++){
            int tv=0,tw=0;
            for(int j=0;j<sz;j++){
                if((i>>j)&1){
                    tv += v[ids[j]];
                    tw += w[ids[j]];
                }
            }
            if(tw <= L){
                ans = max(ans , dp[node][L-tw] + tv);
            }
        }
         cout << ans << endl;
    }
   
}

int main(){
    IOS;
    pre();
    ll T = 1;
    //cin >> T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 206748
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int t = (c % b == 0) ? c/b : c/b + 1;
        int s = (a % d == 0) ? a/d : a/d + 1;

        if (t <= s) {
            System.out.println("Yes");
        } else {
            System.out.println("No\n");
        }
    }
}


Measured memory_bytes: 35768
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n, x, a[2000], b[2000];
int main() {
  cin >> n >> x; read_n(a, n);
  copy(&a[0], &a[n], b);

  lli ans = 1e18;
  for (lli d = 0; d < n; ++d) {
    lli scr = d * x;
    for (lli i = 0; i < n; ++i) {
      b[i] = min(b[i], a[(n + i - d) % n]);
      scr += b[i];
    }
    ans = min(ans, scr);
  }

  cout << ans << '\n';
  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 repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0) return 0;
    vector<int> dp(1<<16,0);
    rep(i,n){
      int m,l;
      cin >> m >> l;
      int s,e;
      int x=0;
      rep(j,m){
        cin >> s >> e;
        repp(k,s-6,e-6) x|=(1<<k);
      }
      rep(j,1<<16){
        if((j&x)==x){
          dp[j]=max(dp[j],dp[j^x]+l);
        }
      }
    }
    int ans=0;
    rep(i,1<<16) ans=max(ans,dp[i]);
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3340
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define R cin>>
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
typedef pair<int,int> P;
typedef pair<int,P> P2;

vector<int> v[20010];
bool u[20010];

int main() {
  int n,m;
  while(R n >> m && n) {
    rep(i,20010) {v[i].clear();u[i]=false;}
    P2 a[m];
    rep(i,m) {
      int x,y,z;
      R x >> y >> z;
      a[i]=P2(x,P(y,z));
    }
    sort(a,a+m);
    u[1]=true;
    rep(i,m) {
      if(u[a[i].S.F]) u[a[i].S.S]=true;
    }
    int ans=0;
    REP(i,1,n+1) if(u[i]) ans++;
    pr(ans);
  }
  return 0;
}


Measured memory_bytes: 1884
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
using namespace std;

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

	int cnt = 0;
	for (int i = 1; i < s.size(); i++) {
		if (s[i] == s[i - 1]) {
			cnt++;
			if (s[i] == '0') s[i] = '1';
			else s[i] = '0';
		}
	}
	cout << cnt << endl;

	return 0;
}

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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type / Class / Struct Definitions:
using ll = long long;
using ull = unsigned long long;

//Constants:
const int INF = (1ll << 30) - 1;  //nearly 1.07e9
const ll INFLL = 1ll << 60;       //nearly 1.15e18
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);

//================ Main Loop ================
int main() {
    int k;
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cin >> k;
    cout << a[k - 1] << endl;
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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;
}


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

vector<int> v;

int main(){
    int n; cin >> n;
    n*= 2;
    for(int i = 0 ; i < n ; i++){
        int tmp; cin >> tmp;
        v.push_back(tmp);
    }
    sort(v.begin(),v.end(),greater<int>());
    int ans = 0;
    for(int i = 1 ; i < n ; i+=2){
        ans += min(v[i],v[i-1]);
    }
    cout << ans;
}



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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll a;
    string s;
    cin >> a >> s;

    if(a >= 3200) cout << s << endl;
    else cout << "red" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define all(a) (a).begin(), (a).end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF  = 1<<30;


struct item {
  int v, w;
  bool operator<(const item &r) const { return w < r.w; }
  void operator+=(const item &r) { w += r.w, v += r.v; }
};


vector<item> enum_powerset(const vector<item> &is) {
  vector<item> a = {{0, 0}};
  vector<item> c;
  c.reserve(1<<sz(is));
  for (auto &i : is) {
    auto b = a;
    for (auto &e : b) e += i;
    merge(all(a), all(b), back_inserter(c));
    swap(a, c);
    c.clear();
  }
  return a;
}


int solve(const vector<item> &is, int W) {
  int n = sz(is);
  auto a = enum_powerset({is.begin(), is.begin() + n/2});
  auto b = enum_powerset({is.begin() + n/2, is.end()});
  reverse(all(a));
 
  int ans = 0;
  int vbmax = -INF;
  auto itr = b.begin();
  for (auto &[va, wa] : a) {
    while (itr != b.end() && wa + itr->w <= W) {
      chmax(vbmax, itr->v);
      ++itr;
    }
    chmax(ans, va + vbmax);
  }
  return ans;
}


int main() {
  int n; cin >> n;
  vector<item> is(n);
  for (auto &[v, w] : is) cin >> v >> w;
  is.insert(is.begin(), {0, 0});

  int q; cin >> q;
  rep(_, q) {
    int v, l; cin >> v >> l;
    vector<item> qi;
    while (v) {
      qi.push_back(is[v]);
      v /= 2;
    }
    cout << solve(qi, l) << '\n';
  }
}


Measured memory_bytes: 7420
while STDIN.gets do
  n = $_.to_i

  count = 0
  10.times{|i|
  10.times{|j|
  10.times{|k|
  10.times{|l|
    if(i+j+k+l==n) then count+=1 end
  }
  }
  }
  }

  puts count
  
end

Measured memory_bytes: 6112
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

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

int main(void) {
	int num, i, j;
	cin >> num;
	vector<vector<ll>> dp(num + 1, vector<ll>(4, 0));
	dp[0][0] = 1;
	rep(i, num) {
		dp[i + 1][0] = dp[i][0] * 8 % MOD;
		dp[i + 1][1] = (dp[i][0] + dp[i][1] * 9) % MOD;
		dp[i + 1][2] = (dp[i][0] + dp[i][2] * 9) % MOD;
		dp[i + 1][3] = (dp[i][1] + dp[i][2] + dp[i][3] * 10) % MOD;
	}
	cout << dp[num][3] << "\n";
	return 0;
}

Measured memory_bytes: 73344
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
string str;
int x, y;

bool getable(vector<int> v, int goal){
	set<int> s, sbuf;
	s.insert(0);
	for(int i = 0; i < v.size(); i++){
		for(auto itr = s.begin(); itr != s.end(); itr++){
			int pos = *itr;
			sbuf.insert(pos+v[i]);
			sbuf.insert(pos-v[i]);
		}
		s = sbuf;
		sbuf.clear();
	}

	return (s.find(goal) != s.end());
}

int main(){
	cin >> str >> x >> y;
	str += 'E';//end
	int n = str.size();
	
	char isf = str[0];
	bool started = false;
	bool ishorizon = true;
	int cnt = 0;
	vector<int> xx, yy;
	
	for(ll i = 0; i < n; i++){
		if(isf == str[i]){cnt++;}
		else{
			if(isf == 'F'){
				if(started){
					if(ishorizon){xx.push_back(cnt);}
					else{yy.push_back(cnt);}
				}
				else{
					x -= cnt;
					started = true;
				}
			}
			else{
				if(cnt%2){ishorizon = !ishorizon;}
				started = true;
			}
			isf = str[i];
			cnt = 1;
		}
	}
	
	//for(ll i = 0; i < xx.size(); i++){cout << xx[i] << " ";}cout << endl;
	//for(ll i = 0; i < yy.size(); i++){cout << yy[i] << " ";}cout << endl;
	
	if(getable(xx, x) && getable(yy, y)){cout << "Yes" << endl;}
	else{cout << "No" << endl;}
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main()
{
  int k, a, b, i;
  int dif;
  
  scanf("%d", &k);
  scanf("%d %d", &a, &b);
  
  i = 0;
  while(i <= (b - a))
  {
    if ((a + i) % k == 0)
    {
      printf("OK");
      return(0);
    }
    i++;
  }
  printf("NG");
  return(0);
}

Measured memory_bytes: 1732
a, b = map(int, input().split())
c = input()
c = list(c)
if (c[b-1] == 'A'):
    c[b-1] = 'a'
if (c[b-1] == 'B'):
    c[b-1] = 'b'
if (c[b-1] == 'C'):
    c[b-1] = 'c'
c = ''.join(c)
print('{}'.format(c))

Measured memory_bytes: 3060
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.Set;

public class Main {

  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    Scanner scc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    Set<Integer> set = new HashSet<Integer>();
    for (int i = 0; i < k; i++) {
      int di = sc.nextInt();
      for (int j = 0; j < di; j++) {
        set.add(sc.nextInt());
      }
    }
    System.out.println(n - set.size());
  }

}

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        buflen = in.read(buffer);
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen <= 0) {
        return false;
      }
    }
    return true;
  }

  private int readByte() {
    if (hasNextByte())
      return buffer[ptr++];
    else
      return -1;
  }

  private static boolean isPrintableChar(int c) {
    return 33 <= c && c <= 126;
  }

  public boolean hasNext() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr]))
      ptr++;
    return hasNextByte();
  }

  public String next() {
    if (!hasNext())
      throw new NoSuchElementException();
    StringBuilder sb = new StringBuilder();
    int b = readByte();
    while (isPrintableChar(b)) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }

  public long nextLong() {
    if (!hasNext())
      throw new NoSuchElementException();
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }

  public int nextInt() {
    long nl = nextLong();
    if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
      throw new NumberFormatException();
    return (int) nl;
  }

  public double nextDouble() {
    return Double.parseDouble(next());
  }
}

Measured memory_bytes: 36752
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


fn main() {
    let N: u32 = read();

    let mut A = Vec::new();

    for _ in 0..N {
        let n: u32 = read();
        A.push(n);
    }

    let mut count = 0;
    'outer: loop {
        for n in 0..(A.len()) {
            let a = A[n];
            if (a % 2) == 1 {
                break 'outer;
            }
            A[n] = a / 2;
        }
        count += 1;
    }
    println!("{}", count);
}


Measured memory_bytes: 4352