akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int K = sc.nextInt();
		sc.close();
		List<Integer> ary = new ArrayList<>();
		int flg = 1;
		while(flg <= A || flg <= B){
			if(A%flg==0&&B%flg==0) {
				ary.add(flg);
			}
			flg++;
		}
		Collections.sort(ary, Collections.reverseOrder());
		System.out.println(ary.get(K-1));
	}
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
int w[125];

int main(){
    cin>>n;
    REP(i,n)cin>>w[i];
    int ans = 1e9;
    FOR(j,1,n){
        int s1=0, s2=0;
        s1 = accumulate(w,w+j,0);
        s2 = accumulate(w+j,w+n,0);
        CHMIN(ans,abs(s1-s2));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int last = -1;
        var set = new HashSet<string>();
        for (int i = 0; i < N; i++)
        {
            string s = cin.nextString();
            if (last != -1 && last != s[0])
            {
                Console.WriteLine("No");
                return;
            }
            set.Add(s);
            last = s[s.Length - 1];
        }

        if (set.Count() != N)
        {
            Console.WriteLine("No");
            return;
        }
        Console.WriteLine("Yes");
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}



Measured memory_bytes: 11348
import math  # noqa
import bisect  # noqa
import queue  # noqa


if __name__ == '__main__':
    a, b, x = map(int, input().split())

    L = b - a + 1
    res = L // x
    if L % x != 0:
        if a % x == 0 or b % x == 0:
            res += 1
        else:
            c = b - b % x
            if a <= c:
                L = c - a + 1
                res = L // x
                if L % x != 0:
                    if a % x == 0 or c % x == 0:
                        res += 1
    print(res)


Measured memory_bytes: 38764
#include<iostream>

using namespace std;

int main(){
  int N,now,before;
  int sum = 0;
  int i = 0;
  
  cin >> N;
  
  for(i=0;i<N-1;i++){
    cin >> now;
    if(i==0){
      sum += now;
    }
    else{
      if (before < now){
        sum += before;
      }
      else{
        sum += now;
      }
    }
    before = now;
  }
  
  cout << sum+now;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

//returns 1 instead of true
//also 0 - false
inline int isPrime(const int& n){
    if(n == 2){
        return 1;
    }

    if(!(n & 1)){
        return 0;
    }

    float root = std::sqrt(n);
    for(int div = 3; div <= root; div += 2){
        if(!(n % div)){
            return 0;
        }
    }
    return 1;
}

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

    std::vector<int> vec(n);
    for(auto& e : vec){
        std::cin >> e;
    }

    int numOfPrime = 0;
    for(const auto& e : vec){
        numOfPrime += isPrime(e);
    }

    std::cout << numOfPrime << '\n';
}


Measured memory_bytes: 3096
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
#define MOD 998244353
#define ll long long
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
ll n,m,f[1000010],finv[1000010];
ll qpow(ll a,ll b){
	ll re=1;
	while(b){
		if(b&1) re=re*a%MOD;
		a=a*a%MOD;b>>=1;
	}
	return re;
}
void init(){
	ll i,len=n+m;
	f[0]=f[1]=finv[0]=finv[1]=1;
	for(i=2;i<=len;i++) f[i]=f[i-1]*i%MOD;
	finv[len]=qpow(f[len],MOD-2);
	for(i=len;i>2;i--) finv[i-1]=finv[i]*i%MOD;
}
ll C(ll y,ll x){
//	cout<<"C "<<x<<' '<<y<<' '<<f[x]<<' '<<finv[y]<<' '<<finv[x-y]<<'\n'; 
	return f[x]*finv[y]%MOD*finv[x-y]%MOD;
}
int main(){
	n=read();m=read();int i;ll ans=0;
	if(n<m) swap(n,m);
	init();
	for(i=1;i<=m;i++) (ans+=C(i,2*i)*C(n-i,n+m-2*i)%MOD)%=MOD;
	ans=ans*qpow(2*C(n,n+m)%MOD,MOD-2)%MOD;
//	cout<<ans<<'\n';
	ans=(ans+n+MOD)%MOD;
	cout<<ans;
}


Measured memory_bytes: 15872
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    s = input()
    t = input()
    if len(s)+1 == len(t) and s == t[:len(t)-1]:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()


Measured memory_bytes: 10516
n = input()
m = len(n)
dp0 = [0]*m
dp1 = [0]*m
dp1[0] = min(int(n[0])+2,11-int(n[0]))
dp0[0] = int(n[0])
for i in range(1,m):
    dp0[i] = min(dp0[i-1],dp1[i-1]) + int(n[i])
    if int(n[i]) != 9:
        dp1[i] = min(dp0[i-1]+int(n[i])+2,dp1[i-1]+min(int(n[i])+2,9-int(n[i])))
    else:
        dp1[i] = dp1[i-1]
print(min(dp0[m-1],dp1[m-1]))

Measured memory_bytes: 71512
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
  int n, k;
  cin >> n >> k;
  long long sumCount = 0;
  for (long long i = k; i <= n + 1; i++) {
    sumCount += ((n - i + 1) * i + 1) % MOD;
    sumCount %= MOD;
  }
  cout << sumCount << endl;
  return 0;
}
	

Measured memory_bytes: 3644
#include <cstdio>

using namespace std;

typedef long long lint;

int main()
{
	lint M, rd, rr, cd, cr;
	
	scanf("%lld %lld %lld %lld %lld", &M, &rd, &rr, &cd, &cr);
	
	lint nd = (100 * cd + rd - 1) / rd;
	lint nr = (100 * cr + rr - 1) / rr;
	
	printf("%lld\n", M - nd - nr >= 0 ? M - nd - nr : -1);
	
	return (0);
}

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

using namespace std;

string s;

int ans;

void solve() {
	int last = 2;
	char ch;
	for (int i = 0; i < s.size(); ++i) {
		if (last == 2) {
			ans++;
			ch = s[i];
			last = 1;
		} else {
			if (ch == s[i]) {
				last = 2;
				if (i != s.size() - 1) ans++;
				i++;
			} else {
				last = 1;
				ans++;
				ch = s[i];
			}
		}
	}
	cout << ans << endl;
}

int main() {
	cin >> s;
	solve();
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
const int maxn = 10000005;
const int mod = 998244353;
const int mx = 2e9;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    int k;
    cin >> k;
    cin >> s;
    if (s.size() <= k) {
        cout << s << endl;
    }
    else {
        s = s.substr(0, k);
        s += "...";
        cout << s << endl;
    }
}

Measured memory_bytes: 3656
#-----UnionFind-----(0-indexed)
import sys;sys.setrecursionlimit(10**9)
class UnionFind:
  def __init__(self,n):
    self.n=[-1]*n
    self.r=[0]*n
    self.siz=n
  def find_root(self,x):
    if self.n[x]<0:
      return x
    else:
      self.n[x]=self.find_root(self.n[x])
      return self.n[x]
  def unite(self,x,y):
    x=self.find_root(x)
    y=self.find_root(y)
    if x==y:return
    elif self.r[x]>self.r[y]:
      self.n[x]+=self.n[y]
      self.n[y]=x
    else:
      self.n[y]+=self.n[x]
      self.n[x]=y
      if self.r[x]==self.r[y]:
        self.r[y]+=1
    self.siz-=1
  def root_same(self,x,y):
    return self.find_root(x)==self.find_root(y)
  def count(self,x):
    return -self.n[self.find_root(x)]
  def size(self):
    return self.siz

n,m=map(int,input().split())
p=list(map(int,input().split()))
u=UnionFind(n)
for i in range(m):
  x,y=map(int,input().split())
  x-=1
  y-=1
  u.unite(x,y)
ans=0
for i in range(n):
  if u.root_same(p[i]-1,i):ans+=1
print(ans)

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


int main() {
    string s,t;
    cin >> s >> t;
    rep(i,t.length()){
        if(s==t){
            cout << "Yes" << endl;
            return 0;
        }else{
            rotate(s.begin(),s.begin()+1,s.end());
        }
    }
    cout << "No" << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	input := scanString()
	fmt.Println(check(input))
}

// example
func check(s string) (result int) {
	if s == "SUN" {
		return 7
	} else if s == "MON" {
		return 6
	} else if s == "TUE" {
		return 5
	} else if s == "WED" {
		return 4
	} else if s == "THU" {
		return 3
	} else if s == "FRI" {
		return 2
	} else {
		return 1
	}
}

func scanString() string {
	sc.Scan()

	return sc.Text()
}

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

#define pb push_back
#define fi first
#define se second
#define eb emplace_back

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

const int N = 2007;
vector<ii> vec;
ll memo[N][N];
int n;

ll solve(int l, int r) {
    if(l > r) return 0;
    ll & st = memo[l][r];
    if(st == -1) {
        st = 0;
        int p = l - 0 + (n - 1 - r);
        ll x;
        int j;
        tie(x, j) = vec[p];

        st = solve(l + 1, r) + x * ll(abs(j - l));
        st = max(st, solve(l, r-1) + x * ll(abs(j - r)));
    }
    return st;
}

int main() {
    memset(memo, -1, sizeof memo);
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;

    for(int i = 0; i < n; ++i) {
        int a; cin >> a;
        vec.eb(a, i);
    }

    sort(vec.rbegin(), vec.rend());

    cout << solve(0, n - 1) << endl;
}

Measured memory_bytes: 35280
#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;

#define INF ((i64)(1e18))
#define MOD ((i64)(1e9+7))
#define REP(i, n) for(i64 i = 0; i < (n); i++)
#define RREP(i, n) for(i64 i = (n)-1; i >= 0; i--)
#define RANGE(i, a, b) for(i64 i = (a); i < (b); i++)
#define RRANGE(i, a, b) for(i64 i = (b)-1; i >= (a); i--)
#define ALL(v) (v).begin(), (v).end()
#define SIZE(v) ((i64)(v).size())
template<class T> inline void chmax(T &a, const T &b) { if (a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if (a > b) a = b; }

i64 n, a, b, c;
vector<i64> l;

i64 dfs(vector<i64>::iterator it, i64 sa, i64 sb, i64 sc) {
  if (it == l.end()) {
    if (min({sa, sb, sc}) == 0) return INF;
    return abs(a-sa)+abs(b-sb)+abs(c-sc);
  }
  i64 val0 = dfs(it+1, sa, sb, sc);
  i64 val1 = dfs(it+1, *it+sa, sb, sc)+10;
  i64 val2 = dfs(it+1, sa, *it+sb, sc)+10;
  i64 val3 = dfs(it+1, sa, sb, *it+sc)+10;
  return min({val0, val1, val2, val3});
}

int main() {
  cin >> n >> a >> b >> c;
  l = vector<i64>(n);
  REP(i, n) cin >> l.at(i);

  cout << dfs(l.begin(), 0, 0, 0)-30 << endl;

  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    vector<long long> a(N);
    long long ans = 0;
    for(int i = 0; i < N;i++){
        cin >> a[i];
        ans ^= a[i];
    }
    for(int i = 0; i < N;i++){
        long long aans = ans;
        aans ^= a[i];
        cout << aans  << endl;
    }
    
}

Measured memory_bytes: 4756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
const int N=2e5+5; 
ll n,c,x[N],v[N],pv[N],sv[N];
priority_queue<ii> q,q2;
int main(){	
    cin>>n>>c;	
	for(int i=1;i<=n;i++)		
	cin>>x[i]>>v[i],pv[i]=pv[i-1]+v[i];	
	ll val=0;	
	for(int i=n;i>=1;i--)	
	{		
	val+=v[i],sv[i]=val;		
	q.push(ii(val-(c-x[i]),n-i+1));	
	}	
	ll res=0,p=1,mx=0;	
	for(int i=0;i<=n;i++)	
	{		
	ll c1=2ll*x[i];		
	if(i==0)			
	c1=0;				
	while(!q.empty()&&(q.top().second>n-i||c-x[n-q.top().second+1]<=x[i]))
    q.pop();		
	if(!q.empty())			
	res=max(res,pv[i]-c1+max(0ll,q.top().first));
	while(p<=n-i&&c-x[n-p+1]<=x[i])			
	q2.push(ii(sv[n-p+1]-2ll*(c-x[n-p+1]),p)),p++;		
	while(!q2.empty()&&(q2.top().second>n-i))			
	q2.pop();					
	if(!q2.empty())			
	res=max(res,pv[i]-x[i]+max(0ll,q2.top().first));		
	res=max(res,pv[i]-x[i]);			
	}	
	cout<<res<<endl;	
	return 0;
	}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
    string S, T; cin >> S >> T;
    
    int ans = 0;
    rep(i,S.size()) {
        if (S[i] != T[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3784
"""
author : halo2halo
date : 25,Oct,2019
"""

import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

S = readline().rstrip()
print()
print(abs(S.find('A')-S.rfind('Z'))+1)


Measured memory_bytes: 3500
// C++ code to print all possible
// subsequences for given array using
// recursion
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll ans=10000000;
ll cost[15];
ll arra[15][15];
ll m,x;
bool possible(vector<int> arr, int n)
{

    int i,j;
    ll fin[15]={0},cnt=0;
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            fin[j]+=arra[arr[i]][j];
        }

    }
    for(i=0;i<m;i++)
    {
        if(fin[i]>=x)
            {cnt++;}
    }
    if(cnt>=m)
        {return 1;}
    else
        return 0;





}
void printArray(vector<int> arr, int n)
{
    ll sum=0;
    for(int i=0;i<n;i++)
        sum+=cost[arr[i]];

	ans=min(ans,sum);

}

// Recursive function to print all
// possible subsequences for given array
void printSubsequences(vector<int> arr, int index,
					vector<int> subarr)
{
	// Print the subsequence when reach
	// the leaf of recursion tree
	if (index == arr.size())
	{
		int l = subarr.size();

		// Condition to avoid printing
		// empty subsequence
		if (l != 0)
        {
            if(possible(subarr,l))
                printArray(subarr, l);
        }

	}
	else
	{
		// Subsequence without including
		// the element at current index
		printSubsequences(arr, index + 1, subarr);

		subarr.push_back(arr[index]);

		// Subsequence including the element
		// at current index
		printSubsequences(arr, index + 1, subarr);
	}
	return;
}

// Driver Code
int main()
{
    ll i,j,k,l,n,a,c,d,cnt=0,pos;
    cin>>n>>m>>x;

    for(i=0;i<n;i++)
    {
        cin>>cost[i];
        for(j=0;j<m;j++)
        {
            cin>>arra[i][j];
        }
    }
    vector<int> arr(n);
    vector<int> b;
    for(i=0;i<n;i++)
    {
        arr[i]=i;
    }



	printSubsequences(arr, 0, b);
	if(ans==10000000)
        cout<<-1<<endl;
    else
        cout<<ans<<endl;

	return 0;
}

// This code is contributed by
// sanjeev2552


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

int main(){
    int price;
    int all;
    int s,g,h;
    while(1){
        s=0;
        g=0;
        h=0;
        cin >> price >> all;
        if(price == 0 && all == 0) break;
        all -= price;
        s = all/1000;
        all %= 1000;
        g = all/500;
        all %= 500;
        h = all/100;;
        cout << h << " " << g << " " << s << endl;
    }
}

Measured memory_bytes: 1160
import sys
input = sys.stdin.readline

def print_vec(vec):
    print(" ".join(map(str, vec)))

N = int(input())
A = list(map(int, input().split()))
for i in range (len (A)):
    key = A [i]
    j = i - 1
    while j >= 0 and A [j] > key:
        A [j + 1] = A [j]
        j -= 1
    A [j + 1] = key
    print_vec(A)



Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c,n,i,j,k=0;
  cin>>a>>b>>c>>n;
  ll x[n],y[n],z[n];
  for(i=0;i<n;i++) cin>>x[i]>>y[i]>>z[i],k+=(x[i]==0)+(x[i]==a-1)+(y[i]==0)+(y[i]==b-1)+(z[i]==0)+(z[i]==c-1);
  for(i=0;i<n;i++)
    for(j=i+1;j<n;j++)
      k+=((abs(x[i]-x[j])+abs(y[i]-y[j])+abs(z[i]-z[j]))==1);
  cout << 2*(a*b+b*c+c*a)+6*n-k*2 << endl;
  return 0;
}

Measured memory_bytes: 3144
import java.util.*;

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

        int N = sc.nextInt();
        
        for(int i=1; i<=999; i++){
            if(N<=111*i){
                System.out.println(111 * i);
                break;
            }
        }
    }
}

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

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

  string ans = "" ;

  while(n >26){
      
      unsigned long long par = n%26;
      
      n = n/26;

      if(par==0) n-=1;

      if(par==1) ans = 'a' + ans;
      else if(par==2)ans = 'b' + ans;
      else if(par==3) ans ='c' + ans;
      else if(par==4)ans = 'd' + ans;
      else if(par==5) ans ='e' + ans;
      else if(par==6)ans = 'f' + ans;
      else if(par==7)ans= 'g' + ans;
      else if(par==8)ans= 'h' + ans;
      else if(par==9)ans= 'i' + ans;
      else if(par==10)ans= 'j' + ans;
      else if(par==11)ans= 'k' + ans;
      else if(par==12)ans= 'l' + ans;
      else if(par==13)ans= 'm' + ans;
      else if(par==14)ans= 'n' + ans;
      else if(par==15)ans= 'o' + ans;
      else if(par==16)ans= 'p' + ans;
      else if(par==17)ans= 'q' + ans;
      else if(par==18)ans= 'r' + ans;
      else if(par==19)ans= 's' + ans;
      else if(par==20)ans= 't' + ans;
      else if(par==21)ans= 'u' + ans;
      else if(par==22)ans= 'v' + ans;
      else if(par==23)ans= 'w' + ans;
      else if(par==24)ans= 'x' + ans;
      else if(par==25)ans= 'y' + ans;
      else if(par==0)ans= 'z' + ans;
      
      


  }

  if(n==1)ans= 'a' + ans;
      else if(n==2)ans= 'b' + ans;
      else if(n==3)ans= 'c' + ans;
      else if(n==4)ans= 'd' + ans;
      else if(n==5)ans= 'e' + ans;
      else if(n==6)ans= 'f' + ans;
      else if(n==7)ans= 'g' + ans;
      else if(n==8)ans= 'h' + ans;
      else if(n==9)ans= 'i' + ans;
      else if(n==10)ans= 'j' + ans;
      else if(n==11)ans= 'k' + ans;
      else if(n==12)ans= 'l' + ans;
      else if(n==13)ans= 'm' + ans;
      else if(n==14)ans= 'n' + ans;
      else if(n==15)ans= 'o' + ans;
      else if(n==16)ans= 'p' + ans;
      else if(n==17)ans= 'q' + ans;
      else if(n==18)ans= 'r' + ans;
      else if(n==19)ans= 's' + ans;
      else if(n==20)ans= 't' + ans;
      else if(n==21)ans= 'u' + ans;
      else if(n==22)ans= 'v' + ans;
      else if(n==23)ans= 'w' + ans;
      else if(n==24)ans= 'x' + ans;
      else if(n==25)ans= 'y' + ans;
      else if(n==26)ans= 'z' + ans;

  cout << ans << endl;

}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second > secondElof.second;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, modinv, bitSearch, bitList, dfs, bfs, dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l, m, n; ll N, M, K, H, W, L;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 0;
vl flag, color; vll path; vl D;
//***********//
int main() {
	ll X;
	cin >> X;
	ll p = X / 500;
	X %= 500;
	cout << p * 1000 + (X / 5) * 5;
}

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

int a[1<<19][2];

void update(int*a,int d){
	if(d>a[0])a[1]=a[0],a[0]=d;
	else a[1]=max(a[1],d);
}
int main(){
	int n;scanf("%d",&n);
	rep(i,1<<n){
		scanf("%d",&a[i][0]);
	}
	rep(i,n)rep(j,1<<n){
		if(!(j>>i&1)){
			update(a[j|1<<i],a[j][0]);
			update(a[j|1<<i],a[j][1]);
		}
	}
	int Max=0;
	for(int i=1;i<(1<<n);i++){
		Max=max(Max,a[i][0]+a[i][1]);
		printf("%d\n",Max);
	}
}

Measured memory_bytes: 7168
#include<bits/stdc++.h>
using namespace std;
int a,b,k;
int main(){
	cin>>k>>a>>b;
	for(int i=a;i<=b;i++){
		if(i%k==0){
			printf("OK");
			return 0;
		}
	}
	printf("NG");
	return 0;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 200010
using namespace std;
ll n,k,c;
string s;
vector<ll> wk1,wk2;
int main(){
	ll i,j;
	cin>>n>>k>>c>>s;
	for(i=0;i<s.size();i++)
	{
		if(s[i]=='o')
		{
			wk1.push_back(i);
			i+=c;
		}
	}
	for(i=s.size()-1;i>=0;i--)
	{
		if(s[i]=='o')
		{
			wk2.push_back(i);
			i-=c;
		}
	}
	sort(wk1.begin(),wk1.end());
	sort(wk2.begin(),wk2.end());
	if(wk1.size()>k||wk2.size()>k||wk1.size()!=wk2.size())
	{
		return 0;
	}
	for(i=0;i<wk1.size();i++)
	{
		if(wk1[i]==wk2[i])
		{
			cout<<wk1[i]+1<<" ";
		}
	}
	puts("");
	return 0;
}

Measured memory_bytes: 5108
import java.util.*;
public class Main{   
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      int[] x = new int[n];
      for(int i = 0;i < n;i++){
        x[i]=sc.nextInt();
      }
      
      int min = 1000000000;
      for(int i = 0;i <= n-k;i++){
      	int r = x[i+k-1];
        int l = x[i];
        min = Math.min(min, Math.min(Math.abs(r-l)+Math.abs(r), Math.abs(r-l)+Math.abs(l)));
      }
      System.out.println(min);
    }
}

Measured memory_bytes: 49580
x,n=map(int,input().split())
p=list(map(int,input().split()))
p=set(p)

for i in range(2*n+1):
    a=x-i
    b=x+i

    if a not in p:
        m=a
        break
    if b not in p:
        m=b
        break
print(m)


Measured memory_bytes: 9184
#include<stdio.h>
    
#define MAX 100000
    
   int parent(int i){
    
  return i/2;
}
    
int left(int i){
    
  return 2 * i;
}
    
int right(int i){
    
  return 2 * i + 1;
}
 
int main(){
  int i,n,A[MAX+1];
    
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d",&A[i]);
    
  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i) >= 1)printf("parent key = %d, ",A[parent(i)]);
    if(left(i) <= n)printf("left key = %d, ",A[left(i)]);
    if(right(i) <= n)printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
    
  return 0;
}
   

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

#define FOR(i,a,n) for (int i = a; i < (int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<typename T> bool chmin(T &a, const T &b) {if (a > b) { a = b; return true; }return false;}
template<typename T> bool chmax(T &a, const T &b) {if (a < b) { a = b; return true; }return false;}

using ll = int_fast64_t;

constexpr ll INF = (1e9);
constexpr ll MOD = (1e9+7);

using vl = vector<ll>;

ll d[] = {1, -1};

int main() {
  int n, m; cin >> n >> m;
  vl x(n), y(n), z(n);
  REP(i,n) cin >> x[i] >> y[i] >> z[i];
  vector<vl> v(8, vl(n));
  int cnti = 0;
  REP(j,2) REP(k,2) REP(l,2) {
    REP(i,n) {
      v[cnti][i] = d[j]*x[i] + d[k]*y[i] + d[l]*z[i];
    }
    cnti++;
  }
  REP(i,8) whole(sort, v[i], greater<ll>());
  ll sum = 0, res = 0;
  REP(i,8) {
    REP(j,m) {
      sum += v[i][j];
    }
    chmax(res, sum);
    sum = 0;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

const char dat[7][4][5] = {
    { "1100", "1100", "0000", "0000" },
    { "1000", "1000", "1000", "1000" },
    { "1111", "0000", "0000", "0000" },
    { "0100", "1100", "1000", "0000" },
    { "1100", "0110", "0000", "0000" },
    { "1000", "1100", "0100", "0000" },
    { "0110", "1100", "0000", "0000" },
};

char f[16][16];

bool match(int k, int x, int y) {
    rep (i, 4) rep (j, 4) if (f[x+i][y+j] != dat[k][i][j]) return false;
    return true;
}

int solve() {
    rep (k, 7) rep (i, 8) rep (j, 8) if (match(k, i, j)) return k;
    return -1;
}

int main() {
    memset(f, '0', sizeof(f));
    while (scanf(" %c", f[0]) != EOF) {
        rep (i, 8) rep (j, 8) if (i || j) scanf(" %c", f[i]+j);
        printf("%c\n", (char)('A'+solve()));
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
using matrix = vector<vector<uint>>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acos(-1);

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

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

    ll ans = 0;
    for (int i = K; i <= N + 1; ++i) {
        ll mi = (ll)i * (i - 1) >> 1;
        ll ma = (ll)N * i - mi;
        ans += max<ll>(ma - mi + 1, 0);
        ans %= MOD;
    }

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


Measured memory_bytes: 3652
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n,A,B;
int main(){
	scanf("%lld%lld%lld",&n,&A,&B);
	if((B-A)%2==0)printf("%lld\n",(B-A)/2);
	else{
		ll t1=1,t2=B-A;
		
ll ans=min((B-A-1)/2+A,n-B+1+(B-A-1)/2);
printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 256
<?php
list($A, $B, $Q) = explode(" ", trim(fgets(STDIN)));
$A = intval($A);
$B = intval($B);
$Q = intval($Q);
for($i = 0; $i < $A; $i++){
    $aArray[] = intval(fgets(STDIN));
}
array_unshift($aArray, -10**18);
$aArray[] = 10**18;
for($i = 0; $i < $B; $i++){
    $bArray[] = intval(fgets(STDIN));
}
array_unshift($bArray, -10**18);
$bArray[] = 10**18;

for($i = 0; $i < $Q; $i++){
    $qArray[] = intval(fgets(STDIN));
}

foreach($qArray as $q){
    $min = 10**18;
    $a = bsl($aArray, $q);
    $b = bsl($bArray, $q);
    foreach([[[$aArray, $a], [$bArray,$b]], [[$bArray, $b], [$aArray,$a]]] as list(list($aa, $_a), list($bb, $_b))){
        foreach([$aa[$_a], $aa[$_a+1]] as $a1){
            $p3 = $bb[$_b]??10**12;
            $p4 = $bb[$_b+1]??10**12;
            $min = min($min, abs($q - $a1) + abs($a1 - $p3));
            $min = min($min, abs($q - $a1) + abs($a1 - $p4));
        }
    }
    printf("%d\n", $min);
}

//二分探索　target以下で最大の値の場所を返す
function bsl($nums, $target) {
    $size = count($nums);
    $min = 0; 
    $max = $size - 1;
    while(true){
        $center = floor(($min + $max) / 2);
        $centerValue = $nums[$center];
        if($target == $centerValue){
            return $center;
        }elseif($target > $centerValue){
            $min = $center + 1;
        }else{
            $max = $center;
        }
        if($min == $max){
            $center = floor(($min + $max) / 2);
            $centerValue = $nums[$center];
            if($centerValue == $target){
                return $center;
            }elseif($centerValue < $target){
                return $center;
            }else{
                return $center-1;
            }
        }
    }
}


Measured memory_bytes: 18928
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (!n) return 0;
    vector<pair<int, int> > es;
    for (int i = 0; i < n; i++) {
      int m, a, b;
      cin >> m >> a >> b;
      es.push_back(make_pair(a, m));
      es.push_back(make_pair(b, -m));
    }
    sort(es.begin(), es.end());
    int s = 0;
    for (int i = 0; i < 2 * n; i++) {
      s += es[i].second;
      if (s > 150) {
        cout << "NG" << endl;
        goto next;
      }
    }
    cout << "OK" << endl;
next:;
  }
}

Measured memory_bytes: 0
//D
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+10;
queue<ll>q;
int main(){
	int k;
	cin >> k;
	k--;
	for(int i = 1;i <= 9;i++)q.push(i);
	while(k--){
		ll u = q.front();
		q.pop();
		ll d = u%10;
		if(d)q.push(u*10+d-1);
		q.push(u*10+d);
		if(d != 9)q.push(u*10+d+1);
	}
	cout << q.front();
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <climits>
#define LIM 1000007
#define ll long long
using namespace std;
int main() {
  ll a, b, x;
  cin >> a >> b >> x;
  if (a % x != 0) {
    a += x - (a % x);
  }
  if (b % x != 0) {
    b -= b % x;
  }
  cout << (b - a) / x + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
/*
 *
 * Author: r3gz3n
 * 
 * 3b 13 12 9 56 4e
 * 6 56 a a 5f f
 * 6 56 47 18 56 d
 * 13 46 14 1f 13 27
 * 52 52 a 5a 47 1
 * 1d 13 b 1b 49 17
 *
 */


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;


#define endl '\n'


class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
        double l;
        in >> l;
        l = l*l*l;
        out << l / 27.0 << endl;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




Measured memory_bytes: 256
s = input()

for i in range(8): #全部で2**3=8通りの入れ方がある。
    s_temp = s[0]
    for j in range(3): #調べるのは数と数の間３つ
        if i >> j & 1: #もし２進法で右からj+1番目が1なら
            s_temp += "+" + s[j+1] #左からj+1番目の間に+を入れて
        else: #そうでなければ
            s_temp += "-" + s[j+1] #そこに-を入れる
    #+と-を入れ終わったら計算結果をチェックして
    if eval(s_temp) == 7: #もし合っているなら
        ans = s_temp + "=7"
        print(ans) #答えを表示する
        exit()

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

bool isPali(string s, ll a, ll b){
  if (b-a <= 0) return true;
  return s[a] == s[b] && isPali(s, a+1, b-1);
}

int main(){

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

  string s;
  cin >> s;
  ll N = s.size();
  if(isPali(s, 0, N-1) && isPali(s, 0, (N-1)/2 -1 ) && isPali(s, ((N+3)/2)-1, N-1)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        String sN = scan.next();
        String sA = scan.next();
        String sB = scan.next();

        int N = Integer.parseInt(sN);
        int A = Integer.parseInt(sA);
        int B = Integer.parseInt(sB);
        if( 1 <= N || N <= 20 ){
            int hogeo = N * A;
            if(hogeo < B){
                System.out.println(hogeo);
            }else{
                System.out.println(B);
            }
        }
    }
}

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

#ifdef HELTHAZAR
#define dbg(x) cerr << #x << " " << x << endl
#define dbg2(x, y) cerr << #x << " " << x << " " << #y << " " << y << endl
#define dbg3(x, y, z) cerr << #x << " " << x << " " << #y << " " << y << " " << #z << " " << z << endl
#else
#define dbg(x) ;
#define dbg2(x, y) ;
#define dbg3(x, y, z) ;
#endif

#define rep(i, from, to) for (int i = from; i < int(to); i++)
#define repn(i, from, to) for (int i = from; i <= int(to); i++)
#define repr(i, from, to) for (int i = int(from); i >= to; i--)
#define trav(a, x) for (auto& a: x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

typedef long long ll;
typedef double dbl;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<ll> vll;

const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int MAXN = 2e3 + 5;

int t[4 * MAXN];

void build(int v, int tl, int tr) {
	if (tl == tr) t[v] = 1;
	else {
		int tm = (tl + tr) >> 1;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v] = t[v * 2] + t[v * 2 + 1];
	}
}

void add(int v, int tl, int tr, int k) {
	if (tl == tr) t[v]--;
	else {
		int tm = (tl + tr) >> 1;
		if (k <= tm) add(v * 2, tl, tm, k);
		else add(v * 2 + 1, tm + 1, tr, k);
		t[v] = t[v * 2] + t[v * 2 + 1];
	}
}

int get(int v, int tl, int tr, int l, int r) {
	if (tl == l && tr == r) return t[v];
	else {
		int tm = (tl + tr) >> 1;
		int res = 0;
		if (l <= tm) res += get(v * 2, tl, tm, l, min(tm, r));
		if (r > tm) res += get(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r);
		return res;
	}
}

void solve() {
	int n, k, q;
	cin >> n >> k >> q;
	vector<pair<int, int> > v(n + 1);
	repn(i, 1, n) {
		cin >> v[i].fi;
		v[i].se = i;
	}
	sort(all(v));

	int ans = v[n].fi - v[1].fi;
	repn(i, 1, n) {
		set<int> pos;
		pos.insert(0);
		pos.insert(n + 1);
		build(1, 0, n + 1);
		rep(j, 1, i) {
			pos.insert(v[j].se);
			add(1, 0, n + 1, v[j].se);
		}
		int cnt = 0;
		repn(j, i, n) {
			auto l = *(--pos.lower_bound(v[j].se));
			auto r = *(pos.lower_bound(v[j].se));
			if (get(1, 0, n + 1, l + 1, r - 1) >= k) {
				add(1, 0, n + 1, v[j].se);
				cnt++;
			}
			if (cnt >= q) {
				ans = min(ans, v[j].fi - v[i].fi);
				break;
			}
		}
	}

	cout << ans;
}

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

	solve();
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  vector<int> a(3);
  for (int i = 0; i < 3; i++)
  {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int ans = 0;
  ans += a[2] - a[1];
  ans += a[1] - a[0];
  cout << ans << endl;
}

Measured memory_bytes: 3596
N,K = map(int,input().split())
A = list(map(int,input().split()))
town = 0 #index
count=[0]*N #index
all=[1] #not index
roop=[] #not index
for _ in range(K):
  if count[town] == 2:
    break
  elif count[town]==1:
    roop.append(town+1)
  count[town]+=1
  all.append(A[town])
  town = A[town] -1
if K < len(all):
  print(all[K])
else:
  all.pop(-1)
  print(roop[(K-(len(all)-len(roop)*2))%len(roop)])

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

vector< int64_t > divisor(int n){
    vector<int64_t >ret;
    for(int i=1;i*i<n;i++){
        if(n%i==0){
            ret.push_back(i);
            if(i*i!=n){
                ret.push_back(n/i);
            }
        }
    }
    sort(ret.begin(),ret.end());
    return ret;
}


int main()
{
    int32_t n,m;
    cin>>n>>m;
    vector<int64_t >v = divisor(m);
    int64_t ans=1;
    for(int i=1;i<v.size();i++){
        if(v[i]*n<=m)ans=v[i];
    }
    cout<<ans<<endl;
}

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

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 62;

int main() {
  int N;
  ll X, D;
  std::cin >> N >> X >> D;

  if(D == 0) {
    if(X == 0) {
      std::cout << "1" << '\n';
      return 0;
    } else {
      std::cout << N + 1 << '\n';
      return 0;
    }
  }

  std::map<ll, std::vector<std::pair<ll, ll>>> ranges;

  for(ll k = 0; k <= N; ++k) {
    ll L = k * (k - 1) / 2;
    ll R = k * (2 * N - k - 1) / 2;
    if(L > R) {
      std::swap(L, R);
    }

    ll r = X * k % D;
    ll n = (X * k) / D;
    if(r < 0) r -= D;
    ranges[r].push_back(std::make_pair(n + L, n + R + 1));
  }

  ll ans = 0;
  for(auto& p : ranges) {
    auto& range_vec = p.second;

    ll last = - INF;
    std::sort(range_vec.begin(), range_vec.end());
    for(auto range : range_vec) {
      ll L = range.first;
      ll R = range.second;

      if(R <= last) continue;
      L = std::max(L, last);
      ans += R - L;
      last = R;
    }
  }

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


Measured memory_bytes: 22144
import sys
sys.setrecursionlimit(10000)
def f(x,y):
    if 0<=x<w and 0<=y<h and a[y][x]=='1':
        a[y][x]='0'
        for dx,dy in[[-1,0],[1,0],[0,-1],[0,1],[-1,-1],[1,-1],[-1,1],[1,1]]:f(x+dx,y+dy)
while 1:
    w,h=map(int,input().split())
    if w==0:break
    a=[input().split() for _ in[0]*h];b=0
    for i in range(w):
        for j in range(h):
            if a[j][i]=='1':
                b+=1;f(i,j)
    print(b)


Measured memory_bytes: 9824
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
    int N, K;
    std::cin >> N >> K;

    std::vector<int> change;
    change.emplace_back(0);
    char first;
    std::cin >> first;
    char now = first;
    for (int i = 1; i < N; ++i) {
        char c;
        std::cin >> c;
        if (c != now) {
            change.emplace_back(i);
            now = c;
        }
    }
    change.emplace_back(N);

    std::vector<int> candidate;
    int first_index = 0;
    int max_index = change.size() - 1;
    if (first == '0') {
        int last_index = std::min(first_index + 2 * K, max_index);
        int x = change[last_index] - change[first_index];
        candidate.emplace_back(x);
        first_index = 1;
    }
    while (first_index < max_index) {
        int last_index = std::min(first_index + 2 * K + 1, max_index);
        int x = change[last_index] - change[first_index];
        candidate.emplace_back(x);
        first_index += 2;
    }

    int ans = *std::max_element(candidate.begin(), candidate.end());
    std::cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define ll long long;
using namespace std;
long long int a[100005][105];
long long int v[100005],w[100005];
long long int n,we;
long long sl(long long va,long long i)
{
    if(va==0)
     return 0;
    
    if(i==n+1)
     return INT_MAX;
     
     if(a[va][i]!=-1)
      return a[va][i];

  a[va][i]=min(sl(va,i+1),w[i]+sl(va-v[i],i+1));
  return a[va][i];
    
}
long long fun()
{
    for(long long i=100004;i>=0;i--)
    {
        if(sl(i,0)<=we)
         return i;
    }
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin>>n>>we;
    for(int i=1;i<=n;i++)
     cin>>w[i]>>v[i];
    
    for(int i=0;i<100005;i++)
     for(int j=0;j<105;j++)
      a[i][j]=-1;
    
    cout<<fun()<<"\n";
   
   //cout<<a[n][w]<<"\n";
}

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

using namespace std;
int main()
{
	string s, t;

	cin >> s;
	cin >> t;

	if (0 >= s.size() && s.size() > 10) {
		cout << "No" << endl;
		return 0;
	}

	if (s.size()+ 1 != t.size()) {
		cout << "No" << endl;
		return 0;
	}

	for (int i = 0; i < s.size(); ++i) {
		if (s[i] < 'a' && s[i] > 'z') {
			cout << "No" << endl;
			return 0;
		}
		if (t[i] != s[i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	if (t[t.size() - 1] < 'a' && s[t.size() - 1] > 'z') {
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <cmath>
#include <queue>
#include <map>
#include <cstring>
#include <string>
#include <set>
#include <vector>
#include <list>
#include <deque>
#include <algorithm>
#include <stack>
#include <numeric>
#include <time.h>
#include<iomanip>
#include<sstream>
#pragma disable:4996)
using namespace std;
const long long inf = 0x7f7f7f7f;
long long GCD(long long a, long long b) { return 0 == b ? a : GCD(b, a%b); }
const long long mod = 1e9 + 7;
const double pi = acos(-1);
long long a[120000];
long long l[120000];
long long r[120000];
int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    l[0] = a[0];
    for (int i = 1; i < n; i++)
        l[i] = GCD(l[i - 1], a[i]);
    r[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; i--)
        r[i] = GCD(r[i + 1], a[i]);
    long long ans = 1;
    for (int i = 1; i < n-1; i++)
        ans = max(GCD(l[i - 1], r[i + 1]), ans);
    cout << max(ans,max(r[1],l[n-2])) << endl;
    //return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <string.h>
#include <vector>

using namespace std;
int main() {
    int N, K;
    char S[50];
    cin >> N >> K;
    cin >> S;
    S[K - 1] += 32;
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 888
while True:
    n, r = map(int, input().split())
    if n == r == 0:
        break
    cards = [i + 1 for i in range(n)]
    for _ in range(r):
        p, c = map(int, input().split())
        swap = []
        for i in range(c):
            swap.append(cards.pop(n - p - i))
        for i in swap[::-1]:
            cards.append(i)
    print(cards[n - 1])

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

bool judge(string s, bool head)
{
	if (s.empty()) return true;
	
	char c = s[0];
	bool ff = true, fff = true, ffff = true;
	string ss = s, sss = s, ssss = s;
	
	for (int i = 0; i < 3; i++){
		if (ss.find(c) == -1){ ff = false; break; }
		ss.erase(ss.find(c), 1);
	}
	if (ff) ff = judge(ss, head);
	
	for (int i = 0; i < 3; i++){
		if (sss.find(c+i) == -1){ fff = false; break; }
		sss.erase(sss.find(c+i), 1);
	}
	if (fff) fff = judge(sss, head);
	
	if (!head){
		for (int i = 0; i < 2; i++){
			if (ssss.find(c) == -1){ ffff = false; break; }
			ssss.erase(ssss.find(c), 1);
		}
		if (ffff) ffff = judge(ssss, true);
	}
	else ffff = false;
	
	return ff || fff || ffff;
}

int main(void)
{
	string s;
	while (cin >> s){
		bool flag = false;
		vector <int> v;
		for (char c = '1'; c <= '9'; c++){
			string ss = s;
			ss += c;
			if (static_cast <int> (count(ss.begin(), ss.end(), c)) > 4) continue;
			sort(ss.begin(), ss.end());
			if (judge(ss, false))
			{
				v.push_back(c - '0');
				flag = true;
			}
		}
		if (!flag) cout << "0" << endl;
		else {
			for (int i = 0; i < v.size(); i++){
				cout << v[i];
				if (i+1==v.size()) puts("");
				else cout << " ";
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;

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

	void run() {
		Scanner sc = new Scanner();
		int n = sc.nextInt();
		long[] a = new long[n];
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextLong();
		}
		Arrays.sort(a);
		if (a[n - 1] % 2 == 0) {
			long tmp = a[0];
			for (int i = 0; i < a.length; ++i) {
				if (Math.abs(tmp - a[n - 1] / 2) > Math.abs(a[i] - a[n - 1] / 2)) {
					tmp = a[i];
				}
			}
			System.out.println(a[n - 1] + " " + tmp);
		} else {
			long tmp = a[0];
			for (int i = 0; i < a.length; ++i) {
				if (Math.abs(tmp - a[n - 1] / 2) > Math.abs(a[i] - a[n - 1] / 2)
						|| Math.abs(tmp - (a[n - 1] + 1) / 2) > Math.abs(a[i] - (a[n - 1] + 1) / 2)) {
					tmp = a[i];
				}
			}
			System.out.println(a[n - 1] + " " + tmp);

		}

		//0,1,2,,,,,a[n-1]
		// a[n-1]/2   0,1,2,3
	}

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

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

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

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

		private void skipUnprintable() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
		}

		public boolean hasNext() {
			skipUnprintable();
			return hasNextByte();
		}

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

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

		public int nextInt() {
			return (int) nextLong();
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


Measured memory_bytes: 24516