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

long long n,k;
vector<long long > a,v;

long long solve();

int main(){
    cin >> n >> k;
    a.resize(n);
    for(int i = 0;i < n;++i)cin >> a[i];
    cout << solve() << endl;
    return 0;
}

long long  solve(){
    long long ans = 0;
    for(int i = 1;i < n;++i)a[i] += a[i-1];
    for(int i = 0;i< n;++i)
        for(int j = i;j < n;++j){
            long long now = a[j];
            if(i != 0)now -= a[i-1];
            v.push_back(now);
        }
    for(long long i = 40;i >= 0;--i){
        vector<long long> newv;
        int vsize = v.size();
        for(int j = 0;j < vsize;++j)
            if((v[j] >> i) & 1)newv.push_back(v[j]);
        if((int)newv.size() >= k)v = newv;
    }
    ans = v[0];
    for(int i = 0;i < k;++i)ans &= v[i];
    return ans;
}

Measured memory_bytes: 6388
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
//library begin
int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
int log(int a){
    int b=a;
    int cnt=0;
    while(b%2==0){
        b/=2;
        cnt++;
    }
    return cnt;
}
int mypow(int a,int b){
    if(b==0)return 1;
    if(b==1)return a;
    int t=mypow(a,b/2);
    if(b%2==0)return t*t;
    return t*t*a;
}
//library end
int a[5][5];
bool bo[5][5];
bool x[5],y[5],l=true,r=true;
int n;
int b[15];
signed main(){
    rep(i,3){
        rep(j,3){
            cin>>a[i][j];
        }
    }
    cin>>n;
    rep(i,n){
        cin>>b[i];
        rep(j,3){
            rep(k,3){
                if(a[j][k]==b[i])bo[j][k]=true;
            }
        }
    }
    rep(i,4){
        x[i]=true;
        y[i]=true;
    }
    rep(i,3){
        rep(j,3){
            if(bo[i][j]==false){
                x[i]=false;
                y[j]=false;
                if(i==j)l=false;
                if(i+j==2)r=false;
            }
        }
    }
    if(x[0]||x[1]||x[2]||y[0]||y[1]||y[2]||l||r)puts("Yes");
    else puts("No");
    return 0;
}


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

int H, W;
char field[110][110];

int main() {
  cin >> H >> W;
  for (int i = 1; i < H + 1; i++) {
    for (int j = 1; j < W + 1; j++) {
      cin >> field[i][j];
    }
  }
  for (int i = 0; i < H + 2; i++) field[i][0] = field[i][W+1] = '#';
  for (int i = 0; i < W + 2; i++) field[0][i] = field[H+1][i] = '#';
  // 解答
  for (int i = 0; i < H + 2; i++) {
    for (int j = 0; j < W + 2; j++) {
      cout << field[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
void solve()
{
    ll a, b, c;
    cin>>a>>b>>c;
    if(a+b+c>=22)
    	cout<<"bust";
    else
    	cout<<"win";
}
int main()
{
	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3808
#include <iostream>
#include <string>
using namespace std;
int main(void){
    
    int K;
    string S;
    cin >> K >> S;
    if(S.size() > K){
        cout << S.substr(0, K) << "..." << endl;;
    }
    else{
        cout << S << endl;
    }
    
}


Measured memory_bytes: 3108
fun main(args: Array<String>) {
    val A = IntArray(5)
    repeat(5) { i ->
        A[i] = readLine()!!.toInt()
    }
    val B = A.map { ((it + 9) / 10) * 10 }
    val max = A.zip(B).maxBy { it.second - it.first }!!
    println(B.sum() - max.second + max.first)
}

Measured memory_bytes: 35860
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    int P[N];
    for(int i=0;i<N;i++)
        cin >> P[i];

    int M[N], m = INT_MAX;
    for(int i=0;i<N;i++){
        m = min(P[i], m);
        M[i] = m;
    }

    int ans = 0;
    for(int i=0;i<N;i++){
        if(M[i] == P[i])    // P[i]が最小 → P[i] = M[i]
            ans++;
    }

    cout << ans << endl;

}

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

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

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define sa(v) sort(v.begin(),v.end())
#define sd(v) sort(v.begin(),v.end(),greater<>())
#define rev(s) reverse(s.begin(),s.end())
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()

#define sqr(a) ((a) * (a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define mem(a,b) memset(a,b,sizeof(a))

#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

ll f[mx];

int main()
{
   su;
   int n;
   cin>>n;
   for(int i=1;i<101;i++)
   {
     for(int j=1;j<101;j++)
     {
       for(int k=1;k<101;k++)
       {
         if(i*i+j*j+k*k+i*j+i*k+j*k>n)
          continue;
          f[i*i+j*j+k*k+i*j+i*k+j*k]++;
       }
     }
   }
   for(int i=1;i<=n;i++)
   {
     cout<<f[i]<<nl;
   }
   return 0;
}


Measured memory_bytes: 3724
from sys import exit
from itertools import count

def read():
  return [int(x) for x in input().split()]

P = 10**9 + 7

def inv(x):
  return pow(x, P-2, P)

def comb(n, r):
  res = 1
  for i in range(r):
    res = (res * (n-i) * inv(i+1)) % P
  return res

(H, W, A, B) = read()

result = 0

c1 = comb(H-A-1+B, B)
c2 = comb(W-B-1+A, A)

for i in range(1, min(H-A+1, W-B+1)):
  # print(c1, c2)
  result = (result + c1 * c2) % P
  c1 = (c1 * (H-A-i) * inv(B+i)) % P
  c2 = (c2 * (W-B-i) * inv(A+i)) % P

print(result)


Measured memory_bytes: 7396
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
using namespace std;

typedef long long ll;
int dist[200][200];
int inf=1000000000;

int main() {
    int N,M,R;
    cin >> N >> M >> R;
    vector<int> city(R);
    for(int i=0; i<R; i++){
        cin >> city[i];
        city[i]--;
    }
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            dist[i][j]=inf;
        }
    }
    for(int i=0; i<M; i++){
        int a,b,c;
        cin >> a >> b >> c;
        a--;
        b--;
        dist[a][b]=c;
        dist[b][a]=c;
    }
    while(true){
        bool flag=false;
        for(int i=0; i<N; i++){
            for(int j1=0; j1<N; j1++){
                for(int j2=0; j2<N; j2++){
                    if(dist[j1][j2]>dist[j1][i]+dist[i][j2]){
                        dist[j1][j2]=dist[j1][i]+dist[i][j2];
                        flag=true;
                    }
                }
            }
        }
        if(!flag) break;
    }

    sort(city.begin(), city.end());
    int ans=1000000000;
    do {
        int tmp=0;
        for(int i=0; i<R-1; i++){
            tmp+=dist[city[i]][city[i+1]];
        }
        ans=min(tmp, ans);
    } while (next_permutation(city.begin(), city.end()));
    cout << ans << endl;
 
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;
ll gcd(ll a, ll b);
ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);


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

ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  k--;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}

int main(void){
  ll n, k;
  cin >> n >> k;
  
  vector<ll> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  
  ll ma = 0, mi = 0;
  ll c1 = (nck(n-1, k-1) * inv(n-k+1) % MOD) * n % MOD, c2 = 0;
  for (int i = 0; i < n; i++){
    c1 = (c1 * (n-i-k+1) % MOD) * inv(n-i) % MOD;
    c2 = c2 * i % MOD * inv(i-k+1) % MOD;

    if (i == k - 1){
      c2 = 1;
    }

    mi = (mi + a[i]*c1) % MOD;
    ma = (ma + a[i]*c2) % MOD;
  }


  cout << (ma - mi + MOD) % MOD << endl;
  return 0;
}


Measured memory_bytes: 1024
using System;
class AOJ
{
    public static void Main()
    {
        while (true)
        {
            string[] st = Console.ReadLine().Split(' ','\n');
            int a = int.Parse(st[0]);
            int b = int.Parse(st[1]);
            if (a == 0 && b == 0)
                break;
            for (int i = 0; i < a; i++)
            {
                for (int j = 0; j < b; j++)
                {if (i % 2 == 0)
                    {
                        if (j % 2 == 0)
                            Console.Write("#");
                        else
                            Console.Write(".");
                    }
                    else
                    {

                        if (j % 2 != 0)
                            Console.Write("#");
                        else
                            Console.Write(".");
                    }
                }
                Console.WriteLine();
            }
            Console.WriteLine();
       

        }
    }
}

Measured memory_bytes: 8892
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n; char s[MAXN];
int a[MAXN], b[MAXN];
int main() {
	read(n), scanf("%s", s + 1);
	for (int i = 1; i <= n; i++)
		a[i] = a[i - 1] + (s[i] == '#');
	for (int i = n; i >= 1; i--)
		b[i] = b[i + 1] + (s[i] == '.');
	int ans = n;
	for (int i = 0; i <= n; i++)
		chkmin(ans, a[i] + b[i + 1]);
	writeln(ans);
	return 0;
}

Measured memory_bytes: 2048
(let* ((a (read))
       (b (read))
       (m (read))
       (a-l (map 'vector (lambda (x) x) (loop :repeat a :collect (read))))
       (b-l (map 'vector (lambda (x) x) (loop :repeat b :collect (read))))
       (ll (loop :repeat m :collect (list (read) (read) (read)))))
  (princ (min (+ (loop :for k :across a-l :minimize k)
                 (loop :for k :across b-l :minimize k))
              (loop :for n-ll :in ll
                    :minimize (+ (aref a-l (1- (first n-ll)))
                                 (aref b-l (1- (second n-ll)))
                                 (* -1 (third n-ll)))))))

Measured memory_bytes: 68008
V_0, E_0 = map(int, input().split())
from collections import deque
V = [False]*V_0
V[0] = True
E = 0
import heapq

S = []
heapq.heapify(S)
graph = [[] for i in range(V_0)]

for e in range(E_0):
    s, t, w = map(int, input().split())
    graph[s].append((w, t))
    graph[t].append((w, s))

for w, a in graph[0]:
    heapq.heappush(S, (w, a))

while len(S)!=0:
    w, a = heapq.heappop(S)
    if V[a]:
        continue
    for w2, b in graph[a]:
        if not V[b]:
            heapq.heappush(S, (w2, b))
    V[a] = True
    E += w

print(E)


Measured memory_bytes: 37592
#[allow(unused_imports)]
use std::cmp::{max, min};
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, x: usize, n: usize, mut p: [usize; n]);
    if n == 0 {
        println!("{}", x);
        return;
    }
    p.sort();
    let p: Vec<usize> = p;
    let mut l = 0;
    let mut r = p.iter().max().unwrap() + 1;
    for i in 0..101 {
        if !p.contains(&i) {
            if i <= x {
                l = i;
            } else {
                r = i;
                break;
            }
        }
    }
    if x - l <= r - x {
        println!("{}", l);
    } else {
        println!("{}", r);
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2128
//--- pB ---//
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Scanner scanner;
	public Solution() {
		scanner = new Scanner(System.in);

		// scanner.nextLine();
		while (scanner.hasNext()) {
			run_case();
		}
	}
	private void run_case() {
		// scanner.nextLine();
		String line = scanner.nextLine();
		int N = Integer.parseInt(line.split("\\s+")[0]);
		int K = Integer.parseInt(line.split("\\s+")[1]);

		int len = 0;
		while (N > 0) {
			N /= K;
			len ++;
		}

		System.out.println(len);
		return;
	}

	private int[] strToIntArray(String str) {
	    String[] vals = str.split("\\s+");
	    int sz = vals.length;
	    int[] res = new int[sz];
	    for (int i=0; i<sz; i++) {
	        res[i] = Integer.parseInt(vals[i]);
	    }
	    return res;
	}

}

class LCS {
    int[][] dp;
    public int lcs(String A, String B) {
        int sz_a = A.length(), sz_b = B.length();
        dp = new int[sz_a+1][sz_b+1];

        for (int i=0; i<=sz_a; i++) dp[i][0] = 0;
        for (int j=0; j<=sz_b; j++) dp[0][j] = 0;

        for (int i=1; i<=sz_a; i++) {
            for (int j=1; j<=sz_b; j++) {
                if (A.charAt(i-1) == B.charAt(j-1)) {
                    dp[i][j] = dp[i-1][j-1] + 1;
                } else {
                    dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
                }
            }
        }

        return dp[sz_a][sz_b];
    }

    public String getLCS(String X, String Y) {
		int m = X.length();
		int n = Y.length();
        // Following code is used to print LCS
        int index = dp[m][n];
        int temp = index;

        // Create a character array to store the lcs string
        char[] lcs = new char[index+1];
        lcs[index] = '\0'; // Set the terminating character

        // Start from the right-most-bottom-most corner and
        // one by one store characters in lcs[]
        int i = m;
		int j = n;
        while (i > 0 && j > 0) {
            // If current character in X[] and Y are same, then
            // current character is part of LCS
            if (X.charAt(i-1) == Y.charAt(j-1))
            {
                // Put current character in result
                lcs[index-1] = X.charAt(i-1);

                // reduce values of i, j and index
                i--;
                j--;
                index--;
            }

            // If not same, then find the larger of two and
            // go in the direction of larger value
            else if (dp[i-1][j] > dp[i][j-1])
                i--;
            else
                j--;
        }

        // // Print the lcs
        // System.out.print("LCS of "+X+" and "+Y+" is ");
        // for(int k=0;k<=temp;k++)
        //     System.out.print(lcs[k]);
        //

        return String.valueOf(lcs).substring(0, temp+2);
    }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(),(x).end()
#define pushb(x) push_back(x)
#define popb() pop_back()
#define makep make_pair
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv);
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v);
template<typename T> ll gcd(T a,T b);
template<typename T> ll lcm(T a,T b);
ll num(ll a,ll b,ll k){
    ll firstak=((a-1)/k+1)*k;
    ll firstbk=(b/k+1)*k;
    ll dif=firstbk-firstak;
    // cout<<firstak<<' '<<firstbk<<endl;
    return dif/k;
}

int main(){
    ll a,b,c,d;cin>>a>>b>>c>>d;
    ll dn=0;
    ll dnc,dnd,dncd;
    ll cd=lcm(c,d);
    ll firstc,firstd;
    dnc=num(a,b,c);
    dnd=num(a,b,d);
    dncd=num(a,b,cd);
    // cout<<dnc<<' '<<dnd<<' '<<dncd<<endl;
    cout<<b-a+1-dnc-dnd+dncd<<endl;

    return 0;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
    int len = vv.size();
    for (int i = 0; i < len; ++i) {
        s << vv[i] << endl;
    }
    return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len - 1) s << ' ';
    }
    return s;
}
template<typename T> ll gcd(T a,T b){
    if(b==0){
        return a;
    }
    return gcd(b,a%b);
}
template<typename T> ll lcm(T a,T b){
    return a*b/gcd(a,b);
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VECINT;
typedef vector<ll> VECLL;

int main() {
  int N;cin>>N;
  vector<P> graph[N];
  REP(i,N-1) {
    int u,v,w;cin>>u>>v>>w;
    u--;
    v--;
    graph[u].push_back({v,w});
    graph[v].push_back({u,w});
  }
  int ans[N];
  REP(i,N) ans[i] = -1;
  ans[0] = 0;
  // グラフの頂点を一つずつ見ていって、dfsで色を塗っていく
  deque<int> q{0};
  while (!q.empty()) {
    int cur_p = q.front();
    q.pop_front();
    for (auto x:graph[cur_p]) {
      // すでに塗られている場合はスキップ
      if (ans[x.first]!=-1) continue;
      // 現在のポイントと、距離に応じて色を塗り分けた上で、qに追加
      if (x.second%2==0) {
        if (ans[cur_p]==0) ans[x.first] = 0;
        else ans[x.first] = 1;
      } else {
        if (ans[cur_p]==0) ans[x.first] = 1;
        else ans[x.first] = 0;
      }
      q.push_back(x.first);
    }
  }
  REP(i,N) OUT(ans[i]);

  return 0;
}

Measured memory_bytes: 8192
/*
ID: hafiz.i1
TASK: milk2
LANG: C++
*/
#include<bits/stdc++.h>

#define ll long long
#define mod 1000000007

using namespace std;



int main()
{
//    freopen("milk2.in", "r", stdin);
//    freopen("milk2.out", "w", stdout);
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    ll n,i=1;
    cin>>n;
    map<ll,ll>m;m[n]=1;
    while(1){
        if(n&1)n=3*n+1;
        else n/=2;
        ++i;
        if(m[n]==1){
            cout<<i;return 0;
        }
        else m[n]=1;
    }
}


Measured memory_bytes: 3576
#include<iostream>
#include<deque>
#include<utility>
#include<algorithm>
#include<stack>
#include<vector>

using namespace std;
vector< vector<char> > map;
 

int main(){

    int H,W,N;
    int HP=1;
    char temp;
    int dx[] = {1,-1,0,0};
    int dy[] = {0,0,1,-1};
    int count=0;
    cin >> H >> W >> N;
    vector< vector<bool> > fmap(H,vector<bool>(W));
    vector<bool> f(W);
    fill(f.begin(),f.end(),false);
    fill(fmap.begin(),fmap.end(),f);
    deque< pair<int,int> > next;
    for(int i=0;i<H;i++){
	map.push_back( vector<char>(W) );
	for(int j=0;j<W;j++){
	    cin >> temp;
	    if(temp == 'S') next.push_back(pair<int,int>(i,j));
	    map[i][j] = temp;
	}
    }
    int x,y;
    bool flag = false;
    deque< pair<int,int> > t;
    while(true){
	count++;
	while(true){
	    if(next.empty() && t.empty()) cout << HP <<endl;
	    y = next.front().first;
	    x = next.front().second;
	    next.pop_front();
	    for(int i=0;i<4;i++){
		if( dx[i]+x<0 || dx[i]+x>=W || dy[i]+y<0 || dy[i]+y>=H || map[y+dy[i]][x+dx[i]] == 'X')   continue;
		else if(HP == (int)(map[y+dy[i]][x+dx[i]] - '0') ){
		    HP++;
		    if(HP == N+1){
			flag = true;
		    }
		    t.clear();
		    next.clear();
		    t.push_back(pair<int,int>(y+dy[i],x+dx[i]));
		    fill(fmap.begin(),fmap.end(),f);
		    break;
		}
		else if(!fmap[y+dy[i]][x+dx[i]]){
		    t.push_back(pair<int,int>(y+dy[i],x+dx[i]));
		    fmap[y+dy[i]][x+dx[i]] = true;
		}

		
	    }
	    if(flag||next.empty()) break;
	}
	if(flag) break;
	swap(next,t);
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 2324
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n) 
long long mod(long long a, long long m){
  long long c=0,x=1;
  do{
    x = a*x % m;
    c++;
  }while(x!=1);
  return c;
}
long long gcd(long long m,long long n){
  return (n==0)?m:gcd(n,m%n);
}
long long lcm(long long m, long long n){
  return m*n/((m>n)?gcd(m,n):gcd(n,m));
}
int main(void){
  long long a,b,c,l,m,n;
  while(cin>>a>>l>>b>>m>>c>>n){
    if(!a&&!b&&!c&&!l&&!m&&!n) break;
    cout << lcm(mod(a,l),lcm(mod(b,m),mod(c,n))) << endl;
  }
  return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    ll n, m;
    cin >> n >> m;
    if (n >= m)
        swap(n, m);

    if (n == 1 && m == 1)
    {
        OP(1);
        return 0;
    }
    else if (n == 1)
    {
        OP(m - 2);
        return 0;
    }
    else
    {
        OP((m - 2) * (n - 2));
        return 0;
    }

    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ordered_set tree<ll int, null_type,less<ll int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  1000005

int main()
{
    ios;
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
        ll i,j,k,l,m,n;
        cin>>n>>l;
        ll w[103],v[104];
        k=n*1000;
        for(i=1;i<=n;i++)
        {
            cin>>w[i]>>v[i];
        }
        ll dp[100005];
        for(i=0;i<100005;i++)
            dp[i]=hell;
        dp[0]=0;
        for(i=1;i<=n;i++)
        {
            for(j=k;j>=0;j--)
            {
                if(j+v[i]>k)
                    continue;
                dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i]);
            }
        }
        ll ans=0;
        for(i=k;i>=0;i--)
        {
            if(dp[i]<=l)
            {
                cout<<i;
                return 0;
            }
        }
        cout<<0;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n';
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1e9+7;
int dp[(1<<21)+10];
void add(int &a, int b){
	a+=b;
	if(a>mod) a-=mod;
}
bool a[22][22];
vector<int>v[22];
int main(){
	IOS;
	int n;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			cin>>a[i][j];
		}
	}
	for (int i = 0; i < 1<<n; ++i)
	{
		int k=__builtin_popcount(i);
		v[k].emplace_back(i);
	}
	dp[0]=1;
	for (int i = 0; i < n; ++i)
	{
		for(auto mask:v[i]){
			for (int j = 0; j < n; ++j)
			{
				if(!a[i][j] or (mask&(1<<j))) continue;
				add(dp[(mask|(1<<j))],dp[mask]);
			}
		}
	}
	cout<<dp[(1<<n)-1]<<endl;
	return 0;
}

Measured memory_bytes: 18748
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder(101);
		while(sc.hasNext()){
			int JOI = 0;
			int IOI = 0;
			String s = sc.nextLine();
			if(s.equals("EOF"))break;
			for(int i=0;i<s.length()-1;i++) {
				if((s.indexOf("JOI",i)) != -1){
					i = s.indexOf("JOI", i);
					JOI++;
				}
			}
			for(int i=0;i<s.length()-1;i++) {
				if((s.indexOf("IOI", i)) != -1) {
					i = s.indexOf("IOI", i);
					IOI++;
				}
			}
			
			System.out.println(JOI);
			System.out.println(IOI);
		}
	}
}


Measured memory_bytes: 27800
n,m = map(int,input().split())
x = list(map(int,input().split()))
base = [0]*(m-1)

x.sort()

for i in range(m-1):
  base[i] = x[i+1] - x[i]
  
base.sort()
ans = 0

for i in range(m-n):
  ans = ans + base[i]
  
print(ans)

Measured memory_bytes: 13968
#define _CRT_SECURE_NO_WARNINGS
//#define DEBUG
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(void) {
#ifdef DEBUG
	printf("");
#endif

	int N;
	int ans=1;

	scanf("%d", &N);

	while (N > 1) {
		N = N / 2;
		ans *= 2;
	}
	printf("%d\n", ans);

}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set>
using namespace std;
//int p = 998244353;
long long p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define rev(s) reverse(s.begin(),s.end())
#define lower(h,val) lower_bound(h.begin(),h.end(),val)-h.begin()
#define upper(h,val) upper_bound(h.begin(),h.end(),val)-h.begin()
int max_kai = 150000;
vel kai(max_kai, 1);
vel inv_kai;
int rui(int a, int n) {
	if (n == 0) { return 1; }
	int x = rui(a, n / 2);
	x *= x; x %= p;
	if (n % 2 == 1) { x *= a; x %= p; }
	return x;
}
int inv(int a) { return rui(a, p - 2); }
void make_kai() {
	for (int i = 1; i < max_kai; i++) { kai[i] = kai[i - 1] * i; kai[i] %= p; }
	inv_kai = kai;
	rep(i, max_kai) { inv_kai[i] = inv(kai[i]); }
}
int nCr(int n, int r) {
	int a = kai[n] * inv_kai[r]; a %= p;
	a *= inv_kai[n - r]; a %= p;
	return a;
}
vel pa;
int root(int x) {
	if (pa[x] == -1) { return x; }
	int ans = root(pa[x]); pa[x] = ans;
	return ans;
}
void marge(int x, int y) {
	x = root(x);
	y = root(y);
	if (x != y) {pa[x] = y;}
}


#define T vel
T mul(T &a,T &b) {//calcureate a(b(x))
	int sz = a.size();
	vel c(sz);
	rep(i, sz) { c[i] = a[b[i]]; }
	return c;
}
T rui1(T &a, int n) {
	if (n == 1) { return a; }
	T x = rui1(a, n / 2);
	x = mul(x, x);
	if (n % 2 == 1) { x = mul(x, a); }
	return x;
}

signed main(){
	int n; cin >> n;
	vel x(n);
	rep(i, n) { cin >> x[i]; }
	int m, k; cin >> m >> k;
	vel per(n - 1);
	rep(i, n - 1) { per[i] = i; }
	rep(i, m) {
		int a; cin >> a;
		swap(per[a - 2], per[a - 1]);
	}
	per = rui1(per, k);
	int back = x[0];
	cout << back << endl;
	rep(i, n - 1) {
		back += (x[per[i]+1] - x[per[i]]);
		cout << back << endl;
	}
	return 0;
}

Measured memory_bytes: 4816
def make_tree(n):
    i = 2
    while True:
        if i >= n * 2:
            tree = [[inf] * i for _ in range(26)]
            break
        else:
            i *= 2
    return tree

def update(i, x, tree):
    i += len(tree) // 2
    tree[i] = x
    i //= 2
    while True:
        if i == 0:
            break
        tree[i] = min(tree[2 * i], tree[2 * i + 1])
        i //= 2
    return

def find(s, t, tree):
    s += len(tree) // 2
    t += len(tree) // 2
    ans = inf
    while True:
        if s > t:
            break
        if s % 2 == 0:
            s //= 2
        else:
            ans = min(ans, tree[s])
            s = (s + 1) // 2
        if t % 2 == 1:
            t //= 2
        else:
            ans = min(ans, tree[t])
            t = (t - 1) // 2
    return ans

s = list(input())
t = list(input())
inf = 10 ** 6
n = len(s)
first = [-2] * 26
tree = make_tree(n)
for i in range(n):
    m = ord(s[i]) - 97
    update(i, i, tree[m])
    if first[m] == -2:
        first[m] = i
ans = 1
c = -1
for i in t:
    m = ord(i) - 97
    if not c == -1:
        u = -1
        u = find(c + 1, n - 1, tree[m])
        if u == -1 or u == inf:
            ans += n
            c = -1
        else:
            c = u
    if c == -1:
        c = first[m]
        if c == -2:
            print(-1)
            exit()
ans += c
print(ans)

Measured memory_bytes: 115108
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <cstdio>
#define INF 1e+9

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int N,M,R; 
int d[201][201]; 
int r[9]; 
int A,B,C;
int res; 
bool used[9];

void dfs(int c,int las,int dist) {
  if(c==R+1) { 
    if(res>dist) res=dist; 
    return; 
  } 
  for(int i=1;i<=R;i++){
    if(!used[i]) { 
      used[i]=true; 
      if(las==-1)dfs(c+1,i,0); 
      else dfs(c+1,i,dist+d[r[las]][r[i]]); 
      used[i]=false; 
    } 
  }
}

int main(void){
  //long N, M, R;
  cin >> N >> M>> R;
  rep_s(i, 1, N+1) {
    rep_s(j, 1, N+1) {
      if(i != j) d[i][j] = INF;
    }
  }
  rep_s(i, 1, R+1) cin >> r[i];
  
  rep_s(i, 1, M+1) {
    cin >> A >> B >> C;
    if (d[A][B] > C) d[A][B] =d[B][A] = C;
  }
  rep_s(k, 1, N+1){ 
    rep_s(i, 1, N+1) {
      rep_s(j,1, N+1) {
        if (d[i][j] > d[i][k] + d[k][j]){
        	d[i][j] = d[i][k] +d[k][j];
        }
      }
    }
  }
  res = INF;
  dfs(1, -1, 0);
  cout << res << endl; 
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;


int main() {
	ll N, P, ans, even = 0, odd = 0;
	cin >> N >> P;

	vector<ll>A(N);

	rep(i, N) {
		cin >> A[i];
		if (A[i] % 2 == 0) {
			even++;
		}
	}
	if (even == N) {
		if (P == 0) {
			ans = pow(2, N);
		}
		else {
			ans = 0;
		}
	}
	else {
		ans = pow(2, N - 1);
	}

	cout << ans;

	return 0;

}


Measured memory_bytes: 3992
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

N,M = Ints()
H = IntList()
Ans = [0]*N

for i in range(M):
    A,B = Ints()
    if H[A-1] < H[B-1]:
        Ans[A-1] = -1
    elif H[A-1] > H[B-1]:
        Ans[B-1] = -1
    else:
        Ans[A-1] = -1
        Ans[B-1] = -1
    
ans = 0
for i in Ans:
    if i==0:
        ans += 1
print(ans)

Measured memory_bytes: 84976
#include<set>
using namespace std;
#include<iostream>
int	main(){
	/*
	while(true){
	
	int A,B,C,D,E,F,G,H,I,J,answer;
		
	cin >> A;
	if(A == 0) return 0;
	cin >> B >> C >> D >> E >> F >> G >> H >> I >> J;
	answer = A - B - C - D-E-F-G-H-I-J;
	cout << answer << endl;

	}
	*/
	/*
	int A,B,C,D,E,F;

	cin >> A, B, C, D;
	if(A < B, C, D){ 
	cout << B + C + D << endl;
	}
	
	else if(B < A, C, D){
	cout << A + C + D << endl;
	}

	else if(C < A && C < B && C < D){
	cout << A + B + D << endl;
	}

	else if(D < A && D < B && D < C){
	cout << A + B + C << endl;
	}

	if(E < F){
	cout << F << endl;
	}

	else{
	cout << E << endl;
	}
	
	return 0;
}*/
	/*
	int N, M;
	cin >> N >> M;
	cout << N + M << endl << N - M << endl << N * M << endl << N / M << endl;
}*/

/*int N, M; 
	cin >> N >> M;
	cout << N % M << endl;
}*/

/*	int N;
	cin >> N;
	cout << -(N % 2)+1 ;
}*/

	/*int A, B, C, D, E ;
	cin >> A >> B >> C >> D >> E;
	cout << (A + B + C + D + E) / 5 ;
}*/

	/*int A, B, C, D ;
	cin >> A >> B >> C >> D;
	cout << (A + B + C + D) / 60 << endl << (A + B + C + D) % 60 << endl;
	*/

/*	int A,B;
	cin >> A >> B;
	cout << ( A + B ) / 2 << endl;*/

	int m, f, b;
	cin >> m >> f >> b;

	if ( m + f >= b && m <= b ){
	cout << b - m << endl;
	}
	
	if ( m + f > b && m > b ){
	cout << 0 << endl;
	}


	if ( m + f < b ){
	cout << "NA" << endl;
	}

}


Measured memory_bytes: 3100
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int step = sc.nextInt();
		long height[] = new long[num];
		for(int i = 0; i < num; i ++) {
			height[i] = sc.nextLong();
		}
		long dp[] = new long[num];
		dp[0] = 0;
		for(int i = 1; i < num; i ++) {
			dp[i] = Long.MAX_VALUE;
			for(int j = Math.max(i - step, 0); j < i; j ++) {
				dp[i] = Math.min(dp[i], dp[j] + Math.abs(height[i] - height[j]));
			}
		}
		System.out.println(dp[num - 1]);
	}
}

Measured memory_bytes: 60580
#include <stdio.h>
#include <string.h>

int main(void)
{
    int exist[100002];
    int n, k;
    int i, j;
    int t;
    int ans;
    int flag;
    int before;
    
    while (1){
        scanf("%d%d", &n, &k);
        
        if (n == 0 && k == 0){
            break;
        }
        
        memset(exist, 0, sizeof(exist));
        flag = 0;
        for (i = 0; i < k; i++){
            scanf("%d", &t);
            if (t == 0){
                flag = 1;
            }
            else {
                exist[t] = 1;
            }
        }
        
        ans = before = 0;
        for (i = 1; i <= n + 1; i++){
            if (exist[i] && exist[i - 1]){
                exist[i] += exist[i - 1];
                ans = ans > exist[i] ? ans : exist[i];
            }
            else if (flag == 1 && exist[i - 1]){
                ans = ans > before + exist[i - 1] + 1 ? ans : before + exist[i - 1] + 1;
                before = exist[i - 1];
            }
        }
        
        printf("%d\n", ans);
    }
    
    return (0);
}

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

#define ONLINE_JUDGE
#define ll long long
#define PI 3.14159265359
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define pb(a) push_back(a)

//////////// Solution /////////////////////////////////

int n,k,v[52];

void solve() {
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> v[i];
	}

	ll ans = 0;
	ll cur_left = 0, cur = 0;
	set<int> neg, neg_left;

	for (int i = 0; i <= min(k,n); ++i) {
		cur_left += v[i];
		//cout << "##" << ' ' << v[i] << '\n';

		if (v[i] < 0) {
			neg_left.insert(v[i]);
		}

		neg.clear();
		for (auto x : neg_left) {
			neg.insert(x);
		}
		cur = cur_left;

		for (int j = 0; j+i <= min(k,n); ++j) {
			cur += v[n+1-j];
			//cout << "### " << v[n+1-j] << '\n';
			//cout << i << ' ' << j << ": " << cur << '\n';
			if (v[n+1-j] < 0) {
				neg.insert(v[n+1-j]);
			}

			int op_left = k-(i+j);
			auto it = neg.begin();
			ll tcur = cur;
			while (op_left && it != neg.end()) {
				tcur -= *it;
				--op_left;
				++it;
			}

			ans = max(ans,tcur);
			//cout << "#: " <<  i << ' ' << j << ": " << tcur << '\n';
		}
	}

	cout << ans << '\n';
}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

			#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
			#endif

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	solve();

			#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
			#endif

	return 0;
}

		//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 256
//2018.9.29 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define eps 1e-15
inline int read(){
    res s=0;
    bool w=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=1;ch=getchar();}
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
    return w?-s:s;
}
inline void _swap(res &x,res &y){
    x^=y^=x^=y;
}
inline int _abs(const res &x){
    return x>0?x:-x;
}
inline int _max(const res &x,const res &y){
    return x>y?x:y;
}
inline int _min(const res &x,const res &y){
    return x<y?x:y;
}
namespace MAIN{
    int A,B,C;
    LL ans;
    inline void MAIN(){
        A=read(),B=read(),C=read();
        ans=min((LL)A*B,min((LL)A*C,(LL)B*C));
        if((A&1)&&(B&1)&&(C&1))printf("%lld\n",ans);
        else puts("0");
    }
}
int main(){
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 256
// 2011/09/12 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	while(true){
		string str;
		cin >> str;
		if(cin.eof())
			break;

		int joi = 0;
		int ioi = 0;
		for(int i=0; i<str.size()-2; i++){
			if(str[i]=='J'&&str[i+1]=='O'&&str[i+2]=='I')
				joi++;
			if(str[i]=='I'&&str[i+1]=='O'&&str[i+2]=='I')
				ioi++;
		}

		cout << joi << endl;
		cout << ioi << endl;
	}

	return 0;
}

Measured memory_bytes: 0
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let a: Vec<i64> = (0..n).map(|_| input()).collect();

    let max = *a.iter().max().unwrap();
    let mut temp = 0;
    let mut r = 0;
    for i in a {
        let t = std::cmp::min(i, max - i);
        if temp < t {
            temp = t;
            r = i;
        }
    }

    print!("{}", max);
    println!(" {}", r);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, K; cin >> N >> K;
  cout << min(N%K, K-N%K) << endl;
}

Measured memory_bytes: 3600
import java.util.Scanner;
import java.util.Arrays;

public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
long n=scan.nextLong();
long k=scan.nextLong();

long a=n/k;
long b=n%k;
long c=Math.min(b,k-b);


System.out.println(c);


}
}


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

#define rep(n, i) for (int i = 0; i < (n); ++i)

using ll = long long;
using namespace std;

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

    auto i = 1;
    while ( n /= k ) ++i;
    cout << i << endl;
}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val _ = io.StdIn.readInt()
    val an: Iterator[Int] = io.StdIn.readLine().split(" ").map(_.toInt).toIterator
    var acc = an.next()
    while(an.hasNext) acc = lcm(acc, an.next())
    println(acc)
  }
  def lcm(m: Int, n: Int): Int = (m * n) / gcd(m, n)
  def gcd(x: Int, y: Int): Int = {
    var (m, n) = if (x < y) (y, x) else (x, y)
    while(n > 0) {
      val tmp = m
      m = n
      n = tmp % n
    }
    m
  }
}

Measured memory_bytes: 43968
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
int main(){
	int n;
	cin >> n;
	if (n % 2 == 0)cout << n << endl;
	else cout << 2 * n << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N, M;
    cin >> N >> M;

    int E[N][N];
    REP(i, N) REP(j, N) E[i][j] = inf;


    int a[M], b[M];
    REP(i, M) {
        cin >> a[i] >> b[i];
        --a[i]; --b[i];
        E[a[i]][b[i]] = 1;
        E[b[i]][a[i]] = 1;
    }

    int ans = 0;
    REP(l, M) {
        int tmp[N][N];
        REP(i, N) REP(j, N) {
            tmp[i][j] = E[i][j];
        }
        tmp[a[l]][b[l]] = inf;
        tmp[b[l]][a[l]] = inf;

        REP(k, N) REP(i, N) REP(j, N) {
            tmp[i][j] = min(tmp[i][j], tmp[i][k] + tmp[k][j]);
        }

        bool f = false;
        REP(i, N) {
            REP(j, N) {
                if (tmp[i][j] == inf) {
                    f = true;
                    break;
                }
            }
            if (f) break;
        }
        if (f) ++ans;
    }

    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
	using namespace std;
	#define int long long int
	#define pb push_back
	const int mod=1e9+7;
	#define all(x) x.begin(),x.end()
	#define endl '\n'
	#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
	
	int32_t main(){
		IOS;
		double d,t,s;
		cin>>d>>t>>s;
		double temp = (double)d/s;
		if(t>=temp){
			cout<<"Yes"<<endl;
			
		}
		else cout<<"No"<<endl;
		return 0;
	}


Measured memory_bytes: 3684
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    int ans = 1;
    rep(i, 0, n){
        cin >> s[i];
    }
    sort(s.begin(), s.end());
    rep(i, 0, n-1){
        if(s[i] != s[i+1]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <string>

using namespace std;

typedef string::const_iterator Cursor;
bool cat(Cursor& c,Cursor& e){
    if(*c == 'm'){
        c++;
        cat(c,e);
        if(*c == 'e'){
            c++;
            cat(c,e);
            if(*c == 'w'){
                c++;
                return true;
            }
        }
        return false;
    }else{
        return true;
    }
}

int main(){
    string s;
    cin >> s;
    Cursor c = s.begin(),e = s.end();
    bool r = cat(c,e);
    if(c == e){
        cout << "Cat" << endl;
    }else{
        cout << "Rabbit" << endl;
    }
    return 0;
}

Measured memory_bytes: 1188
# -*- coding: utf-8 -*-

import sys

sys.setrecursionlimit(10 ** 6)

input_line = input()
inputs = input_line.split(' ')
N, K, C = [int(s) for s in inputs]
input_line = input()
s = list(input_line)

L = []
i = 1
k = 0
while i<=N:
    if s[i-1]=='o':
        L.append(i)
        i += (C+1)
        k += 1
        if k==K:
            break
    else:
        i += 1

R = []
i = N
k = 0
while i>0:
    if s[i-1]=='o':
        R.append(i)
        i -= (C+1)
        k += 1
        if k==K:
            break
    else:
        i -= 1
R = R[::-1]

for i in range(K):
    if L[i]==R[i]:
        print(L[i])


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

int main(){

  string str;
  cin >> str;
  int len = str.length();

  for(int i=0;i<len;i++){
    if(len==1 && str[0]=='?'){
      str[0]='D';
    }else{
      if(str[i]=='?'){
        if(i==0){
          if(str[i+1]!='P') str[i]='P';
          else str[i]='D';
        }else if(i==(len-1)){
          str[i]='D';
        }else{
          if(str[i-1]=='D' && str[i+1]!='P') str[i]='P';
          else str[i]='D';
        }
      }
    }
  }
  cout << str << endl;
}

Measured memory_bytes: 3724
#include <iostream>
#include <vector>
#include <string>

typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  ll cnt = 0;
  for(int i=0;i<n;i++){
    ll a;std::cin >> a;
    if(i%2) continue;
    if(a%2) cnt++;
  }
  std::cout << cnt << '\n';
  return 0;
}


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

int main() {
	int A, B;//A 縦のピクセル B 横のピクセル
	cin >> A >> B;
    char x;
	int C = 0;
	string F;
	while (C < B + 2) {
    	cout << "#";
		C++;
    }
	cout << endl;
	C = 0;
	for (int D = 0; D < A; D++) {
    	cin >> F;
    	cout << "#";
    	for (int E = 0; E < F.size(); E++) {
        	x = F.at(E);
        	cout << x;
        }
    	cout << "#" << endl;
    }
	while (C < B + 2) {
    	cout << "#";
		C++;
    }
    cout << endl;	
}

Measured memory_bytes: 256