akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
unsigned long long a[87];
int main()
{
	a[0]=2;a[1]=1;
	int n;
	cin>>n;
	for(int i=2;i<=n;++i)
	a[i]=a[i-1]+a[i-2];
	cout<<a[n]<<endl;
}

Measured memory_bytes: 256
n = int(input())
l = [[[],0]]
for i in range(n):
    nxt = []
    for li, ma in l:
        for j in range(ma+1):
            lj = li[:]
            lj.append(j)
            if j == ma:
                nxt.append([lj, ma+1])
            else:
                nxt.append([lj, ma])
    l = nxt

ans = []
aa = ord("a")
for li,_ in l:
    ans.append("".join(map(lambda x: chr(x+aa), li)))
ans.sort()
print(*ans, sep="\n")

Measured memory_bytes: 107868
#include<stdio.h>
 
long max(long a,long b){
	if(a>b){
    	return a;
    }else{
    	return b;
    }
}
 
long min(long a,long b){
	if(a>b){
    	return b;
    }else{
    	return a;
    }
}
 
int f(long a,long b){
  long c=max(a,b);
  int keta=1;
  for(int i=0;i<10;i++){
  	if(c/10>0){
    	keta++;
      	c/=10;
    }
  }
  return keta;
}
 
 
 
int main(void){
  
  long N;
  int minnum=11;
  scanf("%ld",&N);
  
  for(long a=1;a*a<=N;a++){
    long b=0;
  	if(N%a == 0){
      b=N/a;
      int res=f(a,b);
      minnum=min(minnum,res);
    }
  }
  
  printf("%ld",minnum);
  
 
return 0;
}

Measured memory_bytes: 128
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());

        for (int num4 = 0; num4 <= n / 4; num4++) {
            if ((n - num4 * 4 ) % 7 == 0) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}


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

int main()
{
	vector<char> q;
	q.push_back('T');
	char c;
	while(scanf("%c",&c)!=EOF)
	{
		if(c=='\n') continue;
		if(c=='T'&&*(q.end()-1)=='S')
		{
			q.pop_back();
			continue;
		}
		else
		{
			q.push_back(c);
		}
	}
	cout<<q.size()-1;
 } 

Measured memory_bytes: 640
N = int(input())
a =[0]*N
for i in range(N):
  a[i] = int(input())

i = 0
l = 1
while 1:
  i+=1
  l=a[l-1]
  if l==2:
    ans=i
    break
  if i>N:
    ans=-1
    break
print(ans)
  

Measured memory_bytes: 6900
/*
 _  __    _   _   _ ____ _____ 
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |  
| . \  / ___ \ |_| |___) || |  
|_|\_\/_/   \_\___/|____/ |_|  
*/
#include <bits/stdc++.h>
#include <fstream>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb push_back
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
int dp[3005][3005];
int main()
{
    CIN;
    string x, y;
    cin >> x >> y;
    int n = x.size(), m = y.size();
    rep(i, 0, n)
    {
        rep(j, 0, m)
        {
            if (x[i] == y[j])
            {
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
            }
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j]);
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
            dp[i][j + 1] = max(dp[i][j + 1], dp[i][j]);
        }
    }
    vector<pair<int, pair<int, int>>> hl;
    rep(i, 1, n + 1)
    {
        rep(j, 1, m + 1)
        {
            if (dp[i][j] > max(dp[i - 1][j], dp[i][j - 1]))
            {
                hl.pb({dp[i][j], {i, j}});
            }
        }
    }
    sort ar(hl);
    int maxi = -1, xx = n + 1, yy = m + 1;
    string klo;
    rep(i, 0, hl.size())
    {
        if (hl[i].ff != maxi && xx > hl[i].ss.ff && yy > hl[i].ss.ss)
        {
            maxi = hl[i].ff;
            xx = hl[i].ss.ff;
            yy = hl[i].ss.ss;
            klo.pb(x[xx-1]);
        }
    }
    reverse a(klo);
    cout << klo;
}


Measured memory_bytes: 49516
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define SREP(s,i,m) for(unsigned int i = s; i < m; ++i)
#define REP(i,m) SREP(0,i,m)

using namespace std;
#ifdef _MSC_VER
using LONG = __int64;
#else
using LONG = long long int;
#endif

int main(void) {
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  LONG score = 0;
  score = A[0] - 1;
  A[0] = 1;
  int checkindex = 0;
  int minV = 1;
  for (int i = 1; i < N; i++) {
    if (A[i] > minV) {
      if (A[i] - (minV + 1) > 0) {
        score += (A[i] - 1) / (minV + 1);
        A[i] = minV;
      }
      minV = max(minV, A[i]);
    }
  }
  cout << score << endl;
  return 0;
}

Measured memory_bytes: 768
s = gets.chomp
t = s+s
k = gets.to_i
n = s.size
f = true
(n-1).times do |i|
    f = false if s[i] != s[i+1]
end
if f
    puts (n*k)/2
    exit
end
if s[0] == s[-1]
    ans = 0
    a = 1
    b = 1
    n.times do |i|
        if s[i] == s[i+1]
            a += 1
        else
            break
        end
    end
    n.times do |j|
        i = n-1-j
        if s[i] == s[i-1]
            b += 1
        else
            break
        end
    end
    ans += a/2
    ans += b/2
    ans += (a+b)/2*(k-1)
    c = 1
    (a..(n-b-2)).each do |i|
        if s[i] == s[i+1]
            c += 1
        else
            if c > 1
                ans += c/2*k
            end
            c = 1
        end
    end
    ans += c/2*k
    puts ans
else
    ans = 0
    c = 1
    (0..(n-1)).each do |i|
        if s[i] == s[i+1]
            c += 1
        else
            if c > 1
                ans += c/2*k
            end
            c = 1
        end
    end
    ans += c/2*k
    puts ans
end

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

#define LIM 300020
using namespace std;

int main(){
	
	int n;
	bool isprime[LIM]={0};
	vector<int> primes;
	
	for(int i=2; i<LIM; ++i)
		isprime[i]=true;
	
	for(int i=2; i*i<LIM; ++i){
		
		if(isprime[i] && (i%7==1 || i%7==6)){
			for(int j=2; i*j<LIM; j++){
				if(j%7==1 || j%7==6){
					isprime[i*j]=false;
				}
			}
		}
		
	}
	
	for(int i=0; i<LIM; ++i){
	
		if(isprime[i]&&(i%7==1 || i%7==6))
			primes.push_back(i);
	}
	
	while(cin>>n, n>1){
		
		cout << n << ":";
		
		for(int i=0; i<primes.size(); ++i){
			
			if(n%primes[i]==0)
				cout << " " << primes[i];
		}
		
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1640
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1E9 + 9;
const int INF = 1 << 29;

ll rec(ll x, ll k) {
  ll abs_diff = abs(x - k);
  if (abs_diff >= x) return x;
  return rec(abs_diff, k);
}

int main() {
  ll N, K;
  cin >> N >> K;
  ll ans = rec(N % K, K);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
#include <string>

//Some constants don't work
#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
#ifndef INT_MIN
#define INT_MIN -2147483648
#endif
//short hand tricks
typedef long long ll;

using namespace std;

int main(int argc, char * argv[]) {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> sticks(n);
    for(int i=0; i<n; i++) {
        cin >> sticks[i];
    }
    sort(sticks.begin(), sticks.end());
    //triangle inequality the 2 shortest sides a,b > c
    ll res = 0;
    for(int i=0; i<n-2; i++) {
        ll LI = sticks[i];
        for(int j=i+1; j<n-1; j++) {
            ll LJ = sticks[j];
            if(LI==LJ) continue;
            for(int k=j+1; k<n; k++) {
                ll LK = sticks[k];
                if(LI==LK || LJ==LK) continue;
                if(LI+LJ>LK) {
                    res++;
                }
            }
        }
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 3624
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = LIST()
b = 0
for x in a:
    b ^= x
ans = []
for x in a:
    ans.append(b^x)
print(*ans)

Measured memory_bytes: 32292
import bisect

N = int(input())
a = set(map(int,input().split()))
A = sorted(list(a))
M = max(A)
num = M//2

index = bisect.bisect_right(A,num)

if index > 0 and abs(num - A[index]) > abs(num - A[index-1]):
    index = index-1
#print(index)

if M != A[index]:
    print(M,A[index])
else:
    print(M,A[index-1])

Measured memory_bytes: 68140
#include<cstdio>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1111;
char s[N];
int map[N][N],vis[N][N];
int n,m,tot,ax,ay,bx,by,head,tail;
int c[N*N*10][2],Next[N*N*10][2];
void bfs(){
	while (head<=tail){
		int tx=c[head][0],ty=c[head++][1];
		Next[++tot][0]=tx,Next[tot][1]=ty;
		for (int dx=-1; dx<=1; dx++)
			for (int dy=-1; dy<=1; dy++){
				if (abs(dx)+abs(dy)!=1)	continue;
				int p=tx+dx,q=ty+dy;
				if (p<=0||p>n||q<=0||q>m||map[p][q])	continue;
				if (!vis[p][q])	c[++tail][0]=p,c[tail][1]=q,vis[p][q]=1;
			}
	}
}
void find(){
	head=1,tail=0;
	for (int i=1; i<=tot; i++){
		int tx=Next[i][0],ty=Next[i][1];
		for (int dx=-2; dx<=2; dx++)
			for (int dy=-2; dy<=2; dy++){
				int p=tx+dx,q=ty+dy;
				if (p<=0||p>n||q<=0||q>m||map[p][q])	continue;
				if (!vis[p][q])	c[++tail][0]=p,c[tail][1]=q,vis[p][q]=1;
			}
	}
	tot=0;
}
void solve(){
	head=1;
	c[++tail][0]=ax,c[tail][1]=ay;
	int ans=0;
	while (1){
		bfs();
		if (vis[bx][by]){
			printf("%d\n",ans);
			return;
		}
		if (tot==0)	break;
		ans++;
		find();
	}
	printf("-1\n");
}
int main(){
	scanf("%d%d",&n,&m);
	scanf("%d%d%d%d",&ax,&ay,&bx,&by);
	for (int i=1; i<=n; i++){
		scanf("%s",s+1);
		for (int j=1; j<=m; j++){
			if (s[j]=='#')	map[i][j]=1;
			if (s[j]=='.')	map[i][j]=0;
		}
	}
	solve();
	return 0;
}

Measured memory_bytes: 10512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1373>
 問題文============================================================
 =================================================================
 解説=============================================================

 ================================================================
 */

void solve(){
    int n; cin >> n;
    vector<int> x(n); for(auto& in:x) cin >> in;
    set<int> s;
    int lim = 1;
    for(int i = 0; i < n;i++){
        if(s.count(0)){
            cout << "No" << endl;
            continue;
        }
        while(s.count(lim)) lim++;
        if(x[i] < lim - 1){
            cout << "No" << endl;
            continue;
        }
        if(x[i] == lim -1 && s.size() != x[i]){
            cout << "No" << endl;
            continue;
        }
        cout << "Yes" << endl;
        while(s.count(x[i])) s.erase(x[i]--);
        s.insert(x[i]);
    }
    return;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve();
    return 0;
}



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

typedef long long ll;

vector< vector< ll > > AdjMat;
ll n,k;
const ll MOD = 1e9 + 7;

vector< vector< ll > > matMul(vector< vector< ll > > a,vector< vector< ll > > b)
{
	vector< vector< ll > > ans;
	ans.resize(n);
	for (ll i = 0 ; i < n ; i++)
	{
		ans[i].resize(n,0);
		for (ll j = 0 ; j < n ; j++)
			for (ll k = 0 ; k < n ; k++)
			{
				ans[i][j] += a[i][k] * b[k][j];
				ans[i][j] %= MOD;
			}
	}
	return ans;
}

vector< vector< ll > >  matPow(vector< vector< ll > > base,ll p)
{
	vector< vector<ll > > ans;
	ans.resize(n);
	for (ll i = 0 ; i < n ; i++)
	{
		ans[i].resize(n,0);
		for (ll j = 0 ; j < n ; j++)
			ans[i][j] = (i == j);
	}
	while (p)
	{
		if (p & 1) ans = matMul(ans,base);
		base = matMul(base,base);
		p >>= 1;
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> k;
	AdjMat.resize(n);
	for (ll i = 0 ; i < n ; i++)
	{
		AdjMat[i].resize(n);
		for (ll j = 0 ; j < n ; j++)
			cin >> AdjMat[i][j];
	}
	vector< vector< ll > > ans = matPow(AdjMat,k);
	ll ret = 0;
	for (ll i = 0 ; i < n ; i++)
	{
		for (ll j = 0 ; j < n ; j++)
		{
			// cout << ans[i][j] << " ";
			ret += ans[i][j];
			ret %= MOD;
		}
		// cout << endl;
	}
	cout << ret << endl;
}

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

using namespace std;

int h, w, k;
int sum;
char s[10][10];
int cnt;
int main()
{
	cin >> h >> w >> k;
	for(int i = 0; i <= h-1; i++)
	{
		for(int j = 0; j <= w-1; j++)
		{
			cin >> s[i][j];
			if(s[i][j] == '#')
			{
				sum++;
			//	printf("%d %d ---> %d\n", i, j, sum);
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < (1 << h); i++)
	{
		for(int j = 0; j < (1 << w); j++)
		{
			int cnt = 0;
			for(int r = 0; r < h; r++)
			{
				for(int c = 0; c < w; c++)
				{
					if(((1 << r) & i) || ((1<<c) & j))
					{
						 	if(s[r][c] == '#')
						 	{
						 		cnt++;
						 	//	printf("%d %d:\n", i, j);
						 	//	printf("%d %d ---- > %d\n", r, c, cnt);
						 	}
					}
				}
			}
			if(cnt == sum - k)
			{
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

struct drink {
		ll a;
		ll b;
};

int main() {
		int N, M;
		cin >> N >> M;
		vector<drink> info(N, {0, 0});
		for (int i = 0; i < N; i++) {
				cin >> info[i].a >> info[i].b;
		}

		sort(info.begin(), info.end(), [](const drink &x, const drink &y) {
				return x.a < y.a;
		});

		ll ans = 0;
		int bought = 0;
		for (int i = 0; i < N; i++) {
				if (M - bought > info[i].b) {
						ans += info[i].a * info[i].b;
						bought += info[i].b;
				} else if (M - bought <= info[i].b) {
						ans += info[i].a * (M - bought);
						break;
				}
		}

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


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

void solve(int N, std::vector<std::string> S, std::vector<int> P){
    vector<tuple<string, int, int>> a;
    for(int i = 1; i <= N; ++i) a.push_back(make_tuple(S[i-1], -P[i-1], i));
    sort(a.begin(), a.end());
    for(int i = 0; i < N; ++i) cout << get<2>(a[i]) << endl;
}

int main(){
    int N;
    cin >> N;
    std::vector<std::string> S(N);
    std::vector<int> P(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> S[i] >> P[i];
    }
    solve(N, std::move(S), std::move(P));
    return 0;
}


Measured memory_bytes: 256
from sys import stdin, stdout
read = stdin.readline
write = stdout.write
flush = stdout.flush
xr = range

def main():
  n,k = map(int,read().split())
  a = sorted(list(map(int,read().split())))
  write('{}\n'.format(sum(a[:k])))

if __name__ == "__main__":
  main()

Measured memory_bytes: 85048
#include <bits/stdc++.h>
using namespace std;
int main()
{
    vector<int> arr;
    int q,c,d;
    cin>>q;
    for(int i=1;i<=q;i++){
        cin>>c;
        if(c==0){
            cin>>d;
            arr.push_back(d);
        }
        else if(c==2){
            arr.pop_back();
        }
        else if(c==1){
            cin>>d;
            cout<<arr[d]<<endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
#define N 610
int a[N][N],n,d1,d2,b;
int main(){
	scanf("%d%d%d",&n,&d1,&d2);
	while (d1%4==0){
		b++; d1/=4;
	}
//	printf("%d\n",d1);
	if (d1&1){
		for (int i=0;i<2*n;i++)
			for (int j=0;j<2*n;j++)
				if (((i>>b)+(j>>b))&1)
					a[i][j]=1;
	}
	else
		for (int i=0;i<2*n;i++)
			for (int j=0;j<2*n;j++)
				if ((i>>b)&1) a[i][j]=1;
	b=0;
	while (d2%4==0){
		b++; d2/=4;
	}	
//	printf("%d\n",d2);
	if (d2&1)
		for (int i=0;i<2*n;i++){
			for (int j=0;j<2*n;j++)
				if (((i>>b)+(j>>b))&1)
					a[i][j]=1;
		}
	else
		for (int i=0;i<2*n;i++)
			for (int j=0;j<2*n;j++)
				if ((i>>b)&1) a[i][j]=1;
	
	int tt=0;
	/*for (int i=0;i<2*n;i++) {
		for (int j=0;j<2*n;j++) printf("%d ",a[i][j]);
		puts("");
	}*/
	for (int i=0;i<2*n;i++)
		for (int j=0;j<2*n;j++)
			if (a[i][j]==0) {
				tt++;
				printf("%d %d\n",i,j);
				if (tt==n*n) return 0;
			}
	return 0;
}

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

bool dp[81][81][160*80];
int r[81][81];
int s = 80*80;

int main() {
    int h, w; cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> r[i][j];
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int b; cin >> b; r[i][j] -= b;
        }
    }

    dp[0][0][r[0][0]+s] = true;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            for (int k = 0; k < 160*80; k++) {
                if (!dp[i][j][k]) continue;
                dp[i+1][j][k+r[i+1][j]] = true;
                dp[i+1][j][k-r[i+1][j]] = true;
                dp[i][j+1][k+r[i][j+1]] = true;
                dp[i][j+1][k-r[i][j+1]] = true;
            }
        }
    }
    int ans = 1e9;
    for (int k = 0; k < 160 * 80; k++) {
        if (!dp[h-1][w-1][k]) continue;
        ans = min(ans, abs(s-k));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 81792
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
list<int> L;
stack<int> S;
queue<int> Q;
deque<int> dq;
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
static const int MAX=1e5;
static const int MOD=1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int H,W;
int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    cin>>H>>W;
    bool cc[H+2][W+2];
    memset(cc,0,sizeof(cc));
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            char c;
            cin>>c;
            if(c=='#')cc[i][j]=true;
        }
    }
    
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            if(cc[i][j]){
                bool flag=false;
                for(int k=0;k<4;k++){
                    if(cc[i+dx[k]][j+dy[k]])flag=true;
                }
                if(!flag){
                    cout<<"No"<<"\n";
                    return 0;
                }
            }
        }
    }
    cout<<"Yes"<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c<'0' || c>'9'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	ll f=1;
	while((c=getchar())!='-' && (c<'0' || c>'9'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=3e5+10,inf=0x3f3f3f3f;
inline bool chkmin(int &x,int y){return (y<x)?(x=y,1):0;}
inline bool chkmax(int &x,int y){return (y>x)?(x=y,1):0;}
int n,w,h;
struct Segment_tree{
	int Max[maxn<<2],tag[maxn<<2];
	void push_down(int x){
		if(tag[x]!=0){
			Max[x<<1]+=tag[x],Max[x<<1|1]+=tag[x];
			tag[x<<1]+=tag[x],tag[x<<1|1]+=tag[x];
			tag[x]=0;
		}
	}
	void build_tree(){
		REP(i,1,n<<2) Max[i]=-inf,tag[i]=0;
	}
	void update(int x,int L,int R,int ql,int qr,int v){
		if(ql<=L && R<=qr){
			tag[x]+=v;Max[x]+=v;
			return;
		}
		int Mid=(L+R)>>1;push_down(x);
		if(ql<=Mid) update(x<<1,L,Mid,ql,qr,v);
		if(qr>Mid) update(x<<1|1,Mid+1,R,ql,qr,v);
		Max[x]=max(Max[x<<1],Max[x<<1|1]);
	}
}Seg;
struct point{
	int x,y;
	bool operator <(const point &rhs) const{
		return x<rhs.x;
	}
}a[maxn];
point sta[maxn],stb[maxn];
int tmpa,tmpb,ans;
void work(){
	Seg.build_tree();
	sort(a+1,a+n+1);
	tmpa=tmpb=0;
	REP(i,1,n-1){
		if(a[i].y<=h/2){
			int lst=i;
			while(tmpa && a[i].y>=sta[tmpa].y){
				Seg.update(1,1,n,sta[tmpa].x,lst-1,sta[tmpa].y-a[i].y);
				lst=sta[tmpa].x;--tmpa;
			}
			if(lst<i) sta[++tmpa]=(point){lst,a[i].y};
		}
		else{
			int lst=i;
			while(tmpb && a[i].y<=stb[tmpb].y){
				Seg.update(1,1,n,stb[tmpb].x,lst-1,a[i].y-stb[tmpb].y);
				lst=stb[tmpb].x,--tmpb;
			}
			if(lst<i) stb[++tmpb]=(point){lst,a[i].y};
		}
		sta[++tmpa]=(point){i,0};
		stb[++tmpb]=(point){i,h};
		Seg.update(1,1,n,i,i,inf+h-a[i].x);
		chkmax(ans,Seg.Max[1]+a[i+1].x);
	}
}
int main(){
	w=read(),h=read(),n=read();
	REP(i,1,n) a[i].x=read(),a[i].y=read();
	a[++n]=(point){0,0},a[++n]=(point){w,h};
	work();
	REP(i,1,n) swap(a[i].x,a[i].y);
	swap(w,h);
	work();
	printf("%d\n",ans*2);
	return 0;
}

Measured memory_bytes: 15616
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cctype>
#include <ctime>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define eps 1e-9

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

const ll INF = 1e18;
const int maxn = 2e3 + 10;
int n, m, a, b, c, edge = 0;
int head[maxn], Next[maxn], to[maxn], cnt[maxn];
ll val[maxn], dis[maxn];
bool vis[maxn], vis1[maxn];
bool flag;

inline void add_edge(int u, int v, int _val) {
    to[edge] = v; val[edge] = _val; Next[edge] = head[u]; head[u] = edge++;
}
void dfs(int u) {
    if (u == n) { flag = true; return; }
    for (int i = head[u]; i != -1; i = Next[i]) {
        if (vis1[to[i]]) { continue; } vis1[to[i]] = true; dfs(to[i]);
    }
}
bool judge(int u) { memset(vis1, false, sizeof(vis1)); flag = false; dfs(u); return flag; }
bool spfa() {
    memset(vis, false, sizeof(vis)); memset(cnt, 0, sizeof(cnt)); int f;
    dis[1] = 0; for (int i = 2; i <= n; ++i) { dis[i] = INF; }
    queue<int> q; q.push(1);
    while (!q.empty()) {
        f = q.front(); q.pop(); vis[f] = false; ++cnt[f];
        if (cnt[f] > n - 1) {
            if (judge(f)) { return false; } vis[f] = true;
        }
        for (int i = head[f]; i != -1; i = Next[i]) {
            if (dis[to[i]] > dis[f] + val[i]) {
                dis[to[i]] = dis[f] + val[i];
                if (!vis[to[i]]) { vis[to[i]] = true; q.push(to[i]); }
            }
        }
    }
    return true;
}

int main() {
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif // __AiR_H
    memset(head, -1, sizeof(head));
    scanf("%d %d", &n, &m);
    while (m--) {
        scanf("%d %d %d", &a, &b, &c); c = -c; add_edge(a, b, c);
    }
    if (spfa()) { printf("%lld\n", -dis[n]); } else { printf("inf\n"); }
#ifdef __AiR_H
    printf("Time used = %.2fs\n", (double)clock() / CLOCKS_PER_SEC);
#endif // __AiR_H
    return 0;
}


Measured memory_bytes: 384
import java.util.*;
import static java.lang.Math.*;
public class Main {
	final Scanner sc=new Scanner(System.in);
	public static void main(String[] args) {
		new Main().init();
	}
	void init(){
		final long STACK_SIZE=8*1024*1024;
		new Thread(null, new AOJ1217(), "RUN!", STACK_SIZE).start();
	}
	
	class AOJ1217 implements Runnable{
		AOJ1217(){}
		
		int N,M;
		
		@Override public void run(){
			while(sc.hasNext()){
				N=sc.nextInt();
				M=sc.nextInt();
				if((N|M)==0)	break;
				solve();
				System.out.println();
			}
		}
		
		Person[] a;
		HashMap<String,Integer> dic;
		
		void solve(){
			a=new Person[N];
			dic=new HashMap<String, Integer>();
			int p=-1;
			sc.nextLine();
			for(int i=0; i<N; i++){
				StringBuilder line=new StringBuilder(sc.nextLine());
				int j=0;
				while(line.charAt(j)==' ')	++j;
				for(int k=i-1; k>=0; k--){
					if(a[k].n==j-1){
						p=k;
						break;
					}
				}
				if(j>0){
					if(p<0)	throw new RuntimeException("parent not found");
					a[p].child.add(i);
				}
				String name=line.toString().replaceAll(" ", "");
				a[i]=new Person(name, p,j);
				dic.put(name, i);
				p=-1;
			}
			
			for(int i=0; i<M; i++){
				String line=sc.nextLine().replaceAll("\\.", "");
				String[] q=line.split(" ");
				boolean ans=false;
				if(q[3].equals("child")){
					int now=dic.get(q[5]);
					for(int j:a[now].child){
						if(a[j].name.equals(q[0])){
							ans=true;
							break;
						}
					}
				}else if(q[3].equals("parent")){
					int tmp=a[dic.get(q[5])].parent;
					ans=(tmp>=0 && a[tmp].name.equals(q[0]));
				}else if(q[3].equals("sibling")){
					int now=a[dic.get(q[5])].parent;
					if(now>=0){
						for(int j:a[now].child){
							if(a[j].name.equals(q[0])){
								ans=true;
								break;
							}
						}
					}
				}else if(q[3].equals("descendant")){
					ans=findChild(dic.get(q[5]),q[0]);
				}else if(q[3].equals("ancestor")){
					int now=dic.get(q[5]);
					while(a[now].parent>=0){
						now=a[now].parent;
						if(a[now].name.equals(q[0])){
							ans=true;
							break;
						}
					}
				}
				System.out.println(ans?"True":"False");
			}
		}
		
		boolean findChild(int now,String target){
			if(a[now].name.equals(target))	return true;
			for(int i:a[now].child){
				if(findChild(i,target))	return true;
			}
			return false;
		}
		
		class Person{
			int parent,n;
			ArrayList<Integer> child;
			String name;
			Person(String name,int parent,int n){
				this.name=name;
				this.parent=parent;
				this.n=n;
				this.child=new ArrayList<Integer>();
			}
			@Override public String toString(){
				return name+" P:"+parent+" C:"+child+" N:"+n;
			}
		}
	}
}

Measured memory_bytes: 13000
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)


// ------------debug用------------
#define FALSE cout<<"false"<<endl;
#define TRUE cout<<"true"<<endl;
// ------------debug用------------


// ------------計算用------------
#define ALL(x) (x).begin(),(x).end()
#define FOR(x) for(ll i = 0;i < x;++i)
// ------------計算用------------


// ------------出力用------------
#define PRINT(x) cout<<x<<endl;
// ------------出力用------------


using namespace std;
typedef long long ll;

int main(){
  int A,X;
  cin>>X>>A;
  int ans = 10;
  if(X < A)ans = 0;
  cout<<ans;
  return 0;
}


Measured memory_bytes: 256
li = list(map(int,input().split()))
s=list(input())
N=li[0]
A=li[1]
B=li[2]
domPass=0
forePass=0
for x in s:
    if(x=='a'):
        if((domPass+forePass)<(A+B)):
            domPass=domPass+1
            print('Yes')
        else:
            print('No')
    elif(x=='b'):
        if(((domPass+forePass)<(A+B))and(forePass<B)):
            forePass=forePass+1
            print('Yes')
        else :
            print('No')
    elif(x=='c'):
        print('No')

Measured memory_bytes: 74340
#include <iostream>
#include <cstdio>
using namespace std;
#define MAX 15

int main(){
    int Mag[MAX][MAX],n;
    
    while(cin >> n,n){
        for(int i = 0 ; i < n ; i++)
            for(int j = 0 ; j < n ; j++)
                Mag[i][j] = 0;
        
        int dx = n/2+1, dy = n/2, cnt = n*n, num = 1;
        Mag[dx++][dy++] = num++;
        while(num < cnt+1){
            if(dx >= n) dx = 0;
            else if(dy >= n) dy = 0;
            else if(dy < 0) dy = n-1;
            else if(Mag[dx][dy]){
                dx++;
                dy--;
            }
            else{
                Mag[dx++][dy++] = num++;
            }
        }
        
        for(int i = 0 ;i < n ; i++){
            for(int j = 0 ; j < n ; j++){
                printf("%4d" ,Mag[i][j]);
            }
            puts("");
        }
    }

    return 0;
}

Measured memory_bytes: 1156
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
XY=[[None] for i in range(N)]
x,y=MAP()
XY[0]=(x, y)
od_ev=(abs(x)+abs(y))%2
for i in range(1, N):
    x,y=MAP()
    # まず大前提として偶奇が合うかどうか
    if od_ev!=(abs(y)+abs(x))%2:
        print(-1)
        exit()
    XY[i]=(x, y)

# アームの作成(2冪で構成する)
arms=[]
for i in range(31, -1, -1):
    arms.append(2**i)
if od_ev==0: arms.append(1)
print(len(arms))
print(*arms)

for i in range(N):
    ans=['']*len(arms)
    x,y=XY[i]
    # 斜めに交差するu座標とv座標を使う
    u=x+y
    v=x-y
    for j, arm in enumerate(arms):
        # uとvの正負の応じて、動かす方向を決める
        if u>=0 and v>=0:
            ans[j]='R'
            u-=arm
            v-=arm
        elif u>=0 and v<0:
            ans[j]='U'
            u-=arm
            v+=arm
        elif u<0 and v>=0:
            ans[j]='D'
            u+=arm
            v-=arm
        elif u<0 and v<0:
            ans[j]='L'
            u+=arm
            v+=arm
    print(''.join(ans))


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

using namespace std;

#define INF 1000000000
#define pb(a) push_back(a)
#define vi vector<int>
#define vvi vector<vi>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
#define ll long long
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x;
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < sz(v);i++)


int main(){
	int n,h;
	int aa,bb;
	vi b;
	int ma=0;
	int cnt=0;
	cin>>n>>h;
	REP(i,n){
		cin>>aa>>bb;
		if(ma<aa)ma=aa;
		b.pb(bb);
	}
	sort(all(b),greater<int>());
	REP(i,n){
		if(ma<b[i]){
			h-=b[i];
			cnt++;
		}else break;
		if(h<=0){
			h=0;break;
		}
	}
	cout<<cnt+(h+ma-1)/ma<<"\n";
	return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;

int main(){
  FIO
 int n,b,fl=1;
 cin>>n;
 forn(i,n)
 {
  cin>>b;
  if(b%2==0)
  {
    if(b%3==0||b%5==0)fl*=1;
    else fl*=0;
  }
 }
 if(fl)cout<<"APPROVED";
 else cout<<"DENIED";
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  ll N; cin >> N;
  vector<ll> a(N);
  vector<ll> b(N);
  ll suma=0,sumb=0;
  rep(i,N){
    cin >> a[i];
    suma+=a[i];
  } 
  rep(i,N){
    cin >> b[i];
    sumb+=b[i];
  }
  if(suma<sumb){
    cout << -1 << endl;
    return 0;
  }
  ll mcnt=0;
  ll msum=0;
  vector<ll> c(N);
  rep(i,N){
    c[i]=a[i]-b[i];
    if(c[i]<0){
      mcnt++;
      msum+=c[i];
    }
  }
  sort(all(c));
  reverse(all(c));
  int id=0;
  while(msum<0){
    msum+=c[id];
    id++;
  }
  cout << mcnt+id << endl;
}

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

int main(){
 int r = 0;
 cin >> r;
 if(r < 1200){
     cout << "ABC\n";
 }else if(r < 2800){
     cout << "ARC\n";
 }else{
     cout << "AGC\n";
 }
 return 0;
}

Measured memory_bytes: 256
let () = Scanf.scanf "%d %d %d" @@ fun a b x ->
  Printf.printf "%.12f\n" @@
  if x <= a * a * b / 2
  then 90. -. 45. *. atan2 (2. *. float_of_int x) (float_of_int (a * b * b)) /. atan 1.
  else 90. -. 45. *. atan2 (float_of_int (a * a * a)) (2. *. float_of_int (a * a * b - x)) /. atan 1.


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
#define N 1000015
const int p=1e9+7;
int n,m,k,f[N],finv[N],inv[N],bin[N];
inline int C(int nn,int mm)
{
	if(nn==mm||mm==0)return 1;
	if(nn<mm)return 0;
	return 1ll*f[nn]*finv[mm]%p*finv[nn-mm]%p;
}
int main()
{
    scanf("%d%d%d",&n,&m,&k);if(m<k)swap(m,k);
    f[0]=finv[0]=f[1]=finv[1]=inv[1]=bin[0]=1;bin[1]=3;
    for(int i=2;i<=n+m+k;i++)
    {bin[i]=3ll*bin[i-1]%p;
    	inv[i]=1ll*(p-p/i)*inv[p%i]%p;
    	f[i]=1ll*f[i-1]*i%p;finv[i]=1ll*finv[i-1]*inv[i]%p;
	}int ans=0,sum=1;
	for(int i=0;i<=m+k;i++)
	{
		int te=sum;
		te=1ll*te*bin[m+k-i]%p*C(n+i-1,n-1)%p;
		ans=(ans+te)%p;
		if(i<k)sum=2ll*sum%p;
		else if(i<m)sum=(2ll*sum%p-C(i,k)+p)%p;
		else sum=(2ll*sum%p-C(i,k)+p-C(i,i-m)+p)%p;
	}printf("%d\n",ans);
}


Measured memory_bytes: 15488
//
//  main.cpp
//  ProgrammingContestChallengeBook2
//
//  Created by Hisaki Kobayashi on 2020/04/04.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <string>
#include <bits/stdc++.h>
#include <stdlib.h>
//#include "mylibrary.hpp"



using namespace std;


int main(){
    long long K,N; cin >> K >> N;
    long long i;
    vector<long long> A;
    for(i=0;i<N;i++){
        int temp; cin >> temp;
        A.push_back(temp);
    }
    
    long long max_dist = 0,sum=0;
    vector<long long> d;
    long long distance;
    for(i=0;i<N-1;i++){
        distance = A.at(i+1) - A.at(i);
        d.push_back(distance);
        max_dist = max(max_dist,distance);
        sum += distance;
    }
    
    distance =K - A.at(N-1) + A.at(0);
    d.push_back(distance);
    max_dist = max(max_dist,distance);
    sum += distance;
    cout << sum - max_dist << endl;
}


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

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

    int digit1, digit2;
    digit1 = n % 10;
    digit2 = n / 10;

    if (digit1 == 9 || digit2 == 9) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <regex>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;
const int INF = 2147483647;

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//myfuncs
//素数判定
template<class T> inline T isPrime(T x) {
	bool ret = true;
	if (x < 2) {
		ret = false;
	}
	for (LL i = 2; i <= sqrt(x); i++) {
		if (x%i == 0) {
			ret = false;
		}
	}
	return ret;
}

//Union FInd
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//main code

int main(int argc, char const* argv[])
{
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a[0];
    int ans = 0;
    for (int i = 1; i < n; i++) {
        cin >> a[i];
        if (a[i-1] == a[i]) {
            ans++;
            a[i] = INF;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){

  int n, q, i, j, S[10000], T[500], C = 0;

  scanf("%d", &n);
  for(i = 0; i < n; i++)
    scanf("%d", &S[i]);
  scanf("%d", &q);
  for(i = 0; i < q; i++)
    scanf("%d", &T[i]);
  
  for(i = 0; i < q; i++){
    for(j = 0; j < n; j++){
      if(T[i] == S[j]){
	C++;
	break;
      }
    }
  }

  printf("%d\n", C);
  return 0;
}

Measured memory_bytes: 640
N,M = map(int,input().split(" "))
arr = []
for i in range(N):
    a,b = map(int,input().split(" "))
    arr.append([a,b])

arr = sorted(arr)
sum = 0
i = 0
while M > 0:
    a = arr[i]
    b = min(M,a[1])
    sum = sum + b * a[0]
    M = M - b
    i = i + 1

print(sum)


Measured memory_bytes: 20832
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
struct P {
  int x, y;
  P(int x_, int y_) : x(x_), y(y_) {}
  P() {}
  bool operator ==(const P &other) const {
    return x == other.x && y == other.y;
  }
  bool operator !=(const P &other) const {
    return !(*this == other);
  }
};
ostream &operator <<(ostream &os, const P &p) {
  os << "(" << p.x << "," << p.y << ")";
  return os;
}
int direction(const P &p) {
  if (p.y == 0 && p.x > 0) return 0;
  if (p.y > 0 && p.x == 0) return 3;
  if (p.y == 0 && p.x < 0) return 2;
  return 1;
}
P rot(const P &p, int direction) {
  if (direction == 0) return p;
  if (direction == 1) return P(-p.y, p.x);
  if (direction == 2) return P(-p.x, -p.y);
  return P(p.y, -p.x);
}
bool same(const vector<P> &a, const vector<P> &b) {
  if (a.size() != b.size()) return false;
  int N = a.size();
  vector<P> l(N), r(N);
  REP(i,N) {
    l[i] = P(a[i].x - a[0].x, a[i].y - a[0].y);
    r[i] = P(b[i].x - b[0].x, b[i].y - b[0].y);
  }
  bool ok = true;
  for(int i = 1; i < N; i++) {
    if(rot(l[i], direction(l[1])) != rot(r[i], direction(r[1]))) ok = false;
  }
  // if(ok) {
  //   cerr << "[";
  //   REP(i,N) cerr << l[i];
  //   cerr << "] = [";
  //   REP(i,N) cerr << r[i];
  //   cerr << "]" << endl;
  // }
  if(ok) return true;
  REP(i,N) {
    l[i] = P(a[i].x - a[0].x, a[i].y - a[0].y);
    r[i] = P(b[N - 1 - i].x - b[N - 1].x, b[N - 1 - i].y - b[N - 1].y);
  }
  ok = true;
  for(int i = 1; i < N; i++) {
    if(rot(l[i], direction(l[1])) != rot(r[i], direction(r[1]))) ok = false;
  }
  // if(ok) {
  //   cerr << "[";
  //   REP(i,N) cerr << l[i];
  //   cerr << "] = [";
  //   REP(i,N) cerr << r[i];
  //   cerr << "]" << endl;
  // }
  if(ok) return true;
  return false;
}
signed main() {
  ios::sync_with_stdio(false);
  while(true) {
    int N; cin >> N;
    if(N == 0) break;
    vector<vector<P>> DS(N + 1);
    REP(i,N + 1) {
      int M; cin >> M;
      vector<P> D(M);
      REP(j,M) {
        int x, y; cin >> x >> y;
        D[j] = P(x, y);
      }
      DS[i] = D;
    }
    for(int i = 1; i <= N; i++) {
      if(same(DS[0], DS[i])) {
        cout << i << endl;
      }
    }
    cout << "+++++" << endl;
  }
}

Measured memory_bytes: 3116
require 'prime'

n = gets.to_i
count = 0
reject = []
n.prime_division.each do |prime|
  num = prime[0] ** prime[1]
  1.upto(prime[1]) do |i|
    z = (prime[0] ** i)
    next if reject.include?(z)
    num = num / z
    reject << z
    if num >= 1
      count += 1
    elsif num == 0
      break
    end
  end
end

p count


Measured memory_bytes: 14368
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define _GLIBCXX_DEBUG
int main()
{
    int r,d,x00;
    cin>>r>>d>>x00;
    int y=x00;
    vin x(10);
    rep(i,10){
        x[i]=r*y-d;
        cout<<x[i]<<endl;
        y=x[i];
    }
}

Measured memory_bytes: 256
using namespace std;
#include<string>
#include<cmath>
#include <map>
#include <unordered_map>
#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)

#define fr(i,a,b) for(ll i=a;i<b;i++)
#define ffr(i,a,b) for(ll i=a;i>=b;i--)
#include<bits/stdc++.h>
#include<vector>
#define vl vector<ll>
#define PI 3.141592654
const ll N = 1e9;
#include<iterator>




void solve() {
	ll n, amt = 1000; cin >> n;
	ll a[n];
	fr(i, 0, n)cin >> a[i];
	fr(i, 1, n) {
		if (a[i] > a[i - 1]) {
			ll k = amt / a[i - 1];
			ll p = k * a[i];
			amt = p + (amt % a[i - 1]);
		}
	}
	cout << amt;
}



int main() {
	fio;
#ifndef ONLINE_JUDGE
	// for getting input
	freopen("input.txt", "r", stdin);
	//for writing output
	freopen("jout.txt", "w", stdout);
#endif

	ll t, h = 1;
	if (1)
		t = 1;
	else
		cin >> t;
	while (t--) {
		//cout << "Case #" << h << ":\n";
		solve();
		//h++;
		//cout << '\n';
	}
	return 0;
}

Measured memory_bytes: 3652
MOD = 998244353
list_size = 2500100

f_list = [1] * list_size
f_r_list = [1] * list_size

for i in range(list_size - 1):
	f_list[i + 1] = (f_list[i] * (i + 2)) % MOD

f_r_list[-1] = pow(f_list[-1], MOD - 2, MOD)

for i in range(2, list_size + 1):
	f_r_list[-i] = (f_r_list[-i + 1] * (list_size + 2 - i)) % MOD

def comb(n, r):
	if n < r:
		return 0
	elif n == 0 or r == 0 or n == r:
		return 1
	else:
		return (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD 

n, m = map(int, input().split())
ans = comb(3*m+n-1, n-1)
ans -= n*(m+n-2)*comb(m+n-3, n-2)*pow(n-1, MOD-2, MOD)
for k in range(m+1, n+1):
	if (m-k)%2 == 1:
		continue
	ans -= comb(n, k) * comb((3*m-k)//2+n-1, n-1)
	ans %= MOD
print(ans%MOD)

Measured memory_bytes: 79836
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  int n;
  string s;
  cin >> n >> s;
  for (auto&&c: s) {
    char rot = (char)(((c - 'A' + n)%26) + 'A');
    cout << rot;
  }
  cout << endl;
}


Measured memory_bytes: 256
# Code for B - Popular Vote
# Use input() to fetch data from STDIN
[n, m] = map(int, input().split())
a = list(map(int, input().split()))

total = sum(a)

if len(list(filter(lambda x: x >= (total / (4 * m)), a))) >= m:
    print("Yes")
else:
    print("No")



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

void MatrixChainMultiplication(int n,int p[],int m[101][101]) {
	int i, j, k,l;
	for (i = 1; i <= n; i++) m[i][i] = 0;
	for (l = 2; l <= n; l++) {
		for (i = 1; i <= n - l +1; i++) {
			j = i + l - 1;
			m[i][j] = 100000000;
			for (k = i; k <= j - 1; k++) {
				
				m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
}

int main() {
	int n, p[101], m[101][101];
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> p[i - 1] >> p[i];
	MatrixChainMultiplication(n, p, m);
	cout << m[1][n] << endl;

	
}

Measured memory_bytes: 3124