akhauriyash/Code-Regression huggingface dataset:
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Enu = System.Linq.Enumerable;

public class Program
{
    public void Solve()
    {
        int X = Reader.Int(), Y = Reader.Int();
        long ans = long.MaxValue;

        for (int before = 0; before < 2; before++)
            for (int after = 0; after < 2; after++)
            {
                long a = X;
                long count = 0;
                if (before == 1) { count++; a = -a; }
                if (after == 0) count = (a <= Y) ? count + Y - a : long.MaxValue;
                else { count = (a <= -Y) ? 1 + count + -Y - a : long.MaxValue; }
                ans = Math.Min(ans, count);
            }

        Console.WriteLine(ans);
    }
}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string[] Split(string s) { return s.Split(separator, op); }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}

Measured memory_bytes: 2776
K, N = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
max = (K - a[N-1] + a[0]).abs
(0..(N-2)).each do |i|
  tmp = (a[i] - a[i+1]).abs
  if tmp > max
    max = tmp
  end
end
puts K - max

Measured memory_bytes: 15364
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,p;
map <ll,ll> mp;
vector <ll> at;
int main(){
	cin>>n>>p;
	ll pp=p;
	for (ll i=2;i*i<=p;i++){
		if (p%i!=0) continue;
		while (pp%i==0){
			mp[i]++;
			pp/=i;
			if (mp[i]==1)
				at.push_back(i); 
		}
	}
	for (ll j=2;j*j<p;j++){
		if (p%j!=0) continue;
		ll i=p/j;
		while (pp%i==0){
			mp[i]++;
			pp/=i;
			if (mp[i]==1)
				at.push_back(i); 
		}
	}
	ll ans=1;
	for (ll i=0;i<at.size();i++){
		for (ll j=0;j<mp[at[i]]/n;j++)
			ans*=at[i];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
a=input()
num=len(a)
mod_map={0:1}
moji_int=0
Sn=[0]*(num+1)
tens=[1]*(num+1)
for i in range(-1,-num-1,-1):
    tens[-i]=tens[-i-1]*10%2019
    tmp=int(a[i])*(tens[-i-1])
    Sn[-i]=(Sn[-i-1]+tmp)%2019
    mod=Sn[-i]
    if mod not in mod_map:
        mod_map[mod]=1
    else:
        mod_map[mod]+=1

res=0
for i in mod_map.values():
    res+=int(i*(i-1)/2)
print(res)


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

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

    int l = 0, r = 0;
    for(int i=0;i<n;++i) {
        if(s[i]=='('){
            ++r;
        } else {
            if(r == 0) ++l;
            else --r;
        }
    }

    for(int i=0;i<l;++i) cout << '(';
    cout << s;
    for(int i=0;i<r;++i) cout << ')';
    cout << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int n;
int a[3030];
ll mem[3030][3030];

ll dp(int l, int r) {
    if(~mem[l][r]) return mem[l][r];
    if(l == r) return mem[l][r] = a[l];
    return mem[l][r] = max(a[l] - dp(l+1, r), a[r] - dp(l, r-1));
}

signed main() {

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

    memset(mem, -1, sizeof(mem));

    cout << dp(0, n-1) << endl;
    
    return 0;
}



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

//g数组
vector<int>G;
long long cnt;
int A[1000000 + 10];

// 间隔为g的插入排序
void insertionSort(int A[], int n, int g) {
    for (int i = g; i < n; i++) {
        int v = A[i];
        int j = i - g;
        while (j >= 0 && A[j] > v) {
            A[j + g] = A[j];
            j -= g;
            cnt++;
        }
        A[j + g] = v;
    }
}
//希尔排序
void shellsort(int A[], int n) {
    for (int i = G.size() - 1; i >= 0; i--) {
        insertionSort(A, n, G[i]);
    }
}

// 生成g数组
void getArray(int n) {
    for (int h = 1; h <= n;) {
        G.push_back(h);
        h = 3 * h + 1;
    }
}


int main() {

    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &A[i]);
    getArray(n);
    shellsort(A,n);

    int len = G.size();
    printf("%d\n", len);
    for (int i = len - 1; i >= 0; i--)
        printf("%d%c", G[i], i == 0 ? '\n' : ' ');
    printf("%lld\n", cnt);
    for (int i = 0; i < n; i++)
        printf("%d\n", A[i]);
    return 0;
}



Measured memory_bytes: 7092
import itertools,sys
def I(): return int(sys.stdin.readline().rstrip())
N = I()
if N<=5:
    print(N)
    exit()
dp = [float('INF')]*(N+1)
dp[0] = 0
num6,num9 = 6,9
d6d9 = set()
while num6<=N:
    d6d9.add(num6)
    num6 *= 6
while num9<=N:
    d6d9.add(num9)
    num9 *= 9
for i,x in itertools.product(range(N+1),d6d9):
    if i+x>=N+1:
        continue
    dp[i+1] = min(dp[i+1],dp[i]+1)
    dp[i+x] = min(dp[i+x],dp[i]+1)
print(dp[-1])


Measured memory_bytes: 50128
#include <iostream>
 using namespace std;
 int main()
 {
     int n,m;
     cin>>n>>m;
     if(n==1)
     {
         n=14;
     }
     if(m==1)
     {
         m=14;
     }
     if(n==m)
       {
         cout<<"Draw";
     }
     else if(n<m)
     {
         cout<<"Bob";
     }
     else
     {
         cout<<"Alice";
     }
     return 0;
 }

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define LL long long

 
 int main(){
 	int N, K, X, Y;
 	cin >> N >> K >> X >> Y;
 	if(N >= K){
	 	cout << K*X + (N-K)*Y << endl;
	 }
	 else {
	 	cout << N*X << endl;
	 }
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
ll p;
int main(){
  ll n;
  cin>>n;
  vll a(n);
  ll k=0;
  rep(i,n){
    cin>>a[i];
    if(a[i]%2==1) k++;
  }
  if(k) COUT("first");
  else COUT("second");
}


Measured memory_bytes: 1024
#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 N;
    cin >> N;
    vector<int> X(N);
    vector<int> Y(N);
    rep(i,N) cin >> X[i], Y[i] = X[i];
    sort(all(Y));
    rep(i,N){
        if(X[i] <= Y[N/2-1]) cout << Y[N/2+1-1] << endl;
        else cout << Y[N/2-1] << endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 3712
#include <stdio.h>
int main() {
	int a, ans = 0, rMax = 0, wait = 0;
	for (int i = 0; i < 5; i++)	{
		scanf("%d", &a);
		if (a % 10 == 0) {
			wait = 0;
		}
		else {
			wait = 10 - (a % 10);
		}
		ans += a + wait;
		if (rMax < wait) {
			rMax = wait;
		}
	}
	printf("%d\n", ans - rMax);
	return 0;
}

Measured memory_bytes: 128
H, W = map(int, input().split())
A = []
for _ in range(H):
    A.append(list(input()))

row = [False] * H
col = [False] * W

for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            row[i] = True
            col[j] = True

for i in range(H):
    if row[i]:
        for j in range(W):
            if col[j]:
                print(A[i][j], end="")
        print()

Measured memory_bytes: 74968
#include <bits/stdc++.h>
using namespace std;
int dp[101][101];
int solve(int x, int y) {
  if (x < 0 || y < 0) return 0;
  if (!x && !y) return 1;
  if (dp[x][y] != -1) return dp[x][y];
  int s = max(solve(x - 1, y - 4), solve(x - 1, y - 2));
  dp[x][y] = s;
  return s;
}
int main() {
  for (int i = 0; i < 101; i++) 
    for (int j = 0; j < 101; j++) 
      dp[i][j] = -1;
  int x, y; cin >> x >> y;
  int s = solve(x, y);
  cout << (s ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 3660
#include<stdio.h>
int main()
{
    int A,B,C;
    scanf("%d %d %d",&A,&B,&C);
    B=B/A;
    if(B>=C){
        printf("%d",C);
    }
    else if(B<C){
        printf("%d",B);
    }
    else{
        printf("%d",B);
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#ifdef BIZON
	#define rr(x) cerr << "\e[1;38;5;172m" << #x << "\e[0m = " << (x) << endl;
#else
	#define rr(x)
	#define endl '\n'
#endif
#define ALL(c) begin(c), end(c)
using namespace std;
using ll = long long;
using ld = long double;



ll inv_mod(ll a, ll m){
	assert(0<a);
	assert(a<m);
	return a==1 ? 1 : m-m*__int128_t(inv_mod(m%a, a))/a;
}


ll gg(ll a, ll b){
	if(b == 1) return a+1; //for(ll x=1;;++x) if(b*x>1 && (b*x-1) %a==0) return x;
	//bx - 1 = ay
	//bx = 1 (mod a)
	
	if(a == 1) return 1;
	ll x = inv_mod(b%a, a);
	return x;
}

ll solve(ll n){
	n*=2;
	ll ans = n-1;
	for(ll d=1; d*d<=n; ++d) if(n%d==0){
		ll d2 = n/d;
		if(gcd(d,d2) == 1){
			ll x1 = gg(d,d2);
			ll x2 = gg(d2,d);
			
			ans = min(ans, d2 * x1 - 1);
			ans = min(ans, d * x2 - 1);
		}
	}
	
	return ans;
}


int main(){
	//if(auto f="in.txt"; fopen(f,"r") && freopen(f,"r",stdin));
	ios::sync_with_stdio(0);cin.tie(0);//cout.precision(9);cout<<fixed;
	
	ll n;
	cin>>n;
	cout<<solve(n)<<endl;
	
	/*
	for(int n=1;n<=1e5;++n){
		for(int k=1;;++k){
			if((k+1LL)*k % (2*n) == 0){
				cout<<n<<": "<<k<<' '<<solve(n)<<endl;
				assert(k == solve(n));
				break;
			}
		}
	}*/
	
	
	return 0;
}


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

int main() {
    int r, g, b;
    cin >> r >> g >> b;

    if( (10*g + b) % 4 == 0) {
        cout << "YES";
    }
    else {
        cout << "NO";
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;
struct UF
{
    vi r, p, sz;
    UF(int n) : r(n, 0), p(n, 0), sz(n, 1)
    {
        iota(p.begin(), p.end(), 0);
    }

    int f(int x)
    {
        return (p[x] == x ? x : p[x] = f(p[x]));
    }

    void u(int i, int j)
    {
        int x = f(i), y = f(j);
        if (x == y)
            return;

        if (r[x] >= r[y])
        {
            p[y] = x;
            sz[x] += sz[y];
            if (r[x] == r[y])
                r[x]++;
        }
        else
        {
            p[x] = y;
            sz[y] += sz[x];
        }
    }

    bool s(int i, int j)
    {
        return f(i) == f(j);
    }
};

int main()
{
    int n;
    cin >> n;
    vector<tuple<int, int, int>> points;
    for (int i = 0; i < n; ++i)
    {
        int x, y;
        cin >> x >> y;
        points.emplace_back(x, y, i);
    }
    vector<int> sol(n);
    sort(all(points));
    set<pair<int, int>> ys;
    UF uf(n);
    for (auto [x, y, i] : points)
    {
        if (ys.empty() || ys.begin()->first > y)
            ys.emplace(y, i);
        else
        {
            uf.u(i, ys.begin()->second);
            for (auto it = next(ys.begin()); it != ys.upper_bound({y, 0}); it = ys.erase(it))
                uf.u(i, it->second);
        }
    }
    for (int i = 0; i < n; ++i)
        cout << uf.sz[uf.f(i)] << '\n';
}


Measured memory_bytes: 12512
#include <iostream>
#include <algorithm>

using namespace std;

const int UP = 1;
const int DOWN = -1;


int main() {
	int n;

	cin >> n;
	long long a[n];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	//sort(a,a+n);
	long long ans = 1;
	long long mae = a[0];
	int direction = 0;
	int count = 0;

	for(int i = 1; i < n; i++){
		long long ato = a[i];

		if(mae < ato){//上向き
			count++;
			if(direction == UP){

			}else if(direction == DOWN){
				if(count > 1){
					ans++;
					count = 0;
				}
			}
			direction = UP;
		}else if(mae > ato){//下向き
			count++;
			if(direction == UP){
				if(count > 1){
					ans++;
					count = 0;
				}
			}else if(direction == DOWN){

			}

			direction = DOWN;
		}else{//水平

		}
		//cout << direction << ",";
		mae = ato;
	}
	//cout << endl;
	cout << ans << endl;
	return 0;
}
/*


*/


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
struct Edge {
    int to;
};
using Graph = vector<vector<Edge>>;
int N, M, K;
int id;
// 深さ優先探索
vector<int> cc_id;   // どの連結成分か
vector<int> cc_num;  // 連結成分のサイズ
void dfs(const Graph &G, int v, int &cnt) {
    cc_id[v] = id;
    cnt++;
    for (auto e : G[v]) {
        if (cc_id[e.to] == -1) {
            dfs(G, e.to, cnt);
        }
    }
}
int main() {
    cin >> N >> M >> K;
    Graph G(N);  // グラフとして考える
    vector<int> A(M), B(M);
    REP(i, M) {
        cin >> A.at(i) >> B.at(i);
        A[i]--, B[i]--;
        G[A[i]].push_back({B[i]});
        G[B[i]].push_back({A[i]});
    }
    vector<int> C(K), D(K);
    REP(i, K) {
        cin >> C.at(i) >> D.at(i);
        C[i]--, D[i]--;
    }
    // どの連結成分に属し、サイズがいくつなのかを求める
    cc_id.assign(N, -1);  // 初期化
    id = 0;
    REP(i, N) {
        if (cc_id[i] == -1) {
            int cnt = 0;
            dfs(G, i, cnt);
            cc_num.push_back(cnt);
            id++;
        }
    }
    vector<int> ans(N);
    REP(i, N) { ans[i] = cc_num[cc_id[i]] - 1 - (int)G[i].size(); }
    REP(i, K) {  // 同じ連結成分にあるブロック関係を引く
        if (cc_id[C[i]] == cc_id[D[i]]) {
            ans[C[i]]--;
            ans[D[i]]--;
        }
    }
    REP(i, (int)ans.size()) {
        cout << ans[i];
        if (i != (int)ans.size() - 1) cout << " ";
    }
    cout << endl;
    return 0;
}

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

int main() {
  int N, cnt=0;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A.at(i);
  rep(i, N) if(A.at(A.at(i)-1)==i+1) cnt++;
  cout << cnt/2 << endl;
}

Measured memory_bytes: 640
n, m, q = map(int, input().split())
l = [list(map(int, input().split())) for i in range(q)]

import itertools

seq_list = itertools.combinations_with_replacement(range(1, m + 1), n)
max_score = 0

for seq in seq_list:
    temp_max = 0
    for j in l:
        if seq[j[1] - 1] - seq[j[0] - 1] == j[2]:
            temp_max += j[3]
    max_score = max(max_score, temp_max)

print(max_score)

                




Measured memory_bytes: 9128
import java.util.*;

public class Main {
	final static int MOD = 1000000007;
	
	public static void main(String[] args) {
		MyScanner in = new MyScanner();
		int n = in.nextInt();
		System.out.println(n*n*n);
		
		
	}
	
	static class MyScanner {
		static Scanner sc = new Scanner(System.in);
		
		String next() {
			return sc.next();
		}
		
		String nextLine() {
			return sc.nextLine();
		}
		
		int nextInt() {
			return Integer.parseInt(sc.next());
		}
		
		double nextDouble() {
			return Double.parseDouble(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextInt();
			}
			return array;
		}
		
		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextDouble();
			}
			return array;
		}
		
		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}
			return array;
		}
		
		String[] nextLineArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLine();
			}
			return array;
		}
		
		int[][] nextIntMatrix(int n, int m) {
			int[][] matrix = new int[n][m];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					matrix[i][j] = nextInt();
				}
			}
			return matrix;
		}
		
		double[][] nextDoubleMatrix(int n, int m) {
			double[][] matrix = new double[n][m];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					matrix[i][j] = nextDouble();
				}
			}
			return matrix;
		}
		
		long[][] nextLongMatrix(int n, int m) {
			long[][] matrix = new long[n][m];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					matrix[i][j] = nextLong();
				}
			}
			return matrix;
		}
	}
}

Measured memory_bytes: 21332
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/abc179/tasks/abc179_e

//ポイント：
//制約が10^10となっているときに使えそうなアルゴリズム
//二部探索
//ダブリング
//ループ構造
 
//今回はmodのループする性質を用いる

//ループする場合
//スタート地点からある距離まで進んだ地点がループ開始地点
//スタート地点がループ開始地点
//の場合がある

//また、ループの時はグラフに起こしてみると分かりやすくなる場合がある
 
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,X,M;

LL ans = 0;

void solve(){
    //i回の操作までの累積和をaccum[i]とおく
    vector<LL> accum(M+1,0);
    //ループ一回あたりの操作回数
    LL operation_per_loop = 0;
    //ループ一回あたりの和
    LL sum_per_loop = 0;
    //ループ開始地点
    LL loop_start_Ai = 0;
    //最初の状態から操作を何回繰り返すとAiになるかをdist[Ai]とする
    vector<LL> dist(M,-1); dist[X] = 0;
    LL operation = 0;
    LL now = X;
    while(1){
        operation++;
        accum[operation] = accum[operation-1] + now;
        LL next = (now*now)%M;
        if(dist[next]!=-1){
            loop_start_Ai = next;
            operation_per_loop = operation - dist[next];
            sum_per_loop = accum[operation] - accum[dist[next]];
            accum[operation+1] = accum[operation] + next;
            break;
        }
        dist[next] = operation;
        now = next;
    }

   //cout << loop_start_Ai << "," << operation_per_loop << "," << sum_per_loop << endl;

    if(N<=operation) ans = accum[N];
    else{
        LL former_operation = dist[loop_start_Ai];
        LL numof_loop = (N-former_operation)/operation_per_loop;
        LL later_operation = (N-former_operation)%operation_per_loop;
        //cout << later_operation << endl;
        //                                                           ↓この項注意 later_operationはあくまでループから抜ける時の回数なので、ループに入るまでの操作回数を足さなければならない
        ans = accum[former_operation]  + numof_loop*sum_per_loop + (accum[former_operation+later_operation]-accum[former_operation]);
    }
}
 
int main(){
	cin >> N >> X >> M;
 
    solve();

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

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

int main() {
  int N, K, A;
  cin >> N >> K;
  A = 1;
  for(int i = 0; i < N; i++){
    if( A * 2 >= A + K){
    A += K; }
    else{ A = A*2 ;}
  }
   cout << A << endl;
}
 

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc167/tasks/abc167_a

#include <bits/stdc++.h>
using namespace std;
#define watch(x) cerr << (#x) << " is " << (x) << endl;
#define endl '\n'
#define int long long
#define all(x) (x).begin(), (x).end()

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

    string s, t;
    cin >> s >> t;

    string ans = "Yes";
    for(int i = 0; i < s.size(); i++) {
        if(s[i] != t[i]) {
            ans = "No";
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3656
from itertools import product
n = int(input())
if n <= 356:
	print(0)
else:
	ans = 0
	shi_list = ["3", "5", "7"]
	shi_set = {"3", "5", "7"}
	for i in range(3, len(str(n))+1):
		for num in product(shi_list, repeat=i):
			x = int("".join(num))
			if x <= n and set(list(str(x))) & shi_set == shi_set:
				ans += 1
	print(ans)


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


//TEMPLATE
#define pb                push_back
#define mp                make_pair
#define ll                long long
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second

#define newline           printf("\n")
#define minusone          printf("-1\n")
#define zeroo             printf("0\n")
#define scl1(a)           scanf("%lld", &a)
#define scl2(a, b)        scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)     scanf("%lld %lld %lld", &a, &b, &c)
#define prl1(a)           printf("%lld\n", a)
#define prl2(a, b)        printf("%lld %lld\n", a, b)
#define ssl1(s)           scanf(" %[^\n]", s)
#define scd1(a)           scanf("%lf", &a)
#define scd2(a, b)        scanf("%lf %lf", &a, &b)
#define prd(a)            printf("%lf\n", a)
#define prld(a)           printf("%Lf\n", a)
#define prcase(cs)        printf("Case %lld: ", cs)
#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotline           cout << "\n"
#define cotminus          cout << "-1\n"
#define cot0              cout << "0\n"
#define cotyes            cout << "YES\n"
#define cotno             cout << "NO\n"
#define cotcase(cs)       cout << "Case " << cs << ": "

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       (s.find(x) != s.end())

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)
#define fori(it, s)       for(auto it = s.begin(); it != s.end(); it++)

#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)

//#define pi              3.1415926536
#define pi                acos(-1)

const ll INF = LLONG_MAX;
const ll SZ = 4e5+5;
const ll mod = 1e9+7;


ll n;
//ll a[SZ];
//ll b[SZ];
vector <pii> adj[SZ];
ll dis[SZ];

void dfs(ll u, ll p, ll d) {
    dis[u] = dis[p] + d;

    for(auto e: adj[u]) {
        if(e.F == p) continue;

        dfs(e.F, u, e.S);
    }
}

int main() {
    ll cs = 0, tc = 1, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0, t = 0;
//    ll a, b, d;
    string s, s1, s2;

    cin1(n);
    for1(i, n-1) {
        cin3(x, y, z);
        adj[x].pb({y, z});
        adj[y].pb({x, z});
    }

    dfs(1, 0, 0);

    for1(i, n) cot1(dis[i]%2);

    return 0;
}



Measured memory_bytes: 20204
//ABC120C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
using namespace std;

int main(){
	string s;
	cin >> s;
	int num = s.size();
	int red = 0, black = 0;
	for(int i=0;i<num;i++){
		if(s.at(i) == '0'){
			red++;
		}else{
			black++;
		}
	}
	int count = min(red,black);
	cout << 2 * count << endl;
}

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

int main() {
 int N ;
  cin >> N ;
  bool a = false;
  rep(i, N) {
  string Si;
  cin >> Si;
  if(Si == "Y"){
   a = true;
  break;
  }
  }
if(a){
cout << "Four" << endl;
}
else{
cout  <<"Three" << endl;
}
}

Measured memory_bytes: 256
# coding:utf-8

import sys
from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    s = SI()

    C = Counter(s)
    res = 1
    for c in C.values():
        res *= c + 1
        res %= MOD

    return res - 1 if res else MOD - 1


print(main())


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

const int maxn = 100+10;

int f[maxn][maxn];
char s[maxn][maxn];

int main() {
    int h, w;
    scanf("%d%d", &h, &w);
    for(int i=1; i<=h; i++)
        scanf("%s", s[i]+1);
    memset(f, 0x3f, sizeof(f));
    f[1][1] = (s[1][1]=='#');
    for(int i=1; i<=h; i++) {
        for(int j=1; j<=w; j++) {
            if(i>1)
                f[i][j] = min(f[i][j], f[i-1][j]+(s[i][j]=='#' && s[i-1][j]=='.'));
            if(j>1)
                f[i][j] = min(f[i][j], f[i][j-1]+(s[i][j]=='#' && s[i][j-1]=='.'));
        }
    }
    printf("%d\n", f[h][w]);
    return 0;
}


Measured memory_bytes: 256
S = input()
A = [0 for i in range(2019)]
x = 0
q = 1
for i in range(len(S)):
    p = i + 1
    a = (int(S[-p]))
    b = a*q%2019
    x = (x+b) % 2019
    A[x] += 1
    q = q*10%2019
ans = A[0]
for i in range(2019):
    ans += A[i]*(A[i]-1)//2
print(ans)

Measured memory_bytes: 9284
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10, M = 2*N;
std::vector<int> to[N];
int n, q;
long long av[N], ans[N];
void dfs(int u, int fa) {
  ans[u] = av[u] + ans[fa];
  for (auto v: to[u]) if (v != fa) {
    dfs(v, u);
  }
}
int main() {
  cin >> n >> q;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    to[u].push_back(v);
    to[v].push_back(u);
  }
  for (int i = 1; i <= q; i++) {
    int pos, value;
    cin >> pos >> value;
    av[pos] += value;
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) 
    cout << ans[i] << " ";
}

Measured memory_bytes: 25600
import java.util.ArrayList;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();

		int B = sc.nextInt();

		int K = sc.nextInt();

		ArrayList<Integer> array = new ArrayList<>();

		for(int i=0;i<K;i++) {

			if(A+i<=B) array.add(A+i);
		}

		for(int i=K-1;i>=0;i--) {

			if(!array.contains(B-i) && B-i>=A) array.add(B-i);
		}

		for(int i=0;i<array.size();i++) {

			System.out.println(array.get(i));
		}
	}

}


Measured memory_bytes: 22604
s=list(input())
#print(s)
if 1<=int(s[0])*10+int(s[1])<=12 and 1<=int(s[2])*10+int(s[3])<=12:
    print('AMBIGUOUS')
elif 1<=int(s[0])*10+int(s[1])<=12:
    print('MMYY')
elif 1<=int(s[2])*10+int(s[3])<=12:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3064
n = gets.to_i

primes = []
2.upto(Math.sqrt(n)) do |p|
    next if n%p != 0
    count = 0
    while n%p == 0
        n /= p
        count += 1
    end

    primes << [p,count]
end
primes << [n,1] if n!=1

ans = 0
primes.each do |p,count|
    num = 1
    while count>=num
        count -= num
        ans += 1
        num += 1
    end
end

p ans


Measured memory_bytes: 14324
#include <iostream>
#include <string>
#include <set>
#include <vector>
using namespace std;

int main(){
    int N;
    int n4, n7;

    cin >> N;

    for(n4 = 0; 4 * n4 <= N; ++n4){
        for(n7 = 0; 4*n4 + 7*n7 <=N; ++ n7){
            if( (4*n4 + 7*n7) == N ){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		int x,y,b,p;
		cin>>x>>y>>b>>p;
		int mid=x*b+y*p;
		int over=(x*5+y*2+x*max(b-5,0)+y*max(p-2,0))*8/10;
		if(b>=5 && p>=2){
			cout<<mid*8/10<<endl;
		}else if(over<mid){
			cout<<over<<endl;
		}else{
			cout<<mid<<endl;
		}

	}
	return 0;

}

Measured memory_bytes: 1160
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  
  val hw = inputs.head.split(" ").map(_.toInt)
  val h = hw(0)
  val w = hw(1)
  val image = inputs.tail

  println(solve(h, w, image))

  private def solve(h: Int, w: Int, image: Seq[String]): String = {
    val longImage = scala.collection.mutable.ArrayBuffer.empty[String]

    (0 until h).foreach { i =>
      longImage.append(image(i))
      longImage.append(image(i))
    }
    longImage.toSeq.mkString("\n")
  }
}

Measured memory_bytes: 26408
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
//#define int long long

int n;
vector<int> places[200200];
ll dp[200200];

void add(ll &a, ll b) {a += b; if(a >= mod) a -= mod;}

void solve() {
    cin >> n;
    vector<int> c(n);
    rep(i, n) {
        cin >> c[i];
        places[c[i]].push_back(i);
    }
    dp[0] = 1LL;
    for(int i = 1; i <= n; i++) {
        add(dp[i], dp[i - 1]);

        int color = c[i - 1];
        int it = lower_bound(all(places[color]), i - 1) - places[color].begin();
        if(it > 0) {
            int j = places[color][it - 1];
            if((i - 1) - j > 1) add(dp[i], dp[j + 1]);
        }
    }
    cout << dp[n] << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 13568
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000009
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	nums := nextInt()
	trueTotal := 0
	min := 1000000
	var cur int
	for i := 0; i < nums; i++ {
		cur = nextInt()
		if min >= cur {
			trueTotal++
			min = cur
		}
	}
	fmt.Println(trueTotal)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

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

func readInt64() int64 {
	sc.Scan()
	r, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return r
}

func readFloat64() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

func stringToint(s []string) []int {
	f := make([]int, len(s))
	for n := range s {
		f[n], _ = strconv.Atoi(s[n])
	}
	return f
}


Measured memory_bytes: 34432
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
int a[3];
int main() {
	string s;
	cin >> s;
	for (auto p : s) a[p - 'a']++;
	sort(a, a + 3);
	if (a[2] - a[0] <= 1)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}

Measured memory_bytes: 512
#define MOD_TYPE 2

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using multiInt = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
*/

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
#pragma endregion

inline ll gcd(ll a, ll b)
{
  if (a < b)
    swap(a, b);
  return b == 0 ? a : gcd(b, a % b);
}

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

ll f(ll x, ll c, ll d)
{
  return (x + 1) - (x / c + 1) - (x / d + 1) + (x / lcm(c, d) + 1);
}

int main()
{
  init_main();

  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << f(b, c, d) - f(a - 1, c, d) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
  int N,M;
  cin >> N >> M;
  vector<int>R(N);
  for(int i=0; i < M; i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    R[a]++;
    R[b]++;
  }
  for(int i=0; i < N; i++)
    cout << R[i] << endl;
  return 0;
}


Measured memory_bytes: 256
N,M,X=map(int,input().split())
C=[]
A=[]
for _ in range(N):
    c,*a=map(int,input().split())
    C.append(c)
    A.append(a)
    
import itertools

ans=float('inf')
f=False
for i in range(1,N+1):
    for j in itertools.combinations(range(N), i):
        t=[0]*M
        c=0
        
        for k in j:
            c+=C[k]
            t=[t+a for (t,a) in zip(t,A[k])]
        #print(c,t)
        if M <= len([x for x in t if x>=X]):
            ans=min(ans,c)
            f=True
print(ans if f else -1)

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

int main() {
  string s;
  cin >> s;
  int r = 0,b = 0;
  rep(i,s.size()){
    if(s[i] == '0') r++;
    else b++;
  }
  cout << min(r,b)*2 << endl;
}

Measured memory_bytes: 512
S=input()

n=len(S)
for i in range(n):
  if S[i]!=S[-(i+1)]:
    print('No')
    exit()
    
s1,s2=S[:(n-1)//2],S[(n+3)//2-1:]
lim=(n-1)//2
for i in range(lim):
  if s1[i]!=s1[-(i+1)] or s2[i]!=s2[-(i+1)]:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int n,m,x[110],y[110];
int main(){
    cin>>n>>m>>x[0]>>y[0];
    for(int i=1;i<=n;i++)cin>>x[i];
    for(int i=1;i<=m;i++)cin>>y[i];
    sort(x+1,x+n+1);
    sort(y+1,y+m+1);
    for(int z = -100;z <= 100;z++)
        if(x[0] < z && y[0] >= z && x[n] < z && y[1] >= z)return cout<<"No War"<<endl, 0;
    cout<<"War"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(ll)(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n;
  	ci(n);
  st s;
  	ci(s)
  ll ans=0;
  FOR(i,1,n-1){
      st a=s.substr(0,i);
      st b=s.substr(i,n-i);
      vpll A(26);
      FOR(j,0,a.sz){
        ch c=a[j];
        A[c-'a'].fi++;
      }
      FOR(j,0,b.sz){
        ch c=b[j];
        A[c-'a'].se++;
      }
      ll count=0;
      FOR(j,0,26){
        if(A[j].fi!=0&&A[j].se!=0) count++;
      }
    ans=M(ans,count);
  }
  co(ans)
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

ll highpow(ll N){
    ll pow = 1;
    while(pow <= N){
        pow *= 2;
    }
    return pow/2;
}

ll solve(ll A, ll B){
    if(A==B) return 1;

    ll Apow = highpow(A);
    ll Bpow = highpow(B);

    

    if(Bpow > Apow){
        ll ans = Bpow - A;
        ll Bsub = 2*highpow(B - Bpow);
        if(Bsub == 0){
            Bsub = 1;
        }
        if(A>=Bsub){
            ans += Bsub + (Bpow - A);
        }else{
            ans += Bpow;
        }
        return ans;
    }else{
        return solve(A - Apow, B - Bpow);
    }
}

int main(){
    ll A, B;
    cin >> A >> B;
    
    cout << solve(A, B) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		final Scanner in = new Scanner(System.in);
		final int n = in.nextInt(), m = in.nextInt();

		if (n == 1) {
			System.out.println(in.nextInt());
			return;
		} else {
			// boolean result = true;

			List<Integer> array = new ArrayList<>();

			int k = in.nextInt();
			for (int j = 0; j < k; j++) {
				array.add(in.nextInt());
			}

			// array.forEach(System.out::println);

			boolean smallResult = false;
			List<Integer> smallResultList = new ArrayList<>();

			for (int i = 0; i < n - 1; i++) {
				smallResultList.clear();

				k = in.nextInt();
				for (int j = 0; j < k; j++) {
					int a = in.nextInt();

					if (array.contains(a)) {
						smallResult = true;
						smallResultList.add(a);
					}
				}

				// System.out.println("");
				// smallResultList.forEach(System.out::print);

				if (!smallResult) {
					System.out.println(0);
					return;
				}
				array.removeIf(number -> !smallResultList.contains(number));
			}

			if (smallResult) System.out.println(array.size());
		}
	}

}

Measured memory_bytes: 28808
import sys
input = sys.stdin.readline
N, M = [int(x) for x in input().strip().split()]
score = [-float('inf')] * N
score[0] = 0
passed = [False] * N
edges = [0] * M
for m in range(M):
    edges[m] = tuple([int(x) for x in input().strip().split()])

for n in range(N):
    updated = False
    for (i, j, c) in edges:
        # print('i={}, j={}'.format(i, j), end='')
        if score[j-1] < score[i-1] + c:
            score[j-1] = score[i-1] + c
            if j == N-1:
                updated = True
        # print(score)
    if not updated:
        break

if updated:
    print('inf')
else:
    print(score[N-1])

Measured memory_bytes: 3316
import java.io.*;
import java.util.*;
 
public class Main {
 
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Integer count = 0;
        Scanner s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String word = s.next().toLowerCase();
        while(s.hasNext()){
            String input = s.next();
            if(input.equals("END_OF_TEXT")){
                break;
            }
            if(word.equals(input.toLowerCase())){
                count++;
            }
        }
        s.close();
        System.out.println(count);
    }
}

Measured memory_bytes: 18276
#include <stdio.h>
#include <algorithm>

int main() {
    int x[3];
    scanf("%d %d %d", &x[0], &x[1], &x[2]);
    for(int i=2; i>0; i--) {
        for(int j=0; j<i; j++){
            if(x[j] > x[j+1]) std::swap(x[j], x[j+1]);
        }
    }
    printf("%d %d %d\n", x[0], x[1], x[2]);
}


Measured memory_bytes: 2688
import itertools
from collections import Counter
import bisect

def main():
    s = list(input())
    s = list(set(s))
    s.sort()
    cur = ord('a')
    # print(s)
    for c in s:
        if cur == ord(c):
            cur = cur + 1
        else:
            print(chr(cur))
            exit()
    if cur == ord('z') + 1:
        print('None')
    else:
        print(chr(cur))

if __name__ == '__main__':
    main()


Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

struct enem
{
	ll x,h;
};

bool cmp(enem a,enem b)
{
	return a.x<b.x;
}
struct dp
{
	ll del,num;
};


int main()
{
	ll n,d,a;
	cin >> n >> d >> a;
	vector<enem> xh(n);
	rep(i,n)
	{
		ll foo,fooo;
		cin >> foo >> fooo;
		xh[i].x=foo;
		xh[i].h=fooo;
	}
	sort(ALL(xh),cmp);
	queue<dp>Q;
	d = d*2;
	ll ans = 0;
	ll nowdamage = 0;
	for(int i=0;i<n;i++)
	{
		

		
		while(!Q.empty()&&Q.front().del<xh[i].x)
		{
			nowdamage -= Q.front().num*a;
			Q.pop();
		}
		xh[i].h-=nowdamage;
		if(xh[i].h>0)
		{
			dp now;
			now.num = (xh[i].h+a-1)/a;
			now.del = xh[i].x+d;
			//cout<<now.num<<a<<endl;
			nowdamage += now.num*a;
			Q.push(now);
			ans += now.num;
		}
		//cout<<xh[i].h<<";"<<nowdamage<<endl;
		
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4992