akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>

using namespace std;
int main(){
    int A,B,K;
    cin>>A>>B>>K;
    int C=max(A,B);

    int a[100];
    
    int l=0;
    int o=0;
    for(int i=1;i<=C;i++){
        if(A%i==0&&B%i==0)
        { a[l]=i;
        l++;
        
        }
    }
    int ans=a[(l-K)];
    cout<<ans;
    return 0;

}

Measured memory_bytes: 256
///
// File:  d.go
// Author: ymiyamoto
//
// Created on Sun Feb 18 21:21:33 2018
//
package main

import (
	"fmt"
)

type pos struct {
	x int
	y int
}

func dfs(board []string) int {
	visited := make([][]int, len(board))
	for i := range visited {
		visited[i] = make([]int, len(board[i]))
		for j := 0; j < len(board[i]); j++ {
			visited[i][j] = -1
		}
	}

	q := make([]pos, 0)

	q = append(q, pos{0, 0})
	visited[0][0] = 0
	for len(q) > 0 {
		p := q[0]
		q = q[1:]

		x := p.x
		y := p.y
		for _, d := range [4]pos{{-1, 0}, {1, 0}, {0, -1}, {0, 1}} {
			dx := d.x + x
			dy := d.y + y
			if 0 <= dx && dx < len(board) && 0 <= dy && dy < len(board[0]) && board[dx][dy] == '.' && visited[dx][dy] == -1 {
				visited[dx][dy] = visited[x][y] + 1
				q = append(q, pos{dx, dy})
			}
		}
	}

	return visited[len(board)-1][len(board[0])-1]
}

func main() {
	var H, W int
	fmt.Scan(&H, &W)
	board := make([]string, H)

	for i := range board {
		fmt.Scan(&board[i])
	}

	whites := 0
	for i := range board {
		for j := range board[i] {
			if board[i][j] == '.' {
				whites++
			}
		}
	}

	len := dfs(board)
	if len == -1 {
		fmt.Println(-1)
	} else {
		fmt.Println(whites - 1 - len)
	}
}


Measured memory_bytes: 768
n=int(input())
def f(a,b):
  a=len(str(a))
  b=len(str(b))
  return max(a,b)

ans=10**9
for i in range(1,int(n**0.5)+1):
  if n%i==0:
    ans=min(ans,f(i,n//i))
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;

int main(){
  string N;
  cin >> N;
  bool flag = false;
  if(N[0] == N[1] && N[1] == N[2]) flag = true;
  if(N[1] == N[2] && N[2] == N[3]) flag = true;
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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


int main() {
    long long int a, b, c;
    cin >> a >> b >> c;
    long long int k;
    cin >> k;
    if (k % 2 == 1) {
        cout << b - a << endl;
    } else {
        cout << a - b << endl;
    }
}




Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep_1(i, n) for (int(i) = 0; (i) <= (n); (i)++)
#define rep_2(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  rep(i, m) { cin >> a[i]; }
  int sm = accumulate(all(a), 0);

  cout << (sm <= n ? n - sm : -1) << endl;

  return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl);
#define cop(a) for(auto x:(a)){cout << x << endl;}


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){

    int n;
    cin >> n;

    int m = 1<<n;
    multiset<int, greater<int>> S;
    rep(i, m) {
        int x; scanf("%d", &x);
        S.insert(x);
    }
    vector<int> now, nxt;
    now.emplace_back(*S.begin());
    S.erase(S.begin());


    rep(i, n){
        nxt = now;
        for(int x : now){
            auto it = S.upper_bound(x);
            if(it == S.end()){
                No();
                return 0;
            }
            nxt.emplace_back(*it);
            S.erase(it);
        }
        now = nxt;
    }
    Yes();
    return 0;
}


Measured memory_bytes: 14324
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var C = Read();
            Println((char)(C[0] + 1));
        }

        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static void YESOrNO(bool e) => Println(e ? "YES" : "NO");

        static void YesOrNo(bool e) => Println(e ? "Yes" : "No");

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());
        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <vector>
using namespace std;
int dp[2000005];
const int inf = 1 << 30;
main()
{
    int n;
    cin >> n;
    vector< int > h(n);for(int i = 0; i < n; i++ )cin >> h[i];
    h.push_back( inf);
    h.push_back( inf);
    for( int i = 0; i < n; i++ )dp[i] = inf;
    dp[0] = 0;
    for( int i = 0; i < n; i++ )
    {
        dp[i + 1] = min( dp[i + 1], dp[i] + abs( h[i] - h[i + 1] ) );
        dp[i + 2] = min( dp[i + 2], dp[i] + abs( h[i] - h[i + 2] ) );
    }
    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <vector>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
const long long INF = 1LL << 60;
 
long long h[100010];
 
long long dp[100010];
 
int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> h[i];
  
  for(int i = 0; i < 100010; i++) dp[i] = INF;
  
  dp[0] = 0;
  
  for(int i = 1; i < n; i++){
    chmin(dp[i], dp[i - 1] + abs(h[i] - h[i-1]));
    if(i > 1) chmin(dp[i], dp[i-2] + abs(h[i] - h[i - 2]));
  }
  
  cout << dp[n-1] << endl;
  return 0;
}

Measured memory_bytes: 5036
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説どおりに作成したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			int[] h = new int[n];
			int max = IntStream.range(0, n).map(i -> h[i] = scanner.nextInt()).max().getAsInt();
			int high = (max + b - 1) / b, low = 0;
			while (high > low + 1) {
				int middle = (high + low) / 2;
				if (enough(middle, h, a, b)) {
					high = middle;
				} else {
					low = middle;
				}
			}
			System.out.println(high);
		}
	}

	/**
	 * @param t 爆発回数
	 * @param h 怪物のHPの配列
	 * @param a 爆発の個体破壊力
	 * @param b 爆発の全体破壊力
	 * @return t回の爆発ですべての怪物が倒せるかどうか
	 */
	private static boolean enough(final int t, final int[] h, final int a, final int b) {
		return Arrays.stream(h).mapToLong(hi -> ((hi - b * t) + (a - b) - 1) / (a - b)).map(i -> (i > 0) ? i : 0)
				.sum() <= t;
	}
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int A, B, C, D;
  cin >> A >> B >> C >> D;
  bool takahashi = true;
  while (true) {
    if (takahashi) {
      takahashi = false;
      C -= B;
      if (C <= 0) {
        cout << "Yes" << endl;
        return 0;
      }
    } else {
      takahashi = true;
      A -= D;
      if (A <= 0) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3652
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include <string.h>

int main(){
    int len;
    char s[1003], ss[] = "s", es[] = "es";

    scanf("%s", s);

    len = strlen(s);

    if(s[len - 1] == 's') strcat(s, es);
    else strcat(s, ss);

    printf("%s", s);

    return 0;
}

Measured memory_bytes: 2120
import java.util.Scanner;
 
public class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);
    int H = scan.nextInt();
    int A = scan.nextInt();
    int result = H/A;
    if(H%A>0){
      result++;
    }
    System.out.println(result);
  }
}

Measured memory_bytes: 22228
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int sum = 0;
		if (a > b) {
			sum = a;
			a = b;
			b = sum;
		}
		if (a > c) {
			sum = a;
			a = c;
			c = sum;
		}
		if (b > c) {
			sum = b;
			b = c;
			c = sum;
		} 
		System.out.println(a + " " + b + " " + c);
	}

}

Measured memory_bytes: 26272
from functools import reduce
N = int(input())
DIV = 10**9 + 7
S = {chr(i): 0 for i in range(ord('a'), ord('z') + 1)}
for c in input():
    S[c] += 1
print(reduce(lambda acc, n: acc * (n + 1) % DIV, S.values(), 1) - 1)


Measured memory_bytes: 4068
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod=1e9+7 ;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define input_from_file  freopen("input.txt", "r", stdin);
using namespace std::chrono; 

int main()
{
  // input_from_file 
  ll q;q=1;while(q--){
    ll n,k;cin>>n>>k;vector<ll> vec(n,0);
    for(int i=0;i<n;i++)  cin>>vec[i];
    ll j=0;
    for(int i=k;i<n;i++){
      if(vec[i]>vec[j]) cout<<"Yes\n";
      else cout<<"No\n";
      j++;
    }
  }
  return 0;
}

Measured memory_bytes: 4836
import java.util.Scanner;

public class Main {

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

        int n = sc.nextInt();

        sc.close();

        int ans = 0;

        for (int i = 1; i <= n; i++) {
            ans += i;
        }

        System.out.println(ans);

    }
}

Measured memory_bytes: 23380
# 1,3を入れ替えたあとに3,5を入れ替えれば1,5が入れ替わるパターンが難しいポイント
# イメージ：ある頂点を入れる->つながっている辺が返ってくる。その中で該当のものがあれば交換する？
class Tree():
    def __init__(self, array):
        n = len(array)
        # 最初はすべてを根として定義する
        self.roots = [x for x in range(n + 1)]

    def get_root(self, a):
        if self.roots[a] == a:
            return a
        else:
            self.roots[a] = self.get_root(self.roots[a])
            return self.roots[a]

    def unite(self, x, y):
        if self.get_root(x) == self.get_root(y):
            pass
        else:
            self.roots[self.get_root(y)] = self.get_root(x)


if __name__ == '__main__':
    n, m = map(int, input().split())
    p_array = [int(x) for x in input().split()]
    xy_array = [[int(x) for x in input().split()] for y in range(m)]

    tree = Tree(p_array)

    # 連結しなおす
    for x, y in xy_array:
        tree.unite(x, y)

    res = 0
    for i in range(1, n + 1):
        if tree.get_root(i) == tree.get_root(p_array[i-1]):
            res += 1
    print(res)


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


int main()
{
	cout << setprecision(20);
	double N;
	cin >> N;
	int M, L;
	M = N / 1.08;
	L = M + 1;
	int S = M * 1.08;
	int T = L * 1.08;
	if (S==N || T==N)
	{
		if (S==N)
		{
			cout << M <<  endl;
		}else{
			cout << L << endl;
			}
	}
	else {
		cout << ":(" << endl;
	}
}

Measured memory_bytes: 3724
#include <iostream>
#include <math.h>

int check(int a, int b, int c);

int main(){
  int n;
  int a, b, c;
  int longest;
  
  std::cin >> n;
  for(int i=0; i<n; i++){
    std::cin >> a;
    std::cin >> b;
    std::cin >> c;
    
    longest = check(a, b, c);
    switch(longest){
      case 1:
        if(pow((double)a,2.0)==pow((double)b, 2.0)+pow((double)c, 2.0)){
          std::cout << "YES" << std::endl;
        }else{
          std::cout << "NO" << std::endl;
        }
        break;
      case 2:
        if(pow((double)b,2.0)==pow((double)a, 2.0)+pow((double)c, 2.0)){
          std::cout << "YES" << std::endl;
        }else{
          std::cout << "NO" << std::endl;
        }
        break;
      default:
        if(pow((double)c,2.0)==pow((double)a, 2.0)+pow((double)b, 2.0)){
          std::cout << "YES" << std::endl;
        }else{
          std::cout << "NO" << std::endl;
        }
        break;
    }
  }
  
  return 0;
}

int check(int a, int b, int c){
  if(a>b){
    if(a>c) return 1;
    else    return 3;
  }else{
    if(b>c) return 2;
    else    return 3;
  }
}

Measured memory_bytes: 3096
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
S = [sr() for _ in range(H)]
bl = True
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            continue
        for dy, dx in zip([0, 1, 0, -1], [1, 0, -1, 0]):
            ny = i + dy
            nx = j + dx
            if 0 <= ny < H and 0 <= nx < W and \
                    S[ny][nx] == '#':
                break
        else:
            bl = False

print('Yes' if bl else 'No')


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

int main(){
    int t,n,x,m=1001; cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>t;
        x=x-t;
        m=min(t,m);
        }
    int r=0;
    while(x>=0){
        x=x-m;
        r++;
        }
    cout<<n+r-1<<endl;

    }


Measured memory_bytes: 256
X = int(input())

if 400 <= X < 600:
    print(8)
elif 600 <= X < 800:
    print(7)
elif 800 <= X < 1000:
    print(6)
elif 1000 <= X < 1200:
    print(5)
elif 1200 <= X < 1400:
    print(4)
elif 1400 <= X < 1600:
    print(3)
elif 1600 <= X < 1800:
    print(2)
elif 1800 <= X < 2000:
    print(1)

Measured memory_bytes: 9184
#include <stdio.h>

int main(void){
  int i;
  long int N,K,ans=0;
  scanf("%ld",&N);
  scanf("%ld",&K);
  for(i=N+1;i>=K;i--){
    ans += (N - i + 1) * i + 1;
    ans%=1000000007;
  }
  printf("%ld",ans);
}

Measured memory_bytes: 1728
#include<stdio.h>
#define N 2000001
 
int a[N],c[N],b[N];
 
int main(){
  int i,j,n,k=0;
    
  scanf("%d",&n);
 
  for(i = 1; i < n+1; i++){
    scanf("%d",&a[i]);
    if(a[i] >k){
      k = a[i];
    }
  }
  for(i = 0; i < k+1; i++){
    c[i] = 0;
  }
  for(j = 1; j < n+1; j++){
    c[a[j]] = c[a[j]] + 1;
  }
 
  for(i = 1; i <= k; i++){
    c[i] = c[i] + c[i-1];
  }
  
  for(j = n; j > 0; j--){
    b[c[a[j]]] = a[j];
    c[a[j]] = c[a[j]] - 1;
  }
 
  for(i = 1; i < n; i++){
    printf("%d ",b[i]);
  }
  printf("%d\n",b[n]);
 
  return 0;
}

		





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

#define MAX 1000000

int main( void )
{
	vector <bool> primes(MAX+1, false);

	for ( int i = 3; i <= MAX; i += 2 )
	{
		primes[i] = true;
	}

	for ( int i = 3; i <= MAX; i += 2 )
	{
		if ( primes[i] )
		{
			for ( int j = i + i; j <= MAX; j += i )
			{
				primes[j] = false;
			}
		}
	}
	primes[2] = true;
	
	int n;
	while ( cin >> n )
	{
		int cnt = 0;
		for ( int i = 0; i <= n; ++i )
		{
			if ( primes[i] )
				cnt++;
		}
		cout << cnt << endl;
	}

	return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  ll n, k;
  cin >> n >> k;
  vector<ll> l(n);
  for(int i = 0; i < n; ++i)
  {
    cin >> l[i];
  }
  sort(RALL(l));
  ll ans = 0;
  for(int i = 0; i < k; ++i) ans += l[i];
  cout << ans;

}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3596
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz");
char s[500][500];
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
int vi[500][500];

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

  cin >> h >> w >> k;
  rep(i, h) rep(j, w) cin >> s[i][j];

  rep(i, h) {
    rep(j, w) {
      if (s[i][j] != '#') continue;
      ll mix = j, maax = j;
      vi[i][j] = k;
      rrrep(z, j - 1, 0) {
        if (s[i][z] == '#' || vi[i][z] != 0) break;
        mix = z;
        vi[i][z] = k;
      }
      rrep(z, j + 1, w) {
        if (s[i][z] == '#' || vi[i][z] != 0) break;
        maax = z;
        vi[i][z] = k;
      }
      // if (k == 6) cout << mix << " " << maax << "\n";

      rrrep(zy, i - 1, 0) {
        int ok = 0;
        rrep(zx, mix, maax + 1) {
          if (vi[zy][zx] || s[zy][zx] == '#') ok = 1;
          if (ok) break;
        }
        if (ok) break;
        rrep(zx, mix, maax + 1) {
          if (vi[zy][zx]) ok = 1;
          if (ok) break;
          vi[zy][zx] = k;
        }
      }

      rrep(zy, i + 1, h) {
        int ok = 0;
        rrep(zx, mix, maax + 1) {
          if (vi[zy][zx] || s[zy][zx] == '#') ok = 1;
          if (ok) break;
        }
        if (ok) break;
        rrep(zx, mix, maax + 1) {
          if (vi[zy][zx]) ok = 1;
          if (ok) break;
          vi[zy][zx] = k;
        }
      }

      k--;
    }
  }

  rep(i, h) {
    rep(j, w) {
      if (j == w - 1)
        Cout(vi[i][j]);
      else
        cout << vi[i][j] << " ";
    }
  }
  return 0;
}

Measured memory_bytes: 1536
#!/usr/bin/env python3

from collections import defaultdict
from heapq import heappush, heappop
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")


def debug(*x):
    print(*x)


def solve(N, heights):
    heights += [INF]
    costs = [INF] * (N + 1)
    costs[0] = 0
    for i in range(N - 1):
        costs[i + 1] = min(
            costs[i + 1],
            costs[i] + abs(heights[i + 1] - heights[i]))
        costs[i + 2] = min(
            costs[i + 2],
            costs[i] + abs(heights[i + 2] - heights[i]))
    return costs[N - 1]


def solve2(N, heights):
    costs = [0] * N
    costs[0] = 0
    costs[1] = abs(heights[1] - heights[0])
    for i in range(2, N):
        costs[i] = min(
            costs[i - 2] + abs(heights[i] - heights[i - 2]),
            costs[i - 1] + abs(heights[i] - heights[i - 1]),
        )
    return costs[-1]


def main():
    N = int(input())
    heights = list(map(int, input().split()))
    print(solve(N, heights))


def _test():
    """
    >>> solve(4, [10, 30, 40, 20])
    30
    >>> solve(2, [10, 10])
    0
    >>> solve(6, [30, 10, 60, 10, 60, 50])
    40
    """
    import doctest
    doctest.testmod()


def as_input(s):
    "use in test, use given string as input file"
    import io
    global read, input
    f = io.StringIO(s.strip())
    input = f.readline
    read = f.read


USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', solve.__doc__.strip().split()[0])(solve)
    cc.compile()
    exit()
else:
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read

    if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
        # -p: pure python mode
        # if not -p, import compiled module
        from my_module import solve  # pylint: disable=all
    elif sys.argv[-1] == "-t":
        _test()
        sys.exit()
    elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
        # input given as file
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline
        read = input_as_file.buffer.read

    main()


Measured memory_bytes: 19172
// scanf 等でエラーを出さないように追加
#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <memory>
#include <algorithm>
#include <numeric>
#include <set>
#include <functional>
#include <utility>


using namespace std;


typedef long long ll;





int main() {

	char s1[16], s2[16], s3[16];
	scanf("%s %s %s", s1, s2, s3);

	int conv_capitalize = 'A' - 'a';

	printf("%c%c%c\n", s1[0] + conv_capitalize, s2[0] + conv_capitalize, s3[0] + conv_capitalize);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};
ll N,K,R,S,P;

ll win(char aite){
    if(aite=='r') return P;
    else if(aite=='s') return R;
    else return S;
}

int main() {
     cin>>N>>K>>R>>S>>P;
    string T;
    cin>>T;
    ll ans=0ll;
    vector<bool> is_win(N,false);
    for(int i=0;i<N;++i){
        if(i<K) {
            ans+=win(T[i]);
            is_win[i]= true;
            //cout<<i<<endl;
        }else{
            //cout<<T[i]<<" "<<T[i-K]<<endl;
            if(T[i]!=T[i-K]||!is_win[i-K]){
                ans+=win(T[i]);
                is_win[i]= true;
                //cout<<i<<endl;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}


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

int main() {
  int N;
  cin>>N;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    a--;
    p.at(i)=a;
  }
  vector<int> z(N,-1);
  z.at(0)=0;
  int c=0,b=1;
  while(true){
    if(z.at(p.at(c))==-1){
      c=p.at(c);
      z.at(c)=b;
      b++;
    }
    else{
      break;
    }
  }
  cout<<z.at(1)<<endl;
}

Measured memory_bytes: 1152
#include <iostream>
using namespace std;
using ll = long long;

ll n;
ll k[10'005];
ll ans;
ll f;

int main()
{
    while (cin >> n, n != 0) {
        f = 0, ans = 0;
        
        for (int i = 0; i < n; i++) {
            cin >> k[i];

            if (k[i]) ans++;
            if (k[i] >= 2) f = 1;
        }

        if (f) {
            cout << ans+1 << endl;
        }
        else {
            cout << "NA" << endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 3176
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll const mod = 1000000007;

  vll dp(13, 0);
  dp[0] = 1;

  string s;
  cin >> s;
  ll n = s.size();
  rep(i, n) {
    vll ndp(13, 0);
    rep(j, 13) {
      ll res;
      if (s[i] == '?') {
        rep(k, 10){
          res = j * 10 + k;
          res %= 13;
          ndp[res] += dp[j];
          ndp[res] %= mod;
        }
      } else {
        res = j * 10 + s[i] - '0';
        res %= 13;
        ndp[res] += dp[j];
        ndp[res] %= mod;
      }
    }
    swap(dp, ndp);
  }

  cout << dp[5] << endl;

  return 0;
}


Measured memory_bytes: 3728
n = int(input())
s1 = input()
s2 = input()
i = 0
ans = 1 
while i < len(s1):
	if s1[i] == s2[i] and i == 0:
		ans = 3
		i += 1
		continue
	if s1[i] != s2[i] and i == 0:
		ans = 6
		i += 2
		continue
	if s1[i] != s2[i] and i >= 1 and s1[i-1] == s2[i-1]:
		ans = (ans*2)%(pow(10,9) + 7)
		i += 2
		continue
	if s1[i] != s2[i] and i >= 1 and s1[i-1] != s2[i-1]:
		ans = (ans*3)%(pow(10,9) + 7)
		i += 2
		continue
	if s1[i] == s2[i] and i >= 1 and s1[i-1] != s2[i-1]:
		i += 1
		continue
	if s1[i] == s2[i] and i >= 1 and s1[i-1] == s2[i-1]:
		ans = (ans*2)%(pow(10,9) + 7)
		i += 1
print(ans)

Measured memory_bytes: 9188
#include <stdio.h>

int main()
{
    int K, A, B, i, j;

    scanf("%d", &K);

    scanf("%d %d", &A, &B);

    if((K >= 1 && K <= 1000) && (A >= 1 && A <= 1000) && (B >= 1 && B <= 1000)){
        for(i = 1; i <= 1000; i++){
            j= K*i;

            if(j >= A && j <= B){
                break;
            }
        }
        if(j >= A && j <= B){
            printf("OK");
        }
        else if(j <= A || j >= B){
            printf("NG");
        }
    }
    return 0;
}


Measured memory_bytes: 1732
#include<cstdio>
#define MAXN (int)200100
#define _rep(i,a,b) for(int i = (a); i <= (b); ++i)
int N;
long long a[MAXN],b[MAXN];
int p[MAXN];
int main(){
	scanf("%d",&N);
	_rep(i,1,N)scanf("%d",&p[i]),a[i] = i * N,b[i] = (N - i + 1) * N;
	_rep(i,1,N)b[p[i]] += (i - 1);
	_rep(i,1,N - 1)printf("%lld ",a[i]);printf("%lld\n",a[N]);
	_rep(i,1,N - 1)printf("%lld ",b[i]);printf("%lld\n",b[N]);
	return 0;
}


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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<29)
#define INFLL (1L<<29)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int Cost;
struct Edge {
  int src, dst; Cost cost;
  Edge(int s, int d, Cost c) : src(s), dst(d), cost(c) {}
};
typedef vector<Edge>  Edges;
typedef vector<Edges> Graph;
typedef vector<Cost>  Array;
typedef vector<Array> Matrix;

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

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int N; cin >> N;
  vector<int> vec(N, 0);
  for (int i = 0; i < N; i++) cin >> vec[i];

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (vec[vec[i]-1] == i+1) ans++;
  }
  cout << ans / 2 << endl;
  return 0; 
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
long long int n,ans;cin>>n;
  double root = sqrt(n);
  ans = root;
  while(1){
    if(n%ans==0)break;
    ans--;
  }
  cout<<ans + n/ans -2;
  
}
  
  

Measured memory_bytes: 256
def main():
    D,G =map(int,input().split())
    pc = [list(map(int,input().split())) for i in range(D)]
    max_D = int("1"*D,2)
    res = float("inf")
    for i in range(max_D,-1,-1):
        ansed_num = 0
        point = 0
        now = format(i,"0"+str(D)+"b")
        #print(now)
        for j in range(len(now)):
            if now[j] == "1":
                #print(j+1)
                ansed_num += pc[j][0]
                point += (j+1) * 100 * pc[j][0] + pc[j][1]
        for j in range(len(now)-1,-1,-1):
            if now[j] == "0":
                ansed_num_this = 0
                while point < G and ansed_num_this < pc[j][0]:
                    ansed_num += 1
                    point += (j+1) * 100
                    ansed_num_this += 1
            #print(ansed_num,point)
            if point >= G:
                if ansed_num < res:
                    res = ansed_num
    print(res)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <string>
#include <functional>

using namespace std;

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

string dp[11][1 << 11];

int main() {
	int n;
	while (cin >> n && n) {
		vector<string> s(n);
		rep(i, n) {
			cin >> s[i];
		}
		set<int, greater<int>> del;
		rep(i, n)for (int j = i + 1; j < n; j++) {
			if (s[i] == s[j]) {
				del.insert(j);
			}
		}
		for (auto i : del) {
			s.erase(s.begin() + i);
		}
		n = s.size();
		del.clear();
		rep(i, n)rep(j, n) if(i != j) {
			rep(k, s[i].size()) {
				if (s[i].substr(k, s[j].size()) == s[j]) {
					del.insert(j);
					break;
				}
			}
		}
		for(auto i : del) {
			s.erase(s.begin() + i);
		}
		n = s.size();
		int table[11][11];
		rep(i, n)rep(j, n)if(i != j){
			table[i][j] = 0;
			rep(k, s[i].size()) {
				int len = min(s[j].size(), s[i].size() - k);
				if (s[i].substr(k) == s[j].substr(0, len)){
					table[i][j] = max(table[i][j], len);
				}
			}
		}
		rep(bit, 1 << n) {
			rep(i, n) {
				dp[i][bit] = "";
			}
		}
		rep(i, n) {
			dp[i][1 << i] = s[i];
		}
		pair<size_t, string> ans = make_pair(1e9, "");
		rep(bit, 1 << n) {
			rep(i, n)if (dp[i][bit].size()) {
				if (bit == (1 << n) - 1) {
					ans = min(ans, make_pair(dp[i][bit].size(), dp[i][bit]));
				}
				rep(j, n) {
					if ((bit & (1 << j)) == 0) {
						string next = dp[i][bit] + s[j].substr(table[i][j]);
						if (dp[j][bit | (1 << j)].size() == 0 || make_pair(next.size(), next) < make_pair(dp[j][bit | (1 << j)].size(), dp[j][bit | (1 << j)])) {
							dp[j][bit | (1 << j)] = next;
						}
					}
				}
			}
		}
		cout << ans.second << endl;

	}

	return 0;
}

Measured memory_bytes: 3652
x, n = list(map(int, input().split()))
p_list = list(map(int, input().split()))

if x not in p_list:
    print(x)
    exit()

for i in range(1, 101):
    if (x+i not in p_list) and (x-i not in p_list):
        print(x-i)
        exit()
    elif x-i not in p_list:
        print(x-i)
        exit()
    elif x+i not in p_list:
        print(x+i)
        exit()
    else:
        continue

Measured memory_bytes: 9204
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <queue>

using namespace std;

vector<vector<int> > ns;

pair<int, int> longest(int n){
    vector<int> dist(ns.size(), -1);
    dist.at(n) = 0;
    queue<int> q;
    q.push(n);
    while(!q.empty()){
        int x = q.front(); q.pop();
        for(auto y : ns.at(x)){
            if(dist.at(y) == -1){
                dist.at(y) = dist.at(x) + 1;
                q.push(y);
            }
        }
    }
    auto me = max_element(dist.begin(), dist.end());
    return make_pair(me - dist.begin(), *me);
}

int main(){
    int n;
    scanf("%d", &n);
    ns.resize(n);
    for(int i = 0; i < n - 1; ++i){
        int a, b;
        scanf("%d %d", &a, &b);
        a--; b--;
        ns.at(a).push_back(b);
        ns.at(b).push_back(a);
    }

    auto tmp = longest(0);
    int diam = longest(tmp.first).second;
    if(diam % 3 == 1){
        printf("Second\n");
    }else{
        printf("First\n");
    }
    return 0;
}


Measured memory_bytes: 13556
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////


signed main(){
  int n, m;cin>>n>>m;
  if(n == m)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
from itertools import permutations
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    n=II()
    aa=[II() for _ in range(5)]
    mn=min(aa)
    ans=(n+mn-1)//mn+4
    print(ans)

main()


Measured memory_bytes: 3316
#include <iostream>
using namespace std;
int main(){
    int a;
    int b[9];
    while(cin>>a){
if(a==0)return 0;
    for(int i=0;i<9;i++){
        cin>>b[i];
        a-=b[i];
    }
    cout<<a<<endl;
    }
}

Measured memory_bytes: 3088
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;

	int ans = a - 1;
	ans += a <= b ? 1: 0;
	cout << ans << endl;
	return 0;
}


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


ll L[50+1];
ll P[50+1];

ll dfs(ll m, ll x) {
    if (x == 0) return 0;
    if (m == 0) return x;

    if (2 * x < L[m]) {
        return dfs(m-1, max(0LL, x-1));
    } else {
        return P[m-1] + 1 + dfs(m-1, min(L[m-1], x-2-L[m-1]));
    }
}


int main() 
{
    ll n, k;
    cin >> n >> k;
    L[0] = 1;
    P[0] = 1;
    for(int i=1; i<=n; i++) {
        L[i] = 2*L[i-1] + 3;
        P[i] = 2*P[i-1] + 1;
    }

    ll ans = dfs(n, k);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

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

    int n, m;
    cin >> n >> m;
    if (n == m) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    long n,c,k;
    cin>>n>>c>>k;
    vector<long> t(n);
    rep(i,n) cin>>t[i];
    sort(all(t));
    long bus=1,num=0,time=t[0]+k;
    rep(i,n){
        if(t[i]<=time&&num<c) num++;
        else time=t[i]+k,num=1,bus++;
    }
    cout<<bus;
}

Measured memory_bytes: 4028
#include <iostream>
using namespace std;
int main(){
  int n,k;cin>>n>>k;
  int a[n][k];
  for(int i = 0; n > i; i++){
    for(int j = 0; k > j; j++){
      cin>>a[i][j];
    }
  }
  int ans = 0;
  for(int i = 0; n > i; i++){
    for(int j = i+1; n > j; j++){
      int s = 0;
      for(int z = 0; k > z; z++){
        s += (a[i][z]-a[j][z])*(a[i][z]-a[j][z]);
      }
      for(int i = 0; s >= i*i;i++){
        if(i*i==s)ans++;
      }
    }
  }
  cout << ans << endl;
}

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


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

    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

    int n;

    cin >> n;
    cout << floor(pow(n, 3)) << '\n';

    return 0;
}

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

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;cin>>n;
    int arr[n];
    memset(arr,0,sizeof(arr));
    for(int i=1;i<n;i++){
        int d;cin>>d;d--;
        arr[d]++;
    }
    for(auto x:arr)cout<<x<<'\n';
}


Measured memory_bytes: 4404
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define For(i,a,b) for(int (i)=(a); (i)<(b); (i)++)

typedef pair<int, int> P;

bool isokay(vector<P> v, P p) {
    REP(i, v.size()) {
        if (v[i].first == p.first && v[i].second == p.second) return false;
    }
    return true;
}

void solve15(int a, int b) {
    int n;
    cin >> n;
    vector<P> v;
    REP(i,n) {
        int x, y;
        cin >> x >> y;
        v.push_back(make_pair(x, y));
    }
    queue<P> que;
    int ans = 0;
    que.push(make_pair(1, 1));
    while(que.size()) {
        P pos = que.front(); que.pop();
        if (pos.first == a) {
            if (pos.second == b) ans++;
            else {
                P p = make_pair(pos.first, pos.second + 1);
                if (isokay(v, p)) que.push(p);
            }
        }else {
            if (pos.second == b) {
                P p = make_pair(pos.first + 1, pos.second);
                if (isokay(v, p)) que.push(p);
            }
            else {
                P p = make_pair(pos.first, pos.second + 1);
                if (isokay(v, p)) que.push(p);
                p = make_pair(pos.first + 1, pos.second);
                if (isokay(v, p)) que.push(p);
            }
        }
    }
    cout << ans << endl;
}

int main() {
    int a, b;
    while(cin >> a >> b, a+b) {
        solve15(a, b);
    }
    return 0;
}

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


int main() {
    string s;
    cin>>s;
    if(s[2]==s[3]){
        if(s[4]==s[5]){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(){
    ll n,w;
    cin>>n>>w;
    ll weight[n+1],profit[n+1];
    weight[0] = 0;
    profit[0] = 0;
    for(ll i = 1; i<=n; i++){
        cin>>weight[i]>>profit[i];
    }
    ll max_profit = 0;
    for(auto i:profit){
        max_profit +=i;
    }
    vector<ll>dp(max_profit+1,INT_MAX);
    dp[0] = 0;
    for(ll item = 1;item<=n;item++){
        for(ll value = max_profit; value >= profit[item]; value--){
            dp[value] = min(dp[value],dp[value-profit[item]] + weight[item]);
            // cout<<dp[value]<<" ";
        }
        // cout<<endl;
    }
    ll res = 0;
    for(ll i = 1; i<=max_profit;i++){
        if(dp[i] <= w){
            // cout<<dp[i]<<" "<<i<<endl;
            res = max(res,i);
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int MAXN = 100005;
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;

int N;
int x[MAXN];
int suff[MAXN];

void load() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++)
    scanf("%d", x + i);
}

void mn(int &a, int b) {
  a = min(a, b);
}

int solve() {
  memset(suff, INF, sizeof suff);
  suff[N] = N;
  for (int i = 0; i < N; i++)  
    if (x[i] <= 2 * i)
      mn(suff[(2 * i - x[i]) / 2], i);
  
  int sol = 1;
  for (int i = N - 1; i >= 0; i--) {
    suff[i] = min(suff[i], suff[i + 1]);
    sol = (long long)sol * (min(suff[i] + 1, N) - i) % MOD;
  }
  
  return sol;
}

int main() {
  load();
  printf("%d\n", solve());
  return 0;
}

Measured memory_bytes: 896
package main

import (
    "fmt"
    "os"
    "bufio"
    "strconv"
    // "sort"
)
var sc = bufio.NewScanner(os.Stdin)


func main() {
    sc.Split(bufio.ScanWords)
    // code goes here
    str := nextString()
    N := len(str)
    
    best := 0
    cnt := 0
    for i := 0; i < N; i+=1 {
        if (str[i] == 'A' || str[i] == 'G' || str[i] == 'C' || str[i] == 'T') {
            cnt += 1
        } else {
            cnt = 0
        }
        best = Max(best, cnt)
    }
    fmt.Println(best)
}



func nextInt() int {
    sc.Scan()
    v, e := strconv.Atoi(sc.Text())
    if e != nil { panic(e) }
    return v
}
func nextInt64() int64 {
    sc.Scan()
    v, e := strconv.ParseInt(sc.Text(), 10, 64)
    if e != nil { panic(e) }
    return v
}
func nextString() string {
    sc.Scan()
    return sc.Text()
}
func nextFloat() float64 {
    sc.Scan()
    v, e := strconv.ParseFloat(sc.Text(), 64)
    if e != nil { panic(e) }
    return v
}
func Max(x, y int) int { if x > y { return x }; return y }
func Min(x, y int) int { if x < y { return x }; return y }
func Abs(x int) int { if x > 0 { return x }; return -x }

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;
  ll dir = 1;
  vector<ll> res;
  for(int i = 0;i < n;i++){
    ll in;
    cin >> in;
    if(dir == 1)res.push_back(in);
    else res.insert(res.begin(),in);
    dir *= -1;
  }
  if(dir == -1)reverse(res.begin(),res.end());
  for(int i = 0;i < n - 1;i++)cout << res[i] << " ";
  cout << res[n - 1] << endl;
}

Measured memory_bytes: 5348
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
typedef long long ll;
typedef long double ld;
#define trace(x)  cerr << #x << ": " << x << endl;
const int N=1e6+5;
ll n,k;vector<ll> a(N);
int main()
{
	fast;
	ll n,k;cin>>n>>k;ll a[n];for(ll i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);ll sum=0;for(ll i=0;i<k;i++)sum+=a[i];
	cout<<sum;
	
	
}

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


typedef long long ll;
typedef pair<ll,int> P;

struct edge {int to; ll cost; };

int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int n;
  cin >> n;
  vector<P> a;
  for(int i=1; i<=n; i++){
    int k;
    cin >> k;
    a.push_back(make_pair(k, i));
  }
  sort(a.begin(), a.end());
  for(int i=0; i<n; i++){
    if(i==n-1) cout << a[i].second << endl;
    else cout << a[i].second << " ";
  }
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n+1);
  rep(i,n) cin >> a[i+1];
  vector<int> b(n+1);
  for (int i = n; i >= 1; --i) {
    int sum = 0;
    for (int j = i+i; j <= n; j += i) {
      sum ^= b[j];
    }
    b[i] = sum^a[i];
  }
  vector<int> ans;
  for (int i = 1; i <= n; i++) {
    if (b[i]) ans.push_back(i);
  }
  cout << ans.size() << endl;
  rep(i,ans.size()) {
    printf("%d%c", ans[i], i+1==ans.size()?'\n':' ');
  }
  return 0;
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(0)
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
typedef long long ll;
#define pri(n) printf("%d\n",n)
#define lpri(n) printf("%lld\n",n);
#define rep(i,st,ed) for(int i=st;i<ed;i++)
#define F first
#define S second 
#define pb(n) push_back(n)
const int N=1e5+6;
const ll M=1e9+7;
ll dp[3001][3001],a[3001],pre[3001];
void rec(int i,int j)
{
	if(dp[i][j]!=-1)
		return ;
	if(i==j)
	{
		dp[i][j]=a[i];
		return ;
	}
	if(i>j)
	{
		dp[i][j]=dp[i][j]=0;
		return ;
	}
	rec(i+1,j);
	rec(i,j-1);

	ll val2;
	ll val1=a[i]+pre[j]-pre[i]-dp[i+1][j];
	if(i)
		val2=a[j]+pre[j-1]-pre[i-1]-dp[i][j-1];
	else
		val2=a[j]+pre[j-1]-dp[i][j-1];
	dp[i][j]=max(val1,val2);
}
int main()
{
	int n;
	scn(n);
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<n;i++)
	{
		lscn(a[i]);
		pre[i]=a[i];
		if(i)
			pre[i]+=pre[i-1];
	}
	rec(0,n-1);

	// for(int i=0;i<n;i++)
	// {
	// 	for(int j=0;j<n;j++)
	// 		printf("%lld \t",dp[i][j]);
	// 	printf("\n");
	// }
	ll taro=dp[0][n-1];
	ll jiro=pre[n-1]-taro;
	lpri(taro-jiro);
}

Measured memory_bytes: 70784