akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define ALL(obj) (obj).begin(),(obj).end()

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template<class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } else return; }
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) { o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o; }
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) { o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o; }
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) { o << "{" << obj.first << ", " << obj.second << "}"; return o; }
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
void print(void) { cout << endl; }
template <class Head> void print(Head&& head) { cout << head; print(); }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << " "; print(forward<Tail>(tail)...); }
template <class T> void chmax(T& a, const T b) { a = max<T>(a, b); }
template <class T> void chmin(T& a, const T b) { a = min<T>(a, b); }
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }

int main() {
	int H, W; cin >> H >> W;
	V<string> A(H),B(H),C(H);
	REP(i, H) cin >> A[i];
	REP(i, H) REP(j, W) B[i].push_back('.');
	REP(i, H) REP(j, W) C[i].push_back('.');
	REP(i, H) B[i][0] = '#';
	for (int i = 0; i < H; i += 2) REP(j, W-1) B[i][j] = '#';
	REP(i, H) REP(j, W) C[i][j] = (B[i][j]=='#'?'.':'#');
	REP(i, H) REP(j, W) if (A[i][j] == '#') B[i][j] = C[i][j] = '#';
 	REP(i, H)cout << B[i] << endl;
	cout << endl;
	REP(i, H)cout << C[i] << endl;
	return 0;
}



Measured memory_bytes: 1536
#include <stdio.h>

int main()
{
    int i,N,T,c,t,cmin;
    cmin=0;
    scanf("%d %d",&N,&T);
    for(i=0;i<N;i++)
    {
        scanf("%d %d",&c,&t);
        if(t<=T){
            if(!cmin || cmin>c) cmin=c;
        }
    }
   if(cmin!=0){
   printf("%d",cmin);
   }else{
   printf("TLE");
   }

 return 0;
}

Measured memory_bytes: 128
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=1;i<=H;i++){
                for(int j=1;j<=W;j++) {
                    System.out.printf("#");
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
    }
}


Measured memory_bytes: 63092
import java.util.Scanner;
public class Main {
	long Q;
	long r,l;
	public void solve() {
		Scanner cin = new Scanner(System.in);
		Q = cin.nextLong();
		r = 0;
		l = 0;
		for(int i = 0;i < Q;i++){
			long p = cin.nextLong();
			String c = cin.next();
			long n = cin.nextLong();
			
			if(c.equals("(")){
				r += n;
			}else{
				l += n;
			}
			
			if(r == l){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
		}
		cin.close();
	}
 
	public static void main(String[] args) {
		new Main().solve();
	}
}

Measured memory_bytes: 57536
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <random>

using ll = long long int;
using P = std::pair<ll, int>;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int l[30];
ll c[30],s[400][30],ans[150000];
std::vector<int> v[150000];

int main(void){
	int d,i,j,n=26,k,m=125000;
	ll ansm = -INFLL;
	for(k=0; k<m; ++k){
		for(j=0; j<n; ++j){
			v[k].push_back(j);
		}
		std::random_device seed_gen;
		std::mt19937 engine(seed_gen());
		std::shuffle(v[k].begin(), v[k].end(), engine);
	}
	std::cin >> d;
	for(i=0; i<26; ++i){
		std::cin >> c[i];
	}
	for(i=0; i<d; ++i){
		for(j=0; j<n; ++j){
			std::cin >> s[i][j];
		}
	}
	for(k=0; k<m; ++k){
		for(j=0; j<n; ++j){
			l[j] = -1;
		}
		for(i=0; i<d; ++i){
			ans[k] += s[i][v[k][i%26]];
			l[v[k][i%26]] = i;
			for(j=0; j<n; ++j){
				ans[k] -= c[j]*(i-l[j]);
			}
		}
		ansm = std::max(ansm,ans[k]);
		// std::cout << ans[k] << std::endl;
	}
	for(k=0; k<m; ++k){
		if(ans[k] == ansm){
			for(i=0; i<d; ++i){
				std::cout << v[k][i%26]+1 << std::endl;
			}
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 25820
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cstring>
#include<queue>
#include<tuple>
#include<stack>
#include<cstdio>
#include<iomanip>
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<string> vs;
Def inf = sizeof(Def) == sizeof(ll) ?2e18:1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int d[52][52][52][52];
typedef tuple<int,int,int,int>tp;
vs a,b;
int n,m;
int f(int x1,int y1,int x2,int y2){
  //    cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;

  priority_queue<tp>q;
  q.push(tp{x1,y1,x2,y2});
  while(!q.empty()){ 
    int x1,y1,x2,y2;
    tie(x1,y1,x2,y2)=q.top();
    q.pop();
    rep(i,4){
  
      int nx1=x1+dx[i];
      int ny1=y1+dy[i];
      int nx2=x2+dx[i];
      int ny2=y2+dy[(2+i)%4];
      if(nx1<0||ny1<0||nx1>=n||ny1>=m){
	nx1-=dx[i];
	ny1-=dy[(i)%4];
      }
      if(nx2<0||ny2<0||nx2>=n||ny2>=m){
	nx2-=dx[i];
	ny2-=dy[(i+2)%4];
      }
      if(a[nx1][ny1]=='#'){
	nx1-=dx[i];
	ny1-=dy[i];
      }
      if(b[nx2][ny2]=='#'){
	nx2-=dx[i];
	ny2-=dy[(i+2)%4];
      }
      bool A=a[nx1][ny1]=='%';
      bool B=b[nx2][ny2]=='%';
      if(A!=B)continue;
      if(d[nx1][ny1][nx2][ny2])continue;
      // cout<<nx1<<" "<<ny1<<" "<<nx2<<" "<<ny2<<endl;
      d[nx1][ny1][nx2][ny2]=1;
      q.push(tp{nx1,ny1,nx2,ny2});//f(nx1,ny1,nx2,ny2);
    }
  }
}
int main(){
  while(cin>>m>>n,n){
    rep(i,52)rep(j,52)rep(k,52)rep(l,52)
      d[i][j][k][l]=0;
    a=b=vs(n);
    rep(i,n)cin>>a[i]>>b[i];
    rep(i,n)rep(j,m)rep(k,n)rep(l,m)if(a[i][j]=='L'&&b[k][l]=='R'){
      d[i][j][k][l]=1;
      f(i,j,k,l);
    }
    rep(i,n)rep(j,m)rep(k,n)rep(l,m)if(a[i][j]=='%'&&b[k][l]=='%'){
      if(d[i][j][k][l])cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
    }
  }
}



Measured memory_bytes: 32964
N, D = map( int, input().split() )
d = list( map( int, input().split() ) )
Q = int( input() )
q = list( map( lambda x: int( x ) - 1, input().split() ) )

dis = [ 0 for i in range( N + 1 ) ]
dis[ 0 ] = D
for i in range( N ):
  dis[ i + 1 ] = min( dis[ i ], abs( dis[ i ] - d[ i ] ) )

dp = [ 0 for i in range( N + 1 ) ]
dp[ N ] = 1
for i in range( N - 1, -1, -1 ):
  if dp[ i + 1 ] <= d[ i ] // 2:
    dp[ i ] = dp[ i + 1 ]
  else:
    dp[ i ] = dp[ i + 1 ] + d[ i ]

for qi in range( Q ):
  print( [ "NO", "YES" ][ dis[ q[ qi ] ] >= dp[ q[ qi ] + 1 ] ] )


Measured memory_bytes: 135928
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll n, d;
  cin >> n >> d;
  cout << (n + (2*d)) / (2*d + 1);

  return 0;
} //good night.

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//#define int long long  ←保留
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

int gcd(int a, int b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {      //最小公倍数
    return a * b / gcd(a, b);
}

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/*-------------ここまで---------------------------------------------*/

//C++(GCC9.2.1)

/*signed*/int main() {
    int r, D, x2000;

    cin >> r >> D >> x2000;
    int x = x2000;
    rep(i, 10) {
        x = r * x - D;
        cout << x << endl;

    }
    return 0;
}

Measured memory_bytes: 3592
#include<iostream>
using namespace std;
int main(){
	int n,count=1;
	cin >> n;
	char s[n];
	cin >> s;
	for(int i=0;i<n-1;i++){
		if(s[i]!=s[i+1])
			count++;
	}
	cout << count;
		
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
    ll n,t;
    cin >> n >> t;

    ll a[n];
    for(int i = 0; i < n; i++)
        scanf("%lld",&a[i]);

    ll mn = a[0];
    ll p = 0, mp = 0;
    ll c = 1;

    for(int i = 1; i < n; i++)
    {
        if(a[i] <  mn)   mn = a[i];
        if(a[i] >= mn)   p = a[i] - mn;

        if(p > mp)         mp = p,c = 1;
        else if(p == mp)   c++;
    }

    cout << c << endl;

    return 0;
}


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

typedef ostringstream OSS;
typedef istringstream ISS;

typedef long long LL;
typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define fst first
#define snd second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

/***** ?´??????? *****/

// ????¬?????´???????
template<typename T>
vector<T> calc_csum(vector<T> &val) {
	vector<T> sum(val.size());
	partial_sum(val.begin(), val.end(), sum.begin());
	return sum;
}

template<typename T>
T sum_csum(vector<T> &sum, int begin, int end) {
	return sum[end] - sum[begin];
}
/********************/

const int OFFSET = 200000;
int N, W, H;

bool check(VI &xs, int n) {
    for (int i = 0; i < n; i++) {
        if (xs[OFFSET + i] == 0) {
            return false;
        }
    }
    return true;
}

int main(void) {
    cin >> N >> W >> H;
    VI xs(N), ys(N), ws(N);
    for (int i = 0; i < N; i++) {
        cin >> xs[i] >> ys[i] >> ws[i];
    }

    VI rows(400000), cols(400000);
    for (int i = 0; i < N; i++) {
        rows[OFFSET + ys[i] - ws[i]]++;
        rows[OFFSET + ys[i] + ws[i]]--;
        cols[OFFSET + xs[i] - ws[i]]++;
        cols[OFFSET + xs[i] + ws[i]]--;
    }

    VI sum_rows = calc_csum(rows);
    VI sum_cols = calc_csum(cols);

    cout << (check(sum_rows, H) || check(sum_cols, W) ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 8388
import sys, math
from functools import lru_cache
from collections import defaultdict
from decimal import Decimal
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    s, t = input(), input()

    for i in range(N):
        if s[i:] == t[:N-i]:
            print(N+i)
            return
    print(2*N)

if __name__ == '__main__':
    main()


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

int main()
{
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); ++i)
  {
    if (s[i] == '1')
      s[i] = '9';
    else if (s[i] == '9')
      s[i] = '1';
  }
  cout << s << endl;

  return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
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; }

using Lint=long long;

template<typename T> class SlidingBestElement
{
 private:
    vector<T> a,best;
    int N,L;
    deque<int> deq;
    function<bool(T,T)> good;
 public:
    SlidingBestElement(vector<T> a,int L,function<bool(T,T)> good):a(a),N(a.size()),L(L),good(good)
    {
        for(int i=0;i<L;i++) insert(i);
        best.resize(N-L+1);
        for(int i=0;i+L<=N;i++){
            best[i]=a[deq[0]];
            if(deq[0]==i) deq.pop_front();
            if(i+L<N) insert(i+L);
        }
    }
    void insert(int i){
        while(!deq.empty() and !good(a[deq.back()],a[i])) deq.pop_back();
        deq.push_back(i);
    }
    T operator[](int i){ return best[i]; }
};

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

    int N,L; cin>>N>>L;
    vector<int> a(N);
    for(int i=0;i<N;i++) cin>>a[i];

    SlidingBestElement<int> best(a,L,[](int a,int b){return a<b;});
    for(int i=0;i+L<=N;i++){
        cout<<best[i]<<(i+L==N? '\n':' ');
    }  
    return 0;
}


Measured memory_bytes: 18448
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

using P = pair<double,double>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
/////////////////

void solve(){
  ini(N , C);
  vvi v(C , vi(100100 , 0));
  rep(i , N){
    ini(s,t,c); c--;
    for(int i = s; i <= t; i++) v[c][i] = 1;
  }
  int ans = 0;
  rep(j,  100010){
    int cur = 0;
    rep(i , C) cur += v[i][j];
    amax(ans , cur);
  }
  out(ans);

}

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

int main(void){
  int N;
  int k = 0;
  cin >> N;
  for(int i = 1; i <= N; i++){
    if(i % 2 != 0)
      k++;
  }
  printf("%.10f", (double)k / N);
  return 0;
}


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

int main() {
  int N;
  cin>>N;
  vector<string> strn(100);
  rep(i,N) cin>>strn[i];
  int M;
  cin>>M;
  vector<string> strt(100);
  rep(i,M) cin>>strt[i];
  int answer=0;
  rep(i,N){
    int num=1;
    rep(j,N-i-1){
      if(strn[i]==strn[j+i+1]) ++num;
    }
    rep(j,M){
      if(strn[i]==strt[j]) --num;
    }
          answer=max(answer,num);
  }
          cout<<answer<<endl;
}

Measured memory_bytes: 256
from collections import deque

def main():
    N, u, v, *AB = map(int, open(0).read().split())

    E = [[] for _ in range(N + 1)]
    for a, b in zip(*[iter(AB)] * 2):
        E[a].append(b)
        E[b].append(a)

    def solve(s):
        D = [-1] * (N + 1)
        D[s] = 0

        Q = deque([s])
        while Q:
            a = Q.popleft()
            for b in E[a]:
                if D[b] != -1:
                    continue
                D[b] = D[a] + 1
                Q.append(b)

        return D[1:]

    T = solve(u)
    A = solve(v)

    print(-1 + max(a for t, a in zip(T, A) if t < a))

main()

Measured memory_bytes: 31732
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); ++i)
#define all(a) (a).begin(),(a).end()

bool is_op(char c){
    return c=='+' || c=='-' || c=='*' || c=='/';
}

int operate(int &e1,int &e2,char &op){
    if(op == '+') return e1+e2;
    if(op == '-') return e1-e2;
    if(op == '*') return e1*e2;
    if(op == '/') return e1/e2;
    assert(false);
}

set<int> calc(vector<set<int>> Es, vector<char> &ops, vector<int> &perm){
    int n = perm.size();
    if(n == 0){
        return Es[0];
    }
    vector<bool> done(n);
    rep(i,n){
        int p = perm[i];
        set<int> E;
        char op = ops[p];
        for(int e1 : Es[p]){
            for(int e2 : Es[p+1]){
                if(op == '/' && e2 == 0) continue;
                E.insert(operate(e1,e2,op));
            }
        }
        done[p] = true;
        Es[p] = E;
        Es[p+1] = E;
        int l = p-1, r = p+1;
        while(l>=0 && done[l]){
            Es[l] = E;
            l--;
        }
        while(r<n && done[r]){
            Es[r+1] = E;
            r++;
        }
    }
    return Es[0];
}

set<int> all_check(vector<set<int>> &Es, vector<char> &ops){
    int n = ops.size();
    vector<int> perm(n);
    rep(i,n){
        perm[i] = i;
    }

    set<int> res;
    do{
        set<int> tmp = calc(Es,ops,perm);
        for(int t : tmp){
            res.insert(t);
        }
    }while(next_permutation(all(perm)));
    return res;
}


set<int> eval(string &s, int &i){
    vector<set<int>> Es;
    vector<char> ops;
    while(1){
        if(isdigit(s[i])){
            set<int> res;
            int num = 0;
            while(isdigit(s[i])){
                num = num*10 + s[i]-'0';
                i++;
            }
            res.insert(num);
            Es.push_back(res);
        }else if(s[i] == '('){
            i++; // (
            Es.push_back(eval(s,i));
            i++; // )
        }

        if(i == (int)s.size()) break;
        if(is_op(s[i])){
            ops.push_back(s[i]);
            i++;
        }else{
            break;
        }
    }
    return all_check(Es,ops);

}

int main(){
    string s;
    while(cin>>s, s!="#"){
        int index = 0;
        cout<<eval(s, index).size()<<endl;
    }
    return 0;
}


Measured memory_bytes: 3208
import java.util.Arrays;
import java.util.Scanner;

//Educational DP Contest / DP まとめコンテスト
//B - Frog 2
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		int h[] = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = Integer.parseInt(sc.next());
		}
		sc.close();

		int[] dp = new int[N + 2];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0] = 0;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < K; j++) {
				if (i - j >= 1) {
					dp[i] = Math.min(dp[i], dp[i - j - 1] + Math.abs(h[i - j - 1] - h[i]));
				}
			}
		}

		System.out.println(dp[N - 1]);
	}
}


Measured memory_bytes: 48920
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)

string animals(string res, int& N, string& S){
    for(int i=1;i<N-1;i++){
        if(res[i] == 'S'){
            if(S[i] == 'o'){
                if(res[i-1] == 'S') res += 'S';
                else res += 'W';
            }
            else {
                if(res[i-1] == 'S') res += 'W';
                else res += 'S';
            }
        }
        else {
            if(S[i] == 'o'){
                if(res[i-1] == 'S') res += 'W';
                else res += 'S';
            }
            else{
                if(res[i-1] == 'S') res += 'S';
                else res += 'W';
            }
        }
    }

    bool ok = true;
    if(res[0] == 'S'){
        if(S[0] == 'o' && res[N-1] != res[1]) ok = false;
        if(S[0] == 'x' && res[N-1] == res[1]) ok = false;
    }
    else {
        if(S[0] == 'o' && res[N-1] == res[1]) ok = false;
        if(S[0] == 'x' && res[N-1] != res[1]) ok = false;
    }
    for(int i=1;i<N;i++){
        if(res[i] == 'S'){
            if(S[i] == 'o' && res[i-1] != res[(i+1)%N]) ok = false;
            if(S[i] == 'x' && res[i-1] == res[(i+1)%N]) ok = false;
        }
        else {
            if(S[i] == 'o' && res[i-1] == res[(i+1)%N]) ok = false;
            if(S[i] == 'x' && res[i-1] != res[(i+1)%N]) ok = false;
        }
    }

    //cout << res << endl;

    if(!ok) return "-1";
    return res;
}

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

    string ans = "-1";

    if(ans == "-1") ans = animals("SS",N,S);
    if(ans == "-1") ans = animals("SW",N,S);
    if(ans == "-1") ans = animals("WS",N,S);
    if(ans == "-1") ans = animals("WW",N,S);

    cout << ans << endl;

}


Measured memory_bytes: 740
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int dp[6011];
int mem[6011];
bool act[6011];
string solve(const string &s) {
    int n = s.size();

    if (s[0] == 'a') {
	memset(dp, 0, sizeof (int) * (n+1));

	for (int i=0, j=0; i<n && j<n;) {
	    while (s[i] != 'a') i++;
	    while (s[j] != 'b') j++;
	    mem[i] = j;
	    i++;
	    j++;
	}

	int ma = 0;
	REP (i, n) {
	    if (s[i] == 'a') {
		dp[mem[i]] = ma + 1;
	    } else {
		amax(ma, dp[i]);
	    }
	}

	string ret;
	REP (i, ma) {
	    ret.push_back('a');
	    ret.push_back('b');
	}
	return ret;
    }

    for (int i=0, j=0; i<n && j<n;) {
	while (s[i] != 'b') i++;
	while (s[j] != 'a') j++;
	mem[i] = j;
	i++;
	j++;
    }

    string ret;
    REP (i, n) if (s[i] == 'b') {
	string tmp;
	int ma = mem[i];
	memset(act, 0, sizeof (bool) * (n+1));
	for (int j=i; j<n; j++) {
	    if (s[j] == 'b') {
		if (j < ma) {
		    tmp.push_back('b');
		    ma = mem[j];
		    act[ma] = true;
		}
	    } else {
		if (act[j]) {
		    tmp.push_back('a');
		}
	    }
	}
	amax(ret, tmp);
    }
    return ret;
}

int N, N2;
char S[6011];

void MAIN() {
    scanf("%d%s", &N, S);
    N2 = N+N;

    vector<string> X;
    int sum = 0;
    int prv = 0;
    REP (i, N2) {
	if (S[i] == 'a') sum--;
	else sum++;
	if (sum == 0) {
	    X.push_back(solve(string(S+prv, S+i+1)));

	    prv = i+1;
	}
    }

    string ans;
    for (int i=X.size(); i--;) {
	amax(ans, X[i] + ans);
    }

    puts(ans.c_str());
}

int main() {
    int TC = 1;

    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <vector>

using namespace std;

using ll = long long;

ll count(vector<ll>& bit, ll i) {
    i++;
    ll s = 0;
    while (i > 0) {
        if (bit[i] > s) {
            s = bit[i];
        }
        i -= i&(-i);
    }
    return s;
}

void update(vector<ll>& bit, ll i, ll v) {
    i++;
    while (i < bit.size()) {
        if (v > bit[i]) {
            bit[i] = v;
        }
        i += i&(-i);
    }
}

int main() {
    int n;
	scanf("%d", &n);
    
    vector<ll> dp(n+1), bit(n+2);
    
	vector<ll> h(n), a(n);
	
	for (int i=0; i<n; ++i) {
		scanf("%d", &h[i]);
	}

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

	for (int i=0; i<n; ++i) {
	    ll tmp = count(bit, h[i]) + a[i];
	   // cout << tmp << " "<< count(bit, h[i]) << '\n';
	    if (tmp > dp[h[i]]) {
	        dp[h[i]] = tmp;
	    }
	    update(bit, h[i], dp[h[i]]);
	}
	ll ans = 0;
	for(int i=0; i<=n; i++) {
		if (dp[i] > ans) {
			ans = dp[i];
		}
	}
	printf("%lld\n", ans);

}

Measured memory_bytes: 9572
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>

#define ll long long int

using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int n;
  ll ans=1;
  int i;
  cin>>n;

  for(i=n;i>1;i--)
    ans*=i;
  cout<<ans<<endl;

}

Measured memory_bytes: 1152
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 61
#define MAX 1LL << 30
#define MOD 1000000007
typedef long long ll;
//typedef pair<ll,ll> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

int C[110000],P[110000];

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

    int N,M;
    cin>>N>>M;
    for(int i=0;i<M;i++){
        int p;
        string s;
        cin>>p>>s;
        if(s=="AC"){
            C[p]++;
        }else{
            if(C[p]==0) P[p]++;
        }
    }
    int ans=0,count=0;
    for(int i=0;i<=N;i++){
        if(C[i]){
            ans++;
            count+=P[i];
        }
    }
    cout<<ans<<" "<<count<<endl;

}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};
/*
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_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 || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
*/

int main(){
    int x,y,z,k; cin >> x >> y >> z >> k;
    vector<ll> a(x),b(y),c(z),d(0),e(0);
    ll sum = 0,cnt = 0;
    for (int i = 0; i < x; i++) cin >> a[i];
    for (int i = 0; i < y; i++) cin >> b[i];
    for (int i = 0; i < z; i++) cin >> c[i];
    sort(a.begin(),a.end()); reverse(a.begin(),a.end());
    sort(b.begin(),b.end()); reverse(b.begin(),b.end());
    sort(c.begin(),c.end()); reverse(c.begin(),c.end());

    for (int i = 0; i < x; i++){
        for (int j = 0; j < y; j++){
            d.push_back(a[i]+b[j]);
        }
    }
    sort(d.begin(),d.end()); reverse(d.begin(),d.end());
    for (int i = 0; i < min(k,x*y); i++){
        for (int j = 0; j < y; j++){
            e.push_back(d[i]+c[j]);
        }
    }
    sort(e.begin(),e.end()); reverse(e.begin(),e.end());
    for (int i = 0; i < k; i++){
        cout << e[i] << endl;
    }
}

Measured memory_bytes: 43368
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>

#define P 1000000007

using namespace std;

class Counting {
	unsigned long long p, n;
	vector<long long> invMemo, facMemo, facInvMemo;
public:
	Counting(unsigned long long nn, unsigned long long np) {
		p = np;
		n = nn;
		invMemo.resize(n + 1);
		facMemo.resize(n + 1);
		facInvMemo.resize(n + 1);
		facMemo[0] = 1;
		facMemo[1] = 1;
		facInvMemo[0] = 1;
		facInvMemo[1] = 1;
		invMemo[0] = 0;
		invMemo[1] = 1;
		for (unsigned long long i = 2; i <= n; i++) {
			invMemo[i] = p - (p / i)*invMemo[p%i] % p;
			facMemo[i] = (facMemo[i - 1] * i) % p;
			facInvMemo[i] = (facInvMemo[i - 1] * invMemo[i]) % p;
		}
	}
	unsigned long long fac(unsigned long long k) {
		return facMemo[k];
	}
	unsigned long long facInv(unsigned long long k) {
		return facInvMemo[k];
	}
	unsigned long long choose(unsigned long long n, unsigned long long k) {
		if (!(0 <= k && k <= n))
			return 0;
		return (((facMemo[n] * facInvMemo[k]) % p)*facMemo[n - k]) % p;
	}
	unsigned long long divide(unsigned long long a, unsigned long long b) {
		return (a * invMemo[b]) % p;
	}
	unsigned long long mod(unsigned long long a) {
		a %= p;
		if (a < 0) a += p;
		return a;
	}
	unsigned long long power(unsigned long long a, unsigned long long e) {
		unsigned long long ans = 1;
		for (; e > 0; e /= 2) {
			if (e % 2 != 0)
				ans = ans * a % p;
			a = a*a%p;
		}
		return ans;
	}
};

long long combmemo[51][51] = { {} };

long long comb(int n, int k) {
	if (combmemo[n][k] > 0) {
		return combmemo[n][k];
	}
	if (k == 0 || k == n) {
		combmemo[n][k] = 1;
		return 1;
	}
	combmemo[n][k] = comb(n-1, k) + comb(n -1, k -1);
	return combmemo[n][k];
}

int main() {
	int n, p;
	cin >> n >> p;
	vector<int> a;
	a.resize(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int odd = 0, even = 0;
	for (int i = 0; i < n; i++)
		if (a[i] % 2 == 0)
			even++;
		else
			odd++;
	long long ans = 1;

	if (p == 0) {
		ans = 0;
		for (int i = 0; i <= even; i++) {
			ans += comb(even, i);
		}
		long long b = 0;
		for (int i = 0; i <= odd / 2; i++) {
			b += comb(odd, 2 * i);
		}
		ans *= b;
	}
	else {
		long long b = 0;
		for (int i = 0; i <= even; i++) {
			b += comb(even, i);
		}
		ans = 0;
		for (int i = 1; i <= odd; i += 2) {
			ans += comb(odd, i);
		}
		ans *= b;
	}
	cout << ans << endl;
	//cin >> n;
	return 0;
}


Measured memory_bytes: 256
# include "iostream"
# include "cstdio"
# include "algorithm"

using namespace std;

long long N, X;

long long GCD(long long x,long long y){
	return y==0?x:GCD(y,x%y);
}

int main() {
	scanf("%lld%lld",&N,&X);
	printf("%lld\n",3ll*(N-GCD(N, X)));
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int number = scan.nextInt();
		for(int i = 1; i<=number; i++){
			int x = i;
			if(x%3==0){
				System.out.print(" "+i);
			}else if(x % 10 == 3){
				System.out.print(" "+i);
			}else{
				while(true){
				if(x%10==3){
					System.out.print(" "+i);
					break;
			}
			x = x/10;
			if(x==0){
				break;
			}
			}
			}
		}
		System.out.println();
		}
	}

Measured memory_bytes: 28348
#include<iostream>
#include<vector>
using namespace std;
vector<int> v(100001);
int searching(int j,int n){
  while(j<n-1&&v[j]==v[j+1]){
    j++;
  }if(v[j]<=v[j+1]){
    return 1;
  }else{
    return 0;
  }
}
int main(){
  int n,ans=1,flag;
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>v[i];

  flag=searching(0,n);
  for(int i=0;i<n-1;i++){
    if(flag==1){
      if(v[i]>v[i+1]){
	ans++;
	flag=searching(i+1,n);
      }
    }else{
      if(v[i]<v[i+1]){
	ans++;
	flag=searching(i+1,n);
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 640
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		String S = I.next();
		boolean valid=false;
		int N = S.length();
		if (S.equals("keyence")) valid=true;
		else {
			if (S.charAt(0)!='k'&&S.substring(N-7,N).equals("keyence")) valid=true;
			else if (S.charAt(N-1)!='e'&&S.substring(0,7).equals("keyence")) valid=true;
			else if (S.charAt(0)=='k'&&S.substring(N-6,N).equals("keyence")) valid=true;
			else if (S.substring(0,2).equals("ke")&&S.substring(N-5,N).equals("yence")) valid=true;
			else if (S.substring(0,3).equals("key")&&S.substring(N-4,N).equals("ence")) valid=true;
			else if (S.substring(0,4).equals("keye")&&S.substring(N-3,N).equals("nce")) valid=true;
			else if (S.substring(0,5).equals("keyen")&&S.substring(N-2,N).equals("ce")) valid=true;
			else if (S.substring(0,6).equals("keyenc")&&S.substring(N-1,N).equals("e")) valid=true;
		}
		O.pln(valid?"YES":"NO");
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
}

Measured memory_bytes: 25592
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
dic = defaultdict(int)
for a in A:
    dic[a] += 1

ans = 0
for k, v in dic.items():
    if k != v:
        if k < v:
            ans += v-k
        else:
            ans += v
print(ans)

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

int main()
{
    char num[4];

    cin >> num;

    if(((num[0] == '0' && num[1] != '0') || (num[0] == '1' && (num[1] == '0' || num[1] == '1' || num[1] == '2'))) && ((num[2] == '0' && num[3] != '0') || (num[2] == '1' && (num[3] == '0' || num[3] == '1' || num[3] == '2')))){
        cout << "AMBIGUOUS" << endl;
    }else if((num[0] == '0' && num[1] != '0') || (num[0] == '1' && (num[1] == '0' || num[1] == '1' || num[1] == '2'))){
        cout << "MMYY" << endl;
    }else if((num[2] == '0' && num[3] != '0') || (num[2] == '1' && (num[3] == '0' || num[3] == '1' || num[3] == '2'))){
        cout << "YYMM" << endl;
    }else{
        cout << "NA" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

int main()
{
    int m[50],f[50],r[50];
    int i = 0,j=0;

    for (;;) {
        std::cin >> m[i] >> f[i] >> r[i];
        if ((m[i] == -1) && (f[i] == -1) && (r[i] == -1)) {
            break;
        }
        i++;
    }

    for (j = 0; j < i; j++) {
        if ((m[j] == -1) || (f[j] == -1)) {
            std::cout << "F" << std::endl;
        }
        else if ((m[j] + f[j]) >= 80) {
            std::cout << "A" << std::endl;
        }
        else if ((m[j] + f[j]) >= 65) {
            std::cout << "B" << std::endl;
        }
        else if ((m[j] + f[j]) >= 50) {
            std::cout << "C" << std::endl;
        }
        else if ((m[j] + f[j]) >= 30) {
            if (r[j]>= 50) {
                std::cout << "C" << std::endl;
            }
            else {
                std::cout << "D" << std::endl;
            }
        }
        else {
            std::cout << "F" << std::endl;
        }
    }
       return 0;
}


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

int main() {
    int n;
    cin >> n;
    double sum = 0;
    rep(i,n) {
        double x;
        string u;
        cin >> x >> u;
        if (u == "JPY") sum += x;
        else sum += x * 380000.0;
    }
    printf("%.10f",sum);
}

Measured memory_bytes: 256
s = raw_input()
while True:
    # print s
    if s == "":
        print 'YES'
        break
    elif s[-5:] == "dream" or s[-5:] ==  "erase":
        s = s[:-5]
    elif s[-7:] == "dreamer":
        s = s[:-7]
    elif s[-6:] == "eraser":
        s = s[:-6]
    else:
        print "NO"
        break



Measured memory_bytes: 2820
#include <cstdio>

int main() {
	int H1, M1, H2, M2, K;
	scanf("%d%d%d%d%d", &H1, &M1, &H2, &M2, &K);
	printf("%d\n", (H2 - H1) * 60 + M2 - M1 - K);
	return 0;
}

Measured memory_bytes: 1728
using System;
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        int[] T = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int M = int.Parse(Console.ReadLine());
        int[][] PX = new int[M][].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();
        int tsum = T.Sum();
        for (int i = 0; i < M; i++)
        {
            Console.WriteLine(tsum - T[PX[i][0] - 1] + PX[i][1]);
        }
    }
}

Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER
//ABC 149, task c, 2020/06/27
//ms,
/*
*/

int main(void){
  int X;
  vector<int> sieve(4*100000);
  int index = 1;

  cin >>X;
  for(int i=0;i<=2*X;i++) sieve[i]=1;
  sieve[0]=0;
  sieve[1]=0;

  while(index<sqrt(2.0*X)){
    if(sieve[index]){
      int i=1;
      while(index*i<2*X) {
        sieve[index*i]=0;
        i++;
      }
    }
    index++;
  }

  for(int i=X;i<2*X;i++){
    if(sieve[i]) {
      cout <<i;
      break;
    }
  }

  return 0;
}
/*
エラトステネスして下から見ていけばよし。
素数の存在性。どのくらい大きいところまでやればいいの？？
ベルトランの仮説で二倍まででいい。計算資源的にもいけそう。
*/


Measured memory_bytes: 4648
<?php
error_reporting(0);
//$A = explode(" ",trim(fgets(STDIN)));
list($N,$M) = explode(" ",trim(fgets(STDIN)));
//頂点フラグ
$used = new SplFixedArray($N);
//接続状態を保存する
$connected = new SplFixedArray($N);
//初期化
for($i=0;$i<$N;$i++) {
  $used[$i]=0;
  //接続状態はconnected[頂点数=N][頂点数=N]
  $connected[$i]=new SplFixedArray($N);
  for($j=0;$j<$N;$j++) {
    $connected[$i][$j]=0;
  }
}
for($i=0;$i<$M;$i++) {
  list($P1[],$P2[]) = explode(" ",trim(fgets(STDIN)));
}
$ret=0;
for($i=0;$i<$M;$i++) {
  $used=array_fill(0,$N,0);
  for($j=0;$j<$M;$j++) {
    if ($j==$i) {
      $connected[$P1[$j]-1][$P2[$j]-1] = 0;
      $connected[$P2[$j]-1][$P1[$j]-1] = 0;
      continue;
    }
    $connected[$P1[$j]-1][$P2[$j]-1] = 1;
    $connected[$P2[$j]-1][$P1[$j]-1] = 1;
  }
  dfs(0);
  $v=0;
  foreach($used as $u) {
    $v+=$u;
  }
  if ($v!=$N) {
    $ret++;
  }
}
printf("%d\n",$ret);

function dfs($now) {
  global $used,$connected,$M,$N;
  if ($used[$now]==1) return 0;
  $used[$now]=1;
  for($i=0;$i<$N;$i++) {
    if ($connected[$now][$i]) {
      dfs($i);
    }
  }
}


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

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

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

    if(a == 0 && b == 0){
        cout << a << " " << b << endl;
        return 0;
    }

    if(a <= k) {
        b = b - (k - a);
        if(b < 0) b = 0;
        a = 0;
    }else{
        a = a - k;
    }

    cout << a << " " << b << endl;
}

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

#define INF 2147483600
#define long long long // for codeforces

int main(){
  int n;
  cin>>n;
  vector<string> vec(n);
  rep(i,n) cin>>vec[i];
  string t;
  cin>>t;
  vector<string> s(vec);
  for(auto &str : s) replace(all(str), '?', 'a');
  for(auto &str : vec) replace(all(str), '?', 'z');

  int bf=0,af=0;
  rep(i,n){
    if(t>=s[i]) bf++;
    if(t<=vec[i]) af++;
  }

  // n-af ~ bf+1 まで
  for(int i=n-af+1; i<bf+1; i++) cout<<i<<" ";
  cout<<bf+1<<endl;

  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <math.h>
#include <cmath>
#include <iomanip>


using namespace std;

//-------------------------------------------------------------------------------------
/*2点[(x1,y1),(x2,y2)]を入力し二点を通る直線ax+by+cの(a,b,c)を返す,  */
/*x1==x2ならfalseを返す*/
/*falseならばx=cの形の直線*/
void straight_line_passing_through_the_two_points(double x1, double y1, double x2, double y2, double *a, double *b, double *c){
    *a=(y2-y1);
    *b=-(x2-x1);
    *c=y2*(x2-x1)-x2*(y2-y1);
}

//-------------------------------------------------------------------------------------
/*(x,y)を通るa1x+b1y+c1=0に垂直な直線a2x+b2y+c2=0を返す*/
void vertical_straight_line(double x, double y, double a1, double b1, double c1, double *a2, double *b2, double *c2){
    *a2 = -b1;
    *b2 = a1;
    *c2 = b1*x - a1*y;
}


//-------------------------------------------------------------------------------------
/*2直線 a1x+b1y+c1=0 a2x+b2y+c2=0 の交点 (x,y)を返す*/
/*2直線が平行であるならばfalseを返す*/
bool intersection_and_parallel(double a1, double b1, double c1, double a2, double b2, double c2, double *x, double *y){
    if(a1*b2==a2*b1)return false;//平行の判定
    
    *x = (b1*c2-b2*c1)/(a1*b2-a2*b1);
    *y = (a2*c1-a1*c2)/(a1*b2-a2*b1);
    
    return true;
}

//-------------------------------------------------------------------------------------
/* 
 a1x+b1y+c1=0 と　a2x+b2y+c2=0 が
 平行なら2
 直交なら1
 それ以外は0
 を返す
 */
int judges_whether_parallel_or_perpendicular(double a1, double b1, double c1, double a2, double b2, double c2){
    if(a1*b2 == a2*b1)return 2;
    if(a1*a2 + b1*b2 == 0)return 1;
    return 0;
}


//-------------------------------------------------------------------------------------
/*直線ax+by+c=0に対し　(x1,y1)と線対称な位置(x2,y2)を出力*/
/*vertical_straight_lineを使用*/
/*intersection_and_parallelを使用*/
void line_symmetry(double a, double b, double c, double x1, double y1, double *x2, double *y2){
    //垂直な直線を求める
    double a2,b2,c2;
    vertical_straight_line(x1, y1, a, b, c, &a2, &b2, &c2);
    
    //垂直な直線との交点を求める
    double c_x, c_y;
    intersection_and_parallel(a, b, c, a2, b2, c2, &c_x, &c_y);
    *x2 = x1 + 2*(c_x-x1);
    *y2 = y1 + 2*(c_y-y1);
}



//-------------------------------------------------------------------------------------
/*2点(x1,y1), (x2,y2) の距離*/
double distance_between_the_two_pointss(double x1,double y1, double x2, double y2){
    return  sqrt(fabs((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}


//-------------------------------------------------------------------------------------
/* (x1,y1)から(x2,y2)へ伸ばした直線の角度を求める  */
double angle_of_the_line(double x1, double y1, double x2, double y2){
    return atan2(y2-y1, x2-x1);
}



int main(int argc, const char * argv[]){
    int q;
    cin>>q;
    for(int i=0; i<q; i++){
        double x1,x2,x3,x4,y1,y2,y3,y4;
        cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
        double a1,b1,c1,a2,b2,c2;
        straight_line_passing_through_the_two_points(x1, y1, x2, y2, &a1, &b1, &c1);
        straight_line_passing_through_the_two_points(x3, y3, x4, y4, &a2, &b2, &c2);
        int ans = judges_whether_parallel_or_perpendicular(a1, b1, c1, a2, b2, c2);
        cout<<ans<<endl;
        
        
    }
}

Measured memory_bytes: 1228