akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std ;
typedef  long long int ll ;
#define inf ll(1e18)
#define mod 1000000007
#define mod1 998244353
#define mod2 999983
ll power(ll a,ll n,ll m) ;
ll power(ll a,ll n,ll m)
{  if(n==0)
   return 1 ;
   ll x=power(a,n/2,m) ;
   if(n%2!=0)
    return (((a*x)%m)*(x)%m)%m ;
    else return (x*x)%m ;
}
map<ll,ll>::iterator itr ;
ll ans ;
double PI=3.14159265357 ;
bool comp(pair<ll,ll> a,pair<ll,ll> b)
{
    if(a.first!=b.first)
        return a.first<b.first ;
    return a.second>b.second ;
}
int32_t main()
{ ll n,i,j,x,y,m,k,t,sum,count,cnt,b,c,d,j1,z,a,o,temp;
  ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
  cin>>a>>b>>c>>d>>k ;
  a=(a*60)+b ;
  b=(c*60)+d ;
  cout<<b-k-a ;
  return 0; }


Measured memory_bytes: 3648
#include <stdio.h>

int main()
{
 long int x,y,z,sum,i,k;
 
 scanf("%ld%ld%ld",&x,&y,&z);
if(x==y)
{
    printf("%ld",z);
}else{
    if(y==z)
    {
        printf("%ld",x);
    }else{
        printf("%ld",y);
    }
}
 
 
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main() {
    int r, c, i, j, num[101][101];
    scanf("%d%d", &r, &c);
    for (i = 0; i < r; i++) {
        num[i][c] = 0;
        for (j = 0; j < c; j++) {
            scanf("%d", &num[i][j]);
            num[i][c] += num[i][j];
        }
    }
    for (j = 0; j <= c; j++) {
        num[r][j] = 0;
        for (i = 0; i < r; i++) {
            num[r][j] += num[i][j];
        }
    }
    for (i = 0; i <= r; i++) {
        for (j = 0; j < c; j++) {
            printf("%d ", num[i][j]);
        }
        printf("%d\n", num[i][j]);
    }
    return 0;
}

Measured memory_bytes: 636
"""
AtCoder :: Beginner Contest 172 :: D :: Sum of Divisors
https://atcoder.jp/contests/abc172/tasks/abc172_d
"""
import sys

def summation(n):
    return (n * (n+1)) // 2

def solve(N):
    """Solve puzzle."""
    soln = 0
    for i in range(1, N+1):
        k = N // i
        soln += i * summation(k)
    return soln


def main():
    """Main program."""
    N = int(sys.stdin.readline())
    print(solve(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9192
n, x = gets.chop.split.map(&:to_i)
a = gets.chop.split.map(&:to_i)

count = 0
a.sort!.each_with_index do |num, i|
  if i == a.length - 1
    count += 1 if num == x
  else
    break if num > x
    count += 1
    x -= num
  end
end

puts count

Measured memory_bytes: 1788
//ΔAGC 013D
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
const int N = 3033;
const int mod = 1e9+7;
LL dp[N][N][2];
int main()
{
	int n,m,i,j,k;
	LL ans;
	cin>>n>>m;
	n--;
	m--;
	memset(dp,0,sizeof(dp));
	for(j=0;j<=n;j=j+1)
		dp[0][j][0]=1;
	for(i=1;i<=m+1;i=i+1){
		dp[i-1][0][1]=dp[i-1][0][0];
		if(i==m+1) break;
		for(j=0;j<=n;j=j+1){
			for(k=0;k<=1;k=k+1){
				dp[i][j][k]=dp[i-1][j][k]*2;
				if(j)
					dp[i][j][k]+=dp[i-1][j-1][k];
				if(j!=n)
					dp[i][j][k]+=dp[i-1][j+1][k];
				dp[i][j][k]%=mod;
			}
		}
	}
	ans=0;
	for(j=0;j<=n;j=j+1)
		ans+=dp[m][j][1];
	cout<<(ans*4)%mod<<endl;
	return 0;
}

Measured memory_bytes: 144000
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+5;
int main()
{
	int h,w,m;
	cin>>h>>w>>m;
	map<int,int>row,col;
	set<pair<int,int>>st;
	int r[N*3]={0},c[N*3]={0};
	int Mxrow=0,Mxcol=0;
	for(int i=0;i<m;++i)
	{
	    cin>>r[i]>>c[i];
	    st.insert({r[i],c[i]});
	    row[r[i]]++;
	    col[c[i]]++;
	    Mxrow=max(Mxrow,row[r[i]]);
	    Mxcol=max(Mxcol,col[c[i]]);
	}
	set<int>X,Y;
	for(int i=0;i<m;++i)
	{
	    if(row[r[i]]==Mxrow)X.insert(r[i]);
	    if(col[c[i]]==Mxcol)Y.insert(c[i]);
	}
	int ans=Mxrow+Mxcol-1;
	for(auto i:X)
	{
	    for(auto j:Y)
	    {
	        if(!st.count({i,j}))
	        {
	            cout<<ans+1<<endl;return 0;
	        }
	    }
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 76236
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i > 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << (b - a == c - b ? "YES" : "NO") << endl;
  return 0;
}

Measured memory_bytes: 256
from itertools import permutations
def main():
  n, m = map(int, input().split())
  a=[]
  for i in range(n):
    a.append(input())
  b = ""
  for j in range(m):
    b += input()
  for i in range(n - m + 1):
    for j in range(n - m + 1):
      x = ""
      for k in range(m):
        x += a[j+k][i: i + m]
      if b == x:
        print("Yes")
        return
  print("No")
main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int n;
void solve()
{
    int tag=0;
    for (int i=0;i<=n/7;i++)
        if ((n-i*7)%4==0) {tag=1;break;}
    if (tag) cout<<"Yes";
    else cout<<"No";
    cout<<endl;
}
int main()
{
    while(cin>>n)
        solve();
}

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

const int N = 1e5 + 10;
typedef long long ll;
int n, m, a[N], f[N][2];
priority_queue<int> q;
ll ans;

int main() {
    cin >> n >> m;
    rep(i, 1, n) {
        scanf("%d", &a[i]);
        q.push(a[i]);
    }
    while (m--) {
        int x = q.top(); q.pop();
        x /= 2;
        q.push(x);
    }
    while (q.size()) {
        int x = q.top(); q.pop();
        ans += x;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1148
#include <stdio.h>

main(){
    long long v[87],n,i;
    scanf("%d", &n);
    v[0] = 2;
    v[1] = 1;
    long long s=v[0]+v[1];
    for(i=2; i<=n; i++){
        v[i] = v[i-1] + v[i-2];
    }
    long long a=v[n];
    printf("%llu", a);
}


Measured memory_bytes: 128
/*
	将边异或转化成点异或
	最后状压 dp 即可 
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#define N 100005

using namespace std;

const int upp = 1 << 16;

int n, ans, fin;
int val[N], f[upp], cnt[16];
bool legal[upp];

inline int bitcnt(int x) {
	int res = 0;
	for(int i = x; i; i -= i & -i)
		++res;
	return res;
}

int main() {
	scanf("%d", &n);
	for(int i = 1, u, v, w; i < n; ++i) {
		scanf("%d %d %d", &u, &v, &w);
		++u, ++v;
		val[u] ^= w, val[v] ^= w;
	}

	for(int i = 1; i <= n; ++i)
		++cnt[val[i]];

	cnt[0] = 0;
	for(int i = 1; i < 16; ++i) {
		ans += cnt[i] / 2;
		if(cnt[i] & 1) fin |= 1 << i;
	}

	for(int i = 0; i < upp; ++i) {
		int r = 0;
		for(int o = 0; o < 16; ++o)
			if(i >> o & 1)
				r ^= o;
		if(!r) legal[i] = true;
	}

	memset(f, 32, sizeof f), f[0] = 0;
	for(int i = 1; i <= fin; ++i) {
		if((fin | i & fin) != fin || !legal[i]) continue;
		f[i] = bitcnt(i) - 1;
		for(int x = i; x; x = x - 1 & i) {
			int y = i ^ x;
			if(legal[x] && legal[y])
				f[i] = min(f[i], f[x] + f[y]);
		}
	}

	ans += f[fin];
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 896
class SegmentTreeMax
  attr_accessor(:node, :e, :offset)
  
  def initialize(n, e)
    @e = e

    ofs = 1
    while ofs < n
      ofs <<= 1
    end
    
    @node = Array.new((ofs << 1) - 1, @e) # 0-indexed
    @offset = ofs - 1 # log2(n).ceil - 1
  end

  def update(i, x) # 一点更新
    i += @offset
    @node[i] = x
    
    while i > 0
      i = (i - 1) >> 1
      @node[i] = op(@node[(i << 1) + 1], @node[(i << 1) + 2])
    end
  end

  def query(l, r) # [l, r)
    l += @offset
    r += @offset

    res = @e
    while l < r
      if l & 1 == 0
        res = op(res, @node[l])
      end
      if r & 1 == 0
        res = op(res, @node[r - 1])
      end
      l = l >> 1
      r = (r - 1) >> 1
    end
    return res
  end
  
  def op(x, y)
    return (x > y)? x : y
  end
end

m = 3 * (10 ** 5)
n, k = $stdin.readline.chomp.split.map(&:to_i)
a = Array.new(n) { $stdin.readline.to_i }
seg = SegmentTreeMax.new(m + 1, 0)

res = 0
a.each do |x|
  v = seg.query((x > k)? x - k : 0, ((x + k < m)? x + k : m) + 1) + 1
  res = v if v > res
  seg.update(x, v)
end
puts res


Measured memory_bytes: 24908
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)
#define MP make_pair


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(10);

  int INF = 1000000;

  vector<pair<int,int> > list;
  int num,score;
  char del;
  while(cin>>num>>del>>score){
    if(num==0&&score==0) break;
    list.push_back( MP(score,num));
  }

  sort(list.begin(), list.end(), greater<pair<int,int> >() );


  map<int,int> sc2rank;
  int rank=1;
  for(vector<pair<int,int> >::iterator it=list.begin(); it!=list.end(); ++it){
if( sc2rank.find(it->first) == sc2rank.end() ){
sc2rank[it->first] = rank;
rank++;
}
  }

  int qu;
  while(cin >> qu){
for(vector<pair<int,int> >::iterator it=list.begin(); it!=list.end(); ++it){
if(it->second == qu){
cout << sc2rank[it->first] << endl;
break;
}
}
  }

  return 0;
}

Measured memory_bytes: 1196
#include<iostream>
using namespace std;
#define INF 100000000
int main(){
  int n,m;
  cin >> n >> m;
  int data[n+1][n+1],a,b,c,d;
  char s;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++) data[i][j] = INF;
  }
  for(int i=0;i<m;i++){
    cin >> a >> s >> b >> s >> c >> s >> d;
    data[a][b] = c;
    data[b][a] = d;
  }
  for(int k=1;k<=n;k++){
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
	data[i][j] = min(data[i][j],data[i][k]+data[k][j]);
      }
    }
  }
  /*for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++) cout << data[i][j] << ' ';
    cout << endl;
    }*/
  int x,x2,y,y2;
  cin >> x >> s >> x2 >> s >> y >> s >> y2;
  cout << y - data[x][x2] - data[x2][x] - y2 << endl;
  return 0;
} 

Measured memory_bytes: 1160
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		int min = 753;

		for (int i = 0;i<s.length()-2 ;i++ ) {
			String ss = s.substring(i,i+3);
			int n = Integer.parseInt(ss);
			min = Math.min(min,Math.abs(753-n));
		}

		System.out.println(min);
	}
}


Measured memory_bytes: 21844
from collections import deque
import numpy as np
 
 
H,W= [int(x) for x in input().split()]
n=[]
T=np.zeros((H,W),dtype=int)
#T=[]
S=np.zeros_like(T,dtype=int) 
for i in range(H):
  n=input()
  for j in range(W):
    if n[j]=="#": T[i][j]=1
#B=T.copy()    
d=0
c=deque()  
for i in range(H):
    for j in range(W):
         
        if T[i][j] ==1:continue
 
          
        c.append((i,j))
        S[i][j] = 1
        #c.append(j)
        
        #t=len(c)
        while True:

                try:
                  m,n = c.popleft()
                except IndexError: break
                
                
                for kk in [(m+1,n),(m-1,n),(m,n+1),(m,n-1)]:
                  if not (0<=kk[0]<H and 0<= kk[1] <W): continue
                  if T[kk]==1:continue
                  if S[kk] == 0:
                    c.append(kk)
                    S[kk] = S[m][n]+1        
                        
 
        #print(T)
        d = max(d,np.max(S))
        S=np.zeros_like(T,dtype=int)
        
print(d-1)

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

using namespace std;
void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
} 
 string str;
int n,cnt=0;
int main()
{ init();
   cin>>n;
   vector <string>vec ;
 for(int i=0;i<n;i++){
   cin>>str;
   vec.push_back (str);
 }
 sort(vec.begin(),vec.end());
 for(int i=0;i<(int)vec.size();i++){
   if(vec [i]!=vec [i+1]){
     cnt++;
   }
 }
 cout<<cnt<<endl;
}

 
  

Measured memory_bytes: 11624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
ll MM = 1000000000; ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
const ll INF = 1LL << 60;
//cout << fixed << setprecision(10);

int main(){
    ll n, ans=100; cin>>n;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            string a=to_string(i), b=to_string(n/i);
            ans=min(ans, (ll)max(a.size(), b.size()));
        }
        else{
            continue;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    double a, a1, b, c, d, e, f;
    double t1, t2;
    double x;
    double y;

    while (scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF){
        x = (c * e - f * b) / (a * e - d * b) + 0.0001;
		y = (a * f - d * c) / (a * e - d * b) + 0.0001;
		
		printf("%.3lf %.3lf\n", x, y);
    }
    return (0);
}

Measured memory_bytes: 656
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();

		int i = Integer.parseInt(input);

		System.out.println(i * i * i);
	}

}



Measured memory_bytes: 26180
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)

//your code here!

int main(void){
    ll N, H[100100];
    scanf("%lld", &N);
    rep(i, N) scanf("%lld", H+i);
    for(ll i=N-1; i>0; i--){
        if(H[i-1]>H[i]){
            if(H[i-1]-H[i]==1) H[i-1]--;
            else {
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if ((a == b && b != c) || (b == c && c != a) || (c == a && a != b)) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3540
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int l = sc.nextInt();
		long[][] mtx1 = new long[n][m];
		long[][] mtx2 = new long[m][l];
		for(int i = 0; i < n; i++){
			for(int k = 0; k < m; k++){
				mtx1[i][k] = sc.nextLong();
			}
		}
		for(int i = 0; i < m; i++){
			for(int k = 0; k < l; k++){
				mtx2[i][k] = sc.nextLong();
			}
		}
		for(int i = 0; i < n; i++){
			for(int k = 0; k < l; k++) {
				if(k != 0) {
					System.out.print(" ");
				}
				long sum = 0;
				for(int p = 0; p < m; p++){
					sum += mtx1[i][p] * mtx2[p][k];
				}
				System.out.print(sum);
			}
			System.out.println();
		}
	}
}



Measured memory_bytes: 55444
def main():
    r, g, b, n = map(int, raw_input().split())
    s = 0
    for i in range(n // r + 1):
        c = i * r
        if c == n:
            s += 1
            continue
        for j in range((n - c) // g + 1):
            cc = c + j * g
            if cc <= n and (n - cc) % b == 0:
                s += 1
    print s


if __name__ == '__main__':
    main()


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

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

  int a, b, k;
  cin >> a >> b >> k;

  rep(i, k) {
    if (i % 2 == 0) {
      if (a & 1) a--;
      b += a/2;
      a -= a/2;
    } else {
      if (b & 1) b--;
      a += b/2;
      b -= b/2;
    }
  }

  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1000005;
int ans,n,q[N];
char s1[N],s2[N];
int main(){
	scanf("%d%s%s",&n,s1+1,s2+1);
	if (!strcmp(s1+1,s2+1)){
		puts("0");
		return 0;
	}
	for (int i=n,j=n,l=1,r=0;i;i--)
		if (s2[i]!=s2[i-1]){
			j=min(i,j);
			for (;j&&s1[j]!=s2[i];j--);
			if (!j){
				puts("-1");
				return 0;
			}
			while (l<=r&&i<q[l]-(r-l))l++;
			if (i!=j)q[++r]=j;
			ans=max(ans,r-l+1);
		}
	printf("%d\n",ans+1);
	return 0;
}


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

int main(int argc, char const *argv[])
{
	int a, b;
	int c, d;
	cin >> a >> b;
	cin >> c >> d;
	if(a == 2 && b == 28){
        printf("1\n");
	}
	else if((a == 4 || a == 6 || a == 9 || a == 11) && (b == 30)){
        printf("1\n");
	}
	else if((a == 1 || a == 3 || a == 5 || a == 7 || a == 8 || a == 10 || a == 12) && (b == 31)){
        printf("1\n");
	}
	else{
        printf("0\n");
	}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};

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

  cout << n*(n+1)/2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i = x; i < n; i++)
#define MAX 100
#define INF 1000000001

int k;
// int a[2000];

// char X[100][100];
// int dp[1000000001];
vector<pair<int,int>> adj[114514];
long long dis[114514];
bool processed[114514];

void dijkstra() {
    priority_queue<pair<int,int>> q; // q({-d,x})
    
    REP(i,0,114514) dis[i] = INF;
    dis[1] = 0;
    q.push({0,1});
    
    while(!q.empty()) {
        int a = q.top().second; q.pop();
        if (processed[a]) continue;
        processed[a] = true;
        for (auto u : adj[a]) {
            int b = u.first, w = u.second;
            if (dis[a] + w < dis[b]) {
                dis[b] = dis[a] + w;
                q.push({-dis[b],b});
            }
        }
    }
    
    return;
}

int main(void){
    // a[0] = 100;
    // a[2] = 2;
    // fill(a,a+3,100);
    // cout << count(a,a+3,100) << endl;
    cin >> k;
   
    
    REP(i,0,k) {
        adj[i].push_back({(i+1)%k,1});
    }
    
    REP(i,0,k) {
        adj[i].push_back({(i*10%k),0});
    }
    
    dijkstra();
    cout << dis[0] + 1 << endl;

}

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

typedef long long int LL;
typedef long long int LLint;

//Faster Program
#define endl "\n"

//Faster Coding
#define ED return
#define GET(a) int a;cin >> a
#define DGET(a) double a;cin >> a
#define SGET(a) string a;cin >> a
#define CGET(a) char a;cin >> a
#define PRINT(a) cout << a << "\n"
#define ANS(a,b) int a;cin >> a;cout << b << "\n"
#define FOR(n) for(int i = 0;i < n;i++)
#define SORT(vec) sort(vec.begin(),vec.end())
#define REV(vec) reverse(vec.begin(),vec.end())

//As Function
#define UP(a,b) ((a+(b-1))/b)
#define ipow(x,y) LL(pow(x,y))

//Debug
#define TEST cout << "OK\n"

const double PI = M_PI;
const long long INF = int(999999999);
const long long MOD = int(1000000007);

//Settings
const bool DO_BENCHMARK = false;
const int DOUBLE_ACCURACY = 15;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(DOUBLE_ACCURACY);
    void solve();
    if(DO_BENCHMARK){
        clock_t clock_start = clock();
        solve();
        clock_t clock_end = clock();
        const double time = static_cast<double>(clock_end-clock_start)/CLOCKS_PER_SEC*1000.0;
        cout << "\n" << time << "[ms]\n";
    }
    else solve();
}

void solve(){
    int N;
    cin >> N;
    vector<int> vec (N);
    int ans = 1;
    for(int i = 0;i < N;i++){
        cin >> vec[i];
        if(vec[i] == ans){
            ans++;
        }
    }

    if(ans == 1){
        cout << -1 << endl;
        ED;
    }

    cout << N-ans+1 << endl;
}


Measured memory_bytes: 1024
//g++ test1.cc　でコンパイル
//./a.out <input.txt
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;
typedef long long ll;
using Graph =vector<int>;
typedef pair<ll,int> P;

const ll MAX_N=131072;
int bit[MAX_N*2-1];
ll n;
int main(){
  string s;
  cin >>s;
  if(s=="a"||s=="e"||s=="i"||s=="o"||s=="u") cout <<"vowel"<<endl;
  else cout <<"consonant"<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

  int64_t N, M;
  cin >> N >> M;

  int64_t a[N+1], b[N+1], c[M+1], d[M+1];
  for(int64_t i=1;i<=N;i++)
    cin >> a[i] >> b[i];

  for(int64_t i=1;i<=M;i++)
    cin >> c[i] >> d[i];

  int64_t distance[M+1];
  int64_t min[N+1];
  for(int64_t i=1;i<=N;i++) {
    int64_t min;
    for(int64_t j=1;j<=M;j++) {
      distance[j] = abs(a[i]-c[j]) + abs(b[i]-d[j]);
      if(j==1)
	min = distance[1];
      else
	if(distance[j] < min)
	  min = distance[j];
    }

    for(int64_t j=1;j<=M;j++) {
      if(distance[j] == min) {
	cout << j << endl;
	break;
      }
    }
  }

  return 0;
}

    


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;
ll n,h;
vector<ll> a,b;

int main(){
  cin >> n >> h;
  a.resize(n,0);
  b.resize(n,0);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    cin >> b.at(i);
  }
  sort(a.rbegin(),a.rend());
  sort(b.rbegin(),b.rend());
  ll i = 0, ans = 0;
  while(h>0){
    ll x = b.at(i);
    if(x<=a.at(0)) break;
    h -= x; ans++;
    if(i == n-1) break;
    i++;
  }
  while(h>0){
    ll x = a.at(0);
    h -= x; ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
n=int(input())
def pri(n):
  l=[]
  for i in range(1,int((n)**(1/2))+1):
    if n%i==0:
      l.append(i)
      if i!=n//i:
        l.append(n//i)
  return l
list1=pri(n)
sum=0
for i in list1:
  if n>i*(i+1):
    sum+=n//i-1
print(sum)

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

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n-r)
    return fact[n] *factinv[r]* factinv[n-r] %p

p = 998244353
N = 2 * 10**5 + 2

fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

y = [0,m]
for i in range(n):
    y.append((y[-1]*(m-1))%p)
r = 0
for i in range(k+1):
    r = (r + y[n-i]*cmb(n-1, i, p))%p
print(r)

Measured memory_bytes: 40780
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define vv(T) vector<vector<T>>
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
using qint = queue<int>;
using sint = stack<int>;
using pii = pair<int, int>;

const long long MOD = 2019;

struct mint{
    long long x;
    mint(long long x = 0) : x((x % MOD + MOD) % MOD){}
    mint operator-() const{
        return mint(-x);
    }
    mint& operator+=(const mint a){
        if((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a){
        if((x += MOD - a.x) >= MOD) x-= MOD;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const{
        return mint(*this) += a;
    }
    mint operator-(const mint a) const{
        return mint(*this) -= a;
    }
    mint operator*(const mint a) const{
        return mint(*this) *= a;
    }
    mint pow(long long t) const{
        if(!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if(t & 1) a *= *this;
        return a;
    }

    mint inv() const{
        return pow(MOD - 2);
    }
    mint& operator/=(const mint a){
        return *this *= a.inv();
    }
    mint operator/(const mint a) const{
        return mint(*this) /= a;
    };
    void max(){
        x = MOD - 1;
    }
};
istream& operator>>(istream& is, mint& a){
    return is >> a.x;
}
ostream& operator<<(ostream& os, const mint& a){
    return os << a.x;
}

int main(){
    long long l, r;
    cin >> l >> r;

    mint ans;
    ans.max();

    for(long long tl = l; tl < r; tl++){
        for(long long tr = l + 1; tr <= r; tr++){
            mint tmp = tl * tr;
            ans.x = min(ans.x, tmp.x);
            if(ans.x == 0) break;
        }
        if(ans.x == 0) break;
    }

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

Measured memory_bytes: 3616
#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 a,b,k;
  cin >> a >> b >> k;
  map<ll,ll> mp;
  for(int i = a;i <= a + k - 1;i++)mp[i]++;
  for(int i = b;i >= b - k + 1;i--)mp[i]++;
  for(auto i:mp){
    if(i.first >= a && i.first <= b)cout << i.first << endl;
  }
}

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

int main() {
  int64_t N,Z=0;
  cin>>N;
  for(int64_t i=1;i*i<N;i++){
    if(N%i==0&&i*(i+1)!=N){
      Z+=N/i;
      Z--;
    }
  }
  cout<<Z<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IO {ios_base::sync_with_stdio(false); cin.tie(0);}
#define ll   long long
#define pi pair<ll,ll>
int main()
{
    IO;
    ll i, j, k, l=0, n, m, h, mod=1e9+7, cnt=0, mx = 0, t, ans=0, tc=0,r , b;

        cin>>n>>m>>k;
        cout<<m/k-(n-1)/k<<endl;
    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> inline bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> inline bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m,a;
    ll s{};
    cin>>n>>m;
    fr(i,m){
        cin>>a;
        s+=a;
    }
    cout<<(s>n?-1:n-s)<<'\n';
}

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

int main(){
  string s;
  int res=700;
  
  for(int i = 0;i<3;i++){
    cin >> s[i];
    if(s[i] == 'o'){
      res = res +100;
    }
  }
  cout << res <<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    ll A, B; cin >> A >> B;

    ll ans = 1, N = min(A, B);
    for (ll i = 2; i * i <= N; i++) {
        if (A % i == 0 && B % i == 0) ans++;
        while (A % i == 0) A /= i;
        while (B % i == 0) B /= i;
    }

    if (A > 1 && B >> 1) {
        if (A % B == 0 || B % A == 0) ans++;
    }

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

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

typedef long long ll;

const ll maxn = 100;
const ll mod = 1e9 + 7;
char val[2][maxn];
ll dp[maxn][8][8];
ll n;

ll dfs(ll pos, ll a, ll b){
	if(dp[pos][a][b] == -1){
		ll &res = dp[pos][a][b];

		if(pos == n){
			res = 1;
		} else {
			res = 0;

			if(val[0][pos] == val[1][pos]){
				for(ll j = 1; j <= 4; j *= 2){
					if((a & j) and (b & j)){
						res += dfs(pos + 1, 7 ^ j, 7 ^ j);
					}
					res %= mod;
				}
			} else {
				for(ll j = 1; j <= 4; j *= 2){
					for(ll k = 1; k <= 4; k *= 2){
						if((a & j) and (b & k) and j != k){
							if(val[0][pos + 1] == val[0][pos] and val[1][pos + 1] == val[1][pos]){
								res += dfs(pos + 1, j, k);
							} else if(val[0][pos + 1] == val[0][pos]){
								res += dfs(pos + 1, j, 7 ^ k);
							} else if(val[1][pos + 1] == val[1][pos]){
								res += dfs(pos + 1, 7 ^ j, k);
							} else {
								res += dfs(pos + 1, 7 ^ j, 7 ^ k);
							}
						}
						res %= mod;
					}
				}
			}
		}
	}

	return dp[pos][a][b];
}

int main(){
	std::ios::sync_with_stdio(false);

	std::cin >> n;

	for(ll i = 0; i < 2; i++){
		for(ll j = 0; j < n; j++){
			std::cin >> val[i][j];
		}
	}

	memset(dp, -1, sizeof(dp));

	std::cout << dfs(0, 7, 7) << '\n';
}


Measured memory_bytes: 256
from math import gcd

n = int(input())
sum = 0
for i in range(1, n + 1):
    for j in range(1, i):
        for k in range(1, j):
            sum += 6 * gcd(gcd(k, j), i)
        sum += 6 * gcd(j, i)
    sum += i
print(sum)


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

using namespace std;
const int N = 2e5 + 10;
const int inf = 1e9;
struct E{
    int to , nex , cap;
}e[N * 8];int head[N] , ecnt;

void init(){ecnt = 1;}
void putin(int fr,int to,int cap) { e[++ecnt]=(E){to,head[fr],cap}; head[fr] = ecnt; }
void adde (int fr,int to,int cap) { putin(fr,to,cap);putin(to,fr,0); }


int dep[N];
queue <int> q;
void bfs(int s,int t)
{
    memset(dep,-1,sizeof dep);
    dep[s] = 0;q.push(s);
    
    while (!q.empty())
    {
        int cur = q.front();q.pop();
        for (int j=head[cur];j;j=e[j].nex)
        if ( e[j].cap && dep[ e[j].to ] == -1)
        {
            dep[ e[j].to ] = dep[ cur ] + 1;
            q.push( e[j].to );
        }
        
    }
}
int iter[N];
int dfs(int o,int t,int lim)
{
    if (o == t || !lim) return lim;
    
    int flow = 0;
	for (int &j = iter[o];j;j = e[j].nex)
    if ( e[j].cap && dep[e[j].to] == dep[o] + 1)
    {
        int d = dfs( e[j].to , t , min(lim , e[j].cap ) ) ;
        flow += d;
        lim -= d;
        e[j].cap -= d;
        e[j^1].cap += d;
    }
    
    return flow;
}

int dinic(int s,int t,int n)
{
    int ans = 0 , f;
    for (;;)
    {
        bfs(s,t);
//		printf("%d\n",dep[t]);
        if (dep[t] == -1 ) return ans;
        memcpy(iter,head,sizeof (int) * (n+1) ) ;
        ans += dfs(s,t,inf);
    }
    return ans;
}

vector <int> G[N];

int apo[N] , sem[N] , bel[N] , n , root;

int main(){
	init();
	scanf("%d",&n);
	
	for (int i = 1;i < n;i++){
		int v;scanf("%d",&v);
		
		while (v--){
			int u;scanf("%d",&u);
			G[u].push_back(i);
			adde(u , i + n , 1);	
		}
		adde(i + n , 2 * n + 1 , 1);	
	}
	
	for (int i = 1;i <= n;i++){
		adde(2 * n , i , 1);
	}
	
	if (dinic(2 * n , 2 * n + 1 , 2 * n + 1) != n - 1) return puts("-1") , 0;
	
	for (int i = 1;i < n;i++){
		for (int j = head[i + n]; j; j = e[j].nex){
			if (e[j].cap && e[j].to != 2 * n + 1 ){
				apo[i] = e[j].to;
				bel[e[j].to] = i;
			}
		}
	}
	for (int i = 1;i < n;i++){
		if (!apo[i]) return puts("-1") , 0;
	}
	
	for (int i = 1;i <= n;i++){
		if (!bel[i]) root = i;
	}
	
	q.push(root);
	while (!q.empty()){
		int cur = q.front();q.pop();
		for (int u : G[cur]){
			if (!sem[u]){
				sem[u] = cur;
				q.push(apo[u]);
			}
		}
	}
	
	for (int i = 1;i < n;i++){
		if (!sem[i]) return puts("-1") , 0;
	}
	for (int i = 1;i < n;i++){
		printf("%d %d\n",apo[i],sem[i]);
	}
	return 0;
}

Measured memory_bytes: 24952
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=100010;
int a[N];
long long ans,b[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int n,s;
    cin>>n>>s;
    for(int i=1;i<=n;i++) a[i]=gi(),b[i]=gi();
    int l=1,r=n,t=0;
    while(1) {
	if(a[r]<=s) {ans+=s-a[l];break;}
	if(a[l]>=s) {ans+=a[r]-s;break;}
	if(b[l]>=b[r]) {
	    if(t!=1) t=1,ans+=a[r]-a[l];
	    b[l]+=b[r--];
	}
	else {
	    if(t!=2) t=2,ans+=a[r]-a[l];
	    b[r]+=b[l++];
	}
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>  //for bool
#include <stdlib.h> // abs,labs,llabs
#include <limits.h>
#include <ctype.h>

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld; //%Lf

int main(void) {
  int a, b, ans = 0;
  scanf("%d %d", &a, &b);
  ans = ((a + b) > (a - b)) ? ((a + b) > (a * b) ? (a + b) : (a * b)) : ((a - b) > (a * b) ? (a - b) : (a * b));
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
num_of_rectangle, num_of_rhombus = 0, 0

$stdin.readlines.each do |input|
  edge1, edge2, diagonal_line = input.split(',').map(&:to_i)

  num_of_rectangle += 1 if (edge1**2 + edge2**2) == diagonal_line**2
  num_of_rhombus += 1 if edge1 == edge2
end

puts num_of_rectangle, num_of_rhombus

Measured memory_bytes: 8636
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
/* テンプレートここまで */

int main() {
  int K, S;
  cin >> K >> S;

  ll cnt = 0;

  REP(i, K+1){
    REP(j, K+1){
      int k = S - i - j;
      if(k>=0 && k<= K) cnt++;
    }
  }

  cout << cnt << endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <cmath>
#include <string>

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

char str[105];

int main()
{
	scanf("%s",&str);
	int n=strlen(str);
	if(n>=3)
	{
		string A="";
		A+=str[0];
		A+=str[1];
		A+=str[2];
		A+=str[3];
		if(A=="YAKI")
		{
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per0(i, st, ed) for (int i = (st); i > ed; --i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
#define chmin(a, b) (a = a > b ? b : a)
#define chmax(a, b) (a = a < b ? b : a)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
template<class T> void _out(const T &x) { cout << x; }
void _out(const int &x) { printf("%d", x); }
void _out(const ll &x) { printf("%lld", x); }
void _out(const double &x) { printf("%.16f", x); }
void _out(const char &x) { putchar(x); }
void _out(const char *x) { printf("%s", x); }
template<class T,class U> void _out(const pair<T,U> &x) {_out(x.F); putchar(' '); _out(x.S);}
template<class T> void _out(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _out(*i++)) if (i != x.cbegin()) putchar(' '); }
void out() {}
template<class T, class... U> void out(const T &head, const U &... tail) { _out(head); putchar(sizeof...(tail) ? ' ' : '\n'); out(tail...); }
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

const int maxn = 105;
char s[maxn];

bool ok(int st, int ed) {
    int len = ed - st + 1;
    for (int i = st, j = ed; i <= j; ++i, --j) {
        if (s[i] != s[j]) return false;
    }
    return true;
}

int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    scanf("%s", s + 1);
    int len = strlen(s + 1);
    bool f = ok(1, len) && ok(1, (len - 1) / 2) && ok((len + 3) / 2, len);
    if (f) {
        puts("Yes");
    }else {
        puts("No");
    }
    return 0;
}

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

const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};
queue<pair<int,int> > M;
int W,H;
int q[20+5][20+5] = {};	
char p[20+5][20+5];
int counter;
int x,y;

int main() {
	while(cin >> W >> H && W != 0){
		counter = 0;
		for (int i = 1; i <= 22; i++){
			for (int j = 1; j <= 22; j++){
					q[i][j] = 0;
					p[i][j] = ' ';
				
			}
		}
		for (int i = 1; i <= H; i++){
			for (int j = 1; j <= W; j++){
				cin >> p[i][j];
				if (p[i][j] == '@' ){
					M.push(make_pair(i,j));
					counter = 1;
					q[i][j] = 1;
				}
			}
		}
		while(!M.empty()){
			x = M.front().first;
			y = M.front().second;
			M.pop();
			for (int k = 0; k <= 3; k++)
			{		
				if (p[x+dx[k]][y+dy[k]] == '.' && q[x+dx[k]][y+dy[k]] == 0)
				{
					M.push(make_pair(x+dx[k], y+dy[k]));
					q[x+dx[k]][y+dy[k]] = 1;
					counter += 1;
				}
			}
		}
		cout << counter << endl;
	}
}

Measured memory_bytes: 3092
#include<cstdio>
#include<cstring>
using namespace std;
int n,ans,s[100010],now;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&s[i]);
	for(int i=1;i<=n+1;++i){
		if(s[i]==i)++now;
		else ans+=(now+1)>>1,now=0;
	}
	printf("%d",ans);
}


Measured memory_bytes: 512
p1=list(map(int,input().split()))
p2=list(map(int,input().split()))
p3=list(map(int,input().split()))
from collections import defaultdict
d=defaultdict(list)
for p in [p1,p2,p3]:
    a,b=p
    d[a].append(b)
    d[b].append(a)

for i in range(1,5):
    if len(d[i])>2:
        print('NO')
        exit()
print('YES')


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int n,h[100010],f[100010];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	f[1]=0;
	f[2]=abs(h[1]-h[2]);
	for(int i=3;i<=n;i++){
		f[i]=min(f[i-1]+abs(h[i]-h[i-1]),f[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<f[n];
	return 0;
} 

Measured memory_bytes: 1024
#include<stdio.h>

int main()
{
	int a, b, r1, r2, r3;
	scanf("%d %d", &a, &b);

	r1 = a + b;
	r2 = a - b;
	r3 = a * b;
	
	if(r1 >= r2 && r1 >= r3) printf("%d\n", r1);
	else if(r2 >= r1 && r2 >= r3) printf("%d\n", r2);
	else if(r3 >= r1 && r3 >= r2) printf("%d\n", r3);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(void)
{
  int res = 1e9;                             //1e9は10の9乗(十分に大きい数);

  int n; cin >> n;                                  //ケースの数

  for (int i = 0; i < n; i++) {
    int a; cin >> a;

    int count = 0;                                  //2で割れる回数を数える 毎周0にリセットされる

    while (a % 2 == 0) {
      a /= 2;
      count++;
    }

    if (res > count) res = count;
  }

  cout << res << endl;
}

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

typedef long long int ll;

int lcs(string s,string t,int n,int m){
    int dp[n+1][m+1],i,j;
    for(i=0;i<n+1;i++){
        for(j=0;j<m+1;j++){
            if(i==0 || j==0)
                dp[i][j]=0;
            else if(s[i-1]==t[j-1]){
                dp[i][j]=1+dp[i-1][j-1];
            }else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);   
        }
    }
    int index=dp[n][m];
    char ls[index+1];
    ls[index]='\0';
    i=n;j=m;
    while(i>0 && j>0){
        if(s[i-1]==t[j-1])
        {
            ls[index-1]=s[i-1];
            i--;j--;index--;
        }
        else if(dp[i-1][j]>dp[i][j-1])
            i--;
        else
            j--;    
    }
    cout<<ls<<endl;
}

int main(){
    string s,t;
    cin>>s>>t;
    int n=s.length(),m=t.length();
    
    lcs(s,t,n,m);
     
    return 0;
}

Measured memory_bytes: 35456
a,b,c,d = map(int,input().split())
 
li = [1,9,7,4]
 
if (a in li)and (b in li)and(c in li)and(d in li):
  if a!=b and b!=c and c!=d and a!=c and a!=d and b!=d:
	  print("YES")
  else:
    print("NO")
else:
  print("NO")

Measured memory_bytes: 3060
#include <stdio.h>

int n,A[20];

int solve(int,int);
int main(){
  int q,m[200],i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m[i]);
    if(solve(0,m[i])==1){
      printf("yes\n");
    }else{
      printf("no\n");
    }
  }
  
  return 0;
}

int solve(int i,int m){
  int res;
  
  if(m==0){
    return 1;
  }
  
  if(i>=n){
    return 0;
  }
  
  res = solve(i+1,m) || solve(i+1,m-A[i]);
  return res;
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll>adj[100010];
bool visited[100010];
vector<ll>dp(100010);
void addEdge(int v,int w){
    adj[v].push_back(w);
}
void dfs(ll src){
    visited[src]=true;
    for(ll i=0;i<adj[src].size();i++){
        if(!visited[adj[src][i]])
        dfs(adj[src][i]);
        dp[src]=max(dp[src],1+dp[adj[src][i]]);
    }
}
void solve(){
    ll n,m;
    cin>>n>>m;
    ll x,y;
    for(int i=0;i<m;i++){
        cin>>x>>y;
        addEdge(x,y);
    }
    for(int i=1;i<=n;i++) {visited[i]=false;dp[i]=0;}
    ll ma=0;
    for(int i=1;i<=n;i++){
        dfs(i);
    }
    for(int i=1;i<=n;i++)
    ma=max(ma,dp[i]);
    cout<<ma;
}
int main(){
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <cstdio>

#define THRESHOLD 1000000000000000000

using namespace std;

int main() {
  long A, B, C, K;
  cin >> A >> B >> C >> K;
  if (abs(A - B) > THRESHOLD) {
    printf("Unfair\n");
    return 0;
  }
  if (K % 2 == 0) {
    printf("%ld\n", A - B);
  } else {
    printf("%ld\n", B - A);
  }
  return 0;
}


Measured memory_bytes: 256
let solve s =
  let n = String.length s in
  let check i =
    if s.[i] = s.[n-1-i]
    then 0
    else 1 in
  let rec iter i res =
    if i = n/2
    then res
    else iter (i+1) (res + check i)
  in iter 0 0

let () = Scanf.scanf "%s" @@ fun s -> Printf.printf "%d\n" @@ solve s 

Measured memory_bytes: 3848
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int x = scan.nextInt();
		int happy = 0;
		
		int ans = x/500;
		x -= 500*ans;
		happy += 1000*ans;
		
		ans = x/5;
		happy += 5*ans;
		
		System.out.println(happy);
		
	}	
}


Measured memory_bytes: 21716
n,m = map(int,input().split())
li = [list(map(int,input().split())) for _ in range(n)]
li.sort()

nw = 0
cst = 0
for i in range(n):
    memo = min(m,li[i][1])
    m-=memo
    cst += li[i][0]*memo
    if m==0:
        break
print(cst)

Measured memory_bytes: 27880
import itertools
n = int(input())

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

div_list = make_divisors(n)
#print(div_list)

mn =2**50
for i in div_list:
    mn = min(mn,i+n//i)

print(mn-2)

Measured memory_bytes: 9344
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
typedef long long ll;
const int MOD = 1000000007;
using namespace std;

int main(){
    int k; cin >> k;
    cout << k/2 * ((k+1)/2) << "\n";
    return 0;
}


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

using namespace std;

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

    int M; long K; cin>>M>>K;
    if (1ul<<M <= K) {
        cout << -1 << endl;
        return 0;
    }
    if (M == 0) {
        cout << 0 << ' ' << 0 << endl;
    } else if (M == 1 and K == 1) {
            cout << -1 << endl;
    } else if (K == 0) {
        for (long i = 0; i < 1ull<<M; i++) {
            cout << i << ' ' << i << ' ';
        }
        cout << '\n';
    } else {
        cout << K << ' ';
        for (long i = 0; i < 1ull<<M; i++) {
            if (i == K)
                continue;
            cout << i << ' ';
        }
        cout << K << ' ';
        for (long i = (1ull<<M)-1; i >= 0; i--) {
            if (i == K)
                continue;
            cout << i << ' ';
        }
        cout << endl;
    }
    
    return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

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

    int idx = 0;
    while(idx <s.size() && s[idx]=='1') idx++;

    if(k-1<idx) cout << 1 << endl;
    else cout << s[idx] << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cstring>

using namespace std;

typedef long long ll;
ll a[200001];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(NULL);
	//0100 1011 0110 1101

	int n; cin >> n;
	ll tmp = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		tmp = tmp ^ a[i];
	}

	for (int i = 0; i < n; i++) {
		cout << (tmp ^ a[i]) << ' ';
	}
	cout << '\n';




}

Measured memory_bytes: 4784
#include <bits/stdc++.h>
#define int long long
using namespace std;
using P = pair<double, double>;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;



signed main() {
    int n;
    cin >> n;
    vector<P> v;
    for (int i = 0; i < n; i++) {
        double x, y;
        cin >> x >> y;
        v.emplace_back(x, y);
    }
    sort(v.begin(), v.end());
    double d = 0;
    do {
        for (int i = 0; i < n - 1; i++) {
            d += hypot((v[i].first - v[i + 1].first), (v[i].second - v[i + 1].second));
        }
    } while (next_permutation(v.begin(), v.end()));
    double fact = 1;
    for (int i = 2; i <= n; i++) {
        fact *= (double)i;
    }
    double ave = d / fact;
    cout << setprecision(10) << ave << "\n";
}

Measured memory_bytes: 256