akhauriyash/Code-Regression huggingface dataset:
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var ans = xArray("[]",n-1);
  for(var i = 0; i < n; i++){
    for(var j = i+1; j < n; j++){
      var t = 1, b = i^j;
      while(b%2 === 0)b >>= 1, t++;
      ans[i][j-i-1] = t;
    }
  }
  return ans.map(a=>a.join(" ")).join("\n");
}

Measured memory_bytes: 15692
using System;
class Program
{
    static void Main(string[] args)
    {
        // スペース区切りの整数の入力
        string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);
        int c = int.Parse(input[2]);

        swap(ref a, ref b);
        swap(ref a, ref c);

        Console.WriteLine(a + " " + b + " " + c); ;
        
    }
    public static void swap(ref int a,ref int b)
    {
        int tmp = 0;
        tmp = a;
        a = b;
        b = tmp;
    }
}

Measured memory_bytes: 11220
n, m = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(m)]

class UnionFind:
    def __init__(self, n):
        self.root = list(range(n))
        self.size = [1] * (n)
    def find_root(self, x):
        root = self.root
        while root[x] != x:
            root[x] = root[root[x]]
            x = root[x]
        return x
    def merge(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        sx,sy = self.size[x],self.size[y]
        if sx < sy:
            self.root[x] = y
            self.size[y] += sx
        else:
            self.root[y] = x
            self.size[x] += sy
    def same(self, x, y):
        return self.find_root(x) == self.find_root(y)

uf = UnionFind(n)
p = n * (n-1) // 2
ans = [p]
for ai, bi in reversed(ab):
    a_root = uf.find_root(ai-1)
    b_root = uf.find_root(bi-1)
    if a_root != b_root:
        a_size = uf.size[uf.find_root(ai-1)]
        b_size = uf.size[uf.find_root(bi-1)]
        p = p - a_size * b_size
        ans.append(p)
    else:
        ans.append(p)
    uf.merge(ai-1, bi-1)

print('\n'.join(map(str, reversed(ans[:-1]))))


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

using namespace std;

typedef long long ll;
typedef long double ld;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

int get_random(int l, int r) {
  int len = r - l + 1;
  return l + rng() % len;
}

const int N = 365 + 7;
const int K = 26 + 7;
int n;
int c[K], s[N][K], t[N], last[K], ct, sol[N];

int get() {
  for (int j = 1; j <= 26; j++) {
    last[j] = 0;
  }
  int sol = 0;
  for (int i = 1; i <= n; i++) {
    sol += s[i][t[i]];
    last[t[i]] = i;
    for (int j = 1; j <= 26; j++) {
      sol += c[j] * last[j];
    }
  }
  return sol + ct;
}

void putrng() {
  for (int i = 1; i <= n; i++) {
    t[i] = get_random(1, 26);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= 26; i++) {
    cin >> c[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 26; j++) {
      cin >> s[i][j];
    }
  }
  ct = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 26; j++) {
      ct -= c[j] * i;
    }
  }
  int best = -(int) 1e9;
  for (int j = 1; j <= 60; j++) {
    putrng();
    int cur = get();
    if (cur > best) {
      best = cur;
      for (int i = 1; i <= n; i++) {
        sol[i] = t[i];
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << sol[i] << "\n";
  }
  return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXN = 100000 + 10;

queue<int> q;
int in[MAXN], a[MAXN], d[MAXN];

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	int ans = 0;
	for(int i=1; i<=n; i++) {
		scanf("%d", a+i);
		if(i == 1) {
			if(a[1] != 1)	ans++;
			a[1] = 1;
		}
		in[a[i]]++;
	}

	for(int i=1; i<=n; i++)
		if(!in[i])	q.push(i);
	
	while(!q.empty()) {
		int u = q.front();	q.pop();
		if(u == 1)	break;
		if(d[u] == k-1 && a[u] != 1) {
			ans++;
			d[u] = -1;
		}
		d[a[u]] = max(d[a[u]], d[u]+1);
		in[a[u]]--;
		if(!in[a[u]])	q.push(a[u]);
	}
	printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mset(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(ll i=a;i<b;++i)
#define dloop(i,a,b) for(ll i=a;i>=b;--i)
#define all(a) a.begin(),a.end()
#define lar 1000000007
#define pq priority_queue
#define pll pair<ll,ll>
#define ss second
#define ff first
#define pb push_back
#define ppb pop_back
#define umap unordered_map
#define ub upper_bound
#define lb lower_bound
#define br "\n"
#define sp " "
const int N=1e5;

void solve(){
	ll n;
  cin>>n;
  ll a[n];
  loop(i,0,n) cin>>a[i];
  ll pre[n];
  pre[0] = a[0];
  ll ans=0;
  loop(i,1,n)
    pre[i] = (pre[i-1]+a[i])%lar;
  loop(i,1,n)
  {
    ans = (ans+(pre[i-1]*a[i])%lar)%lar;
  }
  cout<<ans<<endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 6704
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    map<ll,ll>m;
    ll a;
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        cin>>a;
        ans=ans+m[a-i];
        m[-a-i]+=1;
    }
    cout<<ans;
}

Measured memory_bytes: 26364
#include<bits/stdc++.h>
using namespace std;
int main(){
	unsigned long long n,a,b;
	cin>>n>>a>>b;
	unsigned long long s=a+b,sum,ans=0;
	sum=n/s;
	if(n%s>a)ans=a;
	else ans=n%s;
	cout<<sum*a+ans;
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b, c, d, e, k int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)
	fmt.Scan(&e)
	fmt.Scan(&k)

	arr := []int{a, b, c, d, e}

	for i := 0; i < len(arr)-1; i++ {
		for j := 1; j < len(arr); j++ {
			if (arr[j] - arr[i]) > k {
				fmt.Println(":(")
				return
			}
		}
	}
	fmt.Println("Yay!")

}

Measured memory_bytes: 512
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include "bits/stdc++.h"

using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i, n)  FOR(i,0,(n))
#define SP << " " <<


class BRuinedSquare {
public:
    void solve(std::istream &in, std::ostream &out) {
      int x1, y1, x2, y2;
      in >> x1 >> y1 >> x2 >> y2;
      int a = x2 - x1;
      int b = y2 - y1;
      int tx = x2;
      int ty = y2;
      REP(i, 2) {
        swap(a, b);
        a *= -1;
        tx += a;
        ty += b;
        out << tx SP ty << " ";
      }
      out << endl;
    }
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
  BRuinedSquare solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	string s;
	int ans=0;
	cin >>s;
	cout<<solve(s[2]==s[3] and s[4]==s[5])<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <map>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define RepG0(i, x) for (int i = head0[x]; i; i = edge0[i].next)
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 400010;

struct Edge{int to, next;} edge[N * 42], edge0[N * 42];
int head[N], num, d[N], head0[N], num0;
map<int, bool> m[N], m0[N];
void add_edge(int a, int b) { edge[++ num] = (Edge){b, head[a]}, head[a] = num, m[a][b] = true; }
void add_edge0(int a, int b) { edge0[++ num0] = (Edge){a, head0[b]}, head0[b] = num0, m0[a][b] = true;}

int f[N];
int f_f(int x) { return f[x] == x ? x : f[x] = f_f(f[x]);}

pair<int, int> q[N];

int main()
{
	int n, a, b;
	scanf("%d", &n);
	Rep(i, n - 1) { 
		scanf("%d%d", &a, &b); 
		add_edge(a, b); add_edge(b, a); 
		d[a] ++, d[b] ++;
	}
	Rep(i, n - 1) { 
		scanf("%d%d", &a, &b); 
		add_edge0(a, b); add_edge0(b, a); 
		d[a] ++, d[b] ++;
	}
	int he = 0, ta = 0, cnt = 0;
	Rep(i, n) f[i] = i;
	
	Rep(i, n) RepG(j, i)if (m0[edge[j].to][i])
		q[++ ta] = mp(i, edge[j].to);
	
	while (he != ta) {
		int fx = f_f(q[++ he].first), fy = f_f(q[he].second);
		if (fx == fy) continue;
		cnt ++;
		if (d[fx] < d[fy]) swap(fx, fy);
		RepG0(i, fy){
			int fv = f_f(edge0[i].to);
			if (fv == fx || fv == fy) continue;
			if (m[fx][fv]) q[++ ta] = mp(fx, fv);
			add_edge0(fx, fv); add_edge0(fv, fx);
		}
		RepG(i, fy){
			int fv = f_f(edge[i].to);
			if (fv == fx || fv == fy) continue;
			if (m0[fx][fv]) q[++ ta] = mp(fx, fv);
			add_edge(fx, fv); add_edge(fv, fx);
		}
		f[fy] = fx, d[fx] += d[fy];
	}
	
	if (cnt == n - 1) printf("YES\n");
	else printf("NO\n");
	
	return 0;
}

/*
5
2 1
3 1
4 3
5 4
2 1
3 2
4 3
5 1

*/

Measured memory_bytes: 103680
import java.util.Scanner;
import java.util.stream.Stream;

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

        int odd = n- n/2;
        Double ans = (double) odd/n;
        System.out.println(String.format("%.10f", ans));
    }
}

Measured memory_bytes: 22996
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;


// 最大公約数（Greatest Common Divisor）
uint64_t gcd(uint64_t m, uint64_t n)
{
	// ユークリッドの互除法
	for (;;)
	{
		if (0 == m) { return n; }
		n %= m;
		if (0 == n) { return m; }
		m %= n;
	}
}
// 最小公倍数（Least Common Multiple）を返す。
uint64_t lcm(uint64_t m, uint64_t n)
{
	if (0 == m) { return n; }
	if (0 == n) { return m; }
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

int32_t N;
uint64_t A[100000];
uint64_t r[100000];
uint64_t l[100000];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	for (size_t i = 0; i < N; i++)
	{
		in >> A[i];
	}
	l[0] = A[0];
	for (size_t i = 1; i < N; i++)
	{
		l[i] = gcd(l[i - 1], A[i]);
	}
	r[N - 1] = A[N - 1];
	for (int i = N-2; i >= 0; --i)
	{
		r[i] = gcd(r[i + 1], A[i]);
	}

	uint64_t max = std::max(l[N-2],r[1]);
	for (size_t i = 1; i < N -1; i++)
	{
		max = std::max(max, gcd(l[i - 1], r[i + 1]));
	}
	out << max << endl;


	return 0;
}
#endif


Measured memory_bytes: 2560
// 天才成分が多すぎて100%は理解できていない
#include<iostream>
using namespace std;
typedef long long ll;

ll solve(ll a, ll b){
    if(a == b)  return 2*(a-1); // これは自明
    ll upper = a*b-1;
    ll l = 1, r = 1ll<<31;
    while(r-l > 1){
        ll mid = (l+r)/2;   // 2回のコンテストで[1,mid]位だった人のみからなるマッチング
        ll tmp = (mid/2+1)*(mid-(mid/2+1)+1);   // このマッチングにおける最悪のケース
        if(tmp > upper) r = mid;
        else            l = mid;
    }
    return l-1; // lはmin(a,b)以上なのでmin(a,b)の分を引く(多分)
}

int main(){
    int q;
    cin >> q;
    while(q-- > 0){
        ll a, b;
        cin >> a >> b;
        cout << solve(a,b) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Console;

namespace AtCoder_1
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = CinT();
            var a = CinTAr();
            var b = CinTAr();
           long ccc = 0;
            for(int i = n; i > 0; i--)
            {
                a[i] -= b[i - 1];
                ccc += b[i - 1];
                if(a[i] < 0)
                {
                    int abs = a[i] * -1;
                    a[i] = 0;
                    a[i - 1] -= abs;
                    if(a[i - 1] < 0)
                    {
                        ccc += a[i - 1];
                        a[i - 1] = 0;
                    }
                }
            }
            Cout(ccc);
            Cin();
        }



        static readonly int MOD1E9 = (int)1e9 + 7;
        static string Cin() { return ReadLine(); }
        static string[] CinAr() { return ReadLine().Split(' '); }
        static int CinT() { return S2i(Cin()); }
        static int[] CinTAr() { return CinAr().Select((x, i) => { return S2i(x); }).ToArray(); }
        static long CinL() { return S2L(Cin()); }
        static long[] CinLAr() { return CinAr().Select((x, i) => { return S2L(x); }).ToArray(); }
        static double CinD() { return S2D(Cin()); }
        static double[] CinDAr() { return CinAr().Select((x, i) => { return S2D(x); }).ToArray(); }
        static int S2i(string s) { return int.Parse(s); }
        static long S2L(string s) { return long.Parse(s); }
        static double S2D(string s) { return double.Parse(s); }
        static void OYes() { Cout("Yes"); }
        static void ONo() { Cout("No"); }
        static void Cout(object s) { WriteLine(s); }
        static int[] yakusuu(int n)
        {
            if (n == 1) { return new int[] { 1 }; }
            HashSet<int> res = new HashSet<int>();
            for (int i = 1; i < Math.Ceiling(n / 2.0); i++)
            {
                if (n % i == 0)
                {
                    res.Add(i);
                    res.Add(n / i);
                }
            }
            return res.ToArray();
        }
        /// <summary>
        /// Debug時のみの使用を推奨
        /// </summary>
        /// <typeparam name="Type"></typeparam>
        /// <param name="types"></param>
        static void CoutAr<Type>(IEnumerable<Type> types)
        {
            string text = "";
            foreach (var i in types)
            {
                text += " " + i;
            }
            WriteLine(text.Substring(1));
        }
    }
}


Measured memory_bytes: 34012
#include <stdio.h>

int main(void) {
    int k, n, i, max;
    scanf("%d %d", &k, &n);

    int A[n+1];
    for (i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    A[n] = k + A[0];
    max = 0;

    for (i = 1; i <= n; i++) {
        if (max < A[i] - A[i-1]) max = A[i]-A[i-1];
    }
    printf("%d\n", k - max);
    return 0;
}

Measured memory_bytes: 896
s=input()

r=[]
l=0

for i in range(len(s)):

    if s[i]=='R':
        l+=1

    else:
         if l!=0:
            r.append(l)
            l=0

if l!=0:
    r.append(l)
if len(r):    
   
   print(max(r))    
else:
    print(0)








Measured memory_bytes: 8972
// ConsoleApplication98.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<set>
#include<map>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
	int a=0,b=0;
	string ss;
	cin >> ss;
	for (int q = 0; q < 3; q++)
	{
		if (ss[q] == 'A')
		{
			a++;
		}
		else
		{
			b++;
		}
	}
	if (a == 0 || a == 3)
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
	}


}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int numo=0;
  int number;
  scanf("%d", &number);
  numo = number;
  int V[numo];
  int C[numo];
  int sum = 0;
  int i;
  for(i = 0;i < number; i++){
    scanf("%d",&V[i]);
}
   for(i = 0;i < number; i++){
    scanf("%d",&C[i]);
}
   for(i = 0;i < number; i++){
   if(V[i] > C[i]){
     sum =  sum + V[i] - C[i];
   	}
   }
  printf("%d", sum);
  
  return 0;
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

//Main
const (
	initialBufSize = 100000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var n, m int

func main() {
	sc.Split(bufio.ScanWords)
	n, m = nextInt(), nextInt()

	ac, pen := 0, 0
	isSolved := make([]bool, n+1)
	WA := make([]int, n+1)

	for i := 0; i < m; i++ {
		p, s := nextInt(), nextStr()
		if !isSolved[p] {
			if s == "WA" {
				WA[p]++
			} else {
				isSolved[p] = true
				ac++
				pen += WA[p]
			}
		}
	}

	fmt.Println(ac, pen)

}


Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long n = Long.parseLong(scan.next());
        scan.close();

        StringBuilder sb = new StringBuilder();

        while (n > 0) {
            long l = n % 26;
            if (l == 0) {
                sb.append('z');
                n -= 1;
            } else {
                char c = 'a';
                c += l - 1;
                sb.append(c);
            }

            n /= 26;
        }

        System.out.println(sb.reverse().toString());
    }

}


Measured memory_bytes: 35524
#include <iostream>

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

using namespace std;

int main(){
	
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	
	if (a<=c && c<=b && b<=d){
		cout << b-c << endl;
	}else if (c<=a && a<=d && d<=b){
		cout << d-a << endl;
	}else if (a<=c && d<=b){
		cout << d-c << endl;
	}else if (c<=a && b<=d){
		cout << b-a << endl;
	}else{
		cout << 0 << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
n,m = map(int, input().split())

p = 7+pow(10,9)
def cmb(n,r,p):
    numerator = 1
    for i in range(n-r+1, n+1):
        numerator = numerator * i % p
    denominator = 1
    for i in range(1, r+1):
        denominator = denominator * i % p
    return numerator * pow(denominator, p-2, p) % p

print(cmb(n, 2, p)+ cmb(m,2,p))

Measured memory_bytes: 3064
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end
N, M, K = gets_i_list

0.upto(N) do |i|
  0.upto(M) do |j|
    b_count = i * (M - j) + j * (N - i)
    if K == b_count
      puts "Yes"
      exit
    end
  end
end

puts "No"


Measured memory_bytes: 4092
#include <stdio.h>

int main()
{
    int a, b, W;
    scanf("%d%d%d", &W, &a, &b);
    if(b > a + W)
        printf("%d\n", b - a - W);
    else if(b >= a - W && b <= a + W)
        printf("0\n");
    else
        printf("%d\n", a - b - W);
    return 0;
}


Measured memory_bytes: 128
I=lambda:map(int,input().split());F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):*a,c=I();R+=[(a,c)];Y+=[c];X+=a
for i in r(m):a,*b=I();H+=[(a,b)];X+=[a];Y+=b
def g(X):s=dict(enumerate(sorted(set(X))));return{s[i]:i for i in s},s,len(s)+1
h,s,K=g(X);w,t,L=g(Y);j=lambda:[[0]*(K+1)for i in r(L+1)];V=j();U=j();v=j()
for(a,b),c in R:U[w[c]][h[a]]+=1;U[w[c]][h[b]]+=-1
for d,(e,f)in H:V[w[e]][h[d]]+=1;V[w[f]][h[d]]+=-1
for i in r(L):
 for j in r(K):U[i][j+1]+=U[i][j];V[i+1][j]+=V[i][j]
q=[(h[0],w[0])];v[w[0]][h[0]]=1;a=0
while q:
 x,y=q.pop();a+=(s[x]-s[x+1])*(t[y]-t[y+1])
 for e,f in[(-1,0),(1,0),(0,1),(0,-1)]:
  c=x+e;d=y+f
  if(K>c>=0<=d<L)*v[d][c]==0:
   if U[(f>0)+y][x]|e==0 or V[y][(e>0)+x]|f==0:q+=[(c,d)];v[d][c]=1
if a>F:a='INF'
print(a)

Measured memory_bytes: 551500
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;

int n;
int a[3*MAXN];

void run() {
	scanf("%d",&n);
	REP(i,3*n) scanf("%d",&a[i]);
	sort(a,a+3*n);
	reverse(a,a+3*n);
	ll ret=0;
	REP(i,n) ret+=a[2*i+1];
	printf("%lld\n",ret);
}

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


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

void tamesiwari(int *table, int n){
	table[1] = 1;
	table[2] = 2;
	for(int i = 3; i < n; i += 2){
		bool ok = true;
		for(int j = 3; i >= (j * j); j += 2){
			if(i % j == 0) ok = false;
		}
		if(ok) table[i] = i;
	}
}

int main(){
	int table[60000] = {0};
	tamesiwari(table, 60000);
	int n = 0;
	while(cin >> n){
		if(cin.eof()) break;
		
		for(int i = n - 1; i >= 0; i--){
			if(table[i] != 0){
				cout << table[i] << " ";
				break;
			}
		}

		for(int i = n + 1; i < 60000; i++){
			if(table[i] != 0){
				cout << table[i] << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1400
#include "bits/stdc++.h"
#define readInt(x) scanf("%d", &x)
#define readStr(x) scanf("%s", x)
#define rep(i, n) for(int i=0; i<(n); ++i)
#define write(x) cout << (x) << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1 << 28;

int A, B, C;

int main()
{
    cin >> A >> B >> C;
    rep(i, B) {
        if (A * i % B == C) {
            write("YES");
            return 0;
        }
    }
    write("NO");
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
  int n,t,h,m,f=0,ansr[1000];
  int ansh=0,ansm=0,anst;
  int afh,afm;
  char p;
  string str[1000],ans[1000],s;
  cin>>n>>t;
  cin>>h>>p>>m>>str[0];
  for(int i=1;i<n;i++){
    cin>>h>>p>>m>>str[i]>>afh>>p>>afm>>s;
    ansh=afh-h,ansm=afm-m;
       anst=ansh*60+ansm;
       if(anst>=t) ans[f]=str[i],ansr[f]=anst,f++;
  }
  if(f==0) cout<<"0"<<endl;
  else{
    cout<<f<<endl;
 for(int i=0;i<f;i++) cout<<ans[i]<<" "<<ansr[i]<<endl;
  }
  return 0;
}

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

int main(){
  int n_slimes;
  char *info_color;
  int answer = 0;
  scanf("%d", &n_slimes);
  
  info_color = (char *)malloc(sizeof(char)*n_slimes);
  scanf("%s", info_color);
  
  char color;
  int i;
  for(color='a'; color<='z'; color++){
    for(i=0; i<n_slimes; i++){
      if(info_color[i] == color){
        answer++;
        do{
          i++;
          if(i>=n_slimes) break;
        }while(info_color[i] == color);
      }
    }
  }
  
  printf("%d", answer);
}

Measured memory_bytes: 256
n,t = map(int,input().split())
times = list(map(int,input().split()))

ans = t
stop = t

for i in range(1,n):
    start = times[i]
    nextstop = start + t
    if start >= stop:
        ans +=t
    else:
        ans += nextstop -stop
    stop = nextstop

print(ans)

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

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

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

long long stoi(string str) {
	long long ret;
	stringstream ss; ss << str;
	ss >> ret;
	return ret;
}

ull gcd(ull a, ull b) {
	if (b > a)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a%b);
}
void solve() {
	int n;
	cin >> n;
	int count4 = 0;
	int count2 = 0;
	int countelse = 0;
	rep(i, n) {
		int a;
		cin >> a;
		if (a % 2 == 0) {
			if (a % 4 == 0)count4++;
			else count2++;
		}
		else {
			countelse++;
		}
	}
	n -= count4;
	if (count2 >= 2) {
		n -= count2;
		n++;
	}
	if (count4 >= n - 1) {
		P("Yes");
	}
	else {
		P("No");
	}
}

int main() {
	solve();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    int n, t; cin >> n>>t;
    int sol = 10000;
    REP(i, n){
    int ic, it;
    cin >> ic >> it;
    if(it<=t) sol = min(sol, ic);
    }
    if(sol!=10000)cout << sol << endl;
    else cout << "TLE" << endl;
}

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

Measured memory_bytes: 256
# import math
# import statistics
# import itertools
# a=int(input())
# b,c=int(input()),int(input())
# c=[]
# for i in a:
#     c.append(int(i))
A,B= map(int,input().split())
f = list(map(int,input().split()))
# g = [input().split for _ in range(a)]
# h = []
# for i in range(a):
#     h.append(list(map(int,input().split())))
# a = [[0] for _ in range(H)]#nizigen
kyori=[]
for i in range(len(f)-1):
    an=f[i+1]-f[i]
    kyori.append(an)
    
an2=A-f[-1]+f[0]
ans=max(max(kyori),an2)
print(A-ans)

Measured memory_bytes: 32372
(function(input) {
    var a = parse(input, '');
    for (var i = 0; i < a.length; i++) {
        var n = a[i].map(Number);
        if (n.join() == '0') {
            return;
        }
        console.log(n.reduce(function(p, c) {
            return p + c;
        }))
    }
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function parse(str, sep, ter) {
    sep = typeof(sep) !== 'undefined' ? sep : ' ';
    ter = typeof(ter) !== 'undefined' ? ter : '\n';
    str = str.replace(/\n$/, '');
    var a = str.split(ter);
    for (var i = 0; i < a.length; i++) {
        a[i] = a[i].split(sep);
    }
    return a;
}

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

using namespace std;

int main() {
  cin.tie(0);
  int n;
  cin >> n;
  long long MOD = 1e9 + 7;
  vector < long long > vt(n + 1), ara(n + 1);;
  for(int i = 1 ; i <= n ; ++i) {
    cin >> vt[i];
    ara[i] = vt[i];
  }
  for(int i = n - 1 ; i >= 1 ; --i) {
   	vt[i] += vt[i + 1]; 
    vt[i] %= MOD;
  }
  long long ans = 0;
  for(int i = 1 ; i < n ; ++i) {
    ans +=  (1LL * ara[i] * vt[i + 1]) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long int ll;

int main()
{ 
    int N,H[100005],A[100005],i,t1,t2;
    cin>>N;
    for(i=1;i<=N;i++)
    {
        cin>>H[i];
    }
    
    A[N]=0;
    A[N-1]=abs(H[N]-H[N-1]);
    for(i=N-2;i>=1;i--)
    {
        t1 = abs(H[i]-H[i+1])+ A[i+1];
        t2 = abs(H[i]-H[i+2]) + A[i+2];
        A[i] = min(t1,t2);
    }
    cout<<A[1];
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;
//const int MOD=1e9+7;


int main(){
	int N;
	cin>>N;
	int a[100];
	rep(i,N)cin>>a[i];
	int slime=500;
	int ans=0;
	rep1(i,N-1){
		if(a[i]==a[i-1]){
			ans++;
			a[i]=slime;
		}
	}
	cout<<ans;
}

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

int main()
{
  ll cntEven = 0, cntOdd = 0, n;
  cin >> n;
  ll a[n], b[n], sumEven[n], sum[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
    if (i == 0) sumEven[i] = b[i];
    else if (i > 0) sumEven[i] = b[i] + sumEven[i - 1];
    if (i == 0) sum[i] = a[i];
    else if (i > 0) sum[i] = a[i] + sum[i - 1];
    // 偶数項が正、奇数項が負としたい場合
    if ((i % 2 == 0) && (sumEven[i] <= 0)) {
      cntEven += 1 - sumEven[i];
      b[i] += 1 - sumEven[i];
      sumEven[i] = 1;
    }
    if ((i % 2 == 1) && (sumEven[i] >= 0)) {
      cntEven += sumEven[i] + 1;
      b[i] = b[i] - 1 + sumEven[i];
      sumEven[i] = -1;
    }
    // 偶数項が負、奇数項が正としたい場合
    if ((i % 2 == 1) && (sum[i] <= 0)) {
      cntOdd += 1 - sum[i];
      a[i] += 1 - sum[i];
      sum[i] = 1;
    }
    if ((i % 2 == 0) && (sum[i] >= 0)) {
      cntOdd += sum[i] + 1;
      a[i] = a[i] - 1 + sum[i];
      sum[i] = -1;
    }
  }
  cout << min(cntEven, cntOdd) << endl;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int sum=0,cnt;
  for(int i=0;i<s.length();)
  {
    if(s[i]=='R')
    {  cnt=0;
      while(s[i]=='R')
      {
        cnt++;
        i++;
      }
     sum=max(sum,cnt);
    }
    else
      i++;
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define MOD 1000000007
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
inline ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
inline ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
inline ll char_to_ll(char c) { return (int)(c - '0'); }
inline ll string_to_ll(string s) { return atoi(s.c_str()); }
inline bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }
#define cal(a, b, op) a op b

// 動作環境 : C++14 AOJ
int main(){
    vector<tuple<ll, ll, char>> A;
    while(true){
        ll a, b;
        char op;
        cin >> a >> op >> b;
        if(op == '?') break;
        A.pb(make_tuple(a, b, op));
    }

    for(tuple<ll, ll, char> t : A){
        ll a = get<0>(t);
        ll b = get<1>(t);
        switch(get<2>(t)){
            case '+':
                cout << a + b << endl;
                break;
            case '-':
                cout << a - b << endl;
                break;
            case '*':
                cout << a * b << endl;
                break;
            case '/':
                cout << a / b << endl;
                break;
        }
    }

    return 0;
}



Measured memory_bytes: 3108
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define INF 2147483647
using namespace std;
using Graph=vector<vector<int>>;

int main(){
  int ans=0,ma=0;
  string s;
  cin>>s;
  rep(i,3){
    if(s[i]=='R'){
      ans++;
      ma=max(ans,ma);
    }else{
      ans=0;
    }
  }
  cout<<ma;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[40]={0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
	int k;
	scanf("%d",&k);
	printf("%d\n",a[k]);
	return 0;
} 

Measured memory_bytes: 256
n=int(input())
A1=list(map(int,input().split()))
A2=list(map(int,input().split()))
ans=0
for i in range(n):
    B1=A1[:i+1]
    B2=A2[i:]
    ans=max(ans,sum(B1)+sum(B2))
print(ans)

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

int main(){
  int N;
  cin >> N;
  
  vector<ll> vec(N+1);
  for(int i=0;i<=N;i++){
    if(i==0){
      vec[i]=2;
    }
    if(i==1){
      vec[i]=1;
    }
    if(i>1){
      vec[i]=vec[i-1]+vec[i-2];
    }
  }
  cout << vec[N] <<endl;
}


Measured memory_bytes: 3600
/* */

#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;

#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
#else
	#define errp(...)
#endif
#define dbg(x) errp(" %s = %s\n", #x, to_string(x).data())
/* ==================== */ 
int main() {
	
	int a, b;
	cin >> a >> b;

	int pro = a * b;
	if (pro % 2 == 0) cout << "Even" << '\n';
	else cout << "Odd" << '\n';
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const long long INF = 1LL << 60;
const ll C = 1000000000+7;

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

    ll count = 0;
    for(int i=0; i<N; i++) {
        if(s[i] == 'E') count++;
    }
    ll min_count = count;
    for(int i=0; i<N; i++) {
        if(s[i] == 'W') {
            count++;
        }
        else {
            count--;
        }
        min_count = min(min_count, count);
    }
    cout << min_count << endl;
}

Measured memory_bytes: 3888
#include <bits/stdc++.h>
using namespace std;
#define int long long
int N,A,B,C;
int l[8];
vector<int>sentaku[4];
int ans = 10020201010;
signed dfs(int n) {
    if(n == N) {
        if(sentaku[0].size() > 0 && sentaku[1].size() > 0 && sentaku[2].size() > 0) {
            int cnt1 = 0;
            int cnt2 = 0;
            int cnt3 = 0;
            for(int i = 0; i < sentaku[0].size(); i++) {
                cnt1+=sentaku[0][i];
            }
            for(int i = 0; i < sentaku[1].size(); i++) {
                cnt2+=sentaku[1][i];
            }
            for(int i = 0; i < sentaku[2].size(); i++) {
                cnt3+=sentaku[2][i];
            }
            int Z = N-sentaku[3].size();
            ans = min(ans,abs(A-cnt1)+abs(B-cnt2)+abs(C-cnt3)+(Z-3)*10);
            return 0;
        }
        else {
            return 0;
        }
    }
    else {
        sentaku[0].push_back(l[n]);
        dfs(n+1);
        sentaku[0].pop_back();
        sentaku[1].push_back(l[n]);
        dfs(n+1);
        sentaku[1].pop_back();
        sentaku[2].push_back(l[n]);
        dfs(n+1);
        sentaku[2].pop_back();
        sentaku[3].push_back(l[n]);
        dfs(n+1);
        sentaku[3].pop_back();
    }
        return 0;
}
signed main() {
    cin >> N >> A >> B >> C;
    for (int i = 0; i < N; i++) {
        cin >> l[i];
    }
    dfs(0);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(long long i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;
 
int main()
{
  int a;
  cin >> a;
  cout << 3*a*a << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define flash ios_base::sync_with_stdio(false);     cin.tie(NULL);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(v) v.begin(),v.end()
#define f first
#define s second



using namespace std;

int main()
{
  flash
  ll n,w;
  cin>>n>>w;

  std::vector<int> wt(n);
  std::vector<int> v(n);
  for(int i=0; i <n;i++){

    cin>>wt[i]>>v[i];

  }

  //std::vector<std::vector<int>> dp( n+1 , std::vector<int>(w+1,0));
  ll dp[n+1][w+1];

  for(int i=0;i<=n;i++){

    for(int j=0;j<=w;j++){

      if(i==0 || j==0)
        dp[i][j]=0;
      else if( wt[i-1]<=j )
        dp[i][j] = max ( v[i-1] + dp[i-1][j-wt[i-1]] , dp[i-1][j] );
      else
        dp[i][j] = dp[i-1][j];
    }

  }
  cout<<dp[n][w]<<"\n";


}


Measured memory_bytes: 82516
import bisect
n, q = map(int, input().split())
s = input()
t = []
for i in range(n-1):
  if s[i:i+2] == "AC":
    t.append(i+1)
for j in range(q):
  l, r = map(int, input().split())
  x = bisect.bisect_left(t, l)
  y = bisect.bisect_right(t, r-1)
  print(y-x)

Measured memory_bytes: 5724
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        string[] s = Console.ReadLine().Split(' ');
        int T = int.Parse(s[0]);
        int A = int.Parse(s[1]);
        int[] H = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        float min = float.MaxValue;
        int pos = 0;
        for(int i = 0; i < N; i++)
        {
            float t = Math.Abs(A - T + H[i] * 0.006f);
            if (t < min)
            {
                min = t;
                pos = i + 1;
            }
        }
        Console.WriteLine(pos);
    }
}


Measured memory_bytes: 13340
#include<bits/stdc++.h>
#define maxn 510
using namespace std;

int cnt[maxn][maxn],n,m,q;
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>m>>q;
	for(int i=1,x,y;i<=m;i++)
		cin>>x>>y,cnt[x][y]++;
	for(int len=2;len<=n;len++)
		for(int i=1;i+len-1<=n;i++)
			cnt[i][i+len-1]+=cnt[i][i+len-2]+cnt[i+1][i+len-1]-cnt[i+1][i+len-2];
	for(int i=1,x,y;i<=q;i++)	
		cin>>x>>y,cout<<cnt[x][y]<<endl;

	return 0;
}

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

vector<long long> divisor(long long n){
  vector<long long> ret;
  for(long long i=1; i*i<=n; i++){
    if(n%i == 0){
      ret.push_back(i);
      if(i*i != n) ret.push_back(n/i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

int main(){
  long long N;
  cin >> N;
  long long i;
  vector<long long> notDiv = divisor(N-1);
  vector<long long> Div = divisor(N);
  int DivNum = Div.size();
  long long tmp,yaku;
  long long divCount = 0;
  for(i=1; i<DivNum; i++){
    yaku = Div.at(i);
    tmp=N;
    while(tmp%yaku == 0){
      tmp /= yaku;
    }
    if(tmp%yaku == 1) divCount++;
  }
  cout << notDiv.size() + divCount-1;
  return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n, m) for (int (i) = (n); (i) < (m); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

int main() {
   ll x, y;
   cin >> x >> y;
   if (x % y == 0) {
      cout << -1 << endl;
   } else {
      cout << x << endl;
   }

   return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main() {
  stack<int> S;
  string s;
  int a, b;
  while (cin >> s) {
    if (s == "*") {
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      S.push(a * b);
    } else if (s == "+") {
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      S.push(a + b);
    } else if (s == "-") {
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      S.push(b - a);
    } else {
      sscanf(s.c_str(), "%d", &a);
      S.push(a);
    }
  }
  a = S.top();
  cout << a << endl;
}

Measured memory_bytes: 1252
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())

INF = float('inf')

plusmax = minusmax =-INF
plusmin = minusmin = INF

for i in range(n):
    x, y = map(int, input().split())

    x_minus_y = x-y
    x_plus_y = x+y

    plusmax = max(plusmax, x_plus_y)
    plusmin = min(plusmin, x_plus_y)
    minusmax = max(minusmax, x_minus_y)
    minusmin = min(minusmin, x_minus_y)

ans0 = plusmax - plusmin
ans1 = minusmax - minusmin
print( max(ans0, ans1))


Measured memory_bytes: 73952
#include <stdio.h>

int
main (
  int   argc,
  char *argv[ ]
  )
{
  for ( ; ; )
  {
    int m, f, r;
    int sum;

    scanf ( "%d%d%d", &m, &f, &r );
    if ( m == -1
      && f == -1
      && r == -1 ) break ;

    sum = m + f;
    if ( m == -1 || f == -1 )
    {
      sum = 0;
    }
    if ( 30 <= sum && sum < 50
      && r >= 50 )
    {
      sum = 50;
    }

    puts ( sum >= 80 ? "A"
         : sum >= 65 ? "B"
         : sum >= 50 ? "C"
         : sum >= 30 ? "D"
         :             "F" );
  }

  return ( 0 );
}

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

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    s = lines[0]
    t = lines[1]

    return (s, t)


def solve(s, t):

    result = 'Yes'
    if s != t[:len(s)]:
        result = 'No'
    if len(s) + 1 != len(t):
        result = 'No'
    
    return  result
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 62056
#include <assert.h>
#include <bits/stdc++.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <iostream>
#include <list>
#include <set>
#include <stack>
#include <string>
#include <vector>

 
using namespace std;
 
typedef string str;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;




#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define trav(a, x) for (auto &a : x)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define PRINT_ARRAY(a, N)        \
  F0R(z, N) cout << a[z] << " "; \
  cout << "\n"
 
const int MOD = 1000000007;  // 998244353
const ll INF = 1e18;
const ld PI = 4 * atan((ld)1);


ll N, W;
ll w[100005];
ll v[100005];
ll dp[100005];

int main() {
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
		cout.tie(NULL);
		cin >> N >> W;

		F0R(i, N) cin >> w[i] >> v[i];

		// dp[i] = best value using weight equal to exactly i.
		ll best = -1;
		for (int i = 1; i <= N; i++) {
				int weight = w[i - 1], value = v[i - 1];
				for (int j = W - weight; j >= 0; j--) {
						dp[j + weight] = MAX(dp[j + weight], dp[j] + value); 
						best = MAX(best, dp[j + weight]);
				}
		}
		cout << best << endl;
}


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

import itertools

l = [i for i in range(1, n+1)]

zyu = itertools.permutations(l, n)

for t, child in enumerate(zyu):
    p_flag = True
    q_flag = True
    for check_idx in range(0, n):
        if list(child)[check_idx] == p[check_idx]:
            pass
        else:
            p_flag = False
            break

    for check_idx in range(0, n):    
        if list(child)[check_idx] == q[check_idx]:
            pass
        else:
            q_flag = False
            break

    if p_flag:
        p_idx = t+1

    if q_flag:
        q_idx = t+1



print(abs(q_idx-p_idx))



Measured memory_bytes: 3064
module CharMap = Map.Make (Char)

let () =
  let s = read_line () in
  let t = read_line () in
  let skip = Array.make (String.length s + 1) CharMap.empty in
  for i = String.length s - 1 downto 0 do
    skip.(i) <- CharMap.add s.[i] i skip.(i + 1)
  done;
  skip.(String.length s) <- skip.(0);
  for i = String.length s - 1 downto 0 do
    skip.(i) <- CharMap.add s.[i] i skip.(i + 1)
  done;
  Printf.printf "%d\n" @@
  match
    Array.fold_left (fun (i, n) c ->
      let j = CharMap.find c skip.(i) in
      (j + 1, n + if j < i then 1 else 0)) (0, 0) @@
    Array.init (String.length t) (String.get t)
  with
  | exception Not_found -> -1
  | (i, n) -> n * String.length s + i


Measured memory_bytes: 61056