akhauriyash/Code-Regression huggingface dataset:
sa = list(str(input()))
sb = list(str(input()))
sc = list(str(input()))

turn = "a"

while 1:
    if turn == "a":
        if len(sa) == 0:
            print("A")
            break
        turn = sa.pop(0)
    elif turn == "b":
        if len(sb) == 0:
            print("B")
            break
        turn = sb.pop(0)
    elif turn == "c":
        if len(sc) == 0:
            print("C")
            break
        turn = sc.pop(0)

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

int main(){
    int N; string S; cin >> N >> S;
    int count = 1; 
    for(int i = 1; i < N; ++i){
        if (S[i - 1] == S[i]){
            continue;
        }else{
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define F first
#define S second
#define mod 1000000007

using namespace std;
vector<int> v;
int main()
{
    int i,n;
    cin>>n;
    
    for(int i=0;i<n;i++){int a;cin>>a; v.push_back(a);}
    sort(v.begin(),v.end());
    pair<int,int> ans;
    for(i=1;i<n;i++)
    {
        vector<int>::iterator it=lower_bound(v.begin(),v.end(), v[i]/2);
        if(*it== v[i]/2)ans= make_pair(v[i], *it);
        else{
            vector<int>::iterator it2= it;
            
            if(it!=v.begin()){
                it2--;
                if( *it-v[i]/2<= v[i]/2- *it2 && *it!=v[i])ans= make_pair(v[i],*it);
                else ans= make_pair(v[i], *it2);
            }
        }
        
    }
    cout<<ans.F<<" "<<ans.S;
    return 0;
}


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

const int mod = 1e5;

int main()
{
	int h, w;
	while (cin >> h >> w, h | w) {
		vector<vector<vector<vector<int>>>> dp(h, vector<vector<vector<int>>>(w, vector<vector<int>>(2, vector<int>(2))));
		dp[1][0][0][0] = 1;
		dp[0][1][1][0] = 1;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				for (int k = 0; k < 2; k++) {
					for (int l = 0; l < 2; l++) {
						if (!(k == 1 && l) && i + 1 < h) {
							(dp[i + 1][j][0][k != 0] += dp[i][j][k][l]) %= mod;
						}
						if (!(k == 0 && l) && j + 1 < w) {
							(dp[i][j + 1][1][k != 1] += dp[i][j][k][l]) %= mod;
						}
					}
				}
			}
		}
		int res = 0;
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < 2; j++) {
				(res += dp[h - 1][w - 1][i][j]) %= mod;
			}
		}
		cout << res << endl;
	}
	return 0;
}



Measured memory_bytes: 4624
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
bool visited[int(3e4 + 5)];
vector <int> ans;

int main(){
  scanf("%d", &N);
  if (N == 3){
    printf("2 5 63\n"); return 0;
  }

  ans = {3, 9}; N -= 2;
  int now = 0;
  while (N >= 2 && now < 5000){
    ans.push_back(6 * now + 2);
    ans.push_back(6 * now + 4);
    now++; N -= 2;
  }


  now = 15;
  while (N >= 2 && now <= 30000){
    ans.push_back(now);
    ans.push_back(now + 6);
    now += 12; N -= 2;
  }

  for (int i = 1; i <= N; i++){
    ans.push_back(6 * i);
  }

  printf("%d", ans[0]);
  for (int i = 1; i < ans.size(); i++) printf(" %d", ans[i]);
  printf("\n");

  return 0;
}


Measured memory_bytes: 3924
s = input()
n = 0
ans = 0
m = [0]*2019
m[0] = 1
for i, j in enumerate(reversed(s)):
  n = (n+int(j)*pow(10, i, 2019))%2019
  m[n] += 1
for i in m: ans += i*(i-1)//2
print(ans)

Measured memory_bytes: 9236
#!/usr/bin/env python3
import sys
from bisect import bisect_left
from collections import Counter
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(N: int, a: "List[int]"):
    cnt = Counter(a)
    v = list(cnt.values())
    b = list(cnt.keys())
    if len(cnt) == 3:
        if all([x == v[0] for x in v]):
            if b[0] ^ b[1] == b[2] or b[0] ^ b[2] == b[1]:
                yes()
                return
    elif len(cnt) == 2:
        if b[0] != 0:
            b[1], b[0] = b[0], b[1]
        if b[0] == 0 and cnt[b[1]] == cnt[b[0]]*2:
            yes()
            return

    elif len(cnt) == 1:
        if b[0] == 0:
            yes()
            return

    no()
    return

    # print(*keta, sep="\n")
    # def solve(N: int, a: "List[int]"):
    #     a.sort()
    #     used = Counter(a)
    #     used_orig = used.copy()
    #     x = [a[0]]
    #     used[0] -= 1

    #     # print("first, ", a[0])
    #     # 2番目の帽子を全探索
    #     for i in range(1, N):
    #         # print("2nd, ", a[i])
    #         x.append(a[i])
    #         used[i] -= 1
    #         for j in range(2, N):
    #             cand = x[-1] ^ x[-2]
    #             # print("cand, ", cand)
    #             pl = bisect_left(a, cand)
    #             if pl >= len(a):
    #                 break
    #             if cand == a[pl] and used[cand] > 0:
    #                 x.append(cand)
    #                 used[pl] -= 1
    #             else:
    #                 break
    #         else:
    #             yes()
    #             print(x)
    #             print(used)
    #             return
    #         x = [a[0]]
    #         used = used_orig.copy()
    #     no()
    #     return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 17392
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s = input.ReadLine();

        if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) return Yes;
        if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) return Yes;
        if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1]) return Yes;

        return No;
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<string,int>> vpsi;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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 int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



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

int a,b;
cin >> a >> b;
if(a<=9 && b<=9){
    cout << a*b << endl;
}else{
    cout << -1 << endl;
}

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
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;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
const ll MOD = 1e9+7;
ll powmod(ll x, ll n){
    ll ret=1;
    while(n>0){
        if(n&1){
            ret*=x;
            ret%=MOD;
            n-=1;
        }
        else{
            x*=x;
            x%=MOD;
            n>>=1;
        }
    }
    return ret;
}
signed main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n; cin >> n;
    string s; cin >> s;
    int sz=s.size();
    ll dp[n+1][n+1];
    rep(i,n+1){
        rep(j,n+1){
            dp[i][j]=0;
        }
    }
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        dp[i][0]+=dp[i-1][0];
        rep(j,n+1){
            if(j>0) dp[i][j]+=dp[i-1][j-1]*2;
            if(j+1<=n) dp[i][j]+=dp[i-1][j+1];
            dp[i][j]%=MOD;
        }
    }
    ll res=powmod(2,MOD-1-sz);
    dp[n][sz]*=res;
    cout << dp[n][sz]%MOD << endl;
    
}



Measured memory_bytes: 199004
N = int(input())

height = list(map(int,input().split()))

ans = 0
interval = 0

for i in range(N):
  #区間が足りない時
  if height[i] > interval:
   #今の区間と必要な区間の差分を取って足し、新たな区間の数を定義する
   ##順番に注意 先にintervalに定義すると、
   ##ansがそれに影響されるためansが差分の分だけ余分にに大きくなる
    ans += height[i] - interval
    interval += height[i] - interval
  #区間が多い時、必要な数に減らす
  else:
    interval = height[i]

print(ans)

Measured memory_bytes: 3060
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    s = sorted(A)
    for a in A:
        if a == s[-1]:
            print(s[-2])
        else:
            print(s[-1])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14120
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define inf 100000007
#define eps 1e-8
#define PI 3.14159265359
#define sp printf(" ")
#define vi vector<int>
#define vl vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pcc pair<char, char>
#define mp make_pair
#define FF first
#define SS second
#define pb(x) push_back(x)
#define sd(x) scanf("%d", &(x))
#define pd(x) printf("%d", (x))
#define pdn(x) printf("%d\n", (x))
#define sld(x) scanf("%ld", &(x))
#define pld(x) printf("%ld", (x))
#define pldn(x) printf("%ld\n", (x))
#define slf(x) scanf("%lf", &(x))
#define plf(x) printf("%.9lf", (x))
#define plfn(x) printf("%.2lf\n", (x))
#define sch(x) scanf("%c", &(x))
#define pch(x) printf("%c", (x))
#define pchn(x) printf("%c\n", (x))
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define ios ios::sync_with_stdio(false); cin.tie(0) ; cout.tie(0)
#define endl '\n'
using namespace std;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int x,y;
    cin>>x>>y;
    int ans=0;
    if(2*c<a+b)
    {
        ans+=2*c*(min(x,y));
        int z=min(x,y);
        x=x-z;
        y=y-z;
       // cout<<ans<<"x" <<endl;
        if(x>0)
        {
            if(2*c<a)ans+=2*c*x;
            else ans+=a*x;
        }
       // cout<<ans<<" "<<y<<" "<<b<<endl;
        if(y>0)
        {
            if(2*c<b)ans+=2*c*y;
            else ans+=b*y;
        }
       // cout<<ans<<endl;

    }
    else
    {
        ans+=a*x+b*y;
    }
    cout<<ans<<endl;

       
}

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

#define ll long long
using namespace std;
 
int n,a[10];
map<int,int>k;
bool b[10],ans=false;
 
int main() {
	for(int i=0;i<9;i++){
		cin>>a[i];
		k[a[i]]=i;
		b[i]=false;
	}
	cin>>n;
	for(int i=0;i<n;i++){
		int c;
		cin>>c;
		if(k.count(c))b[k[c]]=true;
	}
	ans=((b[0]&&b[4]&&b[8])||(b[6]&&b[4]&&b[2]));
	for(int i=0;i<3;i++){
		if(b[i*3]&&b[i*3+1]&&b[i*3+2])ans=true;
		if(b[i]&&b[i+3]&&b[i+6])ans=true;
	}
	cout<<(ans?"Yes":"No")<<endl;
 
	return 0;
}
 

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
double lim[20],limbit[1<<20],inf=1e9,eps=1e-9,limit[21][21];
int n,hx,hy,mx,my,cx[21],cy[21];
void calc(){
	rep(i,n+1) rep(j,n+1){
		if(i==j) limit[i][j]=0;
		double sx=cx[i],sy=cy[i],tx=cx[j],ty=cy[j],d=sqrt((tx-sx)*(tx-sx)+(ty-sy)*(ty-sy)),dx=(tx-sx)/d,dy=(ty-sy)/d,x=sx-mx,y=sy-my;
		double b=2*d,c=-(x*x+y*y+2*d*(x*dx+y*dy));
		limit[i][j]=(-b+sqrt(b*b-4*c))/2;
	}
}
bool dfs(int bit,int v,double t){
	if(bit==(1<<n)-1) return true;
	if(t+eps>limbit[bit]) return false;
	rep(i,n){
		if((bit>>i)&1) continue;
		if(t+eps>limit[v][i]) return false;
	}
	rep(i,n){
		if((bit>>i)&1) continue;
		if(dfs(bit+(1<<i),i,t+sqrt((cx[i]-cx[v])*(cx[i]-cx[v])+(cy[i]-cy[v])*(cy[i]-cy[v])))) return true;
	}
	return false;
}
int main(){
	while(true){
		cin >> n;
		cin >> cx[n] >> cy[n] >> mx >> my;
		if(n==0) break;
		rep(i,n){
			cin >> cx[i] >> cy[i];
			lim[i]=sqrt((cx[i]-mx)*(cx[i]-mx)+(cy[i]-my)*(cy[i]-my));
		}
		rep(i,1<<n){
			limbit[i]=inf;
			rep(j,n){
				if((i<<j)&1==0) limbit[i]=min(limbit[i],lim[j]);
			}
		}
		calc();
		cout << (dfs(0,n,0) ? "YES\n" : "NO\n");
	}
}

Measured memory_bytes: 9320
#include <bits/stdc++.h>
using namespace std;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) a.begin(),a.end()

int main(void){
    int n;
    string s;
    cin>>n>>s;
    int res = 0;
    rep1(i,n-1){
        set<char> xst,yst;
        string x = s.substr(0,i);
        string y = s.substr(i,n-i);
        xst.insert(all(x));
        yst.insert(all(y));
        vector<char> v;
        set_intersection(all(xst),all(yst),back_inserter(v));
        res = max(res,(int)v.size());
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	long int i, j;
	long int x, y;
	long int sum = 0;
	long int syokin[3] = {300000, 200000, 100000};
	
	scanf("%ld%ld", &x, &y);
	
	if(x <= 3) {
		sum = syokin[x - 1];
	}
	
	if(y <= 3) {
		sum += syokin[y - 1];
	}
	
	if( (x == 1) && (y == 1) ) {
		sum += 400000;
	}
	
	printf("%ld\n", sum);
	
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll MOD = 1e9 + 7;
const ll dx[4] = { -1,1,0,0 };
const ll dy[4] = { 0,0,-1,1 };
const ll MAX = 1e5 + 50 ;
const ll oo = 1e16;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
long long gcd(long long  a, long long  b) { return (b == 0 ? a : gcd(b, a % b)); }
ll n , m , q , ans; string s ;

vector < int > res , v;

void check(){

    int l = (int)v.size() - 1;

    int ind = -1 ;
    for(int i = l ; i >= 0 ; --i)
        if(v[i] == i){
            ind = i ;
            break;
    }

    if(~ind){
        res.pb(ind + 1);
        v.erase(v.begin() + ind , v.begin() + ind + 1);
        return;
    }

    cout << -1 << '\n';
    exit(0);
}

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

    cin >> n ;
    for(int i = 0 ; i < n ; ++i){
        int x ;
        cin >> x ;
        v.pb(x - 1);
    }

    while((int)v.size() >= 1)
        check();

    reverse(all(res));

    for(int i = 0 ; i < n ; ++i)
        cout << res[i] << '\n';
     return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio;
	cin.tie(NULL);
	cout.tie(NULL);
	long long int i,j,k,l,m,n,min1;
	cin>>n>>k;
	long long int a[n],dp[n];
	for(i=0;i<n;i++)
	cin>>a[i];
	dp[0]=0;
	if(n>k)
	{
	for(i=1;i<k;i++)
	{
		dp[i]=abs(a[i]-a[0]);
	}
	for(i=k;i<n;i++)
	{
	long long int abmin=INT_MAX;
		for(j=1;j<=k;j++)
	{
			min1=dp[i-j]+abs(a[i-j]-a[i]);
		if(min1<abmin)
		abmin=min1;}
		dp[i]=abmin;
	}
		cout<<dp[n-1];
    }
    else
    {
    	cout<<abs(a[n-1]-a[0]);
	}
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
using namespace std;
#define mod 1e9+7
int n;
vector<int> dp(1<<21,-1);
bool a[21][21];
int cal(int num,int h)
{
  int res=0;
  if(dp[num]!=-1)return dp[num];
  for(int i=0;i<n;i++)
  {
    if(a[h-1][i] && (num & (1<<i)))
    {
        res+=cal(num-(1<<i),h-1);
        if(res>=mod)res-=mod;
    }
  }
  dp[num]=res;
  return res;
}
int main()
{
  ios::sync_with_stdio(false);
  cin>>n;
  dp[0]=1;
  for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>a[i][j];
  for(int i=0;i<n;i++)
  {
    cal(1<<i,1);
  }
  cout<<cal((1<<n)-1,n);
  return 0;

}


Measured memory_bytes: 8448
//Author: Herson Rezende - 2ºSemestre de CC - UFBA - 2020
//Site: hrezend.github.io/resume-web
#include <bits/stdc++.h>
#define desync ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define all(x) (x.begin(), x.end())
#define rall(x) (x.rbegin(), x.rend())
#define mkp(x,y) (make_pair(x,y))
#define out(x) cout << x << endl
using namespace std;

int main(){
	desync;
	int n, count = 0;
	cin >> n;
	int v[n+1];
	
	for(int i = 1; i <= n; i++){
		cin >> v[i];
		if(v[i] % 2 == 0){
			continue;
		}
		if(i % 2 != 0 && v[i] % 2 != 0){
		    count++;   
		}
	}
	out(count);
}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<tuple>
#include<functional>
using namespace std;
int n, m, a, b, c, dist[4000][100]; vector<tuple<int, int, int>>p; vector<tuple<int, int, int>>K[4000][100];
int main() {
	while (true) {
		for (int i = 0; i < 4000; i++) { for (int j = 0; j < 100; j++) { dist[i][j] = 999999999; K[i][j].clear(); } }
		cin >> n >> m; p.clear(); if (n == 0 && m == 0)break;
		for (int i = 1; i <= n; i++) {
			cin >> a; for (int j = 0; j < a; j++) { cin >> b >> c; p.push_back(make_tuple(i, b, c)); }
		}
		sort(p.begin(), p.end());
		for (int i = 0; i < p.size(); i++) {
			if (get<0>(p[i]) == 1 || get<0>(p[i]) == 2) { p.push_back(make_tuple(0, get<1>(p[i]), 0)); }
			if (get<0>(p[i]) == n || get<0>(p[i]) == n - 1) { p.push_back(make_tuple(n + 1, get<1>(p[i]), 0)); }
		}
		sort(p.begin(), p.end());
		for (int h = 0; h <= m; h++) {
			for (int i = 0; i < p.size(); i++) {
				for (int j = i + 1; j < p.size(); j++) {
					if (get<0>(p[j]) - get<0>(p[i]) == 1) {
						int rx = get<1>(p[i]), sx = get<1>(p[j]);
						int rp = get<2>(p[i]), sp = get<2>(p[j]);
						int U = abs(rx - sx)*(rp + sp);
						K[i][h].push_back(make_tuple(j, h, U));
					}
					if (get<0>(p[j]) - get<0>(p[i]) == 2) {
						int rx = get<1>(p[i]), sx = get<1>(p[j]);
						int rp = get<2>(p[i]), sp = get<2>(p[j]);
						int U = abs(rx - sx)*(rp + sp);
						K[i][h].push_back(make_tuple(j, h + 1, U));
					}
					if (get<0>(p[j]) - get<0>(p[i]) >= 3) { break; }
				}
			}
		}
		priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>>Q;
		for (int i = 0; i < p.size(); i++) {
			if (get<0>(p[i]) == 0) { Q.push(make_tuple(0, i, 0)); dist[i][0] = 0; }
		}
		while (!Q.empty()) {
			int a1 = get<0>(Q.top()), a2 = get<1>(Q.top()), a3 = get<2>(Q.top()); Q.pop();
			for (int i = 0; i < K[a2][a3].size(); i++) {
				int to1 = get<0>(K[a2][a3][i]), to2 = get<1>(K[a2][a3][i]), cost = get<2>(K[a2][a3][i]);
				if (dist[to1][to2] > a1 + cost) {
					dist[to1][to2] = a1 + cost; Q.push(make_tuple(dist[to1][to2], to1, to2));
				}
			}
		}
		int maxn = 999999999;
		for (int i = 0; i < p.size(); i++) {
			if (get<0>(p[i]) != (n + 1))continue;
			for (int j = 0; j <= m; j++)maxn = min(maxn, dist[i][j]);
		}
		cout << maxn << endl;
	}
	return 0;
}

Measured memory_bytes: 59516
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;

  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
      cout << "vowel";
    } else {
      cout << "consonant";
  }
}

Measured memory_bytes: 256
from collections import deque
n,*L=map(int,open(0).read().split())
G=[[]for _ in range(n)]
db=[-1]*n
dw=[-1]*n
for a,b in zip(*[iter(L)]*2):
	G[a-1]+=[b-1]
	G[b-1]+=[a-1]
q=deque([(0,0)])
while q:
	cur,d=q.popleft()
	db[cur]=d
	for nxt in G[cur]:
		if db[nxt]<0:
			q.append((nxt,d+1))
q=deque([(n-1,0)])
while q:
	cur,d=q.popleft()
	dw[cur]=d
	for nxt in G[cur]:
		if dw[nxt]<0:
			q.append((nxt,d+1))
b=w=0
for i,j in zip(db,dw):
	if i<=j:b+=1
	else:w+=1
if b<=w:
	print("Snuke")
else:
	print("Fennec")

Measured memory_bytes: 37208
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H,W,K;
  cin>>H>>W>>K;
  vector<string>G(H);
  vector<string>CPY(H);
  for(int i=0;i<H;i++)cin>>G[i];


int ans=0;
CPY=G;
  for(int bit1=0;bit1<(1<<H);bit1++){
    for(int bit2=0;bit2<(1<<W);bit2++){
      for(int h=0;h<H;h++){
        for(int w=0;w<W;w++){
          if((bit1&(1<<h))||(bit2&(1<<w))){
            CPY[h][w]='.';
          }
        }
      }
      
      //黒マス
      int black=0;
      for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
          if(CPY[i][j]=='#')black++;
        }
      }
      if(black==K)ans++;
      CPY=G;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3492
#include <bits/stdc++.h>
int main() {
    int N, M, X, Y; scanf("%d%d%d%d", &N, &M, &X, &Y);
    std::vector<int> x(N), y(M);
    for(int i=0; i<N; i++) scanf("%d", &x[i]);
    for(int i=0; i<M; i++) scanf("%d", &y[i]);

    int MX = *std::max_element(x.begin(), x.end());
    int MY = *std::min_element(y.begin(), y.end());
    for(int i=X+1; i<=Y; i++) {
        bool ok = true;
        ok &= MX < i;
        ok &= MY >= i;
        if(ok) {
            puts("No War");
            return 0;
        }
    }
    puts("War");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	string s;
	cin >> s;
	int n = s.size();
	if (n % 2) {
		cout << "No\n";
		return 0;
	}
	string res = "Yes\n";
	for (int i = 0;i < n;i += 2) {
		if(s.substr(i,2) != "hi"){
			res = "No\n";
		}
	}

	cout << res;
	
	return 0;
}


Measured memory_bytes: 256
def template_match(m, x, y, a, b)
  m.times do |i|
    m.times do |j|
      return false unless a[x + i][y + j] == b[i][j]
    end
  end
  true
end

n, m = gets.split.map(&:to_i)
a = []
b = []
n.times { a << gets.split('') }
m.times { b << gets.split('') }
(0..(n - m)).each do |i|
  (0..(n - m)).each do |j|
    if template_match(m, i, j, a, b)
      puts 'Yes'
      exit
    end
  end
end
puts 'No'

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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N;
    while(true){
        cin >> N;
        if(N == 0) break;
        //L: name P: price A+B+C: leaf D+E from leaf to fruit F: num of fruits S: sell price per fruit M: how many times
        //A+B+C + (D+E)*M: 所要時間 F*M*S - P: 収入
        vector<pair<double, string>> res;
        rep(i, N){
            string L; cin >> L;
            double p, a, b, c, d, e, f, s, m;
            cin >> p >> a >> b >> c >> d >> e >> f >> s >> m;
            res.push_back(make_pair(-(f*m*s-p)/(a+b+c+(d+e)*m), L));
        }
        sort(res.begin(), res.end());
        rep(i, res.size()){
            cout << res[i].second << endl;
        }
        cout << "#" << endl;
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

void koch(ll d, pair<double, double> a, pair<double, double> b) {
  if (d == 0) return;
  
  pair <double, double> s, t, u;
  double th = (M_PI/180.0)*60.0;
  
  s.first = (2.0*a.first+b.first)/3.0;
  s.second = (2.0*a.second+b.second)/3.0;
  t.first = (a.first+2.0*b.first)/3.0;
  t.second = (a.second+2.0*b.second)/3.0;
  u.first = (t.first-s.first)*cos(th) - (t.second-s.second)*sin(th) + s.first;
  u.second = (t.first-s.first)*sin(th) + (t.second-s.second)*cos(th) + s.second;
  
  koch(d-1, a, s);
  cout << s.first << ' ' << s.second << endl;
  koch(d-1, s, u);
  cout << u.first << ' ' << u.second << endl;
  koch(d-1, u, t);
  cout << t.first << ' ' << t.second << endl;
  koch(d-1, t, b);
}

int main() {
  ll n;
  cin >> n;
  pair <ll, ll> a, b;
  a = make_pair(0, 0);
  b = make_pair(100, 0);
  
  cout << fixed << setprecision(8);
  cout << a.first << ' ' << a.second << endl;
  koch(n, a, b);
  cout << b.first << ' ' << b.second << endl;
}


Measured memory_bytes: 3296
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <queue>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

const int MAX_N = 1e5+5;
const ll inf = 1e15;

struct human{
    int a,b,c;
}h[MAX_N];

int n,x,y,z;
ll res = 0;
priority_queue<int, vector<int>, greater<int> > q;
ll pre[MAX_N], suf[MAX_N];

int main(){
    cin >> x >> y >> z;
    n = x + y + z;
    reps(i,1,n+1){
        cin >> h[i].a >> h[i].b >> h[i].c;
    }
    sort(h+1,h + n + 1, [&](const human& m, const human& n){
        return m.a - m.b < n.a - n.b;
    });//金-銀でソート
    
    reps(i,1,n+1){
        res += h[i].c;//銅のコインの総和
        h[i].a -= h[i].c;//銅の枚数だけ減らす
        h[i].b -= h[i].c;//銅の枚数だけ減らす
    }

    reps(i,1,n+1){
        pre[i] = pre[i-1] + h[i].b;//pre[i] に（銀-銅）を足す
        q.push(h[i].b);//銀-銅
        if(q.size() > y) pre[i] -= q.top(), q.pop();
    }//qにはいるのは銀-銅の枚数の総和が大きくなるY人

    while(!q.empty()) q.pop();//queueを空っぽに
    for(int i = n; i; i--){
        suf[i] = suf[i+1] + h[i].a;//suf[i]に(金-銅)を足す
        q.push(h[i].a);//金-銅
        if(q.size() > x) suf[i] -= q.top(), q.pop();
    }//qにはいるのは金-銅の枚数の総和が大きくなるX人

    ll tmp = -inf;//最大値の初期値
    reps(i,y,n-x+1){
        tmp = max(tmp,pre[i] + suf[i+1]);
    }
    cout << res + tmp << endl;
    return 0;
}

Measured memory_bytes: 3448
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>
#include <cassert>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n)cin >> a[i];
    map<int,int> ma;
    ma[0] = 1000;//株、現金
    rep(i,n){
        map<int,int> tmp;
        for(auto x: ma){
            int kabu = x.first;
            int yen = x.second;
            //何もしない
            tmp[kabu] = max(tmp[kabu],yen);
            //売れるだけ売る
            tmp[0] = max(tmp[0], yen + kabu*a[i]);
            //買えるだけ買う
            int cnt = yen/a[i];
            tmp[kabu + cnt] = max(tmp[kabu+cnt], yen%a[i]);
        }
        ma = tmp;
    }
    int ans = 0;
    for(auto x: ma){
        ans = max(ans, x.second);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3644
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n;
    while(cin >> n) {
        if(n == 0) break;
        vector<int> a(n);
        int sum = 0;
        rep(i, n) {
            cin >> a[i];
            sum += a[i];
        }
        int cnt = 0;
        rep(i, n) {
            if(n * a[i] <= sum) ++ cnt;
        }
        cout << cnt << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}


Measured memory_bytes: 3136
N=int(input())

seq=[]

for i in range(N):
    a= int(input())
    seq.append(a)

import heapq

tmp=list(map(lambda x: x*(-1),seq))
heapq.heapify(tmp)

a=heapq.heappop(tmp)*(-1)
b=heapq.heappop(tmp)*(-1)

for j in range(N):
    if seq[j]==a:
        print(b)
    else:
        print(a)

Measured memory_bytes: 20520
use std::io::stdin;

fn read_line() -> Vec<i32> {
    let mut a_str = String::new();
    stdin().read_line(&mut a_str).expect("read error");
    a_str.split_whitespace()
        .map(|x| x.parse::<i32>().expect("parse error"))
        .collect::<Vec<i32>>()
}

fn main() {
    let v = read_line();
    let n = v[0] as usize;
    let k = v[1] as usize;
    let mut h = read_line();

    if n <= k {
        println!("0");
        return;
    }

    h.sort();
    let mut c: u64 = 0;
    for i in 0..n-k {
        c += h[i] as u64;
    }
    println!("{}", c);
}

Measured memory_bytes: 10232
def comb(k, n)
  if (k == 0)
    return (n == 0) ? 1 : 0
  end

  n0 = [9, n].min
  count = 0

  for i in (0..n0)
    count += comb(k - 1, n - i)
  end

  return count
end

while (line = gets)
  n = line.chop.to_i
  puts comb(4, n)
end

Measured memory_bytes: 6096
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
// #define endl "\n"

double recurse(ll a, ll b, ll c, ll n, vector<vector<vector<double>>>& dp) {
    if (a+b+c == 0) {
        return 0; // nothing more needs to be done
    }

    if (dp[a][b][c] > -0.5) {
        return dp[a][b][c];
    }

    double ans = (double)n / (a+b+c); // expected number of steps reqt to pick a sushi plate
    // now it could be any one of them, with a conditional probability

    if (a) {
        ans += recurse(a-1, b, c, n, dp) * (double)a / (a + b + c);
    }
    if (b) {
        ans += recurse(a + 1, b - 1, c, n, dp) * (double)b / (a + b + c);
    }
    if (c) {
        ans += recurse(a, b + 1, c - 1, n, dp) * (double)c / (a + b + c);
    }
    dp[a][b][c] = ans;
    return ans;
}

int main(void) {
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);
    ll n;
    cin >> n;

    vector<ll> count (4);
    for (ll i = 0; i  < n; i++) {
        ll a;
        cin >> a;
        count[a]++;
    }

    vector<vector<vector<double>>> dp (n+1, vector<vector<double>> (n+1, vector<double> (n+1, -1)));
    cout << fixed << setprecision(12) << (double)recurse(count[1], count[2], count[3], n, dp) << endl;;


    
    return 0;
}

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


int main() {

    int n;
    cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    sort(l.rbegin(), l.rend());
    int m = l[0];
    int res = 0;
    for (int i = 1; i < n; ++i) res += l[i];
    cout << (m < res ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderWorkspace
{
    class Program
    {
        static void Main(string[] args)
        {
            var cin = new Scanner();

            var r = cin.nextInt();
            var D = cin.nextInt();
            var x2000 = cin.nextInt();

            var init = r * x2000 - D;            
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(init);
                init = r * init -D;                
            }


        }
    }
    
    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}


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

# define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<vs> vvs;


typedef vector<pair<int, int>> vpi;
typedef vector<tuple<int, int, int>> vti;


ll count(ll diff, ll start, ll v){
    ll ans = diff / v;
    if (diff % v > (v - start % v) % v) ans++;
    return ans;
}

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

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    ll a, b;
    int c, d;
    cin >> a >> b >> c >> d;
    
    if (c < d) swap(c, d);
    ll diff = b - a + 1;
    ll e = (ll)c * d / gcd(c, d);
    
    ll ans = diff - (count(diff, a, c) + count(diff, a, d) - count(diff, a, e));
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
/********************************************************************************************************************************/
/* main *************************************************************************************************************************/
/********************************************************************************************************************************/
int DEBUG = 0;										/* デバッグプリント 提出時は0 */
	int		ss[14] = {0};
	int		hh[14] = {0};
	int		cc[14] = {0};
	int		dd[14] = {0};
int main()
{
	int		i,N,V;
	char	T;

	scanf("%d", &N);
	for(i=1;i<=N;i++) {
		scanf(" %c %d", &T,&V);
		if (T=='S') ss[V] = 1;
		if (T=='H') hh[V] = 1;
		if (T=='C') cc[V] = 1;
		if (T=='D') dd[V] = 1;
	}
	for(i=1;i<=13;i++) {
		if (ss[i]==0) printf("S %d\n",i);
	}
	for(i=1;i<=13;i++) {
		if (hh[i]==0) printf("H %d\n",i);
	}
	for(i=1;i<=13;i++) {
		if (cc[i]==0) printf("C %d\n",i);
	}
	for(i=1;i<=13;i++) {
		if (dd[i]==0) printf("D %d\n",i);
	}


	return 0;
}



Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
 
const int N = 505;
 
int n, m, q;
int f[N][N];
 
int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> m >> q;
	while (m--) {
		int l, r; cin >> l >> r;
		f[l][r]++;
	}
	for (int l = n; l >= 1; --l) {
		for (int r = l; r <= n; ++r) {
			f[l][r] += f[l + 1][r];
			f[l][r] += f[l][r - 1];
			f[l][r] -= f[l + 1][r - 1];
		}
	}
	while (q--) {
		int l, r; cin >> l >> r;
		cout << f[l][r] << '\n';
	}
}

Measured memory_bytes: 1920
#include<stdio.h>
#include<string.h>

#define MAX 100000

struct num_t {
  int l;
  int r;
};

int main() {
  int q, i, j;
  struct num_t num[MAX];
  char prime[MAX + 1];
  char neer[MAX + 1];
  int count[MAX + 1];
  
  
  scanf("%d", &q);
  for (i = 0; i < q; ++ i) {
    scanf("%d %d", &(num[i].l), &(num[i].r));
  }

  memset(prime, 1, MAX + 1);
  prime[1] = 0;
  for (i = 2; i <= MAX; ++ i) {
    if (prime[i]) {
      for (j = i * 2; j <= MAX; j += i) {
        prime[j] = 0;
      }
    }
  }
  
  memset(neer, 0, MAX + 1);
  for (i = 1; i <= MAX; i += 2) {
    if (prime[i]) {
      j = (i + 1) >> 1;
      if (prime[j]) {
        neer[i] = 1;
      }
    }
  }
  
  count[0] = 0;
  for (i = 0; i < MAX; ++ i) {
    count[i + 1] = count[i] + (int)neer[i + 1];
  }
  
  for (i = 0; i < q; ++ i) {
    printf("%d\n", count[num[i].r] - count[num[i].l - 1]);
  }
  fflush(stdout);
  return 0;
}

Measured memory_bytes: 3020
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 10000000007; //10^9+7

int main(){
  int n;
  int x,y,t;
  int px=0,py=0,pt=0;
  bool flag=true;
  cin>>n;
  REP(i,n){
    cin>>t>>x>>y;
    int dx=abs(x-px);
    int dy=abs(y-py);
    int dt=abs(t-pt);
    if(dx+dy>dt||(dt-(dx+dy))%2){
      flag=false;
    }
  }
  if(flag){print("Yes");}
  else {print("No");}

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#define EPS 1e-10
#define INF 1e12
using namespace std;
typedef pair<double,int> P;
double add(double a,double b){
	if(fabs(a+b)<EPS*(fabs(a)+fabs(b)))return 0.0;
	return a+b;
}

struct Point{
	double x,y;
	Point(double xx=0.0,double yy=0.0){
		x=xx;
		y=yy;
	}
	Point operator + (Point a){
		return Point(add(x,a.x),add(y,a.y));
	}
	Point operator - (Point a){
		return Point(add(x,-a.x),add(y,-a.y));
	}
	Point operator * (double d){
		return Point(x*d,y*d);
	}
	Point operator / (double d){
		return Point(x/d,y/d);
	}
};
typedef Point Vector;

double norm(Vector a){
	return add(a.x*a.x,a.y*a.y);
}

double abs(Vector a){
	return sqrt(norm(a));
}

double dot(Vector a,Vector b){
	return add(a.x*b.x,a.y*b.y);
}

double cross(Vector a,Vector b){
	return add(a.x*b.y,-a.y*b.x);
}

bool on_seg(Point p1,Point p2,Point q){
	return cross(p1-q,p2-q)==0 && dot(p1-q,p2-q)<=0;
}

Point intersection(Point p1,Point p2,Point q1,Point q2){
	return p1+(p2-p1)*(cross(q2-q1,q1-p1)/cross(q2-q1,p2-p1));
}

bool intersect(Point p1,Point p2,Point q1,Point q2){
	if(cross(p1-p2,q1-q2)==0){
		return on_seg(p1,p2,q1) || on_seg(p1,p2,q2) || on_seg(q1,q2,p1) || on_seg(q1,q2,p2);
	}else{
		Point r=intersection(p1,p2,q1,q2);
		return on_seg(p1,p2,r) && on_seg(q1,q2,r);
	}
}

int na,nb;
Point a[1001],b[1001];
double dist[1001];

double dijk(){
	double res=INF;
	for(int i=0;i<na;i++){
		dist[i]=INF;
	}
	priority_queue<P,vector<P>,greater<P> > que;
	que.push(P(0.0,0));
	dist[0]=0.0;
	while(que.size()){
		P q=que.top();
		que.pop();
		int v=q.second;
		if(dist[v]<q.first)continue;
		for(int i=0;i<na;i++){
			double cost=abs(a[i]-a[v]);
			if(cost+dist[v]<dist[i] && !intersect(b[0],b[1],a[i],a[v])){
				dist[i]=cost+dist[v];
				que.push(P(dist[i],i));
			}
		}
	}
	res=dist[1]+abs(b[1]-b[0]);

	for(int i=0;i<nb;i++){
		dist[i]=INF;
	}
	que.push(P(0.0,0));
	dist[0]=0.0;
	while(que.size()){
		P q=que.top();
		que.pop();
		int v=q.second;
		if(dist[v]<q.first)continue;
		for(int i=0;i<nb;i++){
			double cost=abs(b[i]-b[v]);
			if(cost+dist[v]<dist[i] && !intersect(a[0],a[1],b[i],b[v])){
				dist[i]=cost+dist[v];
				que.push(P(dist[i],i));
			}
		}
	}
	res=min(res,dist[1]+abs(a[1]-a[0]));
	return res+EPS<INF?res:-1;
}


int main(void){
	scanf("%d %d",&na,&nb);
	for(int i=0;i<na;i++){
		scanf("%lf %lf",&a[i].x,&a[i].y);
	}
	for(int i=0;i<nb;i++){
		scanf("%lf %lf",&b[i].x,&b[i].y);
	}

	if(intersect(a[0],a[1],b[0],b[1]))printf("%.20f\n",dijk());
	else printf("%.20f\n",abs(a[1]-a[0])+abs(b[1]-b[0]));
	return 0;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
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;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

signed main() {
    INIT;
    cin >> H >> W >> M;
    vi h(H), w(W);
    map<pair<int, int>, int> mp;
    REP(i, M) {
        cin >> A >> B;
        A--, B--;
        h[A]++;
        w[B]++;
        mp[{A, B}] = 1;
    }
    ll mxh = *max_element(ALL(h));
    ll mxw = *max_element(ALL(w));
    vi hh, ww;
    REP(i, H) {
        if (h[i] == mxh) {
            hh.push_back(i);
        }
    }
    REP(i, W) {
        if (w[i] == mxw) {
            ww.push_back(i);
        }
    }
    dump(mxh, mxw);
    if ((ll)(hh.size()) * (ll)(ww.size()) > M) {
        cout << mxh + mxw << endl;
    } else {
        REP(i, hh.size()) {
            REP(j, ww.size()) {
                if (!mp[{hh[i], ww[j]}]) {
                    cout << mxh + mxw << endl;
                    return 0;
                }
            }
        }
        cout << mxh + mxw - 1 << endl;
    }
}

Measured memory_bytes: 28460
H,W  = map(int,input().split())
s = []
ans = 'Yes'
for _ in range(H):
    s.append(input())

for i in range(1,H-1):
    for j in range(1,W-1):
        if s[i][j]=='#' and s[i][j+1]==s[i+1][j]==s[i][j-1]==s[i-1][j]=='.':
                print('No')
                exit()
print(ans)

Measured memory_bytes: 9036
#include <iostream>
#define mod 1000000007

using namespace std;
int n,i,j,b,f,m,mask;
int a[25][25];
long long dp[2097159];
bool ok(int n, int nr)
{
    while(n)
    {
        if(n%2)
            nr--;
        n/=2;
    }
    return (nr==0);
}
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            cin>>a[i][j];
    dp[0]=1;
    for(b=1;b<=n;b++)
    {
        for(mask=0;mask<(1<<n);mask++)
        {
            if(ok(mask, b-1))
            {
                for(f=0;f<n;f++)
                {
                    if(!((mask>>f)&1) && a[b][f+1])
                    {
                        dp[mask+(1<<f)]+=dp[mask];
                        dp[mask+(1<<f)]%=mod;
                    }
                }
            }
        }
    }
    cout<<dp[(1<<n)-1];
    return 0;
}


Measured memory_bytes: 16640