akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

ll add(ll a,ll b){
  return (a+b)%mod;
}

#define MAX 3005
int n,m;
string s;
int a[MAX],b[MAX];
int x[MAX];

ll dp[MAX][MAX];

int main(){
  cin>>n>>m>>s;
  for(int i=0;i<n;i++){
    x[i]=i;
    a[i]=(s[i]=='0'?1:0) + (i?a[i-1]:0);
    b[i]=(s[i]=='1'?1:0) + (i?b[i-1]:0);
  }
  for(int i=0;i<m;i++){
    int l,r;
    cin>>l>>r;
    l--;
    r--;
    for(int j=l;j<r;j++){
      x[j]=max(x[j],r);
    }
  }

  dp[0][0]=1;
  for(int i=0;i<n;i++){
    int p=x[i];
    for(int j=0;j<=i;j++){
      if(dp[i][j]==0)continue;
      int A=j;
      int B=i-A;
      if( A+1 <= a[p] ){
        dp[i+1][A+1]=add(dp[i+1][A+1],dp[i][j]);
      }
      if( B+1 <= b[p] ){
        dp[i+1][A]=add(dp[i+1][A],dp[i][j]);
      }
    }
  }

  cout<<dp[n][ a[n-1] ]<<endl;
  return 0;
}


Measured memory_bytes: 68352
inf = pow(10, 9)+7

n, k = map(int, input().split())
a = [int(x) for x in input().split()]
a.sort()

ans = 0
comb = 1
for i in range(k, n+1):
    ans += (a[i-1]-a[-i])*comb
    ans %= inf
    comb = (comb * i * pow(i-k+1, inf-2, inf))%inf
print(ans)

Measured memory_bytes: 14040
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s; cin >>s;
  if(s.at(0) ==  'R' and s.at(1) == 'R' and s.at(2) == 'R')
    cout << 3;
  else if(s.at(0) == 'R' and s.at(1) == 'R' or s.at(1) == 'R' and s.at(2) =='R')
    cout << 2;
  else if(s.at(0) ==  'S' and s.at(1) == 'S' and s.at(2) == 'S')
    cout << 0;
  else cout << 1;
}

Measured memory_bytes: 3624
def main():
    N, M = map(int, input().split())
    
    A = []
    for _ in range(N):
        A.append(input())
        
    B = []
    for _ in range(M):
        B.append(input())

    def check(x, y):
        for i in range(M):
            for j in range(M):
                if A[x + i][y + j] != B[i][j]:
                    return False
        return True

    for i in range(N - M + 1):
        for j in range(N - M + 1):
            if check(i, j):
                print('Yes')
                return
    print('No')

main()


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e3+23;

int n;
int bio[N][N];
int a[N][N];
int dp[N][N];
vector<pair<int, int>> g[N][N];

int dfs(int x, int y) {
  int &ret = dp[x][y];
  if (ret) return ret;
  bio[x][y] = 1;
  ret = 1;
  for (const auto &v: g[x][y]) {
    if (bio[v.first][v.second] == 1) {
      printf("-1");
      exit(0);
    }
    ret = max(ret, 1+dfs(v.first, v.second));
  }
  bio[x][y] = 2;
  return ret;
}

void solve() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n-1; ++j) {
      scanf("%d", a[i]+j);
      --a[i][j];
      if (j) {
	g[min(i, a[i][j-1])][max(i, a[i][j-1])]
	  .emplace_back(min(i, a[i][j]), max(i, a[i][j]));
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i+1; j < n; ++j) {
      if (bio[i][j]) continue;
      ans = max(ans, dfs(i, j));
    }
  }
  printf("%d", ans);

}
int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 55936
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main()
{
    //freopen("A.01.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b;
    scanf("%d %d", &a, &b);
    rep(i, 1, 3 + 1)
    {
        if (a * b * i % 2 != 0)
        {
            printf("%s", "Yes");
            return 0;
        };
    }
    printf("%s", "No");
    return 0;
}

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

int n;
vector<int> x, y;
// vector<int> viewed;

double dist(int a, int b){
    return sqrt((x[a]-x[b])*(x[a]-x[b]) + (y[a]-y[b])*(y[a]-y[b]));
}

bool dfs(int v, double t, int c){
    if(c == n) return true;

    for(int i=0;i<n;i++){
        // if(viewed[i]) continue;
        if(t + dist(v, i) >= dist(i, n+1)) return false;
    }

    for(int i=0;i<n;i++){
        // if(viewed[i]) continue;
        double nt = t + dist(v, i);
        if(nt < dist(i, n+1)){
            // viewed[i] = true;
            if(dfs(i, nt, c+1)) return true;
            // viewed[i] = false;
        }
    }

    return false;
}

int main(){
    while(1){
        cin >> n;
        if(n == 0) break;
        x.assign(n+2, 0);
        y.assign(n+2, 0);
        cin >> x[n] >> y[n] >> x[n+1] >> y[n+1];
        for(int i=0;i<n;i++){
            cin >> x[i] >> y[i];
        }
        // viewed.assign(n, 0);
        if(dfs(n, 0, 0)){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3096
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int n;
    int[] a;

    scan(n);
    a = readln.split.to!(int[]);

    long ans = 1;
    int cnt, p;

    a.sort!"a > b"();

    foreach (i ; 0 .. n) {
        if (p == 0) {
            p = a[i];
        }
        else {
            if (p == a[i]) {
                ans *= a[i];
                cnt++;
                p = 0;

                if (cnt == 2) break;
            }
            else {
                p = a[i];
            }
        }
    }

    if (cnt == 2) {
        writeln(ans);
    }
    else {
        writeln(0);
    }
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 4268
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = Integer.parseInt(scan.next());
        int b = Integer.parseInt(scan.next());
        int h = Integer.parseInt(scan.next());
        int m = Integer.parseInt(scan.next());
        scan.close();

        double rad = Math.abs((double)(h * 60 + m) / 720 - (double)m / 60) * Math.PI * 2;
        if (rad > Math.PI) {
            rad = Math.PI * 2 - rad;
        }

        double ans2 = a * a + b * b - 2 * a * b * Math.cos(rad);

        if (rad == Math.PI) {
            System.out.println(a + b);
        } else {
            System.out.println(Math.sqrt(ans2));
        }
    }

}


Measured memory_bytes: 35860
a, b, x = gets.split.map(&:to_f)
if a * a * b >= 2 * x
  h = 2 * x / a / b / b
  puts 90 - Math.atan(h) / Math::PI * 180
else
  h = 2 * (x - a * a * b) / a / a / a
  puts Math.atan(h).abs / Math::PI * 180
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define YESNO(i) if((i)) puts("YES");else puts("NO");
#define YesNo(i) if((i)) puts("Yes");else puts("No");
#define yesno(i) if((i)) puts("yes");else puts("no");
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;cin>>s;
  if(s=="ABC") puts("ARC");else puts("ABC");
  return 0;
}

Measured memory_bytes: 3612
N, K = map(int, input().split())

H = list()
for n in range(N):
    H.append(int(input()))

H.sort(reverse=True)

diff = list()
for n in range(N-K+1):
    diff.append(H[n] - H[n+K-1])

diff.sort()
print(diff.pop(0))

Measured memory_bytes: 11288
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main() {
    int n; cin >> n;
    vector<int> v(n, 0);
    
    double average = 0.0;
    for(int i = 0; i < n; i += 1) {
        cin >> v[i];
        average += v[i] / (n + 0.0);
    }

    int who = -1;
    double best = 1e8;

    for(int i = 0; i < n; i += 1) {
        if(fabs(v[i] - average) < best) {
            best = fabs(v[i] - average);
            who = i;
        }
    }

    cout << who << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T> vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

// 素数篩＋素因数分解
// 初期化O(N),素因数分解O(logN)
// たくさん素因数分解するときはこっち
#include <cassert>
struct prime_sieve {
    int N;
    vector<ll> sieve;
    prime_sieve(int n) : N(n + 1) {
        sieve.resize(N);
        iota(All(sieve), 0);
        init();
    }

    void init() {
        for(int i = 2; i * i <= N; i++) {
            if(sieve[i] < i)
                continue;
            for(int j = i * i; j < N; j += i) {
                if(sieve[j] == j)
                    sieve[j] = i;
            }
        }
    }

    map<ll, int> prime_factorize(ll n) {
        assert(n <= N);
        map<ll, int> ret;
        while(n > 1) {
            ret[sieve[n]]++;
            n = n / sieve[n];
        }
        return ret;
    }
};
int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) { cin >> A[i]; }
    ll g = A[0];
    rep(i, N) { g = __gcd(g, A[i]); }
    if(g != 1) {
        cout << "not coprime" << endl;
    } else {
        prime_sieve sieve(1000001);
        set<int> se;
        bool ok = 1;
        rep(i, N) {
            auto m = sieve.prime_factorize(A[i]);
            for(auto p : m) {
                if(se.count(p.first))
                    ok = 0;
                se.insert(p.first);
            }
        }
        if(ok) {
            cout << "pairwise coprime" << endl;
        } else {
            cout << "setwise coprime" << endl;
        }
    }
}

Measured memory_bytes: 22436
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * 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;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            int[] b = new int[n];
            int[] c = new int[n - 1];
            for (int i = 0; i < n; i++)
                a[i] = in.nextInt();
            int ans = 0;
            for (int i = 0; i < n; i++) {
                b[i] = in.nextInt();
                ans += b[i];
            }
            for (int i = 0; i < n - 1; i++) {
                c[i] = in.nextInt();
            }
            for (int i = 0; i < n - 1; i++) {
                if (a[i] + 1 == a[i + 1])
                    ans += c[a[i] - 1];
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21460
#include <stdio.h>

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


Measured memory_bytes: 2080
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

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

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

int x[30] = {0}, n, r;

void prnt(void){
  int i;
  printf("%d", x[0]);
  rep1(i, r)printf(" %d", x[i]);
  kara;
  return;
}

void nxt(void){
  int i, j, sum = 0;
  per(i, r){
    if(x[i] != 1)break;
    sum += x[i];
  }
  if(i < 0)return;
  --x[i]; ++sum;
  for(j = i + 1;sum > 0;++j){
    x[j] = min(x[i], sum);
    sum -= x[i];
  }
  r = j;
  return;
}

void solve(int z){
  for(;;){
    prnt();
    if(r == n)break;
    nxt();
  }
  return;
}

signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    scanf("%d", &n);
    if(!n)break;
    rep(i, 30)x[i] = 0;
    x[0] = n;
    r = 1;
    solve(n);

//*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3176
package main

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

func cost(a []int, i, j int) int {
	c := a[i] - a[j]
	if c < 0 {
		return -c
	}
	return c
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanInt := func() int {
		scanner.Scan()
		num, err := strconv.Atoi(scanner.Text())
		if err != nil {
			log.Fatal(err)
		}
		return num
	}
	n := scanInt()
	a, memo := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}

	memo[0], memo[1] = 0, cost(a, 0, 1)
	for i := 2; i < n; i++ {
		memo[i] = min(memo[i-1]+cost(a, i-1, i), memo[i-2]+cost(a, i-2, i))
	}

	fmt.Println(memo[n-1])
}


Measured memory_bytes: 2688
#include<stdio.h>
int main(void)
{
	int a[4+1],b[4+1],x,y;
	while(scanf("%d %d %d %d %d %d %d %d",&a[1],&a[2],&a[3],&a[4],&b[1],&b[2],&b[3],&b[4])!=EOF) {
		x=0;
		y=0;
		if(a[1]==b[1]) {
			x+=1;
		}
		if(a[2]==b[2]) {
			x+=1;
		}
		if(a[3]==b[3]) {
			x+=1;
		}
		if(a[4]==b[4]) {
			x+=1;
		}
		if((a[1]==b[2])||(a[1]==b[3])||(a[1]==b[4])) {
			y+=1;
		}
		if((a[2]==b[1])||(a[2]==b[3])||(a[2]==b[4])) {
			y+=1;
		}
		if((a[3]==b[1])||(a[3]==b[2])||(a[3]==b[4])) {
			y+=1;
		}
		if((a[4]==b[1])||(a[4]==b[2])||(a[4]==b[3])) {
			y+=1;
		}
		printf("%d %d\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 596
import sys
from io import StringIO
import unittest

doTest=0

def yn(n):
    if n==1:
        print("Yes")
    else:
        print("No")
    return

def resolve():
    readline=sys.stdin.readline

    a,b=list(map(int, readline().strip().split()))

    for i in range(10000):
        if a==int(i * 0.08) and b==int(i * 0.1):
            print(i)
            return
    print(-1)

    return

if doTest==0:
    resolve()
    sys.exit()

Measured memory_bytes: 6380
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
int main()
{
    char s[10010],c;
    scanf("%s",s);
    int n=strlen(s);
    c=s[n-1];
    if(c=='2'||c=='4'||c=='5'||c=='7'||c=='9')
        cout<<"hon";
    else if(c=='0'||c=='1'||c=='6'||c=='8')
        cout<<"pon";
    else if(c=='3')
        cout<<"bon";
    return 0;
}


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

#define ll long long

int main() {
	int k;
	int len;
	string s;
	string sout;
	cin >> k;
	cin >> s;
	len = s.length();
	if (len <= k)cout << s;
	else {
		sout = s.substr(0, k);
		sout += "...";
		cout << sout;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

using pii = pair<int, int>;

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vec<pii, 2> G(N);
    for (int i = 0; i < N - 1; i++) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      G[a].emplace_back(b, i);
      G[b].emplace_back(a, i);
    }
    int M;
    cin >> M;
    vector<pii> rules;
    for (int i = 0; i < M; i++) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      rules.emplace_back(a, b);
    }
    vector<ll> edge_masks(N);
    auto dfs = [&](auto& dfs, int v, int p = -1, ll m = 0) -> void {
      edge_masks[v] = m;
      for (auto e : G[v]) {
        if (e.fst == p) continue;
        dfs(dfs, e.fst, v, m | (1ll << e.snd));
      }
    };
    dfs(dfs, 0);
    ll res = 0;
    vector<ll> white(1 << M, 0);
    for (int m = 1; m < (1 << M); m++) {
      int i = __builtin_ctz(m);
      int x = rules[i].fst, y = rules[i].snd;
      ll w = edge_masks[x] ^ edge_masks[y];
      white[m] = white[m ^ (1 << i)] | w;
    }
    for (int m = 0; m < (1 << M); m++) {
      ll w = white[m];
      int c = __builtin_popcount(m);
      ll ways = 1ll << ((N - 1) - __builtin_popcountll(w));
      if (c % 2 == 0) {
        res += ways;
      } else {
        res -= ways;
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 8576
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

ct = 0
R, G, B, N = na()
for r in range((N // R) + 1):
    for g in range((N // G) + 1):
        if N < r * R + g * G:
            break
        elif (N - r * R - g * G) % B == 0:
            ct += 1
print(ct)


Measured memory_bytes: 40428
#include <bits/stdc++.h>
 
using namespace std;
 
#define PB(x)	push_back(x)
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define MP(x)	make_pair(x);
    
#define debug(x) 		cerr << #x << '=' << x << endl;
#define debug2(x, y)	cerr << #x << '=' << x << ' ' << #y << '=' << y << endl;
#define debugn(_a)		cerr << #_a << ": "; for (auto _x: _a) cerr << _x << ' '; cerr << endl;
#define debugm(a) 		cerr << #a << ":\n"; \
						for (auto v: a) { for(auto x: v) cout << x << ' '; cerr << "\n"; }
 
#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long
 
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vii;
typedef vector<string> vs;
typedef unsigned long long ull;
 
const int INF  = LONG_LONG_MAX;
const int NINF = LONG_LONG_MIN;
const int mmod = 998244353;

const int N = 100009;

vi adj[N];

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

// g++ -Wall -Wextra -Wshadow -fsanitize=undefined 


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <boost/multi_array.hpp>
#include <boost/range/algorithm.hpp>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
#define MAX 310
#define INF 1000000000000
ll dp1[MAX][MAX];
ll dp2[MAX][MAX];

void warshall_floyd(ll dp[MAX][MAX], int n) {
  for (int k = 0; k < n; k++) {      // 経由する頂点
    for (int i = 0; i < n; i++) {    // 始点
      for (int j = 0; j < n; j++) {  // 終点
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
}

int main() {
  int n, m;
  ll l;
  cin >> n >> m >> l;
  vector<int> a(m), b(m);
  vector<ll> c(m);
  rep(i, m) { cin >> a[i] >> b[i] >> c[i]; }
  int q;
  cin >> q;
  vector<int> s(q), t(q);
  rep(i, q) { cin >> s[i] >> t[i]; }

  rep(i, n) {
    rep(j, n) {
      dp1[i][j] = INF;
      dp2[i][j] = INF;
    }
  }
  rep(i, n) { dp1[i][i] = 0; }
  rep(i, m) {
    dp1[a[i] - 1][b[i] - 1] = c[i];
    dp1[b[i] - 1][a[i] - 1] = c[i];
  }

  warshall_floyd(dp1, n);

  rep(i, n) {
    rep(j, n) {
      if (dp1[i][j] <= l) dp2[i][j] = 1;
    }
    dp2[i][i] = 0;
  }
  warshall_floyd(dp2, n);

  rep(i, q) {
    int temp =
        (dp2[s[i] - 1][t[i] - 1] < 10000) ? dp2[s[i] - 1][t[i] - 1] - 1 : -1;
    cout << temp << endl;
  }

  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> v(N), P(N), Q(N);
  for(int i = 0; i < N; i++){
     v.at(i) = i + 1;
    cin >> P.at(i);
  }
  for(int i = 0; i < N; i++){
    cin >> Q.at(i);
  }
  int PPP = 0, QQQ = 0;
  int A = 1;
  while(next_permutation(v.begin(),v.end())) {
    bool PP = true, QQ = true;
    for(int i = 0; i < N; i++){
      if (v.at(i) != P.at(i)) {
        PP = false;
      }
      if (v.at(i) != Q.at(i)) {
        QQ = false;
      }
    }
    if (PP) {
      PPP = A;
    }
    if (QQ) {
      QQQ = A;
    }
    A++;
  }
  if (PPP <= QQQ) {
    cout << QQQ - PPP << endl;
  }
  else {
    cout << PPP - QQQ << endl;
  }
}

Measured memory_bytes: 3636
# coding: utf-8
# Your code here!
N,M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))
LAST = 10**6
MOD = 10**9 + 7
S.append(LAST)
T.append(LAST)
dp = [[0 for j in range(M+2)] for i in range(N+2)]
total = [[0 for j in range(M+2)] for i in range(N+2)]
for i in range(N+1):
    for j in range(M+1):
        I,J = i+1,j+1
        total[I][J] = (total[I][J-1] + total[I-1][J] - total[I-1][J-1]) % MOD
        if S[i] != T[j]:
            continue
        
        dp[I][J] = total[I-1][J-1] + 1
        total[I][J] = (total[I][J] +  dp[I][J]) % MOD
print(dp[N+1][M+1])

Measured memory_bytes: 107740
#include<bits/stdc++.h>
#define INF 2000000000
#define int long long int
#define MOD 1000000007
#define pb push_back
#define cin1(n) (cin >> n)
#define cin2(a,b) (cin >> a >> b)
#define cin3(a,b,c) (cin >> a >> b >> c)
#define cout(n) (cout << n << endl)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define fr first 
#define sc second 
#define EPS (1e-10)

using namespace std;

typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<pair<int,int>> vpii;
typedef vector<string> vs;
typedef vector<vector<string>> vss;
typedef pair<int,int> pii;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int n,m;
int a,b;
int p,q;

pii input(string t1,string t2) {
	int ret1,ret2;

	ret1 = stoi(t1.substr(6,2)) + 60 * stoi(t1.substr(3,2)) + 60 * 60 * stoi(t1.substr(0,2));
	ret2 = stoi(t2.substr(6,2)) + 60 * stoi(t2.substr(3,2)) + 60 * 60 * stoi(t2.substr(0,2));
	return make_pair(ret1,ret2);
}

signed main() {

	while(1) {
		cin1(n);
		if (n == 0) break;

		vpii table(n,make_pair(0,0));
		rep(i,0,n) {
			string time1,time2;
			cin2(time1,time2);
			table[i] = input(time1,time2);	
		}

		sort(table.begin(),table.end());
		
		int idx = 0;
		vector<pair<bool,int>> train;
		train.pb(make_pair(true,0));
		rep(i,0,60*60*24) {
			rep(j,0,train.size()) {
				if (train[j].sc == i) {
					train[j].fr = true;
					train[j].sc = 0;
				}
			}
			if (table[idx].fr == i) {
				bool flag = false;
				rep(j,0,train.size()) {
					if (train[j].fr) {
						train[j].fr = false;
						train[j].sc = table[idx].sc;
						flag = true;
						break;
					}
				}
				if (!flag) {
					train.pb(make_pair(false,table[idx].sc));
				}
				idx++;
				i--;
			}
		}
		cout(train.size());
	}

	return 0;
}

Measured memory_bytes: 3124
/*
 *  Created on: 2 / 5 / 2020
 *  Author:     Eslam Waheed
 */
#include <bits/stdc++.h>
//#include <bits/BIGINT.h>
//#include <bits/Int128.h>
using namespace std;

//#define _CRT_SECURE_NO_WARNINGS
//#define __USE_MINGW_ANSI_STDIO
#define Eslam__Waheed ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

#define ll   long long
#define ull  unsigned ll
#define dd   double
#define ld   long dd
#define ss   string

#define pb      push_back
#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n)  cout << fixed << setprecision(n);
#define iq(v)   v.resize(unique(v.begin(),v.end())-v.begin())
#define sz(s)   (ll)(s.size())
#define endl    '\n'

#define loop(i,m,n)  for(ll i=m;i<n;i++)

ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }

//const ll mod = 1e9 + 7;
//__int128
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/
int main()
{
    //stp(0)
    Eslam__Waheed
        ll n; cin >> n;
    ll c = 0;
    ll a = 100;
    while (a < n)
    {
        a += (a / 100);
        c++;
    }
    cout << c;
}

Measured memory_bytes: 3648
#include <iostream>

using namespace std;

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

  int c2 = 0, c4 = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;

    if (x % 4 == 0) c4++;
    else if (x % 2 == 0) c2++;
  }

  n -= 2 * c4;
  cout << (n <= c2 || n <= 1 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
namespace io
{
	const int N=1<<20;
	char buf[N],*t1=buf,*t2=buf;
	#ifdef cjy
	#define getc() getchar()
	#else
	#define getc() t1==t2&&(t2=(t1=buf)+fread(buf,1,N,stdin),t1==t2)?EOF:*t1++
	#endif
	inline int read()
	{
		static int an,f;an=0,f=1;
		static char ch;ch=getc();
		while(ch<48||ch>57)ch=='-'?f=-1:0,ch=getc();
		while(ch>=48&&ch<=57)an=(an<<3)+(an<<1)+(ch^48),ch=getc();
		return an*f;
	}
	char buff[N],*T=buff;
	void flush(){fwrite(buff,1,T-buff,stdout);T=buff;}
	inline void putc(char ch){if(T==buff+N)flush();*T++=ch;}
	inline void print(int x)
	{
		if(x<0)putc('-'),x=-x;
		if(!x)return putc('0'),void();
		static int st[20],tp;
		while(x)st[++tp]=x%10,x/=10;
		while(tp)putc(st[tp]^48),--tp;
	}
}
using io::read;
using io::putc;
using io::flush;
using io::print;
int n,p[250050],cur[250050],ans,fx[4]={1,0,-1,0},fy[4]={0,1,0,-1};
bool vis[250050];
void upd(int w)
{
	int y=(w-1)%n+1,x=(w-y)/n+1,xx,yy,ww;
	for(int i=0;i<4;++i)
	{
		xx=x+fx[i],yy=y+fy[i];
		if(xx==0||yy==0||xx==n+1||yy==n+1)continue;
		ww=(xx-1)*n+yy;
		if(cur[w]+(!vis[ww])<cur[ww])cur[ww]=cur[w]+(!vis[ww]),upd(ww);
	}
}
int main()
{
	n=read();
	for(int i=1;i<=n*n;++i)p[i]=read();
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			cur[(i-1)*n+j]=min(min(i,n-i+1),min(j,n-j+1));
	for(int i=1;i<=n*n;++i)
	{
		ans+=cur[p[i]]-1,--cur[p[i]],vis[p[i]]=1,upd(p[i]);
		// printf("%d:\n",i);
		// for(int j=1;j<=n;++j)
		// {
		// 	for(int k=1;k<=n;++k)printf("%d ",cur[(j-1)*n+k]);
		// 	printf("\n");
		// }
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 20260
#include<bits/stdc++.h>
using namespace std;
#define MAX 100005

int n,a,b,c;
vector<int> G[MAX];
int size[MAX];
int par[MAX];
int dep[MAX];
int depth[MAX];
int parent[MAX];

void idfs(int pos){
  int m=-1;
  if(G[pos].empty())return;
  for(int i=0;i<(int)G[pos].size();i++){
    int to=G[pos][i];
    depth[to]=depth[pos]+1;
    idfs(to);
    size[pos]+=size[to];
    if(m==-1||size[m]<size[to])m=to;
  }
  par[m]=pos;
}

int calc(int x){
  if(par[x]==x)return x;
  return par[x]=calc(par[x]);
}

void init(){
  for(int i=0;i<MAX;i++){
    size[i]=1;
    par[i]=i;
  }
  for(int i=0;i<n;i++){
    scanf("%d",&a);
    while(a--){
      scanf("%d",&b);
      G[i].push_back(b);
      parent[b]=i;
    }
  }
  parent[0]=-1;
  idfs(0);
  for(int i=0;i<n;i++){
    int p=calc(i);
    while(p){
      p=par[parent[p]];
      dep[i]++;
    }
  }
}

int main(){
  scanf("%d",&n);
  init();
  int q;
  scanf("%d",&q);
  while(q--){
    scanf("%d %d",&a,&b);
    while(par[a]!=par[b]){
      if(dep[a]<dep[b])swap(a,b);
      a=parent[par[a]];
    }
    printf("%d\n",(depth[a]<depth[b]?a:b));      
  }
  return 0;
}

Measured memory_bytes: 16032
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	n1 := n / 100
	n2 := n % 100 / 10
	n3 := n % 100 % 10

	if n1 == 7 {
		fmt.Println("Yes")
		return
	}
	if n2 == 7 {
		fmt.Println("Yes")
		return
	}
	if n3 == 7 {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    string S, T;
    cin >> S >> T;
    T.pop_back();
    if (S == T) {
        cout << "Yes" << '\n';
    }else {
        cout << "No" << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


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

int solve(string s);

int main() {
  string s;
  cin >> s;
  int i;
  for (i = s.length(); i > 0; i--) {
    s.pop_back();
    int solve_ret = solve(s);
    if (solve_ret) {
      cout << solve_ret << endl;
      break;
    }
    if (i == s.length() - 1) {
      cout << 0 << endl;
    }
  }
  return 0;
}

int solve(string s) {
  if (s.length() % 2 != 0) {
    return 0;
  }
  int s_length = s.length();
  int i;
  for (i = 0; i < s.length() / 2; i++) {
    if (s.at(i) != s.at(i + s_length / 2)) {
      return 0;
    }
  }
  return s_length;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int flag=0;
	if(a==b||a==c||b==c)
		if(a!=c||a!=b)
			flag=1;
	if(flag)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int A, B;
    int max;
    scanf("%d %d",&A, &B);
    if(A+B>A*B){
        if(A+B>A-B)max = A+B;
        else max = A-B;
    }else{
        if(A*B > A-B)max = A*B;
        else max = A-B;
    }
    printf("%d\n",max);
    return 0;
}



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

int main() {
    string s;
    cin >> s;
    if(s == "Sunny") cout << "Cloudy" << endl;
    else if(s == "Cloudy") cout << "Rainy" << endl;
    else if(s == "Rainy") cout << "Sunny" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }

template<typename T>
T gcd(T x, T y) {
    if (y==0) return x;
    return gcd(y, x % y);
}

template<typename T>
T lcm(T x, T y) {
    T g = gcd(x, y);
    return x / g * y;
}

int n;
ll a[10];

int main() {
    cin >> n;
    rep(i, n) cin >> a[i];

    ll ans = 1;
    rep(i, n) {
        ans = lcm(a[i], ans);
    }
    cout << ans << endl;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

    int N; cin >> N;
    ve_vei F(N, vei(10)); rep(i,N) rep(j,10) cin >> F[i][j];
    ve_vei P(N, vei(11)); rep(i,N) rep(j,11) cin >> P[i][j];
    ll ans = -INF;
    rep1(i,1024) {
        int a11 = (i % 2);
        int a12 = (i / 2) % 2;
        int a21 = (i / 4) % 2;
        int a22 = (i / 8) % 2;
        int a31 = (i / 16) % 2;
        int a32 = (i / 32) % 2;
        int a41 = (i / 64) % 2;
        int a42 = (i / 128) % 2;
        int a51 = (i / 256) % 2;
        int a52 = (i / 512) % 2;
        
        int c[101];
        rep(j,N){
            c[j] = F[j][0] * a11 + F[j][1]* a12 + F[j][2] * a21 + F[j][3] * a22 + F[j][4] * a31 + F[j][5] * a32 + F[j][6] * a41 + F[j][7] * a42 + F[j][8] * a51 + F[j][9] * a52;
        }
        ll temp = 0;
        rep(j,N) temp += P[j][ c[j] ];
        ans = max(ans, temp);
    }
    cout << ans << endl;
    return 0;
    


}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <functional>
#include <cassert>
#define SIZE 5005
#define BT 64*128*2
#define MX 205

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

struct segtree
{
	ll seg[BT];
	int mum;
	
	void init(int n)
	{
		mum=1;
		while(mum<n) mum<<=1;
		for(int i=0;i<mum*2;i++) seg[i]=0;
	}
	void add(int k,ll x)
	{
		k+=mum-1;
		seg[k]=x;
		while(k>0)
		{
			k=(k-1)/2;
			seg[k]=max(seg[k*2+1],seg[k*2+2]);
		}
	}
	ll get(int a,int b,int k,int l,int r)
	{
		if(b<=l||r<=a) return 0LL;
		if(a<=l&&r<=b) return seg[k];
		else
		{
			ll vl=get(a,b,k*2+1,l,(l+r)/2);
			ll vr=get(a,b,k*2+2,(l+r)/2,r);
			return max(vl,vr);
		}
	}
	ll get(int a,int b)
	{
		return get(a,b,0,0,mum);
	}
};
segtree seg[MX];
ll S[SIZE];
ll ans[SIZE];
ll B[SIZE][MX];
ll mx[MX];
int n,m;

void solve(int l,int r,int L,int R)//[l,r]のoptは[L,R]
{
	if(l>r) return;
	int t=(l+r)/2;
	int start=max(L,t);
	for(int i=0;i<m;i++) mx[i]=seg[i].get(t,start+1);
	ll sum=0;
	for(int i=0;i<m;i++) sum+=mx[i];
	int pos=start;
	ll now=sum-S[start];
	for(int i=start;i<=R;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(mx[j]<B[i][j])
			{
				sum+=B[i][j]-mx[j];
				mx[j]=B[i][j];
			}
		}
		if(now<=sum-S[i])
		{
			now=sum-S[i];
			pos=i;
		}
	}
	//printf("%d %d : %lld\n",t,pos,now);
	ans[t]=now+S[t];
	solve(l,t-1,L,pos);
	solve(t+1,r,pos,R);
}
int main()
{
	scanf("%d %d",&n,&m);
	S[0]=0;
	for(int i=1;i<n;i++)
	{
		scanf("%lld",&S[i]);
		S[i]+=S[i-1];
	}
	for(int i=0;i<m;i++) seg[i].init(n+2);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			scanf("%lld",&B[i][j]);
			seg[j].add(i,B[i][j]);
		}
	}
	solve(0,n-1,0,n-1);
	ll ret=0;
	for(int i=0;i<n;i++) ret=max(ret,ans[i]);
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 33920
#include <stdio.h>
#define mod 1000000007
int H, W, K, ret, res, fact[300000], inv[300000], factinv[300000];
int ncr(int n, int r) { return (n - r >= 0 && r >= 0) ? 1LL * fact[n] * factinv[r] % mod * factinv[n - r] % mod : 0; }
int cal(int a, int b) { return (ncr(a + b, b) - ncr(a + b, b - 1) + mod) % mod; }
int main() {
	scanf("%d%d%d", &H, &W, &K);
	fact[0] = 1;
	for (int i = 1; i < 300000; i++) fact[i] = 1LL * fact[i - 1] * i % mod;
	inv[1] = 1;
	for (int i = 2; i < 300000; i++) inv[i] = 1LL * inv[mod % i] * (mod - mod / i) % mod;
	factinv[0] = 1;
	for (int i = 1; i < 300000; i++) factinv[i] = 1LL * factinv[i - 1] * inv[i] % mod;
	for (int i = 0; i <= K; i++) {
		res = 1LL * cal(W + i, i) * cal(H + K - i, K - i) % mod * ncr(H + W + 2 * K, W + 2 * i) % mod;
		ret = (ret + res) % mod;
	}
	printf("%d\n", ret);
	return 0;
}

Measured memory_bytes: 6260
n=int(input())
h=list(map(int,input().split()))
dp=[0 for i in range(n)]
dp[1] = dp[0] + abs(h[1]-h[0])
for i in range(2,n):
  dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),
              dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])

Measured memory_bytes: 52720
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;


int n, m, fa[N];

int find(int x) {
    if (x != fa[x]) {
        return fa[x] = find(fa[x]);
    }
    return x;
}

int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        fa[i] = i;
    }
    for (int i = 1; i <= m; i++) {
        int u, v;
        cin >> u >> v;
        int fy = find(u), fx = find(v);
        if (fy != fx) {
            fa[fy] = fx;
        }
    }
    set<int> ans;

    for (int i = 1; i <= n; i++) {
        int fy = find(i);
        ans.insert(fy);
    }
    cout << ans.size() - 1 << endl;
}

Measured memory_bytes: 7940
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    set<int>s;
    int n,j;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>j;
        s.insert(j);
    }
    if(s.size()==n)
    {
        cout<<"YES";
    }
    else
    cout<<"NO";
}

Measured memory_bytes: 10496
def main():
    N, K = list(map(int, input().split(' ')))
    H = [int(input()) for _ in range(N)]
    H.sort()
    min_diff = H[-1] - H[0]
    for i in range(N - K + 1):
        min_diff = min([min_diff, H[i + K - 1] - H[i]])
    print(min_diff)


if __name__ == '__main__':
    main()

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);



int main(void)
{
    IOS
    string s;
    cin >> s;
    int len = s.length();
    int one = 0;
    int zero = 0;
    int count = 0;
    for(auto i = 0; i < len; i++) {
        if (s[i] == '0') zero++;
        if (s[i] == '1') one++;     
        if ((one > 0) && (zero > 0)) {
            zero--;
            one--;
            count++;
        }   
    }
    cout << count * 2 << endl;
    return 0;
    }


Measured memory_bytes: 512
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector as V
import Debug.Trace as De

-- 入出力ライブラリ（コピペ） --
readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine

-- 関数 --
func :: Int -> V.Vector Int -> [Int]
func nn av = solve 0 0 0
  where
    solve :: Int -> Int -> Int -> [Int]
    solve n px qx
      | n == 300100 = []
      | px == nn = ((px-qx):(solve (n+1) px px))
      | (av V.! px) /= n = ((px-qx):(solve (n+1) px px))
      | (av V.! qx) == n = solve n (px+1) qx

get1 :: [Int] -> Int
get1 x = (x!!0)

get2 :: [Int] -> Int
get2 x = (x!!1)

hantei :: (Int, Int) -> Bool
hantei x
  | fst(x) == 0 = True
  | otherwise = False

reflect :: [Int] -> Int -> [Int]
reflect x border = map hikizan x
  where
    hikizan :: Int -> Int
    hikizan t = t - border

tansaku :: Int -> V.Vector Int -> V.Vector Int -> V.Vector Int -> V.Vector Int -> Int
tansaku n xv yv ix iy = solve 0
  where
    solve :: Int -> Int
    solve pos
      | pos == n = 0
      | otherwise = newnum + (solve (pos+1))
        where newnum = if ((ix V.! (xv V.! pos)) == 1 && (iy V.! (yv V.! pos)) == 1) then 1 else 0

main = do
  -- 入力 --
  [h, w, n] <- (map read . words) <$> getLine
  a <- getIntNList n
  
  -- パース --
  let x = map get1 a
  let y = map get2 a
  let xw = (V.fromList x) :: V.Vector Int
  let yw = (V.fromList y) :: V.Vector Int
  let xs = sort x
  let ys = sort y
  let xv = (V.fromList xs) :: V.Vector Int
  let yv = (V.fromList ys) :: V.Vector Int
  
  -- 本質部分 --
  let numx = func n xv
  let numy = func n yv
  let maxx = maximum numx
  let maxy = maximum numy
  let evalx = reflect numx maxx
  let evaly = reflect numy maxy
  let ex = zip evalx [0..300100]
  let ey = zip evaly [0..300100]
  let fx = filter hantei ex
  let fy = filter hantei ey
  let gx = snd (unzip fx)
  let gy = snd (unzip fy)
  let gx2 = (V.fromList gx) :: V.Vector Int
  let gy2 = (V.fromList gy) :: V.Vector Int
  
  -- 探索パート --
  let szx = length gx
  let szy = length gy
  let hx = func szx gx2
  let hy = func szy gy2
  let ix = (V.fromList hx) :: V.Vector Int
  let iy = (V.fromList hy) :: V.Vector Int
  let ret = tansaku n xw yw ix iy
  
  -- 答えを出力 --
  let ans = if (ret == (szx * szy)) then (maxx + maxy - 1) else (maxx + maxy)
  putStrLn $ show ans

Measured memory_bytes: 268164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
//ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
//ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
ll ketawa(ll a){ll r=0;while(a){r+=a%10;a/=10;}return r;}


int main(){

  ll n;
  cin >> n;
  set<ll> se;

  FOR(i,0,n){
    ll a;
    cin >> a;
    if(se.count(a)){
      se.erase(a);
    }else{
      se.insert(a);
    }
  }
  cout << se.size() << endl;
}


Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <math.h>
#include <stack>
#include <tuple>
#include <cstring>
#include <chrono>
#include <bitset>
#include <list>
#include <stdlib.h>
#include <iomanip>
#include <bitset>
#include <chrono>

using namespace std;

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long

bool comparator(const pair<ll, ll> &x, const pair<ll, ll> &y)
{
    return x.second - x.first < y.second - y.first;
}

ll gcd(ll x, ll y)
{
    return y == 0LL ? x : gcd(y, x % y);
}

struct dot {
    ll coordinate, tree;
    bool is_left;

    dot(ll _coordinate, ll _tree, bool _is_left)
    {
        coordinate = _coordinate;
        tree = _tree;
        is_left = _is_left;
    }

    ll dist() const
    {
        return abs(coordinate - tree);
    }

    bool operator<(const dot& other) const
    {
        return dist() > other.dist();
    }
};

bool is_free(ll x, set<ll> &used_coords)
{
    return used_coords.find(x) == used_coords.end();
}

int main()
{
    std::ios::sync_with_stdio(false);

    ll a, b, c;
    cin >> a >> b >> c;
    
    ll remove = min(a, c);
    a = a - remove;
    c -= remove;
    
    b = b - min(b, c);
    
    cout << a << ' ' << b << endl;

    return 0;
}


Measured memory_bytes: 256