akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

  reverse(s.begin(), s.end());
  vector<string> t = {"maerd", "remaerd", "esare", "resare"};
  int n = s.size(), idx = 0;
  while (idx < n) {
    if (s[idx] == 'r') {
      if (idx >= n - 2 || s[idx + 1] != 'e') {
        cout << "NO" << endl;
        return 0;
      }
      else if (s[idx + 2] == 'm') {
        FOR(i, 3, 7) {
          if (idx + i >= n || s[idx + i] != t[1][i]) {
            cout << "NO" << endl;
            return 0;
          }
        }
        idx += 7;
      }
      else if (s[idx + 2] == 's') {
        FOR(i, 3, 6) {
          if (idx + i >= n || s[idx + i] != t[3][i]) {
            cout << "NO" << endl;
            return 0;
          }
        }
        idx += 6;
      }
      else {
        cout << "NO" << endl;
        return 0;
      }
    }
    else if (s[idx] == 'm') {
      FOR(i, 1, 5) {
        if (idx + i >= n || s[idx + i] != t[0][i]) {
          cout << "NO" << endl;
          return 0;
        }
      }
      idx += 5;
    }
    else if (s[idx] == 'e') {
      FOR(i, 1, 5) {
        if (idx + i >= n || s[idx + i] != t[2][i]) {
          cout << "NO" << endl;
          return 0;
        }
      }
      idx += 5;
    }
    else {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;


  
  return 0;
}

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

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

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

    // start
    int m;
    cin >> m;
    cout << 48 - m << endl;
    // end

    return 0;
}


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

using namespace std;
#define int long long int
int32_t main() {
    
    int d,s,t;
    cin>>d>>t>>s;
    float x=(float)d/(s*1.0);
    if(x<=t)
    cout<<"Yes";
    else
    cout<<"No";
    return 0;
}

Measured memory_bytes: 3632
n = int(input())
w = list(map(int, input().split()))
s = sorted(w)

cost = 0
for i in range(n):
    # 最小の要素と最小の要素の位置に適した要素と交換していく
    now_v = s[i]
    now_idx = w.index(s[i])
    j = 0 # 交換回数
    while now_idx > i:
        j += 1
        target_v = s[now_idx]
        target_idx = w.index(target_v)
        cost += w[target_idx] # ターゲットの方だけ足していく
        w[now_idx], w[target_idx] = w[target_idx], w[now_idx]
        now_idx = target_idx
    # now_v * j: 普通の交換。
    # now_v * 2 + s[0] * (j + 2): 
    #       s[0]は最小値。
    #       最小値と現在値を交換して(コスト: now_v + s[0])、
    #       ソート完了後に(コスト: s[0] * j)
    #       最小値と現在値を元に戻すコスト(コスト: now_v + s[0])。
    #       2回以上ならこっちが少ない。
    cost += min(now_v * j, now_v * 2 + s[0] * (j + 2))
print(cost)



Measured memory_bytes: 5624
#include<iostream>
#include<algorithm>
#include<cstring>
#define INF 1<<28
using namespace std;

int memo[10000];

int solve(int n){

  int res = INF;
  if(!n) return 0;
  if(n < 0) return INF;
  if(memo[n]) return memo[n];

  return memo[n] = res = min(res, min(solve(n-500), min(solve(n-100), min(solve(n-50), min(solve(n-10), min(solve(n-5), solve(n-1)))))) +1);
}

int main(){

  int n;
  while(cin >> n, n){
    memset(memo, 0, sizeof(memo));
    cout << solve(1000-n) << endl;
  }

}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    ll k,a,b;cin>>k>>a>>b;
    if(b-a<=2)return cout<<k+1 , 0;
    ll ans = min(k , a-1) + 1;
    k-=min(k,a-1);
    ans+=(b-a)*(k/2);
    ans+=k%2;
    cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool isprime(int x)
{
	for (int i = 2; i <= sqrt(x); i++)
	{
		if (x % i == 0) return false;
	}
	return true;
}
int main(int argc, char const *argv[])
{

#if !ONLINE_JUDGE

	freopen("in1.txt", "r", stdin);
	freopen("out1.txt", "w" , stdout);

#endif

	int n;
	cin >> n;



	vector<long long>vc(n + 1, 0);
	for (int i = 2; i <= n; i++)
	{
		if (isprime(i))
		{
			vc[i]++;
		}
		else {

			for (int j = 2; j <= i; j++)
			{
				if (isprime(j) and i % j == 0)
				{
					int ct = 0;
					int x = i;
					while (x % j == 0)
					{
						x = x / j;
						ct++;
					}
					vc[j] += ct;

				}
			}



		}
	}

	long long res = 1;


	for (int i = 2; i <= n; i++)
	{
		if (isprime(i))
		{
			res = ((res % 1000000007) * ((vc[i] + 1) % 1000000007)) % 1000000007;
		}
	}

	cout << res << endl;









	return 0;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int H, W;
char G[2001][2001];
int w_sum[2001][2001];
int h_sum[2001][2001];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < W; j++) {
      G[i][j] = s[j];
    }
  }

  for (int i = 0; i < H; i++) {
    vector<int> v;
    int j = 0;
    int cnt = 0;
    while (j < W) {
      if (G[i][j] == '#') {
        if (cnt > 0) {
          v.push_back(cnt);
        }
        v.push_back(0);
        cnt = 0;
      } else {
        cnt++;
      }
      j++;
    }
    if (cnt > 0) {
      v.push_back(cnt);
    }

    j = 0;
    for (auto e : v) {
      if (e == 0) {
        w_sum[i][j] = 0;
        j++;
      } else {
        for (int k = 0; k < e; k++) {
          w_sum[i][j] = e;
          j++;
        }
      }
    }
  }

  for (int i = 0; i < W; i++) {
    vector<int> v;
    int j = 0;
    int cnt = 0;
    while (j < H) {
      if (G[j][i] == '#') {
        if (cnt > 0) {
          v.push_back(cnt);
        }
        v.push_back(0);
        cnt = 0;
      } else {
        cnt++;
      }
      j++;
    }
    if (cnt > 0) {
      v.push_back(cnt);
    }

    j = 0;
    for (auto e : v) {
      if (e == 0) {
        h_sum[j][i] = 0;
        j++;
      } else {
        for (int k = 0; k < e; k++) {
          h_sum[j][i] = e;
          j++;
        }
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (G[i][j] == '.') {
        ans = max(ans, w_sum[i][j] + h_sum[i][j]);
      }
    }
  }

  cout << ans - 1 << endl;
  return 0;
}

Measured memory_bytes: 35456
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      String[] info = new String[n];
      for(int i = 0;i < n;i++){
      	info[i] = sc.next()+"_"+(1100-sc.nextInt())+"_"+(i+1);
      }
      Arrays.sort(info);
      for(int i = 0;i < n;i++){
      	String[] s = info[i].split("_");
        System.out.println(s[2]);
      }
    }
}


Measured memory_bytes: 21716
#include<stdio.h>
#include<string.h>

#define MAX 1000

void conb(char* x,char* y){
  int i,j;
  int x_len=strlen(x);
  int y_len=strlen(y);
  int c[x_len+1][y_len+1];

  for(i=0;i<=x_len;i++){
    for(j=0;j<=y_len;j++){
      c[i][j]=0;
    }
  }
  for(i=1;i<=x_len;i++){
    for(j=1;j<=y_len;j++){
      if( x[i-1] == y[j-1] ){
	c[i][j] = c[i-1][j-1] + 1;
      }else if( c[i-1][j] >= c[i][j-1] ){
	c[i][j] = c[i-1][j];
      }else{
	c[i][j] = c[i][j-1];
      }
    }
  }
  printf("%d\n",c[i-1][j-1]);
}

int main(){
  int n,i;
  char l_1[MAX],l_2[MAX];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",l_1);
    scanf("%s",l_2);
    conb(l_1,l_2);
  }
  return 0;
}

Measured memory_bytes: 4524
#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>;

const int di[] = { 0, 1,-1, 0};
const int dj[] = { 1, 0, 0,-1};
int main() {
	// input
	int h,w;
	cin >> h >> w;
	int si,sj;
	cin >> si >> sj;
	int ti,tj;
	cin >> ti >> tj;
	si--;	sj--;	ti--;	tj--;
	vector<string> s(h);
	rep(i,h) cin >> s[i];
	const int INF = 1e9;
	vector<vector<int>> dist(h, vector<int>(w, INF));
	deque<P> q;
	dist[si][sj] = 0;
	q.emplace_back(si,sj);
	while(!q.empty()) {
		int i = q.front().first;
		int j = q.front().second;
		int d = dist[i][j];
		q.pop_front();
		if (dist[i][j] != d) continue;
		rep(v,4) {
			int ni = i+di[v], nj = j+dj[v];
			if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
			if (s[ni][nj]=='#')	continue;
			if (dist[ni][nj] <= d) continue;
			dist[ni][nj] = d;
			// printf("nx: %d, ny: %d,cost: %d\n",nx,ny,d[ny][nx]);
			q.emplace_front(ni,nj);
		}
		for (int ei = -2; ei <= 2; ++ei) {
			for (int ej = -2; ej <= 2; ++ej) {
				int ni = i+ei, nj = j+ej;
				if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
				// printf("B nx: %d, ny: %d, s: %c\n", nx, ny, s[ny][nx]);
				if (s[ni][nj]=='#') continue;
				if (dist[ni][nj] <= d+1) continue;
				dist[ni][nj] = d+1;
				q.emplace_back(ni,nj);
			}
		}
	}
	int ans = dist[ti][tj];
	if (ans == INF ) ans = -1;
		cout << ans << endl;
	return 0;
}


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

using namespace std;
int a[4][4];
int check(int i)
{
    int b1 = a[0][0] - i , b2 = a[0][1] - i,b3= a[0][2] - i;
    int a2 = a[1][0]-b1 ,  a3 = a[2][0]-b1 ;
    if(a2+b2==a[1][1]&& a2 + b3 == a[1][2] && a3+b2 == a[2][1] && a3+b3 == a[2][2])
    {
        return 1 ;
    }
    return 0 ;
}
int main()
{

    for(int i = 0 ; i< 3; i++)
        for(int j = 0 ; j < 3;j++)
        cin>>a[i][j];
    for(int i = -200 ; i <= 200;i++)
    {
            if(check(i)) {
                cout<<"Yes"<< endl;
                return 0;
            }
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 256
from collections import deque

n = int(input())
graph = [[] for _ in range(n)]
for _ in range(n-1):
    (u, v, w) = map(int, input().split())
    graph[u-1].append([v-1, w])
    graph[v-1].append([u-1, w])


q = deque()
ans = [-1 for _ in range(n)]
q.append(0)
ans[0] = 0
while 0 != len(q):
    v = q.popleft()
    for neigbhor in graph[v]:
        u = neigbhor[0]
        w = neigbhor[1]
        if -1 != ans[u]:
            continue
        ans[u] = (ans[v] + w) % 2
        q.append(u)

for i in ans:
    print(i)


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

ll solve(){
    int n,k;
    cin>>n>>k;
    int ptr[n] ;
    vector<int> dp(n,INT_MAX);
    for(int i=0;i<n;i++) cin>>ptr[i];
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j =i+1; j<=i+k && j<n; j++){
            dp[j]= min(dp[j] , dp[i] + abs(ptr[i] - ptr[j]));
        }
    }
    return dp[n-1];
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--){
        cout<<solve()<<endl;
    }
}



Measured memory_bytes: 3992
n = int(input())
if n%2 == 1:
  x = []
  for i in range(1,n+1):
    for j in range(i+1,n+1):
      if i + j != n:
        x.append((i,j))
  print(len(x))
  for xi in x:
    print(xi[0],xi[1])
else:
  x = []
  for i in range(1,n+1):
    for j in range(i+1,n+1):
      if i + j != n+1:
        x.append((i,j))
  print(len(x))
  for xi in x:
    print(xi[0],xi[1])
  

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a)
        cout<<k<<endl;
    else if(k>a&&k<=(a+b))
        cout<<a<<endl;
    else if(k>(a+b))
        cout<<2*a-k+b<<endl;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		long cnt = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] % 2 == 1) {
				if (i != n - 1 && a[i + 1] > 0) {
					cnt++;
					a[i + 1]--;
					a[i]--;
				}
			}
			cnt += a[i] / 2;
			a[i] = a[i] / 2;
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 50928
n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]

ans = []
for i in range(1, 2**10):
    x = list(map(int, (bin(i)[2:].zfill(10))))
    _ans = 0
    for j in range(n):
        c = sum(map(lambda x, y: x*y, x, f[j]))
        _ans += p[j][c]
    ans.append(_ans)
print(max(ans))


Measured memory_bytes: 3064
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <ostream& out = cout, class... T> void prints(T&&...){ }
template <ostream& out = cout, class... T> void printd(T&&...){ }
template <ostream& out = cout, class... T> void printde(T&&...){ }
template <ostream& out = cout, class... T> void printb(T&&...){ }
template <ostream& out = cout, class... T> void printArr(T&&...){ }
#endif

int main(){
    ll k; cin >> k;
    ll n1 = k / 50, n2 = k % 50;
    vector<ll> as(50, 48);
    // if(n1 == 0){
    //     cout << 2 << '\n';
    //     cout << 0 << ' ' << 2 * k << '\n';
    //     return 0;
    // }
    as[49]++;
    if(k == 49){
        cout << 2 << '\n';
        cout << 23 << ' ' << 27 << '\n';
        return 0;
    }
    for(int i = 0; i < 50; i++){
        as[i] += n1;
    }
    for(int i = 0; i < 50; i++){
        as[i] -= n2;
    }
    as[46] += n2 / 4 * 51;
    as[47] += n2 / 4 * 51;
    as[48] += n2 / 4 * 51;
    as[49] += (n2 / 4 + n2 % 4) * 51;
    cout << 50 << '\n';
    for(int i = 0; i < 50; i++){
        cout << as[i] << ' ';
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int q[5][1000];
int w[5][1000];
signed main(){
  int a,b,c,d,e,f;
  cin>>a;
  for(int i=0;i<2;i++){
    for(int j=0;j<a;j++) cin>>q[i][j];
  }
  w[0][0]=q[0][0];
  w[0][1]=w[0][0]+q[0][1];
  w[1][0]=w[0][0]+q[1][0];
  for(int i=1;i<a;i++){
    w[1][i]=max(w[0][i],w[1][i-1])+q[1][i];
    w[0][i+1]=w[0][i]+q[0][i+1];
    w[1][i+1]=w[1][i]+q[1][i+1];
  }
  cout<<w[1][a-1]<<"\n";
}

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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n, m, c;
    cin >> n >> m >> c;

    int b[m];
    rep(i, m) cin >> b[i];
    int a[n][m];
    rep(i, n) rep(j, m) cin >> a[i][j];

    int cnt = 0;

    rep(i, n)
    {
        int sum = 0;
        rep(j, m)
        {
            sum += a[i][j] * b[j];
        }
        if (sum + c > 0)
            cnt++;
    }

    OP(cnt);

    return 0;
}

Measured memory_bytes: 256
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define pb push_back
#define lowbit(x) x&(-x)
#define PII  pair<int, int> 
#define FAST ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)1e5 + 5;
using namespace std;

int sum[100001];
int a[100001];
map<int, int> ma;

int main(){
	int n, m;
	scanf("%d %d", &n, &m);
	ll ans = 0;
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		sum[i] = (sum[i-1] + a[i]) % m;
		ans += ma[sum[i]];
		ma[sum[i]]++;
	}
	printf("%lld\n", ans + ma[0]);
	return 0;
}

Measured memory_bytes: 3968
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
count = 0

for i in range(n):
  count += b[a[i]-1]
  if i>=1 and a[i]-a[i-1] == 1:
    count += c[a[i-1]-1]
    
print(count)

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>

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

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main()
{
	int N, M;
	cin >> N >> M;

	vector<ll> Hi(N, 0);
	vector<P> pair(M);
	vector<bool> map(N, true);
	rep(i, N) cin >> Hi.at(i);
	rep(i, M) cin >> pair.at(i).first >> pair.at(i).second;

	sort(pair.begin(), pair.end());

	for (auto elem : pair)
	{
		if (Hi.at(elem.first - 1) == Hi.at(elem.second - 1))
		{
			map.at(elem.first - 1) = false;
			map.at(elem.second - 1) = false;
		}
		else if (Hi.at(elem.first - 1) < Hi.at(elem.second - 1))
		{
			map.at(elem.first - 1) = false;
		}
		else 
		{
			map.at(elem.second - 1) = false;
		}
	}

	int ret = 0;
	for (auto elem : map)
	{
		if (elem) ++ret;
	}

	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 4848
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
V = getList()

# 条件を満たすもののうちで最も多く現れる多い２数を採用する方針
even = [0] * (10 ** 5 + 1)
odd = [0] * (10 ** 5 + 1)
for i in range(N):
    if i % 2 == 0:
        even[V[i]] += 1
    else:
        odd[V[i]] += 1
# 偶数列、奇数列に現れる数字の中で一番多かったもの
topeven = even.index(max(even))
topodd = odd.index(max(odd))
even.sort()
odd.sort()

ans = 0
if topeven == topodd:
    # 偶数列で一番多かった数、奇数列で２番目に多かった数
    opt1 = N - even[-1] - odd[-2]
    # 偶数列で２番目に多かった数、奇数列で一番多かった数
    opt2 = N - even[-2] - odd[-1]
    # どちらか小さい方
    ans = min(opt1, opt2)
else:
    ans = N - even[-1] - odd[-1]
print(ans)

Measured memory_bytes: 57520
def main():
    K, N = map(int, input().split())
    A = list(map(int,input().split()))
    ans = K
    for i in range(0,N,1):
        s = A[i]
        if i == 0:
            g = A[N-1]
            ans = min(ans, g-s)
        else:
            g = A[i-1]
            ans = min(ans, K-(s-g))

    print(ans)

main()

Measured memory_bytes: 26444
#include<stdio.h>
#include<stdlib.h>

void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  int max=100*n;
  int *dp=(int *)calloc(max+1,sizeof(int));
  int i;
  for(i=1;i<=max;i++) dp[i]=m+1;
  dp[0]=0;
  while(n--){
    int v,w;
    scanf("%d%d",&v,&w);
    for(i=max;i>=v;i--) if(dp[i]>dp[i-v]+w) dp[i]=dp[i-v]+w;
  }
  for(i=max;dp[i]>m;i--);
  printf("%d\n",i);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int a[200];
signed main(){
	int n;cin>>n;
	rep(i,n)cin>>a[i];
	sort(a,a+n,greater<>());
	int A=0,B=0;
	rep(i,n){
		if(i%2==0)A+=a[i];
		else B+=a[i];
	}
	cout<<A-B<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string k="CODEFESTIVAL2016";

int main()
{
	string a;cin>>a;
	int s=0;
	for(int i=0;i<=15;i++){
		if(a[i]!=k[i])s+=1;
	}
	cout<<s<<endl;;
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var steps string
	fmt.Scan(&steps)

	easy := "Yes"
	for i, step := range steps {
		i += 1
		if i%2 == 0 && step == 'R' || i%2 == 1 && step == 'L' {
			easy = "No"
			break
		}
	}

	fmt.Println(easy)
}


Measured memory_bytes: 512
// C - Digits in Multiplication
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int len_digits(ll n){
	int c = 0;
	while(n>0){ n /= 10; c++; }
	return c;
}

int main(){
	ll N; cin>>N;
	int ans = 11;
	ll s = sqrt(N);
	for(ll a=1; a<=s; a++)
		if(N%a==0) ans = min(ans, max(len_digits(a), len_digits(N/a)));
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
  
int main(){
  int i, j, n, q, c=0, l, r, m;
  int S[100001], T[50001];
  
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&T[i]);
  }
    
  for(i=0; i<q; i++){
    l = 0;
    r = n;
    while(l < r){
      m = (l + r)/2;
      if(S[m] == T[i]){
        c++;
        break;
      }
      else if(S[m] < T[i]) l = m+1;
      else  r = m;
    }
  }
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const double PI  = acos(-1.0);
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const LL INF  = 0x3f3f3f3f3f3f3f3f;
const int N=3e5+10;
const int M=1e6+10;
const int mod=1e9+7;
inline LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
inline LL lcm(LL a, LL b) { return a * b / gcd(a, b); }
inline LL read(){LL x=0,f=1;char c=getchar();while(c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}return x*f;}
inline LL qpow(LL x,LL k=mod-2,LL m=mod){LL res=1;while(k){if(k&1) res=res*x%m;x=x*x%m;k>>=1;}return res;}
/*=================================================================================================================*/
int n,m,fa[N];

int findfa(int x){return x==fa[x]?x:fa[x]=findfa(fa[x]);}

int main(){
    n=read(),m=read();
    for(int i=1;i<=n;i++) fa[i]=i;
    for(int i=1,u,v;i<=m;i++){
        u=read(),v=read();
        fa[findfa(u)]=findfa(v);
    }
    int cnt=0;
    for(int i=1;i<=n;i++) cnt+=(i==findfa(i));
    cout<<cnt-1<<endl;
    return 0;
}


Measured memory_bytes: 3988
import java.util.Scanner;

public class Main{

	public static void main(String args[]){
		
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		
		int d = a / b;
		int reminder = a % b;
		double f = (double)a / b;
		
		System.out.println(d + " " + reminder + " " + String.format("%.5f", f));
		
		sc.close();
	}

}



Measured memory_bytes: 26520
#include "bits/stdc++.h"
using namespace std;

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

const int MAXSSTN = 200010;
class StarrySkyTree{
public:
  int size=0;
  int depth=0; // the depth of the tree
  int best=0;  // the index of maximum element
  int start=0; // the initial index of inputs
  long long dat_add[4 * MAXSSTN];
  long long dat[4 * MAXSSTN];
  
  StarrySkyTree(int n){
    size=n;
    while((1<<depth)<n)depth++;
    start=(1<<depth)-1;
    for(int i=start;i<(1<<(depth+1));i++){
      if(i<start+n)
	dat[i]=0;
      else
	dat[i]=1e15;
    }
    for(int i=start;i<start+n;i++){
      int tmp=i;
      while(par(tmp)!=-1){
	dat[par(tmp)]=min(dat[tmp],dat[(tmp+1)/2*4-1-tmp]);
	tmp=par(tmp);
      }
    }
    int i=0;
    while(i<start)i=(dat[i]==dat[2*i+1])?2*i+1:2*i+2;
    best=i-start;
  }
  long long max_element(int a, int b){ return max_element(a, b, 0, 0, (1<<depth)); }
  void add(int s, int t, int x){ add(s, t, 0, 0, (1<<depth), x); }
  void add(int i, int x){ add(i, i + 1, 0, 0, (1<<depth), x); }

  int par(int i){
    if(i==0)
      return -1;
    return (i-1)/2;
  }
  
  void clear() {
    for(int i=start;i<(1<<(depth+1));i++){
      if(i<start+size)
	dat[i]=0;
      else
	dat[i]=1e15;
    }
    for(int i=start;i<start+size;i++){
      int tmp=i;
      while(par(tmp)!=-1){
	dat[par(tmp)]=min(dat[tmp],dat[(tmp+1)/2*4-1-tmp]);
	tmp=par(tmp);
      }
    }
    int i=0;
    while(i<start)i=(dat[i]==dat[2*i+1])?2*i+1:2*i+2;
    best=i-start;
    
    REP(i,4*MAXSSTN)dat_add[i]=0;
  }

  void update(int d,long long x){
    int i=d+start;
    dat[i]=x;
    while(par(i)!=-1){
      dat[par(i)]=min(dat[i],dat[(i+1)/2*4-1-i]);
      i=par(i);
    }
    i=0;
    while(i<start){
      i=(dat[i]==dat[2*i+1])?2*i+1:2*i+2;
    }
    best=i-start;
  }
  void dump(){
    for(int i=0;i<(1<<(depth+1));i++){
      cerr<<dat[i]<<" ";
    }
    cerr<<endl;
  }
private:
  long long max_element(int a, int b, int k, int l, int r){
    if(b <= l || r <= a) return 1e15;
    if(a <= l && r <= b) return dat[k] + dat_add[k];

    long long vl = max_element(a, b, k * 2+1, l, (l + r) / 2);
    long long vr = max_element(a, b, k * 2+2, (l + r) / 2, r);
    return min(vl, vr) + dat_add[k];
  }
  void add(int a, int b, int k, int l, int r, long long x){
    if(b <= l || r <= a) return;
    if(a <= l && r <= b){
      dat_add[k] += x;
    }else{
      add(a, b, k * 2+1, l, (l + r) / 2, x);
      add(a, b, k * 2+2, (l + r) / 2, r, x);
      dat[k] = min(dat[k * 2+1] + dat_add[k * 2+1], dat[k * 2 + 2] + dat_add[k * 2 + 2]);
    }
  }
};

int n,k;
int a[200000];
 
int main(){
  cin>>n>>k;
  REP(i,n)cin>>a[i];
  if(k >= 41){
    REP(i,n)cout<<n<<" ";
    cout<<endl;
    return 0;
  }
 
  StarrySkyTree sst(n);
  REP(i,k){
    REP(j,n)sst.update(j,0);
    REP(j,n){
      sst.add(max(0,j-a[j]),min(n-1,j+a[j])+1,1);
    }
    REP(j,n){
      if(a[j]!=n || !i)
	      a[j]=sst.max_element(j,j+1);
    }
    sst.clear();
  }
 
  REP(i,n)cout<<a[i]<<" ";
  cout<<endl;
  return 0;
}


Measured memory_bytes: 14304
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long
#define pii pair<int,int>
#define ff first
#define ss second
#define vi vector<int>
#define fo(n) for(int i = 0;i < int(n);i++)
#define foo(a,b) for(int i = int(a);i <= int(b);i++)
#define mk make_pair
#define pb push_back
#define MAXN (int)1e5
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define fastio ios_base:: sync_with_stdio(false)
#define inf (int)1e9

int dp[MAXN+1][2];
vi arr(100);

int sol(int n,int K,int mv){

	if(dp[K][mv] != -1) return dp[K][mv];


	if(K < arr[0]){

		if(mv%2 == 0) return 0;
		else return 1;
	}

	int res;
	if(mv%2 == 0){
		res = 0;

		for(int i = 0;i < n;i++){
			if(arr[i] <= K){
				res = res|(sol(n,K-arr[i],(mv+1)%2));
			}
		}
	}

	else if(mv%2 == 1){

		res = 1;

		for(int i = 0;i < n;i++){
			if(arr[i] <= K){
				res = res&(sol(n,K-arr[i],(mv+1)%2));
			}
		}
	}

	dp[K][mv] = res;

	return dp[K][mv];
}


int main(){
	
	fastio;
	int n,K;
	cin >> n >> K;

	fo(n) cin >> arr[i];

	sort(arr.begin(),arr.begin()+n);
	memset(dp,-1,sizeof(dp));


	int first = sol(n,K,0);


	if(first) cout << "First" << endl;
	else cout << "Second" << endl;


	return 0;
 }	

Measured memory_bytes: 8832
/* Coin Changing Problem
 *
 * Find the minimum number of coins to make change for n cents using coins of
 * denominations d1, d2,.., dm. The coins can be used any number of times.
 *
 * Input
 * n m
 * d1 d2 ... dm
 * Two integers n and m are given in the first line. The available denominations
 * are given in the second line.
 *
 * Output
 * Print the minimum number of coins in a line.
 *
 * Constraints
 * 1 ≤ n ≤ 50000
 * 1 ≤ m ≤ 20
 * 1 ≤ denomination ≤ 10000
 * The denominations are all different and contain 1.
 */

#include <algorithm>
#include <iostream>
#include <vector>

#define MAXN 50050
using namespace std;
int dp[MAXN];

int main() {
  fill(dp, dp + MAXN, 2 * MAXN);
  int n, m;
  cin >> n >> m;
  vector<int> ds;
  for (int d; cin >> d;)
    ds.push_back(d);
  dp[0] = 0;
  for (int i = 1; i <= n; ++i)
    for (int d : ds)
      if (d <= i)
        dp[i] = min(dp[i], 1 + dp[i - d]);
  cout << dp[n] << endl;
}



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

int main() {
  int N,R;
  cin >> N >> R;
  
  int a;
  if (N >= 10) {
    a = R;
  }
  else {
    a = R + 100 * (10 - N);
  }
  
  cout << a << endl;
  
}

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

typedef long long ll;

int main() {
    string s;
    int K;
    vector<string>a;
    set<string>b;
    cin >> s;
    cin >> K;
    
    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j <= K; j++) {
            string t = "";
            for (int k = 0; k < j; k++) {
                if (i+k < s.size()) {
                    t += s[i+k];
                }
            }
            if (t != "") {
                a.push_back(t);
            }
        }
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < a.size(); i++) {
        b.insert(a[i]);
    }
    auto itr = b.begin();
    int cnt = 1;
    while (cnt < K) {
        cnt++;
        itr++;
    }
    cout << *itr << endl;
}


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

using namespace std;
typedef long long ll;
//ループ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//コンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

//2値の最大公約数(順序関係なし・0はダメ)
int gcd(int a, int b){
    return b ? gcd(b, a%b) :a;
}

//n個の最大公約数
int ngcd(vector<int>& a){
    int res;
    res = a.at(0);
    for(int i = 1; i< a.size() && res != 1; i++){
        res = gcd(a.at(i), res);
    }
    return res;
}

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

//n個の最小公倍数
int nlcm(vector<int> numbers){
    int res;
    res = numbers.at(0);
    for(int i = 0; i< numbers.size();i++){
        res = lcm(res, numbers[i]);
    }
    return res;
}

//素数判定O(√N)
bool isPrime(int x){
    if(x<2) return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(int i = 3; i*i <= x; i+=2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(int n){
    int res = 0;
    while(n>0){
        res += n%10;
        n /= 10;
    }
    return res;
}

//約数全列挙
vector<int> enum_div(int n){
    vector<int> ret;
    for(int i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i != 1 && i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}

//繰り返し自乗法
long long int mod_pow(long long int x, long long int n, long long int mod){
    long long int res = 1;
    while(n > 0){
        if(n & 1) res = res*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}

//文字列の中で何回文字が出てきたのかを数える
int stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c); //覚える
}

int main(){
    int cnt=0, n, d1, d2;
    cin >> n;
    bool ans=false;

    REP(i,n){
        cin >> d1 >> d2;

        if(d1==d2) cnt++;
        else cnt=0;

        if(cnt>2) ans=true;
    }

    if(ans) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 3624
N = int(input())
A = input()
B = input()
C = input()
cnt = 0

for idx in range(N):
    if A[idx] == B[idx] and A[idx] == C[idx] and B[idx] == C[idx]:
        continue
    elif A[idx] == B[idx]:
        C = C[:idx] + A[idx] + C[idx+1:]
        cnt += 1
    elif A[idx] == C[idx]:
        B = B[:idx] + A[idx] + B[idx+1:]
        cnt += 1
    elif B[idx] == C[idx]:
        A = A[:idx] + B[idx] + A[idx+1:]
        cnt += 1
    else:
        B = B[:idx] + A[idx] + B[idx+1:]
        C = C[:idx] + A[idx] + C[idx+1:]
        cnt += 2
#print(A,B,C)
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
int dp[3002][3002][4];
void chmax(int &a,int b){
	if(a < b)a = b;
}
signed main(){
	// dp[i][j][k] = dp[i-1][j][k],dp[i][j-1][k],dp[i-1][j][k-1],dp[i][j-1][k-1];
	int r,c,K;cin >> r >> c >> K;
	vector<int> items(r*c+1);
	auto toID = [&](int i,int j){
		return i*c + j;
	};
	rep(i,K){
		int a,b,v;cin >> a >> b >> v;
		a--;b--;
		items[toID(a,b)] = v;
	}
	rep(i,r+1)rep(j,c+1)rep(k,4){
		chmax(dp[i+1][j][0],dp[i][j][k]);
		chmax(dp[i][j+1][k],dp[i][j][k]);

		if(i < r && j < c && items[toID(i,j)]){
			if(k < 3)chmax(dp[i+1][j][0],dp[i][j][k] + items[toID(i,j)]);
			if(k+1 < 4)chmax(dp[i][j+1][k+1],dp[i][j][k]+ items[toID(i,j)]);
		}

	}
	int ret = 0;
	rep(i,4)ret = max(ret,dp[r][c][i]);
	cout << ret << endl;
	
	return 0;
}

Measured memory_bytes: 355172
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
	int n, k;	cin >> n >> k;
  	vector<int64_t> h(n);	rep(i,n) cin >> h.at(i);
  	sort(h.begin(), h.end(),greater<int>());
  	int64_t atk = k;
  	for(int i = k; i < n; i++) atk += h.at(i);
  	cout << atk - k << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>

using namespace std;
int gcd(int a, int b) {
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
#define MOD 1000000007
#define INF 99999999999 
#define pb push_back
#define mt make_tuple
#define ll long long
ll ncr(ll n, ll r)
{
	ll i, ans = 1, k = 0;
	if (r == 0)
		return 1;
	else if (n < r)
		return 0;
	for (i = n; i >= n - r + 1; i--)
	{
		ans *= i;
		ans /= n - i + 1;
	}


	return ans;

}
bool visited[6] = { false };
int n = 6;
vector<int> adj[6];


void max_heapify(int a[100], int i)
{
	int l, r, largest = i;
	l = 2 * i + 1;
	r = 2 * i + 2;
	if (l<n && a[l]>a[i])
		largest = l;
	if (r<n && a[r]>a[l])
		largest = r;
	if (largest != i)
	{
		int k;
		k = a[i];
		a[i] = a[largest];
		a[largest] = k;
		max_heapify(a, largest);
	}

}
int power(ll x, ll y, ll p)
{
	int res = 1;
	x = x % p;

	while (y > 0)
	{

		if (y & 1)
			res = (res * x) % p;


		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

bool square(ll n)
{
	double x;
	x = sqrt(n);
	if (x == floor(x))
		return true;
	else return false;
}


bool prime(ll n)
{
	ll i;
	for (i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
			return false;
	}
	return true;
}
void dfs(ll a, ll b, vector<pair<ll, ll>>adj[][1001], bool visited[][1001])
{
	visited[a][b] = true;
	for (auto u : adj[a][b])
	{
		if (!visited[get<0>(u)][get<1>(u)])
		{
			visited[get<0>(u)][get<1>(u)] = true;
			dfs(get<0>(u), get<1>(u), adj, visited);
		}
	}
}
ll modi(ll a, ll m)
{
	return power(a, m - 2, m);

}
ll dp[101][100001] = { 0 }, N, W, w[10000], v[10000];
int main() {
	ll i, j;
	cin >> N >> W;
	for (i = 0; i < N; ++i) 
		cin >> w[i] >> v[i];

	dp[0][0] = 0;
	for (i = 1; i <= 1000 * N; ++i) dp[0][i] = INF;

	for (i = 0; i < N; ++i) {
		for (j = 0; j < v[i]; j++) 
			dp[i + 1][j] = dp[i][j];
		for (j = v[i]; j <= 1000 * N; j++) {
			dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
		}
	}
	for (j = 1000 * N; j > 0; --j) 
		if (dp[N][j] <= W) {
		    {
		        cout << j << endl;
		        return 0;
		    }
		
	}
	cout << "0" << endl;
	return 0;
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

class UnionFind {
public:
	vector<int> par;//親の番号
    vector<int> rank;//木の深さ
 
	UnionFind(int n){//全ての要素に対して自身が根となるように初期化, 木の深さは0になる
		rep(i,n){
            par.push_back(i);
            rank.push_back(0);
        }
	}
 
	int find(int x) {//木の根を求める
		if(par[x]==x){
            return x;
        }else{
            return par[x]=find(par[x]);
        }
	}
 
	void unite(int x,int y){//xとyの属する集合を併合
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]){//木の深さが小さい方を大きい方へ繋げる
            par[x]=y;
        }else{
            par[y]=x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }

    bool same(int x,int y){//xとyが同じ集合に属するか否か
        return find(x)==find(y);
    }
};
//x以下の要素への最小index, ソートしてから使ってね
template <class T> 
int former(const vector<T> &v, T x){
  return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
//x以上の要素への最小index
template <class T> 
int latter(const vector<T> &v, T x){
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}
//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}
//nCk
template <class T>
T comb(T n,T k){
    T ans=1;
    FOR(i,n-k+1,n+1){
        ans*=i;
    }
    FOR(i,1,k+1){
        ans/=i;
    }
    return ans;
}
//a,bの最大公約数
template <class T>
T gcd(T a,T b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}
//素因数分解
template <class T>
map<T,T> prime_factor(T x){
    map<T,T> ans;
    for(T i=2;i*i<=x;i++){
        while(x%i==0){
            x/=i;
            ans[i]++;
        }
    }
    if (x!=1){
        ans[x]=1;
    }
    return ans;
}
//約数列挙
template <class T>
vector<T> divisor(T x){
    vector<T> res;
    for(T i=1;i*i<=x;i++){
        if(x%i==0){
            res.push_back(i);
            if(i!=x/i){
                res.push_back(x/i);
            }
        }
    }
    return res;
}
//素数判定
template <class T>
bool is_prime(T x){
    for(T i=2;i*i<=x;i++){
        if(x%i==0){
            return false;
        }
    }
    return x!=1;
}

const ll inf=1e9+7;

ll mult(ll n,ll m){//n^m%infを求める
    if(m==1){
        return n%inf;
    }else if(m%2==0){//オーバーフロー防止のためにn^(m/2)*n^(m/2)を考える
        ll t=mult(n,m/2);
        return (t*t)%inf;
    }else{//奇数の時はn^(m-1)*nを考える
        ll t=mult(n,m-1);
        return (t*n)%inf;
    }
}

typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x,a,b;
    cin>>x>>a>>b;
    if(b-a<=0){
        cout<<"delicious"<<endl;
    }else if(b-a<x+1){
        cout<<"safe"<<endl;
    }else{
        cout<<"dangerous"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int n;

int main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        cin >> n;
        vector<pair<int, int> > v;
        for (int i = 0; i < n; i++) {
                int b, a; cin >> b>> a;
                v.push_back({a, b});
        }
        sort(v.begin(), v.end());
        int cur = 0;
        for (int i = 0; i < n; i++) {
                if (cur + v[i].second > v[i].first) {
                        cout << "No";
                        return 0;
                } else cur += v[i].second;
        }
        cout << "Yes";
return 0;
}


Measured memory_bytes: 2420
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <utility>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
int H, W;
bool b[2000][2000];
int L[2000][2000], R[2000][2000], D[2000][2000], U[2000][2000];  

int main(){
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  cin >> H >> W;

  rep(i,H){
    string s;
    cin >> s;
    rep(j,W){
      if (s[j] == '.') {
         b[i][j] = true;
      }
    }
  }
   
  rep(i,H) {
    rep(j,W) {
      if (!b[i][j]) continue;
      if (j==0){
        L[i][j] = 1;
      }else{
        L[i][j] = L[i][j-1] + 1;
      }
    }
    rep_down(j, W){
      if (!b[i][j]) continue;
      if (j==W-1){
        R[i][j] = 1;
      }else{
        R[i][j] = R[i][j+1] + 1;
      }
    }
  }


  rep(j,W){
    rep(i,H) {
      if (!b[i][j]) continue;
      if (i==0){
        D[i][j] = 1;
      }else{
        D[i][j] = D[i-1][j] + 1;
      }
    }
    rep_down(i, H){
      if (!b[i][j]) continue;
      if (i==H-1){
        U[i][j] = 1;
      }else{
        U[i][j] = U[i+1][j] + 1;
      }
    }
  }

  int ans = 0;
  rep(i,H){
    rep(j,W){
      if (!b[i][j]) continue;
      ans = max(ans, L[i][j]+R[i][j]+D[i][j]+U[i][j] -3);
    }
  }

  
  cout << ans << endl;
  return 0;
}


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

using namespace std;
int main (){
    int n;
    cin >> n;
    int p[n];
    for (int i = 0; i < n; i++){
        cin >> p[i];
    }
    int count=0;
    int lmin=p[0];
    for (int i = 0; i < n; i++){
        if(p[i]<=lmin) count++;
        lmin=min(lmin,p[i]);
    }
    cout << count << "\n";
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
long mod = (long) 1e9 + 7;

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

int main(){
    
    long n;
    cin >> n;
    
    long ans = 0;
    
    for(long i = 1; i <= n; i++)
        for(long j = 1; j <= n; j++)
            for(long k = 1; k <= n; k++)
                ans += fun(fun(i, j), k);
    
    cout << ans << "\n";
    
    return 0;
}


Measured memory_bytes: 3072
#include<iostream>
using namespace std;
#include<stdio.h>
int main(){
	int n,i,a[100]={0};
	cin>>n;
	for(i=0;i<n;i++)
	cin>>a[i];
	for(i=n-1;i>=0;i--){
		cout<<a[i];
		if(i==0)
		cout<<endl;
		else
		cout<<' ';
	}
	return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
 
#define       pb(a)             push_back((a))
#define       mp(a,b)           make_pair((a),(b))
#define       REP(a,b)          for(ll i=(a);i<(b);i++)
#define       REP2(a,b)         for(ll j=(a);j<(b);j++)
#define       REPE(a,b,c,d)     REP(a,b)for(ll j=(c);j<(d);j++)
#define       REPV(a,b,c)       for(ll (a)=b;(a)<(c);(a)++)
#define       IREP(a,b)         for(ll i=(a);i>=(b);i--)
#define       IREP2(a,b)        for(ll j=(a);j>=(b);j--)
#define       IREPV(a,b,c)      for(ll (a)=b;(a)>=(c);(a)--)
#define       all(v)            (v).begin(),(v).end()
#define       Trvs(c)           for (auto it = (c).begin(); it != (c).end(); it++)
#define       INF               INT_MAX
#define       sz(x)             x.size()
#define       flash             ios_base::sync_with_stdio(false);cin.tie(NULL);
#define       F                 first
#define       S                 second
#define       MOD               1000000007
 
using         ll     = long long;
using         vi     = vector<int>;
using         vvi    = vector<vi>;
using         vll    = vector<ll>;
using         vvll   = vector<vll>;
using         vb     = vector<bool>;
using         vd     = vector<double>;
using         vs     = vector<string>;
using         pii    = pair<int, int>;
using         pll    = pair<ll, ll>;
using         pdd    = pair<double, double>;
using         vpii   = vector<pii>;
using         vvpii  = vector<vpii>;
using         vpll   = vector<pll>;
using         vvpll  = vector<vpll>;
using         vpdd   = vector<pdd>;
using         vvpdd  = vector<vpdd>;
 
 
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

void solve(){
    ll n,k,r,p,s;
    string t;
    cin>>n>>k>>r>>s>>p;
    cin>>t;
    ll ans = 0;
    REP(0,n){
        if(t[i]=='r')ans+=p;
        if(t[i]=='p')ans+=s;
        if(t[i]=='s')ans+=r;
    }
    //cout<<ans<<endl;
    REP(k,n){
       if(t[i] == t[i-k]){
        if(t[i]=='r')ans-=p;
        if(t[i]=='p')ans-=s;
        if(t[i]=='s')ans-=r;
        t[i]='0';
        //cout<<ans<<endl;
        }
    }
    cout<<ans;
}
 
 
int main(){
 
	flash
	/*
    #ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("output.txt","w",stderr);
	#endif
 	*/
   
	//ll t;cin>>t;while(t--)
	solve();
 
 
	return 0;
}

Measured memory_bytes: 512
#ifdef __GNUC__
#include <bits/stdc++.h>
#endif // __GNUC_

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

int main() {

    int N;
    std::cin >> N;
    std::vector<int> A(N);
    for (auto& i : A)std::cin >> i;

    std::vector<int> L(N + 1, 0), R(N + 1, 0);
    for (int i = 0; i < N; ++i)L[i + 1] = gcd(L[i], A[i]);
    for (int i = N - 1; i >= 0; --i)R[i] = gcd(R[i + 1], A[i]);
    int ans = -1;
    for (int i = 0; i < N; ++i) {
        ans = std::max(ans, gcd(L[i], R[i + 1]));
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

bool is_prime(int x){
	for (int i = 2; i <= (int)sqrt(x); i++){
		if (x % i == 0) return false;
	}
	return true;
}


int main(){
	int q;
	cin >> q;
	vector<int> like2017(100001);
	vector<int> sum(100001);
	for (int i = 3; i <= 100000; i+=2){
		if (is_prime(i) && is_prime((i+1)/2)) like2017[i]++;
	}
	for (int i = 1; i <= 100000; i++){
		sum[i] = sum[i-1] + like2017[i];
	}
	for (int i = 0; i < q; i++){
		int l, r;
		cin >> l >> r;
		cout << sum[r] - sum[l-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1408