akhauriyash/Code-Regression huggingface dataset:
n,m,q=gets.chomp.split.map(&:to_i)
k=(1..m).to_a.repeated_combination(n).to_a




array=[]
q.times{
  array << gets.chomp.split.map(&:to_i)
  }
sum=[]

k.each do |p|
  #p p
  u=0
  array.each do |y|
    #p y
	if (p[y[1]-1] - p[y[0]-1])==y[2]
    	u+=y[3]
    end
  end
  sum << u
end

puts sum.max

Measured memory_bytes: 28956
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 2e3 + 5;
const ll MOD = 1e9 + 7;
int N, M, Q;
int A[MAXN];

int main() {
	int i, j;
	scanf("%d", &N);
	for (i = 1; i <= N; ++i) scanf("%d", &A[i]);
	A[N + 1] = INF;
	sort(A + 1, A + 1 + N);
	ll sum = 0ll;
	for (i = 1; i <= N; ++i) {
		for (j = i + 1; j <= N; ++j) {
			int a = A[i];
			int b = A[j];
			int *idx1 = upper_bound(A + 1, A + 2 + N, b - a);
			int *idx2 = lower_bound(A + 1, A + 2 + N, a + b);
			int num1 = *idx1;
			int num2 = *idx2;
			int s = idx2 - idx1;
			if (num1 <= a && a < num2) --s;
			if (num1 <= b && b < num2) --s;
			sum += (ll)s;
		}
	}
	printf("%lld", sum/3ll);
	return 0;
}

Measured memory_bytes: 256
n=int(input())
c=[]
s=[]
f=[]

for i in range(n-1):
    C,S,F=map(int,input().split())
    c.append(C)
    s.append(S)
    f.append(F)
T=[-1]*n
T[-1]=0
for i in range(n-1):
    p=i
    t=0
    for j in range(n-i-1):
        if t<=s[p]:
            t=s[p]
            t+=c[p]
        else:
            m=(t+f[p]-1)//f[p]
            t=m*f[p]
            t+=c[p]
        p+=1
    T[i]=t
for i in range(n):
    print(T[i])


Measured memory_bytes: 68188
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;



int main() {
int N;
cin>>N;
bool time_table[N][10];
rep(i,N){
  rep(j,10){
    
    cin>>time_table[i][j];
  }
}
ll P[N][11];
rep(i,N){
  rep(j,11){
    cin>>P[i][j];
  }
}
ll max_sum=-1e9;
rep(i,1<<10){
  if(__builtin_popcount(i)==0)continue;
  int count[N];
  rep(j,N)count[j]=0;
  rep(j,10){
    if(i&(1<<j)){
      rep(k,N){
        if(time_table[k][j]){
          count[k]++;
        }
      }
    }
  }
  ll sum=0;
  rep(j,N){
    sum+=P[j][count[j]];
  }
  max_sum=max(max_sum,sum);


}
cout<<max_sum<<endl;

return 0;
}

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

using namespace std;


int main(){
  const double PI = acos(-1.0);
  double a, b, x;
  cin >> a >> b >> x;
  
  x /= a;
  
  cout << fixed << setprecision(10);
  if(x>a*b/2) cout << atan2((a*b-x)*2, a*a) * 180 / PI << endl;
  else cout << atan2(b*b, x*2) * 180 / PI << endl;
  
  
  return 0;
}

Measured memory_bytes: 4092
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
set<int> st;
int main(){
    int n;
    pair<int,int> a[110],b[110];
    cin>>n;
    lol(i,n){
	cin>>a[i].second>>a[i].first;
    }
    sort(a,a+n);
    lol(i,n){
	cin>>b[i].second>>b[i].first;
    }
    sort(b,b+n);
    int ans=0;
    int pnt=0;
    lol(i,n){
	while(pnt<n){
	    if(a[pnt].first<b[i].first){
		st.insert(a[pnt].second);
		pnt++;
	    }
	    else break;
	}
	set<int>::iterator it=lower_bound(st.begin(),st.end(),b[i].second);
	if(it==st.begin())continue;
	ans++;it--;
	st.erase(it);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int gcd(int x, int y);
int main(){
  int n,m;
  while(cin >>n>>m){
    int x = gcd(n,m);
    cout <<x<<" "<<(n/x)*m<<endl;
  }
  return 0;
}
int gcd(int x, int y){
  int r = x%y;
  if(r == 0) return y;
  else return gcd(y,r);
}

Measured memory_bytes: 1160
import sys

def comb_mod(n, r, MOD=10**9+7):
    if n < 0 or r < 0 or n < r:
        return 0

    factrial = [1] * (n+1)
    for k in range(1, n+1):
        factrial[k] = (factrial[k-1] * k) % MOD

    fact_inv = [1] * (n+1)
    fact_inv[n] = pow(factrial[n], MOD - 2, MOD)
    for k in range(n-1, -1, -1):
        fact_inv[k] = (fact_inv[k+1] * (k+1)) % MOD

    return (factrial[n] * fact_inv[r] * fact_inv[n-r]) % MOD

def main():
    input = sys.stdin.readline
    MOD = 10**9 + 7
    X, Y = map(int, input().split())

    x1, x2 = 0, 0
    while min(X, Y) > 0:
        if 2*X == Y:
            x1 += X
            n = x1 + x2
            r = min(x1, x2)
            return comb_mod(n, r, MOD)
        
        elif X == 2*Y:
            x2 += Y
            n = x1 + x2
            r = min(x1, x2)
            return comb_mod(n, r, MOD)

        elif X >= Y:
            x2 += 1
            X -= 2
            Y -= 1
        
        else:
            x1 += 1
            X -= 1
            Y -= 2

    return 0

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 55668
S=str(input())

N=len(S)
i=0
r="No"

s=int((N-1)/2)
t=int((N+3)/2)

a=S[0:s]
b=S[t-1:N]

if(N==3 and S==S[::-1]):
  print("Yes")
elif(S==S[::-1] and a==(a[::-1]) and b==(b[::-1])):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;

int main(){
  int N = 0;
  cin >> N;
  long double n[100];
  n[0] = 2;
  n[1] = 1;
  int i = 2;
  while(i < 100){
    n[i] = n[i-1]+n[i-2];
    i++;
  }
  cout << fixed << setprecision(0) << n[N];
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const int mod = 1e9+7;
const int N = 1e6+5;
//int a[N];

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int ans = 1, tmp = 1;

    string s;

    cin >> s;

    for (int i = 1; i < s.size(); i++) {

        if (tmp == 2) tmp = 1;
        else if (s[i] == s[i-1]) {

        	tmp = 2;
        	if (i == s.size()-1) break;
        	i++;
        }

        ans++;
    }

    cout << ans;

    return 0;
}


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

LL A[mx5], B[mx5], C[mx5], cb[mx5];

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

    for(int i = 0; i < n; i++)
        cin >> A[i];
    for(int i = 0; i < n; i++)
        cin >> B[i];
    for(int i = 0; i < n; i++)
        cin >> C[i];

    sort(A, A + n);
    sort(B, B + n);
    sort(C, C + n);

    int c = 0;
    for(int i = 0; i < n; i++){
        int l = 0, r = n - 1;
        while(l <= r){
            int mid = (l + r) >> 1;
            if(C[mid] > B[i])
                r = mid - 1;
            else
                l = mid + 1;
        }

        cb[i] = n - l;
    }

    for(int i = n; i >= 0; i--)
        cb[i] += cb[i + 1];

    c = 0;
    LL ans = 0;

    for(int i = 0; i < n; i++){
        int l = 0, r = n - 1;
        while(l <= r){
            int mid = (l + r) >> 1;
            if(B[mid] > A[i])
                r = mid - 1;
            else
                l = mid + 1;
        }

        ans += cb[l];
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 6812
// Remember...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=1e5+10,mod=1e9+7;
const ll inf=1e18;

vector<int> v;

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

    string s; cin>>s;
    int k; cin>>k;
    ll ans=0;
    char ch=s[0];
    int cnt=0;
    for(int i=0;i<sz(s);i++){
	if(ch==s[i]) cnt++;
	else v.PB(cnt), cnt=1, ch=s[i];
    }
    v.PB(cnt);

    if(sz(v)==1){
	ans=(1ll*k*sz(s))/2;
    }
    else{
	for(int i=1;i<sz(v)-1;i++){
	    ans+= 1ll*k*(v[i]/2);
	}
	if(s[0]==s.back()){
	    ans+=v[0]/2, ans+=v.back()/2;
	    ans+= 1ll*(k-1)*((v[0]+v.back()) /2);
	}
	else{
	    ans+= 1ll*k*((v[0]/2)+(v.back()/2));
	}
    }
    return cout<<ans<<endl,0;
}
// Deathly mistakes:
//  * Read the problem carefully.
//  * Check maxn.
//  * Overflows.


// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;

struct P{
	int x,y;
	P(int x_, int y_){
		x = x_; y = y_;
	}
	P(){}
};
bool exist[5001][5001];
int x[3001], y[3001];

int main(){
	int n;
	while( cin >> n , n ){
		for(int i=0 ; i < 5001 ; i++ ){
			for(int j=0 ; j < 5001 ; j++ ){
				exist[i][j] = false;
			}
		}
		for(int i=0 ; i < n ; i++ ){
			cin >> x[i] >> y[i];
			exist[y[i]][x[i]] = true;
		}
		int ans = 0;
		for(int i=0 ; i < n ; i++ ){
			for(int j=i+1 ; j < n ; j++ ){
				P p1 = P( x[i] , y[i] );
				P p2 = P( x[j] , y[j] );
				int dx = abs(p1.x - p2.x);
				int dy = abs(p1.y - p2.y);
				P p3( p2.x - dy , p2.y + dx );
				P p4( p1.x - dy , p1.y + dx );
				if( p3.x < 0 || p3.x > 5000 || p3.y < 0 || p3.y > 5000 ) continue;
				if( p4.x < 0 || p4.x > 5000 || p4.y < 0 || p4.y > 5000 ) continue;
				if( exist[p3.y][p3.x] && exist[p4.y][p4.x] ){
					ans = max( ans , dx*dx + dy*dy );
				}
				p3 = P( p1.x + dy , p1.y - dx );
				p4 = P( p2.x + dy , p2.y - dx );
				if( p3.x < 0 || p3.x > 5000 || p3.y < 0 || p3.y > 5000 ) continue;
				if( p4.x < 0 || p4.x > 5000 || p4.y < 0 || p4.y > 5000 ) continue;
				if( exist[p3.y][p3.x] && exist[p4.y][p4.x] ){
					ans = max( ans , dx*dx + dy*dy );
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 24000
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main(){
	int l,r;cin>>l>>r;
	vector<P>v;
	for(int i=0;i<2019;i++){
		int x=(r-i)/2019*2019+i;
		if(l<=x&&x<=r)v.push_back(P(x,i));
		x=(l-i)/2019*2019+i+2019;
		if(l<=x&&x<=r)v.push_back(P(x,i));
	}
	sort(v.begin(),v.end());
	int Min=INT_MAX;
	rep(i,v.size()){
		for(int j=i+1;j<v.size();j++)Min=min(Min,v[i].second*v[j].second%2019);
	}
	cout<<Min<<endl;
}

Measured memory_bytes: 256
N = int(input())
pos = [0, 0, 0]
ans = 'Yes'
for i in range(N):
  t, x, y = map(int, input().split())
  if t-pos[0] >= abs(x-pos[1]) + abs(y-pos[2]):
    if ((t-pos[0]) % 2 == 0) and ((abs(x-pos[1]) + abs(y-pos[2])) % 2 == 0):
      pos = [t, x, y]
    elif ((t-pos[0]) % 2 == 1) and ((abs(x-pos[1]) + abs(y-pos[2])) % 2 == 1):
      pos = [t, x, y]
    else:
      ans = 'No'
      break
  else:
    ans = 'No'
    break
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int m,nmin,nmax;

void solve(){
    vi p(m);
    int gap = -1;
    int ans = -1;
    rep(i,m) cin >> p[i];
    for(int i=nmin;i<=nmax;i++){
        int d = p[i-1] - p[i];
        //cout << p[i] << " " << p[i-1] << endl;
        if(gap <= d){
            gap = d;
            ans = i;
        }
    }
    cout << ans << endl;
}

int main(){
    while(1){
        cin >> m >> nmin >> nmax;
        if(m==0 and nmin == 0 and nmax == 0) break;
        solve();
    }
}

Measured memory_bytes: 3060
def main():
     def gcd(a, b):
          while b:
               a, b = b, a % b
          return a

     def lcm(a, b):
          return a * b // gcd (a, b)
     a,b,c,d=map(int,input().split())
     ans=b-a+1
     ans-=(b)//c-(a-1)//c
     ans-=(b)//d-(a-1)//d
     cd=lcm(c,d)
     ans+=(b)//(cd)-(a-1)//(cd)
     print(ans)
     
if __name__=='__main__':
     main()

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int a, b;

int main() {
    cin >> a >> b;
    if (a <= 8 && b <= 8) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
    return 0;
}


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

int main(){
  int A[1000],N,ans=0;
  cin>>N;
  for(int i=0;i<2*N;i++)cin>>A[i];
  sort(A,A+N*2);
  for(int i=0;i<N;i++) ans+=A[2*i];
  
  cout<<ans<<endl;
    
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
using ll = long long;


int main() {
	
	int a, b;
	cin >> a >> b;
	
	if ( a % 2 == 0 or b % 2 == 0)
      cout << "No" << endl;
	else
      cout << "Yes" << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  Int n,t;
  cin>>n>>t;
  vector<Int> as(n),bs(n);
  for(Int i=0;i<n;i++) cin>>as[i]>>bs[i];

  vector<Int> cs;
  using P = pair<Int, Int>;
  vector<P> vp;
  for(Int i=0;i<n;i++){
    if(as[i]==0){
      cs.emplace_back(bs[i]);
    }else{
      vp.emplace_back(as[i],bs[i]);
    }
  }

  auto cmp=[&](P x,P y){
             return (x.second+1)*(y.first+0)<(y.second+1)*(x.first+0);
           };
  sort(vp.begin(),vp.end(),cmp);

  n=vp.size();
  as.resize(n);bs.resize(n);
  for(Int i=0;i<n;i++)
    tie(as[i],bs[i])=vp[i];

  const Int LOG = 40;
  vector<Int> dp(LOG,t+1000);
  dp[0]=0;
  for(Int i=0;i<n;i++)
    for(Int j=LOG-2;j>=0;j--)
      chmin(dp[j+1],(dp[j]+1)+as[i]*(dp[j]+1)+bs[i]);

  Int m=cs.size();
  sort(cs.begin(),cs.end());
  vector<Int> sm(m+1,0);
  for(Int i=0;i<m;i++) sm[i+1]=sm[i]+1+cs[i];

  Int ans=0;
  for(Int j=0;j<LOG;j++){
    if(dp[j]>t) break;
    Int num=--upper_bound(sm.begin(),sm.end(),t-dp[j])-sm.begin();
    chmax(ans,j+num);
  }

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


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cout <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cout <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb() fflush(stdout);

using namespace std;

char s[100005];

int main() {
	make(n);
	scanf("%s", s);
	int diff = 0;
	FOR(i,0,n) if (s[i] == 'R') diff++; else diff--;
	if (diff > 0) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}

}






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

int main (){
	int score [10];
	int r,d,x;
	cin >> r >> d >> x;
	score[0] = x * r - d;
		cout << score[0] << endl;
	for (int i=1;i<10;i++){
		score[i] = score[i-1] * r - d;
		cout << score[i] << endl;
	}
}


Measured memory_bytes: 256
#include <stdio.h>

main() {
    int x1,y1,x2,y2;
    int x,y,x3,y3,y4,x4;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    x=x2-x1;
    if(x<0) x=0-x;
    y=y2-y1;
    if(y<0) y=0-y;
    if(x2>=x1 && y2>=y1) {
        y3=y2+x;
        x3=x2-y;
        y4=y3-y;
        x4=x3-x;
    }
    if(x2>=x1 && y2<=y1) {
        y3=y2+x;
        x3=x2+y;
        y4=y3+y;
        x4=x3-x;
    }
    if(x2<=x1 && y1>=y2) {
        y3=y2-x;
        x3=x2+y;
        y4=y3+y;
        x4=x3+x;
    }
    if(x2<=x1 && y1<=y2) {
        y3=y2-x;
        x3=x2-y;
        y4=y3-y;
        x4=x3+x;
    }
    printf("%d %d %d %d\n", x3, y3, x4, y4);
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

ll DP[100005];
vector<vector<pair<int, ll> > > edge(100005);

void solve(int u, int v){
    if(DP[v]>-1) return ;
    if(u==-1) {
        DP[v] = 0;
    }
    for(int i=0;i<edge[v].size();++i){
        if(edge[v][i].fi==u) DP[v] = DP[u] + edge[v][i].se;
    }
    for(int i=0;i<edge[v].size();++i){
        if(DP[edge[v][i].fi]>0) continue;
        solve(v, edge[v][i].fi);
    }
}

int main() {
    int N;
    cin>>N;
    for(int i=0;i<N;++i){
        DP[i] = -1;
    }
    int a, b;
    ll c;
    for(int i=0;i<N-1;++i){
        cin>>a>>b>>c;
        a--;
        b--;
        edge[a].push_back(mp(b, c));
        edge[b].push_back(mp(a, c));
    }
    int Q, K;
    cin>>Q>>K;
    K--;
    solve(-1, K);
    int x, y;
    ll ans[Q];
    for(int i=0;i<Q;++i){
        cin>>x>>y;
        x--;
        y--;
        ans[i] = DP[x] + DP[y];
    }
    for(int i=0;i<Q;++i){
        cout<<ans[i]<<endl;
    }
}



Measured memory_bytes: 12800
X=int(input())
#m1,d1=map(int,input().split())
#hl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

flag=0
for i in range(1,1001):
    if i*100 <= X and X <= i*105:
        flag=1
        break
print(flag)


Measured memory_bytes: 9160
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n, m;
    cin >> n >> m;
    ll cost[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    vector<int> a(m);
    rep(i, m) cin >> a[i];

    string dp[11000];
    rep(i, 11000) dp[i] = "-";
    dp[0] = "";
    for (ll i = 0; i <= n; i++) {
        if (dp[i] == "-") continue;
        rep(j, m) {
            string b = dp[i] + (char)('0' + a[j]);
            if (dp[i+cost[a[j]]].size() < b.size() ) dp[i+cost[a[j]]] = b;
            else if (dp[i+cost[a[j]]].size() == b.size() ) {
                if (dp[i+cost[a[j]]] < b) dp[i+cost[a[j]]] = b;
            }
        }
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 45056
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = numeric_limits<ll>::max() / 4;
namespace utils{
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
    using V_Set = unordered_set<int>;
    using E_Set = unordered_map<int, V_Set>;

#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
}
using namespace utils;


void sub_main(istream &is) {
    ll N, k;
    is >> N >> k;
    if(!is) return;
    cout << int(ceil(N / (2*k + 1.))) << endl;

}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
#ifdef DEBUG
    string test_cases = "test_B.txt";
    cerr << "DEBUG MODE" <<  endl;
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#" << endl;
    if(lp <= 1) sub_main(cin);
#else
    sub_main(cin);
#endif
    return 0;
}


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

int main()
{
  int N, M;
  cin >> N;
  int Problems[N];
  for (int i = 0; i < N; i++)
  {
    cin >> Problems[i];
  }
  cin >> M;
  int ans[M];
  for (int j = 0; j < M; j++)
  {
    int P, T, sum = 0;
    cin >> P >> T;
    for (int k = 0; k < N; k++)
    {
      if (k != P-1)
      {
        sum += Problems[k];
      }
      else
      {
        sum += T;
      }
    }
    ans[j] = sum;
  }
  for (int a = 0; a < M ; a++)
  {
      cout << ans[a] << endl;
  }
  return 0;
}

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


int main() {
    string x,y;
	cin >> x>> y;
    string ans;
    if(x==y)ans="H";
    else ans = "D";
      cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	var fourNum int
	for {
		rest := n - fourNum*4
		if rest < 0 {
			fmt.Println("No")
			return
		}
		if rest%7 == 0 {
			fmt.Println("Yes")
			return
		}
		fourNum++
	}
}


Measured memory_bytes: 1768
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    cin >> n;
    ll ans=0;
    rep1eq(i,1,n){
        if(i%3!=0 && i%5!=0) ans+=i;
    }

    cout << ans <<endl;
    return 0;

}

Measured memory_bytes: 3644
num_500 = int(input())
num_100 = int(input())
num_50 = int(input())
ans = int(input())

resultCnt = 0

for i in range(num_500+1):
  for j in range(num_100+1):
    for k in range(num_50+1):
      if 500*i + 100*j + 50*k == ans:
        resultCnt += 1

print(resultCnt)

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

const ll M = 1000000007;

vector<ll> fac(2000005);
vector<ll> ifac(2000005);
//べき乗高速化
ll mpow(ll x, ll n){
	ll ans = 1;
	while(n != 0){
		if (n&1) ans = ans * x % M;
		x = x*x % M;
		n  = n >> 1;
	}
	return ans;
}

//aCbを計算
ll comb(ll a, ll b){
	if (a == 0 && b == 0) return 1;
	if (a < b || a < 0){
		return 0;
	}
	ll temp = ifac[a-b] * ifac[b] % M;
	return temp * fac[a] % M;
}

int main(){
	ll k;
	cin >> k;
	string s;
	cin >> s;
	ll l = s.size();
	fac[0] = 1;
	ifac[0] = 1;
	for(ll i = 0; i<= 2000000; i++){
		fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
		ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
	}
	ll ans = 0;
	for (ll i = 0; i <= k; ++i) {
		ll count = mpow(26,i);
		count *=comb(l+k-i-1, l-1);
		count %= M;
		count *= mpow(25, k-i);
		ans += count % M;
		ans %= M;
	}
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 36600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}


void solve(long long r){
    cout << 3 * r * r  << endl;
}

int main(){
    long long r;
    scanf("%lld",&r);
    solve(r);
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  ll N,K; cin>>N>>K;
  string S; cin>>S;
  
  ll count=0;
  rep(i,N){
    if(S[i]=='L'&&(i==0||S[i-1]=='R')) count++;
    else if(S[i]=='R'&&(i==N-1||S[i+1]=='L')) count++;
  }
  
  count=max((ll)1,count-2*K);
  
  cout<<N-count<<endl;
  return 0;
}

Measured memory_bytes: 3752
#include <iostream>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)

int main(){
  int n;
  cin >> n;
  int a[n];
  int sum = 0;
  REP(i, n){
    cin >> a[i];
    if(i & 1){
      sum -= a[i];
    }else{
      sum += a[i];
    }
  }
  cout << sum;
  REP(i, n - 1){
    sum = a[i] * 2 - sum;
    cout << " " << sum;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>

main(){
	char buf[10101];
	scanf("%s",buf);
	
	
	int n=0,s=0,e=0,w=0;
	for(int i=0;buf[i];i++){
		if(buf[i]=='N')n++;
		if(buf[i]=='S')s++;
		if(buf[i]=='E')e++;
		if(buf[i]=='W')w++;
	}
	if((n>0 && s==0) || (s>0 && n==0) || (e>0 && w==0) || (w>0 && e==0))puts("No");
	else puts("Yes");
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
	int n,i,a[10000],min,max;
	long sum = 0;
	
	scanf("%d",&n);
	
	scanf("%d",&a[0]);
	min = a[0];
	max = a[0];
	sum += a[0];
	
	for(i = 1;i < n;i++){
		scanf("%d",&a[i]);
		if(a[i] > max) max = a[i];
		if(a[i] < min) min = a[i];
		sum += a[i];
	}
	printf("%d %d %ld\n",min,max,sum);
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(void){
    int a,i,n,min=1000001,max=-1000001;
    long long sum=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a);
        if(a<min) min=a;
        if(a>max) max=a;
        sum=sum+a;
    }
    printf("%d %d %lld\n",min,max,sum);
    return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>> &pq) {return (ll)pq.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>, greater<T>> &pq) {return (ll)pq.size(); }
ll sz(string &s) {return (ll)s.size(); } 
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
bool checkindex(ll i,ll n){ return (i < n && i >= 0); }
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

using P = pair<ll,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

struct edge{
    ll to,cost;  
};

void dijkstra(ll V,vector<vector<edge> > &G,vector<ll> &d,ll s){
    PQ que;
    fill(d.begin(),d.end(), LINF);
    d[s] = 0;
    que.push(P(0,s));

    while(!que.empty()){
        P p = que.top(); que.pop();
        ll v = p.second;
        if(d[v] < p.first) continue;

        rep(i,0,G[v].size()){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }


}

int main(){
    ll n,u,v;
    cin >> n >> u >> v;
    u--;v--;
    vector<vector<edge>> G(n);
    
    ll a,b;
    rep(i,0,n-1){
        cin >> a >> b;
        a--;b--;
        edge e;
        e.cost = 1; e.to = b;
        G[a].push_back(e);
        e.to = a;
        G[b].push_back(e);
    }

    vector<ll> d(n),d2(n);
    dijkstra(n,G,d,v);
    dijkstra(n,G,d2,u);

    ll ans = 0;
    rep(i,0,n){
        if(d[i] >= d2[i]){
            ans = max(ans,d[i]-1);
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 13020
#include <cmath>
#include <iostream>
#include <vector>

int main() {
  std::string nums;
  std::cin >> nums;
  for (size_t i = 0; i < std::pow(2, 3); ++i) {
    int result = nums[0] - '0';
    int flags = i;
    for (size_t j = 1; j < 4; ++j) {
      auto plus = flags & 1;
      flags >>= 1;
      if (plus)
        result += nums[j] - '0';
      else
        result -= nums[j] - '0';
    }
    if (result == 7) {
      std::cout << nums[0] - '0';
      flags = i;
      for (size_t j = 1; j < 4; ++j) {
        std::cout << (flags & 1 ? "+" : "-") << nums[j];
        flags >>= 1;
      }
      std::cout << "=7" << std::endl;
      return 0;
    }
  }
}

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

set<UL> ans;
ULL P[] = { 2,3,5,7,11,13,17,19,23,29,31,37 };
ULL I[] = { 5,3,2,1,1,1,1,1,1,1,1,1 };
vector<ULL> D;

int main() {
	D = { 1 };
	rep(i, 12) {
		UL p = D.size();
		rep(j, I[i]) rep(pp, p)
			D.push_back(D[D.size() - p] * P[i]);
	}
	UL N; cin >> N;
	UL A[40]; rep(i, N) cin >> A[i];
	rep(i, D.size()) {
		UL tmp = 0;
		rep(j, N) {
			if (D[i] % A[j] == 0)
				tmp |= (1u << j);
		}
		if (tmp) ans.insert(tmp);
	}
	cout << ans.size() << endl;
	return 0;
}



Measured memory_bytes: 4028
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int a,b,x,y,z;
	cin>>a>>b;
	x=a+b;
	x=x*5;
	if(x%10>=5) x=x+10;
	x=x/10;
	cout<<x<<endl;
	return 0;
}


Measured memory_bytes: 256
#0. setting
CHR_A = ord("a") #97
NUM_CHR = 26
CHR_LIST = [chr(CHR_A+i) for i in range(NUM_CHR)]

def addChar(s, chr_list):
    for char in chr_list:
        if not(char in s):
            s = s+char
            break
    return s

def removeTail(s):
    for i in range(1,NUM_CHR):
        if ord(s[-1])<ord(s[-2]):
            s = s[:-1]
        else:
            s = s[:-1]
            last_s = s[-1]
            s = s[:-1:1]
            candidate = [chr(i) for i in range(ord(last_s)+1, CHR_A+NUM_CHR)]
            s = addChar(s, candidate)
            break
    return s

def main():
    #1. input
    s = input()

    #sp. output -1 if S='zyx...a'
    if s == ''.join(CHR_LIST[::-1]):
        print(-1)
    
    
    #2. add next char if |S| <= 25
    elif len(s) <= 25:
        s = addChar(s, CHR_LIST)
        print(s)
    
    
    #3. jump next step if |S| == 26
    else:
        s = removeTail(s)
        print(s)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const ll mod=1e9+7;
void solve(){
	int i, j, n, m;
	cin>>n;
	m=3;
	int arr[n][3];
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin>>arr[i][j];
		}
	}
	for(i=1;i<n;i++){
		for(j=0;j<m;j++){
			int ma=0;
			for(int k=0;k<m;k++){
				if(k==j){
					continue;
				}
				ma=max(ma, arr[i-1][k]);
			}
			arr[i][j]+=ma;
		}
	}
	cout<<*max_element(arr[n-1], arr[n-1] + m)<<endl;
}

int main()
{
	solve();
	return 0;
}

Measured memory_bytes: 1408
def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)

T = int(input())

for _ in range(T):
    a, b, c, d = map(int, input().split())

    if a < b or d < b:
        flag = False
    elif c >= b - 1:
        flag = True
    else:
        g = gcd(b, d)
        flag = (b + a % g - g) <= c

    if flag:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3064
// abc053b: A to Z String
#include <stdio.h>
#include <string.h>

int main(){
  char s[200001];
  scanf("%s",s);
  int len = strlen(s);
  int start = -1;
  int end = -1;
  for(int i=0;i<len;i++){
    if(start<0){
      if(s[i]=='A') start = i;
    }else{
      if(s[i]=='Z') end = i;
    }
  }
  printf("%d\n",end-start+1);
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cstring>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
int i, j, k;
int m, n, coun, ans, jud = 1, s;
int town[11][11];
P start;
void dfs(int y, int x, int flag);

inline int bit(int n, int i) {
	return n | 1 << i;
}

inline bool bitj(int n, int i) {
	if (n & 1 << i )
		return false;
	else
		return true;
}
int main() {
	while (cin >> m >> n&& m && n) {
		ans = 0;
		coun = 1;
		for (i = 1; i <= n; i++) {
			for (j = 1; j <= m; j++) {
				cin >> town[i][j];
				if (town[i][j] == 2) {
					start = make_pair(i, j);
					s = coun;
				}
				if (town[i][j]) {
					town[i][j] = coun;
					coun++;
				}
			}
		}
		jud = 1;
		for (i = 0; i < coun; i++) {
			jud *= 2;
		}
		dfs(start.first, start.second, 1 << s);
		cout << ans << endl;
	}
}
void dfs(int y, int x, int flag) {
	/*if (start == make_pair(y, x)) {
		if (flag == jud - 1) {
			ans++;
		}
		if (flag) {
			return;
		}
	}*/
	for (i = x + 1; i <= m; i++) {
		if (town[y][i] && bitj(flag, town[y][i])) {
			dfs(y, i, bit(flag, town[y][i]));
			break;
		}
		if (town[y][i] == s&&bit(flag, town[y][i]) == jud - 2) {
			ans++;
			break;
		}
	}
	for (i = x - 1; i > 0; i--) {
		if (town[y][i] && bitj(flag, town[y][i])) {
			dfs(y, i, bit(flag, town[y][i]));
			break;
		}
		if (town[y][i] == s&&bit(flag, town[y][i]) == jud - 2) {
			ans++;
			break;
		}
	}
	for (i = y + 1; i <= n; i++) {
		if (town[i][x] && bitj(flag, town[i][x])) {
			dfs(i, x, bit(flag, town[i][x]));
			break;
		}
		if (town[i][x] == s&&bit(flag, town[i][x]) == jud - 2) {
			ans++;
			break;
		}
	}
	for (i = y - 1; i > 0; i--) {
		if (town[i][x] && bitj(flag, town[i][x])) {
			dfs(i, x, bit(flag, town[i][x]));
			break;
		}
		if (town[i][x] == s&&bit(flag, town[i][x]) == jud - 2) {
			ans++;
			break;
		}
	}
}

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

int main()
{
	int n,k,num=1;
	cin>>n>>k;
	while(n--)
	{
		if(num<=k)
			num=2*num;
		else
			num=num+k;
	}
	cout<<num<<endl;
	return 0;
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

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

const int mod = (int)1e9 + 7;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}

int mx;
vector<pair<int, int>> g[MX];
vector<int> res;

void dfs(int x, int par, int c){
	int color = (c + 1) % mx;
	for(auto &p : g[x]){
		int y = p.X;
		int id = p.Y;
		if(y == par) continue;
		res[id] = color;
		dfs(y, x, res[id]);
		color = (color + 1) % mx;
	}
}

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);

	int n;
	cin >> n;

	for(int i = 0; i < n - 1; ++i){
		int x, y;
		cin >> x >> y;
		--x, --y;
		g[x].push_back({y, i});
		g[y].push_back({x, i});
	}

	for(int i = 0; i < n; ++i)
		mx = max(mx, (int)g[i].size());

	res.resize(n - 1);

	dfs(0, -1, -1);

	cout << mx << endl;
	for(auto &x : res) cout << x + 1 << "\n";
	
	return 0;
}

Measured memory_bytes: 7552
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;
long long T[100010];
int main()
{
	long long N,C,K,i,ans,c,t;
	scanf("%lld%lld%lld",&N,&C,&K);
	memset(T,0,sizeof(T));
	for(i=0;i<N;i++)
		scanf("%lld",&T[i]);
	sort(T,T+N);
	for(t=0,ans=c=i=1;i<N;i++)
	{
		if(T[i]<=T[t]+K&&c<C)
		{
			c++;
		}
		else
		{
			ans++;
			c=1;
			t=i;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}



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

	int d=POW(2,k);
	cout<<max(a,max(b,c))*(d-1)+a+b+c<<endl;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef unsigned long long u64;
typedef signed long long l64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int size_s = s.size();
  int min_b = 101;
  for (char c = 'a'; c <= 'z'; ++c) {
    int max_c = 0;
    int now_c = 0;
    for (int i = 0; i < size_s; ++i) {
      if (s[i] == c) {
        max_c = max(max_c, now_c);
        now_c = 0;
      } else {
        now_c++;
      }
    }
    max_c = max(max_c, now_c);
    min_b = min(min_b, max_c);
  }
  cout << min_b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };
LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)

// ---- ----

int main() {
	string s, t;
	cin >> s >> t;
	
	cout << t << s << endl;
	
	return 0;
}


Measured memory_bytes: 384