akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder.Question
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var k = ReadHelper.ReadValue<int>();
            var (a, b) = ReadHelper.ReadValue<int, int>();
            var mod = a % k;
            Console.WriteLine(mod == 0 || b >= a + k - mod ? "OK" : "NG");
        }

        static class ReadHelper
        {
            internal static T ReadValue<T>()
            {
                return (T)Convert.ChangeType(Console.ReadLine(), typeof(T));
            }
            internal static (T1, T2) ReadValue<T1, T2>()
            {
                var input = Console.ReadLine().Split(' ');
                return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)));
            }
            internal static (T1, T2, T3) ReadValue<T1, T2, T3>()
            {
                var input = Console.ReadLine().Split(' ');
                return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)));
            }
            internal static (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>()
            {
                var input = Console.ReadLine().Split(' ');
                return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)), (T4)Convert.ChangeType(input[3], typeof(T4)));
            }
            internal static T[] ReadValues<T>()
            {
                var input = Console.ReadLine().Split(' ');
                return input.Select(x => (T)Convert.ChangeType(x, typeof(T))).ToArray();
            }
        }

        static class MathAlgorithm
        {
            internal static bool IsPrime(long n)
            {
                if (n == 2) return true;
                if (n < 2 || n % 2 == 0) return false;
                var sqrt = Math.Sqrt(n);
                for (int i = 3; i <= sqrt; i += 2) if (n % i == 0) return false;
                return true;
            }
            internal static IEnumerable<long> EnumeratePrimes(long n)
            {
                var i = 2L;
                while (i * i <= n)
                {
                    if (n % i == 0)
                    {
                        n /= i;
                        yield return i;
                    }
                    else
                    {
                        i += i == 2 ? 1 : 2;
                    }
                }
                if (n != 1) yield return n;
            }
        }
    }
}


Measured memory_bytes: 27524
class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        # 根への距離を管理
        self.weight = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            # 親への重みを追加しながら根まで走査
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    # 併合
    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        # xの木の高さ < yの木の高さ
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        # xの木の高さ ≧ yの木の高さ
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            # 木の高さが同じだった場合の処理
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    # 同じ集合に属するか
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # xからyへのコスト
    def diff(self, x, y):
        return self.weight[x] - self.weight[y]
    
n,m = map(int,input().split())
lrd = [[int(i) for i in input().split()] for j in range(m)]

ki = WeightedUnionFind(n)

for i in range(m):
    if ki.same(lrd[i][0],lrd[i][1]):
        if ki.diff(lrd[i][0],lrd[i][1]) != lrd[i][2]:
            print('No')
            exit()
    else:
        ki.union(lrd[i][0],lrd[i][1],lrd[i][2])
    
print('Yes')

Measured memory_bytes: 46928
import sys
input = sys.stdin.readline
class UnionFindNode:
    def __init__(self, group_id, parent=None, value=None):
        self.group_id_ = group_id
        self.parent_ = parent
        self.value = value
        self.rank_ = 1
        self.member_num_ = 1

    def is_root(self):
        return not self.parent_

    def root(self):
        parent = self
        while not parent.is_root():
            parent = parent.parent_
            self.parent_ = parent
        return parent

    def find(self):
        root = self.root()
        return root.group_id_

    def rank(self):
        root = self.root()
        return root.rank_

    def unite(self, unite_node):
        root = self.root()
        unite_root = unite_node.root()

        if root.group_id_ != unite_root.group_id_:
            if root.rank() > unite_root.rank():
                n_root, child = root, unite_root
            else:
                n_root, child = unite_root, root
            child.parent_ = n_root
            n_root.rank_ = max(n_root.rank_, child.rank_ + 1)
            n_root.member_num_ = n_root.member_num_ + child.member_num_
N, K, L = map(int, input().split())
node_list1 = [UnionFindNode(i) for i in range(N)]
node_list3 = [UnionFindNode(i) for i in range(N)]
for _ in range(K):
    a, b = map(int, input().split())
    node_list1[a-1].unite(node_list1[b-1])
#    node_list3[a-1].unite(node_list3[b-1])
    
node_list2 = [UnionFindNode(i) for i in range(N)]
for _ in range(L):
    a, b = map(int, input().split())
    node_list2[a-1].unite(node_list2[b-1])
#    node_list3[a-1].unite(node_list3[b-1])
rs = []
from collections import defaultdict
d = defaultdict(int)
for i in range(N):
    rs.append((node_list1[i].root().group_id_, node_list2[i].root().group_id_))
    d[(node_list1[i].root().group_id_, node_list2[i].root().group_id_)] += 1

for i in range(N):
    print(d[(node_list1[i].root().group_id_, node_list2[i].root().group_id_)])


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

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

    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == t[i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
// ITP_1_4-B

import java.util.Scanner;

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

		final double PI = Math.PI;
		double r;
		double en_menseki;
		double en_shu;

		r = sc.nextDouble ();
		en_menseki = r * r * PI;
		en_shu = 2 * PI * r;

		System.out.println ( String.format ( "%.6f", en_menseki ) + " " + String.format ( "%.6f", en_shu ) );
	}
}

Measured memory_bytes: 28136
import sys
from collections import Counter
n = int(input())
D = list(map(int,input().split()))
if D[0] != 0 or D.count(0) != 1:
    print(0)
    sys.exit()
D = Counter(D)
L = sorted(D.items())
pk = 0
pv = 1
ans = 1
for i,j in L:
    if i == 0:
        continue
    if i != pk+1:
        print(0)
        break
    ans *= pv**j
    ans %= 998244353
    pk = i
    pv = j
else:
    print(ans)

Measured memory_bytes: 20684
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
void sleep( double sec = 1021 ){
  clock_t s = clock();
  while( clock() - s < CLOCKS_PER_SEC * sec );
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/
void build(){

}
LL x , y;
void init(){
  cin >> x >> y;
}
void solve(){
  if( x % y == 0 )
    cout << -1 << endl;
  else
    cout << x << endl;
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
string str;
ll res;
int main(void){
    // Your code here!
    cin >> str;
    for (int i = 0; i < str.length(); i++) {
        res += str[i] - '0';
    }
    if (res == 1) cout << 10 << endl;
    else cout << res << endl;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;

class Program
{
    static void Solve()
    {
        var S = Read();
        var rest = 15 - S.Length;

        var win = 0;
        foreach (var s in S)
        {
            if (s == 'o') win++;
        }

        Console.WriteLine(win + rest >= 8 ? "YES" : "NO");
    }


    static void Main(string[] args)
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();

    }

    public static string Read() { return Console.ReadLine(); }
    public static int ReadInt() { return int.Parse(Read()); }
    public static long ReadLong() { return long.Parse(Read()); }
    public static double ReadDouble() { return double.Parse(Read()); }

    public static string[] Reads() { return Console.ReadLine().Split(' '); }
    public static int[] ReadInts() { return Reads().Select(_ => int.Parse(_)).ToArray(); }
    public static long[] ReadLongs() { return Reads().Select(_ => long.Parse(_)).ToArray(); }
    public static double[] ReadDoubles() { return Reads().Select(_ => double.Parse(_)).ToArray(); }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main()
{
	 string s;
	 cin>>s;
	 long long  m;
	 cin>>m;
	 long long k;
	 double sum=0;
	 for(int i=0;i<s.length();i++)
	 { 
	    sum+=pow((s[i]-'0'),5*10e+15);
	    
	    if(sum>=m)
	    {
	    	 cout<<s[i]<<endl;
	    	 return 0;
		}
	 }
	
}

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

int main(){
  
  int N,count=0;
  cin >> N;
  
  for(int i=0; i<N; i++){
    char x;
    cin >> x;
    if(x=='Y'){
      count++;
    }
  }
  
  if(count==0){
    cout << "Three" << endl;
  }
  else{
    cout << "Four" << endl ;
  }
    
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define INTMAX 2147483647LL
#define PII pair<int,int>
#define MK make_pair
#define re register
#define Eps (1e-10)
#define Equal(a,b) (fabs((a)-(b))<Eps)
using namespace std;
typedef long long ll;
typedef double db;
const double Pi=acos(-1.0);
const int Inf=0x3f3f3f3f;

inline int read(){
	re int x=0,f=1,ch=getchar();
	while(!isdigit(ch))f=ch=='-'?-1:1,ch=getchar();
	while(isdigit(ch))x=x*10+ch-48,ch=getchar();
	return x*f;
}
inline ll readll(){
	re ll x=0,f=1,ch=getchar();
	while(!isdigit(ch))f=ch=='-'?-1:1,ch=getchar();
	while(isdigit(ch))x=x*10+ch-48,ch=getchar();
	return x*f;
}

struct Point{
	db x,y;
	Point(){}
	Point(db xx,db yy):x(xx),y(yy){}
	inline Point operator +(const Point &p){return Point(x+p.x,y+p.y);}
	inline Point operator -(const Point &p){return Point(x-p.x,y-p.y);}
	inline Point operator *(const db &k){return Point(x*k,y*k);}
	inline Point operator /(const db &k){return Point(x/k,y/k);}
	inline db Norm(){return x*x+y*y;}
	inline db abs(){return sqrt(Norm());}
	inline bool operator <(const Point &p)const{return x!=p.x?x<p.x:y<p.y;}
	inline bool operator ==(const Point &p)const{return fabs(x-p.x)<Eps&&fabs(y-p.y)<Eps;}
}; 

typedef Point Vector;
typedef vector<Point> Poly;

struct Segment{
	Point p1,p2;
	Segment(){}
	Segment(Point p1_,Point p2_):p1(p1_),p2(p2_){}
};
typedef Segment Line;
struct Circle{
	Point c;db r;
	Circle(Point cc,db rr):c(cc),r(rr){}
};

double norm(Vector a){return a.x*a.x+a.y*a.y;}
double abs(Vector a){return sqrt(norm(a));}
double dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
double cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}

inline bool Is_Vertical(Vector a,Vector b){return Equal(dot(a,b),0.0);}
inline bool Is_Vertical(Point a1,Point a2,Point b1,Point b2){return Is_Vertical(a1-a2,b1-b2);}
inline bool Is_Vertical(Segment s1,Segment s2){return Equal(dot(s1.p2-s1.p1,s2.p2-s2.p1),0.0);}

inline bool Is_Parallel(Vector a,Vector b){return Equal(cross(a,b),0.0);}
inline bool Is_Parallel(Point a1,Point a2,Point b1,Point b2){return Is_Parallel(a1-a2,b1-b2);}
inline bool Is_Parallel(Segment s1,Segment s2){return Equal(cross(s1.p2-s1.p1,s2.p2-s2.p1),0.0);}

Point Project(Segment s,Point p){
	Vector bse=s.p2-s.p1;
	double res=dot(p-s.p1,bse)/norm(bse);
	return s.p1+bse*res;
}
Point Reflect(Segment s,Point p){
  return p+(Project(s,p)-p)*2.0;
}

int q;
int x,y,xx,yy;

int main(){
	x=read();y=read();xx=read();yy=read();q=read();
	Line bse=Line(Point(x,y),Point(xx,yy));
	while(q--){
		x=read();y=read();
		Point p=Reflect(bse,Point(x,y));
		printf("%.8lf %.8lf\n",p.x,p.y);
	}
	return 0;
}


Measured memory_bytes: 3232
#include<bits/stdc++.h>
#define PB push_back
#define FO(i,a,b) for (int i = a; i <= b; i++)
#define FOb(i,a,b) for(int i=b;i>=a;i--)
#define vi vector<int>
#define vulli vector<unsigned long long int>
using namespace std;
typedef unsigned long long int ulli;
void solve()
{ 
 
 ulli n,t=1000;
 cin >> n;
 while(n>t)
        t += 1000;
    cout << t - n;    
  
}
int main()
{
    std::ios_base::sync_with_stdio(false);
    ulli t=1;
   // cin>>t;   
    while(t--){ solve(); cout<<"\n"; }
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  string s,t;
  cin >> s >> t;
  rep(i,s.size()) {
    rotate(s.begin(),s.begin()+1,s.end());
    if(s==t) {
      pr("Yes");
      return;
    }
  }
  pr("No");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()
    
    def gcd(x,y):
        r = x%y
        if r==0:
            return y

        return gcd(y, r)

    a, b  = map(int, input().split())
    c = gcd(a, b)

    tmp = c
    cnt = 1
    for i in range(2, int(c**0.5)+1):

        if tmp%i == 0:
            cnt += 1
            while tmp%i == 0:
                tmp /= i
    if tmp != 1:
        cnt += 1
    print(cnt) 

            
            
    




    
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9444
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

const string C = "RGB";

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

    long long ret = 0;
    for (int i = 0; i < n; i++) {
        int here = -1;
        for (int j = 0; j < 3; j++) {
            if (C[j] == s[i])here = j;
        }

        vector<set<int>> se(2);
        for (int j = 1; i + j < n; j++) {
            for (int k = 1; k < 3; k++) {
                if (C[(here + k) % 3] == s[i + j])se[k - 1].insert(j);
            }
        }

        for (auto x:se[0]) {
            ret += se[1].size();
            if (se[1].find(x * 2) != se[1].end())ret--;
            if (x % 2 == 0 && se[1].find(x / 2) != se[1].end())ret--;
        }
    }
    cout << ret << endl;
    return 0;
}

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

int main() {
	int n,x,t;
	cin>>n>>x>>t;
	if(n==x){
	    cout<<t;
	}else{
	    int ans=0;
	    int remain = n-x;
	    while(remain>0){
	        ans++;
	        remain=remain-x;
	    }
	    t=t+ans*t;
	    cout<<t;
	}
	
}

Measured memory_bytes: 3592
#include <iostream>

int main(void){
    /* input */
    int width   = 0;
    int height  = 0;
    int circleX = 0;
    int circleY = 0;
    int circleR = 0;
    int result  = 0;
    std::cin >> width >> height >> circleX >> circleY >> circleR;
    
    /* judge */
    if( ((circleX - circleR) < 0 )      /* left side   */
     || ((circleY - circleR) < 0 )      /* bottom side */
     || ((circleX + circleR) > width)   /* right side  */
     || ((circleY + circleR) > height) )/* upper side  */
    {
        result = -1;    /* area over */
    }
    
    /* output */
    if(result == 0)
    {
        std::cout << "Yes" << std::endl;
    }
    else
    {
        std::cout << "No" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3096
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for(int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef complex<double> com;
typedef pair<ll,ll> P;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;



int main(){
	int r, g, b, n; cin >> r >> g >> b >> n;
	int ans = 0;
	rep(i, 0, n+1)rep(j, 0, n+1) {
		int k = n - i * r - j * g;
		if (k>=0&&k%b==0) ans++;
	}
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    str_list = [input() for _ in range(n)]

    if len(str_list) != len(set(str_list)):
        print('No')
        exit()

    for i in range(1,n):
        if str_list[i-1][-1] != str_list[i][0]:
            print('No')
            exit()

    print('Yes')

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
char a[10];
int vis[10000];
int main(){
	cin>>a+1;
	int n = strlen(a+1);
	if(a[1] == a[2] && a[1] == a[3]) cout<<"Yes";
	else if(a[1] == a[2] && a[1] == a[3] && a[1] == a[4]) cout<<"Yes";
	else if(a[2] == a[3] && a[2] == a[4]) cout<<"Yes";
	else cout<<"No";
	return 0;
}

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

int main() {
    int n,a,b;
    int count = 0;
    int countB = 1;
    string s;
    cin >> n >> a >> b >> s;

    for(int i = 0; i < n; i ++){
        if(s[i] != 'c'){
            if(count < a+b){
                if(s[i] == 'a'){
                    count ++;
                    cout << "Yes" << endl;
                }else if(s[i] == 'b' && countB <= b){
                    count ++;
                    countB ++;
                    cout << "Yes" << endl;
                }else{
                    cout << "No" << endl;
                }
            }else{
                cout << "No" << endl;
            }
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3716
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 * 
 * @author daltao
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "daltao", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            PrintWriter out = new PrintWriter(outputStream);
            TaskA solver = new TaskA();
            solver.solve(1, in, out);
            out.close();
        }
    }
    static class TaskA {
        public void solve(int testNumber, FastInput in, PrintWriter out) {
            char[] s = new char[200000];
            int n = in.readString(s, 0);
            int sCnt = 0;
            int tCnt = 0;
            for (int i = 0; i < n; i++) {
                if (s[i] == 'S') {
                    sCnt++;
                } else {
                    if (sCnt > 0) {
                        sCnt--;
                    } else {
                        tCnt++;
                    }
                }
            }

            out.println(sCnt + tCnt);
        }

    }
    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readString(char[] data, int offset) {
            skipBlank();

            int originalOffset = offset;
            while (next > 32) {
                data[offset++] = (char) next;
                next = read();
            }

            return offset - originalOffset;
        }

    }
}



Measured memory_bytes: 23508
#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() {
  int H, W; cin >> H >> W;
  char num[26] = {};
  rep(i,H) {
    string a; cin >> a;
    rep(j,W) num[a[j]-'a']++;
  }
  int d1 = 0, d2 = 0, d4 = 0;
  rep(i,26) {
    if (num[i]%2) d1++;
    else if (num[i]%4) d2++;
    else d4++;
  }
  
  string result;
  if (H%2&&W%2) {
    result = (d1==1&&d2*2<=H+W-2) ? "Yes" : "No";
  }
  else if (H%2) {
    result = (d1==0&&d2*2<=W) ? "Yes" : "No";
  } 
  else if (W%2) {
    result = (d1==0&&d2*2<=H) ? "Yes" : "No";
  }
  else {
    result = (d1==0&&d2==0) ? "Yes" : "No";
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <string>

using namespace std;

int main() {
    string s;
    stack<int> st;

    while (cin >> s) {
        if (s == "+") {
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(a + b);
        } else if (s == "-") {
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(b - a);
        } else if (s == "*") {
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(a * b);
        } else {
            // convert string to integer
            // require c++11
            st.push(stoi(s));
        }
    }
    cout << st.top() << endl;

    return 0;
}

Measured memory_bytes: 3180
def solve(S):
    dp = [0]*(2000+1)
    dp[0] = 1
    dp[3] = 1
    MOD = 10**9+7
    for n in range(4, S+1):
        answer = 0
        for c in range(3, n+1):
            #print(n, "c=%d"%c, dp[c])
            answer = (answer + dp[n-c]) % MOD
        dp[n] = answer % MOD
        #print(n, dp[n])
    return dp[S]
#solve(7)
print(solve(int(input())))


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

using namespace std;

#define pb push_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define fast_cin ios_base::sync_with_stdio(false)

const int MOD = 1e9+7;

typedef long long ll;

bool comp(ll a, ll b){

	return a > b;
}
int main(int argc, char const *argv[])
{
	ll x,y,z;
	cin >> x >> y >> z;
	if ((x % (y + z)) < z)
	{
		cout << (x/ (y+z)) - 1 << endl;
	}
	else{
		cout << (x/ (y+z)) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    ll b[n + 1];
    b[0] = INF;
    b[n] = INF;
    REP(i,n - 1){
        cin >> b[i + 1];
    }
    ll ans = 0;
    REP(i,n){
        ans += min(b[i], b[i + 1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
n, k = map(int, input().split())
x=Base_10_to_n(n, k)
xx = str(x)
print(len(xx))

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 0x3f3f3f3f;
const ll LINF = 1ll << 55;
const ll MOD = 1e9 + 7;
const ll MAXN = 400 + 5;
const ll MAXK = 1e5 + 10;

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

int main() {
    ll N;
    cin >> N;
    vll A(N);
    vll B(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    for (int i = 0; i < N; ++i) {
        cin >> B[i];
    }
    vll a(N);
    vll b(N);
    ll ans = 0;
    for (int i = 0; i < 40; ++i) {
        ll T2 = 1ll << (i + 1);
        ll T = 1ll << i;
        for (int j = 0; j < N; ++j) {
            a[j] = A[j] % T2;
            b[j] = B[j] % T2;
        }
        sort(b.begin(), b.end());
        ll cnt = 0;
        for (ll& x : a) {
            ll k1 = lower_bound(b.begin(), b.end(), T - x) - b.begin();
            ll k2 = lower_bound(b.begin(), b.end(), 2 * T - x) - b.begin();
            ll k3 = lower_bound(b.begin(), b.end(), 3 * T - x) - b.begin();
            cnt += k2 - k1 + N - k3;
        }
        if (cnt & 1) {
            ans += T;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8576
S = input()
T = input()
q = int(input())
ans = []

cnt = 0
sbs = [0]
for c in S:
    if c == 'B':
        cnt += 1
    sbs.append(cnt)
cnt = 0
tbs = [0]
for c in T:
    if c == 'B':
        cnt += 1
    tbs.append(cnt)

for _ in range(q):
    a, b, c, d = map(int, input().split())
    sb = sbs[b] - sbs[a - 1]
    tb = tbs[d] - tbs[c - 1]
    sa = (b - a) + sb
    if tb % 2 == 0:
        ta = (d - c - tb) + tb // 2
    else:
        ta = (d - c - tb) + (tb + 3) // 2
    if (sa - ta) % 3 == 0:
        ans.append('YES')
    else:
        ans.append('NO')

for yn in ans:
    print(yn)


Measured memory_bytes: 9644
//#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;


// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T>
constexpr int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F>
constexpr int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T>
void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C>
void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U>
constexpr void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U>
constexpr void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C>
constexpr void reverse(C& c) { reverse(ALL(c)); }
template<typename C>
constexpr void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred>
constexpr void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9+7)
#pragma endregion


int main()
{
    int d;
    while(cin>>d) {
        int n=0, s=0;
        while(n<600) {
            s+=n*n*d;
            n+=d;
        }
        P(s);
    }
    return 0;
}

Measured memory_bytes: 3084
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::io::Read;
use std::io::{stdout, BufWriter, Write};
 
fn main() {
    let mut buf = String::new();
    
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
 
    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();
 
    // 読み込んだStringを空白で分解する
    let mut iter = buf.split_whitespace();
 
    
    let n: usize = iter.next().unwrap().parse().unwrap();
    
    let mut d : Vec<u32> = (0..n).map(|_| {
        iter.next().unwrap().parse().unwrap()
        }).collect();
    
    d.sort();
    
    //println!("{:?}",d);
    
    if d[n/2 - 1] == d[n/2] {
        println!("0");
    }else {
        println!("{}", d[n/2] - d[n/2-1]);   
    }
    
    /*
    let mut buf = [0u32; 100001];
    
    let mut min = 100000;
    let mut max = 0;
    
    for i in 0..n {
        let item = d[i];
        //println!("item {}" ,item);
        buf[item as usize] += 1;
        if item < min {
            min = item;
        }
        else if item > max {
            max = item;
        }
    }
    
    let mut kcount = 0;
    let mut under = buf[min as usize];
    for i in min+1..max{
        if under * 2 == n as u32 {
            //println!("detect {}", i);
            kcount += 1;
        }
        if under * 2 > n as u32 {
            break;
        }
        
        // for next steps
        under += buf[i as usize];
    }

    //println!("{} {}", min, max);
    println!("{}", kcount);
    
    //println!("{:?}", buf);
    */
}

Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAX = 1000000;
const int INF = 1e9;
const double pi=acos(-1);

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  string s;
  cin >> s;
  int num=0;
  int abr=0;
  rep(i,n){
    if(s[i]=='c'){
      cout <<"No"<<endl;
    }
    else if(s[i]=='a'){
      if(num<(a+b)){
        cout <<"Yes"<<endl;
        num++;
      }
      else cout <<"No"<<endl;
    }
    else{
      if(num<(a+b)&&abr<b){
        cout <<"Yes"<<endl;
        num++;
        abr++;
      }
      else cout <<"No"<<endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 896
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] s = br.readLine().split(" ");
        int[] arr = new int[n];
        for(int i=0; i<n;i++) {
            arr[i] = Integer.parseInt(s[i]);
        }
        int q = Integer.parseInt(br.readLine());
        int[][] qarr = new int[q][2];
        for(int i=0; i<q;i++) {
            String[] t = br.readLine().split(" ");
            qarr[i][0] = Integer.parseInt(t[0]);
            qarr[i][1] = Integer.parseInt(t[1]);
        }
        int[] carr = new int[100000];
        long k = 0;
        for(int i=0; i<n;i++) {
            carr[arr[i]-1]+=1;
            k+=(long)arr[i];
        }
        for(int i=0; i<q;i++) {
            long a = (long)carr[qarr[i][0]-1];
            long b = (long)qarr[i][0];
            long c = (long)qarr[i][1];
            k-=a*b;
            k+=a*c;
            carr[qarr[i][1]-1]+=a;
            carr[qarr[i][0]-1]=0;
            System.out.println(k);
        }
    }
}


Measured memory_bytes: 60860
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int P = sc.nextInt();
        int Q = sc.nextInt();
        int R = sc.nextInt();
        sc.close();

        int tmp=0;

        ArrayList<Integer> list = new ArrayList<>();

        list.add(P);
        list.add(Q);
        list.add(R);

        Collections.sort(list);

        int one = list.get(0);
        int two = list.get(1);

        System .out.println(one+two);

    }
}

Measured memory_bytes: 22356
#include<stdio.h>
#define MAX 2000000
#define INFTY 1<<30

int A[MAX + 1]; // 1オリジン
int H; // 要素数

void maxHeapify(int i)
{
	int v = A[i];
	int parent = i;

	int cl, cr, child;
	while (true)
	{
		cl = parent * 2;
		cr = parent * 2 + 1;

		if (cl > H) break;

		if (cr <= H && A[cl] < A[cr])
		{
			child = cr;
		}
		else
		{
			child = cl;
		}

		if (v >= A[child]) break;
		A[parent] = A[child];
		parent = child;
	}
	A[parent] = v;
}

// 最大値を取り出して、ヒープを再構築する
int extract()
{
	int x = A[1];
	A[1] = A[H];
	H = H - 1;
	maxHeapify(1);
	return x;
}

// 要素iのキー値を指定のキー値に増やす
void increaseKey(int i, int key)
{
	if (A[i] >= key) return;

	int v = key;
	int c = i;
	while (c / 2 > 0 && A[c / 2] < v)
	{
		A[c] = A[c / 2];
		c = c / 2;
	}
	A[c] = v;
}

// 指定のキー値をヒープに挿入(追加)する
void insert(int key)
{
	H = H + 1;
	A[H] = -1 * INFTY;
	increaseKey(H, key);
}

int main()
{
	H = 0;

	char com[20];
	int key;
	while (true)
	{
		scanf("%s%d", com, &key);
		if (com[0] == 'i')
		{
			insert(key);
		}
		else if (com[0] == 'e'&&com[1] == 'x')
		{
			printf("%d\n", extract());
		}
		else
		{
			break;
		}
	}
}


Measured memory_bytes: 6664
const teststr = 
"""
1333333333
"""

function lines()
  Channel{String}(32) do ch
    ll = readlines()
    lines = isempty(ll) ? split(teststr, "\n") : ll
    for s in lines
      put!(ch, s)
    end
  end
end

quit() = exit(0)
in_1(ch) = parse(Int, take!(ch))
in_a(ch) = parse.(Int, split(take!(ch)))

function main()
  ch = lines()
  X = in_1(ch)
  m = 100
  y = 0
  while m < X
    y += 1
    m = floor(Int, m * 1.01)
  end
  println(y)
end

main()


Measured memory_bytes: 177284
#include<stdio.h>

int main(){
  int n;
  int i;
  int debt=100000;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    debt=debt*105/100;
    if(debt%1000!=0){
      debt=(1+debt/1000)*1000;
    }
  }

  printf("%d\n",debt);

  return 0;
}

Measured memory_bytes: 592
#![allow(unused_imports)]
#![allow(unused_variables)]

use itertools::Itertools;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        a: i32,
        b: i32,
        c: i32,
        k: i32,
    }

    let ans = if a >= k {
        k
    } else if a + b >= k {
        a
    } else {
        a - (k - a - b)
    };

    println!("{}", ans);
}


Measured memory_bytes: 2164
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    int ans = 0;
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        for(int j = i; j < s.size(); j++){
            int flg = 1;
            for(int k = i; k <= j; k++){
                if(s[k] != 'A' && s[k] != 'C' && s[k] != 'G' && s[k] != 'T')flg = 0;
            }
            if(flg)ans = max(ans, 1 + j - i);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
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<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, d;
    cin >> n >> d;
    d = 2 * d + 1;
    cout << (n + d - 1) / d << endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cstring>
#include <cstdio>

using namespace std;

void runCase();

const int N = 400005;
char s[N];

void runCase()
{
	scanf("%s",s);
	long long olen = strlen(s);
	long long res = 0;
	long long cnt[26] = {0};
	for(int i = 0; i < olen; i++) cnt[s[i]-'a']++;
	for(int i = 0; i < 26; i++) {
		res += cnt[i]*(cnt[i]+1)/2;
	}
	res = 1LL * olen * (olen+1) / 2 - res + 1;
	cout << res << endl;
}

int main()
{
	runCase();
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  long long A, B, N;
  cin >> A >> B>> N;
  long long x = min(N, B - 1);
  long long ans = A * x / B;
  ans -= A * (x / B);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3556
#include <stdio.h>
#include <string>
#include <string.h>
#include <cstring>
#include <algorithm>

using namespace std;
int a;
char test[21];
char temp;

int main()
{
	scanf("%s",test);
	for(a=strlen(test)-1;a>=0;a--)
	{
	printf("%c",test[a]);
	}
	printf("\n");
	return 0; 
}

Measured memory_bytes: 932
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using ld = long double;
using vld = vector<ld>;
using vvld = vector<vld>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

#define fst first
#define snd second

const int INF = 1e9;
struct edge
{
    int c;
    P p;
    edge(int c, P p) : c(c), p(p) {}
    bool operator>(const edge &r) const { return c > r.c; }
};
int main()
{

    int h, w, k, x1, y1, x2, y2;
    cin >> h >> w >> k;
    cin >> y1 >> x1 >> y2 >> x2;
    x1--;
    y1--;
    x2--;
    y2--;
    vvchar g(h, vchar(w));
    rep(y, h) rep(x, w) cin >> g[y][x];
    vvint v(h, vint(w, INF));

    priority_queue<edge, vector<edge>, greater<edge>> q;
    P start = P(y1, x1), goal = P(y2, x2);
    q.push(edge(0, start));
    v[y1][x1] = 0;

    vint dy = {0, 1, 0, -1}, dx = {1, 0, -1, 0};
    while (q.size())
    {
        edge e = q.top();
        q.pop();
        P p = e.p;

        if (p == goal)
        {
            break;
        }

        int now = e.c;
        rep(dir, 4) for (int i = 1; i <= k; i++)
        {
            int ny = p.fst + dy[dir] * i;
            int nx = p.snd + dx[dir] * i;
            if (ny < 0 || nx < 0 || ny > h - 1 || nx > w - 1 || g[ny][nx] == '@' || v[ny][nx] <= now)
            {
                break;
            }

            if (v[ny][nx] > now + 1)
            {
                v[ny][nx] = now + 1;
                q.push(edge(now + 1, P(ny, nx)));
            }
        }
    }

    ld ans = ceil(v[y2][x2]);
    if (ans == INF)
    {
        ans = -1;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11996
// ABC 119

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static int N;
    static int A;
    static int B;
    static int C;
    static int[] l;

    static void Main()
    {
        int[] inp = Console.ReadLine().Split().Select(int.Parse).ToArray();
        N = inp[0];
        A = inp[1];
        B = inp[2];
        C = inp[3];
        l = new int[N];
        for (int i = 0; i < N; i++)
            l[i] = int.Parse(Console.ReadLine());

        List<int> bam = new List<int>();
        foreach (var i in l) bam.Add(i);
        Console.WriteLine(Solv(bam));
    }

    /* 合成魔法なし */
    static int Min(List<int> bam)
    {
        int[] a = bam.Select(s => Math.Abs(s - A)).ToArray();
        int[] b = bam.Select(s => Math.Abs(s - B)).ToArray();
        int[] c = bam.Select(s => Math.Abs(s - C)).ToArray();
        int min = 0;
        min += a.Min();
        for (int i = 0; i < a.Length; i++)
        {
            if (a[i] == a.Min())
            {
                b[i] = int.MaxValue;
                c[i] = int.MaxValue;
                break;
            }
        }
        min += c.Min();
        for (int i = 0; i < a.Length; i++)
        {
            if (c[i] == c.Min())
            {
                b[i] = int.MaxValue;
                break;
            }
        }
        min += b.Min();
        return min;
    }

    static int Solv(List<int> bam)
    {
        if (bam.Count < 3) return int.MaxValue;
        if (bam.Count == 3) return Min(bam);
        int rv = Min(bam);
        if (rv <= 10) return rv;
        for (int i = 0; i < bam.Count; i++)
        {
            for (int j = i + 1; j < bam.Count; j++)
            {
                if (bam[i] <= 10 || bam[j] <= 10) continue;
                List<int> bam2 = new List<int>();
                for (int k = 0; k < bam.Count; k++)
                    if (k != i && k != j)
                        bam2.Add(bam[k]);
                bam2.Add(bam[i] + bam[j]);
                rv = Math.Min(rv, Solv(bam2) + 10);
            }
        }
        return rv;
    }
}

Measured memory_bytes: 17512
n,m = map(int,input().split())
aa = [int(input()) for i in range(m)]

cnt2 = 0
cnt1 = 1
aa.append(-1)
a = aa.pop(0)


for i in range(1,n):
    if i == a:
        cnt2, cnt1 = cnt1, 0
        a = aa.pop(0)
    else:
        cnt2, cnt1 = cnt1, cnt2+cnt1
else:
    ans = (cnt2+cnt1)%1000000007

print(ans)

Measured memory_bytes: 7080
n, m = map(int, input().split())

for i in range(n):
    if i == 0:
        k = list(map(int, input().split()))[1:]
        k = set(k)

    else:
        tmp = list(map(int, input().split()))[1:]
        tmp = set(tmp)
        k = k & tmp

print(len(k))

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

typedef pair<int,int> P;

const int INF = 1 << 28;

int main ()
{
    int n;
    while (cin >> n, n) {
        vector<vector<int> > edge(n+1, vector<int>(n+1, 0));
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                cin >> edge[j][i];
            }
        }

        vector<int> ver(1 << n, INF);
        queue<P> q;

        for (int i = 0; i < n; i++) {
            ver[1 << i] = edge[0][i+1];
            q.push(P(1 << i, edge[0][i+1]));
        }
        while (q.size()) {
            P p = q.front(); q.pop();
            int v = p.first;
            int cost = p.second;

            if (ver[v] < cost) continue;

            for (int i = 0; i < n; i++) {
                if ((v & (1 << i)) == 0) {
                    int cost_ = cost + edge[0][i+1];
                    int to_ = v | (1 << i);
                    if (ver[to_] > cost_) {
                        ver[to_] = cost_;
                        q.push(P(to_, cost_));
                    }
                }
            }


            for (int i = 0; i < n; i++) {
                if ((v & (1 << i)) == 0) {
                    for (int j = 0; j < n; j++) {
                        if (v & (1 << j)) {
                            int cost_ = cost + edge[j+1][i+1];
                            int to_ = v | (1 << i);
                            if (ver[to_] > cost_) {
                                ver[to_] = cost_;
                                q.push(P(to_, cost_));
                            }
                        }
                    }
                }
            }
        }

        cout << ver[(1 << n) - 1] << endl;
    }

    return 0;
}

Measured memory_bytes: 2016