akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;

int main(){
  long long X;
  cin >> X;
  int happy = 0;
  
  while(X>=500){
    happy += 1000;
    X -=500;
  }
  while(X>=5){
    happy += 5;
    X -=5;
  }
  cout << happy << endl;
}

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

using namespace std;

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

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];

    long long sum_a = 0;
    long long min_a = abs(a[0]);
    int count_minus = 0;
    for (int i = 0; i < n; i++)
    {
        const long long now_a = abs(a[i]);
        sum_a += now_a;
        min_a = min(now_a, min_a);
        if(a[i]<0)
            count_minus++;
    }

    if(count_minus%2==0)
    {
        cout << sum_a << endl;
        return 0;
    }
    else
    {
        cout << sum_a - min_a*2 << endl;
        return 0;
    }

    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
int main() {
    int x, y; 
    int t;
    for (;;) {
        scanf("%d%d", &x, &y);
        if (x == 0 && y == 0) 
        break;
        if (x > y) t = x, x = y, y = t;
        printf("%d %d\n", x, y);
        } 
        return 0; 
    
} 



Measured memory_bytes: 2028
def main():
    n, x = map(int, input().split())
    inix = x
    a = sorted(list(map(int, input().split())))
    if a[0] > x:
        print(0)
        exit()
    elif sum(a) == x:
        print(n)
        exit()
    ans = 0
    for i in range(n):
        if x >= a[i]:
            x -= a[i]
            ans += 1
        else:
            break
    if x != 0 and ans == n:
        ans-=1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int g1[4][4] = {
  {0, 1, 2, 3},
  {0, 1, 2, 3},
  {2, 3, 0, 1},
  {2, 3, 0, 1},
};

int main() {
  int h, w, d;
  cin >> h >> w >> d;

  vector<string> ans(h, string(w, 0));

  string x = "RYGB";

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int b = (i + j) / d % 2;
      int c = (i - j + d * 1000) / d % 2;
      ans[i][j] = x[(b + c * 2) % 4];
    }
  }
  for (string s : ans) cout << s << endl;
}

Measured memory_bytes: 768
X=int(input())
dp=['']*(X+1)
for i in range(X+1):
    if i==0:
        dp[0]=1
    elif i<100:
        dp[i]=0
    else:
        if 1 in [dp[i-100],dp[i-101],dp[i-102],dp[i-103],dp[i-104],dp[i-105]]:
            dp[i]=1
        else:
            dp[i]=0
print(dp[X])

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

const int MAX_N = 100;
int to[MAX_N][MAX_N];
int ans[MAX_N];
bool visited[MAX_N];

int main() {
  int N;
  cin >> N;
  for (int i=0; i<N; i++) {
    for (int j=0; j<N; j++) {
      to[i][j] = -1;
    }
    ans[i] = -1;
    visited[i] = false;
  }
  for (int i=0; i<N; i++) {
    int tmp, n;
    cin >> tmp >> n;
    for (int j=0; j<n; j++) {
      int t;
      cin >> t; t--;
      to[i][j] = t;
    }
  }

  queue<pair<int, int> > que;
  que.push(make_pair(0, 0));
  while (!que.empty()) {
    pair<int, int> tmp = que.front(); que.pop();
    int x = tmp.first, depth = tmp.second;
    if (ans[x] == -1) {
      ans[x] = depth;
    } else {
      continue;
    }
    for (int i=0; to[x][i] != -1; i++) {
      que.push(make_pair(to[x][i], depth + 1));
    }
  }

  for (int i=0; i<N; i++) {
    cout << i+1 << " " << ans[i] << endl;
  }
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  int sum = 0;
  sum += N / 100000000;
  sum += (N % 100000000 - N % 10000000) / 10000000;
  sum += (N % 10000000 - N % 1000000) / 1000000;
  sum += (N % 1000000 - N % 100000) / 100000;
  sum += (N % 100000 - N % 10000) / 10000;
  sum += (N % 10000 - N % 1000) / 1000;
  sum += (N % 1000 - N % 100) / 100;
  sum += (N % 100 - N % 10) / 10;
  sum += N % 10;
  N %= sum;
  
  if (N != 0) {
    cout << "No" << endl;
  }
  
  else {
    cout << "Yes" << endl;
  }
 
}


Measured memory_bytes: 256
#include <stdio.h>

#define PRIME_MAX 1000000
int getprimes(int list[], int top){
    int i, j;
    int index = 0;
    char tmp[PRIME_MAX];

    for(i=0;i<top;i++) {
        tmp[i] = 1;
    }
   
    tmp[0] = tmp[1] = 0;
    for(i=2;i<top;i++) {
        if(tmp[i] == 1) {
            /* 素数 */
            list[index] = i;
            index ++;
            for(j=2;j*i<top;j++) {
                tmp[j*i] = 0;
            }
        }
    }

    list[index] = -1;
    return index;
}

int main(void) {
    int i;
    int n;
    int size;
    int primes[100000];
    size = getprimes(primes, PRIME_MAX);
   
    while(scanf("%d\n", &n) == 1) {
        for(i=0;i<size;i++) {
        	if(primes[i] == n) {
            	printf("%d %d\n", primes[i-1], primes[i+1]);
            	break;
        	} else if(primes[i] > n) {
            	printf("%d %d\n", primes[i-1], primes[i]);
            	break;
            }
        }
    }
   
    return 0;
}

Measured memory_bytes: 1888
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
  int K;
  scanf("%d", &K);

  int *mod = (int *)malloc(sizeof(int)*K);
  for(int i=0;i<K;i++){
    if(i==0){
      mod[i] = 7 % K;
    }
    else{
      mod[i] = (10*mod[i-1]+7) % K;
    }
  }

  int flag=0;
  int i;
  for(i=0;i<K;i++){
    if(mod[i]==0){
      flag = 1;
      break;
    }
  }

  if(flag==1) printf("%d\n", i+1);
  else printf("-1");
  
  return 0;
}


Measured memory_bytes: 5556
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vc= vector<char>;
#define REP(i,x,n) for(int i=x; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()

int main(){
  int r;
  cin >> r;

  cout << r*r*3 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

void solve() {
  int n, q;
  cin >> n >> q;
  vector<tuple<int, int, int> > v(n);
  rep(i, n) {
    int s, t, x;
    cin >> s >> t >> x;
    v[i] = make_tuple(x, s, t);
  }
  sort(all(v));

  set<pii> st;
  rep(i, q) {
    int d;
    cin >> d;
    st.insert(pii(d, i));
  }
  vector<int> ans(q, -1);
  rep(i, n) {
    int s, t, x;
    tie(x, s, t) = v[i];
    auto it = st.lower_bound(pii(s - x, -1));
    while (it != st.end()) {
      if (it->F > t - 1 - x) break;
      ans[it->S] = x;
      st.erase(it++);
    }
  }
  rep(i, q) cout << ans[i] << endl;
}


Measured memory_bytes: 14464
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
char str[100005];
int num[100005];
int main()
{
	int k,i,j,min,bei;
	scanf("%s",str);
	scanf("%d",&k);
	int len = strlen(str);
	for(i = 0;i < len; i++)
	{
		if(str[i] == 'a')
		{
			num[i] = 0;
			continue;
		}
		num[i] = 'z' - str[i] + 1;
	}
	for(i = 0;i < len; i++)
	{
		if(k == 0)
			break;
		if(i + 1 < len)
		{	
			if(k >= num[i] && str[i] != 'a')
			{
				str[i] = 'a';
				k -= num[i];
			}
		}
		else
		{
			k = k % 26;
			if(str[i] + k <= 'z')
			{
				str[i] = str[i] + k;
				}
			else
			{
				k = k - num[i];
				str[i] = 'a';
				str[i] = str[i] + k;
				}
			k = 0;
		}
	}
	puts(str);
	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <math.h>
#include <time.h>
#include <bitset>
#include <assert.h>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) x.begin(),x.end() 
#define PII pair <ll,ll>
#define N 100005
#define MOD 1000000007
#define INF 1000000000000000000
using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	if(a > 12)
	{
		cout << b;
	}
	else if(a > 5)
	{
		cout << b / 2;
	}
	else
	{
		cout << 0;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
//using namespace __gnu_pbds; 
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update>
#define standardVar ll n,m,i,j,k,num,num1,num2,flag=0
#define nn <<"\n"
#define __ <<" "<<
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define ittr(x,v) for(auto x=v.begin();x!=v.end();x++)
#define itr(x,n) for(x=0;x<n;x++)
#define itrab(x,a,b) for(x=a;x<b;x++)
#define itpr(v) ittr(x,v)cout<<*x<<" "; cout nn
#define itppr(v) ittr(x,v)cout<<(*x).ff<<" "<<(*x).ss<<"  "; cout nn
#define pi 3.14159265359
#define dTor(x) ((x)*pi)/180.0
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef map<ll,ll> ml;
typedef set<ll> sl;
typedef string str;
typedef pair<ll, ll> pl;
typedef vector< pl > vpl;
typedef map<pl,ll> mpl;
typedef set< pl > spl;
typedef vector<str> vst;
typedef vector<vl> vvl;

const ll M=1000000007;
const ll N=998244353;

ll power(ll x, ll y, ll p){     //MODULAR EXPONENTIATION
    ll res=1;
    x=x%p;
    if(x==0)
        return 0;
    while(y>0){
        if(y&1)
            res=(res*x)%p;
        y=y>>1;
        x=(x*x)%p;
    }
    return res;
}
ll inv(ll x, ll m){             //FERMAT INVERSE
    return power(x,m-2,m);
}
struct comp{                    //COMPARISON ON PAIRS
    template<typename T>        
    bool operator()(const T &a, const T &b){
        if (a.ff==b.ff)
            return (a.ss<b.ss);
        else
            return (a.ff<b.ff);
    }
};
bool mod(const pair<ll,ll> &a, const pair<ll,ll> &b){   //COMPARATOR FOR PAIRS (SORTING)
    if(a.ff!=b.ff)
        return (a.ff<b.ff);
    else
        return (a.ss<b.ss);
}
void sieve(vl &prime){          //SIEVE OF ERATOSTHENES
    ll maxN=1e6;
    vector<bool> pr(maxN+1,1);
    for(int i=2;i*i<=maxN;i++)
        if(pr[i]==1)
            for(int j=i*i;j<=maxN;j+=i)
                pr[j]=0;
    for(ll i=2;i<=maxN;i++)
        if(pr[i]==1)
            prime.pb(i);
}
bool isValid(ll i, ll j, ll n, ll m){   //CHECKS FOR OVERFLOW
    if(i>=0&&i<n&&j>=0&&j<m){
        return true;
    }
    return false;
}

//MAIN FUNCTION STARTS HERE

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    standardVar;
    int t;
    cin>>t;
    if(t>=30)
        cout<<"Yes" nn;
    else
        cout<<"No" nn;
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename Monoid>
class segment_tree {
  public:
    using value_type = typename Monoid::value_type;

  private:
    ll const sz, n;
    std::vector<value_type> data;

    /// n is the first integer that satisfies 2^n >= sz
    ll calc_n(ll sz) {
        sz--;
        sz |= sz >> 1;
        sz |= sz >> 2;
        sz |= sz >> 4;
        sz |= sz >> 8;
        sz |= sz >> 16;
        sz |= sz >> 32;
        return sz + 1;
    }

  public:
    segment_tree(std::vector<value_type> const &init)
        : sz(init.size())
        , n(calc_n(sz))
        , data(n * 2, Monoid::id()) {
        std::copy(init.begin(), init.end(), data.begin() + n);
        for (ll i = n - 1; i >= 0; i--) {
            data[i] = Monoid::op(data[i * 2], data[i * 2 + 1]);
        }
    }

    segment_tree(ll sz, value_type init = Monoid::id())
        : segment_tree(std::vector<value_type>(sz, init)) {}

    void update(ll i, ll x) {
        assert(0 <= i && i <= sz);
        data[i += n] = x;
        while (i /= 2) data[i] = Monoid::op(data[i * 2], data[i * 2 + 1]);
    }

    value_type find(ll l, ll r) const {
        assert(0 <= l && l <= r && r <= sz);
        l += n, r += n;
        value_type res1 = Monoid::id(), res2 = Monoid::id();
        while (l < r) {
            if (l & 1) res1 = Monoid::op(res1, data[l++]);
            if (r & 1) res2 = Monoid::op(data[--r], res2);
            l >>= 1, r >>= 1;
        }
        return Monoid::op(res1, res2);
    }

    value_type const &get(ll i) const { return data[i + n]; }
};

template <typename T, T inf>
struct range_minimum_query {
    using value_type = T;
    constexpr static T id() { return inf; }
    constexpr static T op(T const &lhs, T const &rhs) {
        return std::min(lhs, rhs);
    }
};
int main(){
  int n,q;
  scanf("%d%d",&n,&q);
  segment_tree<range_minimum_query<ll,(1ll << 31)-1>> st(n);
  int com;
  ll x,y;
  for (int i = 0; i < q; i++) {
    scanf("%d%lld%lld\n",&com,&x,&y );
    if (com == 0) {
      st.update(x,y);
    } else {
      ++y;
      printf("%lld\n",st.find(x,y) );
    }
  }
  return 0;
}


Measured memory_bytes: 5720
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <stack>
#include <queue>

typedef long long ll;
using namespace std;

int main(){
  ll i,j,k,n;
  cin >> n;
  string s;
  double x,ret=0;
  for(i=0;i<n;i++){
    cin >> x;
    cin >> s;
    if(s=="JPY")ret+=x;
    else ret+=x*380000;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        if ((a < b) && (b < c)) {
            System.out.println ("Yes");
        } else {
            System.out.println ("No");
        }
    }
}


Measured memory_bytes: 26284
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
	ll r=1;
	a=a%m;
	while(b>0)
	{
		if(b&1)
		    r=(r*a)%m;
		b>>1;
		a=(a*a)%m;
	}
	return r%m;
}


int main(){
    ll n; cin>>n;
    map<pair<ll,ll> ,ll>mp;

    rep(i,1,n+1)
    {
        string s = to_string(i);
        char x = s[0];
        reverse(s.begin(),s.end());
        char y = s[0];
        ll ta  = x - '0',tb = y - '0';
        mp[{ta,tb}]++;
        //cout<<mp[{x,y}]<<endl;
    }
    ll ans = 0;
    for(ll i =0;i<=9;i++)
    {
        for(ll j = 0;j<=9;j++)
        {
            if(mp.find({i,j})!=mp.end()&&mp.find({j,i})!=mp.end())ans+=(mp[{i,j}]*mp[{j,i}]);
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e15;
const ll MOD = 1e9+7;
const ll LINF = 1e18;


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  cout<<n/3<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main
{
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static void main(String args[])
    {
        FastReader obj = new FastReader();
        int a = obj.nextInt(),b = obj.nextInt(),c = obj.nextInt();
        System.out.println(c+" "+a+" "+b);
    }
}


Measured memory_bytes: 20692
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

class UnionFind {
public:
  vector <ll> par;
  vector <ll> siz;
  UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
    for (ll i = 0; i < sz_; ++i) par[i] = i;
  }
  void init(ll sz_) {
    par.resize(sz_);
    siz.assign(sz_, 1LL);
    for (ll i = 0; i < sz_; ++i) par[i] = i;
  }
  ll root(ll x) {
    while (par[x] != x) {
      x = par[x] = par[par[x]];
    }
    return x;
  }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }
    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }
    ll size(ll x) {
        return siz[root(x)];
    }
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,M; cin >> N >> M;
    vector<vector<int>> L(M);
    rep(i,N) {
        int k; cin >> k;
        rep(j,k) {
            int l; cin >> l;
            l--;
            L[l].emplace_back(i);
        }
    }

    UnionFind uf(N);
    rep(i,M) {
        if (L[i].size() == 0) continue;
        for (int j = 1; j < L[i].size(); j++) {
            uf.merge(L[i][0],L[i][j]);
        }
    }
    bool ok = true;
    rep(i,N) {
        if (!uf.issame(0,i)) ok = false;
    }

    cout << (ok ? "YES" : "NO") << endl;
}

Measured memory_bytes: 4864
s=input()
t=input()
ans=9999
for i in range(len(s)-len(t)+1):
    
    temp=s[i:i+len(t)]
    cnt=0
    for j in range(len(t)):
        if temp[j]!=t[j]:
            cnt+=1
    ans=min(ans,cnt)
print(ans)

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

using namespace std;
#define ll long long
int main()
{
    ll a,b,c,d,l;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    l=c*d/__gcd(c,d);
    c=(b/c)-(a/c-(a%c==0));
    d=(b/d)-(a/d-(a%d==0));
    l=(b/l)-(a/l-(a%l==0));
    printf("%lld\n",b-a-c-d+l+1);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace NOMURA2020_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var H1 = RInt;
            var M1 = RInt;
            var H2 = RInt;
            var M2 = RInt;

            int s = H1 * 60 + M1;
            int f = H2 * 60 + M2;

            int ans = f - s - RInt;

            Console.WriteLine(ans);

        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String RNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int RInt => int.Parse(RNext());
        public static long RLong => long.Parse(RNext());
        public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
        public static string RString => RNext();
        //以下未テスト
        public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
        public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
        public static char[][] RMap(int h) => Enumerable.Repeat(0, h).Select(x => Console.ReadLine().ToCharArray()).ToArray();
    }

    static class Debug
    {
        static public void Draw2D<T>(T[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            T[,] map2 = new T[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = (T)(object)0;
                    else if (i == 0) map2[i, j] = (T)(object)(j - 1);
                    else if (j == 0) map2[i, j] = (T)(object)(i - 1);
                    else map2[i, j] = map[i - 1, j - 1];
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write((dynamic)map2[i, j] % 10);
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D(int[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 27824
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())

L1 = t1*a1+t2*a2
L2 = t1*b1+t2*b2
if L1 == L2:
    print('infinity')
    exit()
if t1*a1 == t1*b1:
    print(1)
    exit()

flg = 1 if L1 < L2 else 0
ok = 0
ng = 10**15+1
mid = (ok + ng)//2
ev = 0
while ng - ok > 1:
    #print(mid * L1 - t2*a2, mid * L2 - t2*b2)
    if mid * L1 - t2*a2 > mid * L2 - t2*b2:
        if flg:
            ok = mid
        else:
            ng = mid
    elif mid * L1 - t2*a2 == mid * L2 - t2*b2:
        ok = mid
        ev = 1
        break
    else:
        if flg:
            ng = mid
        else:
            ok = mid
    mid = (ok + ng)//2
if ok == 0:
    print(0)
    exit()
if ev:
    print((ok-1) * 2)
else:
    print(ok * 2 - 1)


Measured memory_bytes: 38612
from  math import gcd
 
 
k = int(input())
sum_c = 0
 
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            sum_c += gcd(gcd(a, b), c)
            
print(sum_c)

Measured memory_bytes: 9180
# coding: utf-8
N, M, X, Y = map(int, input().split())

x = max(list(map(int, input().split())))
y = min(list(map(int, input().split())))

ans = "War"
for z in range(X+1, Y+1):
    if x < z <= y:
        ans = "No War"
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  vector<int> v(n);
  for(int i=0; i<n; i++){
    cin >> v[i];
  }
 
  sort(v.begin(), v.end());
  
  vector<double> sum(n);
  sum[0] = (v[0] + v[1])/2.0;
  
  for(int j=0; j<n-2; j++){
    sum[j+1] = (sum[j] + v[j+2])/2.0;
  }
  
  cout << sum[n-2] << endl;
  
}


Measured memory_bytes: 3748
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		for(int i = 0; i < n; i++){
			int x = sc.nextInt();
			map.put(x, map.containsKey(x) ? map.get(x)+1 : 1);
		}
		int sum = 0;
		for(Entry<Integer, Integer> entry : map.entrySet()){
			if(entry.getKey() > entry.getValue()) sum+=entry.getValue();
			else if(entry.getKey() < entry.getValue()) sum += entry.getValue() - entry.getKey();
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 63400
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let P = read![[usize]];

    let mut m = N;
    let mut count = 0_i64;

    for i in 0..N {
        if m >= P[i] {
            count += 1;
        }

        m = min(m, P[i]);
    }

    println!("{}", count)
}


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

using std::vector;
using std::printf;
using std::cout;
using std::endl;
using std::string;
using std::cin;
using std::pair;
using std::sort;
using std::priority_queue;

#define i64t long long int
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

template<typename T>
void dump(vector<T> vec) {
    for (auto x : vec) {
        std::cout << x << " ";
    }
    std::cout << std::endl;
}

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

const i64t MOD = 1000000007;

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

    int N_even = N / 2;
    float ans = (1.0 * (N - N_even) ) / N ;

    printf("%f", ans);

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;
    cin >> n;
    vi c(n-1),s(n-1),f(n-1);
    rep(i,n-1){
        cin >> c[i] >> s[i] >> f[i];
    }
    rep(i,n-1){
        ll t = 0;
        int j = i;
        while(j<=n-2){
            if(t>=s[j]){
                if(t%f[j]==0) t = t + c[j];
                else t = t + (f[j] - t%f[j]) + c[j];
            }else{
                t = s[j] + c[j];
            }
            j++;
        }
        cout << t << endl;
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define K 1000
using namespace std;
int v[2][2*K+2][2*K+2];
int s[2][2*K+2][2*K+2];
int query(bool color, int r1, int c1, int r2, int c2) {
    r1++, c1++, r2++, c2++;
    return s[color][r2 - 1][c2 - 1]
         - s[color][r1 - 1][c2 - 1]
         - s[color][r2 - 1][c1 - 1]
         + s[color][r1 - 1][c1 - 1];
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    memset(v, 0, sizeof v);
    for(int i = 0; i < n; i++) {
        int x, y; char c;
        cin >> x >> y >> c;
        v[c == 'W'][x % (2 * k) + 1][y % (2 * k) + 1]++;
    }
    for(int c = 0; c < 2; c++) {
        for(int i = 0; i <= 2 * k; i++) {
            for(int j = 0; j <= 2 * k; j++) {
                s[c][i][j] = (i == 0 || j == 0 ? 0 : s[c][i-1][j] + s[c][i][j-1] - s[c][i-1][j-1] + v[c][i][j]);
            }
        }
    }
    int best = 0;
    for(bool c : {0, 1}) {
        for(int i = 0; i < k; i++) {
            for(int j = 0; j < k; j++) {
                best = max(best, query(c, 0, 0, k - i, k - j)
                               + query(!c, k - i, 0, 2 * k - i, k - j)
                               + query(c, 2 * k - i, 0, 2 * k, k - j)

                               + query(!c, 0, k - j, k - i, 2 * k - j)
                               + query(c, k - i, k - j, 2 * k - i, 2 * k - j)
                               + query(!c, 2 * k - i, k - j, 2 * k, 2 * k - j)

                               + query(c, 0, 2 * k - j, k - i, 2 * k)
                               + query(!c, k - i, 2 * k - j, 2 * k - i, 2 * k)
                               + query(c, 2 * k - i, 2 * k - j, 2 * k, 2 * k));
            }
        }
    }
    cout << best << endl;
    return 0;
}


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    string s;
    cin >> s;

    if(s.size() == 2) cout << s << endl;
    else cout << s[2] << s[1] << s[0] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    int a,i;
    scanf("%d",&a);
    int x[a],y[a],z[a];
    double p1,p2,p3,pI,t1=0,t2=0,t3=0,tI=0,e1,e2,e3,eI,m=0,g=1/3.0;
    for(i=0;i<a;i++)
    {
        scanf("%d",&x[i]);
    }
    for(i=0;i<a;i++)
    {
        scanf("%d",&y[i]);
    }
    for(i=0;i<a;i++)
    {
        if(x[i]>y[i] || x[i]==y[i])
        {
            e1=(x[i]-y[i]);
            z[i]=e1;
            t1=t1+e1;
            e2=e1*e1;
            t2=t2+e2;
            e3=e1*e1*e1;
            t3=t3+e3;
        }
        else if(y[i]>x[i])
        {
            e1=(y[i]-x[i]);
            z[i]=e1;
            t1=t1+e1;
            e2=e1*e1;
            t2=t2+e2;
            e3=e1*e1*e1;
            t3=t3+e3;
        }
    }
    p1=t1;
    p2=sqrt(t2);
    p3=pow(t3,g);
    for(i=0;i<a;i++)
    {
        if(z[i]>m)
        {
            m=z[i];
        }
    }
    pI=m;
    printf("%.6lf\n%.6lf\n%.6lf\n%.6lf\n",p1,p2,p3,pI);
    return 0;
}


Measured memory_bytes: 2124
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

#define rep(i, a, b) for(auto (i)=a;i<b;i++)
#define list(i, N) for(auto (i)=0;i<N;i++)

typedef long long ll;
typedef vector <ll> vi;
typedef pair <ll, ll> pi;
#define mp make_pair
#define pb push_back
#define eb emplace_back

#define int ll
#define INF 1e18+5
#define mod 1000000007

template<class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

#define MAX_N 100005
int n, m; bool gotRight[MAX_N];
int cnt[MAX_N];
int penaltyCount = 0;
int correctCount = 0;

int32_t main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n >> m;
    list(i,m){
        int p; cin >> p;
        string status; cin >> status;
        if(status=="WA"){
            if(!gotRight[p-1]){
                cnt[p-1] += 1;
            }
        }else {
            if (!gotRight[p-1]) {
                gotRight[p-1] = true;
                correctCount++;
                penaltyCount += cnt[p-1];
            }
        }
    }

    cout << correctCount << " " << penaltyCount << "\n";
    return 0;
}

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

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())

#define REP(a, b) for (int a = 0; a < (b); a++)
#define FOR(a, b, c) for (int a = (b); a <= (c); a++)
#define REPD(a, b) for (int a = (b) - 1; a >= 0; a--)
#define FORD(a, b, c) for (int a = (b); a >= (c); a--)

#define MIN(a, b) (a) = min((a), (b))
#define MAX(a, b) (a) = max((a), (b))

#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif

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

template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2> &p) {
  return is >> p.fi >> p.se;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  VV<int> a(n, vi(3));
  REP(i, n) REP(j, 3) cin >> a[i][j];
  VV<int> dp(n + 1, vi(4, -1));
  dp[0][3] = 0;
  REP(i, n) REP(j, 4) if (dp[i][j] > -1) {
    REP(k, 3) if (k != j) MAX(dp[i + 1][k], dp[i][j] + a[i][k]);
  }
  cout << *max_element(ALL(dp[n])) << endl;
}


Measured memory_bytes: 11264
#include<stdio.h>




int main(){
    int N,i,max,min,ans;
    
    max=1;
    min=1000000000;
    
    scanf("%d",&N);
    
    int A[N];
    
    
    
    
    for (i=1;i<N+1;i++) {
        
    scanf("%d",&A[i]);
        if (A[i]<min) min = A[i];
        if (A[i]>max) max = A[i];

    }
    
    
    
              printf("%d\n",max-min);
        
    
    
    return 0;
    
}


Measured memory_bytes: 128
#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 ans=0;
  int n;
  cin >> n;
  string s,t;
  cin >> s >> t;
  rep(i,n){
    if(s==t){ 
      cout << ans + s.size() << endl;
      return 0;
    }
    else{
      s.erase(s.begin());
      t.pop_back();
      ans+=2;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    int n,q;
    int cnt=0;
    cin>>n;
    vector<int>s(n);
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    cin>>q;
    vector<int>t(q);
    for(int i=0;i<q;i++){
        cin>>t[i];
    }
    for(int i=0;i<q;i++){
        for(int j=0;j<n;j++){
            if(s[j]==t[i]){
                cnt++;
                break;
            }
        }
    }
    cout<<cnt<<endl;
    return 0;
}


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

int div(int n)
{
    if (n == 1)
        return 1;
    else if (n == 2)
        return 2;
    else if (n == 3)
        return 2;
    else
    {
        int s = 0;
        int n2 = sqrt(n);
        for (int i = 1; i <= n2; i++)
        {
            if (n % i == 0)
                s++;
        }
        int n3 = sqrt(n);
        if (pow(n3, 2) == n)
            s = s * 2 - 1;
        else
            s *= 2;

        return s;
    }
}

int main()
{
    int n;
    cin >> n;

    int ans = 0;
    for (int i = 1; i < n; i++)
    {
        ans += div(i);
    }
    cout << ans << endl;
}

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

using namespace std;


int main() {
    string s;
    cin >> s;
    int n = s.size();
    bool ok = true;
    if(s[0] != 'A') {
        ok = false;
    }
    int counter = 0;
    for(int i = 2; i <= n-2; i++) {
        if(s[i] == 'C') {
            counter++;
        }
    }
    if(counter != 1) {
        ok = false;
    }
    if(!ok) {
        puts("WA");
        return 0;
    }
    for(int i = 0; i < n; i++) {
        if(s[i] != 'A' && s[i] != 'C') {
            if(s[i] < 97) {
                ok = false;
            }
        }
    }
    if(ok) {
        puts("AC");
    } else {
        puts("WA");
    }
    return 0;
}

Measured memory_bytes: 3592
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

using namespace std;
typedef long long int64;

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin>>p[i];
  }

  int result=0;
  int dp[200010]={};
  for(int i=0;i<n;i++){
    dp[p[i]]=dp[p[i]-1]+1;
    result=max(result,dp[p[i]]);
  }
  cout<<n-result<<endl;




  return 0;
}

Measured memory_bytes: 1792
import scala.collection.mutable._
import io.StdIn.readLine

object Main extends App {
  val map = new HashMap[String,Int]
  val s = readLine.split(" ")
  s.foreach(e => {
    if(!map.contains(e)) map.put(e,1)
    else map.put(e,map(e)+1)
  })
  val maxF = map.maxBy(_._2)._1
  val maxL = s.map(e => (e.length, e)).max._2

  println(maxF + " " + maxL)
}


Measured memory_bytes: 43852
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()

Scc = min(N, M // 2)
N = N - Scc
M = M - Scc * 2
if N == 0:
    ans = Scc + M // 4
else:
    ans = Scc
print(ans)

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

using namespace std;

int n, a[200005], b[200005];
bool no[200005];
long long ans;
priority_queue<pair<int, int>> q;

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", a + i);
	for (int i = 0; i < n; i++) {
		scanf("%d", b + i);
		q.emplace(b[i], i);
	}
	while (!q.empty()) {
		int ta = q.top().first;
		int tb = q.top().second;
		q.pop();
		int tc = (tb + 1) % n;
		int td = (tb + n - 1) % n;
		int sum = b[tc] + b[td];
		if (ta <= a[tb])
			continue;
		int te = (ta - a[tb]) / sum;
		if (te) {
			ans += te;
			b[tb] -= te * sum;
			q.emplace(b[tb], tb);
			if (no[tc]) {
				q.emplace(b[tc], tc);
				no[tc] = 0;
			}
			if (no[td]) {
				q.emplace(b[td], tc);
				no[td] = 0;
			}
		} else
			no[tb] = 1;
	}
	for (int i = 0; i < n; i++)
		if (a[i] != b[i]) {
			puts("-1");
			return 0;
		}
	printf("%lld\n", ans);
}


Measured memory_bytes: 3700
a=gets.chomp.to_i
b=gets.chomp.to_i
c=gets.chomp.to_i
d=gets.chomp.to_i
e=gets.chomp.to_i
k=gets.chomp.to_i

l=[a,b,c,d,e]
puts l.max-l.min > k ? ":(" : "Yay!"


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

using namespace std;

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

    int A , B, C;
    cin >> A >> B >> C;

    string S;

    if (A == B && A == C) {
//        if (A == C) {
            S = "Yes";
//        }
    }
    else {
        S = "No";
    }

    cout << S << "\n";
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
typedef long long ll;
 
using namespace std;
 
int main() {
    int n;
    cin >> n;
    vector<ll> stairs(n);
 
    rep(i, n) {
        cin >> stairs.at(i);
    }
 
    ll lower_flg = 0;
    for (size_t i = n-1; i > 0; i--)
    {
        /* code */
        if (stairs.at(i) < stairs.at(i-1) - 1) 
        {
            /* code */
            lower_flg = 1;
            break;
        }
        
        if (stairs.at(i) == stairs.at(i-1) - 1)
        {
            /* code */
            stairs.at(i-1)--;
        }
        
    }
    
    string ans = (lower_flg != 1) ? "Yes" : "No";
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define forn(i,n)       for(int i=0; i<n; i++)
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void zeus()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
	//zeus();

	int n,w; cin>>n>>w;

	int dp[w+1]={0};

	for (int i = 0; i < n; ++i)
	{
		int weight, value;
		cin>>weight>>value;

		for(int j=w-weight;j>=0; j--){
			dp[j+weight]=max(dp[j]+value, dp[j+weight]);
			//cout<<j+weight<<" "<<dp[j+weight]<<endl;
		}
	}
	int ans=0;
	for(int i=0; i<w+1; i++){
	    //cout<<dp[i]<<endl;
		ans=max(ans,dp[i]);
	}

	cout<<ans<<endl;
}

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

using namespace std;

long long sum , j;
string s;

int main()
{
	cin >> s;
	j = s.size() - 1;
	for(int i = s.size() - 1 ; i >= 0 ; i--)
		if(s[i] == 'B')
		{
			sum += abs(j - i);
			j--;
		}
	cout << sum;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;

namespace AtCoder20190309B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N,M,C;
            //a = int.Parse(Console.ReadLine()); //標準入力
            string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            N = int.Parse(str[0]);  
            M = int.Parse(str[1]);
            C = int.Parse(str[2]);
            
            //B配列
            string[] str2 = Console.ReadLine().Split(' ');
            var listB = new List<int>();
            for (int i = 0; i< M; i++) {
                int num2 = int.Parse(str2[i]);
                listB.Add(num2);
            }
            
            int num = 0;
            
            for (int i = 0;  i < N; i++)
            {
                int sum = 0;
                string[] str3 = Console.ReadLine().Split(' ');
                for (int j = 0; j < M; j++)
                {
                    int num3 = int.Parse(str3[j]);
                    sum=sum+listB[j]*num3;
                }
                if (sum + C > 0)
                {
                    num++;
                }

            }

            Console.Write(num);
            //Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
            //Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
        }
    }
}


Measured memory_bytes: 13140