akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
using namespace std;

int main(void)
{
    int x,a,b;
    cin>>x>>a>>b;
    int xa=abs(x-a);
    int xb=abs(x-b);
    if(xa<xb)
    {
        cout <<"A"<<endl;
    }
    else
    {
        cout <<"B"<<endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}

#define deb(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define END '\n'
#define inf 9e18
#define ff first
#define ss second
#define pb push_back

void solve(){
    string a, b, c;
    cin >> a >> b >> c;
    cout << ((a[(int)a.size() - 1] == b[0] && b[(int)b.size() - 1] == c[0]) ? "YES" : "NO");
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll H,W,ans=0;
  cin >> H >> W;
  queue<P> Q;
  vector<string> A(H);
  vector<vector<ll>> dp(H,vector<ll>(W,INF));
  rep(i,H){
    cin >> A.at(i);
    rep(j,W){
      if(A.at(i).at(j)=='#'){
        Q.push(P(i,j));
        dp.at(i).at(j)=0;
      }
    }
  }
  while(!Q.empty()){
    ll h,w;
    h=Q.front().first;
    w=Q.front().second;
    Q.pop();
    if(h!=0&&dp.at(h-1).at(w)==INF){
      dp.at(h-1).at(w)=dp.at(h).at(w)+1;
      ans=max(ans,dp.at(h-1).at(w));
      Q.push(P(h-1,w));
    }
    if(h!=H-1&&dp.at(h+1).at(w)==INF){
      dp.at(h+1).at(w)=dp.at(h).at(w)+1;
      ans=max(ans,dp.at(h+1).at(w));
      Q.push(P(h+1,w));
    }
    if(w!=0&&dp.at(h).at(w-1)==INF){
      dp.at(h).at(w-1)=dp.at(h).at(w)+1;
      ans=max(ans,dp.at(h).at(w-1));
      Q.push(P(h,w-1));
    }
    if(w!=W-1&&dp.at(h).at(w+1)==INF){
      dp.at(h).at(w+1)=dp.at(h).at(w)+1;
      ans=max(ans,dp.at(h).at(w+1));
      Q.push(P(h,w+1));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 29268
using System;
using System.IO;
using System.Text;
using static Scanner;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Solve();
        Console.Out.Flush();
    }
    static void Solve() {
        var N = ScanInt();
        long count = 0;
        for (int i = 0; i < N; i++) {
            var a = ScanLong();
            while (a % 2 == 0) {
                a /= 2;
                count++;
            }
        }
        Console.WriteLine(count);
    }
}

public static class Scanner
{
    static readonly byte[] buffer = new byte[1024];
    static int length, p;
    static bool isEof;
    static Stream stream => Console.OpenStandardInput();
    private static byte ConsoleIn() {
        if (isEof) return 0;
        if (p < length) return buffer[p++];
        p = 0;
        if ((length = stream.Read(buffer, 0, 1024)) > 0) return buffer[p++];
        isEof = true;
        return 0;
    }
    private static char Char() {
        var let = ConsoleIn();
        while ((let < '!' || '~' < let) && !isEof) let = ConsoleIn();
        return (char) let;
    }
    public static int ScanInt() {
        var temp = 0;
        for (var let = Char(); '0' <= let && let <= '9'; let = (char) ConsoleIn()) {
            temp = temp * 10 + let - '0';
        }
        return temp;
    }
    public static long ScanLong() {
        long temp = 0;
        for (var let = Char(); '0' <= let && let <= '9'; let = (char) ConsoleIn()) {
            temp = temp * 10 + let - '0';
        }
        return temp;
    }
}

Measured memory_bytes: 23564
def main():
    n = int(input())
    hlis = list(map(int, input().split()))
    ans = 0
    tmp = 0
    for i in range(n-1):      
        if hlis[i+1] <= hlis[i]:
            tmp += 1
        else:
            if ans < tmp:
                ans = tmp
            tmp = 0
    if ans < tmp:
        ans = tmp
    print(ans)
    


if __name__ == "__main__":
    main()


Measured memory_bytes: 85280
#!/usr/bin/env python3
import sys
from math import log2

ROUND = 10 ** 5
LOG = 18#int(log2(ROUND))

def test():
    print(len(format(ROUND, "b")))

def main():
    #test()
    #return 


    S = input()
    #S = "R" * (10 ** 5 - 1) + "L"
    N = len(S)
    to = []
    for _ in range(LOG):
        l = [0] * N
        to.append(l)
    
    for i in range(N):
        to[0][i] = i + 1 if S[i] == "R" else i - 1
    
    for i in range(1, LOG):
        for j in range(N):
            to[i][j] = to[i - 1][to[i - 1][j]]

    ans = [0] * N
    for j in range(N):
        ans[to[LOG - 1][j]] += 1

    L = [str(i) for i in ans]
    print(" ".join(L))
    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 28156
from itertools import product
N = int(input())
A = []
shougen = []
for i in range(N):
    a = int(input())
    A.append(a)
    ls = []
    for j in range(a):
        ls.append([int(k) for k in input().split()])
    shougen.append(ls)
truth = [0, 1]
ans = 0
for x in product(truth, repeat=N):
    num = 0
    for i, y in enumerate(x):
        if y == 1:
            for z in shougen[i]: 
                if x[z[0]-1] != z[1]:
                    num += 1
    if num == 0:
        ans = max(ans, sum(x))
print(ans)

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

main(int n){
    static int H[4][3][10];
    cin >> n;
    for(int i=0,b,f,r,v; i<n; ++i){
        cin >> b >> f >> r >> v;
        H[b-1][f-1][r-1] += v;
    }
    for(int i=0,j,k; i<4; ++i){
        for(j=0; j<3; ++j){
            for(k=0; k<10; ++k) cout << " " << H[i][j][k];
            cout<<endl;
        }
        cout<<(i<3?"####################\n":"");
    }
}


Measured memory_bytes: 3088
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        int N;
        int[] color; // white: 0, black: 1, not painted: -1
        List<Set<int[]>> graph = new ArrayList<>();

        void bfs() {
            Queue<Integer> q = new ArrayDeque<>();

            color[1] = 0;
            q.offer(1);

            while (q.size() > 0) {
                int node = q.poll();
                for (int[] nextNodeInfo : graph.get(node)) {
                    int v = nextNodeInfo[0];
                    int w = nextNodeInfo[1];

                    if (color[v] == -1) {
                        q.offer(v);
                        if (w % 2 == 0) {
                            color[v] = color[node];
                        } else {
                            color[v] = 1 - color[node];
                        }
                    }
                }
            }
        }

        void solve(InputReader in, PrintWriter out) {
            // write your code here
            N = in.nextInt();

            color = new int[N];
            Arrays.fill(color, -1);

            for (int i = 0; i < N; i++) {
                graph.add(new HashSet<>());
            }

            for (int i = 0; i < N - 1; i++) {
                int u = in.nextInt(); --u;
                int v = in.nextInt(); --v;
                int w = in.nextInt() % 2;

                graph.get(u).add(new int[] {v, w});
                graph.get(v).add(new int[] {u, w});
            }

            bfs();

            for (int i = 0; i < N; i++) {
                out.println(color[i]);
            }
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }
    }
}


Measured memory_bytes: 86032
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = long long;
#define MAX_N 1000001
#define MAX_M 100010
const long long mod = 1e9 + 7;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vec) for(int aqw=0;aqw<vec.size();aqw++){cout<<vec[aqw]<<" ";}ent;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,m,n) for(int i=m;i<(int)n;++i)
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define INF 1e+9
using P = pair<int, int>;
#define PLL pair<ll, ll>;
#define MAX_V 1000
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;


int main()
{
	int n, t;
	cin >> n >> t;
	vec S(t + 3, 0);
	for (int i = 0; i < n;i++) {
		int l, r;
		cin >> l >> r;
		l++; r++;
		S[l]++;
		S[r]--;
	}
	int ans = 0;
	for (int i = 1;i < t + 3;i++) S[i] += S[i - 1];
	for (int i = 1;i < t + 3;i++) chmax(ans, S[i]);
	cout << ans << endl;
}



Measured memory_bytes: 3116
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<map>
#include<set>
#include<string>
#include<cctype>
#include<cmath>
#include<algorithm>
#define LL long long
#define ULL unsigned long long
#define debug(x) cerr << #x << " = " << x << endl
#define MAXN 100010
using namespace std;
int read(){
    int x = 0, f = 1; char ch = getchar(); for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; return x * f;
}

int n;
int a[MAXN];
int cnt1 = 0, cnt2 = 0;

int main(){
    n = read();
    for(int i = 1, x; i <= n; i++){
        x = read();
        if(x % 4 == 0){
            cnt1++;
        }else if(!(x & 1)){
            cnt2++;
        }
    }
    n -= cnt2;
    if(!cnt2) n--;
    n -= cnt1 * 2;
    if(n > 0) puts("No");
    else puts("Yes");
    return 0;
}

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

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

  int h,w,k;
  std::cin>>h>>w>>k;

  std::vector<std::vector<char>> g(h,std::vector<char>(w,0));
  std::vector<int> HValue(h,0);
  std::vector<int> WValue(w,0);
  for(int i=0;i!=h;i++)
  {
    for(int j=0;j!=w;j++)
    {
      std::cin>>g[i][j];

      if(g[i][j]=='#')
      {
        HValue[i]++;
        WValue[j]++;
      }
    }
  }

  int result=0;
  for(int bit=0;bit!=(1<<h);bit++)
  {
    std::vector<int> hvalue=HValue;
    std::vector<int> wvalue=WValue;

    int sum=0;
    for(int i=0;i!=h;i++)
    {
      if(bit&(1<<i))
      {
        for(int j=0;j!=w;j++)
        {
          if(g[i][j]=='#')
          {
            hvalue[i]=0;
            wvalue[j]--;
          }
        }
      }
      sum+=hvalue[i];
    }

    int over=sum-k;

    if(over<0)
      continue;

    auto &a=wvalue;
    int A=over;
    int N=a.size();

    for (int bit=0;bit!=(1<<N);bit++)
    {
      int sum=0;
      for (int i=0;i!=N;i++)
      {
        if (bit&(1<<i))
        {
          sum+=a[i];
        }
      }

      if (sum==A)
      {
        result++;
      }
    }
  }

  std::cout<<result<<std::endl;

  return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

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

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
    int n;
    cin >> n;
    cout << n * n * n << endl;
}

Measured memory_bytes: 256
def ox_sw(ox,sw,prev):
    if ox =="o":
        if sw == 1:
            ans = prev
        else:
            ans = -1*prev
    elif ox =="x" :
        if sw ==1:
            ans = -1*prev
        else:
            ans = prev
    return ans

n = int(input())
s  = input()
a1 = [1,1]   #1---> sheep -1 ---> WOLF
a2 = [1,-1]
a3 = [-1,1]
a4 = [-1,-1]
f= False

for a in [a1,a2,a3,a4]:
    for i in range(1,n):
        a.append(ox_sw(s[i],a[i],a[i-1]))
    if a[n] == a[0] and a[1] == ox_sw(s[0],a[0],a[-2]):
        f = True
        break

if f:
    ans = []
    for i in range(n):
        if a[i]==1:
            ans.append("S")
        else:
            ans.append("W")
    print("".join(ans))
else:
    print(-1)


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

int main() {

    ll n, k;
    cin >> n >> k;

    n %= k;
    ll ans = n;
    rep(i, 1000000){
        ans = min(ans, abs(n-k));
        n = abs(n-k);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// atcoder/abc167/A/mani.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  str s, t;
  while (cin >> s >> t) {
    bool f = (s.size() + 1 == t.size());
    for (int i = 0; i < s.size(); ++i) {
      f = f && (s[i] == t[i]);
    }
    cout << (f ? "Yes" : "No") << endl;
  }

  return 0;
}


Measured memory_bytes: 3620
while True:
    n, l, r = map(int, input().split())
    if n+l+r == 0:
        break
    As = [int(input()) for _ in range(n)]
    ans = 0
    for jj in range(l, r+1):
        flag = False
        for i, a in enumerate(As):
            if flag:
                break
            if jj % a == 0:
                if (i+1) % 2 == 1:
                    flag = True
                    ans += 1
                    break
                else:
                    flag = True
        if flag:
            continue
        else:
            if n % 2 == 0:
                ans += 1

    print(ans)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
int cal(int index,vector<vector<int>>& graph,vector<int>& dp,int dist)
{
if(graph[index].size()==0)
return dist;
if(dp[index]==-1)
{
int k=0;
for(int i=0;i<graph[index].size();i++)
{
    dp[graph[index][i]]=max(dp[graph[index][i]],cal(graph[index][i],graph,dp,1));
    k=max(k,dist+dp[graph[index][i]]);
}
return k;
}
else
return dp[index];
}
int main()
{
int n,m;
cin>>n>>m;
vector<vector<int>> graph(n+1);
int temp1,temp;
for(int i=0;i<m;i++)
{
    cin>>temp>>temp1;
    graph[temp].push_back(temp1);
} 
vector<int> dp(n+1,-1);
for(int i=1;i<=n;i++)
{
    if(graph[i].size()>0 && dp[i]==-1)
    {
        dp[i]=max(dp[i],cal(i,graph,dp,1));
    }
}
int ans=0;
for(int i=0;i<=n;i++)
{
    if(ans<dp[i])
    ans=dp[i];
    if(graph[i].size()==0)
    dp[i]=0;
}
cout<<ans-1;
return 0;
}

Measured memory_bytes: 9472
#include<iostream>
using namespace std;
int main(){
  int h,m,s;
  int h1,m1,s1;
  int ha,ma,sa;
  while(cin >> h >> m >> s >> h1 >> m1 >> s1){
    ha=h1-h;
    ma=m1-m;
    if(ma<0){
      ha--;
      ma=60+ma;
    }
    sa=s1-s;
    if(sa<0){
      if(ma==0){
	ha--;
	ma=60;
      }
      ma--;
      sa=60+sa;
    }
    cout << ha << " " << ma << " "  << sa << endl;
  }
  return 0;
}
  

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
const int MAXN=5005;
const int Mod=1000000007;
int p[MAXN],vis[MAXN];
vector<int> e[MAXN],sz;
void dfs(int u,vector<int> &t)
{
    vis[u]=1;
    t.push_back(u);
    for(auto &v:e[u])
        if(!vis[v])dfs(v,t);
}
int fac[MAXN],pw[MAXN],dp[2][MAXN];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=(fac[0]=1);i<MAXN;i++)
        fac[i]=1LL*i*fac[i-1]%Mod;
    for(int i=(pw[0]=1);i<MAXN;i++)
        pw[i]=1LL*(n-1)*pw[i-1]%Mod;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&p[i]);
        if(p[i]>0)
        {
            e[i].push_back(p[i]);
            e[p[i]].push_back(i);
        }
    }
    int res=n;
    for(int i=1;i<=n;i++)
        if(!vis[i])
        {
            vector<int> t;
            dfs(i,t);
            int has=0;
            for(auto &u:t)
                has|=(p[u]<0);
            if(has)sz.push_back(t.size());
            else res--;
        }
    res=1LL*res*pw[sz.size()]%Mod;
    int now=0,la=1;
    dp[now][0]=1;
    for(size_t i=0;i<sz.size();i++)
    {
        swap(now,la);
        for(int j=0;j<=i+1;j++)
            dp[now][j]=0;
        for(int j=0;j<=i;j++)
        {
            dp[now][j]=(dp[now][j]+dp[la][j])%Mod;
            dp[now][j+1]=(dp[now][j+1]+1LL*sz[i]*dp[la][j])%Mod;
        }
    }
    for(size_t j=0;j<sz.size();j++)
        res=(res-1LL*pw[sz.size()-1]*(sz[j]-1)%Mod+Mod)%Mod;
    for(size_t j=2;j<=sz.size();j++)
        res=(res-1LL*fac[j-1]*pw[sz.size()-j]%Mod*dp[now][j]%Mod+Mod)%Mod;
    return 0*printf("%d\n",res);
}


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

int main() {
	int n, k;
	while (cin >> n >> k,n,k) {
		int s[100];
		for (int i = 0;i < k;i++) {cin >> s[i];}
		int b[100] = {};
		for (int i = 0;i < n;i++) {
			for (int j = 0;j < k;j++) {
				int a;
				cin >> a;
				b[j] += a;
			}
		}
		int flg = 0;
		for (int i = 0;i < k;i++) {
			if (b[i] > s[i]) {
				flg = 1;
				break;
			}
		}
		if (flg == 0)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
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;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

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

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

    ll n;
    cin >> n ;
    ll a, w, t, r;
    a = w = t = r = 0;
    REP(i,n){
        string s;
        cin >> s;
        if(s=="AC"){
            a++;
        }
        else if(s=="WA"){
            w++;
        }
        else if(s=="TLE"){
            t++;
        }
        else{
            r++;
        }
    }
    cout << "AC" <<" x "<< a <<endl;
    cout << "WA" <<" x "<< w <<endl;
    cout << "TLE" << " x "<< t <<endl;
    cout << "RE" << " x " << r <<endl;


    
    return 0;
}

Measured memory_bytes: 3652
package main

import (
	"fmt"
	"math"
)

func main() {
	var  A,B,N float64
	fmt.Scan(&A,&B,&N)
	var max float64
	var i float64
	if B < N {
		N = B
	}
	max = 0
	for i = N; i>0; i-- {
		value := math.Floor(A*i/B) - A*math.Floor(i/B)
		if value != 0 {
			max = value
			break
		}
		//fmt.Println(value,i)
		if value > max {
			max = value
		}
	}
	fmt.Println(max)
}

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

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n;
    cin >> n;
    i64 e = 0;
    for (i64 i = 0; i < n; i++) {
        i64 a;
        cin >> a;
        if (a % 2 == 0) e++;
    }

    cout << (i64) (pow(3, n) - pow(2, e)) << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=200000 +117;
const int MM=200000 +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n;
struct node{
	int id,v;
	node(int i_=0,int v_=0){
		id=i_;
		v=v_;
	}
};
vector<node> res[NN]={};
vector<int> p[NN]={};
int c[NN]={};
int mm[NN]={};
int cnt(int x,int fa,int c){
	for(int i=0;i<res[x].size();++i){
		if(res[x][i].id==c)return res[x][i].v;
	}
	int ans=1;
	for(int i=0;i<p[x].size();++i){
		int cur=p[x][i];
		if(cur!=fa&&cur<c)ans+=cnt(cur,x,c);
	}
	res[x].push_back(node(c,ans));
	return ans;
}
void dfs(int x,int fa,int mx){
	if(x!=1){
		if(x>mm[fa])c[x]=c[fa]+cnt(x,fa,mx);
		else{
			c[x]=c[fa]+cnt(x,fa,mx)-cnt(x,fa,mm[fa]);
		}
	}
	mm[x]=mx;
	mx=max(mx,x);
	for(int i=0;i<p[x].size();++i){
		int cur=p[x][i];
		if(cur!=fa){
			dfs(cur,x,mx);
		}
	}
}
int main(){
	//open();
	n=read();
	for(int i=1;i<n;++i){
		int x=read(),y=read();
		p[x].push_back(y);
		p[y].push_back(x);
	}
	c[1]=0;
	dfs(1,0,0);
	for(int i=2;i<=n;++i){
		printf("%d ",c[i]);
	}
	putchar('\n');
	close();
	return 0;
}

Measured memory_bytes: 43776
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int a[540][540];
Int n;
Int dp[540][540];
Int minuss[540][540];
Int pluss[540][540];
Int calc(Int i, Int j, Int k){
    Int res = minuss[j][k] + pluss[0][k] + pluss[i][j] - pluss[0][j] - pluss[i][k];
//    cout << i << " " << j << " " << k << ":" << res << endl;
    return res;
}

int main(){
    cin >> n;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            if(i == j)continue;
            cin >> a[i][j];
        }
    }
    for(Int k = 2;k <= n;k++){
        for(Int i = 0;i + k <= n;i++){
            Int j = i + k;
            minuss[i][j] = minuss[i][j-1] + minuss[i+1][j] - minuss[i+1][j-1] + a[i][j-1];
            pluss[i][j] = pluss[i][j-1] + pluss[i+1][j] - pluss[i+1][j-1] + a[j-1][i];
//            cout << i << " " << j << " " << minuss[i][j] << " " << pluss[i][j] << endl;
        }
    }
    for(Int i = 1;i <= n;i++){
        dp[0][i] = minuss[0][i];
        
        //      cout << "dp["<< 0 <<"][" << i <<"]: " << dp[0][i] << endl;
    }

    for(Int i = 1;i < n;i++){
        for(Int j = i+1;j <= n;j++){
            dp[i][j] = LINF;
            for(Int k = 0;k < i;k++){
                dp[i][j] = min(dp[i][j], dp[k][i] + calc(k, i, j));
            }
//            cout << "dp["<< i <<"][" << j <<"]: " << dp[i][j] << endl;
        }
    }
    Int res = LINF;
    for(Int i = 0;i < n;i++){
        res = min(res, dp[i][n]);
    }
    cout << res << endl;
    
    return 0;
}

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

int main(){
  int H,W;
  bool f=true;
  cin>>H>>W;
  char c[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++) cin>>c[i][j];
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(c[i][j]=='#'){
        int cnt=0;
        for(int dx=-1;dx<=1;dx++){
          for(int dy=-1;dy<=1;dy++){
            if(fabs(dx)+fabs(dy)==2) continue;
            if(c[i+dx][j+dy]=='#') cnt++;
          }
        }
        if(cnt<2) f=false;
      }
    }
  }
  if(f) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.util.function.*;
 
public class Main{
	
	int N;
	int M;
	public void solve(){
		N = nextInt();
		M = nextInt();
		boolean[] flgs = new boolean[N];
		int[] ball = new int[N];
		Arrays.fill(ball, 1);
		flgs[0] = true;
		
		for(int i = 0; i < M; i++){
			int x = nextInt() - 1;
			int y = nextInt() - 1;
			flgs[y] |= flgs[x];
			ball[y] += 1;
			ball[x] -= 1;
			if(ball[x] == 0){
				flgs[x] = false;
			}
		}
		int cnt = 0;
		for(int i = 0; i < N; i++){
			if(flgs[i]) cnt++;
		}
		out.println(cnt);
	}
	
	private static PrintWriter out;
	public static void main(String[] args){
		out = new PrintWriter(System.out);
		new Main().solve();
		out.flush();
	}
	
	
	
	public static int nextInt(){
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;
	}
	
	public static long nextLong(){
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}
	public static String next(){
		int c;
		while(!isAlNum(c = read())){}
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNum(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}
	
	
	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;
	private static int read(){
		if(bufferLength < 0) throw new RuntimeException();
		if(bufferIndex >= bufferLength){
			try{
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			}catch(IOException e){
				throw new RuntimeException(e);
			}
			if(bufferLength <= 0) return (bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}
	
	private static boolean isAlNum(int c){
		return '!' <= c && c <= '~';
	}
}

Measured memory_bytes: 18824
#include <iostream>
#include<algorithm>
using namespace std;
int main(void){
    
    string S;
    string T;
    int x = 0;
    
    cin >> S;
    cin >> T;
    
    for(int i = 0; i < 3; i++){
        if(S[i] == T[i]){
            x++;
        }
    }
    
    cout << x;
    
    return 0;
}

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

int main(){
while(1){
int n;
cin >> n;
if(n == 0)break;
int a=0,b=0,c=0;
for(int i=0;i<n;i++){
int x,y;
cin >> x >> y;
if(x>y)a+=x+y;
else if(x<y)b+=x+y;
else c+=x;
}
cout << a+c << " " << b+c << endl;
}
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {

    int N, A, B;

    cin >> N >> A >> B;


    string S;
    cin >> S;
    int C = A + B;
    int cnt_a_b = 0;
    int cnt_b = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'c') cout << "No\n";
        else if (cnt_a_b < C) {
            if (S[i] == 'b') {
                if (cnt_b < B) {
                    cout << "Yes\n";
                    cnt_b++;
                    cnt_a_b++;
                }
                else 
                    cout << "No\n";
            }
            else {
                cnt_a_b++;
                cout << "Yes\n";
            }
        }
        else cout << "No\n";
    }


}


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

map<int, int> count;
int getCount(int n) {
  int ret = 0;
  for (auto& i : count) {
    if (i.second >= n) ++ret;
  }
  return ret;
}

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;

  rep(i, N) {
    int n = i + 1;
    for (int64_t j = 2; j * j <= n; ++j) {
      while (n % j == 0) {
        count[j]++;
        n /= j;
      }
    }
    if (n != 1) count[n]++;
  }

  int answer = 0;
  answer += getCount(75 - 1);
  answer += getCount(25 - 1) * (getCount(3 - 1) - 1);
  answer += getCount(15 - 1) * (getCount(5 - 1) - 1);
  answer += getCount(5 - 1) * (getCount(5 - 1) - 1) / 2 * (getCount(3 - 1) - 2);
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3600
#include<atcoder/all>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long Int;

int main(){
    Int t, n, m, a, b;
    cin >> t;
    while(t--){
        cin >> n >> m >> a >> b;
        cout << atcoder::floor_sum(n, m, a, b) << endl;
    }
    return 0;
}

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

int main(){
    int A = 0;
    int B = 0;
    int T = 0;
    
    cin>>A>>B>>T;
    
    int res = 0;
    
    for(int i = 1;i < T + 0.5;i++){
        
        if(i%A == 0){
            res += B;
        }
        
    }
    
    cout<<res;
    
    
    
    return 0;
}

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    int count=0;
    int answer=0;
    rp(i,n){
        if(s.at(i)=='A'){
            count=1;
            continue;
        }
        if(count==1&&s.at(i)=='B'){
            count=2;
            continue;
        }
        if(count==2&&s.at(i)=='C'){
            count=0;
            answer++;
            continue;
        }
        else count=0;
    }
    cout << answer << endl;
    return 0;
}

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

int M=1e9+7;

int solve(vector<vector<int>>& grid){
	int n=grid.size();
	vector<int> dp(1<<n);
	dp[0]=1;
	for (int mask=0;mask<(1<<n)-1;mask++){
		int a = __builtin_popcount(mask);
		for (int b=0;b<n;b++){
			if (grid[a][b] and !(mask & (1<<b))){
				int m2=mask^(1<<b);
				dp[m2]=(dp[m2]%M+dp[mask]%M)%M;
			}
		}
	}
	return dp[(1<<n)-1];
}

signed main() {

	int N;
	cin>>N;
	vector<vector<int>> grid(N,vector<int>(N));
	for (int i=0;i<N;i++){
		for (int j=0;j<N;j++){
			cin>>grid[i][j];
		}
	}
	cout<<solve(grid)<<endl;
    return 0; 
}


Measured memory_bytes: 11420
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if (a < b && b < c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    };
}


Measured memory_bytes: 3092
#include <cstdio>
#include <cmath>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, x, n) for (int i = x; i < n; ++i)

typedef std::vector<int> v;
typedef std::vector<std::vector<int>> vv;
typedef unsigned long long ull;

int n, m, q;
v a, b, c, d;
v aa;
ull ans = 0;
void f(int x)
{
    if (aa.size() == n)
    {
        ull total = 0;
        REP(i, q)
        {
            if (aa[b[i] - 1] - aa[a[i] - 1] == c[i])
                total += d[i];
        }
        if (ans < total)
        {
            ans = total;
        }
        return;
    }
    FOR(i, x, m + 1)
    {
        aa.push_back(i);
        f(i);
        aa.pop_back();
    }
}

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

    a.resize(q), b.resize(q), c.resize(q), d.resize(q);
    REP(i, q)
    {
        scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
    }

    f(1);

    printf("%llu", ans);
}

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

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

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

  int a[N], b[N];
  int r[N];
  rep(i, N) {
    int p; cin >> p;
    r[p-1] = i + 1;
  }
  rep(i, N) {
    if (i) cout << " ";
    cout << 30000 * (i+1);
  }
  cout << "\n";
  rep(i, N) {
    if (i) cout << " ";
    cout << 30000 * (N-(i+1)) + r[i];
  }
  cout << "\n";

  return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include <algorithm>
using namespace std;
int a,n;
string b[105];
int main()
{
    //freopen("bfr.in","r",stdin);
    //freopen("bfr.out","w",stdout);
    cin>>a>>n;
    for(int s=0;s<a;s++)
    {
        cin>>b[s];
    }
    sort(b,b+a);
    for(int s=0;s<a;s++)
    cout<<b[s];
    cout<<endl;
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}

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

int main(){
  std::vector<int> A(3);
  std::cin >> A[0] >> A[1] >> A[2];
  std::sort(A.begin(), A.end());
  int ans = 0;
  if((A[1] - A[0]) % 2 == 0) ans += (A[1] - A[0])/2;
  else ans += (A[1] - A[0])/2 + 2;
  ans += A[2] - A[1];
  std::cout << ans << std::endl;
}

Measured memory_bytes: 256
# 問題:文字の先頭が'i'で末尾が'j', 且つ文字の先頭が'j'で末尾が'i'のペアはいくつ？
# 'n'以下の全ての数について 先頭を'i', 末尾が'j'としたDBを作成

n = int(input())
# cnt[i][j] := 先頭が'i', 末尾が'j'の数
cnt = [[0] * 10 for _ in range(10)]

for i in range(1, n + 1):
    cnt[int(str(i)[0])][int(str(i)[-1])] += 1

# 先頭が'i'で末尾が'j'の総数 [掛ける] 先頭が'j'で末尾が'i'の総数の総和が'ans'
ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j] * cnt[j][i]

print(ans)

Measured memory_bytes: 9108
mod = 10**9+7
n,a,b = map(int,input().split())
base = pow(2,n,mod)-1
def comb(n,k):
  comb = 1
  for i in range(n-k+1,n+1):
    comb *= i
    comb %= mod
  for i in range(1, k+1):
    comb *= pow(i,mod-2,mod)
    comb %= mod
  return comb
print((base-comb(n,a)-comb(n,b))%mod)

Measured memory_bytes: 9156
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
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)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll dp[222][111][3000];


vector<ll> inv,fact,invfact;
void mod_build(int n=101010){
    fact.resize(n+1);
    inv.resize(n+1);
    invfact.resize(n+1);
    fact[0]=inv[0]=invfact[0]=1;
    inv[1]=1;
    rep(i,n){
        fact[i+1]=fact[i]*(i+1)%mod;
        if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
        invfact[i+1]=invfact[i]*inv[i+1]%mod;
    }
}
ll perm(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return fact[n]*invfact[n-k]%mod;
}
ll comb(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod;
}
ll powmod(ll n,ll k){
    k%=mod-1;
    if(k<0)k+=mod-1;
    ll ret=1;
    while(k){
        if(k&1)ret=ret*n%mod;
        n=n*n%mod;
        k>>=1;
    }
    return ret;
}
int main(){
    mod_build(55);
    int n,k;
    cin>>n>>k;
    if(k%2){
        cout<<0<<endl;
        return 0;
    }
    int x = n*(n-1)/2+k/2;
    dp[0][0][0]=1;
    rep(i,n){
        int cur = n-i-1;
        rep(j,n+1)rep(k,2000){
            if(i+j<=n)(dp[i+1][j+1][k+2*cur]+=(n-i-j)*(n-i-j-1)*dp[i][j][k])%=mod;
            if(i+j<=n)(dp[i+1][j][k+cur]+=(n-i-j)*(2*j+1)*dp[i][j][k])%=mod;
            if(j>=1)(dp[i+1][j-1][k]+=j*j*dp[i][j][k])%=mod;
        }
    }
    cout<<dp[n][0][x]*invfact[n]%mod<<endl;
    return 0;
}

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

int main(){
    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1LL << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n + 1), b(n);
	rep(i, n + 1) cin >> a[i];
	rep(i, n) cin >> b[i];
	ll ans = 0;
	rep(i, n) {
		if (a[i] <= b[i]) {
			ans += a[i];
			ans += min(a[i + 1], b[i] - a[i]);
			a[i + 1] = max(0, a[i + 1] - (b[i] - a[i]));
		}
		else {
			ans += b[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define RFOR(i,s,e) for(int (i) = (s);(i) >= (e);(i)--)
#define rep(i,n) FOR(i,0,n-1)
#define MOD 1000000007

map<int,int> f;
int s(int n){
	if(f[n] != 0) return f[n];
	else return f[n] = (s(n/2) + s((n-1)/2) + s((n-2)/2))%MOD;
}
	
signed main(){
	int n;cin >> n;
	f[0] = 1;
	f[1] = 2;
	cout << s(n);
}

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

using namespace std;
typedef long long ll;

int main(){
  ll N, K;
  cin >> N >> K;
  
  vector<ll> A(N);
  for(ll i=0; i<N; i++){
    ll temp;
    cin >> temp;
    A[i] = temp-1;
  }

  vector<ll> teleN(N, -1);
  ll loopS = 0, loopN = N;
  ll s = 0;
  for(ll i=0; i<N; i++){
    if(i != 1 && teleN[s] != -1){
      loopS = s;
      loopN = i - teleN[s];
      break;
    } 
    teleN[s] = i;
    s = A[s];
  }

  ll cur = (K < teleN[loopS]) ? 0 : loopS;
  ll num   = (K < teleN[loopS]) ? K : ((K - teleN[loopS]) % loopN);
  for(ll i=0; i<num; i++){
    cur = A[cur];
  }
  
  cout << cur+1 << endl;
  return 0;
}

Measured memory_bytes: 6420
#include <iostream>
#include <queue>
#include <string>

using namespace std;

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

    queue<pair<string, int>> que;

    for (int i = 0; i < N; ++i) {
        pair<string, int> p;
        cin >> p.first >> p.second;
        que.push(p);
    }

    int now = 0;
    while (!que.empty()) {
        auto p = que.front();
        que.pop();

        if (p.second <= Q) {
            now += p.second;
            cout << p.first << " " << now << endl;
        } else {
            now += Q;
            p.second -= Q;
            que.push(p);
        }
    }
    return 0;
}



Measured memory_bytes: 6332
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
//     for(int i=0; i<N;i++){
//     }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    set<int> s;
    int N; int d;
    cin>>N;
    for(int i=0; i<N;i++){ cin>>d; s.insert(d);}

    cout<<s.size()<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int n;
int a[10000];
int b[10000];
int mx=0;
int main(){
bool ok=true;
int sm=0;
cin>>n;
int ct=n;
for (int i=1;i<=n;){
  cin>>a[i];
  i++;
  }
for (int i=1;i<=n;){
  cin>>b[i];
  i++;
  }
for (int i=1;i<=n;i++){
  for (int j=1;j<=i;j++) sm+=a[j];
  for (int j=i;j<=n;j++) sm+=b[j];
  mx=max(mx,sm);
  sm=0;
  }
cout<<mx<<endl;
return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

double rad2deg(double rad) { return (((rad)/2/M_PI)*360); }
int main() {
  double a, b, x; cin >> a >> b >> x;
  double rad;
  if (a * a * b / 2.0 <= x) {
    rad = atan2(2 * (a * a * b - x), a * a * a);
  } else {
    rad = M_PI/2 - atan2(2*x, a*b*b);
  }
  printf("%.9f\n", rad2deg(rad));
}


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

const int N=3e5+1e3+7;

int n;

char s[N];

int a[N],b[N];

int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
		a[i]=a[i-1]+(s[i]=='W');
	for(int i=n;i>=1;i--)
		b[i]=b[i+1]+(s[i]=='E');
	int ans=n;
	for(int i=1;i<=n;i++)
		ans=min(ans,a[i-1]+b[i+1]);
	printf("%d",ans);
} 

Measured memory_bytes: 2944
import bisect

n=int(input())
arr=list(map(int,input().split()))
l=int(input())
pos=0
dbl=[[0]*(n+1)]
for i in range(n):
  dbl[0][i+1]=bisect.bisect_right(arr,arr[i]+l)
for _ in range(20):
  tmp=[0]*(n+1)
  for i in range(n+1):
    tmp[i]=dbl[-1][dbl[-1][i]]
  dbl.append(tmp)
q=int(input())
for _ in range(q):
  a,b=map(int,input().split())
  if a>b:
    a,b=b,a
  l=0
  r=b-a+1
  while r-l!=1:
    mid=(l+r)//2
    tmp=a
    for i in range(20):
      if mid&(1<<i):
        tmp=dbl[i][tmp]
    if tmp>=b:
      r=mid
    else:
      l=mid
  print(r)

Measured memory_bytes: 98952
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

a = [INT() for _ in range(N)]
tmp = [0]*N
tmp2 = a[0]-1
cnt = 0
while 1:
	if tmp[tmp2] == 1:
		print("-1")
		break
	elif tmp2 == 1:
		print(cnt+1)
		break
	tmp[tmp2] = 1
	tmp2 = a[tmp2] -1
	cnt += 1

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

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

    ll w = 0;
    vector<ll> mf(N+1);
    for ( int i = N; i >= 1; i-- ) {
        w += A[i];
        mf[i-1] = w;
    }

    ll v = 1, c = 0;
    for ( int i = 0; i < N+1; i++ ) {
        if ( A[i] > v ) return -1;
        c += A[i];
        v -= A[i];
        if ( v > mf[i] ) v = mf[i];
        c += v;
        v *= 2;
    }

    return c;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
#define Maxn 507
#define inf 100007
using namespace std;
int n,p;
char s[Maxn];
int f[Maxn][30];
int main()
{
    scanf("%s",s+1);
    scanf("%d",&p);
    n=strlen(s+1);
    for (int i=n+1;i<=3*n;i++)
        s[i]=s[i-n];
    for (int i=1;i<=3*n;i++)
        for (int j=1;j<=26;j++)
            f[i][j]=inf;
    for (int i=1;i<=26;i++)
        f[1][i]=1;
    f[1][s[1]-'a'+1]=0;
    for (int i=2;i<=3*n;i++)
        for (int k=1;k<=26;k++)
        {
            int tmp=0;
            if (s[i]-'a'+1==k) tmp=0; else tmp=1;
            for (int t=1;t<=26;t++)
                if (k!=t) f[i][k]=min(f[i][k],f[i-1][t]+tmp);
        }
    int ans1=inf,ans2=inf,ans3=inf;
    for (int i=1;i<=26;i++)
    {
        ans1=min(ans1,f[n][i]);
        ans2=min(ans2,f[2*n][i]);
        ans3=min(ans3,f[3*n][i]);
    }
    long long ans=1LL*((p-1)/2)*(ans3-ans1);
    ans+=ans1;
    if (p%2==0) ans+=ans2-ans1;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3828