akhauriyash/Code-Regression huggingface dataset:
import sys
n = int(input())
l = list(map(int,input().split()))
##print(n)
##print(l)
x = l[0]
if 0 in l:
  print(0)
  sys.exit()
for i in range(1,n):
  ##print(i)
  ##print(l[i])
  x *= l[i]
  if x >+ 1000000000000000000:
    ##print(i)
    ##print(x)
    print(-1)
    sys.exit()
print(x)

Measured memory_bytes: 21464
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "{ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "}";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

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

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#ifdef LOCAL
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll N, K;
    cin >> N >> K;
    ll INF = 1LL << 60;

    vector<ll> A(N);
    REP(i, N) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    ll t = INF;
    ll b = -INF;

    while(t - b > 1) {
        ll m = (t + b) / 2;
        ll c = 0;
        REP(i, A.size()) {
            if (A[i] * A[i] <= m) --c;
            if (A[i] < 0) {
                ll mn = (m / A[i]) - 1;
                while (mn * A[i] > m) ++mn;
                int pos = lower_bound(A.begin(), A.end(), mn) - A.begin();
                c += N - pos;
            } else if (A[i] > 0) {
                ll mx = (m / A[i]) + 1;
                while (mx * A[i] > m) --mx;
                int pos = upper_bound(A.begin(), A.end(), mx) - A.begin();
                c += pos;
            } else {
                if (m >= 0) {
                    c += N;
                }
            }
        }

        c /= 2;
        if (c >= K) {
            t = m;
        } else {
            b = m;
        }
    }

    cout << b + 1 << endl;




    
}


Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int[]a = new int[5];
    ArrayList<Integer>b = new ArrayList<>();

    int count = 0;
    int all = 0;
    for(int i=0; i<5; i++) {
    	a[i] = sc.nextInt();
    	if(a[i]%10==0) {
    		all += a[i];
    		count++;
    	}
    }
    if(count == 5) {
    	System.out.println(all);
    }else{
    	for(int i=0; i<5; i++) {
       	if(a[i]%10 != 0) {
    		b.add(a[i]%10); 
    	}
    	}
    Collections.sort(b);
    int last = 0;
    for(int i=0; i<5; i++) {
    	if(a[i]%10 == b.get(0)) {
    		last = a[i];
    		break;
    	}
    }
    int al = 0;
    int cou = 0;
    for(int i=0; i<5; i++) {
    	if(a[i] != last) {
    		if(a[i]%10==0) {
    			al += a[i];
    		}else {
    			al += ((a[i]/10)+1)*10;
    		}
    		cou++;
    	}
     }
    if(cou != 4) {
    	al += ((last/10)+1)*10*(4-cou);
    }
    System.out.println(al + last);
    }
}
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a,b,c,r1,r2,r3;
  r1=0;
  r2=0;
  r3=0;
  cin>>a>>b>>c;
  fr(i,a){
    int x;
    cin>>x;
    if(x>b){
      if(x<=c){
        ++r2;
      }
      else{
        ++r3;
      }
    }
    else{
      ++r1;
    }
  }
  cout<<min(r1,min(r2,r3));

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <ll, ll> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll R,C,N;
    cin>>R>>C>>N;
    ll x[N][2], y[N][2];
    vector<P> u,r,d,l;
    rep(i,0,N){
        cin>>x[i][0]>>y[i][0]>>x[i][1]>>y[i][1];
        if((x[i][0]==0||x[i][0]==R||y[i][0]==0||y[i][0]==C)&&(x[i][1]==0||x[i][1]==R||y[i][1]==0||y[i][1]==C)){
            rep(j,0,2){
                ll s=x[i][j], t=y[i][j];
                if(s==0&&t<C) u.pb(P(t,i));
                if(t==C&&s<R) r.pb(P(s,i));
                if(s==R&&t>0) d.pb(P(C-t,i));
                if(t==0&&s>0) l.pb(P(R-s,i));
            }
        }
    }
    sor(u);
    sor(r);
    sor(d);
    sor(l);
    vector<ll> v;
    rep(i,0,sz(u)){
        if(sz(v)==0||v.back()!=u[i].sc) v.pb(u[i].sc);
        else{
            v.pop_back();
        }
    }
    rep(i,0,sz(r)){
        if(sz(v)==0||v.back()!=r[i].sc) v.pb(r[i].sc);
        else{
            v.pop_back();
        }
    }
    rep(i,0,sz(d)){
        if(sz(v)==0||v.back()!=d[i].sc) v.pb(d[i].sc);
        else{
            v.pop_back();
        }
    }
    rep(i,0,sz(l)){
        if(sz(v)==0||v.back()!=l[i].sc) v.pb(l[i].sc);
        else{
            v.pop_back();
        }
    }
    cout<<(sz(v)?"NO":"YES")<<"\n";
}

Measured memory_bytes: 8496
from collections import deque

H, W = [int(i) for i in input().split()]
S = [list(input()) for _ in range(H)]

white = sum(s.count(".") for s in S)

Q = deque([(0, 0, 1)])
while Q:
    h, w, count = Q.popleft()
    if (h, w) == (H - 1, W - 1):
        print(white - count)
        quit()

    for nh, nw in [(h, w + 1), (h, w - 1), (h + 1, w), (h - 1, w)]:
        if not (0 <= nh < H and 0 <= nw < W):
            continue
        if S[nh][nw] == ".":
            S[nh][nw] = "" # visited
            Q.append((nh, nw, count + 1))
print(-1)

Measured memory_bytes: 3316
import java.util.*;
public class Main {
        static Scanner sc = new Scanner(System.in);
        static void myout(Object t){System.out.println(t);}
        static String getStr(){return sc.next();}
        static int getInt(){return sc.nextInt();}
        static Long getLong(){return sc.nextLong();}
        static boolean isNext(){return sc.hasNext();}
        public static void main(String[] args){
          int x = getInt();
          int y = getInt();
          int output = 0;
          if(x == 3){
            output += 100000;
          }else if(x == 2){
            output += 200000;
          }else if(x == 1){
            output += 300000;
          }
          
          if(y == 3){
            output += 100000;
          }else if(y == 2){
            output += 200000;
          }else if(y == 1){
            output += 300000;
          }
          
          if(x == 1 && y == 1){
            output += 400000;
          }
          
          myout(output);
        }
        //便利メソッド追加枠ここから

        //便利メソッド追加枠ここまで
}


Measured memory_bytes: 22100
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

void solve() {
    cini(n);

    vi a;
    for(int i=1; i<=n; i++) {
        cini(aux);
        if(a.size()==0 || aux!=a.back())
            a.push_back(aux);
    }

    vi mi;
    vi ma;

    for(int i=1; i+1<a.size(); i++) {
        if(a[i-1]>a[i] && a[i+1]>a[i])
            mi.push_back(i);
        else if(a[i-1]<a[i] && a[i+1]<a[i])
            ma.push_back(i);
    }

    int mon=1000;
    int amt=0;
    if(a[0]<a[1]) {
        amt=mon/a[0];
        mon-=amt*a[0];
    }

    int idxmi=0;
    int idxma=0;
    while(idxmi<mi.size() || idxma<ma.size()) {
        if(amt>0) {
            mon+=amt*a[ma[idxma]];
            amt=0;
            idxma++;
        }  else {
            amt=mon/a[mi[idxmi]];
            mon-=amt*a[mi[idxmi]];
            idxmi++;
        }
    }
    if(amt>0)
        mon+=amt*a.back();

    cout<<mon;
}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


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

void solve(long long N, std::vector<long long> a){
    ll all = 0;
    for(int i=0;i<N;i++){
        all ^= a[i];
    }
    for(int i=0;i<N;i++){
        cout << (a[i]^all) << " ";
    }
    cout << endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 4776
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<functional>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef queue<P> Q;

int H,W;
int N;
int a[100010];
int main(){
    cin >>H>>W>>N;
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    P now(0,0);
    int nowColor=0;
    int coloredNum=0;
    int c[101][101]={};
    while(1){
        c[now.first][now.second]=nowColor;
        coloredNum++;
        if(now.first%2==0){
            if(now.second>=W-1){
                now.first++;//下へ
            }else{
                now.second++;//右へ
            }
        }
        else{
            if(now.second<=0){
                now.first++;//下へ
            }else{
                now.second--;//左へ
            }
        }
        if(now.first>=H){
            break;
        }
        if(coloredNum>=a[nowColor]){
            nowColor++;
            coloredNum=0;
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cout << c[i][j]+1<<" ";
        }
        if(i<H-1)cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
/* 
chirag11032000
Chirag Thakur
*/

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

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

void test_case();

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void test_case() {
	int w, h, x, y;
	cin >> w >> h >> x >> y;
	ll area = 1ll * w * h;
	db part = area / 2.;
	cout << fixed << setprecision(10) << part << " ";
	if (2 * x == w && 2 * y == h) {
		cout << "1\n";
	} else {
		cout << "0\n";
	}
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    ll A[N]; F0R(i, N) cin >> A[i];
    F0R(i, N) {
        if (A[i] == 0) {
            cout << 0 << nl; return 0;
        }
    }
    ld L = 0;
    F0R(i, N) {
        L += log10(A[i]);
    }
    if (L > 18.1) {
        cout << -1 << nl; return 0;
    }
    ll ans = 1; F0R(i, N) ans *= A[i];
    if (ans > 1000000000000000000) {
        cout << -1 << nl; return 0;
    }
    cout << ans << nl;
	
	return 0;
}

Measured memory_bytes: 4688
#include <cstdio>
typedef long long ll;
ll n, a, b, l=1, r=1e9, m, ans, h[100005];

bool f(ll p) {
	ll i, c=0;
	for(i=0; i<n; i++)
		c += h[i]>p*b ? (h[i]-p*b+a-1)/a : 0;
	return c<=p;
}

int main() {
	scanf("%lld%lld%lld", &n, &a, &b);
	a -= b;
	for(ll i=0; i<n; i++) scanf("%lld", &h[i]);
//	while(l<=r) {
//		m = (l+r) / 2;
//		if(f(m)) ans = m, r = m-1;
//		else l = m+1;
//	}
	while(l<r) {
		m = (l+r) / 2;
		if(f(m)) r = m;
		else l = m+1;
	}
	printf("%lld", r);
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N; cin >> N;
    vector<ll> cnt(N + 1);
    for(int i = 1; i <= N; i++) {
        int j = i;
        while(j <= N) {
            cnt[j]++;
            j += i;
        }
    }
    ll ans = 0;
    for(int i = 1; i <= N; i++) {
        ans += i * cnt[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 81300
N = int(input())

# 素因数分解
def factorization( n, e ):
    for i in range( 2, N+1 ):
        for j in range( 2, i+1 ):
            while i % j == 0:
                e[j] += 1
                i /= j

# e の要素のうち m-1 以上のものの個数
def num( m ):
    return len( list(filter(lambda x: x>= m-1, e)) )


e = [0]*(N+1)
factorization( N, e )
ans = num(75) + num(25)*(num(3)-1) + num(15)*(num(5)-1) \
      + num(5)*(num(5)-1)*(num(3)-2)//2
print( ans )

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

#define ll long long
int arr[105];
int main()
{
    int n, x;
    cin >> n >> x;

    ll min = 1000000005;
    ll totalsum = 0;
    int cnt = 1;
    for (int i = 1; i <= n; i++){
        cin >> arr[i];
        totalsum = totalsum + arr[i];
        if (arr[i] < min){
            min = arr[i];
        }
    }
    
    sort(arr + 1, arr + n + 1);

    if (min > x){
        cout << "0" << endl;
        return 0;
    }
    
    if (totalsum == x){
        cout << n << endl;
    }
    
    else if (totalsum > x){
        int cntr = 0;
        int def = 1;
        while (def <= n){
            if (arr[def] <= x){
                cntr++;
                x = x - arr[def];
            }
            def++;

        }
        cout << cntr << endl;
    }
    
    else if (totalsum < x){
        cout << n-1 << endl;
    }
    return 0;
}



Measured memory_bytes: 256
/* Jay Solanki */

#include <ext/pb_ds/assoc_container.hpp>
#include<bits/stdc++.h>
typedef long long int ll;
#define pii pair<ll, ll>
#define pb push_back
#define pf push_front
#define F first
#define S second
#define mp make_pair
#define For(i,a,b) for(ll i=a;i<b;i++)
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll mode = 1e9 + 7;

int modInverse(int a, int m)
{

    int m0 = m;
    int y = 0, x = 1;

    if (m == 1)
      return 0;
    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

ll power(ll x,ll y){
    ll res = 1;
    x = x % mode;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mode;
        y = y>>1;
        x = (x*x) % mode;
    }
    return res;
}

int main()
{
    FAST;
    int t=1;
    // cin>>t;
    while(t--)
    {
        ll n,c=0,k=1,y=0,x=0,z=0;
        cin>>n>>k;
        // string s;
        // cin>>s;
        vector<ll> v(n),ans(n);
        For(i,0,n) cin>>v[i];
        ans[0]=0;
        for(int i=1;i<n;i++)
        {
            if(i==1) ans[i]=abs(v[i-1]-v[i]);
            else
            {
                ans[i]=INT_MAX;
                for(int j=i-1;j>=0 && i-j<=k;j--)
                    ans[i]=min(ans[i],ans[j]+abs(v[i]-v[j]));
            }
        }
        cout<<ans[n-1];
    }
    return 0;
}

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


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

    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    rep (i, n) cin >> h[i];
    sort(ALL(h));
    int ans=1e9;
    rep(i, n-k+1) {
        int tmp = h[i+k-1] - h[i];
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3732
#include <stdio.h>

#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i+=a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

int main() {
    char x;
    scanf("%c", &x);
    printf("%c", x+1);
    return 0;
}

Measured memory_bytes: 128
def main():

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

    list = []
    for i in range(1, N+1):
        list.append(L + i - 1)

    list2 = []
    for i in range(N):
        list2.append(abs(list[i]))

    list2.sort()
    tmp = list2.pop(0)

    if tmp in list:
        list.remove(tmp)
    elif -tmp in list:
        list.remove(-tmp)

    ans = 0
    for i in list:
        ans += i

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    s64 n, k;
    cin >> n >> k;

    vs64 p(n), c(n);
    rep (i, n)
    {
        cin >> p[i];
        --p[i];
    }
    rep (i, n)
    {
        cin >> c[i];
    }

    vector< vs64 > dp(n, vs64(n + 1));
    vector< vs32 > dst(n, vs32(n + 1));
    rep (i, n) dp[i][0] = 0;
    rep (i, n) dst[i][0] = i;

    rep (j, n)
    {
        rep (i, n)
        {
            dst[i][j + 1] = p[dst[i][j]];
        }
    }

    rep (j, n)
    {
        rep (i, n)
        {
            dp[i][j + 1] = dp[i][j] + c[dst[i][j + 1]];
        }
    }

    s64 ans = -1e18;
    rep (i, n)
    {
        s64 loop;
        for (loop = 1; loop <= n; ++loop)
        {
            if (dst[i][loop] == i)
            {
                break;
            }
        }

        s64 sum;
        if (k > n && loop <= k && dp[i][loop] >= 0)
        {
            s64 tk = k % loop;
            sum = dp[i][loop] * (k / loop);
            s64 temp = 0;
            rep (j, tk + 1)
            {
                temp = max(temp, dp[i][j]);
            }
            rep (j, loop + 1)
            {
                temp = max(temp, dp[i][j] - dp[i][loop]);
            }
            sum += temp;
        }
        else
        {
            sum = -1e18;
            rep (j, MIN(n, k))
            {
                sum = max(sum, dp[i][j + 1]);
            }
        }
        ans = max(ans, sum);
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 296752
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);

vector<vector<int>> fri(100005);
vector<vector<int>> blo(100005);

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

  rep (i, m) {
    int a, b;
    cin >> a >> b;
    fri[a].push_back(b);
    fri[b].push_back(a);
  }

  rep (i, k) {
    int c, d;
    cin >> c >> d;
    blo[c].push_back(d);
    blo[d].push_back(c);
  }

  vector<int> group(100005);
  map<int, int> mi;
  for (int i = 1; i <= n; i++) {
    if (group[i] == 0) {
      queue<int> qi;
      qi.push(i);
      group[i] = i;
      mi[i]++;
      while (!qi.empty()) {
	int now = qi.front();
	qi.pop();
	for (auto next_v : fri[now]) {
	  if (group[next_v] == 0) {
	    group[next_v] = i;
	    mi[i]++;
	    qi.push(next_v);
	  }
	}
      }
    }
  }

  for (int i = 1; i <= n; i++) {
    int ans = 0;
    ans += mi[group[i]] - (1+ fri[i].size());
    for (auto v : blo[i]) {
      if (group[i] == group[v]) ans--;
    }
    cout << ans << " ";
  }
  cout << endl;

  //printVec(group);
  return 0;
}


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

int get(){
    int a,b,c;
    cin>>a>>b>>c;
    return a*3600+b*60+c;
}

int main(){

    for(int i=0;i<3;i++){
        int a=-get();
        a+=get();

        cout<<a/3600<<" "<<a%3600/60<<" "<<a%60<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int a, b;
int main() {
	cin >> a >> b;
	if (0 < a&&b < 0 || 0 < b&&a < 0)cout << "Zero" << endl;
	else if ((b - a) % 2|| 0 < a && 0 < b)cout << "Positive" << endl;
	else cout<<"Negative"<<endl;

}

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

int main(){
    int N, A, B, x;
    cin >> N >> A >> B;
    int x1, x2;
    x1 = A * N;
    x2 = B;
    if(x1 <= x2){
        cout << x1 << endl;
    }else{
        cout << x2 << endl;
    }
}

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

int main() {

    int h,w;

    cin >> h >> w;

    for(int i=0; i<h+2; i++){
        for(int j=0; j<w+2; j++){
            if(i == 0 || j == 0 || i == h+1 || j == w+1){
                cout << '#';
                continue;
            }
            char c;
            cin >> c;
            cout << c;
        }
        cout << endl;
    }

    return 0;
}

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

int main(){
    int n;
    string a, b, c;
    cin >> n >> a >> b >> c;
    int count = 0;

    for (int i = 0; i < n; i++) {
        char charA = a[i];
        char charB = b[i];
        char charC = c[i];
        if ( charA != charB && charA != charC && charB != charC) {
            count = count + 2;
        }
        else if ( charA == charB && charA == charC ) {
        }
        else {
            count++;
        }
    } 

    cout << count << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <tuple>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define DECIM8  fixed<<setprecision(8) 
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

using namespace std;
int main(void)
{
  for(;;){
    int n,r;
    deque<int> deck;
    cin >> n >> r;
    REP(i,n) deck.push_front(i+1);
    if(!n&&!r) return 0;
    REP(i,r){
      int p,c;
      cin >> p >> c;
      REP(j,c){
	deck.push_front(deck[p+c-2]);
	deck.erase(deck.begin()+p+c-1);
      }
    }
    cout << deck.front() << endl;
  }
}

Measured memory_bytes: 1216
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

constexpr int MOD = 1e9+7;

int main(void){
  	Cin(ll, t1, t2, a1, a2, b1, b2);
  	ll v1 = a1-b1, v2 = a2-b2;
  	if(v1 > 0 && t1*v1+t2*v2 > 0){
      Cout(0);
      return 0;
    }
  	if(v1 < 0 && t1*v1+t2*v2 < 0){
      Cout(0);
      return 0;
    }
  	if(t1*v1+t2*v2 == 0){
      Cout("infinity");
      return 0;
    }
  	if(v1 < 0){
      v1 = -v1, v2 = -v2;
    }
  	ll ans = 1 - t1*v1 / (t1*v1+t2*v2);
  	ans = 2*ans - 1;
  	if((t1*v1) % abs(t1*v1+t2*v2) == 0) ans --;
  	Cout(ans);
}




Measured memory_bytes: 256
# https://atcoder.jp/contests/arc081/tasks/arc081_b
from collections import defaultdict
n = int(input())
s1 = input()
s2 = input()
ans = 0
mod = 10 ** 9 + 7

if s1[0] == s2[0]:
    i = 1
    ans += 3
    flag = False
else:
    i = 2
    ans += 6
    flag = True
while i < n:
    if flag:
        if s1[i] == s2[i]:
            flag = False
        else:
            ans *= 3 % mod
            i += 1
    else:
        ans *= 2 % mod
        if s1[i] != s2[i]:
            flag = True
            i += 1
    i += 1
print(ans % mod)


Measured memory_bytes: 64992
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll A,B,C,K;
    cin>>A>>B>>C>>K;
    if(!(K%2)){
        cout <<A-B<<"\n";
    }
    else{
    cout <<B-A<<"\n";
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
  
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF 100000000
 
int p[21],q[51][21],r[51][21];
int cost[20][100001];
struct edge{
    int dis;
    int com;
    int cos;
};
 
vector<edge> G[101][101];
int C[101][101],D[101][101];
 
int main(){
    while(1){
        int n,m,c,s,g;
        scanf("%d%d%d%d%d",&n,&m,&c,&s,&g);
        if(n == 0 && m == 0 && c == 0 && s == 0 && g == 0){
            break;
        }
 
        REP(i,n)
            REP(j,n) {
                while(!G[i][j].empty())
                G[i][j].pop_back();
            }
         
 
        REP(i,m){
            int x,y,d,c2;
            scanf("%d%d%d%d",&x,&y,&d,&c2);
            x--;y--;
            edge z;z.dis = d;z.com = c2 - 1;
            G[x][y].pb(z);
            G[y][x].pb(z); 
        }
        REP(i,c){
            scanf("%d",&p[i]);
        }
        REP(i,c){
            q[i][0] = -1;
            REP(j,p[i] - 1)
                scanf("%d",&q[i][j]);
            REP(j,p[i])
                scanf("%d",&r[i][j]);
        }
        REP(i,c){
            int k = 0;
            cost[i][0] = 0;
            FOR(j,1,100001){
                cost[i][j] = cost[i][j - 1] + r[i][k];
                if(k < p[i] - 1 && j == q[i][k])
                    k++;
            }
        }
        REP(i,n)
            REP(j,n)
                C[i][j] = INF * (i != j);
        REP(l,c){
            REP(i,n)
                REP(j,n)
                    D[i][j] = INF * (i != j);
            REP(i,n){
                REP(j,n){
                    REP(k,G[i][j].size()){
                        if(G[i][j][k].com == l && D[i][j] > G[i][j][k].dis)
                            D[i][j] = G[i][j][k].dis;
                    }
                }
            }
             
            REP(k,n){
                REP(i,n){
                    REP(j,n){
                        D[i][j] = min(D[i][j],D[i][k] + D[k][j]);
                    }
                }
            }
 
            REP(i,n){
                REP(j,n){
                    if(D[i][j] != INF)
                        C[i][j] = min(C[i][j],cost[l][D[i][j]]);
                }
            }
        }
 
        REP(k,n){
            REP(i,n){
                REP(j,n){
                    C[i][j] = min(C[i][j],C[i][k] + C[k][j]);
                }
            }
        }
        if(C[s - 1][g - 1] == INF)
            printf("-1\n");
        else
            printf("%d\n",C[s - 1][g - 1]);
    }
    return 0;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	string s, t;
	cin >>s >>t;
	
	vector<VI> sd(28);
	rep(i, sz(s)) sd[s[i]-'a'].push_back(i);
	for(auto z: t) if(sz(sd[z-'a']) <1){puts("-1"); return 0;}
	
	ll cr =-1, sh=0;
	for(auto x: t){
		int p = x -'a';
		auto it = lower_bound(all(sd[p]), cr+1);
		if(it == sd[p].end()){
			sh++; it = lower_bound(all(sd[p]), 0);
		}
		cr =*it;
	}
	cout << sh * sz(s) + cr +1<<"\n";
	return 0;
	
}


Measured memory_bytes: 1228
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include<cstring>
//namespace
using namespace std;
//繰り返し
#define REP(i, m, n) for(int i=(int)m; i<(int)n; ++i)
#define rep(i, n) REP(i, 0, n)
//イテレータ
#define all_range(C) begin(C), end(C)
//簡略化
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
typedef pair<string,int> pst;

const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
//最大最小
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;}

//関数

//最大公約数を求める
ll my_gcd(ll x, ll y) {
  ll r;

  while(y!=0) {
    r = x%y;
    x = y;
    y = r;
  }

  return x;
}

//最小公約数を求める
ll my_lcm(ll x, ll y) {

  return (x*y)/my_gcd(x,y);
}

//xのy乗を求める ※参考：10^18乗まで
ll my_pow(ll x, ll y) {
  ll sum = 1;

  while(y>0) {
    sum *= x;
  }

  return sum;
}

//main.cpp----------------------------


void solve();

ll x, y, z;
ll a[3];

int main() {
  cin >> x >> y >> z;
  a[0] = x;
  a[1] = y;
  a[2] = z;

  solve();

  return 0;
}

void solve() {
  ll cnt = 0;

  while(!(a[0]==a[1]&&a[0]==a[2])) {
    sort(a, a+3);
    if(a[1]==a[2]) {
      a[0] += 2;
      cnt += 1;
    }else {
      a[0] += 1;
      a[1] += 1;
      cnt += 1;
    }

  }

  cout << cnt << endl;
}

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

int main() {
  int n;
  cin >> n;
  
  int s, t_n;
  s = 0;
  t_n = n;
  while (t_n > 0) {
    s += t_n % 10;
    t_n /= 10;
  }
  
  cout << (n % s == 0 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define endl '\n'
#define gcd __gcd
#define lcm(a,b) (a*b)/gcd(a,b)
#define inf 0xFFFFFFFF/2
#define uinf 0xFFFFFFFF
#define infl 0xFFFFFFFFFFFFFFFF/2
#define uinfl 0xFFFFFFFFFFFFFFFF
#define TEST(t) int t; cin>>t; while(t--)
#define rep(i,a,b) for(int i=(int)a; i<b; i++)
#define repc(i,a,c) for(int i=(int)a; c; i++)
#define reps(i,a,b,s) for(int i=(int)a; i<b; i+=s)
#define repcs(i,a,c,s) for(int i=(int)a; c; i+=s)
#define repn(i,n)  for(int i=0; i<n; i++)
#define per(i,a,b) for(int i=b; i >= a; i--)
#define linv(a,n)  vector<int> a(n); for(int i=0; i<n; i++) cin>>a[i];
#define linp(a,n)  int arr[n]; for(int i=0; i<n; i++) cin>>a[i];
#define lgenv(t,a,n) vector<t> a(n); for(int i=0; i<n; i++) cin>>a[i];
#define lgenp(t,a,n) t a[n]; for(int i=0; i<n; i++) cin>>a[i];
#define lgeni(t,a,n,v) t a[n]; memset(a, v, (sizeof(a)/sizeof(t)));
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define SZ(x) (x).size()
#define DEBUG_ARR(a,n) for(int i=0; i<n; i++) cerr<<a[i]<<" "; cerr<<endl;
#define PRINT_ARR(a,n) for(int i=0; i<n; i++) cout<<a[i]<<" "; cout<<endl;
#define RD_I(fi) freopen(fi, "r", stdin);
#define RD_O(fo) freopen(fo, "w", stdout);
#define RD_IO(fi,fo) RD_I(fi); RD_O(fo);
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long llu;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector< vector<int> > vvi;

int main()
{
	FIO
	string s;
	cin>>s;
	int len = SZ(s);
	bool poss = false;
	for(int i=1; i<len && !poss; i++)
		if(s[i-1] == 'A' && s[i] == 'C')
			poss = true;
	cout<<(poss? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define len(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define chmax(x, v) x = max((x), (v))
#define chmin(x, v) x = min((x), (v))
using namespace std;
using ll = long long;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s; cin >> s;
	vector<char> r;
	for (char c : s) {
		if (r.empty() || r.back() == 'T' || c == 'S')
			r.push_back(c);
		else
			r.pop_back();
	}
	cout << len(r) << "\n";
}


Measured memory_bytes: 3768
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int H, W, N, Sr, Sc;
string S, T;

int main() {
    cin >> H >> W >> N;
    cin >> Sr >> Sc;
    cin >> S;
    cin >> T;

    Sc--;
    Sr--;

    int r, c;

    // SU, TD
    r = Sr;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'U') r--;
        if (r < 0) {
            cout << "NO" << endl;
            return 0;
        }
        if (T[i] == 'D') r = min(r + 1, H - 1);
    }

    // SD, TU
    r = Sr;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'D') r++;
        if (r > H - 1) {
            cout << "NO" << endl;
            return 0;
        }
        if (T[i] == 'U') r = max(r - 1, 0);
    }

    // SL, TR
    c = Sc;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'L') c--;
        if (c < 0) {
            cout << "NO" << endl;
            return 0;
        }
        if (T[i] == 'R') c = min(c + 1, W - 1);
    }

    // SR, TL
    c = Sc;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'R') c++;
        if (c > W - 1) {
            cout << "NO" << endl;
            return 0;
        }
        if (T[i] == 'L') c = max(c - 1, 0);
    }

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


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

int main() {
    int a; cin >> a;
    int a2 = a*a;
    int a3 = a*a*a;
    cout << a + a2 + a3 << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<iostream>

using namespace std;

int main(){
  int x,y;
  cin >> x >> y;
  while(x!=0||y!=0){
    if(x<y)
      cout << x <<" " << y << endl;
    else
      cout << y <<" " << x << endl;
    cin >> x >> y;
  }
}


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

using namespace std;


template< typename T >
struct edge
{
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};

template< typename G >
struct LowLink
{
  const G &g;
  UnionFind uf;
  vector< int > used, ord, low, parent;

  LowLink(const G &g) : g(g), uf(g.size()), used(g.size()), ord(g.size()), low(g.size()), parent(g.size(), -1) {}

  void dfs(int idx, int &k, int par = -1)
  {
    used[idx] = true;
    ord[idx] = k++;
    low[idx] = ord[idx];

    for(auto &to : g[idx]) {
      if(!used[to]) {
        dfs(to, k, idx);
        low[idx] = min(low[idx], low[to]);
        parent[to] = idx;
        if(ord[idx] >= low[to]) uf.unite(idx, to);
      } else if(to != par) {
        low[idx] = min(low[idx], ord[to]);
      }
    }
  }

  void dfs()
  {
    int k = 0;
    dfs(0, k);
  }
};

template< typename G >
struct BiConnectedComponents : LowLink< G >
{
  using LL = LowLink< G >;

  vector< int > comp;

  BiConnectedComponents(const G &g) : LL(g), comp(g.size()) {}

  int operator[](int k)
  {
    return (comp[k]);
  }

  vector< pair< int, int > > build(UnWeightedGraph &t)
  {
    LL::dfs();
    int ptr = 0;
    vector< int > cc(LL::g.size());
    for(int i = 0; i < LL::g.size(); i++) {
      if(i == LL::uf.find(i)) cc[i] = ptr++;
    }

    t.resize(ptr);
    for(int i = 0; i < LL::g.size(); i++) {
      comp[i] = cc[LL::uf.find(i)];
    }

    vector< pair< int, int > > edges;
    for(int i = 0; i < LL::g.size(); i++) {
      for(auto &to : LL::g[i]) edges.emplace_back(minmax(i, to));
    }
    sort(begin(edges), end(edges));
    edges.erase(unique(begin(edges), end(edges)), end(edges));
    vector< pair< int, int > > vs;
    for(auto &e : edges) {
      int x = comp[e.first], y = comp[e.second];
      if(x == y) continue;
      vs.emplace_back(e.first, e.second);
      t[x].push_back(y);
      t[y].push_back(x);
    }
    sort(begin(vs), end(vs));
    return (vs);
  }
};

void solve()
{
  int V, E;
  cin >> V >> E;
  UnWeightedGraph g(V);
  for(int i = 0; i < E; i++) {
    int s, t;
    cin >> s >> t;
    g[s].push_back(t);
    g[t].push_back(s);
  }
  BiConnectedComponents< UnWeightedGraph > bp(g);
  UnWeightedGraph gg;

  for(auto &p : bp.build(gg)) {
    cout << p.first << " " << p.second << endl;
  }
}

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


Measured memory_bytes: 5932
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    string ans = "";
    for(int i = 0; i < s.size(); i++)
    {
        ans += 'x';
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int sum = 0;
		if (b > 1) {
			for (int i = 0; i < a; i++) {
				int c = sc.nextInt();
				if (b - c >= c) {
					sum += c * 2;
				} else if (c >= b - c) {
					sum += (b - c) * 2;
				}
			}
			System.out.println(sum);
		} else if (b == 1) {
			int d = sc.nextInt();
			if (b - d >= d) {
				System.out.println(d * 2);
			} else if (d >= b - d) {
				System.out.println((b - d) * 2);
			}
		}
	}

}

Measured memory_bytes: 21460
# AOJ 0520: Lightest Mobile
# Python3 2018.6.30 bal4u

def lcm(a, b):
	return a // gcd(a, b) * b

def gcd(a, b):
	while b != 0:
		r = a % b
		a, b = b, r
	return a

def calc(i):
	wr = calc(t[i][2]) if t[i][2] > 0 else 1
	wb = calc(t[i][3]) if t[i][3] > 0 else 1
	w = lcm(t[i][0] * wr, t[i][1] * wb)
	return w//t[i][0] + w//t[i][1]

while True:
	n = int(input())
	if n == 0: break
	f = [0]*(n+1)
	t = [(0,0,0,0)]
	for i in range(1, n+1):
		p, q, r, b = map(int, input().split())
		t.append((p, q, r, b))
		if r > 0: f[r] = i
		if b > 0: f[b] = i
	for i in range(1, n+1):
		if f[i] == 0: break
	print(calc(i))


Measured memory_bytes: 5624
# nCr(n, r, m): 組合せ
# nHr(n, r, m): 重複組合せ
MOD = 10**9 + 7
fac = [1,1] # 階乗 n!
inv = [0,1] # 逆元 1/n
finv = [1,1] # 逆元の階乗 (n^-1)! = (1/n)!

def finv_init(n, m):
    for i in range(2, n+1):
        fac.append( (fac[-1] * i ) % m )
        inv.append( (-inv[m%i] * (m//i)) % m )
        finv.append( (finv[-1] * inv[-1]) % m )

def nCr(n, r, m):
    if (n<0 or r<0 or n<r): return 0
    r = min(r, n-r)
    return fac[n] * finv[n-r] * finv[r] % m

def nHr(n, r, m): return nCr(n+r-1, r, m)

s = int(input())
finv_init(s, MOD) # 初期設定
ans = 0
for n in range(1, s+1):
    if s < 3*n: break
    ans += nHr(n, s - 3*n, MOD)
print(ans % MOD)


Measured memory_bytes: 9176
import scala.math.floor

object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val a, b = sc.nextInt()
  val ans = (1 to 1250).find(i => floor(i*0.08) == a && floor(i*0.1) == b)
  println(ans.getOrElse("-1"))
}

Measured memory_bytes: 55524
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;
 
int main() {
  
  int N;

  cin >> N;

  vector<int> L(2*N);

  REP(i,2*N) cin >> L.at(i);//入力終了

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

  reverse(L.begin(),L.end());

  int64_t ans=0;

  for(int i=0;i<N;i++){
    ans+=L.at(2*i+1);
  }

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int K = Integer.parseInt(sc.nextLine());
	    String S = sc.nextLine();
	    int Slength = S.length();
	    
	    if(Slength>K) {
	    	System.out.println(S.substring(0, K)+"...");
	    }else {
	    	System.out.println(S);
	    }
    }

}


Measured memory_bytes: 38552