akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

struct mint {

  ll x; 

  mint(ll x=0):x((x%mod+mod)%mod){} //コンストラクタを呼んで自動的にmodを取っている。

  mint operator-() const { return mint(-x);}

  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    //メンバ関数にはthisポインタがある。メンバ変数の値を返す。
    return *this;
  }

  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }

  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }

  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }

  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }

  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }

  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1); //a=x/2
    a *= a; //繰り返し二乗法
    if (t&1) a *= *this; //tが奇数のときはxを1回かける
    return a;
  }



  // for prime mod

  mint inv() const {
    return pow(mod-2);
  }

  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }

  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
    
};

struct combination{
  vector<mint> fact, ifact; //ifactはinverse factorial
  combination(ll n):fact(n+1), ifact(n+1){
    assert(n<mod);
    fact[0]=1;
    for(ll i=1;i<=n;i++) fact[i]=fact[i-1]*i;
    ifact[n]=fact[n].inv();
    for(ll i=n;i>=1;--i) ifact[i-1]=ifact[i]*i; // 1/(i-1)!=(1/i!)*i
  }
  mint operator()(ll n,ll k){
    if(k<0 || k>n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main()
{
    ll n,m;
    cin >> n >> m;
    map<ll,ll> h;
    for(ll i=2;i*i<=m;i++){
        ll cnt=0;
        while(m%i==0){
            m/=i;
            cnt++;
        }
        if(cnt){
            h[i]=cnt;
        }
    }
    if(m!=1){
        h[m]=1;
    }
    mint ans=1;
    combination c=combination(200000);
    for(auto x:h){
        ans*=c(n-1+x.se,x.se);
    }
    cout << ans.x << endl;
    
    return 0;
} 

Measured memory_bytes: 3328
N=int(input())
A=list(map(int,input().split()))
p=1000000007


R=[0]
G=[0]
B=[0]

#print(A)
ans=1
for i in range(N):
    tmp=0
    if A[i]==R[-1]:
        tmp+=1
    if A[i]==G[-1]:
        tmp+=1
    if A[i]==B[-1]:
        tmp+=1
    ans = (ans*tmp)%p

    if A[i]==R[-1]:
        R.append(R[-1]+1)
        G.append(G[-1])
        B.append(B[-1])
    elif A[i]==G[-1]:
        R.append(R[-1])
        G.append(G[-1]+1)
        B.append(B[-1])
    else:
        R.append(R[-1])
        G.append(G[-1])
        B.append(B[-1]+1)
    
#print(R)
#print(G)
#print(B)
print(ans)

Measured memory_bytes: 14564
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

k,n=nm()
a=nl()

mx = k+a[0]-a[-1]

for i in range(n-1):
  mx = max(mx, a[i+1]-a[i])
print(k-mx)

Measured memory_bytes: 26444
#include<stdio.h>

#define N 3

void Insert_Sort(int *data);

int main(void)
{
	int i,data[N];
	char c;
	
	for(i=0;i<N;i++){
		scanf("%d",&data[i]);
		c=getchar();
	}
	
	Insert_Sort(data);
	
	for(i=0;i<N;i++){
		printf("%d",data[i]);
		if(i!=N-1){
			printf(" ");
		}
	}
	printf("\n");
	
	return 0;
}

void Insert_Sort(int *data)
{
	int i,x,t;
	
	for(i=1;i<N;i++){
		t=i;
		x=data[i];
		while(x<data[t-1] && t>0){
			data[t]=data[t-1];
			t--;
		}
		data[t]=x;
	}
}


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

#define vi vector<int>
#define vvi vector<vi>

const int INF = 1e9 + 5;

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

    string a,b;

    cin >> a >> b;

    if(b.substr(0,b.length() -1) == a){
        cout << "Yes";
    }else{
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 3616
N,M = map(int,input().split())
Height = list(map(int,input().split()))
MichiList = []
cnt = 0
for _ in range(M):
    li = list(map(int,input().split()))
    MichiList.append(li)
IkeruList = []
for _ in range(N):
    IkeruList.append([])
for i in MichiList:
    a = i[0]
    b = i[1]
    IkeruList[a-1].append(Height[b-1])
    IkeruList[b-1].append(Height[a-1])
for i in range(N):
    if len(IkeruList[i]) == 0:
        cnt += 1
    else:
        if Height[i] > max(IkeruList[i]):
            cnt += 1
print(cnt)

Measured memory_bytes: 41484
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long modpow(long long a, long long b){
	a %= MOD;
	long long res = 1;
	while (b > 0){
		if (b % 2 == 1) res = res * a % MOD;
		a = a * a % MOD;
		b = b / 2;
	}
	return res;
}
int main(){
  int N;
  cin >> N;
  map<pair<long long, long long>, pair<int, int>> mp;
  int zero = 0;
  for (int i = 0; i < N; i++){
    long long A, B;
    cin >> A >> B;
    if (A == 0 && B == 0){
      zero++;
    } else {
      long long d = gcd(A, B);
      A /= d;
      B /= d;
      if (B < 0){
        A *= -1;
        B *= -1;
      }
      //cout << "A = " << A << ", B = " << B << endl;
      if (mp.count(make_pair(A, B))){
        mp[make_pair(A, B)].first++;
      } else if (mp.count(make_pair(-B, A))){
        mp[make_pair(-B, A)].second++;
      } else if (mp.count(make_pair(B, -A))){
        mp[make_pair(B, -A)].second++;
      } else {
        mp[make_pair(A, B)].first++;
      }
    }
  }
  vector<long long> cnt;
  for (auto P : mp){
    int c1 = P.second.first;
    int c2 = P.second.second;
    long long tmp = modpow(2, c1) + modpow(2, c2) - 1;
    cnt.push_back(tmp % MOD);
  }
  long long ans = 1;
  for (long long c : cnt){
    ans = ans * c % MOD;
    //cout << "c = " << c << endl;
  }
  ans += (MOD - 1);
  ans += zero;
  ans %= MOD;
  cout << ans << endl;
}

Measured memory_bytes: 17804
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000000

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

    ll n, k;
    cin >> n >> k;
    if(n%k){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
}



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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    vi a(5);
    rep(i,5)cin>>a[i];
    int k;cin>>k;
    int cnt=0;
    rep(i,4){
        for(int j=1;j<5;++j){
            if(abs(a[i]-a[j])>k)cnt++;
        }
    }
    if(cnt>0)cout<<":("<<endl;
    else cout<<"Yay!"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
signed main()
{   

      senky_bansal
      IIIT_ALLAHABAD

      string s;
      ll k;
      cin>>s>>k;
      set<char>st;
      for(int i=0;i<s.size();i++)
      {
          st.insert(s[i]);
      }
      ll ans=0;
      ll p = s.size();
      if(st.size()==1)
      {
          cout<<k*s.size()/2;
          return 0;
      }
      if(s[0]!=s[p-1])
      {
          ll cur=1;
          for(int i=0;i<p-1;i++)
          {
              if(s[i]==s[i+1]) cur++;
              else {ans+=cur/2; cur=1;}
          }
          ans+=cur/2;
          ans*=k;
          cout<<ans<<endl;
    //      cout<<ans<<endl;
      }
      else
      {
           ll fir=0;
           ll las=p-1;
           ll count1=0,count2=0;
           while(s[fir]==s[0])
           {
               fir++;
           }
           count1=fir;
           while(s[las]==s[0])
           {
                las--;
                count2++;
           }
           ll cur=1;
           for(int i=fir;i<las;i++)
           {
              if(s[i]==s[i+1]) cur++;
              else {ans+=cur/2; cur=1;}
           }
           ans+=cur/2;
           ans*=k;
           ans+=count1/2+count2/2+(count1+count2)/2*(k-1);
           cout<<ans<<endl;
      }

    

}






Measured memory_bytes: 256
n = gets.to_i
h = gets.split.map(&:to_i)
able = true

(n-1).times do |i|
    if h[i] < h[i+1]
        h[i+1] -= 1
    end
    
    if h[i] > h[i+1]
        able = false
        break
    end
end

puts able ? 'Yes' : 'No'

Measured memory_bytes: 8580
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		StringBuffer ioi = new StringBuffer();
		String ts;
		String rs;
	
		int count;
		int p;
		
		String n = scanner.nextLine();
		while (Integer.valueOf(n).intValue() != 0) {
			ioi.setLength(0);
			ioi.append("IOI");
			ts = scanner.nextLine();
			ts = scanner.nextLine();
			count = 0;
			
			for(int i = 1; i < Integer.valueOf(n).intValue(); i++) {
				ioi.append("OI");
			}
			rs = ioi.toString();
			
			p = ts.indexOf(rs, 0);
			while (p > -1) {
				count++;
				p = ts.indexOf(rs, p + 1);
			}
			
			System.out.println(count);
			
			n = scanner.nextLine();
		}
	}

}

Measured memory_bytes: 45164
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <bits/stdc++.h>

using namespace std;

bool isACGT (char c) {
  return (c == 'A' || c == 'C' || c == 'G' || c == 'T');
}

/**
 * main
 */
int main () {
  string S;
  cin >> S;

  int count = 0;
  int max_count = 0;
  for (char c : S) {
    if (isACGT(c)) {
      count++;
    } else  {
      max_count = max(max_count, count);
      count = 0;
    }
  }
  max_count = max(max_count, count);

  cout << max_count << '\n';
}


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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

int main(){
  int n;

  scanf("%d",&n);

  int a[n + 1];
  FOR (i, 1, n + 1) {
    scanf("%d",&a[i]);
  }

  int ans = 0;
  FOR (i, 1, n + 1) {
    if (a[a[i]] == i) ans++;
  }

  printf("%d\n",ans / 2);
}


Measured memory_bytes: 640
package main

import (
	"fmt"
)

func answer158A(s string) string {
	if s == "AAA" || s == "BBB" {
		return "No"
	} else {
		return "Yes"
	}
}

func main() {
	var s string
	fmt.Scan(&s)
	
	fmt.Println(answer158A(s))
}


Measured memory_bytes: 1768
N=int(input())
t_lst, x_lst, y_lst = [], [], []
for _ in range(N):
    buf = [int(_) for _ in input().split()]
    t_lst.append(buf[0])
    x_lst.append(buf[1])
    y_lst.append(buf[2])

t, x, y =0,  0, 0
isValid=True
for i in range(N):
    move = abs(x_lst[i] - x) + abs(y_lst[i] - y)
    step = t_lst[i] - t
    if move <= step and (step - move)%2 ==0:
            x = x_lst[i]
            y = y_lst[i]
            t = t_lst[i]
    else:
        isValid=False
        break
if isValid:
    print("Yes")
else:
    print("No")

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

int main() {
  int N;
  cin >> N;
  long long  ret = 0;
  map< string, int > mp;
  for(int i = 0; i < N; i++) {
    string x;
    cin >> x;
    sort(begin(x), end(x));
    ret += mp[x];
    mp[x]++;
  }
  cout << ret << endl;
}

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

#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,x,g;
    cin>>n>>x;
    ll a,b[n];
    for(int i=0;i<n;i++){
        cin>>a;
        b[i]=abs(x-a);
    }
    if(n==1){
        cout << b[0]<<endl;
    }
    else{
        g=__gcd(b[0],b[1]);
        for(int i=2;i<n;i++){
            g=__gcd(g,b[i]);
        }
        cout <<g<<endl;
    }

    return 0;
}


Measured memory_bytes: 1024
N,Y = map(int, input().split())

#10000*x + 5000*y + 1000*z = Y
#x+y+z = N

flag = False
for x in range(0,1+Y//10000):
  for y in range(0,1+(Y-10000*x)//5000):
    z=N-x-y
    if z==(Y-10000*x-5000*y)//1000:
      flag = True
      ans = [x,y,z]
      break
  else:
    continue
  break
if flag:
  print(ans[0], ans[1], ans[2])
else:
  print(-1, -1, -1)

Measured memory_bytes: 3064
N, T, A0, *A = map(int, open(0).read().split())

ma, mi = 0, A0
B = {}
for a in A:
    b = a - mi
    B[b] = B.get(b, 0) + 1
    ma, mi = max(ma, b), min(mi, a)

print(B[ma])

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

int md = 1000 * 1000 * 1000 + 7;

int h, w, dp[1003][1003];
string grid[1003];
int ans = 0;

int fn(int i, int j) {
    if (i == 0 && j == 0) return 0;
    if (i == 1 && j == 0) return 1;
    if (i == 0 && j == 1) return 1;
    if (~dp[i][j]) return dp[i][j];
    dp[i][j] = 0;
    if (i > 0 && grid[i - 1][j] == '.') dp[i][j] = (dp[i][j] + fn(i - 1, j)) % md;
    if (j > 0 && grid[i][j - 1] == '.') dp[i][j] = (dp[i][j] + fn(i, j - 1)) % md;
    return dp[i][j];
}

int main() {
    scanf("%d%d", &h, &w);
    for (int i = 0; i < h; ++i) {
            cin >> grid[i];
 
    }
    memset(dp, -1, sizeof dp);
    printf("%d\n", fn(h - 1, w - 1));
    return 0;
}

Measured memory_bytes: 5376
#include <stdio.h>

long long fact(long long n){
    if(n<=1) return 1;
    return (n*fact(n-1));
}

int main(){

    long long  i,n;

    while(scanf("%lld", &n)==1){

        printf("%lld\n", fact(n));
    }
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
const int maxn=305;
typedef long long ll;

int c[10][10];
int a[maxn][maxn];
int dp[maxn][maxn];
const int inf=0x3f3f3f3f;

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	int h,w;
	while(cin>>h>>w){
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				cin>>c[i][j];
				dp[i][j]=c[i][j];
			}
		}
		for(int k=0;k<10;k++){
			for(int i=0;i<10;i++){
				for(int j=0;j<10;j++){
					dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
				}
			}
		}
		int temp;
		int ans=0;
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				cin>>temp;
				if(temp!=1&&temp!=-1){
					ans+=dp[temp][1];
				}	
			}
		}
		cout<<ans<<endl;
	}	
	return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())

if H == 1 or W == 1:
    print(1)
elif H % 2 == 0 or W % 2 == 0:
    print(H * W // 2)
else:
    print((H + 1) * (W + 1) // 4 + (H - 1) * (W - 1) // 4)


Measured memory_bytes: 38384
import java.util.ArrayList;
import java.util.Scanner;

class Main{


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		ArrayList<Integer> data = new ArrayList<Integer>();
		for(int i = 2;i <= 55555;i++){
			boolean ok = true;
			for(int j = 2; j*j <= i;j++){
				if(i%j == 0){
					ok = false;
					break;
				}
			}
			if(ok){
				if((i - 1) % 10 == 0){
					data.add(i);
				}
			}
		}
		for(int i = 0;i < n;i++){
			System.out.println(data.get(i));
		}




	}





}

class UnionFind{
	int[] parent;
	public UnionFind(int N){
		this.parent = new int[N];
		for(int i = 0; i < N;i++){
			parent[i] = i;
		}
	}
	public int root(int x){			//根要素を取得
		if(parent[x] == x){			//初期状態
			return x;
		}else{
			return parent[x] = root(parent[x]);    	//再帰によって根を取得
		}
	}
	public void unite(int x,int y){ 	//統合メソッド
		if(same(x,y)){					//同じ根なら終了
			return;
		}
		int xroot = root(x);
		int yroot = root(y);
		parent[xroot] = yroot;			//統合
		return;

	}

	public boolean same(int x,int y){			//根が同じか（同じグループに属しているか）を判定
		return(root(x) == root(y));
	}
}



class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}



Measured memory_bytes: 22228
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
B = LI()
A = B + [B[-1]]
for i in range(1, n):
    A[i] = min(B[i-1], A[i])



print(sum(A))




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

using namespace std;
typedef long long ll;


int main()
{
    int x, y;
    cin >> x >> y;

    if (y%2) cout << "No";
    else if (2*x > y) cout << "No";
    else if (4*x < y) cout << "No";
    else cout << "Yes";

    return 0;
}


Measured memory_bytes: 3656
#include <stdio.h>

char S[100100];

int main()
{
	scanf ("%s",S);
	int mx = 0, L = 0;
	while (S[L]) L++;
	for (int i=0;S[i];i++){
		int c = S[i] - '0';
		if (i) c ^= S[i-1] - '0';
		if (c){
			int v = i;
			if (v > L - i)
				v = L - i;
			if (mx < v)
				mx = v;
		}
	}
	printf ("%d\n",L-mx);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;

typedef long long ll;
ll MOD = 998244353;
int a[300];
ll dp[301][90001];//長辺の候補 dp[i][j]...i番目の辺まで使って構成できる辺の長さj
ll kei=0;

int main()
{
	int n;
	ll ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		kei+=a[i];
	}
	fill(dp[0],dp[301],0);
	dp[0][0]=1;
	int s=0;
	//ここからdp
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<s+1;j++)
		{
			if(dp[i][j]>0)
			{
				dp[i+1][j+a[i]]+=dp[i][j]; //i番目の辺を使う
				dp[i+1][j+a[i]]%=MOD;
				dp[i+1][j]+=dp[i][j]*2;//i番目の辺を使わない
				dp[i+1][j]%=MOD;
			}
		}
		s+=a[i];
	}
	//ここまでdp
	//kei/2以上の辺の通り数を求める
	for(int i=kei/2+kei%2;i<kei+1;i++)
	{
		if(dp[n][i]>0)
		{
			//cerr<<i<<" "<<dp[n][i]<<endl;
			ans+=dp[n][i];
			ans%=MOD;
		}
	}
	ans*=3;
	ans%=MOD;
	if(ans<0)
		ans+=MOD;
	
	//dp2回目
	fill(dp[0],dp[301],0);
	dp[0][0]=1;
	s=0;
	//ここからdp
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<s+1;j++)
		{
			if(dp[i][j]>0)
			{
				dp[i+1][j+a[i]]+=dp[i][j];//i番目の辺を使う
				dp[i+1][j+a[i]]%=MOD;
				dp[i+1][j]+=dp[i][j];//i番目の辺を使わない
				dp[i+1][j]%=MOD;
			}
		}
		s+=a[i];
	}
	//ここまでdp
	//減らしすぎた分を戻す
	if(kei%2==0)
		ans-=dp[n][kei/2]*3;
	
	ans%=MOD;
	if(ans<0)
		ans+=MOD;
	//すべての通り数を求める
	//3^n
	ll allpaturn=1;
	for(int i=0;i<n;i++)
	{
		allpaturn*=3;
		allpaturn%=MOD;
	}
	if(allpaturn<0)
		allpaturn+=MOD;
	
	//cerr<<ans<<" "<<allpaturn<<endl;
	ans=allpaturn-ans;
	if(ans<0)
		ans+=MOD;
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> P(n);
    for (int i = 0; i < n; i++)
        cin >> P[i];

    int res = 0;
    for (int i = 1; i <= n - 2; i++) {
        if ((P[i] >= P[i - 1] && P[i] <= P[i + 1]) || (P[i] <= P[i - 1] && P[i] >= P[i + 1]))
            res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
import math
cos60 = math.cos(math.pi*60/180)
sin60 = math.sin(math.pi*60/180)
#add_triangle
# input: start(x, y) end(x, y)
def add_triangle(start, end):
    x1 = (2*start[0] + end[0]) / 3
    x3 = (start[0] + 2*end[0]) / 3
    y1 = (2*start[1] + end[1]) / 3
    y3 = (start[1] + 2*end[1]) / 3
    x2 = x1 + (x3-x1)*cos60 - (y3-y1)*sin60
    y2 = y1 + (x3-x1)*sin60 + (y3-y1)*cos60
    return [(x1,y1), (x2,y2), (x3,y3)]

#koch_recursion
#input list [(x1,y1),(x2,y2),(x3,y3)...]
def koch_recursion(list1):
    output = []
    for i in range(len(list1)-1):
        output.append(list1[i])
        output += add_triangle(list1[i], list1[i+1])
    output.append(list1[len(list1)-1])
    return output

#Koch  call koch_recursion(0, 100)
def Koch(start, end, n):
    output = [start, end]
    for i in range(n):
        output = koch_recursion(output)
    for x, y in output:
        print("{:.8f} {:.8f}".format(x, y))

n = int(input())
Koch((0,0), (100,0), n)


Measured memory_bytes: 6264
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	if (n > k * 2) {

	}
	return fac[n] / (fac[k] * fac[n - k]);
}

ll dp[201010][2];
ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
char c[10][10];
bool flag[10][10];
bool flag2[10][10];

//long longしか使わない
//素数は1より大きい
int main() {
	ll h, w, k;
	cin >> h >> w >> k;
	rep(i, h) {
		rep(j, w) {
			cin >> c[i][j];
			if (c[i][j] == '#')flag[i][j] = true;
		}
	}
	ll ans = 0;
	ll kazu = 0;
	for (ll bit = 0;bit < (1 << h);++bit) {
		for (ll bit2 = 0;bit2 < (1 << w);++bit2) {
			rep(i, h) {
				rep(j, w) {
					flag2[i][j] = flag[i][j];
				}
			}
			for (ll i2 = 0;i2 < h;++i2) {
				if (bit & (1 << i2)) {
					rep(j2, w) {
						flag2[i2][j2] = false;
					}
				}
			}
			for (ll i3 = 0;i3 < w;++i3) {
				if (bit2 & (1 << i3)) {
					rep(j3, h) {
						flag2[j3][i3] = false;
					}
				}
			}
			ll res = 0;
			rep(i4, h) {
				rep(j4, w) {
					if (flag2[i4][j4])res++;
				}
			}
			if (res == k)ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3600
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

//const double PI = 3.1415926535897932384626433832795;

int main() {
  int n;
  cin >> n;
  cout << n / 2 + n % 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll ans = 100000000000,t, m,n;std::cin >> n;
  multiset<ll> s, k;
  re(i, n){
    std::cin >> t;
    s.insert(t);
  }
  std::cin >> m;
  re(i, m) {
    std::cin >> t;
    k.insert(t);
  }
  while(k.size()>0){
    auto itr = k.begin();
    if(k.count(*itr)>s.count(*itr)) ans = -1;
    k.erase(*itr);
    s.erase(*itr);
  }
  std::cout << (ans>0?"YES":"NO") << '\n';
}


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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    from math import gcd
    K=I()
    ans=0
    
    for i in range(1,K+1):
        for j in range(1,K+1):
            for k in range(1,K+1):
                temp=gcd(i,j)
                temp=gcd(temp,k)
                ans+=temp
                
    print(ans)
                
    

main()


Measured memory_bytes: 67744
//見えてほしい建物を決め打ちO(2^n)したとき, 左の建物から高さを決めていくことができる。
//左から見る。最初の建物はその高さがよい。見える建物について、高さをhにしてよいのならh以下にすべき。
#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;

int n, k;
int a[15];
int ma[15];

signed main() {
	int i, j, l;
	
	cin >> n >> k;
	if (k <= 1) { cout << 0 << endl; return 0; }
	for (i = 0; i < n; i++) cin >> a[i];
	ma[0] = a[0];
	for (i = 1; i < n; i++) ma[i] = max(a[i], ma[i - 1]);
	
	int ans = 1145141919810;
	
	for (i = 0; i < (1 << n); i++) {
		vector<int> ids;
		
		for (j = 0; j < n; j++) {
			if ((i >> j) % 2) {
				ids.push_back(j);
			}
		}
		if (ids.size() < k) { continue; }
		
		int maxHigh = 0;
		int sumCost = 0;
		for (j = 0; j < ids.size(); j++) {
			int high = max(ma[ids[j]], maxHigh + 1);
			maxHigh = high;
			sumCost += high - a[ids[j]];
		}
		ans = min(ans, sumCost);
	}
	
	cout << ans << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  vector<pair<ll, ll> > red(n), blue(n);

  for (int i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    red[i].first = x;
    red[i].second = y;
  }
  for (int i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    blue[i].first = x;
    blue[i].second = y;
  }
  sort(red.begin(), red.end());
  sort(blue.begin(), blue.end());

  ll cnt = 0;
  vector<ll> exist(n,0);
  for (int i = 0; i < n; i++) {
    ll jmax = -1000;
    ll jindex = -1;
    for (int j = 0; j < n; j++) {
      if (!exist[j] && red[j].first < blue[i].first && red[j].second < blue[i].second) {
        if (red[j].second > jmax) {
          jmax = red[j].second;
          jindex = j;
        }
      }
    }
    if (jindex >= 0) {
      exist[jindex] = true;
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int A[]=new int[N];
		int B[]=new int[N];
		for(int i=0;i<N;i++) {
			A[i]=sc.nextInt();
			B[A[i]-1]++;
		}
		long ans=0;
		for(int i=0;i<N;i++) {
			ans+=calcNumOfCombination(B[i],2);
		}
		for(int i=0;i<N;i++) {
			System.out.println(ans-calcNumOfCombination(B[A[i]-1], 2)+calcNumOfCombination(B[A[i]-1]-1, 2));
		}

	}
	public static long calcNumOfCombination(int n, int r){
		if(n==0||n==1) {
			return 0;
		}else {
        long num = 1;
        for(int i = 1; i <= r; i++){
            num = num * (n - i + 1) / i;
        }
        return num;}
    }
}


Measured memory_bytes: 101900
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N), cnt(N + 1);

    ll ans = 1;

    ll ins = 3;
    rep(i, N) {
        cin >> A[i];
        cnt[A[i]]++;

        if (A[i] == 0) {
            ans *= ins;
            ans %= mod;
            ins--;
            continue;
        } else {
            ans *= cnt[A[i] - 1];
            ans %= mod;
            cnt[A[i] - 1]--;
        }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 4776
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int c_number = 0;
		for(int i = 1; i <= n; i++){
			c_number = c_number + i;
		}
		System.out.println(c_number);
	}
}

Measured memory_bytes: 23124
while True:
	n = int(input())
	if n == 0:
		break
	dict = {}
	for _ in range(n):
		a = list(input().split())
		dict[a[0]] = a[1]
#	print(dict)
	m = int(input())
	s = ''
	for _ in range(m):
		j = input().strip()
		if j in dict:
			j = dict[j]
		s = s + j
	print(s)


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

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

  vector<double> p(n + 1);
  for (ll i = 1; i <= n; i++) {
    cin >> p[i];
  }

  // dp[until i][num of heads] = prob
  vector<vector<double>> dp(n + 1, vector<double>(n + 1));
  dp[0][0] = 1;
  for (ll i = 1; i <= n; i++) {
    dp[i][0] = dp[i - 1][0] * (1 - p[i]);
    for (ll j = 1; j <= i; j++) {
      dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
    }
  }

  double ans = 0;
  for (ll j = n / 2 + 1; j <= n; j++) {
    ans += dp[n][j];
  }
  printf("%.12f\n", ans);
}


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

int g[710][710];
int dp[710];
int vis[710];
int cnt1, cnt2;
int n, m;

int dfs(int x, int p){
	vis[x] = p;
	if (p) cnt1++;
	else cnt2++;
	for (int i = 1; i <= n; i++){
		if (g[x][i] || i == x) continue;
		if (vis[i] == -1){
			if (!dfs(i, p ^ 1)) return 0;
		}
		if (vis[i] != p ^ 1) return 0;
	}
	return 1;
}

int main(){
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++){
		int u, v; scanf("%d%d", &u, &v);
		g[u][v] = g[v][u] = 1;
	}
	dp[0] = 1;
	memset(vis, -1, sizeof(vis));
	for (int i = 1; i <= n; i++){
		if (~vis[i]) continue;
		cnt1 = cnt2 = 0;
		if (!dfs(i, 0)){
			printf("-1\n");
			return 0;
		}
		for (int j = n; j >= 0; j--){
			int tmp = 0;
			if (j - cnt1 >= 0) tmp |= dp[j - cnt1];
			if (j - cnt2 >= 0) tmp |= dp[j - cnt2];
			dp[j] = tmp;
		}
	}
	int ans = 0x3f3f3f3f;
	for (int i = 0; i <= n; i++){
		if (dp[i]) ans = min(ans, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
	}
	printf("%d\n", ans);
	return 0;
}


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

N = int(input())
H = [int(x) for x in input().split()]

if N == 1:
    print("Yes")
    sys.exit()

down = 0
for x in range(1, N):
    if H[x - 1] > H[x]:
        if H[x - 1] - H[x] >= 2:
            print("No")
            sys.exit()
        down += 1
    elif H[x - 1] < H[x]:
        down = 0
    if down >= 2:
        print("No")
        sys.exit()

print("Yes")


Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

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

	char last = ' ';
	int ret = 0;
	rep(i, S.length()){
		if(last != S[i]) ret++;
		last = S[i];
	}
	ret--;

	cout << ret << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b; cin >> a >> b;
  if(a > b) swap(a, b);
  if((b-a)%2) cout << "IMPOSSIBLE" << endk;
  else cout << (b+a)/2 << endk;
  return 0;
}


Measured memory_bytes: 3592
N, M = map(int, input().split())
a1, a2 = 2, M
a = {}
while (a1 - 1) ** 2 <= a2 or a1 == a2:
    if a2 % a1 == 0:
        a2 //= a1
        a[a1] = a.get(a1, 0) + 1
    else:
        a1 += 1
if a2 != 1:
    a[a2] = 1
p = 1
for v in a.values():
    for i in range(v):
        p = p * (v + N - 1 - i) // (i + 1)
print(p % (10 ** 9 + 7))

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

int main() {
  ll int a, b, n;
  cin >> a >> b >> n;
  
  ll int k;
  if(b <= n) k = n - (n % b) - 1;
  else k = n;
  
  ll int answer = ((a * k) / b) - (a * (k / b));
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3560
import sys
import heapq
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,M=nm()
A=nl()
h=[]
for i in A:
    heapq.heappush(h,-1*i)

for i in range(M):
	maxval=heapq.heappop(h)
	heapq.heappush(h,-(-maxval//2))
    
print(-sum(h)) 

Measured memory_bytes: 14204
#include"bits/stdc++.h"

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int A, B;
	cin >> A >> B;
	int ans = 0;

	int tmp = 0;
	if (B == 1) {
		cout << 0 << endl;
	}
	else {
		for (int i = 1; i <= 20; i++)
		{
			if (A * i - tmp >= B) {
				cout << i << endl;
				return 0;
			}
			tmp++;
		}
	}

	return 0;
}


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

int main(){
    int n;
    cin >> n;
    int a[n];
    for (int i = n-1; i >= 0; i--) cin >> a[i];
    for (int i = 0; i < n; i++){
        if (i == n-1) cout << a[i] << endl;
        else cout << a[i] << ' ';
    }
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define ull unsigned long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) (int)(x).size()
using namespace std;

const int N = 1e5+7;

int n, a, ile1, ile2, ile4;

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n;

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

		if(a%4==0)
			++ile4;
		else if(a%2==0)
			++ile2;
		else
			++ile1;
	}

	if(!ile2)
	{
		if(ile4+1>=ile1)
			cout << "Yes";
		else
			cout << "No";
	}
	else
	{
		if(ile4>=ile1)
			cout << "Yes";
		else
			cout << "No";
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int N, K;
    cin >> N >> K;
    int A[N];
    rep(i, N) {
        cin >> A[i];
    }

    int ans;
    if((N-1) % (K-1) == 0) {
        ans = (N-1)/(K-1);
    }
    else {
        ans = (N-1)/(K-1) + 1;
    }

    cout << ans;

    cout << endl;
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int dp[4001][4];
int main()
{
  int i,j,k;
 
  for(j=0;j<4001;j++)
    dp[j][0] = j<=1000?1:0;

  for(i=2;i<=4;i++)
    for(j=0;j<=4000;j++)
      for(k=0;k<=j && k<=1000;k++)
	dp[j][i-1] += dp[j-k][i-2];

  int n;
  while(scanf("%d",&n) != EOF)
    printf("%d\n",dp[n][3]);
    
  return 0;
}

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

H,W,M=map(int,input().split())
B=set([tuple(map(int,input().split())) for i in range(M)])

HH=[0]*(H+1)
WW=[0]*(W+1)

for x,y in B:
    HH[x]+=1
    WW[y]+=1

MAXH=max(HH)
MAXW=max(WW)

ANS=MAXH+MAXW-1

HLIST=[]
WLIST=[]
for i in range(1,H+1):
    if HH[i]==MAXH:
        HLIST.append(i)

for j in range(1,W+1):
    if WW[j]==MAXW:
        WLIST.append(j)

for i in HLIST:
    for j in WLIST:
        if (i,j) in B:
            continue
        else:
            print(ANS+1)
            sys.exit()
print(ANS)

Measured memory_bytes: 168592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long


int main() {
  char a, b;
  cin >> a >> b;
  
  if (a==b) {
  cout << 'H' << endl;
    return 0;
  }
  
  cout << 'D' << endl;
  
}


Measured memory_bytes: 256
import scala.collection.mutable.ListBuffer
import scala.io.StdIn

object Main extends App {

  var temp = Array(-1, -1)
  val buff = new ListBuffer[(Int, Int)]
  while(temp(0) != 0 && temp(1) != 0){
    temp = StdIn.readLine().split(' ').map(_.toInt)
    buff += ((temp(0), temp(1)))
  }

  val result = buff.dropRight(1).map { case (h, w) =>
    (0 until h).map { j =>
      if(j == 0 || j == h - 1){
        Array.fill(w)("#").mkString("")
      } else {
        val temp = Array.fill(w)(".")
        temp(0) = "#";temp(w-1) = "#";
        temp.mkString("")
      }
    }.mkString(f"%n")
  }
  println(result.mkString(f"%n%n"))
  println("")
}



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

using namespace std;

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

Measured memory_bytes: 3560
#include<stdio.h>
int main(){
  int i,n,x;
  int L[100],cnt=1;
  scanf("%d %d",&n,&x);
  for(i=0;i<n;i++)
    scanf("%d",&L[i]);
  for(i=0;i<n;i++){
    if(L[i]<=x){
      L[i+1] += L[i];
      cnt++;
    }else
      break;
  }
  printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main(void) {
  int n, q;
  cin >> n >> q;
  char s[n+1];
  cin >> s;
  int cnt[n-1];
  cnt[0] = 0;
  for (int i = 0; i < n-1; i++) {
    if (i > 0) cnt[i] = cnt[i-1]; 
    if (s[i] == 'A' && s[i+1] == 'C') {
      cnt[i]++;
    }
  }
  for (int j = 0; j < q; j++) {
    int l, r;
    cin >> l >> r;
    if (l == n || r == 1) {
      cout << 0 << endl;
    } else if (l == 1) {
      cout << cnt[r-2] << endl;
    } else {
      cout << cnt[r-2] - cnt[l-2] << endl;
    }
  }
  return 0;
}


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

int main() {
	int N, ave = 0;
	cin >> N;
	vector<int> X(N);
	for (int i = 0; i < N; i++) {
		cin >> X.at(i);
		ave += X.at(i);
	}
	ave /= N;
	int min = 0;
	for (int i = 0; i < N; i++) {
		min += (X.at(i) - ave)*(X.at(i) - ave);
	}
	int tmp = 0;
	ave++;
	for (int i = 0; i < N; i++) {
		tmp += (X.at(i) - ave)*(X.at(i) - ave);
	}
	if (min > tmp) min = tmp;
	cout << min << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 #include <string.h>
 char s[101];
 int main(void) {
 scanf("%s", s);
 int res = 0;
 int n = strlen(s);
 for (int i = 0; i < n; i++) {
 if (s[i] != s[n - 1 - i]) res++;
 }
printf("%d\n", res / 2);
 }

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

ll gcd(ll a,ll b){
  while(b!=0){
    a%=b;
    swap(a,b);
  }
  return a;
}

ll kaizyou(ll N){
  ll num=1;
  for(ll i=1;i<=N;i++){
  num*=i;
  }
  return num;
}

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

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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())
#define ALL(v) (v).begin(), (v).end()

//π M_PI
//deg = rad*180/M_PI

int main() {
    ll k, x;
    cin >> k >> x;
    if ( 500*k >= x ) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

int main() {
	string s; //長さ4の数字列
	vector<string> month = { //月
		"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"
	};

	cin >> s;
	
	string sub_s1 = s.substr(0, 2);
	string sub_s2 = s.substr(2, 4);
	int all_result1 = -100;
	int all_result2 = -100;

	for (int i = 0; i < month.size(); i++) {
		int result1 = month[i].compare(sub_s1);
		int result2 = month[i].compare(sub_s2);
		
		if (result1 == 0 && result2 == 0) {
			all_result1 = result1;
			all_result2 = result2;
		}
		else if (result1 == 0) {
			all_result1 = result1;
		}
		else if (result2 == 0) {
			all_result2 = result2;
		}
	}
	
	if (all_result1 == 0 && all_result2 == 0) {
		cout << "AMBIGUOUS" << endl;
	}
	else if (all_result1 == 0) {
		cout << "MMYY" << endl;
	}
	else if (all_result2 == 0) {
		cout << "YYMM" << endl;
	}
	else {
		cout << "NA" << endl;
	}

}

Measured memory_bytes: 3040
fun main(args: Array<String>) {
    val x = readLine()!!.toDouble()

    val min = -1000.0
    val max = 1000.0
    var a = min
    var b = min

    while(a <= max) {
        val ap = Math.pow(a, 5.0)
        b = min
        var bp = Math.pow(b, 5.0)
        while(b <= max) {
            if (ap - bp == x) break
            b++
            bp = Math.pow(b, 5.0)
        }
        if (ap - bp == x) break
        a++
    }

    println("${a.toInt()} ${b.toInt()}")

}


Measured memory_bytes: 34668
#include<stdio.h>
main(){
  int i,j;
  int H,W;
  int count=0;
  char tairu[1000][1000];
  int sub[1000][1000];
  int a,b;
  while(1){
    scanf("%d %d",&H,&W);
    if(H==0 && W==0) break;
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
	scanf(" %c",&tairu[i][j]);
      }
    }
    i=0;
    j=0;
    count=0;
    for(a=0;a<1000;a++){
      for(b=0;b<1000;b++){
	sub[a][b]=0;
      }
    }
    while(count!=1){
      if(tairu[i][j]=='.') break;
      if(tairu[i][j]=='>'){ 
	j++;
	if(sub[i][j]==1){
	  count=1;
	}
	sub[i][j]=1;
      }
      if(tairu[i][j]=='v'){
	i++;
	if(sub[i][j]==1){
	  count=1;
	}
	sub[i][j]=1;
      }
      if(tairu[i][j]=='<'){ 
	j--;
	if(sub[i][j]==1){
	  count=1;
	}
	sub[i][j]=1;
      }
      if(tairu[i][j]=='^'){
	i--;
	if(sub[i][j]==1){
	  count=1;
	}
	sub[i][j]=1;
      }
    }
    if(count==1) printf("LOOP\n");
    else{
      printf("%d %d\n",j,i);
    }
  }
  return 0;
}

Measured memory_bytes: 4820
#include <iostream>
#include <string>
using namespace std;
int main(){
  int n,o,i,j;
  int l,r,s;
  string str;
  cin >> n;
  while(n!=0){
    o=0;
    l=0;r=0;s=0;
    for(i=0;i<n;i++){
      cin >> str;
      if(str[0]=='l'){
	if(str[1]=='u') l=1;
	else l=0;
      }else{
	if(str[1]=='u') r=1;
	else r=0;
      }
      if(l==1&&r==1&&s==0){
	o++;
	s=1;
      }
      if(l==0&&r==0&&s==1){
	o++;
	s=0;
      } 
    }
    cout << o << endl;
    cin >> n;
  }
  
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);

    for (int i = 0; i < n; ++i) cin >> v[i];

    int cur = 1, br = 0;
    for (int i = 0; i < n; ++i) {
        if (v[i] == cur) {
            cur++;
        } else {
            br++;
        }
    }
    if (cur == 1)
        cout << -1 << endl;
    else
        cout << br << endl;

    return 0;
}


Measured memory_bytes: 3988
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n,m;
int dist[500][500],vis[500][500];
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
string s[55];

int get(int x, int y){
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      dist[i][j]=inf;
      vis[i][j]=false;
    }
  }
  queue<pair<int,int>> q;
  dist[x][y]=0;
  q.push({x,y});
  while(!q.empty()){
    pi p = q.front();q.pop();
    int u = p.fs;
    int v = p.sc;
    if(vis[u][v])continue;
    vis[u][v]=1;
    for(int i=0;i<4;i++){
      int l = u+dx[i];
      int r = v+dy[i];
      if(u<=0 || u>n || v<=0 || v>m )continue;
      if(s[l][r]=='#')continue;
      dist[l][r]=min(dist[u][v]+1,dist[l][r]);
      q.push({l,r});
    }
  }
  int res = 0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      if(s[i][j]=='.'){
        res = max(res,dist[i][j]);
      }
    }
  }
  return res;
}

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  cin >> n >> m;
  for(int i=1;i<=n;i++){
    cin >> s[i];
    s[i] = " "+s[i];
  }
  int ans = 0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      if(s[i][j]=='.'){
        ans = max(ans, get(i,j));
      }
    }
  }
  cout << ans << endl;


return 0;
}
///....


Measured memory_bytes: 384