akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<bits/stdc++.h>
#include<array>
using namespace std;
#define int long long
#define fast_cin ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define endl "\n"
#define with_tests int t; cin >> t; while(t--){ solve(); cout << endl; }
#define without_tests solve(); cout << endl;
#define CEIL(x, y) (ll)ceil((long double)(x)/(long double)(y))
#define epsilon 1e-9 
typedef long long ll;
const int mod = 1e9+7;
const int N = 1e3+1;

// vector<int> adj[N];
// int vis[N];
// int dp[N];
// int n, u, v;

// // int dp[N][N];

// int dfs(int u){

//     if(vis[u] == 1){
//         return dp[u];
//     }
//     vis[u] = 1;
//     for(int v: adj[u]){
//         dp[u] = max(dp[u], dfs(v)+1);
//     }
//     return dp[u];
// }

char a[N][N];
int dp[N][N];

void solve(){
    
    int h, w;
    cin >> h >> w;
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            cin >> a[i][j];
        }
    }
    dp[h][w] = 1;
    for(int i=h-1; i>=1; i--){
        dp[i][w] = (a[i][w] == '#')? 0: dp[i+1][w];
    }
    for(int i=w-1; i>=1; i--){
        dp[h][i] = (a[h][i] == '#')? 0: dp[h][i+1];
    }

    for(int i=h-1; i > 0; i--){
        for(int j=w-1; j > 0; j--){
            dp[i][j] = (a[i][j] == '#')? 0: (dp[i+1][j] + dp[i][j+1])%mod;
        }
    }
    cout << dp[1][1];

}

int32_t main(){

    fast_cin;
    // with_tests;
    without_tests;

    return 0;
}


Measured memory_bytes: 12304
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,i,s=0,ans=0;
	cin>>a>>b;
	int L[a+1];
	L[0]=0;
	for(i=1;i<=a;i++)  cin>>L[i];
	i=0;
	while(1)
	{
		if(i>a)  break;
		s+=L[i];
		if(s<=b)  ans++;
		else      break;
		i++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int N;
    cin >>N;
    cout<<N*800-(N/15)*200<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast","unroll-loops")
#pragma GCC target("avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i)
#define iter(it,c) for (__typeof((c).begin()) \
  it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = ~(1<<31);

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
  return (a % b + b) % b; }

int n;
vi h;
int memo[100050];
int k;

int dp(int at){
    if(memo[at] != -1) return memo[at];
    if(at == n-1) return 0;
    int ans = dp(at + 1) + abs(h[at] - h[at + 1]);
    for (int i = at + 1; i <= at + k; i++){
        if (i < n) ans = min(ans, dp(i) + abs(h[at] - h[i]));
        //if (n - at - 1 > 1) ans = min(ans, dp(at + 2) + abs(h[at] - h[at + 2]));
    }
    
    return memo[at] = ans;
}

int main(){
    cin >> n >> k;
    h = vi(n);
    memset(memo, -1, sizeof(memo));
    for (int i = 0; i < n; ++i){
        cin >> h[i];
    }
    cout << dp(0) << endl;
    return 0;
}

Measured memory_bytes: 7296
fun main(args: Array<String>) {

    val list = readLine()!!.split(" ").map { it.toInt() }
    val numList = readLine()!!.split(" ").map { it.toInt() }

    var okashi = list[1]
    var counter = 0
//    numList.sorted() mutableListじゃないとオブジェクト自体はソートされない。sortedの場合は戻り値のリストがソートされる
    // toMutableListでワンライナーで書こうとしたが、toMutableList自体が戻り値を必要としていることに・・・
//    numList.toMutableList().sort()
    val sortedNumList = numList.sorted()
 
    for ((index, value) in sortedNumList.withIndex())

    // おかし大きいかつ最後じゃない || おかし一致
    // おかし小さいは不足
        if (okashi < value)
        // カウントしない
        else if (okashi > value && index != sortedNumList.size - 1 || okashi == value) {
            // LOOK 最後のオブジェクトのプログラムがスッと出てこない
            counter += 1
            okashi -= value
        }

    println(counter)
}

Measured memory_bytes: 36008
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    string s;
    cin >> s;
    cout << ((s[2] == s[3] and s[4] == s[5]) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		final Scanner sc = new Scanner(System.in);
		String key=sc.nextLine().toLowerCase();
		int count = 0;
		while(true){
			String[] str=sc.nextLine().split(" ");
			if(str[0].equals("END_OF_TEXT")) break;
			for(String s:str){
				s=s.toLowerCase();
				if(s.equals(key)) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 17160
#include<stdio.h>
#define GridSize 3 
int main(void)
{
	//変数を定義。
	int c[GridSize][GridSize];
	int flag = 0;
 
	//3×3のグリッドを入力。
	for (int i = 0; i < GridSize; i++) {
		scanf("%d %d %d\n", &c[i][0], &c[i][1], &c[i][2]);
	}
 
	/*表の上の数値から下の数値を引いた値がそれぞれ等しいと条件が満たされる。
	  例えば、c[0][0] - c[1][0] と c[0][1] - c[1][1]の差が等しい。*/
	for (int j = 0; j < GridSize - 1; j++) {
		for (int k = 0; k < GridSize - 1; k++) {
			if (c[j][k] - c[j + 1][k] != c[j][k + 1] - c[j + 1][k + 1]) {
				printf("No\n");
                return 0;
			}
		}
	}
		printf("Yes\n");
		
		return 0;
}

Measured memory_bytes: 128
from itertools import product

H, W = map(int, input().split())

a = [ list(map(int, input().split())) for _ in range(H) ]

output = ''
direction = -1
idou = 0
last_i = 0
last_j = 0
count = 0
j = -1
for i in range(H):
    direction *= -1
    j += direction
    for _ in range(W):
        if idou == 1:
            count += 1
            output += '{} {} {} {}\n'.format(last_i+1, last_j+1, i+1, j+1)
        if (a[i][j] + idou) % 2 == 1:
            idou = 1
        else:
            idou = 0
        last_i = i
        last_j = j
        j += direction

output = str(count) + '\n' + output.strip()
print(output)


Measured memory_bytes: 11168
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int X = sc.nextInt();
   int Y = sc.nextInt();
   int Z = sc.nextInt();
   X -=Y+2*Z;
   System.out.println(1+X/(Y+Z));
 }
}

Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int MAX_N = 150;
template<class Type> class Queue
{
    private:
        struct Node { Type num; Node *back; };
        Node *head, *tail;
        int sz;
    public:
        Queue() { head = tail = new Node; sz = 0; }
        void push(Type x)
        {
            Node *n = new Node;
            n->num = x;
            tail->back = n; tail = n;
            if(empty()) head = tail; sz++;
        }
        Type pop()
        {
            Type res = head->num;
            Node *_head = head;
            head = head->back;
            delete _head; sz--;
            return res;
        }
        Type front() { if(not empty()) return head->num; }
        bool empty() { return sz == 0; }
};
int Gragh[MAX_N][MAX_N];
int used[MAX_N];
void bfs(int u, int n)
{
    used[u] = 0;
    Queue<int> que;
    que.push(u);
    while(!que.empty())
    {
        int u = que.front(); que.pop();
        for(int v = 1; v <= n; v++)
        {
            if(Gragh[u][v] == -1 || used[v] != -1) continue;
            used[v] = used[u] + 1;
            que.push(v);
        } 
    }
}
void init(int n)
{
    for(int i = 0; i <= n; i++)
    {
        used[i] = -1;
        for(int j = 0; j <= n; j++) Gragh[i][j] = -1;
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    init(n);
    for(int i = 0; i < n; i++)
    {
        int u, k; cin >> u >> k;
        for(int j = 0; j < k; j++)
        {
            int v; cin >> v;
            Gragh[u][v] = 1;
        }
    }
    bfs(1, n);
    for(int u = 1; u <= n; u++) cout << u << " " << used[u] << endl;
    return 0;
}




Measured memory_bytes: 3176
def main():
    S = input()
    n = len(S) - 1

    ans = 0

    for i in range(2 ** n):
        ops = [""] * (n + 1)
        for j in range(n):
            if (i >> j) & 1:
                ops[j] = "+"

        fomula = ""
        for num, op in zip(S, ops):
            fomula += num + op

        ans += eval(fomula)

    print(ans)


if __name__ == "__main__":
    main()


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

int a, b, c, d;

int main(){
    scanf("%d %d %d %d", &a, &b, &c, &d);
    if(b <= c){
        puts("0");
    } else if(d <= a){
        puts("0");
    } else {
        printf("%d\n", min(b,d) - max(a,c));
    }
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
using namespace std;
int main(void){
    char s[101];
    scanf("%s",s);
    int n = strlen(s);
    int flag = 0;
    for(int i=1;i<=n;i++){
        if(i%2 == 0){
            if(s[i-1] == 'R'){
                flag = 1;
                break;
            }
        } else if(i%2 == 1){
            if(s[i-1] == 'L'){
                flag = 1;
                break;
            }
        }
    }
    
    if(flag == 1) printf("No\n");
    else printf("Yes\n");
    
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
const int INF = 1<<28;
const ll MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

struct point {
	double x, y, z;
};

double dis(point p1 , point p2) {
	double x = (p1.x - p2.x) * (p1.x - p2.x);
	double y = (p1.y - p2.y) * (p1.y - p2.y);
	double z = (p1.z - p2.z) * (p1.z - p2.z);
	return sqrt(x + y + z);
}

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

	int n; cin >> n;
	REP(_, n) {
		double qr, rp, pq;
		cin >> qr >> rp >> pq;
		int m; cin >> m;
		vector<point> v(m);
		REP(i, m)
			cin >> v[i].x >> v[i].y >> v[i].z;
		REP(i, m) {
			REP(j, m) {
				if(i == j)
					continue;
				double a = dis(v[i], v[j]);
				double rate = a / pq;
				REP(k, m) {
					if(i == k || j == k)
						continue;
					double b = dis(v[j], v[k]);
					double c = dis(v[k], v[i]);
					if(abs(rate - b / qr) < 1e-3 && abs(rate - c / rp) < 1e-3) {
						cout << i+1 << ' ' << j+1 << ' ' << k+1 << endl;
					}
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1244
#include <stdio.h>
#include <string.h>
#define MAX 2000000
#define INFTY (1<<30)
int H,A[MAX+1];

void maxHeapify(int i){
    int l,r,largest,temp;
    l=2*i;
    r=2*i+1;

    if(l<=H && A[l]>A[i])
        largest=l;
    else
        largest=i;
    if(r <= H && A[r] > A[largest])
        largest=r;

    if(largest != i){
        temp=A[i];
        A[i]=A[largest];
        A[largest]=temp;
        maxHeapify(largest);
    }
}
int extract(void){
    int maxv;
    if(H<1)
        return -INFTY;
    maxv=A[1];
    A[1]=A[H--];
    maxHeapify(1);
    return maxv;
}
void increaseKey(int i,int key){
    int temp;
    if(key < A[i])
        return;
    A[i]=key;
    while(i > 1 && A[i/2]<A[i]){
        temp=A[i];
        A[i]=A[i/2];
        A[i/2]=temp;
        i=i/2;
    }
}
void insert(int key){
    H++;
    A[H]=-INFTY;
    increaseKey(H,key);
}
int main(void){
    int key;
    char com[10];
    while(1){
        scanf("%s",com);
        if(!strcmp(com,"end"))
            break;
        if(!strcmp(com,"insert")){
            scanf("%d",&key);
            insert(key);
        }
        else
            printf("%d\n",extract());
    }
    return 0;
}

Measured memory_bytes: 4696
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(j,n) for(int j = 0; j < (n); ++j)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define drep2(j,n) for(int j = (n)-1; j >= 0; --j)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define srep2(j,s,t) for (int j = s; j < t; ++j)
#define srep3(k,s,t) for (int k = s; k < t; ++k)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N,K;
  cin >> N >> K;
  if(N > K) {
    double ans = 0;
    srep(i,1,K) {
      int x = 0;
      while(x + log2(i) < log2(K)) {
        x++;
      }
      ans += 1 / pow(2,x);
    }
    srep(i,K,N+1) {
      ans += 1;
    }
    cout << setprecision(20) << ans / N << endl;
  } else {
    double ans = 0;
    srep(i,1,N+1) {
      int x = 0;
      while(x + log2(i) < log2(K)) {
        x++;
      }
      ans += 1 / pow(2,x);
    }
    cout << setprecision(20) << ans / N << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (500000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

class e{
public:
  ll a, b;
  e() {a = b = -1;}
  e(ll u, ll v) {a = u; b = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> &V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

vector<ll> fact(MAX, 0), fact_inv(MAX, 0);

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

void prepare_comb_mod(ll n){
	fact[0] = 1LL;
	for(ll i = 0; i < n; i++) fact[i+1] = fact[i] * (i + 1) % MOD;
	fact_inv[n] = pow_mod(fact[n], MOD - 2);
	for(ll i = n - 1; i >= 0; i--) fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
}

ll comb_mod(ll n, ll r){
	return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD;
}

/////////////////////////////////////////////////////////

void Main() {
  int N; cin >> N;
  vector<int> P(N);
  rep(i, 0, N) cin >> P[i];
  int res = 0;
  rep(i, 0, N){
    if(i != N - 1){
      if(P[i] == i + 1){
        swap(P[i], P[i + 1]);
        res++;
      }
    }else{
      if(P[i] == i + 1){
        swap(P[i - 1], P[i]);
        res++;
      }
    }
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 8448
/**
 *      purpose : ABC 51 D
 *      author  : kyomukyomupurin
 *      created : 
**/

#include <iostream>
#include <algorithm>
using namespace std;
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

const int INF = 1e8;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, m; cin >> n >> m;
    int a[m], b[m], c[m];
    rep(i, m) {
        cin >> a[i] >> b[i] >> c[i];
        --a[i]; --b[i];
    }

    int dis[n + 5][n + 5];  // dist[i][j] : shortest distance from vertex 'i' to vertex 'j'

    rep(i, n + 5){
        rep(j, n + 5){
            if (i == j) dis[i][j] = 0;
            else dis[i][j] = INF;
        }
    }

    rep(i, m){
        dis[a[i]][b[i]] = min(dis[a[i]][b[i]], c[i]);
        dis[b[i]][a[i]] = min(dis[b[i]][a[i]], c[i]);
    }

    rep(k, n){
        rep(i, n){
            rep(j, n){
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
            }
        }
    }

    int ans = m;

    rep(i, m){
        bool shortest = false;
        rep(j, n){
            if (dis[j][a[i]] + c[i] == dis[j][b[i]]) shortest = true;
        }
        if (shortest) --ans;
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int n, a[200010];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a, a + n);
  for (int i = 0; i < n - 1; i++) {
    if (a[i] == a[i + 1]) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
}

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

int main(){
    int a,b,c,d,e;
    cin >> a >> b >> c >> d >> e;
    if(a==0){
        cout << "1" << endl;
    }else if(b==0){
        cout << "2" << endl;
    }else if(c==0){
        cout << "3" << endl;
    }else if(d==0){
        cout << "4" << endl;
    }else if(e==0){
        cout << "5" << endl;
    }
}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
#define fst first
#define snd second
#define fr(i, a, b) for(int i=a; i<b; i++)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
int n;
vector<int> l;
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    cin >> n;
    for(int i=0; i<n; i++) {
        int t; cin >> t; l.push_back(t);
    }
    sort(l.begin(), l.end());
    int res = 0;
    for(int i=0; i<n; i++) {
        for(int j=i+1; j<n; j++) {
            auto it = lower_bound(l.begin(), l.end(), l[i]+l[j]);
            res += it - l.begin() - j -1;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 384
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	vvi in(n,vi(2));
	rep(i,n){
		if(i){
			char c;cin>>c;
			in[i][1]=c=='-';
		}
		cin>>in[i][0];
	}
	vvi dp(n+1,vi(3,-inf));
	dp[0][0]=0;
	rep(i,n)rep(j,3)if(dp[i][j]!=-inf){
		int s=in[i][0];
		if(in[i][1])s*=-1;
		if(j==1)s*=-1;
		dp[i+1][j]=max(dp[i+1][j],dp[i][j]+s);
		if(j<2&&in[i][1])dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+s);
		if(j)dp[i+1][j-1]=max(dp[i+1][j-1],dp[i][j]+s);
		if(j>1)dp[i+1][j-2]=max(dp[i+1][j-2],dp[i][j]+s);
	}
	
	cout<<dp[n][0]<<endl;
}








Measured memory_bytes: 11136
from math import sqrt
M = 10**6
p = [1 for i in range(M+1)]
p[0] = 0
p[1] = 0
for x in range(2, int(sqrt(M))+1):
    if p[x]:
        for y in range(x*x, M+1, x):
            p[y] = 0

a = [0 for i in range(M+1)]
for i in range(M):
    if i%2 != 0 and p[i] and p[(i+1)//2]:
        a[i] = 1

ans = [0 for i in range(M)]
for i in range(1, M):
    ans[i] = ans[i-1] + a[i]

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(ans[r] - ans[l-1])

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

int main(){
	int a, b, c;
	cin >> a >> b >> c;

	if((a == 5 && b == 5 && c == 7) || (a == 5 && b == 7 && c == 5) || (a == 7 && b == 5 && c == 5))	cout << "YES\n";
	else	cout << "NO\n";

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

const mod = 1e9 + 7

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	var n int
	fmt.Scan(&n)
	var a, b []int
	for i := 0; i <= n; i++ {
		var t int
		fmt.Scan(&t)
		a = append(a, t)
	}
	for i := 0; i < n; i++ {
		var t int
		fmt.Scan(&t)
		b = append(b, t)
	}
	r := 0
	for i := 0; i < n; i++ {
		t := min(a[i], b[i])
		r += t
		b[i] -= t
		u := min(a[i+1], b[i])
		r += u
		a[i+1] -= u
	}
	fmt.Println(r)
}


Measured memory_bytes: 6144
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class A
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		var A = GetInts(N);
		Array.Sort(A);

		int Q = GetInt();
		var M = GetInts(Q);

		var ans = new string[Q];
		for(int i = 0; i < Q; i++)
		{
			bool flag = false;
			for(int s = 0, E = (1 << N); s < E; s++)
			{
				int S = 0;
				for(int j = 0; j < N; j++)
				{
					if(contains(s, j))
					{
						S += A[j];
						if(S >= M[i])
							break;
					}
				}

				if(S == M[i])
				{
					flag = true;
					break;
				}
			}
			ans[i] = flag ? "yes" : "no";
		}
		WriteLine(string.Join("\n", ans));
	}

	private bool contains(int s, int x) => ((s >> x) & 1) == 1;
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}


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

int main(){
    int a, b; cin >> a >> b;
    int cnt = 0;
    int tap = 1;
    while(tap < b){
        cnt++;
        tap += a-1;
    }
    cout << cnt << endl;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<string>> S(H, vector<string>(W));
  for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> S[i][j];

  char ans1 = 'A';
  int ans2 = 1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == "snuke") {
        ans1 += j;
        ans2 += i;
      }
    }
  }

  cout << ans1 << ans2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define INF 10000
#define MAXV 45

int dist[MAXV][MAXV];

int main(void){
	int n;

	while(1){
		int town=0;

		cin >> n;
		if(n==0)break;

		memset(dist,INF,sizeof(int)*MAXV*MAXV);
		for(int i=0; i<n; i++){
			int from,to,cost;
			cin >> from >> to >> cost;
			dist[from][to] = cost;
			dist[to][from] = cost;
			town = max(town,max(to,from));
		}
		town++;

		for(int i=0; i<town; i++)
			dist[i][i] = 0;
		
		for(int k=0; k<town; k++)
			for(int i=0; i<town; i++)
				for(int j=0; j<town; j++)
					dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);

		/*
		for(int i=0; i<town; i++){
			for(int j=0; j<town; j++){
				printf("%3d",dist[i][j]);
			}
			printf("\n");
		}
		*/
		
		int mincost=INF;
		int mintown;
		for(int i=0; i<town; i++){
			int cost=0;
			for(int j=0; j<town; j++)
				cost += dist[i][j];
			if(mincost>cost){
				mincost = cost;
				mintown = i;
			}
		}

		cout << mintown << " " << mincost << endl;
	}

	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

struct S {
    ll x, y, z;
};

const int N = 1005;
int n, m;
ll ans;
S a[N];
ll cont[N];

void solve(int t1, int t2, int t3) {
    for (int i = 0; i < n; ++i) {
        ll c = 0;
        c += t1 ? -a[i].x : a[i].x;
        c += t2 ? -a[i].y : a[i].y;
        c += t3 ? -a[i].z : a[i].z;
        cont[i] = c;
    }
    sort(cont, cont + n, greater<ll>());
    ll sum = 0;
    for (int i = 0; i < m; ++i) {
        sum += cont[i];
    }
    ans = max(ans, sum);
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> a[i].x >> a[i].y >> a[i].z;
    }
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 2; ++j) {
            for (int k = 0; k < 2; ++k) {
                solve(i, j, k);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	int ans = 0;
	for (int i = 1; i < n - 1 && i < n - i; i++) ans++;
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
int main() {
	var(int, x, y);
	print(x + y / 2);
	return 0;
}


Measured memory_bytes: 256
""" B
"""
import sys
import math
from functools import reduce
from bisect import bisect_left

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def readStringSet(n):
    return sys.stdin.readline().split(" ")[:n]

def readIntegerSet(n):
    return list(map(int, readStringSet(n)))

def readIntegerMatrix(n, m):
    return [readIntegerSet(m) for _ in range(0, n)]

def main(N, D):
    count = 0
    for d in D:
        if d[0] == d[1]:
            count += 1
            if count == 3:
                return "Yes"
        else:
            count = 0

    return "No"


if __name__ == "__main__":
    _N = readInteger()
    _D = readIntegerMatrix(_N, 2)

    print(main(_N, _D))


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



int main() {
    int k;
    cin >> k;
    vector<int> s={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << s[k-1] << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var AB = ReadSplitLong();
            Println(Lcm(AB[0], AB[1]));
        }

        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static void YESOrNO(bool e) => Println(e ? "YES" : "NO");

        static void YesOrNo(bool e) => Println(e ? "Yes" : "No");

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());
        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}



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

int main() {
  ll n,min_p=200050,ans=0;
  cin>>n;
  vector<ll> p(n);
  rep(i,n){
    cin>>p[i];
    if(min_p>p[i]){
      ans++;
      min_p=p[i];
    }
  }
  cout<<ans<<endl;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[200005];
bool T[200005];

int main() {
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }
    memset(T, 0, sizeof(T));
    ll index = 0;
    REP(i, N) {
        if (A[i] == index + 1) {
            T[index] = true;
            index++;
        }
    }

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

Measured memory_bytes: 2048
#!/usr/bin/env pypy3


import collections

INF = 10 ** 8


def solve_by_bfs(abc0):
    dist = collections.defaultdict(lambda: INF)
    dist[abc0] = 0
    q = collections.deque()
    q.append(abc0)
    while q:
        abc1 = q.popleft()
        if abc1[0] == abc1[1] == abc1[2]:
            return dist[abc1]
        a, b, c = abc1
        cands = [(a + 1, b + 1, c),
                 (a, b + 1, c + 1),
                 (a + 1, b, c + 1),
                 (a + 2, b, c),
                 (a, b + 2, c),
                 (a, b, c + 2)]
        for abc in cands:
            if dist[abc] >= INF:
                dist[abc] = dist[abc1] + 1
                q.append(abc)


def main():
    abc0 = tuple(int(x) for x in input().split())
    res = solve_by_bfs(abc0)
    print(res)


if __name__ == '__main__':
    main()


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

public class Main {
    private void solve() {
        int n = sc.nextInt();
        List<int[]> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int[] p = new int[2];
            p[0] = sc.nextInt();
            p[1] = i;
            a.add(p);
        }
        a.sort((x, y) -> y[0] - x[0]);

        long[][] dp = new long[n][n + 1];

        for (int i = 0; i < n; i++) {
            int[] p = a.get(i);
            int m = i + 1;
            dp[i][0] = (i == 0 ? 0 : dp[i - 1][0]) + (long) p[0] * (n - m - p[1]);
            dp[i][m] = (i == 0 ? 0 : dp[i - 1][m - 1]) + (long) p[0] * (p[1] - i);
        }

        for (int i = 1; i < n; i++) {
            int[] p = a.get(i);
            int m = i + 1;
            for (int l = 0; l <= m; l++) {
                if (l > 0) {
                    dp[i][l] = Math.max(dp[i][l], dp[i - 1][l - 1] + (long) p[0] * (p[1] - (l - 1)));
                }

                if (l < m) {
                    dp[i][l] = Math.max(dp[i][l], dp[i - 1][l] + (long) p[0] * (n - (m - l) - p[1]));
                }
            }
        }

        long ans = 0;
        for (int l = 0; l <= n; l++) {
            ans = Math.max(ans, dp[n - 1][l]);
        }
        out.println(ans);
    }

    private static PrintWriter out;
    private static MyScanner sc;

    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        private MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                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());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        out = new PrintWriter(new BufferedOutputStream(System.out));
        sc = new MyScanner();
        new Main().solve();
        out.close();
    }
}


Measured memory_bytes: 83344
import collections as cl

N = int(input())
a = [""]*N
for i in range(N):
    a[i] = "".join(sorted(list(input())))

b = list(cl.Counter(a).values())

ans = 0
for x in b:
    tmp = x * (x-1) // 2
    ans += tmp
print(ans)    

Measured memory_bytes: 19724
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define REP(i, n) for(int i=0; i<(n); i++)
#define REPS(i, n) for(int i=0; i<=(n); i++)
#define FOR(i, a, b) for(int i=a; i<(b); i++)
#define FORS(i, a, b) for(int i=a; i<=(b); i++)
// for container x
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#pragma endregion

int main(){
    ll a, b, v, w, t;
    cin >> a >> v >> b >> w >> t;
    string yes = "YES";
    string no = "NO";
    if (v <= w) {
        cout << no << endl;
        return 0;
    }
    if (b > a) {
        if ((a+t*v) >= (b+t*w)){
            cout << yes << endl;
            return 0;
        }
        else {
            cout << no << endl;
            return 0;
        }
    }
    else {
        if ((a-t*v) <= (b-t*w)){
            cout << yes << endl;
            return 0;
        }
        else {
            cout << no << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3660
from collections import Counter
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)


def judge(x):
    y = k
    for i in range(n):
        goal = x//f[i]
        if a[i] > goal:
            y -= a[i] - goal
            if y < 0:
                return False
    return y >= 0


left = -1
right = 10**12 + 1
while left + 1 < right:
    mid = (left + right)//2
    if judge(mid):
        right = mid
    else:
        left = mid

print(right)


Measured memory_bytes: 114852
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp88 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long N = st[0];
            long Q = st[1];
            string S = Console.ReadLine();

            var l = new long[Q];
            var r = new long[Q];

            for (long i = 0; i < Q; i++) {
                var x = Console.ReadLine().Split().Select(long.Parse).ToArray();
                l[i] = x[0];
                r[i] = x[1];
            }

            //V[i]:i項目までにある、ACの個数
            var V = new long[N];
            V[0] = 0;

            for (int i = 1; i < N; i++) {
                if (S[i - 1] == 'A' && S[i] == 'C') {
                    V[i] = V[i - 1] + 1;
                } else {
                    V[i] = V[i - 1];
                }
            }

            //Console.WriteLine(string.Join(" ", V));

            long ans = 0;

            for (int i = 0; i < Q; i++) {
                ans = V[r[i] - 1] - V[l[i] - 1];
                Console.WriteLine(ans);
            }
        }
    }
}

Measured memory_bytes: 20408
// abc055_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    string s;
    cin >> s;
    s += s[0];

    bool possible = false;
    string ans;
    REP(p, 4){
        vector<bool> cand(N+2);

        cand[0] = p / 2;
        cand[1] = p % 2;

        REPN(i, 2, N+2){
            // i-1が羊かつ発言がo もしくは 狼かつx だったら、i-2と同じ
            if (cand[i-1] == (s[i-1] == 'o')){
                cand[i] = cand[i-2];
            } else {
                cand[i] = not cand[i-2];
            }
        }

        if (cand[0] == cand[N] && cand[1] == cand[N+1]){
            possible = true;
            REP(i, N){
                ans += cand[i] ? 'S' : 'W';
            }
            break;
        }
    }

    if (possible){
        print(ans);
    } else {
        print(-1);
    }


    return 0;
}


Measured memory_bytes: 720
n = int(input())


def getNameFromNumber(num):
    amari = (num - 1) % 26
    char = chr(97 + amari)
    div = (num - 1) // 26
    if div > 0:
        return getNameFromNumber(div) + char
    else:
        return char


print(getNameFromNumber(n))


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  string s;cin>>s;
  int i,j;
  if(s.size()==26)
  {
    bool ok=false;
    vector<char> suf(0);
    suf.emplace_back(s[25]);
    for(i=24;i>=0;i--)
    {
      if(s[i]<s[i+1])
      {
        char k=s[i+1];
        rep(j,suf.size())
        {
          if(suf[j]>s[i]&&suf[j]<k)
          {
            k=suf[j];
          }
        }
        cout<<s.substr(0,i)<<k<<endl;
        ok=true;
        break;
      }
      suf.emplace_back(s[i]);
    }
    if(!ok)cout<<-1<<endl;
  }
  else
  {
    char c;
    for(c='a';c<='z';c++)
    {
      bool used=false;
      rep(i,s.size())
      {
        if(s[i]==c)used=true;
      }
      if(used)continue;
      cout<<s<<c<<endl;
      break;
    }
  }
}


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

using namespace std;

int main () {
  string s;
  cin >> s;

  int delc = 0, pref = 0;
  for (char c : s) {
    if (c == 'S') pref++;
    else {
      if (pref > 0) {
        pref--;
        delc += 2;
      }
    }
  }

  cout << (int) s.size() - delc << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef std::pair<int, int> int_pair;
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }


int main() {
	int n = 0, m = 0;
	int a = 0, b = 0;
	int now_search = 0;
	ll p = 0, q = 0;	
	ll ans = 0, i = 0;
	int_pair drinks[100000] = {};
	cin >> n >> m;

	rep(i, n) {
		cin >> a >> b;
		drinks[i] = make_pair(a, b);
	}

	sort(drinks, drinks+ n);


	while (i < m) {
	
		p = drinks[now_search].first;
		q = drinks[now_search].second;

		if (i + drinks[now_search].second <= m) {
			i += drinks[now_search].second;

			ans += p * q;
		}
		else {
			ans += (m - i) * p;
			i = m;
		}

		now_search++;

	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

const int MAX = 50;
int data[MAX][MAX];
int w,h;

int x[8] = {1,0,-1,0,1,-1,-1,1};
int y[8] = {0,1,0,-1,1,-1,1,-1};

void dfs(int i, int j){
  data[i][j] = 0;
  for(int k = 0; k < 8; k++){
    int ni = i+y[k], nj = j+x[k];
    if(ni < 0 || ni>= h || nj < 0 || nj>= w) continue;
    if(data[ni][nj]) dfs(ni,nj);
  }
}

int main(){

  while(cin >> w >> h && w+h){
    int ans = 0;
    for(int i = 0; i < h; i++)
      for(int j = 0; j < w; j++) cin >> data[i][j];

    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	if(data[i][j]){
	  dfs(i,j);
	  ans++;
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
mod = 10**9+7
rng = 2000100
fctr = [1]+[0]*(rng-1)
for i in range(1,rng):
  fctr[i] = fctr[i-1]*i%mod
def finv(x):
  return pow(fctr[x],mod-2,mod)
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv(n-k)*finv(k)%mod

x1,y1,x2,y2 = map(int,input().split())
print((cmb(x2+y2+2,x2+1)-cmb(x2+y1+1,y1)-cmb(x1+y2+1,x1)+cmb(x1+y1,x1))%mod)

Measured memory_bytes: 71664
import sys
input = sys.stdin.readline
from itertools import combinations

def readlines(n):
    for _ in range(n):
        yield list(map(int,input().split()))

def bene(me, f, p):
    a = len([0 for m in me if f[m] == 1])
    return p[a]

def main():
    n = int(input())
    F = list(readlines(n))
    P = list(readlines(n))

    for i in range(1, 11):
        for comb in combinations(range(10), i):
            yield sum(bene(comb, f, p) for f, p in zip(F,P))

    
print(max(main()))

Measured memory_bytes: 3064
# include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int N = 200005;
# define INF 1000000001
# define MOD 1000000007
# define pb push_back
# define mp make_pair
typedef pair<int, int> Pi;


int main ()
{
    int h, w, n;
    cin >> h >> w >> n;
    h = max(h, w);
    cout << (n+h-1)/h << endl;
    return 0;
}


Measured memory_bytes: 256