akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define M 1000003
#define N 12
using namespace std;
int n,d[M];
char str[N],key[N];

int stoi(string s){
  int r=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='A')r=r*4+1;
    if(s[i]=='C')r=r*4+2;
    if(s[i]=='G')r=r*4+3;
    if(s[i]=='T')r=r*4+4;
  }
  return r;
}

void insert(int k){
  int i=0,f=0;
  while(!f){
    int p=(k%M+i*(1+k%(M-1)))%M;
    if(d[p]<0)d[p]=k,f=1;
    i++;
  }
}

bool find(int k){
  int i=0;
  while(i!=M){
    int p=(k%M+i*(1+k%(M-1)))%M;
    if(d[p]==k)return true;
    if(d[p]<0)return false;
    i++;
  }
  return false;
}

int main(){
  cin>>n;
  for(int i=0;i<M;i++)d[i]=-1;
  while(n--){
    scanf("%s%s",str,key);
    int k=stoi(key);
    if(str[0]=='i')insert(k);
    else{
      if(find(k))printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}

Measured memory_bytes: 5112
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define pi pair<ll,ll>
using namespace std;
int main(){
	//	freopen("in.txt","r",stdin);
	int N;
	int s[110];
	ll SUM=0;
	bool flag = false;
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> s[i];
		SUM += s[i];
	}
	sort(s,s+N);
	if(SUM % 10 == 0){
		for (int i = 0; i < N; ++i)
		{
			if(s[i]%10 != 0){
				SUM -= s[i];
				flag = true;
				break;
			}
		}
	}else{
		flag = true;
	}
	if(flag) cout << SUM << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
n,y = map(int,(input().split())) #N枚　Y円

for i in range(n+1):
    for j in range(n - i + 1):
        sum = (10000 * j) + (5000 * i) + (1000 *(n-j-i))
        if (n -j - i) < 0:
            break
        if sum == y:
            print(j,i,n-j-i)
            sys.exit()
print("-1 -1 -1")




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

ll s[50],p[50];

ll f(ll n,ll x) {
    if (n==0)
        return 1;
    if (x==1)
        return 0;
    if (x<=1+s[n-1])
        return f(n-1,x-1);
    if (x==1+s[n-1]+1)
        return p[n-1]+1;
    if (x<=1+s[n-1]+1+s[n-1])
        return p[n-1]+1+f(n-1,x-2-s[n-1]);
    return 2*p[n-1]+1;
}

int main() {
    ll n,x;
    cin>>n>>x;
    s[0]=p[0]=1;
    for (int i=1;i<n;i++) {
        s[i]=s[i-1]*2+3;
        p[i]=p[i-1]*2+1;
    }
    cout<<f(n,x)<<endl;
    return 0;
}

Measured memory_bytes: 256
#define DEBUG 0

/**
 * File    : C.cpp
 * Author  : Kazune Takahashi
 * Created : 2019-5-28 15:35:36
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N, M;
vector<int> V[100010];
int parent[100010];
int start = -1;
int goal = -1;

bool dfs(int s)
{
  for (auto x : V[s])
  {
    if (x != parent[s])
    {
      if (x == start)
      {
        return false;
      }
      else if (x == goal)
      {
        return true;
      }
      parent[x] = s;
      if (!dfs(x))
      {
        return false;
      }
    }
  }
  return true;
}

int main()
{
  cin >> N >> M;
  for (auto i = 0; i < M; i++)
  {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    V[a].push_back(b);
    V[b].push_back(a);
  }
  bool odd = false;
  bool six = false;
  int four = 0;
  for (auto i = 0; i < N; i++)
  {
    int s = V[i].size();
    if (s % 2 == 1)
    {
      odd = true;
    }
    if (s >= 6)
    {
      six = true;
    }
    if (s == 4)
    {
      four++;
    }
  }
  if (odd)
  {
    cout << "No" << endl;
  }
  else if (six)
  {
    cout << "Yes" << endl;
  }
  else if (four >= 3)
  {
    cout << "Yes" << endl;
  }
  else if (four == 2)
  {
    for (auto i = 0; i < N; i++)
    {
      if ((int)V[i].size() == 4)
      {
        if (start == -1)
        {
          start = i;
        }
        else
        {
          goal = i;
          break;
        }
      }
    }
    fill(parent, parent + N, -1);
    if (!dfs(start))
    {
      cout << "Yes" << endl;
    }
    else
    {
      cout << "No" << endl;
    }
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 7296
#include<stdio.h>
int main()
{
	int a,b,c,more,n;
	scanf("%d %d %d",&a,&b,&c);
	more = b / a;
	if (a >= 1 && b >= 1 && c >= 1 && a <= 100 && b <= 100 && c <= 100)
	{
		goto ass;
	}
	else { return 0; }
	ass : if (more > c)
	{
		printf("%d", c);

	}
	else
	{
		printf("%d", more);
	}
}

Measured memory_bytes: 128
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
int n,m;
const ll M=1000000007;

ll F[211111];
ll IF[211111];
 
ll invl(ll a,ll b,ll m){//ap-2乗るを返す
	ll tmp=1;
	
	while(b){
		if(b&1){
			tmp=(tmp*a)%m;
		}
		a=(a*a)%m;
		b/=2;
	}
 
	return tmp%m;
}
 
void pow(ll m){
	F[0]=1;
	IF[0]=1;
 
	for(ll i=1;i<=210000;i++){
		F[i]=(F[i-1]*i)%m;
		IF[i]=invl(F[i],m-2,m)%m;//逆元を、フェルマーの小定理を利用して求める
	}
}
 
ll C(ll n,ll r,ll m){
 
	if(n<0||r<0||r>n)return (ll)0;
	if(r>n/2)r=n-r;
	
	//cout<<F[n]<<" "<<IF[r]<<" "<<IF[n-r]<<endl;
	ll ret=F[n]*IF[r]%m*IF[n-r]%m;
	return ret;
}

ll t[211111];
ll h,w,a,b;

int main(){
	pow(M);
	cin>>h>>w>>a>>b;
	
	for(int i=0;i<w;i++){
		ll k=h-a-1;//縦に進む回数
		ll ret=C(k+i,k,M);
		//cout<<ret<<" ";
		t[i]=(ret+M)%M;
	}

	for(int i=b;i<w;i++){
		ll k=a;
		ll ret=(C(k+w-i-1-1,k-1,M)+M)%M;

		t[i]=(t[i]*ret+M)%M;
	}


	ll ans=t[b];
	for(int i=b+1;i<w;i++)ans=(ans%M+t[i]%M+M)%M;
	cout<<ans<<endl;
}



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

const ll mod = 1e9 + 7;
const int Inf = 1e9 + 5;
vector<int> phi;

void phi_1_to_n(int n) {
    phi[0] = 0;
    phi[1] = 1;
    for (int i = 2; i <= n; i++)
        phi[i] = i - 1;

    for (int i = 2; i <= n; i++)
        for (int j = 2 * i; j <= n; j += i)
              phi[j] -= phi[i];
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    ll n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n + 1), b(m + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= m; i++) {
        cin >> b[i];
    }
    vector<ll> sum1(n + 1), sum2(m + 1);
    for (int i = 1; i <= n; i++) {
        sum1[i] = sum1[i - 1] + a[i];
    }
    for (int i = 1; i <= m; i++) {
        sum2[i] = sum2[i - 1] + b[i];
    }
    int p1 = 0, p2 = 0;
    for (int i = n; i > 0; i--) {
        if (sum1[i] <= k) {
            p1 = i;
            break;
        }
    }
    int ans = 0;
    while (p1 >= 0 && p2 >= 0) {
            while (p2 <= m && sum1[p1] + sum2[p2] <= k) {
                ans = max(ans, p1 + p2);
                p2++;
            }
            p1--;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 7920
let firstLine = readLine()!.split(separator: " ")
let N = Int(firstLine[0])!
let K = Int(firstLine[1])!

var hashSet = Set<Int>()
for i in 1...N {
  hashSet.insert(i)
}

for i in 0..<K {
  _ = readLine()!
  readLine()!.split(separator: " ").forEach { s in 
    hashSet.remove(Int(s)!)
  }
}
print(hashSet.count)

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

using namespace std;

int main()
{
    int t;
    bool flag = false;
    cin >> t;
    while (t)
    {
        if (t % 10 == 7)
            flag = true;
        t /= 10;
    }
    cout << (flag ? "Yes\n" : "No\n");
}


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

int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  if (a < 10 and b < 10) {
    printf("%d\n", a * b);
  }
  else {
  	puts("-1"); 
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

MOD = 1000000007

dic = {}
dic[0] = 3
for i in range(1,n+1):
    dic[i] = 0

ans = 1
for i in range(n):
    ans = ans * dic[a[i]] % MOD
    dic[a[i]] -= 1
    dic[a[i] + 1] += 1

print(ans)

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

using namespace std;

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

  int count = 0;
  if(s[0] == s[1]) count++;
  if(s[0] == s[2]) count++;
  if(s[0] == s[3]) count++;
  if(s[1] == s[2]) count++;
  if(s[1] == s[3]) count++;
  if(s[2] == s[3]) count++;

  if(count == 2) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,m,i,leap=0;
    double cnt,a[110]={};
    while(~scanf("%d%d",&n,&m))
    {
        double sum=0;
        int ans=0;
        for(i=0;i<n;i++)
        {
            scanf("%lf",&a[i]);
            sum+=a[i];
        }
        cnt=sum/4.0/m*1.0;
        for(i=0;i<n;i++)
        {
            if(a[i]>=cnt)
                ans++;
            if(ans==m)
            {
                leap=1;
                break;
            }
        }
        if(leap)
            printf("Yes\n");
        else
            printf("No\n");
        leap=0;
    }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main()
{
	IOS;
	int n, k;
	cin >> n >> k;
	if(k == 1)
	{
		cout << 0;
		return 0;
	}
	int ans = n - k;
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int left = sc.nextInt()+sc.nextInt();
        int right = sc.nextInt()+sc.nextInt();
        if(left>right) System.out.println("Left");
        else if(right>left) System.out.println("Right");
        else System.out.println("Balanced");


    }
}


Measured memory_bytes: 21716
#include <stdio.h>

int main() {
	int a, b, k, n;

	scanf("%d%d%d", &a, &b, &k);
	for (n = a < b ? a : b; n > 0; n--)
		if (a % n == 0 && b % n == 0)
			if (--k == 0) {
				printf("%d\n", n);
				return 0;
			}
	return 0;
}


Measured memory_bytes: 128
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#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 <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

//~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

int main() {

    int N;
    cin >> N;

    vector<int> a(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
    }

    vector<int> ans;
    vector<int> b(N + 1, 0);
    for (int i = N; i >= 1; i--) {
        int sum = 0;
        for (int j = i; j <= N; j += i) {
            sum += b[j];
        }
        if ((sum + a[i]) % 2 == 1) {
            b[i]++;
            ans.push_back(i);
        }
    }

    reverse(ans.begin(), ans.end());

    cout << ans.size() << endl;
    for(auto x: ans) cout << x << " ";

}

































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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

struct Node { int x, y; };

int H, W, sx, sy, gx, gy;
string grid[1000];
vector< Node > nodes[5];
vector< int > dst[5];

int solve(int init_c) {
	for_(i,0,5) dst[i].assign(nodes[i].size(), (int)1e9);
	
	int sc = (init_c + 1) % 5;
	
	for_(i,0,(int)nodes[sc].size()) {
		dst[sc][i] = abs(sx - nodes[sc][i].x) + abs(sy - nodes[sc][i].y);
	}
		
	for_(i,1,4) {
		int c = (init_c + i) % 5;
		int nc = (c + 1) % 5;
		
		int A = nodes[c].size(), B = nodes[nc].size();
		
		for_(j,0,A) {
			int x1 = nodes[c][j].x;
			int y1 = nodes[c][j].y;
			
			for_(k,0,B) {
				int x2 = nodes[nc][k].x;
				int y2 = nodes[nc][k].y;
				
				dst[nc][k] = min(dst[nc][k], dst[c][j] + abs(x1 - x2) + abs(y1 - y2));
			}
		}
	}
	
	int gc = (init_c + 4) % 5;
	int res = (int)1e9, M = nodes[gc].size();
	
	for_(i,0,M) res = min(res, dst[gc][i] + abs(gx - nodes[gc][i].x) + abs(gy - nodes[gc][i].y));
	
	return res;
}

int main() {
	while (cin >> W >> H, W) {
		for_(i,0,5) nodes[i].clear();
		
		for_(i,0,H) {
			cin >> grid[i];
			
			for_(j,0,W) {
				if (grid[i][j] == 'S') { sx = j; sy = i; }
				else if (grid[i][j] == 'G') { gx = j; gy = i; }
				else if (grid[i][j] != '.') nodes[grid[i][j] - '1'].push_back(Node{j, i});
			}
		}
		
		int ansc = 0, mini = (int)1e9;
		
		for_(i,0,5) {
			int res = solve(i);
			
			if (mini > res) {
				mini = res;
				ansc = i;
			}
		}
		
		if (mini < (int)1e9) cout << ansc + 1 << " " << mini << endl;
		else cout << "NA" << endl;
	}
}

Measured memory_bytes: 2352
#include<stdio.h>
int main()

{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a+b<=a+c){
        if(a+b<b+c){
            printf("%d\n",a+b);
        }
        else{
            printf("%d\n",b+c);
        }
    }
    else{
        if(a+c<=b+c){
            printf("%d\n",a+c);
        }
        else {
            printf("%d\n",b+c);
        }
    }
    return 0;
}


Measured memory_bytes: 128
n = int(input())
arr = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

result = set()
for i in range(2**n):
    tmp = 0
    for j in range(n):
        if i >> j & 1:
            tmp += arr[j]
    result.add(tmp)

for x in m:
    print("yes" if x in result else "no")


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

N,M,X = map(int,input().rstrip().split())
C = []
A = []
for i in range(N):
    c, *a = [int(i) for i in input().rstrip().split()]
    C.append(c)
    A.append(a)

ans = 10**18
for i in range(2**N):
    d = [0]*M
    cst = 0
    for j in range(N):
        if (i>>j&1):
            cst += C[j]
            for s in range(M):
                d[s] += A[j][s]

    for j in d:
        if j < X:
            break
    else:
        ans = min(ans,cst)

if(ans == 10**18):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9244
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define watch(x) cout << (#x) << " is: " << (x) << endl
#define vw(v)                        \
    cout << endl                     \
         << endl                     \
         << (#v) << " is: " << endl; \
    for (ll B : (v))                 \
    {                                \
        cout << B << " ";            \
    }                                \
    cout << endl
#define check(x) cout << "here " << (x) << "?" << endl
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a) for (long long i = (a - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rv(x) (x).rbegin(), (x).rend()
#define pb push_back
typedef long long ll;
ll const MAX = 2147483647, REALMAX = 9223372036854775806;
// ll const N = ;

int main()
{
    FAST_IO
    char c;
    cin >> c;
    cout << char(c + 1);
}

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

const ll INF = 1001001001;

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

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

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

char s[1005][1005];
int dx[4] = {0,0,-1,1};
int dy[4] = {1,-1,0,0};
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int h,w;
    cin >> h >> w;
    queue<pair<int,int>> q;
    rep(i,h)rep(j,w){
        cin >> s[i][j];
        if(s[i][j]=='#')q.push({i,j});
    }
    int ans = 0;
    bool f = 1;
    while(f){
        f = 0;
        queue<pair<int,int>> q2;
        while(!q.empty()){
            auto x = q.front();q.pop();
            rep(i,4){
                int nx = x.first + dx[i];
                int ny = x.second+ dy[i];
                if(nx<0 || ny<0 || nx>=h || ny>=w)continue;
                if(s[nx][ny]=='.'){
                    f = 1;
                    s[nx][ny] = '#';
                    q2.push({nx,ny});
                }
            }
        }
        if(f)ans++;
        q = q2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9600
import heapq

n,m=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
arr2=[[i,0] for i in range(1,m+2)]
arr.extend(arr2)
arr=sorted(arr,key=lambda x:x[0])
q=[]
ans=0
pos=0
while 1:
  a,b=arr[pos]
  if a>m:
    break
  if a==arr[pos+1][0]:
    heapq.heappush(q,-b)
  else:
    heapq.heappush(q,-b)
    ans-=heapq.heappop(q)
  pos+=1
print(ans)

Measured memory_bytes: 43664
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int n;
    cin>>n;
    vector<string>a(n);

    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        a.at(i)=s;
    }
    sort(a.begin(),a.end());
    a.push_back("ZZZZZZZZZZZZ");
    ll ans=0;
    for(ll i=0;i<n+1;i++){
        for(ll j=i+1;j<n+1;j++){
            if(a.at(i)!=a.at(j)){
                ans=ans+(j-i-1)*(j-i)/2;
                i=j-1;
                break;
            }
            // cout<<"i"<<i<<" j"<<j<<endl;
        }
        // cout<<"i"<<i<<endl;
    }
    // cout<<a.at(0)<<endl;
    // cout<<a.at(1)<<endl;
    // cout<<a.at(2)<<endl;
    // cout<<"---------"<<endl;
    // for(int i=0;i<n;i++){
    //     cout<<a.at(i)<<endl;
    // }



    cout<<ans<<endl;



    return 0;
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

const int maxN = 1e5 + 5;
bool isStayed[maxN];
int btn[maxN];

signed main() {
  int n = read();
  REP(i, n) btn[i + 1] = read();
  int ans = 0;
  int now = 1;
  while (!isStayed[now]) {
    if (now == 2) {
      print(ans);
      return 0;
    }
    isStayed[now] = true;
    now = btn[now];
    ans++;
  }
  print(-1);
}


Measured memory_bytes: 1152
const main = (input) => {
  const lines = input.trim().split("\n");
  const N = parseInt(lines[0]);
  const countMap = new Map();

  let maxCount = 0;
  lines.slice(1).forEach(S => {
    if (!countMap.has(S)) {
      countMap.set(S, 1);
    } else {
      countMap.set(S, countMap.get(S) + 1)
    }
    maxCount = Math.max(countMap.get(S), maxCount);
  });

  const answer = Array.from(countMap).filter(entry => entry[1] === maxCount).map(entry => entry[0]).sort();
  console.log(answer.join('\n'));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 91080
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[]={1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  int x, y;
  cin >> x >> y;
  if(a[x-1]==a[y-1]) cout << "Yes" << endl;
  else cout << "No" <<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pi 3.141592653589
 
ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll power(ll b,ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    if(n==1)
        cout<<"0";
    else
        cout<<"1";
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    int n;
    cin >> n;
    vector<int> t(n),a(n);
    rep(i,n) cin >> t[i];
    rep(i,n) cin >> a[i];
    vector<int> dec(n,-1),under(n,INF);
    dec[0] = t[0];
    int now = t[0];
    for(int i=1;i<n;i++){
        if(now < t[i]){
            dec[i] = t[i];
            now = t[i];
        }else{
            under[i] = now;
        }
    }

    if(dec[n-1]==-1){
        if(under[n-1]<a[n-1]){
            cout << 0 << endl;
            return 0;
        }
    }else{
        if(dec[n-1]!=a[n-1]){
            cout << 0 << endl;
            return 0;
        }
    }

    dec[n-1]=a[n-1];
    now = a[n-1];
    for(int i=n-2;i>=0;i--){
        if(now < a[i]){
            if(dec[i]!=-1&&dec[i]!=a[i]){ cout << 0 << endl;return 0;}
            if(dec[i]==-1&&under[i]<a[i]){ cout << 0 << endl;return 0;}
            dec[i] = a[i];
            now = a[i];
        }else{
            if(dec[i]!=-1&&dec[i]>now){ cout << 0 << endl;return 0;}
            under[i] = min(now,under[i]);
        }
    }
    ll ans = 1;
    rep(i,n){
        if(dec[i]==-1){
            ans = (ans * (ll)under[i]) % MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4800
Q = int(input())
numberlist = [0 for i in range(100001)]
prime = [2]

for i in range(3, 100001, 2):
    flag = 1
    for j in prime:
        if i % j == 0:
            flag = 0
            break
    if flag == 1:
        prime.append(i)

for i in prime:
    if (i+1)//2 in prime:
        numberlist[i] += 1
for i in range(100000):
    numberlist[i+1] += numberlist[i]


for i in range(Q):
    l, r = map(int, input().split())
    print(numberlist[r]-numberlist[l-1])


Measured memory_bytes: 53936
n = int(input())
a = list(map(int, input().split()))

result = []

for i in range(2):
    num = 0
    r = 0
    for j in range(len(a)):
        num += a[j]
        if (j + i) % 2 == 0:
            if num <= 0:
                r -= num - 1
                num = 1

        else:
            if num >= 0:
                r += num + 1
                num = -1

    result.append(r)

print(min(result))


Measured memory_bytes: 14332
s=input()
l=len(s)-1
res = 0

for i in range(2**l):
    s_new = s[0]
    for j, c in enumerate(s[1:]):
        flag = True if (i>>j)%2==1 else False
        s_new += c if flag else "+"+c
    res += eval(s_new)
print(res)


Measured memory_bytes: 3060
N, W = map(int, input().split())
# dp[m][w] mまで使ってwを超えない価値の最大値
dp = [[0] * (W + 100) for _ in range(N + 10)]

for i in range(N):
    w, v = map(int, input().split())
    for j in range(W + 1):
        if j - w >= 0:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - w] + v)
        else:
            dp[i + 1][j] = dp[i][j]
# print(dp)
print(dp[N][W])

Measured memory_bytes: 121240
#include <cstdio>

int main()
{
  int a, b, c;

  scanf("%d %d %d", &a, &b, &c);

  if (a < b) {
    if (b < c) {
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");
  return 0;
}


Measured memory_bytes: 2628
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, p[100005], a[100005], b[100005];
const int t = 30000;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    rep(i, 0, n) cin >> p[i];
    a[0] = b[n] = 1;
    rep(i, 0, n) a[i+1] = a[i] + 40000;
    eper(i, n, 1) b[i-1] = b[i] + 40000;
    rep(i, 0, n) a[p[i]-1] += i+1;
    rep(i, 0, n) cout << a[i] << (i == n-1 ? "\n" : " ");
    rep(i, 0, n) cout << b[i] << (i == n - 1 ? "\n" : " ");
    return 0;
}

Measured memory_bytes: 896
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
point = 0
for i in range(N):
    A[i] -= 1
    point += B[A[i]]
    if i > 0 and A[i - 1] + 1 == A[i]:
        point += C[A[i - 1]]
 
print(point)


Measured memory_bytes: 3064
import sys

n, x = [int(_) for _ in input().split()]
l = [int(_) for _ in input().split()]

l.sort()

for i in range(len(l)):
    if i == 0:
        continue
    else:
        l[i] = l[i-1] + l[i]

if x < l[0]:
    print(0)
    sys.exit()

for i in range(0, len(l)):
    if i != len(l)-1:
        if l[i] <= x < l[i+1]:
            print(i+1)
            sys.exit()
    else:
        if x == l[i]:
            print(i+1)
        else:
            print(i)



Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=200010;
int a[N],b[N],top,n;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++){
		if(a[i]==0){
			if(a[top]==0&&top!=0)b[top]++;
			else b[++top]=1,a[top]=0;
		}
		else a[++top]=a[i];
	}
	LL ans=0;
	for(int i=1;i<=top;i++){
		if(a[i]==0)ans+=(LL)b[i]*(b[i]+1)/2;
		else ans++;
	}
	n=top;
	for(int i=1;i<=n;i++){
		int sum=0,xr=0;
		for(int j=i;j<=min(i+50,n);j++){
			sum+=a[j],xr^=a[j];
			if(sum==xr&&i!=j){
				LL ret=1;
				if(a[i]==0)ret*=b[i];
				if(a[j]==0)ret*=b[j];
				ans+=ret;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1664
import bisect
n1 = int(input())
S = list(map(int, input().split()))
n2 = int(input())
T = list(map(int, input().split()))

count = 0
for t in T:
  idx = bisect.bisect_left(S, t)
  if idx < n1 and S[idx] == t:
    count += 1

print(count)


Measured memory_bytes: 16736
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,n=0;
  cin >> a >> b;
  for(a;a<=b;a++){
    if((a/10000==a%10)&&(a%10000/1000==a%100/10))
      n++;
    else
      continue;
  }
  cout << n << endl;
}

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


int ng;
int g[20][10];
int pre[1<<18][10];
int x, y, z;

void initG()
{
	memset(g, -1, sizeof(g));
	memset(pre, -1, sizeof(pre));
	ng = x + y + z;
	for (int i = 0; i < x; i++)
	for (int j = 1; j <= x - i; j++)
		g[i][j] = i+j;
	
	for (int i = x; i < x+y; i++)
	for (int j = 1; j <= y - (i - x); j++)
		g[i][j] = i+j;

	for (int i = x+y; i < x+y+z; i++)
	for (int j = 1; j <= z - (i - x - y); j++)
		g[i][j] = i+j;
	for (int i = 1; i <= 10; i++)
		g[x+y+z][i] = x + y + z;
}

int getMsk(int msk, int x)
{
	if (pre[msk][x] != -1)
		return pre[msk][x];
	int res = 0;
	for (int i = 0; i < ng; i++)
		if (msk & (1<<i))
		{
			if (g[i+1][x] != -1)
				res |= (1<<(g[i+1][x] - 1));
		}
	if (g[0][x] != -1)
		res |= (1<<(g[0][x] - 1));
	return pre[msk][x] = res;
}

int n;
int dp[45][1<<17];

int sol(int i, int msk)
{
	if (i == n)
	{
		if (msk & (1<<(x + y + z - 1)))
			return 1;
		return 0;
	}
	if (dp[i][msk] != -1)
		return dp[i][msk];
	dp[i][msk] = 0;
	for (int j = 1; j <= 10; j++)
	{
		dp[i][msk] += sol(i+1, getMsk(msk, j));
		dp[i][msk] %= 1000000007;
	}
	return dp[i][msk];
}

int main()
{
	scanf("%d %d %d %d", &n, &x, &y, &z);
	memset(dp, -1, sizeof(dp));
	initG();
	printf("%d\n", sol(0, 0));
}

Measured memory_bytes: 33536
/*input
1
1

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
 
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int a, b, c;
  cin >> a >> b >> c;
  a -= b;
  int ans = max(0, c - a);
  cout << ans << endl;
 
  return 0;
}

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

const int mod = 1e9 + 7;
using ll = unsigned long long;

int main() {
	int n, m;
	cin >> n >> m;
	vector<bool> oks(n + 1, true);
	for (int i = 0; i < m; i++) {
		int a;
		cin >> a;
		oks[a] = false;
	}

	vector<ll> dp(n + 1, 0);
	dp[0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j <= min(n, i + 2); j++) {
			if (oks[j]) {
				dp[j] += dp[i];
				dp[j] %= mod;
			}
		}
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from itertools import *
INF = 10**10

N, M = map(int, input().split())
h = [-int(x) for x in input().split()]
heapify(h)
for i in range(M):
    x = -heappop(h)//2
    heappush(h, -x)
print(-sum(h))


Measured memory_bytes: 68224
import java.util.*;

public class Main{

	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			boolean [][] s = new boolean[21][21];
			for(int i = 0; i < n; i++){
				int xx = sc.nextInt();
				int yy = sc.nextInt();
				s[yy][xx] = true;
			}
			int m = sc.nextInt();
			int x = 10,  y = 10;
			int count = 0;
			for(int i = 0; i < m; i++){
				char c = sc.next().charAt(0);
				int len = sc.nextInt();
				for(int j = 0; j < len; j++){
					if(c == 'N'){
						y++;
					}
					else if(c == 'S'){
						y--;
					}
					else if(c == 'E'){
						x++;
					}
					else{
						x--;
					}
					if(s[y][x]){
						s[y][x] = false;
						count++;
					}
				}
			}
			if(count == n){
				System.out.println("Yes");
			}
			else{
				System.out.println("No");
			}

		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 36400
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n,k; cin >> n >> k; vl num(n);
  rep(i,k){
    ll d; cin >> d;
    rep(j,d){
      ll x; cin >> x; x--;
      num[x]++;
    }
  }
  
  cout << count(all(num),0) << endl;
  
  
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int ll;
typedef vector<int > vecint;
typedef vector<string > vecstr;
int main()
{
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;

  for(int i = 1; i < n - 1; i++){
    // cout << i << endl;
    string t, u;
    map<char,int> a, b;
    int tmpans = 0;
    t = s.substr(0,i);
    u = s.substr(i,n - i);
    REP(j, t.size()){
      a[t[j]]++;
    }
    REP(j, u.size()){
      if(a.count(u[j]) > 0&&b.count(u[j]) == 0){
	tmpans ++;
	b[u[j]] ++;
      }
    }
    ans = max(tmpans, ans);
  }
  cout << ans << endl;
}


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

int main(){
    //input
    int a, b, c; cin >> a >> b >> c;
 
    int mx = max({a, b, c});
 
    int diff = mx - a + mx - b + mx - c;
 
    int ans = 0;
    if (diff % 2 == 0) {
        ans = diff / 2;
    } else {
        ans = diff / 2 + 2;
    }
 
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

void solve() {
    int h, w;
    cin >> h >> w;
    char c[h][w];
    rep(i, h) rep(j, w) cin >> c[i][j];

    int dp[h + 2][w + 2];
    rep(i, h + 2) rep(j, w + 2) dp[i][j] = 0;
    dp[0][0] = 1;
    rep(i, h) rep(j, w) {
      if (c[i][j] == '#') continue;
      add(dp[i + 1][j], dp[i][j]);
      add(dp[i][j + 1], dp[i][j]);
    }
    cout << dp[h - 1][w - 1] << endl;
    // rep(i, h + 1) { rep(j, w + 1) cout << dp[i][j] << " "; cout << endl; }
}


Measured memory_bytes: 5120
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
#include<climits>
using namespace std;
inline int read(){
	int f=1,ans=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return f*ans;
}
queue<int> que;
const int MAXN=401;
const int MAXP=10000001;
struct node{
	int u,v,w,nex;
}x[MAXN*MAXN<<1];
int head[MAXN],cnt,dis[MAXN],vis[MAXN],S,T,INF=INT_MAX;
void add(int u,int v,int w){
	x[cnt].u=u,x[cnt].v=v,x[cnt].w=w,x[cnt].nex=head[u],head[u]=cnt++;swap(u,v),w=0;
	x[cnt].u=u,x[cnt].v=v,x[cnt].w=w,x[cnt].nex=head[u],head[u]=cnt++;
}
bool bfs(){
	memset(dis,127/3,sizeof(dis)),memset(vis,0,sizeof(vis));
	int inf=dis[0];dis[S]=0;
	que.push(S);
	while(!que.empty()){
		int xx=que.front();que.pop();
		vis[xx]=0;
		for(int i=head[xx];i!=-1;i=x[i].nex){
			if(x[i].w&&dis[x[i].v]>dis[xx]+1){
				dis[x[i].v]=dis[xx]+1;
				if(!vis[x[i].v]) vis[x[i].v]=1,que.push(x[i].v);
			}
		}
	}return dis[T]!=inf;
}
int dfs(int u,int flow){
	if(u==T) return flow;
	int used=0;
	for(int i=head[u];i!=-1;i=x[i].nex){
		if(x[i].w&&dis[x[i].v]==dis[u]+1){
			int slow=dfs(x[i].v,min(flow-used,x[i].w));used+=slow;
			x[i].w-=slow,x[i^1].w+=slow;
			if(used==flow) break;
		}
	}if(!used) dis[u]=-1;
	return used;
}
int dinic(){
	int Ans=0;
	while(bfs()) Ans+=dfs(S,INF);
	return Ans;
}
int n,g[MAXP],col[MAXP],Maxn,v[MAXP],prime[MAXP];
void Get(){
	for(int i=2;i<MAXP;i++){
		if(!v[i]){
			v[i]=i;
			prime[++prime[0]]=i;
		}
		for(int j=1;prime[j]*i<MAXP&&j<=prime[0];j++){
			v[i*prime[j]]=prime[j];
			if(i%prime[j]==0) break;
		}
	}return;
}
int Ls[MAXP],Rs[MAXP],Ans;
int main(){
//	freopen("1.in","r",stdin);
	memset(head,-1,sizeof(head));
	Get();
	n=read();
	for(int i=1;i<=n;i++){
		int ps=read();
		Maxn=max(Maxn,ps+1);col[ps]=1;
	}
	Maxn++;
	for(int i=1;i<=Maxn;i++){
		g[i]=col[i]^col[i-1];
		if(g[i]&1){
			if(i&1) Ls[++Ls[0]]=i;
			else Rs[++Rs[0]]=i;
		}
	}
	S=0,T=Ls[0]+Rs[0]+1;
	for(int i=1;i<=Ls[0];i++) add(S,i,1);
	for(int i=1;i<=Rs[0];i++) add(i+Ls[0],T,1);
	for(int i=1;i<=Ls[0];i++)
		for(int j=1;j<=Rs[0];j++){
			if(v[abs(Ls[i]-Rs[j])]==abs(Ls[i]-Rs[j])) add(i,Ls[0]+j,1);
		}
	int ans=dinic();
	Ans+=ans;
	Ls[0]-=ans,Rs[0]-=ans;
	Ans+=((Ls[0]/2)*2)+((Rs[0]/2)*2);
	Ls[0]&=1,Rs[0]&=1;
	if(Ls[0]+Rs[0]) Ans+=3;
	printf("%d\n",Ans);return 0;
}


Measured memory_bytes: 125312
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

int main(){
    ll n, m, q;
    cin >> n >> m >> q;
    
    //l, r を二次元座標と捉える
    //cnt[i][j] : 座標i, jより左下の範囲の座標に位置する列車の数
    ll cnt[555][555] = {};
    rep(i, m){
        ll l, r;
        cin >> l >> r;
        cnt[l][r]++;
    }

    for(ll i = 1; i <= n; ++i){
        for(ll j = 1; j <= n; ++j){
            cnt[i][j] += cnt[i][j-1]; 
        }
    }
    
    for(ll i = 1; i <= n; ++i){
        for(ll j = 1; j <= n; ++j){
            cnt[i][j] += cnt[i-1][j]; 
        }
    }

    ll ans[q] = {};
    rep(i, q){
        ll a, b;
        cin >> a >> b;
        ans[i] =  cnt[b][b] + cnt[a-1][a-1] - cnt[a-1][b] - cnt[b][a-1];
    }

    rep(i, q)cout << ans[i] << endl;

}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n , k , INF = 1e9+5;
    cin >> n >> k;
    vector<int> h(n+1);
    for(int i = 1 ; i <= n ; i++) cin >> h[i];
    // vector<int > h(n);
    // for(int &i : h) cin >> i;

    vector<int> dp(n+1,INF);
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);
    for(int i = 3 ; i<=n ; i++)
        for(int j = 1; j <= k && i-j >= 1; j++) 
            dp[i] = min( dp[i] , dp[i-j] + abs(h[i] - h[i-j]));
    
    cout <<dp[n];


    return 0;
}

Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const ll mod=1000000007;

struct PrimeFact {
    vector<ll> spf;
    PrimeFact(ll N) { init(N); }
    void init(ll N) {
        spf.assign(N + 1, 0);
        for (ll i = 0; i <= N; i++) spf[i] = i;
        for (ll i = 2; i * i <= N; i++) {
            if (spf[i] == i) {
                for (ll j = i * i; j <= N; j += i) {
                    if (spf[j] == j) {
                        spf[j] = i;
                    }
                }
            }
        }
    }
    ll get(ll n) {
        map<ll, ll> m;
        while (n != 1) {
            m[spf[n]]++;
            n /= spf[n];
        }
        ll kosuu=1;
        for(auto itr=m.begin();itr!=m.end();itr++){
		kosuu*=(1+itr->second);
	    }
    return kosuu;
    }
};

int main(void){
    ll x;
    cin>>x;
    PrimeFact pp(x);
    pp.init(x);
    ll ans=0;
    for(ll i=1;i<=x;i++){
        ans+=i*pp.get(i);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 81380
#include <bits/stdc++.h>
using namespace std;
 
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

const int N = 2e5+10;
const int inf = 1e14;

int seg[4*N];
int lazy[4*N];
 
void build(int node,int ss,int se)
{
    seg[node] = 0;
    lazy[node] = -1;
    
    if(ss == se) return;  
    
    int mid = (ss+se)/2;
    
    build(node*2+1,ss,mid);
    build(node*2+2,mid+1,se);
}
 
void push(int node,int ss,int se)
{
    if(lazy[node] == -1) return;
    
    seg[node] = lazy[node];
        
    if(ss != se)
    {
       int mid = (ss + se)/2;
        
       lazy[node*2+1] = lazy[node];
       lazy[node*2+2] = lazy[node] + (mid - ss + 1);
    }
    
    lazy[node] = -1;
}
 
void update(int node,int ss,int se,int l,int r,int a)
{
   push(node,ss,se);
    
   if(l > se || r < ss) return;
    
   if(l <= ss && se <= r)
   {
       lazy[node] = ss - l + a;
       push(node,ss,se);
       return;
   }
    
   int mid = (ss+se)/2;
    
   update(node*2+1,ss,mid,l,r,a);
   update(node*2+2,mid+1,se,l,r,a);
 
   seg[node] = min(seg[node*2+1],seg[node*2+2]);  
}
 
int query(int node,int ss,int se,int l,int r)
{
   push(node,ss,se);
   
   if(l > se || r < ss) return inf;
 
   if(l <= ss && se <= r) return seg[node];
    
   int mid = (ss+se)/2;
    
   return min(query(node*2+1,ss,mid,l,r),query(node*2+2,mid+1,se,l,r));
}
 
signed main()
{
    fast;
    
    int n,m;
    cin >> n >> m;
    
    pii a[n];
    f(i,n) cin >> a[i].F >> a[i].S;
    f(i,n) a[i].F--,a[i].S--;
    
    build(0,0,m-1);
    
    f(i,n)
    {
        int val = query(0,0,m-1,a[i].F-1,a[i].F-1);
        
        update(0,0,m-1,a[i].F,a[i].S,val+1);
        
        int ans = seg[0] + i + 1;
        
        if(ans >= inf) ans = -1;
        
        cout << ans << '\n';
    }
}

Measured memory_bytes: 14968
#include <string>
#include <stdlib.h>
#include <iostream>
#include <math.h>

#define BUFSIZE 10
using namespace std;

int main(void){
    int c;
    char buf[BUFSIZE];
    cin >> buf;
    int times = atoi(buf);

    for(int i = 0; i < times; i++){
      cin >> buf;
      int hr, mn;
      double shrt, lng;
      buf[2] = '\0';
      hr = atoi(buf);
      mn = atoi(&buf[3]);
      shrt = hr * 30.0 + mn * 0.5;
      lng = mn * 6.0;
      double deg = fabs(lng - shrt);
      deg = (deg >180) ? (360-deg) : deg;
      if(deg < 30) cout << "alert" << endl;
      else if(deg < 90) cout << "warning" << endl;
      else cout << "safe" << endl;
    }
    return 0;
}

Measured memory_bytes: 1140
#include <bits/stdc++.h>
#define inf 1000000005
#define tam 100005

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> dl;
typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <vi> graph;

bool comp(ll a, ll b) {
	return a > b;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
 
    string s;
    cin >> s;
    if (s == "ABC") cout << "ARC\n";
    else cout << "ABC\n";
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
	return 0;
}

Measured memory_bytes: 3648