akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

class MyClass
{
    public static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var q = int.Parse(Console.ReadLine());
        var t = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var count = 0;
        foreach (var x in t)
        {
            var min = 0;
            var max = n;
            while (min < max)
            {
                var mid = (min + max) / 2;
                if (s[mid] == x)
                {
                    count++;
                    break;
                }
                else if (s[mid] < x)
                {
                    min = mid + 1;
                }
                else
                {
                    max = mid;
                }
            }
        }
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 31324
import math
n, k = map(int, input().split())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7


def com_init():
    MAX = 10 ** 5 + 1
    fac = [0] * MAX
    finv = [0] * MAX
    inv = [0] * MAX
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod
    return fac, finv

fac, finv = com_init()

def nCr(n,r):
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod 

# def nCr(n, r):
#     return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


MAX_SUM = 0
MIN_SUM = 0

A.sort() # asc
for j in range(n - k + 1): # 小さい方からk個
    MIN_SUM += A[j] * nCr(n - j - 1, k - 1)

A = A[::-1] # desc
for i in range(n - k + 1): #大きい方からk個
    MAX_SUM += A[i] * nCr(n - i - 1, k - 1)


print((MAX_SUM - MIN_SUM + mod) % mod)

Measured memory_bytes: 63344
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

int main() {
    ll N;
    cin >> N;
    string s;
    cin >> s;
    stack<char> stl,str;
    vector<ll> ct(N);
    ll ctl=0,r=0,l=0;
    for(int i=0;i<N;i++){
        if(s[i]=='('){
            r++;
            stl.push(i);
        }
        else {
            l++;
            if(stl.empty()) ctl++;
            else stl.pop();
        }
    }
    for(int i=0;i<ctl;i++) cout << '(';
    cout << s;
    for(int i=0;i<r-(l-ctl);i++) cout << ')';
    cout << endl;

    

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){

  int i, N;
  scanf("%d", &N);
  long p=1;
  long k = 1000000000 + 7;
  if(1<=N && N<=100000)
    {
  for(i=0;i<N;i++)
    {
      p = p*(i+1);
      p = p%k;
    }
    }

  printf("%ld\n", p);
  

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
typedef pair<int,int> pii;
typedef vector<int> vi;
#define mp make_pair
#define pb push_back
#define ld long double
#define rep(i,n) for (int i=1;i<=n;++i)
long long k;
int main(){
	ios::sync_with_stdio(false);
	cin>>k;
	cout<<50<<endl;
	ll adds=k/50;
	int left=k%50;
	for (int i=0;i<left;i++){
		cout<<49+adds+51-left<<" ";
	}
	for (int i=left+1;i<=50;i++){
		cout<<49+adds-left<<" ";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<double>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N, K, R, S, P;
bool w[100010];
string T;

int point(char c){
    if(c == 'r') return P;
    if(c == 's') return R;
    if(c == 'p') return S;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> K >> R >> S >> P >> T;
    int sum = 0;
    for(int i = 0; i < K; i++){
        sum += point(T[i]);
        w[i] = true;
        for(int j = i + K; j < N; j += K){
            if(T[j] != T[j - K]){
                w[j] = true;
                sum += point(T[j]);
            }else if(!w[j - K]){
                sum += point(T[j]);
                w[j] = true;
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 592
#include <stdio.h>

int main() {
  int i, j, a, b;
  char line[101];
  while (1) {
    for (i = 0; i < 3; ++i) {
      a = b = 0;
      scanf("%s", line);
      if (line[0] == '0') {
        return 0;
      }
      for (j = 1; line[j]; ++j) {
        if (line[j] == 'A') {
          ++a;
        } else if (line[j] == 'B') {
          ++b;
        }
      }
      if (a > b) {
        ++a;
      } else {
        ++b;
      }
      printf("%d %d\n", a, b);
    }
  }
}

Measured memory_bytes: 964
N = int(input())
h = list(map(int, input().split()))

dp = [0] * (N)
dp[1] = abs(h[1] - h[0])
for i in range(2, N):
    dp[i] = dp[i-1] + abs(h[i] - h[i-1])
    dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

print(dp[N-1])


Measured memory_bytes: 13980
# include <iostream>
# include <string>
# include <set>
# include <algorithm>
# include <cmath>
# include <vector>
# include <string>
# include <map>
# include <iomanip>
# include <queue>
# include <stack>
# include <deque>

using namespace std;

const int N = 1e5 +100;
long long n, a[N], b[N];
long long ans;

int main()
{
    cin >> n;
    for( int i = 1; i <= n+1; i ++ ){
        cin >> a[i];
    }
    for( int i =1 ; i <= n; i++ ){
            cin >> b[i];
    }
    for( int i = 1; i <= n; i ++ ){
        int c = min( b[i], a[i] );
        ans += c;
        a[i] -= c;
        b[i] -= c;
        c = min( b[i], a[i+1] );
        ans += c;
        a[i+1] -= c;
        b[i] -= c;
    }
    cout << ans;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (i = 0; i < n; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
const int mod = 1'000'000'007;

void solve()
{
    int x, y; cin >> x>>y;
    string ans = "No";
    int b;
    for(int a=0; a<=x; a++){
        b = x-a;
        if(a*2 + b*4 == y)
            ans = "Yes";
    }
    cout << ans << endl;
}

int main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  
    solve();
  
  return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#define N 2010
#define M 2000001
#define ls i << 1
#define rs i << 1 | 1
#define inf 0x3f3f3f3f
#define inc(i) (++ (i))
#define dec(i) (-- (i))
// #define mid ((l + r) >> 1)
#define int long long
#define XRZ 998244353
#define debug() puts("XRZ TXDY");
#define n_ ((n >> 1) + 1)
#define mem(i, x) memset(i, x, sizeof(i));
#define Next(i, u) for(register int i = head[u]; i ; i = e[i].nxt)
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout);
#define Rep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i <= i##Limit ; inc(i))
#define Dep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i >= i##Limit ; dec(i))
// const int dx[10] = {1, -1, 0, 0};
// const int dy[10] = {0, 0, 1, -1};
using namespace std;
inline int read() {
    register int x = 0, f = 1; register char c = getchar();
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
void work() {}
int A[N] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
signed main() { int a = read(), b = read(), c = read();
    int now = c - a - b;
    if(now < 0) { puts("No"); return 0;}
    if(4 * a * b >= now * now) puts("No");
    else puts("Yes");
    return 0;
}

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

using namespace std;

int main(void){
    vector<int> cards;
    int N;
    int Alice = 0, Bob = 0;

    cin>>N;

    for(int i = 0; i < N; i++){
        int data;
        cin >> data;
        cards.push_back(data);
    }

    sort(cards.begin(), cards.end(), greater<int>());

    for(int i = 0; i < N; i++){
        if(i % 2 == 0) Alice += cards[i];
        else           Bob   += cards[i];
    }

    cout << (Alice - Bob);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int len=s.size();
    if(s[len-1]=='s')
    {
        cout<<s<<"es"<<endl;
    }
    else
    {
        cout<<s<<"s"<<endl;
    }
}


Measured memory_bytes: 3620
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long lli;
typedef pair<int, int> pii;
int n;
string s;
int a, b, c, d;

void ReadInput()
{
    cin >> n >> a >> b >> c >> d;
    cin >> s;
    --a; --b; --c; --d;
}

bool can_go(int from, int to)
{
    while(from < to)
    {
        if(s[from + 1] == '.')
            ++from;
        else if(s[from + 2] == '.')
            from += 2;
        else return false;
    }
    return true;
}

bool three_empty(int from, int to)
{
    for(int i = from; i <= to; ++i)
        if(s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.')
            return true;
    return false;
}

void Solve()
{
    if(can_go(a, c) && can_go(b, d))
    {
        if(c < d || three_empty(b, d))
        {
            cout << "Yes\n";
            return;
        }
    }
    cout << "No\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}


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

int main() {
	int n, d, x;
	cin >> n >> d >> x;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	int ans = x;
	for(int i = 0; i < n; i++){
		ans += ((d - 1) / a[i]) + 1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
/* ABC140-C
   Takatan */

#include<stdio.h>
#include<stdlib.h>
int main(void){
    int number, *max, sum, i;

    scanf( "%d", &number);
    max = malloc(sizeof(int) * (number-1));
    for(i=0; i < number-1; i++){
        scanf( "%d" , &max[i]);
    }

    sum = max[0] + max[number-2]; /* 考えられるA1,Anの最大値を加える */
    for(i=0; i < number-2; i++){
        if(max[i]<max[i+1]){ /* 考えられるAiの最大値としてBiとB(i+1)のうち小さい方を加える */
            sum += max[i];
        }else{
            sum += max[i+1];
        }
    }

    printf( "%d\n" , sum);
    return 0;
}

Measured memory_bytes: 128
N,L = map(int,input().split())
#A = list(map(int,input().split()))

aji = []
less_effect = []
for i in range(N):
    less_effect.append(abs(L+i))
    aji.append(L+i)

eat_apple = aji[less_effect.index(min(less_effect))]

ans = sum(aji) - eat_apple

print(str(ans))

Measured memory_bytes: 39860
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        int W,H,x,y,r;
        
        Scanner scan = new Scanner(System.in);
        W = scan.nextInt();
        H = scan.nextInt();
        x = scan.nextInt();
        y = scan.nextInt();
        r = scan.nextInt();
        
        if(x > 0 && y > 0){
        if( x-r >= 0 && x+r <= W){
            if( y-r >= 0 && y+r <= H){
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }else {System.out.println("No");
        }
        }else System.out.println("No");
    }
}


Measured memory_bytes: 26412
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9


int main() {
	ll Name[5];
	for (int i = 0; i < 5; i++) Name[i] = 0;
	int N; cin >> N;

	for (int i = 0; i < N; i++) {
		string s; 
		cin >> s;

		switch (s[0]) {
		case 'M':
			Name[0]++; break;
		case 'A':
			Name[1]++; break;
		case 'R':
			Name[2]++; break;
		case 'C':
			Name[3]++; break;
		case 'H':
			Name[4]++; break;
		default:
			break;
		}
	}

	ll ans = 0;
	for (int i = 0; i < 5; i++) {
		for (int j = i + 1; j < 5; j++) {
			for (int k = j + 1; k < 5; k++) {
				ans += Name[i] * Name[j] * Name[k];
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
    int n,t,a;cin>>n>>t>>a;
    vector<int> v(n);
    for(int i=0;i<n;i++)cin>>v[i];
    ld wow=(t-a)/0.006;
    ld dif=1e9;
    ll ans=0;
    for(int i=0;i<n;i++){
        if(dif>abs(wow-v[i])){ans=i+1;dif=abs(wow-v[i]);}
    }
    cout<<ans;
    
    
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template <typename T1, typename T2>
void chmax(T1 &a, const T2 &b) {
  if(a < b) a = b;
}

template <typename T1, typename T2>
void chmin(T1 &a, const T2 &b) {
  if(a > b) a = b;
}

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  double r; cin >> r;

  cout << 2 * acos(-1) * r << endl;
  
}


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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

/*
ifstream ifs("in.txt");
ofstream ofs("out.txt");
#define cin ifs
#define cout ofs
//*/

//拡張ユークリッドの互除法
int extgcd(int a, int b, int& x, int& y) {
    int d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}

// mod逆元
int mod_inverse(int a, int m) {
    int x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}

int N, M;
int dp[3333][3333];
int fact[3333], fact_inv[3333];
int exp_2[9999999], exp_2_2[3333];

signed main() {
    cin >> N >> M;
    fact[0] = 1;
    fact_inv[0] = 1;
    exp_2_2[0] = 2;
    for (int i = 1; i < 3333; i++) {
        fact[i] = fact[i - 1] * i % M;
        fact_inv[i] = mod_inverse(fact[i], M);
        exp_2_2[i] = exp_2_2[i - 1] * exp_2_2[i - 1] % M;
    }
    exp_2[0] = 1;
    for (int i = 1; i < 9999999; i++) {
        exp_2[i] = exp_2[i - 1] * 2 % M;
    }
    for (int i = 0; i < 3333; i++) {
        dp[i][0] = 1;
    }
    for (int i = 1; i < 3333; i++) {
        for (int k = 1; k < 3333; k++) {
            dp[i][k] = (dp[i - 1][k - 1] + dp[i - 1][k] + dp[i - 1][k] * k) % M;
        }
    }
    int ans = 0;
    int sign = -1;
    for (int i = 0; i <= N; i++) {
        sign *= -1;
        int comb = fact[N] * fact_inv[i] % M * fact_inv[N - i] % M;
        int ways = 0;
        for (int k = 0; k <= i; k++) {
            (ways += dp[i][k] * exp_2[k * (N - i)] % M) %= M;
        }
        (ways *= exp_2_2[N - i]) %= M;
        (ans += sign * (comb * ways % M) + M) %= M;
    }
    cout << ans << endl;
}

Measured memory_bytes: 165248
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define RFOR(i,a,b) for(long long i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

int main() {
	int N;
	cin >> N;
	int a,ind[13]={};
	REP(i,N){
		cin >> a;
		ind[a/400]++;
	}
	int cnt=0,cnt2=0;
	REP(i,13)
      if(ind[i]>0)
        if(i<8) cnt++;
      	else cnt2+=ind[i];
	cout << max(1,cnt) << " " << cnt+cnt2 << endl;
	return 0;
}

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

count = 0

for i in range(a, b + 1):
    work_i = i
    n = 1
    while work_i >= 10:
        n += 1
        work_i = int(work_i / 10)

    flag = True
    for j in range(int(n/2)):
        if int(i / 10**j) % 10 != int(i / 10**(n-j-1)) % 10:
            flag = False

    if flag:
        count += 1

print(count)


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

using namespace std;

int main(void)
{
    int a, b, c, d, e, k; cin >> a >> b >> c >> d >> e >> k;
    bool there = false;

    if((b - a) > k)
        there = true;
    if((c - a) > k)
        there = true;
    if((d - a) > k)
        there = true;
    if((e - a) > k)
        there = true;
    if((c - b) > k)
        there = true;
    if((d - b) > k)
        there = true;
    if((e - b) > k)
        there = true;
    if((d - c) > k)
        there = true;
    if((e - c) > k)
        there = true;
    if((e - d) > k)
        there = true;


    if(there)
        cout << ":(\n";
    else
        cout << "Yay!\n";
    
    
    return 0;
}

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


def solve(A: int, B: int, M: int, a: "List[int]", b: "List[int]", x: "List[int]", y: "List[int]", c: "List[int]"):
    m = min(a) + min(b)
    for i in range(M):
        m = min(a[x[i]-1] + b[y[i]-1] - c[i], m)
    print(m)
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 24612
n = gets.to_i
ac = 0
wa = 0
tle = 0
re = 0
n.times do |s|
  i = gets.chomp.to_s
  if i == "AC"
    ac+=1
  elsif i == "WA"
    wa+=1
  elsif i == "TLE"
    tle+=1
  elsif i == "RE"
    re+=1
  end
end

printf("AC x %d\n",ac)
printf("WA x %d\n",wa)
printf("TLE x %d\n",tle)
printf("RE x %d\n",re)

Measured memory_bytes: 14336
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
  int n, x[100003] = {0}, y[100003] = {0}, t[100003] = {0}, flag = 0, dx, dy, dt, dl;

  cin >> n;
  for(int i= 1; i <= n; i++)
    cin >> t[i] >> x[i] >> y[i];

  for(int i = 1; i <= n; i++){
    dt = abs(t[i] - t[i -1]);
    dx = abs(x[i] - x[i -1]);
    dy = abs(y[i] - y[i-1]);
    dl = dx + dy;
    if(dt < dl)
      flag = 1;
    else if(abs(dt - dl) % 2 != 0)
      flag = 1;
  }
    if(flag)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 1536
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur=nil->next;
  while(cur!=nil&&cur->key!=key){
    cur=cur->next;
  }
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if(t==nil)return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void delete(int key){
  deleteNode(listSearch(key));
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;

}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}

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

void cas(int i,char ch) {
    cout<<"Case "<<i<<":"<<ch;
}

typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef vector< pii > vii;

#define ll          long long
#define ff          first
#define ss          second
#define pb          push_back
#define mkp         make_pair
#define sz          size()

#define forf(a,b,c)    for(int i=a;i<=b;i+=c)
#define forr(a,b,c)    for(int i=a;i>=b;i-=c)
#define all(a)      a.begin(),a.end()
#define mem(a,b)    memset(a,b,sizeof(a))
#define pi          2*acos(0.0)
#define End         return 0;

#define scan1(a)    scanf("%d",&a)
#define scan2(a,b)  scanf("%d %d",&a,&b)
#define scan3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define scanl(a)    scanf("%lld",&a)
#define scanll(a,b) scanf("%lld %lld",&a,&b)
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define print1(a)    printf("%d",a)
#define print2(a,b)  printf("%d %d",a,b)
#define print3(a,b,c)  printf("%d %d %d",a,b,c)
#define printl(a)    printf("%lld",a)
#define printll(a,b) printf("%lld %lld",a,b)
#define printlll(a,b,c) printf("%lld %lld %lld",a,b,c)

#define MAXN        100000007
#define INF 0x3f3f3f3f
//int dx[]={+1,-1,+0,+0};///Four Directions
//int dy[]={+0,+0,+1,-1};///Four directions
//int dx [] = {+1,-1,+0,+0,-1,-1,+1,+1};///Eight Directions
//int dy [] = {+0,+0,+1,-1,+1,-1,-1,+1};///Eight Directions

//int mark[10007];vi prime;void seive(){for(int i=2;i<10000;i++){if(mark[i]==0){prime.pb(i);for(int j=i+i;j<=10000;j+=i)mark[j]=1;}}}

//freopen("input.txt", "r", stdin);

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

    int n; cin>>n;
    map<ll,ll>mp;
    set<ll>s;
    ll sum=0, val[n+4];
    vll v(n);
    for(int i=0;i<n;i++) {
        cin>>v[i];
        mp[v[i]]++;
        s.insert(v[i]);
    }

    for(ll u:s) {
        ll tem=mp[u]-1;
        tem= (tem*(tem+1))/2;
        val[u]=tem; sum+=tem;
    }

    for(ll u:v){
        ll summ=sum-val[u];
        ll tem=mp[u]-2;
        tem= (tem*(tem+1))/2;
        summ+=tem;
        if(mp[u]==1) cout<<sum<<endl;
        else cout<<summ<<endl;
    }
    End;
}


Measured memory_bytes: 20224
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
inline int read(){
	int x,t=1;
	char c;
	while(c=getchar(),c<'0' || c>'9')if(c=='-')t=-1;
	x=c-'0';
	while(c=getchar(),c>='0' && c<='9')x=x*10+c-'0';
	return x*t;
}
int main(){
	int n;
	bool flag=1;
	n=read(); 
	for(int i=1;i<=n;i++){
		int t,x,y;
		t=read();
		x=read();
		y=read();
		if((t-(x+y))%2!=0||t<x+y)
			flag=0;
	}
	if(flag==1)
		cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
strings = gets.split(" ")
hash = Hash.new(0)
strings.each_with_index do |e,i|
  #各ハッシュ要素には、　配列[出現数、文字の長さ]　を与える
    hash[e] =
    [
      hash[e][0] + 1,
      e.length
    ]
end

max_s = 0
longest_size = 0


hash.each do |s, (num_i, size_i)|
  # puts "#{s} #{num_i} #{size_i}"
  if num_i > max_s
    max_s = num_i
    @max_s_string = s
  end

  if size_i > longest_size
    longest_size = size_i
    @longest_size_string = s
  end
end

puts "#{@max_s_string} #{@longest_size_string}"


Measured memory_bytes: 6864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn=1e6+5;
vector<ll> V;
int pre[maxn];
int main() {
    int n;cin>>n;
    if(n%1000==0) cout<<0<<endl;
    else cout<<1000-n%1000<<endl;
    return 0;
}

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

int main(void)
{
    using namespace std;
    double PI = acos(-1);  // PI = 3.141593...

    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);

    double rad = c * (PI / 180);
    // printf("%lf\n", rad);

    printf("%lf\n", 0.5 * a * b * sin(rad));
    printf("%lf\n", a + b + sqrt((a*a)+(b*b)-(2*a*b*cos(rad))));
    printf("%lf\n", b * sin(rad));
    return 0;
}


Measured memory_bytes: 3456
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
#include  <cstdio>
#include  <sstream>
#include  <bitset>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using ld = long double;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vd = vector<double>;
using Vld = vector<long double>;
using Vll = vector<vector<ll> >;
using Vldd = vector<vector<ld> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Pli = pair<ll, int>;
using VPi = vector<Pi>;
using VPl = vector<Pl>;
using VPli = vector<Pli>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

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

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };


int main()
{
	ll x, k, d;
	cin >> x >> k >> d;

	ll s = abs(x) / d;
	if (k < s) {
		cout << abs(x) - d * k << endl;
	}
	else {
		if ((k - s) % 2 == 0) {
			cout << abs(x) % d << endl;
		}
		else {
			cout << d - abs(x) % d << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <ctype.h>
#include <string.h>

void print_int(int n)
{
    printf("%d\n",n);
}

void swap(int * a, int * b)
{
    int t = *a;
    *a = *b;
    *b = t;
}

void sort(int a[], int n)
{
    for(int i = 1; i < n; i++)
    {
        int j = i-1;
        while(j >= 0 && a[j+1] > a[j])
        {
            swap(&a[j+1],&a[j]);
            j--;
        }
        
    }
    
}

void print_list(int a[], int n)
{
    for(int i = 0; i < n; i++)
    {
        print_int(a[i]);
    }
    
}

char str[10000000];
int n, k;
int main(void)
{
    int i = 0, j = 0;
    scanf("%d %d", &n, &k);
    scanf("%s", str);
    int count = n;
    int dist[count+2];
    int num_of_0 = 0;
    int max = 0;

    for(i = 0; i < count + 2; i++)
    {
        dist[i] = 0;
    }

    if(str[0] == '0')
    {
        dist[0] = 0;
        dist[1] = 1;
        j = 1;
    }
    else
    {
        dist[0] = 1;
    }
    

    for(i = 1; i < count; i++)
    {
        if(str[i] == str[i-1])
        {
            dist[j]++;
        }
        else
        {
            j++;
            dist[j] = 1;
        }
        
    }

    num_of_0 = (j+1)/2;

    if(num_of_0 <= k)
    {
        for(i = 0; i <= j; i++)
        {
            max += dist[i];
        }
    }
    else
    {
        for(i = 2*k; i <= j + 1; i += 2)
        {
            int num = 0;
            for(int l = i - 2*k; l <= i; l++)
            {
                num += dist[l];
            }
            if(num > max)
                max = num;
        }
    }
    print_int(max);



    
    return 0;
}



Measured memory_bytes: 640
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N;
	cin >> N;
	vector<vector<int>>arr(2, vector<int>(N, 0));
	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < N; j++)
		{
			cin >> arr[i][j];
		}
	}
	int saidai = 0;
	for (int i = 0; i < N; i++)
	{
		int a = 0, b = 0;
		for (int j = 0; j < N; j++)
		{
			if (j == i)
			{
				a += arr[0][i] + arr[1][i];
				b = 1;
			}
			else
			{
				a += arr[b][j];
			}
		}
		saidai = max(a, saidai);
	}
	cout << saidai << "\n";
}

Measured memory_bytes: 256
N,L = map(int, input().split())

total = (2*L + (N-1)) * N / 2

if L * (L+N-1) < 0:
    print(int(total))
else:
    if L < 0:
        print(int(total - L - (N-1)))
    else:
        print(int(total - L))

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

using namespace std;
using ll = long long;

template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

int main() {
    int N, K;
    cin >> N >> K;
    deque<int> D, tD;
    for (int i = 0; i < N; i++) {
        int d;
        cin >> d;
        tD.push_back(d);
    }

    int ans = 0;
    for (int l = 0; l <= K; l++) {
        for (int r = 0; r <= K - l; r++) {
            D = tD;
            int now = 0;
            set<int> s;
            if (l + r > N)
                break;
            int d = K - (l + r);
            for (int i = 0; i < l; i++) {
                now += D.front();
                s.insert(D.front());
                D.pop_front();
            }

            for (int i = 0; i < r; i++) {
                now += D.back();
                s.insert(D.back());
                D.pop_back();
            }

            int cnt = 0;
            for (int ss : s) {
                if (cnt >= d || ss >= 0)
                    break;
                cnt++;
                now -= ss;
            }

            ans = max(ans, now);
            if (ans == 16) {
                cout << l << " " << r << endl;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdlib>
#include <math.h>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrep1(i,a,b) for(long i=(a);i<=(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define X first
#define Y second
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define vpl vector<pair<long, long> >
#define vppl vector<pair<long, pair<long, long> > >

const int INF = 100100100;
const long LONG_INF = 2147483647;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;


int pow(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow(x - 1) * 2;
	}
}

int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int a,x;
    cin >> a >> x;
    if (a >= x)
    {
        cout << 10 << endl;
    } else
    {
        cout << 0 << endl;
    }
    
    

    return 0;
}


Measured memory_bytes: 256
function insert(ary, num) {
  ary.splice(num - 1, 0, num);
}

function main(arg) {
	var b = arg.split("\n")[1].split(" ").map(Number)
	// b = b.sort((x, y) => x - y)
	var n = b.length
	var a = []
	var missed = false
	for (var i = 0; i < n; i++ ) {
		var max = i + 1
		var bi = b[i]
		if (bi > max) {
			missed = true
		}
		insert(a, bi);

	}
	if (missed) {
		console.log(-1)
		return
	}
	for (var j = 0; j < b.length; j++) {
		console.log(a[j])
	}
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 25160
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

const mod int64 = 1000000007

func main() {
	io := newIo()
	defer io.Flush()
	X, Y := io.NextInt(), io.NextInt()
	if (2*Y-X)%3 > 0 || (2*X-Y)%3 > 0 {
		fmt.Println(0)
		return
	}
	a := int64((2*Y - X) / 3)
	b := int64((2*X - Y) / 3)

	if a < 0 || b < 0 {
		fmt.Println(0)
		return
	}
	fmt.Println(combMod(a+b, int64(math.Min(float64(a), float64(b)))))
}

func combMod(n, r int64) int64 {
	i := int64(0)
	up := int64(1)
	down := int64(1)
	for i < r {
		up = up * (n - i) % mod
		down = down * (i + int64(1)) % mod
		i++
	}
	return up * powMod(down, mod-2) % mod
}

func powMod(a, b int64) int64 {
	if b == 0 {
		return 1
	}
	if b%2 == 0 {
		res := powMod(a, b/2) % mod
		return res * res % mod
	}
	return a * powMod(a, b-1) % mod
}

type io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func newIo() *io {
	return &io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}


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

n = int(input())
connect_list = [[] for i in range(n)]
for i in range(n-1):
    a, b, c = [ int(v)-1 for v in input().split() ]
    c += 1
    connect_list[a].append((b,c))
    connect_list[b].append((a,c))


q, k = [ int(v) for v in input().split() ]
k -= 1

shortest_list = [-1 for i in range(n)]
shortest_list[k] = 0

searching_list = [k]

while searching_list != []:

    new_search_list = []
    for i in searching_list:
        for j in connect_list[i]:
            x, y = j
            if shortest_list[x] == -1:
                shortest_list[x] = y + shortest_list[i]
                new_search_list.append(x)
    searching_list = new_search_list


for i in range(q):
    a, b = [ int(v)-1 for v in input().split() ]
    print(shortest_list[a] + shortest_list[b])


Measured memory_bytes: 72180
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


ll dp[22][1<<21];
int n,a[30][30];

ll rec(int x,int mask){
    if(x==0&&mask==0)return dp[x][mask]=1;
    if(dp[x][mask]!=-1)return dp[x][mask];
    ll ret=0;
    rep(i,n){
        if(((1<<i)&mask)&&a[x-1][i]){
            ret+=rec(x-1,mask^(1<<i));
        }
    }
    return dp[x][mask]=ret%mod;
}
int main(){
    cin>>n;
    rep(i,n)rep(j,n)cin>>a[i][j];
    int mask=1<<n;
    rep(i,n+1)rep(j,mask)dp[i][j]=-1;
    cout<<rec(n,mask-1)<<endl;
    return 0;
}

Measured memory_bytes: 360704
def inpl(): return [int(i) for i in input().split()]
import heapq
h,w = inpl()
edge = [] 
inf = float('inf')
for i in range(10):
    edge.append(inpl())
Q = [[inf for _ in range(10)] for _ in range(10)]

for i in range(10):
    decided = [False for _ in range(10)]
    H = []
    Q[i][i] = 0
    heapq.heappush(H,(0,i))
    for _ in range(10):
        while True:
            k = heapq.heappop(H)
            k = k[1]
            if not decided[k]:
                decided[k] = True
                break
        for j in range(10):
            if decided[j]:
                continue
            Q[i][j] = min(Q[i][k] + edge[k][j], Q[i][j])
            heapq.heappush(H,(Q[i][j],j))
ct = [0 for _ in range(11)]
for i in range(h):
    A = inpl()
    for j in range(w):
        ct[A[j]] += 1
ans = 0
for i in range(10):
    ans += ct[i]*Q[i][1]
print(ans)

Measured memory_bytes: 3188
import sys

# import numba as nb
import numpy as np

input = sys.stdin.readline
INF = float("inf")


# @nb.njit("i8(i8,i8,i8[:])")
def solve(N, K, h):
    dp = np.zeros(N, dtype=np.int64)
    for i in range(1, N):
        k = min(K, i)
        dp[i] = np.min(dp[i - k:i] + np.abs(h[i] - h[i - k:i]))
    return dp[-1]


def main():
    N, K = map(int, input().split())
    h = np.array(input().split(), dtype=np.int64)

    ans = solve(N, K, h)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 37952
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

void solve_SE(double* x, double a, double b, double c, double d, double e, double f)
{
    x[0] = (c * e - f * b) / (a * e - d * b);
    x[1] = (c * d - f * a) / (b * d - e * a);
}

int main()
{
    double a, b, c, d, e, f;
    double x[2];
    while ((cin >> a >> b >> c >> d >> e >> f)) {
        solve_SE(&x[0], a, b, c, d, e, f);
        for (int i = 0; i < 2; i++) {
            x[i] = round(x[i] * 1000) / 1000;
            if (x[i] == 0) x[i] = 0;
        }
        cout << fixed << setprecision(3) << x[0] << ' ' << x[1] << endl;
    }
}

Measured memory_bytes: 3208
N, K = map(int, input().split())
H = list(map(int, input().split()))
H = [H[0]] * K + H

# dp[i] := 足場iに来るのにかかる最小のコスト
INF = 10**18
dp = [INF] * (K + N)
dp[0] = 0
for i in range(K, N + K):
    h = H[i]
    tmp = [x + abs(y - h) for x, y in zip(dp[i - K:i], H[i - K:i])]
    dp[i] = min(tmp)
#     dp[i] = min(x + abs(y - h) for x, y in zip(dp[i - K:i], H[i - K:i]))
#     for j in range(1, K + 1):
#         v = dp[i - j] + abs(H[i] - H[i - j])
#         dp[i] = min(dp[i], v)
# print('dp', dp)
ans = dp[-1]
print(ans)


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

int main()
{

        int A, B, C;
        cin >> A >> B >> C;


        long long t = A;
        int cnt = 1;
        for (int i = 1; i < B; ++i) {
                t = A * i;
//              cout << t % B << endl;
                if (t % B == C) {
                        cout << "YES" << endl;
                        return 0;
                }
        }

        cout << "NO" << endl;
}


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

typedef pair<int,int> P; //500, -totalcost

P dp[101][50000];

int main(){
    int n;
    while(cin>>n,n){
        fill(dp[0],dp[101],P(0,-5000000));
        dp[0][0]=P(0,0);
        for(int i=0;i<n;i++){
            int price;
            cin>>price;
            for(int c=0;c<50000;c++){
                if(dp[i][c].second<=-5000000) continue;
                dp[i+1][c]=max(dp[i+1][c],dp[i][c]); //ティツイツキテ」ツつ湘」ツ?ェテ」ツ??
                if(price%1000==0){
                    if(c>=500){
                        dp[i+1][c-500]=max(dp[i+1][c-500],P(dp[i][c].first+1,dp[i][c].second-price));
                    }
                    continue;
                }else{
                    if(price%1000<=500){//500テ・ツ??ァツ篠嘉」ツ?ィテ」ツ?甘ゥツ?」テ」ツつ甘」ツ?古・ツ「ツ療」ツ?暗」ツつ?
                        int cc= c + 1000 - price%1000 - 500;
                        dp[i+1][cc]=max(dp[i+1][cc],P(dp[i][c].first+1,dp[i][c].second-price));
                    }else{
                        if(price%1000-500<=c){
                            int cc = c - (price%1000-500);
                            //テ・ツーツ湘ゥツ環ュテ」ツつ津ヲツクツ崚」ツつ嘉」ツ?療」ツ?ヲ500テ・ツ??ァツ篠嘉」ツつ津・ツ「ツ療」ツつ?」ツ??
                            dp[i+1][cc]=max(dp[i+1][cc],P(dp[i][c].first+1,dp[i][c].second-price));
                        }
                        //500テ・ツ??ァツ篠嘉」ツつ津・ツ「ツ療」ツつ?」ツ?陛」ツ?堙」ツ?ォテ・ツーツ湘ゥツ環ュテ」ツ??」ツ?妥・ツ「ツ療」ツつ?」ツ??
                        int cc = c + (1000-price%1000);
                        dp[i+1][cc]=max(dp[i+1][cc],P(dp[i][c].first,dp[i][c].second-price));
                    }
                }
            }
        }
        P ans = P(0,-5000000);
        for(int c=0;c<50000;c++) if(dp[n][c].second>-5000000) ans = max(dp[n][c],ans);
        cout<<ans.first<<' '<<-ans.second<<endl;
    }


    return 0;
}

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

using namespace std;

const int N = 1e5 + 3;
char a[N];
int n;

int main() {
	scanf("%s", a + 1);
	n = int(strlen(a + 1));
	stack<int> st;
	st.push(2);
	int res = 0;
	for (int i = 1; i <= n; ++i) {
		if (((a[i] - '0') ^ st.top()) == 1) {
			res += 2;
			st.pop();
		}
		else st.push(a[i] - '0');
	}
	printf("%d", res);
	return 0;
}


Measured memory_bytes: 768
#include<stdio.h>
main()
{
    int a,b,c;
    scanf("%d %d",&a,&b);
    c=a+b;
    if(a%3==0)
        printf("Possible\n");
    else if(b%3==0)
        printf("Possible\n");
    else if(c%3==0)
        printf("Possible\n");
    else
        printf("Impossible\n");
}


Measured memory_bytes: 128
n=input()
m=input()
le=len(m)
check=0
for i in range(len(n)-le,-1,-1):
    count=0
    for j in range(le):
        if m[j]==n[i+j]:
            count+=1
    if le-count==n[i:i+le].count('?'):
        n=n[0:i]+m+n[i+le:len(n)]
        check=1
        n=n.replace('?','a')
if check==1:
    print(n)
else:
    print("UNRESTORABLE")

Measured memory_bytes: 3064
// g++ -std=c++11 temp.cpp
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())

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

#define INF INT_MAX/3

#define MAX_N 1000

ll f(ll b,ll n){
	if(n<b)return n;
	else return f(b,(ll)(n/b))+(n%b);
}

int main(){
	cin.sync_with_stdio(false);
	ll n,s;
	cin>>n>>s;
	if(s==n){
		cout<<n+1<<endl;
		return 0;
	}
	ll b;
	for(b=2;b*b<=n;b++){
		if(f(b,n)==s){
			cout<<b<<endl;
			return 0;
		}
	}
	for(ll q=b;q>=1;q--){
		ll b=(n-s)/q+1;
		if(b>=2&&f(b,n)==s){
			cout<<b<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int ar[27][100009] ;
int main()
{
    string s ; cin>>s ; int sz=s.size() ;
    s=" "+s ;
    for(int i = 1 ; i < s.size() ; i++)
    {
        int x=s[i]-'a' ;
        ar[x][i]++ ;
    }
    for(int i = 0 ; i < 26 ; i++)
    {
        for(int j = 1 ; j < s.size() ; j++) ar[i][j]+=ar[i][j-1] ;
    }
    int lo=2 , hi=s.size()-1 , fl=0 ;
    while(lo<=hi)
    {
        //cout<<lo<<" "<<hi<<endl ;
        int md=(lo+hi+1)/2 ;
        for(int i = 1 ; i < s.size() ; i++)
        {
            int j=i+md-1 ;
            if(j>=s.size()) break ;
            int x=j-i+1 ;
            for(int l = 0 ; l < 26 ; l++)
            {
               // cout<<ar[l][j]-ar[l][i-1]<<" chk "<<l<<" "<<i<<" "<<j<<endl ;
                if(ar[l][j]-ar[l][i-1]>md/2) {cout<<i<<" "<<j<<endl ; fl=1 ; break ;}
            }
            if(fl) break ;
        }
        if(fl) break ;
        else hi=md-1 ;
    }
    if(!fl) cout<<"-1 -1"<<endl ;
}


Measured memory_bytes: 14004
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <list>
#include <sys/timeb.h>
#include <fstream>
#include <set>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	int a[] = {0,2,0,1,0,1,0,0,1,0,1,0};

	int x,y;
	cin >> x>>y;

	if (a[x-1] == a[y-1]) {
		cout << "Yes" <<endl;
	} else {
		cout << "No" <<endl;
	}

	return 0;
}



Measured memory_bytes: 256