akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

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

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

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

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

    cin>>n>>a>>b;
    Cout(min(a*n,b));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,i; cin>>n;
    string s,t; cin>>s>>t;
    //int cnt =0;
    for(i=0;i<n;i++){
        if(s.substr(i,n-i) == t.substr(0, n-i)) break;
    }
    cout<<2*n -(n-i)<<endl;
}


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

def cmb(n, r, p):
	if (r < 0) or (n < r):
		return 0
	s = 1
	for i in range(r):
		s = (s * (n-i)) % p
	return (s * factinv[r]) % p

p = 10 ** 9 + 7
N = 2 * 10 ** 5  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
	fact.append((fact[-1] * i) % p)
	inv.append((-inv[p % i] * (p // i)) % p)
	factinv.append((factinv[-1] * inv[-1]) % p)

ans = pow(2, n, p)
ans -= cmb(n, a, p)
ans -= cmb(n, b, p)
ans -= 1
print(ans % p)

Measured memory_bytes: 27092
h, w, k = list(map(int, input().split()))
c = [[] for _ in range(h)]
for i in range(h):
    c[i] = input()

ans = 0
for i in range(1 << h):
    for j in range(1 << w):
        black = 0
        for a in range(h):
            for b in range(w):
                if i >> a & 1 or j >> b & 1:
                    continue
                if c[a][b] == '#': black += 1
        if black == k:
            ans += 1

print(ans)

Measured memory_bytes: 9200
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  while(1){
    C-=B;
    if(C<=0){
      cout<<"Yes"<<endl;
      return 0;
    }
    A-=D;
    if(A<=0){
      cout<<"No"<<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3624
import java.io.*;

public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        int K = Integer.parseInt (reader.readLine());
        String[] arr = reader.readLine().split (" ");
        int A, B;
        A = Integer.parseInt (arr[0]);
        B = Integer.parseInt (arr[1]);
        System.out.println (A <= B / K * K ? "OK" : "NG");
        return;
    }
}

Measured memory_bytes: 32420
n,y = map(int,input().split())

ans = '-1 -1 -1'
for i in range(n+1):
    for j in range(n+1-i):
        k = n - i - j
        tot = (i * 10000 + j * 5000 + k *1000)
        if tot == y:
            ans = '{} {} {}'.format(i,j,k)
            break
print(ans)

Measured memory_bytes: 9040
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

vector<vector<int32_t>> A(101);
vector<int32_t> d(101), f(101);
int32_t t = 1;

void dfs(int32_t u) {
    d[u] = t++;

    for (int32_t v : A[u]) {
        if (d[v] == 0) {
            dfs(v);
        }
    }

    f[u] = t++;

    return;
}

int main() {
    fill(d.begin(), d.end(), 0);

    int32_t n;
    cin >> n;

    for (int32_t i = 0; i < n; i++) {
        int32_t u, k;
        cin >> u >> k;

        for (int32_t j = 0; j < k; j++) {
            int32_t v;
            cin >> v;

            A[u].push_back(v);
        }
    }

    for (int32_t i = 1; i <= n; i++) {
        if (d[i] == 0) {
            dfs(i);
        }
    }

    for (int32_t i = 1; i <= n; i++) {
        cout << i << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3144
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>


using namespace std;


template <class ...Args>
void Input(Args &...args)
{
	(cin >> ... >> args);
}

template <class T>
void InputArray(std::size_t size, T &t)
{
	t.resize(size);
	for (auto &e : t) {
		cin >> e;
	}
}

template <class ...Args>
void InputArray(std::size_t size, Args &...args)
{
	(InputArray(size, args), ...);
}

template <class ...Args>
void InputVerticalArray(std::size_t size, Args &...args)
{
	(args.resize(size), ...);
	for (int i = 0; i < size; i++) {
		((cin >> args[i]), ...);
	}
}

template <class ...Args>
void Output(const Args &...args)
{
	((cout << args << ' '), ...) << endl;
}

template <class ...Args>
void OutputVertical(const Args &...args)
{
	((cout << args << endl), ...);
}

template <class T>
void OutputArray(const T &t)
{
	for (const auto &e : t) {
		cout << e << ' ';
	}
	cout << endl;
}

template <class ...Args>
void OutputArray(const Args &...args)
{
	(OutputArray(args), ...);
}

template <class ...Args>
void OutputVerticalArray(const Args &...args)
{
	for (int i = 0; i < min({ args.size()... }); i++) {
		((cout << args[i] << ' '), ...) << endl;
	}
}


#define inp(type, ...) \
	type __VA_ARGS__; \
	Input(__VA_ARGS__)

#define inpa(type, size, ...) \
	type __VA_ARGS__; \
	InputArray((size), __VA_ARGS__)

#define inpva(type, size, ...) \
	type __VA_ARGS__; \
	InputVerticalArray((size), __VA_ARGS__)

#define otp(...) \
	Output(__VA_ARGS__)

#define otpv(...) \
	OutputVertical(__VA_ARGS__)

#define otpa(...) \
	OutputArray(__VA_ARGS__)

#define otpva(...) \
	OutputVerticalArray(__VA_ARGS__)

#define rep(counter, range) \
	for (int (counter) = 0; (counter) < (range); (counter)++)

#define repi(range) \
	rep(i, range)

#define rrep(counter, range) \
	for (int (counter) = (range) - 1; (counter) >= 0; (counter)--)

#define rrepi(range) \
	rrep(i, range)

#define repc(element, container) \
	for (auto &(element) : (container))

#define repe(container) \
	repc(e, container)

#define all(container) \
	(container).begin(), (container).end()

#ifdef __CCR__
#	define dlog(x) clog << #x " = " << x << endl
#else
#	define dlog(x)
#endif



int main()
{
	inp(int, n, k, q);
	inpa(vector<int>, q, a);
	repe(a) e--;
	
	vector<int> points(n);
	repe(a) {
		points[e]++;
		
	}
	
	repe(points) {
		otp(k - q + e > 0 ? "Yes" : "No");
	}
	
	return 0;
}


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

const double PI=acos(-1.0);

string s;

int main() {
    int d, g;
    cin >> d >> g;
    int p[d], c[d];
    rep(i, d) cin >> p[i] >> c[i];

    ll res = 1 << 29;
    for(int bit = 0; bit < (1 << d); bit++) {
        ll sum = 0;
        ll num = 0; //解いた数
        for(int i = 0; i < d; i++) {
            if(bit & (1 << i)) sum += c[i] + p[i]*100*(i + 1), num += p[i]; 
        }
        if(sum >= g) res = min(res, num);
        else {
            for(int i = d - 1; i >= 0; i--) {
                if(bit & (1 << i)) continue;
                for(int j = 0; j < p[i]; j++) {
                    if(sum >= g) break;
                    sum += 100 * (i + 1);
                    num++;
                }
            }
            res = min(res, num);
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(i,a,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,0,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);   
}
int a[21][21],dp[1<<21];
ll mod=1e9+7;
void solve()
{
  int n;
  cin>>n;
  rep(i,n)rep(j,n)cin>>a[i][j];
  dp[0]=1;
  rep(i,1<<n)
  {
    rep(j,n)
    {
      if(a[__builtin_popcount(i)][j] && !(i&1<<j)){dp[i|1<<j]+=dp[i];dp[i|1<<j]%=mod;}
    }
  }
  cout<<dp[(1<<n)-1];

}
int main()
{
  fastio;
  //fopen();
  int t;
  //cin>>t;
  rep(i,1)
  { 
    solve();
    cout<<endl;
  }
  
}

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

public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Scanner scanner;
	public Solution() {
		scanner = new Scanner(System.in);

		// scanner.nextLine();
		while (scanner.hasNext()) {
			run_case();
		}
	}
	private void run_case() {
		// scanner.nextLine();
		String line = scanner.nextLine();

		int H = Integer.parseInt(line.split("\\s+")[0]);
		int N = Integer.parseInt(line.split("\\s+")[1]);

		int[] arr = strToIntArray(scanner.nextLine());

		int total = 0;
		for (int u : arr) total += u;

		if (total >= H) System.out.println("Yes");
		else System.out.println("No");
	}

	private int[] strToIntArray(String str) {
	    String[] vals = str.split("\\s+");
	    int sz = vals.length;
	    int[] res = new int[sz];
	    for (int i=0; i<sz; i++) {
	        res[i] = Integer.parseInt(vals[i]);
	    }
	    return res;
	}

}


Measured memory_bytes: 46968
import sys
input = sys.stdin.readline
def main():
    N, W = map(int, input().split())
    
    dpt = [0] * (W+1)
    
    for i in range(N):
        w, v = map(int, input().split())
        for j in range(W, w-1, -1):
            a = dpt[j]
            b = dpt[j-w]+v
            if a > b:
                dpt[j] = a
            else:
                dpt[j] = b
    
    print(dpt[W])

if __name__ == '__main__':
    main()

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

using namespace std;

int main(){
  int x=0;
  string S;
  cin >> S;
  size_t size = S.length();
  for(int i=0;i<size;i++){
    if(i%2==1){
      if(S[i]=='R'){
  x = x+1;    }
  }else{
    if(S[i]=='L'){
x = x+1;    }

  }

}
  if(x==0){
    cout << "Yes";
  }else{
    cout<<"No";
  }

 return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <map>
#include <bitset>
#include <unordered_set>
#include <set>

using namespace std;
int n, wei;
int main() {
    const long long INT_MIN = -0x7fffffff - 1;
    scanf("%d %d", &n, &wei);
    vector<long long> w(n);
    vector<long long> v(n);
    for (int i = 0; i < n; i++) {
        scanf("%lld %lld", &w[i], &v[i]);
    }
    vector<vector<long long>> dp(n + 1, vector<long long>(3 * n + 1, INT_MIN));
    dp[0][0] = 0;
    for(int i = 0; i < n; i++) {
        for(int a = n; a >= 0; a--) {
            for(int b = 0; b <= 3 * n; b++) {
                if(dp[a][b] >= 0) {
                    long long b2 = b+ w[i] - w[0];
                    dp[a + 1][b2] = max(dp[a][b] + v[i], dp[a + 1][b2]);
                }
            }
        }
    }
    long long ans = INT_MIN;
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= 3 *n; j++) {
            if(i * w[0] + j <= wei) {
                ans = max(ans, dp[i][j]);
            }
        }
    }
    printf("%lld\n", ans);
    
    
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const double EPS = 1e-10;
const int INF = 2147483647;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int main()
{
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int ans = a + b + c;

	a = max(a, b);
	a = max(a, c);

	ans -= a;

	ans = ans + a * pow(2, k);

	cout << ans << endl;

	return 0;
}


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

int main() {
  long long N, AE[5], minAE, ans;
  cin >> N;
  for (int i = 0; i < 5; i++) cin >> AE[i];

  minAE = N;
  for (int i = 0; i < 5; i++) {
    minAE = min(AE[i], minAE);
  }

  ans = N / minAE + 4;
  if (N % minAE != 0) ans++;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int a, b, x;
    cin >> a >> b >> x;
    if(a <= x && x <= a+b) {
        cout << "YES";
    }
    else {
        cout << "NO";
    }
    
    cout << endl;
    return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;

  vector<string> S(H);
  rep(i, H) cin >> S[i];

  vector<vector<int>> L(H + 2, vector<int>(W + 2, 0));
  vector<vector<int>> R(H + 2, vector<int>(W + 2, 0));
  vector<vector<int>> U(H + 2, vector<int>(W + 2, 0));
  vector<vector<int>> D(H + 2, vector<int>(W + 2, 0));

  rep(h, H) rep(w, W) {
    if (S[h][w] == '.') {
      L[h + 1][w + 1] = L[h + 1][w] + 1;
    }
    int i = W - w - 1;
    if (S[h][i] == '.') {
      R[h + 1][i + 1] = R[h + 1][i + 2] + 1;
    }
  }

  rep(w, W) rep(h, H) {
    if (S[h][w] == '.') {
      U[h + 1][w + 1] = U[h][w + 1] + 1;
    }
    int i = H - h - 1;
    if (S[i][w] == '.') {
      D[i + 1][w + 1] = D[i + 2][w + 1] + 1;
    }
  }

  int ans = 0;
  rep(h, H) rep(w, W) {
    int n = L[h + 1][w + 1] + R[h + 1][w + 1] + U[h + 1][w + 1] +
            D[h + 1][w + 1] - 3;
    if (n > ans) {
      ans = n;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 67200
from sys import stdin

def main():
    n = int(stdin.readline())
    e = [tuple(map(int,stdin.readline().split())) for x in range(n-1)]
    c = [int(x) for x in stdin.readline().split()]    

    c.sort(reverse=True)

    edge = {(i+1):[] for i in range(n)}
    for a,b in e:
        edge[a].append(b)
        edge[b].append(a)

    node = [0]*n
    root = 1

    node[0] = c[0]
    yet = edge[1]
    consume = 1

    while consume < n:
        x = yet[consume-1]
        node[x-1] = c[consume]
        consume += 1
        for y in edge[x]:
            if node[y-1] == 0:
                yet.append(y)

    print(sum(c[1:]))
    print(*node)

if __name__=='__main__':
    main()

Measured memory_bytes: 7204
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		String S = sc.next();
		int z = 0;
		for (int i = 0; i < S.length(); i++) {
			if (S.charAt(i) == '0')
				z++;
		}
		System.out.println(Math.min(z, S.length() - z) * 2);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

lnt powmod(lnt a, lnt p, lnt m){
	lnt res = 1, tmp = a;
	while(p != 0){
		if(p % 2) res = (res*tmp) % m;
		tmp = (tmp*tmp) % m;
		p /= 2;
	}
	return res;
}

int main(){
	summon_tourist;

	lnt N, A, B; cin >> N;
	lnt ans = 0;

	map<plnt, lnt> mpa, mpb;
	vector<plnt> vec;
	map<plnt, bool> check;

	REP(i, N){
		cin >> A >> B;
		if(A == 0 and B == 0) ans++;
		else {
			lnt g = __gcd(A, B);
			A /= g; B /= g;
			if(A == 0 and B != 0){
				mpb[{A, B}]++;
			} else if(A != 0 and B == 0){
				mpa[{A, B}]++;
				vec.eb(A, B);
			} else {
				if((A>0) xor (B>0)){
					mpb[{A, B}]++;
				} else {
					mpa[{A, B}]++;
				}
			}
			vec.eb(A, B);
		}
	}

	lnt plus = 1;
	for(auto p: vec){
		if(check[p]) continue;

		check[p] = 1; check[{-p.first, -p.second}] = 1;
		check[{p.second, -p.first}] = 1; check[{-p.second, p.first}] = 1;
		lnt num = 1;

		if(mpa.count(p)){
			lnt a = mpa[p] + mpa[{-p.first, -p.second}];
			lnt b = mpb[{p.second, -p.first}] + mpb[{-p.second, p.first}];
			num = (powmod(2, a, MOD) + powmod(2, b, MOD) - 1) % MOD;
		} else if(mpb.count(p)){
			lnt a = mpb[p] + mpb[{-p.first, -p.second}];
			lnt b = mpa[{p.second, -p.first}] + mpa[{-p.second, p.first}];
			num = (powmod(2, a, MOD) + powmod(2, b, MOD) - 1) % MOD;
		}
		plus *= num; plus %= MOD;
	}

	ans += plus; ans %= MOD;
	ans = (ans-1+MOD) % MOD;
	
	cout << ans << ln;
}

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

using namespace std;

int main(){
  vector<int> a(5);
  int k;
  for(int i=0;i<5;i++){
    cin >> a[i];
  }
  cin >> k;
  int dif;
  for(int i=0;i<4;i++){
    for(int j=i+1;j<5;j++){
      dif=a[j]-a[i];
      if(dif>k){
        cout << ":(" << endl;
        return 0;
      }
    }
  }
  cout << "Yay!" << endl;
  return 0;
}

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

const int N = 1e5 + 10;
typedef long long LL;

int n;
LL K;
struct Point{
	int a, b;
	void read(){
		scanf("%d %d", &a, &b);
	}
	bool operator < (const Point &A)const{
		return a < A.a;
	}
}p[N];

int main(){
	while(~scanf("%d %lld", &n, &K)){
		for(int i=0; i<n; i++){
			p[i].read();
		}
		sort(p, p+n);
		LL cur = 0;
		for(int i=0; i<n; i++){
			cur = cur + p[i].b;
			if(cur >= K){
				printf("%d\n", p[i].a);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int s = accumulate(a.begin(), a.end(), 0);
  int best = 1 << 30;
  int bestI = -1;
  for (int i = 0; i < n; ++i) {
    int x = a[i];
    int cur = abs(x * n - s);
    if (cur < best) {
      best = cur;
      bestI = i;
    }
  }
  cout << bestI << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(void){
    int i,j,n;
    double alpha,av,s[1001];

    while(1){
        scanf("%d",&n);
        if(n == 0)
            break;

        av  = 0.0;
        for(i = 0;i < n;i++){
            scanf("%lf",&s[i]);
            av += s[i];
        }
        av /= (double)n;

        alpha = 0.0;
        for(i = 0;i < n;i++){
            alpha += (s[i] - av) * (s[i] -  av);
        }
        printf("%lf\n",sqrt(alpha / (double)n));
    }
    return 0;
}

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

const int MAX = 1100000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    int x, y; cin >> x >> y;
    int a = 0, b = 0, f = 0;
    for(int i = 0; i <= y; i++){
        a = i;
        b = y - 2*a;
        if(a + 2*b == x){
            f = 1;
            break;
        }else{
            continue;
        }
    }
    if(f == 0){
        cout << 0 << endl;
        return 0;
    }
    COMinit();
    ll ans = COM(a+b, b);
    cout << ans << endl;
}

Measured memory_bytes: 25984
import numpy as np
s=input()
n=len(s)
MOD=1000000007
wayA=np.array([0,0,0,0])
wayB=np.array([0,0,0,0])
wayC=np.array([0,0,0,0])
MOD2=np.array([MOD,MOD,MOD,MOD])
hatena=0
for c in s:
	if c=="A":
		wayA[0]+=1
	if c=="B":
		wayB+=wayA
	if c=='C':
		wayC+=wayB
	if c=='?':
		wayC[1]=wayC[1]+wayB[0]
		wayC[2]=wayC[2]+wayB[1]
		wayC[3]=wayC[3]+wayB[2]
		wayB[1]=wayB[1]+wayA[0]
		wayB[2]=wayB[2]+wayA[1]
		wayA[1]=wayA[1]+1
		hatena+=1
	wayA%=MOD2
	wayB%=MOD2
	wayC%=MOD2
ans=0
for i in range(0,4):
	ans=ans+pow(3,hatena-i)*wayC[i]
	ans=ans%MOD
print(int(ans))

Measured memory_bytes: 14660
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        String S = st.nextToken();

        Set<String> checkSet = new HashSet<>();
        checkSet.add("A");
        checkSet.add("C");
        checkSet.add("G");
        checkSet.add("T");

        int ans = 0;

        for(int i = 0; i < S.length(); i++) {

            if(!checkSet.contains(S.substring(i, i + 1))) continue;

            int tmp = 1;

            for(int j = i + 1; j < S.length(); j++) {
                String str = S.substring(j, j + 1);
                if(!checkSet.contains(str)) break;
                tmp += 1;
            }

            if(ans < tmp) ans = tmp;
            
        }

        pw.print(ans);
        br.close();
        pw.close();
    }
}

Measured memory_bytes: 32768
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;

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

  if(a<b){
    cout << "a < b" << endl;
  }
  if(a>b){
    cout << "a > b" << endl;
  }
  if(a==b){
    cout << "a == b" << endl;
  }

  return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back

#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
int N=((1e9)+7);
signed main()
{
    speed
    string str;cin>>str;
    int n=str.length();
    vector<vector<int>> f(n,vector<int>(13,0));
    int t=10;
    if(str[n-1]!='?'){f[n-1][str[n-1]-'0']=1;}
    else{for(int i=0;i<10;++i){f[n-1][i]=1;}}
    for(int i=1;i<n;++i)
    {
        int ix=n-1-i;
        if(str[ix]=='?')
        {
            for(int num=0;num<10;++num)
            {
                int rem=(num*t)%13;
                for(int nxt=0;nxt<13;++nxt)
                {
                    f[ix][(nxt+rem)%13]+=f[ix+1][nxt];
                    f[ix][(nxt+rem)%13]%=N;
                }
            }
        }
        else
        {
            int num=(str[ix]-'0');
            int rem=(num*t)%13;
            for(int nxt=0;nxt<13;++nxt)
            {
                f[ix][(nxt+rem)%13]+=f[ix+1][nxt];
                f[ix][(nxt+rem)%13]%=N;
            }
        }
        t*=10;
        t%=13;
    }
    cout<<f[0][5]<<"\n";

}

Measured memory_bytes: 13648
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

//ax+by=gcd(a,b)の解(x,y)を求める
//返り値はgcd(a,b)
int extgcd(int a,int b,int &x,int &y){
    int g=a;
    x=1,y=0;
    if(b!=0) g=extgcd(b,a%b,y,x),y-=(a/b)*x;
    return g;
}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int a,b,x,y;
    cin>>a>>b;
    int d=extgcd(a,b,x,y);
    a=a/d,b=b/d;
    int m,n;
    int min=1000000006;
    for(int i=-1e8;i<=1e8;i++){
        if(min>abs(x+b*i)+abs(y-a*i)){
            min=abs(x+b*i)+abs(y-a*i);
            m=i;
        }
    }
     cout<<x<<" "<<y<<endl;
   // cout<<(x+b*m)<<" "<<(y-a*m)<<endl;
    // cout<<"TIME: "<<(double)clock()/CLOCKS_PER_SEC<<endl;
}


Measured memory_bytes: 3220
#include<bits/stdc++.h>
#define endl '\n'
#define eb emplace_back
#define MAX (int)1e5 + 5
#define vi vector<int>
#define pii pair<int,int>
#define ok cerr<<"ok"<<endl
#define bb binary_search
#define all(A) A.begin(),A.end()
#define mp make_pair
#define pb push_back
#define inf INT_MAX/2
#define fi first
#define se second
//#define int  long long 
using namespace std;



int32_t main() {
	int n,x,t;
	cin >> n >> x >> t;
	int cont = n/x;
	int falta = n%x;
	int resp = cont * t;;
	if(falta > 0){
		resp += t;
	}
	
	cout << resp << endl;
	return 0;
} 

Measured memory_bytes: 3592
#include<stdio.h>
int main(){
    int b,r,g,c,s,t,i,ans=100,game,bonus,free;
    while(1){
        scanf("%d%d%d%d%d%d",&b,&r,&g,&c,&s,&t);
        if(b==0&&r==0&&g==0&&c==0&&s==0&&t==0) return 0;
        bonus = (b*5)+(r*3);
        game = t-bonus;
        free = game - s;
        ans += (bonus*15) + (g*7)+ (c*2) + (b*15) + (r*15);
        ans -= (free*3) + (bonus *2);
        printf("%d\n",ans);
        ans =100;
    }
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
typedef long long ll;
using namespace std;

int main(){
    vi(N,4);
    rep(i,4) cin >> N[i];
    srt(N);
    if(N[0] == 1){
        if(N[1] == 4){
            if(N[2] == 7){
                if(N[3] == 9){
                    cout << "YES" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX 2005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<ll,ll>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);
#define INT_SIZE 32
using namespace std;
 
ll gcd(ll n1,ll n2){
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent)
{
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
int arr[MAX],n;
int ans[MAX][MAX];
int msis[MAX][MAX],msis2[MAX][MAX];
int pre[MAX];
int len[MAX][MAX];
void maxSumIS(int x)
{
    int i, j, max = 0;

    for ( i = x; i < n; i++ )
        msis[x][i] = arr[i];
    for ( i = x+1; i < n; i++ )
        for ( j = x; j < i; j++ )
            if ( arr[i] > arr[j] && msis[x][i] < msis[x][j] + arr[i])
                msis[x][i] = msis[x][j] + arr[i];
 
    for ( i = x; i < n; i++ )
    {
    	ans[x][i]=ans[x][i-1];
        if ( ans[x][i] < msis[x][i] )
            ans[x][i] = msis[x][i];
    }
}
int main()
{
	int mini=MOD;
	int maxi=-1;
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='A')
			mini=min(mini,i);
		if(s[i]=='Z')
			maxi=max(maxi,i);
	}
	cout<<maxi-mini+1<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long
#define N 500005
using namespace std;
char s[N];int ans,tot;
signed main(){
	scanf("%s",s+1);int n=strlen(s+1);
	for (int i=n;i;i--){
		if (s[i]=='W') tot++;
		else ans+=tot;
	}
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 384
#include<stdio.h>

int calc(int x, int y) {
    if(y == 0) {
        return x;
    }else {
        return calc(y, x % y);
    }
}

int main() {
    int x, y;
    scanf("%d %d", &x, &y);
    
    if(x >= y) printf("%d\n", calc(x, y));
    if(x < y) printf("%d\n", calc(y, x));
}


Measured memory_bytes: 2756
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include <utility>
#include<map>
#include<functional>
#include<climits>
#include<regex>
#include<numeric>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
	int n,p[100];
	string s[100];
	bool used[100];
	fill(used, used + 100, false);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i] >> p[i];
	}
	vector <int>ans;
	while (ans.size() != n) {
		int memo = -1;
		for (int i = 0; i < n; i++) {
			if (memo == -1) {
				if (!used[i])memo = i;
			}
			else {
				if ((!used[i]) && ((s[i] < s[memo]) || (s[i] == s[memo] && p[i] > p[memo])))memo = i;
			}
		}
		used[memo] = true;
		ans.push_back(memo);
	}
	for (int i = 0; i < n; i++) {
		cout << ans[i]+1 << endl;
	}

}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

const ll MAX = 1000001;
ll fac[MAX], finv[MAX], inv[MAX];
// nCk初期化
void nCkInit(const ll MOD) {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll nCk(ll n, ll k,const ll MOD){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll N,K;
ll a[200010];
int main(){
    cin>>N>>K;
    nCkInit(MOD);
    for(ll i=0;i<N;i++){
        cin>>a[i];
    }
    sort(a,a+N);
    ll ans=0;
    for(ll i=N-1;i>=0;i--){
        ll tmp=a[i]*nCk(i,K-1,MOD)%MOD;
        ans=(ans+tmp)%MOD;
    }
    for(ll i=0;i<N;i++){
        ll tmp=a[i]*nCk(N-(i+1),K-1,MOD)%MOD;
        ans=(ans+(MOD-tmp))%MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 24448
import itertools
a,b=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(a)]
cnt=0
sum_1=[]
for v in itertools.combinations(l,2):
    sum=0
    for i in range(b):
        sum+=(v[0][i]-v[1][i])**2
    if (sum**0.5).is_integer():
        cnt+=1
print(cnt)

Measured memory_bytes: 3064
#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() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int cnt = 0;
	while(a >= b) {
		b*=2;
		cnt++;
	} 
	while(b >= c) {
		c*=2;
		cnt++;
	} 
	if (cnt > k) cout << "No" << endl;
	else cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int sum = 0;
	for (; a <= b; ++a) {
		if (c % a == 0) sum += 1;
	}

	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3104
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

const M: usize = 1000_000_007;


fn main() {
    let n: usize = util::get();
    let s = vec![
        util::line().chars().collect::<Vec<_>>(),
        util::line().chars().collect::<Vec<_>>(),
    ];

    let mut v = Vec::new();
    let mut i = 0;

    while i < n {
        if s[0][i] == s[1][i] {
            i += 1;
            v.push(true);
        } else {
            i += 2;
            v.push(false);
        }
    }

    println!(
        "{:?}",
        v.get(0)
            .map(|&b| if b { 3 } else { 6 })
            .into_iter()
            .chain(v.windows(2).map(|v| match (v[0], v[1]) {
                (true, true) => 2,
                (true, false) => 2,
                (false, true) => 1,
                (false, false) => 3,
            }))
            .fold(1, |a, b| a * b % M)
    );
}


Measured memory_bytes: 4352
#include <iostream>
    #include <vector>
    #include <utility>
    #include <assert.h>
    using namespace std;
     
    int main(){
      int n,i;
      vector<pair<int,int> > v;
      cin >> n;
      long long a[n];
      int t;
      long long mx = 0,cnt=0;
      bool ch;
      for(i=0;i<n;i++){
        cin >> a[i];
        if(abs(a[i])-abs(mx)>0){
          mx = a[i];
          t=i;
        }
      }
      if(mx>=0)ch=true;
      else ch = false;
      for(i=0;i<n;i++){
        a[i]+=mx;
        cnt++;
        v.push_back(make_pair(t+1,i+1));
      }
      if(ch){
      	for(i=1;i<n;i++){
          if(a[i]<=a[i-1]){
            a[i]+=a[i-1];
            v.push_back(make_pair(i,i+1));
            cnt++;
          }
        }
      }else{
        for(i=n-2;i>=0;i--){
            a[i]+=a[i+1];
            v.push_back(make_pair(i+2,i+1));
            cnt++;
        }
      }
      
      cout << cnt << endl;
      for(i=0;i<v.size();i++){
        cout << v[i].first << " " << v[i].second << endl;
      }
      
      /*
      cout << "===========" << endl;
      for (int i = 0; i < n; i++) {
      	cout << a[i] << endl;
      	if (i + 1 < n) {
      		assert(a[i] <= a[i + 1]);
      	}
      }
      */
      /*for(i=0;i<n;i++)cout << a[i] << " ";
      cout << endl;*/
       return 0;
    }
        

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n;
  cin>>n;
    int check=0;
  string a="7";
    if(n%2==0)
    { cout<<-1;
    check=1;
    }
  long long   num=7
    ;

    for(int i=1;i<=1000000;i++)
    {
   
   
    //cout<<num<<endl;
    //cout<< num<<endl;
      if(num%n==0)
      {check=1;
         cout<<i;
        break;
      }
       num=(num*10+7)%n;
    }
  if(check==0)
    cout<<-1;
  
 }


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

using namespace std;

typedef long long int lli;

class UnionFind {
private:
    vector<int> data;

public:
    UnionFind(int size) : data(size, -1) { }
    
    int root(int x) {
        return (data[x] < 0) ? x : data[x] = root(data[x]);
    }

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }

    bool find(int x, int y) {
        return root(x) == root(y);
    }

    int size(int x) {
        return -data[root(x)];
    }
};


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

    int n, m, p[100000], x, y;
    UnionFind uf(100000);

    cin >> n >> m;
    for (int i=0; i<n; i++) cin >> p[i];
    for (int i=0; i<m; i++) {
        cin >> x >> y;
        uf.unite(x-1, y-1);
    }

    int ans = 0;
    for (int i=0; i<n; i++) {
        if (p[i] == i+1 || uf.root(i) == uf.root(p[i]-1)) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1152
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define all(m) m.begin(), m.end()
#define uid uniform_int_distribution
#define init(m, x) memset(m, x, sizeof(m));
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int getChar(){
    static char buf[1<<16];
    static int pos = 0, size=0;
    if(pos==size){
        pos = 0;
        size = (int)fread(buf, sizeof(buf[0]), sizeof(buf)/sizeof(buf[0]), stdin);
    }
    return buf[pos++];
}

int ni(){
    char c = getChar();
    for(;c=='\n' || c==' ';) c = getChar();
    int o = 0;
    for(; c!=' ' && c!='\n'; c = getChar()) o = o*10+c-'0';
    return o;
}

int kek[23000005][3];
int i = 0;

int build(int l, int r){
    if(l==r) return i++;
    int md = (l+r)/2;
    kek[i][0] = build(l,md);
    kek[i][1] = build(md+1,r);
    return i++;
}

int sum(int l, int r, int l1, int r1, int n){
    if(l==l1 && r==r1) return kek[n][2];
    int md = (l1+r1)/2;
    if(r<=md) return sum(l,r,l1,md,kek[n][0]);
    if(l>md) return sum(l,r,md+1,r1,kek[n][1]);
    return sum(l,md,l1,md,kek[n][0]) + sum(md+1,r,md+1,r1,kek[n][1]);
}

inline int sumP(int p, int l, int r, int n){
    int o = 0;
    for(; l<r;){
        int md = (l+r)/2;
        if(p<=md) r = md, n = kek[n][0];
        else{
            o += kek[kek[n][0]][2];
            l = md+1;
            n = kek[n][1];
        }
    }
    return o+kek[n][2];
}

int plusplus(int pos, int l, int r, int n, int val){
    int u = i++;
    for(int q=0; q<3; q++) kek[u][q] = kek[n][q];
    kek[u][2]+=val;
    if(l==r) return u;
    int md = (l+r)/2;
    if(pos<=md) kek[u][0] = plusplus(pos, l, md, kek[u][0],val);
    else kek[u][1] = plusplus(pos, md+1,r,kek[u][1],val);
    return u;
}

const int R = 500005;
int a,z,c;
int store[R*2];

int main() {
    fast;
    a = ni(), z = ni();
    int n = build(0, R);
    store[0] = n;
    int mp[R];
    init(mp, -1);
    for(int q=0; q<a; q++){
        c = ni();
        int u = store[q];
        if(mp[c]!=-1){
            int pr = mp[c];
            u = plusplus(pr, 0, R, u, -1);
        }
        u = plusplus(q+1, 0, R, u, 1);
        store[q+1] = u;
        mp[c] = q+1;
    }
    int l,r,o;
    for(; z--;){
        l = ni(), r = ni();
        o = sumP(r,0,R,store[r]) - (l==1 ? 0 : sumP(l-1,0,R,store[r]));
        cout<<o<<"\n";
    }
}

Measured memory_bytes: 252892
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]
L = [[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if j == 0 and S[i][j] != '#':
            L[i][j] = 1
        elif S[i][j] != '#':
            L[i][j] = L[i][j-1] + 1
R = [[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w-1, -1, -1):
        if j == w-1 and S[i][j] != '#':
            R[i][j] = 1
        elif S[i][j] != '#':
            R[i][j] = R[i][j+1] + 1
U = [[0]*w for _ in range(h)]
for j in range(w):
    for i in range(h):
        if i == 0 and S[i][j] != '#':
            U[i][j] = 1
        elif S[i][j] != '#':
            U[i][j] = U[i-1][j] + 1
D = [[0]*w for _ in range(h)]
for j in range(w):
    for i in range(h-1, -1, -1):
        if i == h-1 and S[i][j] != '#':
            D[i][j] = 1
        elif S[i][j] != '#':
            D[i][j] = D[i+1][j] + 1
ans = -1
for i in range(h):
    for j in range(w):
        ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
print(ans)

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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e16;
const int N = 2e5 + 5;


struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
    chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

unordered_map <int,LL,custom_hash> dp[ N ];
int n;
LL a[ N ];

LL solve(int idx, int taken) {
  int need = n/2 - (n - idx + 1)/2;
  if (taken < need) return -INF;
  if (idx >= n) return taken == n/2 ? 0 : -INF;
  if (dp[idx].count(taken)) return dp[idx][taken];
  LL ret = -INF;
  ret = max(ret, solve(idx + 2, taken + 1) + a[idx]);
  ret = max(ret, solve(idx + 1, taken));
  return dp[idx][taken] = ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
  #endif // LOCAL
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cout << solve(0, 0) << endl;
  return 0;
}

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


#define M_MAX 20
#define N_MAX 50000
#define INFTY 1 << 29
int a;
int b;

int rep(int moto,int tap){
tap++;
moto--;
moto+=a;
if(moto>=b)return tap;
else return rep(moto,tap);
}

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

if(b<=1){
cout << 0;
}else{
cout <<rep(1,0);

}

}


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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

class ATakahashiCalendar {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int M, D;
    cin >> M >> D;

    int ans = 0;
    for (int m = 1; m <= M; m++){
        for (int d = 1; d <= D; d++){
            if (d % 10 >= 2 and d / 10 >= 2 and (d % 10) * (d / 10) == m)
                ans++;
        }
    }

    cout << ans << endl;
}
};

int main() {
	ATakahashiCalendar solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
N = int(input())
T = [int(input()) for _ in range(N)]


def gcd(x, y):
    if x < y:
        t = x
        x = y
        y = t

    if y == 0:
        return x

    else:
        return gcd(y, x % y)


if N == 1:
    print(T[0])
    exit()

res = T[0] * T[1] // gcd(T[0], T[1])

if N > 2:
    for i in range(2, N):
        r = res * T[i] // gcd(res, T[i])
        res = max(r, res)

print(res)

Measured memory_bytes: 9216
import java.util.Scanner;
import java.util.ArrayList;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int i, o, m = Integer.MAX_VALUE;
        int s = 0, te = 0;
        ArrayList<Integer> t = new ArrayList<Integer>();
        ArrayList<Integer> al = new ArrayList<Integer>();
        for (i = 0; i < n; i++) {
            te = sc.nextInt();
            al.add(te);
            s += te;
        }
        s = Math.round(s/n);
        t.add(f(s, al));
        t.add(f(s-1, al));
        t.add(f(s+1, al));
        for (i = 0; i < 3; i++) {
            int a = t.get(i);
            if (m > a) m = a;
        }
        System.out.println(m);
    }
    private static int f(int s, ArrayList<Integer> al) {
        int te = 0, re = 0, i;
        for (i = 0; i < al.size(); i++) {
            te = al.get(i);
            if (te == s) continue;
            re += (te-s)*(te-s);
        }
        return re;
    }
}

Measured memory_bytes: 9680