akhauriyash/Code-Regression huggingface dataset:
class Mint:
    MOD = 1000000007  # Must be a prime
    CACHE_FACTORIALS = [1, 1]

    def __init__(self, v):
        if self.__isally(v):
            self.v = v.v
        else:
            self.v = v % self.MOD

    @property
    def inv(self):
        return Mint(self.__minv(self.v))

    @classmethod
    def factorial(cls, v):
        for i in range(len(cls.CACHE_FACTORIALS), int(v) + 1):
            cls.CACHE_FACTORIALS.append(cls.CACHE_FACTORIALS[-1] * i % cls.MOD)
        return Mint(cls.CACHE_FACTORIALS[int(v)])

    @classmethod
    def perm(cls, n, r):
        if n < r or r < 0:
            return 0
        return cls.factorial(n) // cls.factorial(n - r)

    @classmethod
    def comb(cls, n, r):
        if n < r or r < 0:
            return 0
        return cls.perm(n, r) // cls.factorial(r)

    @classmethod
    def __isally(cls, v) -> bool:
        return isinstance(v, cls)

    @classmethod
    def __minv(cls, v) -> int:
        return pow(v, cls.MOD - 2, cls.MOD)

    @classmethod
    def __mpow(cls, v, w) -> int:
        return pow(v, w, cls.MOD)

    def __str__(self):
        return str(self.v)
    __repr__ = __str__

    def __int__(self):
        return self.v

    def __eq__(self, w):
        return self.v == w.v if self.__isally(w) else self.v == w

    def __add__(self, w):
        return Mint(self.v + w.v) if self.__isally(w) else Mint(self.v + w)
    __radd__ = __add__

    def __sub__(self, w):
        return Mint(self.v - w.v) if self.__isally(w) else Mint(self.v - w)

    def __rsub__(self, u):
        return Mint(u.v - self.v) if self.__isally(u) else Mint(u - self.v)

    def __mul__(self, w):
        return Mint(self.v * w.v) if self.__isally(w) else Mint(self.v * w)
    __rmul__ = __mul__

    def __floordiv__(self, w):
        return Mint(self.v * self.__minv(w.v)) if self.__isally(w) else Mint(self.v * self.__minv(w))

    def __rfloordiv__(self, u):
        return Mint(u.v * self.__minv(self.v)) if self.__isally(u) else Mint(u * self.__minv(self.v))

    def __pow__(self, w):
        return Mint(self.__mpow(self.v, w.v)) if self.__isally(w) else Mint(self.__mpow(self.v, w))

    def __rpow__(self, u):
        return Mint(self.__mpow(u.v, self.v)) if self.__isally(u) else Mint(self.__mpow(u, self.v))


N, K = map(int, input().split())

for i in range(1, K + 1):
    print(Mint.comb(N - K + 1, i) * Mint.comb(K - 1, i - 1))


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


constexpr lint mod = 1e9 + 7;
inline lint emod(lint a, lint p = mod) { return (a % p + p) % p; }
inline lint powm(lint a, lint n, lint p = mod) { return !n ? 1 : powm(a * a % p, n >> 1, p) * (n & 1 ? a : 1) % p; }

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  lint n, k; cin >> n >> k;
  cout << emod(powm(k, n)) << '\n';
}


Measured memory_bytes: 3172
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringJoiner;
import java.util.StringTokenizer;
import java.util.function.IntUnaryOperator;
import java.util.function.LongUnaryOperator;

public class Main {
    static In in = new In();
    static Out out = new Out();
    static long mod = 1000000007;
    static long inf = 0xfffffffffffffffL;

    void solve() {
        String s = in.next();
        out.println((s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)) ? "Yes" : "No");
    }

    public static void main(String[]$) {
        new Main().solve();
        out.flush();
    }
}

class In {
    private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 0x10000);
    private StringTokenizer tokenizer;

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

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

    long nextLong() {
        return Long.parseLong(next());
    }

    char[][] nextCharArray(int n, int m) {
        char[][] a = new char[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        return a;
    }

    int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

    long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextLong();
        }
        return a;
    }

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}

class Out {
    private PrintWriter out = new PrintWriter(System.out);
    boolean autoFlush = false;

    void println(Object... a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (Object obj : a) {
            joiner.add(String.valueOf(obj));
        }
        out.println(joiner);
        if (autoFlush) {
            out.flush();
        }
    }

    void println(int[] a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (int i : a) {
            joiner.add(Integer.toString(i));
        }
        out.println(joiner);
        if (autoFlush) {
            out.flush();
        }
    }

    void println(long[] a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (long i : a) {
            joiner.add(Long.toString(i));
        }
        out.println(joiner);
        if (autoFlush) {
            out.flush();
        }
    }

    void flush() {
        out.flush();
    }
}


Measured memory_bytes: 22996
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int M = scanner.nextInt();
		int[] a = new int[M];
		int[] b = new int[M];
		int[] ans = new int[N + 1];
		for (int i = 0; i < M; i++) {
			a[i] = scanner.nextInt();
			b[i] = scanner.nextInt();
			ans[a[i]]++;
			ans[b[i]]++;
		}
		scanner.close();

		for(int i = 1; i < ans.length; i++) {
			System.out.println(ans[i]);
		}
	}

}


Measured memory_bytes: 21844
import math

def f(x):
    dic={}
    for a,b in enumerate(sorted(x)):
        dic[b]=a+1
    y=[]
    for i in range(len(x)):
        y.append(dic[x[i]])
    return y

def count(a):
  if len(a) ==1:
    return 1
  return (a[0]-1)*math.factorial(len(a)-1)+count(f(a[1:]))

N=int(input())
p=list(map(int,input().split(' ')))
q=list(map(int,input().split(' ')))

print(abs(count(p)-count(q)))

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
char ch[100005],tt[100005];
int a[100005];
int len,an=0,to=0,tp=0;
bool flag=1;
int abs(int x){return x>0?x:-x;}
int main(){
	scanf("%s",ch+1);
	len=strlen(ch+1);
	for(int i=1;i<=len;i++){
		if(flag&&ch[i]=='x'){tp++;continue;}
		flag=0;int ss=0;
		if(ch[i]!='x')
			tt[++to]=ch[i];
		else{
			for(;i<=len;i++){
				if(ch[i]!='x'){a[to]=ss;break;}
				ss++;
			}
			i--;
		}
	}
	for(int i=len;i>=1;i--){
		if(ch[i]!='x')break;
		tp--;
	}
	an+=abs(tp);
	for(int i=1,j=to;i<j;i++,j--)
		if(tt[i]!=tt[j])return printf("-1"),0;
	for(int i=1,j=to-1;i<j;i++,j--){
		an=an+abs(a[i]-a[j]);
	}
	printf("%d",an);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    string s;
    cin >> s;
    long long int n = s.size();
    long long int res = n * (n - 1) / 2;
    vector<int> v(26, 0);
    for (int i = 0; i < n; i++) {
        res -= v[s[i] - 'a'];
        v[s[i] - 'a']++;
    }
    cout << res + 1 << endl;
}


Measured memory_bytes: 3752
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

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

		int count = sc.nextInt();
		Set<String> array = new TreeSet<>();

		sc.nextLine();
		Map stores = new TreeMap<>();
		for (int i = 1; i <= count; i++) {
			String str = sc.next();
			int point = sc.nextInt();
			if (stores.containsKey(str)) {
				Map<Integer, List> bbb = (TreeMap) stores.get(str);
				if (bbb.containsKey(point)) {
					List list = (List) bbb.get(point);
					list.add(i);
					bbb.put(point, list);
				} else {
					List<Integer> list = new ArrayList<>();
					list.add(i);
					bbb.put(point, list);
				}
				stores.put(str, bbb);
			} else {
				Map<Integer, List> ddd = new TreeMap<>(Collections.reverseOrder());
				List<Integer> list = new ArrayList<>();
				list.add(i);
				ddd.put(point, list);
				stores.put(str, ddd);
			}
			sc.nextLine();
		}
		for (Object map : stores.values()) {
			Map mp = (Map) map;
			for (Object list : mp.values()) {
				List lst = (List) list;
				for (Object obj : lst) {
					System.out.println(obj);
				}
			}
		}
	}
}

Measured memory_bytes: 19924
int main(void){
   int i;
   int x[200],y[200]; 
  int n,m,k; 
    scanf("%d",&n);  
 for(i=0;i<2*n;i++){ 
    x[i] = i+1;  
 }  
   scanf("%d",&m);
   while(m--){
     scanf("%d",&k); 
      if(k){ 

      for(i=0;i<k;i++){  
      y[i+(2*n-k)] = x[i]; 
      } 
      for(i=k;i<2*n;i++){
        y[i-k] = x[i];
       }   
  }     else{ 
      for(i=0;i<n;i++){    
     y[2*i]   = x[i]; 
      y[2*i+1] = x[i+n]; 
      }  
   }   
    for(i=0;i<2*n;i++){   
    x[i] =y[i];   
  } 
  }  
   for(i=0;i<2*n;i++){
    printf("%d\n",x[i]); 
  }  
   return 0;
 }

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

typedef long long ll;

string s;
ll k;

int main()
{
	cin >> s;
	cin >> k;
	for (int i = 0; i < s.length(); i++)
		if (s[i] != '1') { cout << s[i] << endl; return 0; }
		else {
			k--;
			if (k == 0) { cout << s[i] << endl; return 0; }
		}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MOD 1000000007

int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	int top=0;
	while(q--){
		int t,x;
		scanf("%d%d",&t,&x);
		if(t)top=(top+x)%n;
		else printf("%d\n",(top+x)%n?:n);
	}
}


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

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var count = new int[6];
			while (n-- != 0)
			{
				var h = double.Parse(Console.ReadLine());
				if (h < 165)
					count[0]++;
				else if (165 <= h && h < 170)
					count[1]++;
				else if (170 <= h && h < 175)
					count[2]++;
				else if (175 <= h && h < 180)
					count[3]++;
				else if (180 <= h && h < 185)
					count[4]++;
				else if (185 <= h)
					count[5]++;
			}
			for (int i = 0; i < 6; i++)
			{
				Console.WriteLine("{0}:{1}", i + 1, new string(Enumerable.Repeat('*', count[i]).ToArray()));
			}
		}
	}
}

Measured memory_bytes: 5956
#include <stdio.h>
int main(void)
{
	int n,m,x[1000],d,p,g,i,j;
	scanf("%d%d",&n,&m);
	while(n!=0&&m!=0){
		p=0;
		g=0;
		for(i=0;i!=n;++i)
			scanf("%d",&x[i]);
		for(i=0;i!=m;i++){
			scanf("%d",&d);
			if(g==0){
				p+=d;
				p+=x[p];
				if(p>=n-1)
					g=i+1;
			}
		}
		printf("%d\n",g);
		scanf("%d%d",&n,&m);
	}
}

Measured memory_bytes: 2716
#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
typedef long long llong;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h;
    int a;
    for(int i=0; i<n; i++){
        cin >> a;
        h.push_back(a);
    }

    if (k>=n){
        cout << 0 << endl;
        return 0;
    } 
    
    sort(h.begin(), h.end());
    reverse(h.begin(), h.end());
    llong cnt = 0;
    for(int i=k; i<n; i++){
        cnt += h.at(i);
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1400
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)

point = a[0]
cnt = 0
k = 1
for i in range(1, n-1):
    point += a[k]
    cnt += 1
    if cnt == 2:
        cnt = 0
        k += 1

print(point)


Measured memory_bytes: 31396
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>
#include <stack>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator<< (ostream &out, const vector<int> &b) {
    for (auto k : b) out << k << " ";
    return out;
}

istream& operator>> (istream& in, pii& b) {
    in >> b.first >> b.second;
    return in;
}

ostream& operator<< (ostream& out, const pii& b) {
    out << "{" << b.first << ", " << b.second << "}";
    return out;
}

template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 10;
#else
    #define dbg(x) 57
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 179;
#endif

const ld PI = acos(-1);

#define time clock() / (double) CLOCKS_PER_SEC

// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")  
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0, b = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'p') {
            b--;
            if (b == -1) {
                ans--;
                b += 2;
            }
        } else {
            if (b > 0) {
                b--;
                ans++;
            } else {
                b++;
            }
        }
    }
    cout << ans;
}
/*

*/

Measured memory_bytes: 3756
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include <ctime>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x,y) (((x)+(y)-1)/(y))
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	int N, K;
	cin >> N >> K;
	vector<int>A(N);
	rep(i, N)cin >> A[i];
	int left = 0;
	int right = 1e9;
	while (right - left > 1) {
		int mid = (left + right) / 2;
		int cnt = 0;
		rep(i, N) {
			cnt += dup(A[i], mid) - 1;
		}
		if (cnt <= K)right = mid;
		else left = mid;
	}
	cout << right;
}

Measured memory_bytes: 4792
#include <stdio.h>
#define MAX 25
#define N 100000
#define NIL -1
struct Node {
  int parent;
  int left;
  int right;
};
struct Node T[MAX];

void preParse(int u){
  if(u==NIL)
    return;
  printf(" %d",u);
  preParse(T[u].left);
  preParse(T[u].right);
}

void inParse(int u){
  if(u==NIL)
    return;
  inParse(T[u].left);
  printf(" %d",u);
  inParse(T[u].right);
}

void postParse(int u){
  if(u==NIL)
    return;
  postParse(T[u].left);
  postParse(T[u].right);
  printf(" %d",u);
}


int main(){
  int a,n,i,j,x;
  int id,left,right,y,root;
  int deg=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].parent=NIL;  
  }
    
  for(i=0;i<n;i++){
    scanf("%d%d%d",&id,&left,&right);
    T[id].left=left;
    T[id].right=right;
    if(left != NIL)
      T[left].parent=id;
    if(right != NIL)
      T[right].parent=id;
  }
  
  for(i=0;i<n;i++){
    if(T[i].parent==NIL)
      root=i;
  }
  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");  
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");  


  return 0;
}

Measured memory_bytes: 616
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<set>
#include<cmath>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll INF = 1LL << 60;
const int inf = 1 << 25;
ll n, m, k, y,a, q, d, w = 0, sum = 0, ans = INF; string s;
const int MOD = 1000000007;
int main(void) {
	cin >> n; vector<ll> v(n + 1, 0);
	req(i, n) {
		cin >> v[i];v[i] += v[i - 1];
	}
	req(i, n-1) {
		ans = min(ans, (ll)abs(v[n] -v[i] - v[i]));
	}cout << ans << endl;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    string s;
    int y, m, d;
    while (cin >> s, s != "#") {
        cin >> y >> m >> d;
        if (y < 31) cout << "HEISEI " << y << " " << m << " " << d << endl;
        else if (y == 31 && m <= 4) cout << "HEISEI " << y << " " << m << " " << d << endl;
        else cout << "? " << y - 30 << " " << m << " " << d << endl;
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}


Measured memory_bytes: 3196
#include<iostream>

using namespace std;

int main(void) {
    int n, left, right;
    cin >> n >> left >> right;

    int sum = 0;
    for (int i = 1; i <= n; ++i) {
        string str_num = to_string(i);
        int dsum = 0;
        for (auto s: str_num) {
            dsum += s - '0';
        }
        if (left <= dsum && dsum <= right) {
            sum += i;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
rInt :: String -> Int
rInt str = read str :: Int

main :: IO ()
main = do
    [a,b,c,d] <- map rInt . words <$> getLine
    let ab = a * b
    let cd = c * d
    if ab > cd then
        putStrLn $ show ab
    else if ab < cd then
        putStrLn $ show cd
    else
        putStrLn $ show ab

Measured memory_bytes: 508
/**
 *    author:  tourist
 *    created: 26.01.2020 20:47:14       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> t(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    t[x].push_back(y);
    t[y].push_back(x);
  }
  vector<vector<int>> tin(n, vector<int>(n, -1));
  vector<vector<int>> tout(n, vector<int>(n, -1));
  vector<vector<int>> order(n);
  for (int start = 0; start < n; start++) {
    function<void(int, int)> Dfs = [&](int v, int pr) {
      tin[start][v] = (int) order[start].size();
      order[start].push_back(v);
      for (int j : t[v]) {
        if (j != pr) {
          Dfs(j, v);
        }
      }
      tout[start][v] = (int) order[start].size();
    };
    Dfs(start, -1);
  }
  vector<set<int>> s(n);
  function<void(int, int)> Add = [&](int x, int y) {
    if (x == y) {
      return;
    }
    for (int u : {x, y}) {
      int v = u ^ x ^ y;
      auto it = s[u].lower_bound(tin[u][v]);
      if (it != s[u].begin()) {
        int z = order[u][*prev(it)];
        if (tout[u][v] <= tout[u][z]) {
          Add(z, v);
          return;
        }
      }
    }
    vector<pair<int, int>> go;
    for (int u : {x, y}) {
      int v = u ^ x ^ y;
      auto it = s[u].lower_bound(tin[u][v]);
      while (it != s[u].end() && *it < tout[u][v]) {
        go.emplace_back(v, order[u][*it]);
        it = s[u].erase(it);
      }
      s[u].insert(tin[u][v]);
    }
    for (auto& p : go) {
      Add(p.first, p.second);
    }
  };
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    Add(x, y);
  }
  int ans = 0;
  for (int start = 0; start < n; start++) {
    function<void(int, int, int)> Dfs = [&](int v, int r, int pr) {
      if (s[r].find(tin[r][v]) != s[r].end()) {
        ++ans;
        r = v;
      }
      for (int j : t[v]) {
        if (j != pr) {
          Dfs(j, r, v);
        }
      }
    };
    Dfs(start, start, -1);
  }
  cout << ans / 2 << '\n';
  return 0;
}


Measured memory_bytes: 48896
#include<bits/stdc++.h>
#define ll long long

using namespace std;

void dis(int* As, int N) {
  for (int i = 0; i < N; i++) {
    cout << As[i] << " ";
  }
  cout << endl;
}

int main() {
  int mod = 1e9 + 7;
  
  int N;
  cin >> N;
  ll As[N];
  ll Bs[N+1];
  Bs[0] = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> As[i];
    Bs[i+1] = Bs[i] + As[i];
  }
  
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += (Bs[i]%mod)*As[i];
    ans %= mod;
  }
  cout << ans << endl;
}

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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }
typedef long long ll;


int main(){
  while(1) {
    int m,f,r; cin >> m  >> f >> r;
    if (m == -1 && f == -1 && r == -1) break;
    int t = m + f;
    string R;
    if (m == -1 || f == -1) {
      R="F";
    } else if (t >= 80) {
      R="A";
    } else if (t >= 65 && t < 80) {
      R="B";
    } else if (t >= 50 && t < 65) {
      R="C";
    } else if (t >= 30 && t < 50) {
      R="D";
      if (r >= 50) R="C";
    } else if (t < 30) {
      R="F";
    }
    cout << R << endl;
  }
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
int main() {
	int n;
	scanf("%d", &n);
	map<int, int> cnt;
	int a;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a);
		++cnt[a];
	}
	if (cnt.size() == 1) printf(a ? "No\n" : "Yes\n");
	else if (n % 3) printf("No\n");
	else if (cnt.size() > 3) printf("No\n");
	else {
		bool ok = true;
		int x = 0;
		for (auto& v : cnt) {
			if (v.second != n / 3 && v.second != 2 * n / 3) ok = false;
			x ^= v.first;
		}
		if (cnt.size() == 2) {
			ok &= cnt.begin()->first == 0;
		} else {
			ok &= x == 0;
		}
		printf(ok ? "Yes\n" : "No\n");
	}
}


Measured memory_bytes: 3840
program main;
type
  arr = array [1..1000] of longint;
 
var i, n, t, sum : longint;
    juice : arr;

procedure bubble_sort (var number : arr);
var
  i, t : integer;
  swap : boolean = true;

begin
  while swap do begin
    swap := false;
    for i := 1 to (n-1) do 
      if (number[i] > number[i+1]) then begin  //ascending order
      {if (number[i] < number[i+1]) then begin  //descending order}
        t := number[i];
  	   number[i] := number[i+1];
		   number[i+1] := t;
 	   swap := true;
      end;
  end;
end;

 
begin
  read(n);
  readln(t);
  for i := 1 to n do
    read(juice[i]);
  readln;
  bubble_sort(juice);
  sum := 0;
  for i := 1 to t do
    sum := sum + juice[i];
  writeln(sum);
end.

Measured memory_bytes: 1384
#include<iostream>
using namespace std;
int t[10001];
int f(int x){
  if(t[x]!=0)return t[x];
  return t[x]=f(x-1)+x;
}
int main(){
  int n;
  t[0]=1;
  while(cin>>n){
    cout <<f(n)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1476
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
const int MAXN = 1e4 + 10;
const int MAXD = 1e2 + 10;
const int MOD = 1e9 + 7;
 
vector<int> digitos;
string s;
int N,D;
ll dp[MAXN][2][MAXD];
 
ll solve(int pos,int flag,int resto){
 
	if(pos == N) return (resto == 0);
	if(dp[pos][flag][resto] != -1) return dp[pos][flag][resto];
 
	ll tot = 0;
	int limit = (flag) ? (digitos[pos]) : (9);
	for(int i = 0;i<=limit;i++){
		tot += solve(pos+1,flag && (i == limit), (resto + i) % D );
	}
 
	return dp[pos][flag][resto] = tot % MOD;
 
}
 
int main(){
 
	cin >> s;
	cin >> D;
	N = (int)s.size();
	for(int i = 0;i<N;i++){
		digitos.push_back(s[i] - '0');
	}
	memset(dp,-1,sizeof(dp));
 
	ll ans = solve(0,1,0) - 1;
	if(ans < 0) ans += MOD;
	cout << ans << endl;
 
 
	return 0;
 
}

Measured memory_bytes: 21748
#include<iostream>
using namespace std;
long long a[100005]={0};
int main()
{
	int i,j,n,num;
	long long m;
	while(scanf("%d%lld",&n,&m)!=EOF)
	{
		for(i=0;i<=100000;i++)
			a[i]=0;
		while(n--)
		{
			scanf("%d%d",&i,&j);
			a[i]+=j; 
		}
		for(i=1;i<=100000;i++)
		{
			m-=a[i];
			if(m<=0)
				break;
		}
		printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 1024
#
import sys
import math
import numpy as np
import itertools

# いくつか入力
n,m,q = (int(i) for i in input().split())
answer = 0
# n行の複数列ある数値を二次元配列へ。x[q][?]
e = [[int(i) for i in input().split()] for i in range(q)] 
a=[1]*10
for i1 in range(1,m+1):
    a[1] = i1
    for i2 in range(i1,m+1):
        a[2] = i2
        for i3 in range(i2,m+1):
            a[3] = i3
            for i4 in range(i3,m+1):
                a[4] = i4
                for i5 in range(i4,m+1):
                    a[5] = i5
                    for i6 in range(i5,m+1):
                        a[6] = i6
                        for i7 in range(i6,m+1):
                            a[7] = i7
                            for i8 in range(i7,m+1):
                                a[8] = i8
                                for i9 in range(i8,m+1):
                                    a[9] = i9
                                    t=0
                                    for i in range(q):
                                        if a[e[i][1]-1] - a[e[i][0]-1] == e[i][2]:
                                            t += e[i][3]
                                        answer = max(t,answer)

print(answer)


Measured memory_bytes: 27112
from collections import deque
import sys
input = sys.stdin.readline


N, M = map(int, input().split())

obvs = list(range(1,N+1,1))
obvs_height = list(map(int, input().split()))
#print(obvs)

obvs = {}
i = 1
for h in obvs_height:
    obvs[i] = h
    i += 1

obvs_remain = obvs.copy()

while True:
    path = list(map(int, input().strip().split()))
    if path==[]:
        break
    if obvs[path[0]] == obvs[path[1]]:
        obvs_remain.pop(path[0], None)
        obvs_remain.pop(path[1], None)
    elif obvs[path[0]] > obvs[path[1]]:
        obvs_remain.pop(path[1], None)
    elif obvs[path[0]] < obvs[path[1]]:
        obvs_remain.pop(path[0], None)

print(len(obvs_remain))

Measured memory_bytes: 28092
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll sum = 0;
    REP(i, 1, N + 1) {
        if (i % 3 != 0 && i % 5 != 0) {
            sum += i;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3652
N = int(input())
s = input()
def f(s):
    d = 0
    for i in range(len(s)):
        if s[i] == "(":
            d += 1
        else:
            d -= 1
        if d < 0:
            return "("+s
    if d > 0:
        return s+")"
    else:
        print(s)
        exit(0)
while True:
    s = f(s)

Measured memory_bytes: 9108
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    string s;
    int i;
    cin>>s;
    for(i=0;i<3;i++){cout<<s[i];}

    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  string F[N];
  string BK[N];
  string BN[N];
  string SK[N];
  string SN[N];
  for(int i=0;i<N;i++){
    cin >> F[i];
    BK[i] = F[i].at(0);
    SK[i] = F[i].at(0);
    BN[i] = F[i].at(1);
    SN[i] = F[i].at(1);
  }
  for(int i=0;i<N;i++){
    for(int j=N-1;j>0;j--){
      if(BN[j]<BN[j-1]){
        swap(BN[j],BN[j-1]);
        swap(BK[j],BK[j-1]);
      }
    }
  }
  for(int i=0;i<N;i++){
    if(i<N-1){
    cout << BK[i] << BN[i] << " ";
    }
    else if(i==N-1){
      cout << BK[i] << BN[i] << endl << "Stable" << endl;
    }
  }
  for(int i=0;i<N-1;i++){
    int min=i;
    for(int j=i;j<N;j++){
      if(SN[j]<SN[min]){
        min =j;
      }
    }    
    swap(SN[i],SN[min]);
    swap(SK[i],SK[min]);
  }
  for(int i=0;i<N;i++){
    if(i<N-1){
      cout << SK[i] << SN[i] << " ";
    }
    else if(i==N-1){
      cout << SK[i] << SN[i] << endl;
    }
  }
  for(int i=0;i<N;i++){
    if(BK[i]!=SK[i]){
      cout << "Not stable" << endl;
      break;
    }
    if(i==N-1){
      cout << "Stable" << endl;
    }
  }
}  


Measured memory_bytes: 3112
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n;
	scanf("%d", &n);
	vector<int> a(n);
	int cnt = 0;
	rep(i, n) {
		scanf("%d", &a[i]);
		if (a[i] < 0)++cnt;
		a[i] = abs(a[i]);
	}
	if (cnt & 1) {
		sort(all(a));
		a[0] *= -1;
	}
	printf("%lld\n", accumulate(all(a), 0LL));

	Please AC;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
template<typename T>
inline T mod(T n, T mod){ T res = n%mod; if(res < 0) res += mod; return res; }
 
////////////////////////// Solution starts below. //////////////////////////////

int main(){
  fastio;
  int n;
  cin >> n;
  vector<double> v(n);
  double sum = 0;
  for(auto& x : v){
    cin >> x;
    sum += (1/x);
  }
  cout << setprecision(10) << fixed << 1/sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

template <class T>
struct SegmentTree{
  using F = function<T(T,T)>;
  F f;
  T inf;
  int n;
  vector<T> node;

  SegmentTree(vector<T> v,T inf,F f):inf(inf),f(f){
    n = 1; while(n < v.size()) n *= 2;
    node.resize(2*n-1,inf);
    for(int i = 0; i < v.size(); i++) node[i+n-1] = v[i];
    for(int i = n-2; i >= 0; i--) node[i] = f(node[2*i+1],node[2*i+2]);
  }

  void update(int k,T val){
    k += n-1;
    node[k] = val;
    while(k > 0){
      k = (k-1) / 2;
      node[k] = f(node[2*k+1],node[2*k+2]);
    }
  }

  void add(int k,T val){
    k += n-1;
    node[k] += val;
    while(k > 0){
      k = (k-1) / 2;
      node[k] = f(node[2*k+1],node[2*k+2]);
    }
  }

  T getval(int a,int b){ return getval(a,b,0,0,n); }
  T getval(int a,int b,int k,int l,int r){
    //区間[a, b)の値を返す
    if(r <= a || b <= l) return inf;
    if(a <= l && r <= b) return node[k];
    T vl = getval(a, b, 2*k+1, l, (l+r)/2);
    T vr = getval(a, b, 2*k+2, (l+r)/2, r);
    return f(vl, vr);
  }
};

signed main(){

  int n, x; cin >> n >> x;
  vector<int> a(n*2);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  for(int i = 0; i < n; i++){
    a[n+i] = a[i];
  }


  SegmentTree<int> seg(a,1LL << 60,[&](int x,int y){
    return min(x, y);
  });
  int ans = 1LL << 60;
  for(int i = 0; i <= n; i++){
    int res = 0;
    for(int j = 0; j < n; j++){
      res += seg.getval(n + j - i, n + j+1);
    }
    ans = min(ans, res + i * x);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int mod=998244353,N=305;
int nm,m,n,f[N][N][N],ans,sum[N],a[N],sum1[N][N][N],sum2[N][N][N];
char s[N];

signed main(){
	scanf("%s",s+1);read(m);
	n=strlen(s+1);s[++n]='0';
	for(int i=1;i<=n;i++){
		if(s[i]=='0') nm++;
		else a[nm+1]++;
	}
	for(int i=1;i<=nm;i++) sum[i]=sum[i-1]+a[i];
	m=min(m,sum[nm]);
	f[0][0][0]=1;
	for(int i=0;i<=nm;i++) 	for(int j=sum[i];j<=sum[nm];j++){
		int lim=min(j,sum[nm]-sum[i-1]);
		if(i) for(int k=0;k<=m;k++){
			int tp1=min({a[i],lim,j}),tp2=min({lim,a[i]+k,j});
			f[i][j][k]=(sum1[i-1][j][k]-(j>=tp1+1?sum1[i-1][j-tp1-1][k]:0)+mod)%mod;
			if(tp2>=a[i]+1) f[i][j][k]=((f[i][j][k]+(j>=a[i]+1&&k?sum2[i-1][j-a[i]-1][k-1]:0))%mod-(j>=tp2+1&&k>=tp2+1-a[i]?sum2[i-1][j-tp2-1][k-tp2-1+a[i]]:0)+mod)%mod;
//			for(int x=0;x<=tp1;x++) f[i][j][k]=(f[i][j][k]+f[i-1][j-x][k])%mod;
//			for(int x=a[i]+1;x<=tp2;x++) f[i][j][k]=(f[i][j][k]+f[i-1][j-x][k-x+a[i]])%mod;
		} 
		for(int k=0;k<=m;k++){
			sum1[i][j][k]=j?(sum1[i][j-1][k]+f[i][j][k])%mod:f[i][j][k];
			sum2[i][j][k]=j&&k?(sum2[i][j-1][k-1]+f[i][j][k])%mod:f[i][j][k];	
		}
//		for(int k=0;k<=m;k++) for(int bi=0;bi<=lim;bi++) if(max(0,bi-a[i])<=k)
//			f[i][j][k]=(f[i][j][k]+f[i-1][j-bi][k-max(0,bi-a[i])])%mod;
		//f[i][j][k]=f[i-1][j-x][k] x\in[0,min(a[i],lim)]
		//f[i][j][k]=f[i-1][j-x][k-x+a[i]] otherwise
	}
	for(int i=0;i<=m;i++) ans=(ans+f[nm][sum[nm]][i])%mod;
	write(ans);
}

Measured memory_bytes: 84584
// JAI SHREE RAM
#pragma GCC optimize("O3")
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define loop for(int i=0;i<n;i++)
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max3(a,max(b,c),d)
#define max5(a,b,c,d,e) max4(a,max(b,c),d,e)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min3(a,min(b,c),d)
#define min5(a,b,c,d,e) min4(a,min(b,c),d,e)
#define sec second
#define fir first
// #define all(a) (a).begin(),(a).end()
#define vec vector<int>
#define M_PI           3.14159265358979323846  /* pi */
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{


	string a, b;
	cin >> a >> b;
	int n=a.length(),m=b.length();
	int dp[n+1][m+1]={0};
	memset(dp,0,sizeof(dp));
	for(int i=1;i<n+1;i++)
	{
		for(int j=1;j<m+1;j++)
		{
			if(a[i-1]==b[j-1])
				dp[i][j]=1+dp[i-1][j-1];
			else
			{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	// FOR(i,n+1)
	// {
	// 	FOR(j,m+1)
	// 	cout<<dp[i][j]<<" ";
	// 	cout<<endl;
	// }
	string ans="";
	int i=n,j=m;
	while(i>=1 && j>=1)
	{
		if(dp[i-1][j]==dp[i][j])
			i--;
		else if(dp[i][j]==dp[i][j-1])
			j--;
		else
		{
			ans+=a[i-1];
			i--,j--;

		}
		
	}
	reverse(ans.begin(),ans.end());
cout<<ans;




}


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

int calc(int x) {
  int result = 0;
  while(x){
    result += x % 10;
    x /= 10;
  }
  return result;
}

int main() {
	int N = 0, A = 0, B = 0, total = 0, result = 0;
	cin >> N >> A >> B;

	for(int i = 1; i <= N; i++) {
      total = calc(i);
      if (A <= total && total <= B) {
        result += i;
      }
	}
  
  	cout << result << endl;

	return 0;
}


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

int main()
{
    long long N, A, B, C;
    cin>>N>>A>>B>>C;

    long long M = 1000000007;

    auto powmod = [&](long long a, long long b)
    {
        long long r = 1;
        for (; b>0; b>>=1, a=a*a%M)
            if (b&1)
                r = r*a%M;
        return r;
    };

    auto inv = [&](long long a)
    {
        return powmod(a, M-2);
    };

    vector<long long> F(2*N);
    F[0] = 1;
    for (long long i=1; i<2*N; i++)
        F[i] = i*F[i-1]%M;

    long long ans = 0;
    for (long long i=N; i<=2*N-1; i++)
    {
        long long a = i*100;
        a *= inv(100-C);
        a %= M;
        a *= (powmod(A, N)*powmod(B, i-N) + powmod(A, i-N)*powmod(B, N)) % M;
        a %= M;
        a *= inv(powmod(A+B, i));
        a %= M;
        a *= F[i-1];
        a %= M;
        a *= inv(F[N-1])*inv(F[i-N])%M;
        a %= M;
        ans += a;
        ans %= M;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while(getline(ss,x,c)) v.emplace_back(x); return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  ll x;
  cin>>x;
  ll re=x/11*2;
  x%=11;
  if(x){
    cout<<re+1+(x>6)<<endl;
  }else{
    cout<<re<<endl;
  }
  return 0;
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll r,g,b,n;
    cin >> r >> g >> b >> n;
    ll cnt = 0;
    rep(i,3001){
      rep(j,3001){
        ll x = n - (i * r + j * g);
        if(x >= 0 && x % b == 0){
          cnt++;
        }
      }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
   	int N, A, B;
    cin >> N >> A >> B;
  	int ans = 0;
    for(int i = 1; i <= N; ++i){
      int num = i;
      int sum = 0;
      while(num > 0){
        sum += num % 10;
        num /= 10;
      }
      if(sum >= A && sum <= B) ans += i;
    }
   
    cout << ans << endl;
}

Measured memory_bytes: 256
import bisect

n = int(input())
l = list(map(int, input().split()))

ans = 0
l = sorted(l)
for i in range(n):
    for j in range(i):
        tmp = 0
        nokori = l[i] - l[j]
        tmp = max(0, j - bisect.bisect_right(l, nokori))
        ans += tmp
print(ans)

Measured memory_bytes: 43100
import java.io.*;
import java.util.*;

public class Main {
    int n;
    Scanner sc;

    Main() {
        sc = new Scanner(System.in);
    }

    boolean init() {
        n = sc.nextInt();
        if (n == 0) return false;
        return true;
    }

    void run() {
        while (init()) {
            int[][] square = new int[n][n];
            int x = n/2, y = n/2+1;
            int cur = 1;
            square[y][x] = cur++;
            x++;
            y++;
            while (cur <= n*n) {
                if (n <= x) {
                    x = 0;
                    continue;
                } 
                if (x < 0) {
                    x = n-1;
                    continue;
                }
                if (n <= y) {
                    y = 0;
                    continue;
                }
                if (square[y][x] != 0) {
                    y++;
                    x--;
                    continue;
                }
                square[y][x] = cur++;
                x++;
                y++;
            }

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    System.out.printf("%4d", square[i][j]);
                }
                System.out.println("");
            }
        }
    }

    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 12000