akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#define Loop(var,time) for (var = 0; var < (time); var++)

char farm[105][105];
int h,w;

void dfs(int x, int y) {
    char fruit = farm[x][y];
    farm[x][y] = '.';
    if (farm[x][y + 1] == fruit) { dfs(x,y + 1); }
    if (farm[x][y - 1] == fruit) { dfs(x,y - 1); }
    if (farm[x + 1][y] == fruit) { dfs(x + 1, y); }
    if (farm[x - 1][y] == fruit) { dfs(x - 1, y); }
}
int main() {
    while(true) {
        int i,x,y;
        int area = 0;
        scanf("%d", &h);
        scanf("%d", &w);
        if (h == 0 && w == 0) { break; }
        Loop(i,h) {
            scanf("%s",farm[i]);
        }
        Loop(x, h) {
            Loop(y, w) {
                if (farm[x][y] != '.') {
                    dfs(x,y);
                    area++;
                }
            }
        }
        printf("%d\n", area);
    }
    return 0;
}

Measured memory_bytes: 1820
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        
            int n;
            cin>>n;
            int ar[n+1];
            for(int i=1;i<=n;++i)
            {
                cin>>ar[i];
            }
            map<int,int> mp;
            ll ans=0;
            for(int i=n;i>=1;--i)
            {
                ans=ans+mp[ar[i]+i];
                mp[i-ar[i]]++;
            }
            cout<<ans<<endl;
        
        return 0;
    }


Measured memory_bytes: 21428
#![allow(unused_imports)]
use num::integer::gcd;
use proconio::*;
use std::cmp::*;
use std::collections::VecDeque;
use std::ops::*;

const INF: i64 = 1001001001001001001;

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

   let k = n % 2 + 1;
   let mut dp = vec![vec![-INF; 4]; n + 1];
   dp[0][0] = 0;
   for i in 0..n {
      for j in 0..=k {
         dp[i + 1][j + 1] = dp[i][j];
         dp[i + 1][j] = max(
            dp[i + 1][j],
            dp[i][j] + if (i + j) % 2 == 0 { a[i] } else { 0 },
         );
      }
   }
   println!("{}", dp[n][k]);
}


Measured memory_bytes: 19612
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x7f
#define MAX_INF_VAL 0x7f7f7f7f
#define pi 3.141592653589
#define eps 1e-10
//#define p 2173412051LL
//#define sz 2

using namespace std;

char s[ 110 ][ 110 ];
int f[ 110 ][ 110 ];

int main() {
	int n, m;
	scanf( "%d%d", &n, &m );
	for( int i = 1; i <= n; ++i )
		scanf( "%s", s[ i ] + 1 );
	memset( f, MAX_INF, sizeof( f ) );
	f[ 1 ][ 1 ] = s[ 1 ][ 1 ] == '.'? 0: 1;
	for( int i = 2; i <= m; ++i ) {
		f[ 1 ][ i ] = f[ 1 ][ i - 1 ];
		if( s[ 1 ][ i ] == '#' && s[ 1 ][ i - 1 ] == '.' )
			++f[ 1 ][ i ];
	}
	for( int i = 2; i <= n; ++i ) {
		f[ i ][ 1 ] = f[ i - 1 ][ 1 ];
		if( s[ i ][ 1 ] == '#' && s[ i - 1 ][ 1 ] == '.' )
			++f[ i ][ 1 ];
	}
	for( int i = 2; i <= n; ++i )
		for( int j = 2; j <= m; ++j )
			if( s[ i ][ j ] == '.' )
				f[ i ][ j ] = min( f[ i - 1 ][ j ], f[ i ][ j - 1 ] );
			else {
				if( s[ i - 1 ][ j ] == '#' )
					f[ i ][ j ] = min( f[ i - 1 ][ j ], f[ i ][ j ] );
				else
					f[ i ][ j ] = min( f[ i - 1 ][ j ] + 1, f[ i ][ j ] );
				if( s[ i ][ j - 1 ] == '#' )
					f[ i ][ j ] = min( f[ i ][ j - 1 ], f[ i ][ j ] );
				else
					f[ i ][ j ] = min( f[ i ][ j - 1 ] + 1, f[ i ][ j ] );
			}
	printf( "%d", f[ n ][ m ] );
	return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
  int i;
  int R;
  long cnt = 0;
  scanf("%d", &R);
  printf("%f\n", (double)R*2*3.141592);
  return 0;
}


Measured memory_bytes: 2240
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
    vector<int> vec(3);

    for (int i = 0; i < 3; i++) {
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());

    cout << vec.at(0)+vec.at(1) << endl;

}


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

int main() {
  int H, W;

  cin >> H >> W;
  vector<string> line(H);

  for (int i = 0; i < H; i++) {
    cin >> line.at(i);
  }

  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }
  cout << endl;

  for (int i = 0; i < H; i++) {
    cout << "#" << line.at(i) << "#" << endl;
  }

  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            line.pop();
            line
        }
    )
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let iter = line.split_whitespace();
            iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    )
}

fn solve(a: u64, b: u64, c: u64, d: u64) -> bool {
    use std::collections::HashMap;

    if a < b {
        return false
    }

    if d < b {
        return false
    }

    if b-1 <= c {
        return true
    }

    let mut m = HashMap::new();
    m.insert(a, true);

    let mut na = a;

    let dmodb = if d % b == 0 { d } else {d % b};
    let mut r = na % b;

    while true {
        if r > c {
            return false
        }

        let na = r + (((c - r) / dmodb ) + 1) * dmodb;
        if na > c && na < b {
            return false
        }
        if m.contains_key(&na) {
            return true
        }

        m.insert(na, true);
        r = na % b;
    }

    unreachable!()
}

fn main() {
    let n = parse_line!(usize);
    let mut ss = Vec::new();

    for _ in 0..n {
        ss.push(parse_vec!(u64));
    }

    for v in ss {
        println!("{}", if solve(v[0], v[1], v[2], v[3]) { "Yes" } else { "No" });
    }
}

#[test]
fn solve_test() {
    assert_eq!(solve(9,7,5,9), false);
    assert_eq!(solve(7,7,5,7), true);
    assert_eq!(solve(13,7,5,7), false);
    assert_eq!(solve(7,2,1,3), true);
    assert_eq!(solve(1000000000000000000, 17, 14, 999999999999999985), false);
    assert_eq!(solve(1000000000000000000, 17, 15, 999999999999999985), true);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    LL N,A,B;cin >> N >> A >> B;
    LL tmp = A+B;
    LL num = N/tmp;
    LL tmp2 = num*tmp;
    LL tmp3 = N - tmp2;
    LL tmp4 = 0;
    if(tmp3 > A)tmp4 = A;
    else tmp4 = tmp3;

    cout << (num * A) + tmp4 << endl; 

}


Measured memory_bytes: 256
def main():
    s = list(map(int,raw_input()))
    flag = True
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            flag = False
    if flag == True:
        print("Good")
    else:
        print("Bad")





if __name__=="__main__":
    main()


Measured memory_bytes: 2568
h = int(input())
w = int(input())
n = int(input())

if h <= w:
    if n % w == 0:
        print(int(n / w))
    else:
        print(int(n // w) + 1)
else:
    if n % h == 0:
        print(int(n / h))
    else:
        print(int(n / h) + 1)


Measured memory_bytes: 2940
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int N;
  ll T;
  cin >> N >> T;
  ll a[N];
  rep(i, N){
    cin >> a[i];
  }
  ll ans = 0;
  rep(i, N-1){
    ans += min(a[i+1] - a[i], T);
  }
  ans += T;
  cout << ans << endl;
    
    
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <set>
using namespace std;

const int MAX_N=10000;
string s;

int main(){
	cin >> s;
	for(int i=0;i<s.length();i++) if(s[i]=='9'){
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
vvi g;
int v[1010];
int dp[1010];
bitset<5050> bs[2];
bool pos;
int ds(int u) {
	if(dp[u] != -1) return dp[u];
	for(int i=0;i<g[u].size();i++) {
		ds(g[u][i]);
	}
	bs[0].reset();bs[1].reset();
	bs[0].set(0);
	int cu = 1;
	int tot = 0;
	for(int i=0;i<g[u].size();i++) {
		bs[cu].reset();
		int a = ds(g[u][i]),b = v[g[u][i]];
		tot += a+b;
		for(int j=0;j<=v[u];j++) {
			if((j-a >= 0) && bs[1-cu][j-a]) {bs[cu].set(j);}
			if((j-b >= 0) && bs[1-cu][j-b]) {bs[cu].set(j);}
		}
		cu = 1-cu;
	}
	cu = 1-cu;
	int mi = -1;
	for(int i=v[u];i>=0;i--) {
		if(bs[cu][i]) {mi = i;break;}
	}
	if(mi == -1) {pos = false;return dp[u] = 9999;}
	return dp[u] = tot-mi;
}
int main() {
	int n;
	scanf("%d ",&n);
	g.assign(n,vi());
	memset(dp,-1,sizeof(dp));
	pos = true;
	for(int i=1;i<n;i++) {
		int t;
		scanf("%d ",&t);t--;
		g[t].push_back(i);
	}
	for(int i=0;i<n;i++) {
		scanf("%d ",&v[i]);
	}
	ds(0);
	printf("%sPOSSIBLE\n",pos?"":"IM");
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define MAXN 100100
#define pii pair<int, int>
#define pb push_back
typedef long long ll;

using namespace std;

ll n, k, dp[110][MAXN], pre[110][MAXN], a[MAXN], mod = 1e9 + 7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> a[i];
    dp[0][0] = 1;
	for(int i = 0; i <= k; i++)
		pre[0][i] = 1;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= k; j++){
			dp[i][j] = mod + pre[i - 1][j] - pre[i - 1][max(0LL, j - a[i - 1])] + dp[i - 1][max(0LL, j - a[i - 1])];
			pre[i][j] = dp[i][j];
			if(j > 0) pre[i][j] += pre[i][j - 1];
			pre[i][j] %= mod;
			dp[i][j] %= mod;
		}
	}
	cout << dp[n][k];
}

Measured memory_bytes: 159232
#include<cstdio>
#include<queue>
#define ll long long
using namespace std;
priority_queue<int>q;
ll ans;
int n,m;
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1,x;i<=n;i++)
		scanf("%d",&x),ans+=(ll)x,q.push(x);
	while(m--)
	{
		int temp=q.top();
		q.pop();
		q.push(temp>>1);
		ans-=temp-(temp>>1);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 892
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
 
class Program{
    static void Main(){
        int n = int.Parse(Console.ReadLine());
        string[] inputs = Console.ReadLine().Split(' ');
        int[] A = new int[n];
        for (int i = 0; i < n; i++)
        {
            A[i] = int.Parse(inputs[i]);
        }
        InsertionSort(ref A, n);
    }

    static void InsertionSort(ref int[] arr, int n){
        for (int i = 0; i < n; i++)
        {
            int tmp = arr[i];
            int j = i - 1;
            while(j >= 0 && arr[j] > tmp){
                arr[j + 1] = arr[j];
                j--;
            }
            arr[j + 1] = tmp;
            
            Console.WriteLine(String.Join(" ", arr.Select(val => val.ToString()).ToArray()));
        }
    }
}

Measured memory_bytes: 9552
// Problem : F - Range Set Query
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

#define maxn 1010000
#define maxb 1010
int aa[maxn], cnt[maxn], belong[maxn];
int n, m, sz, bnum, now, ans[maxn];
struct query {
	int l, r, id;
} q[maxn];

int cmp(query a, query b) {
	return (belong[a.l] ^ belong[b.l]) ? belong[a.l] < belong[b.l] : ((belong[a.l] & 1) ? a.r < b.r : a.r > b.r);
}
#define isdigit(x) ((x) >= '0' && (x) <= '9')
int read() {
	int res = 0;
	char c = getchar();
	while(!isdigit(c)) c = getchar();
	while(isdigit(c)) res = (res << 1) + (res << 3) + c - 48, c = getchar();
	return res;
}
void printi(int x) {
	if(x / 10) printi(x / 10);
	putchar(x % 10 + '0');
}

int main() {
	scanf("%d%d", &n,&m);
	sz = sqrt(n);
	bnum = ceil((double)n / sz);
	for(int i = 1; i <= bnum; ++i) 
		for(int j = (i - 1) * sz + 1; j <= i * sz; ++j) {
			belong[j] = i;
		}
	for(int i = 1; i <= n; ++i) aa[i] = read(); 
	for(int i = 1; i <= m; ++i) {
		q[i].l = read(), q[i].r = read();
		q[i].id = i;
	}
	sort(q + 1, q + m + 1, cmp);
	int l = 1, r = 0;
	for(int i = 1; i <= m; ++i) {
		int ql = q[i].l, qr = q[i].r;
		while(l < ql) now -= !--cnt[aa[l++]];
		while(l > ql) now += !cnt[aa[--l]]++;
		while(r < qr) now += !cnt[aa[++r]]++;
		while(r > qr) now -= !--cnt[aa[r--]];
		ans[q[i].id] = now;
	}
	for(int i = 1; i <= m; ++i) printi(ans[i]), putchar('\n');
	return 0;
}


Measured memory_bytes: 17408
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
typedef long long LL;

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

	if (x % 2 == 0) {
		std::cout << x << std::endl;
	}
	else {
		std::cout << x * 2 << std::endl;
	}

}

Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<map>
#include<unordered_map>
#include<set>
#include<algorithm>
#include <cstdlib>
#include<unordered_set>
#include<cmath>
#include<list>
#include<functional>
#include<cmath>
#include <iostream>
#include <fstream>
using namespace std;

int main() {
	int n;
	cin >> n;
	int len = 2 * n;
	vector<int> nums(len);
	for (int i = 0; i < len; i++) {
		cin >> nums[i];
	}
	sort(nums.begin(),nums.end());
	int total = 0;
	for (int i = 0; i < n; i++) {
		total += nums[2 * i];
	}
	cout << total << endl;
	return 0;
}


Measured memory_bytes: 256
import kotlin.math.ceil
import kotlin.system.exitProcess

fun main(args: Array<String>) {
    abc105B(args)
}

fun abc105B(args: Array<String>) {
    val N = readLine()!!.toInt() // 1 <= N <= 100 dollars
    val priceCake = 4
    val priceDonut = 7

    val upperLimitOfCake = ceil(N.toDouble() / priceCake).toInt()
    val upperLimitOfDonut = ceil(N.toDouble() / priceDonut).toInt()

    for (cake in 0..upperLimitOfCake) {
        for (donut in 0..upperLimitOfDonut) {
            if (cake*priceCake + donut*priceDonut == N) {
                print("Yes")
                exitProcess(0)
            }
        }
    }
    print("No")
}


Measured memory_bytes: 34568
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        sc.close();
        if(s.equals("Sunny")){
            System.out.println("Cloudy");
        } else if (s.equals("Cloudy")){
            System.out.println("Rainy");
        } else {
            System.out.println("Sunny");
        }
    }
}



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

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

  long long n, k, ans=0;
  string s;
  cin >> n >> k >> s;
  vector<long long> vec;
  long long cnt=0;
  s+='.';
  for(int i=0;i<n;i++){
    cnt++;
    if(s[i+1] != s[i]){
      vec.push_back(cnt);
      cnt=0;
    }else{
      ans++;
    }
  }
  long long ans1=0, ans2=0, kk=k;
  for(size_t i=1;i<vec.size();i+=2){
    if(i == vec.size()-1){
      ans1++;
    }else{
      ans1+=2;
    }
    kk--;
    if(kk==0) break;
  }
  kk=k;
  for(size_t i=0;i<vec.size();i+=2){
    if(i == vec.size()-1 or i == 0){
      ans2++;
    }else{
      ans2+=2;
    }
    kk--;
    if(kk==0) break;
  }
  cout << min(n-1, ans+max(ans1, ans2)) << endl;
  return 0;
}


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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	LL n;
	cin >> n;
	vector<int> v;
	while (n) v.pb(n % 10), n /= 10;
	reverse(ALL(v));
	int ans = 0;
	int cur = SZ(v) * 9;
	for (auto u : v)
	{
		cur -= 9;
		chkmax(ans, u - 1 + cur);
		cur += u;
	}
	chkmax(ans, cur);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
// writer: w33z8kqrqk8zzzx33
#include <bits/stdc++.h>
using namespace std;
 
#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

struct matr {
    int aray[50][50];
    void init() {
        rep(i, 50) rep(j, 50) aray[i][j] = 0;
    }
    matr mult(const matr& o) {
        matr ans; ans.init();
        rep(i, 50) rep(j, 50) rep(k, 50) ans.aray[i][k] = (ans.aray[i][k] + 1ll*aray[i][j]*o.aray[j][k]) % MOD;
        return ans;
    }
};

matr pow(const matr& b, const ll& e) {
    matr ans;
    if(e == 0) {
        ans.init();
        rep(i, 50) ans.aray[i][i] = 1;
        return ans;
    }
    if(e == 1) return b;
    matr hv = pow(b, e>>1);
    ans = hv.mult(hv);
    if(e&1) { hv = ans; ans = hv.mult(b); }
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; ll k; cin >> n >> k;
    matr re; re.init();
    rep(i, n) rep(j, n) cin >> re.aray[i][j];
    matr v = pow(re, k);
    int ans = 0;
    rep(i, 50) rep(j, 50) ans = (ans + v.aray[i][j]) % MOD;
    cout << ans << endl;
}



Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define inf 0x3f3f3f3f
const int maxn = 5e6+100;
int tree[maxn][30];
bool flag[maxn];
int tot;
void insertt(string s)
{
   int len=s.size();
   int root=0;
   for(int i=0;i<len;i++)
   {
       int id=s[i]-'a';
       if(!tree[root][id]) 
	   tree[root][id]=++tot;
       root=tree[root][id];
   }
   flag[root]=true;
}
bool findt(string s)
{
    int len=s.size();
    int root=0;
    for(int i=0;i<len;i++)
    {
        int id=s[i]-'a';
        if(!tree[root][id]) 
		return true;
        root=tree[root][id];
    }
    if(flag[root]) 
	return false;
    else return true;
}
string s;
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++){
    	cin>>s;
    	if(findt(s)){
    		ans++;
    		insertt(s);
		}
	} 
	cout<<ans;
    return 0;
}

Measured memory_bytes: 165476
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 ff=unix

DICT_SIZE = 1000003
REHASH = 10007
DICT = [None] * DICT_SIZE


def hash_value(S):
    M = 257
    val = 0
    for c in S:
        val = (val * M + ord(c)) % DICT_SIZE
    return val


def insert(s):
    h = hash_value(s)
    while DICT[h] is not None:
        if DICT[h] == s:
            return
        h = (h + REHASH) % DICT_SIZE
    DICT[h] = s


def find(s):
    h = hash_value(s)
    while True:
        if DICT[h] is None:
            return 'no'
        elif DICT[h] == s:
            return 'yes'
        h = (h + REHASH) % DICT_SIZE


if __name__ == "__main__":

    n = int(input())

    for _ in range(n):
        cmd, s = input().split()
        if cmd == 'insert':
            insert(s)
        else:
            print(find(s))



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

int main()
{
  long long int M=1000000007;
  
  int n,m;
  cin>>n>>m;
  int k[m];
  for(int i=0;i<m;i++)
  {
  	cin>>k[i];
  }
  long long int ans=1;
  long long int dp[n+1];
  int b=0;
  dp[0]=1;
  dp[1]=1;
  for(int i=2;i<=n;i++)
    dp[i]=(dp[i-1]+dp[i-2])%M;
  int a;
  for(int i=0;i<m;i++)
  {
   a=k[i];
    if(a==b)
    {
      cout<<"0";
      return 0;
    }
    ans*=dp[a-1-b]%M;
    ans%=M;
    b=a+1;
  }
  ans*=dp[n-b]%M;
  ans%=M;
  cout<<ans;
}
  
    

Measured memory_bytes: 1408
#include <stdio.h>

int main(void) {
	int n,p[n],i,c;
	c=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&p[i]);
	}
	for(i=1;i<n-1;i++){
		if(p[i]>p[i+1]&&p[i]<p[i-1]){
			c++;
		}else{
			if(p[i]<p[i+1]&&p[i]>p[i-1]){
			c++;
		}
		}
	}
	printf("%d",c);
	
	// your code goes here
	return 0;
}


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, k, p;
string s, t;
ld w;

// <------------- Implement Functions Here ----------> //

// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>s;
	n = s.length();
	ll cou = 1;
	for(ll i=1;i<n;i++) {
		while(i<n && s[i]==s[i-1]) i++;
		if(i < n)
		cou++;
	}
	cout<<cou-1;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 3752
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int main() {
    long long A;
    long long B;
    long long C;
    long long D;

    cin >> A >> B >> C >> D;

    cout << max(max(B*C, A*D), max(A*C, B*D)) << endl;

    return 0;
}

Measured memory_bytes: 3564
while True:
    m, f, r = map(int, input().split())
    
    if m == -1 and f == -1 and r == -1:
        break
        
    if m == -1 or f == -1:
        print("F")
    elif m + f >= 80:
        print("A")
    elif m + f >= 65:
        print("B");
    elif m + f >= 50:
        print("C")
    elif m + f >= 30:
      
        if r >= 50:
            print("C")
        else:
            print("D")
            
    else:
        print("F")


Measured memory_bytes: 5596
def f(X):
    res = 0
    
    if X%4 in [1, 2]:
        res += 1
    
    p = 4
    
    for i in range(50):
        if X%p>=p//2 and (X%p-p//2+1)%2==1:
            res += 2**(i+1)
        
        p *= 2
        
    return res

A, B = map(int, input().split())

if A==0:
    print(f(B))
else:
    print(f(B)^f(A-1))

Measured memory_bytes: 38384
#define first f
#define second s
#define ll long long
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#include <bits/stdc++.h>
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=2005;
const int MOD=1e9+7;
const double PI=acos(-1);
const double e=2.718281828459;


int main()
{
    int n;
    cin>>n;
    printf("%d\n",(n+1)/2);
    return 0;
}


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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
        #define eprintf(...) 42
#endif

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

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

  vi a(n);
  rep(i, n) cin >> a[i];

  int ans = -1;
  rep(i, n-1) if(a[i]+a[i+1] >= l) ans = i;

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

  cout << "Possible" << endl;
  rep(i, ans){
    cout << i+1 << endl;
  }
  for(int i = n-2; i >= ans; i--){
    cout << i+1 << endl;
  }

  return 0;
}


Measured memory_bytes: 1152
/* Atcoder abc169a
 * See tasks at: https://atcoder.jp/contests/abc169/tasks/abc169_a
 */
#include <bits/stdc++.h>

#define until(symbol, max) for (int symbol = 0; (symbol) < (max); (symbol)++)

using namespace std;
using ll = long long;
int main()
{
    int a, b;
    cin >> a >> b;
    cout << a * b;
    return 0;
}


Measured memory_bytes: 3612
using System;

namespace AOJ.ITP
{
    public class OfficialHouse
    {
        public static void Main()
        {
            // 入居状況を表す配列を用意
            // house[棟, 階, 部屋]
            // 1棟1階1番目の部屋→house[0, 0, 0]
            int[, ,] house = new int[4, 3, 10];

            int cnt = int.Parse(Console.ReadLine());
            for (int i = 0; i < cnt; i++)
            {
                var input = Console.ReadLine().Split(' ');
                int bldg = int.Parse(input[0]) - 1;
                int floor = int.Parse(input[1]) - 1;
                int room = int.Parse(input[2]) - 1;
                int p = int.Parse(input[3]);

                house[bldg, floor, room] += p;
            }

            // 出力
            string split = "####################";
            for (int bldg = 0; bldg < 4; bldg++)
            {
                for (int floor = 0; floor < 3; floor++)
                {
                    string output = "";
                    for (int room = 0; room < 10; room++)
                    {
                        output += " " + house[bldg, floor, room];
                    }
                    Console.WriteLine(output);
                }
                // ループ最終回以外は区切りを出力
                if (bldg < 3) { Console.WriteLine(split); }
            }
        }
    }
}

Measured memory_bytes: 7668
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)	
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<string> vs;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
Def inf = sizeof(Def) == sizeof(ll) ? 2e18 : 1e9+10;
vvi G,in,t;
int n,m,N;
bool h;
vvi data;
void dfs(int x,int y,int d,int c){
//	data[c][0]=min(data[c][0],y);
//	data[c][1]=max(data[c][1],y);
	data[c][2]+=y;
	data[c][3]++;
	
	t[x][y]=c;
	in[x][y]=-1;
	rep(i,4){
		int nx=x+dx[i];
		int ny=y+dy[i];
		if(nx<0||ny<0||nx>=n||ny>=m)continue;
		if(in[nx][ny]==d){
			dfs(nx,ny,d,c);
		}
	}
}
pii dfs2(int a){
	int sum=data[a][2],co=data[a][3];
	rep(i,N)if(G[a][i]){
		pii tmp=dfs2(i);
		sum+=tmp.first;
		co+=tmp.second;
	}
	//  sum/co
//	cout<<sum<<" "<<co<<endl;
	if(!((2*data[a][0]-1)*co<2*sum&&2*sum<(2*data[a][1]+1)*co))h=false;
	return {sum,co};
}
int main(){
	while(cin>>m>>n,n){
		in=vvi(n,vi(m));
		data=vvi(0);
		rep(i,n)rep(j,m){
			char c;
			cin>>c;
			if(c=='.')in[i][j]=-1;
			else in[i][j]=c-'0';
		}
		t=in;
		int c=0;
		rep(i,n)rep(j,m)if(in[i][j]+1){
			data.pb({inf,-inf,0,0});
			dfs(i,j,in[i][j],c++);
		}
//		show2d(t);
		N=data.size();
		G=vvi(N,vi(N));
		rep(i,n-1)rep(j,m){
			int x=i+1,y=j;
			if(t[i][j]+1&&t[x][y]+1&&t[i][j]!=t[x][y]){
				G[t[x][y]][t[i][j]]=1;
				data[t[i][j]][0]=min(data[t[i][j]][0],j);
				data[t[i][j]][1]=max(data[t[i][j]][1],j);
			}
		}
		rep(i,m)if(t[n-1][i]+1){
			data[t[n-1][i]][0]=min(data[t[n-1][i]][0],i);
			data[t[n-1][i]][1]=max(data[t[n-1][i]][1],i);
		}
//		show2d(G);
		h=true;
		rep(i,N){
			dfs2(i);
		}
		if(h)cout<<"STABLE"<<endl;
		else cout<<"UNSTABLE"<<endl;
	}
}



Measured memory_bytes: 3160
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <functional>
 
using namespace std;

int main() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while(true){
        c-=b;
        if (c <= 0){
            cout<<"Yes";
            return 0;
        }
        
        a-=d;
        if (a<= 0){
            cout<<"No";
            return 0;
        }
    }
}

Measured memory_bytes: 3636
#include <cstdio>

#define min(a, b) (a < b ? a : b)

int main()
{
    int no_of_elements;
    scanf("%d", &no_of_elements);

    const int oo = 1e9 + 9;
    int sum = 0, min_non_multiple_10 = oo;

    while(no_of_elements--)
    {
        int element;
        scanf("%d", &element);

        sum += element;

        if(element%10 != 0)
            min_non_multiple_10 = min(min_non_multiple_10, element);
    }

    if(sum%10 == 0)
        printf("%d\n", min_non_multiple_10 == oo ? 0 : sum - min_non_multiple_10);
    else
        printf("%d\n", sum);

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  int64_t Y;
  cin >> Y;

  int a = -1;
  int b = -1;
  int c = -1;

  for(int i = 0; i <= N; i++){
    for(int j = 0; j + i <= N; j++){
      int k = (N - i -j);
      int sum = 10000 * i + 5000 * j + 1000 * k;
      if(sum == Y){
        a = i;
        b = j;
        c = k;
      }
    }
  }
 cout << a << " " << b << " " << c << endl;
  
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>
int N,K,cnt;
int A[101][101];
int d[101], d_chk[101], sunuke[101];
int main(void) {
	scanf("%d %d", &N, &K);
	for(int j = 0; j < K; j++){
		scanf("%d", &d[j]);
		for(int i = 0; i < d[j]; i++){
			scanf("%d", &A[j][i]);
		}
	}

	for(int j = 0; j < K; j++){
		for(int i = 0; i < d[j]; i++){
			int tmp = A[j][i];
			sunuke[tmp]++;
		}

	}

	for(int l = 1; l <= N; l++){
		if(sunuke[l] == 0){
			cnt++;
		}
	}

	printf("%d", cnt);

	return 0;
}

Measured memory_bytes: 1776
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String n = sc.next();
		
		// 計算
		String result = "No";
		long sum = 0;
		for(int i = 0; i < n.length(); i++){
		    int a = n.charAt(i)-'0';
		    sum += a;
		}
		if(sum%9 == 0) result = "Yes";
		
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


Measured memory_bytes: 29548
def main():
    a, b, c = map(int, input().split(" "))
 
    x = c - a - b

    if x > 0:

        y = x * x - 4 * a * b

        if y > 0:

            print("Yes")

        else:
            print("No")

    else:

        print("No")

main()



Measured memory_bytes: 38384
import Data.Array
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine

getIntList = readIntList <$> BS.getLine

temp :: Int -> Int -> Int -> Float
temp a h t = abs (((fromIntegral a) :: Float) - (((fromIntegral t) :: Float) - ((fromIntegral h) :: Float) * 0.006))

calc :: Array Int Int -> Int -> Int -> Float -> Int -> Int -> Int
calc hs t a a' 1 n'
  | a'' < a' = 1
  | otherwise = n'
  where
    a'' = temp a (hs ! 1) t
calc hs t a (-1) n (-1)
  | a'' == 0 = n
  | otherwise = calc hs t a a'' (n -1) n
  where
    a'' = temp a (hs ! n) t
calc hs t a a' n n'
  | a'' == 0 = n
  | a'' < a' = calc hs t a a'' (n -1) n
  | otherwise = calc hs t a a' (n -1) n'
  where
    a'' = temp a (hs ! n) t

main = do
  n <- getInt
  [t, a] <- getIntList
  hs <- getIntList
  let hs' = listArray (1, length hs) hs
  print $ calc hs' t a (-1 :: Float) n (-1)


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll r , d , x2;
  	cin >> r >> d >> x2;
  	for(int i = 1 ; i <= 10 ; i++){
		cout << r * x2 - d << endl;
      	x2 = r * x2 - d;
    }
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();
        String s = input + input;

        String p = br.readLine();

        if(s.indexOf(p) != -1){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 24292
#include<stdio.h>
#include<string.h>
int main(){
	int i,j,n,h;
	char S,str[101];
	int A=0,B=0;
	for(i=0;scanf("%s",str)&&str[0]!='0';i++,A=0,B=0){
		if(i%3+1==3)S='A';
		h=strlen(str);
		for(j=1;j<h;j++){
			if(str[j]=='A')A++;
			else B++;
		}
		if(B>A)B++;
		else A++;
		printf("%d %d\n",A,B);
	}
	exit(0);
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
#define NUM ((long long)1000000007)
#define int long long

using namespace std;

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

    int n;
    cin >> n;
    if (n >= 1000)
    {
        cout << "ABD" << endl;
    }
    else
    {
        cout << "ABC" << endl;
    }

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  long long n;
  cin >> n;
  if(n%2==1){
    cout << 0 << endl;
    exit(0);
  }
  long long count = 0;
  n/=2;
  while(n>=5){
    n/=5;
    count+=n;
  }
  cout << count << endl;
  return 0;
}

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

int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    vector<int> water, suger;
    //水の量の全列挙
    for(int i = 0; 100*i <= F; i++){
        for(int j = 0; 100*j <= F; j++){
            if(100*A*i + 100*B*j <= F){
                water.push_back(100*A*i + 100*B*j);
            }
        }
    }
    //砂糖の量の全列挙
    rep(i, F){
        rep(j, F){
            if(C*i + D*j <= F){
                suger.push_back(C*i + D*j);
            }
        }
    }
    int ans1 = 0, ans2 = 0;
    double max = -1;
    double con = -1;
    for(int w : water){
        for(int s : suger){
            if(w + s <= F && w != 0 && s <= w*E / 100){
                con = 100.0*s / (w+s);
                if(max < con){
                    max = con;
                    ans1 = w + s;
                    ans2 = s;
                }
            }
        }
    }
    cout << ans1 << " " << ans2;
}


Measured memory_bytes: 1400
import java.util.ArrayList;
import java.util.Scanner;




class Main{


	static	ArrayList<Integer> one ;
	static	ArrayList<Integer> two ;
	static	ArrayList<Integer> three ;
	static	ArrayList<Integer> four ;
	static long pow = 1000000007;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);			//文字の入力
		int n =sc.nextInt();
		long p = 1;
		for(long i = 1;i <= n;i++){
			p *= i;
			p %= pow;
		}
		System.out.println(p);
	}
	
	
	
}

class Pair implements Comparable{
	Character from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}




Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
int main()
{

    int a, b, k;
    cin >> k >> a >> b;
    rep(i, a, b + 1)
    {
        if (i % k == 0)
        {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

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

using namespace std;

const int N = 1234567;

vector <int> g[N];
int a[N];
int k;

int ans;

int dfs(int v) {
  int sz = g[v].size();
  int steps = 0;
  for (int j = 0; j < sz; j++) {
    int u = g[v][j];
    int cur = dfs(u);
    steps = max(steps, cur + 1);
  }
  if (steps == k - 1 && a[v] != 0) {
    a[v] = 0;
    steps = -1;
    ans++;
  }
  return steps;
}

int main() {
  int n;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    a[i]--;
  }
  ans = 0;
  if (a[0] != 0) {
    a[0] = 0;
    ans++;
  }
  for (int i = 1; i < n; i++) {
    g[a[i]].push_back(i);
  }
  dfs(0);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 38144
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define per(i,n) for (int i = (n)-1; i >=0; --i)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;

int main(){
    int n,x;
    cin>>n>>x;
    
    int sum = 0, mmin = 1200, m;
    rep(i,n){
        cin>>m;
        sum += m;
        mmin = min(mmin, m);
    }
    x -= sum;
    
    cout << n + x/mmin << endl;
    return 0;
}

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

using namespace std;

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

	int n = s.size();

	string x = s.substr(0, (n - 1) / 2);
	string y = s.substr((n + 3) / 2 - 1, n - (n + 3) / 2 + 1);

	auto same = [&] (string s) {
		string t = s;
		reverse(t.begin(), t.end());
		return s == t;
	};

	if(same(s) && same(x) && same(y)) {
		cout << "Yes" << '\n';
	} else {
		cout << "No" << '\n';
	}
	return 0;
}


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

typedef long long ll;

int main(){
  int n; cin >> n;
  ll a[n];
  int tcount=0, fcount=0;
  for(int i=0; i<n; i++){
    cin >> a[i];
    if(a[i]%4==0) fcount++;
    else if(a[i]%2==0) tcount++;
  }

  int rest = n-tcount-fcount;
  int candidate = tcount>0 ? fcount : fcount+1;
  if(rest>candidate) cout << "No" << endl;
  else cout << "Yes" << endl;

  return 0;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pll, pii> P;
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int main() {
	ll S; cin >> S;
	
	ll x1 = 0, y1 = 0;
	ll x2 = 1e9, y3 = (S + x2 - 1) / x2;
	ll x3 = 1, y2 = x2*y3 - S;
	
	printf("%lld %lld %lld %lld %lld %lld\n", x1, y1, x2, y2, x3, y3);
	
	return 0;
}


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

int main(){
  int n,x;
  cin >> n >> x;
  
  vector<int> l(n);
  
  for(int i=0;i<n;i++){
    cin >> l[i];
  }
  
  int ans = 1;
  int kyo = 0;
  for(int i=0;i<n;i++){
    kyo += l[i];
    if(kyo<=x) ans++;
  }
  cout << ans << endl;
}

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

int main(){
    
    string S;
    cin>>S;
    int N=S.size();
    vector<int> T(N+1,0);
    long long int ans=0;
    for(int i=0;i<N;i++){
        if(S[i]=='B') T[i+1]=T[i]+1;
        else{
            T[i+1]=T[i];
            ans+=T[i+1];
    }
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 1412
__author__ = 'Gen'

n = int(raw_input(""))
for i in xrange(0, n):
    text = raw_input("")
    found = [text]
    count = 1
    rev = [(1, 1), (-1, 1), (1, -1), (-1, -1)]
    for i in xrange(0, len(text)):
        for r in rev:
            if text[0:i][::r[0]] + text[i:len(text)][::r[1]] not in found:
                count += 1
                found.append(text[0:i][::r[0]] + text[i:len(text)][::r[1]])
            if text[i:len(text)][::r[0]] + text[0:i][::r[1]] not in found:
                count += 1
                found.append(text[i:len(text)][::r[0]] + text[0:i][::r[1]])
    print count

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<long long> h(n);
  for (auto&& e : h) {
    cin >> e;
  }

  vector<long long> cost(n);
  cost[1] = abs(h[1] - h[0]);
  for (int i = 2; i < n; ++i) {
    long long tmpCost = 1e18;
    int jEnd = min(i, k);
    for (int j = 1; j <= jEnd; ++j) {
      long long c = cost[i - j] + abs(h[i] - h[i - j]);
      tmpCost = min(tmpCost, c);
    }
    cost[i] = tmpCost;
  }

  cout << cost[n - 1] << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>

int comp(const void *a, const void *b){
  return *(int*)a - *(int*)b;
}

int main(){
  int n;
  int i;
  int a[128];
  int k = 1;
  
  scanf("%d", &n);
  
  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }
  
  qsort(a, n, sizeof(int), comp);
  
  for(i = n - 1; i > 0; i--){
    if(a[i - 1] < a[i])
      k++;
  }
  
  printf("%d\n", k);
  return 0;
}

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

int main(void){
    int a, b;
    int tmp;
    while(true){
        cin >> a >> b;
        if(a + b == 0) break;
        if(a < b){
            tmp = a;
            a = b;
            b = tmp;
        }

        //ユークリッドの互除法
        int r, c = 0; //余り、ステップ数
        while(true){
            r = a % b;
            c++;
            if(r == 0) break;
            a = b;
            b = r;
        }
        cout << b << " " << c << endl;
    }   
}



Measured memory_bytes: 3080
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair
#define X first
#define Y second

typedef pair<int, int> P;

const int h = 12;
const int w = 6;
char field[h][w];
bool check[h][w];

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
bool erase(){
	bool ret = false;
	memset(check, 0, sizeof(check));
	rep(i, h){
		rep(j, w){
			if(check[i][j]) continue;
			char c = field[i][j];
			if(c == 'O' || c == '.') continue;
			queue<P> q;
			q.push(MP(j, i));
			vector<P> bye;
			int cnt = 0;
			while(!q.empty()){
				P p = q.front();
				q.pop();

				if(check[p.Y][p.X]) continue;
				check[p.Y][p.X] = true;
				bye.push_back(p);
				cnt++;
				rep(i, 4){
					int nx = p.X + dx[i], ny = p.Y + dy[i];
					if(nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
					if(field[ny][nx] == 'O') bye.push_back(MP(nx, ny));
					if(field[ny][nx] == c) q.push(MP(nx, ny));
				}
			}
			if(cnt >= 4){
				rep(k, bye.size()){
					field[bye[k].Y][bye[k].X] = '.';
				}
				ret = true;
			}
		}
	}
	return ret;
}

void drop(){
	char next[h][w];
	rep(i, h) rep(j, w) next[i][j] = '.';
	rep(i, h){
		rep(j, w){
			if(field[i][j] != '.'){
				int y = i;
				int height = h-1;
				while(++y<h){
					if(field[y][j] != '.') height--;
				}
				next[height][j] = field[i][j];
			}
		}
	}
	memcpy(field, next, sizeof(field));
	//rep(i, h){
	//	rep(j, w) cout << field[i][j];
	//	cout << endl;
	//}
	//cout << endl;
}

int main(){
	int T;
	cin >> T;
	while(T--){
		rep(i, h) rep(j, w) cin >> field[i][j];
		int ans = 0;
		while(erase()){
			ans++;
			drop();
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1200
#include <iostream> 
#include <cstdio> 
#include <cstdlib>  
#include <algorithm> 
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include<iomanip>
#include<functional>
using namespace std;
typedef long long ll;


long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}


int main() {
    string s;
    cin >> s;
    int n = s.size() - 1;
    if (s[n] == 's') s += "es";
    else s += "s";
    cout << s << endl;
}


Measured memory_bytes: 3628