akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <list>
#include <cstdlib>

using namespace std;

#define mod (1e9 + 7)
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()

typedef long long ll;

void solve1(){
   int h, w; cin >> h >> w;
   vector<vector<char>> a(h, vector<char>(w));
   rep(i, h) {
      rep(j, w) {
         cin >> a[i][j];
      }
   }

   set<int> allr;
   set<int> allc;

   rep(i, h) {
      bool f = true;
      rep(j, w) {
         if(a[i][j] != '.') {
            f = false;
         }
      }
      if(f) {
         allr.insert(i);
      }
   }

   rep(i, w) {
      bool f = true;
      rep(j, h) {
         if(a[j][i] != '.') {
            f = false;
         }
      }

      if(f) {
         allc.insert(i);
      }
   }

  /* for(auto itr = allr.begin(); itr != allr.end(); itr++) {
      cout << *itr << endl;
   }

   for (auto itr = allc.begin(); itr != allc.end(); itr++)
   {
      cout << *itr << endl;
   }
   */

  rep(i, h) {
      if(allr.find(i) == allr.end()) {
         rep(j, w) {
            if (allc.find(j) == allc.end()) {
               cout << a[i][j];
            }
         }
         cout << endl;
      }
   }

}

int main()
{
   solve1();
}

Measured memory_bytes: 3636
a, b, c = map(int, input().split())
k = int(input())
d = 0
while a >= b:
    if k == 0:
        d = 1
        break;
    b *= 2
    k -= 1
while b >= c:
    if k == 0:
        d = 1
        break;
    c *= 2
    k -= 1
if d == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9176
#include<cstdio>
#include<cctype>
#include<algorithm>

using namespace std;

inline char nc(){ return getchar();static char buf[100000] , *p1,*p2; return p1 == p2 && (p1 = (p2 = buf) + fread(buf,1,100000,stdin),p1 == p2) ? EOF : *p1++;}
template<class T>inline void rd(T & x){ x = 0;int f = 1;char ch = nc(); for(;!isdigit(ch);ch = nc()) if(ch == '-') f = -1; for(;isdigit(ch);ch = nc()) x = x * 10 - 48 + ch; x *= f;}

typedef long long ll;

const int maxn = 1e5 + 10;
ll L[maxn] , R[maxn] , ans,n;

bool cmp(ll a,ll b) { return a > b;}
void calc(ll L[],ll R[]){
	ll tmp = 0;
	for(int i = 1;i <= n * 2;i++) {
		if(i % 2 == 1) tmp += L[i / 2] ; 
		else tmp += R[i / 2] ;
		ans = max(ans,tmp);
	}
}
int main(){
	rd(n);
	for(int i = 1;i <= n;i++){
		rd(L[i]); rd(R[i]); R[i] = -R[i];
	}
	sort(L + 1,L + n + 1,cmp); sort(R + 1,R + n + 1,cmp);
	calc(L,R) ; calc(R,L);
	printf("%lld",ans * 2);
	return 0;
}

Measured memory_bytes: 1664
N=int(input())
inf=float("inf")
A=[list(map(int,input().split())) for _ in range(N)]

def calc():
    ans=0
    for i in range(N):
        for j in range(N):
            used=True
            for k in range(N):
                if i==k or k==j:continue
                if A[i][j]>A[i][k]+A[k][j]:
                    return -1
                elif A[i][j]==A[i][k]+A[k][j]:
                    used=False
            if used:
                ans+=A[i][j]
    return ans//2
                
print(calc())

Measured memory_bytes: 44376
N=int(input())

ACcount=0
WAcount=0
TLEcount=0
REcount=0

for i in range(N):
    s = input()
    if s == "AC":
        ACcount = ACcount + 1
    elif s == "WA":
        WAcount = WAcount + 1
    elif s == "TLE":
        TLEcount = TLEcount + 1
    elif s == "RE":
        REcount = REcount + 1

print("AC x " + str(ACcount))
print("WA x " + str(WAcount))
print("TLE x " + str(TLEcount))
print("RE x " + str(REcount))

Measured memory_bytes: 9204
#include <iostream>
using namespace std;
int main(){
  int a,b,c,ans=0;
  cin>>a>>b>>c;
  if(a!=b)ans++;
  if(b!=c)ans++;
  if(a!=c)ans++;
  if(ans==0)ans++;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    v = list(map(int, input().split(" ")))
    while len(v) > 1:
        v.sort(reverse=True)
        a = v[-1]
        b = v[-2]
        v = v[:-2]
        v.append((a + b) / 2)
    print(v[0])


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
<?php
$A=fgets(STDIN);
$B=fgets(STDIN);
$Aarray=str_split($A);
$Barray=str_split($B);
$Acount=count($Aarray);
$Bcount=count($Barray);
if($Acount>$Bcount){
  echo "GREATER";
}elseif($Acount<$Bcount){
  echo "LESS";
}else{
  if($A>$B){
    echo "GREATER";
  }elseif($A<$B) {
    echo "LESS";
  }else {
    echo "EQUAL";
  }
}

 ?>


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

using ll = long long;
using P = pair<int, int>;
using PP = pair<int, P>;
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define rep0(i,n) for (int i=0; i<(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; }
#ifdef _DEBUG
string _format(string args) { string r = "", t; istringstream s(args); while (getline(s, t, ',')) r += t+":%d "; return r + "\n"; }
#define debug(...) do{printf(_format(#__VA_ARGS__).c_str(), __VA_ARGS__);}while(0)
#define FAST_IOSTREAM() do{}while(0);
#else
#define debug(...) do{}while(0)
#define FAST_IOSTREAM() do{std::ios::sync_with_stdio(false); std::cin.tie(nullptr);}while(0)
#endif

// GCD, LCM
// https://youtu.be/8lm8o8L9Bmw?t=2285
// https://youtu.be/XI8exXVxZ-Q?t=3595
// https://youtu.be/F2p_e6iKxnk?t=843
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;}

int main() {
    FAST_IOSTREAM();

    int k;
    cin >> k;

    ll ans = 0;
    rep1(a,k) {
        rep1(b,k) {
            ll g = gcd(a,b);
            rep1(c,k) {
                ans += gcd(c,g);
            }
        }
    } 
    cout << ans << endl;
}


Measured memory_bytes: 3656
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
T meguru_search(T ok, T ng, function<bool(T)> check){
    while(max(ok, ng) - min(ok, ng) > T(1)){
        T mid = (ok + ng) / T(2);
        if(check(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    return ok;
}

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

    int n;
    cin >> n;

    vector<int> cnt(n);
    rep(i, n){
        int a;
        cin >> a;
        ++cnt[--a];
    }
    SORT(cnt);

    vector<int> sum(n + 1);
    reps(i, n){
        sum[i] = sum[i - 1] + cnt[i - 1];
    }

    vector<int> v(n + 1);
    rep(i, n + 1){
        auto f = [&](int l){
            int k = lower_bound(cnt.begin(), cnt.end(), i) - cnt.begin();
            return sum[k] + (lint)(n - k) * i >= (lint)l * i;
        };
        v[i] = meguru_search<int>(0, n + 1, f);
    }

    reps(i, n){
        cout << meguru_search<int>(0, n + 1, [&](int k){ return v[k] >= i; }) << endl;
    }

    cout << flush;

    return 0;
}

Measured memory_bytes: 4352
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, M = map(int, input().split())
edges = [set() for _ in range(N)]
ins = [0]*N
for _ in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    ins[b] += 1
    edges[a].add(b)

dp = [-1]*N


def dfs(s):
    if dp[s] != -1:
        return dp[s]
    mx = 0
    if edges[s]:
        mx = max([dfs(dest)+1 for dest in edges[s]])
    dp[s] = mx
    return mx


ans = -1
for i in range(N):
    ans = max(ans, dfs(i))

print(ans)


Measured memory_bytes: 125028
using System;
using System.Collections.Generic;
using System.Linq;

class Progaram
{
    static Char[,] mass = new Char[8, 8];
    static int h = 0; 
    static int w = 0;

    static void Main(string[] args)
    {
        var l = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        h = l[0];  w = l[1];
        var go = 0;
        for (var i = 0; h > i; i++)
        {
            var line = Console.ReadLine().ToCharArray();
            for (var j = 0; w > j; j++)
            {
                if (line[j] == '#') go++;
                mass[i, j] = line[j];
            }
        }
        if (go == h + w - 1) Console.WriteLine("Possible");
        else Console.WriteLine("Impossible");
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

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

Measured memory_bytes: 256
N = int(input())
A = []
ans = 1
P = 1
for i in range(N):
    A.append(int(input()))

for j in range(N):
    if A[P-1] == 2 :
        print(ans)
        break
    else:
        P = A[P-1]
        ans += 1
if ans == N+1 : print(-1)


Measured memory_bytes: 7084
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Harlequin | diff Harlequin.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Harlequin.cpp && ./a.out

/*
 
 6/8/2019
 
 16:07-
 
 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N;

void solve() {
  bool alle=true;
  REP(i,N) alle&=(A[i]%2LL)==0LL;
  string res=(alle?"second":"first");
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N) cin>>A[i];
  solve();
  
  return 0;
}


Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;

class ProgramC
    {
        static void Main(string[] args)
        {
            
            //入力
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]);
            int s = int.Parse(input[2]);
            
            for(int i = 0;i < n;i++)
            {
                if(s == 1000000000)
                {
                    if(i < k)
                        Console.Write(s);
                    else
                        Console.Write('1');
                }
                else
                {
                    if(i < k)
                        Console.Write(s);
                    else
                        Console.Write(s+1);
                }
                
                Console.Write(' ');
                
            
            }
          
        } 
    }

Measured memory_bytes: 16336
fun main(args: Array<String>) {
    while (true) {
        val (H, W) = readLine()!!.split(" ").map(String::toInt)
        if (H == 0 && W == 0) break
        println("#".repeat(W))
        print("#${".".repeat(W - 2)}#\n".repeat(H - 2))
        println("#".repeat(W))
        println()
    }
}


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

int main() {
  int N;
  cin >> N;
  int ans = N % 1000;
  if (ans != 0) ans = 1000 - ans;
  cout << ans << endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>

#define INF 10e10
#define REP(i,n) for(int i=0; i<n; i++)
#define REP_R(i,n,m) for(int i=m; i<n; i++)
#define MAX 100

using namespace std;

typedef long long ll;

int N;
int a[MAX + 1];
bool width[8];

int main() {
  scanf("%d", &N);
  REP(i,N) scanf("%d", &a[i]);

  int count = 0;
  int over = 0;

  REP(i,8) width[i] = false;

  for (int i = 0; i < N; i++) {
    int target = a[i];
    if (target < 400) {
      width[0] = true;
    } else if (target < 800) {
      width[1] = true;
    } else if (target < 1200) {
      width[2] = true;
    } else if (target < 1600) {
      width[3] = true;
    } else if (target < 2000) {
      width[4] = true;
    } else if (target < 2400) {
      width[5] = true;
    } else if (target < 2800) {
      width[6] = true;
    } else if (target < 3200) {
      width[7] = true;
    } else {
      over++;
    }
  }

  REP(i,8) {
    if (width[i]) count++;
  }

  int min = count;
  int max = count + over;
  if (min == 0) min = 1;
  cout << min << " " << max << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

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

Measured memory_bytes: 256
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

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

    # N = int(input())
    # H = list(map(int, input().split()))
    # a = 0
    # res = 0
    # while a < N-1:
    #     c = 0
    #     for i in range(a, N-1):
    #         if H[i]-H[i+1] >= 0:
    #             c += 1
    #         else:
    #             break
    #     a += c + 1
    #     res = max(res, c)
    # print(res)

    a,b = map(int, input().split())
    res = 0
    c = 1
    while c < b:
        c += a - 1
        res += 1
    print(res)



if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
#define INF 2000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
//input power
string s;
int main(){
	// 出力用の文字列
	string ans;
	cin >> s ;
	rep(i,s.size()){
		if(i%2==0){
			ans+=s.at(i);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <stdio.h>
                                                                                                
  
int main(void){
                                                                                                
   
    int i;

    char c;
   
    char s[6] = {"aiueo"};
   
      
    scanf("%c", &c);
   
    
    for( i = 0 ; i < 5 ; i = i + 1 ){

         if( s[i] == c ){

             printf("vowel\n");

             return 0;

             }

         }

    printf("consonant\n");


    return 0;
                                                          
}

Measured memory_bytes: 128
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	string s,t;
	int alf[26]={0};
	cin>>s>>t;
	int time[s.size()]={0};
	for(int i=0;i<s.size();i++){
		alf[s[i]-97]++;
	}
	for(int i=0;i<26;i++){
		time[alf[i]]++;
	}
	memset(alf,0,sizeof(alf));
	for(int i=0;i<t.size();i++){
		alf[t[i]-97]++;
	}
	for(int i=0;i<26;i++){
		if(time[alf[i]]==0){
			cout<<"No";
			return 0;
		}
		time[alf[i]]--;
	}
	for(int i=0;i<s.size();i++){
		if(time[i]!=0){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 1544
import sys
input = sys.stdin.readline
from itertools import combinations
N = int(input())
L = list(map(int,input().split()))

ans = 0
for a,b,c in combinations(L,3):
    if c<a+b and a<b+c and b<a+c:
        if a != b and b != c and c != a:
            ans += 1

print(ans)



Measured memory_bytes: 67808
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
int p=pow(10,9)+7;

int main(){
    int N;cin>>N;
    int a[30][30];
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++)
            cin>>a[i][j];
    }
    vec dp(3000000,0);
    dp[0]=1;
    for(int i=0;i<(1<<N)-1;i++){
        int M=0;
        for(int j=0;j<N;j++){
            if(i & (1<<j))M++;
        }
        for(int k=0;k<N;k++){
            if(a[M][k]==1 && !(i & (1<<k)))
                dp[i+(1<<k)]=(dp[i]+dp[i+(1<<k)])%p;
        }  
    }
    cout<<dp[(1<<N)-1]<<endl;
    return 0;
}

Measured memory_bytes: 12032
#include <stdio.h>

void CS(int*,int*,int);

int main(){
  int i,n;

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

  CS(A,B,n);

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

  return 0;
}

void CS(int *A, int *B,int n){
  int i,j,C[10001];

  for(i=0;i<10001;i++){
    C[i]=0;
  }

  for(j=0;j<n;j++){
    C[A[j]]++;
  }

  for(i=1;i<10001;i++){
    C[i]+=C[i-1];
  }

  for(j=n-1;j>=0;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
}


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

int main() {
	int x, y, size;
	int sol[10][10];
	char c;
	for(int i = 0; i < 10; i++) {
		for(int j = 0; j < 10; j++) {
			sol[i][j] = 0;
		}
	}
	while(cin >> x >> c >> y >> c >> size) {
		sol[x][y]++;
		if(x - 1 >= 0) sol[x-1][y]++;
		if(y - 1 >= 0) sol[x][y-1]++;
		if(x + 1 < 10) sol[x+1][y]++;
		if(y + 1 < 10) sol[x][y+1]++;
		if(size >= 2) {			
			if(x-1 >= 0 && y-1 >= 0) sol[x-1][y-1]++;
			if(x+1 < 10 && y-1 >= 0) sol[x+1][y-1]++;
			if(x-1 >= 0 && y+1 < 10) sol[x-1][y+1]++;
			if(x+1 < 10 && y+1 < 10) sol[x+1][y+1]++;
		}
		if(size == 3) {
			if(y - 2 >= 0) sol[x][y-2]++;
			if(y + 2 < 10) sol[x][y+2]++;
			if(x - 2 >= 0) sol[x-2][y]++;
			if(x + 2 < 10) sol[x+2][y]++; 
		}
		/*
		for(int i = 0; i < 10; i++) {
			for(int j = 0; j < 10; j++) {
				cout << sol[i][j] << " " ;
			}
			cout << endl;
		}
		*/
	}
	int count = 0;
	int max = 0;
	for(int i = 0; i < 10; i++) {
		for(int j = 0; j < 10; j++) {
			if(sol[i][j] == 0) count++;
			if(sol[i][j] > max) max = sol[i][j];
		}
	}
	cout << count << endl;
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <string>
#include <sstream>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define clr(a) memset(a, 0, sizeof(a))
#define set(a) memset(a, -1, sizeof(a))
#define pb push_back
#define sz(a) ((ll)a.size())
#define all(a) a.begin(), a.end()
#define mp make_pair
#define rep(i, a, y) for (ll i = a; i <= y; i++)
#define rep2(i, b) for (ll i = 0; i < b; i++)
#define repl(i, a, b) for (ll i = a; i <= b; i++)
#define ppi pair<int, int>
#define scl(x) scanf("%d", &x)
#define pcl(x) printf("%d", x)
#define FastRead                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0)
/*
 
     ██╗██╗   ██╗██╗  ██╗ █████╗ ███╗   ██╗
     ██║██║   ██║██║  ██║██╔══██╗████╗  ██║
     ██║██║   ██║███████║███████║██╔██╗ ██║
██   ██║██║   ██║██╔══██║██╔══██║██║╚██╗██║
╚█████╔╝╚██████╔╝██║  ██║██║  ██║██║ ╚████║
 ╚════╝  ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝
 
*/
map<string,int> p;
ll lcm(ll a ,ll b)
{
    return (a*b)/__gcd(a,b);
}
int main()
{
    FastRead;
    ll n,m;
    cin>>n>>m;
    cout<<lcm(n,m)<<endl;
    return 0;
}

Measured memory_bytes: 3580
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxx=1406;

int a[maxx][maxx],c[maxx][maxx];
int h,w,ans;

int main() {
	std::ios::sync_with_stdio(false);
	cin>>h>>w;
	for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
			cin>>a[i][j];
			if(a[i][j]) c[i][j]=0;
			else c[i][j]=1;
			ans=max(ans,c[i][j]);
		}
	}
	for(int i=2;i<=h;i++){
		for(int j=2;j<=w;j++){
			if(a[i][j]==0) {
				c[i][j]=min(min(c[i-1][j],c[i][j-1]),c[i-1][j-1])+1;
				ans=max(ans,c[i][j]);
			}
		}
	}
//	for(int i=1;i<=h;i++){
//				for(int j=1;j<=w;j++){
//				cout<<c[i][j]<<"  ";
//			}cout<<endl;
//		}
	cout<<ans*ans<<endl;
	return 0;
}


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

a_list = list(map(int, input().split()))
a_list.sort()
a_max = a_list[n - 1]
temp_max = [1, 0]
bunbo = 1
bunshi = 1
center = int((a_max + 1) / 2)
a_set = set(a_list)
diff_min = a_max
ans = 0
for a in a_set:
    diff = abs(a-center)
    if diff_min > diff:
        diff_min = diff
        ans = a

print(a_max, ans)


Measured memory_bytes: 22108
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

const int INF = 1e8;

signed main(){
	int h, w;
	cin >> h >> w;
	string s[51];
	rep(i, 0, h) {
		cin >> s[i];
	}
	int dp[51][51];
	rep(i, 0, h) {
		rep(j, 0, w) {
			dp[i][j] = INF;
		}
	}
	dp[0][0] = 0;
	rep(i, 0, h) {
		rep(j, 0, w) {
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (int)(s[i + 1][j] - '0'));
			dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + (int)(s[i][j + 1] - '0'));
		}
	}
	cout << dp[h - 1][w - 1] << endl;
}

Measured memory_bytes: 1224
#include <stdio.h>
#include <string.h>
#include <algorithm>

char W[101];
int len, cnt=1, flag, i, j=1;

int main()
{
	scanf("%s", W);
	len = strlen(W);
	
	std::sort(W, W+len);
	
	while(i<len)
	{
		while(W[i]==W[j])
		{
			cnt++;
			j++;
		}
		
		if(cnt%2)
		{
			flag = 1;
			break;
		}
		cnt = 1;
		
		i = j;
		j = i+1;
	}
	
	if(flag) printf("No\n");
	else printf("Yes\n");
	
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a < b) {
            int tmp = a;
            a = b;
            b = tmp;
        }
        System.out.println(GCV(a, b));
    }

    public static int GCV(int a, int b) {
        if (b == 0) {
            return a;
        }
        return GCV(b, a%b);
    }
}



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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vi vector<ll>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define el printf("\n")
#define pb push_back
#define f first
#define s second
#define arrondi(a) (long long)floor(a+0.5);
#define NIL -1
ll N=500005;
ll MAX=9223372036854775807;
ll MOD=1000000007;
long double PI =4*atan(1);

int main()
{
	IOS;
    cout.precision(30);
    int n; cin >> n; vector<ll> B(n-1,0);
    for (int i=0;i<n-1;i++)
    {
        cin >> B[i];
    }
    ll ans=0;
    //if (n==2) return cout << 2*B[0] ,0;
    ans=B[0];
    for (int i=0;i<n-2;i++)
    {
        ans+=min(B[i],B[i+1]);
    }
    ans+=B[n-2];
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
<?php
$min = 0;

for ($i = 0; $i < 5; $i++) {
  $times[] = nextInt();
}
$a = array_map(function ($time) {
  return ceil($time / 10) * 10;
}, $times);
$b = array_sum($a);

$c = array_map(function ($time) {
  return $time % 10;
}, $times);
$d = array_filter($c, function ($i) {
  return $i != 0;
});
$e = $d ? min($d) : 10;

echo $b - (10 - $e), PHP_EOL;

function nextInt()
{
  return (int) trim(fgets(STDIN));
}


Measured memory_bytes: 4856
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a=0,b=0,c=0,d,n=0,x;
    string s,s1,s2;
    cin >> a;   
    if(a>999) cout << "ABD" << endl;
    else cout << "ABC" << endl;
    return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <complex>
#include <math.h>

typedef long long ll;

using namespace std;

double pi=2*acos(0);
const int INF = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};


int main()
{
    int a;
    string s;
    cin >> a;
    cin >> s;
    if(a>=3200) cout << s;
    else cout << "red";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int gcd(int, int);

int main(void)
{
    int x,y,s;
    int i;

    scanf("%d %d", &x, &y);
    s = gcd(x,y);
    printf("%d\n", s);
    return (0);
}
/*xとyの最大公約数を返す*/
int gcd(int x, int y){
    int n;
    int r;

    if (x < y){
        n = y;
        y = x;
        x = n;
    }
    while (y > 0){
        r = x % y;
        x = y;
        y = r;
    }
    return (x);
    
}


Measured memory_bytes: 2100
#素数でない数
#   1
#   ２以外の２の倍数
#   二乗してもnumberを超えない奇数で割り切れる数
def checkPrime(number)
  return true if number == 2
  return false if number % 2 == 0
  i = 3
  while (i * i < number + 1)
    return false if number % i == 0
    i += 2
  end
  return true;
end

numPrime = Array.new(1000000)
input = ""

#あらかじめ素数の数を求めておく
numPrime[0] = 0
numPrime[1] = 0
for i in 2...numPrime.size
  numPrime[i] = numPrime[i - 1]
  numPrime[i] += 1 if checkPrime(i)
end

#メインルーチン
while input = gets
  p numPrime[input.to_i]
end

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

typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<ll, pii> piii;
const int N = 1e5 + 100;
const ll HAVE = 1000LL * 1000 * 1000 * 1000 * 1000;

ll n, m, s, t, u, v, a, b, dis_s[N], dis_t[N];
bool done[N];
vector<piii> nei[N];
set<pii> st;

int main() {//a ro darim, a be b tabdil mishe...
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	
	cin >> n >> m >> s >> t;
	s--;
	t--;
	while(m--) {
		cin >> u >> v >> a >> b;
		nei[--v].push_back(piii(--u, pii(a, b)));
		nei[u].push_back(piii(v, pii(a, b)));
	}
	
	st.insert(pii(0, s));
	while(st.size()) {
		pii p = *st.begin();
		st.erase(st.begin());
		bool brk = false;
		while(done[p.second]) {
			if(st.size() == 0) {
				brk = true;
				break;
			}
			p = *st.begin();
			st.erase(st.begin());
		}
		if(brk)
			break;
		ll u = p.second, 
			w = p.first;
		done[u] = true;
		dis_s[u] = w;
		for (piii p: nei[u])
			if(done[p.first] == false)
				st.insert(pii(dis_s[u] + p.second.first, p.first));
	}
	
	memset(done, false, sizeof done);
	st.clear();
	
	st.insert(pii(0, t));
	while(st.size()) {
		pii p = *st.begin();
		st.erase(st.begin());
		bool brk = false;
		while(done[p.second]) {
			if(st.size() == 0) {
				brk = true;
				break;
			}
			p = *st.begin();
			st.erase(st.begin());
		}
		if(brk)
			break;
		ll u = p.second, 
			w = p.first;
		
		done[u] = true;
		dis_t[u] = w;
		for (piii p: nei[u])
			if(!done[p.first])
				st.insert(pii(dis_t[u] + p.second.second, p.first));
	}
	
	vector<ll> ans;
	
	ans.push_back(dis_s[n - 1] + dis_t[n - 1]);
	
	for (int i = n - 2; i >= 0; i--)
		ans.push_back(min(dis_s[i] + dis_t[i], ans.back()));
	
	reverse(ans.begin(), ans.end());
	for (ll num: ans)
		cout << HAVE - num << '\n';
	return 0;
}

Measured memory_bytes: 15104
#include<stdio.h>
int main(){
    int r,g,b,rgb=0;
    scanf("%d %d %d", &r,&g,&b);
    rgb += r*100;
    rgb += g*10;
    rgb += b;
    if(rgb%4 == 0)
        printf("YES");
    else
        printf("NO");
return 0;
}

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

char str[30005];
int nxt[30005][10];

int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",&str);
	for(int i=0;i<10;i++) nxt[n][i]=n;
	for(int i=n-1;i>=0;i--)
	{
		for(int j=0;j<10;j++) nxt[i][j]=nxt[i+1][j];
		int a=str[i]-'0';
		nxt[i][a]=i;
	}
	int ret=0;
	for(int i=0;i<10;i++)
	{
		for(int j=0;j<10;j++)
		{
			for(int k=0;k<10;k++)
			{
				int now=nxt[0][i];
				now++;
				now=nxt[min(now,n)][j];
				now++;
				now=nxt[min(now,n)][k];
				if(now<n) ret++;
			}
		}
	}
	printf("%d\n",ret);
	return 0;
}


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

using namespace std;
using ll = long long int;

int main(void) {
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(16);
    cin.tie(0); ios::sync_with_stdio(false);

    ll n, x;
    cin >> n >> x;
    vector<ll> dp(x+1);
    vector<ll> s(n);
    for(auto &e: s) cin >> e;
    sort(s.begin(), s.end(), greater<>());

    dp[x] = 1;
    for(ll k=1; k<=n; k++) {
        vector<ll> pre(x+1);
        swap(dp, pre);

        for(ll i=0; i<=x; i++) {
            (dp[i%s[k-1]] += pre[i]) %= MOD;
            (dp[i] += pre[i]*(n-k)) %= MOD;
        }
    }

    {
        ll s = 0;
        for(ll i=0; i<=x; i++)
            (s += dp[i]*i) %= MOD;
        cout << s << endl;
    }
}


Measured memory_bytes: 1888
X, Y = map(int, input().split())
mod = 10**9+7

plus = X+Y

if not plus%3==0:
    print(0)
elif abs(X-Y)>plus//3:
    print(0)
else:
    row = plus//3
    col = Y-row
    l, r = 1, 1
    for c in range(col):
        l = (l*(row-c))%mod
        r = r*(c+1)%mod
    print((l*pow(r, mod-2, mod))%mod)

Measured memory_bytes: 40172
import java.util.Scanner;


class Main {

	public static void main(String[] args) {   

		Scanner scanner = new Scanner(System.in);

		double a = scanner.nextDouble();
		double b = scanner.nextDouble();
		double c = scanner.nextDouble();

		c=Math.toRadians (c);
		double S=((a*b)*Math.sin(c))/2;
		double L=a+b+Math.sqrt((Math.pow(a,2)+Math.pow(b, 2)-(2*a*b*Math.cos(c))));
		double h=b*Math.sin(c);
		System.out.println(S);
		System.out.println(L);
		System.out.println(h);

		scanner.close();
	}
}


Measured memory_bytes: 27780
n, m = map(int, input().split())

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

ops = []
for i in nums:
    ops.append([1, i])
    
for i in range(m):
    b, c = map(int, input().split())
    ops.append([b, c])

total = 0
sums = []
for b, c in sorted(ops, key=lambda x:x[1], reverse=True):
    if total > n:
        break
    sums.extend([c]*b)
    total = total + b
print(sum(sums[:n]))

Measured memory_bytes: 39372
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define D_iN	200

int main (void) {
	int ii=0, iRetValue=0, iN=0, iA[D_iN], iCount=0;
	int	a=0, b=0, c=0;

	iRetValue = scanf ("%d", &iN);
	for (ii=0; ii < iN; ii++) {
		iRetValue = scanf ("%d", &iA[ii]);
	}

	while (1) {
		for (ii=0; ii < iN; ii++) {
			//c=a-(a/b)*b;
//			a = iA[ii] >> 1;	// /2
//			b = a << 1;			// x2
//			c = iA[ii] - b;		// 1 - 

			a = iA[ii] >> 1;	// /2
			c = iA[ii] - (a << 1);
			if (c == 0) {
				iA[ii] = a;
			} else {
				goto l_Exit;
			}
		}
		iCount++;
	}

l_Exit:
	printf ("%d\n", iCount);

	return 0;
}


Measured memory_bytes: 128
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0 ,0 };

int n, m;
int p[100001], y[100001];
vector <int> yd[100001];
int tmp;

int main(void) {
	

	cin >> n >> m;
	FOR(i, 1, m) {
		cin >> p[i] >> y[i];
		yd[p[i]].push_back(y[i]);
	}

	FOR(i, 1, n) {
		sort(yd[i].begin(), yd[i].end());
	}

	FOR(i, 1, m) {
		
		printf("%06d%06d\n", p[i], int(lower_bound(yd[p[i]].begin(),yd[p[i]].end(),y[i])-yd[p[i]].begin())+1);
	}

	return 0;
}

Measured memory_bytes: 7808
N = int(input())
A = [int(n) for n in input().split()]
maxA = max(A)

C = {a:0 for a in A}
D = {a:0 for a in A}
for a in A:
    C[a] += 1
for a in A:
    if C[a] > 0:
        t = 2
        while a*t <= maxA:
            D[a*t] = 1
            t += 1
ans = 0
for a in A:
    if C[a] == 1 and D[a] == 0:
        ans += 1
print(ans)

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

int main()
{
  int n;
  while( cin >> n, n ) {
    double id, h, w;
    double close_id = (1 << 30), close_bmi = (1 << 30);
    double basic = 22.0;

    while( n-- ) {
      cin >> id >> h >> w;

      double bmi = w / ((h/100) * (h/100));
      if( fabs(basic - bmi) == fabs(basic - close_bmi) ) {
	close_id = min(close_id, id);
      }
      else if( fabs(basic - bmi) < fabs(basic - close_bmi) ) {
	close_id = id;
	close_bmi = bmi;
      }

    }

    cout << close_id << endl;
  }

}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    string s;
    cin >> s;
    for (size_t i = 0; i < s.size() - 1; i++) {
        if (s.at(i) == 'A' && s.at(i + 1) == 'C') {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}

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

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

typedef long long ll;

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

int main() {
    int N; cin >> N;
    vector<double> A(N); repp(i,0,N) cin >> A[i];
    double sum = 0;
    repp(i,0,N) sum += 1/A[i];
    cout << setprecision(10) << 1/sum << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long ll;
int main(){
  ll a, b, c;
  cin >> a >> b >> c;
  set<int> s;
  set<int>::iterator ite;
  ll temp = a;
  while (true) {
  	if (a % b == c) {
	  	cout << "YES\n";
	  	break;
  	}
  	ite = s.find(a % b);
  	if (ite != s.end()) {
	  	cout << "NO\n";
	  	break;
  	}
  	s.insert(a % b);
  	a += temp;
  }
  return 0;
}

Measured memory_bytes: 256
_, *aa = map(int, open(0).read().split())
r = 0
mi = 1000000000
m = 0
for a in aa:
    if a < 0:
        m += 1
    b = abs(a)
    r += b
    if b < mi:
        mi = b
print(r - mi * 2 * (m % 2))


Measured memory_bytes: 14084
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		double total = 0.0;
		
		for (int i = 0; i < n; i++) {
			double price = scanner.nextDouble();
			String currency = scanner.next();
			
			if (currency.equals("JPY")) {
				total += price;
			} else if (currency.equals("BTC")) {
				total += price*380000.0;
			}
		}
		System.out.println(total);
		scanner.close();

	}

}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define LL long long

using namespace std;

const int Maxn = 100 + 10;

int N, x, A[Maxn];

int main()
{
#ifdef hk_cnyali
	freopen("A.in", "r", stdin);
	freopen("A.out", "w", stdout);
#endif
	scanf("%d%d", &N, &x);
	for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
	sort(A + 1, A + N + 1);
	int sum= 0, cnt = 0, xx = x;
	for (int i = 1; i <= N; ++i)
	{
		if (A[i] <= x) x -= A[i], sum = i;
		else break;
	}
	if (x && sum == N) sum--;

	cout<<sum<<endl;
	return 0;
}

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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int sx = stdIn.nextInt();
		int sy = stdIn.nextInt();
		int tx = stdIn.nextInt();
		int ty = stdIn.nextInt();
		
		for(int i = sy; i <ty; i++) {
			System.out.print('U');
		}
		for(int i = sx; i < tx; i++) {
			System.out.print('R');
		}
		for(int i = ty; i > sy; i--) {
			System.out.print('D');//
		}
		for(int i = tx; i > sx; i--) {
			System.out.print('L');
		}
		//ここまでで1週
		System.out.print('L');//
		
		for(int i = sy; i < ty; i++) {
			System.out.print('U');
		}
		System.out.print('U');
		System.out.print('R');
		
		for(int i = sx; i < tx; i++) {
			System.out.print('R');
		}
		System.out.print('D'); //tx,tyに到着
		
		System.out.print('R');
		
		for(int i = ty; i > sy; i--) {
			System.out.print('D');
		}
		System.out.print('D');
		System.out.print('L');
		
		for(int i = tx; i > sx; i--) {
			System.out.print('L');
		}
		System.out.print('U');
		
		
	}

}


Measured memory_bytes: 28804
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)

constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;

ll n, k;

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cin >> n; 
	vector<int> a(n), b(n), c(n);
	rep(i, 0, n) cin >> a[i], --a[i];
	rep(i, 0, n) cin >> b[i];
	rep(i, 0, n - 1) cin >> c[i];

	int ans = 0;
	rep(i, 0, n) {
		int m = a[i];
		ans += b[m];
		if (i + 1 < n && a[i + 1] == m + 1) ans += c[m];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

int main(){
  int i,j;
  int n,m;
  cin>>n>>m;
  int p;
  string s;
  VI v(n+1,0);
  ll cnt=0;
  VI wa(n+1,0);
  for(i=0;i<m;i++){
      cin>>p>>s;
      if(s=="AC"){
          if(v[p]==0){
              cnt++;
              v[p]=1;
          }
      }
      else {
          if(v[p]==0) wa[p]++;
      }
  }
  ll w=0;
  for(i=1;i<=n;i++){
      if(v[i]==1) w+=wa[i];
  }
  cout<<cnt<<" "<<w<<endl;


  return 0;
}


Measured memory_bytes: 1024
i = list(map(int, input().split()))
n = i[0]
k = i[1]

if n >= 1 and k <= 100:
  if n == 1 and k == 1:
    print("YES")
  elif n > k:
    if n % 2 == 1:
      if int(n / k) >= 2:
        print("YES")
      elif int(n / k) == 1 and (int(n % k) == k - 1):
        print("YES")
      else:
        print("NO")
    else:
      if int(n / k) >= 2:
        print("YES")
      elif n % k == 0:
        print("YES")
      else:
        print("NO")
  else:
    print("NO")


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

int main() {
	int n;cin>>n;
	long long a[n];for(int i=0;i<n;i++)cin>>a[i];
	vector<long long> sum(n);
	sum[0]=a[0];
	for(int i=1;i<n;i++){
		sum[i]=a[i]+sum[i-1];
//		cout<<sum[i]<<' ';
	}
	long long ans=-1;
	for(int i=1;i<n-2;i++){
		long long max1,min1,max2,min2,max3,min3,max4,min4,temp;
		long long k=lower_bound(sum.begin(),sum.begin()+i+1,sum[i]/2)-sum.begin();
		max1=max(sum[k],sum[i]-sum[k]);
		min1=min(sum[k],sum[i]-sum[k]);
//		cout<<i<<' '<<k<<' '<<max1<<' '<<min1<<endl;
		if(k){
			max2=max(sum[k-1],sum[i]-sum[k-1]);
			min2=min(sum[k-1],sum[i]-sum[k-1]);
			if((max1-min1>max2-min2)+(min1==0)){
				max1=max2;
				min1=min2;
			}
		}
//		cout<<i<<' '<<k<<' '<<max1<<' '<<min1<<endl;
		k=lower_bound(sum.begin()+i+1,sum.end()-1,(sum[n-1]-sum[i])/2+sum[i])-sum.begin();
		max3=max(sum[k]-sum[i],sum[n-1]-sum[k]);
		min3=min(sum[k]-sum[i],sum[n-1]-sum[k]);
//		cout<<i<<' '<<k<<' '<<max3<<' '<<min3<<endl;
		if(k!=i+1){
			max4=max(sum[k-1]-sum[i],sum[n-1]-sum[k-1]);
			min4=min(sum[k-1]-sum[i],sum[n-1]-sum[k-1]);
			if((max3-min3>max4-min4)+(min3==0)){
				max3=max4;
				min3=min4;
			}
		}
//		cout<<i<<' '<<k<<' '<<max3<<' '<<min3<<endl;
		if(max1<max3)max1=max3;
		if(min1>min3)min1=min3;
		if((ans>max1-min1)+(ans==-1))ans=max1-min1;
//		cout<<i<<' '<<max1<<' '<<min1<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    int ans = 0;
    rep(r, 0, N + 1) {
        rep(g, 0, N + 1) {
            int b = N - (r * R + g * G);
            if (b >= 0 && b % B == 0) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return (0^_^0);
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>

#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
#define FILLA(a, x) memset((a), (x), sizeof (a))
#define COPYA(a, b) memcpy((b), (a), sizeof (a))

using namespace std;

typedef long long li;
typedef unsigned long long lu;
const li infl = ~0LLU >> 2;

template <class T>
inline void Min(T &x, T y) {
  if (y < x) x = y;
}
template <class T>
inline void Max(T &x, T y) {
  if (y > x) x = y;
}

const int mod = 1e9 + 7;
inline int Add(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
inline int Mul(int x, int y) { return (int)((li)x * y % mod); }
inline int Mul(int x, int y, int z) { return Mul(x, Mul(y, z)); }
int Pow(int x, int y) {
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = Mul(z, x);
    x = Mul(x, x);
  }
  return z;
}
int Inv(int x) {
  return Pow(x, mod - 2);
}

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

const int maxn = 3e5;
const int inf = 1e9;

int n, a[maxn], sum_a;
int sumd[maxn];
bool dp[maxn];

void Exit(int ans) {
  printf("%d %d\n", ans, sum_a - ans);
  exit(0);
}

bool Check(int lim) {
  FILL(dp, n, 0);
  int min_yes = 0;

  for (int i = 1; i < n; i += 2) {
    dp[i] = (sumd[i - 1] - min_yes >= lim);
    if (dp[i]) {
      Min(min_yes, sumd[i]);
    }
  }

  return sumd[n - 1] - min_yes >= lim;
}

int main(void) {
  scanf("%d", &n);
  sum_a = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    sum_a += a[i];
  }
  int sum1 = 0;
  for (int i = 0; i < n; i += 2) {
    sum1 += a[i];
  }
  int ans = max(sum1, sum_a - sum1);
  if (~n & 1) {
    Exit(ans);
  }

  sumd[0] = a[0];
  for (int i = 1; i < n; ++i) {
    sumd[i] = sumd[i - 1] + a[i] * (i & 1 ? -1 : 1);
  }

  int low = 0, high = 2 * sum_a + 1;
  while (high - low > 1) {
    int mid = low + high >> 1;
    if (Check(mid)) {
      low = mid;
    } else {
      high = mid;
    }
  }
  Max(ans, sum_a - sum1 + low);
  Exit(ans);
}


Measured memory_bytes: 2816