akhauriyash/Code-Regression huggingface dataset:
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
#ts=time.time()
#sys.setrecursionlimit(10**6)
#input=sys.stdin.readline
show_flg=False
show_flg=True


n=I()
a=LI()
b=[]
b=[(i+1,j) for i,j in enumerate(a)]
b.sort(key=lambda x: x[1])


print(*[i for i,j in b])

Measured memory_bytes: 68660
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final long MOD = 1000000007;
		int N = sc.nextInt();
		int[] cnt = new int[N];
		for(int i=0; i<N; i++)
			cnt[sc.nextInt()]++;
		
		long ans = 1;
		for(int i=(N-1)%2; i<=N-1; i+=2) {
			if(cnt[i]==(i==0 ? 1 : 2)) {
				ans = (ans * cnt[i])%MOD;
			} else {
				ans = 0;
				break;
			}
		}
		
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 32616
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
/*
int main() {
    // 前処理
    COMinit();

    // 計算例
    cout << COM(100000, 50000) << endl;
}*/

//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
  ll N,M;
  cin >> N >> M;
  if(M != 100){
  cout << pow(10,N * 2) * M << endl;
  }
  else{
      cout << 101;
      rep(i,N)cout << "00";
      cout << endl;
  }
}


Measured memory_bytes: 256
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


x, y = LI()

print(x + y // 2)


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

int main()
{
    // int A, B;
    // cin >> A >> B;
    // vector<int> nums{1,2,3};
    // nums.erase(remove(nums.begin(), nums.end(), A), nums.end());
    // nums.erase(remove(nums.begin(), nums.end(), B), nums.end());
    // int ans = nums.at(0);
    // cout << ans << endl;
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    string ans = "";
    for (int i = 0; i < N; i++) {
        ans += S.at(i);
        ans += T.at(i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define iii tuple<int, int, int>
#define ii pair<int, int>
#define fi first
#define se second

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    // freopen("in", "r", stdin);

    ll n, w, wi, vi;
    cin >> n >> w;
    ll dp[w + 1] = {};
    for (int i = 0; i < n; ++i) {
        cin >> wi >> vi;
        for (int j = w; j >= wi; --j) dp[j] = max(dp[j], dp[j - wi] + vi);
        // for (int j = 0; j <= w; ++j) cout << dp[j] << " \n"[j == w];
    }
    cout << dp[w] << '\n';

    return 0;
}

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

double dp[3001][3001];

double Solve(double* &a,int i,int heads){
	if(heads == 0)
		return 1;

	if(i == 0)
		return 0;

	if(dp[i][heads] > -1) return dp[i][heads];
	return dp[i][heads] = a[i]*Solve(a,i-1,heads-1) + (1-a[i])*Solve(a,i-1,heads);
}

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

	double *coins = new double[n+1];

	for(int i=1;i<=n;i++){
		cin>>coins[i];
	}
	
	memset(dp,-1,sizeof(dp));

	cout<<fixed<<setprecision(10)<<Solve(coins,n,(n+1)/2)<<endl;

	return 0;
}


Measured memory_bytes: 70912
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten53 300005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;


//stack<char> stk;
//set<ll> sll;
set<pair<ll,ll> > spll;
//map<string,ll> mp;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<ll> deq;
vector<pair<ll,ll> > vh(ten53),vw(ten53);
//vector<ll> vll;
ll numh[ten53],numw[ten53];
//priority_queue<pair<ll,ll>> pq;          //decreasing

int main(void)
{
    ll m,n,i,j,k=0,d,pre=0,now,h,w,inh,inw,bh=0,bw=0;
    string s;
    cin>>h>>w>>m;
    if(m==1)
    {
        cout<<1;
        return 0;
    }
    for(i=1;i<=m;i++)
    {
        cin>>inh>>inw;
        spll.insert(mkpr(inh,inw));
        vh[inh].first--;
        vh[inh].second=inh;
        vw[inw].first--;
        vw[inw].second=inw;
    }
    sort(all(vh));
    sort(all(vw));
    for(i=0;i<m;i++)
    {
        if(bh>-vh[i].first) break;
        bh=-vh[i].first;
        for(j=0;j<m;j++)
        {
            if(bw>-vw[j].first) break;
            bw=-vw[j].first;
            pre=bw+bh;
            if(spll.find(mkpr(vh[i].second,vw[j].second))!=spll.end())
            {
                pre--;
                k=max(k,pre);
            }
            else
            {
                cout<<pre;
                return 0;
            }
        }
    }
    cout<<k;
    return 0;
}



Measured memory_bytes: 31508
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

h, n = Is()
A = LI()
if sum(A) >= h:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 77888
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
#undef LOCAL
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#ifdef LOCAL
struct PrettyOS {
    ostream& os;
    bool first;
    template <class T> auto operator<<(T&& x) {
        if (!first) os << ", ";
        first = false;
        os << x;
        return *this;
    }
};
template <class... T> void dbg0(T&&... t) {
    (PrettyOS{cerr, true} << ... << t);
}
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        dbg0(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

using P = pair<int, int>;
VV<P> g(20);
int m = 0;
void adde(int a, int b, int c) {
    if (a == 20 || b == 20) return;
    m++;
    g[a].push_back({b, c});
}

// make [0, f, 2f, ..., lf)
void solve(int p, int f, int l) {
    if (l % 2 == 1 && p != 19) {
        adde(p, 19, f * (l - 1));
        l--;
    }
    if (l == 0) return;
    adde(p, p+1, 0);
    adde(p, p+1, f);
    solve(p + 1, 2 * f, l / 2);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int l;
    cin >> l;
    
    solve(0, 1, l);

    using B = bitset<1000100>;
    V<B> dp(20);
    dp[0][0] = true;
    for (int i = 0; i <20; i++) {
        for (P p: g[i]) {
            assert(i != p.first);
            dp[p.first] |= dp[i] << p.second;
        }
    }
    for (int j = 0; j < 1000100; j++) {
        assert(dp[19][j] == (j < l));
    }

    cout << 20 << " " << m << endl;
    for (int i = 0; i < 20; i++) {
        for (P p: g[i]) {
            cout << i+1 << " " << p.first+1 << " " << p.second << endl;
        }
    }
    return 0;
}


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

int N, change[20], g[150000], h[150000], ans[150000];

int main() {
	int A, B;
	cin >> N >> A >> B;
	int cnt=0;
	for(int i=0; i<N; ++i){
		if((A&(1<<i))^(B&(1<<i))){
			++cnt;
			change[N-cnt]=i;
		}
		else change[i-cnt]=i;
	}
	if(cnt%2==0){
		cout << "NO" << endl;
		return 0;
	}
	for(int i=1; i<(1<<(N-cnt)); ++i){
		while(!(i&(1<<g[i]))) ++g[i];
	}
	int now=2;
	for(int i=2; i<=cnt; ++i){
		h[now]=i-1;
		if(i%2==0){
			for(int j=1; j<now; ++j) h[now+j]=h[j];
		}
		else{
			for(int j=1; j<now; ++j){
				if(j%2==0) h[now+j]=h[j/2];
				else h[now+j]=i-2;
			}
		}
		now *= 2;
	}
	int here=1;
	for(int i=1; i<(1<<N); ++i){
		if(i%(1<<(N-cnt))) ans[i]=change[g[i%(1<<(N-cnt))]];
		else{
			ans[i]=change[h[here]+N-cnt];
			++here;
		}
	}
	cout << "YES" << endl;
	cout << A;
	for(int i=1; i<(1<<N); ++i){
		A ^= (1<<ans[i]);
		cout << ' ' << A;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define mod 1000000007
#define show(n) cerr<<#n<<" = "<<n<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl

#define yes cout << "YES" << endl
#define no cout << "NO" << endl

using namespace std;

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using pint = pair<int,int>;

const int INF = (1 << 30);

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

    int n;
    cin >> n;
    vi vec(n);
    rep(i, n){
        cin >> vec[i];
    }

    rep(i, n){
        rep(j, n){
            //show(abs(vec[i] - vec[j]));
            if(abs(vec[i] - vec[j]) != 0){
                if(abs(vec[i] - vec[j]) % (n - 1) == 0){
                    cout << vec[i] << ' ' << vec[j] << endl;
                    return 0;
                }
            }
            
        }
    }

    return 0;
}


Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;int l(string a,string b){int m=a.size(),n=b.size(),i=0,j,s=0,c[1001][1001]={};for(a=' '+a,b=' '+b;++i<=m;)for(j=0;++j<=n;s=s<c[i][j]?c[i][j]:s)c[i][j]=a[i]==b[j]?c[i-1][j-1]+1:c[i-1][j]>c[i][j-1]?c[i-1][j]:c[i][j-1];return s;}main(){string a,b;int n;for(cin>>n;n--;)cin>>a>>b,cout<<l(a,b)<<endl;}

Measured memory_bytes: 7096
n,k=map(int,input().split())
s=str(input())
s=s+'e'
arr=[[] for _ in range(2)]
count=1
for i in range(n):
  if s[i]==s[i+1]:
    count+=1
  else:
    if s[i]=='1':
      arr[0].append(count)
      count=1
    else:
      arr[1].append(count)
      count=1
if len(arr[1])<=k:
  print(n)
else:
  if s[0]=='0':
    arr2=[0]
    arr2.extend(arr[0])
    arr[0]=arr2
  arr[0].append(0)
  arr[1].append(0)
  tmp=0
  sum=0
  count=0
  max=0
  flag=False
  for i in range(len(arr[1])-1):
    sum+=arr[0][i]
    sum+=arr[1][i]
    count+=1
    if flag:      
      sum-=arr[0][i-k]
      sum-=arr[1][i-k]
    if count==k:
      tmp=sum
      tmp+=arr[0][i+1]
      if tmp>max:
        max=tmp
      count-=1
      flag=True
  print(max)

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

struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const long long INF = 9223372000000000000/2145;
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define itn int
#define scnaf scanf
#define reutnr return
#define scamf scanf
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

signed main(){
    char a,b,c,d;
    scanf("%c%c%c%c",&a,&b,&c,&d);
    if(a==b&&b==c || b==c&&c==d) printf("Yes\n");
    else printf("No\n");
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<string> a(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		sort(a[i].begin(), a[i].end());
	}
	long long ans = 0;
	sort(a.begin(), a.end());
	int j = 1;
	for(int i = 0; i < n - 1; i++) {
		if(a[i] == a[i + 1]) {
			ans += j;
			j++;
		}else {
			j = 1;
		}
	}
	cout << ans << endl;
}

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define F first
#define S second
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
const int MOD = 1e9+7; 
const int N = 1e6; 
ll iv[3*N], f1[3*N], f2[3*N]; 

ll combi(int n, int k) 
{
	return f1[n]*f2[k]%MOD*f2[n-k]%MOD;
}


int main(void) 
{
	
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	#endif 

	iv[1]=1; 
	for (int i=2; i<3*N; i++) 
		iv[i] = MOD-MOD/i*iv[MOD%i]%MOD;
	f1[0]=f2[0]=1; 
	for (int i=1; i<3*N; i++) 
	{
		f1[i]=f1[i-1]*i%MOD; 
		f2[i]=f2[i-1]*iv[i]%MOD; 
	} 



	int r1, r2, c1, c2; 
	scanf("%d %d %d %d", &r1, &c1, &r2, &c2); 

	int ans = 0; 
	cout << (combi(r2+c2+2, c2+1)-combi(r1+c2+1, c2+1)-combi(r2+c1+1, c1)+combi(r1+c1, c1)%MOD+MOD)%MOD; 

	

	//cout << fixed << setprecision(9) << (double) (ans+k)*0.5 << '\n'; 




 
 
 
	return 0;   

}












Measured memory_bytes: 70528
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MinMaxSum
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();

            string line = Console.ReadLine();
            string[] strs = line.Split(' ');

            List<int> list = new List<int>();
            foreach (string str in strs)
            {
                list.Add(int.Parse(str));
            }

            MinMaxSum problem = new MinMaxSum(list);

            Console.WriteLine
                (
                problem.Min() + " " +
                problem.Max() + " " +
                problem.Sum()
                );
        }
    }

    public class MinMaxSum
    {
        private List<int> list;

        public MinMaxSum(List<int> list)
        {
            this.list = list;
        }

        public int Min()
        {
            return list.Min();
        }

        public int Max()
        {
            return list.Max();
        }

        public long Sum()
        {
            long sum = 0;
            foreach (int number in list) {
                sum += number;
            }
            return sum;
        }
    }
}

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

int main(){
  int k, x;
  cin >> k >> x;
  for (int i = max(-1000000, x - k + 1); i <= x && i <= 1000000; i++) cout << i << endl;
  for (int i = max(-1000000, x + 1); i <= x + k - 1 && i <= 1000000; i++) cout << i << endl;
}

Measured memory_bytes: 256
from collections import Counter

n = input()
data = list(map(int, input().split(" ")))

counter = Counter(data)
result = 0
s = 0

for x, y in counter.most_common():
    s = counter[x-1] + counter[x] + counter[x+1]
    if result < s:
        result = s

print(result)


Measured memory_bytes: 16096
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; //924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans;
double dp[3000][3000], a[220000], b[220000];
string str, ss;
bool f[220000];
char c[4000][4000];
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<Edge>>vec,rvec;
vector<edge>ed;
vector<LL>v;
map<string, LL>ma;
set<LL>st;

void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	dp[0][0] = 1.00;
	rep(i, n) {
		rep(j, i + 1) {
			dp[i + 1][j + 1] += dp[i][j] * a[i];
			dp[i + 1][j] += dp[i][j] * (1.00 - a[i]);
		}
	}
	double res = 0;
	for(int i=n/2+1;i<=n;i++) {
		res += dp[n][i];
	}
	printf("%.15f\n", res);
	return 0;
}


Measured memory_bytes: 75520
#include <stdio.h>

int main (void)
{
int n , i , max = 0,maxi, ans = 0;
scanf("%d",&n);

int  a[n];

for(i = 0; i < n;i ++){
  scanf("%d",&a[i]);
   if(max < a[i]){
         max = a[i];
         maxi = i;
}}
for(i = 0;i < n;i++){
   if(i == maxi){
     ans += a[i]/2;
}
 else
     ans += a[i];
}

printf("%d",ans);

return 0;
}

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

int main(){
  int n;
  cin >> n;
  int d;
  long long a[200005];
  map<long long, int> ma;
  int ans = 0;

  a[0] = 0;
  for(int i = 1;i <= n;++i){
    cin >> d;
    a[i] = a[i - 1] + d;
    if(a[i] == 0){
      ans = max(ans, i);
    }else if(ma[a[i]] == 0){
      ma[a[i]] = i;
    }else{
      ans = max(ans, i - ma[a[i]]);
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 17172
/**
 *  author: andychen
 *  created: 09.19.2020 23:46:44
**/

#include <bits/stdc++.h>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    long long n, x, m;
    cin >> n >> x >> m;
    
    vector<long long> cycle, used(m, -1);
    long long ans = 0, cycle_start = -1, cycle_end = -1;
    function<void (long long)> find_cycle = [&](long long newx){
        n -= 1;
        ans += newx;

        if (n == 0)
            return ;

        if (used[newx] != -1){
            cycle_start = used[newx];
            cycle_end = (int) cycle.size();
            return ;
        }
        
        used[newx] = (int) cycle.size();
        
        int rem = (newx * newx) % m;
        cycle.push_back(rem);
        find_cycle(rem);
    };

    find_cycle(x);

    long long cycle_len = cycle_end - cycle_start;
    if (cycle_len > 0){
        for (int i = cycle_start, rem = n % cycle_len; i < cycle_end; i++, rem--){
            if (rem > 0)
                ans += cycle[i];
            ans += cycle[i] * (n / cycle_len);
        }
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 6796
#include <stdio.h>

int main(void)
{
	int x[30], n, i;
	int year;
	
	while (1){
		scanf("%d", &n);
		x[0] = 1;
		x[1] = 2;
		x[2] = 4;
		
		if (n == 0){
			break;
		}
		
		
		for (i = 3; i <= n; i++){
			x[i] = x[i - 3] + x[i - 2] + x[i - 1];
		}
		
		year = (x[n - 1] + 3650 - n) / 3650;
		
		
		
		printf("%d\n", year);
	}
	return (0);
}

Measured memory_bytes: 600
nums = list(map(int, input().split()))
n = nums[0]
a = nums[1]
b = nums[2]

if a == 0:
    print(0)
elif b == 0:
    print(n)
else:
   c = n // (a+b) * a
   mod = n % (a+b)
   if mod > a :
       mod = a
   print(c + mod)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<int> l(n);
  for(int i=0;i<n;i++) cin>>l.at(i);

  int len=0;
  bool flag=true;
  for(int i=0;i<n;i++) len+=l.at(i);

  for(int i=0;i<n;i++)
  {
    if(l.at(i)>=len-l.at(i)) flag=false;
  }

  if(flag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.nio.channels.AsynchronousByteChannel;
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
String K= scan.next();

if (K.equals("ABC")){System.out.println("ARC");};
        if (K.equals("ARC")){System.out.println("ABC");};

        
    }
}


Measured memory_bytes: 35716
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
const int inf=(int)1e9+5;
int n,m,l;
int E[maxn];
int g[2][305][305];
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>m>>l;
    rep(i,0,1)rep(j,1,n)rep(k,1,n)g[i][j][k]=(j==k?0:inf);
    rep(i,1,m){
        int x,y,z;
        cin>>x>>y>>z;
        g[0][x][y]=z;
        g[0][y][x]=z;
    }
    
    rep(k,1,n)rep(i,1,n)rep(j,1,n)g[0][i][j]=min(g[0][i][j],g[0][i][k]+g[0][k][j]);
    rep(i,1,n)rep(j,1,n)if(g[0][i][j]<=l)g[1][i][j]=1;
    rep(k,1,n)rep(i,1,n)rep(j,1,n)g[1][i][j]=min(g[1][i][j],g[1][i][k]+g[1][k][j]);
    int q;cin>>q;while(q--){
        int x,y;
        cin>>x>>y;
        cout<<(g[1][x][y]==inf?-1:(g[1][x][y]-1))<<endl;
    }
}
/* 
询问任意两点间最少加几次油

预处理能一次油到达的地方，建权值为1的边然后floyd

3 2 5
1 2 3
2 3 3
2
3 2
1 3
 */

Measured memory_bytes: 1408
#include <iostream>
#include <string>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int N;
    std::cin >> N;

    std::string S;
    std::cin >> S;

    if (N % 2) {
        std::cout << "No";
    } else {
        if (S.substr(0, N / 2) == S.substr(N / 2, N / 2)) {
            std::cout << "Yes";
        } else {
            std::cout << "No";
        }
    }

    std::cout << std::endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    n , m = map(int, input().split(' '))
    df = [list(map(int, input().split(' '))) for _ in range(n)]
    df.sort()
    result = 0
    counter = 0
    i = 0
    while counter < m:
        result += min(m-counter, df[i][1])*df[i][0]
        counter += df[i][1]
        i += 1
    print(result)
if __name__ == '__main__':
    main()

Measured memory_bytes: 27812
import java.io.*;
import java.util.*;

class Main {
	public static void main(String[] $) {
		new Main().run();
	}
	
	final long M=998244353;
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		long[] a=new long[N+1];
		int[] L=new int[K];
		int[] R=new int[K];
		for (int i=0;i<K;++i) {
			L[i]=sc.nextInt();
			R[i]=sc.nextInt();
		}
		a[0]=1;
		for (int i=1;i<=N;++i){
			a[i]=a[i-1];
			for (int j=0;j<K;++j) {
				if (i-L[j]>=0)   a[i]=(a[i]+a[i-L[j]])%M;
				if (i-R[j]-1>=0) a[i]=(a[i]+M-a[i-R[j]-1])%M;
			}
		}
		System.out.println((a[N-1]-a[N-2]+M)%M);
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}


Measured memory_bytes: 38284
X = 5.times.map{gets.to_i}
M = X.map{|v|v%10}.map{|v|v.zero? ? 10 : v}
T = X.map{|v|if v%10==0 then v else (v/10+1)*10 end}

a = M.min
i = M.index{|v|v == a}

T[i] = X[i]

p T.inject(:+)


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

#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r) {
    return uniform_int_distribution<int>(l, r) (rng);
}

const int N = 505;

int a[N], b[N * N];

int main() {
//    freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        b[a[i]] = i;
    }
    queue<int> q;
    for(int i = 1; i <= n*n; i++) {
        if(b[i] == 0) q.push(i);
        else {
            int remaining = b[i]-1;
            if(remaining > q.size()) {
                cout << "No" << endl;
                return 0;
            }
            while(remaining--) {
                int idx = q.front(); q.pop();
                b[idx] = b[i];
            }
        }
    }
    while(q.size() > 0) q.pop();
    vector<bool> done(n + 1);
    for(int i = n*n; i >= 1; i--) {
        if(b[i] == 0) q.push(i);
        else {
            if(done[b[i]]) continue;
            done[b[i]] = true;
            int remaining = n-b[i];
            if(remaining > q.size()) {
                cout << "No" << endl;
                return 0;
            }
            while(remaining--) {
                int idx = q.front(); q.pop();
                b[idx] = b[i];
            }
        }
    }
    cout << "Yes" << endl;
    for(int i = 1; i <= n*n; i++) cout << b[i] << " ";
}





Measured memory_bytes: 5216
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {

            int A = GetInt();
            int B = GetInt();
            int C = GetInt();
            int D = GetInt();

            int ans = new int();

            if (A >= D)
            {
                ans = D;
            }
            else if (A + B >= D)
            {
                ans = A;
            }
            else
            {
                ans = A - (D - A - B);
            }

            Console.WriteLine(ans);


            return;
        }
    }
}


public static class MyIO
{
    private static string[] args = null;
    private static int num = -1;
    private static int used = -1;

    private static string getArg()
    {
        if (used == num)
        {
            args = Console.ReadLine().Split(' ');
            num = args.Length;
            used = 0;
        }
        return args[used++];
    }

    public static int GetInt() => int.Parse(getArg());
    public static long GetLong() => long.Parse(getArg());
    public static double GetDouble() => double.Parse(getArg());
    public static string GetString() => getArg();
    public static char GetChar() => getArg()[0];
    public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
    public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
    public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
    public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}

Measured memory_bytes: 27400
#include <cstdio>
#include <vector>

int main()
{
    int N;

    scanf("%d", &N);
    std::vector<int> L;
    L.resize(N);
    for (auto& l : L)
    {
        scanf("%d", &l);
    }

    int total = 0;
    for (int a = 0; a < N - 2; ++a)
    {
        for (int b = a + 1; b < N - 1; ++b)
        {
            for (int c = b + 1; c < N; ++c)
            {
                if (L[a] >= (L[b] + L[c])) continue;
                if (L[b] >= (L[a] + L[c])) continue;
                if (L[c] >= (L[a] + L[b])) continue;

                ++total;
            }
        }
    }

    printf("%d\n", total);
}


Measured memory_bytes: 888
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

int firstAndSecondOrderOf(int X){
	int firstOrder;
	int secondOrder;
	firstOrder = X % 10;
	X = X / 10;
	secondOrder = X % 10;
	return 10*secondOrder + firstOrder;
}

int howManyProductsAreNeed(int X){
	int count = 0;
	while( X >= 5){
		X -= 5;
		count++;
	}

	while( X >= 4){
		X -= 4;
		count++;
	}

	while( X >= 3){
		X -= 3;
		count++;
	}

	while( X >= 2){
		X -= 2;
		count++;
	}

	while( X >= 1){
		X -= 1;
		count++;
	}
	return count;
}

int main()
{
	int n;
	cin>>n;
	int firstAndSecond = firstAndSecondOrderOf(n);
	int howManyProduct = howManyProductsAreNeed(firstAndSecond);
	if( ( n - firstAndSecond - 100* howManyProduct) >= 0){
		cout<<1<<endl;
	}else{
		cout<<0<<endl;
	}
	
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef unsigned long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n;
    cin >> n;

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }

    sort(all(a));

    vl v0(62);  // v0[j] : jビット目が0の数の個数
    vl v1(62);  // v1[j] : jビット目が1の数の個数
    rep(i, n) {
        rep(j, 62) {
            if( a[i] & (1ull<<j) ) {
                v1[j]++;
            }
            else {
                v0[j]++;
            }
        }
    }

    ll ans = 0;
    rep(i, 62) {

        if(v0[i] == 0 || v1[i] == 0) {
            continue;
        }
        
        ll p = 1;
        rep(j, i) {
            p *= 2;
            p %= mod;
        }

        ll x = v0[i]*v1[i]%mod;
        ans += x*p;
        ans %= mod;
    }
    
    out(ans);
    re0;
}

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



int main() {

    int N;
    cin>>N;

    vector<long long> h(N);

    for(int i=0;i<N;i++){
        cin>>h.at(i);
    }

    int jud=0;

    for(int i=1;i<N;i++){
        bool a = h.at(N-1-(i-1)) >= h.at(N-1-i);
        if(!a){
            if(h.at(N-1-i)-h.at(N-1-(i-1))==1){
                h.at(N-1-i)--;
            }else{
                jud = 1;
                break;
            }
        }
    }

    if(jud==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 1024
import java.util.NavigableSet;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n;
		NavigableSet<Integer> taroAll = new TreeSet<Integer>();
		NavigableSet<Integer> hanaAll = new TreeSet<Integer>();
		NavigableSet<Integer> taro;
		NavigableSet<Integer> hana;
		while ((n = in.nextInt()) != 0) {
			taro = taroAll.headSet(Integer.valueOf(n * 2), true);
			hana = hanaAll.headSet(Integer.valueOf(n * 2), true);
			taro.clear();
			for (int i = 1; i <= n; i++) {
				Integer card = Integer.valueOf(in.nextInt());
				taro.add(card);
				hana.add(Integer.valueOf(i));
				hana.add(Integer.valueOf(i + n));
			}
			hana.removeAll(taro);
			Integer table = null;
			NavigableSet<Integer> pc = taro;
			while (!taro.isEmpty() && !hana.isEmpty()) {
				if (table == null) {
					table = pc.pollFirst();
				} else {
					table = pc.higher(table);
					if (table != null) {
						pc.remove(table);
					}
				}
				pc = (pc == taro) ? hana : taro;
			}
			System.out.println(hana.size());
			System.out.println(taro.size());

		}
	}
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<P> vp;
typedef vector<ll> vll;

const int INF = 99999999;
const int MAX_V = 100000;

struct edge { int to, cap, cost, rev; };

int V, E, F;
vector<edge> G[MAX_V];
int h[MAX_V];                   // potential
int dist[MAX_V];
int prevv[MAX_V], preve[MAX_V]; // privious vertex, edge

void add_edge(int from, int to, int cap, int cost) {
    G[from].emplace_back((edge){to, cap, cost, (int)G[to].size()});
    G[to].emplace_back((edge){from, 0, -cost, (int)G[from].size() - 1});
}

// get min cost flow from s to t
// if we cannot flow f, then return -1
int min_cost_flow(int s, int t, int f) {
    int res = 0;
    fill(h, h + V, 0);
    while (f > 0) {
        // update h by dijkstra
        priority_queue<P, vector<P>, greater<P>> que;
        fill(dist, dist + V, INF);
        dist[s] = 0;
        que.push(P(0, s));
        while (!que.empty()) {
            P p = que.top(); que.pop();
            int v = p.second;
            if (dist[v] < p.first) continue;
            rep(i, G[v].size()) {
                edge &e = G[v][i];
                if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
                    dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
                    prevv[e.to] = v;
                    preve[e.to] = i;
                    que.push(P(dist[e.to], e.to));
                }
            }
        }
        if (dist[t] == INF) {
            // no more flow
            return -1;
        }
        rep(v, V) h[v] += dist[v];

        // flow as much as possible along the minimum path from s to t
        int d = f;
        for (int v = t; v != s; v = prevv[v]) {
            d = min(d, (int)G[prevv[v]][preve[v]].cap);
        }
        f -= d;
        res += d * h[t];
        for (int v = t; v != s; v = prevv[v]) {
            edge &e = G[prevv[v]][preve[v]];
            e.cap -= d;
            G[v][e.rev].cap += d;
        }
    }
    return res;
}

signed main() {
    cin >> V >> E >> F;
    rep(i, E) {
        int u, v, c, d;
        cin >> u >> v >> c >> d;
        add_edge(u, v, c, d);
    }

    cout << min_cost_flow(0, V - 1, F) << endl;
}

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

int main()
{
    long long int i,j,m=0,n,sum=0,in;
    long long int k=1000000007;
 
 
    cin>>n;
    vector<long long int>a;
    for(i=0;i<n;i++)
        {
            cin>>in;
            a.push_back(in);
            sum=sum+a[i];
 
        }
        for(i=0;i<n-1;i++)
        {
            sum=sum-a[i];
            m=m+(((sum%k)*(a[i]%k))%k);
            m%=k;
 
        }
        cout<<m<<endl;
}

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

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

}


Measured memory_bytes: 256
# 約数の列挙
#############################################################
def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n // i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
#############################################################


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

sum_A = sum(A)
div_list = make_divisors(sum_A)
ans = 1
# print(div_list)

for div in div_list:
    tmp = []
    for a in A:
        tmp.append(a % div)
    tmp.sort()
    cumsum1 = [0]
    cumsum2 = [0]
    for i in tmp:
        cumsum1.append(cumsum1[-1] + i)
        if i != 0:
            cumsum2.append(cumsum2[-1] + (div - i))
        else:
            cumsum2.append(cumsum2[-1])
    for i in range(1, N):
        if cumsum1[i] <= K and cumsum2[N] - cumsum2[i] <= K:
            ans = div

print(ans)


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

using namespace std;

int main() {

    long long N, result = 1e15;

    scanf("%lld", &N);

    for (long long i=1 ; i*i <= N ; i++ ) {

        if (N % i == 0LL) {
            result = min(result, i - 1LL + (N / i) - 1LL);
        }
    }

    printf("%lld\n", result);
    return 0;
}

Measured memory_bytes: 256
while line = gets
  m = line.chomp.to_i
  break if m == 0

  dp = Array.new(101) { Array.new(1001, 0) }
  a = []
  b = []

  m.times do
    stack = gets.chomp.split.map(&:to_i)
    a << stack[0]
    b << stack[1]
  end

  dp[0][0] = 1

  for i in 0...m
    for j in 0..b[i]
      for k in 0..1000
        dp[i + 1][k] += dp[i][k - a[i] * j] if k - a[i] * j >= 0
      end
    end
  end

  g = gets.chomp.to_i

  g.times do
    v = gets.chomp.to_i
    puts dp[m][v]
  end
end

Measured memory_bytes: 13416
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

#define MAX_W 101

char map[MAX_W][MAX_W];
int w,h;
bool vis[MAX_W][MAX_W];
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};

void dfs(int x,int y)
{
	vis[y][x]=true;

	for(int i=0;i<4;i++)
	{
		int nx=x+dx[i],ny=y+dy[i];
		if(nx>=0 && nx<w && ny>=0 && ny<h && !vis[ny][nx] && map[y][x]==map[ny][nx])
			dfs(nx,ny);
	}
}

int main()
{
	scanf("%d%d",&h,&w);

	while(w!=0 || h!=0)
	{
		for(int i=0;i<h;i++)
		{
			scanf("%s",map[i]);
		}

		memset(vis,0,sizeof(vis));

		int cnt=0;

		for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			if(!vis[i][j])
			{
				dfs(j,i);
				cnt++;
			}

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

		scanf("%d%d",&h,&w);
	}

	return 0;
}

Measured memory_bytes: 1840
#include <bits/stdc++.h>
using namespace std;
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;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<vector<ll>> dp(n + 1, vector<ll>(5, LLINF));
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++) {
        for(int k = 0; k < 5; k++) {
            for(int j = 0; j <= k; j++) {
                if(k == 0 || k == 4) {
                    chmin(dp[i][k], dp[i - 1][j] + a[i - 1]);
                } else if(k == 1 || k == 3) {
                    chmin(dp[i][k],
                          dp[i - 1][j] + (!a[i - 1] ? 2 : a[i - 1] & 1LL));
                } else {
                    chmin(dp[i][k], dp[i - 1][j] + !(a[i - 1] & 1LL));
                }
            }
        }
    }
    ll ans = LLINF;
    for(int i = 0; i < 5; i++) {
        chmin(ans, dp[n][i]);
    }
    print(ans);
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
int gcd(int p, int q){
    while (q != 0){
        int r = p % q;
        p = q;
        q = r;
    }
    return p;
}
int main() {
	int K, cnt, g1, g2;
  	cnt = 0;
	cin >> K;
  	for (int a = 1; a < K + 1 ; a++){
      for (int b = 1; b < K + 1 ; b++){
        for (int c = 1; c < K + 1 ; c++){
            g1 = 0;
            g2 = 0;
            g1 = gcd(a, b);
            g2 = gcd(g1, c);
            cnt += g2;
        }
      }
    }
	cout << cnt << endl;
}

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

int main() {
    int N, D, X;
    int A[100];
    cin >> N >> D >> X;

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

    long long ans = X;
    for (int i = 0; i < N; i++) {
        long long tmpAns = 1;
        for (int day = 1 + A[i]; day <= D; day += A[i]) {
            tmpAns++;
        }
        ans += tmpAns;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int n, k;
    string s;

    cin >> n >> k >> s;

    if (s.at(k-1) == 'A') {
        s.at(k-1) = 'a';
    }

    else if (s.at(k-1) == 'B') {
        s.at(k-1) = 'b';
    }

    else {
        s.at(k-1) = 'c';
    }

    cout << s << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define dunk(a) cout << (a) << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

int main() {
	int n, m; cin >> n >> m;
	vector<pair<int, char>> sc(m);
	rep(i, m) cin >> sc[i].first >> sc[i].second;
	int ans = pow(10, n - 1) - 1;

	if (n > 1) {
		while (ans < pow(10, n)) {
			ans++;
			string s = to_string(ans);
			int c = 0;
			rep(i, m) {
				if (s.at(sc[i].first - 1) == sc[i].second) c++;
			}
			if (c == m) {
				dunk(ans);
				return 0;
			}
		}
	}

	else {
		while (ans < pow(10, n)) {
			string s = to_string(ans);
			int c = 0;
			rep(i, m) {
				if (s.at(sc[i].first - 1) == sc[i].second) c++;
			}
			if (c == m) {
				dunk(ans);
				return 0;
			}
			ans++;
		}
	}

	dunk(-1);
	return 0;
}


Measured memory_bytes: 256
import sys
N,Y=map(int,input().split())
count=0
for x in range(N+1):
  for y in range(N+1):
    z=N-x-y
    if z<0:
      continue
    else:  
      total=10000*x+5000*y+1000*z
      if total == Y:
        print(x,y,z)
        sys.exit()    
print("-1 -1 -1")      

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

 
int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  for(int i=0; i<N; i++){
    cin >> s.at(i);
  }
  int M;
  cin >> M;
  vector<string> t(M);
  for(int i=0; i<M; i++){
    cin >> t.at(i);
  }
  
  vector<int> score(N);
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      /* if(j == i) continue;
      else */ if(s.at(j) == s.at(i)){
        score.at(i)++;
      }
    }
    for(int j=0; j<M; j++){
      if(t.at(j) == s.at(i)){
        score.at(i)--;
      }
    }
  }
  
  int max = 0;
  for(int i=0; i<N; i++){
    if (score.at(i) > max){
      max = score.at(i);
    }
  }
  
  cout << max << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r,D,x;
  cin >> r>>D>>x;
  int tmp1=x;
  int tmp;
  
  for(int i=1;i<11;i++){
    tmp=tmp1;
    cout<<r*tmp-D<<endl;
    tmp1=r*tmp-D;
  }
}

Measured memory_bytes: 256