akhauriyash/Code-Regression huggingface dataset:
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 cou = 0;
    for(int i=0; i<N; i++){
        A[i] = sc.nextInt();
        if(A[i]%2==0){
        if(A[i]%3!=0 && A[i]%5!=0){
            cou++;
    }
    }
}
    if(cou==0){
            System.out.println("APPROVED");
    }else{
            System.out.println("DENIED");
        }
    }
}

Measured memory_bytes: 21844
A, B, K = map(int, input().split())
num = min([A,B])
count = 0
yakusuu = []
for i in range(1,num+1):
        if A%i == 0 and B%i==0:
                yakusuu.append(i)
#print(yakusuu)
print(yakusuu[-K])


#2番目に大きいもの

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

using namespace std;
int main(){
    long long N;
    cin>>N;
    int A,B;
    cin>>A>>B;


    int iti=0,ni=0,san=0;

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

        if(tmp<=A){
            iti++;
        }else if(tmp<=B){
            ni++;
        }else{
            san++;
        }
    }


    vector<int> test;
    test.emplace_back(iti);
    test.emplace_back(ni);
    test.emplace_back(san);


    cout<<*min_element(test.begin(),test.end())<<endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
 
j = True
for i in range(N):
    if A[i] % 2 == 0:
        if A[i] %3 == 0 or A[i] % 5 ==0:
            pass
        else:
            print("DENIED") 
            exit()
            
print("APPROVED")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define de(x) cout<<#x<<" = "<<x<<endl
const int N=3e2+7;
int mp[N][N];
bool in[N][N];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            scanf("%d",&mp[i][j]);
        }
    }
    bool fg=0;
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                if(k==i||j==k)continue;
                if(mp[i][k]+mp[k][j]==mp[i][j]  ){in[i][j]=1; }
                else if(mp[i][k]+mp[k][j]<mp[i][j] ){fg=1;}
            }
        }
    }
    long long ans=0;
    if(fg){
        cout<<-1<<endl;return 0;
    }
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            if(!in[i][j]){ans+=mp[i][j];}
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

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

int main() {
	int a, b, c ,d; cin >> a >> b >> c >> d;
	cout << min(a,b) + min(c,d) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <cassert>
#include <random>
#include <ctime>
#include <chrono>
#include <set>
using namespace std; typedef long long ll; const int INF=1e9; typedef pair<int,int> P;
bool cha(ll a, ll b) {
  //cout<<a<<" "<<b<<endl;
  while(a>1) {
    //cout<<" "<<a<<" "<<b<<endl;
    if (a%b==0) a/=b;
    else {a%=b; break;}
  }
  //cout<<a<<" "<<b<<" "<<endl;
  if (a==1) return true;
  else return false;
}
int main() {
  ll n; cin>>n;
  ll n2=n-1;

  set<ll> s;
  if (n2>2) s.insert(n2);

  for(ll i=1;i*i<=n;i++) {
    if (n%i==0) {
      s.insert(i);
      s.insert(n/i);
      //if (i*i==n || i==1) an++;
      //else an+=2;
    }
  }

  for(ll i=1;i*i<=n2;i++) {
    if (n2%i==0) {
      s.insert(i);
      s.insert(n/i);
      //if (i*i==n2 || i==1) an++;
      //else an+=2;
    }
  }
  if (s.find(1) != s.end()) s.erase(1);
  ll an=0;
  for(ll x:s) {
    if (cha(n,x)) an++;
  }
  //cout<<s.size()<<endl;
  cout<<an<<endl;
}

Measured memory_bytes: 512
from collections import Counter

N = input()
D_list = list(map(int, input().split()))

max_D = max(D_list)
cnt_dic = dict(Counter(D_list))

if (D_list[0] == 0) & (cnt_dic.get(0) == 1):
    ans = 1
    for n in range(1, max_D + 1):
        ans *= cnt_dic.get(n - 1, 0)  ** cnt_dic.get(n, 1)
    print(ans % 998244353)
else: 
    print(0)

Measured memory_bytes: 27036
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
const int INF = 1e18;

int dp[100010];

signed main(){
    int n, w; cin >> n >> w;
    REPS(i,100000) dp[i] = INF;
    REP(i,n){
        int a, b; cin >> a >> b;
        RREP(j,100003)if(j-b>-1) chmin(dp[j],dp[j-b]+a);
    }
    RREP(j,100001) if(dp[j]<=w){
        cout << j << endl;
        return 0;
    }
}


Measured memory_bytes: 1024
n = int(input())
hlist = list(map(int, input().split()))

prevc = -1
c = 0
while prevc != c:
  prevc = c
  is_c = False
  newhs = []
  for h in hlist:
    if h == 0:
      is_c = False
      newhs.append(0)
    else:
      if is_c:
        newhs.append(h-1)
      else:
        newhs.append(h-1)
        is_c = True
        c += 1
  hlist = newhs

print(prevc)


Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

int main(){
    ll n;
    cin >> n;
    ll a[n];
    
    ll iMin = INF;
    ll cnt = 0;
    //負の数は2個ずつしか減らせない
    //min(abs(a[i]))を引けばいい気がする
    //0があれば min -> 0

    ll res = 0;

    REP(i,n)
    {
        cin >> a[i];
        ll tmp = abs(a[i]);
        res += tmp;
        iMin = min(iMin,tmp);
        if(a[i] < 0)++cnt;
    }

    if(cnt % 2 == 1)
    {
        res -= iMin * 2;
    }

    cout << res << endl;

    return 0;    
}



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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    ll n;
    cin>>n;
    VL arr(n);
    map<ll,ll> mp;
    fr(i,0,n)
    {
        cin>>arr[i];
        mp[arr[i]]+=1;
    }
    vector<PLL> tmp;
    for(auto i: mp)
    {
        tmp.pb(i);
    }
    ll ct=0;
    fr(i,0,n)
    {
        fr(j,i+1,n)
        {
            fr(k,j+1,n)
            {
                if(tmp[i].F!=tmp[j].F&&tmp[i].F!=tmp[k].F)
                {
                    if(tmp[i].F<(tmp[j].F+tmp[k].F)&&tmp[j].F<(tmp[i].F+tmp[k].F)&&tmp[k].F<(tmp[j].F+tmp[i].F))
                    {
                        ct+=(tmp[i].S*tmp[j].S*tmp[k].S);
                    }
                }
            }
        }
    }
    cout<<ct;
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        //cout<<"Case #"<<pp-t<<":\n";
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int N;
		N = sc.nextInt();
		int M=sc.nextInt();
		int ans=M;
	for (int i = 1; i < N; i++) {
				int X = sc.nextInt();
			ans=GCD(ans,X);
	}
			

					System.out.print(ans); 	

	}
	public static int GCD(int a,int b) {
		if(a>b) {
			int tmp=a;
			a=b;
			b=tmp;
		}
		int r=-1;
		while(r!=0) {
			r=a%b;
			a=b;
			b=r;
					
		}
      return a;
	}
}




Measured memory_bytes: 48224
#include<bits/stdc++.h>
#define ll long long int
#define vl vector<ll>
#define pl pair<ll,ll>
#define pb push_back
#define F first
#define S second
using namespace std;
int main()
{
	ll t,n,k,i,j,x=0;
	cin >> n;
	vl v(n+1,0);
	for(i=0;i<n;i++)
	cin >> v[i];
	for(i=1;i<n;i++)
	{
		if(v[i]<v[i-1])
		{
		x+=v[i-1]-v[i];
		v[i]=v[i-1];
		}
	}
	cout << x;
	return 0;
}

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

using namespace std;

constexpr int INF = 1145141919;

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> v(n, vector<int>(m + 1));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= m; j++)cin >> v[i][j];
    }

    int ret = INF;
    for (int i = 0; i < 1 << n; i++) {
        vector<int> skill(m);
        int cost = 0;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                cost += v[j][0];
                for (int k = 0; k < m; k++) skill[k] += v[j][k + 1];
            }
        }

        bool ok = true;
        for (auto tmp:skill) {
            if (tmp < x)ok = false;
        }
        if (ok)ret = min(ret, cost);
    }

    cout << (ret == INF ? -1 : ret) << endl;
    return 0;
}

Measured memory_bytes: 3632
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	parseProblem()
}

func parseProblem() {
	n := scanInt(sc)
	hs := nextIntSlice(sc, n)
	cur := 0
	for i := 0; i < len(hs); i++ {
		if !(cur <= hs[i]) {
			fmt.Println("No")
			return
		}
		if hs[i]-1 >= cur {
			cur = hs[i] - 1
		} else {
			cur = hs[i]
		}
	}
	fmt.Println("Yes")
	return
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return int(a)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextIntSlice(sc *bufio.Scanner, n int) (a []int) {

	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	return a
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


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

typedef long long ll;
typedef unsigned long long ull;

#define FRO freopen("in.txt","r",stdin);

int arr[100005],dp[100005];
int k;
int fun(int n)
{
      if(dp[n]!=-1) return dp[n];
      int lo=max(1,n-k);
      int tmp=INT_MAX;
      for(int i=n-1;i>=lo;i--)
      {
            tmp=min(tmp,fun(i)+abs(arr[i]-arr[n]));
      }
      return dp[n]=tmp;
}



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


      int n,i,j;
      cin>>n>>k;
      memset(dp,-1,sizeof dp);
      for(i=1;i<=n;i++) cin>>arr[i];
      dp[0]=0;
      dp[1]=0;
      arr[0]=0;

      cout<<fun(n);



	return 0;
}


Measured memory_bytes: 5760
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


n = onem()
k = onem()

s = str(n)

dp0 = [[0 for j in range(4)] for i in range(len(str(n))+1)]
dp1 = [[0 for j in range(4)] for i in range(len(str(n))+1)]

po = 0

dp0[0][0] = 0
dp1[0][0] = 1

for i in range(1,len(str(n))+1):
    point = i - 1
    np = int(s[point])
    po += 1 if np == 0 else 0

    dp0[i][0] = 1
    dp1[i][0] = 0

    dp0[i][1] = dp1[i-1][0]*(max(0,np-1)) + dp0[i-1][0]*9 + dp0[i-1][1] + ( dp1[i-1][1] if np != 0 else 0 )
    dp1[i][1] = 1 if i == 1 + po else 0

    dp0[i][2] = dp1[i-1][1] * (max(0,np-1)) + dp0[i-1][1] * (9) + dp0[i-1][2] + ( dp1[i-1][2] if np != 0 else 0 )
    dp1[i][2] = 1 if i == 2 + po else 0

    dp0[i][3] = dp1[i-1][2] * (max(0,np-1)) + dp0[i-1][2] * (9) + dp0[i-1][3] + ( dp1[i-1][3] if np != 0 else 0 )
    dp1[i][3] = 1 if i == 3 + po else 0

    


print(dp0[-1][k]+dp1[-1][k])






Measured memory_bytes: 38384
#include <stdio.h>

#define MAX_N 100000
#define MAX_Q 50000

int binary_search(int* s, int n, int x) {
  int max = n-1;
  int min = 0;

  int avg = 0;
  int avg_ = -1;
  while(avg != avg_) {
    avg_ = avg;
    avg = (max+min)/2;

    if(s[avg] > x) {
      max = avg;
    } else if(s[avg] < x) {
      min = avg;
    } else {
      return avg;
    }
  }

  if(s[avg+1] == x) {
    return avg+1;
  }
  return -1;
}

int main() {
  int n, q;
  int s[MAX_N], t[MAX_Q];
  scanf("%d", &n);
  for(int i=0; i<n; i++) {
    scanf("%d", &s[i]);
  }

  scanf("%d", &q);
  for(int i=0; i<q; i++) {
    scanf("%d", &t[i]);
  }

  int cnt = 0;
  for(int i=0; i<q; i++) {
    if (binary_search(s, n, t[i]) != -1)
      cnt++;
  }

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

  return 0;
}

Measured memory_bytes: 3168
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <algorithm>
#include <string.h>
#include <memory.h>

using namespace std;

typedef long long ll;
int const N = 1e5 + 5, oo = 2e9 + 1;
int n, m, q, k, a[N], fr[N];
vector<vector<int> > g;

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%d", a + i);

	int res = 0;

	if(a[1] == 1) {
		swap(a[1], a[2]);
		++res;
	}

	for(int i = 2; i < n; ++i) {
		if(a[i] == i) {

			swap(a[i], a[i + 1]);
			--i;
			++res;
		}
	}

	if(a[n] == n) {
		swap(a[n], a[n - 1]);
		++res;
	}

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

    return 0;
}


Measured memory_bytes: 640
INF = int(1e9)
N, M, K = list(map(int, input().split()))
R = list(map(lambda x: int(x) - 1, input().split()))

G = [[INF] * N for i in range(N)]
for i in range(N):
    G[i][i] = 0
            
for i in range(M):
    a, b, c = list(map(int, input().split()))
    a = a - 1
    b = b - 1
    G[a][b] = G[b][a] = c
    
ls = range(N)
for k in ls:
    for i in ls:
        for j in range(i+1,N):
            x = G[i][k] + G[k][j]
            if x < G[i][j]:
                G[i][j] = G[j][i] = x

dp = [[INF] * (1<<K) for i in range(K)]
for i in range(K):
    dp[i][1<<i] = 0

for bit in range(1<<K):
    for pre in range(K):
        if (bit >> pre) & 1 == 0:
            continue
        for to in range(K):
            if (bit >> to) & 1 == 1:
                continue
            cost = dp[pre][bit] + G[R[pre]][R[to]]
            nbit = bit | (1<<to)
            if dp[to][nbit] > cost:
                dp[to][nbit] = cost

ans = INF     
for pre in range(K):
    ans = min(ans, dp[pre][(1<<K) - 1])
print (ans)
              


Measured memory_bytes: 4080
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
int dy[4] = { 1, 0, -1, 0 }, dx[4] = { 0, 1, 0, -1 };
const ll MOD = 1e9 + 7;
const ll INF = 1e9;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    int sum = 0;
    int day = 0;
    while (sum < c) {
        day++;
        sum += a;
        if (day % 7 == 0)
            sum += b;
    }
    cout << day << endl;
    return 0;
}


Measured memory_bytes: 3216
from collections import deque

def main():
  k = int(input())

  # 前後をチェックする再帰関数( 要素として深さも必要そう / DPのメモ化とか使えそう )
  # 
  # 生データ
  # 1桁
  # [1, 2, 3, 4, 5, 6, 7, 8, 9]
  # 2桁 
  # [10, 11, 12, 21, 22, 23,..., 98, 99]
  #
  # 1
  # 10 11 12
  #
  #          2
  # .. .. .. 21 22 23
  #
  # Point.
  #   1の木, 2の木と小さい順に自然となってる
  #   重複していない
  #
  # キューを使った方法の解説
  #
  # 初期状態
  # 1 2 3 4 5 6 7 8 9
  #
  # 遷移1
  # . 2 3 4 5 6 7 8 9 10 11 12
  #
  # 遷移2
  # . . 3 4 5 6 7 8 9 10 11 12 21 22 23
  #
  # 遷移3
  # . . . 4 5 6 7 8 9 10 11 12 21 22 23 32 33 34

  # 最初の1桁データの用意
  q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

  for _ in range(k-1):
    p = q.popleft()
    l = p % 10
    # print("l:", l)

    if l - 1 >= 0:
      new_data1 = p*10 + (l - 1)
      # print("new_data1:", new_data1)
      q.append(new_data1)
      # print("q:", q)
    
    new_data2 = p*10 + l
    # print("new_data2:", new_data2)
    q.append(new_data2)
    # print("q:", q)

    if l + 1 <= 9:
      new_data3 = p*10 + (l + 1)
      # print("new_data3:", new_data3)
      q.append(new_data3)
      # print("q:", q)

  print(q[0])

if __name__ == "__main__":
  main()


Measured memory_bytes: 12404
#include <cstdio>
#define INF 1e9
#define eps 1e-6
typedef long long ll;

int n, k, ans;

int main(){

	scanf("%d%d", &n, &k);
	while(n){
		ans++;
		n /= k;
	}
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n, a[100];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    if (sum % 10 != 0)
    {
        cout << sum << "\n";
        return 0;
    }
    sort(a, a + n);
    for (int i = 0; i < n; i++)
    {
        if (a[i] % 10 != 0)
        {
            cout << sum - a[i] << "\n";
            return 0;
        }
    }
    cout << 0 << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MIN -1000000
using namespace std;
typedef long long ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;
const int MOD=1e9+7;
const int inf=1e9;
double N,w;

int main(void)
{
  cin >>  N;
  for(double h=1.0;h<=3500.0;h+=1.0)
    {
      for (double n = 1.0; n <=3500.0; n+=1.0)
	{
	  w=(N*h*n*1.0)/(4.0*h*n-N*(h+n));
	  if(w>0 && abs(w-ceil(w))<1e-9)
	    {
	      cout << int(h) << ' ' <<  int(n) << ' ' << int(w) << endl;;
	      return 0;
	    }
	}
    }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <complex>
#include <cmath>
#include <iomanip>

using ll = long long;

using namespace std;

using C = complex<double>;

int main() {
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    C jisin = {(double)a, 0.}, funsin = {(double) b, 0.};
    double time = h * 60 + m;
    jisin  *= exp( complex< double >( .0, (time * 0.5) * M_PI / 180.0 ) );
    funsin *= exp( complex< double >( .0, (time * 6.0) * M_PI / 180.0 ) );
    cout << setprecision(15) << fixed << abs(jisin - funsin) << '\n';
    return 0;
}

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

int main() {
  long long A,B,N;
  cin >> A >> B >>N;
  long long X=0;
  long long ans=0;
  if(A<B){
    if(N<B){
      ans=(A*N/B)-A*(N/B);
    }
    else{
      ans=(A*(B-1)/B)-A*((B-1)/B);
    }
  }
  if(A>=B){
    if(N<B){
      ans=(A*N/B)-A*(N/B);
    }
    else{
      X=B%N;
      if(X!=0){
      ans=(A*N/B)-A*(N/B);
    }
     if(X==0){
      ans=(A*(N-1)/B)-A*((N-1)/B);
    } 
    }
  }
  cout << ans <<endl;
}


Measured memory_bytes: 3632
import java.util.Scanner;

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

    public static void solvA(int n){
        Double d = (n / 2 + n % 2) / (n * 1.0);
        System.out.println(d);
    }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }

vector<ll> a(60), b(60), c(60), d(60);
ll N,M,Q;
vector<ll> A(15);
ll best=0;

ll solve(ll cur, ll prev){
    if(cur == N){
        ll tmp = 0;
        /*rep(i,N){
            cout << A[i] << " ";
        }
        cout << endl;*/
        rep(i,Q){
            if(A[b[i]-1] - A[a[i]-1] == c[i]){
                tmp+=d[i];
            }
        }
        cmax(best,tmp);
        return 0;
    }else{
        REP(i,prev,M+1){
            A[cur] = i;
            solve(ll(cur+1), ll(i));
        }
        return 0;
    }
}

int main(){
    //ll N,M,Q;
    string S;
    cin >> N >> M >> Q;
    rep(i,Q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    solve(ll(0),ll(1));
    cout << best <<endl;
}

Measured memory_bytes: 3632
l = list(map(int, input().split()))

N = l[0]
K = l[1]

s = list(map(int, input().split()))

for value in range(100001):
  result = 0
  if value >= N:
    flg = 1
    for num in s:
      if str(num) in str(value):
        flg = 0
        break
    if flg == 1:
      result = value
      break
print(result)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(){
  	string a, b;
  	cin >> a >> b;
  	int cnt = 0;
  	for(int i=0;i<a.length();i++){
  		if(a[i]!=b[i]){
  			cnt++;
		}
	}
	cout << cnt;
}

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


int main() {
    ll n; cin >> n;
    
    vector<ll> f(n+1);
    for(ll i = 1; i <= n; i++) {
        ll x = i;
        while(x <= n) {
            f[x]++;
            x += i;
        }
    }

    ll ans = 0;

    for(ll i = 1; i <= n; i++) {
        ans += i * f[i];
    }

    cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<vector<int>> A(2, vector<int>(N));
  for(int i = 0;i<2;i++){
    for(int j = 0;j<N;j++){
      cin >> A[i][j];
    }
  }
  vector<int> ans(N);
  
  for(int i = 0;i<N;i++){
    for(int j = i;j<N;j++){
      ans[i] += A[1][j];
    }
  }
  for(int i = 0;i<N;i++){
    for(int j = 0;j<=i;j++){
      ans[i] += A[0][j];
    }
  }
  sort(ans.begin(),ans.end());
  cout << ans[ans.size()-1] << endl;

}




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

using namespace std;

typedef long long ll;
typedef long double ld;

const ld PI = (acos(-1));

int main() {
  ld a, b, x;
  cin >> a >> b >> x;

  ld ans;
  if (a * a * b / 2.0 <= x) {
    ans = atan(2 * (a * a * b - x) / (a * a * a));
  } else {
    ans = PI / 2 - atan(2 * x / (a * b * b));
  }

  cout << fixed << setprecision(10) << ans * 180.0 / PI << endl;

  return 0;
}


Measured memory_bytes: 256
def check(field):
    tr = list(map(''.join, zip(*field)))
    paired = set()
    center = -1
    for i, col1 in enumerate(tr):
        if i in paired:
            continue
        for j, col2 in enumerate(tr[i + 1:], start=i + 1):
            if j in paired:
                continue
            if col1 == col2[::-1]:
                paired.add(i)
                paired.add(j)
                break
        else:
            if center == -1 and col1 == col1[::-1]:
                center = i
            else:
                return False
    return True


def arrange_row(field, new_field, i, remain):
    if len(remain) == 0:
        return check(new_field)
    j = remain.pop()
    new_field[i] = field[j]
    for k in list(remain):
        remain.remove(k)
        new_field[h - i - 1] = field[k]
        result = arrange_row(field, new_field, i + 1, remain)
        if result:
            return True
        remain.add(k)
    remain.add(j)
    return False


def solve(h, w, field):
    new_field = [None] * h
    remaining_row = set(range(h))

    if h % 2 == 0:
        return arrange_row(field, new_field, 0, remaining_row)

    for i in list(remaining_row):
        remaining_row.remove(i)
        new_field[h // 2] = field[i]
        result = arrange_row(field, new_field, 0, remaining_row)
        if result:
            return True
        remaining_row.add(i)
    return False


h, w = map(int, input().split())
field = [input() for _ in range(h)]
print('YES' if solve(h, w, field) else 'NO')


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

int main()
{
	int n, m, l, r, i, gl, gr;
	scanf("%d %d", &n, &m);
	for (i = 0; i < m; i++) {
		scanf("%d %d", &l, &r);
		if (i == 0 or l > gl)
			gl = l;
		if (i == 0 or r < gr)
			gr = r;
	}
	printf("%d\n", (gr < gl ? 0 : gr - gl + 1));
	return 0;
}

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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;

int main() {
    lli n, h;
    cin2(n, h);
    lli a[n], b[n];
    ncin2(n, a, b);


    lli a_max = 0;
    lli a_max_b = LLONG_MAX;
    lli a_max_i;
    REP(i, 0, n) {
        if (a_max < a[i] || (a_max == a[i] && a_max_b > b[i])) {
            a_max = max(a_max, a[i]);
            a_max_b = b[i];
            a_max_i = i;
        }
    }
    priority_queue<lli> que;
    priority_queue<lli> que2;
    REP(i, 0, n) {
        if (i == a_max_i)
            continue;
        else if (a_max < b[i]) {
            que.push(b[i]);
            que2.push(b[i]);
        }
    }

    lli ans1 = 0;
    lli damage = 0;

    // a_max_b を使うケース
    damage += a_max_b;
    ans1++;
    while (!que.empty()){
        lli x = que.top();
        que.pop();
        damage += x;
        ans1++;
        if (damage >= h)
            break;
    }
    if (damage < h) {
        ans1 += ((h+a_max-1) - damage) / a_max;
    }

    lli ans2 = 0;
    damage = 0;
    // a_max_b を使わないケース
    while (!que2.empty()){
        lli x = que2.top();
        que2.pop();
        damage += x;
        ans2++;
        if (damage >= h)
            break;
    }
    if (damage < h) {
        ans2 += ((h+a_max-1) - damage) / a_max;
    }

    cout << min(ans1, ans2) << endl;
}


Measured memory_bytes: 3572
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct BINNODE {
	int key;
	BINNODE *parent;
	BINNODE *left;
	BINNODE *right;

	BINNODE (int k) {
		key=k;
		parent=nullptr;
		left=nullptr;
		right=nullptr;
	}
};

void preorderwalk(BINNODE* root) {
	if(root==nullptr) return;
	printf(" %d",root->key);
	preorderwalk(root->left);
	preorderwalk(root->right);
	return;
}

void inorderwalk(BINNODE* root) {
	if(root==nullptr) return;
	inorderwalk(root->left);
	printf(" %d",root->key);
	inorderwalk(root->right);
	return;
}

BINNODE* findnode(int v, BINNODE* root) {
	if(root == nullptr) return nullptr;
	if(root->key ==v ) return root;
	return (v< root->key)?findnode(v,root->left) : findnode(v,root->right);
}

int main() {
	int m,v;
	int i;
	string cmd;
	BINNODE* root=nullptr;
	BINNODE* x;
	BINNODE* y;
	BINNODE* z;
	cin >> m;
	for(i=0; i<m; ++i) {
		cin >> cmd;
		if(cmd=="delete") {
			cin >> v;
			z=findnode(v,root);
			while(1) {
				if(z->left==nullptr && z->right==nullptr) {
					if(z->parent==nullptr) {
						root=nullptr;
						delete z;
						break;
					} else if(z->parent->key > z->key) {
						z->parent->left=nullptr;
						delete z;
						break;
					} else if(z->parent->key < z->key) {
						z->parent->right=nullptr;
						delete z;
						break;
					}
				} else if(z->right==nullptr) {
					if(z->parent==nullptr) {
						root=z->left;
						delete z;
						break;
					} else if(z->key < z->parent->key) {
						z->parent->left=z->left;
						delete z;
						break;
					} else {
						z->parent->right=z->left;
						delete z;
						break;
					}
				} else if(z->left==nullptr) {
					if(z->parent==nullptr) {
						root=z->right;
						z->right->parent=nullptr;
						delete z;
						break;
					} else if(z->key < z->parent->key) {
						z->parent->left=z->right;
						z->right->parent=z->parent;
						delete z;
						break;
					} else {
						z->parent->right=z->right;
						z->right->parent=z->parent;
						delete z;
						break;
					}
				} else {
					y=z->right;
					while(y->left!=nullptr || y->right!=nullptr) {
						if(y->left!=nullptr) {
							y=y->left;
						} else {
							y=y->right;
						}
					}
					z->key=y->key;
					if(y->parent->left==y) {
						y->parent->left=nullptr;
					} else {
						y->parent->right=nullptr;
					}
					free(y);
					break;
				}
			}
		} else if(cmd=="find") {
			cin >> v;
			printf(findnode(v,root)!=nullptr ? "yes\n" : "no\n");
		} else if(cmd=="insert") {
			cin >> v;
			z=new BINNODE(v);
			y=nullptr;
			x=root;
			while(x!=nullptr) {
				y=x;
				if (z->key < x->key) {
					x=x->left;
				} else {
					x=x->right;
				}
			}
			z->parent = y;

			if(y==nullptr) {
				root=z;
			} else if(z->key < y->key) {
				y->left = z;
			} else {
				y->right = z;
			}
		} else {
			inorderwalk(root);
			printf("\n");
			preorderwalk(root);
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 21932
def t():
    n=int(input())
    s=input()
    from collections import defaultdict
    l,r=s[:n],s[-1:-n-1:-1]
    d=defaultdict(int)
    for i in range(2**n):
        a={j for j in range(n)if (i>>j)%2}
        d[("".join(l[p] for p in sorted(list(a))),"".join(l[o] for o in range(n)if o not in a))]+=1
    ans=0
    for i in range(2**n):
        a={j for j in range(n)if (i>>j)%2}
        ans+=d[("".join(r[p] for p in sorted(list(a))),"".join(r[o] for o in range(n)if o not in a))]

    print(ans)
if __name__ == "__main__":
    t()

Measured memory_bytes: 129496
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[3][5],i,t=0,n=10,m=0;
	cin>>a[0][0]>>a[0][1]>>a[0][2]>>a[0][3]>>a[0][4]; 
	for(i=0;i<=4;i++)
	{
		a[1][i]=a[0][i]%10;
		if((a[0][i]%10)!=0)
	    {m++;
	    	if((a[0][i]%10)<n)
	    	n=(a[0][i]%10);
	    }
	    a[2][i]=a[0][i]/10;
	    t+=a[2][i]*10;
	}
	if(m!=0)
	t+=(m-1)*10+n;
	cout<<t;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    long long n;  scanf("%lld", &n);
    long long arr[100005];
    for(long long i=0; i<n+1; i++)
        scanf("%lld", &arr[i]);
    long long barr[100005];
    for(long long i=0; i<n; i++)
        scanf("%lld", &barr[i]);
    long long count = 0;
    for(int i=0; i<n; i++)
    {
        if(arr[i]>=barr[i])
        {
            arr[i] -= barr[i];
            count += barr[i];
            barr[i] = 0;
        }
        else
        {
            barr[i] -= arr[i];
            count += arr[i];
            arr[i] = 0;
            
            if(arr[i+1]>=barr[i])
            {
                count += barr[i];
                arr[i+1] -= barr[i];
                barr[i] = 0;
            }
            else
            {
                count += arr[i+1];
                arr[i+1] = 0;
            }
        }
    }
    printf("%lld\n", count);
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <set>
#include <cstring>
using namespace std;

int t[26][26];

//m[hid©ç¢­ÂÌm[hÉÚ®Â\©
//·ÅÉTõÏÝÌm[hÍÊçÈ¢
int reachableNode(int id,bool *used){
	int res = 1;

	used[id] = true;
	for(int i=0;i<26;i++){
		if(t[id][i] > 0 && !used[i]){
			res += reachableNode(i,used);
		}
	}

	return res;
}

int main(void){
	int n;

	while(cin>>n && n){
		string s;
		int from,to;
		set<int> ap;

		memset(t,0,sizeof(t));

		for(int i=0;i<n;i++){
			cin>>s;
			from = s[0] - 'a';
			to = s[s.length()-1] - 'a';

			//©È[vÈOÌÓÍJEg
			if(from != to){
				t[from][to]++;
			}
			ap.insert(from);
			ap.insert(to);
		}

		//XªêÂ¾¯Å é©ÌmF
		bool used[26];
		memset(used,0,sizeof(used));
		int count = reachableNode(from,used);
		if(count != ap.size()){
			cout<<"NG\n";
			continue;
		}

		//üÆoª¯¶©Ç¤©ÌmF
		set<int>::iterator i = ap.begin();
		for(;i!=ap.end();i++){
			int in=0,out=0;
			for(int j=0;j<26;j++){
				in += t[j][*i];
				out += t[*i][j];
			}

			if(in != out) break;
		}

		if(i == ap.end())
			cout<<"OK\n";
		else
			cout<<"NG\n";
	}

	return 0;
}

Measured memory_bytes: 916
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, string> P;
typedef tuple<int, string, string> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int a;

bool solve() {
    return a >= 30;
}

void input() {
    cin >> a;
}

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

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


Measured memory_bytes: 3052
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <cctype>
#include <stack>
#include <cstdlib>
#include <cstdio>
using namespace std;

int main() {
  string s;
  while(getline(cin, s)) {
    stringstream ss(s);
    stack<double> stk;
    while(ss >> s) {
      if(isdigit(*s.rbegin())) {
        stk.push(atof(s.c_str()));
      } else {
        double b = stk.top(); stk.pop();
        double a = stk.top(); stk.pop();
        double res = 0;
        switch(s[0]) {
        case '+': res = a+b; break;
        case '-': res = a-b; break;
        case '*': res = a*b; break;
        case '/': res = a/b; break;
        }
        stk.push(res);
      }
    }
    printf("%.10f\n", stk.top());
  }
  return 0;
}

Measured memory_bytes: 1272
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

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

int main() {
    int N, M; cin >> N >> M;
    if (N == M) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main () {
  unsigned int n;

  cin >> n;
  vector<string> words(n);
  bool flag = true;

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

  for(int i = 0; i < n; ++i){
    for(int j = i+1; j < n; ++j){
      if (words.at(i) == words.at(j)){
        flag = false;
        goto end;
      }
    }
  }

  for(int i = 0; i < n - 1; ++i) {
    if (words.at(i)[words.at(i).size() -1] != words.at(i + 1)[0]){
      flag = false;
      break;
    }
  }
  end:
  cout << (flag ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
typedef pair<ll,ll> P;
const ll MAX_N=1e6;
ll N;
string S[MAX_N];
ll mcp[MAX_N],op[MAX_N];
P mcop[MAX_N];

string str[2][MAX_N];
ll n[2];
int main(){
	cin>>N;
	ll sop=0;
	REP(i,N){
		cin>>S[i];
		ll op=0;
		for(auto c:S[i]){
			if(c=='('){
				op++;
			}else{
				op--;
			}
		}
		if(op>=0){
			str[0][n[0]++]=S[i];
		}else{
			str[1][n[1]++]=S[i];
		}
		sop+=op;
	}
	if(sop!=0){
		cout<<"No"<<endl;
	}else{
		REP(t,2){
			if(t==1){
				REP(i,n[1]){
					reverse(str[1][i].begin(),str[1][i].end());
					for(auto &c:str[1][i]){
						if(c=='('){
							c=')';
						}else{
							c='(';
						}
					}
				}
			}
	
			REP(i,n[t]){
				mcp[i]=op[i]=0;
				ll cp=0;
				for(auto c:str[t][i]){
					if(c=='('){
						op[i]++;
						cp--;
					}else{
						cp++;
						op[i]--;
						mcp[i]=max(mcp[i],cp);
					}
				}
			}
			REP(i,n[t]){
				mcop[i]=P(mcp[i],op[i]);
			}
			sort(mcop,mcop+n[t]);
			ll cop=0;
			REP(i,n[t]){
				if(cop<mcop[i].first){
					cout<<"No"<<endl;
					return 0;
				}else{
					cop+=mcop[i].second;
				}
			}
		}
		cout<<"Yes"<<endl;	
	}
}


Measured memory_bytes: 112964
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int w = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();

    if (a+w <= b) {
      System.out.println(b-(a+w));
    } else if (a+w > b && a <= b) {
      System.out.println(0);
    } else if (b+w <= a) {
      System.out.println(a-(b+w));
    }

  }

}


Measured memory_bytes: 21844
#include <iostream>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int a[10000];

int main() {
	int i;
	
	while (cin >> n) {
		if (!n) break;
		rep(i, n) cin >> a[i];
		
		double aveA = 0;
		rep(i, n) aveA += a[i];
		aveA /= n;
		
		int cnt = 0;
		rep(i, n) if (a[i] <= aveA) cnt++;
		cout << cnt << endl;
	}
	return 0;
}


Measured memory_bytes: 3144
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int[][] a = new int[n][m];
		int b[] = new int[m];
		int c[] = new int[n];
		int i,r;
		for(i = 0; i < n; ++i){
			for(r = 0; r < m; ++r){
				a[i][r] = scan.nextInt();
			}
		}
		for(i = 0; i < m; i++){
			b[i] = scan.nextInt();
		}
		for(i = 0; i < n; i++){
			for(r = 0; r < m; r++){
				c[i] += a[i][r] * b[r];
			}
			System.out.println(c[i]);
		}
		
 			}

	}


	

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

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

void solve(){
	int n;
	cin >> n;
	ll sum = 0;
	for(int i = 1; i <= n; ++i) {
		if(i % 3 == 0 || i % 5 == 0) continue;
		sum += i;
	}
	cout << sum;
}

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

	solve();
    
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;

int main(){
    int N;
    cin>>N;
    ll before=0;
    bool ans=true;

    for(int i=0;i<N;i++){
        ll H;
        cin>>H;
        if(H>before) before=(H-1);
        else if(H<before) ans=false;
        //cout<<before<<' ';
        if(!ans) break;
    }

    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}

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

cnt = 0
for i in range(N):
	if P[i] == i+1:
		if i == N-1:
			cnt += 1
			break

		P[i], P[i+1] = P[i+1], P[i]
		cnt += 1


print(cnt)

Measured memory_bytes: 14008
s = input()
ans = 0
for i in range(2 ** (len(s) - 1)):
    fom_lst = []
    for j in range(len(s) - 1):
        if (i >> j & 1):
            fom_lst.append('+')
        else:
            fom_lst.append('')
    S = ''
    for num, fom in zip(s, fom_lst):
        S += num + fom
    S += s[-1]
    if '+' in S:
        ans += sum(map(int, S.split('+')))
    else:
        ans += int(S)

print(ans)

Measured memory_bytes: 3064
n, a, b = map(int,input().split())

if n == 1:
    if a == b:
        print(1)
    else:
        print(0)
elif a >= b:
    if a == b:
        print(1)
    else:
        print(0)
else:
    ans = (b-a)*(n-2)+1
    print(ans)

Measured memory_bytes: 38384
(defun s (n)
  (labels ((s (n sum)
             (multiple-value-bind (a b) (floor n 10)
               (if (zerop a)
                   (+ b sum)
                   (s a (+ sum b))))))
    (s n 0)))

(let ((n (read)))
  (princ (if (zerop (rem n (s n)))
             "Yes"
             "No")))

Measured memory_bytes: 5864
#include<bits/stdc++.h>
using namespace std;
int n;
string str;
set<string>s;
int main()
{
	cin >> n;
	while (n--)
	{
		cin >> str;
		if (!s.count(str))
			s.insert(str);
	}
	cout << s.size() << endl;
	return 0;
}

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

#define st first
#define nd second
typedef long long LL;
typedef long double LLD;
typedef pair <int, int> PII;
typedef pair <LL, LL> PLL;

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

    int result = 0;
    for (int i = 0; i < n; ++i)
    {
        int a;
        scanf("%d", &a);
        result += a - 1;
    }

    printf("%d", result);
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	vector<vector<int>> G(n);
	for(int i = 0; i < m; ++i){
		int s, t;
		scanf("%d%d", &s, &t);
		G[s - 1].push_back(t - 1);
	}

	vector<double> prob(n);
	prob[0] = 1;
	for(int i = 0; i < n - 1; ++i){
		double d = prob[i] / G[i].size();
		for(int t : G[i]){
			prob[t] += d;
		}
	}

	double ans = 0;
	vector<double> exp(n);
	for(int i = n - 2; i >= 0; --i){
		double s = 0;
		double mx = 0;
		for(int t : G[i]){
			s += exp[t];
			mx = max(mx, exp[t]);
		}
		exp[i] = s / G[i].size() + 1;
		if(G[i].size() >= 2){
			double delta = (s - mx) / (G[i].size() - 1) - s / G[i].size();
			ans = min(ans, delta * prob[i]);
		}
	}
	ans += exp[0];
	printf("%.9f\n", ans);
}


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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define ALL(v) (v).begin(), (v).end()

typedef pair<int, int> P;

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

    int kai = 1;
    REP(i, m) kai *= 2;
    kai *= m;

    int ans = 100*(n-m)*(kai/m) + 1900*kai;

    cout << ans << endl;


    return 0;
}


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

int main() {
  ll N;
  cin >> N;
  ll a[N];

  for(ll i = 0; i < N; i++)
    cin >> a[i];


  map<ll, vector<ll> > mp;

  for(ll i = 0; i < N; i++) {
    mp[a[i]].push_back(i + 1);
  }


  vector< pair<ll, vector<ll> > > v;

  for(auto i: mp) {
    v.push_back(make_pair(i.first, i.second));
  }

  reverse(v.begin(), v.end());

  ll ans[N + 1];

  for(ll i = 0; i < N + 1; i++) {
    ans[i] = 0;
  }

  ll cnt = 0;
  ll mi = N;
  for(ll i = 0; i < v.size(); i++) {
    cnt += v[i].second.size();
    mi = min(mi, v[i].second[0]);
    if(i == v.size() - 1) {
      ans[mi] += (v[i].first - 0) * cnt;
      continue;
    }
    ans[mi] += (v[i].first - v[i+1].first) * cnt;
  }

  for(ll i = 1; i <= N; i++) {
    cout << ans[i] << endl;
  }

}


Measured memory_bytes: 20588
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <array>

using namespace std;

class Knapsack
{
public:
  int n, maxw;
  vector<int> v,w;
  vector<vector<int>> dp;
  Knapsack(){}
  Knapsack( int n, int w ) : n(n), maxw(w), v(n), w(n), dp(n+1, vector<int>(w+1)) {}
  int solve();
};

int Knapsack::solve()
{
  for ( auto j = 0; j <= maxw; ++j )
    dp[0][j] = 0;
  
  for ( auto i = 0; i <= n; ++i )
    dp[i][0] = 0;

  for ( auto i = 0; i < n; ++i )
    for ( auto j = 1; j <= maxw; ++j )
      if ( j >= w[i] )
        dp[i+1][j] = max( dp[i][j], dp[i][j-w[i]] + v[i] );
      else
        dp[i+1][j] = dp[i][j];
  
  cout << dp[n][maxw] << endl;
  
  return 0;
}

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

  Knapsack k( n, w );

  for ( auto i = 0; i < n; ++i )
    cin >> k.v[i] >> k.w[i];

  k.solve();

  return 0;
}

Measured memory_bytes: 4956