akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

template<typename T>
struct CumulativeSum2D{
    int H,W;
    vector<vector<T>> dat;
    CumulativeSum2D(vector<vector<T>> v){
        H=v.size(),W=v[0].size();
        dat.resize(H+1);
        rep(i,H+1) dat[i].assign(W+1,0);
        rep(i,H) rep(j,W) dat[i+1][j+1]=v[i][j];
        rep(i,H) rep(j,W) dat[i+1][j+1]+=dat[i+1][j];
        rep(j,W) rep(i,H) dat[i+1][j+1]+=dat[i][j+1];
    }
    T query(int sx,int sy,int gx,int gy){ //[sx,gx),[sy,gy)
        return dat[gx][gy]-dat[sx][gy]-dat[gx][sy]+dat[sx][sy];
    }
};

const int MAX_X=1e3+10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<vector<int>> v(MAX_X,vector<int>(MAX_X));
    rep(i,N){
        int a,b,c,d; cin >> a >> b >> c >> d;
        ++v[a][b],--v[a][d],--v[c][b],++v[c][d];
    }
    CumulativeSum2D<int> CS(v);
    int ans=0;
    rep(i,MAX_X) rep(j,MAX_X){
        chmax(ans,CS.query(0,0,i,j));
    }
    cout << ans << endl;
}


Measured memory_bytes: 15020
from collections import Counter
import sys
N=int(input())
v=[int(i) for i in input().split()]
A=[]
B=[]
for i in range(N):
    if i%2==0:
        A.append(v[i])
    else:
        B.append(v[i])
S=Counter(A).most_common(2)
T=Counter(B).most_common(2)
if S[0][0]!=T[0][0]:
    print(N-S[0][1]-T[0][1])
    sys.exit()
if len(S)==1 and len(T)==1:
    print(N-S[0][1])
    sys.exit()
if len(S)==1:
    print(N-S[0][1]-T[1][1])
    sys.exit()
if(len(T)==1):
    print(N-S[1][1]-T[0][1])
    sys.exit()    

a=S[0][1]+T[1][1]
b=S[1][1]+T[0][1]
c=max(a,b)
print(N-c)

Measured memory_bytes: 64492
from functools import reduce

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

N = int(input())
A = list(map(int, input().split()))

lcm = reduce(lambda x, y: (x * y) // gcd(x, y), A)

score = 0
for a in A:
    score += (lcm - 1) % a

print(score)

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

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    int K;
    cin >> K;

    int maximum = max(A, max(B, C));
    int minimum = min(A, min(B, C));
    int mid = A + B + C - maximum - minimum;
    for(int i = 0; i < K; i++){
        maximum = maximum * 2;
    }

    cout << maximum + minimum + mid << endl;
}

Measured memory_bytes: 256
n = int(input())
a = [int(input()) for _ in range(n)]
ans = 0

def isPrime(x):
    if x == 2:
        return True
    if x < 2 or x%2 == 0:
        return False
    i = 3
    while i <= int(x**0.5):
        if x%i == 0:
            return False
        i += 2
    return True

for i in range(n):
    if isPrime(a[i]):
        ans += 1
    
print(ans)


Measured memory_bytes: 5996
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+10;
const int INF=1e9+10;
int n;
int a[MAX],dp[MAX];
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	dp[0]=0;
	for(int i=1;i<n;i++) dp[i]=INF;
	for(int i=1;i<n;i++){
		dp[i]=min(dp[i],dp[i-1]+abs(a[i]-a[i-1]));
		if(i-2>=0) dp[i]=min(dp[i],dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n-1]<<"\n";
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int a,b,k,d[105];
int main()
{
    cin>>a>>b>>k;
    int c=min(a,b);
    int t=0;
    for(int i=1;i<=c;i++){
        if(a%i==0&&b%i==0)
            d[++t]=i;
    }
    cout<<d[t-k+1];
	return 0;
}



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

int isPrime(int);

main(){
  int N,i,a,j,count=0;

  scanf("%d", &N);

  for(i=0; i<N; i++){
    scanf("%d",&a);
    if((isPrime(a)) == 0){
      count++;
    }
  } 
  printf("%d\n", count);
  return 0;
}

int isPrime(int b){
  int i;

  for(i=2; i<=sqrt(b); i++){
    if(b % i == 0){
      return 1;
    }
  }
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  ll ans = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (a[i] > a[i + 1]) {
      ll tmp = a[i] - a[i + 1];
      ans += tmp;
      a[i + 1] += tmp;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4844
# https://atcoder.jp/contests/abc153/tasks/abc153_e


def main():
    h, n = map(int, input().split(" "))
    dp = [float("inf")] * (h + 1)
    dp[0] = 0
    for i in range(n):
        damage, cost = map(int, input().split(" "))
        for total in range(h +1):
            # 現在の蓄積ダメージから、魔法iを使った場合に与えるダメージ
            next_damage = min(total + damage, h)
            dp[next_damage] = min(dp[next_damage], dp[total] + cost)
    print(dp[-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 48476
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 100005;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int d,n;
    cin >> d >> n;
    if (n != 100){
        PRINT(n*(int)pow(100,d));
    }
    else{
        PRINT(101*(int)pow(100,d));
    }
}





Measured memory_bytes: 256
x=list(map(int,input().split()))
y=list(map(int,input().split()))
y.sort()
i=0
"""
while x[1]>0 and i<x[0]:
    x[1]-=y[i]
    i+=1
"""
num=0
for i in y:
    if x[1]-i>=0:
        num+=1
    x[1]-=i
if x[1]>0:
    print(num-1)
else:
    print(num)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n;

signed main(){
    cin >> n;
    if(n%2==1){
        print(0);
        return 0;
    }
    int cnt = 10;
    int ans = 0;
    while(n>=cnt){
        ans += n/cnt;
        cnt *= 5;
    }
    print(ans);

    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;
ll mod = 1e+9 + 7;

int main(){
    ll S;
    cin >> S;
    
    ll A[S+1] = {0};
    A[0] = 1;
    A[1] = 0;
    A[2] = 0;

    FOR(i, 3, S){
        A[i] = A[i-1] + A[i-3];
        A[i] %= mod;
    }

    int ans = A[S];
    ans = (ans + mod)%mod;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
import queue

"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""
N = int(input())
A = input()
S = ""
for a in  A:
	if len(S) == 0 or S[-1]!=a:
		S += a
print(len(S))

Measured memory_bytes: 4336
A=list(map(int,input().split()))
a,b,c,d,e=A[0],A[1],A[2],0,0
if a==5:
    d+=1
if b==5:
    d+=1
if c==5:
    d+=1
if a==7:
    e+=1
if b==7:
    e+=1
if c==7:
    e+=1
if d==2 and e==1:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
import sys
from collections import deque

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
A = LI()
ans = 1
if 0 in A:
    ans = 0
else:
    for i in range(N):
        ans = ans * A[i]
        
        if (ans > 1000000000000000000):
            ans = -1
            break
print(ans)



Measured memory_bytes: 84240
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

void dfs(int i, int j, int** c,bool **used, int h, int w){
		if(used[i][j])return;
		used[i][j] = true;
		for(int x = -1; x < 2; x++){
				for(int y = -1; y < 2; y++){
						int dx = i + x;
						int dy = j + y;
						if(dx > -1 && dx < h && dy > -1 && dy < w){
								if(!used[dx][dy] && c[dx][dy] == 1){
										dfs(dx, dy, c, used, h, w);
								}
						}
				}
		}
}

int main(int argc, char const* argv[])
{
	int w, h;
	cin >> w >> h;
	while(w != 0 || h != 0){
			int **c = new int*[h];
			bool **used = new bool*[h];
			for(int i = 0; i < h; i++){
					c[i] = new int[w];
					used[i] = new bool[w];
					for(int j = 0; j < w; j++){
							cin >> c[i][j];
							used[i][j] = false;
					}
			}
			int res = 0;
			for(int i = 0; i < h; i++){
					for(int j = 0; j < w; j++){
							if(used[i][j])continue;
							if(c[i][j] == 0)continue;
							dfs(i, j, c, used, h, w);
							res++;
					}
			}
			cout << res << endl;
			cin >> w >> h;
	}
	return 0;
}



Measured memory_bytes: 3508
Scanf.scanf "%d" (fun k ->
    let arr = Array.make k max_int in

    let deq = Array.make (2 * k) 0 in

    let rec loop f l =
        if f <= l then (
            let num = deq.(f) in
            let f = f + 1 in
            let cost = arr.(num) in
            let next = (num * 10) mod k in
            let f = if cost < arr.(next) then (
                arr.(next) <- cost;
                let f = f - 1 in
                deq.(f) <- next;
                f
            ) else f in
            let next = (num + 1) mod k in
            let l = if cost + 1 < arr.(next) then (
                arr.(next) <- cost + 1;
                let l = l + 1 in
                deq.(l) <- next;
                l
            ) else l
            in
            loop f l
        ) else f, l
    in
    arr.(1) <- 1;
    deq.(k) <- 1;
    ignore (loop k k);
    Printf.printf "%d\n" arr.(0)
)

Measured memory_bytes: 6148
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    public struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } }
    public static void Solve()
    {
        int N = NextInt();
        int A = NextInt();
        int B = NextInt();

        Console.WriteLine(Math.Min(N * A, B));
    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 11220
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef long long ll;

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

int main(){
	int n,ans;
	cin>>n;
	int a;
	rep(i,n){
		cin>>a;
		if(i==0)ans=a;
		else ans=gcd(ans,a);
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define PB push_back
#define f first
#define s second

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

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll x;
    cin >> x;
    map<ll, ll> m;
    for(ll a=0; a*a*a*a*a <= 1000000000000000000; a++)
    {
        m[a*a*a*a*a] = a;
    }
    ll y = floor(pow(x/5.0, 0.25));
    for(ll b = -y; b <= y; b++)
    {
        if(m.find(b*b*b*b*b + x) != m.end())
        {
            cout << m[b*b*b*b*b + x] << " " << b << "\n";
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 4260
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int M, K;
	
	cin>>M>>K;
	
	if(K >= (1<<M)){
		cout<<-1<<endl;
		return 0;
	}
	if(M == 1){
		if(K >= 1){
			cout<<-1<<endl;
		} else {
			cout<<"0 0 1 1"<<endl;
		}
		return 0;
	}
	
	for(int i = 0; i < K; i++){
		if(i)cout<<" ";
		cout<<i;
	}
	if(K)cout<<" "<<K;
	else cout<<K;
	
	for(int i = K-1; i >= 0; i--){
		cout<<" "<<i;
	}
	for(int i = K+1; i < (1<<M); i++){
		if(i)cout<<" ";
		cout<<i;
	}
	cout<<" "<<K;
	for(int i = (1<<M)-1; i >= K+1; i--){
		cout<<" "<<i;
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		sc.close();

		if (s[2] == s[3] && s[4] == s[5]) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21844
loop do
  n = gets.to_i
  break if n.zero?
  board = n.times.map { gets.chomp }
  check = lambda do |x, y|
    0 <= x && x < n && 0 <= y && y < n && board[y][x] == ?1
  end
  r = 0
  n.times do |j|
    n.times do |i|
      [[-1, 0], [-1, 1], [0, 1], [1, 1]].each do |d|
        unless check[i-d[0], j-d[1]]
          x, y, c = i, j, 0
          x, y, c = x+d[0], y+d[1], c+1 while check[x, y]
          r = c if c > r
        end
      end
    end
  end
  p r
end

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

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var d = new Dictionary<int, int>();
        var d2 = new Dictionary<int, int>();
        for (int i = 0; i < n; i += 2)
        {
            if (d2.ContainsKey(a[i])) d2[a[i]]++;
            else d2[a[i]] = 1;
        }
        for (int i = 1; i < n; i += 2)
        {
            if (d.ContainsKey(a[i])) d[a[i]]++;
            else d[a[i]] = 1;
        }
        var ans = new List<int>();
        var dr = d.OrderByDescending(x => x.Value).ToArray();
        var d2r = d2.OrderByDescending(x => x.Value).ToArray();
        if (dr.Length == 1 && d2r.Length == 1 && dr[0].Key != d2r[0].Key)
        { Console.WriteLine(0); goto end; }
        if (dr.Length == 1 && d2r.Length == 1 && dr[0].Key == d2r[0].Key)
        { Console.WriteLine(n / 2); goto end; }
        if (dr.Length == 1 && d2r.Length > 1)
        {
            if (dr[0].Key != d2r[0].Key) { Console.WriteLine(n / 2 - d2r[0].Value); goto end; }
            else if (dr[0].Key != d2r[1].Key) { Console.WriteLine(n / 2 - d2r[1].Value); goto end; }
        }
        if (dr.Length > 1 && d2r.Length == 1)
        {
            if (d2r[0].Key != dr[0].Key) { Console.WriteLine(n / 2 - dr[0].Value); goto end; }
            else if (d2r[0].Key != dr[1].Key) { Console.WriteLine(n / 2 - dr[1].Value); goto end; }
        }
        if (dr[0].Key != d2r[0].Key) ans.Add(n - dr[0].Value - d2r[0].Value);
        if (dr[0].Key != d2r[1].Key) ans.Add(n - dr[0].Value - d2r[1].Value);
        if (dr[1].Key != d2r[0].Key) ans.Add(n - dr[1].Value - d2r[0].Value);
        if (dr[1].Key != d2r[1].Key) ans.Add(n - dr[1].Value - d2r[1].Value);
        Console.WriteLine(ans.Min());
        end:;
    }

}


Measured memory_bytes: 28640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int a[] = new int[n];
		int count[] = new int[n + 1];
		
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			count[a[i]]++;
		}
		
		//まずはすべての組み合わせの合計を出す
		long total = 0;
		for(int i = 1; i <= n; i++) {
			total += (long)count[i]*(count[i] - 1)/2;
		}
		
		for(int i = 0; i < n; i++) {
			System.out.println(total - (count[a[i]] - 1));
		}
	}

}


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

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

NA=[]

cnt=0
d={}
for i in range(N):
    if A[i]-i in d:
        cnt+=d[A[i]-i]
    if not -A[i]-i in d:
        d[-A[i]-i]=1
    else:
        d[-A[i]-i]+=1

print(cnt)



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

int ans,w,h;
string g[30];
bool visit[30][30];

int rec(int y,int x){
  int res = 1;
  int dx[] = {0,1,0,-1}, dy[] = {-1,0,1,0};
  visit[y][x] = true;

  for(int k=0;k<4;k++){
    int sy = y+dy[k] ,sx = x+dx[k];
    if(sy<0 || sx<0 || h<=sy || w<=sx)continue;
    if(visit[sy][sx] || g[sy][sx] == '#')continue;
    res += rec(sy,sx);
  }
  return res;
}

int main(){
  while(cin >> w >> h && (w||h)){

    for(int i=0;i<h;i++)for(int j=0;j<w;j++)visit[i][j] = false;
    for(int i=0;i<h;i++)cin >> g[i];

    ans = 0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(g[i][j] == '@')cout << rec(i,j) << endl;
      }
    }
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;

constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main() {
    string n; cin>>n;
    string ans = "";
    REP(i,n.size()) {
        if (n[i]=='1') {
            ans += '9';
        } else if (n[i]=='9') {
            ans += '1';
        } else {
            ans += n[i];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	void solve() {
		int X, N;
		cin >> X >> N;
		vector<bool> p( 1000 );
		for( int i = 0; i < N; ++i ) {
			int a;
			cin >> a;
			p[a] = true;
		}

		int ans = 0;
		int d = INT_MAX;
		for( int i = 0; i < 1000; ++i ) {
			if( !p[i] && abs( X-i ) < d ) {
				d = abs( X-i );
				ans = i;
			}
		}

		cout << ans << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <tuple>
#include <string>
#include <iterator>
#include <regex>
using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;
    int rt;
    rt = max(A + B, A - B);
    rt = max(rt, A * B);
    cout << rt << endl;
    return 0;
}


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

int main(){
    while(true){
        int m, min, max, p;
        vector<int> score;
        int n, gap=0;
        cin >> m >> min >> max;
        if(!(m||min||max)) break;
        for(int i=0;i<m;++i){
            cin >> p;
            score.push_back(p);
        }
        for(int i=min;i<=max;++i){
            if(gap <= score[i-1]-score[i]){
                gap = score[i-1]-score[i];
                n = i;
            }
        }
        cout << n << endl;
    }
}

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

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
const long long INF = (1LL << 60);
typedef long long ll;


void solve(long long H, long long N, vector<long long> A, vector<long long> B){
    vector< vector <ll> > dp(N+1, vector<ll>(H+1, INF));

    dp[0][0] = 0;
    REP(i, N) {
        REP(j, H+1) {
            if (dp[i+1][j] > dp[i][j]) {
                dp[i+1][j] = dp[i][j];
            }
            if (dp[i+1][min(j+A[i], H)] > dp[i+1][j] + B[i]) {
                dp[i+1][min(j+A[i], H)] = dp[i+1][j] + B[i];
            }
        }
    }
    cout << dp[N][H] << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long H;
    cin >> H;
    long long N;
    cin >> N;
    vector<long long> A(N);
    vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        cin >> A[i];
        cin >> B[i];
    }
    solve(H, N, move(A), move(B));
}


Measured memory_bytes: 78592
#include <bits/stdc++.h>
using namespace std;
unordered_map <string, int> votes;
vector <string> words;

int main(){
  int N;
  cin >> N;
  string a;
  int most = 0;
  for (int i=0; i<N; i++){
    cin >> a;
    votes[a]++;
    most = max(most, votes[a]);
  }
  for (auto it: votes){
  	if (it.second == most){
      words.push_back(it.first);
    }
  }
  sort(words.begin(), words.end());
  for (string e: words){
    cout << e << endl;
  }
  return 0;
}

Measured memory_bytes: 26692
n = int(input())
edges = [list(map(int, input().split())) for _ in range(n)]
need_of_routes = [[True]*n for _ in range(n)]

for k in range(n):
    for i in range(n):
        if i == k:
            continue
        for j in range(n):
            if j == i or j == k:
                continue

            if edges[i][j] > edges[i][k] + edges[k][j]:
                print(-1)
                exit()
            elif edges[i][j] == edges[i][k] + edges[k][j]:
                need_of_routes[i][j] = False

count = 0
for i in range(n):
    for j in range(n):
        if need_of_routes[i][j]:
            count += edges[i][j]

print(count//2)

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


def solve(N, X, L):
    ds = [0] * (N +2)
    for i in range(1, N+1):
        ds[i] = ds[i-1] +   L[i-1]
    print(len([x for x in ds if x<=X]) - 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
    X = int(next(tokens))  # type: int
    L = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, X, L)

if __name__ == '__main__':
    main()


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

using namespace std;
using ll = long long;

template <typename T>
struct BIT {
  int size;
  vector<T> tree;

  BIT(int sz) : size(sz), tree(sz + 1, T()) {}

  void update(int i, T v) {
    i++;
    while (i <= size) {
      tree[i] = tree[i] + v;
      i += i & (-i);
    }
  }

  // prefix sum up to index i
  T query(int i) {
    i++;
    T res = T();
    while (i > 0) {
      res = res + tree[i];
      i -= i & (-i);
    }
    return res;
  }
};

struct mx {
  ll v;
  mx() : v(0) {}
  mx(ll _v) : v(_v) {}
  mx operator+(const mx& o) const { return max(v, o.v); }
};

constexpr int MAXN = 200005;

int n;
int H[MAXN];
ll A[MAXN];
BIT<mx> dp(MAXN);

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> H[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  ll res = 0;
  for (int i = 0; i < n; i++) {
    ll cur = dp.query(H[i] - 1).v + A[i];
    dp.update(H[i], cur);
    res = max(res, cur);
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 4096
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
using namespace std;

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	vector<int> m(b+10,-1);
	
	for(int i=0;;i++){
		m[i]=a*(i+1)%b;
		if(i>0){
			if(m[0]==m[i])break;
		}
	}
	
	for(int i=0;i<m.size();i++){
		if(m[i]==c){
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n, a, b, c, d;
	string s;
	read(n, a, b, c, d, s);
	s = " " + s;

	while (a < c || b < d) {
		bool jaf = c > d;
		//printf("%d/%d %d/%d\n", a, c, b, d);
		if (jaf) {
			if (a < c) {
				if (a + 1 <= c && s[a + 1] == '.' && a + 1 != b) { a = a + 1; continue; }
				if (a + 2 <= c && s[a + 2] == '.' && a + 2 != b) { a = a + 2; continue; }
			}
			if (b < d) {
				if (b + 1 <= d && s[b + 1] == '.' && b + 1 != a) { b = b + 1; continue; }
				if (b + 2 <= d && s[b + 2] == '.' && b + 2 != a) { b = b + 2; continue; }
			}
		} else {
			if (b < d) {
				if (b + 1 <= d && s[b + 1] == '.' && b + 1 != a) { b = b + 1; continue; }
				if (b + 2 <= d && s[b + 2] == '.' && b + 2 != a) { b = b + 2; continue; }
			}
			if (a < c) {
				if (a + 1 <= c && s[a + 1] == '.' && a + 1 != b) { a = a + 1; continue; }
				if (a + 2 <= c && s[a + 2] == '.' && a + 2 != b) { a = a + 2; continue; }
			}
		}
		//printf("B %d/%d %d/%d\n", a, c, b, d);
		break;
	}

	die ((a == c && b == d) ? "Yes" : "No");
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  string s;
  cin >> s;
  if(s[2]==s[3]&&s[4]==s[5]) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

int main() {
  int a,b;
  cin >> a >> b;
  if((a + b) % 2 == 0){
    cout << (a + b) / 2 << endl;
  }else{
    cout << (a + b) / 2 + 1 << endl;
  }
}

Measured memory_bytes: 256
def main(N, aa):
    """
    a_i * a_(i+1) = 4k
        i=2n and i+1=2m
        i=4n or  i+1=4m

    half: 4m -> ok
    all: 2n -> ok

    example5
        2 7 1 8 2 8
          -     -
        2 2 1 8 7 8
    all2を作成
    残りhalfのパターン

    example2
        1 2 3 4
        2 1 3 4
          1 3 4

        all2, 最後の１つは２＊２にならないので以下でフォロー
        2, 4m, x, 4m
        2, 4m, x, 4m, x
    """
    n_m2 = 0
    n_m4 = 0
    n_m2_notm4 = 0
    for a in aa:
        is_m2 = a % 2 == 0
        is_m4 = a % 4 == 0

        n_m2 += int(is_m2)
        n_m4 += int(is_m4)
        n_m2_notm4 += int(is_m2 and not is_m4)

    if n_m2_notm4 == 0 and n_m4 >= N // 2:
        return "Yes"
    else:
        rest = N - n_m2_notm4 + 1
        if n_m4 >= rest // 2:
            return "Yes"
        else:
            return "No"


if __name__ == '__main__':
    N = int(input())
    aa = map(int, input().split())

    print(main(N, aa))


Measured memory_bytes: 11052
#include<stdio.h>
int main()
{
	int k;
	scanf("%d", &k);
	int i;
	int c = 7;
	for (i = 0; i < k; i++)
	{
		c %= k;
		if (c == 0)
		{
			printf("%d\n", i + 1);
			return 0;
		}
		c = 10 * c + 7;
	}
	printf("-1\n");
	return 0;
}


Measured memory_bytes: 2164
/* it was worth becoming a chemist */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int uni;
typedef unsigned long long unll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<int> vi;
typedef vector<long long> vll;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define NAME "puts"
#define F first
#define S second

const ll INF = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const db EPS = (db) 1e-9;
const db pi = acos(-1.0);
const int MAXN = 1e5 + 5;

string s;

bool check() {
	for (int i = 1; i < sz(s); i++) {
		if (s[i] != '9') return 0;
	}
	return 1;
}

int main() {	
    #ifndef ONLINE_JUDGE
	//~ freopen(NAME".in", "r", stdin);
    //~ freopen(NAME".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << setprecision(9) << fixed;
	
	cin >> s;
	int c = s[0] - '0';
	if (check()) {
		cout << c + (sz(s) - 1) * 9;
	}
	else {
		cout << c + ((sz(s) - 1) * 9) - 1;
	}
	return 0;
}


Measured memory_bytes: 256
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

a, b, c = na()

flag = False
if a + b == c or a + c == b or b + c == a:
    flag = True

print("Yes" if flag else "No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    int A, B, K;
    cin >> A >> B >> K;
    int eat;
    eat = min(A, K);
    A = A - eat;
    K = K - eat;
    if (K == 0)
    {
        cout << A << " " << B << endl;
        return 0;
    }
    eat = min(B, K);
    B = B - eat;
    K = K - eat;
    cout << A << " " << B << endl;
    return 0;
    // system("pause");
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp18
{
    class Program
    {
        static void Main(string[] args)
        {
            var numbers = Console.ReadLine().Split(' ').Select(c => int.Parse(c))
                .ToArray();
            int A = numbers[0];
            int B = numbers[1];
            int K = numbers[2];

            var result = Enumerable.Range(1, 100).Where(i => A % i == 0 && B % i == 0).Reverse().Skip(K - 1).First();

            Console.WriteLine(result);
        }
    }
}


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

signed main() {
    long long sum;
    int n, m, c, a[20], b[20], ans;
    
    cin >> n >> m >> c;
    for ( int i = 0; i < m; i++ ) {
        cin >> b[i];
    }
    
    ans = 0;
    for ( int i = 0; i < n; i++ ) {
        sum = 0;
        for ( int j = 0; j < m; j++ ) {
            cin >> a[j];
            
            sum += a[j] * b[j];
        }
        
        if ( sum + c > 0 ) {
            ans ++;
        }
    }
    
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 3580
N,M = map(int,input().split())

moves = [list(map(int,input().split())) for i in range(M)]
isRed = [False for i in range(N)]
isRed[0] = True
Ball = [1 for i in range(N)]

for i in range(M):
    p = moves[i][0] - 1
    q = moves[i][1] - 1

    if isRed[p] == True:
        isRed[q] = True
        Ball[p] -= 1
        Ball[q] += 1
        if Ball[p] < 1:
            isRed[p] = False
        
    else:
        Ball[p] -= 1
        Ball[q] += 1
    
ans = isRed.count(True)

print(ans)


Measured memory_bytes: 29080
def calculate_mean(data):
    s = sum(data)
    N = len(data)
    mean =s/N

    return mean

#平均からの偏差を求める
def find_difference(data):
    mean = calculate_mean(data)
    diff = []

    for num in data:
        diff.append(num-mean)
    return diff

def calculate_variance(data):
    diff = find_difference(data)
    #差の2乗を求める
    squared_diff = []
    for d in diff:
        squared_diff.append(d**2)

    #分散を求める
    sum_squared_diff = sum(squared_diff)
    variance = sum_squared_diff/len(data)
    return variance

while True:
    n = int(input())
    if n==0:
        break
    data = list(map(int, input().split()))
    
    variance = calculate_variance(data)
    # print('分散の値は:{0}'.format(variance))

    std = variance**0.5
    # print('標準偏差は:{0}'.format(std))
    print('{}'.format(std))
    


Measured memory_bytes: 5672
import math
import numpy as np
a, b = map(int, input().split())

MAX = 1000 + 1
xa = np.zeros((MAX))
xb = np.zeros((MAX))

for i in range(MAX):
    xa_tmp = math.floor(0.08 * i)
    if xa_tmp == a:
        xa[i] = 1

for i in range(MAX):
    xb_tmp = math.floor(0.1 * i)
    if xb_tmp == b:
        xb[i] = 1

#print(xa[:30])
#print(xb[:30])
x = xa + xb

ans = -1
for i in range(MAX):
    if x[i] == 2:
        ans = i
        break

print(ans)


Measured memory_bytes: 19880
use std::io::Read;

const MOD : u64 = 1_000_000_007;

fn main(){
  let mut buf = String::new();
  std::io::stdin().read_to_string(&mut buf).unwrap();
  let mut iter = buf.split_whitespace().map(|s| s.parse().unwrap());
  
  let n : u64 = iter.next().unwrap();
  let A : Vec<_> = iter.collect();
  
  let s0 = ([0_u64;3], 1_u64);
  let ans = A.iter().try_fold(s0, |s, &a|{
    let (mut dp, ans) = s;

    let c = dp.iter().filter(|&s| *s == a).count();
    if c == 0 {
      return None;
    }

    let i = dp.iter().position(|s| *s == a).unwrap();
    dp[i] += 1;

    let ans = ans * (c as u64) % MOD;
    
    Some((dp, ans))
  });
  
  println!("{}", ans.map_or(0, |s| s.1 ));
}

Measured memory_bytes: 3468
#include<iostream>
using namespace std;
int main(){
    int n, m, p;
    while(1){
        cin>>n>>m>>p;
        if(n == 0 && m == 0 && p == 0) break;
        int a[1001], sum=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            sum += a[i];
        }
        int b;
        if(a[m-1] != 0) b = (sum * 100 - sum * p) / a[m-1];
        else b = 0;
        cout<<b<<endl;
    }
    return 0;
}



Measured memory_bytes: 3088
n,m = map(int,input().split())
A =[]
ans = 0
for i in range(n):
    B = list(map(int,input().split()))
    A.append(B)
C = [input() for j in range(m)]
for i in range(n):
    for j in range(m):
        ans = ans +int(A[i][j])*int(C[j])
    print(ans)
    ans = 0


Measured memory_bytes: 6024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main() {
	int X;
	cin >> X;
	if (X == 3 || X == 5 || X == 7) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 3616
def solve(H, W):
    s = [0]*3
    ans = H*W
    for h in range(H):
        s[0] = W * h
        s[1] = (H - h) * (W // 2)
        s[2] = H * W - s[0] - s[1]
        if max(s) - min(s) < ans:
            ans = max(s) - min(s)
        if ans == 0:
            print(ans)
            exit()
    for h in range(H):
        s[0] = h * W
        s[1] = (H - h) // 2 * W
        s[2] = H * W - s[0] - s[1]
        if max(s) - min(s) < ans:
            ans = max(s) - min(s)
        if ans == 0:
            print(ans)
            exit()
    return ans

H, W = [int(i) for i in input().split()]
ans = solve(H,W)
ans2 = solve(W,H)

print(min(ans,ans2))


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
typedef long long ll;

int main(void) 
{
    ll n, mi = 2000000,ma = -2000000,su = 0;
    ll a;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a;
        mi = (mi > a) ? a : mi;
        ma = (ma < a) ? a : ma;
        su += a;
    }
    cout << mi << " " << ma << " " << su << endl;

}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[8] = { 0,0,-1,1 };
ll dy[8] = { -1,1,0,0 };
ll dp[101010];

//long longしか使わない
//素数は1より大きい
int main() {
	ll n;
	cin >> n;
	vector<ll>ins(101010);
	ins[3] = 1;
	ins[5] = 1;
	for (ll i = 7;i < 101010;i += 2) {
		ll target = (i + 1) / 2;
		ll res = sqrt(i);
		ll res2 = sqrt(target);
		bool flag = true;
		for (ll j = 2;j <= res;++j) {
			if (i % j == 0)flag = false;
		}
		for (ll j = 2;j <= res2;++j) {
			if (target % j == 0)flag = false;
		}
		if (flag)ins[i] = 1;
	}
	for (ll i = 1;i < 101010;++i) {
		ins[i + 1] += ins[i];
	}
	rep(i, n) {
		ll a, b;
		cin >> a >> b;
		ll ans = ins[b] - ins[a - 1];
		cout << ans << endl;
	}
	return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> pys(M);
    for(int i=0; i<M; i++)
    {
        int a, b;
        cin >> a >> b;
        pys.at(i) = make_pair(a, b);
    }

    vector<tuple<int, int, int>> ts;
    for(int i=0; i<M; i++)
    {
        ts.emplace_back(pys[i].first, pys[i].second, i);
    }

    sort(ts.begin(), ts.end());
    int prep = -1;
    int num = 1;
    for(auto &t : ts)
    {
        if(get<0>(t) != prep)
        {
            prep = get<0>(t);
            num = 1;
            get<1>(t) = num;
        }
        else
        {
            num++;
            get<1>(t) = num;
        }
    }

    auto comp = [](const tuple<int, int, int> &a, const tuple<int, int, int> &b){
        return get<2>(a) < get<2>(b);
    };
    sort(ts.begin(), ts.end(), comp);
    for(auto &t : ts)
    {
        cout << setfill('0') << setw(6) << get<0>(t) << setfill('0') << setw(6) << get<1>(t) << endl;
    }


    return 0;
}


Measured memory_bytes: 5640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int f(ll a){
    int cnt = 0;
    while(a > 0){
        cnt++;
        a /= 10;
    }
    return cnt;
}
int main() {
    ll n; cin >> n;
    int ans = 9999999;
    for(ll i=1; i*i<=n; i++){
        if(n % i == 0){
            ans = min(ans, max(f(i), f(n/i)));
        }
    }
    cout << ans << endl;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k)
{
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL)
  {
    y=x;
    if(z->key < x->key)x = x->left;
    else x = x->right;
  }

  z->parent = y;
  if(y == NIL)
  {
    root = z;
  }
  else
  {
    if(z->key < y->key)y->left = z;
    else y->right = z;
  }
}

void inorder(Node u)
{
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u)
{
  if(u == NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);

    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 25296
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;

const string NO = "IMPOSSIBLE";

void solve(long long A, long long B){
  if((A+B)%2==0) cout << (A+B)/2 << endl;
  else cout << NO << endl;
}

int main(){
  std::cout << std::fixed << std::setprecision(15);
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  solve(A, B);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	char c[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>c[i];
	}
	int t,count=0;
	for(int i=1;i<=n;i=t+1)
	{
		t=i;
		if(c[i]==c[i+1])
		{
			while(c[t]==c[t+1])
			{
				t++;
			}
		}
		count+=t-i;
	}
	cout<<n-count<<endl;
	return 0;
}

Measured memory_bytes: 384
//https://atcoder.jp/contests/exawizards2019/tasks/exawizards2019_a
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
// clang-format on
int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    cout << (A == B && B == C && C == A ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int cumulative_sum[110000];


int main() {
    int n, q;
    string s;
    cin >> n >> q >> s;
    rep(i,n-1) {
        if (s[i] == 'A' && s[i+1] == 'C') s[i] = 'a';
    }
    rep(i,n) {
        if (s[i] == 'a') cumulative_sum[i+1] = cumulative_sum[i] + 1;
        else cumulative_sum[i+1] = cumulative_sum[i];
    }
    int ans[q];
    rep(i,q) {
        int lef, rig;
        cin >> lef >> rig;
        ans[i] = cumulative_sum[rig-1] - cumulative_sum[lef-1]; 
    }
    rep(i,q) cout << ans[i] << endl;
}

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

using namespace std;
using ll = long long;

int main()
{
    int n, c = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int t;
        cin >> t;
        if ((i + 1) % 2 == 1 && t % 2 == 1)
        {
            c++;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 3600