akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

signed main() {
  ll N;
  cin >> N;
  vector<ll> H;
  rep(i, N) {
    ll h;
    cin >> h;
    H.pb(h);
  }

  ll dp[1000010];
  rep(i, 1000010) {
    dp[i] = INF;
  }
  dp[0] = 0;
  rep(i, N) {
    chmin(dp[i], dp[i - 1] + abs(H[i] - H[i - 1]));
    if (i > 1) {
      chmin(dp[i], dp[i - 2] + abs(H[i] - H[i - 2]));
    }
  }
  COUT(dp[N - 1]);
  return 0;
}

Measured memory_bytes: 8948
#include <iostream>
#include <vector>
using namespace std;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1}, H, W;
string dir[] = {"N","E","S","W"};

bool in_range(int a, int b){
  return a >= 0 && a < b;
}

string dfs(vector<string> &C, vector< vector< vector<long long int> > > &T,
           int x, int y, long long int l, int d){
  string ret = "!";
  while(ret == "!"){
    if(T[x][y][d] > 0){
      l %= (T[x][y][d]-l);
    }else{
      T[x][y][d] = l;
    }
    
    if(l == 0){
      ret = to_string(x+1) + " " + to_string(y+1) + " " + dir[d];
    }
  
    for(int i = 0; i < 4; ++i){
      int d_ = (d+i)%4, x_ = x + dx[d_], y_ = y + dy[d_];
      //--l;
      if(in_range(x_,H) && in_range(y_,W) && C[x_][y_] != '#'){
        x = x_;
        y = y_;
        --l;
        d = d_;
        break;
      }
    }
  }
  return ret;
}

int main(){
  long long L;
  while(cin >> H >> W >> L, H){
    vector<string> C(H);
    int s_x, s_y, d;
    for(int i = 0; i < H; ++i){
      cin >> C[i];
      for(int j = 0; j < W; ++j){
        if(C[i][j] != '.' && C[i][j] != '#'){
          s_x = i;
          s_y = j;
          if(C[i][j] == 'N') d = 0;
          if(C[i][j] == 'E') d = 1;
          if(C[i][j] == 'S') d = 2;
          if(C[i][j] == 'W') d = 3;
        }
      }
    }
    vector< vector< vector<long long int> > > T(H,vector< vector<long long int> >(W,vector<long long int>(4,-1ll)));

    cout << dfs(C,T,s_x,s_y,L,d) << endl;
  }
  return 0;
}



Measured memory_bytes: 3948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)

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

    int N,K; cin >> N >> K;
    vel h(N); rep(i,N) cin >> h[i];

    sort(all(h));

    vel delta(N - K + 1);
    rep(i,N-K+1) delta[i] = h[i + K - 1] - h[i];

    sort(all(delta));
    
    cout << delta[0] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long int
#define ii pair<int,int>
#define lli pair<ll,ll>
#define pii pair<int,int>
#include<limits>
#define deb(x) cout<<#x<<'='<<(x)<<endl
#define deb2(x,y) cout<<'['<<#x<<'='<<(x)<<','<<#y<<'='<<(y)<<']'<<endl
#define debarr(a,n) {cout<<#a<<'='; for(int i=0;i<n;i++) cout << a[i] << ' '; cout<<endl;}
#define debvec(v) {cout<<#v<<'=';for(auto itr=v.begin();itr!=v.end();itr++)cout<<*itr<<' ';cout<<endl;}
#define INF numeric_limits<int>::max()
#define NINF numeric_limits<int>::min()
#define endl "\n"
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define MOD (pow(10,9)+7)
using namespace std;

ll mod(ll n,ll a)
{
    string num = to_string(n);
    ll res= 0;
    for(auto i=0;i<num.length();i++)
    {
        res=(res*10+(ll)num[i]-'0')%a;
    }
    return res;
}




int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr);
    cout.tie(nullptr);
  
    double n;
    cin>>n;
    cout<<2*M_PI*n;
    return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int main(){
	cin.sync_with_stdio(false);
	int cases;
	cin>>cases;
	while(cases--){
		int n,d;
		cin>>n>>d;
		ll sum=0;
		rep(i,7){
			bool bt=d>>i&1;
			if(n%2==0){
				if(bt)sum+=pow(2,i)*(n-1);
				else sum+=pow(2,i)*n;
			}else{
				if(bt)sum+=pow(2,i)*n;
				else sum+=pow(2,i)*(n-1);
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define fs first
#define sc second

int main(void){
    int n,m;
    cin >> n >> m;
    priority_queue<long double> q;
    long double a;
    rep(_,n){
        cin >> a;
        q.push(a);
    }
    rep(_,m){
        a = q.top();
        q.pop();
        a /= 2;
        q.push(a);
    }
    ll ans = 0;
    while(!q.empty()){
        a = q.top();
        q.pop();
        ans += (ll)a;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2420
#include <stdio.h>

int main(void){
    char S[10];
    scanf("%s", S);
    if (S[0]==S[1] && S[1]==S[2] && S[2]==S[3]) {
        printf("No");
    }
    else {
        if ((S[0]==S[1] && S[2]==S[3]) || (S[0]==S[2] && S[1]==S[3]) || (S[0]==S[3] && S[1]==S[2])) printf("Yes");
        else printf("No");
    }
    return 0;
}


Measured memory_bytes: 760
/* Preprocess */
#include <bits/stdc++.h>

#define pow(n) (n)*(n)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()


/* Field */
using namespace std;


/* function */

int main (void) 
{

  /* Variable_Proclamation */
  int A, B;  // 水を入れる量 (*100) (A<B)
  int C, D;  // 砂糖を入れる量 (C<D)
  int E;     // 100gに溶ける砂糖
  int F;     // ビーカーの最大容量

  int i, j, k, l;    // subscript
  int trial; // ループを回す回数
  int capa_i, capa_j, capa_k, capa_l;

  int water;
  int suger;
  int can_melt;
  int beaker;

  int ans_suger, ans_beaker;
  double con, max_con; // concentration（濃度）


  /* Input, Resize, Initialize */
  cin >> A >> B;
  cin >> C >> D;
  cin >> E;
  cin >> F;

  trial   = 31;
  max_con = -1;


  /* Calculation */

  capa_i = F;
  for(i=0; capa_i -(A*100)*i >= 0; i++)
  {
    capa_j = capa_i -(A*100)*i;

    for(j=0; capa_j -(B*100)*j >= 0; j++)
    {
      capa_k = capa_j -(B*100)*j;

      for(k=0; capa_k -C*k >= 0; k++)
      {
        capa_l = capa_k -C*k;  

        for(l=0; capa_l -D*l >= 0; l++)
        {

            water    = (A*i + B*j) *100;
            can_melt = (A*i + B*j) *E;
            suger    =  C*k + D*l;
            beaker   = water + suger;

            if(can_melt >= suger)
            {
              con = (double)suger / (double)beaker;
              if(max_con < con)
              {
                max_con    = con;
                ans_suger  = suger;
                ans_beaker = beaker;
              }
            }

        }
      }
    }
  }

  // space;
  cout << ans_beaker << " " << ans_suger << endl;

  return 0;

}





Measured memory_bytes: 256
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		char[] n = sc.next().toCharArray();

		int nn = n.length;

		for (int i = 0; i < nn / 2; i++) {
			if (n[i] != n[nn - 1 - i]) {
				pr.println("No");
				return;
			}
		}

		pr.println("Yes");
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 21972
from collections import deque
deq = deque()
for _ in range(int(input())):
    moji = list(map(int, input().split()))
    method, d = moji[:2]
    if method == 0:
        x = moji[2]
        if d == 0:
            deq.appendleft(x)
        else:
            deq.append(x)
    elif method == 1:
        print(deq[d])
    elif method == 2:
        if d == 0:
            deq.popleft()
        else:
            deq.pop()


Measured memory_bytes: 21976
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx,tune=naive")
//#pragma GCC diagnostic ignored "-W"
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define INF 2000000000
#define PI 3.1415926535897932384626
const ll MOD=1e9+7;
char in[10005];
int main(){
        int n,m;
        while(~getII(n,m)){
                int ans=max(max(n+m,n-m),n*m);
                printf("%d\n",ans);
        }
}

Measured memory_bytes: 256
def gcd(a, b):
    return gcd(b%a, a) if a else b
def lcm(a, b):
    return a * b // gcd(a, b)

A, B, C, D = map(int, input().split(' '))

total = B - A + 1

group_CD = lcm(C, D)

if A % C == 0:
    lower_C = A // C
else:
    lower_C = A // C + 1
upper_C = B // C + 1
num_C = upper_C - lower_C

if A % D == 0:
    lower_D = A // D
else:
    lower_D = A // D + 1
upper_D = B // D + 1
num_D = upper_D - lower_D

if A % group_CD == 0:
    lower_CD = A // group_CD
else:
    lower_CD = A // group_CD + 1
upper_CD = B // group_CD + 1
num_CD = upper_CD - lower_CD

print(total - num_C - num_D + num_CD)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define PI 3.14159265359
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pai;
typedef pair<ll, ll> pal;
const int MOD = 1e9+7;
const ll LLINF = 1e18;


int main(){
	int n;
  	cin >> n;
	cout << 48-n << endl;
	return 0;
}

Measured memory_bytes: 3580
import java.util.Scanner;

public class Main {

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

	Scanner sc = new Scanner(System.in);

	void run() {
		int c[][] = new int[3][3];
		
		for(int i =0 ; i  < 3 ; i++){
			for(int j =0 ; j < 3 ;j++){
				c[i][j] = sc.nextInt();
			}
		}
		
		int a[] = new int[3];
		int b[] = new int[3];
		
		a[0] = 0;
		b[0] = c[0][0];
		b[1] = c[0][1];
		b[2] = c[0][2];
		a[1] = c[1][0] - b[0];
		a[2] = c[2][0] - b[0];
		
		int x = 0;
		for(int i = 0; i < 3; i++){
			for(int j = 0; j < 3; j++){
				if(c[i][j] != a[i]+b[j]){
					x = 1;
				}
			}
		}
		System.out.println(x==0?"Yes":"No");
	}
}


Measured memory_bytes: 22996
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
 
using namespace std;
 
int main(){
    int N,M;
    cin >> N >> M;

    for(int i = 0; i < M; i++){
        int a;
        cin >> a;

        N -= a;
    }

    if(N < 0){
        cout << -1 << endl;
    }else{
        cout << N << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(n,v) cout<<#v<<":";for(int i=0;i<n;i++)cout<<v[i]<<" ";cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

int main(){
    ll n;cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    bool f=true;
    for(int i=0;i<n-1;i++){
        if(a[i+1]-a[i]>=2) f=false;
    }
    if(!f||a[0]!=0){
        cout<<-1<<endl;return 0;
    }
    ll ans=0;
    ll idx=n-1;
    while(idx>=0){
        ll num=a[idx];
        while(a[idx-1]+1==a[idx]&&idx>=0){
            idx--;
        }
        idx--;
        ans+=num;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

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)];
    }
};

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(m),b(m);
    rep(i,m){
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
    }

    int ans=0;
    rep(i,m){
        UnionFind uf(n);
        rep(j,m){
            if(i==j) continue;
            uf.merge(a[j],b[j]);
        }
        rep(i,n){
            if(uf.size(i)!=n){
                ans++;
                break;
            }
        }
    }

    cout<<ans<<endl;
} 


Measured memory_bytes: 3592
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,ans;
int a[100001];
int panduan[100001];
bool cnt()
{
	for(int i=1;i<=n;i++)
	{
		if(!(panduan[i]&1))return 1;
	}
	return 0;
}
void dfs(int x)
{
	if(x==n+1){
		if(cnt()==1)ans++;return;
	}
	for(int i=-1;i<=1;i++)
	{
		panduan[x]=a[x]+i;
		dfs(x+1);
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	dfs(1);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i > n; --i)
typedef long long ll;
#define mod 1000000007

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  ll ans = 0;
  ll h = H - A;
  ll w = W - B;
  COMinit();
  rep(i, 0, h) {
    ans = (ans + COM(i + B - 1, B - 1) * COM(H - i + w - 2, w - 1)) % mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 12160
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = int(1e9);
typedef long long int ll;

/* -- template -- */
int main(){
    int N, K, Q;cin >> N >> K >> Q;
    int A[Q];
    rep(i, Q)cin >> A[i];
    vector<int> score(N, 0);
    rep(i, Q){
        score[A[i] - 1] += 1;
    }
    rep(i, N){
        if(score[i] - Q > -K)cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main(){
    int x,y;
    cin >> x >> y;
    cout << x + y/2 << endl;
    


    return 0;

}


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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define bit(n) (1LL<<(n))
// functions
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(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << p.first << " " << p.second; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  int n; cin >> n;
  FOR(i, 1, 10){
    FOR(j, 1, 10){
      if(i * j == n){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/math/common_factor.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
#ifdef BOOST_RANGE_ALGORITHM_FOR_EACH_HPP_INCLUDED
  boost::for_each(vc, [&os](T value) {
#else
  std::for_each(vc.begin(), vc.end(), [&os](T value) {
#endif
    os << value << '\n';
    });
  return os;
}

template<class T1, class T2>
inline
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  //string S{}; std::cin >> S;
  ui N{}; cin >> N;

  vector<ull> A(N);
  uc odd{};
  rep(0, N)
  {
    ll tmp;
    cin >> tmp;
    if (tmp < 0)
    {
      odd = !odd;
      tmp = -tmp;
    }
    A[i] = tmp;
  }

  ull min{};
  if (odd)
  {
    auto it = boost::min_element(A);
    min = *it;
    *it = 0;
  }
  ull sum = boost::accumulate(A, 0ULL) - min;

  using std::cout;
  cout << sum << '\n';
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 1024
import sys
fin = sys.stdin.readline
from heapq import heappop, heappush


# assuming that the vertices are 0, 1, ..., N - 1
# if V^2 >> E, use a hashmap representation of w
# time complexity: O(ElgE)
# space complexity: O(E)
def prim(adj, w):
    num_vertices = len(adj)
    # initialize
    min_cost = [float('inf')] * num_vertices
    min_cost[0] = 0
    used = [False] * num_vertices
    priority_queue = [(0, 0)]
    total_cost = 0

    while priority_queue:
        cost, vertex = heappop(priority_queue)
        if cost > min_cost[vertex] or used[vertex]:
            continue
        used[vertex] = True
        total_cost += cost

        for neighbor in adj[vertex]:
            cost_v_to_n = w[(vertex, neighbor)]
            if min_cost[neighbor] > cost_v_to_n:
                min_cost[neighbor] = cost_v_to_n
                heappush(priority_queue, (cost_v_to_n, neighbor))

    return total_cost


N = int(fin())
coords = [[int(elem) for elem in fin().split()] + [i] for i in range(N)]

adj = [set() for _ in range(N)]
w = {}

# sort coords in increasing order of x
coords.sort(key=lambda x: x[0])
for i, (x, _, vertex) in enumerate(coords[:-1]):
    next_x, _, next_vertex = coords[i + 1]
    adj[vertex].add(next_vertex)
    adj[next_vertex].add(vertex)
    weight = next_x - x
    if (vertex, next_vertex) not in w or w[(vertex, next_vertex)] > weight:
        w[(vertex, next_vertex)] = weight
    if (next_vertex, vertex) not in w or w[(next_vertex, vertex)] > weight:
        w[(next_vertex, vertex)] = weight

# sort coods in increasing order of y
coords.sort(key=lambda x: x[1])
for i, (_, y, vertex) in enumerate(coords[:-1]):
    _, next_y, next_vertex = coords[i + 1]
    adj[vertex].add(next_vertex)
    adj[next_vertex].add(vertex)
    weight = next_y - y
    if (vertex, next_vertex) not in w or w[(vertex, next_vertex)] > weight:
        w[(vertex, next_vertex)] = weight
    if (next_vertex, vertex) not in w or w[(next_vertex, vertex)] > weight:
        w[(next_vertex, vertex)] = weight


print(prim(adj, w))



Measured memory_bytes: 149760
S = input()
L = len(S)
for i in range(L):
  c = S[i]
  if c == "A":
    s = i
    break
for i in range(L):
  c = S[-(i+1)]
  if c == "Z":
    e = L - (i+1)
    break
print(e-s+1)


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

using namespace std;

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

const int INF = 1000000000; //
const ll LINF = (ll) 4000000000000000000; //
const ll MOD = (ll) 1000000007; //
const double PI = 3.1415926535898; //
const int limit = 100010;

#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define Size(s) (int) s.size()

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

int main() {
    string s;
    cin >> s;
    int gx, gy;
    cin >> gx >> gy;
    vector<int> vx, vy;

    bool vec_is_x = true;
    int F_cnt = 0;
    bool first_move = true;

    rep(i, s.length()) {
        if (s[i] == 'F' && i < s.length() - 1) {
            F_cnt++;
        } else {
            if (s[i] == 'F') F_cnt++;
            if (F_cnt != 0 && !first_move) {
                if (vec_is_x) vx.push_back(F_cnt);
                else vy.push_back(F_cnt);
            } else if (first_move) {
                gx -= F_cnt;
                first_move = false;
            }
            vec_is_x = !vec_is_x;
            F_cnt = 0;
        }
    }

    set<int> stx[8010], sty[8010];
    stx[0].insert(0);
    sty[0].insert(0);

    rep(i, Size(vx)) {
        for (auto x : stx[i]) {
            stx[i + 1].insert(x + vx[i]);
            stx[i + 1].insert(x - vx[i]);
        }
    }

    rep(i, Size(vy)) {
        for (auto y : sty[i]) {
            sty[i + 1].insert(y + vy[i]);
            sty[i + 1].insert(y - vy[i]);
        }
    }

    Yes(stx[Size(vx)].count(gx) && sty[Size(vy)].count(gy));

    return 0;
}

Measured memory_bytes: 188672
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n,k;
  string s;
  cin >> n >> k >> s;
  int ans=1;
  int cnt=0;
  if(s[0]=='0')cnt++;
  int l=0,r=0;
  while(r<n-1){
    if(s[r]=='1'&&s[r+1]=='0'){
      cnt++;
    }
    r++;
    if(cnt>k){
      while(l<r){
        l++;
        if(s[l-1]=='0'&&s[l]=='1'){
          cnt--;
          break;
        }
      }
    }
    ans=max(ans,r-l+1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<bits/stdc++.h>
#include<climits>

using namespace std;

int main(){
    int n,x,t;cin>>n>>x>>t;
    int sol = 0;
    if(n%x==0){
        sol = (n/x)*t;
    }else{
        sol = (n/x+1)*t;
    }
    cout<<sol<<endl;
}  


Measured memory_bytes: 3576
// Why I am so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int MAXN = (int)1e5 + 5;

ll a[MAXN], b[MAXN];

int n;

void solve() {                   
	scanf("%d", &n);

    for (int i = 1; i <= n; ++i) {
    	scanf("%lld %lld", &a[i], &b[i]);
    }

    ll sum = 0;

    for (int i = n; i > 0; --i) {
		a[i] += sum;

		if (a[i] % b[i]) {
			ll nxt = (a[i] / b[i] + 1) * b[i];
			sum += (nxt - a[i]);
		}                   
    }

    printf("%lld\n", sum);
}    	

int main() {    
    int tt = 1;

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

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(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 dx[2] = {0,1};
int dy[2] = {1,0};
int main()
{
    int N;
    cin >> N;

    vector<vector<int>> c(2, vector<int>(N, 0));

    REP(i,2){
        REP(j,N){
            cin>>c[i][j];
        }
    }


    vector<vector<int>> dist(2, vector<int>(N, -1));
    queue<pair<int,int>> que;
    que.push(make_pair(0,0));
    dist[0][0] = c[0][0];

    while(!que.empty()){
        pair<int,int> p = que.front();
        int x=p.second;
        int y=p.first;
        que.pop();
        
        REP(i,2){
            int nx, ny;
            nx = x + dx[i];
            ny = y + dy[i];
            if(nx>=N||ny>=2) continue;
            que.push(make_pair(ny,nx));
            chmax(dist[ny][nx], dist[y][x]+c[ny][nx]);
        }
    }
    /*
    REP(i,2){
        REP(j,N){
            cout<<c[i][j]<<" ";
        }
        cout  << endl;
    }
    REP(i,2){
        REP(j,N){
            cout<<dist[i][j]<<" ";
        }
        cout  << endl;
    }
    */
    cout << dist[1][N-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;



int main()
{
	int m, f, r;

	while (true) {
		char ans = 'x';
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1) break;

		if (m == -1 || f == -1) ans = 'F';
		else if (m + f >= 80) ans = 'A';
		else if (m + f >= 65) ans = 'B';
		else if (m + f >= 50) ans = 'C';
		else if (m + f >= 30) {
			if (r >= 50) ans = 'C';
			else ans = 'D';
		}
		else ans = 'F';

		cout << ans << endl;
	}

	return 0;
}



Measured memory_bytes: 3092
process.stdin.resume();
process.stdin.setEncoding("utf8");

const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

const lines = [];

reader.on("line", (line) => {
  lines.push(line);
});

reader.on("close", () => {
  let s = lines[0];
  const n = Number(lines[1]);
  for (let i = 2; i < n + 2; i++) {
    const ts = lines[i].split(" ");
    const a = Number(ts[1]);
    const b = Number(ts[2]);
    switch (ts[0]) {
      case "replace":
        s = s.slice(0, a) + ts[3] + s.slice(b + 1);
        break;
      case "reverse":
        s =
          s.slice(0, a) +
          s
            .slice(a, b + 1)
            .split("")
            .reverse()
            .join("") +
          s.slice(b + 1);
        break;
      case "print":
        console.log(s.slice(a, b + 1));
        break;
    }
  }
});



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

int main() {
  int N;
  int a=0;
  int b=1;
  cin >>N;
  for (int i=0; i<8; i++){
    
    a+= N%(b*10)/b;
      b*=10;
    }
  if (N%a==0){
    cout << "Yes" << endl;
  }
  else
    cout << "No" << endl;
}
   

Measured memory_bytes: 3532
import copy
a = int(input())
b = input().split(" ")
c = int(input())
for i in range(c):
  second = 0
  d = input().split(" ")
  e = copy.deepcopy(b)
  e[int(d[0])-1] = d[1]
  for i in range(a):
    second += int(e[i])
  print(second)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
//#include <boost/functional/hash.hpp>
//example: unordered_set< pair<int,int>,boost::hash< std::pair<int, int> > > used;
//priority_queue< pair<int,pair<int,int> >, vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int> > > > pqueue;    //cost, vertex(行き先)
using namespace std;

#define MODULE 1000000007
#define MP make_pair
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
template<typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val){ //usage: int dp[10][10]; Fill(dp,INF);
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef pair<int, int> P;
typedef long long LL;
const int INF = INT_MAX / 2;    //int_max->2*e+9 LLの時はLLONG_MAX
/*const int MAXN = 100001;

struct edge {
    edge(int to, int cost) : to(to), cost(cost) {}
    int to, cost;
};
vector<edge> graph[MAXN];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};*/

//-----Template---------
string s;
int counter;
int main(){
    ios::sync_with_stdio(false); //cout<< fixed << setprecision(10);
    cin>>s;
    if(s.length()==1){
        cout<<0<<endl;
        return 0;
    }
    char now=s[0];
    for (int i = 1; i < s.length(); ++i) {
        if(now!=s[i]){
            counter++;
            now=s[i];
        }
    }cout<<counter<<endl;
}

Measured memory_bytes: 512
import sys

def find(x,par,rank):
    if par[x] == x : return x
    else:
        par[x] = find(par[x],par,rank)
        return par[x]

def unite(x,y,par,rank): 
    x = find(x,par,rank)
    y = find(y,par,rank)
    if (x != y):
        if rank[x] < rank[y]:
            par[x] = y
        else :
            par[y] = x
            if (rank[x] == rank[y]) : rank[x] += 1

def same(x,y,par,rank):
    return (find(x,par,rank) == find(y,par,rank)) 

n,k,l = map(int, sys.stdin.readline().split())

par1 = [i for i in range(n)]
par2 = [i for i in range(n)]
rank1 = [0 for i in range(n)]
rank2 = [0 for i in range(n)]

for i in range(k):
    pp,qq = map(int, sys.stdin.readline().split())
    unite(pp-1,qq-1,par1,rank1)

for i in range(l):
    rr,ss = map(int, sys.stdin.readline().split())
    unite(rr-1,ss-1,par2,rank2)

dic = {}
parlis = []
for i in range(n):
    p1 = find(i,par1,rank1)
    p2 = find(i,par2,rank2)
    parlis.append((p1,p2))
    if (p1,p2) in dic:
        dic[(p1,p2)] += 1
    else: 
        dic[(p1,p2)] = 1

ans =[]

for i in range(n):
    ans.append(dic[parlis[i]])

print(*ans)

Measured memory_bytes: 69732
//boom diggy diggy boom boom
/*
freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
      */
#include<bits/stdc++.h>
#define ull unsigned long long int 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define mod 1000000007
#define F first
#define S second
#define ll long long 
#define ld long double 

int power(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int ncr(int n,int r){int res=1;if(r>n-r)r=n-r;for(int i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
int gcd(int a,int b){if (a==0)return b;return gcd(b%a,a);}
int lcm(int a,int b){return (a/gcd(a,b)*b);}int max(int a,int b){int ans=a>b?a:b;return ans;}

using namespace std;

int main()
{
  int n;
  cin>>n;
  ll a[n][3];
  for (int i = 0; i < n; ++i)
  {
    cin>>a[i][0]>>a[i][1]>>a[i][2];
  }
  for (int i = 1; i < n; ++i)
  {
    a[i][0]=max(a[i][0]+a[i-1][1],a[i][0]+a[i-1][2]);
    a[i][1]=max(a[i][1]+a[i-1][0],a[i][1]+a[i-1][2]);
    a[i][2]=max(a[i][2]+a[i-1][1],a[i][2]+a[i-1][0]);
  }
  cout<<max({a[n-1][0],a[n-1][1],a[n-1][2]});

return 0;
}

Measured memory_bytes: 2560
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const P p1, const P p2){ return p1.first < p2.first;};
bool p_comp_fg(const P p1, const P p2){ return p1.first > p2.first;};
bool p_comp_ss(const P p1, const P p2){ return p1.second < p2.second;};
bool p_comp_sg(const P p1, const P p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    string S; cin >> S;
    ll ret = 0;
    for(int i = 0; i < 1 << (S.size() - 1); i++){
        int st = 0;
        for (int j = 0; j < S.size() - 1; j++) {
            if(i >> j & 1){
                ret += stoll(S.substr(st, j - st + 1)); st = j + 1;
            }
        }
        ret += stoll(S.substr(st, S.size() - st));
    }
    cout << ret << endstr;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n,m,a[201][201],c[11][11];

    cin>>n>>m;

    for(int i = 0 ; i < 10 ; i++)
        for(int j = 0 ; j < 10 ; j++)
            cin>>c[i][j];

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

    for (int k = 0; k < 10; ++k)
        for (int i = 0; i < 10; ++i)
            for (int j = 0; j < 10; ++j)
                if (c[i][k] + c[k][j] < c[i][j])
                    c[i][j] = c[i][k] + c[k][j];

    int s=0;

    for(int i = 0 ; i < n ; i++)
        for(int j = 0 ; j < m ; j++)
            if(a[i][j]!=-1)
                s+=c[a[i][j]][1];

    cout<<s;
}


Measured memory_bytes: 384
from bisect import bisect_left

n = int(input())
length_list = list(map(int, input().split()))

count = 0
length_list.sort()

for a_idx in range(n - 2):
    for b_idx in range(a_idx + 1, n - 1):
        a = length_list[a_idx]
        b = length_list[b_idx]

        left_count = bisect_left(length_list, a+b)
        count += max(0, left_count - b_idx - 1)


print(count)

Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

int main(){
    ll n, m, k;
    cin >> n >> m >> k;
    ll a[n], b[m];
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    ll suma[n+1], sumb[m+1];
    suma[0] = 0;
    sumb[0] = 0;
    rep(i, n) suma[i+1] = suma[i] + a[i];
    rep(i, m) sumb[i+1] = sumb[i] + b[i];
    ll ans = 0;
    ll idx = 0;
    for (ll i = n; i >= 0; i--){
        ll t = suma[i];
        while(idx < m && t + sumb[idx+1] <= k){
            idx++;
        }
        if(t+sumb[idx] <= k && i + idx > ans){
            ans = i + idx;
        }
        // cout << i << " " << idx << " " << t + sumb[idx] << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9872
import collections

N = int(input())
S = [input() for i in range(N)]

counter = collections.Counter(S)
maxcount = max(counter.values())

strs_max = []
for k, v in counter.items():
    if v == maxcount:
        strs_max.append(k)

ans_list = sorted(strs_max)
for a in ans_list:
    print(a)

Measured memory_bytes: 35568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define rreps(i,n) for(int i = (int)(n); i > 0; i--)
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(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; }
const int INF = INT_MAX;
const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vi x(N), y(N);
    rep(i, N) cin >> x[i] >> y[i];

    vi array(N);
    rep(i, N) array[i] = i;
    double ans = 0;
    ll cnt = 0;
    do {
        double d = 0;
        int X, Y;
        bool first = true;
        for (auto i : array) {
            if (first) {
                X = x[i];
                Y = y[i];
                first = false;
            } else {
                d += sqrt(pow(X-x[i], 2) + pow(Y-y[i], 2));
                X = x[i];
                Y = y[i];
            }
        }
        ans += d;
        cnt++;
    } while (next_permutation(all(array)));
    
    ans /= cnt;
    cout << fixed << setprecision(10);
    cout << ans << endl;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    deque<int> elements(n);
    
    string operation;
    int key, count = 0;
    deque<int>::iterator it;
    for(int i = 0; i < n; i++){
        cin >> operation;

        if(operation == "insert"){
            cin >> key;
            it = elements.begin();
            elements.insert(it, key);
            count++;
        } else if(operation == "delete"){
            cin >> key;
            it = find(elements.begin(), elements.end(), key);
            if (it != elements.end()){
                elements.erase(it);
                count--;
            }
        } else if(operation == "deleteFirst"){
            it = elements.begin();
            elements.erase(it);
            count--;
        } else if(operation == "deleteLast"){
            elements.pop_back();
            count--;
        }
    }

    for(int i = 0; i < count; i++){
        if(i != 0) cout << " ";
        cout << elements[i];
    }
    cout << endl;
    
}


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

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

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

using namespace std;


signed main() {
  int A, B, Q; 
  cin >> A >> B >> Q;

  set<int> s;
  REP(i, A){
    int a;
    cin >> a;
    s.insert(a);
  }
  set<int> t;
  REP(i, B){
    int a;
    cin >> a;
    t.insert(a);
  }

  s.insert(-INF); s.insert(INF);
  t.insert(-INF); t.insert(INF);

  while(Q--){
    int x;
    cin >> x;

    auto it1 = s.upper_bound(x);
    int a = *it1---x;
    int b = x-*it1;
    auto it2 = t.upper_bound(x);
    int c = *it2---x;
    int d = x-*it2;

    cout << min(min(max(b, d), max(a, c)), min(min(a, d)*2+max(a, d), min(b, c)*2+max(b, c))) << endl;
  }

  return 0;
}

Measured memory_bytes: 10752
#include <iostream>
#include <string>

int w[] = {1,2,6,5,3,4};
//0上、1手前、2下、3奥、4右、5左

using namespace std;

void Shift(int a,int b,int c,int d)//左へつめる
{
	int e = w[a];
	w[a] = w[b];
	w[b] = w[c];
	w[c] = w[d];
	w[d] = e;
}

void Set()
{
	w[0] = 1;
	w[1] = 2;
	w[2] =6;
	w[3] = 5;
	w[4] = 3;
	w[5] = 4;
}

int main(void)
{
	int n;
	string s;
	int sum=0;
	while(1)
	{
		cin >> n;
		if(n==0)
			return 0;
		sum = 0;
		Set();
		for(int i=0;i<n;++i)
		{
			cin >> s;
			if(s[0] == 'N')
			{
				Shift(0,1,2,3);
			}
			if(s[0] == 'E')
			{
				Shift(0,5,2,4);
			}
			if(s[0] == 'W')
			{
				Shift(0,4,2,5);
			}
			if(s[0] == 'S')
			{
				Shift(0,3,2,1);
			}
			if(s[0] == 'R')
			{
				Shift(1,4,3,5);
			}
			if(s[0] == 'L')//0上、1手前、2下、3奥、4右、5左
			{
				Shift(1,5,3,4);
			}
			sum+=w[0];
		}
		cout << sum+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.IOException;
import java.util.Scanner;

public class Main {

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

	private void run() throws NumberFormatException, IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		Node[] nodes = new Node[n];
		for (int i = 0; i < n; i++) {
			nodes[i] = new Node();
		}
		for (int i = 0; i < n; i++) {
			int v = scanner.nextInt();
			int l = scanner.nextInt();
			int r = scanner.nextInt();
			nodes[v].l = l;
			nodes[v].r = r;
			if (l != -1)
				nodes[l].p = v;
			if (r != -1)
				nodes[r].p = v;
		}

		int root = 0;
		for (int i = 0; i < n; i++) {
			if (nodes[i].p == -1) {
				root = i;
			}
		}
		System.out.println("Preorder");
		preParse(root, nodes);
		System.out.println();
		System.out.println("Inorder");
		inParse(root, nodes);
		System.out.println();
		System.out.println("Postorder");
		postParse(root, nodes);
		System.out.println();
	}

	private void postParse(int u, Node[] nodes) {
		if (u == -1)
			return;
		postParse(nodes[u].l, nodes);
		postParse(nodes[u].r, nodes);
		System.out.print(" " + u);
	}

	private void inParse(int u, Node[] nodes) {
		if (u == -1)
			return;
		inParse(nodes[u].l, nodes);
		System.out.print(" " + u);
		inParse(nodes[u].r, nodes);
	}

	private void preParse(int u, Node[] nodes) {
		if (u == -1)
			return;
		System.out.print(" " + u);
		preParse(nodes[u].l, nodes);
		preParse(nodes[u].r, nodes);
	}

	class Node {
		int p = -1, l, r;
	}
}

Measured memory_bytes: 18072