akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);
  if(a[0]==5 && a[1]==5 && a[2]==7)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <atcoder/mincostflow>
using namespace std;
using namespace atcoder;
vector<int> dy = {1, 0};
vector<int> dx = {0, 1};
int main(){
  int N, M;
  cin >> N >> M;
  vector<string> S(N);
  for (int i = 0; i < N; i++){
    cin >> S[i];
  }
  int cnt = 0;
  vector<int> yp, xp;
  for (int i = 0; i < N; i++){
    for (int j = 0; j < M; j++){
      if (S[i][j] == 'o'){
        cnt++;
        yp.push_back(i);
        xp.push_back(j);
      }
    }
  }
  int V = N * M + cnt + 2;
  mcf_graph<int, int> G(V);
  int MAX = N + M - 2;
  for (int i = 0; i < cnt; i++){
    G.add_edge(0, i + 1, 1, 0);
  }
  for (int i = cnt + 1; i < cnt + 1 + N * M; i++){
    G.add_edge(i, V - 1, 1, 0);
  }
  for (int i = 0; i < cnt; i++){
    vector<vector<int>> d(N, vector<int>(M, -1));
    d[yp[i]][xp[i]] = 0;
    G.add_edge(i + 1, cnt + 1 + yp[i] * M + xp[i], 1, MAX);
    queue<pair<int, int>> Q;
    Q.push(make_pair(yp[i], xp[i]));
    while (!Q.empty()){
      int y = Q.front().first;
      int x = Q.front().second;
      Q.pop();
      for (int j = 0; j < 2; j++){
        int y2 = y + dy[j];
        int x2 = x + dx[j];
        if (y2 < N && x2 < M){
          if (d[y2][x2] == -1 && S[y2][x2] != '#'){
            d[y2][x2] = d[y][x] + 1;
            G.add_edge(i + 1, cnt + 1 + y2 * M + x2, 1, MAX - d[y2][x2]);
            Q.push(make_pair(y2, x2));
          }
        }
      }
    }
  }
  cout << MAX * cnt - G.flow(0, V - 1).second << endl;
}

Measured memory_bytes: 7124
#include <iostream>
using namespace std;
int main() {
    int A, B;
    cin >> A >> B;
    if(A == B)
        cout << "Draw";
    else if(A == 1)
        cout << "Alice";
    else if(B == 1)
        cout << "Bob";
    else if(A > B)
        cout << "Alice";
    else
        cout << "Bob";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

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


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

int main(){
    int i, j, s, m[50], f[50], r[50];
    i = 0;
    j = 0;
    
    while(1){
        cin >> m[i] >> f[i] >> r[i];
        if((m[i] == -1) && (f[i] == -1) && (r[i] == -1)) break;
        i++;
    }
    
    while(j < i){
        if((m[j] == -1) || (f[j] == -1)){
            cout << "F" << endl;
        }
        else{
            s = m[j] + f[j];
            if(s >= 80){
                cout << "A" << endl;
            }
            else if((65 <= s) && (s < 80)){
                cout << "B" << endl;
            }
            else if((50 <= s) && (s < 65)){
                cout << "C" << endl;
            }
            else if((30 <= s) && (s < 50)){
                if(r[j] >= 50){
                    cout << "C" << endl;
                }
                else{
                    cout << "D" << endl;
                }
            }
            else if(s < 30){
                cout << "F" << endl;
            }
        }
        j++;
    }
    
    return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)                                                         

using namespace std;
#define ll long long

int main(){
  int X;
  cin >> X;
  int ret = 1;
  for(int i=2; i<ceil(sqrt(X)); i++){
    int tmp = i;
    while(tmp * i <= X)
      tmp *= i;
    if(ret < tmp)
      ret = tmp;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        string[] cin = Console.ReadLine().Split();
        int N = int.Parse(cin[0]);
        int T = int.Parse(cin[1]);
        List<int> t = Console.ReadLine().Split().Select(i => int.Parse(i)).ToList();

        long ans = T;

        for (int i = 0; i < N - 1; i++)
        {
            ans += Math.Min(t[i + 1] - t[i], T);
        }

        Console.WriteLine(ans);
    }
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

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

const int mod = 1000000007;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,a,b;
  cin >> n >> a >> b;
  string s;
  cin >> s;
  ll ca = 0,cb = 0;
  rep(i,s.size()){
    if(s[i] == 'a' && ca+cb < a+b){
      ++ca;
      cout << "Yes" << endl;
    }
    else if(s[i] =='b' && ca+cb<a+b && cb < b){
      ++cb;
      cout << "Yes" << endl;
    }
    else
      cout << "No"<< endl;
  }
  return 0;
}



Measured memory_bytes: 976
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;



int main(void) {
  int n;
  cin >> n;
  vpii a(n-1);
  vi b(n-1);
  rep(i,n-1){
    int p,q,r;
    cin >> p >> q >> r;
    a[i] = make_pair(p,r);
    b[i] = q;
  }
  vi ans(n);
  rep(j,n){
  vi dp(1000,0);
  dp[0] = 0;
  
  rep2(i,j,n-1){
    if(dp[i]<=b[i]) dp[i+1] = b[i]+a[i].first;
    else {
      if(dp[i]%a[i].second!=0)dp[i+1] = dp[i]+a[i].second-(dp[i]%a[i].second)+a[i].first;
      else dp[i+1] = dp[i]+a[i].first;
    }
  }
  ans[j] = dp[n-1];
  }
  rep(i,n){
    cout << ans[i] << endl;
  }
    
}




Measured memory_bytes: 256
N, K = gets.split(' ').map(&:to_i)
R, S, P = gets.split(' ').map(&:to_i)
T = $stdin.read.chomp
# r グー, s チョキ p パー
result = 0
BYTE_R = "r".getbyte(0)
BYTE_S = "s".getbyte(0)
BYTE_X = "!".getbyte(0)
N.times do |i|
  rsp = T.getbyte(i)
  if i < K || rsp != T.getbyte(i-K)
    case rsp
    when BYTE_R
      result += P
    when BYTE_S
      result += R
    else
      result += S
    end
  else
    T.setbyte(i, BYTE_X)
  end
end
puts result

Measured memory_bytes: 2044
#include <stdio.h>

int main(void)
{
        int i;
        char s[100000];

        scanf("%s",s);
        i=1;
        while(s[i-1]!='\0'){
                if(i%2==1)printf("%c",s[i-1]);
                i++;
        }
        printf("\n");
        return 0;
}



Measured memory_bytes: 1700
arr = input().split()
arr = list(map(int,arr))
a = arr[0]
b = arr[1]
c = arr[2]
d = arr[3]


if (abs(b - a) <= d and abs(c - b) <= d) or abs(a-c) <= d:
    print('Yes')
else:
    print('No')


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

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

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

int main(){
  long long A,B;
  cin >> A >> B;
  
  cout << lcm(A,B) << endl;
  

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N;
    cin >>N;
    cout << (N*(N-1))/2 << endl;
    return 0;
}

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

typedef pair<long long, long long> pairll;

set<pairll> determined; 

long long coins(long long N, int A, int B, int C, int D){
    if(N == 0) return 0;
    if(N == 1) return D;

    auto itr = determined.lower_bound(pairll(N, 0));
    if((*itr).first == N)return (*itr).second;

    long long res;
    res = A + D * abs(N-N/2*2) + coins(N/2, A, B, C, D);
    res = min(res, A + D * abs((N+1)/2*2-N) + coins((N+1)/2, A, B, C, D));
    res = min(res, B + D * abs(N-N/3*3) + coins(N/3, A, B, C, D));
    res = min(res, B + D * abs((N+2)/3*3-N) + coins((N+2)/3, A, B, C, D));
    res = min(res, C + D * abs(N-N/5*5) + coins(N/5, A, B, C, D));
    res = min(res, C + D * abs((N+4)/5*5-N) + coins((N+4)/5, A, B, C, D));
    if(res/D >= N){
        res = N*D;
    }
    determined.insert(pairll(N, res));
    return res;
}

int main(void){
    int T, A, B, C, D;
    long long N;
    cin >> T;
    vector<long long> ans;
    for(int i=0; i<T; i++){
        cin >> N >> A >> B >> C >> D;
        determined.clear();
        ans.push_back(coins(N, A, B, C, D));
    }
    
    for(int i=0; i<T; i++){
        cout << ans[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 4464
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
		int ans=0;
		System.out.println((a-b+1)*(a-c+1));
}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LLINF = 9223372036854775807;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int a, b, h; cin >> a >> b >> h;
	cout << (a + b) * h / 2;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1000;
int n, m;
int a[N], b[N];

int main()
{
 //   freopen("in.txt","r",stdin);
    cin>>n;
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    cin>>m;
    for(int i=0;i<m;i++)scanf("%d",&b[i]);
    sort(a, a + n);
    sort(b, b + m);
    int p = 0;
    for(int i=0;i<n;i++) {
        if(a[i] == b[p]) {
            p ++;
            if(p == m)break;
        }
    }
    if(p == m)puts("YES");
    else puts("NO");
    return 0;
}


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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};
int a[112345];
int b[112345];
int main() {
	string s;
	cin >> s;
	const int n = s.size();
	if (s.back() == '1'||s.front()=='0') {
		cout << -1 << endl;
		return 0;
	}
	s = "0" + s;
	for (int i : range(n+1)) {
		if(s[i]!=s[n-i]) {
			cout << -1 << endl;
			return 0;
		}
	}
	int e = 0;
	int r1 = 1;
	int r2 = n;
	for (int i : range(n-1)) {
		const int v = i + 2;
		a[e] = r1;
		b[e] = v;
		e++;
		if (s[i + 1] == '1')r1 = v;
	}
	for (int i : range(n - 1)) {
		cout << a[i] << " " << b[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 2432
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;

int main() {
  ll dp[101][10];
  memset(dp,0,sizeof(dp));
  int H,W,K; cin >> H >> W >> K;
  dp[0][0] = 1;

  for ( int i = 0; i < H; i++ ) {
    for ( int j = 0; j < W; j++ ) {
      for ( int bit = 0; bit < (1 << W-1); bit++ ) {
	bool ok = true;
	for ( int l = 0; l < W-2; l++ ) {
	  if ( (bit & ( 1 << l)) && (bit & (1<<l+1)) ) {
	    ok = false;
	  }
	}
	if (ok) {
	  if ( j >= 1 && ( bit & ( 1 << j-1 ))) {
	    dp[i+1][j-1] += dp[i][j];
	    dp[i+1][j-1] %= 1000000007;
	  } else if ( j <= W-2 && ( bit & ( 1 << j ) ) ) {
	    dp[i+1][j+1] += dp[i][j];
	    dp[i+1][j+1] %= 1000000007;
	  } else {
	    dp[i+1][j] += dp[i][j];
	    dp[i+1][j] %= 1000000007;
	  }
	}
      }
    }
  }

  cout << dp[H][K-1] << endl;
  return 0;
}


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

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< pair<int,int> > vpii;
typedef vector< pair<ll,ll> > vpll;
typedef vector< vector<int> > matrix;

#define SET(Ar,val) memset(Ar,val,sizeof(Ar))
#define rep(i,val,n)  for(int i=val;i<n;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LMAX LONG_LONG_MAX
#define LMIN LONG_LONG_MIN
#define IMAX INT_MAX
#define IMIN INT_MIN
#define M 1000000007

/*--------------------------------------------------------------------------------------------------------------------------------*/

template <class T> T modpower(T a,T b,T MOD)
{
    T ans=1;
    while(b!=0)
    {
        if(b%2==1)
        ans=(ans*a)%MOD;
        a=(a*a)%MOD;
        b/=2;
    }
    return ans;
}

void init()
{
    int n,m;
    string s;
    map<string,int> ma;
    cin >> n ;
    rep(i,0,n)
    {
        cin >> s;
        if(ma.find(s)!=ma.end())
        {
            ma[s]++;
        }
        else
            ma[s] = 1;
    }
    cin >> m ;
    rep(i,0,m)
    {
        cin >> s;
        if(ma.find(s) != ma.end())
        {
            ma[s]--;
        }
    }
    int ans = 0;
    for(auto it : ma)
    {
        ans = max(ans,it.se);
    }
    cout << ans ;
}

int main()
{
    clock_t time1=clock();
	/*#ifndef ONLINE_JUDGE
	freopen("abc_091.in","r",stdin);
	#else
	//ONLINE_JUDGE
	#endif*/
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    init();
    clock_t time2 = clock();
    cerr <<"Time: " <<(double)(time2-time1)/CLOCKS_PER_SEC <<" seconds" <<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();
    
    while(true){
      C -= B;
      if(C <= 0){
        System.out.println("Yes");
        break;
      }
      
      A -= D;
      if(A <= 0){
        System.out.println("No");
        break;
      }
    }
    
  }
}

Measured memory_bytes: 35592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll a;cin>>a;
    ll b;cin>>b;
    ll m;cin>>m;
    vector<ll> ref(a);
    For(i,0,a) cin>>ref[i];
    vector<ll> mic(b);
    For(i,0,b) cin>>mic[i];
    ll ma=10000000,mb=10000000;
    For(i,0,a){
        ma=min(ma,ref[i]);
    }
    For(i,0,b){
        mb=min(mb,mic[i]);
    }
    ans=ma+mb;
    For(i,0,m){
        ll x;cin>>x;x--;
        ll y;cin>>y;y--;
        ll c;cin>>c;
        ans=min(ans,ref[x]+mic[y]-c);
    }
    cout<<ans<<endl;
}
int main(){
    Main();
    return 0;
}

Measured memory_bytes: 1792
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
 
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
 
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
 
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
 
    return result
x,y = map(int,input().split())
mod=10**9+7
if (x+y)%3!=0 or x>2*y or y>2*x:
  print('0')
else:
  p=(2*y-x)//3
  q=(2*x-y)//3
  print(cmb(p+q,p)%mod)

Measured memory_bytes: 44148
import java.io.BufferedReader;
        import java.io.InputStreamReader;
        import java.util.Scanner;

public class Main {
    public static void main(String []args)
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);
        float a = sc.nextFloat();
        float b = sc.nextFloat();
        System.out.println(a/b);


    }
}


Measured memory_bytes: 23376
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = A.copy()
k = 0
while k < K and sum(B) < N**2:
  tmp = [0]*N
  i = 0
  while i < N:
    a = B[i]
    tmp[max(0, i-a)] += 1
    if i+a+1 < N:
      tmp[i+a+1] -= 1
    i += 1
  s = 0
  i = 0
  while i < N:
    B[i] = tmp[i]+s
    s = B[i]
    i += 1
  k += 1
print(" ".join([str(b) for b in B]))


Measured memory_bytes: 158636
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

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

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n; cin >> n;
  vl num(n);
  
  rep(i,n){
    ll x; cin >> x;
    num[i] = x;
  }
  
  sort(all(num));
  
  ll cnt = n-2;
  
  ll now = n-2; ll sum = num[n-1];
  while(cnt != 0){
    rep(i,2){
      sum += num[now];
      cnt--;
      if(cnt == 0){
        break;
      }
    }
    now--;
  }
  
  
  cout << sum << endl;
  
  
}

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

int main(void){
	
	int N;
	vector<int> array;
	
	int swap_num;
	
	int tmp;
	
	cin >> N;
	
	for(int i=0;i<N;++i){
		cin >> tmp;
		array.push_back(tmp);
	}
	
	swap_num = 0;
	for(int i=0;i<N;++i){
		for(int j=N-1;i<j;--j){
			if(array[j-1]>array[j]){
				tmp = array[j-1];
				array[j-1] = array[j];
				array[j] = tmp;
				
				swap_num++;
			}
		}
	}
	
	for(int i=0;i<N;++i){
		cout << array[i];
		if(i<N-1){
			cout << " ";
		}
	}
	cout << endl;
	cout << swap_num << endl;
	
	return 0;
}

Measured memory_bytes: 1220
<?php
while (true) {
    $line = trim(fgets(STDIN));
    list($H, $W) = explode(' ', $line);
    if ($W == 0 && $H == 0) {
        break;
    }
    $room = array();
    for ($i = 0; $i < $H; $i++) {
        $room[$i] = trim(fgets(STDIN));
    }
    $visited = array();
    for ($i = 0; $i < $H; $i++) {
        for ($j = 0; $j < $W; $j++) {
            $visited[$i][$j] = false;
        }
    }
    $x = 0; $y = 0;
    $isLoop = false;
    while (true) {
        $line = $room[$y];
        $dir = $line[$x];
        if ($dir == '.') {
            break;
        }
        $visited[$y][$x] = true;
        switch ($dir) {
            case '>':
                $x++;
                break;
            case '<':
                $x--;
                break;
            case 'v':
                $y++;
                break;
            case '^':
                $y--;
                break;
        }
        if ($visited[$y][$x]) {
            $isLoop = true;
            break;
        }
    }
    if ($isLoop) {
        echo "LOOP\n";
    } else {
        echo "$x $y\n"; 
    }
}

 

Measured memory_bytes: 16736
import sys
sys.setrecursionlimit(10 ** 6)
N = int(input())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

dist = [0] * N
def dfs(u, d, p=-1):
    global dist
    dist[u] = d
    for v in edges[u]:
        if v == p:
            continue
        dfs(v, d + 1, u)
    return dist

dist1 = dfs(0, 0, -1)
dist = [0] * N
dist2 = dfs(N - 1, 0, -1)

cnt = 0
for d1, d2 in zip(dist1, dist2):
    if d1 <= d2:
        cnt += 1
if N - cnt < cnt:
    print("Fennec")
else:
    print("Snuke")

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

using namespace std;

int main() {
  int N;
  string S;

  cin >> N;
  cin >> S;

  int num = 0;

  int max = 0;

  for (int i = 0; i < S.length(); i++) {
    if (S[i] == 'I')
      num++;
    else {
      num--;
    }
    max = (num > max) ? num : max;
  }
  cout << max << endl;

  return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector < pair<int,int> > a;
    while(n--)
    {
        long long x,y;
        cin>>x>>y;
        a.push_back(pair<int,int>(x,y));
    }
    sort(a.begin(),a.end());
    for(int j=0;j<a.size();j++)
    {
         cout<<a[j].first<<" "<<a[j].second<<endl;
    }
    return 0;
}



Measured memory_bytes: 3888
#include<bits/stdc++.h>
using namespace std;
int d[30];
char a,b,c;
int main(){
	scanf("%c%c%c",&a,&b,&c);
	d[a-'a']=1;
	d[b-'a']=1;
	d[c-'a']=1;
	if(d[0]&&d[1]&&d[2])printf("Yes");
	else printf("No");
	return 0;
}


Measured memory_bytes: 256
#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

const int maxn = 200005;
int head[maxn], nxt[maxn << 1], to[maxn << 1], hp = 1;

inline void add(int u, int v) {
	nxt[++ hp] = head[u];
	head[u] = hp;
	to[hp] = v;
}

int vis[maxn];
int identy(int u, int c) {
	vis[u] = c;
	if(!head[u]) return 3;

	bool odd = 0;
	for(int i = head[u]; i; i = nxt[i])
		if(vis[to[i]] and vis[to[i]] == c)
			odd = 1;
		else if(!vis[to[i]] and identy(to[i], 3 - c) == 1)
			odd = 1;

	return odd ? 1 : 2;
}

int main() {
	int n = read, m = read;

	for(int i = 1; i <= m; i ++) {
		int u = read, v = read;
		add(u, v);
		add(v, u);
	}

	ll x = 0, y = 0, z = 0;
	for(int i = 1; i <= n; i ++)
		if(!vis[i]) {
			int t = identy(i, 1);
			if(t == 3) ++ z;
			else {
				++ x;
				if(t == 2) ++ y;
			}
		}

	/* debug("%lld %lld %lld\n", x, y, z); */

	printf("%lld\n", x * x + y * y + z * n * 2 - z * z);
}


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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 100010
#define inf 1e9

int main()
{

    ll a, b;
    cin >> a >> b;
    ll c = __gcd(a,b);
    ll ans = (a*b)/c;
    cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int D;
  cin >> D;
  D=25-D;
  cout << "Christmas";
  while(D>0){
    D--;
    cout << " Eve";
  }
  cout << endl;
  return 0;
}

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

static const int maxn=44;

int DP[45];

int Fibonacci(int n) {
  if (n==0 or n==1) {
    return DP[n]=1;
  }
  if (DP[n]!=(-1)) {
    return DP[n];
  }
  return DP[n]=Fibonacci(n-1)+Fibonacci(n-2);
}
int main() {
  std::ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  memset(DP,(-1),sizeof(DP));
  Fibonacci(maxn);
  int n;
  cin>>n;
  cout<<DP[n]<<endl;
  return 0;
}



Measured memory_bytes: 3176
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

def main():
    N, M = mi()
    A = sorted(li())

    '''
    for j in range(M):
        b, c = mi()
        ind = min(bisect.bisect_left(A, c), b)
        A = sorted([c]*ind + A[ind:])
    
    print(sum(A))
    '''
    ab = li2(M)
    ab.sort(key=lambda x: x[1], reverse=True)
    c_list = []
    l = 0
    for b, c in ab:
        if l + b > N:
            c_list += [c]*(N-l)
            l = N
        else:
            c_list += [c]*b
            l += b
        if l == N:
            break
    ans = sum(sorted(A+c_list, reverse=True)[:N])
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 36756
# -*- coding: utf-8 -*-

x = input()

# ペアになっていないSの数（ペアができたら-1）
sc = 0
# ペアにならなかったTの数
tc = 0

for c in x:
    if c == 'S':
        sc += 1
    elif sc >= 1:
        sc -= 1
    else:
        tc += 1

print(sc + tc)


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

#define ll 				long long int
#define gof 			for(long long int i = 0 ; i < n ; i++)
#define for1(i,s,e) 	for(long long int i = s ; i < e ; i++)
#define forr(i,e,s) 	for(long long int i = e ; i >= s; i--)
#define vi 				vector<long long int>
#define all(x) 			x.begin(), x.end()
#define pb(x) 			push_back(x)
#define maxv(x) 		*max_element(x)
#define minv(x) 		*min_element(x)
#define mkvec(type,a,n) vector<type> a(n)

const ll ARR = 1e5;
const ll INF = 1e9;
const ll mod = 1e9+7;

void IO()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}

void solve(){

	int n;
	cin >> n;
	cout << (1000 - n%1000)%1000 << "\n";
	return;

}

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




Measured memory_bytes: 3600
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
  string s;
  cin>>s;
  long long int sum=0;
  for(int i=0;i<s.length();i++)
  {
      sum=sum+(s[i]-'0');
  }
  long long int a=stoi(s);

  if(a%sum==0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;

    return 0;

}










Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted!
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

ll dp[100010];
ll w[110];
ll v[110];
int main(int argc, char const *argv[])
{
    ll n;scanf("%lld",&n);
    ll W;scanf("%lld",&W);
    fill(dp,dp+100010,INT_MAX);
    dp[0] = 0;
    for (int i = 0; i < n; ++i)
    {
        scanf("%lld %lld",&w[i],&v[i]);
        for (int j = 100000 - v[i]; j >= 0;j--)
        {
            dp[j+v[i]] = min(dp[j+v[i]],dp[j] + w[i]);
        }
    }
    int ans = 0;
    for (int i = 0; i < 100010; ++i)
    {
        if(dp[i] <= W)ans = max(ans,i);
    }
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
   int k;
   string s;
   cin >> k >> s;
   int n = s.size();
   if(n <= k){
       cout << s << endl;
   }
   else{
       for(int i=0 ;i<k;i++){
           cout << s[i];
       }
       cout <<"..." << endl;

   }
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<string.h>
 
int main(void)
{
 char str[20],temp;
 int i,l;
 scanf("%s",str);
 l = strlen(str);
 for(i = 0; i < l/2; i++)
 {
  temp = str[i]; 
  str[i] = str[(l-1)-i];
  str[(l-1)-i] = temp;
 }
 printf("%s\n",str);
 return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  ll x; cin >> x;
  for(int a=0; a<1000; a++) {
    for (int b=0; b<1000; b++) {
      ll ans1 = pow(a, 5) - pow(b,5);
      ll ans2 = pow(a, 5) - pow(-b,5);
       if (ans1 == x) {
        printf("%d %d\n", a, b);
        return 0;
      }
      if (ans2 == x) {
        printf("%d %d\n", a, -b);
        return 0;
      }
    }
  }
  return 0;
} 

Measured memory_bytes: 4164
$M=1e9+7;
$O=-1;
<>;
for(<>){
	($a,$b)=split$";
	if($a==0&&$b==0)
	{
		$O++;
	}
	else
	{
		($ga,$gb)=($a,$b);
		($ga,$gb)=($gb,$ga%$gb)while$gb!=0;
		$a/=$ga;$b/=$ga;
		($a,$b)=(-$a,-$b)if$a<0||$a==0&&$b>0;
		$f=0;
		($a,$b,$f)=(-$b,$a,1)if$b<0;
		$_{"$a $b"}[$f]=($_{"$a $b"}[$f]//1)*2%$M;
	}
}
$s=1;
$s=$s*(($_{$_}[0]//1)+($_{$_}[1]//1)-1)%$M for keys%_;
print+($s+$O)%$M,$/;

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

int main() {

    int N, A, B;
    cin >> N >> A >> B;
    N -= 2;
    ll ans = (ll)B*N - (ll)A*N + 1LL;
    cout << (ans >= 0 ? ans : 0) << endl;

}


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

using namespace std;
typedef long long ll;

int main(){
  ll N;
  cin >> N;
  
  ll count = 0;
  for(ll i=1; i<=N; i++){
    if(i % 3 == 0 || i % 5 == 0) continue; 
    count += i;
  }
  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3668
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, T;
    cin >> N >> T;
    vector<ll> t(N);
    REP(i, N) {
        cin >> t[i];
    }
    ll st = t[0], en = t[0] + T;
    ll res = 0;
    FOR(i, 1, N, 1) {
        if (t[i] >= en) {
            res += T;
            st = t[i], en = t[i] + T;
        } else {
            res += t[i] - st;
            st = t[i], en = t[i] + T;
        }
    }
    res += T;
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 1792
n = int(input())
t = list(input().split(" "))
s={}
for i in set(t):
    s[i] = 0
    
for i in t:
    s[i] += 1

# print(s)
# print(s["1"])
for i in range(n):
    if str(i+1) in s:
        # print(i)
        print(s[str(i+1)])
    else:
        print(0)

Measured memory_bytes: 51636
// 2015/07/07 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int N;
		cin >> N;

		if(N==0)
			break;

		int cnt0 = 0;		// 0個残っている景品の数
		int cnt1 = 0;		// 1個残っている景品の数

		for(int i=0; i<N; i++){
			int k;
			cin >> k;

			if(k==0){
				cnt0++;
			}
			else if(k==1){
				cnt1++;
			}
		}

		if(cnt0+cnt1==N){
			cout << "NA" << endl;
		}
		else{
			cout << N-cnt0+1 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include <cstring>
#include <cassert>
#include <utility>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <tuple>
#include <climits>
#include <limits>
#include <deque>
#include <list>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <complex>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll              long long
#define pi              pair<int,int>
#define pll             pair<ll,ll>
#define pb              push_back
#define F               first
#define S               second
#define vi              vector<int>
#define vll             vector<ll>
#define endl            '\n'
#define all(v)          (v).begin(),(v).end()
#define FOR(i,a,b)      for(int i=a;i<b;i++)
#define MP(a,b)         make_pair(a,b)
#define debug(x)        cerr<< #x << " : " << x << endl;
#define debugp(p)       cerr<< #p << " : " << "(" << (p).first << "," << (p).second << ")\n";
#define debugv(v)       cerr<< #v << " : " << "["; for(int i = 0; i < (v).size(); i++) cerr << v[i] << " "; cerr<<"]\n";
#define debugs(m)       cerr<< #m << " : [ "; for(auto itr = m.begin(); itr != m.end(); itr++) cerr <<*itr << " "; cerr << "]\n";
#define debugm(m)       cerr<< #m << " : [ "; for(auto itr = m.begin(); itr != m.end(); itr++) cerr <<"(" << itr->first << "," << itr->second << ") "; cerr << "]\n";

/* ordered set: 
tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
member functions :
1. order_of_key(k) : number of elements strictly lesser than k
2. find_by_order(k) : k-th element in the set
*/

inline ll modexp(ll x, ll ex , ll md) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}

const int inf = 1e9 + 7;

void solve(){
    int n;
    cin >> n;
    vector<int> h(n + 4);
    for (int i = 1; i <= n; i++) cin >> h[i];
    vector<int> dp(n + 3, inf);
    dp[1] = 0;
    for (int i = 1; i <= n; i++){
        dp[i + 1] = min (dp[i + 1] , dp[i] + abs (h[i] - h[i + 1]));
        dp[i + 2] = min (dp[i + 2] , dp[i] + abs (h[i] - h[i + 2]));
    }
    cout << dp[n] << endl;

}
int main(){
    ios :: sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr);
    
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
    #ifdef LOCAL
    cerr << "Time elapsed\t: " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";       
    #endif
}



Measured memory_bytes: 3920
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;

int main()
{
    int n;
    int i, judge = 0;
    
    cin >> n;
    
    char s[n];
    
    for(i = 0; i < n; i++) {
        cin >> s[i];
        if(s[i] == 'Y') {
            judge = 1;
        }
    }
    
    if(judge == 1) {
        cout << "Four\n";
    } else {
        cout << "Three\n";
    }
    
    return 0;
}

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

int n;
long long int a, b;
vector<long long int> x;

int main(void){
  cin >> n >> a >> b;
  for(int i = 0; i < n; i++){
    long long int z;
    cin >> z;
    x.push_back(z);
  }
  long long int sum = 0;
  for(int i = 1; i < n; i++){
    long long int cost = a * (x[i] - x[i - 1]);
    if(cost <= b){
      sum += cost;
    }
    else{
      sum += b;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 1400
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define error(args...) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

bool solve(int N, vector<LL> A) {
    LL one = 0;
    REP(i, N) one += i + 1;

    LL sum = 0;
    REP(i, N) sum += A[i];

    if(sum % one != 0){
        // cerr << "one" << endl;
        return false;
    }

    LL times = sum / one;

    LL s_sum = 0;
    vector<LL> start(N);
    REP(i, N) {
        LL a = A[(i+N-1) % N];
        LL b = A[i];
        LL diff = b - a;
        // k * 1 - (times - k) * (N - 1)
        // (D + T * (N - 1)) / N
        LL X = diff + times * (N - 1);
        LL Y = N;
        if(X % Y != 0){
            // cerr << "two" << endl;
            // error(i, a, b, diff);
            // error(X, Y);
            return false;
        }
        LL k = X / Y;
        LL h = times - k;
        if(!(k >= 0 && k <= times)){
            return false;
        }
        start[i] = h;
        s_sum += h;
    }

    if(s_sum != times){
        // cerr << "three" << endl;
        // error(s_sum, times);
        return false;
    }

    return true; // ?
}
int main(){
    iostream_init();
    while(true) {
        int N;
        cin >> N;
        vector<LL> A(N);
        REP(i, N) cin >> A[i];
        if(cin.eof()) break;
        cout << (solve(N, A) ? "YES" : "NO") << endl;
    }
    return 0;
}



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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){

	int A, B; cin >> A >> B;

	int ans = 0;

	ans += max(A, B);
	if(ans == A) A--;
	else B--;
	ans += max(A, B);

	cout << ans << endl;

	return 0;

}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, x;
	cin >> n >> x;
	vl b(n), l(n), r(n);
	REP(i, n)cin >> b[i] >> l[i] >> r[i];
	ll sum = 0;
	REP(i, n) {
		sum -= b[i] * l[i];
	}
	vector < pll > p(n);
	REP(i, n)p[i] = { (x - b[i]) * r[i] + b[i] * l[i],i };
	sort(ALL(p), greater<>());
	vl a(n + 1, 0);
	REP(i, n)a[i + 1] = a[i] + p[i].first;
	ll ans = INF * INF;
	REP(i, n) {

		ll j = p[i].second;
		{
			ll t = (-sum + l[j] - 1) / l[j];
			if (t <= x)chmin(ans, t);
		}
		ll c = -1, d = n;
		while (d - c > 1) {
			ll mid = (c + d) / 2;
			ll tmp = sum + a[mid + 1];
			if (mid >= i)tmp -= p[i].first;
			ll cnt = mid + 1;
			if (mid >= i)cnt--;
			ll t = (-tmp + l[j] - 1) / l[j];
			if (t <= x)d = mid;
			else c = mid;
		}
		if (d == n)continue;
		ll tmp = sum + a[d + 1];
		if (d >= i)tmp -= p[i].first;
		ll cnt = d + 1;
		if (d >= i)cnt--;
		ll t = (-tmp + l[j] - 1) / l[j];
		if (t < 0)continue;
		if (t <= x)chmin(ans, cnt * x + t);
	
	}
	REP(i, n) {

		ll j = p[i].second;
		{
			ll t = (-(sum + l[j] * b[j] - r[j] * b[j]) + r[j] - 1) / r[j];
			if (t <= x)chmin(ans, t);
		}
		ll c = -1, d = n;
		while (d - c > 1) {
			ll mid = (c + d) / 2;
			ll tmp = sum + a[mid + 1];
			if (mid >= i)tmp -= p[i].first;
			ll cnt = mid + 1;
			if (mid >= i)cnt--;
			ll t = (-(tmp + l[j] * b[j] - r[j] * b[j]) + r[j] - 1) / r[j];
			if (t <= x)d = mid;
			else c = mid;
		}
		if (d == n)continue;
		ll tmp = sum + a[d + 1];
		if (d >= i)tmp -= p[i].first;
		ll cnt = d + 1;
		if (d >= i)cnt--;
		ll t = (-(tmp + l[j] * b[j] - r[j] * b[j]) + r[j] - 1) / r[j];
		if (t < 0)continue;
		if (t <= x)chmin(ans, cnt * x + t);

	}
	
	cout << ans << endl;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define int long long
const int inf=1145141919;
const int mod=1000000007;
const int dd[]={0,-1,0,1,0};
using namespace std;
int a,b,c,d;
int p[100000],q[100000],r[100000];
signed main(){
	int i=0,j=0;
	cin>>a>>b;
	for(i=0;i<a;i++)
		cin>>p[i];
	for(i=0;i<b;i++)
		cin>>q[i];
	int u=0;
	for(i=0;i<a-1;i++){
		u+=(p[i+1]-p[i])*(i+1)*(a-1-i);
		u%=mod;
	}
	int v=0;
	for(i=0;i<b-1;i++){
		v+=(q[i+1]-q[i])*(i+1)*(b-1-i);
		v%=mod;
	}
	cout<<(u*v)%mod<<endl;

}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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 h, w;
int L[2010][2010], R[2010][2010], U[2010][2010], D[2010][2010];

int main() {
    cin >> h >> w;
    vector<string> field(h+2, "");
    rep(i, w+2) {
        field[0] += '#';
        field[h+1] += '#';
    }
    rep(i, h) {
        string s; cin >> s;
        field[i+1] += '#';
        field[i+1] += s;
        field[i+1] += '#';
    }

    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (field[i][j] == '#') L[i][j] = 0;
            else L[i][j] = L[i][j-1] + 1;
        }
    }

    for (int i = 1; i <= h; i++) {
        for (int j = w; j >= 1; j--) {
            if (field[i][j] == '#') R[i][j] = 0;
            else R[i][j] = R[i][j+1] + 1;
        }
    }

    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (field[i][j] == '#') U[i][j] = 0;
            else U[i][j] = U[i-1][j] + 1;
        }
    }

    for (int i = h; i >= 1; i--) {
        for (int j = 1; j <= w; j++) {
            if (field[i][j] == '#') D[i][j] = 0;
            else D[i][j] = D[i+1][j] + 1;
        }
    }

    int ans = 0;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            int tmp = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3;
            chmax(ans, tmp);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 71296