akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define A 2000
#define Q 2000
void solve(int, int, int);
int count,a[A];

main(){
  int n,q,m[Q],i;
  
  scanf("%d",&n);
  for(i=0; i<n; i++)
    scanf("%d",&a[i]);
  
  scanf("%d",&q);
  for(i=0; i<q; i++)
    scanf("%d",&m[i]);
  
  for(i=0; i<q; i++){
    count=0;
    solve(0,m[i],n);
      if(count==1) printf("yes\n");
      else printf("no\n");
  }
  return 0;
}


void solve(int i, int m,int n){
    if(m==0) count=1;
    else if(i!=n){(solve(i+1,m,n));
      solve(i+1,m-a[i],n);
    }
}

Measured memory_bytes: 588
n = int(input())
f = [input().split(' ') for _ in range(n)]
p = [input().split(' ') for _ in range(n)]
res = -10 ** 7 * n
for num in range(1, 1024):
  tmp = 0
  for index in range(0, n):
    tmp += int(p[index][len([True for x in range(0, 10) if f[index][x]=='{:010b}'.format(num)[x]=='1'])])
  res = max(tmp, res)
print(res)


Measured memory_bytes: 3064
import java.util.*;
public class Main {
        static Scanner sc = new Scanner(System.in);
        static void myout(Object t){System.out.println(t);}//standard output
        static void myerr(Object t){System.err.println(t);}//standard error
        static String getStr(){return sc.next();}
        static int getInt(){return Integer.parseInt(getStr());}
        static long getLong(){return Long.parseLong(getStr());}
        static boolean hasNext(){return sc.hasNext();}
        static char[] mySplit(String str){return str.toCharArray();}
        public static void main(String[] args){
          long L = getLong();
          long R = getLong();
          
          long output = 2020;
          for(long i = L; i < R; i++){
            for(long j = i + 1; j <= R; j++){
              long tmp = (i * j) % 2019;
              output = Math.min(output,tmp);
              if(output == 0){
                myout(output);
                return;
              }
            }
          }
          myout(output);
        }
        //Method addition frame start

        //Method addition frame end
}


Measured memory_bytes: 23892
import java.io.*;
import java.util.*;
public class Main {
	public static class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch (Exception e) {}
			} return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
	}

	public static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); }
	public static long lcm(long a, long b) { return a * b / gcd(a, b); }
	public static int abs(int x) { if (x < 0) return -x; return x; }

	public static void main(String[] args) {
		FS in = new FS();

		long n = in.nextLong();
		int pd = (int) (n & 1L);
		if (pd == 1) {
			System.out.println(0);
			return;
		}

		long ans = 0;
		long div = 10L;
		while (n >= div) {
			ans += (n / div);
			div *= 5L;
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 24660
import sys

def main():
  input = sys.stdin.readline
  N = int(input().strip())
  A = list(map(int, input().split()))
  
  a = min(A)
  B = [b % a for b in A if b % a != 0]
  if (len(B) == 0) or (min(B) == 0):
    print(a)
  else:
    b = min(B)
    while a % b != 0:
      c = b
      b = a % b
      a = c
    print(b)


if __name__ == '__main__':
  main()

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 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 pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> void re(T& x) { cin >> x; }
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "/home/o_o/MyCodes/pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  

void solve(){
	string s ;
	re(s);
	int tot = 0 ;
	trav(i,s) tot+=i-'0';
	if(tot%9) cout << "No\n" ;
	else cout << "Yes\n";
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3764
from bisect import bisect_left,bisect_right
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
ans=0
for i in range(n):
  indea=bisect_left(a,b[i])
  indec=bisect_right(c,b[i])
  ans+=indea*(n-indec)
print(ans)

Measured memory_bytes: 23360
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, K, Q;
  cin>> N>> K>> Q;
  vector<int>P(N+1, Q);
  for(int i=0; i<Q; i++){
    int a;
    cin>> a;
    P[a]--;
  }
  for(int i=1; i<=N; i++){
//    cout<<"i:"<<i<<" P[i]:"<<P[i]<<endl;
    if(K-P[i]>0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 1024
x=int(input())
p=[100,101,102,103,104,105]
ans=[False]*2001
ans[0]=True
for i in range(2000):
    if ans[i]:
        for j in p:
            if i+j>2000:
                continue
            else:
                ans[i+j]=True
if x>2000:
    print(1)
elif ans[x]:
    print(1)
else:
    print(0)


Measured memory_bytes: 3060
N=int(input())
order=list(map(int,input().split()))
sat=list(map(int,input().split()))
a=list(map(int,input().split()))

total=sum(sat)

for i in range(N-1):
  if order[i]==order[i+1]-1:
    total += a[order[i]-1]

print(total)

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

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

        long n = sc.nextLong();
        long a[] = new long[100000];
        long min = 1000000000;

        for (int i = 0; i < n; i++) {
            long ai = sc.nextInt();
            a[i] = ai;
            if (ai < min) min = ai;
        }

        long count = 0;
        for (;count != n;) {
            count = 0;
            for (int i = 0; i < n; i++) {
                if (a[i] == 0 || a[i] == min) {
                    count++;
                    continue;
                }

                a[i] = a[i] % min;
                if (a[i] < min && a[i] > 0) min = a[i];
            }
        }

        System.out.println(min);
    }
}


Measured memory_bytes: 50584
/*
  AUTHOR:SOURABH
  CREATED:09:02:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<ll , null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

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

    //freopen("in.txt","r",stdin);
    //freopen(2 "out.txt","w",stdout);

    ll t,a,b;
    string s,tt,u;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>s>>tt;
        cin>>a>>b;
        cin>>u;
        if(s==u)
            a--;
        else
            b--;
        cout<<a<<" "<<b<<"\n";
    }
    return 0;
}

























Measured memory_bytes: 256
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
   int H, W;
   cin >> H >> W;
   char C[100][100] = {0};
   char D[200][100] = {0};
   rep(i, H) {
       rep(j, W) {
            char cij;
            cin >> cij;
            C[i][j] = cij;
       }
   }

   rep(i, H * 2) {
       rep(j, W) {
           int newi = i / 2;
           D[i][j] = C[newi][j];
       }
   }

   rep(i, H * 2) {
       rep(j, W) {
         cout << D[i][j];
       }
       cout << endl;
   }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int,int>;

const int mx = 2e5+5;
int n, w, a[mx], b[mx];
ll dp[105][mx];

ll fun(int i, int k){
    if(i == n) return 0;

    ll &ans = dp[i][k];
    if(~ans) return ans;

    ans = fun(i+1, k);
    if(k >= a[i])
        ans = max(ans, b[i]+fun(i+1, k-a[i]));
    return ans;
}

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

    cin >> n >> w;
    for(int i=0; i<n; i++)
        cin >> a[i] >> b[i];
    memset(dp, -1, sizeof dp);
    cout << fun(0, w) << "\n";
    return 0;
}



Measured memory_bytes: 167696
typedef long long ll;

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int main(){
  const int n = getInt();
  int i = 0;
  ll sum = 0;
  for(; sum < n; i++){
    sum += i;
  }

  printf("%d\n", i - 1);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	int a, b, t;

	cin >> a >> b >> t;

	int keika = 0;
	int sum = 0;
	int x = 1;

	for (int i = 1; i <= t; i++) {
		if (x * a == i) {
			//keika += i * a;
			sum += b;
			x++;
		}
	}

	cout << sum << endl;



	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE BangPatterns #-}

-- Default Imports

import Control.Monad
import Control.Monad.ST
import Control.Monad.Trans.Class

import qualified Control.Monad.Reader as Reader
import Control.Monad.Reader (Reader, ReaderT, runReader, runReaderT)

import qualified Data.Array.MArray as MArray
import qualified Data.Array.ST as STArray
import Data.Array.ST (STArray, STUArray, runSTArray, runSTUArray)
import Data.Ix (Ix)

import qualified Data.Bits as Bits
import Data.Bits ((.&.), (.|.))

import qualified Data.ByteString.Char8 as BS
import Data.ByteString.Char8 (ByteString)

import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map.Strict as Map
import Data.Map.Strict (Map)
import qualified Data.Maybe as Maybe
import qualified Data.Set as Set
import Data.Set (Set)

import qualified Data.Vector as Vector
import qualified Data.Vector.Generic as GVector
import qualified Data.Vector.Mutable as MVector
import Data.Vector.Mutable (STVector)
import qualified Data.Vector.Unboxed as UVector

import Numeric

import Debug.Trace
-- ----------

-- Custom Import Here


-- ----------

-- Default Definitions

type Vector = Vector.Vector
-- type GVector = GVector.Vector
type UVector = UVector.Vector

readIntToList :: ByteString -> [Int]
readIntToList = List.unfoldr (fmap (second $ BS.dropWhile Char.isSpace) . BS.readInt)

readToList :: Read a => ByteString -> [a]
readToList = List.unfoldr $ fmap (mapTaken . mapRemain) . span' (not . Char.isSpace)
	where
		mapTaken  = first $ read . BS.unpack
		mapRemain = second $ BS.dropWhile Char.isSpace
		span' pred s
			| BS.null taken = Nothing
			| otherwise     = Just (taken, remain')
			where
				(taken, remain) = BS.span pred s
				remain' = BS.dropWhile Char.isSpace remain

readToListN :: Read a => Int -> ByteString -> [a]
readToListN n = take n . readToList

readIntToVector :: ByteString -> Vector Int
readIntToVector = Vector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVector :: ByteString -> UVector.Vector Int
readIntToUVector = UVector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToVectorN :: Int -> ByteString -> Vector.Vector Int
readIntToVectorN n = Vector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVectorN :: Int -> ByteString -> UVector.Vector Int
readIntToUVectorN n = UVector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace


first :: (a -> a') -> (a, b) -> (a', b)
first f (a, b) = (f a, b)

second :: (b -> b') -> (a, b) -> (a, b')
second f (a, b) = (a, f b)

average :: Fractional a => [a] -> a
average xs = sum xs / (fromIntegral . length) xs

-- ----------

main :: IO ()
main = do
	[a, b] <- readIntToList <$> BS.getLine
	print $ a * b


Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
int main()
{
      string s;
      cin>>s;
      long int j=s.size()-1,cnt=0;
      for(long int i=0;i<s.size()/2;i++)
      {
            if(s[i]!=s[j])
            cnt++;
            j--;
      }
      cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#define mod 1000000007
using namespace std;
typedef long long ll;
const int MAXN=100000+10;
int n,m;
int a[MAXN];
int dp[MAXN];
bool vis[MAXN];

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d",&a[i]);
		vis[a[i]]=1;
	}
	dp[0]=1;
	for(int i=1;i<=n;i++){
		if(vis[i]) continue; //vis[i] == 1のときa[i]は壊れている
		dp[i]=dp[i-1]+dp[i-2];
		dp[i]%=mod;
	}
	printf("%d\n",dp[n]%mod);
	return 0;
}

Measured memory_bytes: 896
S = input()

x = len(S)-1

s = 0
for i in range(1 << x):
    t = 0
    for j in range(x):
        if ((i >> j) & 1 == 1):
            s += int(''.join(S[t:j+1]))
            t = j+1
    s += int(''.join(S[t:]))
print(s)

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10**8)
N,U,V = map(int,input().split())
U,V = U-1,V-1
AB = [tuple(map(int,input().split())) for i in range(N-1)]
es = [[] for _ in range(N)]
for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)

prev = [-1] * N
def dfs(v,p=-1):
    for to in es[v]:
        if to==p: continue
        prev[to] = v
        dfs(to,v)
dfs(U)

path = [V]
while prev[path[-1]] >= 0:
    path.append(prev[path[-1]])
ban = set(path[:(len(path)+1)//2])

reach = [0] * N
reach[U] = 1
def dfs2(v,p=-1):
    for to in es[v]:
        if to==p: continue
        if to in ban: continue
        reach[to] = 1
        dfs2(to,v)
dfs2(U)

depth = [0] * N
ans = 0
def dfs3(v,p=-1):
    global ans
    for to in es[v]:
        if to==p: continue
        depth[to] = depth[v] + 1
        if reach[to]:
            ans = max(ans, depth[v])
        dfs3(to,v)
dfs3(V)

print(ans)

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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();


    int n;
    cin>> n;

    int a, c= -1;
    for(int i= 0; i<n; i++)
    {
        cin>> a;
        if(a% 2== 0 && a%5!= 0 && a%3!= 0)
            c= 0;
    }

    cout << (c== -1? "APPROVED\n" : "DENIED\n");

             return 0;
}



Measured memory_bytes: 3604
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに作成したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), a = scanner.nextInt(), b = scanner.nextInt();
			int[] h = new int[n];
			int max = IntStream.range(0, n).map(i -> h[i] = scanner.nextInt()).max().getAsInt();
			int high = (max + b - 1) / b, low = 0;
			while (high > low + 1) {
				int middle = (high + low) / 2;
				if (enough(middle, h, a, b)) {
					high = middle;
				} else {
					low = middle;
				}
			}
			System.out.println(high);
		}
	}

	/**
	 * @param t 爆発回数
	 * @param h 怪物のHPの配列
	 * @param a 爆発の個体破壊力
	 * @param b 爆発の全体破壊力
	 * @return t回の爆発ですべての怪物が倒せるかどうか
	 */
	private static boolean enough(final int t, final int[] h, final int a, final int b) {
		return Arrays.stream(h).mapToLong(hi -> ((hi - b * t) + (a - b) - 1) / (a - b)).map(i -> (i > 0) ? i : 0)
				.sum() <= t;
	}
}


Measured memory_bytes: 60304
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  string S;
  cin >> S;
  vector<int> a;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='A' || S.at(i)=='T' || S.at(i)=='G' || S.at(i)=='C'){
      int count=0;
      for(int j=i;j<S.size();j++){
        
        if(S.at(j)=='A' || S.at(j)=='T' || S.at(j)=='G' || S.at(j)=='C')
          count++;
        else
          break;
      }
      a.push_back(count);
    }
  }
  if(!a.empty()){
  sort(a.begin(),a.end());
  cout << a.at(a.size()-1) << endl;
  }
  else cout << 0 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  map<string,ll>cnt;
  for(int i=0;i<n;i++){
    string s;cin>>s;
    sort(ALL(s));
    cnt[s]++;
  }
  ll ans = 0;
  for(auto a:cnt){
    ans += a.S*(a.S-1)/2;
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 11264
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    w = input().rstrip()
    a = [w]
    for i in range(1, n):
        w = input().rstrip()
        if w in a:
            print('No')
            break
        if a[-1][-1] != w[0]:
            print('No')
            break
        a.append(w)
    else:
        print('Yes')

if __name__ == '__main__':
    main()

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

int main(){
    string s;
    cin>>s;
    int n=s.size();
    vector<vector<ll>> dp(4,vector<ll> (n+1));
    dp[0][0]=1;
    rep(i,n){
        if(s[i]=='?'){
            rep(j,4)dp[j][i+1]=3*dp[j][i]%mod;
            rep(j,3)(dp[j+1][i+1]+=dp[j][i])%=mod;
        }
        else{
            rep(j,4)dp[j][i+1]=dp[j][i];
            int c=s[i]-'A';
            (dp[c+1][i+1]+=dp[c][i])%=mod;
        }
    }
    cout<<dp[3][n]<<endl;
    return 0;
}

Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include <cmath>
using namespace std;
 
int main(){
    int N,a[15000],b,c=0;
    char g[100];
  cin>>N>>b;
  c=b-N+1;
  for(int i=c;i<c+2*N-1;i++){
      cout <<i<<" ";
  }
}

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

int main()
{
	
	int n;
	cin >> n;
	if(n <= 1) return 0;
	vector<int> h(n);

	for(int i = 0; i < n; i++)
	{
		cin >> h[i];
	}
	vector<int> dp(n, 0);
	for(int i = 1; i < n; i++)
	{
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), (i >= 2) ? dp[i -  2] + abs(h[i] - h[i - 2]) : INT_MAX);
	}
	
	cout << dp[n - 1] << endl;
	
	return 0;
}


Measured memory_bytes: 4024
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

int main(){
    vector<int> v(9);
    rep(i, 9) cin >> v[i];
    int diff1 = v[1] - v[0];
    int diff2 = v[2] - v[1];
    if(v[4] - v[3] == diff1 && v[5] - v[4] == diff2 && v[7]-v[6] == diff1
            && v[8] - v[7] == diff2){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}




Measured memory_bytes: 256
use std::collections::*;
use std::cmp::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input!{
        k: usize
    }

    let mut all: Vec<i64> = Vec::new();
    for i in 1..10 {
        rec(1, i, &mut all);
    }

    all.sort();
    println!("{}", all[k-1]);


}

fn rec(d: i32, val: i64, all: &mut Vec<i64>) {
    all.push(val);

    if d == 10 { return; }

    let diff: Vec<i64> = vec![-1, 0, 1];
    for j in 0..3 {
        let add = (val % 10) + diff[j];
        if add >= 0 && add <= 9 {
            rec(d+1, val*10+add, all);
        }
    }
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  int64_t u;
  int64_t sum = 0;
  int A[1000000];
  cin >> N;
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  if (N == 1){
    cout<<sum<<endl;
  }
  else{
  for(int i=0 ; i < N-1 ; i++){
    int s =i+1;
    //cout<<A[i]<<A[s]<<endl;
  if(A[i] > A[s]){
    u = A[i] - A[s];
    A[s] = A[i] ;
    sum += u;
    //cout << u <<endl;
   }
                 }
  cout << sum << endl;
  }
}

Measured memory_bytes: 4376
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int bc = 0;
    long ans = 0;
    int n = s.length();
    for(int i=n-1;i>=0;i--){
        if(s[i]=='A'){
            ans += bc;
        }else if(s[i]=='B')bc = 0;
        else{
            if(i!=0 && s[i-1]=='B'){
                bc++;
                i--;
            }else bc = 0;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
ll GCD(ll a,ll b) { return b ? GCD(b,a%b) : a; }
ll LCM(ll a,ll b) { return a/GCD(a,b)*b; }
ll Factorial(ll n){ ll m=1;while(n>=1)m*=n--;return m; }
ll modPow(ll x,ll n,ll mod=MOD){
    return (!n?1:!n%2?modPow(x*x,n/2,mod)%mod:x%mod*modPow(x,n-1,mod)%mod);
}
int main(void){
    ll N;cin>>N;
    typedef pair<ll,ll> P;
    vector<P> t(N);
    REP(i,N){
        cin>>t[i].first>>t[i].second;
    }
    sort(ALLv(t));
    ld ans=0;
    do{
        //REP(i,N)cout<<t[i].first<<","<<t[i].second<<" ";
        REP(i,N-1){
            ll x1=t[i].first,x2=t[i+1].first,y1=t[i].second,y2=t[i+1].second;
            ll dx=x1-x2,dy=y1-y2;
            ans+=sqrt(dx*dx+dy*dy);
            //cout<<sqrt(dx*dx+dy*dy)<<" ";
        }//cout<<"\n";
    }while(next_permutation(ALLv(t)));

    cout<<dcml(10)<<ans/Factorial(N)<<"\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>

using namespace std;

int main(){
  int n,l[15],sum=0;  
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&l[i]);
  }

  sort(l,l+n,greater<int>());

  for(int i=1;i<n;i++){
    sum+=l[i];
  }

  if(sum>l[0]) 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;
    int a,cnt=0;

    for(int i=1;i<=n;i++)
    {
        cin>>a;
        if(i%2==1)
        {
            if(a*a%2==1)
            {
                cnt++;
            }
        }
    }

    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3584
s = input()
t = input()
d = len(s) - len(t)
cnt = 0
for i in range(d+1):
    cnt2 = 0
    for j in range(len(t)):
        if t[j] == s[i+j]:
            cnt2 += 1
        cnt = max(cnt, cnt2)
print(len(t)-cnt)

Measured memory_bytes: 9104
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  char x,y;
  cin>>x>>y;
  if(x > y) {
    cout << ">" << endl;
  } else if (x < y) {
    cout << "<" << endl;
  } else {
    cout << "=" << endl;
  }

  return 0;
}


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

C = [[0]*3 for i in range(3)]

def exit_if_not_eq(i, j):
    if i != j:
        print("No")
        exit()

for i in range(3):
    C[i] = list(map(int, input().split()))  
#print(*C)

for i in range(C[0][0]+1):
    a1 = i
    b1 = C[0][0] - a1
    if b1 < 0:
        continue
    b2 = C[0][1] - a1
    if b2 < 0:
        continue
    b3 = C[0][2] - a1
    if b3 < 0:
        continue
    a2 = C[1][0] - b1
    if a2 < 0:
        continue
    if C[1][1] != a2 + b2:
        continue
    if C[1][2] != a2 + b3:
        continue
    a3 = C[2][0] - b1
    if a3 < 0:
        continue
    if C[2][1] != a3 + b2:
        continue
    if C[2][2] != a3 + b3:
        continue
    print("Yes")
    exit()
print("No")


Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>

int isprime(int x);

int main(void){
	long int n,i,temp;
	/*n?????§????´???°???????????????*/
	scanf("%ld",&n);
	temp=n;
	printf("%ld:",n);
	if(isprime(n)==1){printf(" %ld\n",n);return 0;}
	while(temp!=0){
		for(i=2;i<=temp;i++){
			if(isprime(i)!=0 && temp%i==0){printf(" %ld",i);break;}
		}
		temp=temp/i;
	}
	printf("\n");
	return 0;
}


int isprime(int x){
	int i;
	if(x==2)return 1;
	if(x<2 || x%2==0)return 0;
	for(i=3;i < sqrt(x);i=i+2){
		if(x%i==0)return 0;
	}
	return 1;
}

Measured memory_bytes: 600
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#define MAXN (20)
#define MAXM (60)
#define INF ()
#define LL long long
#define DD double
using namespace std;
struct edge
{
	int from, to, cost;
	edge(int a, int b, int c): from(a), to(b), cost(c) {}
};
int l;
int ws(int x)
{
	int re = 0;
	while (x)
		++re, x >>= 1;
	return re;
}
int lowbit(int x)
{
	int re = 1;
	while (re <= x)
		re <<= 1;
	return re / 2;
}
int main()
{
	scanf("%d", &l);
	vector<edge> edg;
	for (int i = 1; i < 20; i++)
		edg.push_back(edge(i, i + 1, 0));
	int x = lowbit(l), xws = ws(x);
	int cnt = x;
	for (int i = 20 - xws + 1; i < 20; i++)
		edg.push_back(edge(i, i + 1, 1 << (20 - i - 1)));
	l -= x;
	while (l)
	{
		x = lowbit(l), xws = ws(x);
		edg.push_back(edge(1, 20 - xws + 1, cnt));
		cnt += x;
		l -= x;
	}
	printf("20 %d\n", edg.size());
	for (int i = 0; i < edg.size(); i++)
		printf("%d %d %d\n", edg[i].from, edg[i].to, edg[i].cost);
	return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define forin(x,n) for(auto& (x) : n)
#define all(v) (v).begin(),(v).end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define inf 1000000000
#define llinf 1000000000000000
#define MAX 1000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;
typedef pair<int,pint> P;

int main(){
    int n;
    cin>>n;
    int x,y;
    vint table(n);
    vll number(n);
    vll ans(n);
    vint clear(n);
    vector<vector<int>> tree(n);
    rep(i,n-1){
        cin>>x>>y;
        table[x-1]++;
        table[y-1]++;
        tree[x-1].pb(y-1);
        tree[y-1].pb(x-1);
    }
    rep(i,n)cin>>number[i];

    sort(all(number));
    ll sum=0;
    rep(i,n-1)sum+=number[i];
    cout<<sum<<endl;

    rep(i,n)ans[i]=-1;
    reverse(all(number));

    queue<int> q;
    q.push(0);

    int i=0;
    while(!q.empty()){
        int id=q.front();
        q.pop();
        if(ans[id]!=-1){
            continue;
        }
        ans[id]=number[i];
        i++;
        rep(j,tree[id].size()){
            if(ans[tree[id][j]]==-1){
                q.push(tree[id][j]);
            }
        }
    }

    rep(i,n){
        cout<<ans[i];
        if(i!=n-1)cout<<" ";
    }
    cout<<endl;
    
}

Measured memory_bytes: 1152
package main

import (
   "fmt"
)

func solution(n, m int, s, t []string) int {
   memo := make([]int, len(s))

   for i := range memo {
        for j := range s {
                if s[i] == s[j] {
                        memo[i]++
                }
        }
        for j := range t {
                if s[i] == t[j] {
                        memo[i]--
                }
        }
   }

   out := 0
   for _, n := range memo {
        out = max(out, n)
   }
   return out
}

func max(x, y int) int {
   if x > y {
        return x
   }
   return y
}
func main() {
   var n int
   fmt.Scan(&n)
   s := make([]string, n)
   for i := range s {
        fmt.Scan(&s[i])
   }
   var m int
   fmt.Scan(&m)
   t := make([]string, m)
   for i := range t {
        fmt.Scan(&t[i])
   }
   fmt.Println(solution(n, m, s, t))
}

Measured memory_bytes: 1784
#include<bits/stdc++.h>
#define REP(i,n) for(long long i=0;i<n;++i)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
using namespace std;

class Node{
    public:
        int location;
        int p,l,r;
        Node(){}
};

class Point{
    public:
        int id,x,y;
        Point(){}
        Point(int id,int x,int y): id(id),x(x),y(y){}
        bool operator<(const Point &p) const {
            return id<p.id;
        }

        void print(){
            printf("%d\n",id);
        }
};

const int MAX=1e6;
const int NIL=-1;

int N;
Point P[MAX];
Node T[MAX];
int np;

bool lessX(const Point &p1,const Point &p2){ return p1.x<p2.x; }
bool lessY(const Point &p1,const Point &p2){ return p1.y<p2.y; }

int makeKDTree(int l,int r,int depth){
    if(l>=r) return NIL;
    int mid=(l+r)/2;
    int t=np++;
    if(depth%2) sort(P+l,P+r,lessY);
    else sort(P+l,P+r,lessX);
    T[t].location=mid;
    T[t].l=makeKDTree(l,mid,depth+1);
    T[t].r=makeKDTree(mid+1,r,depth+1);

    return t;
}

void find(int v,int sx,int tx,int sy,int ty,int depth,vector< Point > &ans){
    int x=P[T[v].location].x;
    int y=P[T[v].location].y;

    if(sx<=x&&x<=tx&&sy<=y&&y<=ty) ans.push_back(P[T[v].location]);

    if(depth%2){
        if(T[v].l!=NIL){
            if(sy<=y) find(T[v].l,sx,tx,sy,ty,depth+1,ans);
        }if(T[v].r!=NIL){
            if(y<=ty) find(T[v].r,sx,tx,sy,ty,depth+1,ans);
        }
    }else{
        if(T[v].l!=NIL){
            if(sx<=x) find(T[v].l,sx,tx,sy,ty,depth+1,ans);
        }if(T[v].r!=NIL){
            if(x<=tx) find(T[v].r,sx,tx,sy,ty,depth+1,ans);
        }
    }
}

int main(){
    int x,y;
    scanf("%d",&N);
    REP(i,N){
        scanf("%d%d",&x,&y);
        P[i]=Point(i,x,y);
        T[i].l=T[i].r=T[i].p=NIL;
    }

    np=0;

    int root=makeKDTree(0,N,0);

    int q;
    scanf("%d",&q);
    int sx,tx,sy,ty;
    vector< Point > ans;
    REP(i,q){
        scanf("%d%d%d%d",&sx,&tx,&sy,&ty);
        ans.clear();
        find(root,sx,tx,sy,ty,0,ans);
        sort(ans.begin(),ans.end());
        REP(j,ans.size()) ans[j].print();
        puts("");
    }

    return 0;
}




Measured memory_bytes: 16492
from collections import Counter
S = input()[::-1]

memo = [0]
d = 0
mod = 2019

for s in S:
    tmp = int(s) * pow(10, d, mod) % mod
    tmp = memo[-1] + tmp
    memo.append(tmp % mod)
    d += 1

c = Counter(memo)
ans = sum(v * (v - 1) // 2 for v in c.values())
print(ans)

Measured memory_bytes: 16640
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>    
#define inf 100000000
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
long long mod=(long long)1e09+7;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct

int main(void){
    int a=in(),b=in();
    print((b-a-1)*(b-a)/2-a);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<long long> ACcnt(n),WAcnt(n);
  for(int i=0;i<m;i++){
    int p;
    string s;
    cin>>p>>s;
    p--;
    if(ACcnt[p]==0 && s=="WA")WAcnt[p]++;
    if(ACcnt[p]==0 && s=="AC")ACcnt[p]++;
  }
  long long AC=0,WA=0;
  for(int i=0;i<n;i++){
    AC+=ACcnt[i];
    if(ACcnt[i])WA+=WAcnt[i];
  }
  cout<<AC<<' '<<WA<<endl;
  return 0;
}


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

using namespace std;

const int N = (int)5000 + 7;
const int mod = (int)1e9 + 7;

int add(int a, int b) {
	a += b;
	if (a > mod) a -= mod;
	return a;
}

int mul(int a, int b) {
	return (a * 1LL * b) % mod;
}

int n;
string s;
int dp[N][N];

int binpow(int a, int n) {
	int res = 1;
	while (n) {
		if (n & 1)
			res = mul(res, a);
		a = mul(a, a);
		n >>= 1;
	}
	return res;
}

main() {
	scanf("%d", &n);
	cin >> s;
	int len = s.size();
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= n; j++) {
			dp[i + 1][j + 1] = add(dp[i + 1][j + 1], add(dp[i][j], dp[i][j]));
			if (j - 1 >= 0) dp[i + 1][j - 1] = add(dp[i + 1][j - 1], dp[i][j]);
			else dp[i + 1][j] = add(dp[i + 1][j], dp[i][j]);
		}
	}
	int ans = mul(dp[n][len], binpow(binpow(2, len), mod - 2));
	printf("%d", ans);
}


Measured memory_bytes: 98048
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	set<pair<llint,int>>aaa;
	llint ans=0,i,j,n;cin>>n;
	vector<llint>a(n);
	vector<llint>b(n);
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<n;i++){
		cin>>b[i];
		if(b[i]>a[i]){aaa.ins(mp(b[i],i));}
	}
	while(aaa.size()){
		
		int bas=prev(aaa.end())->sec;
		aaa.erase(prev(aaa.end()));
		llint kai=(b[bas]-a[bas])/(b[(bas+1)%n]+b[(bas+n-1)%n]);
		if(kai==0){cout<<-1<<endl;return 0;}
		ans+=kai;
		b[bas]-=(b[(bas+1)%n]+b[(bas+n-1)%n])*kai;
		if(b[bas]>a[bas]){aaa.ins(mp(b[bas],bas));}
		//for(auto it:b){cerr<<it<<" ";}cerr<<endl;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 17920
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int N;
  cin>>N;
  vector<double> A(N);
  rep(i,N) cin>>A[i];
  double ans=0;
  rep(i,N) ans+=(1/A[i]);
  cout<<(1/ans)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
int ceil(int a,int b){
    return (a+b-1)/b;
}
int main(void){
    while(1){
        int h,w;
        cin>>h>>w;
        int t=h*h+w*w;
        if(h==0 && w==0) break;
        int min1=1000000;
        int hn=100000,wn=1000000;
        int sum = h*h+w*w;
        for(int i=1;i<=1000;i++){
            for(int j=i+1;j<=1000;j++){
                int t=i*i+j*j;
                if(t<sum)continue;
                if(t==sum&&i<=h)continue;
                if(t-sum<min1){
                    min1=t-sum;
                    hn=i;
                    wn=j;
                }
                else if(t-sum==0){
                    if(hn>i){
                        hn=i;
                        wn=j;
                        min1=0;
                    }
                }
            }
        }
        cout<<hn<<" "<<wn<<endl;
    }
    return 0;

}


Measured memory_bytes: 3052
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
int main() {
	int a, b, c, d, sum = 0;
	cin >> a >> b >> c >> d;
	if (a > b)
		sum = (b*c + d*(a - b));
	else
		sum = a*c;
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 3e18;
double Pi = 3.1415926535897932384626;
 
//vector<ll> G[550010];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
ll mod = 1000000007;
/*
2000000011 is prime
2000000033 is prime
*/

ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}


//ll fact[800005],rfact[800005];
/*
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[800000] = rui(fact[800000],mod - 2);
    for(ll i=800000; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,a,b,c,d,e,g,h,w,i,j,q,r;
ll k,ans;
ll x[500005],y[500005],z[500005];
char s[500005];



int main(){
    cin >> m >> d;
    for(i=1;i<=m;i++){
        for(j=1;j<=d;j++){
            a = j / 10;
            b = j % 10;
            if(a >= 2 && b >= 2 && a * b == i)ans++;
        }
    }
    p(ans);

    
    
    return 0;
}






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

int main()
{
  int pay;
  int change;

  change = 0;
  cin >> pay;

  if(pay % 1000 != 0)
  {
    pay = pay % 1000;
    change = 1000 - pay;
  }

  //change = 1000 - pay;
  cout << change << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <math.h>
using namespace std;

/* define const */
const int N_max = 100010;
/* end up defineing const */

int dp[N_max] = {};
string S;

int main()
{
  cin >> S;
  int len = S.length();
  // end up inputting

  int num_pa = 0;
  int num_gu = 0;

  for (int i = 1; i <= len; i++) {
    if (S[i-1] == 'g') {
      if (num_pa+1 <= num_gu) { // パーをだす
        dp[i] = dp[i-1] + 1;
        num_pa++;
      }
      else { // グーをだす
        dp[i] = dp[i-1] + 0;
        num_gu++;
      }
    }
    else { // 相手がパー
      if (num_pa+1 <= num_gu) {
        dp[i] = dp[i-1] + 0;
        num_pa++;
      }
      else {
        dp[i] = dp[i-1] - 1;
        num_gu++;
      }
    }
    //    cout << dp[i] << " ";
  }
  //  cout << endl;
  cout << dp[len] << endl;
}



Measured memory_bytes: 896
//ABC143
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int n;
	string s;
	cin >> n >> s;
	int count = 1;
	for(int i=0;i<n-1;i++){
		if(s.at(i) != s.at(i+1)){
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 512