akhauriyash/Code-Regression huggingface dataset:
from sys import stdin
n,m,k = map(int,stdin.readline().split())
a = list(map(int,stdin.readline().split()))
b = list(map(int,stdin.readline().split()))
su = sum(b)
su1 = 0
ans = m
fin = 0
for i in range(n+1):
    if i:
        su1 += a[i-1]
    while su+su1 > k and ans != 0:
        su -= b[ans-1]
        ans -= 1
    if su+su1 <= k:
        fin = max(fin,ans+i)
print(fin)

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

using namespace std;

#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);
const long double PI = acos(-1);
typedef long long ll;
typedef pair<ll, ll> pii;
typedef complex<double> pnt;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

/* START */
#define int long long
int32_t main() { _
	string s;
	cin >> s;
	for (int i = 0; i < 8; ++i) {
		int ans = s[0] - '0';
		for (int j = 0; j < 3; ++j) {
			if ((i >> j) & 1)
				ans += -(s[j + 1] - '0');
			else
				ans += (s[j + 1] - '0');
		}
		if (ans == 7) {
			cout << s[0];
			for (int j = 0; j < 3; ++j)
				cout << (((i >> j) & 1)? '-': '+') << s[j + 1];
			cout << "=7" << endl;
			return 0;
		}
	}
			
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr ll MAX = LLONG_MAX / 2 - 1;

void floyd(vvll &a) {
  int v = (int)a.size();
  rep(k, v) {
    rep(i, v) {
      if (a[i][k] == MAX) continue;
      rep(j, v) {
        if (a[k][j] == MAX) continue;
        a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
      }
    }
  }
}

int main() {
  int v, e;
  cin >> v >> e;
  
  vvll a(v, vll(v, MAX));
  rep(i, v) rep(j, v) if (i == j) a[i][j] = 0;

  int s, t, d;
  rep(i, e) {
    cin >> s >> t >> d;
    a[s][t] = d;
  }

  floyd(a);

  rep(i, v) {
    if (a[i][i]  < 0) {
      printf("NEGATIVE CYCLE\n");
      return 0;
    }
  }

  rep(i, v) {
    rep(j, v) {
      if (j) cout << " ";
      if (a[i][j] == MAX) printf("INF");
      else printf("%lld", a[i][j]);
    }
    cout << endl;
  }
}



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

int finder(vector<int> vec, int number){
  vector<int>::iterator itr;
  itr = find(vec.begin(), vec.end(), number);
  size_t index = distance(vec.begin(), itr);
  if (index != vec.size()) {return 1;}
  else {return 0;}
}

int main(){
  int s;
  vector<int> v;
  cin >> s;
  v.push_back(s);
    
  int a,b;
  b=0;
  while(b==0){
    if(v[v.size()-1]%2==0){a = v[v.size()-1]/2;}
    else{a = 3*v[v.size()-1]+1;}
    
    if(finder(v,a)==1){
      cout << v.size()+1;
      b=1;
    }
    else{v.push_back(a);}
  }
  
  return 0;
}

Measured memory_bytes: 256
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    n = int(input())
    as_ = list(map(int, input().split()))
    counter_a_tmp = collections.Counter(as_)
    counter_a = collections.defaultdict(int)
    for key, count in counter_a_tmp.items():
        counter_a[key] = count

    ans = 0
    if max(as_) == 0:
        print(n)
    else:
        for i in range(0, max(as_) - 1):
            ans = max(ans, counter_a[i] + counter_a[i + 1] + counter_a[i + 2])

        print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 24024
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(ch>'9'||ch<'0'){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int n,a[100010];
int gcd(int l,int r){return (r?gcd(r,l%r):l);}
int dfs(){
	int cnt=0,rec=0,tmp,i;
	for(i=1;i<=n;i++) ((a[i]&1)?(rec=i):(cnt++));
//	cout<<"dfs "<<cnt<<' '<<rec<<'\n';
	if(cnt&1) return 1;
	if(cnt<n-1||a[rec]==1) return 0;
	tmp=a[rec]-1;a[rec]--;
	for(i=1;i<rec;i++) tmp=gcd(tmp,a[i]);
	for(i+=2;i<=n;i++) tmp=gcd(tmp,a[i]);
	for(i=1;i<=n;i++) a[i]/=tmp;
	return !dfs();
}
int main(){
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	puts((dfs()?"First":"Second"));
}

Measured memory_bytes: 640
from itertools import combinations

n = int(input())
c = {
    "M": 0,
    "A": 0,
    "R": 0,
    "C": 0,
    "H": 0
}
ck = list(c.keys())
cnt = 0

for i in range(n):
    s = input()
    if s[0] in c.keys():
        c[s[0]] += 1
        cnt += 1

if cnt >= 3:
    ans = 0
    for p in list(combinations("MARCH", 3)):
        ans += c[p[0]] * c[p[1]] * c[p[2]]
    print(ans)
else:
    print(0)


Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
#define long long long
const int MAXN = 1e6 + 7;
const long MOD = 1e9 + 7;
const long INF = 1e15;


main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int i, j, k;

    int N; cin >> N;
    long A[N]; for (i = 0; i < N; ++i) cin >> A[i];

    --A[0];
    for (i = 1; i < N; ++i) {
        if (A[i] == A[i - 1]) continue;
        else if (A[i] < A[i - 1]) {
            cout << "No\n"; return 0;
        } else --A[i];
    }
    cout << "Yes\n";
}

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

int main()
{
	int N;
	cin >> N;
	
	char S[N+2];
	for (int i = 1; i <= N; i++) {
		cin >> S[i];
	}
	
	// 累積和
	int S_W[N+2];
	int S_E[N+2];
	S_W[0] = 0;
	S_E[0] = 0;
	for (int i = 1; i <= N; i++) {

		if (S[i] == 'W') {
			S_W[i] = S_W[i - 1] + 1;
			S_E[i] = S_E[i - 1];
		}
		else { // S[i] == 'E'
			S_W[i] = S_W[i - 1];
			S_E[i] = S_E[i - 1] + 1;
		}
	}
	
	int answer = N;
	int tmp;

	// クエリ
	for (int leader = 2; leader <= N - 1; leader++) {

		tmp = (S_W[leader - 1] - S_W[0]) + (S_E[N] - S_E[leader]);
		answer = min(answer, tmp);

	}

	// leader = 1
	answer = min(answer, S_E[N] - S_E[1]);

	// leader = N
	answer = min(answer, S_W[N - 1] - S_W[0]);


	cout << answer << endl;
		
	return 0;
}

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

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);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
    	int N;
    	long[][] AB;
    	
        void solve(InputReader in, PrintWriter out) {
        	N = in.nextInt();
        	AB = new long[N][2];
        	
        	for (int i = 0; i < N; ++i) {
        		long[] ab = {in.nextLong(), in.nextLong()};
        		AB[i] = ab;
        	}
        	Arrays.sort(AB, (x, y) -> Long.signum(x[1] - y[1]));
        	
        	long t = 0;
        	for (long[] ab : AB) {
        		t += ab[0];
        		if (t > ab[1]) {
        			out.println("No");
        			return;
        		}
        	}
        	
        	out.println("Yes");
        }
    }
    
    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

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

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

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

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


Measured memory_bytes: 70500
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    int X,Y;
    cin >> X >> Y;
    if( X % Y == 0){
        cout << -1 << endl;
    }else{
        cout << X << endl;
    }


    return 0;
}


Measured memory_bytes: 888
S=input()

from collections import defaultdict
d=defaultdict(int)

n=len(S)
b=0
for i in range(n):
    a=int(S[n-i-1])
    b+=a*pow(10,i,2019)
    b%=2019
    d[b]+=1

ans=0

for k,v in d.items():
    if k==0:
        ans+=v
    ans+=v*(v-1)//2

print(ans)

Measured memory_bytes: 9536
N = int(input())
X = list(map(int, input().split()))
X_max = max(X)
ans = float('inf')
for i in range(X_max + 1):
    tmp_ans = 0
    for x in X:
        tmp_ans += (x - i) ** 2
    if tmp_ans < ans:
        ans = tmp_ans
print(ans)


Measured memory_bytes: 38896
import java.util.Scanner;

public class Main{
       public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int h = sc.nextInt();
            int w = sc.nextInt();
            if (h == 0 & w == 0)
                break;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if(i == 0 || i == h-1)
                        System.out.print("#");
                    else if(j == 0 || j == w-1)
                        System.out.print("#");
                    else
                        System.out.print(".");
                    }
                System.out.println();
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 33188
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

using Weight = int;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int s = 0, int d = 0, Weight w = 0)
    : src(s), dst(d), weight(w) {
  }
};

using Edges  = vector<Edge>;
using Graph  = vector<Edges>;
using Array  = vector<Weight>;
using Matrix = vector<Array>;

void addArc(Graph &g, const int &a, const int &b, const Weight &w = 1) {
  g[a].emplace_back(a, b, w);
}

void addEdge(Graph &g, const int &a, const int &b, const Weight &w = 1) {
  addArc(g, a, b, w);
  addArc(g, b, a, w);
}

void solve() {
  int v, e;
  cin >> v >> e;
  Graph g(v);
  while (e--) {
    int s, t, d;
    cin >> s >> t >> d;
    addArc(g, s, t, d);
  }
  vvi dp(1 << v, vi(v, INF));
  dp[0][0] = 0;
  rep(s, 1 << v) {
    for (auto &es : g) {
      for (auto &e : es) {
        if (~s >> e.dst & 1) cmin(dp[s | 1 << e.dst][e.dst], dp[s][e.src] + e.weight);
      }
    }
  }
  int x = dp.back()[0];
  cout << (x == INF ? -1 : x) << endl;
}

Measured memory_bytes: 7584
use std::io::Read;
use std::collections::BinaryHeap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let k: usize = iterator.next().unwrap().parse().unwrap();
    let t: usize = iterator.next().unwrap().parse().unwrap();
    let mut pq: BinaryHeap<(usize, usize)> = BinaryHeap::new();
    for i in 1..(t + 1) {
        let a: usize = iterator.next().unwrap().parse().unwrap();
        pq.push((a, i));
    }

    let mut ans: usize = 0;
    let mut prev: usize = 0;
    for _ in 0..k {
        let mut first = pq.pop().unwrap();
        if first.1 != prev {
            prev = first.1;
            first.0 -= 1;
            if first.0 > 0 {
                pq.push(first);
            }
        } else {
            if let Some(mut second) = pq.pop() {
                prev = second.1;
                second.0 -= 1;
                if second.0 > 0 {
                    pq.push(second);
                }
                pq.push(first);
            } else {
                prev = first.1;
                first.0 -= 1;
                if first.0 > 0 {
                    pq.push(first);
                }
                ans += 1;
            }
        }
    }
    return format!("{}", ans);
}


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

#define int long long int
#define ff first
#define ss second
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int cmod = 998244353;
const int N = 2e5 + 5;
const int inf = 1e16 + 2;

void solve(int ze) {
    char a;
    cin >> a;
    if(a >= 'A' and a <= 'Z') cout << "A" << '\n';
    else cout << "a" << '\n';
}
/*
 */

int32_t main()
{
    fastio
    int testcase = 1;
    //cin >> testcase;
    int x = 1;
    while(testcase --) {
        solve(x ++);
    }
    return 0;
}
 



Measured memory_bytes: 3548
N = int(input())
H = list(map(int,input().split()))
flag = 0
tmp_max = H[0]
for i in range(len(H)-1):
    if H[i]>tmp_max:
        tmp_max = H[i]
    if tmp_max-2>=H[i+1]:
        flag = 1
if flag == 0:
    print("Yes")
else:
    print("No")

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  string s;
  cin >> s;
  int r = 0, b = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R')
      r++;
    else
      b++;
  }
  if (r > b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <stdint.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
using namespace std;
 
#define int long long
 
 
int gcd(int a, int b){
	
	if(a==0){
		return b;
	}
	
	return gcd(b%a,a);
	
}
 
 int lcm(int a, int b)  
 {  
    return (a*b)/gcd(a, b);  
 }  
 
 
int f(int x){
	
	
	int res = 0;
	
	while( x%2 == 0){
		
		x/=2;
		res++;
	}
	
	return res;
	
}
 
 
int32_t main() {
 
 	int a,b;
 	
 	cin >> a >> b;
 	
  
 
 	cout << lcm(a,b) << endl;
 	
 	
 
 
  
}
 
 
 

Measured memory_bytes: 3576
N = gets.to_i
M = []
N.times do |i|
  s,p = gets.chomp.split
  key = sprintf("%-10s%03d", s, 100 - p.to_i)
  M << [key, i+1]
end
M.sort_by!{|v|v[0]}

M.each do |v|
  puts v[1]
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
//解ける気がしない

string f( ll n ){
  if( n == 0 ) return "";
  --n;
  return f(n/26) + string(1,'a' + n%26);
}

int main(){
  ll n;cin >> n;
  cout << f(n) << endl;
  
  return 0;
}


Measured memory_bytes: 3660
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=2e5+5;const double Pi=acos(-1.0);
int x[N],y[N],id[N],f[N],num[N];
int n,tot,cnt;
inline bool cmp(const int &a,const int &b){return y[a]<y[b];}
int main(){
	int x1,y1,x2,y2;
	scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&n);
	fp(i,1,n)scanf("%d%d",&x[i],&y[i]);
	if(x1>x2)swap(x1,x2),swap(y1,y2);
	if(y1>y2){
		swap(y1,y2);
		fp(i,1,n)y[i]=y1+y2-y[i];
	}
	fp(i,1,n)id[i]=i;
	sort(id+1,id+1+n,cmp);
	fp(i,1,n){
		R int u=id[i];
		if(y[u]>=y1&&y[u]<=y2&&x[u]>=x1&&x[u]<=x2)
			num[++tot]=x[u];
	}
	cnt=0,f[cnt]=-1;
	fp(i,1,tot){
		if(num[i]>f[cnt])f[++cnt]=num[i];
		else{
			R int k=lower_bound(f+1,f+1+cnt,num[i])-f;
			f[k]=num[i];
		}
	}
	R double res;
	if(cnt<min(x2-x1,y2-y1)+1)
		res=100.0*(x2-x1+y2-y1)-(20-Pi*5)*cnt;
	else res=100.0*(x2-x1+y2-y1)-(20-Pi*5)*(cnt-1)+(10*Pi-20);
	printf("%.12lf\n",res);
	return 0;
}

Measured memory_bytes: 4096
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))

flag = True
for i in range(N):
  if(A[i] % 2 == 0):
    if not(A[i] % 3 == 0 or A[i] % 5 == 0):
      flag = False
      print('DENIED')
      break

if(flag == True):
  print('APPROVED')


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

const int N = 1e5 + 5;
const int inf = 1e4 + 5;

int dp[N];

int main () {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  int n;
  cin >> n;
  vector<int> a(n);
  dp[0] = inf;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    dp[i] = inf;
  }
  dp[1] = 0;
  for (int i = 2; i <= n; i++) {
    dp[i] = dp[i-2] + abs(a[i] - a[i-2]);
    dp[i] = min(dp[i-1] + abs(a[i-1] - a[i]), dp[i]);
  }
  cout << dp[n] << '\n';
  return 0;
}

Measured memory_bytes: 1024
$_=<>;($a,$b)=glob<>;s#F+#push@{$`=~y/T//&1},length$&#ge;$a-=/^1/&&shift@0;*s=$_?b:a,map$s+=$s>0?-$_:$_,sort{$b-$a}@$_ for 0,1;print$a|$b?No:Yes

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);cout<<"\n";};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){   return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); }
template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value!=0>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value==0>::type fill_v(U &u,const V... v){ for(auto &e:u) fill_v<T>(e,v...);}
//FUNCTION  


void solve(void)
{ 
  int N;
  cin>>N;
  string str;
  cin>>str;
  stack<char> st;
  for (int i = 0; i < str.size(); i++)
  {
    char c = str[i];
    if(st.size() == 0)
    {
      st.push(c);
      continue;
    }

    if(c == ')')
    {
      if(st.top() == '(')
      {
        st.pop();
      }
      else
      {
        st.push(')');
      }
      
    }
    else
    {
      st.push('(');
    }
    

  }
  int L = 0;
  int R = 0;
  string sL,sR;
  while(!st.empty())
  {
    if(st.top() =='(')sR += ')';
    else sL += '(';
    st.pop();
  }
  
  cout<<sL + str + sR<<endl;
  
  
  return;
}
  
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 256
n, x0, y0 = list(map(int, input().split()))

cards = [y0] + list(map(int, input().split()))
# yの手持ちはゲームに関与するため、リストに加えてしまう

xs = [[-1] * (n+1) for i in range(n+1)]
ys = [[-1] * (n+1) for i in range(n+1)] 
#xs[i][j] = xの手番で、xがcards[i]を持ちyがcards[j]を持っているとき(i<j)の最善スコア
#ys[i][j] = yの手番で、xがcards[j]を持ちyがcards[i]を持っているとき(i<j)の最善スコア

for i in range(n+1):
	xs[i][-1] = abs(cards[-1] - cards[i])
	ys[i][-1] = abs(cards[-1] - cards[i])

for j in range(n-1, -1, -1):

	# x[i][j] = max (y[j][j+1] , y[j][j+2] , ……, y[j][n] )
	xs_temp = max(ys[j][j+1:n+1])
	ys_temp = min(xs[j][j+1:n+1])
	for i in range(0, j):
		xs[i][j] = xs_temp
		ys[i][j] = ys_temp

# print(xs)
# print(ys)
print(max(ys[0][1:]))	


Measured memory_bytes: 68084
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	String a = sc.next();
    //char[] a = sc.nextLine().toCharArray();
    if(a.equals("Sunny")){
      System.out.println("Cloudy");
    }
    else if(a.equals("Cloudy")){
      System.out.println("Rainy");
    }
    else{
      System.out.println("Sunny");
    }
  }
}

Measured memory_bytes: 21716
#include "bits/stdc++.h"
using namespace std;
 
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
 
typedef long long Int;
typedef vector<int> VI;
typedef pair<int, int> PII;
 
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const Int LINF = INF * (Int) INF;
const int MAX = 100007; 

const int MOD = 998244353;

map<pair<PII, PII> , Int> M;
Int A[20];

Int F(int l, int r, int Cl, int Cr)
{
    if (M.count(MP(MP(l, r), MP(Cl, Cr))))
        return M[MP(MP(l, r), MP(Cl, Cr))];
    if (l + 1 == r)
    {
        return M[MP(MP(l, r), MP(Cl, Cr))] = 0;
    }
    Int res = LINF;
    FOR(m, l + 1 , r)
    {
        res = min(res , F(l, m, Cl, Cl + Cr) + F(m, r, Cl + Cr, Cr) + A[m] * (Cl + Cr));
    }
    return M[MP(MP(l, r), MP(Cl, Cr))] = res;
}

int main(int argc, char* argv[])
{
	// freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);
    
    int n;
    cin >> n;
    FOR(i,0,n)
        cin >> A[i];
    
    cout << F(0, n - 1, 1, 1) + A[0] + A[n - 1] << endl;
    

    cerr << 1.0 * clock() / CLOCKS_PER_SEC << endl;
}

Measured memory_bytes: 34944
class Node
  attr_accessor :key, :left, :right
  def initialize key
    @key = key
  end
  
  def inorder
    left.inorder if left
    print " ", key
    right.inorder if right
  end
  
  def preorder
    print " ", key
    left.preorder if left
    right.preorder if right
  end
end
  
def insert
  z = Node.new $key.to_i
  x = $root
  while x
    y = x
    x = z.key < x.key ? x.left : x.right
  end
  
  unless y
    $root = z
  else
    z.key < y.key ? y.left = z : y.right = z
  end
end

def find(x)
  y = $root
  while y
    if y.key == x
      puts "yes"
      return
    end
    z = y
    y = x < y.key ? y.left : y.right
  end
  puts "no"
end

n = gets.to_i
n.times do
  command, $key = gets.split
  if command == "insert"
    insert
  elsif command == "find"
    find($key.to_i)
  else
    $root.inorder
    puts
    $root.preorder
    puts
  end
end

Measured memory_bytes: 47776
n = gets.to_i
p = gets.split.map(&:to_i)

min = 200001
count = 1
min = p[0]
(n-1).times do |i|
  if min > p[i+1]
    min = p[i+1]
  end
  if min >= p[i+1]
    count += 1
  end
end

print count

Measured memory_bytes: 15236
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i = a; i < n; i++)
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; }


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

int main(){
    int sum = 0, tmp = 0;
    int n, a, b; cin >> n >> a >> b;
    for(int i = 0; i <= n; i++){
        tmp = divSum(i);
        if(a <= tmp && tmp <= b){
            sum += i;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;
import javax.xml.ws.WebEndpoint;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main //implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        long mod=1000000007;
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        
        int n=sc.nextInt();
        int d[]=sc.nextIntArray(n);
        sort(d);
        long a=0;
//        db(d);
        for (int i = 0; i < d.length; i++) {
			for (int j = i+1,w; j < d.length-1; j++) {
				w=d[i]+d[j];
				int dw=j+1,up=d.length,md=0,e=-1;
//				db(dw,up,md,a);
				for (int k = 0; k < 40; k++) {
					md=(dw+up)/2;
					if(w>d[md]) {e=max(e,md);dw=md;}
					else up=md;
				}
				if(0<=e) {
					a+=e-j;
				}
			}
		}

        out.println(a);
     	out.flush();
    }
    
    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}


class P {
	int x, y, d;
	P(int  x, int y, int d) {
	  this.x=x;
	  this.y=y;
	  this.d=d;
	}
}

//class P implements Comparable<P>{
//    int a,b;
//    P(int a, int b) {
//    	this.b=b;
//    	this.a=a;
//    }
//
//    public int compareTo(P p){
//        return p.a-a;//des
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() throws IOException{
        return this.nextString().toCharArray();
    }    
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 21972
#include<iostream>
using namespace std;
int main(){
  	int n,k,h,i,x=0;
  	cin >> n >> k;
  	for(i=0;i<n;i++){
    	cin >> h;
      	if(h>=k){
        	x++;
        }
    }
  	cout << x << endl;
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
num = [0] * (N + 1)
ans = 1
for i in range(N + 1):
    num[i] += i
#print(num)
for k in range(K, N + 1):
    sum_min = k * (k - 1) // 2
    sum_max = k * N - k * (k - 1) // 2
    #print(sum_min, sum_max, k, num[N:N-k:-1])
    ans += sum_max - sum_min + 1
    #print(ans)
    ans %= 10**9 + 7
print(ans)

Measured memory_bytes: 65884
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let n: usize = sc.get();
    let mut ans = Vec::new();
    let mut rem = n;
    for i in (2..).take_while(|i| i * i <= n) {
        while rem % i == 0 {
            rem /= i;
            ans.push(i);
        }
    }
    if rem != 1 {
        ans.push(rem);
    }
    print!("{}:", n);
    for i in &ans {
        print!(" {}", i);
    }
    println!("");
}



Measured memory_bytes: 5032
n,m = map(int,input().split())
#a_L = [0] * float(10**10)
#a_L[0] = 1
#a_L[1] = 1
MOD = 10 ** 9 + 7
dp = [0] * (n+1)
a_L = []

for val in range(m):
    a_L.append(int(input()))


a_L = set(a_L)
dp[0] = 1
if 1 in a_L:
    dp[1] = 0
else:
    dp[1] = 1

for i in range(2,n+1):
    if i not in a_L:
        dp[i] = dp[i-1] + dp[i-2]
    else:
        dp[i] = 0

print(dp[n]%MOD)
#print(dp)

Measured memory_bytes: 470264
n,k = (int(i) for i in input().split())
d = list(int(i) for i in input().split())

def ketajudge(x):
  while x != 0:
    if x%10 in d:
      return False
      break
    else:
      if x//10 == 0:
       return True
       break
    x = x//10 
  
  

for i in range(10*n):
  judge = n+i
  if ketajudge(judge) == True:
    print(judge)
    break
    
  
  

Measured memory_bytes: 2940
#include <cstdio>

int N,K;

bool has[102];

int main(){
    scanf("%d%d",&N,&K);

    for(int i=0;i<K;i++){
        int k;
        scanf("%d",&k);
        for(int i=0;i<k;i++){
            int d;
            scanf("%d",&d);
            has[d]=true;
        }
    }

    int ans=0;
    for(int i=1;i<=N;i++) if (!has[i]) ans++;

    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 1732
import bisect

A, B, Q = map(int, input().split())

INF=10**18
S=[-INF]+[int(input()) for i in range(A)]+[INF]
T=[-INF]+[int(input()) for i in range(B)]+[INF]

for i in range(Q):
    x = int(input())
    s = bisect.bisect_left(S, x)
    t = bisect.bisect_left(T, x)
    saisyo = float("inf")
    for j in [S[s], S[s-1]]:
        for k in [T[t], T[t-1]]:
            saisyo = min(saisyo, abs(j-x)+abs(k-j), abs(k-x)+abs(j-k))
    print(saisyo)

Measured memory_bytes: 14176
#include<bits/stdc++.h>
using namespace std;
const int N=500005;
typedef long long ll;

ll a[6],b[6];

void solve()
{
    for(int i=1;i<=4;i++) scanf("%lld",&a[i]);
    b[1]=a[1]*a[3]; b[2]=a[1]*a[4]; b[3]=a[2]*a[3]; b[4]=a[2]*a[4];
    sort(b+1,b+5); printf("%lld\n",b[4]);
}

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

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

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

	set<string> substring;
	
	for(int i = 1; i <= min(5, (int) s.size()); i++){
		for(int j = 0; j < s.size() - i + 1; j++){
			substring.insert(s.substr(j, i));
		}
	}
	
	// for(auto x: substring) cout << x << endl;
	
	int cnt = 0;
	for(string x: substring){
		cnt++;
		if(cnt == k){
			cout << x << endl;
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 N;
  cin >> N;
  i64 ans = 0;
  for (i64 i = 1; i <= N; ++i) {
    i64 x = N / i;
    ans += x * (x + 1) / 2 * i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 5e5+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;
ll bin_pow(ll base,ll deg)
{
    if (deg==0)
        return 1;
    ll t=bin_pow(base,deg/2);
    if (deg&1)
        return (((t*t)%mod1)*base)%mod1;
    else
        return (t*t)%mod1;
}
int main() {
 //   ios_base::sync_with_stdio(0);
  //  cin.tie(0);
#ifdef LOCAL
    freopen("a.in","r",stdin);
#endif
    ll n;
    cin>>n;
    vector <ll> c(n);
    rep(i,n)
    cin>>c[i];
    sort(c.begin(),c.end());
    ll ans=0;
    vector <ll> two(MAXN);
    ll f=1;
    for (int i=0;i<MAXN;i++)
        two[i]=f,f*=2,f%=mod1;
   /* f=1;
    for (int i=0;i<MAXN;i++)
        fact[i]=f,f*=(i+1),f%=mod1; */
    for (ll i=0;i<n;i++)
    {
        //cout<<2*(n-i-2)+1<<" "<<two[1]<<'\n';
        ll t;
        if (i!=n-1)
       t=two[n-i-1]+(n-i-1)*two[n-i-2];
        else
            t=two[n-i-1];
        t%=mod1;
        t*=c[i];
        t%=mod1;
    ans+=(t*two[i])%mod1;
    ans%=mod1;
    }
    cout<<(ans*two[n])%mod1;





}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

void solve()
{
	long double a,b;
	cin>>a>>b;
	long double x=a*b;
	ll s=floor(x);
	cout<<s;
}

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


Measured memory_bytes: 3748
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int m = sc.nextInt();
			int f = sc.nextInt();
			int r = sc.nextInt();
			if(m == -1 && f == -1 && r == -1){
			 break;
			}
			if(m == -1 || f == -1){
			System.out.println("F");
			}
			else if(m + f >= 80){
			System.out.println("A");
			} 
			else if(m + f >= 65){
			System.out.println("B");
			}             
			else if(m + f >= 50){                 
			System.out.println("C");             
			}             
			else if(m + f >= 30){                 
			if(r >= 50){                    
			 System.out.println("C");                 
			}                 
			else{                     
			System.out.println("D");                 
			}             
			}             
			else{                 
			System.out.println("F");             
			}        
			} 
	}

}

Measured memory_bytes: 19112
N, M = map(int, input().split())
def mod_factorial(a, mod):
    ans = 1
    while a != 1:
        ans *= a
        ans = ans % mod
        a -= 1
    return ans

mod = 10**9 + 7
if abs(N - M) > 1:
    print(0)
elif abs(N - M) == 0:
    ans = mod_factorial(N, mod) * mod_factorial(M, mod) * 2
    print(ans % mod)
else:
    ans = mod_factorial(N, mod) * mod_factorial(M, mod)
    print(ans % mod)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
  double a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  cout << ceil(a/10)*10+ceil(b/10)*10+ceil(c/10)*10+ceil(d/10)*10+ceil(e/10)*10+(min({((int)a%10==0 ? 10 : (int)a%10),((int)b%10==0 ? 10 : (int)b%10),((int)c%10==0 ? 10 : (int)c%10),((int)d%10==0 ? 10 : (int)d%10),((int)e%10==0 ? 10 : (int)e%10)})==10 ? 0 : min({((int)a%10==0 ? 10 : (int)a%10),((int)b%10==0 ? 10 : (int)b%10),((int)c%10==0 ? 10 : (int)c%10),((int)d%10==0 ? 10 : (int)d%10),((int)e%10==0 ? 10 : (int)e%10)})-10);
  return 0;
}

Measured memory_bytes: 256
//BISMILLAHIR RAHMANIR RAHIM
                                               //BY THE NAME OF ALLAH
                                               //FAISAL AHAMMED SHAWON
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#include<set>
#include<map>
#include<iterator>
#include<numeric>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define SQ(a) (a)*(a)
#define pi acos(-1.0)
const int MAX=100001;
const int MOD=1e9+7;
int ara[MAX];
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    else
    gcd(b,a%b);
}
ll lcd(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}

bool f(ll a,ll b)
{
    return a>b;
}
ll max_sum_subarrays(ll ara[],ll n)
{
    ll ans=0,sum=0;
    for(ll k=0;k<n;k++){
        sum=max(ara[k],sum+ara[k]);
        ans=max(ans,sum);
    }
    return ans;
}
ll num_divisors(ll n)
{
    long long cnt=0;
    for(int i=1;i*i<=n;i++)
    {
        if(n%i==0 && i*i==n)
            cnt+=1;
        if(n%i==0 && i*i!=n)
                cnt+=2;
    }
    return cnt;
}
ll comb(ll m, ll n)
{
    ll x = max(m-n,n),ans = 1,i=1;
    for(ll k=m;k>=x+1;k--){
        ans*=k;
        ans/=i;
        i++;
    }
    return ans;
}
ll binsearch(ll low,ll high,ll target)
{
    while(low<=high)
    {
        ll mid=(low+high)/2;
        if(ara[mid]>target)
            high=mid-1;
        else if(ara[mid]<target)
            low=mid+1;
        else return mid;
    }
    return -1;
}

int main()
{
    fast();
    int n;
    cin>>n;
    int ara[n];
    for(int i=0;i<n;i++)
    {
        cin>>ara[i];
    }
    int maxm=ara[0];
    int ans=0;
    for(int i=1;i<n;i++)
    {
        if(maxm>ara[i])
        {
            maxm=ara[i];
            ans++;
        }
    }
    cout<<ans+1<<endl;
}

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

int k,ans;
int dif[12];
const int M = 10;

void rec(int d, int p){
  if(p==k){
    ans = d;
    return;
  }
  if(d>=ans)return;

  int rot = dif[p];
  if(rot == 0){
    rec(d,p+1);
    return;
  }

  rec(d+1,p+1);

  for(int i=p;i<k;i++){
    dif[i] = (dif[i]-rot)%M;
    rec(d+1,p+1);
  }
  for(int i=p;i<k;i++)dif[i] = (dif[i]+rot+M)%M;
}

int main(){
  while(cin >> k,k){
    string s,t;
    cin >> s >> t;
    for(int i=0;i<k;i++){
      dif[i] = ( (int)(t[i]-s[i]) + M ) % M;
    }

    ans = k;
    rec(0,0);
    cout << ans << endl;
  }
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n;
    cin>>n;
    int c=0;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        if(a==b)
         c++;
        else
         c=0;
      ans=max(ans,c); 
    }
    if(ans>=3)
      cout<<"Yes"<<endl;
     else 
       cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 3668
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
//　30min
int main(void){
  int n;
  int v[1001];
  double ans;
  int tmp;

  scanf("%d", &n);

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

//    数値を降順にソート
  for (int i = 1; i<= n; i++){
    for (int j = i; j <= n; j++){
      if (v[i] > v[j]) {
        tmp =  v[i];
        v[i] = v[j];
        v[j] = tmp;
      }
    }
  }

  ans = (((double) v[1]) + ((double)v[2])) / 2;
  //  ans = ans + (v[1] + v[2]) % 2;
  for(int i = 2; i < n; i++){
    ans = (ans + ((double) v[i + 1])) / 2;
    //    ans += fmod(ans, v[i + 1]);
  }
  
  printf("%.5f\n", ans);
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=1e6+10;

int main(){
    string s1,s2;
    cin>>s1>>s2;
    int n,m;
    cin>>n>>m;
    string s3;
    cin>>s3;
    if(s1==s3)n--;
    else if(s2==s3)m--;
    cout<<n<<' '<<m<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<numeric>
#include<vector>
#include<limits.h>
#include<float.h>
#define foreach(t,p) for(t::iterator it=p.begin();it!=p.end();++it)
#define rforeach(t,p) for(t::reverse_iterator it=p.begin();it!=p.rend();++it)
#define all(p) p.begin,p.end()
using namespace std;
typedef pair<int,int> pp;

int main()
{
    int times[110]={0};
    int n;
    while(cin>>n){times[n]++;if(cin.eof())break;}
    
    set<pp,greater<pp> > kaisu;
    for(int i = 1;i<101;i++)
    {
        kaisu.insert(pp(times[i],i));
    //    cout << i << " "<< times[i] << endl;
    }

    n=(*kaisu.begin()).first;
    set<pp>::iterator pit;
    set<int> outs;
    for(pit=kaisu.begin();(*pit).first==n;++pit)
    {
        outs.insert((*pit).second);
        //cout << (*pit).second << endl;
    }
        //    cout << (*it).second << endl;
        //
    //cout << *(outs.begin()) << endl;
    foreach(set<int>,outs)cout << *it << endl;
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
int main() {
    long long x, t;
    cin >> x >> t;
    cout << max(x - t, x - x);
}

Measured memory_bytes: 3588
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

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

    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    string ans = (s < t)? "Yes" : "No";

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384