akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ldouble = long double;
 
const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;

string res = "No";
ll sum = 0;

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

    string a[n];
    string b[m];

    for (ll i = 0; i < n; i++)
    {
        string x;
        cin >> a[i];
    }

    
    for (ll i = 0; i < m; i++)
    {
        string x;
        cin >> b[i];
    }

    for (ll i = 0; i < n; i++)
    {
        for (ll j = 0; j < n; j++)
        {

            bool is = true;
            ll h, w;
            for (h = 0; h  < m; h++)
            {
                ll y = i + h;
                if (y >= n)
                {
                    is = false;
                    break;
                }

                for (w = 0; w  < m; w++)
                {
                    ll x = j + w;
                    if (x >= n)
                    {
                        is = false;
                        break;
                    }

                    if (a[y][x] != b[h][w])
                    {
                        is = false;
                    }
                }
            }


            if (is)
            {
                res = "Yes";
            }

        }
    }

    println(res);
}

Measured memory_bytes: 3600
n = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(n-2):
    if p[i] < p[i+1] and p[i+1] < p[i+2] or p[i+2] < p[i+1] and p[i+1] < p[i]:
        cnt+=1
print(cnt)

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

int main() {
  // 現在のレーティングRの高橋君が次のコンテストでレーティングをGにするために
  // 取るべきパフォーマンスを出力する。
	int R, G;
	cin >> R >> G;
  
   // R = 4500, G = 0;
  
  	cout << 2 * G - R << endl;
}
  

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

struct node{
  struct node *right;
  struct node *left;
  struct node *p;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->right!=NIL) x=x->right;
  return x;

}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u;
  if(k<u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);

}

Node treeSuccessor(Node x){
  Node y; 
  if(x->right!=NIL) return treeMinimum(x->right);
 
  y=x->p;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->p;
    return y;
    
  }
} 
void treeDelete(Node z){
  
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL || x->right==NIL)
    y=z;
  else y=treeSearch(z,z->key);
  if(y->left!=NIL)
    x=y->left;
  else x=y->right;
  if(x!=NIL)
    x->p=y->p;
  if(y->p==NIL)
    root=x;  
  else if(y==y->p->left)
    y->p->left;
  else y->p->left=x;
  if(y!=z){
    z->key=y->key;
    y=z;
  }
}


void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
   while(x!=NIL){
     y=x;
     if(z->key<x->key) x=x->left;
     else x=x->right;
   }
   z->p=y;
   if(y==NIL)
     root=z;
   else if(z->key<y->key)
     y->left=z;
   else y->right=z;
 }


void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}

void preorder(Node u){
  if(u!=NIL){
 printf(" %d",u->key);  
  preorder(u->left);
  preorder(u->right);
}
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19360
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, p = LI()
    print((a*3+p)//2)
    return

#B
def B():
    n = II()
    sp = []
    for i in range(n):
        sp.append(input().split())
    another = [(s[0], -1 * int(s[1]),num) for num,s in enumerate(sp)]
    another.sort()
    for s,p,q in another:
        print(q+1)

    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 39280
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
from functools import lru_cache
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))
def inpl_str():
    '''
    一行に複数の文字
    '''
    return list(input().split())

n, k = inpl()
dp = [[0] * (k+1) for i in range(n+1)]
for i in range(n):
    w, v = inpl()
    for j in range(k + 1):
        include = dp[i][j - w] + v if j >= w else 0
        not_include = dp[i][j]
        dp[i + 1][j] = max(include, not_include)
print(max(dp[n][:]))
# for i in dp:
#     print(i)

Measured memory_bytes: 119276
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265
ll mm=1000000007;
 
ll pow1(ll n,ll k){
if(k==0)return 1;
if(k%2==0)return (pow1((n%mm)*(n%mm),k/2))%mm;
return ((n%mm)*(pow1((n%mm)*(n%mm),k/2)%mm))%mm;
}

ll ceil1(ll n,ll k){
    if(n%k==0) return n/k;
    return n/k+1;
}
 
void solve(){
    ll n,k,r,s,p,sum=0;
    cin>>n>>k;
    cin>>r>>s>>p;
    string t;
    cin>>t;
    vector<ll> ans(n+5,-1);
    for(ll i=0;i<n;i++){
        if(ans[i]==0) continue;
        if(t[i]=='r') ans[i]=p;
        if(t[i]=='s') ans[i]=r;
        if(t[i]=='p') ans[i]=s;
        if(i+k<n){
        if(t[i]==t[i+k]) ans[i+k]=0;
        }
    }
    for(ll i=0;i<n;i++){
        sum+=ans[i];
    }
    cout<<sum<<endl;
}    
 
 
int main(){
    FIO;
    ll q=1;
    //cin>>q;
    while(q--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1232
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections


def solve(N: int, s: "List[str]"):
    S = []
    for ss in s:
        ss = sorted(ss)
        S.append(''.join(ss))
    c = list(collections.Counter(S).values())
    s = 0
    for cc in c:
        s += cc*(cc-1)//2
    print(s)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 28912
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  int X, Y, Z, K; // X種Y種Z種から一つずつ買う，K:選び方
  cin >> X >> Y >> Z >> K;

  vector<long> A, B, C; // 価格
  long a, b, c;
  for( int i = 0; i < X; i++ ){ cin >> a; A.push_back(a); }
  for( int j = 0; j < Y; j++ ){ cin >> b; B.push_back(b); }
  for( int k = 0; k < Z; k++ ){ cin >> c; C.push_back(c); }
  
  sort(A.begin(), A.end(), greater<long>());
  sort(B.begin(), B.end(), greater<long>());
  sort(C.begin(), C.end(), greater<long>());
  
  tuple<long, int, int, int> d;
  priority_queue< tuple<long, int, int, int> > q; // cout用コンテナ
  set< tuple<long, int, int, int> > s; // 重複したものをq.pushしないための検索用コンテナ
  int i = 0;
  int j = 0;
  int k = 0;
  
  // 一番美味しいケーキの組み合わせ
  d = make_tuple(A[i]+B[j]+C[k], i, j, k);
  if( !s.count(d) ){ q.push( d ); s.insert( d ); }
  auto qtop = q.top();
  i = get<1>(qtop);
  j = get<2>(qtop);
  k = get<3>(qtop);
  cout << get<0>(qtop) << endl;
  q.pop();
  K--;
 
  while(K > 0){
    // 次の一番美味しいケーキの組み合わせ
    if( i+1 < X ){ 
    	d = make_tuple(A[i+1]+B[j]+C[k], i+1, j, k);
    	if( !s.count(d) ){ q.push( d ); s.insert( d ); }
    }
    if( j+1 < Y ){ 
    	d = make_tuple(A[i]+B[j+1]+C[k], i, j+1, k);
    	if( !s.count(d) ){ q.push( d ); s.insert( d ); }
    }
    if( k+1 < Z ){ 
    	d = make_tuple(A[i]+B[j]+C[k+1], i, j, k+1);
    	if( !s.count(d) ){ q.push( d ); s.insert( d ); }
    }
    auto qtop = q.top();
    i = get<1>(qtop);
    j = get<2>(qtop);
    k = get<3>(qtop);
    cout << get<0>(qtop) << endl;
    q.pop();
    K--;
  }
  
  return 0;
}

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


using namespace std;

int main()
{
    string s;
    long long k;
    cin >> s >> k;
    long long len = s.size();
    for(int i = 0; i < min(len, k); i++)
    {
        if(s[i] != '1')
        {
            cout << s[i];
            return 0;
        }
    }
    cout << '1' <<endl;

    return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

template<typename T> 
struct BIT {
    vector<T> dat;

    BIT (int n) { dat.assign(n + 1, 0); }

    void add(int k, T x) {
        for (++k; k < dat.size(); k += k & -k) dat[k] += x;
    }

    T query(int k) {
        T sum = 0;
        for (++k; k > 0; k -= k & -k) sum += dat[k];
        return (sum);
    }

    int lower_bound(T x) {
        int l, r;
        l = -1, r = dat.size();
        while (l + 1 < r) {
            int m = (l + r) / 2;
            if (query(m) >= x) r = m;
            else l = m;
        }
        return (r);
    }
};


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

    BIT<int> tree(M + 2);
    vint L(N), R(N);
    vector<Pi> length(N);
    for (int i = 0; i < N; i++) {
        cin >> L[i] >> R[i];
        length[i] = Pi(R[i] - L[i] + 1, i);
    }
    sort(begin(length), end(length)); 
    int cur = 0;
    for (int i = 1; i <= M; i++) {
        while (cur < N && length[cur].first < i) {
            auto idx = length[cur].second;
            tree.add(L[idx], 1);
            tree.add(R[idx] + 1, -1);
            cur++;
        }
        int cnt = 0;
        for (int j = 0; j <= M; j += i) {
            cnt += tree.query(j);
        }
        cout << (N - cur) + cnt << el;
    }

    return ( 0 );
}

Measured memory_bytes: 6016
/*
Hanit Banga
*/

#include <iostream>
#include <vector>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false)

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

const int N = 1e5 + 5;

bool a[N], eq[N];

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

	for (int i = 1; i <= n; ++i)
	{
		if (s[i - 1] == 'o')
			eq[i] = true;
		else
			eq[i] = false;
	}

	bool ans = false;
	for (int j = 0; j < 2; ++j)
	{
		for (int k = 0; k < 2; ++k)
		{
			a[1] = j;
			a[2] = k;

			bool temp;
			if (eq[1])
				temp = ((a[1] == 0) ? a[2] : !a[2]);
			else
				temp = ((a[1] == 0) ? !a[2] : a[2]);

			for (int i = 3; i <= n; ++i)
			{
				if (eq[i - 1])
					a[i] = ((a[i - 1] == 0) ? a[i - 2] : !a[i - 2]);
				else
					a[i] = ((a[i - 1] == 0) ? !a[i - 2] : a[i - 2]);
			}

			if (a[n] != temp)
				continue;

			if (eq[n])
				temp = ((a[n] == 0) ? a[n - 1] : !a[n - 1]);
			else
				temp = ((a[n] == 0) ? !a[n - 1] : a[n - 1]);

			if (temp != a[1])
				continue;

			ans = true;
			break;
		}
		if (ans)
			break;
	}

	if (!ans)
		cout << "-1\n";
	else
	{
		for (int i = 1; i <= n; ++i)
		{
			if (a[i])
				cout << 'W';
			else
				cout << 'S';
		}
		cout << '\n';
	}
}

Measured memory_bytes: 768
#include<cstdio>
#include<cstring>
#define reg register
#define max(a,b) (a>b?a:b)
typedef long long ll;
int f[305][305][305];
char ch[305];
int main(){
	scanf("%s",ch+1);
	reg int k,n=strlen(ch+1),ans=0;scanf("%d",&k);
	for(reg int i=1;i<=n;i++)
		for(reg int j=0;j<=k;j++)
			f[i][i][j]=1;
	for(reg int l=1;l<n;l++)
		for(reg int i=1,j=i+l;j<=n;i++,j++)
			for(reg int s=0;s<=k;s++){
				f[i][j][s]=max(f[i+1][j][s],f[i][j-1][s]);
				if(ch[i]==ch[j])f[i][j][s]=max(f[i][j][s],f[i+1][j-1][s]+2);
				if(s>0)f[i][j][s]=max(f[i][j][s],f[i+1][j-1][s-1]+2);
			}
	for(reg int i=0;i<=k;i++)ans=max(ans,f[1][n][i]);
	printf("%d\n",ans);
	return 0;
}

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

int main()
{
	int i, N;
	long long x[51], y[51];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%lld %lld", &(x[i]), &(y[i]));
	
	int j;
	long long p[51][51] = {}, q[51][51] = {};
	for (i = 1; i <= N; i++) {
		for (j = 1; j <= N; j++) {
			p[i][j] = x[i] - x[j];
			q[i][j] = y[i] - y[j];
		}
	}
	
	int k, l, count, max = 0;
	for (i = 1; i <= N; i++) {
		for (j = 1; j <= N; j++) {
			if (j == i) continue;
			count = 0;
			for (k = 1; k <= N; k++) {
				for (l = 1; l <= N; l++) {
					if (p[k][l] == p[i][j] && q[k][l] == q[i][j]) count++;
				}
			}
			if (count > max) max = count;
		}
	}
	
	printf("%d\n", N - max);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
if n == 1:
    print(1)
    exit()
a = 1
b = n
for i in range(1, 10**5):
    if n % i == 0:
        if i > n // i:
            print(min(len(str(i)), len(str(b))))
            exit()
        a = i
        b = n // i
print(len(str(b)))

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

int main() {
       long long int n,k;
       cin>>n>>k;
       long long int a[n];
       for(long int i=0;i<n;i++)
       cin>>a[i];
       sort(a,a+n);
       long long int ans=1;
       long long int mod=1e9+7;
       if(a[n-1]==0 && (k&1))
       ans=0;
       else if(a[n-1]<0 && (k&1))
       {
           for(long int i=n-1;i>=n-k;i--)
           ans=(ans*a[i])%mod;
       }
       else
       {
           long int j=n-1;
           if(k&1)
           {
           ans=(ans*a[j])%mod;
           j--;
           }
           long int i=0;
           k>>=1;
           for(long int s=0;s<k;s++)
           {
               if(a[i]*a[i+1]>a[j]*a[j-1])
               {
                   long long int temp=(a[i]*a[i+1])%mod;
                   i+=2;
                   ans=(ans*temp)%mod;
               }
               else
               {
                   long long int temp=(a[j]*a[j-1])%mod;
                   j-=2;
                   ans=(ans*temp)%mod;
               }
           }
       }
       ans=(ans+mod)%mod;
       cout<<ans;
	// your code goes here
	return 0;
}


Measured memory_bytes: 5188
N, A, B = map(int, input().split())

if A * B < N:
  print(-1)
elif A + B - 1 > N:
  print(-1)
else:
  P = [0] * N
  b = (N - A) // (B - 1) if B > 1 else 0
  r = (N - A) % (B - 1) + 1 if B > 1 else 1
  i = 1
  pos = 0
  while i <= N:
    if b:
      for j in range(B):
        P[pos + B - j - 1] = i
        i += 1
      pos += B
      b -= 1
    elif r:
      for j in range(r):
        P[pos + r - j - 1] = i
        i += 1
      pos += r
      r = 0
    else:
      P[pos] = i
      i += 1
      pos += 1
    
  for p in P:
    print(p, end=' ')

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

typedef long long ll;
typedef long double ld;
// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// use merge(all(vec1), all(vec2), vec3.begin()) to merge 2 vectors, use vec3.resize(vec1.size() + vec2.size()) first
// ll pos = partition_point(all(vec), pred) - vec.begin(); bool pred(ll a){return a<3};
// print number in binary -> cout << bitset<20>(n);

int main(){
	string s;cin>>s;
	cout<<s[0]<<s[1]<<s[2]<<endl;
}


Measured memory_bytes: 3596
#!/usr/bin/env python3
n, d = map(int, input().split())
l = []
ans = []

for i in range(n):
  l.append(list(map(int, input().split())))

for i in range(n-1):
  for j in range(i+1, n, 1):
    total = 0
    for k in range(d):
      total += abs(l[i][k] - l[j][k]) ** 2

    ans.append(total)

cnt = 0

for i in ans:
  for j in range(i+1):
    if j**2 == i:
      cnt += 1
      break

print(cnt)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <string>
#include <iomanip>

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

using namespace std;

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

  int height = 0;
  for(int i=1; i<1000; i++) {
    height += i;
    if(i==b-a) {
      cout << height - b << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
double a[1100],b[10];
int main()
{
    double n,m,p1,p2;
    scanf("%lf%lf",&n,&m);
    b[0]=1.0;
    for(int j=1; j<=5; j++)
        b[j]=b[j-1]*1.0/2.0;
    double x=1900*m+(n-m)*100;
//    printf("x=%lf\n",x);
    a[1]=1;
    p1=b[(int)(m)],p2=1.0-p1;
//    printf("p1=%lf,p2=%lf\n",p1,p2);
//    if(n==m) p1=1.0/2,p2=1.0/2;
//    else p1=1.0/4,p2=3.0/4;
    for(int i=2; i<=1000; i++)
        a[i]=a[i-1]*p2;
    double ans=0;
    for(int i=1; i<=1000; i++)
    {
        ans+=(p1*a[i]*i*x);
    }
    printf("%.0lf\n",ans);
    return 0;
}


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

using namespace std;

int main()
{
    int n,arr[100005],cnt;

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

        cnt=0;

        for(int i=1; i<=n; i++)
        {
            if(arr[arr[i]]==i)
            {
                cnt++;

                arr[i]=-1;
                arr[arr[i]]=-2;
            }
        }

        printf("%d\n",cnt);
    }

    return (0);
}


Measured memory_bytes: 640
ope = []
def plus(i,j,k):
    ope.append(('+',i,j,k))
def lt(i,j,k):
    ope.append(('<',i,j,k))

#assume a[0]+a[1] > 0
#a[3] = 1
plus(0,1,3)
lt(2,3,3)

#a[4] = A+1, a[5] = B+1
plus(0,3,4)
plus(1,3,5)

#a[1000] = 1, a[1001] = 2, a[1002] = 4, ..., a[1030] = 2**30
plus(1000,3,1000)
for i in range(30):
    plus(1000+i, 1000+i, 1000+i+1)

#a[2900] = x
#a[2901] = x + 2**i
#a[2000+i] = int(x + 2**i < A+1) : A_i
for i in range(29,-1,-1):
    plus(2900, 1000+i, 2901)
    lt(2901, 4, 2000+i)
    #x += a[2000+i] * 2**i
    lt(99, 2000+i, 2902)
    for j in range(i):
        plus(2902, 2902, 2902)
    plus(2900, 2902, 2900)

#a[3900] = x
#a[3901] = x + 2**i
#a[3000+i] = int(x + 2**i < B+1) : B_i
for i in range(29,-1,-1):
    plus(3900, 1000+i, 3901)
    lt(3901, 5, 3000+i)
    #x += a[3000+i] * 2**i
    lt(99, 3000+i, 3902)
    for _ in range(i):
        plus(3902, 3902, 3902)
    plus(3900, 3902, 3900)

# {A_0, ... A_29} * {B_0, ... B_29}
for a in range(30):
    for b in range(30):
        plus(2000+a, 3000+b, 4000)
        lt(3, 4000, 4001)
        for _ in range(a+b):
            plus(4001, 4001, 4001)
        plus(2, 4001, 2)

print(len(ope))
for row in ope:
    print(*row)

Measured memory_bytes: 11692
fn main() {
    let k: i64 = read();
    let s: i64 = read();
    let mut ans = 0;
    for x in 0..k + 1 {
        for y in 0..k + 1 {
            let z = s - x - y;
            if 0 <= z && z <= k {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    use std::io::prelude::*;

    let stdin = std::io::stdin();
    let s: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    s.parse().ok().unwrap()
}

Measured memory_bytes: 4352
#include <stdio.h>
int main()
{
	int N;
	int a,b,c;
	scanf("%d",&N);
	a=N%10;
	b=N/10%10;
	c=N/10/10%10;
	if(a==7||b==7||c==7)
		printf("Yes");
	else
		printf("No");
	return 0;
} 

Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <iomanip>

using ll = long long;

using namespace std;

using P = pair<long, long>;
#define fi first
#define se second

bool used[8] = {0};
int n;
P xy[8]; 

double dist(int i, int j) {
    if (i < 0 || j < 0) return 0;
    long xd = xy[i].fi - xy[j].fi,
         yd = xy[i].se - xy[j].se;
    return sqrt(xd * xd + yd * yd);
}

int main() {
    cin >> n;
    for (int i=0; i<n; i++) cin >> xy[i].fi >> xy[i].se;
    double sum = 0;
    for (int i=0; i<n; i++) {
        for (int j=i; j<n; j++) {
            sum += dist(i, j) * 2 / n;
        }
    }
    cout << setprecision(15) << sum << '\n';
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ans = 0;

		for (int i = 1; i <= 5; i++) {
			if (0 == sc.nextInt())
				ans = i;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 35840
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
double dp[301][301][301];
int n;
double solve(int i,int j,int k){
	if(dp[i][j][k]>=0)return dp[i][j][k];
	if(!(i|j|k))return 0.0;
	double res=0.0;
	if(i)res+=solve(i-1,j,k)*i;
	if(j)res+=solve(i+1,j-1,k)*j;
	if(k)res+=solve(i,j+1,k-1)*k;
	res+=n;
	res/=(i+j+k);
	return dp[i][j][k]=res;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    int a,c[4]={0};
    for(int i=0;i<n;i++){
    	cin>>a;
    	c[a]++;
    	//if(a<3)c[3-a]++;
    }
    memset(dp,-1,sizeof(dp));
    doublecout(solve(c[1],c[2],c[3]));
    return 0;
}


Measured memory_bytes: 213504
<?php
$antennas = array();
for($i = 0; $i <= 5; $i++){
    $antennas[$i] = trim(fgets(STDIN));
}
$k =  $antennas[5];

//セット組み合わせ
/*
 * ** 01 02 03 04
 * -- ** 12 13 14
 * -- -- ** 23 24
 * -- -- -- ** 34
 * -- -- -- -- **
 */

    if( delta($antennas[0], $antennas[1] ) > $k ){echo ":("; exit();}
    if( delta($antennas[0], $antennas[2] ) > $k ){echo ":("; exit();}
    if( delta($antennas[0], $antennas[3] ) > $k ){echo ":("; exit();}
    if( delta($antennas[0], $antennas[4] ) > $k ){echo ":("; exit();}
    if( delta($antennas[1], $antennas[2] ) > $k ){echo ":("; exit();}
    if( delta($antennas[1], $antennas[3] ) > $k ){echo ":("; exit();}
    if( delta($antennas[1], $antennas[4] ) > $k ){echo ":("; exit();}
    if( delta($antennas[2], $antennas[3] ) > $k ){echo ":("; exit();}
    if( delta($antennas[2], $antennas[4] ) > $k ){echo ":("; exit();}
    if( delta($antennas[3], $antennas[4] ) > $k ){echo ":("; exit();}
echo "Yay!";
    exit();


function delta($a,$b){
    if($a > $b){
        return $a-$b;
    }else if($a < $b){
        return $b-$a;
    }
}


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

#define UNION_FIND_MAX 200

int uf_table[UNION_FIND_MAX];

void uf_init(void) {
	int i;
	for(i=0;i<UNION_FIND_MAX;i++)uf_table[i]=0;
}

void uf_merge(int a,int b) {
	int next;
	while(uf_table[a]>0) {
		next=uf_table[a]-1;
		if(uf_table[next]>0)uf_table[a]=uf_table[next];
		a=next;
	}
	while(uf_table[b]>0) {
		next=uf_table[b]-1;
		if(uf_table[next]>0)uf_table[b]=uf_table[next];
		b=next;
	}
	if(a!=b)uf_table[a]=b+1;
}

int uf_issame(int a,int b) {
	int next;
	while(uf_table[a]>0) {
		next=uf_table[a]-1;
		if(uf_table[next]>0)uf_table[a]=uf_table[next];
		a=next;
	}
	while(uf_table[b]>0) {
		next=uf_table[b]-1;
		if(uf_table[next]>0)uf_table[b]=uf_table[next];
		b=next;
	}
	return a==b;
}

typedef struct {
	int id,tb_time;
} island_t;

typedef struct {
	int a,b,cost;
} bridge_t;

/* desc */
int tbt_comp(const void* x,const void* y) {
	int tbx=((const island_t*)x)->tb_time;
	int tby=((const island_t*)y)->tb_time;
	if(tbx<tby)return 1;
	if(tbx>tby)return -1;
	return 0;
}

/* asc */
int cost_comp(const void* x,const void* y) {
	int cx=((const bridge_t*)x)->cost;
	int cy=((const bridge_t*)y)->cost;
	if(cx>cy)return 1;
	if(cx<cy)return -1;
	return 0;
}

int main(void) {
	int N,M;
	while(scanf("%d%d",&N,&M)==2 && (N|M)!=0) {
		static island_t islands[200];
		static int iss_taio[200];
		static bridge_t bridges[200*199];
		int i,j;
		int answer;
		int connect_count;
		for(i=0;i<N;i++) {
			islands[i].id=i;
			scanf("%d",&islands[i].tb_time);
		}
		for(i=0;i<M;i++) {
			scanf("%d%d%d",&bridges[i].a,&bridges[i].b,&bridges[i].cost);
			bridges[i].a--;
			bridges[i].b--;
		}
		qsort(islands,N,sizeof(island_t),tbt_comp);
		qsort(bridges,M,sizeof(bridge_t),cost_comp);
		for(i=0;i<N;i++)iss_taio[islands[i].id]=i;
		uf_init();
		answer=0;
		connect_count=0;
		for(i=0;i<N;i++) {
			while(i+1<N && islands[i].tb_time==islands[i+1].tb_time)i++;
			for(j=0;j<M;j++) {
				if(islands[iss_taio[bridges[j].a]].tb_time>=islands[i].tb_time &&
				islands[iss_taio[bridges[j].b]].tb_time>=islands[i].tb_time) {
					if(!uf_issame(bridges[j].a,bridges[j].b)) {
						uf_merge(bridges[j].a,bridges[j].b);
						answer+=bridges[j].cost;
						connect_count++;
					}
				}
			}
			if(connect_count<i) {
				/* can't connect all islands */
				uf_init();
				answer=0;
				connect_count=0;
			}
		}
		printf("%d\n",answer);
	}
	return 0;
}

Measured memory_bytes: 1120
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define INF (1ll<<60)
typedef pair<int, int> pii;
#define FI first
#define SE second
#define all(s) s.begin(),s.end()

int N;
vector<pii> vec;
int a[100100];
int res[100100];

signed main() {
	cin >> N;
	/*
	 rep(i,N)
	 {
	 cin >> a[i];
	 que.push(pii(a[i], i));
	 }
	 if (N == 1) {
	 cout << a[0] << endl;
	 return 0;
	 }
	 {
	 pii p = que.top();
	 que.pop();
	 pii q = que.top();
	 res[p.SE] += p.FI - q.FI;
	 a[p.SE] = q.FI;
	 que.push(pii(q.FI, p.SE));
	 cerr << p.SE << endl;
	 }
	 BIT bit(N);
	 for (int i = N - 1; i >= 0; --i) {
	 res[i] += (N - i - 1) - bit.sum(a[i]);
	 bit.add(a[i], 1);
	 }
	 rep(i,N)
	 {
	 cout << res[i] << endl;
	 }
	 */

	rep(i,N)
	{
		int a;
		cin >> a;
		vec.push_back(pii(a, i));
	}
	sort(all(vec), greater<pii>());
	int minin = INF;
	rep(i,N-1)
	{
		minin = min(minin, vec[i].SE);
		res[minin] += (i + 1) * (vec[i].FI - vec[i + 1].FI);
		vec[i].FI = vec[i + 1].FI;
	}
	minin = min(minin, vec[N - 1].SE);
	res[minin] += N * (vec[N - 1].FI);
#if 0
	while (!que.empty()) {
		pii p = que.top();
		int index = p.SE;
		minindex = min(minindex, index);
		//res[index]++;
		que.pop();
		int lim = 0;
		if (!que.empty()) {
			lim = que.top().FI;
			/*
			 if (lim == p.FI) {
			 pii q = que.top();
			 que.pop();
			 vector<int> same;
			 while (que.top().FI == lim) {
			 //
			 }
			 if (q.FI - 1 > 0)
			 que.push(pii(q.FI - 1, q.SE));
			 res[index]++;
			 }
			 */
		}
		res[minindex] += p.FI - lim;
		//cout << index + 1 << "," << p.FI << "," << lim << "," << res[index]
		//	<< endl;
		if (lim != 0)
		que.push(pii(lim, p.SE));
	}
#endif
	rep(i,N)
	{
		cout << res[i] << endl;
	}

}


Measured memory_bytes: 3568
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int n,a[100001],ans,sum=1;
int main()
{
//	freopen("1.txt","r",stdin);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	ans=pow(3,n);
	for(int i=1;i<=n;i++)
	{
		if(a[i]%2==0) sum*=2;
	}
	cout<<ans-sum;
} 

Measured memory_bytes: 640
N,M=map(int,input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
ans=0
#print(AB)
for a,b in AB:
    if M>=b:
        M-=b
        ans+=a*b
    else:
        ans+=a*M
        M=0
    if M<=0:
        break
print(ans)

Measured memory_bytes: 27756
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
using namespace std;

long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long N; cin >> N;
	string S; cin >> S;
	long mycount = 0;
	long res;
	long cres;

	for (int i = 0; i <= N - 1; i++) if (S[i] == '#') mycount++;
	res = mycount; //res in i = N - 1
	cres = mycount;
	// i番目以降が黒のとき
	for (int i = N - 2; i >= -1; i--) {
		if (S[i + 1] == '#') res--; else res++;
		cres = min(cres, res);
	}


	cout << cres << endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h> 
#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define per(i,n) for(long long i = (long long)(n-1);i >= 0;--i)
#define REP(i,s,t) for(long long i=s;i<t;i++)
#define PER(i,s,t) for(long long i=s;i>t;--i)
#define all(x) x.begin(),x.end()
#define sp(n) setprecision(n)
typedef long long ll;
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<int> a(n);
  double s=0;
  rep(i,n){
    cin>>a[i];
    s+=a[i];
  }
  sort(all(a));
  reverse(all(a));
  s=s/(4*m);
  if(a[m-1]>=s){
    cout<<"Yes"<<endl;
  }
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	char c1[]=sc.next().toCharArray();
	char c2[]=sc.next().toCharArray();
int i1,i2;
i1=1;
i2=1;
if(c1[0]=='D'){
	i1=-1;
}
if(c2[0]=='D'){
	i2=-1;
}
if(i1*i2>0){
	System.out.println("H");
}else{
	System.out.println("D");
}
	}}

Measured memory_bytes: 25044
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

int main(){
	ll a,b;
	scanf("%lld%lld",&a,&b);
	printf("%d",!!(a%b));
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define dbug printf("I am here\n");
#define Fast ios_base::sync_with_stdio(false); cin.tie(0);
#define vs              v.size()
#define ss              s.size()
#define sot(v)        sort(v.begin(),v.end())
#define rev(v)        reverse(v.begin(),v.end())
#define ii                pair<int,int>
#define ll                long long
#define ull              unsigned long long
#define pb              push_back
#define mpp          make_pair
#define Okay         0
#define pi               3.14159

static ll int inf = 1e9;
using namespace std;

void solve(){
    int n,m;
    cin>>n>>m;
    ll int a,b;
    long double sum;
    int cnt =0;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        sum = (a-b)*(a-b);
        sum += 2*a*b;
        if(sqrt((double)sum) <= m)cnt++;
    }
    cout<<cnt<<endl;

}


int main(){

    solve();

    return Okay ;
}


Measured memory_bytes: 3648
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int main()
{

  cout << fixed << setprecision(10);
  
  int n; cin >> n;
  vector< cord<int> > c(n);
  rep(i,n){cin >> c[i].x >> c[i].y;}
  vector<int> v(n);
  rep(i,n){v[i]=i;}
  double sum=0;
  do{
    rep(i,n-1){
      sum += dist(c[v[i]],c[v[i+1]]);
    }
  } while(next_permutation(v.begin(),v.end()));
  int f=1;
  rep(i,n){f*=(i+1);}
  cout << sum/(double)f << endl;

  return 0;
}


Measured memory_bytes: 256
Sd = input()
T = input()

Sd = Sd[::-1]
T = T[::-1]
flg = False
for s in range(len(Sd) - len(T)+1):
    # print(Sd[s:s + len(T)])
    cnt = 0
    for t in range(len(T)):
        # print(Sd[s+t:s + t+1], T[t])
        if Sd[s+t:s + t+1] == T[t] or Sd[s+t:s + t+1] == "?":
            cnt += 1
        else:
            continue
    if cnt == len(T):
        S = Sd.replace(Sd[s:s + len(T)], T, 1)
        S = S.replace("?", "a")
        print(S[::-1])
        flg = True
        break

if flg is False:
    print("UNRESTORABLE")


Measured memory_bytes: 3064
#include<stdio.h>

int main(){
	int a,s,d,f,g;
	scanf("%d %d %d %d %d", &a,&s,&d,&f,&g);
	if(a == 0){
		printf("1");
	}
	
	else if(s == 0){
		printf("2");
	}
	
	else if(d == 0){
		printf("3");
	}
	
	else if(f == 0){
		printf("4");
	}
	
	else if(g == 0){
		printf("5");
	}
	return 0;
}


Measured memory_bytes: 1584
using System;
class Program
{
  static void Main(string[] args)
  {
    if(Read()==1){
      Write("Hello World");
    }else{
      Write(Read()+Read());
    }
  }

  static void Write(string s) { Console.WriteLine(s); return; }
  static void Write(long n) { Console.WriteLine(n.ToString()); return; }
  static string ReadStr() { return Console.ReadLine(); }
  static string[] ReadStrs() { return Console.ReadLine().Split(' '); }
  static long Read() { return long.Parse(Console.ReadLine()); }
  static long[] Read(long n) {
    long[] p = new long[n];
    string[] t = Console.ReadLine().Split(' ');
    for(long i = 0; i < n; i++) { p[i] = long.Parse(t[i]); }
    return p;
  }
  static long abs(long n) { return (n > 0) ? n : -n; }
  static long gcd(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = gcd(p, n[i]); } return p; }
  static long gcd(long a, long b) { return (a==0)?b:gcd(b % a, a); }
  static long lcm(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = lcm(p, n[i]); } return p; }
  static long lcm(long a, long b) { return a * b / gcd(a, b); }
  static long max(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p>n[i])?p:n[i]; } return p; }
  static long min(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p<n[i])?p:n[i]; } return p; }
  static void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); }
  static void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); }
  static void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); }
  static string clip(string s, int start, int count) {
    if (start + count < s.Length) { s = s.Remove(start + count); }
    if (start > 0) { s = s.Remove(0, start); }
    return s;
  }
}


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

int main(){
  int a;
  int b;
  cin >> a >> b;
  
  if(a % 2 == 1 && b % 2 == 1){
    cout << "Odd" << endl;
  }
  else{
    cout << "Even" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool isPrime[1000000];

int main()
{
  int64_t X;
  cin >> X;
  for (int i = 2; i < 1000000; i++)
  {
    isPrime[i] = true;
  }
  for (int i = 2; i < 1000000; i++)
  {
    if (!isPrime[i])
      continue;
    for (int j = 2; i * j < 1000000; j++)
    {
      isPrime[i * j] = false;
    }
  }
  for (int i = X; i < 1000000; i++)
  {
    if (isPrime[i])
    {
      cout << i << endl;
      break;
    }
  }
}


Measured memory_bytes: 4636
N=int(input())
A=list(map(int,input().split()))
dp=[0]*(10**6+1)
A.sort()
A.append(10**9+7)
ans=0
for i in range(N):
  if dp[A[i]]==0:
    if A[i]!=A[i+1]:
      ans+=1
    for j in range(1,int(10**6//A[i])+1):
      dp[A[i]*j]+=1
print(ans)

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

int main()
{
    int a,b;
    cin>>a>>b;
    vector<int> v;

    for(int i=(b-a+1);i<=(a+b-1);i++)
    {
        v.push_back(i);
    }

    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i++)
        cout<<v[i]<<" ";
    cout<<endl;

    return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 100005
#define PI 	3.14159265358979323846

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll sum=0;
    ll maxV=0;
    REP(i,n){
        ll p;
        cin >> p;
        maxV = (ll)max(maxV,p);
        sum += p;
    }
    cout << sum-(maxV/2) << endl;
    return 0;
}

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

typedef long long ll;
#define INF INT_MAX
#define MAXN 100005

int N;
int memo[MAXN][4];
int arr[MAXN][4];

int dp(int r,int c)
{
    if(r == N)
        return arr[r][c];

    if(memo[r][c] > 0)
        return memo[r][c];

    int val = 0;
    for(int col = 1 ; col <= 3 ; col++){
        if(col == c)continue;
        val = max(val,dp(r+1,col));
    }
    memo[r][c] = val + arr[r][c];
    return memo[r][c];
}

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

    cin >> N;
    for(int i = 1 ; i <= N ; i++){
        for(int j = 1 ; j <= 3 ; j++){
            cin >> arr[i][j];
        }
    }
    cout << max({dp(1,1),dp(1,2),dp(1,3)}) << '\n';
    
    return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;

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

    if (a > b) swap(a, b);

    ll x = b;
    for (; x % a != 0; x += b) ;

    cout << x << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,f;
int main()
{
	cin>>a>>b>>c>>d>>e;
	f=c-a;
	if (f<0) f=0-f;
	if ((b-d)*e>=f) printf("YES\n");
	else printf("NO\n");
	return 0;
}


Measured memory_bytes: 3624
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())

pattern = []
score = 0

for t in T:
    if t == 'r':
        pattern.append('p')
    elif t == 's':
        pattern.append('r')
    else:
        pattern.append('s')

double = []
single = []
for i in range(K, N - K):
    if pattern[i] == pattern[i - K] and pattern[i] == pattern[i + K]:
        pattern[i] = ''

for i in range(K, N):
    if pattern[i] == pattern[i - K]:
        pattern[i] = ''

for p in pattern:
    if p == 'r':
        score += R
    elif p == 's':
        score += S
    elif p == 'p':
        score += P

print(score)

Measured memory_bytes: 50060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(p,a,b)    for(int p=a;p<b;p++)
#define INF 0x3f3f3f3f
#define N 100007


int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("o2.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n,k,d,i,sum=0,x;
    map<int,int>m;

    cin>>n>>k;
    while(k--)
    {
        cin>>d;
        for(i=0 ; i<d ; i++)
        {
            cin>>x;
            if(m[x]==0){m[x]=1;sum++;}
        }
    }
    cout<<n-sum;
    return 0;
}

Measured memory_bytes: 3668
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
	int n,W;cin>>n>>W;
	int dp[10001];
	for(int i=0;i<=W;i++)dp[i]=0;
	int v[100],w[100],m[100];
	for(int i=0;i<n;i++)cin>>v[i]>>w[i]>>m[i];
	for(int i=0;i<n;i++)
	{
		int num=m[i];
		for(int k=1;num>0;k<<=1)
		{
			int mul=min(num,k);
			for(int j=W;j>=w[i]*mul;j--)
			{
				dp[j]=max(dp[j],dp[j-w[i]*mul]+v[i]*mul);
			}
			num-=mul;
		}
	}
	cout<<dp[W]<<endl;
	return 0;
}

Measured memory_bytes: 3136
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>

using namespace std;

#define REP(var, count) for(int var=0; var<count; var++)

int dp[1010][1010];

int main(void) {
	int Q;
	cin >> Q;
	
	REP(data, Q) {
		
		string xstr, ystr;
		cin >> xstr;
		cin >> ystr;
		
		for(int x=0; x<xstr.size()+1; x++) {
			dp[x][0] = 0;
			
			for(int y=1; y<ystr.size()+1; y++) {
				if (x==0) { dp[0][y] = 0; continue; }
				
				if ( xstr[x-1] == ystr[y-1] ) {
					dp[x][y] = dp[x-1][y-1] + 1;
				} else {
					dp[x][y] = max(dp[x-1][y], dp[x][y-1]);
				}
				
			}
		}
		
		cout << dp[xstr.size()][ystr.size()] << endl;
	}

}

Measured memory_bytes: 7080
#include "bits/stdc++.h"
using namespace std;
const int N = 10;
int n , m;
char str[N][N];
char tmp[N][N];
void check(){
    for(int i = 1 ; i <= n ; ++i){
        for(int j = 1 ; j <= m ; ++j){
            if(tmp[i][j] != str[i][j]){
                return;
            }
        }
    }
    printf("Possible\n");
    exit(0);
}
void go(int x , int y){
    tmp[x][y] = '#';
    if(x == n && y == m){
        check();
    }
    if(x < n){
        go(x + 1 , y);
    }
    if(y < m){
        go(x , y + 1);
    }
    tmp[x][y] = '.';
}
int main(){
    scanf("%d %d" , &n , &m);
    for(int i = 1 ; i <= n ; ++i){
        scanf("%s" , str[i] + 1);
    }
    for(int i = 1 ; i <= n ; ++i){
        for(int j = 1 ; j <= m ; ++j){
            tmp[i][j] = '.';
        }
    }
    go(1 , 1);
    printf("Impossible\n");
}

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

int main(){
    ll inf = 300000000000;
    ll N, M, L;
    cin >> N >> M >> L;
    vector<vector<ll>> dist(N+1, vector<ll>(N+1, inf));
    for (int i = 1; i <= N; i++) dist[i][i] = 0;
    for (int i = 0; i < M; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        dist[a][b] = c;
        dist[b][a] = c;
    }
    for (int k = 1; k <= N; k++){
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= N; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    
    vector<vector<ll>> fill(N+1, vector<ll>(N+1, inf));
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            if (dist[i][j] <= L) fill[i][j] = 0;
        }
    }
    
    for (int k = 1; k <= N; k++){
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= N; j++) {
                fill[i][j] = min(fill[i][j], fill[i][k] + fill[k][j] + 1);
            }
        }
    }
    
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int s, t;
        cin >> s >> t;
        if (fill[s][t] == inf) {
            cout << "-1\n";
            continue;
        }
        cout << fill[s][t] << endl;
        
    }
}


Measured memory_bytes: 1920
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 3e18;
const double INFD = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1);
const int MOD = 998244353;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 10;
const int MAXV = 3;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;
char _mpp[MAXN][MAXN];
char _tmp[MAXN][MAXN];
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    scanf("%d%d%d", &n, &m, &k);
    for (int i = 0; i < n; i++) {
        scanf("%s", _mpp[i]);
    }
    int ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < (1 << m); j++) {
            memcpy(_tmp, _mpp, sizeof(_mpp));
            for (int a = 0; a < n; a++) {
                if ((i >> a) & 1) {
                    for (int t = 0; t < m; t++) _tmp[a][t] = 'R';
                }
            }
            for (int a = 0; a < m; a++) {
                if ((j >> a) & 1) {
                    for (int t = 0; t < n; t++) _tmp[t][a] = 'R';
                }
            }
            int cnt = 0;
            for (int a = 0; a < n; a++)
                for (int b = 0; b < m; b++) cnt += (_tmp[a][b] == '#');
            if (cnt == k) {
                ans++;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3808
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x;
	cin>>n>>x;
	int count=1;
	int sum=0;
	for(int i=0;i<n;i++){
		int temp;
		cin>>temp;
		sum+=temp;
		if(sum<=x){
			count++;
		}
	}
	cout<<count;
	return 0;
}

Measured memory_bytes: 256
// C - Many Requirements
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	int ans,N,M,Q; cin>>N>>M>>Q;
	vi a(Q),b(Q),c(Q),d(Q);
	rep(i, Q) cin>>a[i]>>b[i]>>c[i]>>d[i];
	vi bin(N+M-1, 1);
	rep(i, M-1) bin[i] = 0;
	ans = 0;
	do{
		vi A(1); // 1 origin
		for(int count=0, i=0; i<N+M-1; ++i){
			if(bin[i]) A.push_back(count);
			else count++;
		}
		int now = 0;
		rep(i, Q) if(c[i] == A[b[i]] - A[a[i]]) now += d[i];
		ans = max(ans, now);
	} while(next_permutation(bin.begin(), bin.end()));
	cout<< ans <<endl;
}


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

int main() {
  int a[3][3];
  REP(i,3){
    REP(j,3) cin>>a[i][j];
  }
  int n; cin>>n;
  int b[n];
  REP(i,n){
    cin>>b[i];
    REP(j,3){
      REP(k,3){
        if(a[j][k]==b[i]) a[j][k]=0;
        else continue;
      }
    }
  }
  
  if((a[0][0]+a[0][1]+a[0][2]==0)||
     (a[1][0]+a[1][1]+a[1][2]==0)||
     (a[2][0]+a[2][1]+a[2][2]==0)||
     (a[0][0]+a[1][0]+a[2][0]==0)||
     (a[0][1]+a[1][1]+a[2][1]==0)||
     (a[0][2]+a[1][2]+a[2][2]==0)||
     (a[0][0]+a[1][1]+a[2][2]==0)||
     (a[0][2]+a[1][1]+a[2][0]==0)) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

}

Measured memory_bytes: 256