akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)(n),(int)(n))
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0,r,s,p;
  int a[LIMIT2]={0};
  char t[LIMIT1],pc[LIMIT1]={'\0'};
  
  scanf("%lld %lld",&n,&k);
  scanf("%lld %lld %lld",&r,&s,&p);
  scanf("%s",t);
  rep(i,n){
    if(i<k || t[i]!=t[i-k]){
      if(t[i]=='r'){
        pc[i]='p';
        result+=p;
      }else if(t[i]=='s'){
        pc[i]='r';
        result+=r;
      }else{
        pc[i]='s';
        result+=s;
      }
    }else{
      if(t[i]=='r'){
        if(pc[i-k]!='p'){
          pc[i]='p';
          result+=p;
        }else{
          pc[i]=' ';
        }
      }else if(t[i]=='s'){
        if(pc[i-k]!='r'){
          pc[i]='r';
          result+=r;
        }else{
          pc[i]=' ';
        }
      }else{
        if(pc[i-k]!='s'){
          pc[i]='s';
          result+=s;
        }else{
          pc[i]=' ';
        }
      }      
    }
  }
  printf("%lld",result);
  return 0;
}



Measured memory_bytes: 512
// E - Who Says a Pun?

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int N;
string S;

bool is_ok(ll k) {
	map<string, int> pos;
	for (int i=0; i<=S.size() - k; i++) {
		string sub = S.substr(i, k);
		if (pos.count(sub) == 0) {
			pos[sub] = i;
		} else {
			if (pos[sub] + k <= i) {
				return true;
			}
		}
	}

	return false;
}

ll find_max_ok(ll lower, ll upper) {
	if (!is_ok(lower)) return 0; // 存在しない

	ll ok = lower;
	ll ng = upper;

	while(ng - ok > 1) {
		ll trying = (ng + ok) / 2;

		if (is_ok(trying)) {
			ok = trying;
		} else {
			ng = trying;
		}
	}

	return ok;
}

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

	int ans = find_max_ok(1, S.size());

	cout << ans << endl;

	return 0;
}

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

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

    bool is_ok = true;

    
    if (s.size() + 1 != t.size()) {
        is_ok = false;
    } else {
        for (int i = 0; i < s.size(); ++i) {
            if (s[i] != t[i]) {
                is_ok = false;
            }
        }
    }

    if (is_ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

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

  string S; cin >> S;
  string ans = "ABC";
  if (S == "ABC") ans = "ARC";
  cout << ans << '\n';
  return 0;
}

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

int N;
vector<int> x, sx;

int main(){
  cin >> N;
  
  int v;
  for(int i = 0; i < N; i++){ cin >> v;  x.push_back(v); sx.push_back(v); }
  sort(sx.begin(), sx.end());

  for(int i = 0; i < N; i++){
    if(sx[N/2] > x[i]) cout << sx[N/2] << endl;     //削除場所が中央値かそれより左ならずれる
    else cout << sx[N/2-1] << endl;                          //右ならずれない
  }

  return 0;
}
    

 

Measured memory_bytes: 3948
#include <stdio.h>

int main(){
	int N, R;
	
	scanf ("%d %d", &N, &R);
	if (N >= 10) {
		printf ("%d", R);
	}
	else {
		printf ("%d", R + 100*(10-N) );
	};
	
	return 0;
}

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')

typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    //检查有没有特判0,有没有越界限.
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    string s;
    cin >> s;
    int len = s.size();
    int ans = 0;
    for (int i = 0; i < len / 2; i++)
    {
        if (s[i] != s[len - i - 1])
            ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
//#include <algorithm>
using namespace std;

int main()
{
	char s[200];
	
	char *a;
	
	cin>>s;
	
	a=s;
	
	while(*a!='\0')
	{
		if(*a=='L')
		{
			cout<<"No";
			return 0;
		}
		a++;
		if(*a=='\0')
			break;
		if(*a=='R')
		{
			cout<<"No";
			return 0;
		}
		a++;
	}
	
	cout<<"Yes";
	return 0;
}


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

int main() {
  int N, l, r;
  int sum = 0;
  
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> l >> r;
    sum += r - l + 1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <bits/stdc++.h>
using namespace std;
int A;
int a[1000010];
int B;
int b[1000010];
map<int, int> mpa, mpb;
int main(void)
{
    int i;
    cin >> A;
    for (i = 0; i < A; i++)
        scanf("%d", &a[i]);
    cin >> B;
    for (i = 0; i < B; i++)
        scanf("%d", &b[i]);
    for (i = 0; i < A; i++)
        mpa[a[i]]++;
    for (i = 0; i < B; i++)
        mpb[b[i]]++;
    for (i = 0; i < B; i++)
    {
        int x = b[i];
        if (mpb[x] > mpa[x])
        {
            cout << "NO" << endl;
            return 0;
        }
    }

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


Measured memory_bytes: 23936
//by xay5421 2449670833@qq.com
#include<set>
#include<map>
#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#define int long long
#define debug(...) fprintf(stderr,__VA_ARGS__)
//#define debug(...) ((void)0)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;typedef unsigned long long ull;typedef std::pair<int,int> pii;
template<typename T>void rd(T&x){int f=0,c;while((c=getchar())<48||57<c)f^=!(c^45);x=(c&15);while(47<(c=getchar())&&c<58)x=x*10+(c&15);if(f)x=-x;}
template<typename T>inline void pt(T x){if(x<0)x=-x,putchar('-');if(x>9)pt(x/10);putchar(x%10+48);}
template<typename T>inline void pt(T x,int c){pt(x),putchar(c);}
template<typename T>inline T max(const T&x,const T&y){return x<y?y:x;}
template<typename T>inline T min(const T&x,const T&y){return x<y?x:y;}

const int N=205;

int n,g[N][N],q[N],id[N];

signed main(){
	rd(n);
	rep(i,1,n)rep(j,1,n){
		int ch;while(ch=getchar(),ch!='0'&&ch!='1');
		g[i][j]=ch&1;
	}
	int ans=0;
	rep(s,1,n){
		memset(id,0,sizeof(id));
		int he=0,ta=1;q[1]=s,id[s]=1;
		while(he!=ta){
			int u=q[++he];
			rep(v,1,n)if(g[u][v]){
				if(!id[v])id[v]=id[u]+1,q[++ta]=v;
				else if(id[v]==id[u]){
					return puts("-1"),0;
				}
			}
		}
		rep(i,1,n)ans=max(ans,id[i]);
	}
	pt(ans,'\n');
	return 0;
}

Measured memory_bytes: 512
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(dead_code)]
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)*}
    };
}
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, 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")
    };
}

fn main() {
    input!{
        S: chars,
    }
    let mut map = std::collections::HashMap::new();
    for s in S {
        if map.contains_key(&s) {
            let t = map[&s];
            map.insert(s, t + 1);
        } else {
            map.insert(s, 1);
        }
    }
    let mut ret = true;
    for (k,v) in &map {
        if v != &2 {
            ret = false;
        }
    }
    println!("{}", if ret {"Yes"} else {"No"});
}



Measured memory_bytes: 4352
//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define file_input
//#define multitest
//#define measure_time
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<v32>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c)
{
	cout << "{ ";
	for (const auto &v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

void solve()
{
	ll n, d, a;
	cin >> n >> d >> a;
	vector<p64> arr;
	v64 work(n + 1, 0);
	arr.resize(n);
	for (int i = 0; i < n; i++)
		cin >> arr[i].fi >> arr[i].se;
	sort(arr.begin(), arr.end());
	ll sum = 0, ans = 0;
	for (int i = 0; i < n; i++)
	{
		arr[i].se -= sum;
		if (arr[i].se <= 0)
		{
			sum -= work[i];
			continue;
		}
		ll temp = (arr[i].se + a - 1) / a;
		ans += temp;
		sum += temp * a;
		ll idx = 2 * d + arr[i].fi;
		auto cnt = lower_bound(arr.begin(), arr.end(), make_pair(idx + 1, -MOD)) - arr.begin();
		cnt--;
		work[cnt] += a * temp;
		sum -= work[i];
	}
	cout << ans << ln;
	return;
}

int main()
{
	FASTIO;
#ifdef file_input
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	clock_t start, stop;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
#ifdef measure_time
	start = clock();
#endif
	for (int tc = 1; tc < t + 1; tc++)
		solve();
#ifdef measure_time
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 4992
/***** author :  C0d1ngPhenomena *****/

    #include <bits/stdc++.h>
    #define endl "\n"
    #define ll long long int
    #define TestCases int T; cin>>T; while(T--)
    #define rep(i,n) for(ll i = 0; i < n; i++)
    #define revrep(i,n) for(ll i = n-1; i >= 0; i--)
    #define vll vector<ll>
    #define vvll vector < vll >
    #define pll pair<ll, ll>
    #define mp(x,y) make_pair(x,y)
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define alld(c) c.begin(),c.end(),greater<int>()
    #define mem(a,val) memset(a,val,sizeof(a))
    #define f first
    #define s second
    #define pb push_back
    using namespace std;
    



    
    int main()
    {
        std::ios::sync_with_stdio(false);
        cin.tie(NULL);
        
        ll N;
        cin >> N;

       vll arr(N,0);

       rep(i,N)
       {
            cin >> arr[i];
       }
       sort(alld(arr));
       ll sum = 0;
          rep(i,N)
          {

            if(i != 0)
                sum+= arr[i/2];
          }

    
          cout << sum;

        return 0;
    }







Measured memory_bytes: 4792
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


vector<int> dijkstra(int i, int n, vector<vector<pair<int, int>>> graph) {
  vector<int> d(n, INF);
  d[i] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
  q.push(make_pair(0, i));
  while (!q.empty()) {
    pair<int, int> p = q.top();
    q.pop();
    int v = p.second;
    if (d[v] < p.first) {
      continue;
    }
    for (auto x : graph[v]) {
      if (d[x.first] > d[v] + x.second) {
        d[x.first] = d[v] + x.second;
        q.push(pair<int, int>(d[x.first], x.first));
      }
    }
  }
  return d;
}

signed main() {
  int N, u, v; 
  cin >> N >> u >> v;
  u--; v--;
  
  vector<vector<pair<int, int>>> graph(N);
  REP(i, N-1){
    int a, b;
    cin >> a >> b;
    a--; b--;
    graph[a].emplace_back(b, 1);
    graph[b].emplace_back(a, 1);
  }

  vector<int> dist1 = dijkstra(u, N, graph);
  vector<int> dist2 = dijkstra(v, N, graph);

  int ans = (dist1[v]-1)/2;
  bool tonari = false;
  if(dist1[v]%2){
    tonari = true;
  }

  int dist = dist1[v];
  int now;
  int ng;
  REP(i, N){
    if(dist1[i] == ans && dist2[i] == dist-ans) now = i;
    if(dist1[i] == ans+1 && dist2[i] == dist-ans-1) ng = i;
  }

  queue<int> q;
  q.push(now);
  vector<int> d(N, INF);
  d[now] = 0;
  while(!q.empty()){
    int p = q.front(); q.pop();
    for(auto v : graph[p]){
      if(d[v.first] != INF) continue;
      if(v.first == ng) continue;
      q.push(v.first);
      d[v.first] = d[p]+1;
    }
  }

  int MAX = 0;
  REP(i, N){
    if(d[i] == INF) continue;
    chmax(MAX, d[i]);
  }

  if(!tonari) ans++;
  ans += MAX;

  cout << ans << endl;

  return 0;
}

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

typedef long long int ll ;

ll gcd(ll aaa,ll bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

ll lcm(ll m,ll n)
{
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m / gcd(m, n)) * n);
}

int main() {

	int N,count=0;
	cin >> N;
	ll a[3*N],ans=0;
	for(int i = 0; i < 3*N; i++) {
		cin >> a[i];
	}
	sort(a,a+3*N);
	reverse(a,a+3*N);
	for(int i = 1; count != N; i += 2) {
		ans += a[i];
		count++;
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
  int N,sum_X,ans;
  cin>>N;
  vector<int> vec(N);
  sum_X=0;
  ans=0;
  
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
    sum_X+=vec.at(i);
  }
  int G;
  double g;
  g=double(sum_X)/N+0.5;
  G=int(g);
  for(int i=0;i<N;i++){
     if(G>=vec.at(i)){
       ans+=(G-vec.at(i))*(G-vec.at(i));
     }
    if(G<vec.at(i)){
      ans+=(vec.at(i)-G)*(vec.at(i)-G);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 21474836001234567LL
#define width 100000

typedef pair<long,int> P;

vector<P> x[width];
vector<P> y[width];

int main(){
  int n,m,k;
  cin>>m>>n>>k;

  // <??§?¨?, idx>
  rep(i,k){
    int a,b;
    cin>>a>>b;
    a--; b--;
    x[a].pb(mp(b,i));
    y[b].pb(mp(a,i));
  }
  x[m-1].pb(mp(n-1,k));
  y[n-1].pb(mp(m-1,k));
  k++;

  // k*2: y????????????????????????
  // k*2+1: x????????????????????????

  vector<vector<P>> vec(2*k+1);

  rep(i,width) if(x[i].size()>0){
    sort(all(x[i]));
    repl(j,1,x[i].size()){
      int a = x[i][j-1].se*2;
      int b = x[i][j].se*2;
      int d = x[i][j].fi - x[i][j-1].fi;
      vec[a].pb(mp(d,b));
      vec[b].pb(mp(d,a));
    }
  }

  rep(i,width) if(y[i].size()>0){
    sort(all(y[i]));
    repl(j,1,y[i].size()){
      int a = y[i][j-1].se*2 + 1;
      int b = y[i][j].se*2 + 1;
      int d = y[i][j].fi - y[i][j-1].fi;
      vec[a].pb(mp(d,b));
      vec[b].pb(mp(d,a));
    }
  }

  rep(i,k){
    int a = i*2, b = i*2+1;
    vec[a].pb(mp(1,b));
    vec[b].pb(mp(1,a));
  }

  if(x[0].size()==0){
    cout << -1 << endl;
    return 0;
  } else {
    int b = x[0][0].se*2;
    vec[2*k].pb(mp(x[0][0].fi, b));
  }

  // 2*k??????dijkstra??????
  // 2*k-1, 2*k-2?????????????????´??????

  vector<long> d(2*k+1, INF);
  priority_queue<P, vector<P>, greater<P>> pq;
  pq.push(mp(0,2*k));
  while(!pq.empty()){
    auto p = pq.top(); pq.pop();
    int idx = p.se; long dist = p.fi;
    if(d[idx] < dist) continue;
    for(auto &pp : vec[idx]){
      long nd = dist + pp.fi;
      int ni = pp.se;
      if(d[ni] <= nd) continue;
      else {
        pq.push(mp(nd,ni));
        d[ni] = nd;
      }
    }
  }
//dbg(d);
  long ans = min(d[2*k-1], d[2*k-2]);
  if(ans >= INF){
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }


  return 0;
}

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

#define ll long long
#define ld long double
#define ii pair<int ,int >
#define S second
#define F first
#define PI 3.1415926535897932384626
#define SPEED std::ios_base::sync_with_stdio(false);

int main(){
    SPEED
    string s;
    cin>>s;
    int n = s.size();
    for(int i=0;i<n-1;i++){
        if(s[i]==s[i+1]){
            cout<<i+1<<" "<<i+2;
            return 0;
        }
        if(i<n-2){
            if(s[i]==s[i+2]){
                cout<<i+1<<" "<<i+3;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1;

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  string S;
  cin >> S;
  sort(ALLOF(S));

  bool flg = true;
  rep(i,S.size()){
    if(S[0] != S[i]) flg = false;
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  ll H, W, h, w;
  cin >> H >> W >> h >> w;
  cout << (H-h)*(W-w) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	void run() {
		try (Scanner sc = new Scanner(System.in)) {
			int n = Integer.parseInt(sc.next());
			int d = Integer.parseInt(sc.next());
			int sum = 0;
			for (int i = 0; i < n; i++) {
				int p = Integer.parseInt(sc.next());
				if (p > d) {
					sum += (p - d);
				}
			}
			if(sum == 0) {
				System.out.println("kusoge");
			} else {
				System.out.println(sum);
			}
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

using namespace std;

typedef long long ll;

const int N = 1e6;
const int MOD = 998244353;

ll d[N], f[N];

ll bigMod(ll b, ll p, ll m) {
  ll ret = 1, cur = b % m;
  while (p) {
    if (p & 1) ret = (ret * cur) % m;
    cur = (cur * cur) % m;
    p = p >> 1;
  }
  return ret;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", d + i);
    f[d[i]]++;
  }
  if (f[0] == 0 || f[0] > 1 || d[1] > 0) {
    puts("0");
    return 0;
  }
  ll ans = 1;
  for (int i = 1; i < N; i++) {
    if (f[i]) {
      if (!f[i - 1]) {
        puts("0");
        return 0;
      } else {
        ll x = bigMod(f[i - 1], f[i], MOD);
        ans *= x;
        ans %= MOD;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 5120
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = 300 + 10;
const int N = 90000 + 10;
const int MOD = 998244353;

inline int inc(int a, int b) { return (a + b >= MOD) ? (a + b - MOD) : (a + b); }
inline int dec(int a, int b) { return (a >= b) ? (a - b) : (a + MOD - b); }
inline int mul(int a, int b) { return 1LL * a * b % MOD; }

inline int power(int x, int k) {
	int tmp = 1;
	while(k) {
		if(k & 1) tmp = mul(tmp,x);
		x = mul(x,x);
		k >>= 1;
	}
	return tmp;
}

int n, a[maxn], f[maxn][N], g[maxn][N];
int main() {
	scanf("%d", &n);
	for(int i = 1;i <= n;i ++) scanf("%d", &a[i]);
	f[0][0] = g[0][0] = 1;
	int sum = 0;
	for(int i = 1;i <= n;i ++) {
		sum += a[i];
		for(int j = 0;j <= sum;j ++) {
			f[i][j] = f[i - 1][j];
			g[i][j] = mul(g[i - 1][j],2);
			if(j >= a[i]) {
				f[i][j] = inc(f[i][j],f[i - 1][j - a[i]]);
				g[i][j] = inc(g[i][j],g[i - 1][j - a[i]]);
			}
		}
	}
	int Ans = power(3,n);
	for(int i = (sum + 1) / 2;i <= sum;i ++) {
		Ans = dec(Ans,mul(3,g[n][i]));
	}
	if(sum % 2 == 0) {
		Ans = inc(Ans,mul(3,f[n][sum / 2]));
	}
	printf("%d\n", Ans);
	return 0;
} 

Measured memory_bytes: 211200
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
#from scipy.misc import comb

N = int(input())
A = list(map(int, input().split()))

ans=10**15
for t in [1,-1]:
    r=0
    cnt=0
    T=t
    for i in range(N):
        r+=A[i]
        if(T>0 and r<=0):
            cnt+=1-r
            r+=1-r
        if(T<0 and r>=0):
            cnt+=r+1
            r-=r+1
        T*=-1
    ans=min(cnt,ans)
print(ans)

Measured memory_bytes: 24756
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

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

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

long long inputValueLongLong(){
    long long a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

void inputVectorlonglong(vector<long long> * p, long long a){
    rep(i, a){
        long long input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}


int main(int argc, const char * argv[]) {

    int X,Y;
    X = inputValue();
    Y = inputValue();
    int sum = 0;
    if(X==1 && Y==1){
        sum += 400000;
    }



    if(X==1){
        sum += 300000;
    }else if(X==2){
        sum += 200000;
    }else if(X==3){
        sum += 100000;
    }

    if(Y==1){
        sum += 300000;
    }else if(Y==2){
        sum += 200000;
    }else if(Y==3){
        sum += 100000;
    }

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

Measured memory_bytes: 256
def lcm(x, y):
    return (x * y) // gcd(x, y)
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
A,B,C,D=map(int,input().split())
abc=B//C-A//C
abd=B//D-A//D
abcd=(B//(lcm(C,D)))-(A//(lcm(C,D)))
if A%C==0:
    abc+=1
if A%D==0:
    abd+=1
if A%(lcm(C,D))==0:
    abcd+=1



#print(B-A+1)
#print(abc,abd,abcd)
print(B-A+1-(abc+abd-abcd))

Measured memory_bytes: 3064
/*
 * =template=.cpp
 * Copyright (C) 2017 hzw <hzw@huzhenweideMacBook.local>
 *
 * Distributed under terms of the MIT license.
 */

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<cstring>
#include<sstream>
#define FR first
#define SC second
#define MP make_pair
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=100010;
const int p=1000000007;
int pow(int a,int b,int c)
{
    if (a==0)return 0;
    int d=a,e=1;
    while (b)
    {
        if (b&1) e=(1LL*e*d)%c;
        d=1LL*d*d%c;
        b>>=1;
    }
    return e;
}
int random(int n) { return 1LL*rand()*rand()%n+1;}
int main()
{
	int n;
	scanf("%d",&n);
	int f=0;
	for (int i=1;i<=n;i++)
	{
		char ch;
		while ((ch=getchar())<=32);
		if (ch=='Y') f=1;
	}
	if (f) cout<<"Four\n";else cout<<"Three\n";
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define MOD 1000000007
using namespace std;
typedef long long int ll;

int main()
{
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    ll p[n];
    for(ll i=0;i<n;i++)
        p[i]=0;
    p[n-1]=a[n-1];
    for(ll i=n-2;i>0;i--)
    {
        p[i]=p[i+1]+a[i];
    }
    ll sum=0;
    for(ll i=0;i<n-1;i++)
    {
       sum+=((a[i]%MOD)*(p[i+1]%MOD))%MOD;
    }
    cout<<sum%MOD<<"\n";
}

Measured memory_bytes: 6740
from collections import defaultdict

N,M = map(int, input().split())

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

es = []

for i in range(M):
    a,b = map(int, input().split())
    a,b = a-1, b-1
    #a,b = min(a,b), max(a,b)
    es.append((a,b))

class UnionFind:
    def __init__(self,N):
        self.parent = [i for i in range(N)]
        self.rank = [0] * N
        self.count = 0
    def root(self,a):
        if self.parent[a] == a:
            return a
        else:
            self.parent[a] = self.root(self.parent[a])
            return self.parent[a]
    def is_same(self,a,b):
        return self.root(a) == self.root(b)
    def unite(self,a,b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb: return
        if self.rank[ra] < self.rank[rb]:
            self.parent[ra] = rb
        else:
            self.parent[rb] = ra
            if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1
        self.count += 1

uf = UnionFind(N)
for a,b in es:
    uf.unite(a,b)


ans = 0
for i in range(N):
    if P[i]-1 == i or uf.is_same(i,P[i]-1):
        ans += 1
print(ans)

Measured memory_bytes: 25568
from math import gcd

def get_loop(a, m):
  count = 1
  acc = a
  while acc != 1:
    count += 1
    acc *= a
    acc %= m
  return count

while True:
  a1, m1, a2, m2, a3, m3 = map(int, input().split())
  if not a1:
    break
  loop_a = get_loop(a1, m1)
  loop_b = get_loop(a2, m2)
  loop_c = get_loop(a3, m3)
  loop_ab = loop_a * loop_b // gcd(loop_a, loop_b)
  loop_abc = loop_ab * loop_c // gcd(loop_ab, loop_c)
  print(loop_abc)



Measured memory_bytes: 5668
#n=int(input())
h1,m1,h2,m2,k=map(int,input().split())
#a=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
#l=[list(input().split()) for i in range(n)]

m=(h2-h1)*60+m2-m1
print(m-k)


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846
 
typedef long long ll;
typedef pair< int, int > P;   
typedef pair< ll, P > PP;

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

int n;
string s[300];
ll ans;

set<P> st;

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

	cin >> n;
	REP(i, n) {
		cin >> s[i];
	}

	REP(k, n) {
		bool flga = true, flgb = true;
		REP(i, n) {
			REP(j, n) {
				int ax = (i + k) % n, ay = (j - k + n) % n;
				if (s[i][j] != s[ay][ax]) flga = false;
				ax = (i - k + n) % n, ay = (j + k) % n;
				if (s[i][j] != s[ay][ax]) flgb = false;
			}
		}
		if (flga) {
			REP(i, n) st.insert(P(i, (k + i) % n));
		}
		if (flgb) {
			REP(i, n) st.insert(P((i + k) % n, i));
		}
	}

	cout << st.size() << endl;
 
    return 0;
}


Measured memory_bytes: 4608
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <climits>
#include <bitset>
#include <cassert>
#include <random>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end())
#define MP make_pair
#define MT make_tuple

using namespace std;

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

const int N = 16;
double p[N][N];

double dp[N][1 << N];

int n, m;
double rec(int i, int bits){
	if (bits == 0) return 0;
	if (i == n) return 1;

	double &res = dp[i][bits];
	if (res >= -.5) return res;

	res = 0;

	rep(j, m){
		if (~bits >> j & 1) continue;
		int x = bits&~(1 << j);
		double pp = 1;
		double win = 0;
		for (int k = i; k < n; ++k){
			win += pp*(1 - p[k][j])*rec(k, x);
			pp *= p[k][j];
		}
		res = max(res, win+pp);
	}

	return res;
}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout.setf(ios::fixed);
	cout.precision(12);

	cin >> m >> n;
	rep(i, m) rep(j, n) cin >> p[j][i];

	rep(i, N) rep(j, 1 << N) dp[i][j] = -1;
	cout << rec(0, (1 << m) - 1) << endl;

	return 0;
}

Measured memory_bytes: 9492
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Extentions;

class IO
{
    int idx;
    string[] input = In.ReadToEnd().Split(new[] { " ", "\n", "\r" },
        StringSplitOptions.RemoveEmptyEntries);

    T Get<T>(Func<string, T> parser) => parser(input[idx++]);

    public string S => Get(s => s);
    public char C => Get(char.Parse);
    public int I => Get(int.Parse);
    public long L => Get(long.Parse);
    public double F => Get(double.Parse);
    public decimal D => Get(decimal.Parse);
    public BigInteger B => Get(BigInteger.Parse);

    T[] Gets<T>(int n, Func<string, T> parser)
        => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray();

    public string[] Ss(int n) => Gets(n, s => s);
    public char[] Cs(int n) => Gets(n, char.Parse);
    public int[] Is(int n) => Gets(n, int.Parse);
    public long[] Ls(int n) => Gets(n, long.Parse);
    public double[] Fs(int n) => Gets(n, double.Parse);
    public decimal[] Ds(int n) => Gets(n, decimal.Parse);
    public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse);

    public void Write<T>(params T[] xs) => WriteLine(string.Join(" ", xs));
    public void Write(params object[] xs) => WriteLine(string.Join(" ", xs));
}

static class Extentions
{
}

static class Program
{
    public static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { NewLine = "\n" };
#if DEBUG
        sw.AutoFlush = true;
#else
        sw.AutoFlush = false;
#endif
        SetOut(sw);
        Solve(new IO());
        Out.Flush();
    }

    static void Solve(IO io)
    {
        var s = io.S;
        io.Write(s.Remove(s.Length - "FESTIVAL".Length));
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;



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

	while (1) {
		int N; cin >> N;
		if (!N)return 0;
		VI A(N);
		REP(i, N)cin >> A[i];
		rSORT(A);
		if (A[0] < 2)cout << "NA" << endl;
		else {
			int sum = 0;
			REP(i, N)if (A[i])sum++;
			cout << sum + 1 << endl;
		}
	}

	return 0;
}




Measured memory_bytes: 3244
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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, 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_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

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

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      aa: [[usize; n]; n],
    }
    let mut dp = vec![vec![0; 1 << n]; n+1];
    dp[0][0] = 1;

    const MOD: usize = 1e9 as usize + 7;

    for i in 0..n {
        for j in 0usize..(1 << n) {
            if j.count_ones() != i as u32 {
                continue;
            }

            for g in 0..n {
                if aa[i][g] == 1 && (j & (1 << g) == 0) {
                    let nj = j | (1 << g);
                    // debug!(i, j, g, dp[i][j], nj);
                    dp[i+1][nj] += dp[i][j];
                    dp[i+1][nj] %= MOD;
                }
            }
        }
    }
    println!("{}", dp[n][(1 << n) - 1]);
}


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

int x,y,z;
long long sum;

long long LCM(long long o, long long p) {
	if (o == 0) return p; else
	return LCM(p%o,o);
}

int main() {
	cin >> x;
	for (int a = 1; a <= x; a++) {
		for (int b = 1; b <= x; b++) {
			for (int c = 1; c <= x; c++) {
				sum += LCM(a,LCM(b,c));
			}		
		}		
	}
	cout << sum  << "\n";
}

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

llong h, m;
llong hh, mm;
llong k;

int main() {
    cin >> h >> m >> hh >> mm >> k;
    llong s = h * 60 + m;
    llong t = hh * 60 + mm;

    cout << (t - s + 1) - k - 1 << endl;
    
    return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define N 509
#define INF 10000000000009
#define MOD 1000000007
typedef long long int ll;
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) printf("%lld\n",x);
#define pf2(x,y) printf("%d %d\n",x,y);
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<<" " << endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
ll a[N];
int pi[N][N]; // storing best k -> dp[i][j] = dp[i][k] + dp[k][j]
ll dp[N][N];

ll calculate(int n){
    int i,j,len;
    for (int len = 1; len < n; len++) {                   //s - length(size) of substring
        for (int l = 1; l+len <= n; l++) {              //l - left point

          int r = l + len;                            //r - right point

          if (len < 2) {
            dp[l][r] = a[r] - a[l-1];                          //DP base - nothing to break
            pi[l][r] = l;                          //pi is equal to left border
            continue;
          }

          int mleft = pi[l][r-1];                  //Knuth's trick: getting bounds on m
          int mright = pi[l+1][r];
          dp[l][r] = INF;

          for (int m = mleft; m<=mright; m++) {     //iterating for m in the bounds only
                ll temp = dp[l][m] + dp[m+1][r] + (a[r]-a[l-1]);
                if (dp[l][r] > temp) {                 //relax current solution
                  dp[l][r] = temp;
                  pi[l][r] = m;
                }
          }


        }
    }

    return dp[1][n];
}
int main(){
    int i,j,t,x,y,k,m,n,z;
    sd(n);
    for(i=1; i<=n; i++){
        cin >> a[i];
        a[i] += a[i-1];
    }
    ll ans = calculate(n);
    tr(ans);
    return 0;
}

// https://atcoder.jp/contests/dp/tasks/dp_n

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  map<int, int> mp;
  int a, b, c;
  cin >> a >> b >> c;
  mp[a]++;
  mp[b]++;
  mp[c]++;
  if (mp[a] == 1) cout << a << endl;
  else if (mp[b] == 1) cout << b << endl;
  else cout << c << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define N 200010
#define mod 1000000007
using namespace std;
int ans[N],stone[N];
int n;
int a[N];
int main()
{
	cin >> n;
	int sum = 1;
	for(int i = 1;i <=  n;i ++)
	{
		scanf("%d",stone + sum);
		if(stone[sum] ^ stone[sum - 1])
			sum ++;
	}
	sum --;
	ans[1] = 1;
	a[stone[1]] = 1;
	for(int i = 2;i <= sum;i ++)
	{
		int now_color = stone[i];
		ans[i] = (ans[i - 1] + ans[a[now_color]]) % mod;
		a[now_color] = i;
	}
	printf("%d\n",ans[sum]);
	return 0;
}

Measured memory_bytes: 6160
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
using namespace std;

typedef long long ll;

int main()
{
    int H,W,N;
    cin >> H >> W >> N;
    int M=max(H,W), m=min(H,W);
    int ans=N/M;
    int r=N-ans*M;
    if(r==0) cout << ans << endl;
    else cout << ans + 1 << endl;




    return 0;
}

Measured memory_bytes: 256
main :: IO()
main = do
    _ <- getLine
    line <- getLine
    let list = split ' ' line
    let reverseList = reverse list
    putWithSpase reverseList
    
putWithSpase ::  [String] -> IO()
putWithSpase (x:[]) = putStrLn  x
putWithSpase (x:xs) = putStr ( x ++ " ") >> putWithSpase xs

split d = _split d []
_split d cs "" = cs
_split d cs s = _split d (cs ++ [token d s]) (drop (length(token d s) + 1) s)
 
token d = _token d ""
_token d t "" = t
_token d t (x:xs) = if (x == d) then t else _token d (t ++ [x]) xs



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

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

bool sortby(const pair<long long,long long> &a, const pair<long long,long long> &b)
{
    if(a.first==b.first) return a.second>b.second;
    return a.first<b.first;
}

void _case()
{
    long long n,i,m,x,y,ans=0;
    vector<pair<long long,long long> > v;
    cin>>n>>m;
    for(i=0;i<n;i++){
        cin>>x>>y;
        v.push_back({x,y});
    }
    sort(v.begin(),v.end(),sortby);
    for(i=0;i<n;i++){
        if(v[i].second>=m){
            ans+= v[i].first*m;
            m-=m;
            break;
        }
        else{
            ans+= v[i].first*v[i].second;
            m-=v[i].second;
        }
    }
    cout<<ans<<'\n';
}

main()
{
    fastio();
    _case();

}



Measured memory_bytes: 5304
#include<bits/stdc++.h>
using namespace std;
int main(){
  int s;cin>>s;
  int a,b,c,d;
  a=s/1000;
  b=(s-a*1000)/100;
  c=(s-a*1000-b*100)/10;
  d=(s-a*1000-b*100-c*10);
  string op="+-";
  for(int i=0;i<2;++i){
    for(int j=0;j<2;++j){
      for(int k=0;k<2;++k){
        int res=0;
        if(op[i]=='+')res=a+b;
        else res=a-b;
        if(op[j]=='+')res+=c;
        else res-=c;
        if(op[k]=='+')res+=d;
        else res-=d;

        if(res==7){
          printf("%d%c%d%c%d%c%d=7\n",a,op[i],b,op[j],c,op[k],d);
          return 0;
        }
      }
    }
  }
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

    ll sumU[2222][2222] = {0};
    ll sumR[2222][2222] = {0};
    ll sumD[2222][2222] = {0};
    ll sumL[2222][2222] = {0};
    int h;
    int w;

void print() {
    REP(i,h) {
        REP(j,w) {
            cout << sumU[i][j] << " ";
        }
        cout << endl;
    }
}

int main(int argc, char const *argv[]) {
    cin >> h >> w;
    vector<string> s(h);

    REP(i,h) cin >> s[i];


     // U
    for (int j = 0; j < w; ++j) {
        for (int i = 1; i < h; ++i) {
            if (s[i][j] == '.') {
                if (s[i-1][j] == '#') sumU[i][j] = sumU[i-1][j];
                else sumU[i][j] = sumU[i-1][j]+1;
            }
        }
    }
 
    // D
    for (int j = 0; j < w; ++j) {
        for (int i = h-2; i >= 0; --i) {
            if (s[i][j] == '.') {
                if (s[i+1][j] == '#') sumD[i][j] = sumD[i+1][j];
                else sumD[i][j] = sumD[i+1][j]+1;
            }
        }
    }
 
    // L
    for (int i = 0; i < h; ++i) {
        for (int j = 1; j < w; ++j) {
            if (s[i][j] == '.') {
                if (s[i][j-1] == '#') sumL[i][j] = sumL[i][j-1];
                else sumL[i][j] = sumL[i][j-1]+1;
            }
        }
    }
 
    // R
    for (int i = 0; i < h; ++i) {
        for (int j = w-2; j >= 0; --j) {
            if (s[i][j] == '.') {
                if (s[i][j+1] == '#') sumR[i][j] = sumR[i][j+1];
                else sumR[i][j] = sumR[i][j+1]+1;
            }
        }
    }
    ll ans = 0;
    REP(i,h) {
        REP(j,w) {
            ll tmp = 0;
            ll U = sumU[i][j];
            ll R = sumR[i][j];
            ll D = sumD[i][j];
            ll L = sumL[i][j];
            // printf("i = %d, j = %d ,U = %lld, R = %lld, D = %lld, L = %lld\n", i, j, U, R, D, L);
            tmp += U+R+L+D;
            ans = max(ans, tmp);
        }
    }
 
    cout << ans+1 << endl;
 
    return 0;
}

Measured memory_bytes: 149760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)

/*
最大要素
*/

ll n,a[200010],b=0,c;

void init(){
	cin>>n;
	rep(i,n)cin>>a[i];
}

int main(void){
	init();
	rep(i,n){
		if(a[i]>=a[b]){
			b=i;
		}
	}
	c=-1;
	rep(i,n){
		if(i==b)continue;
		if(c==-1 || a[i]>a[c])c=i;
	}
	rep(i,n){
		if(i==b){
			cout<<a[c]<<endl;
		}else{
			cout<<a[b]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3200
L, R = map(int, input().split())

choices = set()
for i in range(L, R + 1):
    choices.add(i % 2019)
    if len(choices) == 2019:
        break

min_ = None
choices = sorted(choices)
for i in range(len(choices)):
    vi = choices[i]
    for j in range(i + 1, len(choices)):
        vj = choices[j]
        if min_ is None or (vi * vj) % 2019 < min_:
            min_ = (vi * vj) % 2019
print(min_)


Measured memory_bytes: 41196
#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.14159265358979323846;
long long dp[55][55][2505] = {0};

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

    int n, a;
    cin >> n >> a;
    vector<int> arr(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> arr[i];
    }
    dp[0][0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= n; ++j) {
            for (int k = 0; k <= 2500 - arr[i + 1]; ++k) {
                dp[i + 1][j][k] += dp[i][j][k];
                dp[i + 1][j + 1][k + arr[i + 1]] += dp[i][j][k];
            }
        }
    }
    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += dp[n][i][a * i];
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 54528