akhauriyash/Code-Regression huggingface dataset:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N, M = NMI()
    query = [NLI() for _ in range(M)]
    numbers = list(range(10**(N-1), 10**N))
    if N == 1: numbers = [0] + numbers
    for n in numbers:
        s = str(n)
        ok = True
        for q in query:
            if s[q[0]-1] == str(q[1]):
                continue
            else:
                ok = False
        if ok:
            print(n)
            exit()
    print(-1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>

using namespace std;

int main(){
    string s;
    char output[210];
    getline(cin,s);
    const char *input = s.c_str();
    int i;
    while(input[i] != '\0'){
        if(input[i] >= 'a' && input[i] <= 'z'){
            output[i] = input[i] - 32;
        }
        else{
            output[i] = input[i];
        }
        i++;
    }
    output[i] = '\0';
    cout << output << endl;
}

Measured memory_bytes: 3136
#include <iostream>

using namespace std;

int main()
{
	int X;

	cin >> X;

	if ((X == 3)
		|| (X == 5)
		|| (X == 7)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}


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

int main(){
 set<int> s;
  int n,a;
  cin >> n;
  while(n--){
    cin >> a;
    s.insert(a);
  }
  for(auto it=s.begin();it!=s.end();it++){
    if(it!=s.begin())cout << " ";
    cout << *it;
  }
  cout << endl;
}


Measured memory_bytes: 7788
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
if(a > b)
System.out.println("a > b");
if(a < b)
System.out.println("a < b");
if(a == b)
System.out.println("a == b");
    }
}


Measured memory_bytes: 26144
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

constexpr int INF = (1 << 30);
constexpr ll LINF = (1LL << 62);

int N, M;
vector<int> A, B, C, D, E, F;

void input() {
	cin >> N >> M;
	A.resize(N); B.resize(N); C.resize(N);
	D.resize(M); E.resize(M); F.resize(M);
	for (int i = 0; i < N; ++i)
		cin >> A[i] >> B[i] >> C[i];
	for (int i = 0; i < M; ++i)
		cin >> D[i] >> E[i] >> F[i];
}

struct node {
	ll S;
	bool l, r, u, d;
	node() {
		S = 0;
		l = r = u = d = true;
	}
};

map<int, int> x, y;
vector<int> _x, _y;

void compress() {
	x[INF]; y[INF]; x[-INF]; y[-INF]; x[0]; y[0];
	for (int i = 0; i < N; ++i)
		x[A[i]], x[B[i]], y[C[i]];
	for (int i = 0; i < M; ++i)
		x[D[i]], y[E[i]], y[F[i]];
	int t = 0;
	for (auto& e : x) {
		e.second = t++;
		_x.push_back(e.first);
	}
	t = 0;
	for (auto& e : y) {
		e.second = t++;
		_y.push_back(e.first);
	}
}

int H, W;
node grid[3010][3010];

void make_grid() {
	W = x.size() - 1;
	H = y.size() - 1;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			ll dx = _x[j + 1] - (ll)_x[j];
			ll dy = _y[i + 1] - (ll)_y[i];
			ll S = dx * dy;
			grid[i][j].S = S;
			if (i == 0) grid[i][j].u = false;
			if (i == H - 1) grid[i][j].d = false;
			if (j == 0) grid[i][j].l = false;
			if (j == W - 1) grid[i][j].r = false;
		}
	}
	for (int i = 0; i < N; ++i) {
		int y_idx = y[C[i]];
		for (int x_idx = x[A[i]]; x_idx < x[B[i]]; ++x_idx) {
			grid[y_idx][x_idx].u = false;
			grid[y_idx - 1][x_idx].d = false;
		}
	}
	for (int i = 0; i < M; ++i) {
		int x_idx = x[D[i]];
		for (int y_idx = y[E[i]]; y_idx < y[F[i]]; ++y_idx) {
			grid[y_idx][x_idx].l = false;
			grid[y_idx][x_idx - 1].r = false;
		}
	}
}

int visited[3010][3010];
ll res = 0;

void dfs(int y_st, int x_st) {
	stack<pair<int, int>> st;
	visited[y_st][x_st] = 1;
	st.push({ y_st, x_st });
	while (!st.empty()) {
		auto p = st.top();
		st.pop();
		int sy = p.first, sx = p.second;
		if (sy == 0 || sy == H - 1 || sx == 0 || sx == W - 1) {
			res = LINF;
			return;
		}
		res += grid[sy][sx].S;
		if (grid[sy][sx].l && !visited[sy][sx - 1])
			visited[sy][sx - 1] = 1, st.push({ sy, sx - 1 });
		if (grid[sy][sx].r && !visited[sy][sx + 1])
			visited[sy][sx + 1] = 1, st.push({ sy, sx + 1 });
		if (grid[sy][sx].u && !visited[sy - 1][sx])
			visited[sy - 1][sx] = 1, st.push({ sy - 1, sx });
		if (grid[sy][sx].d && !visited[sy + 1][sx])
			visited[sy + 1][sx] = 1, st.push({ sy + 1, sx });
	}
}

int main() {
	input();
	compress();
	make_grid();
	dfs(y[0], x[0]);
	if (res < LINF) cout << res << endl;
	else cout << "INF" << endl;
	return 0;
}

Measured memory_bytes: 210856
a, b, k = map(int,input().split())
for i in range(k//2):
    if a%2!=0:
        a -= 1
    b += (a//2)
    a -= (a//2)
    if b%2!=0:
        b -= 1
    a += (b//2)
    b -= (b//2)

if k%2!=0:
    if a%2!=0:
        a -= 1
    b += (a//2)
    a -= (a//2)

print(a, b)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		long min = 0;
		long max = 0;
		long cnt = 0;

		if(n == 1) {
			if(a == b) {
				cnt++;
			}else if(a != b) {
				//なにもしない
			}
		}else if(n > 1) {
			if(a > b) {
				//なにもしない
			}else if(a < b){
				for(int i = 0 ; i < n ; i++) {
					min += a;
					max += b;
				}
				cnt = (max - b + a) - (min - a + b) + 1;
			}else if(a == b){
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ.Volume1
{
    public class Bowling
    {
        public static int Main()
        {
            while (true)
            {
                int counter = int.Parse(Console.ReadLine());
                if (counter == 0) { break; }

                var result = new List<KeyValuePair<int, int>>();
                for (int s = 0; s < counter; s++)
                {
                    var input = Console.ReadLine().Split(' ');

                    var pin = new int[21];
                    for (int i = 1; i < input.Length; i++) { pin[i - 1] = int.Parse(input[i]); }
                    int score = 0;
                    int pos = 0;
                    for (int frame = 1; frame <= 10; frame++)
                    {
                        // ストライク
                        if (pin[pos] == 10)
                        {
                            score += 10 + pin[pos + 1] + pin[pos + 2];

                            pos++;
                            continue;
                        }
                        // スペア
                        if (pin[pos] + pin[pos + 1] == 10)
                        {
                            score += pin[pos + 2];
                        }

                        // スペアの10点もここで加算
                        score += pin[pos] + pin[pos + 1];
                        pos = pos + 2;
                    }

                    result.Add(new KeyValuePair<int, int>(int.Parse(input[0]), score));
                }

                foreach (var kvp in result.OrderByDescending(x => x.Value).ThenBy(y => y.Key))
                {
                    Console.WriteLine(kvp.Key.ToString() + " " + kvp.Value.ToString());
                }
            }
            return 0;
        }
    }
}

Measured memory_bytes: 10264
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return

#define INF 2000000000	//int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

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

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

   int x, y, z;
   cin >> x >> y >> z;
   cout << (x-z) / (y+z) << endl;
   
   rtn 0;
}

Measured memory_bytes: 256
import math

n = int(input())
t = int(math.sqrt(n)) + 1

count = 0
p = 0
for a in range(1,t):
    for b in range(a,1000000):
        if a*b < n:
            count += 1
        else:
            break
        if a==b: p+=1
count = (count*2) - p
print(count)

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

int main(void){ 
    int n, cnt = 0;
	cin >> n;
	vector<int> a(n);
	for(int i=0; i<n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	vector<int> p(1000001);
	for(int i=0; i<n; i++){
		if(!p[a[i]]){
			cnt++;
			if(i != n-1 && a[i] == a[i+1]) cnt--;
			int64_t now = a[i];
			while (now <= 1000000) {
				p[now] = 1;
				now += a[i];
			}
		}
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 7992
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

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

    vector<string> S(N);
    for (int i = 0; i < N; i++)
    {
        cin >> S[i];
    }

    vector<bool> cnt(26, false);
    
    for (int i = 0; i < N; i++)
    {
        if(S[i] == "P"){
            cnt['P' - 'A'] = true;
        }
        else if(S[i] == "W"){
            cnt['W' - 'A'] = true;
        }
        else if(S[i] == "G"){
            cnt['G' - 'A'] = true;
        }
        else if(S[i] == "Y"){
            cnt['Y' - 'A'] = true;
        }
    }

    int output = 0;
    for (int i = 0; i < 26; i++)
    {
        if(cnt[i] == true){
            output++;
        }
    }

    if(output == 3){
        cout << "Three" << endl;
    }else if(output == 4){
        cout << "Four" << endl;
    }
    

    
}

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

int main(){
	int n, x;
	while(cin >> n >> x && (n || x)){
		int ans = 0;
		for(int i = 1; i <= n; i++) for(int j = i + 1; j <= n; j++) for(int k = j + 1; k <= n; k++) if(i + j + k == x) ans++;
		cout << ans << endl;
	}
}

Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <iomanip>
#include <vector>
#include <queue>
#include<algorithm>
using namespace std;

int num[3];


int main()
{
      for(int i=0;i<3;i++)
      {
            cin>>num[i];
      }
      sort(num,num+3);
      cout<<num[0]+num[1]<<endl;

      return 0;
}


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

const int N = 3054, mod = 1000000007;

int n, q;
int dp[2][2][N], (*cur)[N] = *dp, (*nxt)[N] = dp[1];

inline void add(int &x, const int y) {x += y - mod, x += x >> 31 & mod;}

void step() {
	int i;
	std::swap(cur, nxt), memset(nxt, 0, sizeof *dp);
	for (i = 0; i <= n; ++i) {
		// 00 (decrease)
		if (i > 1)
			add(nxt[0][i - 1], cur[0][i]), add(nxt[1][i - 1], cur[1][i]);
		else if (i == 1)
			add(nxt[1][i - 1], cur[0][i]), add(nxt[1][i - 1], cur[1][i]);
		// 01 (decrease - increase)
		if (i > 1)
			add(nxt[0][i], cur[0][i]), add(nxt[1][i], cur[1][i]);
		else if (i == 1)
			add(nxt[1][i], cur[0][i]), add(nxt[1][i], cur[1][i]);
		// 10 (increase - decrease)
		if (i < n)
			add(nxt[0][i], cur[0][i]), add(nxt[1][i], cur[1][i]);
		// 11 (increase)
		if (i < n)
			add(nxt[0][i + 1], cur[0][i]), add(nxt[1][i + 1], cur[1][i]);
	}
}

int main() {
	int i;
	scanf("%d%d", &n, &q);
	std::fill(*nxt + 1, *nxt + (n + 1), 1), nxt[1][0] = 1;
	for (; q; --q) step();
	printf("%d\n", int(std::accumulate(nxt[1], nxt[1] + (n + 1), 0ll) % mod));
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

ll a,b,c,d,ret;
int main() {
	scanf("%lld%lld%*d%lld%lld%*d%*d",&a,&b,&c,&d);
	ret=a/2*2+c/2*2+d/2*2+b;
	if (a>=1&&c>=1&&d>=1) ret=max(ret,(a-1)/2*2+(c-1)/2*2+(d-1)/2*2+3+b);
	printf("%lld\n",ret);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define MAXN 300000+10
int n;
int w[MAXN],e[MAXN];	
string s;

int main() {
	
	cin>>n>>s;
	if (s[0]=='W') w[0]=1; else e[0]=1;
	for (int i=1;i<n;i++) {
		if (s[i]=='W') w[i]=w[i-1]+1,e[i]=e[i-1];
		else w[i]=w[i-1],e[i]=e[i-1]+1;	
	}
	int ans=e[n-1];
	
	for (int i=1;i<n;i++)
		ans=min(ans,w[i-1]+e[n-1]-e[i]);
		
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3076
import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int h = stdIn.nextInt();
			int m = stdIn.nextInt();
			int s = stdIn.nextInt();
			if(h == -1 && m == -1 && s == -1) break;
			s += h*3600+ m*60;
			
			int a = 3600*2 - s;
			int b = a*3;
			
			int ah = a/3600;
			int bh = b/3600;
			a %= 3600;
			b %= 3600;
			
			int am = a/60;
			int bm = b/60;
			a %= 60;
			b %= 60;
			int as = a;
			int bs = b;
			System.out.printf("%02d:%02d:%02d\n",ah,am,as);
			System.out.printf("%02d:%02d:%02d\n",bh,bm,bs);
		}
	}
}

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


int main() {
    int N;
    std::cin >> N;

    long long int MAX = 1000000000000000000;
    long long int sum = 1;
    bool overflow = false;
    bool zero = false;

    for (int i = 0; i < N; i++) {
        long long int n;
        std::cin >> n;
        if (n == 0) {
            zero = true;
        } else {
            long long int prev = sum;
            sum *= n;
            if ((double)prev * (double)n > (double)MAX) {
                overflow = true;
            }
            if (sum > MAX) {
                overflow = true;
            }
        }
    }

    if (zero) {
        std::cout << 0 << std::endl;
        return 0;
    }
    if (overflow) {
        std::cout << -1 << std::endl;
        return 0;
    }

    std::cout << sum << std::endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int n, k;
    cin >> n >>k;
    vector<int> h(n);
    rep(i, 0, n){
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    int ans = 1e9;
    rep(i, 0, n - k + 1){
        ans = min(ans, h[i+k-1] - h[i]);
    }
    cout << ans << endl;
    return 0;
}


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

map<pair<int, int>, int> dp;

int solve(int n, int a, int b) {
    auto it = dp.find({a, b});
    if (it != end(dp)) {
        return it->second == 1;
    }
    dp[{a, b}] = -1;
    if (a + 1 <= n && a + 1 != b && dp.count({a + 1, b}) == 0 && !solve(n, b, a + 1)) {
        dp[{a, b}] = 1;
        return true;
    }
    if (a - 1 >= 1 && a - 1 != b && dp.count({a - 1, b}) == 0 && !solve(n, b, a - 1)) {
        dp[{a, b}] = 1;
        return true;
    }
    dp[{a, b}] = 0;
    return false;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    bool result = solve(n, a, b);
    if (result) {
        cout << "Alice";
    } else {
        cout << "Borys";
    }
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
typedef long long LL;

int int_vector_find(std::vector<int> vec, int num) {
	auto itr = std::find(vec.begin(), vec.end(), num);
	int index = std::distance(vec.begin(), itr);

	if (index != vec.size()) {
		return 1;
	}
	else {
		return 0;
	}
}

int main() {
	int a, p;
	std::cin >> a >> p;

	p += a * 3;

	std::cout << p / 2 << std::endl;
}

Measured memory_bytes: 256
using System;
using System.Text;

public class Test
{
	static public void Main( )
	{
		StringBuilder output = new StringBuilder();
		while( true ) {
			int[] nm = Array.ConvertAll( Console.ReadLine().Split( ' ' ), int.Parse );
			int n = nm[0];
			int x = nm[1];
			
			if( 0 == n && 0 == x ) { break; }
			
			int cnt = 0;
			for( var i=1; i<n; i++ ) {
				for( var j=i+1; j<=n; j++ ) {
					var k = x-i-j;
					if( i < k && k < j ) { cnt++; }					
				}
			}
			output.AppendLine( cnt.ToString() );
		}
		Console.Write( output );
	}
}

Measured memory_bytes: 5668
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define debug(x) cout<<x<<endl
#define int long long 
const int mod=1000000007;
int powmod(int a,int b) {int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b) { return b?gcd(b,a%b):a;}
inline int read() {int num=0, w=0;char ch=0;while (!isdigit(ch)) {w|=ch=='-';ch = getchar();}while (isdigit(ch)) {num = (num<<3) + (num<<1) + (ch^48);ch = getchar();}return w? -num: num;}
// cin.tie(0);
// ios::sync_with_stdio(false);
// head
// long long *long long 		**
struct node{
	
};
//all 
signed main()
{
	string a;
	cin>>a;
	if(a.size()%2==1){
		cout<<"No"<<endl;
	}
	else{
		int flag=0;
		for(int i=0;i<a.size();i+=2){
			if(a[i]=='h'&&a[i+1]=='i'){
				continue;
			}
			else{
				flag=1;
			}
		} 
		if(flag){
			cout<<"No"<<endl;
		}
		else{
			cout<<"Yes"<<endl;
		}
	}
	
    return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<algorithm>
#include<iostream>
template<class F>
auto  minimize(int imin,int imax,F &f,int sy,int sx, int base){ //(imin,imax]
    while(imax - imin > 1){
        int mid = imin + (imax - imin)/2;
        if(f(mid,base,sy,sx)) imax = mid;
        else imin = mid;
    }
    return imax; //imax is ans
}
template<class F>
auto  maximize(int imin,int imax,F &f,int sy,int sx,int base){ //[imin,imax)
    while(imax - imin > 1){
        int mid = imin + (imax - imin)/2;
        if(f(mid,base,sy,sx)) imin = mid;
        else imax = mid;
    }
    return imin; //imin is ans
}

signed
main(){
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int H,W;
    std::cin >> H >> W;
    std::vector<std::string>graph(H);
    for(auto & str : graph)
        std::cin >> str;
    std::vector<std::vector<int>>hsum(H,std::vector<int>(W,0));
    std::vector<std::vector<int>>wsum(H,std::vector<int>(W,0));
    for(int i = 0; i < graph.size(); ++i){
        wsum[i][0] = (graph[i][0] == '.' ? 0 : -1);
        for(int j = 1; j < W;++j){
            if(graph[i][j-1] == '.' and graph[i][j] == '.')
                wsum[i][j] += wsum[i][j-1] + 1;
            else if(graph[i][j] == '.' and graph[i][j-1] == '#')
                wsum[i][j] = 0;
        }
    }
    for(int j = 0; j < W; ++j){
        hsum[0][j] = (graph[0][j] == '.' ? 0 : -1);
        for(int i = 1; i < H;++i){
            if(graph[i-1][j] == '.' and graph[i][j] == '.')
                hsum[i][j] += hsum[i-1][j] + 1;
            else if(graph[i][j] == '.' and graph[i-1][j] == '#')
                hsum[i][j] = 0;
            
        }
    }
    auto xmaxi_f = [&](int mid,int base,int sy,int sx){ return (mid - sx == wsum[sy][mid] - base);};
    auto xmini_f = [&](int mid,int base,int sy,int sx){ return (sx - mid == base - wsum[sy][mid]);};
    auto ymaxi_f = [&](int mid,int base,int sy,int sx){ return (mid - sy == hsum[mid][sx] - base);};
    auto ymini_f = [&](int mid,int base,int sy,int sx){ return (sy - mid == base - hsum[mid][sx]);};
    
    auto subcalx = [&](int sy, int sx){
        int base = wsum[sy][sx];
        int rx = maximize(sx-1,W,xmaxi_f,sy,sx,base);
        int lx = minimize(-1, sx,xmini_f, sy, sx, base);
        return (rx - lx);
    };
    auto subcaly = [&](int sy, int sx){
        int base = hsum[sy][sx];
        int ry = maximize(sy-1,H,ymaxi_f,sy, sx, base);
        int ly = minimize(-1,sy,ymini_f,sy, sx, base);
        return (ry - ly);
    };
    auto cal = [&](int sy,int sx){
        return subcalx(sy,sx) + subcaly(sy,sx);
    };
    int maxi = -1;
    for(int sy = 0; sy < H; sy++){
        for(int sx = 0; sx < W;sx++){
            if(graph[sy][sx] == '#') continue;
            int cnt = cal(sy,sx) + 1;
            maxi = std::max(maxi,cnt);
        }
    }
    std::cout << maxi << std::endl;
}


Measured memory_bytes: 35968
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 922337203685477580LL;
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 T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

const int N = 20;
const int X = 1<<17;

//head

int n;
int a[N][N];
ll group[X];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  rep(i, n) rep(j, n) cin >> a[i][j];

  rep(i, 1<<n) {
    rep(j, n) rep(k, n) if(i>>j&1 and i>>k&1) group[i] += a[j][k];
    group[i] >>= 1;
    for(int j = i; j > 0;) {
      j--;
      j &= i;
      chmax(group[i], group[j] + group[i^j]);
    }
  }

  cout << group[(1<<n)-1] << endl;
}

Measured memory_bytes: 4180
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned int ui;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
#define All(v) (v).begin(),(v).end()
#define Rep(i,n) for(int i = 0; i < (int)n; i++)
#define Reps(i,n) for(int i = 1; i <= (int)n; i++)
#define For(i,m,n) for(int i = m; i < n; i++)
#define Fors(i,m,n) for(int i = m; i <= n; i++)
#define Inf 2e9
#define F first
#define S second
#define pb push_back
#define mp make_pair
struct speed{speed(){cin.tie(); ios::sync_with_stdio(false); cout << fixed << setprecision(18);}}aaa;

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

ll lcm(ll a, ll b){
    return a*b/gcd(a,b);
}


int main (){
    int n,d;
    cin >> n >> d;
    vector<vector<int>> x(n,vector<int>(d,0));
    Rep(i,n){
        Rep(j,d){
            cin >> x[i][j];
        }
    }
    int ans = 0;
    Rep(i,n){
        For(j,i+1,n){
            double kyori = 0;
            Rep(k,d){
                kyori += pow(x[i][k]-x[j][k],2);
            }
            kyori = sqrt(kyori);
            if(fmod(kyori,1) == 0) ans++;
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
# ABC141E - Who Says a Pun?
class RollingHash:
    def __init__(self, source: str, base=1000000007, mod=9007199254740997):
        self.source = source
        self.length = len(source)
        self.base = base
        self.mod = mod
        self.hash = self._get_hash_from_zero()
        self.power = self._get_base_pow()

    def _get_hash_from_zero(self):  # compute hash of interval [0, right)
        cur, hash_from_zero = 0, [0]
        for e in self.source:
            cur = (cur * self.base + ord(e)) % self.mod
            hash_from_zero.append(cur)
        return hash_from_zero

    def _get_base_pow(self):  # computer mod of power of base
        cur, power = 1, [1]
        for i in range(self.length):
            cur *= self.base % self.mod
            power.append(cur)
        return power

    def get_hash(self, l: int, r: int):  # compute hash of interval [left, right)
        return (self.hash[r] - self.hash[l] * self.power[r - l]) % self.mod


def main():
    N = int(input())
    S = input().rstrip()
    rh, ok, ng = RollingHash(S, 27, 10 ** 9 + 7), 0, N // 2 + 1
    while ng - ok > 1:
        mid = (ok + ng) // 2
        flg, memo = 0, set()
        for i in range(N - 2 * mid + 1):
            memo.add(rh.get_hash(i, i + mid))
            if rh.get_hash(i + mid, i + 2 * mid) in memo:
                flg = 1
                break
        if flg:
            ok = mid  # next mid will be longer
        else:
            ng = mid  # next mid will be shorter
    print(ok)  # max length of substrings appeared twice or more


if __name__ == "__main__":
    main()

Measured memory_bytes: 11576
#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 int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n, l;
int a[100005];

int main()
{
	cin >> n >> l;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	int flag = 0;
	for (int i = 1; i < n; i++) {
		if (a[i] + a[i + 1] >= l) flag = i;
	}

	if (flag == 0) {
		cout << "Impossible" << endl;
	}
	else {
		cout << "Possible" << endl;

		for (int i = 1; i < flag; i++) {
			cout << i << endl;
		}

		for (int i = n-1; i >= flag; i--) {
			cout << i << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <cstdio>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdlib>
#include <cstdio>
using namespace std;

#define next '\n'
#define rep(i, n) for(int (i) = (0); (i) < (n); (i++))
using ll = long long;

int a[25], b[25], c[25];

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

    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    for(int i = 1; i <= n; ++i){
        cin >> b[i];
    }
    for(int i = 1; i <= n - 1; ++i){
        cin >> c[i];
    }

    int ans = 0;
    int sum = 0;
    int old = 0;
    for(int i = 1; i <= n; ++i){
        int dish = a[i];
        // 満足度の加算
        sum += b[dish];

        // cの加算
        if(i != 1 && dish - 1 == old){
            sum += c[old];
        }
        
        ans += sum;
        sum = 0;
        old = dish;
    }

    cout << ans << next;
}

Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const long long SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑


int main() {


	int n;
	cin >> n;
	cout << (n - 2) * 180 << endl;





}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define LL long long
#define INF 1e18
using namespace std;
LL n,p,p2,p3,p5;map<LL,LL> f;
I LL dfs(Con LL& x)
{
	#define Fdiv(x,y) ((1.0L*p*(x)/y*(y-1)>=1e18||p##y<=p*(x)/y*(y-1))?p##y:p*(x)/y*(y-1))
	#define DFS(x,v) (t=dfs(x)+v,res>t&&(res=t))
	#define Work(y) ((m=x%y)?(x>=y&&DFS(x/y,Fdiv(x-m,y)+p*m),DFS(x/y+1,Fdiv(x+y-m,y)+p*(y-m))):DFS(x/y,Fdiv(x,y)))
	if(!x) return 0;if(x==1) return p;if(f.count(x)) return f[x];
	RI m;LL t,res=INF;return Work(2),Work(3),Work(5),f[x]=res;
}
int main()
{
	RI Tt;scanf("%d",&Tt);W(Tt--) f.clear(),
		scanf("%lld%lld%lld%lld%lld",&n,&p2,&p3,&p5,&p),printf("%lld\n",dfs(n));
	return 0;
}

Measured memory_bytes: 4508
#include <stdio.h>

int main(void){
	char s[100+1];
	char ss[100*2+1];
	char p[100+1];
	
	scanf("%s", s);
	scanf("%s", p);
	
	strcpy(ss, s);
	strcpy(ss+strlen(s), s);
	
	if(strstr(ss, p) != NULL){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 532
#include <stdio.h>
#include <string.h>

int main(){
  char a,d,in[2][81],out[81],*outp;
  int b,c,e,i,j,k,ln[2],n;
  scanf("%d\n",&n);
  for(i=0;i<n;i++){
    b=0;c=0;e=0;
    while((a=getchar())){
      if(a>='0' && a<='9'){
        if(c>=80) e=1; else in[b][c++]=a;
      }
      if(a=='\n'){
        ln[b]=c;
        in[b][c++]=0;
        b++; if(b>=2) break;
        c=0;
      } 
    }
    if(e==1){
      printf("overflow\n");
      e=0;
    } else {
      for(j=0;j<81;j++){out[j]=0;}
      for(j=(ln[0]>ln[1]?ln[0]:ln[1]);j>=0;j--){
        d=out[j];
        if(ln[0]>0) d+=in[0][--ln[0]]-'0'; 
        if(ln[1]>0) d+=in[1][--ln[1]]-'0'; 
        out[j]=d%10+'0';
        out[j-1]=d/10;
      }
      outp=(out[0]=='0'?out+1:out);
      if(strlen(outp)<=80) printf("%s\n",outp);
       else printf("overflow\n");
    }
  }
  return 0;
}

Measured memory_bytes: 588
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,maxn,minn=1e9,a[105];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        maxn=max(maxn,a[i]);
        minn=min(minn,a[i]);
    }
    if(minn!=(maxn+1)/2){
        puts("Impossible");
        return 0;
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(a[i]==minn){
            cnt++;
        }
    }
    if(cnt!=(maxn&1)+1){
        puts("Impossible");
        return 0;
    }
    for(int i=minn+1;i<=maxn;i++){
        cnt=0;
        for(int j=1;j<=n;j++){
            if(a[j]==i){
                cnt++;
            }
        }
        if(cnt==0||cnt==1){
            puts("Impossible");
            return 0;
        }
    }
    puts("Possible");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

template <typename T>
T gcd(T a, T b) {
    if (a > b) {
        T buf = a;
        a = b;
        b = buf;
    }
    return a == 0 ? b : gcd(a, b % a);
}

template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

int main() {
    ll a, b;
    cin >> a >> b;
    cout << lcm(a, b) << '\n';
    return 0;
}

Measured memory_bytes: 256
main :: IO ()
main = do
    [k,s] <- map read . words <$> getLine
    print . length $ xyzs k s

xyzs :: Int -> Int -> [(Int, Int, Int)]
xyzs k s = [(x,y,z) | x <- [0..k], y <- [0..k], let z = s-(x+y), 0 <= z && z <= k]

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

int main() {
  int a, b, sum, average;
  cin >> a >> b;
  sum = a + b;
  if (sum % 2 == 0) {
    average = sum / 2;
  } else {
    average = sum / 2 + 1;
  }
  cout << average << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long n, h, i, j, k, s, ans, hh, x;
	cin >> n >> h;
	vector<pair<long long, long long>> p(n), d(n);
	vector<pair<long long, long long>>::iterator it;
	for (i = 0; i < n; i++) {
		cin >> p[i].first >> p[i].second;
		d[i].first = p[i].second;
		d[i].second = 0;
	}
	sort(d.rbegin(), d.rend());
	s = 0;
	ans = 1LL << 60;
	for (i = 0; i < n; i++) {
		s += d[i].first;
		d[i].second = s;
		if (s >= h) ans = min(ans, i + 1);
	}
	reverse(d.begin(), d.end());

	for (i = 0; i < n; i++) {
		it = lower_bound(d.begin(), d.end(), make_pair(p[i].first, 0LL));
		hh = h - it->second;
		if (hh <= 0) ans = min(ans, (long long)(d.end() - it));
		else {
			x = (long long)(d.end() - it) + (hh + p[i].first - 1) / p[i].first;
			ans = min(ans, x);
		}
	}

	cout << ans << "\n";
	return 0;
}


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

public class Main {
    private void solve() {
        int k = sc.nextInt();
        String s = sc.next();

        int n = s.length();
        if (n <= k) {
            out.println(s);
        } else {
            out.println(s.substring(0, k) + "...");
        }
    }

    private static PrintWriter out;
    private static MyScanner sc;

    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        private MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

    public static void main(String[] args) {
        out = new PrintWriter(new BufferedOutputStream(System.out));
        sc = new MyScanner();
        new Main().solve();
        out.close();
    }
}

Measured memory_bytes: 25452
using System;
using System.Collections.Generic;
using System.Linq;

class D
{
	static void Main()
	{
		var s = Console.ReadLine();
		var qs = new int[int.Parse(Console.ReadLine())].Select(_ => Console.ReadLine()).ToArray();

		var f = false;
		var l1 = new List<char>();
		var l2 = new List<char>();

		foreach (var q in qs)
			if (q == "1")
				f = !f;
			else if (q[2] == '1' ^ f)
				l1.Add(q[4]);
			else
				l2.Add(q[4]);

		l1.Reverse();
		var r = l1.Concat(s).Concat(l2);
		if (f) r = r.Reverse();
		Console.WriteLine(new string(r.ToArray()));
	}
}


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

int main()
{
  //入力
  int a,b,c,d;
  cin>> a>> b>> c>> d;

  //操作
  while(-1)
  {
    c-=b;
    if(c<=0)
    {
      cout<< "Yes" <<endl;
      break;
    }
    a-=d;
    if(a<=0)
    {
      cout<< "No" <<endl;
      break;
    }
  }
  
  return 0;
}


Measured memory_bytes: 3092
a,b,c,d = map(int,input().split())
mod = 998244353

dp = [[0] * (d+1) for i in range(c+1)]
dp[a][b] = 1

for i in range(a,c+1):
    for j in range(b,d+1):
        dp[i][j] += dp[i-1][j] * j + dp[i][j-1]*i - dp[i-1][j-1]*(i-1)*(j-1)
        dp[i][j] %=mod
print(dp[c][d])

Measured memory_bytes: 136860
#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
int n;
int ar[105];
bool cnt[9];
int fre;
int main(void){
	RI(n);
	REP(i,n){
		RI(ar[i]);
	}
	bool lw=false;
	REP(i,n){
		if(ar[i]>=3200) ++fre;
		else{
			lw = true;
			if(ar[i]<400) ++cnt[0];
			else if(ar[i]<800) ++cnt[1];
			else if(ar[i]<1200) ++cnt[2];
			else if(ar[i]<1600) ++cnt[3];
			else if(ar[i]<2000) ++cnt[4];
			else if(ar[i]<2400) ++cnt[5];
			else if(ar[i]<2800) ++cnt[6];
			else ++cnt[7];
		}
	}
	int cntt=0;
	REP(i,8) cntt+=cnt[i];
	if(lw){
		printf("%d %d\n",cntt,cntt+fre);
	} else {
		printf("%d %d\n",1,fre);
	}
}



Measured memory_bytes: 256
#include <stdio.h>



int main()
{
	int a,b;
	char op;
	int ans;
	while(1){
	scanf("%d %c %d",&a,&op,&b);//????????????????????¨&???????????????
	if(op=='?') break;
	else if(op=='+') printf("%d\n",a+b);
	else if(op=='-') printf("%d\n",a-b);
	else if(op=='*') printf("%d\n",a*b);
	else if(op=='/') printf("%d\n",a/b);
	};


	
	return 0;
}

Measured memory_bytes: 600
lines = []
colums = []
  
while True:
  H,W = map(int,input().split())
  if H == 0 and W == 0:
    break
  lines.append(H)
  colums.append(W)
  
for H,W in zip(lines,colums):
  for i in range(H):
    if i%2==0:
      for j in range(W):
        if j%2==0:
          print("#",end="")
        else:
          print(".",end="")
    else:
      for j in range(W):
        if j%2!=0:
          print("#",end="")
        else:
          print(".",end="")
        
    print("\n",end="")
  print("\n",end="")


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

typedef long long ll;
const int N = 1e5 + 100;

ll n, res, a;
bool have[N];

int f(int a) {
	return (a & 1? 0: f(a >> 1) + 1);
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	while(n--) {
		cin >> a;
		res ^= a;
		have[f(a)] = true;
	}
	int ans = 0;
	for (int i = 31; ~i; i--)
		if((res & (1 << i)) && have[i] == false) {
			cout << -1;
			return 0;
		}
		else if(res & (1 << i))
			res ^= ((1 << (i + 1)) - 1), ans++;
	cout << ans;
	return 0;
}

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

int main(){
    ll a,b,n;
    cin >> a >> b >> n;
    ll x = min(b-1, n);
    ll res = a * x / b - a * (x/b);
    cout << res << endl;
    return 0;
} 

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

int main(){
    string s;
    cin >> s;
    bool ok = false;
    for (int i = 0; i < 3; i++)
    {
        if(s[i] == '7'){
            ok = true;
        }
    }
    if(ok){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long ul;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef set<int> si;
typedef multiset<int> mi;
 
const ll INF = 1e18;
const int MOD = 1e9+7;
 
int main() {
	
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	
	//ofstream cout ("fileName.out");
	//ifstream cin ("fileName.in");
	
	int N;
	cin>>N;
	vi a(N);
	for(int i=0; i<N; ++i) cin>>a[i];
	
	sort(a.rbegin(), a.rend());
	
	priority_queue<pi> pq;
	ll ans=a[0];
	pq.push({a[1],a[0]});
	pq.push({a[1],a[0]});
	
	for(int i=2; i<N; ++i) {
		ans+=pq.top().f;
		pi temp=pq.top();
		//cout<<pq.top().f<<" "<<pq.top().s<<"\n";
		pq.pop();
		pq.push({a[i],temp.f});
		pq.push({a[i],temp.s});
	}
	
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 6072
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0; i<(long long)(n); i++)
#define REP(i, k, n) for(long long i=(long long)(k); i<(long long)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define PQ(T) priority_queue<T>
#define PQS(T) priority_queue<T, vector<T>, greater<T> >
#define deci cout << fixed << setprecision(15);
typedef long long ll;
const ll inf = 1020304050607080910;
const int INF = 2000000000;
const ll mod = 1000000007;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
ll gcd(ll x,ll y){if(x>y)swap(x, y);while(x!=0){y%=x;swap(x, y);}return y;}
ll mpow(ll x,ll r){if(r==0)return 1;if(r%2==1){return x*mpow(x,r-1)%mod;}else{ll aa=mpow(x,r/2);return aa*aa%mod;}}

int main(){
	int N, A, B; cin >> N >> A >> B;
	if(A<B) swap(A, B);
	ll dpb[N+1], dp[N+1], sum[N+1], sum2[N+1];
	rep(i, B) dpb[i] = 1;
	for(int i=B; i<=N; i++){
		dpb[i] = dpb[i-1];
		for(int j=B; j<=i; j++){
			if(j==i) dpb[i] = (dpb[i] + 1) % mod;
			else dpb[i] = (dpb[i] + dpb[i-j-1]) % mod;
		}
	}
	sum2[0] = dpb[0];
	rep(i, N) sum2[i+1] = (sum2[i] + dpb[i+1]) % mod;
	dp[0] = 0, sum[0] = 0;
	for(int i=1; i<=N; i++){
		dp[i] = 0;
		for(int j=1; j<=min(i-1, A-1); j++){
			ll s, cnt = 0;
			if(j==i-1){ dp[i] = (dp[i] + dpb[max(0, j-2)]) % mod; continue; }
			if(i-(j+B-1)<=A-1){
				if(i-j-B+1<=0){
					int l = min(A-1, i-j-1);
					cnt = (cnt + sum2[l-1]+1)%mod;
				}else{
					int l = min(i-j-1, A-1);
					cnt = (cnt + sum2[l-1] + mod - sum2[i-j-B]+dpb[i-j-B])%mod;
				}
			}
			if(i-j-B+1 < 0) s = sum[i-j-1];
			else s = (sum[i-j-1] + mod - sum[i-j-B+1] + dp[i-j-B+1]) % mod;
			cnt = (cnt + s) % mod;
			if(j==1) dp[i] = (dp[i] + cnt) % mod;
			else dp[i] = (dp[i] + dpb[j-2]*cnt) % mod;
		}
		sum[i] = (sum[i-1] + dp[i]) % mod;
	}
	ll ans = mpow(2, N);
	ll c = 0;
	for(int i=0; i<=A-1; i++){
		for(int j=1; j<=B-1; j++){
			if(i+j>N) continue;
			if(N-i-j<=A-1){
				c = (c + dpb[max(0, i-1)]*dpb[max(0, N-i-j-1)]) % mod;
			}
			c = (c + dpb[max(0, i-1)]*dp[N-i-j])%mod;
		}
	}
	cout << (ans - c + 2*mod) % mod << endl;
	return 0;
}


Measured memory_bytes: 3764
N = int(input())
AB = []
for i in range(N):
    AB.append(list(map(int,input().split())))

AB.sort(key=lambda x:x[0]+x[1],reverse=True)

T = 0
A = 0
for i in range(N):
    if i % 2 == 0:
        T += AB[i][0]
    else:
        A += AB[i][1]

print(T-A)

Measured memory_bytes: 32224
import java.util.*;

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

        long answer = n;

        for(long i = 1; i <= Math.sqrt(n); i++){
          if(n % i != 0) continue;
          long len1 = String.valueOf(i).length();
          long len2 = String.valueOf(n / i).length();
          answer = Math.min(answer, Math.max(len1, len2));
        }

        System.out.println(answer);
	}
}

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

void chk_min(long long &min, int target) {
  if (target < min) {
    min = target;
  }
}

int main() {
  int N;
  cin >> N;
  vector<int> input(N);
  for (int i=0; i<N; i++) {
    cin >> input[i];
  }
  const long long INF = 1LL << 60;
  long long dp[100010];
  for (int i=0; i<100010; ++i) dp[i] = INF;
  dp[0] = 0;

  for (int i=1; i<N; i++) {
    chk_min(dp[i], dp[i-1] + abs(input[i]-input[i-1]));
    if (i==1) {
      continue;
    } else {
      chk_min(dp[i], dp[i-2] + abs(input[i]-input[i-2]));
    }
  }
  
  cout << dp[N-1] << endl;
}

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

typedef long long LL;

const int N=(int) 1e5+5, mod=(int) 0;
int px[N], py[N], par[N];
pair <int, int> sx[N], sy[N];

int find (int x)
{
	return x == par[x] ? x : par[x] = find (par[x]);
}

int Unite (int u, int v)
{
	u = find (u);
	v = find (v);
	if (u == v)  return 0;
	par[u] = v;
	return 2;
}

int dist (int x, int y)
{
	return min (abs (px[x]-px[y]), abs (py[x]-py[y]));
}

int main()
{
	int n;
	cin >> n;
	for (int j=0; j<n; j++){
		cin >> px[j] >> py[j];
		par[j] = j;
		sx[j] = make_pair (px[j], j);
		sy[j] = make_pair (py[j], j);
	}
	
	sort (sx, sx+n);
	sort (sy, sy+n);
	set <pair <int, pair <int, int> > > st;
	
	for (int j=0; j<n-1; j++){
		st.insert (make_pair (dist(sx[j].second, sx[j+1].second), make_pair (sx[j].second, sx[j+1].second)));
		st.insert (make_pair (dist(sy[j].second, sy[j+1].second), make_pair (sy[j].second, sy[j+1].second)));
	}
	
	LL res=0;
	while ((int) st.size()){
//		set <pair <int, pair <int, int> > > :: iterator cur = *(st.begin());
		pair <int, pair <int, int> > cur=*(st.begin());
		st.erase (cur);
		int u=cur.second.first, v=cur.second.second;
		res += (LL) Unite (u, v) * dist (u, v);
	}
	
	cout << res/2 << endl;
}

Measured memory_bytes: 15488
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}
signed main() {
    double a, b, x;
    cin >> a >> b >> x;
    if (2 * x > a * a * b) {
        x = a * a * b - x;
        x /= a;
        cout << setprecision(10) << 180 / M_PI * atan2(2 * x / a, a) << endl;
    } else {
        x /= a;
        cout << setprecision(10) << 180 / M_PI * atan2(b, 2 * x / b) << endl;
    }
}


Measured memory_bytes: 4152
#include <bits/stdc++.h>
  using namespace std;
 
  #define vi vector<int>
  #define all(v) v.begin(),v.end()
  #define ll long long int
  #define  IOS    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define D1(x) {cerr<<" [" <<#x<<": "<<x<<"]";cout << endl;}
  #define D2(x) {cerr<<" [" <<#x<<": ";for(auto it:x)cerr<<it<< " ";cerr<<"] ";cout << endl;}
 
  const ll MOD=1e9+7;
  int n,m,q;
  vector<vector<int>> v(55,vector<int> (4));
  vector<int> path;
  ll ans=0LL;
  void check(){
    ll val=0;
      for(int i=0;i<q;i++){
         if((path[v[i][1]]-path[v[i][0]])==v[i][2]){
           val+=v[i][3];
         }
      }
      ans = max(ans,val);
  }
  void dfs(int i,int cur){
     if(i>=n){
        check();
        return;
     }
       for(int j=cur;j<=m;j++){
          path.push_back(j);
          dfs(i+1,j);
          path.pop_back();
       }
  }
 
  void solve(){
     cin >> n >> m >> q;
     for(int i=0;i<q;i++){
        cin >> v[i][0] >> v[i][1]>> v[i][2]>> v[i][3];
        v[i][0]--,v[i][1]--;
     }
     
     dfs(0,1);
     cout << ans;
  }
 
 
  int main(){
    IOS
       solve();
       cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }

Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N, i;
  int t = 1;

  cin >> N;
  vector<int> c(N);
  for(i=0;i<N;i++) cin >> c.at(i);

  sort(c.begin(), c.end());

  for(i = 0; i < N-1; i++){
    if(c.at(i) != c.at(i+1)) t++;
  }
  cout << t << endl;
}

Measured memory_bytes: 256
def power(x, n, mod):
    ans = 1
    while n > 0:
        if n % 2 == 1:
            ans = ans * x % mod
        n //= 2
        x = x * x % mod
    return ans

n = int(input())
mod = 10 ** 9 + 7
print((power(10, n, mod) - 2 * power(9, n, mod) + power(8, n, mod)) % mod)

Measured memory_bytes: 61600