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

namespace Tasks
{
    public class A
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var S = Scanner.Scan<string>();
            if (S[S.Length - 1] == 's') S += "es";
            else S += "s";
            Console.WriteLine(S);
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 26756
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
using namespace std;
#define INF 100000
#define MAX 100000
#define MOD 1000000007n
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
//typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

int main(){
    int N;
    cin>>N;
    vector<P> V(N);
    for(int i=0;i<N;i++){
        cin>>V[i].first;
        V[i].second=i+1;
    } 
    sort(V.begin(),V.end());
    set<int> S;
    S.insert(0); S.insert(N+1);
    ll ans=0;
    for(int i=0;i<N;i++){
        int x=V[i].second;
        auto it=S.lower_bound(x); it--;
        auto it2=it++;
        ans+=(ll)(*it-x)*(x-*it2)*(i+1);
        S.insert(x);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
int main(){
	ll x,k,d;
	cin>>x>>k>>d;
	if(x<0) x=-1*x;
	if(abs(x)<d){
		if(k%2){
			cout<<abs(x-d);
		}else{
			cout<<abs(x);
		}
	}else{
		ll c=(x/d)*d;
		if((c/d)<=k){
			x-=c;
			k-=c/d;
		}else{
			x-=k*d;
			k=0;
		}
		if(k%2){
			cout<<abs(x-d);
		}else{
			cout<<abs(x);
		}
	}
}


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

typedef long long ll;
#define fio() cin.tie(0); ios::sync_with_stdio(false);
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(c) c.begin(),c.end()
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
#define pu push
#define pb push_back
ll f_min(ll a,ll b){
    return (a>b)?b:a; 
}
ll f_max(ll a,ll b){
    return (a>b)?a:b;
}
ll f_abs(ll a){
    return abs(a);
}
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
const ll MOD = 1000000007;
const int inf = 1000000001;
const ll INF = 1e16;
ll i,j,k;


int main(){
    fio();
    ll N;
    ll arr[200005];
    ll cnt[200005];
    // ll record[200005];
    rep(i,200005){
        cnt[i] = 0;
        // record[i] = 0;
    }
    cin>>N;
    rep(i,N){
        cin>>arr[i];
        cnt[arr[i]-1]+=1;
    }

    ll re_ans=0;
    rep(j,N){
        if( cnt[j]>1 ){
            ll t = cnt[j];
            re_ans += t*(t-1)/2;
        }
    }
    // cout<<re_ans<<endl<<endl;
    rep(i,N){
        ll tnum = cnt[arr[i]-1];
        ll ans = re_ans - ( (tnum)*(tnum-1)/2 ) + ( (tnum-1)*(tnum-2)/2);
        cout<<ans<<endl;
        // cnt[arr[i]-1]-=1;
        // ll ans=0;
        // rep(j,N){
        //     if( cnt[j]>1 ){
        //         ans+= cnt[j]*(cnt[j]-1)/2;
        //     }
        // }
        // cout<<ans<<endl;
        // cnt[arr[i]-1]+=1;
    }

}

Measured memory_bytes: 5760
ls=list(input())
first=[ls[0],ls[1]]
second=[ls[2],ls[3]]

if ls[0]=="0":
    del first[0]
if ls[2]=="0":
    del second[0]

a=int("".join(first))
b=int("".join(second))

def can_be_month(n):
    if n>=1 and n<=12:
        return True
    else:
        return False

if can_be_month(a) and can_be_month(b):
    print("AMBIGUOUS")
elif can_be_month(a):
    print("MMYY")
elif can_be_month(b):
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3064
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def solve(N, M):
    ans = min(M // 2, N)
    
    x = (M - 2*N) // 4
    for i in range(x - 5, x + 6):
        if i >= 0 and M >= 2 * i:
            M2 = M - 2 * i
            N2 = N + i
            ans = max(ans, min(M2 // 2, N2))

    return ans


N, M = map(int,input().split())
ret = solve(N,M)
print(ret)



Measured memory_bytes: 3060
from itertools import permutations


N, M, *ab = map(int, open(0).read().split())
g = [[0] * N for _ in range(N)]
for a, b in zip(*[iter(ab)] * 2):
    g[a - 1][b - 1] = 1
    g[b - 1][a - 1] = 1

ans = 0
for path in permutations(range(1, N)):
    path = [0] + list(path)
    if all(g[v][nv] for v, nv in zip(path, path[1:])):
        ans += 1
print(ans)


Measured memory_bytes: 9200
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int val=700;
	string str;
	cin>>str;
	for(int i=0;i<3;i++){
		if(str[i]=='o'){
			val += 100;
		}
	}
	cout<<val<<endl;
	return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  int a, b, c, d;
  readf("%s %s %s %s\n", &a, &b, &c, &d);
  max(a*b, c*d).writeln;
}


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

#define MAX (100001)
#define MOD (1000000007)
long long fac[MAX] = { 1,1 };
long long inv[MAX] = { 1,1 };
long long invsum[MAX] = { 1,1 };

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	for (int i = 2; i <= n; ++i) {
		fac[i] = fac[i - 1] * i%MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		invsum[i] = (invsum[i - 1] + inv[i]) % MOD;
	}

	long long a, b,ans=0;
	for (int i = 1; i <= n; ++i) {
		cin >> a;
		b = (invsum[i] + invsum[n - i + 1] - 1) % MOD;
		ans += (a * b) % MOD;
		ans %= MOD;
	}
	ans *= fac[n] % MOD;
	ans %= MOD;

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
  
int main()
{	
	int n;
	cin>>n;
	int c[n];
	for(int i=0;i<n;i++)
	cin>>c[i];
	int dp[n];
	dp[0]=0;
	dp[1]=abs(c[1]-c[0]);
	for(int i=2;i<n;i++)
	dp[i]=min(dp[i-2]+abs(c[i]-c[i-2]),dp[i-1]+abs(c[i]-c[i-1]));
	cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void)
{
	int a, b;

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

	if (a < b)
	{
		printf("a < b\n");
	}
	else if (a > b)
	{
		printf("a > b\n");
	}
	else
	{
		printf("a == b\n");
	}

	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
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 long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){

    vector<int>p;
    p.push_back(2);
    int at;
    bool flag=true;
    for(int at=2;at<100010;at++){
        flag=true;
        for(auto itr=p.begin();itr!=p.end() and flag;itr++){
            if(at%*itr==0){
                flag=false;
            }
        }
        if (flag and (int) sqrt(at) * (int)sqrt(at) !=at){
            p.push_back(at);
         //   clog<<at<<endl;
        }
    }
    vector<int>ans(100009,0);
    ans[1]=0;
    ans[3]=1;
    auto ter=p.begin();
    ter+=2;
    //clog<<*ter<<endl;
    for(int i=4;i<100002;i++){
        ans[i]=ans[i-1];
        if(i==*ter){
            if(*lower_bound(p.begin(),ter,(i+1)/2)==(i+1)/2){
                ans[i]++;
            }
            ter++;
        }
     //   clog<<ans[i]<<endl;

    }
    int q;
    cin >>q;
    int l,r;
    rep(i,q){
        cin>>l>>r;
        cout << ans[r+1]-ans[l-1] << endl;
       // clog<<ans[r+1]<<" "<<ans[l-1]<<endl;
    }
 
}

Measured memory_bytes: 1152
#include<iostream>
#include<queue>
using namespace std;
typedef long long ll;
priority_queue<int>q;
int main()
{
	int n,m;
	ll x;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		q.push(x);
	}
	for(int i=0;i<m;i++)
	{
		if(!q.empty())
		{
			int t;
			t=q.top();
			t=t/2;
			q.pop();
			q.push(t);
		}
	}
	ll sum=0;
	while(!q.empty())
	{
		sum+=q.top();
		q.pop();
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 892
import java.util.*;
 
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int [] A = new int[N];
        int [] B = new int[N-1];

        for(int i =0; i<N-1; i++){
            B[i] = sc.nextInt();
        }
        

        A[0] = B[0];
        
        for(int i=1; i<N; i++){
            A[i] = B[i-1];
        }
        
        for(int i=1; i<N; i++){
            if(A[i]<A[i-1]){
                A[i-1] = A[i];
            }
        }
        
        int sum =0;
        for(int i=0; i<N; i++){
        sum+=A[i];
        }
            
        
        System.out.println(sum);
        
   }  	
}

Measured memory_bytes: 21844
def slove():
    import sys
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    b = True
    for i in range(len(s)):
        if i % 2 == 0:
            if s[i] == "R" or s[i] == "U" or s[i] == "D":
                b = True
            else:
                b = False
                break
        else:
            if s[i] == "L" or s[i] == "U" or s[i] == "D":
                b = True
            else:
                b = False
                break
    if b:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
main :: IO ()
main = do
  l <- readLn
  print $ solve l

data Graph = Graph !Int ![(Int, Int, Int)]

instance Show Graph where
    show (Graph n es)
        = shows n " " ++ shows (length es) "\n"
        ++ concatMap (\(x, y, z) ->
            (shows x " " ++ shows y " " ++ shows z "\n")) es

solve :: Int -> Graph
solve n = go n
  where
    go 1 = Graph 2 [(1, 2, 0)]
    go 2 = Graph 2 [(1, 2, 1), (1, 2, 0)]
    go 3 = Graph 2 [(1, 2, 2), (1, 2, 1), (1, 2, 0)]
    go x = case quotRem x 2 of
        (q, 0) -> let Graph l es = go q
                  in Graph (l + 1) ((l,l+1,q):(l,l+1,0):es)
        (q, 1) -> let Graph l es = go q
                  in Graph (l + 1) ((1,l+1,x-1):(l,l+1,q):(l,l+1,0):es)


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

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut h: Vec<i32> = (0..n).map(|_| iter.next().unwrap().parse().unwrap()).collect();
    h.reverse();
    let mut current = h[0];
    let mut ans = true;
    for x in &mut h[1..] {
        if current + 1 == *x {
            *x -= 1;
        }

        if current < *x {
            ans = false;
            break;
        }

        current = *x;
    }

    println!("{}", if ans { "Yes" } else { "No "});
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define rep(i, e, n) for (int i = e; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const ll inf=1000000000007;

int main() {
  int n,q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> a(n);
  a[0]=0;
  rep(i,1,n){
    if(s[i-1]=='A' && s[i]=='C') {
     a[i]= a[i-1]+1;
    }
    else a[i]=a[i-1];
  }
//  rep(i,0,n) cout << a[i] << ' ';

  rep(i,0,q){
    int l,r;
    cin >> l >> r;
    l--; r--;
    cout << a[r] - a[l] << endl;
  }

  return 0;
}

Measured memory_bytes: 3836
#include <list>
#include <cstdio>

int main()
{
	int n, v;

	char c[12];

	std::list<int> l;

	scanf("%d", &n);

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

		if (c[0] == 'i')
		{
			scanf("%d", &v);

			l.push_front(v);
		}
		else if (c[6] == 'F')
		{
			l.pop_front();
		}
		else if (c[6] == 'L')
		{
			l.pop_back();
		}
		else
		{
			scanf("%d", &v);

			std::list<int>::iterator it = l.begin();

			std::list<int>::iterator end_it = l.end();

			while (it != end_it)
			{
				if (*it == v)
				{
					l.erase(it); break;
				}

				it++;
			}
		}
	}

	std::list<int>::iterator it = l.begin();

	std::list<int>::iterator start_it = l.begin();
	std::list<int>::iterator end_it = l.end();

	while (it != end_it)
	{
		if (it == start_it)
		{
			printf("%d", *it);
		}
		else
		{
			printf(" %d", *it);
		}

		it++;
	}

	printf("\n");

	return 0;
}

Measured memory_bytes: 33880
#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define fst first
#define snd second

#define fr(i,n)     for (int i = 0; i < n; i++)
#define frr(i,n)    for (int i = 1; i <= n; i++)

//#define endl '\n'
#define gnl cout << endl
#define chapa cout << "oi meu chapa" << endl
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
//cout << setprecision(9)<<fixed;

#define dbg(x)  cout << #x << " = " << x << endl
#define all(x)  x.begin(),x.end()

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

const int INF = 0x3f3f3f3f;
const ll llINF = (long long)(1e18) + 100;   
const int MAXN = 1e5 + 10;
const ll mod=1e9+7;

int x, y, a, b, c;
vector<ll> p, q, r;

int32_t main(){
	fastio;
	cin>>x>>y>>a>>b>>c;

	int aux;
	fr(i, a){
		cin>>aux;
		p.pb(aux);
	}
	fr(i, b){
		cin>>aux;
		q.pb(aux);
	}
	fr(i, c){
		cin>>aux;
		r.pb(aux);
	}

	sort(all(p)); reverse(all(p));
	sort(all(q)); reverse(all(q));
	sort(all(r)); reverse(all(r));

	int pos;
	ll ans = 0;

	pos = 0;
	while (pos < x) 
		ans += p[pos++];

	pos = 0;
	while (pos < y)
		ans += q[pos++];
	x--;
	y--;


	for (int i = 0; i < c; i++){
		int ch = -1;
		if (x >= 0 and y >= 0){
			if (p[x] <= q[y])
				ch = 0;
			else
				ch = 1;
		}
		else if (x >= 0)
			ch = 0;
		else if (y >= 0)
			ch = 1;
		if (ch == 0 and p[x] < r[i])
			ans += r[i] - p[x--];
		if (ch == 1 and q[y] < r[i])
			ans += r[i] - q[y--];
	}

	cout<<ans<<endl;		 


}

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

int main(){
  int n;
  cin>>n;
  
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  
  int sum=0;
  for(int i=0;i<n;i++){
    sum+=a[i];
  }
  
  cout<<sum-n<<endl;
}

Measured memory_bytes: 256
while True :
    n = int(input())
    
    if n == 0 :
        break
    
    else :
        A = list(map(int, input().split()))
        cnt = 0
        
        ave = sum(A) / n
        # 平均 average
        
        for i in range(len(A)) :
            if A[i] <= ave :
                cnt += 1
                
        print(cnt)
        


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


int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int mi=1001001;
  int ans=0;
  rep(i,n) {
      if(a[i]<=mi) {
          ans++;
          mi=a[i];
      }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(4100000)

import math
from collections import deque

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)

I_MIN = 0
I_MAX = 0
J_MIN = 0
J_MAX = 0
I_DELTA = [1, 0, -1, 0]
J_DELTA = [0, -1, 0, 1]
visited_set = set()
grid = None


def resolve():
    global visited_set, I_MAX, J_MAX, grid

    H, W = [int(x) for x in sys.stdin.readline().split()]
    grid = [list(sys.stdin.readline().split()[0]) for _ in range(H)]

    # logger.debug('{}'.format([H, W, grid]))

    I_MAX = H - 1
    J_MAX = W - 1
    queue = deque()

    max_dist = 0
    for i in range(H):
        for j in range(W):
            if grid[i][j] == '.':
                queue.append((i, j, 0))
                visited_set.add((i, j))
                while (len(queue) > 0):
                    i, j, dist = queue.popleft()
                    if max_dist < dist:
                        max_dist = dist
                    for d in range(4):
                        i_next = i + I_DELTA[d]
                        j_next = j + J_DELTA[d]
                        if (
                                i_next, j_next
                        ) not in visited_set and I_MIN <= i_next <= I_MAX and J_MIN <= j_next <= J_MAX:
                            visited_set.add((i_next, j_next))
                            s = grid[i_next][j_next]
                            if s == '.':
                                queue.append((i_next, j_next, dist + 1))
                else:
                    visited_set.clear()
    print(max_dist)


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 3
...
...
..."""
        output = """4"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3 5
...#.
.#.#.
.#..."""
        output = """10"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """1 2
.."""
        output = """1"""
        self.assertIO(input, output)

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

inline int read() {
  int ret, cc, sign = 1;
  while (!isdigit(cc = getchar()))
    sign = cc == '-' ? -1 : sign;
  ret = cc - 48;
  while (isdigit(cc = getchar()))
    ret = cc - 48 + ret * 10;
  return ret * sign;
}

const int MOD = 1e9 + 7;
inline int add(int a, int b) { return (a += b) >= MOD ? a - MOD : a; }
inline int sub(int a, int b) { return (a -= b) <    0 ? a + MOD : a; }
inline int mul(int a, int b) { return 1ll * a * b % MOD; }
inline void upd(int &a, int b) { (a += b) >= MOD ? a -= MOD : 0; }
inline int qpow(int a, int p) {
  int ret = 1;
  for (; p; p >>= 1, a = mul(a, a))
    if (p & 1) ret = mul(ret, a);
  return ret;
}

const int MAXN = 110;
int f[MAXN][MAXN][MAXN];
int a[MAXN];
int n;

int main() {
  n = read();
  for (int i = 1; i < n + n; ++i) a[i] = read();
  std::sort(a + 1, a + n + n);
  f[n][1][0] = 1;
  for (int i = n - 1; i; --i) {
    int pl = (a[i] != a[i + 1]);
    int pr = (a[n + n - i] != a[n + n - (i + 1)]);
    for (int l = 0; l < n + n; ++l)
      for (int r = 0; r < n + n; ++r) {
        for (int L = 1; L <= l + pl; ++L)
          upd(f[i][l + pl - L + 1][r + pr + (L > 1)], f[i + 1][l][r]);
        for (int R = 1; R <= r + pr; ++R)
          upd(f[i][l + pl + 1][r + pr - R], f[i + 1][l][r]);
      }
  }
  int ans = 0;
  for (int i = 0; i < n + n; ++i)
    for (int j = 0; j < n + n; ++j)
      upd(ans, f[1][i][j]);
  printf("%d\n", ans);
}



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

int main() {
	int n, T[100]; cin >> n;
	double V[100];
	for (int i = 0; i < n; i++)cin >> T[i];
	for (int i = 0; i < n; i++)cin >> V[i];
	
	int t = 0;
	double vl[40001], vr[40001];
	vl[0] = 0;
	for (int i = 0; i < n; i++) for (int j = 0; j < 2 * T[i]; j++) {
		vl[t + 1] = min(vl[t] + 0.5, V[i]);
		t++;
	}
	vr[t] = 0;
	for (int i = n - 1; i >= 0; i--) for (int j = 0; j < 2 * T[i]; j++) {
		vr[t - 1] = min(vr[t] + 0.5, V[i]);
		t--;
	}

	double ans = 0;
	t = 0;
	for (int i = 0; i < n; i++) for (int j = 0; j < 2 * T[i]; j++) {
		ans += (min(vl[t], vr[t]) + min(vl[t + 1], vr[t + 1])) / 4;
		t++;
	}
	cout << setprecision(9) << ans << endl;

	return 0;
}

Measured memory_bytes: 896
// Copyright (C) 2017 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>

#define x first
#define y second
#define MP std::make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

using std::pair;
using std::vector;
using std::string;

typedef long long LL;
typedef pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
string procStatus()
{
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        f = (ch == '-' ? -1 : 1);
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MAXN = 6e5 + 15;

int N;
int A[MAXN];

void input()
{
    static char inp[MAXN];
    scanf("%s", inp);
    N = strlen(inp);
    for (int i = 0; i < N; ++i) {
        A[i] = inp[N-i-1] - '0';
    }
}

void solve()
{
    A[0] *= 9;
    for (int i = 0; i < N; ++i) {
        A[i+1] *= 9;
        A[i+1] += A[i] / 10;
        A[i] %= 10;
    }

    int cnt = 0;
    for (int i = 0; i <= N; ++i) {
        cnt += A[i];
    }
    for (int i = 0; ; ++i) {
        if (cnt <= i && (cnt - i) % 9 == 0) {
            printf("%d\n", (i + 8) / 9);
            return;
        }
        for (int j = 0; ++A[j] == 10; ++j) {
            cnt -= 9;
            A[j] = 0;
        }
        cnt += 1;
    }
}

int main()
{
#ifdef __DEBUG
    freopen("E.in", "r", stdin);
    freopen("E.out", "w", stdout);
#endif

    input();
    solve();

    return 0;
}

// 丁丁漏水夜何长，漫漫轻云露月光。
//     -- 张仲素《秋夜曲》


Measured memory_bytes: 2688
#!/usr/bin/env python
#coding: UTF-8
while True:
    h,w = map(int,raw_input().split())
    if h+w==0:
    	break
    else:
    	print w*'#'# ??????####
    	for hight in range(h-2):
            print '#'+(w-2)*'.'+'#'
        print w*'#'#????????????####
        print

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

using namespace std;

#define maxn (int)1e5

  long long a[maxn];

int main() {
    int n, c = 0;
    cin >> n;
    int f = 0;
    long long sum = 0, minn = maxn;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] < 0) { c++; a[i] = -a[i]; }
        if (a[i] == 0) f = 1; 
        sum += a[i]; 
    }
    sort(a, a + n);
    if (c % 2 == 0 || f == 1)
        cout << sum;
    else cout << sum - 2 * a[0];
    return 0;
}


Measured memory_bytes: 1024
n=int(input())

ans=0

a=[]
b=[]

for _ in range(n):
    x=int(input())
    a.append(x)
    b.append(x)
b.sort()

dic={}
for i,v in enumerate(b):
    dic[v]=i%2

cnt=0
for i,v in enumerate(a):
    if i%2 != dic[v]:
        cnt+=1
print(cnt//2)

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


// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef complex<int> ci;
typedef complex<double> cd;
typedef complex<long double> cld;

// macros
#define rep(i, a, b) for(int i=a; i<b; i++)
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define tr(c, it) for(auto it=(c).begin(); it!=c.end(); it++)
#define pb push_back
#define mp make_pair
#define bitcount __builtin_popcount
#define watch(x) cerr<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// template functions
template <typename T>
inline void printV(vector<T>& a) { rep(i, 0, sz(a)) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printV(vector<T>& a, int n) { rep(i, 0, n) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printVV(vector<vector<T>>& a)
{
	rep(i, 0, sz(a)) {
		printV(a[i]);
	}
	cout<<"\n";
}

template <typename T>
inline void clearVV(vector<vector<T>>& a)
{
	for(auto& x:a) {
		x.clear();
	}
	a.clear();
}
template <typename T>
inline void assignVV(vector<vector<T>> &a, T val)
{
	for(int i=0; i<sz(a); i++) {
		for(int j=0; j<sz(a[i]); j++) {
			a[i][j]=val;
		}
	}
}

// random number generation
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// constants
const long double eps = LDBL_EPSILON;
const int inf = 5e8;
const int modn = 1e9+7;
const int MAX = 1e5;

inline int add(int a, int b)
{
	int ret=((ll)a+b)%modn;
	if(ret<0) {
		ret=(ret+modn)%modn;
	}
	return ret;
}

inline int mul(int a, int b)
{
	int ret=((ll)a*b)%modn;
	if(ret<0) {
		ret=(ret+modn)%modn;
	}
	return ret;
}

int freq[26];

int solve(int i)
{
	if(i==26) return 0;
	int ans=add(freq[i], mul(solve(i+1), 1+freq[i]));
	return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
	int n;
	cin>>n;
	string s;
	cin>>s;
	for(int i=0; i<n; i++) {
		freq[s[i]-'a']++;
	}
	int ans=solve(0);
	cout<<ans<<"\n";	
    return 0;
}



Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>




int main() {
	int a, b, c;
	int A, B, C;
	int min = 0,count = 0;
	scanf("%d %d %d", &a, &b, &c);

	if (a + b > b + c) {
		min = b + c;
		if (b + c > a + c) {
			min = a + c;
		}
	}
	else {
		min = a + b;
		if (a + b > a + c){
			min = a + c;
		}
	}

	
	
	printf("%d\n", min);
	


	return 0;
}

Measured memory_bytes: 128
def abc054_c_one_stroke_paths():
    import copy
    N, M = map(int, input().split())

    # create graph G
    G = {}
    for m in range(M):
        a, z = map(int, input().split())
        G[a] = G.get(a, [])
        G[a].append(z)
        G[z] = G.get(z, [])
        G[z].append(a)

    # print(G)

    # find all paths
    if G.get(1, 0) == 0:
        print(0)
        return

    paths = []

    def solve(a, path):
        path.append(a)
        if len(path) == N:
            paths.append(path)
            return
        for z in G.get(a):
            p = copy.copy(path)
            if z in p:
                continue
            solve(z, p)

    solve(1, [])
    # print(paths)
    print(len(paths))


##########
if __name__ == "__main__":
    abc054_c_one_stroke_paths()


Measured memory_bytes: 4328
#include <iostream>

using namespace std;

int main(){
  int N;
  cin >> N;

  int i = 10;
  int total = 0;
  while(N != 0){
    total += (N % i);
    N /= i;
  }
  if(total == 1) total = 10;
  cout << total << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int tmp = 0;
		String s = String.valueOf(n);
		for (int i = 0; i < s.length(); i++) {
			int j = Integer.parseInt(s.substring(i, i+1));
			tmp += j;
		}
		if (n % tmp == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 25172
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n,k;
  cin>>n>>k;
  if(k==0){
    cout<<n*n<<endl;
    return 0;
  }
  Int ans=0;
  for(Int b=k+1;b<=n;b++){
    Int l=0,r=n+1;
    while(l+1<r){
      Int m=(l+r)>>1;
      if(b*m-1<=n) l=m;
      else r=m;
    }
    //cout<<b<<" "<<l<<" "<<r<<endl;
    ans+=(b-k)*l;
    Int x=n-(b*l+k)+1;
    if(x>=0) ans+=x;
  }
  cout<<ans<<endl;
  return 0;
}


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

int main()
{
    int d, l, r, count=0;
    cin>> l >> r >> d;
    for(int i=l; i<=r; i++) {
        if(i%d==0)
            count++;
    }
    cout<< count << endl;

    return 0;
}


Measured memory_bytes: 3592
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}


fn main() {
    input! {
        n: usize,
        v: [i64; n],
        c: [i64; n]
    }

    let mut sum = 0;
    for i in 0..n {
        let diff = v[i] - c[i];
        if diff > 0 {
            sum += diff;
        }
    }
    println!("{}", sum);
}



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

bool SameCheck(string A, string B){
    if(A.size()==B.size()){
        for(int i=0; i<A.size(); i++){
			if(A.at(i)==B.at(i)){
            	if(i==A.size()-1){
                  return true;
                }
              	else{
                  continue;
                }
       	 	}
          else{
            return false;
            break;
          }
        }
    }
    else{
        return false;
    }
}

bool ShiriCheck(string A, string B){
    if(A.at(A.size()-1)==B.at(0)){
        return true;
    }
    else{
        return false;
    }
}


int main (){
    int N;
    cin>>N;
    vector<string> Words(N);
    vector<int> Leng(N);
    bool ClearFlug=true;
    for(int i=0; i<N;i++){
        cin>>Words.at(i);
        Leng.at(i)=Words.at(i).size();
    }

    for(int i=0; i<N-1; i++){
        if(ShiriCheck(Words.at(i), Words.at(i+1))){
            continue;
        }
        else{
            ClearFlug=false;
            break;
        }
    }

    if(ClearFlug){
        for(int i=0; i<N; i++){
            for(int j=i+1; j<N; j++){
                if(!(SameCheck(Words.at(i), Words.at(j)))){
                    continue;
                }
                else{
                    ClearFlug=false;
                    break;
                }
            }
        }
    }
    if(ClearFlug){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

 //strcmp()を使ってもいい？
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;

int main(){

    int h, w; cin >> h >> w;

    char square[h][w];
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> square[i][j];
        }
    }

    int xconnect[h][w] = {};
    int yconnect[h][w] = {};

    vector<int> jobst;
    vector<int> iobst;

    for(int i=0; i<h; i++){
        jobst.clear();
        jobst.push_back(-1);
        for(int j=0; j<w; j++){
            if(square[i][j] == '#'){
                jobst.push_back(j);
            }
        }
        jobst.push_back(w);
        int index = 0;
        // for(int j=0; j<jobst.size(); j++){
        //     cout << jobst[j] << " ";
        // }
        // cout << endl;
        for(int j=0; j<w; j++){
            if(square[i][j] == '.'){
                xconnect[i][j] = jobst[index+1] - jobst[index] - 1;
            }
            else{
                index++;
            }
        }
    }

    for(int j=0; j<w; j++){
        iobst.clear();
        iobst.push_back(-1);
        for(int i=0; i<h; i++){
            if(square[i][j] == '#'){
                iobst.push_back(i);
            }
        }
        iobst.push_back(h);
        int index = 0;
        for(int i=0; i<h; i++){
            if(square[i][j] == '.'){
                yconnect[i][j] = iobst[index+1] - iobst[index] - 1;
            }
            else{
                index++;
            }
        }
    }

    int ans = 0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(xconnect[i][j] != 0 && yconnect[i][j] != 0){
                if(ans < xconnect[i][j] + yconnect[i][j] - 1){
                    ans = xconnect[i][j] + yconnect[i][j] - 1;
                }
            }
        }
    }

    cout << ans << endl;

    // for(int i=0; i<h; i++){
    //     for(int j=0; j<w; j++){
    //         cout << xconnect[i][j];
    //     }
    //     cout << endl;
    // }
    
    return 0;
}

Measured memory_bytes: 35456
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if((a+b)%2==1)
	{
		printf("%d\n",(a+b)/2+1);
	}
	else
	{
		printf("%d\n",(a+b)/2);
	}
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <functional>
#include <utility>
#include <sstream>
#include <numeric>
#include <deque>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;


int main(int argc, const char * argv[]) {
  int n;
  cin >> n;
  string s;
  cin >> s;


  ll r = 0;
  ll g = 0;
  ll b = 0;
  // vector<int> rgb;
  rep(i, n){
    if(s[i] == 'R'){
      r++;
    }else if(s[i] == 'G'){
      g++;
    }else if(s[i] == 'B'){
      b++;
    }
  }
  ll ans = r * g * b;
  if(ans == 0){
    cout << 0 << endl;
    return 0; 
  }
  rep(i, n){
    repd(j, i+1, n){
      ll k = j+(j-i);
      if(k >= n) continue;
      if(s[j] != s[i] && s[k] != s[j] && s[i] != s[k]) ans--;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3164
export class Main {
  static main(input): string {
    const t: string[] = input.split("\n")[0].split("");
    return `${t[0] == t[1] || t[1] == t[2] || t[2] == t[3] ? "Bad" : "Good"}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

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

int main() {
	int h, a; cin >> h >> a;
	int ans = (h % a == 0 ? h / a : h / a + 1);
	cout << ans << endl;
	return 0;
}


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

int main(){
  int a,b;
  int cnt = 0;
  cin>>a>>b;
  for (int i = a; i <= b; i++) {
    string s = to_string(i);
    if (s.at(0) ==s.at(4) && s.at(1)==s.at(3)) cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;


int main(){
    int64_t a, b;
    scanf("%lld%lld", &a, &b);
    printf("%lld\n", abs((a - 2) * (b - 2)));
    return 0;
}

Measured memory_bytes: 764
#include<stdio.h>

int main(void){
    int n,i,s,a_even;
    scanf("%d",&n);
    int a[n+1];
    int x[n+1];

    i = 0, s = 0, a_even = 0;
    while(i < n){
        if(i == n)
        break;
        scanf("%d",&a[i]);
        s += a[i];
        if(i % 2 == 1)
        a_even += a[i];
        i++;
    }

    x[0] = s - 2 * a_even;
    for(i=1; i<n; i++){
        x[i] = 2 * a[i-1] - x[i-1];
    }

    for(i=0; i<n-1; i++){
        printf("%d ",x[i]);
    }
    printf("%d\n",x[n-1]);

    return 0;

}

Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
int a[114514],cnt[114514],ans[114514]; int n, x;
signed main(){
	cin >> n >> x;
	rep(i, n)cin >> a[i];
	if (n == 1)cout << abs(a[0] - x) << endl;
	else {
		rep(i, n)cnt[i] = abs(x - a[i]);
		ans[0] = gcd(cnt[0], cnt[1]);
		for (int i = 1; i < n - 1; i++)ans[i] = gcd(ans[i - 1], cnt[i + 1]);
		cout << ans[n - 2] << endl;
	}
	getchar(); getchar(); return 0;
}

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


			

int main(){
	
	int N,K;
	cin>>N>>K;
	
	deque<long long> D(0);
	for(int i=0;i<N;i++){
		long long a;
		cin>>a;
		D.push_back(a);
	}
	long long maxi = 0;
	for(int i=K/2;i<=K;i++){
		for(int j=0;j<=i;j++){
			deque<long long> DD = D;
			long long x = 0;
			vector<long long> V(0);
			for(int k=0;k<j;k++){
				if(DD.size()!=0){
					V.push_back(DD.front());
					DD.pop_front();
				}
			}
			for(int k=0;k<i-j;k++){
				if(DD.size()!=0){
					V.push_back(DD.back());
					DD.pop_back();
				}
			}
			sort(V.begin(),V.end(),greater<long long>());
			//cout<<V.size()<<endl;
			if(V.size()==0)continue;
			for(int k=0;k<V.size();k++){
				if(V[k]<0&&k>=V.size()-(K-i))break;
				x+=V[k];
				
			}
			//if(x==16)cout<<i<<','<<j<<endl;
			maxi=max(x,maxi);
		}
		
		
		
	}
	
	cout<<maxi<<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int x[10000],i=1,j;
	scanf("%d",&x);
	while(x[i-1]!=0){
		scanf("%d",&x[i]);
		i++;
	}
	
	while(x[i-1]==0){
		for(j=1;j<i;j++){
		printf("Case %d: %d\n",j,x[j-1]);
		}
	break;
	
	}
	
	return 0;
}

Measured memory_bytes: 640
/*input
1 1 1
10 10 10
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (int)(lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

pll v[maxn];

map<ll,ll> mp;

int main(){
	IOS;
	int n,ma,mb;
	cin>>n>>ma>>mb;
	REP(i,n){
		ll a,b,c;
		cin>>a>>b>>c;
		v[i]=MP(a*mb-b*ma,c);
	}

	REP(i,1<<(n/2)) if(i){
		ll val=0, mon=0;
		REP(j,n/2){
			if((i>>j)&1){
				val+=v[j].F;
				mon+=v[j].S;
			}
		}
		if(mp.count(val)){
			mp[val]=min(mp[val],mon);
		}
		else mp[val]=mon;
	}
	// for(auto i:mp) countt<<i<<'\n';
	ll ans=INF;
	REP(i,1<<(n-n/2)){
		ll val=0, mon=0;
		REP(j,n-n/2){
			if((i>>j)&1){
				val+=v[n/2+j].F;
				mon+=v[n/2+j].S;
			}
		}
		if(mp.count(-val)){
			ans=min(ans,mp[-val]+mon);
		}

		if(val==0&&i!=0){
			ans=min(ans,mon);
		}
	}
	if(ans==INF){
		cout<<"-1\n";
	}
	else cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
import java.io.*;

class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
int count;
while((line=br.readLine())!=null){
count=1;
int n=Integer.parseInt(line);
for(int i=1;i<=n;i++){
count+=i;
}
System.out.println(count);
}
}
}

Measured memory_bytes: 17788
#include <bits/stdc++.h>
 
using namespace std;
 
#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define For(I,N)   for(int I=1;I<=(N);I++)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)
#define SZ(X) ((int)(X.size()))
#define LG(X) ((int)(X.length()))
#define CL(X) (X).clear()
#define MAXEL(A,B) (*max_element(A,B))
#define MINEL(A,B) (*min_element(A,B))
#define ROPEN(X) freopen(X,"r",stdin)
#define WOPEN(X) freopen(X,"w",stdout)
#define BG(X) (X.begin())
#define EN(X) (X.end())
#define VI vector<int>
#define PII pair<int,int>
 
//cout << fixed << setprecision(20) << p << endl;
 
template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int m,n;
	cin>>m>>n;
	vector<int>v(n);
	for(int i=0;i<m;i++){
		int a;
		cin>>a;
		for(int i=0;i<a;i++){
			int z;
			cin>>z;
			z--;
			v[z]++;
		}
	}
	int ans=0;
	for(int i=0;i<n;i++){
		if(v[i]==m)ans++;
	}
	cout<<ans<<endl;
	return 0;
}





















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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  map<int,long long> b;
  // vector<long long> b(n+10);
  for (int i = 0; i < n; i++)
  {
    int A;
    cin >> A;
    a[i]=A;
    b[A]++;
  }
  
  long long sum = 0;
  for(auto pai:b){
    long long bi = pai.second;
    sum += bi*(bi-1)/2;
  }
  
  // for (int i = 0; i < n; i++)
  // {
  //   sum += b[i]*(b[i]-1)/2;
  // }
  // cout << sum << endl;

  for (int i = 0; i < n; i++)
  {
    long long ans = sum;
    ans -= b[a[i]]*(b[a[i]]-1)/2;
    ans += (b[a[i]]-1)*(b[a[i]]-2)/2;
    cout << ans << endl;
  }
}

Measured memory_bytes: 10240
/*
教练我要打ACM!
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

const int inf = 0x3f3f3f3f;

int cont[26];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  string s;
  cin >> s;
  int n = s.size();
  ll sum = 1LL * n * (n + 1) / 2 - n + 1;
  for (char x : s) {
    sum -= cont[x - 'a'];
    cont[x - 'a']++;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 720
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  string S;
  cin >> S;

  regex re{"^A[a-z](?:[a-z]*C[a-z]*)[a-z]$"};
  cout << (regex_match(S, re) ? "AC" : "WA") << endl;
  return 0;
}


Measured memory_bytes: 3704
from itertools import accumulate
N,K = map(int,input().split())
S = input()

arr = []
now = S[0]
if now == "1":
    count = 1
else:
    count = -1
for c in S[1:]:
    next = c
    if c == now:
        if now == "1":
            count += 1
        else:
            count -= 1
    else:
        arr.append(count)
        if now == "1":
            count = -1
            now = "0"
        else:
            count = 1
            now = "1"
arr.append(count)

anss = []
Sum = 0
head = 0
if arr[0] < 0:
    arr = [0] + arr
arr2 = [0] + list(accumulate(list(map(abs, arr))))
while head+2*K <= len(arr):
    tail = head+2*K
    Sum += arr2[tail+(tail < len(arr2)-1)]-arr2[head]
    #Sum += sum(map(abs, arr[head:tail+1]))
    anss.append(Sum)
    head += 2
    Sum = 0
if anss == []:
    ans = sum(map(abs,arr))
else:
    ans = max(anss)
print(ans)

Measured memory_bytes: 9988
n = int(input())

c = []
for i in range(n):
    ai, bi = [int(i) for i in input().split()]
    c.append([ai, bi, ai+bi])

d = sorted(c, key=lambda x: x[2], reverse=True)

ans = 0
for j in range(n//2):
    ans += d[j*2][0]
    ans -= d[j*2+1][1]

if n % 2 == 1:
    ans += d[n-1][0]

print(ans)

Measured memory_bytes: 25240
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX_N = 100;
int N, K;
int X[MAX_N];
int main(){
scanf("%d", &N);
scanf("%d", &K);
for(int i = 0; i < N; ++i){
scanf("%d", X + i);
}
int ans = 0;
for(int i = 0; i < N; ++i){
int tmp = min(X[i], K - X[i]);
ans += tmp;
}
printf("%d\n", ans * 2);
return 0;
}


Measured memory_bytes: 1732