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

using namespace std;

typedef long long int64;

const int64 INF = 1LL << 58;

template< typename T >
struct SegmentTree
{
  const T INF;

  vector< T > seg;
  int sz;

  SegmentTree(int n) : INF(numeric_limits< T >::max() / 10)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz - 1, INF);
  }

  T merge(T a, T b)
  {
    return (min(a, b));
  }

  void set(int k, int x)
  {
    seg[k + sz - 1] = x;
  }

  void build()
  {
    for(int k = sz - 2; k >= 0; k--) {
      seg[k] = merge(seg[2 * k + 1], seg[2 * k + 2]);
    }
  }

  T rmq(int a, int b, int k, int l, int r)
  {
    if(a >= r || b <= l) return (INF);
    if(a <= l && r <= b) return (seg[k]);
    return (merge(rmq(a, b, 2 * k + 1, l, (l + r) >> 1),
                  rmq(a, b, 2 * k + 2, (l + r) >> 1, r)));
  }

  T rmq(int a, int b)
  {
    return (rmq(a, b, 0, 0, sz));
  }

  void update(int k, T x)
  {
    k += sz - 1;
    seg[k] = x;
    while(k > 0) {
      k = (k - 1) >> 1;
      seg[k] = merge(seg[2 * k + 1], seg[2 * k + 2]);
    }
  }
};


int main()
{
  int64 N, T, E, X[100002];

  cin >> N >> T >> E;
  for(int i = 1; i <= N; i++) cin >> X[i];

  /*
  int64 dp[2002][2002]; // curr, pending
  fill_n(*dp, 2002 * 2002, INF);
  dp[1][0] = 0;
  dp[1][1] = E;

  auto chmin = [](int64 &a, int64 b)
  {
    a = min(a, b);
  };

  for(int i = 2; i <= N; i++) {
    for(int j = 0; j < i; j++) {
      chmin(dp[i][j], dp[i - 1][j]);
      chmin(dp[i][i], dp[i - 1][j] + max(E, (X[i] - X[j + 1]) * 2));
    }
  }
  // dp[j]+(X[i]-X[j+1])*2 = dp[j]-X[j+1]*2+X[i]*2
  // dp2[j]=dp[j]-X[j+1]*2
  */


  SegmentTree< int64 > dp1(N + 1), dp2(N + 1);

  dp1.update(0, 0);
  dp1.update(1, E);
  dp2.update(0, dp1.rmq(0, 1) - X[1] * 2);
  dp2.update(1, dp1.rmq(1, 2) - X[2] * 2);
  int tail = 0;

  for(int i = 2; i <= N; i++) {
    int low = 0, high = i - 1;
    while((X[i] - X[tail + 1]) * 2 > E) ++tail;
    dp1.update(i, min(dp1.rmq(tail, i) + E, X[i] * 2 + dp2.rmq(0, tail)));
    dp2.update(i, dp1.rmq(i, i + 1) - X[i + 1] * 2);
  }
  cout << dp1.rmq(N, N + 1) + T << endl;
}

Measured memory_bytes: 5120
N = gets.to_i
S = gets.chomp
R = Array.new(N + 1, 0)
(1 .. N).each do |n|
  if S[n - 1] == 'R'
    R[n] = R[n - 1] + 1
  else
    R[n] = R[n - 1]
  end
end

dp = Array.new(N + 1, 0)
(0 .. N).each do |n|
  lw = n - R[n]
  rr = R[N] - R[n]
  dp[n] = [lw, rr].min + (lw - rr).abs
end
puts dp.min


Measured memory_bytes: 17720
//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
#include <climits>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define F first
#define S second
#define OUT(x) cout << x << "\n"
using namespace std;
using point = pair< int,int >;
using ll = long long;

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

    OUT(min(b, a * n));
    return 0;
}



Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())
    A = []
    for _ in range(N):
        A.append(input())
    B = []
    for _ in range(M):
        B.append(input())
    for i in range(N-M+1):
        for j in range(N-M+1):
            isMatch = True
            for k in range(M):
                for l in range(M):
                    if A[i+k][j+l] != B[k][l]:
                        isMatch = False
                        break
            if isMatch:
                return "Yes"
    return "No" 


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3064
n=int(input())
c=list(map(int, input().split()))
ans = 0
ans2 = 0

for i in c:
    if i%2 == 0:
        ans += 1
        if i%3 ==0 or i%5 == 0:
            ans2 += 1

if ans == ans2:
    print('APPROVED')
if ans != ans2:
    print('DENIED')

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

int main(){
    int a, b, c, n;
    cin >> a >> b >> c >> n;
    for(int i = 0; i < n; i++){
        if(a > b && a > c) a *= 2;
        else if(b > c) b *= 2;
        else c *= 2;
    }
    cout << a + b + c << endl;
    return 0;
}

Measured memory_bytes: 256
def sosuu(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n+1):
        j = i + i
        while j <= n:
            is_prime[j] = False
            j += i
    return [p for p in range(n+1) if is_prime[p]]

primes = sosuu(300000)
import bisect
x = int(input())

print(primes[bisect.bisect_left(primes, x)])

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

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

const int INF = 1e8;
const int K = 410;

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  vector<int> a(N), b(N), c(N);
  REP(i,N) cin >> a[i] >> b[i] >> c[i];

  vector<vector<vector<int>>> dp(N + 1, vector<vector<int>> (K, vector<int> (K, INF)));
  dp[0][0][0] = 0;
  REP(i,N)REP(ca,K)REP(cb,K) {
    if(dp[i][ca][cb] == INF) continue;
    dp[i + 1][ca][cb] = min(dp[i + 1][ca][cb], dp[i][ca][cb]);
    dp[i + 1][ca + a[i]][cb + b[i]] = min(dp[i + 1][ca + a[i]][cb + b[i]], dp[i][ca][cb] + c[i]);
  }

  int res = INF;
  REP(ca,K)REP(cb,K) {
    if(ca == 0 || cb == 0) continue;
    if(ca * B == cb * A) res = min(res, dp[N][ca][cb]);
  }
  if(res == INF) res = -1;
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 28416
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

using namespace std;

typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "[ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "]";

    return os;
}

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

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

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


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int N, K;
    cin >> N >> K;

    vector<ll> H(N);
    REP(i, N) cin >> H[i];

    sort(H.begin(), H.end(), greater<ll>());

    ll ans = 0;
    FOR(i, K, N) ans += H[i];

    cout << fixed << setprecision(20);
    cout << ans << endl;

}


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

#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i,p,k) for (int i = p; i <= (int)(k); ++i)
#define FOREACH(it,x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); ++it)
#define ALL(x) x.begin(), x.end()

template<class K, class V> ostream& operator<<(ostream& os, const pair<K,V>& p) { os << '<' << p.first << ',' << p.second << '>'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { REP(i,v.size()) os<<'['<<v[i]<<']'; return os; }
template<class K, class V> ostream& operator<<(ostream& os, const map<K,V>& m) { FOREACH(it,m) os<<'{'<<it->first<<':'<<it->second<<'}'; return os; }
#define DEBUG(x) cerr<<#x":"<<(x)<<" "

template<class T> void DUMP(const T& v) { FOREACH(it,v) cerr<<*it<<' '; cerr<<endl; }

typedef pair<int, int> pt;
#define x first
#define y second

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

int main() {
  int w, h, W, H;
  while (cin >> w >> h, w && h) {
    W = 2*w-1;
    H = 2*h-1;
    vector<string> room(H);
    vector<vector<int> > visited(H, vector<int>(W));
    getline(cin, room[0]);
    REP(i, H) {
      getline(cin, room[i]);
      if (i % 2 == 0) room[i] += ' ';
    }
    // DEBUG(room);
    vector<pt> cur(1, pt(0,0));
    vector<pt> nex;
    int res = 0;
    for (int level = 0; cur.size(); level++) {
      //DEBUG(cur)<<endl;
      nex.clear();
      REP(i, cur.size()) {
        int x = cur[i].x;
        int y = cur[i].y;
        if (visited[y][x]) continue;
        visited[y][x] = 1;
        if (x == W-1 && y == H-1) {
          res = level+1;
          break;
        }
        REP(d, 4) {
          int nx = x + dx[d];
          int ny = y + dy[d];
          if (nx < 0 || nx >= W || ny < 0 || ny >= H || room[ny][nx] == '1') continue;
          nex.push_back(pt(nx+dx[d], ny+dy[d]));
        }
      }
      cur.swap(nex);
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int p, cnt = 0;
    for(int i=1;i<=n;i++){
        cin >> p;
        if(p != i) cnt++;
    }
    if(cnt <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <vector>
using namespace std;

int digits(long long n){
    int sum = 0;
    while (n > 0) {
        n /= 10;
        sum++;
    }
    return sum;
}

int main()
{
    long long n;
    cin >> n;
    
    int result = 0;
    result = digits(n);
    
    for (long long i = 1; i * i <= n; i++) {
        if (n % i != 0) {
            continue;
        }
        
        long long j = n / i;
        int sum = max(digits(i), digits(j));
        if (result > sum) {
            result = sum;
        }
    }
    cout << result << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_set>
using namespace std;
int main() {
  int n; string s;
  cin >> n;
  unordered_set<string> diff;
  while (n--) {
    cin >> s;
    if (diff.find(s) == diff.end()) {
      diff.insert(s);
    }
  }
  cout << diff.size();
}

Measured memory_bytes: 13796
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
ll n,m,ans;
ll a[200005],b[200005];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        cin>>b[n-i+1];
    }
    ll l=1;
    for(int i=1;i<=n;i++){
		if(a[i]!=b[i])continue;
		while(!(a[i]==b[i]&&a[i]!=a[l]&&b[i]!=b[l])){
			l++;
			if(l>n){
				cout<<"No";
				//system("pause");
				return 0;
			}
		}
		swap(b[l],b[i]);
	}
	cout<<"Yes\n";
	for(int i=1;i<=n;i++)cout<<b[i]<<" ";
    //system("pause");
    return 0;
}


Measured memory_bytes: 6728
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def factorial(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
n,x = inp
t = (inp.push(x)).sort
m = []
(t.size-1).times do |i|
  m.push(t[i+1]-t[i])
end
p m.inject(:gcd)

Measured memory_bytes: 11776
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

s = S()
W = ['SUN','MON','TUE','WED','THU','FRI','SAT']
for i in range(len(W)):
    if s == W[i]:
        print(7-i)


Measured memory_bytes: 38256
n = int(input())
keta = len(str(n))

if keta <= 2:
    print(0)
else:
    # keta-1までのパターン
    ans = 0
    for k in range(3, keta):
        ans += pow(3, k) - 3 - (3*(pow(2, k) - 2))

    from itertools import product
    for l in product(['3', '5', '7'], repeat=keta):
        if not '3' in l or not '5' in l or not '7' in l:
            continue
        nn = int(''.join(l))
        if nn <= n:
            ans += 1

    print(ans)


Measured memory_bytes: 73872
#include <iostream>
#include <cstring>

using namespace std;

const int MOD = 1000000007;

int main(){
	static long long comb[2001][2001];
	static long long pow2[2001];
	memset(comb, 0, sizeof(comb));
	comb[0][0] = 1;
	for(int i=1;i<=2000;i++){
		comb[i][0] = 1;
		for(int j=1;j<i;j++) comb[i][j] = (comb[i-1][j] + comb[i-1][j-1])%MOD;
		comb[i][i] = 1;
	}
	pow2[0] = 1;
	for(int i=1;i<=2000;i++) pow2[i] = (pow2[i-1]*2)%MOD;
	static long long dp[2][2001][2001];
	memset(dp, 0, sizeof(dp));
	for(int i=0;i<=2000;i++){
		for(int j=0;j<=2000;j++){
			if(i==0 && j==0){
				dp[0][i][j] = 1;
				dp[1][i][j] = 0;
			} else {
				if(i > 0) dp[0][i][j] = (dp[0][i][j] + dp[0][i-1][j]) % MOD;
				if(i > 0) dp[0][i][j] = (dp[0][i][j] + dp[1][i-1][j]) % MOD;
				if(j > 0) dp[0][i][j] = (dp[0][i][j] + dp[0][i][j-1]) % MOD;
				if(i > 0) dp[1][i][j] = (dp[0][i-1][j+1] + dp[1][i-1][j+1]) % MOD;
			}
		}
	}
	int N, K;
	while(cin >> N >> K){
		long long res = 0;
		for(int end=N-K+1;end<=N;end++){
			int all = end-1;
			int sel = N-K;
			long long add = (sel > 0 ? comb[all-1][sel-1] * pow2[sel-1] % MOD : 1);
			int b = end-(N-K+1);
			int r = K-1-b;
			add = (add * dp[0][r][b]) % MOD;
			res = (res + add) % MOD;
			if(sel == 0) break;
		}
		cout << res << endl;
	}
}


Measured memory_bytes: 94080
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#include<set>
#include<map>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const int N = 1e5 + 3;
char s[N]; 
inline int read(){
	int v = 0,c = 1;char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-') c = -1;
		ch = getchar();
	}
	while(isdigit(ch)){
		v = v * 10 + ch - 48;
		ch = getchar();
	}
	return v * c;
}
int main(){
	scanf("%s",s + 1);
	int l = 1,r = strlen(s + 1);int ans = 0;
	while(l < r){
		ans += (s[l] != s[r]);
		l++,r--;	
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fill(a)  memset(a, 0, sizeof (a))
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
const ll mod = 1e9+7;
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll tt=1;
        // cin >> tt;
    while((tt)--){
     	ll a,p; cin >> a >>p;
     	ll t = a*3+p;
     	cout << t/2 << endl;
    }
}

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

int main(){
    int N,M;
    cin >> N >> M;
    int sum = 0;
    for(int i=1;i<N;++i){
        sum = sum + i;
    }
    for(int j=1;j<M;++j){
        sum = sum + j;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorders
{
	public class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			var w = new string[n];
			for (int i = 0; i < n; i++) {
				w[i] = Console.ReadLine();
			}

			var hash = new HashSet<string>();
			for (int i = 0; i < n; i++) {
				if (hash.Contains(w[i])) {
					Console.WriteLine("No");
					return;
				}

				if (i != 0) {
					if (w[i - 1][w[i - 1].Length - 1] != w[i][0]) {
						Console.WriteLine("No");
						return;
					}
				}

				hash.Add(w[i]);
			}

			Console.WriteLine("Yes");
		}
	}
}

Measured memory_bytes: 13280
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long A = sc.nextLong();
    long B = sc.nextLong();
    
    long ans;
    if(N % (A+B) < A)
      ans = N / (A+B) * A + N % (A+B);
    else
      ans = N / (A+B) * A + A;
    
    System.out.println(ans);
    
  }
}

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

int main(void) {
	int a, b;
	cin >> a >> b;
	if(a > b) {
		cout << "a > b" << endl;
	}
	else if(a < b) {
		cout << "a < b" << endl;
	}
	else if(a == b) {
		cout << "a == b" << endl;
	}
	return 0;
}


Measured memory_bytes: 3100
#include <stdio.h>

int main(){
  
  int a, b, c;
  int count = 0;
  //int flag = 1;
  
  scanf("%d %d %d",&a,&b,&c);
  
  
  if(c > a){
    count = a;
    c = c - a;
    if(c > b){
      count = count + 2*b + 1;
    }
    else{
      count = count + b + c;
    }
    
  } 
  else{
    count = c + b;
   
    }
  
  printf("%d",count);
  
  
  

  return 0;
}

    
    


Measured memory_bytes: 128
#include <iostream>

using namespace std;

typedef long long ll;

ll a, b, ans = 1;

ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}

int main() {
  cin >> a >> b;
  ll d = gcd(a, b);
  
  if (d == 1) {
    cout << 1 << endl;
    return 0;
  }
  
  for (ll i = 2; i * i <= d; i++) {
    if (d % i) continue;
    ans++;
    while (d % i == 0) {
      d /= i;
    }
  }
  if (d != 1) ans++;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    while(true){
      int a = sc.nextInt();
      String op = sc.next();
      int b = sc.nextInt();

      if(op.equals("?")) break;

      switch(op){
        case "+" : System.out.println(a+b);
                   break;
        case "-" : System.out.println(a-b);
                   break;
        case "*" : System.out.println(a*b);
                   break;
        case "/" : System.out.println(a/b);
      }
    }
  }
}


Measured memory_bytes: 26216
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int a,l,c,t,c1,t1,flag=0;
   cin>>a>>l;
    for(int i=0;i<=a;i++)
    {
        c=a-i;
        t=a-c;
        c1=c*2;
        t1=t*4;
        if(c1+t1==l)
        {flag=1;}
    }
    if(flag==1)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

Measured memory_bytes: 3620
/*
ID: alec3
LANG: C++14
PROG:
*/


#include <bits/stdc++.h>

#define check(x) cout<<(#x)<<": "<<x<<" ";
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ss second
#define ff first
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define ld long double
#define all(c) (c).begin(), (c).end()
#define FOR(i, a, b) for (int i = a; i < b; i++)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;


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

    int ans = 0, c = 0;
    for (int i = 0; i < s.size(); i++){
        if (s[i] == 'R')
            c ++;
        else {
            ans = max(ans, c);
            c = 0;
        }
    }
    ans = max(c, ans);
    cout << ans << endl;

    return 0;

}



Measured memory_bytes: 3644
N = int(input())
S = input()
B = []
for i in range(len(S)):
    if ord(S[i])+N<=ord('A')+25:
        B.append(chr(ord(S[i])+N))
    else:
        B.append(chr(ord(S[i])+N-26))
print(''.join(B))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int N=1e6+5; 
int a[N];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	ll sum=0;
	int tep=a[1];
	for(int i=2;i<=n;i++){
		if(a[i]<tep)sum+=tep-a[i];
		else tep=a[i];
	}
	cout<<sum<<endl;
} 

Measured memory_bytes: 4432
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef vector<int64_t> vi;
typedef pair< int64_t,int64_t> ii;
typedef vector<pair<int64_t, int64_t> > vp;
typedef vector<pair<int64_t, ii> > vpp;
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define INF 1e9
#define SIZE 200001
#define mod 1000000007
#define int int64_t
#define sz(x)       (int)x.size()
void solve();
int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    solve();
    return 0;
}
void solve()
{
    int r;
    cin>>r;
    cout<<3*r*r<<"\n";
}


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

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++)
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;


const int MAX_N = 1e5 + 100;

int N; ll Nr[MAX_N * 3], SumL[MAX_N * 3], SumR[MAX_N * 3];
int main() {
	cin >> N;
	REP(i, 3*N) scanf("%lld", &Nr[i]);
	priority_queue<ll, vector<ll>, greater<ll>> lq;
	priority_queue<ll> rq;

	for(int i=0; i<N; i++) {
		if(i) SumL[i] = SumL[i-1];
		SumL[i] += Nr[i];
		lq.push(Nr[i]);
	}
	for(int i=N; i<3*N; i++) {
		SumL[i] = SumL[i-1] + Nr[i];
		lq.push(Nr[i]);
		SumL[i] -= lq.top();
		lq.pop();
	}
	for(int i=3*N-1; i>=2*N; i--) {
		SumR[i] = SumR[i+1] + Nr[i];
		rq.push(Nr[i]);
	}
	for(int i=2*N-1; i>=0; i--) {
		SumR[i] = SumR[i+1] + Nr[i];
		rq.push(Nr[i]);
		SumR[i] -= rq.top();
		rq.pop();
	}
	ll ans = -LINF;
	for(int i=N-1; i<2*N; i++)
		ans = max(ans, SumL[i] - SumR[i+1]);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 8948
#B
n = int(input())
robot = []
for i in range(n):
    x,l = map(int,input().split())
    robot.append([x,l])
    
arm = [(x+l, x-l) for x,l in robot]
    
arm.sort()

max_r = -float('inf')
result = 0

for i in range(n):
    r,l = arm[i]
    if max_r <= l:
        result += 1
        max_r = r
        
print(result)
        

Measured memory_bytes: 33584
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			int[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

			long ans = 0;
			int count = 0;
			int xor = 0;
			int sum = 0;
			for (int i = 0; i < n; i++) {
				int tempXor = a[i] ^ xor;
				int tempSum = a[i] + sum;
				++count;
				if (tempXor == tempSum) {
					ans += count;
					xor = tempXor;
					sum = tempSum;
				} else {
					while (count > 1) {
						xor -= a[i - count + 1];
						sum -= a[i - count + 1];
						count--;

						int temp2Xor = a[i] ^ xor;
						int temp2Sum = a[i] + sum;
						if (temp2Xor == temp2Sum) {
							ans += count;
							xor = temp2Xor;
							sum = temp2Sum;
							break;
						}
					}
				}
			}

			Console.WriteLine(ans);
		}
	}
}


Measured memory_bytes: 32860
#include <iostream>
 
using namespace std;
 
inline int f(int n){
  if(n % 2 == 0) return n / 2;
  else return 3 * n + 1;
}
 
int main(){
  int s, count = 1, twice = 2;
  cin >> s;
  // 特殊ケース
  if(s == 1 || s == 2 || s == 4)
  {
    count = 4;
    twice = 0;
  }
  // 4が二回出たら終了
  while(twice)
  {
    s = f(s);
    count++;
    if (s == 4) twice--;
  }
  cout << count;
}

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

int N, K;
int A[500];
int r[500];
vector<int> ds;

int main() {
  cin >> N >> K;
  rep(i, N) {
    cin >> A[i];
  }
  int sum = accumulate(A, A+N, 0);
  for(int i=1; i*i<sum; i++) {
    if(sum % i == 0) {
      ds.push_back(i);
      ds.push_back(sum/i);
    }
  }
  sort(ds.begin(), ds.end(), greater<int>());
  for(int i=0; i<ds.size(); i++) {
    int d = ds[i];
    rep(i, N) {
      r[i] = A[i] % d;
    }
    sort(r, r+N);
    int st=0;
    int en=N-1;
    int num=0;
    while(st != en) {
      int ch = min(r[st], d-r[en]);
      r[st] -= ch;
      r[en] += ch;
      if(r[st] == 0) {
        st++;
      } else {
        en--;
      }
      num += ch;
    }
    if(num <= K) {
      cout << d << endl;
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
vector<int> graph[200010];
vector<ll> value(200010);

void dfs(int from, int to){
    for(auto next:graph[to]){
        if(from == next)continue;
        value[next] += value[to];
        dfs(to, next);
    }
}
main(){
    int N,Q;
    cin >> N >> Q;
    rep(i,0,N-1){
        int u,v;
        cin >> u >> v;
        u--,v--;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    rep(i,0,Q){
        int p,x;
        cin >> p >> x;
        value[p-1] += x;
    }
    dfs(-1, 0);

    rep(i,0,N)cout << value[i] << " ";
}

Measured memory_bytes: 24320
import sys
input = sys.stdin.readline

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

B = [input().rstrip() for _ in range(H)]


def get_black(X, Y):
    ret = 0
    for i in range(W):
        for j in range(H):
            if i in X or j in Y: continue
            if B[j][i] == '#': ret += 1
    return ret

ans = 0

for i in range(1 << W):
    for j in range(1 << H):
        X = set()
        Y = set()
        for x in range(W):
            if (1 << x) & i: X.add(x)
        for y in range(H):
            if (1 << y) & j: Y.add(y)

        if get_black(X, Y) == K:
            ans += 1
print(ans)

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;

#define NIL NULL

Node root;

//データ挿入関数
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->parent = y;

  if(y == NIL){//Tが空の場合
    root = z;
  }
  else if(z->key < y->key){
    y->left = z;//zをyの左の子にする
  }
  else{
    y->right = z;//zをyの右の子にする
  }
}

//データ出力関数（中間順巡回）
void inorder(Node u){
  if(u == NIL){
    return;
  }
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right); 
}

//データ出力関数（先行順巡回）
void preorder(Node u){
  if(u == NIL){
    return;
  }
  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] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    
    //データの出力（2パターン）
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



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

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

  int t = a * n;

  cout << min(t, b) << endl;
  return 0;
}

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

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

int main()
{
  int n;
  cin >> n;
  for(int i = 1; i < 10; ++i)
  {
    for(int j = 1; j < 10; ++j)
    {
      if(i * j == n)
      {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        long k = sc.nextLong();
        int idx = 0;
        while(idx < k-1) {
            if(s.charAt(idx) != '1')
                break;
            idx++;
        }
        System.out.println(s.charAt(idx));
    }
}


Measured memory_bytes: 22612
S, K = map(int, [input() for i in range(2)])
count = 0
a = 0

for i in str(S):
    if int(i) == 1:
        count += 1
        continue
    else:
        a = int(i)
        break

if count >= K:
    print(1)
else:
    print(a)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x[ohara],y[ohara],sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll X,Y;

//-------------------------↓↓↓↓↓↓------------------------

//------ 自分を天才だと信じる ------

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

    cin>>n>>m>>X>>Y;
    rep(i,n)cin>>x[i];
    rep(i,m)cin>>y[i];
    sort(x,x+n);
    sort(y,y+m);
    ans=y[0];
    if(x[n-1]<ans&&X<ans&&ans<=Y)Cout("No War");
    else Cout("War");
    return 0;
}


Measured memory_bytes: 2304
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String S = in.next();
            char c = S.charAt(0);
            int cnt = 0;
            for (int i = 1; i < S.length(); i++) {
                char s = S.charAt(i);
                if (s != c) {
                    c = s;
                    cnt++;
                }
            }
            out.println(cnt);
        }

    }
}



Measured memory_bytes: 24916
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String t = sc.nextLine();
		int sl = s.length();
		int tl = t.length();
		boolean b = false;
		if(sl < tl){
			System.out.println("UNRESTORABLE");
		}else if(sl == tl){
			if(contains(s,t,tl)){
				System.out.println(t);
			}else{
				System.out.println("UNRESTORABLE");
			}
		}else{
			String front = s.substring(0, sl-tl);
			String subS = s.substring(sl-tl);
			b= contains(subS, t, tl);
			if(b){
				s = front.replaceAll("\\?", "a") + t;
			}
			for(int i = sl; i >= tl && !b;i--){
				front = s.substring(0, i-tl);
				subS = s.substring(i - tl, i);
				String back = s.substring(i);
				b = contains(subS, t, tl);
				if(b){
					s = front.replaceAll("\\?", "a") + t + back.replaceAll("\\?", "a");
					break;
				}
			}
			if(b){
				System.out.println(s);
			}else{
				System.out.println("UNRESTORABLE");
			}
		}
		sc.close();
	}
 
	private static boolean contains(String subS, String t, int tl){
		boolean b = true;
		for(int l = 0; l < tl && b; l++){
			b &= subS.charAt(l) =='?' || subS.charAt(l) == t.charAt(l);
		}
 
		return b;
	}
}

Measured memory_bytes: 23636
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        
        int a = scan.nextInt();
        String op = scan.next();
        int b = scan.nextInt();
        
        if(op.equals("+")) System.out.println((long)(a+b));
        else System.out.println((long)(a-b));
    }
}


Measured memory_bytes: 23760
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair


const int N = (int)1e6;
int n;
ll a[N];

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    scanf("%d", &n);
    n *= 3;
    for (int i = 0; i < n; i++)
        scanf("%lld", &a[i]);
    sort(a, a + n);
    ll ans = 0;
    for (int i = n - 2; i >= n / 3; i -= 2)
        ans += a[i];
    printf("%lld\n", ans);


    return 0;
}

Measured memory_bytes: 4352
package main
 
import (
    "bufio"
    "os"
    "strconv"
    "fmt"
    "strings"
)
 
func insertionSort(a []int, n int, g int) ([]int, int) {
    cnt := 0
    for i := g; i < n; i++ {
        v := a[i]
        j := i -g
        for j >= 0 && a[j] > v {
            a[j+g] = a[j]
            j = j - g
            cnt++
        }
        a[j+g] = v
    }
    return a, cnt
}
 
func shellSort(a []int, n int) ([]int, []int, int) {
    cnt, tmp := 0, 0
    var g []int
    for h := 1; h <= n; h = 3*h+1 {
        g = append(g, 0)
        copy(g[1:], g[0:])
        g[0] = h
    }
    for i := 0; i < len(g); i++ {
        a, tmp = insertionSort(a, n, g[i])
        cnt += tmp
    }
    return a, g, cnt
}
 
func String(A []int) string {
    return strings.Trim(fmt.Sprint(A), "[]")
}
 
func Stringln(A []int) string {
    text := strings.Trim(fmt.Sprint(A), "[]")
    return strings.Replace(text, " ", "\n", -1)
}
 
func main() {
    n := 0
    scanner := bufio.NewScanner(os.Stdin)
    if scanner.Scan() {
        n, _ = strconv.Atoi(scanner.Text())
    }
    a := make([]int, n)
    for i := range a {
        if !scanner.Scan() {
            break
        }
        a[i], _ = strconv.Atoi(scanner.Text())
    }
        g, count := []int{}, 0
        a, g, count = shellSort(a, n)
        fmt.Println(len(g))
        fmt.Println(String(g))
        fmt.Println(count)
        fmt.Println(Stringln(a))
}


Measured memory_bytes: 61428
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <queue>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
using namespace std;
#define sL(i) i << 1
#define sR(i) i << 1 | 1
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<int, pair<int,int>> ppi;
const int MOD = 1e9 + 7;
const int INF = 2e9 + 5;

int h, w, k;
int sx, sy, fx, fy;
vector<string> grid;
vector<vector<int>> dist[4], rem[4], vis[4];

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
string D = "ESWN";

bool valid(int x, int y) {
    return 0 <= x && x < h && 0 <= y && y < w && grid[x][y] != '@';
}

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> h >> w >> k;
    cin >> sx >> sy >> fx >> fy;
    --sx; --sy; --fx; --fy;
    grid.resize(h);
    for (int i = 0; i < h; i++) {
        cin >> grid[i];
    }
    for (int i = 0; i < 4; i++) {
        dist[i].resize(h, vector<int>(w, INF));
        rem[i].resize(h, vector<int>(w, 0));
        vis[i].resize(h, vector<int>(w, false));
    }

    deque<ppi> q;
    q.emplace_back(0, pi(sx, sy));
    dist[0][sx][sy] = 0;
    rem[0][sx][sy] = 0;
    while (!q.empty()) {
        int dir = q.front().first;
        int x = q.front().second.first;
        int y = q.front().second.second;
        q.pop_front();
        if (vis[dir][x][y]) continue;
        vis[dir][x][y] = true;
        int curdist = dist[dir][x][y];
        int currem = rem[dir][x][y];
        // cout << D[dir] << " (" << x + 1 << "," << y + 1 << ")" << " " << curdist << " " << currem << endl;
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (!valid(nx, ny)) continue;
            bool w = true;
            int ndist = curdist + 1;
            int nrem = k - 1;
            if (i == dir && currem > 0) {
                w = false;
                ndist = curdist;
                nrem = currem - 1;
            }
            if (ndist < dist[i][nx][ny] || 
                (ndist == dist[i][nx][ny] && rem[i][nx][ny] < nrem)) {
                dist[i][nx][ny] = ndist;
                rem[i][nx][ny] = nrem;
                if (w) {
                    q.emplace_back(i, pi(nx, ny));
                } else {
                    q.emplace_front(i, pi(nx, ny));
                }
            }
        }
    }
    int ans = INF;
    for (int i = 0; i < 4; i++) {
        ans = min(ans, dist[i][fx][fy]);
    }
    if (ans == INF) ans = -1;
    cout << ans;
}

Measured memory_bytes: 54748
#include <bits/stdc++.h>
    #include <string>
          #define ll long long int
          #define N 3000000
          #define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
          #define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
          #define po pop_back
          #define pb push_back
          #define pp pair<ll,ll>
          #define lb lower_bound
          #define fi first
          #define se second
          #define debug(x) cout << #x << " = " << x << endl
          #define ub upper_bound
          #define ibs ios_base::sync_with_stdio(false)
          #define cti cin.tie(0)
          #define all(x) x.begin(),x.end()
          #define PI 3.14159265
          #define cot cout.tie(0)
          using namespace std;
         /**
          * @author :: Sawlani
          *
          */
           const ll M=1e9+7;
          ll fac[N+1];
ll modularExponentiation(ll x,ll n)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
ll modInverse(ll A)// when M is PRIME
{
    return modularExponentiation(A,M-2);
}

          void factorial()
          {
              fac[0]=1;
              fac[1]=1;
              f(i,2,N)
              fac[i]=(fac[i-1]*(i))%M;
          }

          int main()
          {
              factorial();

              ll x,y;
              cin >> x >> y;

              ll a,b;
              if((2*x-y)%3==0)
              {
                  a=(2*x-y)/3;
                  b=x-2*a;

              }
              else
              {
                  cout << 0 << endl;
                  return 0;

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

              // cout <<  a << " " << b << endl;
                ll ans=(fac[a+b]%M*modInverse(fac[a])%M)%M;
                 ans=(ans%M*modInverse(fac[b])%M)%M;

                cout << ans << endl;



          }


Measured memory_bytes: 23680
#include <bits/stdc++.h>
#define ll long long int
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define pb(v, a) v.push_back(a)
#define Sort(v) sort(v.begin(), v.end())

#define For(m) for (auto it = m.begin(); it != m.end(); it++)
#define mod 1000000007
using namespace std;

ll INF;

int main()
{
  INF = 1000000000000;
  ll n;
  ll w;
  cin >> n >> w;
  ll arr[n+1];
  ll value[n+1];
  ll sum1=0;
  fr(i,0,n)cin >> arr[i+1],cin >> value[i+1],sum1+=value[i+1];
  ll dp[n+1][sum1+1];
  fr(i,0,n+1)
  {
        fr(j,0,sum1+1)
        {
            if(i==0&j==0)
            {
                dp[i][j]=0;
            }
            else if(i==0)
            {
                dp[i][j]=INF;
            }
            else if(j==0)
            {
                dp[i][j]=0;
            }
            else if((j-value[i])>=0)
            {   
                dp[i][j]=min(dp[i-1][j],(dp[i-1][j-value[i]]+arr[i]));
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
           // cout << dp[i][j] << " ";
        }
        //cout << "\n";
  }
  ll max=0;
  fr(i,1,sum1+1)
  {
      if(dp[n][i]<=w)
      max=i;
  }
  cout << max;
  return 0;
}


Measured memory_bytes: 79104
A,B,C = map(int,input().split(' '))
num = 0
if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
    print(0)
elif A == B == C:
    print(-1)
elif A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
    while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
        A_c = A
        B_c = B
        C_c = C
        A = B_c /2 + C_c / 2
        B = A_c / 2 + C_c /2
        C = A_c /2 + B_c / 2
        num += 1
    print(num)

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

using namespace std;

int main(){
    int N, X, c, min;
    c = 0;
    min = 100000007;

    cin >> N >> X;
    int m[N];
    for(int i = 0; i < N; i++){
        cin >> m[i];
        X -= m[i];
        c++;
    }

    for(int i = 0; i < N; i++){
        if(m[i] < min){
            min = m[i];
        }
    }

    while(X >= min){
        X -= min;
        c++;
    }

    cout << c << endl;

    return 0; 
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

struct edge{
  int to, cost;
};

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

  vector<edge> G[N + 1];
  for(int i = 0; i < M; i++){
    int L, R, D;
    cin >> L >> R >> D;
    G[L].push_back(edge{R, D});
    G[R].push_back(edge{L, -D});
  }

  /*for(int i = 1; i <= N; i++){
    for(int j = 0; j < G[i].size(); j++){
      cout << i << j << " " << G[i][j].to << G[i][j].cost << endl;
    }
  }*/

  bool dfd[N + 1];
  fill(dfd, dfd + N + 1, false);
  ll pos[N + 1];

  int ind = 1;
  while(ind <= N){
    if(dfd[ind] == false){
      pos[ind] = 0LL;
      dfd[ind] = true;
      stack<int> st;
      st.push(ind);

      //dfs========================================
      while(st.size()){
        int p = st.top();
        st.pop();
        for(int i = 0; i < G[p].size(); i++){
          int t = G[p][i].to;
          int c = G[p][i].cost;
          if(dfd[t] == false){
            pos[t] = pos[p] + c;
            dfd[t] = true;
            st.push(t);
          }
          else{
            if(pos[t] != pos[p] + c){
              cout << "No" << endl;
              return 0;
            }
          }
        }
      }
      //============================================
    }
    else{
      ind++;
    }
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 9856
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> ind, d;
int k;
int solve() {
	int n, x, m;
	cin >> n >> x >> m;
	n--;
	for(int i=0; i<k; i++) {
		d[i] = ind[i] % m;
	}
	int acc = accumulate(d.begin(), d.end(), 0ll)*(n/k) + accumulate(d.begin(), d.begin()+(n%k), 0ll);
	int zero = count_if(d.begin(), d.end(), [](int t){return !t;})*(n/k) + count_if(d.begin(), d.begin()+(n%k), [](int t){return !t;});
	int sub = (x+acc)/m - x/m;
	return n-sub - zero;
}
int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int q;
	cin >> k >> q;
	ind.resize(k);
	d.resize(k);
	for(int i=0; i<k; i++) {
		cin >> ind[i];
	}
	while(q--)
		cout << solve() << '\n';
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
#define MXN 22
bool matrix[MXN][MXN];
ll dp[(1<<21)];
int N, bit[(1<<21)];

int bit_cnt(int mask)
{
	int ret = 0;
	for(int i=0; i<N; i++) 
		if(mask&(1<<i)) ret++;
	return ret;
}

ll calc(int mask)
{
	if(!mask) return 1ll;
	if(dp[mask]!=-1ll) return dp[mask];
	int man_no = bit[mask]-1;
	ll ret = 0ll;
	for(int i=0; i<N; i++) 
		if(matrix[man_no][i] and mask&(1<<i))
			ret+=calc(mask^(1<<i)), ret%=mod;
	return dp[mask] = ret%mod;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>N;
	for(int i=0; i<N; i++)
		for(int j=0; j<N; j++) cin>>matrix[i][j];

	for(int i=0; i<(1<<N); i++) dp[i] = -1ll, bit[i] = bit_cnt(i);

	cout << calc((1<<N)-1) << '\n';

	//cout << bit_cnt(7) << '\n';
	return 0;
}

Measured memory_bytes: 24832
package main

import (
	"fmt"
)

func calcWa(n int) int {
	var sum int
	for n > 0 {
		sum += n % 10
		n /= 10
	}
	return sum
}

func main() {
	var N, A, B int
	var sum int

	fmt.Scan(&N)
	fmt.Scan(&A)
	fmt.Scan(&B)

	for i := 1; i <= N; i++ {
		if wa := calcWa(i); A <= wa && wa <= B {
			sum += i
		}
	}

	fmt.Println(sum)
}

Measured memory_bytes: 512
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

S = input()
op = ["+", "-"]

def exec():
    for a in op:
        for b in op:
            for c in op:
                exp = S[0:1] + a + S[1:2] + b + S[2:3] + c + S[3:4]
                if eval(exp) == 7:
                    return exp + "=7"

print(exec())

Measured memory_bytes: 3700
fun main(arg: Array<String>) {
    val N = nextInt()
    val A = listOfDouble()
    println(1.0 / A.fold(0.0) { acc, value -> acc + 1.0 / value})
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfDouble() = listOfString().map { java.lang.Double.parseDouble(it) } //{ it.toDouble() }


Measured memory_bytes: 38036