akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
#define N 2000005
char a[N],b[N];
int p[N];
bool ok[N];
int in[N];
int f[N];
signed main()
{
	scanf("%s",a+1);
	scanf("%s",b+1);
	int n=strlen(a+1);
	int m=strlen(b+1);
	int j=0;
	for(int i=n+1;i<=n*2;i++)
	{
		a[i]=a[i-n];
	}
	n*=2;
	while(n<m*2)
	{
		for(int i=n+1;i<=n*2;i++)
		{
			a[i]=a[i-n];
		}
		n*=2;
	}
	for(int i=2;i<=m;i++)
	{
		while(j>0&&b[j+1]!=b[i]) j=p[j];
		if(b[j+1]==b[i]) j++;
		p[i]=j;
	}
	j=0;
	int res=0;
	for(int i=1;i<=n;i++)
	{
		while(j>0&&a[i]!=b[j+1]) j=p[j];
		if(a[i]==b[j+1]) j++;
		if(j==m)
		{
//			cout<<i<<endl;
			ok[i-m+1]=true;
			if(i-m+1>n/2) continue;
			if(i+1>n/2)
			{
				in[i+1-n/2]++;
			}
			else
			{
				in[i+1]++;
			}
		}
	}
	for(int i=1;i<=n/2;i++)
	{
//		printf("%d %d\n",ok[i],in[i]);
		if(ok[i]==true) res++;
	}
//	cout<<res<<endl;
	queue<int> q;
	int tot=0;
	for(int i=1;i<=n/2;i++)
	{
		if(in[i]==0&&ok[i]==true)
		{
			f[i]=1;
			q.push(i);
			tot++;
		}
//		if(ok[i]==false&&in[i]!=0)
//		{
//			int x=i-m;
//			if(x<0) x+=n/2;
//			q.push(x);
//			tot++;
//		}
	}
	while(!q.empty())
	{
		int t=q.front();
		q.pop();
//		cout<<t<<endl;
		int x=t+m;
		if(x>n/2) x-=n/2;
		if(ok[x]==true)
		{
			f[x]=max(f[x],f[t]+1);
			in[x]--;
			if(in[x]==0)
			{
				tot++;
				q.push(x);
			}
		}
	}
	if(tot<res)
	{
		cout<<"-1\n";
		return 0;
	}
	int maxn=0;
	for(int i=1;i<=n/2;i++)
	{
		if(f[i]>maxn) maxn=f[i];
	}
	cout<<maxn<<endl;
#ifndef ONLINE_JUDGE
//	printf("Time Used : %d\n",clock());
#endif
	return 0;
}



Measured memory_bytes: 21632
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

ll W, H, N;
ll eval(ll x, ll y){
    if(0 < x && x < W && 0 < y && y < H)return -1;
    ll ret = 0;
    if(y == 0)ret = x;
    else if(x == W)ret = W + y;
    else if(y == H)ret = W + H + W - x;
    else ret = W + H + W + H - y;
    return ret;
}

int main(){
    
    cin >> W >> H >> N;
    vector<P>v;
    rep(i, N){
        ll x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        ll a = eval(x1, y1);
        ll b = eval(x2, y2);
        if(a < 0 || b < 0)continue;
        v.push_back(P(a, i));
        v.push_back(P(b, i));
    }
    sort(v.begin(), v.end());
    stack<ll>S;
    rep(i, v.size()){
        ll x = v[i].second;
        if(S.empty() || S.top() != x)S.push(x);
        else S.pop();
    }
    if(S.empty())cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 6512
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll X, t;
    cin >> X >> t;
    if (X-t > 0) {
        cout << X - t << endl;
    }
    else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

struct Vector {
    double x, y;
    Vector(double x, double y): x(x), y(y){
    }
};

typedef Vector Point;

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

Vector operator+(const Vector& a, const Vector& b) {
    return Vector(a.x + b.x, a.y + b.y);
}
Vector operator-(const Vector& a, const Vector& b) {
    return Vector(a.x - b.x, a.y - b.y);
}
Vector operator*(const Vector& a, const double p) {
    return Vector(a.x * p, a.y * p);
}

Vector reflect(const Point& a, const Point& b, const Point& p) {
    Vector v = b - a;
    double t = dot(p - a, v) / dot(v, v);
    Vector m = a + v * t;
    return p + (m - p) * 2;
}

int main() {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    Point a(x1, y1);
    Point b(x2, y2);
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        double x, y;
        cin >> x >> y;
        Vector ans = reflect(a, b, Point(x,y));
        cout << setprecision(8) << fixed << ans.x << " " << ans.y << endl;
    }
   
}

Measured memory_bytes: 3276
#include<stdio.h>
int main(){
    int a,b;
    char op;
    while(1){
        scanf("%d %c %d",&a,&op,&b);
        if(op=='?'){
            break;
        }else if(op=='+'){
            printf("%d\n",a+b);
        }else if(op=='-'){
            printf("%d\n",a-b);
        }else if(op=='*'){
            printf("%d\n",a*b);
        }else if(op=='/'){
            printf("%d\n",a/b);
        }
    }
    return 0;
}

Measured memory_bytes: 1804
from collections import deque
import fractions as fr
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

n ,k= map(int,input().split())
a = tuple(map(int,input().split()))

ans = 0
x=a[0]
for i in range(1,n):
    x =fr.gcd(x,a[i])
    # print(x)
if max(a)<k:
    print("IMPOSSIBLE")
elif k in a:
    print("POSSIBLE")
elif k%x == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 16288
class Node
  attr_accessor :parent, :depth, :type, :child
  def initialize(parent, type)
    @parent = parent
    @type = type
    @depth = 0
    @child = []
  end
end

def setdepth(tree, depth, child)
  if child.size != 0 then
    child.each{|i|
      tree[i].depth = depth
      setdepth(tree, depth+1, tree[i].child)
    }
  end
end
n = gets.to_i
tree = Array.new(n){Node.new(-1, "leaf")}
n.times{
  i, m, *child = gets.split.map(&:to_i)
  if m > 0 then
    tree[i].type = "internal node"
    child.each{|j|
      tree[j].parent = i
    }
    tree[i].child = child
  end
}

#find root
0.upto(n-1){|i|
  if tree[i].parent == -1 then
    tree[i].type = "root"
    tree[i].depth = 0
    #calc depth
    setdepth(tree, 1, tree[i].child);
    break
  end
}


0.upto(n-1){|i|
  printf "node %d: parent = %d, depth = %d, %s, [%s]\n", i, tree[i].parent, tree[i].depth, tree[i].type, tree[i].child.join(", ")
}

Measured memory_bytes: 43076
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>

using namespace std;

int main() {
	long n, a, b; cin >> n >> a >> b;
	if (a > b) { cout << 0 << endl; }
	else if (n <= 1 && a < b) { cout << 0 << endl; }
	else {
		cout << (n - 2) * (b - a) + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
using System;

namespace AtCoder
{
    class Program
    {
        static void Main (string[] args)
        {
            int input = int.Parse (Console.ReadLine ());
            if (1000 > input)
            {
                Console.WriteLine ("ABC");
            }
            else if (input <= 1998)
            {
                Console.WriteLine ("ABD");
            }

        }
    }
}

Measured memory_bytes: 13140
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int A = sc.nextInt();
        
        if((N % 500) - A <= 0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}
 

Measured memory_bytes: 23252
while True:
    h,w = map(int,input().split())
    if h == 0 and w == 0:
        break
    for i in range(h):
        for k in range(w):
            if (i+k)%2 == 0:
                print("#",end = "")
            else:
                print(".",end = "")
        print()

    print()


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

using namespace std;

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

// 組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] / (fac[k] * fac[n - k]);
}


ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
char c[310][310];
ll dp[101];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	vector<ll>l(n);
	rep(i, n) {
		cin >> l[i];
	}
	sort(l.begin(), l.end());
	ll ans = 0;
	rep(i, n) {
		for (ll j = i + 1;j < n;++j) {
			ll res= lower_bound(l.begin(), l.end(), l[i] + l[j]) - l.begin();
			ll res2 = j + 1;
			ans += max((ll)0, res - res2);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3644
//yukicoder@cpp14
//author:luckYrat(twitter:@luckYrat_)
//競技プログラミングから逃げるな
//https://www.youtube.com/watch?v=z_B9iJ8r4ic

//せんげん！
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

#include <cctype>
#include <utility>
#include <climits>


//なまえくーかん！
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

//てーすう！
const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);

//でふぁいん！
#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)

//みじかく！
#define pb push_back
#define fir first
#define scn second
#define ednl endl

//いぇすのー！
#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")

//きんぼーnほーこー！！
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/
vector<int> A[100001];
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
  int n,m;cin>>n>>m;
  for(int i = 0; n > i; i++){
    ll a,b;cin>>a>>b;
    A[a].push_back(b);
  }
  priority_queue<ll> Z;
  ll ans = 0;
  for(int i = 0; m >= i; i++){
    for(int j = 0; A[i].size() > j; j++){
      Z.push(A[i][j]);
    }
    if(!Z.empty()){
      ans += Z.top(),Z.pop();
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5632
<?php
const MOD = 10 ** 9 + 7;
list($n) = ints();
$t = ints();
$a = ints();
$t[-1] = 0;
for ($i = 0; $i < $n; ++$i) {
    if ($t[$i] > $t[$i - 1]) $ht[$i] = [$t[$i], $t[$i]];
    else $ht[$i] = [1, $t[$i]];
}
$a[$n] = 0;
for ($i = $n - 1; $i >= 0; --$i) {
    if ($a[$i] > $a[$i + 1]) $ha[$i] = [$a[$i], $a[$i]];
    else $ha[$i] = [1, $a[$i]];
}
$cnt = 1;
for ($i = 0; $i < $n; ++$i) {
    $cnt *= max(0, min($ht[$i][1], $ha[$i][1]) - max($ht[$i][0], $ha[$i][0]) + 1);
    $cnt %= MOD;
}

echo $cnt;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 108456
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  ll N;
  cin>>N;
  ll tmp(0);
  for (ll i(1);i*i<=N;i++){
    if (N % i == 0){
      tmp = max(tmp,i);
    }
  }
  cout << tmp + N/tmp -2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
ll dist[310][310], dis[310][310];
int main()
{
    ll n, m, l;
    while(cin>>n>>m>>l)
    {
        ll ans=0;
        int x, y, c;
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                dist[i][j]=1e15;
            }
            dist[i][i]=0;
        }
        for(int i=0; i<m; ++i)
        {
            scanf("%d%d%d",&x,&y,&c);
            --x;
            --y;
            if(c<=l)
                dist[x][y]=dist[y][x]=c;
        }
        for (int k = 0; k < n; k++)
        {
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (dist[i][k] + dist[k][j] < dist[i][j])
                        dist[i][j] = dist[i][k] + dist[k][j];
                }
            }
        }
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                if(dist[i][j]<=l){
                    dis[i][j]=1;
                }
                else{
                    dis[i][j]=1e15;
                }
            }
            dis[i][i]=0;
        }

        for (int k = 0; k < n; k++)
        {
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (dis[i][k] + dis[k][j] < dis[i][j])
                        dis[i][j] = dis[i][k] + dis[k][j];
                }
            }
        }
        int q;
        cin>>q;
        for(int i=0; i<q; ++i){
            scanf("%d%d",&x,&y);
            --x;--y;
//            cout<<dis[x][y]<<endl;
            if(dis[x][y]>1e14){
                printf("-1\n");
            }
            else{
                printf("%lld\n",max(0ll, dis[x][y]-1));
            }
        }
    }
    return 0;
}




Measured memory_bytes: 2048
import sys

N = int(input())
s = [int(input()) for _ in range(N)]
ss = sum(s)
s = sorted(s)

if ss % 10 != 0:
    print(ss)
else:
    for i in s:
        if i % 10 != 0:
            print(ss - i)
            sys.exit()
    print(0)

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

using namespace std;

bool solve()
{
  int N;
  cin >> N;
  int a = 0, b = 0;
  map<int, int> m;
  for (int i = 0; i < N; i++) {
    int t;
    cin >> t;
    m[t]++;
    if (a && a != t) b = t;
    else a = t;
  }
  if (m.size() > 2) return false;
  if (m.size() == 1) {
    if (a == N-1) return true;
    if (a * 2 <= N) return true;
    return false;
  }
  if (a > b) {
    swap(a, b);
  }
  if (b - a != 1) return false;
  int c = b - m[a];
  if (c <= 0) return false;
  if (c * 2 > m[b]) return false;
  return true;
}

int main()
{
  if (solve()) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  int n, l; cin >> n >> l;
  vi a(n);

  int sum = 0;
  rep(i, n) {
    int x = l + i;
    sum += x;
    a[i] = x;
  }

  int mn = inf, ans;
  rep(i, n) {
    int v = sum - a[i];
    if (mn > abs(sum - v)) {
      mn = abs(sum - v);
      ans = v;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3584
#include<stdio.h>
#define SIZE 101

int main(void)
{
    int slen, plen, i, j;
    char s[SIZE], p[SIZE], c;
    
    for( i=0; (s[i]=getchar()) != '\n'; ++i)
        ;
    slen = i;
    
    for( j=0; (p[j]=getchar()) != '\n'; ++j)
        ;
    plen = j;
    
    for ( i=0; i<slen; ++i)
        for ( j=0; j<plen; ++j) {
            if ( p[j] != s[(i+j)%slen])
                break;
            if ( j == plen-1) { /* 一致した */
                printf("Yes\n");
                return 0;
            }
        }

    /* 一致しなかった */
    printf("No\n");

    return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
#define forr(i,m,n) for (int i=(m); i<=(n); i++)
#define forv(i,m,n) for (int i=(m); i>=(n); i--)
#define forall(it,p) for (auto it = p.begin(); it != p.end(); ++it)
#define R 1000000007
#define DBG 1
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair< int, pair<int,int> > piii;

#define MAXN 500001
ll bit[MAXN];
int n;

ll bitsum(int i) {
  ll s = 0;
  while (i>0) {
    s += bit[i];
    i -= i & -i;
  }
  return s;
}

void bitadd(int i, ll x) {
  while (i<=n) {
    bit[i] += x;
    i += i & -i;
  }
}

int main() {
  int q;
  cin >> n >> q;
  vector<int> a(n+1);
  forr(i,1,n)
    cin >> a[i];
  vector<piii> rli;
  forr(i,0,q-1) { int l,r;
    cin >> l >> r;
    rli.push_back(make_pair(r, make_pair(l,i)));
  }
  sort(rli.begin(), rli.end());
  //cerr << 1 << endl;

  vector<ll> ans(q);
  vector<ll> last(MAXN,-1);
  forv(j,rli[0].first,1)
    if (last[a[j]]<0) {
      last[a[j]] = j;
      bitadd(j,1);
    }
  //cerr << 2 << endl;

  forr(i,0,q-1) {
    if (i>0) {
      forr(j,rli[i-1].first+1,rli[i].first) {
        if (last[a[j]]>0)
          bitadd(last[a[j]],-1);
        last[a[j]] = j;
        bitadd(j,1);
      }
    }
    ans[rli[i].second.second] = bitsum(rli[i].first) - \
                                bitsum(rli[i].second.first-1);
  }
  forr(i,0,q-1)
    cout << ans[i] << endl;
}


Measured memory_bytes: 23368
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        new Program().Solve();
    }

    Scanner sc = new Scanner();
    void Solve()
    {
        int a = sc.NextInt();
        int b = sc.NextInt();
        int c = sc.NextInt();
        bool div = false;
        if (a + b == c) div = true;
        if (a + c == b) div = true;
        if (b + c == a) div = true;
        if (div) wl("Yes");
        if (!div) wl("No");
    }
    
    // ------------------------------------- //
    void wl(string v) { Console.WriteLine(v); }
    int calcDivisorCount(int n)
    {
        if (n == 1) return n;

        int res = 0;
        int i = 2;
        while (n != 1)
        {
            int cnt = 0;
            while (n % i == 0)
            {
                n /= i;
                cnt++;
            }
            if (cnt > 0) res += (cnt + 1);
            i++;
        }
        return res;
    }
    long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); }
    long lcm(long a, long b) { return a / gcd(a, b) * b; }
}
class Scanner
{
    public Scanner() { }
    private string[] buff = null;
    private int bIndex = 0;
    public string Next()
    {
        if (buff == null || bIndex >= buff.Length)
        {
            buff = Console.ReadLine().Split(' ');
            bIndex = 0;
        }
        return buff[bIndex++];
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
}
class Pair<T, K>
{
    public Pair() { }
    public Pair(T f, K s)
    {
        first = f;
        second = s;
    }
    public T first {get; set;}
    public K second {get; set;}
}


Measured memory_bytes: 2776
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val p = Array.fill(n)(sc.nextInt())
  println {
    (1 until n - 1).count(i => {
      val sorted = p.slice(i - 1, i + 2).sorted
      p(i) == sorted(1)
    })
  }
}


Measured memory_bytes: 55416
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		outer: while (true) {
			/* 読み込み */
			int H = sc.nextInt();
			int W = sc.nextInt();
			/* HWが0のとき入力終了 */
			if (H == 0 && W == 00) {
				break;
			}
			if (H < 3 || H > 300 || W < 3 || W > 300) {
				System.out.println("数値の有効範囲は3<=H, W<=300です");
				continue outer;
			}
			/* 1行目出力 */
			for (int i = 0; i < W; i++) {
				System.out.print("#");
			}
			// 改行
			System.out.println();
			/* 中間行出力 */
			for (int i = 1; i < H - 1; i++) {
				/* 最初の文字を出力 */
				System.out.print("#");
				/* 間の文字を出力 */
				for (int j = 1; j < W - 1; j++) {
					System.out.print(".");
				}
				/* 最後の文字を出力 */
				System.out.println("#");
			}
			/* 最後の行を出力 */
			for (int j = 0; j < W; j++) {
				System.out.print("#");
			}
			System.out.println();
			System.out.println();
		}

	}
}


Measured memory_bytes: 32616
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define fi first 
#define se second
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
// ミント
const int mod = 1e9+7 ;
// 998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//昆布
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n,int k){
    return fact[n]*ifact[n-k] ;
  }
}   c(100005);
 
mint modpow(ll a,ll b){
 if(b==0) return 1 ;
 mint c= modpow(a,b/2) ;
 if(b%2==1) return c*c*a ;
 else return c*c ;
}

mint komb(ll n,ll m){
  mint x=1 ;mint y=1 ;
  rep(i,m){
    x*= n-i ;
    y*= i+1 ;
  }
  return x/y ;
}

 
 map<ll,ll> factor(ll n){  //素因数とオーダーをマップで管理
  map <ll,ll> ord ;  
  for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            int res=0;
            while(n%i==0){
                n/=i;
                res++;
            }
            ord[i]=res;
        }
    }
   if(n!=1) ord[n]++;
   return ord ;
 }

int main(){
  ll n ;cin>>n ;
  string s ; cin>> s ;
  vector<ll> A(26) ;
  rep(i,n){
    int p =  s[i]- 'a' ;
    A[p]++ ;
  }
  mint ans=1 ;
  rep(i,26){
    ans*= (A[i]+1ll) ;
  }
   ans= ans-1ll ;
   cout<<ans<<endl ;
    return 0;
  }
   



Measured memory_bytes: 5124
#include <bits/stdc++.h>
#include <limits.h>
using namespace std;
using Edge = struct{
  int to;
  int a;
  int time;
};
vector<int> edge[100000];
bool used[3][100000];
int ans = -1, S, T;
queue<Edge> q;

void bfs() {
  while (!q.empty()) {
    Edge e = q.front();
    q.pop();
    int eto, ea, t;
    eto = e.to;
    ea = e.a;
    t = e.time;
    if (eto == T && ea == 0) {
      ans = t/3;
      return ;
    }
    for (auto &n: edge[eto]) {
      if (used[(ea+1)%3][n])
        continue;
      q.push({n, (ea+1)%3, t+1});
      used[(ea+1)%3][n] = true;
    }
  }
  return ;
}

int main() {
  int N, M, u, v;
  cin >> N >> M;
  for (int i=0; i<M; i++) {
    cin >> u >> v;
    u--;
    v--;
    for (int j=0; j<3; j++)
      edge[u].push_back(v);
  }
  cin >> S >> T;
  S--;
  T--;
  for (int i=0; i<N; i++)
    for (int j=0; j<3; j++)
      used[j][i] = false;
  used[0][S] = true;
  for (auto &n: edge[S]) {
    q.push({n, 1, 1});
    used[1][n] = true;
  }
  bfs();
  cout << ans << endl;
  return 0;
}

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

map<ll,int> primeFact(ll n) {
	map<ll,int> r;
	for(ll i=2; i*i<=n; i++)
		while(n%i == 0) {
			r[i]++;
			n /= i;
		}

	if(n != 1)
		r[n] = 1;
	return r;
}

ll modinv(ll a, ll m) {
	ll b=m, u=1, v=0;
	while(b) {
		ll t=a/b;
		a -= t*b; swap(a, b);
		u -= t*v; swap(u, v);
	}
	u %= m;
	if(u<0)
		u += m;
	return u;
}


int main() {
	ll N,x=1,s=0;
	cin >> N;
	vector<ll> A(N);
	map<ll,int> L;

	rep(i,N) {
		cin >> A.at(i);
		map<ll,int> t = primeFact(A.at(i));

		for(auto p : t)
			if(!L.count(p.first))
				L[p.first] = p.second;
			else
				L.at(p.first) = max(L.at(p.first), p.second);
	}

	for(auto p : L)
		rep(i,p.second) {
			x *= p.first;
			x %= MOD;
		}

	rep(i,N) {
		s += x * modinv(A.at(i), MOD);
		s %= MOD;
	}

	cout << s << endl;
}

Measured memory_bytes: 896
// Garg's Code
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
 
#define ll long long
#define vec vector < ll >
#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++)
#define rf(i,x,n) for(ll i = x; i >= x; i--) 
#define all(c) c.begin(),c.end()
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const ll MAX = LLONG_MAX, MOD = 1000000007, MODA = 1e9 - 1;
const ll MIN = LLONG_MIN;
const long double PI = 3.1415926535;
int la(ll i)
{
  return i%10;
}
int fi(ll i)
{
  int first;
  while(i != 0)
  {
    first = i%10;
    i /= 10;
  }
  return first;
}
int main()
{
  fast();

  
  ll n;
  cin >> n;
  ll arr[10][10] = {0};
  int last, first;
  f(i,1,n+1)
  {
    last = la(i);
    first = fi(i);
    arr[first][last]++;
  }
  ll ans = 0;
  f(i,1,10)
  {
    f(j,1,10)
    {
      ans += arr[i][j]*arr[j][i];
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
    int n, slimes = 0;
    std::cin >> n;

    std::string str;

    std::cin >> str;

    int i = 0;

    while(i < n)
    {
        slimes++;

        while(str[i] == str[i+1])
        {
            i++;
        }

        i++;
    }

    std::cout << slimes << std::endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int a[100005],b[100005];
int main()
{
	int n, m;
	cin>>n>>m;
	for(int i=0;i<m;i++)cin>>a[i];
	sort(a,a+m);
	for(int i=0;i<m-1;i++){
		b[i]=a[i+1]-a[i];
	}
	int ans=0;
	sort(b,b+m-1);
	for(int i=0;i<m-n;i++)ans+=b[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
 
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！
 
def main():
    s=input()
    k=int(input())
    ans=0
    n=[len(list(v)) for k,v in groupby(s)]
#    print(x)
    if s[0]!=s[-1]:
        y=[len(list(v))//2 for k,v in groupby(s)]
        print(sum(y)*k)
    else:
        x=[len(list(v))//2 for k,v in groupby(s)]
#        print(x)
        if len(x)!=1:
            ans+=x[0]+x[-1]
#            print(ans)
            ans+=sum(x[1:-1])*k
#            print(ans)
            ans+=(k-1)*((n[0]+n[-1])//2)
            print(ans)
        else:
            print(len(s)*k//2)
        
    


if __name__ == '__main__':
    main()

Measured memory_bytes: 5556
def solve(n, k, hhh):
    if n - 1 <= k:
        k = n - 1
    dp = [float('inf')] * n
    dp[0] = 0
    for i in range(n - 1):
        hi = hhh[i]
        for j in range(i + 1, min(n, i + k + 1)):
            dp[j] = min(dp[j], dp[i] + abs(hi - hhh[j]))
    return dp[-1]


n, k = map(int, input().split())
hhh = list(map(int, input().split()))
print(solve(n, k, hhh))


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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define PI 3.1415926535897932385 //pi
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main()
{
    lol result{0};
    string s; cin >> s;
    int len = s.length();
    vector<int> b(2019, 0);
    vector<int> m(len+1);
    m[len] = 0;
    int ten = 1;
    b[0]++;
    REPD(i, len)
    {
        //cout << "s[i]=" << s[i] << '\n';
        m[i] = (m[i+1] + (((lol)s[i]-(lol)'0')*ten))%2019;
        b[m[i]]++;
        ten = (ten*10)%2019;
        //cout << m[i] << endl;
    }
    REP(i, 2019)
    {
        lol x = b[i];
        result += (x*(x-1))/2;
    }
    
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 4380
#include<stdio.h>

char s[15];
int n;

int main(){
	int i;
	while(scanf("%s",s)!=EOF){n=0;
		for(i=0;i<3;i++){
			if(s[i*3]!='s' && s[i*3]==s[i*3+1] && s[i*3]==s[i*3+2])printf("%c\n",s[i*3]),n=1;
			else if(s[i]!='s' && s[i]==s[i+3] && s[i]==s[i+6])printf("%c\n",s[i]),n=1;
		}
		if(s[4]!='s'){
			if(s[0]==s[4] && s[0]==s[8])printf("%c\n",s[0]),n=1;
			if(s[2]==s[4] && s[2]==s[6])printf("%c\n",s[2]),n=1;
		}
		if(n==0)printf("d\n");
	}
	return 0;
}

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

int n,k;
LL t;

int main()
{
	scanf("%d%d",&n,&k);
	
	t=n/k;
	LL ans=t*t*t;
	if (!(k&1)&&n>=k/2)
	{
		t=(n-k/2)/k+1;
		
//		cout<<t<<endl;
		ans+=t*t*t;
	}
	
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
<?php
  define('MOD', 1000000007);

  fscanf(STDIN, "%d %d", $N, $M);
  $a = array_pad(array(), $N + 1, 0);
  $a[-1] = 1;
  $a[0] = 0;
  $ans[-1] = 0;
  $ans[0] = 1;

  for ($i = 0; $i < $M; $i++) {
      fscanf(STDIN, "%d", $t);
      $a[$t] = 1;
  }

  for ($i = 1; $i <= $N; $i++) {
    if ($a[$i] === 1) {
        $ans[$i] = 0;
    } else {
        $ans[$i] = $ans[$i - 2] + $ans[$i - 1];
    }
    $ans[$i] %= MOD;
    // printf("%d %d\n", $i, $ans[$i]);
  }

  echo $ans[$N];


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

int main() {
 int N;
  string S;
 cin >> N >> S;
  
  int count = 0;
  
  for(int i = 0 ; i < N-2 ; i++){
	if(S.at(i)=='A' && S.at(i+1)=='B' && S.at(i+2)=='C'){
    	count++;
    }      
  }
  cout << count << endl;

  
}


Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <string>
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#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 = 10010;

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

    string t;
    rep(loop, q) {
        ll ty;
        cin >> ty;
        if(ty == 1) {
            swap(s, t);
        }
        else {
            ll f;
            char c;
            cin >> f >> c;
            if(f == 1) {
                t += c;
            }
            else {
                s += c;
            }
        }
    }

    reverse(all(t));
    
    t += s;
    
    out(t);
    re0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int h, w, n; scanf("%d%d%d", &h, &w, &n);
	int sx, sy; scanf("%d%d", &sx, &sy); sx--; sy--;
	std::string s, t; cin >> s >> t;
	
	bool ans = true;
	int now = sx;
	for(int i = 0; i < n; i++) {
		if(s[i] == 'D') now++;
		if(now >= h) ans = false;
		if(t[i] == 'U') now = std::max(now - 1, 0);
	}
	now = sx;
	for(int i = 0; i < n; i++) {
		if(s[i] == 'U') now--;
		if(now < 0) ans = false;
		if(t[i] == 'D') now = std::min(now + 1, h - 1);
	}
	now = sy;
	for(int i = 0; i < n; i++) {
		if(s[i] == 'R') now++;
		if(now >= w) ans = false;
		if(t[i] == 'L') now = std::max(now - 1, 0);
	}
	now = sy;
	for(int i = 0; i < n; i++) {
		if(s[i] == 'L') now--;
		if(now < 0) ans = false;
		if(t[i] == 'R') now = std::min(now + 1, w - 1);
	}
	
	if(ans) printf("YES\n");
	else printf("NO\n");
	return 0;
}


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

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

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

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

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    int n;cin>>n;
    vl a(n),b(n);
    rep(i,n){
        cin>>a[i]>>b[i];
        a[i]%=b[i];
    }
    ll cnt=0;
    for(int i=n-1;i>=0;--i){
        if((a[i]+cnt%b[i])%b[i]!=0){
                cnt+=b[i]-(a[i]+cnt%b[i])%b[i];
        }
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(int argc, const char * argv[])
{

    int train[11] = {0};
    int input;
    int store = 0;
    while (scanf("%d", &input) != EOF) {
        if (input != 0) {
            store++;
            train[store] = input;
        }
        else {
            printf("%d\n", train[store]);
            store--;
        }
    }
    return 0;
}

Measured memory_bytes: 600
/*
** Author: MAC45
*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.tie(0);
    //freopen("input.txt","rt",stdin);
    //freopen("output.txt","wt",stdout);
    string S;
    cin >> S;
    S=(S=="ABC"?"ARC":"ABC");
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{   int n;
    cin>>n;
    LL s=1;
    for(int i=0;i<n;i++){
        LL x;
        cin>>x;
        s=x/__gcd(x,s)*s;
    }
    cout<<s<<endl;
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll n;
ll a[22];
P dp[1<<18][2];

int main(){
  cin>>n;
  rep(i,1<<n){
    cin>>dp[i][0].fi;
    dp[i][0].se=i;
  }

  rep(i,1<<n){
    rep(j,n){
      if((i>>j)&1){
        P pre0=dp[i^(1<<j)][0];
        P pre1=dp[i^(1<<j)][1];
        if(dp[i][0]<pre0){
          P tmp=dp[i][0];
          dp[i][0]=pre0;
          dp[i][1]=max(tmp,pre1);
        }else{
          if(dp[i][0]!=pre0){
            maxch(dp[i][1],pre0);
          }
        }
      }
    }
  }

  ll crt=0;
  repl(i,1,1<<n){

    maxch(crt,dp[i][0].fi+dp[i][1].fi);
    cout<<crt<<endl;
  }

  return 0;
}


Measured memory_bytes: 11264
#include<stdio.h>

int main(){
  int x,y,tmp,r;
  scanf("%d%d",&x,&y);

  if(x<y){
    tmp=x;
    x=y;
    y=tmp;
  }
  
  r=x%y;
  
  while(r!=0){
    x=y;
    y=r;
    r=x%y;
  }
  
  printf("%d\n",y);

  return 0;
}
  



Measured memory_bytes: 2140
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>


using namespace std;

int main(){
 long long int n;
 cin >> n;
  
 long long int ans = 0;
  
 long long int num = n;
  
 for (long long int i = 1; i*i <= n-1; i++) {
   
 if( (n-1) % i == 0){
   ans += 1;
   if((n-1)/i != i){
     ans += 1;
   }
  }
   
 }
  
  for(long long int i=2; i*i <= n;i++){
    num = n;
    if(n % i == 0){             
      while(num % i ==0){
        num /= i;
      }
      if(num % i == 1){
        ans++;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
# sは奇数で確定
s = input()
list_s = list(s)

ans = 'No'

def is_kaibun(kaibun):
    for i in range(len(kaibun)//2):
        if kaibun[i] != kaibun[-i-1]:
            return False
    return True

# 1. sが回文か
if is_kaibun(s) == True : 

    second_moji = ''
    aaa = (len(s) - 1) / 2
    aaa = int(aaa)

    for i in range(aaa): 
        second_moji = second_moji + list_s[i]

    # 2. (N−1)/2文字目まで回文か
    if is_kaibun(second_moji) == True :


        third_moji = ''
        bbb = (len(s) + 3) / 2
        bbb = int(bbb - 1)

        ccc = len(s) - bbb

        for i in range(ccc): 
            third_moji = third_moji + list_s[i + bbb]

            # 3. Sの (N+3)/2 文字目から N文字目まで(両端含む)からなる文字列は回文か
            if is_kaibun(third_moji) == True :
                ans = 'Yes'
        
print(ans)


Measured memory_bytes: 3064
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e3 + 5, M = 1e5 + 5;


int main(){
    IO;
    int n;
    cin >> n;
    long double ans = 0;
    for(int i = 0 ; i < n ; ++i){
        long double x;
        cin >> x;
        ans += (1.0L / x);
    }
    cout << fixed << setprecision(12) << (1.0L / ans) << endl;
}

Measured memory_bytes: 256
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
INF = 10**18


if __name__ == "__main__":
    n = int(input())
    a = 1000
    while True:
        if a >= n:
            break
        a+=1000
    print(a-n)


Measured memory_bytes: 9612
n,m,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
acum1=[0]
for i in range(n):
  acum1.append(acum1[-1]+arr1[i])
acum2=[0]
for i in range(m):
  acum2.append(acum2[-1]+arr2[i])
ans=0
j=m
for i in range(n+1):
  if acum1[i]>k:
    break
  while acum2[j]>k-acum1[i] and j>0:
    j-=1
  ans=max(ans,i+j)
print(ans)

Measured memory_bytes: 47336
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int main(void) {
	int n; cin >> n;
	vi a(n); rep(i,n) cin >> a[i];
	SORT(a);
	if(n%2){
		rep(i,n){
			int x = (i+1)/2*2;
			if(a[i]!=x){
				cout << 0 << endl;
				return 0;
			}
		}
		mint ans = 2;
		ll t = (n-1)/2;
		ans = ans.pow(t);
		cout << ans << endl;
		return 0;
	}else{
		rep(i,n){
			int x = (i/2)*2+1;
			if(a[i]!=x){
				cout << 0 << endl;
				return 0;
			}
		}
		mint ans = 2;
		ll t = n/2;
		ans = ans.pow(t);
		cout << ans << endl;
		return 0;
	}
}


Measured memory_bytes: 640
# 辺の情報を別で管理しておけば、辺を取り除いたときの状態でシミュレートできる
# 隣接リストじゃなくて隣接行列でもっておく
# 適当にDFSして訪れられなかった場合に+1
n, m = map(int, input().split())
grpah = [[False for _ in range(n)] for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    grpah[a - 1][b - 1] = True
    grpah[b - 1][a - 1] = True


def dfs(cur, visited):
    if all(visited) is False and all(grpah[cur]) is False:
        for i, v in enumerate(grpah[cur]):
            if v == True and visited[i] == False:
                visited[i] = True
                dfs(i, visited)


ans = 0

for i in range(n):
    for j in range(n):
        if grpah[i][j] or grpah[j][i]:
            # 辺を一時的に取り除く
            grpah[i][j] = grpah[j][i] = False
            temp_visited = [False for _ in range(n)]
            temp_visited[0] = True
            dfs(0, temp_visited)
            if all(temp_visited) is False:
                ans += 1

            # 取り除いた辺を復元しておく
            grpah[i][j] = grpah[j][i] = True

print(ans//2)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define FAST {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll,ll>
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
using namespace std;

int main()
{
    FAST
    ll n,k;cin>>n>>k;
    ll p[n+1],c[n+1];
    f(i,1,n+1) cin>>p[i];
    f(i,1,n+1) cin>>c[i];
    bool vis[n+1];
    ll ans=-1e15;
    vector<ll> v;
    f(i,1,n+1)
    {
        memset(vis,false,sizeof vis);
        v.clear();
        ll pos=p[i];
        ll totsum=0;
        while(!vis[pos])
        {
            v.pb(c[pos]);
            vis[pos]=true;
            pos=p[pos];
            totsum+=c[pos];
        }
        ll ns=v.size();
        ll curr=0;
        if(totsum>0 && k>ns) 
        {
            curr+=totsum*(k/ns - 1);
            ll rem=k%ns+ns;
            ll rmax=0;
            ll ss=0;
            f(j,0,rem)
            {
                ss+=v[j%ns];
                rmax=max(ss,rmax);
            }
            curr+=rmax;
            ans=max(ans,curr);
        }
        ll rmax=v[0];
        ll ss=v[0];
        f(j,1,min(ns,k))
        {
            ss+=v[j];
            rmax=max(ss,rmax);
        }
        ans=max(ans,rmax);
        
    }
    cout<<ans<<endl;

}


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

int main() {
	// your code goes here
		int n ; cin >> n;
	vector<double> v(n);
	for(int i=0;i<n;i++){
		cin >> v[i];
	}
	vector<double> ans(n+1,0.0);
	ans[0]=1.0;
	for(int i=0;i<n;i++){
		for(int j=i;j>=0;j--){
			ans[j+1]+=1.0*ans[j]*v[i];
			ans[j]*=1.0*(1-v[i]);
		}
	}
	double sum=0;
	for(int i=(n/2)+1;i<=n;i++) sum+=ans[i];
	cout <<fixed << setprecision(10)<< sum ;
	return 0;
}


Measured memory_bytes: 256