akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(void){
  long A,B,C,K,sum=0;
  scanf("%ld %ld %ld %ld", &A, &B, &C, &K);
  if(A>=K){
    printf("%ld\n", K);
  }else{
    if(A+B>=K){
      printf("%ld\n", A);
    }else{
      // A+B+C>=K
      printf("%ld\n", A-(K-A-B));
    }
  }
  return 0;
}

Measured memory_bytes: 1724
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        int answer = 0;
        for (int i = 0; i < S.length(); i++) {
            if (S.charAt(i) == T.charAt(i)) {
                answer++;
            }
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 22996
#include<iostream>
#include<vector>
using namespace std;
typedef long long int ll;
static const ll MOD = 1000000007;

ll mod_pow(ll n, ll x){
	if(n == 0) return 1;
	ll ret = mod_pow(n / 2, x * x % MOD) % MOD;
	if(n % 2) return ret * x % MOD;
	return ret;
}

ll comb(int n, int k, vector<ll> memo){
	if(k < 0 || k > n) return 0;
	return ((memo[n] * mod_pow(MOD - 2, memo[k])) % MOD) * mod_pow(MOD - 2, memo[n - k]) % MOD;
}

int main(){
	int n, k;
	cin >> n >> k;
	if(n < k){
		cout << 0 << endl;
		return 0;
	}
	vector<ll> memo(k + 1, 0);
	memo[1] = 1;
	vector<ll> memo2(n + 1);
	memo2[0] = 1; memo2[1] = 1;
	for(int i = 2; i <= n; i++){
		memo2[i] = memo2[i - 1] * (ll)i;
		memo2[i] %= MOD;
	}
	for(int i = 2; i <= k; i++){
		memo[i] = mod_pow(n, i);
		for(int j = 1; j < i; j++){
			memo[i] -= (comb(i, j, memo2) * memo[j]) % MOD;
			while(memo[i] < 0) memo[i] += MOD;
		}
	}
	cout << memo[k] << endl;
	return 0;
}



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

int main() {
    int N;
    cin >> N;
    int l[2][1000];
    int Sum = 0;
    for(int i = 0; i < N; ++i) {
        cin >> l[0][i] >> l[1][i];
        Sum += l[1][i] - l[0][i] + 1;
    }
    cout << Sum << endl;
}

Measured memory_bytes: 256
N = int(input())
if N% 10== 2 or  N% 10== 4 or  N% 10== 5 or  N% 10== 7 or  N% 10== 9:
    print("hon")
elif N% 10 == 0 or  N% 10== 1 or  N% 10== 6 or  N% 10== 8:
    print("pon")
else:
    print("bon")

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

using namespace std;

int main(){
        int N;
        cin>>N;
        vector <int> a(N);
        long long res=1;
        for(int i=0;i<N;i++){
                cin>>a[i];
        }
        for(int i=0;i<N;i++){
                if(a[i]%2!=0){
                        res*=1;
                }
                else{
                        res*=2;
                }
        }
        cout<<pow(3, N)-res<<endl;
        return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;

int main(void) {
    char op;
  string sa;
  cin >>sa;
  string a,b,c;
  for(int i=0;i<sa.size();i++)
  {
      if(sa[i]==',')sa[i]=' ';
  }
  istringstream s(sa);
  s >> a >> b >> c;
  cout<<a<<" "<<b<<" "<<c<<endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;

class Main
{
    public static void main (String[] args) throws java.lang.Exception {
        Scanner io = new Scanner(System.in);
        /*for(long i = 1; i <= 1000; i++)
            System.out.println(i + " " + leadingzeros(foo(BigInteger.valueOf(i))));*/
        long s = 0;
        long n = io.nextLong();
        if(n < 10 || n % 2 == 1) {
            System.out.println(0);
            return;
        }
        s += n/10;
        for(long i = 50; i <= n; i*=5)
            s += n / i;
        System.out.println(s);
    }
    /*public static BigInteger foo(BigInteger n) {
        return n.equals(BigInteger.ONE) || n.equals(BigInteger.TWO) ? BigInteger.ONE : n.multiply(foo(n.subtract(BigInteger.TWO)));
    }
    public static long leadingzeros(BigInteger n) {
        String str = n.toString();
        long c = 0;
        for(int i = 1; i <= str.length(); i++)
            if(str.charAt(str.length()-i) != '0' || c++ < 0) break;
        return c;
    }*/
}


Measured memory_bytes: 23764
#include<stdio.h>
int main(){
          int a,b,c;
          scanf("%d %d %d", &a, &b, &c);
          if(a<=b && b<=c){
            printf("%d %d %d\n", a, b, c);
          }else if(a<=c && c<=b){ 
                  printf("%d %d %d\n", a, c, b);
                }else if(b<=a && a<=c){
                        printf("%d %d %d\n", b, a, c);
                      }else if(b<=c && c<=a){       
                              printf("%d %d %d\n", b, c, a);
                            }else if(c<=a && a<=b){
                                    printf("%d %d %d\n", c, a, b);
                                  }else if(c<=b && b<=a){
                                          printf("%d %d %d\n", c, b, a);
          }
          return 0;
}

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

using namespace std;

int main(){
  vector<int> v;
  int t;
  int N;
  cin >> N;
  while(cin >> t){
    v.push_back(t);
  }
  vector<int> sorted = v;
  sort(sorted.begin(), sorted.end());

  if(v == sorted) {
    cout << "YES" << endl;
    return 0;
  }

  for(int i = 0; i < N; ++i) {
    for(int j = i + 1; j < N; ++j){
      vector<int> w = v;
      int a = w[i];
      int b = w[j];

      w[i] = b;
      w[j] = a;

      if(w == sorted) {
        cout << "YES" << endl;
        return 0;
      }
    }
  }

  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

int main(){
   ;
    //サンプルコード;;
    //ABC076-B;;
    ;;
    int n, k;;;
    cin >> n >> k;;;
    ;;
    int ans = 1;;;
    for(int i = 1; i <=  n; ++i){;;;
        ans = min(ans*2, ans+k);;
    ;};;
    cout << (ans) << endl;;;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
int main(void){
  int x,y,z;
  std::cin >> x >> y;
  std::string ans="No";
  
  for(int i=0;i<x+1;i++){
    z=x-i;
    if(i*2+4*z==y){
      ans="Yes";
    }
  }
  
  std::cout << ans;
  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <numeric>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>


using namespace std;
using ll = long long;
const ll INF = 1e9;

int N, M, R;

ll r[8];

int d[200][200];

void warshall_floyd() { // N: length of vertices
    for (int k = 0; k < N; k++)
        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int main() {
    ll ans = INF;
    cin >> N >> M >> R;
    vector<int> A(M), B(M), C(M);
    for (int i = 0; i < R; i++) {
        cin >> r[i];
        r[i]--;
    }
    sort(r, r+R);

    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++) d[i][j] = INF;

    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i] >> C[i];
        A[i]--;
        B[i]--;
        d[A[i]][B[i]] = C[i];
        d[B[i]][A[i]] = C[i];
    }

    warshall_floyd();

    do {
        ll temp = 0;
        for (int i = 1; i < R; i++) {
            temp += d[r[i-1]][r[i]];
        }

        ans = min(ans, temp);
    } while (next_permutation(r, r + R));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    static int time = 1;

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] a = new int[M];
        int[] b = new int[M];
        for (int i = 0; i < M; ++i) {
            a[i] = sc.nextInt() - 1;
            b[i] = sc.nextInt() - 1;
        }

        System.out.println(solve(N, a, b));

        sc.close();
    }

    static int solve(int N, int[] a, int[] b) {
        @SuppressWarnings("unchecked")
        List<Integer>[] adjLists = new List[N];
        for (int i = 0; i < adjLists.length; ++i) {
            adjLists[i] = new ArrayList<>();
        }

        for (int i = 0; i < a.length; ++i) {
            adjLists[a[i]].add(b[i]);
            adjLists[b[i]].add(a[i]);
        }

        int[] ins = new int[N];
        int[] minIns = new int[N];

        return search(adjLists, ins, minIns, 0, -1);
    }

    static int search(List<Integer>[] adjLists, int[] ins, int[] minIns, int node, int parent) {
        ins[node] = time;
        minIns[node] = time;
        ++time;

        int result = 0;
        for (int adj : adjLists[node]) {
            if (adj == parent) {
                continue;
            }

            if (ins[adj] == 0) {
                result += search(adjLists, ins, minIns, adj, node);
            }

            if (minIns[adj] > ins[node]) {
                ++result;
            }

            minIns[node] = Math.min(minIns[node], minIns[adj]);
        }

        return result;
    }
}

Measured memory_bytes: 23380
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>
using namespace std;


int main(void) {
    int N, K;
    int t;
    double ans, p;
    scanf("%d %d", &N, &K);
    
    ans = 0;
    for(int i=1;i<=N;i++){
        t = i;
        p = 1;
        while(t<K){
            t = 2 * t;
            p = p / 2;
        }
        ans += p;
    }
    
    printf("%.15f\n", ans / N);
}

Measured memory_bytes: 128
N, M = map(int, input().split())
l_max, r_min = 0, 100000000

for i in range(0, M):
    l, r = map(int, input().split())
    if l > l_max:
        l_max = l
    if r < r_min:
        r_min = r

print(max(0, r_min-l_max+1))

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

using namespace std;

int main()
{
    long n,i,ans=0;
    cin >> n;
    
    for(i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0)
        ans+=i;
    }
    cout<<ans;

    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl
#define DOUBLE(d) cout << fixed << setprecision(15) << (d) << endl

string S;

int main() {
    cin >> S;
    if (S == "ARC") cout << "ABC" << endl;
    else cout << "ARC" << endl;
}

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

bool check (std::vector<int> a, std::vector<int> b) {
	bool ret = true;
	for (std::size_t i = 0; i < a.size(); i++) ret &= (a[i] != b[i]);
	return ret;
}

void answer (bool ans, std::vector<int> a) {
	std::cout << (ans ? "Yes" : "No") << '\n';
	if (ans) for (int e : a) std::cout << e << '\n';
}

int main() {
	int n;
	std::cin >> n;
	std::vector<int> a(n), b(n), c(n);
	for (int i = 0; i < n; i++) std::cin >> a[i];
	for (int i = 0; i < n; i++) { std::cin >> b[i]; c[i] = b[i]; }
	
	std::reverse(b.begin(), b.end());
	std::rotate(c.begin(), c.begin() + (n / 2), c.end());
	
	if (check(a, b)) answer(true, b);
	else if (check(a, c)) answer(true, c);
	else answer(false, a);
	return 0;
}

Measured memory_bytes: 7184
N,*f = map(int, open(0).read().split())
D = [f[i*2:i*2+2] for i in range(N)]
count = 0
for x in D:
    if x[0] == x[1]:
        if count == 2:
            print('Yes')
            break
        else:
            count += 1
    else:
        count = 0
else:
    print('No')

Measured memory_bytes: 9176
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int A,B,C;
	cin>>A>>B>>C;
	if(A==B){
		ce(C)
	}else if(A==C){
		ce(B)
	}else{
		ce(A)
	}
	
}

Measured memory_bytes: 256
n=int(input())
data=[]
for i in range(n):
    data.append(list(map(int,input().split())))
    
first_h_index=0
for i in range(n):
    if data[i][2] > 0:
        first_h_index=i
        break
    
for i in range(101):
    for j in range(101):
        h=data[first_h_index][2]+abs(data[first_h_index][0]-i)+abs(data[first_h_index][1]-j)
        for k in range(n):
            if data[k][2] != max(h-abs(data[k][0]-i)-abs(data[k][1]-j),0):
                break
        else:
            print(i,j,h)
            break

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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
const int INF = 1e9;
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)
#define print(a)       for(auto x : a) cout << x << " "; cout << "\n"
#define print1(a)      for(auto x : a) cout << x.ff << " " << x.ss << "\n"
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << "\n"


ll fast_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}
// dsu start

vi root(200001,0);
vi size(200001,1);
int find(int x){while(x!=root[x])x = root[x];return x;}
bool same(int a,int b){return find(a)==find(b);}
void unite(int a, int b){a = find(a);b = find(b);if(size[a]<size[b])swap(a,b);size[a] += size[b];root[b] = a;}

// dsu end
vi vis(200001,0);
vi adj[200001];

ll digicheck(ll n)
{
	ll x = n;
	ll cnt = 0;
	while(x)
	{
		x/=10;
		++cnt;
	}
	return cnt;

}
int main()
{	
    std::ios::sync_with_stdio(false);
    //string bitstring = std::bitset< 3 >( 7 ).to_string(); <bits> (num)
    //srand(time(0));
    //cin.tie(NULL);
    //cout.tie(NULL);
 	ll n;
 	cin>>n;
 	vii vec;
 	for(int i=1; i<=sqrt(n); ++i)
 	{
 		if(n%i==0)
 			vec.pb(mp(i,n/i));
 	}
 	int mini = INF;

 	for(int i=0; i<vec.size(); ++i)
 	{
 		int a = vec[i].ff;
 		int b = vec[i].ss;
 		int x = max(digicheck(a),digicheck(b));
 		if(x<mini)
 			mini = x;
 	}
 	cout<<mini<<"\n";

}

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

int main(){
  int num;
  int a[4][3][10];

  for(int i = 0;i<4;++i){
    for(int k = 0;k<3;k++){
      for(int l = 0;l<10;++l){
	a[i][k][l] = 0;
      }
    }
  }
  
  cin >> num;

  int *b = new int[num];
  int *f = new int[num];
  int *r = new int[num];
  int *v = new int[num];

  for(int i = 0 ; i < num ; ++i){
    cin >> b[i] >> f[i] >> r[i] >> v[i];

    a[b[i] - 1][f[i] - 1][r[i] - 1] += v[i];
  }
  
  delete[] b;
  delete[] f;
  delete[] r;
  delete[] v;
  

  for(int i=0;i<4;++i){
    for(int k = 0; k<3; ++k){
      for(int l = 0;l<10; ++l){
	cout << " " << a[i][k][l];
      }

      cout << endl;
    }

    if(i != 3){
      cout << "####################" << endl;
    }
  }

  return 0;
}




Measured memory_bytes: 3108
#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ t : ty ;; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ;; ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
fn solve() {
    let n = get!(usize);
    let ans = (1..n + 1)
        .filter(|&x| x % 2 == 1 && (1..x + 1).filter(|&d| x % d == 0).count() == 8)
        .count();

    println!("{}", ans);
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
#define int long long
#define P(x) {if (debug) cout << x << endl;}
#define H(x) P(#x << ": " << (x))
#define FR(i,a,b) for (int i=(a); i<(b); i++)
#define F(i,n) FR(i,0,n)
#define DR(i,a,b) for (int i=(b); i-->(a);)
#define D(i,n) DR(i,0,n)
#define S(s) (int)(s).size()
#define ALL(v) v.begin(), v.end()
#define MI(a,v) a = min(a,v)
#define MA(a,v) a = max(a,v)
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;
template<class T> ostream &operator<<(ostream &os, V<T> v) {
    F(i,S(v)) os<<(i?" ":"")<<v[i];
    return os;
}
const bool debug = 0;

const int A=92821, PHI=9223372036854775807, N=250005, OFF=N;

int fp(int a, int b) {
    if (b == 0) return 1;
    int rt = fp(a, b/2);
    if (b%2) return rt*rt*a;
    else return rt*rt;
}

V<int> _mem(2*OFF);

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int B = fp(A, PHI);
    H(B) H(A*B)
    int n; cin>>n;
    string s; cin>>s;
    int *p = &_mem[OFF];
    p[0] = 1;
    F(i,n) {
        p[i+1] = p[i]*A;
        p[-i-1] = p[-i]*B;
    }
    V<int> pos(n+1), val(n+1);
    pos[0] = val[0] = 0;
    F(i,n) {
        pos[i+1] = pos[i];
        val[i+1] = val[i];
        if (s[i] == '+') {
            val[i+1] += p[pos[i]];
        } else if (s[i] == '-') {
            val[i+1] -= p[pos[i]];
        } else if (s[i] == '>') {
            pos[i+1]++;
        } else {
            pos[i+1]--;
        }
    }
    map<int,int> occ;
    occ[val[n]]++;
    int tot = 0;
    D(i,n) {
        int goal = val[n] * p[pos[i]] + val[i];
        tot += occ[goal];
        occ[val[i]]++;
    }
    cout<<tot<<"\n";
}

Measured memory_bytes: 39572
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
const int nax=4007;

int n;

int kol[nax];
int tab[nax];

int dp[nax][nax];
int lew[nax][2][nax];
int pra[nax][2][nax];

int main()
{
	scanf("%d", &n);
	for (int i=1; i<=2*n; i++)
	{
		char c;
		scanf(" %c%d", &c, &tab[i]);
		kol[i]=(c=='W');
	}
	for (int i=1; i<=2*n; i++)
	{
		for (int j=1; j<=2*n; j++)
		{
			if (kol[j]!=kol[i])
			{
				if (j<i)
					lew[tab[i]][kol[i]][tab[j]]++;
				else
					pra[tab[i]][kol[i]][tab[j]]++;
			}
		}
		for (int j=n; j; j--)
			lew[tab[i]][kol[i]][j]+=lew[tab[i]][kol[i]][j+1];
		for (int j=1; j<=n; j++)
			pra[tab[i]][kol[i]][j]+=pra[tab[i]][kol[i]][j-1];
	}
	for (int i=0; i<=n; i++)
		for (int j=0; j<=n; j++)
			dp[i][j]=(i || j)*1e9;
	for (int i=0; i<=n; i++)
	{
		for (int j=0; j<=n; j++)
		{
			if (i<n)
			{
				dp[i+1][j]=min(dp[i+1][j], dp[i][j]+lew[i+1][0][j+1]+pra[i+1][0][j]);
			}
			if (j<n)
			{
				dp[i][j+1]=min(dp[i][j+1], dp[i][j]+lew[j+1][1][i+1]+pra[j+1][1][i]);
			}
		}
	}
	int dod=0;
	for (int i=1; i<=2*n; i++)
		for (int j=1; j<i; j++)
			if (kol[i]==kol[j] && tab[j]>tab[i])
				dod++;
	printf("%d\n", dp[n][n]/2+dod);
	return 0;
}


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

const int MAXN = 1e5;

int n, L, a[MAXN];

int main() {
	scanf("%d%d", &n, &L);
	for(int i = 0; i < n; i++) {
		scanf("%d", a+i);
	}
	
	for(int i = 0; i < n-1; i++) {
		if(a[i] + a[i+1] >= L) {
			printf("Possible\n");
			for(int j = 0; j < i; j++)    printf("%d ", j+1);
			for(int j = n-2; j >= i; j--) printf("%d ", j+1);
			return 0;
		}
	}
	printf("Impossible\n");
	return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  set<char> s;
  char ch;
  for (int i = 0; i < N; ++i) {
    cin >> ch;
    s.insert(ch);
  }
  printf("%s\n", s.size() == 3 ? "Three" : "Four");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
typedef pair<P,P> PP;

string s[888];
P d[888][888];
void Main() {
  int h,w,t;
  cin >> h >> w >> t;
  priority_queue<PP,vector<PP>,greater<PP> > que;
  rep(i,h) {
    R s[i];
    rep(j,w) {
      d[i][j]=P(MAX,MAX);
      if(s[i][j]=='S') {
        d[i][j]=P(0,0);
        que.push(PP(P(0,0),P(i,j)));
      }
    }
  }
  int ans=MAX;
  while(!que.empty()) {
    PP p=que.top();que.pop();
    int xx=p.S.F,yy=p.S.S;
    P q=p.F;
    if(d[xx][yy]<q) continue;
    rep(i,4) {
      int x=xx+dx[i],y=yy+dy[i];
      if(!check(h,w,x,y)) continue;
      P e=q;
      if(s[x][y]=='#') {
        e.S++;
        e.F=max(e.F,(int)ceil((double)e.S/t)*t);
        e.F++;
      } else e.F++;
      if(!x||!y||x==h-1||y==w-1) ans=min(ans,(int)max(ceil((double)e.F/t),ceil((double)e.S/t)));
      if(d[x][y]>e) {
        d[x][y]=e;
        que.push(PP(e,P(x,y)));
      }
    }
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}

Measured memory_bytes: 12664
import java.util.Scanner
fun main(args: Array<String>){
    val sc = Scanner(System.`in`) //Scannerのインスタンスを作成

    val s: String = sc.nextLine()  //入力を行で取得
    val i: Int = Integer.parseInt(s)//Int型に変換
    println(i*i*i)
}


Measured memory_bytes: 25636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=1000005;
string s;
char ch[N];
int to[200],n,q[3];
bool cmp(int a,int b){
	return to[a]<to[b];
}
int nxt[N],pre[N];
void del(int p){
	nxt[pre[p]]=nxt[p];
	pre[nxt[p]]=pre[p];
}
int main(){
	cin>>s;
	char lst='z'; 
	for(auto i:s)if(i!=lst){
		ch[++n]=i; lst=i; to[i]++;
	}ch[n+1]=1;
	For(i,0,n+1){pre[i]=i-1; nxt[i]=i+1;}
	For(i,0,2)q[i]='A'+i;
	sort(q,q+3,cmp);
	For(i,1,n)if(ch[pre[i]]!=ch[nxt[i]]&&ch[i]==q[2]&&to[q[2]]>to[q[1]]){del(i); to[q[2]]--;}
	int i=nxt[0];	
	while(to[q[2]]>to[q[1]]){
		if(ch[i]==q[2]&&ch[pre[i]]==q[0]&&ch[nxt[i]]==q[0]){
			int jb=nxt[i];
			del(pre[i]);
			del(i); to[q[2]]--; to[q[0]]--;
			//cout<<i<<" "<<to[q[2]]<<" "<<to[q[1]]<<endl;
			i=jb;
		}else i=nxt[i];
	}
	assert(to[q[2]]==to[q[1]]); //puts("zhu");
	i=nxt[0];
	while(to[q[1]]>to[q[0]]){
		if(ch[i]+ch[nxt[i]]==q[1]+q[2]&&ch[nxt[nxt[i]]]!=ch[pre[i]]){//cout<<i<<endl;
			int jb=nxt[nxt[i]];
			del(nxt[i]);
			del(i); to[q[1]]--;
			i=jb;
		}else i=nxt[i];
	}
	for(int i=nxt[0];i<=n;i=nxt[i])putchar(ch[i]);
}
/*
BABABA

*/

Measured memory_bytes: 11140
import java.util.Scanner;

class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int ans, n, i;
        n = sc.nextInt();
        String s = sc.next();

        int doc = 0;
        for ( i = 0; i < n; i++){
            if (s.charAt(i) == '.') doc++;
        }
        ans = doc;

        for ( i = 0; i < n; i++){
            if (s.charAt(i) == '#') doc++;
            if (s.charAt(i) == '.') doc--;
            ans = Math.min(ans,doc);
        }

        System.out.print(ans);
        sc.close();
    }
}

Measured memory_bytes: 28236
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long n,k,a[2005];
long long kk2,kk,cnt1=0,cnt2=0;
unsigned long long ans=0;
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>k;
	kk=(k*(k+1)/2)%mod;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++){
		cnt1=0,cnt2=0;
		for(int j=0;j<n;j++){
			if(a[i]>a[j]) cnt1++;
			if(a[i]>a[j]&&j<i) cnt2++;
		}
		ans+=mod;
		ans+=(cnt1*kk%mod-k*cnt2)%mod;
		//cout<<"ans+="<<(cnt1*kk-2*cnt2)<<"ans:";
		ans%=mod;
		//printf("%lld\n",ans);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
N = gets.chomp.to_i
X = gets.chomp.split.map(&:to_i)
ans = 1 << 40

101.times do |i|
    res = 0
    X.each do |x|
        res += (x-i) * (x-i)
    end
    ans = ans > res ? res : ans
end

puts ans

Measured memory_bytes: 14236
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
int A[100011];

void MAIN() {
    scanf("%d", &N);
    REP (i, N) scanf("%d", A+i);

    bool yes;
    sort(A, A+N);
    if (N % 3 == 0) {
	int len = N / 3;
	if (A[0] == A[len-1]
		&& A[len] == A[2*len-1]
		&& A[2*len] == A[3*len-1]
		&& (A[0]^A[len])==A[2*len]) {
	    yes = true;
	} else {
	    yes = false;
	}
    } else {
	yes = (A[N-1] == 0);
    }
    puts(yes? "Yes": "No");
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

struct Data {
  int p;
  int dist;
  bool operator<(const Data &d)const{return dist > d.dist;}
};
int dist[2001][2001];

void dijkstra(int n, int x, int y, int s) {
  priority_queue<Data> Q;

  bool visited[2001] = {0};

  Q.push(Data{s, 0});
  while (!Q.empty()) {
    Data d = Q.top();
    Q.pop();
    if(visited[d.p]) continue;
    visited[d.p] = true;
    dist[s][d.p] = d.dist;
    if (d.p > 1) {
      Q.push(Data{d.p-1, d.dist+1});
    }
    if (d.p < n) {
      Q.push(Data{d.p+1, d.dist+1});
    }
    if (d.p == x) {
      Q.push(Data{y, d.dist+1});
    }
    if (d.p == y) {
      Q.push(Data{x, d.dist+1});
    }
  }
}

int main() {
  int n, x, y;
  cin >> n >> x >> y;

  for (int i = 1; i <= n; i++) {
    dijkstra(n, x, y, i);
  }
  int cnt[2001] = {0};
  for (int i = 1; i <= n; i++) {
    for (int j = i+1; j <= n; j++) {
      cnt[dist[i][j]]++;
    }
  }
  for(int k = 1; k < n; k++) {
    cout << cnt[k] << endl;
  }

  return 0;
}

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

int main(){
int N, M, cnt;
  cin >> N >> M;
char n[N][N] = {};
char m[M][M] = {};  
bool a = false;  
  
  for(int i = 0;i < N;i++){
    for(int j = 0;j < N;j++){
    cin >> n[i][j];  
  }
  }

  for(int i = 0;i < M;i++){
    for(int j = 0;j < M;j++){
    cin >> m[i][j]; 
  }
  }
  
  for(int i = 0;i <= N - M;i++){
    for(int j = 0;j <= N - M;j++){
      cnt = 0;
      for(int k = 0;k < M;k++){
        for(int l = 0;l < M;l++){ 
          if(n[i+k][j+l] == m[k][l]) cnt++;   
  }          
  }  
      if(cnt == M * M){ 
            a = true;
            break;
      }
  }
  }
  

  if(a) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}

import Data.Bits
import Data.List
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IntMap
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Data.Coerce

main :: IO ()
main = do
  x <- read <$> getLine :: IO Int
  putStrLn $ if x `elem` [3,5,7] then "YES" else "NO"

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

int main()
{
    long long n;
    cin>>n;
    long long sum = n*(n-1)/2;
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main extends App {
  val in = new Scanner(System.in)
  val V = in.nextInt()
  val E = in.nextInt()
  val dinitz = new Dinitz(V)
  for (_ <- 0 until E) {
    val s = in.nextInt()
    val t = in.nextInt()
    val c = in.nextInt()
    dinitz.addEdge(s, t, c)
    //    dinitz.addEdge(t, s, c)
  }

  val f = dinitz.maxFlow(0, V - 1)
  println(f)
}

import java.util

class Dinitz(val V: Int) {

  class Edge(var to: Int, var cap: Long, var rev: Int)

  private val deque = new util.ArrayDeque[Integer]
  private var g = new util.ArrayList[util.ArrayList[Dinitz#Edge]](V)
  private var level = new Array[Int](V)
  private var iter = new Array[Int](V)
  for (_ <- 0 until V) g.add(new util.ArrayList[Dinitz#Edge])


  def addEdge(from: Int, to: Int, cap: Long): Unit = {
    g.get(from).add(new Edge(to, cap, g.get(to).size))
    g.get(to).add(new Edge(from, 0, g.get(from).size - 1))
  }

  private def dfs(v: Int, t: Int, f: Long): Long = {
    if (v == t) return f

    while ( {
      iter(v) < g.get(v).size
    }) {
      val e = g.get(v).get(iter(v))
      if (e.cap > 0 && level(v) < level(e.to)) {
        val d = dfs(e.to, t, Math.min(f, e.cap))
        if (d > 0) {
          e.cap -= d
          g.get(e.to).get(e.rev).cap += d
          return d
        }
      }

      {
        iter(v) += 1;
        iter(v) - 1
      }
    }
    0
  }

  private def bfs(s: Int): Unit = {
    util.Arrays.fill(level, -1)
    level(s) = 0
    deque.add(s)
    while ( {
      !deque.isEmpty
    }) {
      val v = deque.poll
      import scala.collection.JavaConversions._
      for (e <- g.get(v)) {
        if (e.cap > 0 && level(e.to) < 0) {
          level(e.to) = level(v) + 1
          deque.add(e.to)
        }
      }
    }
  }

  def maxFlow(s: Int, t: Int): Long = {
    var flow = 0L

    while (true) {
      bfs(s)
      if (level(t) < 0) return flow
      util.Arrays.fill(iter, 0)

      var f = 1L
      while (f > 0) {
        f = dfs(s, t, Long.MaxValue)
        flow += f
      }
    }

    throw new IllegalStateException()
  }
}

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

int main(){
	int m, d;
	cin >> m >> d;
	int cnt = 0;
	for( int i = 1; i <= m; ++i){
		for( int j = 1; j <= d; ++j){
			int d1, d10, tmp;
			d1 = j % 10;
			tmp = j / 10;
			d10 = tmp % 10;
			if( d1 >= 2 && d10 >= 2){
				if( i == d1 * d10){
					cnt++;
				}
			}
		}
	}
	cout << cnt << endl;
	return 0;
}


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

int main() {
    string s;
    cin >> s;
    int ans = 0;
    if(s[0] == '1') ans++;
    if(s[1] == '1') ans++;
    if(s[2] == '1') ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std;
#define rep(i, s, t) for(int i = (s); i <= (t); i++)
#define dwn(i, s, t) for(int i = (s); i >= (t); i--)

int read() {
	int x = 0, f = 1; char c = getchar();
	while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
	while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
	return x * f;
}

#define maxn 5010
#define maxm 210
#define LL long long

int n, m, A[maxn], d[maxn][maxm], mxd[maxn][maxm], nowmx[maxm], lid[maxn];
LL mxsum[maxn];

int main() {
	srand(10);
	
	n = read(); m = read();
	rep(i, 1, n - 1) A[i] = read();
	rep(i, 1, n) rep(j, 1, m) d[i][j] = read();
	
	dwn(i, n, 1) rep(j, 1, m) mxd[i][j] = max(mxd[i+1][j], d[i][j]), mxsum[i] += mxd[i][j];
	LL ans = 0;
	rep(i, 1, n) lid[i] = i; random_shuffle(lid + 1, lid + n + 1);
	rep(L, 1, n) {
		int l = lid[L];
		memset(nowmx, 0, sizeof(nowmx));
		LL nowdis = 0;
		rep(r, l, n) {
			LL sum = 0;
			rep(i, 1, m) nowmx[i] = max(nowmx[i], d[r][i]), sum += nowmx[i];
			ans = max(ans, sum - nowdis);
			if(ans >= mxsum[l] - nowdis) break;
			nowdis += A[r];
		}
	}
	
	printf("%lld\n", ans);
	return 0;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a, v, b, w;
    cin >> a >> v >> b >> w;
    ll t;
    cin >> t;
    ll c = abs(a - b);
    ll x = v - w;
    if(t * x >= c) cout << "YES\n";
    else cout << "NO\n";

    return 0;
}

Measured memory_bytes: 3608
package main
import(
  "fmt"
)
func main(){
  var s string
  var i int
  fmt.Scan(&s)
  n:=len(s)
  flag:=0
  temp:=0
  for i=0;i<n;i++{
    if i==0{
      if s[i]=='A'{
        flag++
      }
    }else if i>=2 && i<=n-2{
      if s[i]=='C'{
        temp++
        flag++
      }else if s[i]>='a' && s[i]<='z'{
        flag++
      }
    }else if s[i]>='a' && s[i]<='z'{
      flag ++
    }
  }
  if flag==n && temp==1{
    fmt.Println("AC")
  }else{
    fmt.Println("WA")
  }
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
ld eps=1e-9;

int dx[6] = { -1,-1,0,1,1,0 };
int dy[6] = { 0,-1,-1,0,1,1 };
struct aa {
	int x;
	int y;
	int turn;
};
int main() {
	while (1) {
		int T, N; cin >> T >> N;
		if (!T)break;
		set<pair<int, int>>mp;
		for (int i = 0; i < N; ++i) {
			int x, y; cin >> x >> y;
			mp.emplace(x, y);
		}
		int sx, sy; cin >> sx >> sy;
		queue<aa>que;
		que.push(aa{ sx,sy,0 });
		mp.emplace(sx, sy);
		while (!que.empty()) {
			aa atop(que.front());
			que.pop();
			if (atop.turn == T)continue;
			else {
				for (int i = 0; i < 6; ++i) {
					int nx = atop.x + dx[i];
					int ny = atop.y + dy[i];
					if (mp.find(make_pair(nx, ny)) == mp.end()) {
						mp.emplace(nx, ny);
						que.push(aa{ nx,ny,atop.turn + 1 });
					}
				}
			}
		}
		int ans = mp.size() - N;
		cout << ans << endl;
	}
	return 0;
}

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

#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout if (false) cout
#define debug() if (false)
#define dvout(v) if(false) vout(v)
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v)           \
	for (auto &i : v)     \
	{                     \
		cout << i << " "; \
	}                     \
	cout << "\n"; //配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vecll(v, n) vector<ll> v(n, 0);
#define vecvec(v,n,m) vector<vector<int>> v(n, vector<int>(m));
#define vin(v)        \
	for (auto &i : v) \
		cin >> i; //配列入力

#define mod (int)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\n"
#define _n2 "\n\n"
#define _t "\t"

//	LLONG_MAX 9.2*1e18
//	O(1e7) O(1e8)

void Main()
{
	int N;
	cin>>N;
	vector<bool> c(N);
	rep(i,N){
		char t;
		cin>>t;
		c[i] = (t=='R');
	}
	
	int l=0,r=N-1;
	ll cnt=0;
	while(1){
		for(;l<N;l++)if(!c[l])break;
		for(;r>l;r--)if(c[r])break;
		if(l>=r)break;
		cnt++;
		l++;r--;
	}

	cout<<cnt<<_n;
}


void Test();
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

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

using namespace std;

typedef struct City
{
  int y, idx;
  City(){};
  City(int a,int b):y(a), idx(b){}
}City;
int main()
{
  int n, m;
  cin >> n >> m;
  vector<vector<City>> P(n);
  rep(i, m)
  {
    int p, y;
    cin >> p >> y;
    P[p-1].emplace_back(City{y, i});
  }
  vector<pair<int, int>> ans(m);
  rep(i, n)
  {
    sort(P[i].begin(), P[i].end(), [](City l, City r){return l.y < r.y;});
    for(int j = 0; j < P[i].size(); ++j)
    {
      ans[P[i][j].idx] = make_pair(i+1, j+1);
    }
  }
  rep(i, m)
    printf("%06d%06d\n", ans[i].first, ans[i].second);

  return 0;
}


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

int main(){
  int a,b;
  cin >> a >> b;
  int c = a * b;
  if (c % 2 == 0){
    cout << "Even" << endl;
  }
  else if (c % 2 == 1){
    cout << "Odd" << endl;
  }
           }

Measured memory_bytes: 3592
s = input()
t = input()

flag = False
for i in range(len(s)):
    st =""
    st = s[-1] + s[0:len(s)-1]
    if t == st:
        print("Yes")
        flag = True
        break
    s = ""
    s = st
    st = ""

if flag == False:
    print("No")


Measured memory_bytes: 3060
n,k = map(int,input().split())
w = []
for i in range(0,n):
	w.append(int(input()))

def check(p):
	i = 0
	for j in range(0,k):
		sm = 0
		while sm + w[i] <= p:
			sm = sm + w[i]
			i = i + 1
			if i == n:
				return n
	return i


def solve():
	r = 1000000000
	l = 0
	while r-l > 1:
		mid = int((r+l)/2)
		v = check(mid)
		if(v >= n):
			r = mid
		else:
			l = mid
	return r

print(solve())


Measured memory_bytes: 9556
N, M, K = gets.chomp.split.map(&:to_i)
aAry = gets.chomp.split.map(&:to_i)
bAry = gets.chomp.split.map(&:to_i)

aSubtotals = [0]
aAry.each do |a|
    aSubtotals.push(aSubtotals[-1] + a)
end

bSubtotals = [0]
bAry.each do |b|
    bSubtotals.push(bSubtotals[-1] + b)
end

ans = 0
bestJ = M
0.upto(N) do |i|
    break if aSubtotals[i] > K
    bestJ.downto(0) do |j|
        if aSubtotals[i] + bSubtotals[j] <= K then
            ans = [ans, (i + j)].max
            bestJ = j
            break
        end
    end
end
puts ans

# ans = 0
# (N + 1).times do |n|
#     (M + 1).times do |m|
#         if aAry[0, n].sum + bAry[0, m].sum <= K then
#             ans = n + m if ans < n + m
#         end
#     end
# end
# puts ans


Measured memory_bytes: 52512
a, b, c, x, y = map(int, input().split())

n = min(x, y)
p1 = min(n*a+n*b, 2*n*c)

nn = max(x, y) - n
if x > y:
    p2 = min(nn*a, 2*nn*c)
else:
    p2 = min(nn*b, 2*nn*c)
print(p1+p2)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int>v;
    int A[n];
    for(int i=0; i<n; i++)
        cin>>A[i];
    int m=A[0];
    for(int i=1; i<n; i++){
        if(m<A[i]){
            m=A[i];
        }
    }
    int C[m+1];
    for(int i=0; i<=m; i++){
        C[i]=0;
    }
    for(int i=0; i<n; i++){
        C[A[i]]++;
    }
    for(int i=0; i<=m; i++){
        for(int j=0; j<C[i]; j++){
            v.push_back(i);
        }
    }
    cout<<v[0];
    for(int i=1; i<v.size(); i++)
        cout<<" "<<v[i];
    cout<<endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

const int N=2e6+20;
const ll mod=1e9+7;
char s[N],t[N];
int fail[N],suf[N];

void getfail(int *fail,char *s){
	fail[0]=-1;
	int i=0,j=-1;
	while(s[i]){
		if(j==-1||s[i]==s[j]){
			fail[i+1]=j+1;
			i++,j++;
		}
		else
			j=fail[j];
	}
}
int main(){
	while(scanf("%s",s)!=EOF){
		ll ans=0;
		int len=strlen(s);
		for(int i=0;s[i];i++)	t[i]=s[len-i-1];
		t[len]='\0';
		getfail(fail,s);
		getfail(suf,t);
		int m;
		if(fail[len]==0||len%(len-fail[len]))	m=1;
		else	m=2;
		bool flag=true;
		for(int i=1;s[i];i++)
			if(s[i]!=s[i-1])	flag=false;
		if(flag)	m=len;
		if(m==1||flag)	ans=1;
		else
			for(int i=0;i<len-1;i++){
				int k=len-i-1;
				if((fail[i+1]==0||(i+1)%((i+1)-fail[i+1])) &&(suf[k]==0||(k)%(k-suf[k])))	ans++;
			}
		cout<<m<<endl<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
 int N;
 cin>>N;
 vector<int>A(N),B(N);
 for(int i=0;i<N;i++){
   cin>>A[i];
   B[i]=abs(A[i]);
 }
 int cntm=0;int64_t sum=0;
 for(int i=0;i<N;i++){
   if(A[i]<0){cntm++;}
   sum+=B[i];
 }
 if(cntm%2==0){cout<<sum<<endl;}
 else{cout<<sum-2**min_element(B.begin(),B.end())<<endl;;}

  return 0;
}

Measured memory_bytes: 4044
#include <iostream>
#include <math.h>
using namespace std;

int main() {
    int A, B;
    cin >> A >> B;

    int C, D;
    D = 0;

    for (int i = 0; i < 2; i++) {
        C = max(A, B);
        D += C;

        if (C == A) {
            A --;
        } else {
            B --;
        }
    }

    cout << D << endl;
}

Measured memory_bytes: 256