akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        int H = Integer.parseInt(sc.next());
        int W = Integer.parseInt(sc.next());
        final int N = Integer.parseInt(sc.next());
        sc.close();

        int sum = 0;
        int cnt = 0;
        while (sum<N) {
            if (H>=W) {
                sum += H;
                W--;
            } else {
                sum += W;
                H--;
            }
            cnt++;
        }

        System.out.println(cnt);
    }
}

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

using namespace std ;

int main()
{
    long n , k ;
    cin >> n >> k ;
    
    long a[n] ;
    
    for( long i=0 ; i<n ; i++)
    cin >> a[i];
    
    long long dp[n] ;
    
    
    
    for( long i=0 ; i<n ; i++)
    dp[i] = 9999999999999 ;
    
    dp[0] = 0 ;
    
    for( long i=0 ; i<n ; i++)
    {
        for( long j=1 ; j<=k ; j++)
        {
            if((i+j)<n)
            {
                dp[i+j] = min( dp[i+j] , dp[i] + abs( a[i]-a[i+j]) );
            }
        }
    }
    cout << dp[n-1] ;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    ll ans = 1;
    ll p = max(b-a, 2);
    if (a > ans) {
        if (a-ans >= k) {
            cout << 1+k << endl;
            return 0;
        }
        else {
            k -= a-ans;
            ans += a-ans;
        }
    } 
    ans += k/2 * p;
    k -= k/2 * 2;
    if (k == 1) ans++;

    cout << ans << endl;
    return 0;
}

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

#define mp make_pair
#define X first
#define Y second
#define FOE(x, a) for(auto x : a)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FOD(i, a, b) for(int i = a; i >= b; i--)

using namespace std;

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


const int N = 1e6 + 10;
const int MOD = 1e9 + 7;

int n;
ll f[N], sF[N];

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

    cin >> n;
    f[0] = f[1] = f[2] = 1;
    sF[0] = 1, sF[1] = 2, sF[2] = 3;
    FOR(i, 3, n){
        f[i] = (f[i - 1] + sF[i - 3]) % MOD;
        sF[i] = (sF[i - 1] + f[i]) % MOD;
    }

    ll ans = (f[n] + f[n - 1] * (n - 1)) % MOD;

    FOR(i, 1, n - 1)
        ans = (ans + (i + (ll) (n - 1) * (n - 1)) % MOD * f[i - 1] % MOD) % MOD;

    cout << ans;

    return 0;
}



Measured memory_bytes: 19200
#include<cstdio>
#include<algorithm>
int n,a[300100];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	std::sort(a+1,a+n+1);
	if(a[1]==0&&a[n]==0)return puts("Yes"),0;
	if(n%3!=0)return puts("No"),0;
	if(a[1]!=a[n/3]||a[n/3+1]!=a[n/3*2]||a[n/3*2+1]!=a[n])return puts("No"),0;
	if(a[n/3]^a[n/3*2]^a[n])return puts("No"),0;
	puts("Yes");
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)




int main(){
    int h,w; cin>>h>>w;
    vector<vector<int>> c(10, vector<int> (10,0));
    rep(i,10) rep(j,10) cin>>c[i][j];
    vector<vector<int>> p(h,vector<int>(w));
    rep(i,h) rep(j,w) cin>>p[i][j];
    vector<vector<int>> mipath(10, vector<int>(10,0));
    mipath=c;
    rep(kk,10){
      rep(i,10){
        rep(j,10){
          chmin(mipath[i][j], mipath[i][kk]+mipath[kk][j]);
        }
      }
    }
    int ans=0;
    rep(i,h){
      rep(j,w){
        if(p[i][j]==-1) continue;
        if(p[i][j]!=1){
          ans+=mipath[p[i][j]][1];
        }
      }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define ll  long long 
#define ull unsigned long long int
#define boost ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL)
#define vi vector<int>
#define P push_back
#define F first
#define S second
#define debug(x) cout<<x<<" "
#define pi vector<pair<int,int> >
#define all(a) a.begin(),a.end()
#define int ll
#define vvi vector<vector<int>>
using namespace std;
using namespace __gnu_pbds;
typedef tree <pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll const mod=1e9+7;
int powi(int i,int b){
    int res=1;
    while(b){
        if(b&1)res*=i,res%=mod;
        b>>=1;
        i*=i;
        i%=mod;
    }
    return res;
}
// map<int,int> m;
// ll fact(int n){
// 	//if(n==0)return 0;
// 	if(n<=1)return 1;
// 	if(m[n]!=0)return m[n];
// 	return (n*fact(n-1))%mod;
// }
// int ncr(int n,int r){
//     int h=fact(n);
//     int v=fact(r);
//     int j=fact(n-r);
//     v*=j;
//     v%=mod;
//     v=powi(v,mod-2);
//     return (h*v)%mod;
// }
// vi ar(2000000);
// vi sz(2000000);
// int root(int a){
//     if(ar[a]==a)return a;
//     return ar[a]=root(ar[a]);
// }
// int merge(int a,int b){
//     int h=root(a),j=root(b);
//     int ans=sz[h]*sz[j];
//     sz[j]+=sz[h];
//     if(h!=j){
//         ar[h]=j;
//     }
//     return ans;
// } 
void solve(){
    string s,t;
    cin>>s>>t;
    int ans=0;
    for(int i=0;i<s.length();i++){
        ans+=(s[i]!=t[i]);
    }
    cout<<ans;
}
signed main(){
    boost;
    int t=1;
    //freopen("input.txt", "r", stdin);
    //cin>>t;
    for(int _=1;_<=t;_++){
        //cout<<"Case #"<<_<<": ";
        solve();
        cout<<"\n";
    }
    
    return 0;
}

Measured memory_bytes: 3780
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {

static long[] list=new long[87];

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

   String nyuA=sc.nextLine();
//  String nyuB=sc.nextLine(); 
 

   String[] s=sc.nextLine().split(" ");
 //    String[] t=sc.nextLine().split("");

int N=Integer.parseInt(nyuA);
//int B=Integer.parseInt(nyuB);

int[] num=new int[N];
for(int i=0;i<N;i++){
num[i]=Integer.parseInt(s[i]);
}
Arrays.sort(num);

int Ali=0;
int Bo=0;

int set=num.length-1;
while(true){
try{
Ali+=num[set];
set--;
Bo+=num[set];
set--;

}catch(Exception e){
break;
}

}//wh
System.out.println(Ali-Bo);



}

}



Measured memory_bytes: 21844
#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>;

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;
}

int main() {
  int n;
  cin >> n;
  int human[n];
  rep(i, n) human[i] = 0;

  rep(i, n - 1) {
    int index;
    cin >> index;
    --index;
    human[index]++;
  }
  rep(i, n) {
    cout << human[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 4384
#include<iostream>

using namespace std;

int main(){
	int n,d[10]={512,256,128,64,32,16,8,4,2,1};
	int a[10],c=0;
	while(cin>>n){
	c=0;
		for(int i=0;i<10;i++){
			a[i]=0;
			while(d[i]<=n){n-=d[i];a[i]=++c;}
		}
		
		for(int i=9;i>=0;i--){
			if(a[i]>1)cout<<d[i]<<" ";
			if(a[i]==1){cout<<d[i];}
		}
		cout<<endl;
	}

}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
int A;

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

    std::cin >> N;

    int total = 0;

    for(int i=0;i<N;++i){
        std::cin >> A;

        total += __builtin_ctz(A);
    }

    std::cout << total << std::endl;
}


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

using namespace std;

int gcd(int a, int b){
    return b ? gcd(b, a % b) : a;
}

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(auto&& i : a){
        cin >> i;
    }
    sort(begin(a), end(a));
    if(a.back() < k){
        cout << "IMPOSSIBLE\n";
        return 0;
    }
    if(binary_search(begin(a), end(a), k)){
        cout << "POSSIBLE\n";
        return 0;
    }
    int score = a[1] - a[0];
    for(int i = 1; i + 1 < n; i++){
        score = gcd(score, a[i + 1] - a[i]);
    }
    for(auto&& i : a){
        if(i < k) continue;
        if((k - i) % score == 0){
            cout << "POSSIBLE\n";
            return 0;
        }
    }
    cout << "IMPOSSIBLE\n";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

const double PI = acos(-1.0);
int main() {
    double R;
    cin >> R;
    cout << fixed << setprecision(3) << R * PI * 2 << endl;
}

















Measured memory_bytes: 3788
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

vector<vector<bool>> A;
vector<vector<bool>> T;

bool Matches(const int64_t r, const int64_t c) {
  const int64_t M = static_cast<int64_t>(T.size());
  for (int64_t i = 0; i < M; ++i) {
    for (int64_t j = 0; j < M; ++j) {
      if (A[r + i][c + j] != T[i][j]) {
        return false;
      }
    }
  }
  return true;
}

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

  int64_t N, M;
  cin >> N >> M;
  A = vector<vector<bool>>(N, vector<bool>(N));
  T = vector<vector<bool>>(M, vector<bool>(M));
  for (int64_t i = 0; i < N; ++i) {
    string a;
    cin >> a;
    for (int64_t j = 0; j < N; ++j) {
      A[i][j] = a.c_str()[j] == '.';
    }
  }
  for (int64_t i = 0; i < M; ++i) {
    string a;
    cin >> a;
    for (int64_t j = 0; j < M; ++j) {
      T[i][j] = a.c_str()[j] == '.';
    }
  }
  bool matches = false;
  for (int64_t i = 0; i < N - M + 1; ++i) {
    for (int64_t j = 0; j < N - M + 1; ++j) {
      if (Matches(i, j)) {
        matches = true;
        break;
      }
    }
  }
  cout << (matches ? string("Yes") : string("No")) << endl;
  return 0;
}


Measured memory_bytes: 256
N = input()
digits = len(N)
primal = int(N[0])
ans = 0
if set(N[1:]) == {'9'} or set(N[1:]) == set():
    ans = primal + 9*(digits - 1)
else:
    ans = primal - 1 + 9 * (digits - 1)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int n, m, t, car, lane;
deque<int>q[15];
signed main() {
	cin >> n >> m;
	for1(valsqotch, m) {
		cin >> t;
		if (t) {
			cin >> car;
			int k = q[1].size();
			for1(i, n)k = min(k, (int)q[i].size());
			for1(i, n)if (q[i].size() == k) { q[i].push_back(car); break; }
		}
		else {
			cin >> lane;
			cout << q[lane].front() << endl;
			q[lane].pop_front();
		}
	}
}


Measured memory_bytes: 3224
import math
A, B, H, M = map(int,input().split())

AA = 360 * H/12 + 30 * M/60
BB = 360 * M/60
if AA == BB:
    print(max(A-B,B-A))
elif AA > BB:
    cosC = math.cos(math.radians(AA-BB))
    print((A**2 + B**2 - 2*A*B*cosC)**0.5)
elif AA < BB:
    cosC = math.cos(math.radians(BB-AA))
    print((A**2 + B**2 - 2*A*B*cosC)**0.5)

Measured memory_bytes: 9516
#include<bits/stdc++.h>
using namespace std;
#define INS(x) x.begin(),x.end()
    

    
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    long long n,a,b;
    cin>>n>>a>>b;


    long long ans=n/(a+b)*a;
    long long mod=n%(a+b);
    if (mod>=a) cout<<ans+a;
    else cout<<ans+mod;
    return 0;
}

Measured memory_bytes: 256
A, B = map(int, input().split())
S = input()

if len(S) != A+B+1:
    print("No")
    exit()

for i in range(A+B+1):

    if i == A:
        if S[i] != "-":
            print('No')
            exit()
    else:
        if not('0' <= S[i] <= '9'):
            print('No')
            exit()
print('Yes')


Measured memory_bytes: 9112
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        m: usize,
        a: [chars; n],
        b: [chars; m]
    }
    for i in 0..n - m + 1 {
        'next: for j in 0..n - m + 1 {
            for k in 0..m {
                for l in 0..m {
                    if a[i + k][j + l] != b[k][l] {
                        continue 'next;
                    }
                }
            }
            println!("Yes");
            return;
        }
    }
    println!("No");
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

#define EPS 1e-9

int main(){
  double ax,ay,bx,by,cx,cy,dx,dy;
  double AX, AY, BX, BY, A, B;
  while(cin >> ax >> ay >> bx >> by >> cx >> cy >> dx >> dy){
    AX = ax-bx;
    AY = ay-by;
    BX = cx-dx;
    BY = cy-dy;
    A = AY/AX;
    B = BY/BX;
    if(AX == 0){
      if(BY == 0)cout << "YES" << endl;
      else cout << "NO" << endl;
      continue;
    }
    else if(BX == 0){
      if(AY == 0)cout << "YES" << endl;
      else cout << "NO" << endl;
      continue;
    }
    else cout << (A*B==-1?"YES":"NO") << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
k=N()
x=7%k
ans=1
for i in range(2*k):
    if x==0:
        print(ans)
        break
    x=x*10+7
    x%=k
    ans+=1
else:
    print(-1)

Measured memory_bytes: 63356
N, D = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(N)]
sq_d = D ** 2

count = 0
for x, y in data:
  sq_dist = x ** 2 + y ** 2
  if sq_dist <= sq_d:
    count += 1
    
print(count)

Measured memory_bytes: 45460
#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
int main(){
  int N,W,H,S,T;
  while(cin >> N , N){
    int mas[222][222];
    memset(mas,0,sizeof(mas));
    cin >> W >> H;
    for(int i=0;i<N;i++){
      int x,y; cin >> x >> y;
      x--; y--;
      mas[y][x] = 1;
    }
    cin >> S >> T;
    int maxx = 0;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	int cnt = 0;
	for(int t=0;t<T;t++){
	  for(int s=0;s<S;s++){
	    cnt += mas[i+t][j+s];
	  }
	}
	maxx = max(maxx,cnt);
      }
    }
    cout << maxx << endl;
  }
}

Measured memory_bytes: 1360
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(void) {
  string s, t;
  cin >> s >> t;
  int sn = s.size();
  int tn = t.size();

  vector<vector<int>> dp(sn + 1, vector<int>(tn + 1, 0));
  for (int i = 0; i < sn; i++) {
    for (int j = 0; j < tn; j++) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = dp[i][j] + 1;
      } else {
        dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
      }
    }
  }

  string ans;
  while (dp[sn][tn] > 0) {
    if (dp[sn][tn] == dp[sn - 1][tn]) {
      sn--;
    } else if (dp[sn][tn] == dp[sn][tn - 1]) {
      tn--;
    } else {
      sn--;
      tn--;
      ans = s[sn] + ans;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 35584
n, m = gets.split.map(&:to_i)
h = {}
n.times do
  ary = gets.split
  ary.shift
  ary.each{|i| h[i] = h[i] ? h[i] + 1 : 1 }
end
puts h.each_pair.count{|k, v| v == n }

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
long long n,m,i,j,a[4005],b[4005],ans;
int main()
{
	cin>>n>>m;
	fz1(i,n){
		cin>>a[i];
		a[i+n]=a[i];
		b[i]=a[i];
		ans+=a[i];
	}
	fz1(i,n){
		long long s=i*m;
		fz1(j,n){
			b[j]=min(b[j],a[j+n-i]);
			s+=b[j];
		}
		ans=min(ans,s);
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  int S,mod=(int)pow(10,9)+7;
  scanf("%d", &S);
  long long int a[2002] = {};
  a[3]=1;a[4]=1;a[5]=1;
  for(int i=6;i<=S;i++){
    for( int j=3;j<=i-3;j++){
      a[i] += a[i-j];
      a[i] %= mod;
    }
	a[i]++;
  }
  printf("%lld\n",a[S]);
}

Measured memory_bytes: 1748
#include<iostream>
using namespace std;
int main(){
    int n,m,k,a;
    cin >> n >> m;
    int fav[m],sum=0;
    for(int i=0;i<m;i++){
        fav[i] = 0;
    }
    for(int i=0;i<n;i++){
        cin >> k;
        for(int j=0;j<k;j++){
            cin >> a;
            fav[a-1]++;
        }
    }
    for(int i=0;i<m;i++){
        if(fav[i]==n){
            sum++;
        }
    }
    cout << sum;
}

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


int n,m,x,y;
int t[MAX];
bool flg[MAX];
int main(){
  scanf("%d %d",&n,&m);
  for(int i=1;i<=n;i++){
    t[i]=1;
    flg[i]=false;
  }
  flg[1]=true;
  
  while(m--){
    scanf("%d %d",&x,&y);
    if(flg[x]==true){
      flg[y]=true;
    }
    t[x]--;
    t[y]++;
    if(t[x]==0)flg[x]=false;
  }

  int ans=0;
  for(int i=1;i<=n;i++)
    ans+=flg[i];
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 768
<?php
 
while($line = fgets(STDIN)){
	list($h, $w) = explode(" ", trim($line));
	if($h == 0 && $w == 0){
		break;
	}
	
	$arr = array();
	for($i = 0; $i < $h; $i++){
		$arr[$i] = trim(fgets(STDIN));
	}
	
	$i = 0;		// ??????????????°
	$maxloop = $h*$w;
	$x = 0; $y = 0;
	while($i <= $maxloop){
		if($arr[$y][$x] == "^"){
			$y--;
		}else if($arr[$y][$x] == ">"){
			$x++;
		}else if($arr[$y][$x] == "v"){
			$y++;
		}else if($arr[$y][$x] == "<"){
			$x--;
		}else{
			$arr[$y][$x] = ".";
			break;
		}
		$i++;
	}
	if($arr[$y][$x] == "."){
		echo "{$x} {$y}\n";
	}else{
		// ???????????????
		echo "LOOP\n";
	}
}

Measured memory_bytes: 15440
n=gets.to_i

ans=0;ba=0;a=0;b=0
n.times do |i|
  s=gets.chomp
  ans=ans+s.scan('AB').size
  if s[0]=='B' && s[-1]=='A'
    ba=ba+1
  elsif s[0]=='B'
    b=b+1
  elsif s[-1]=='A'
    a=a+1
  end
end

if ba==0
  ans=ans+[a,b].min
else
  if a+b>0
    ans=ans+ba+[a,b].min
  else
    ans=ans+ba-1
  end
end

puts ans

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

int main() {
	unsigned int n, m;
	unsigned long long p = 0;
	vector<pair<unsigned long, unsigned int>> ab;

	cin >> n >> m;

	for (unsigned int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		ab.push_back(make_pair(a, b));
	}

	sort(ab.begin(), ab.end());

	for (unsigned int i = 0; i < n; i++) {
		if (ab[i].second < m) {
			p += ab[i].first * ab[i].second;
			m -= ab[i].second;
		}
		else {
			p += ab[i].first * m;
			break;
		}

	}
	
	cout << p << endl;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    int tmp = h[0];
    vector<int> list;
    list.push_back(0);
    rep(i, n - 1)
    {
        if(h[i+1]>=tmp){
            tmp = h[i + 1];
            list.push_back(i+1);
        }

    }
    rep(i,list.size()){
     h[list[i]]--;
    }
    rep(i,n-1){
        tmp = h[i];
        if (tmp > h[i + 1])
        {
            cout << "No" << endl;
        return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 1276
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    S = input()
    cnt = [0, 0, 0]
    for s in S:
        if s == "a":
            cnt[0] += 1
        elif s == "b":
            cnt[1] += 1
        else:
            cnt[2] += 1
    if max(cnt) - min(cnt) > 1:
        print("NO")
    else:
        print("YES")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	long long int m=0;
	vector<int> v;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		v.push_back(x);
	}
	long long int ans=0;
	for(int i=0;i<n;i++)
	{
		if(v[i]>m)
		{
			m=v[i];
		}
		else
		{
			ans+=(m-v[i]);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4316
#include<iostream>
#include<stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
  //整数の時はint
  //int a,b,m;
  //文字の時はstring
  string a;
 
  cin>>a;
 
    if(a=="ABC")
  cout<<"ARC"<<endl;
    if(a=="ARC")
  cout<<"ABC"<<endl; 
  else
    cout<<""<<endl;
 
  return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;cin>>a>>b>>c>>d;
  if(abs(c-a)<=d or (abs(b-a)<=d && abs(c-b)<=d))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str= sc.next();
		str = str.replaceAll("9", "A");
		str = str.replaceAll("1", "9");
		str = str.replaceAll("A", "1");
		System.out.println(str);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
struct comb {
    vector<mint> fact, ifact;
    comb(int n) :fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

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

int main() {
	init();

	int H, W; cin >> H >> W;
    vector<string>maze(H);
    rep(i, 0, H)cin >> maze[i];
    vector<vector<mint>>dp(H, vector<mint>(W, 0));
    dp[0][0] = 1;
    rep(i, 0, H) {
        rep(j, 0, W) {
            if (maze[i][j] == '#')continue;
            rep(k, 0, 2) {
                int nx = j + dx[k], ny = i + dy[k];
                if (out(ny, nx, H, W)) {
                    continue;
                }
                dp[ny][nx] += dp[i][j];
            }
        }
    }
    cout << dp[H - 1][W - 1].x << "\n";

	return 0;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
    double n,t,a;
    cin >> n >> t >> a;
    vector<double> h(n);
    rep(i,n) cin >> h[i];
    rep(i,n) h[i]=t-h[i]*0.006;

    double min = pow(10,5);
    int index;
    rep(i,n){
        double t = abs(h[i]-a);
        if(min>t) {
            index = i;
            min = t;
        }
    }
    cout << index+1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	string S,T,U;
	int A,B;
	scan(S>>T>>A>>B>>U);
	if(S==U) A--;
	else B--;
	printf("%d %d\n",A,B);
	return 0;
}


Measured memory_bytes: 768
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define MODNUM (INT(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

template <typename T>
int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T>
void chmax(T& m, T x) {
	m = max(m, x);
}

template <typename T>
void chmin(T& m, T x) {
	m = min(m, x);
}

template <typename T>
T square(T x) {
	return x * x;
}

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int top_digit(int n) {
	while(n / 10 > 0) {
		n /= 10;
	}
	return n;
}

int bottom_digit(int n) {
	return n % 10;
}

int kirisage(int n) {
	int ret = 1;
	while(ret * 10 < n) {
		ret *= 10;
	}
	return ret;
}

int count(int n, int y, int x) {
	int ret = 0;

	RANGE(i, 1, n + 1) {
		int top = top_digit(i);
		int bottom = bottom_digit(i);
		if(top == y && bottom == x) {
			ret++;
		}
	}
	return ret;
}
int main() {
	int n;
	scanf("%d", &n);
	VI2D num(10, VI(10, 0));
	RANGE(i, 1, 10) {
		RANGE(j, 1, 10) { num[i][j] = count(n, i, j); }
	}
	ll result = 0;
	RANGE(i, 1, 10) {
		RANGE(j, 1, 10) { result += (num[i][j] * num[j][i]); }
	}

	printf("%lld\n", result);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 998244353
using namespace std;
typedef pair<llint, llint> P;
typedef pair<llint, P> E;

struct edge{
	llint to, cost;
	edge(){}
	edge(llint a, llint b){
		to = a, cost = b;
	}
};

struct UnionFind{
	int size;
	vector<int> parent;
	
	UnionFind(){}
	UnionFind(int size){
		this->size = size;
		parent.resize(size+1);
		init();
	}
	void init(){
		for(int i = 0; i <= size; i++) parent[i] = i;
	}
	int root(int i){
		if(parent[i] == i) return i;
		return parent[i] = root(parent[i]);
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	void unite(int i, int j){
		int root_i = root(i), root_j = root(j);
		if(root_i == root_j) return;
		parent[root_i] = root_j;
	}
};

llint n, m, Q;
vector<E> vec;
vector<edge> G[4005];
UnionFind uf(4005);
llint dist[4005][4005];

void dfs(int v, int p, llint m, llint s)
{
	dist[s][v] = m;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i].to == p) continue;
		dfs(G[v][i].to, v, max(m, G[v][i].cost), s);
	}
}

int main(void)
{
	cin >> n >> m;
	llint u, v, w;
	for(int i = 1; i <= m; i++){
		cin >> u >> v >> w;
		vec.push_back(E(w, P(u, v)));
	}
	sort(vec.begin(), vec.end());
	
	llint ans = 0;
	for(int i = 0; i < vec.size(); i++){
		w = vec[i].first, u = vec[i].second.first, v = vec[i].second.second;
		if(uf.same(u, v)) continue;
		uf.unite(u, v);
		ans += w;
		G[u].push_back(edge(v, w));
		G[v].push_back(edge(u, w));
	}
	
	for(int i = 1; i <= n; i++) dfs(i, -1, 0, i);
	
	cin >> Q;
	llint s, t;
	for(int i = 1; i <= Q; i++){
		cin >> s >> t;
		cout << ans - dist[s][t] << endl;
	}
	
	return 0;
}


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

#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__) << "] "

typedef long long LL;

const LL INF = 1e18L;
const int maxn = 1e5+1;

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

    int N, W, w, v;
    cin >> N >> W;
    LL dp[maxn];
    fill_n(dp, maxn, INF);

    dp[0] = 0;
    for (int i = 0; i < N; ++i) {
        cin >> w >> v;
        for (int j = maxn-1; j >= v; --j) {
            dp[j] = min(dp[j], dp[j-v]+w);
        }
    }

    for (int j = maxn-1; j >= 0; --j) {
        if (dp[j] <= W) {
            cout << j << endl;
            break;
        }
    }

    return 0;
}



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

typedef struct _Node {
  int key;
  struct _Node *next, *prev;
} Node;

Node *nil;

Node* listSearch(int key) {
  Node *cur = nil->next;
  while(cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}

void init(void) {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(void) {
  Node *cur = nil->next;
  int isf = 0;
  while(1) {
    if(cur == nil) break;
    if(isf++>0) printf(" ");
    printf("%d",cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t) {
  if(t==nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(void) {
  deleteNode(nil->next);
}

void deleteLast(void) {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}

void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(void) {
  int key, n, i;
  char com[20];
  scanf("%d", &n);
  init();
  for(i=0;i<n;i++) {
    scanf("%s%d",com, &key);
    if (com[0] == 'i') insert(key);
    else if(com[0] == 'd') {
      if(strlen(com) > 6) {
        if(com[6] == 'F')
          deleteFirst();
        else if(com[6] == 'L') deleteLast();
      } else deleteKey(key);
    }
  }
  printList();
  return 0;
}


Measured memory_bytes: 32964
#include <iostream>
using namespace std;
int main(){
  int a;
  cin >> a;
  string s;
  cin >> s;
  if(a<s.length()){
    for(int i=0;i<a;i++){
      cout << s[i];
    }
    cout << "..." << endl;
  }else{
    cout << s << endl;
  }
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(void){
  int x;
  vector<int>vec;

  for(int i=0;i<5;i++){
    cin >> x;
    vec.push_back(x);
  }
  sort(vec.begin(),vec.end(),greater<int>());
  for(vector<int>::iterator ite=vec.begin();ite!=vec.end();ite++){
    cout << *ite;
    if(ite+1!=vec.end())cout <<" ";
    else cout << endl;
  }
  return 0;
}

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

int main() {
	int n=0,h,i,k,s;
	cin >> k >> s;
	for(h=0;h<=k;h++){
		if(h==s){
			n++;
			goto skip1;
		}
		for(i=0;i<=k;i++){
				if(h+i==s){
					n++;
					goto skip;
				}
				else if(h+i+k>=s){
					n++;
				}
			}
		skip:;
		}
skip1:;

	cout << n << "\n";
}


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

int main(void){
	char s[4];
	int x=0;
	cin >> s[0] >> s[1] >> s[2] >> s[3];
    for(int i=0;i<4;i++){
    	if(s[i]=='+')x++;
    	else x--;
	}

    cout << x << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define f(i,n) for(int i=0;i<int(n);i++)
#define MOD 1000000007
#define N 200000

int main(){	
	int a,b,c,d;
    cin>>a>>b>>c>>d;

    int sum = 0;
    sum = b*c + (a-b)*d;
    if(a<b) sum = a*c;
    cout<<sum;
}

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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    ll n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;

    ll target = b - a;

    rep(i, n) {
        ll hi = (n - i - 1) * d - i * c;
        ll lo = (n - i - 1) * c - i * d;
        // cout << lo << " " << target << " " << hi << endl;
        if (lo <= target and target <= hi) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define chal ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lli long long
using namespace std;
int main()
{
    int n,k,p=0;
    cin>>n>>k;
    int a[n],i;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    i=0;
    while(k--)
    {
        p+=a[i++];
    }
    cout<<p;
    return 0;
}


Measured memory_bytes: 3628
<?php
  fscanf(STDIN,"%d",$n);
  fscanf(STDIN,"%d",$k);
$num=explode(" ",fgets(STDIN));
$arr=array();
for($i=0;$i<$n;$i++){
	$arr[$i]=intval($num[$i]);
}
$sum=0;
for($i=0;$i<$n;$i++){
	$min=$arr[$i];
  	$min=min($arr[$i],$k-$arr[$i]);
    $min=2*$min;
    $sum =$sum+$min;
}
echo $sum.PHP_EOL;

Measured memory_bytes: 3576
#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-1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9+7;
const ll INF = 1e18;
const int MAX = 1e6;

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

struct edge {int to, cost;}; // 辺
// vector<edge> graph[MAX]; // 隣接リスト
bool visited[MAX]; // 訪問状況

int n, m; // 変数
ll k;
int a[MAX];

int main() {
// input
    cin >> n >> k;
    rep(i, n+1) {
        if (i > 0) cin >> a[i];
    }
// solve
    int cnt = 1; // ループに突入するテレポート回数
    int start = 1;
    visited[start] = true;
    int next = a[start];
    while (not visited[next]) {
        cnt++;
        visited[next] = true;
        next = a[next];
    }
    int loop_start = next; // ループの始点
    // printf("ループに突入するテレポート回数%d\n", cnt);
    // printf("ループの始点%d\n", next);
    int ans;
    if (cnt < k) {
        next = 1; // 再度1からスタート
        int d = 0; // ループの始点までに訪問する都市の数
        while (next != loop_start) {
            d++;
            next = a[next];
        }
        int loop_size = cnt - d; // ループの大きさ
        // printf("ループの大きさ%d\n", loop_size);
        int pos = 1;
        rep(i, d) {
            pos = a[pos]; // とりあえずループの始点までテレポート
        }
        // if (loop_size == 0) {
        //     ans = pos;
        // } else {
            rep(i, (k-d)%loop_size) { // 始点から余りの分だけテレポート
                pos = a[pos];
            }
            ans = pos;
        // }
    } else {
        int pos = 1;
        rep(i, k) {
            pos = a[pos];
        }
        ans = pos;
    }
// output
    cout << ans << "\n";
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int gcd(int a, int b) {
  if(b == 0) return a;
  else return gcd(b, a%b);
}

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

  int n; cin >> n;
  vi v(n), c(n);
  for(int i=0;i<n;++i) {
    cin >> v[i];
  }
  for(int i=0;i<n;++i) {
    cin >> c[i];
  }

  int ans = 0;
  for(int i=0;i<n;++i) {
    ans += max(0, v[i] - c[i]);
  }
  cout << ans << endl;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  for(int i = k; i < n; i++){
    if(a[i] > a[i-k]){
    cout << "Yes" << endl;
    } else {
    cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 4048
public class Main {

  private static void solve() {
    int n = ni();
    int x = 0;
    int[] b = new int[32];
    for (int i = 0; i < n; i ++) {
      int a = ni();
      x ^= a;
      for (int j = 0; j < 32; j ++) {
        if (((a >> j) & 1) == 1) {
          b[j] ++;
          break;
        }
      }
    }

    int ret = 0;
    for (int i = 31; i >= 0; i --) {
      if (((x >> i) & 1) == 1) {
        if (b[i] == 0) {
          System.out.println(-1);
          return;
        }
        x = x ^ ((1 << (i + 1)) - 1);
        ret ++;
      }
    }
    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = System.getProperty("debug");
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

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

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 36924
#include <stdio.h>
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
char buf[(1 << 22)], *p1 = buf, *p2 = buf;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int ab[(1<<17)];
int main(int argc, char *argv[])
{
	int n = read(),m = read();
	for (int i = 0; i < m; ++i) {
		int a = read(),b = read();
		if (*(ab+b) < a) {*(ab+b) = a;}
	}
	int ans = 0;
	int k = 1;
	for (int i = 1; i <= n; ++i) {
		if (k <= *(ab+i)) {
			k = i;
			++ans;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1792
a, b, c = map( int, input().split() )
k = int( input() )

def solve( a, b, c, k ):
    if a < b and b < c:
        print( "Yes" )
        exit()
    elif k == 0:
        return
    else:
        solve( 2 * a, b, c, k - 1 )
        solve( a, 2 * b, c, k - 1 )
        solve( a, b, 2 * c, k - 1 )

solve( a, b, c, k )
print( "No" )

Measured memory_bytes: 9188
S = input()
N = len(S)

MOD = 2019
mod_cnt = [0]*MOD
mod_cnt[0] = 1
k = 0.1
t = 0
for i in range(1, N+1):
    k = int(k * 10) % MOD
    t = (t + k * int(S[-i])) % MOD
    mod_cnt[t] += 1
ans = 0
for cnt in mod_cnt:
    ans += (cnt * (cnt-1)) // 2
print(ans)


Measured memory_bytes: 68440