akhauriyash/Code-Regression huggingface dataset:
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        int[] input1 = MyUtil.ReadIntArray();
        string input = ReadLine();

        int[] Ac_Data = new int[input.Length];
        int count = 0;

        bool has_A = false;
        int startPoint = 0;

        for (int i = 0; i < input.Length; i++)
        {
            if (input[i] == 'A')
            {
                has_A = true;
                startPoint = i;
            }
            else if (input[i] == 'C')
            {
                if (has_A)
                {
                    ++count;
                }
                has_A = false;
            }
            else
            {
                has_A = false;
            }
            Ac_Data[i] = count;
        }

        int[] resArray = new int[input1[1]];
        for (int i = 0; i < input1[1]; i++)
        {
            int[] input2 = MyUtil.ReadIntArray();
            resArray[i] = Ac_Data[(input2[1] - 1)] - Ac_Data[(input2[0] - 1)];
        }

        foreach (var x in resArray)
        {
            WriteLine(x);
        }
        ReadKey();
    }
}

static class MyUtil
{
    public static int[] ReadIntArray()
    {
        return ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
    }

    /// <summary>
    /// <see cref="IEnumerable{T}"/>の各要素を並べてコンソールに出力します。各要素の間には半角スペースが一つ入ります。
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="ts"></param>
    public static void WriteToConsole<T>(this IEnumerable<T> ts)
    {
        StringBuilder stringBuilder = new StringBuilder();
        foreach (T t in ts)
        {
            stringBuilder.Append(t.ToString());
            stringBuilder.Append(" ");
        }
        stringBuilder.Remove(stringBuilder.Length - 1, 1);
        Console.WriteLine(stringBuilder.ToString());
    }
}


Measured memory_bytes: 17912
from collections import deque
d=[(0,1),(1,0),(0,-1),(-1,0)]
h,w=map(int,input().split())
v=[[0]*w for _ in range(h)]
a=[]
for i in range(h):
    s=input()
    a.append([i for i in s])

wh=sum([''.join(i).count('.') for i in a])

def bfs(t,s):
    rt=0
    q=deque([(t,s)])
    v[t][s]=1
    while q:
        y,x=q.popleft()
        if (y,x)==(h-1,w-1):  # condtion for finish
            return
        for dx,dy in d:
            if 0<=y+dy<h and 0<=x+dx<w and v[y+dy][x+dx]==0:
                if a[y+dy][x+dx]=='.':  # condition that the next cell is fine
                    q.append((y+dy,x+dx))
                    v[y+dy][x+dx]=v[y][x]+1
    return -1

bfs(0,0)
dis=v[-1][-1]
ans=wh-dis if dis>0 else -1
print(ans)


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

using ll = long long;
const int MAX = 1e5;
ll m;
vector<int> G[MAX], H[MAX];

vector<int> color(MAX, 0);
vector<ll> dp1(MAX); // dp1[i]:頂点iを根とした木で, 頂点iを黒く塗る方法の数(mod m)
void dfs1(int v) {
  color[v] = 1;
  ll keep = 1;
  for (int i = 0; i < G[v].size(); i++) {
    if (color[G[v][i]] == 0) {
      dfs1(G[v][i]);
      H[v].emplace_back(G[v][i]);
    }
    keep *= dp1[G[v][i]] + 1;
    keep %= m;
  }
  color[v] = 2;
  dp1[v] = keep;
  return;
}

vector<ll> dp2(MAX); // dp2[i]:頂点iから親方向に見たsubtreeで, 頂点iを黒く塗る方法の数(mod m)
void dfs2(int v) {
  vector<ll> l(H[v].size()), r(H[v].size()); // 左右からの累積積
  for (int i = 0; i < H[v].size(); i++) {
    l.at(i) = dp1[H[v][i]] + 1;
    if (i > 0) l.at(i) *= l.at(i - 1);
    l.at(i) %= m;
  }
  for (int i = H[v].size() - 1; i >= 0; i--) {
    r.at(i) = dp1[H[v][i]] + 1;
    if (i < H[v].size() - 1) r.at(i) *= r.at(i + 1);
    r.at(i) %= m;
  }
  
  ll keep = 1;
  if (v != 0) keep *= dp2[v];
  keep %= m;
  
  for (int i = 0; i < H[v].size(); i++) {
    ll pro = 1;
    if (i > 0) pro *= l.at(i - 1);
    pro %= m;
    if (i < H[v].size() - 1) pro *= r.at(i + 1);
    pro %= m;
    
    dp2[H[v][i]] = (keep * pro + 1) % m;
    dfs2(H[v][i]);
  }
  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  // 無向(有向)グラフの隣接リスト
  int n; // n:頂点数
  cin >> n >> m;
  
  // vector<int> G[n]; // G:頂点数がnのグラフを表す隣接リスト
  
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].emplace_back(v);
    G[v].emplace_back(u); // 有向グラフではこの行をコメントアウト
  }
  
  dfs1(0);
  
  dfs2(0);
  
  for (int i = 0; i < n; i++) {
    if (i == 0) cout << dp1[i] << '\n';
    else cout << (dp1[i] * dp2[i]) % m << '\n';
  }
}

Measured memory_bytes: 25088
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
int main(){
	string s;
	cin>>s;
	int cnt=0;
	for(int i=0;i<3;i++){
		if(s[i]=='1') cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        sc.close();

        long[] ary = new long[100];

        ary[0] = 2;
        ary[1] = 1;

        for (int i = 2; i <= n; i++) {
            ary[i] = ary[i - 2] + ary[i - 1];
        }

        System.out.println(ary[n]);
    }
}


Measured memory_bytes: 23764
import scala.io.StdIn.{readInt, readLine}
object Main {
    def main(args: Array[String]): Unit = {
        val len = readInt
        val arr = new Array[Card](len).map { a => 
            val line = readLine.split(" ")
            Card(line(0), line(1).toInt)
        }
        val arr2 = new Array[Card](len)
        arr.copyToArray(arr2)
        quickSort(arr)
        mergeSort(arr2)
        val q = arr.mkString("\n")
        val m = arr2.mkString("\n")
        if (q == m) println("Stable") else println("Not stable")
        println(q)
    }
    def quickSort(arr: Array[Card]): Unit = {
        def go(left: Int, right: Int): Unit = {
            if (left < right) {
                val (pivot, oneKind) = partition(arr, left, right)
                if (!oneKind) {
                    go(left, pivot - 1)
                    go(pivot + 1, right)
                }
            }
        }
        go(0, arr.length - 1)
    }
    def partition(arr: Array[Card], left: Int, right: Int): (Int, Boolean) = {
        val pivot = arr(right)
        def go(sep: Int, seek: Int, oneKind: Boolean): (Int, Boolean) = seek match {
            case s if s <= right => arr(seek) match {
                case e if e > pivot => go(sep, seek + 1, false)
                case e if e < pivot => {
                    swap(arr, sep + 1, seek)
                    go(sep + 1, seek + 1, false)
                }
                case e => {
                    swap(arr, sep + 1, seek)
                    go(sep + 1, seek + 1, oneKind)
                }
            }
            case s => (sep, oneKind)
        }
        go(left - 1, left, true)
    }
    def mergeSort(arr: Array[Card]): Unit = {
        def go(left: Int, right: Int): Unit = {
            if (left < right) {
                val mid = (left + right) / 2
                go(left, mid)
                go(mid + 1, right)
                merge(left, mid, right)
            }
        }
        def merge(left: Int, mid: Int, right: Int): Unit = {
            val tmp = arr.slice(left, mid + 1)
            var leftPtr = 0
            var rightPtr = mid + 1
            for (i <- (left to right)) {
                if (leftPtr >= tmp.length) {
                    rightPtr += 1
                } else if (rightPtr > right || tmp(leftPtr) <= arr(rightPtr)) {
                    arr(i) = tmp(leftPtr)
                    leftPtr += 1
                } else {
                    arr(i) = arr(rightPtr)
                    rightPtr += 1
                }
            }
        }
        go(0, arr.length - 1)
    } 

    def swap(arr: Array[Card], a: Int, b: Int): Unit = {
        val tmp = arr(a)
        arr(a) = arr(b)
        arr(b) = tmp
    }
}
case class Card(symbol: String, num: Int) {
    override def toString(): String = symbol + " " + num
    def <(a: Card): Boolean = this.num < a.num
    def <=(a: Card): Boolean = this.num <= a.num
    def >(a: Card): Boolean =  this.num > a.num
    def >=(a: Card): Boolean =  this.num >= a.num
}


Measured memory_bytes: 157516
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll X,Y,Z;
  cin >> X >> Y >> Z;
  cout << Z  << " "<< X  << " " << Y;
  return 0;
}


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

char field[100][100];
bool chack[100][100];
int H,W;

void move(int i, int j){
    chack[i][j] = true;
    if(i+1 < H && !chack[i+1][j] && field[i][j] == field[i+1][j]) move(i+1,j);
    if(i-1 >= 0&& !chack[i-1][j] && field[i][j] == field[i-1][j]) move(i-1,j);
    if(j+1 < W && !chack[i][j+1] && field[i][j] == field[i][j+1]) move(i,j+1);
    if(j-1 >= 0&& !chack[i][j-1] && field[i][j] == field[i][j-1]) move(i,j-1);
}

int main (void){
    while(1){
        int count = 0;
        cin >> H >> W;
        if(H==0&&W==0) break;
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                cin >> field[i][j];
                chack[i][j] = false;
            }
        }
        for(int i=0; i<H; i++)
            for(int j=0; j<W; j++)
                if(chack[i][j]==false){
                    count++;
                    move(i,j);
                }
        cout << count << endl;
    }
}



Measured memory_bytes: 3896
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,sum=0,x;
    vector<int>ara;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&x);
        ara.push_back(x);
    }
    sort(ara.begin(),ara.end());
    for(int i=0;i<k;i++)
    {
        sum+=ara[i];
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 3796
N,M,X = map(int, input().split())
array=list(map(int, input().split()))

Rcost = 0
Lcost = 0
for i in array:
    if i <  X:
        Lcost += 1
    elif i > X:
        Rcost += 1
print(min(Rcost,Lcost))

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

using namespace std;

int main(){
  
  long long n, m, x;
  cin>>n>>m>>x;

  int A[n][m+1];
  int sum[m];
  int cost = 0;
  int answer = 1000000000;

  for(int i=0; i<n; i++){
    for(int j=0; j<m+1; j++){
      cin>>A[i][j];
    }
  }

  for(int bit=0; bit<(1<<n); bit++){
    for(int i=0; i<n; i++){
    
      if(bit & 1<<i){
        for(int l=1; l<m+1; l++){
            sum[l-1] = sum[l-1] + A[i][l];
        }
        cost = cost + A[i][0];
      }
    }
    sort(sum, sum+m);
    if(sum[0]>=x & cost>0){
      answer = min(answer, cost);
    }
    
    memset(sum, 0, sizeof sum);
    cost=0;
  }

  if(answer == 1000000000){
    cout<<-1<<endl;
  } else {
    cout<<answer<<endl;
  }

}

Measured memory_bytes: 3640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
	int n;
	cin >> n;
	VI x(n), y(n), w(n);
	map<P, int> mp;
	REP(i,n){
		cin >> x[i] >> y[i] >> w[i];
		mp[make_pair(x[i], y[i])] = w[i];
	}
	int ans = 0;
	int dx[] = {1,1,-1,-1}, dy[] = {1,-1,1,-1};
	REP(p,n) REP(k,4){
		int i = x[p], j = y[p];
		int res = mp[make_pair(i, j)] + mp[make_pair(i+dx[k], j)] + mp[make_pair(i, j+dy[k])] + mp[make_pair(i+dx[k], j+dy[k])];
		ans = max(ans, res);
	}

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

    return 0;
}

Measured memory_bytes: 60372
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
    int F => int.Parse(Str);
    long FL => long.Parse(Str);
    int[] G => Strs.Select(int.Parse).ToArray();
    long[] GL => Strs.Select(long.Parse).ToArray();
    string Str => ReadLine();
    string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
    const int MOD = 1000000007;
    public K()
    {
        SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        Solve();
        Out.Flush();
    }
    void Solve()
    {
        var I = G;
        WriteLine(I[1] <= (1 + I[0]) / 2 ? "YES" : "NO");
    }
}


Measured memory_bytes: 13268
var lines = [];

var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]);
    var A = Number(lines[1]);
    var B = Number(lines[2]);
    var C = Number(lines[3]);
    var D = Number(lines[4]);
    var E = Number(lines[5]);

    max = Math.min(A, B, C, D, E);

    console.log(4 + Math.ceil(N / max));
});

Measured memory_bytes: 7884
#include<bits/stdc++.h>                
using namespace std;
int N, A, B;
int main(void){
	cin >> N >> A >> B;
	int ansMax = min(A, B);
	int ansMin = 0;
	if(N < A+B) ansMin =  A + B - N;
	cout << ansMax << ' ' << ansMin;
}


 
 
 
 


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    string s;
    int x, y, f = 0, cnt = 0;
    cin >> s >> x >> y;
    int n = int(s.size());
    vector< vector<int> > d(2);
    for (int i = 0; i < n; ++i) switch (s.at(i)) {
        case 'F': ++cnt; break;
        case 'T': d.at(f).push_back(cnt); f ^= 1; cnt = 0; break;
    }
    d.at(f).push_back(cnt);
    vector< vector< vector<bool> > > dp(2);
    for (int i = 0; i < 2; ++i) dp.at(i) = vector< vector<bool> >(d.at(i).size() + 1, vector<bool>(n * 2 + 1)), dp.at(i).at(0).at(n) = 1;
    for (int i = 0; i < 2; ++i) for (int j = 0; j < int(d.at(i).size()); ++j) {
        if ((i | j) == 0) dp.at(0).at(1).at(n + d.at(0).at(0)) = 1;
        else for (int k = 0; k <= 2 * n; ++k) if (dp.at(i).at(j).at(k)) dp.at(i).at(j + 1).at(k + d.at(i).at(j)) = 1, dp.at(i).at(j + 1).at(k - d.at(i).at(j)) = 1;
    }
    cout << (dp.at(0).back().at(n + x) && dp.at(1).back().at(n + y) ? "Yes" : "No") << '\n';
    return 0;
}


Measured memory_bytes: 16128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

const int INF = 10000000000000;

int n, a[200010];
vector<int> vec[200010];
int d[200010];
int ans[200010];
stack<int> st[200010];

void dfs(int v, int p) {
	int x = lower_bound(d, d + 200005, a[v]) - d;
	st[x].push(a[v]);
	d[x] = a[v];
	ans[v] = lower_bound(d, d + 200005, INF) - d - 1;
	for (int i = 0; i < (int)vec[v].size(); i++) {
		if (vec[v][i] == p)continue;
		dfs(vec[v][i], v);
	}
	st[x].pop();
	d[x] = st[x].top();
}

signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++)cin >> a[i];
	for (int i = 0; i < n - 1; i++) {
		int u, v; cin >> u >> v;
		vec[u].push_back(v);
		vec[v].push_back(u);
	}
	fill(d, d + 200005, INF);
	for (int i = 0; i < 200005; i++)st[i].push(INF);
	d[0] = 0;
	vec[0].push_back(0);
	dfs(1, 0);
	for (int i = 1; i <= n; i++)cout << ans[i] << endl;
}

Measured memory_bytes: 169348
import bisect,collections,copy,heapq,itertools,math,operator,string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int,input().split()))
def LS(): return list(input().split())
##################################################
S = S()
condition1 = S[0]=='A'
condition2 = S[2:-1].count('C')==1
S = S.replace('A','a',1)
S = S.replace('C','c',1)
condition3 = S.islower()
print('AC' if condition1 and condition2 and condition3 else 'WA')


Measured memory_bytes: 3888
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    static int count = 0;
    static int heights[];
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        heights = new int[n];

        for(int i = 0; i < n; i++){
            heights[i] = sc.nextInt();
        }
        while(true){

            int sum = 0;
            for(int i = 0; i < heights.length; i++){
                sum += heights[i];
            }
            if(sum == 0){
                System.out.println(count);
                break;
            }
            reduceHeight(heights);
            //System.out.println(count + ":" + sum);

        }

    }

    private static void reduceHeight(int[] heights) {
        int min = 0;
        int max = heights.length;
        for(int i = 0; i < heights.length; i++){
            if(heights[i] > 0){
                min = i;
                break;
            }
        }

        for(int i = min; i < heights.length; i++){
            if(heights[i] == 0){
                max = i;
                break;
            }
        }
        for(int i = min; i < max; i++){
            heights[i] = heights[i] - 1;
        }

        count++;

    }


}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <climits>
using namespace std;
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repb(i,r,l) for(int i=r;i>l;i--)
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator 

void solve() {
    int n;cin>>n;
    deque<int> q;
    for(int i=0;i<n;i++) {
        int x;cin>>x;
        if(i&1) {
            q.push_front(x);
        } else {
            q.push_back(x);
        }
    }
    if(n%2 ==0)
        while(!q.empty()) {
            cout<<q.front()<<" ";
            q.pop_front();
        }
    else
        while(!q.empty()) {
            cout<<q.back()<<" ";
            q.pop_back();
        }
}

int main() {
    solve();
    return 0;
}

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

int main()
{
  uint64_t a, b, n;
  cin >> n >> a >> b;
  uint64_t r = (n % (a + b));
  if (r > a)
    r = a;
  cout << (n / (a + b)) * a + r << endl;
}


Measured memory_bytes: 256
#include <cstdio>

int main(){
	int n;
	int a[100];
	
	scanf(" %d", &n);
	for(int i=0; i<n; ++i)
		scanf(" %d", &a[i]);

	for(int i=n-1; i>=0; --i) {
		printf("%d", a[i]);
		if(i!=0) printf(" ");
	}
	printf("\n");

	return 0;
}



Measured memory_bytes: 2680
#include<stdio.h>
#define N 100

int main(){
  int n,p[N+1],m[N+1][N+1];
  int i,j,l,min,k;
  
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d %d",&p[i-1],&p[i]);
  }

  for(i=1;i<=n;i++)m[i][i]=0;

  
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=10000000;
      for(k=i;k<=j-1;k++){
	min=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	if(m[i][j]>=min)m[i][j]=min;
      }
    }
  }
  printf("%d\n",m[1][n]);

  return 0;
}

Measured memory_bytes: 636
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")

using namespace std;
using namespace __gnu_pbds;

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifdef HOME
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;
typedef gp_hash_table < int, int > fast;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 5, M = 1e3 + 5, LG = 20;
const int INF = INT_MAX;
const db PI = acos(-1), EPS = 1 / db(1e6);
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

void test() {
    int n;
    cin >> n;
    int a[n], b[n], c[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        --a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    for (int i = 0; i < n - 1; ++i) {
        cin >> c[i];
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += b[a[i]];
        if (i and a[i - 1] == a[i] - 1) {
            ans += c[a[i - 1]];
        }
    }
    cout << ans << "\n";
}

int main() {
    fast_io();
    #ifdef HOME
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    cout << fixed << setprecision(15);
    test();
    #ifdef HOME
        cout << "Time: " << (int)(clock() * 1000. / CLOCKS_PER_SEC) << "ms";
    #endif
    return 0;
}


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

odd_n = 0
for i in range(n):
    if a[i] % 2 == 1:
       odd_n += 1
        

if odd_n == 0:
    if p == 0:
        print(2**n)
    else:
        print(0)

else:
    print(2**(n-1))

Measured memory_bytes: 38256
import java.util.Scanner;

//Bubble Sort
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int[] a = new int[n];
			for(int i=0;i<n;i++)a[i]=sc.nextInt();
			int s = 0;
			for(int j=n-1;j>=1;j--){
				for(int i=0;i<j;i++){
					if(a[i+1]<a[i]){
						int t = a[i];
						a[i]=a[i+1];
						a[i+1]=t;
						s++;
					}
				}
			}
			System.out.println(s);
		}
	}
}

Measured memory_bytes: 28588
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 760
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const long long MOD=1000000007;

// vector<p> cut(M); vector<vector<ll> > v(4);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()), sort(v.rbegin(), v.rend()); //sort
// char '' str ""
int main(void)
{
    str S; cin>>S; str ans;
    int up = (S[0] - '0')*10 + (S[1] - '0') ;
    int down = (S[2] - '0')*10 + (S[3] - '0') ;
    if(0 < up && up <= 12 && 0 < down && down <= 12) ans ="AMBIGUOUS";
    else if(0 < up && up <= 12) ans = "MMYY";
    else if(0 < down && down <= 12) ans = "YYMM";
    else ans = "NA";

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


Measured memory_bytes: 256
fn main() {
    let input: Vec<String> = read_vec();
    let a = &input[0];
    let b = &input[1];

    println!("{}", solve(a, b));
}

fn read<T: std::str::FromStr>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn solve(a: &str, b: &str) -> i64 {
    let n1: i64 = a.parse().ok().unwrap();
    let n2: i64 = b.replace(".", "").parse().ok().unwrap();
    (n1 * n2) / 100
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_solve_1() {
        assert_eq!(217, solve("198", "1.10"));
    }

    #[test]
    fn test_solve_2() {
        assert_eq!(0, solve("1", "0.01"));
    }

    #[test]
    fn test_solve_3() {
        assert_eq!(9990000000000000, solve("1000000000000000", "9.99"));
    }
}


Measured memory_bytes: 2100
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
inline int Rand(){return rand()*32768+rand();}
int n,a[3005];
vector<int>g[3005];
bool dfs(int x,int p){
	for(auto to:g[x])if(to!=p){
		if(!dfs(to,x)&&a[x]>a[to])return 1;
	}
	return 0;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<n;i++){
		int x,y;cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(int i=1;i<=n;i++){
		if(dfs(i,-1)){
			cout<<i<<" ";
		}
	}
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
signed main(){
    int n,k;
    cin>>n>>k;
    int r,s,p;
    cin>>r>>s>>p;
    string t;
    cin>>t;
    ll count=0,count2=k;
  	vector<bool> flag(n+k+3);
  	rep(i,n+k+3){
      flag[i]=false;
      if(i<k){
        flag[i]=true;
      }
    }
    rep(i,n){
        if(flag[i]){
            if(t[i]=='r'){
                count+=p;
            }
            if(t[i]=='s'){
                count+=r;
            }
            if(t[i]=='p'){
                count+=s;
            }
        }
        else{
            if(t[i]=='r' && t[i-k]!='r'){
                count+=p;
            }
          	else if(t[i]=='r'){
              flag[i+k]=true;
            }
            if(t[i]=='s' && t[i-k]!='s'){
                count+=r;
            }
          	else if(t[i]=='s')
              flag[i+k]=true;
            if(t[i]=='p' && t[i-k]!='p'){
                count+=s;
            }
          	else if(t[i]=='p')
              flag[i+k]=true;
        }
    }
    cout<<count<<'\n';
    return(0);
}

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

int n;
int t[10001],s[10001];

int main(void){
	while(cin>>n,n){
		for(int i=0;i<n;i++) cin>>t[i];
		for(int i=0;i<n;i++) cin>>s[i];
		sort(s,s+n);
		reverse(s,s+n);

		bool flg = true;
		for(int i=0;i<n;i++){
			if(flg){
				for(int j=0;j<n;j++){
					if(t[j] > 0){
						t[j]--;
						s[i]--;
					}
					if(s[i] < 0) flg = false;
				}
				if(s[i] > 0) flg = false;
			}
		}

		cout<<(flg ? "Yes" : "No")<<endl;
	}

	return 0;
}

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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>;

int gcd(int x, int y){
    if(x % y == 0) return y;
    return gcd(y, x % y);
}

int main(){
    int k; cin>>k;
    ll ans = 0;
    rep1(i,k){
        rep1(j,k){
            int now = gcd(i,j);
            rep1(n,k){
                ans += gcd(now,n);
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3604
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    String t = scan.next();
    int count = 0;
    for (int i=0;i<n-2;i++){
      if ((t.charAt(i) == 'A') && (t.charAt(i+1) == 'B') && (t.charAt(i+2) == 'C')){
        count += 1;
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 35644
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+1;
int n,cnt,a[N],b[N],v[N];
int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
int main(){
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=(n>>1)+1;i<=n;i++) b[i]=a[i];
	for(int i=n;i>=1;i--){
		int re=0;
		for(int j=i<<1;j<=n;j+=i) re+=b[j];
		re=re&1;if(re!=a[i]) b[i]=1,v[++cnt]=i;
	}
	printf("%d\n",cnt);
	for(int i=cnt;i;i--) printf("%d ",v[i]);
 	return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
    using namespace std;
    int A,B,C,D,E,F;
    set<int>water;
    set<int>sugar;
    int main(void)
    {
        cin>>A>>B>>C>>D>>E>>F;
        for(int a=0;100*a<=F;a+=A)
        {
            for(int b=0;100*b+100*a<=F;b+=B)
            {
                water.insert(100*a+100*b);
            }
        }
        water.erase(0);
        for(int c=0;c<=F;c+=C)
        {
            for(int d=0;d<=F;d+=D)
            {
                sugar.insert(c+d);
            }
        }
        int perfact_water;
        int perfact_sugar;
        double perfact_density=0.0;
        for(auto wa:water)
        {
            for(auto su:sugar)
            {
                if(wa+su<=F)
                {
                    double density=su*1.0/wa;
                    if(density<=E/100.0&&density>=perfact_density)
                    {
                         perfact_density=density;
                         perfact_water=wa;
                         perfact_sugar=su;
                    }
                }
            }
        }
        cout <<perfact_water+perfact_sugar<<" "<<perfact_sugar<<endl;
        return 0;
        }

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<stdio.h>
using namespace std;

static const int INFTY = 20001;

double w[510][510];
double e[510][510];
int root[510][510];

int main(){

    int n;
    double P, Q, t; //グローバル変数にする必要がある
    vector<double> p, q;
    
    //入力処理
    cin >> n;
    p.push_back(0);
    for(int i=0; i<n; i++){
        cin >> P;
        p.push_back(P); 
    }
    for(int i=0; i<n+1; i++){
        cin >> Q;
        q.push_back(Q);
    }

    for(int i=1; i<=n+1; i++){
        e[i][i-1] = q[i-1];
        w[i][i-1] = q[i-1];
    }
    for(int l=1; l<=n; l++){
        for(int i=1; i<=n-l+1; i++){
            int j = i + l - 1;
            e[i][j] = 20001;
            w[i][j] = w[i][j-1] + p[j] + q[j];
            for(int k=i; k<=j; k++){
                t = e[i][k-1] + e[k+1][j] + w[i][j];    //期待値
                if(t < e[i][j]){    //最小値を探す
                    e[i][j] = t;
                    root[i][j] = k;
                }
            }
        }
    }
    printf("%.8lf\n", e[1][n]);
    return 0;
}


Measured memory_bytes: 8348
#include <bits/stdc++.h>
#define INF 1e9

using namespace std;

int n;
int G[210][210], dep[210];

void dfs(int p, int dpth)
{
	if (dep[p])
	{
		if (dep[p] % 2 != dpth % 2)
		{
			cout << -1 << endl;
			exit(0);
		}
		return;
	}
	dep[p] = dpth;
	for (int i = 1; i <= n; i++)
		if (G[p][i] == 1)
			dfs(i, dep[p] + 1);
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
		{
			char ch; cin >> ch;
			G[i][j] = ch - '0';
			if (!G[i][j]) G[i][j] = INF;
		}
	dfs(1, 1);
	for (int k = 1; k <= n; k++)
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
	int ans = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j < i; j++)
			ans = max(ans, G[i][j]);
	cout << ans + 1 << endl;
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<set>
#include<cmath>
using namespace std;



int main(){
  int h ,n,x,result = 0;
  	cin >> h >> n;
  	while(n--){
    	cin >> x;
      	result += x;
      	if(result>=h){
          cout << "Yes" << endl;
          return 0;
        } 
    }
  	cout << "No" << endl;
  
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int num = S.length();
    int max = 0;
    int count = 0;
    
    for(int i=0; i<num; i++) {
      String str = S.substring(i,i+1);
      if(str.equals("A") || str.equals("C") || str.equals("G") || str.equals("T")) {
        count++;
      	if(max < count) {
        	max = count;
      	}
      } else {
        count = 0;
      }

    }
   System.out.println(max);
  }
}

Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){

    bool dic[26]={false};

    string S;
    cin >> S;
    int result;

    for(int i=0; i<S.size(); i++){
        dic[S[i]-97] = true;
    }

    int cnt=0;

    for(int i=0; i<26; i++){
        if(dic[i] == true) cnt++;

        if(dic[i] == false){
            result = i;
            break;
        }
    }

    if(cnt == 26){
        printf("None\n");
    }else{
        printf("%c\n", result+97);
    }
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define DUMP(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<": "<<(x)<<" (L"<<__LINE__<<")"<<endl
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;
using ll = long long;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int main() {
    string s; cin >> s;
    vint c(30, 0);
    rep(i, s.size()) {
        c[s[i]-'a']++;
    }
    rep(i, 30) if(c[i] >= 2) { cout << "no" << endl; return 0; }
    cout << "yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n;
long long m;
long long s[100005];
long long l[100005];
long long r[100005];
bool used[100005];
vector<pair<long long,int> > v;

 main(){
    scanf("%lld%lld",&n,&m);
    for (int x = 0; x<n; x++){
        scanf("%lld%lld%lld",&s[x],&l[x],&r[x]);
    }
    long long t=0;
    for (int x = 0; x<n; x++){
        v.push_back({s[x]*l[x]+(m-s[x])*r[x],x});
        t += s[x]*l[x];
    }
    sort(v.begin(),v.end(),greater<pair<long long,int> >());
    long long ans = 0;
    //printf("amt req %lld\n",t);
    int c = 0;
    for (auto x : v){
        //printf("try use %lld\n",x.first);
        if (x.first>t) break;
        t -= x.first;
        ans += m;
        used[x.second] = true;
        c++;
    }
    long long best = m;
    for (int x = 0; x<n; x++){
        if (used[x]) {
            int diff = s[x]*l[x]+(m-s[x])*r[x] - v[c].first;
            if (s[x]*l[x]>=t+diff){
                best = min(best,(t+diff-1)/l[x]+1);
            }
            else{
                best = min(best,s[x]+(t+diff-l[x]*s[x]-1)/r[x]+1);
            }
        }
        else if (s[x]*l[x]>=t){
            best = min(best,(t-1)/l[x]+1);
        }
        else{
            best = min(best,s[x]+(t-l[x]*s[x]-1)/r[x]+1);
        }
        //printf("best at %d, %lld\n",x,best);
    }
    if (t>0){
        ans += best;
    }
    printf("%lld",ans);
}


Measured memory_bytes: 7748
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

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


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

using namespace std;

const string YES = "Yes";

const string NO = "No";

void solve(int N, vector<int> A, vector<int> B) {
    vector<int> cnt_A(N + 1), cnt_B(N + 1);
    for (int i = 0; i < N; i++) {
        cnt_A.at(A.at(i))++;
        cnt_B.at(B.at(i))++;
    }
    for (int i = 1; i <= N; i++) {
        if (cnt_A.at(i) + cnt_B.at(i) > N) {
            cout << NO << endl;
            return;
        }
    }
    cout << YES << endl;
    vector<int> C(N + 1), D(N + 1);
    for (int i = 1; i <= N; i++) {
        C.at(i) = C.at(i - 1) + cnt_A.at(i);
        D.at(i) = D.at(i - 1) + cnt_B.at(i);
    }
    int x = 0;
    for (int i = 1; i <= N; i++) {
        x = max(x, C.at(i) - D.at(i - 1));
    }
    for (int i = 0; i < N - 1; i++) {
        cout << B.at((i - x + N) % N) << " ";
    }
    cout << B.at((N - 1 - x + N) % N) << endl;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    vector<int> B(N);
    for (int i = 0; i < N; i++) {
        cin >> B.at(i);
    }
    solve(N, move(A), move(B));
    return 0;
}


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


#define li          int
#define uli         unsigned long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


int main() {
    li n;
    cin>>n;
    li res=0;
    repp(i,1,n+1){
        res += (n-1)/i;
    }
    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

int main() {
    int H, W;
    while(1) {
        cin >> H >> W;
        if(H < 1 | W < 1)
            break;
        rep(i, H) {
            rep(j, W) cout << '#';
            cout << endl;
        }
        cout << endl;
    }
}



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

 int P,Q,R;
  cin>>P>>Q>>R;
  int max=P;
  if(max<Q)
    max=Q;
  if(max<R)
    max=R;
  cout<<P+Q+R-max<<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 REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
template<typename T, typename U>
inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; }

typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;
const int MOD = 1e9+7;
int main(){
    int n;
    cin >> n;
    cout << (n + 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
/* 
 *     author-->@harshrajani460
 *     codeforces round-567
 *
 */
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define pb push_back
#define ff first
#define ss second
#define sz size()
#define mp make_pair
#define p(x) cout<< x << " ";
#define pe(x) cout<< x << endl ;
#define deb(x) cout<<#x<<" : "<<x<<endl;
#define debug(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define el endl
#define M 998244353 
#define int long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROR(i,a,b) for(int i=a;i>=b;i--)
const int N = 1e5 + 5;
double dp[3003][3003],pro[3003];
void solve()
{
    int n;
    cin>>n;
    FOR(i,1,n+1)
    cin>>pro[i];
    FOR(i,0,n+1) dp[0][i]=0;
    dp[0][0]=1;
    FOR(i,1,n+1)
    {
        FOR(j,0,n+1)
        {
            dp[i][j]=(j?dp[i-1][j-1]*pro[i]:0)+dp[i-1][j]*(1-pro[i]);
        }
    }
    
    double ans=0;
    FOR(j,0,n+1)
    if(2*j>n) ans+=dp[n][j];
    cout<<fixed<<setprecision(10)<<ans<<endl;    
}
int32_t main() 
{ 
    solve();
   
} 

Measured memory_bytes: 70656
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define ll long long

int GCD(int a, int b)
{
	if (b == 0)
	{
		return a;
	}

	return GCD(b, a % b);
}

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

	vector<int> arr(n);

	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}

	int gcd = abs(arr[0] - x);
	for (int i = 0; i < n - 1; i++)
	{
		gcd = GCD(gcd, abs(arr[i] - arr[i + 1]));
	}
	cout << gcd << endl;
}

Measured memory_bytes: 640
A,B=map(int,input().split())
count=0
for C in range(A,B+1):
    s=str(C)
    res=True
    for i in range(len(s)//2):
        if s[i]!=s[-1-i]:
            res=False
            break

    if res:
        count+=1

print(count)


Measured memory_bytes: 9080
import collections


if __name__ == '__main__':
    n = int(input())
    A = list(map(int,input().split()))

    tmp_A = []
    for a in A:
        tmp_A.append(a-1)
        tmp_A.append(a)
        tmp_A.append(a+1)

    c = collections.Counter(tmp_A)
    most_common_element = c.most_common()[0][0]

    answer = 0
    for a in A:
        if a == most_common_element or a-1 == most_common_element or a+1 == most_common_element:
            answer += 1
    print(answer)



Measured memory_bytes: 30940
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    int a[100010];
    cin >> N;
    rep(i,0,N){
        cin >> a[i];
    }
    sort(a, a+N);
    int mx = *max_element(a, a+N);
    int ans = 0;
    rep(i,0,mx+1){
        int cnt = upper_bound(a, a+N, i+1) - lower_bound(a, a+N, i-1);
        ans = max(ans, cnt);
    }
    print(ans);

}


Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
	int n,a[100],i,k,x,flg,y;
	scanf("%d",&n);
	x=0;
	for(i=0;i<n;i++){ 
		scanf("%d",&a[i]); if(a[i]%10==0) x++;
	}
	if(x==n) printf("0\n");
	else{
		for(i=0;i<n-1;i++){
			for(k=i+1;k<n;k++){
				if(a[i]>a[k]){
					x=a[i]; a[i]=a[k]; a[k]=x;
				}
			}
		}
		x=0;
		for(i=0;i<n;i++){
			x=x+a[i];
		}
		if(x%10==0) flg=1;
		else flg=0;
		if(flg==1){
			for(i=0;i<n;i++){
				if(a[i]%10!=0) break;
			}
			x=x-a[i]; 
		}
		printf("%d\n",x);
	}
	return 0;
}

Measured memory_bytes: 128