akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <functional>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main(void) {
	int N;
	cin >> N;
	ll ans = 0;

	for (int i = 1; i <= N; i++) {
		if ((i % 3 != 0) && (i % 5 != 0)) ans += i;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
import numpy as np

cs = []
cs.append([int(a) for a in input().split()])
cs.append([int(a) for a in input().split()])
cs.append([int(a) for a in input().split()])

cs = np.array(cs)

a1a2 = cs[0] - cs[1]
a2a3 = cs[1] - cs[2]
b1b2 = cs[:,0] - cs[:,1]
b2b3 = cs[:,1] - cs[:,2]

if np.all((a1a2 - a1a2[0]) == 0) and np.all((a2a3 - a2a3[0]) == 0) and np.all((b1b2 - b1b2[0]) == 0) and np.all((b2b3 - b2b3[0]) == 0):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 13900
arr = []
class << arr
  def insert(n)
    self.unshift(n)
  end
  
  def delete(n)
    self.delete_at(self.index(n)) if self.index(n)
  end
  
  def deleteFirst(arg = nil)
    self.shift
  end
  
  def deleteLast(arg = nil)
    self.pop
  end
end
gets.to_i.times do
  arr.send(*gets.split(" ").map(&:to_sym))
end
puts arr.join(" ")

Measured memory_bytes: 404316
// Problem : B - Tag
// Contest : AtCoder - Tokio Marine & Nichido Fire Insurance Programming Contest
// 2020 URL :
// https://atcoder.jp/contests/tokiomarine2020/tasks/tokiomarine2020_b Memory
// Limit : 1024 MB Time Limit : 2000 ms Powered by CP Editor
// (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define mk make_pair
#define fast                    \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define rep(i, a, b) for (ll i = a; i < b; i++)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define sz(x) (int)x.size()
#define mem(a, val) memset(a, val, sizeof(a))
#define deci(x) cout << fixed << setprecision(x);
#define bitcount(x) __builtin_popcountll(x)

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

const long long int mod = 1e9 + 7;
const long double EPS = 1e-12;
const int N = 1e5 + 20;

void solve() {
  ll a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  ll dist = abs(a - b);
  ll vel = (v - w);
  dist -= (vel)*t;
  if (dist > 0) {
    cout << "NO\n";
    return;
  }
  cout << "YES";
}
int main() {
  fast;
  ll t;
  t = 1;

  // cin>>t;

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

  return 0;
}


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

using namespace std;

const int INF = 1e9 + 5;

int main()
{
    int h, n;

    cin >> h >> n;

    vector <int> a(n+1, 0);
    vector <int> b(n+1, 0);

    for (int i = 1; i <= n; i++)
        cin >> a[i] >> b[i];

    vector <int> dp(h+1, INF);

    dp[0] = 0;

    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            int p = max(0, i-a[j]);
            dp[i] = min(dp[i], dp[p] + b[j]);
        }
    }

    cout << dp[h] << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
//---------------------------------------------------------------------------------------------------
typedef pair<int,int> P;

int main(void){
    // Your code here!
    int n,k; cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(_,k) {
        vector<int> b(n,0);
        rep(i,n) {
            // if (a[i] == 0) {
            //     b[i] += 1;
            //     if (i < n-1) b[i+1] += -1;
            // }
            b[max(0,i-a[i])] += 1;
            if (i+a[i]+1 < n) b[i+a[i]+1] += -1;
        }
        FOR(i,1,n-1){
            b[i] = b[i] + b[i-1];
        }
        if (MIN(b) == n) {
            rep(i,n) {
                cout << b[i] << ' ';
            }
            return 0;
        } else {
            a = b;
        }
    }
    rep(i,n) {
                cout << a[i] << ' ';
            }
}


Measured memory_bytes: 4836
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

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

  sort(a.begin(), a.end());
  ll ans=1;
  for (int i = 0; i < n; ++i)
  {
    if(ans!=0 && a[i]>((ll)1e18/ans))
    {
      cout<<-1;
      return 0;
    }
    ans*=a[i];
  }
  cout<<ans;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
from sys import stdin
input = stdin.readline

n, m, k = map(int, input().split())
a = []
r = []
now = []

def f(i):
    global n, k
    flag = 0

    if i + 1 == n:
        if min(now[1:]) >= k:
            r.append(now[0])
        return

    f(i + 1)

    for x in range(m + 1):
        now[x] += a[i + 1][x]

    f(i + 1)

    for x in range(m + 1):
        now[x] -= a[i + 1][x]
    

for x in range(n):
    b = [int(y) for y in input().split()]
    a.append(b)

now = a[0]
f(0)

now = [0] * (m + 1)
f(0)

if len(r) == 0:
    print(-1)
else:
    print(min(r))

Measured memory_bytes: 9252
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int main() {
    int n; cin >> n;
    int m = 100001;
    vector<P> ar(m);
    vector<P> al(m);
    rep(i,m){
        ar[i] = P(0,i);
        al[i] = P(0,i);
    }
    rep(i,n){
        int a; cin >> a;
        if (i % 2 == 0) ar[a].first++;
        else al[a].first++; 
    }
    sort(ar.rbegin(),ar.rend());
    sort(al.rbegin(),al.rend());
    if (ar[0].second != al[0].second){
        cout << n - ar[0].first - al[0].first << endl;
    }
    else {
        cout << min(n-ar[1].first-al[0].first,n-ar[0].first-al[1].first) << endl;
    }
}

Measured memory_bytes: 4812
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
using namespace std;
int main(){
	int a = 0, b = 0, c=0, d[100000], e[100000],f=0, count = 0;
	char uc[100000];
	cin >> uc[0] >> uc[1];
	if (uc[0] < uc[1]) {
		cout << '<' << endl;
	}
	 else if (uc[0] > uc[1]) {
		cout << '>' << endl;
	}
	else { cout << '=' << endl; }
		return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include <climits>
#include<fstream>
using namespace std;
//---------------------------------------------------
//library zone!!!!!
typedef long long ll;
typedef long double ld;
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ld mod_pow(ld x, ll n, ll p) {
	ld res = 1;
	while (n > 0) {
		if (n & 1) res = res * x;
		x = x * x;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
signed main() {
	int n;
	string a, b, c;
	cin >> n >> a >> b >> c;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		set<char>s;
		s.insert(a[i]);
		s.insert(b[i]);
		s.insert(c[i]);
		ans += s.size() - 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

        if (a >= k) {
                cout << a - k << " " << b << endl; 
        } else if (a + b >= k) {
                cout << 0 << " " << (a + b) - k << endl;
        } else {
                cout << 0 << " " << 0 << endl;
        }
        
        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll 	 long long
#define pb push_back
#define mp make_pair
using namespace std;


int main()
{

int n,k; cin>>n>>k;

int a[n+9];

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

vector<int> dp(n+9, INT_MAX);

dp[0]=0;

if(n==1)
{
	cout<<dp[0]<<endl;
	return 0;
}
dp[1]= abs(a[0]-a[1]);

if(n==2)
{
		cout<<dp[1]<<endl;
	return 0;
}

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

cout<<dp[n-1]<<endl;

     return 0;
 }

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

using namespace std;

int main() {
    string Ss[6] = {"abc", "acb", "bac", "bca", "cab", "cba"};
    string S; cin >> S;

    for(int i = 0; i < 6; i++){
        if(S == Ss[i]){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}

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

int main(){
    int a,b,c,d,t=0,s=0;
	cin >> a >> b >> c >> d;
  	if (a%d > 0) s=1;
    if (c%b > 0) t=1;
   	if (a/d+s >= c/b+t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;	
    }
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n,ans=0,cnt=0;
  string s;
  cin >> n >> s;
  for(int i=0; i<n; i++) {
    cnt=0;
    int a[26]={},b[26]={};
    for(int j=0; j<i; j++) {
      a[s[j]-'a']++;
    }
    for(int j=i; j<n; j++) {
      b[s[j]-'a']++;
    }
    for(int j=0; j<26; j++) {
      if(a[j]>0&&b[j]>0) {
        cnt++;
      }
    }
    ans=max(ans,cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>
int main(){
  int n,x[102],y[102],i,j,k,D1=0,D4=0;
  double D2=0.0,D3=0.0;
  scanf("%d",&n);
  for(i=0; i<n; i++)scanf("%d",&x[i]);
  for(i=0; i<n; i++)scanf("%d",&y[i]);
  for(i=0; i<n; i++)D1+=abs(x[i]-y[i]);
  for(i=0; i<n; i++)D2+=pow(x[i]-y[i],2);
  D2=pow(D2,(double)1/2);
  for(i=0; i<n; i++)D3+=pow(abs(x[i]-y[i]),3);
  D3=pow(D3,(double)1/3);
  for(i=0; i<n; i++)if(D4<abs(x[i]-y[i]))D4=abs(x[i]-y[i]);
  printf("%lf\n%lf\n%lf\n%lf\n",(float)D1,D2,D3,(float)D4);
  return 0;
}


Measured memory_bytes: 2096
import re
s = input()
pattern={
    '.*keyence'
    ,'k.*eyence'
    ,'ke.*yence'
    ,'key.*ence'
    ,'keye.*nce'
    ,'keyen.*ce'
    ,'keyenc.*e'
    ,'keyence.*'
    }

for p in pattern:
    if re.fullmatch(p, s):
        print('YES')
        break
else:
    print('NO')

Measured memory_bytes: 9804
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		string[] str = Console.ReadLine().Split(' ');
		int a,b,c;
		a = int.Parse(str[0]);
        b = int.Parse(str[1]);
        c = int.Parse(str[2]);
        if(a == b+c || b == a+c || c == a+b){
			Console.WriteLine("Yes");
        }else{
        	Console.WriteLine("No");
        }
	}
}

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

int main(){
  string s;
  cin >> s;
  
  int n = (int)s.size();
  
  bool ok = true;
  
  for(int i=0; i<(n-1)/2; i++){
    if(s[i]!=s[n-1-i]){
      ok = false;
      break;
    }
  }
  
  for(int i=0; i<(n-1)/2; i++){
    if(s[i]!=s[(n-1)/2-1-i]){
      ok = false;
      break;
    }
    if(s[i+(n+1)/2]!=s[n-1-i]){
      ok = false;
      break;
    }
  }
  
  if(ok)cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
#define ll long long
#define mod 998244353


int main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int n; cin >> n;
        ll ar[100001] = {};
        lp(i, n + 1) cin >> ar[i];
        ll cnt = 0;
        lp(i, n) {
                ll a; cin >> a;
                ll mn = min(ar[i], a);
                cnt += mn;
                a -= mn;
                ll mn2 = min(a, ar[i + 1]);
                cnt += mn2;
                ar[i + 1] -= mn2;
        }
        cout << cnt;
return 0;
}


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

int main () {
  int A[3], B[3], a = 0, b = 0;
  for (int i=0; i<4; i++) {
    cin >> A[i];
    a += A[i];
  }
  for (int i=0; i<4; i++) {
    cin >> B[i];
    b += B[i];
  }
  if(a>b) cout << a << endl;
  else cout << b << endl;
  return 0;
}


Measured memory_bytes: 3100
from collections import Counter
h, w = map(int, input().split())
s = []
for i in range(h):
    s += list(input())

d = Counter(s).most_common()
one = 0
two = 0
if h % 2:
    if w % 2:
        for _, num in d:
            if num % 4 == 1 or num % 4 == 3:
                one += 1
                if one > 1:
                    print("No")
                    exit()
                if num % 4 == 3:
                    two += 1
                    if two > h//2 + w//2:
                        print("No")
                        exit()
            if num % 4 == 2:
                two += 1
                if two > h//2 + w//2:
                    print("No")
                    exit()
    else:
        for _, num in d:
            if num % 4:
                if num % 4 == 2:
                    two += 1
                    if two > w//2:
                        print("No")
                        exit()
                else:
                    print("No")
                    exit()
else:
    if w % 2:
        for _, num in d:
            if num % 4:
                if num % 4 == 2:
                    two += 1
                    if two > h//2:
                        print("No")
                        exit()
                else:
                    print("No")
                    exit()
    else:
        for _, num in d:
            if num % 4:
                print("No")
                exit()
print("Yes")


Measured memory_bytes: 3444
import java.util.Scanner;
 class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int a, b;
        a=input.nextInt();
        b=input.nextInt();

       if (a>b)
           System.out.println("a > b");
       else if (a<b)
           System.out.println("a < b");
       else
           System.out.println("a == b");

    }
}



Measured memory_bytes: 26128
#include<cstdio>
#include<iostream>
using namespace std;
int n,x,t;
inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int main()
{
	n=read(),x=read(),t=read();
	int ans=n/x*t;
	if(n%x)ans+=t;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3760
#include <stdio.h>
#include <string.h>
const int N = 1300;
const int M = 256;

int main()
{
    char str[N];
    int ary[M] = {0};
    while (fgets(str, 1300, stdin))
    {
        for(int i = 0; i <strlen(str)-1; i++)
        {
            if(str[i] >= 'A' && str[i] <= 'Z')
            {
                ary[str[i]+32]++;
            }
            else
            {
                ary[str[i]]++;
            }
        }
    }
    for(int i = 'a'; i <= 'z'; i++)
    {
        printf("%c : %d\n", i, ary[i]);
    }
    return 0;
}



Measured memory_bytes: 2604
from collections import deque

S = deque(input())
Q = int(input())
re_flag = False 
start = deque()
finish = deque()
for i in range(Q):
    l = input()
    if l == "1":
        re_flag = not bool(re_flag)
    else:
        t, f, c = l.split()
        if f == "1":
            if re_flag:
                finish.append(c)
            else:
                start.append(c)
        else:
            if re_flag:
                start.append(c)
            else:
                finish.append(c)

S.extend(finish)
S.extendleft(start)

ans = deque()
if re_flag:
    ans.extendleft(S)
else:
    ans = S

print("".join(list(ans)))




Measured memory_bytes: 74456
import sys
sys.setrecursionlimit(1000000)

N=int(input())
H=list(map(int,input().split()))
ans=[]

def compare(list,i,holder=0):
	if i==N-1:
		ans.append(holder)
		return holder
	if list[i]>=list[i+1]:
		return compare(list,i+1,holder+1)
	else:
		ans.append(holder)
		return compare(list,i+1)						

compare(H,0)
print(max(ans))
 
		
    

Measured memory_bytes: 115736
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a, b) << ' ' << max(a + b - n, 0) << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/02/28  Problem: ABC 108 C / Link: http://abc108.contest.atcoder.jp/tasks/abc108_c  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL ans = 0LL;

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

	LL N, K; cin >> N >> K;
	LL ret = N / K;
	ans = ret * ret*ret;
	if (K % 2 == 0) {
		if ((N / K)*K + K / 2 <= N)ret++;
		ans += ret * ret*ret;
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
char s[100001];
int main()
{
	scanf("%s",s+1);
	for(int i=1;i<strlen(s+1);i++)
	{
		if(s[i]=='A'&&s[i+1]=='C') 
		{
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pll pair<ll,ll>
#define pb push_back
#define F first
#define S second
#define I insert
#define vll vector<ll>
#define vbl vector<bool>
#define vvll vector<vll>
#define vld vector<ld>
#define vb vector<bool>
#define vc vector<char>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()

template<class T> ostream& operator<<(ostream &os, vector<T> V){
	os << "[ ";
	for(auto v  : V) os << v << " ";
	return os << " ]";
}
template<class T> ostream& operator<<(ostream &os, set<T> V){
	os << "[ ";
	for(auto v  : V) os << v << " ";
	return os << " ]";
}
template<class T , class R > ostream& operator<<(ostream &os, map<T , R> V){
	os << "[ ";
	for(auto v  : V) os << "(" << v.first << ":" << v.second << ")";
	return os << " ]";
}
template<class T , class R > ostream& operator<<(ostream &os, pair<T , R> V){
	return os << "(" << V.first << "," << V.second << ")";
}

#define cerr cout
#define TRACE
#ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << 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...);
    }
    clock_t clk=clock();
    #define checktime() cout<<"\nTime Elapsed : "<<float(clock()-clk)/CLOCKS_PER_SEC<<endl
#else
    #define trace(...);
    #define checktime();
#endif

const ll Mod = 1e9 + 7;
// const ll Mod = 998244353;
const ll MAXN = 1e6;

void solve(){
    ll n;cin>>n;
    ll d=n%10;
    if(d==2||d==4||d==5||d==7||d==9) cout<<"hon\n";
    else if(d==0||d==1||d==6||d==8) cout<<"pon\n";
    else cout<<"bon\n";
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout<<fixed<<setprecision(25);

    ll t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define rFORq(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
int main(){
    string S;
    cin >> S;
    int l = S.length();
    reverse(S.begin(),S.end());

    REP(i,l){
        if (S.substr(i,5) == "maerd"){
            i = i + 5 - 1;
        }else if (S.substr(i,7) == "remaerd"){
            i = i + 7 - 1;
        }else if (S.substr(i,5) == "esare"){
            i = i + 5 - 1;
        }else if (S.substr(i,6) == "resare"){
            i = i + 6 - 1;
        }else {
            cout << "NO\n";
            return 0;
        }
    }

    cout << "YES\n";
}

Measured memory_bytes: 512
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
from queue import PriorityQueue
from fractions import gcd
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N, K, Q = LI()
A = [_I() for i in range(Q)]

points = [K-Q for _ in range(N)]

for a in A:
    points[a-1] += 1

for i in points:
    if i <= 0:
        print('No')
    else:
        print('Yes')



Measured memory_bytes: 14348
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scanner =new Scanner(System.in);
		int N = scanner.nextInt();
		int[] edge = new int[N];
		for (int i = 0; i < N; i++) {
			edge[i] = scanner.nextInt();
		}

		Arrays.sort(edge);

		int sum = 0;

		for (int i = 0; i < N-1; i++) {
			sum+=edge[i];
		}

		if (sum > edge[N-1]) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		scanner.close();
	}

}


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

int main(){ 
  int n;
  cin >> n;
  vector<vector<P>> key(n);
  rep(i,n) {
    int a;
    cin >> a;
    int pos = 0;
    rep(j,a) {
      int x, y;
      cin >> x >> y;
      x--;
      key[i].push_back({x,y});
    }
  } 

  int res = 0;

  for (int bit = 0; bit < (1 << n); bit++) {
    bool ok = true;
    for (int j = 0; j < n; j++) {
      if (bit & (1 << j)) {
        for (auto e : key[j]) {
          if (e.second) {
            if (!(bit & (1 << e.first))) ok = false;
          } else {
            if (bit & (1 << e.first)) ok = false;
          }
        }
      }
    }
    if (ok) res = max(res, __builtin_popcount(bit));
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 256
#B - Easy Linear Programming
A,B,C,K = map(int, input().split())

if K >= A:
    a = A
else:
    print(K)
    exit()
if A == 0 and C == 0:
    print(0)
    exit()

if A == 0 and B == 0:
    print(-1*K)
    exit()

if K - (A+B) >= 0:
    c = -1 * (K - (A + B))
else:
    c = 0

print(a+c)

Measured memory_bytes: 9204
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<queue>
using namespace std;

const int dy[4]={-1,0,1,0},dx[4]={0,1,0,-1};
int needlev[2][100002];
int fld[500][500];

struct Data{
	int y,x,lev;
	Data(){}
	Data(int _y,int _x,int _lev){
		y=_y; x=_x; lev=_lev;
	}
	bool operator<(const Data &a)const{
		return lev>a.lev;
	}
};

int main(){
	int W,H,X,Y,R;
	while(cin>>R,R){
		vector<int> r[2];
		for(int K=0;K<2;K++){
			priority_queue<Data> q;
			cin>>W>>H>>X>>Y; X--; Y--;
			q.push(Data(Y,X,1));
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					cin>>fld[i][j];
				}
			}

			int cntR=0;
			Data q_c;
			bool used[500][500]={};
			used[Y][X] = true;
			needlev[K][0] = needlev[K][R+1] = 0;
			while(!q.empty()){
				q_c = q.top(); q.pop();
				cntR++;
				//printf("%d: %d,%d,%d\n",cntR,q_c.y,q_c.x,q_c.lev);
				needlev[K][cntR] = q_c.lev;
				if(cntR==R) break;
				for(int i=0;i<4;i++){
					int ny = q_c.y+dy[i],
						nx = q_c.x+dx[i];
					if(ny<0 || H<=ny || nx<0 || W<=nx || used[ny][nx])
						continue;
					used[ny][nx] = true;
					q.push(Data(ny,nx,max(q_c.lev,fld[ny][nx])));
				}
			}
			for(int i=0;i<=cntR;i++){
				if(needlev[i]!=needlev[i+1]){
					r[K].push_back(i);
					//printf("%d ",i);
				}
			}//puts("");
		}
		int ans=1000000000;
		for(int i=0;i<r[0].size();i++){
			vector<int>::iterator itr = lower_bound(r[1].begin(),r[1].end(),R-r[0][i]);
			if(itr!=r[1].end())
				ans = min(ans,needlev[0][r[0][i]]+needlev[1][*itr]);
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 4416
from collections import deque

h, w = map(int, input().split())

field = [list(input()) for _ in range(h)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

def bfs(x, y):
    distance = [[-1]*w for _ in range(h)]
    que = deque([])
    que.append((y, x))
    distance[y][x] = 0
    while que:
        y, x = que.popleft()
        if x == w-1 and y == h-1:
            break
        for i, j in zip(dx, dy):
            nx = x + i
            ny = y + j
            if 0 <= nx < w and 0 <= ny < h and field[ny][nx] == "." and distance[ny][nx] == -1:
                distance[ny][nx] = distance[y][x] + 1
                que.append((ny, nx))
    return distance

d = bfs(0, 0)
if d[h-1][w-1] == -1:
    print("-1")
    exit()
cnt = 0
for row in field:
    cnt += row.count(".")

ans = cnt - d[h-1][w-1] - 1
print(ans)


Measured memory_bytes: 3436
readline()
D=Dict{Int,Int}()
for a=map(x->parse(Int,x),split(readline()))
  D[a]=get(D,a,0)+1
end
A=Int[]
for (k,v)=D
  for i=1:div(v,2)
    push!(A,k)
  end
end
sort!(A)
reverse!(A)
if length(A)>=2
  println(A[1]*A[2])
else
  println(0)
end

Measured memory_bytes: 148736
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define con_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define con_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
using namespace std;
using ll = long long;
template <typename T>T digitsum(T n);
template <typename T>T gcd(T u,T v);
template <typename T>bool isPrime(T n);
template <typename T>vector<pair<T, T>> prime_factor(T n);
long long int intpow(long long int,long long int);
template <typename T>T intlog(T);

int main(){
    string s;
    string str;
    cin>>s;
    int ans=0,j;
    rep(i,s.length()){
        if(i==0){
            str=s.substr(0,1);
            ans++;
        }else{
            j=1;
            if(i==s.length()-1&&s.substr(i,j)==str)break;
            while(s.substr(i,j)==str){
                j++;
            }
            str=s.substr(i,j);
            i+=j-1;
            ans++;
        }
        cerr<<str<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <fstream>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int a, b, c; cin >> a >> b >> c;
	if (a == b && b == c)cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int main(){
    vector<int> v ;
    for(int i=0;i<3;i++){
        int x ;
        cin >> x ;
        v.push_back(x);
    }
    sort(v.begin(),v.end());
    if ( v[0] == 5 && v[1] == 5 && v[2] == 7 ){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;


    return 0 ;
}


Measured memory_bytes: 256
/*
sonu_verma1
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(a) push_back(a)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	int f=0,i,j,k,l1,l;
	l=s.size();
	if(n%2==0)
	{
		l1=l/2;
		for(i=0;i<l1;i++)
		{
			if(s[i]!=s[i+l1])
			{
				f=1;
				break;
			}
		}
	}
	else
		f=1;
	if(f)
		cout<<"No";
	else
		cout<<"Yes";
	return 0;
}

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

using namespace std;

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

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using ll = long long;

int main() {
  int n, x; cin >> n >> x;
  vector<int> a(n); REP(i,n) cin >> a[i];
  ll ans = 0;
  if (a[0] > x) {
    ans += a[0] - x;
    a[0] = x;
  }
  FOR(i,1,n) {
    if (a[i] + a[i-1] > x) {
      ans += a[i] + a[i-1] - x;
      a[i] = x - a[i-1];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
const ll N=2e5+5;
ll mp[5][5];
bool vis[5][5];
void biao(ll x){
    for(int i=1;i<=3;i++){
        for(int j=1;j<=3;j++){
            if(mp[i][j]==x){
                vis[i][j]=1;
            }
        }
    }
}
int main(){
    ll a,b,n;
    for(int i=1;i<=3;i++){
        for(int j=1;j<=3;j++){
            scanf("%lld",&mp[i][j]);
        }
    }
    scanf("%lld",&n);
    ll x;
    for(int i=0;i<n;i++){
        scanf("%lld",&x);
        biao(x);
    }

    ll f=0;
    for(int i=1;i<=3;i++){
        ll u=0;
        for(int j=1;j<=3;j++){
            if(vis[i][j]){
                u++;
            }
        }
        if(u==3){
           f=1; break;
        }
    }
    for(int j=1;j<=3;j++){
        ll u=0;
        for(int i=1;i<=3;i++){
            if(vis[i][j]){
                u++;
            }
        }
        if(u==3){
            f=1;break;
        }
    }
    ll u=0;
    for(int i=1;i<=3;i++){
        if(vis[i][i]){
            u++;
        }
    }
    if(u==3)f=1;
    u=0;
    for(int i=1;i<=3;i++){
        if(vis[i][4-i]){
            u++;
        }
    }
    if(u==3)f=1;

    if(f){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 256
from sys import stdin


def main():
    lines = stdin.readlines()
    N, K = map(int, lines[0].split())
    abn = [[int(abi) for abi in line.split()] for line in lines[1:]]
    abn.sort()
    cnt = 0
    for ai, bi in abn:
        cnt += bi
        if K <= cnt:
            print(ai)
            break
    return


main()


Measured memory_bytes: 29076
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<algorithm>
#include<numeric>

using namespace std;

#define ll long long

int main(void){
	int n,k; cin >> n >> k;
	vector<int>l(n);
	for(int i=0;i<n;i++) cin >> l[i];
	sort(l.rbegin(),l.rend());
	cout << accumulate(l.begin(),l.begin()+k,0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int dp[300][110],l[300],r[300],p[300],n,m,a[300];
int main(){
	cin>>n>>m;for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<m;i++)cin>>l[i]>>r[i]>>p[i];
	for(int i=0;i<33000;i++)dp[i/110][i%110]=-1000000000;
	for(int i=0;i<m;i++){
		if(l[i]<=a[0] && a[0]<=r[i]){
			dp[0][p[i]]=max(dp[0][p[i]],0);
		}
	}
	for(int i=1;i<n;i++){
		for(int j=0;j<=100;j++){
			for(int k=0;k<m;k++){
				if(l[k]<=a[i] && a[i]<=r[k]){
					dp[i][p[k]]=max(dp[i][p[k]],dp[i-1][j]+abs(j-p[k]));
				}
			}
		}
	}
	int maxn=0;for(int i=0;i<=100;i++)maxn=max(maxn,dp[n-1][i]);
	cout<<maxn<<endl;
	return 0;
}

Measured memory_bytes: 3212
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <functional>
#include <math.h>
using namespace std;

#define ll long long
//#define int long long
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

#define dump(x)  cerr << #x << " = " << (x) << endl; 
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 


typedef pair<int, int> P;
struct Point{
	int x, y;
};
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = {1,0,-1,0};



int main(){

	int N, T;
	cin >> N >> T;
	vector<int> c;
	for (int i = 0; i < N; i++){
		int a, b;
		cin >> a >> b;
		if (b <= T) c.push_back(a);
	}

	if (c.size() == 0)
		cout << "TLE" << endl;
	else
		cout << *min_element(c.begin(), c.end()) << endl;

	return 0;
}


Measured memory_bytes: 256
def main():
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())
    
    train_fare = A if(A < B) else B
#    print(train_fare)
    
    bus_fare = C if(C < D) else D
#    print(bus_fare)
    
    print(train_fare + bus_fare)
    
if __name__=="__main__":
    main()

Measured memory_bytes: 3064
eval"N,*A="+`dd`.split*s=?,
b=A[N,N].reverse
N.times{|i|$*[v=A[i]]||=i;v!=b[i]||(s=v;$r=i)}
puts N<A.count(s)?:No:[:Yes,$r?(t=[s])*(k=[$*[s],b[..$r].count(s)].min)+(b-t)+t*=b.count(s)-k:b]

Measured memory_bytes: 89276
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll n; cin >> n;
    ll p[100001]; INITA(p, 0, 100000, 0);
    REP(i, n) {
        cin >> p[i];
    }
    ll res = 0;
    FOR(i, 0, n-1) {
        if ((i != n - 1) && (p[i] == i+1)) {
            swap(p[i], p[i+1]);
            res++;
        } else if ((i == n - 1) && (p[i] == i+1)) {
            swap(p[i], p[i-1]);
            res++;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4336
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			if (H == 0 && W == 0)
				break;

			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if ((i + j) % 2 == 0)
						System.out.print("#");
					else
						System.out.print(".");
				}
				System.out.println();
			}
			System.out.println();
		}
	}

}


Measured memory_bytes: 35436
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(1e5)+10;
int n,ans[maxn],cnt[maxn];
vector<int> G[maxn];
void ADD(int x,int y) { G[x].push_back(y); }
struct Tree {
	int rt;
	vector<int> g[maxn];
	void add(int x,int y) {
		g[x].push_back(y);
	}
	int dfs(int u) {
		int lst=0;
		for (int i=0,v;i<g[u].size();i++) {
			v=dfs(g[u][i]);
			if (!lst) lst=v;
			else ADD(lst,v),ADD(v,lst),lst=0;
		}
		if (!lst) cnt[u]++,lst=u;
		return lst;
	}
} T1,T2;
void dfs(int u) {
	for (int i=0,v;i<G[u].size();i++) {
		v=G[u][i];
		if (ans[v]) continue;
		ans[v]=-ans[u];
		dfs(v);
	}
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	int x,y;
	for (int i=1;i<=n;i++) {
		read(x);
		if (x==-1) T1.rt=i;
		else T1.add(x,i);
	}
	for (int i=1;i<=n;i++) {
		read(x);
		if (x==-1) T2.rt=i;
		else T2.add(x,i);
	}
	T1.dfs(T1.rt);
	T2.dfs(T2.rt);
	for (int i=1;i<=n;i++)
		if (cnt[i]&1) { printf("IMPOSSIBLE\n"); return 0; }
	printf("POSSIBLE\n");
	for (int i=1;i<=n;i++) {
		if (!ans[i]&&cnt[i]) ans[i]=1,dfs(i);
		printf("%d ",ans[i]);
	}
	printf("\n");
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

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

    #define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #define rep(i,a,b) for(int i=a; i<b; i++)
    #define ll long long
    #define pb push_back
    #define inf 1e+18L
    #define MOD 1000000007
    #define MAXN 1000007

    int n;
    double dp[307][307][307];

    double solve(int a, int b, int c)
    {
        if(a<0 || b<0 || c<0) return 0;
        if(dp[a][b][c] != -1) return dp[a][b][c];
        double A=a, B=b, C=c;
        double currans = 0;
        currans = (A/n * solve(a-1,b,c)) + (B/n * solve(a+1,b-1,c)) + (C/n * solve(a,b+1,c-1)) + 1;
        currans *= n;
        currans /= (a+b+c);
        dp[a][b][c] = currans;
        return dp[a][b][c];
    }

    int main()
    {
        FastIO
        for(int i=0;i<307;i++){
            for(int j=0;j<307;j++){
                for(int k=0;k<307;k++){
                    dp[i][j][k]=-1;
                }
            }
        }
        dp[0][0][0]=0;
        cin >> n;
        vector<int> cnt(4,0);
        int x;
        rep(i,0,n)
        {
            cin >> x;
            cnt[x]++;
        }
        cout << fixed << setprecision(10) << solve(cnt[1], cnt[2], cnt[3]);
        return 0;
    }

Measured memory_bytes: 226304
program problemA
  implicit none

integer :: K,A,B
integer :: n, m, yr,judge


read(*,*) K
read(*,*) A,B

! if (K==1) then
!   write(*,*) 'OK'
! else
!   if (A==B) then
!     if (mod(A,K)==0) then
!       write(*,*) 'OK'
!     else
!       write(*,*) 'NG'
!     end if
!   else
!     if (int(A/K)==int(B/K)) then
!       write(*,*) 'NG'
!     else
!       write(*,*) 'OK'
!     end if
!   end if
! end if

judge=0
do n=A,B
  if (mod(n,K)==0) then
    judge=1
    exit
  end if
end do

if (judge==0) then
  write(*,*) 'NG'
else
  write(*,*) 'OK'
end if


stop
end program


Measured memory_bytes: 2796