akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int T[] = new int[N];
		int A[] = new int[N];
		long xt = 1;
		long xa = 1;
		
		for(int i = 0; i < N; i++) {
			T[i] = Integer.parseInt(sc.next());
			A[i] = Integer.parseInt(sc.next());
		}
		
		for(int i = 0; i < N; i++) {
			long kake = Math.max((xt - 1 + T[i])/T[i], (xa - 1 + A[i])/A[i]);
			xt = T[i] * kake;
			xa = A[i] * kake;
		}
		System.out.println(xt + xa);
	}
}


Measured memory_bytes: 23764
n, k = gets.chomp.split.map(&:to_i)
arr = gets.chomp.split.map(&:to_i)
min = 10 ** 10
0.upto(n - k) do |i|
	l = arr[i]
	r = arr[i + k - 1]
	ld = l.abs + (l - r).abs 
	rd = r.abs + (r - l).abs 
	m = [ld, rd].min 
	min = m if min > m 
end
puts min

Measured memory_bytes: 21632
n = int(input())
h = [int(i) for i in input().split()]
h[0] -= 1
flag = [True]
if len(h) == 1:
    print('Yes')
else:
    for i in range(1, n):
        if h[i] > h[i - 1]:
            h[i] -= 1
        elif h[i] < h[i - 1]:
            print('No')
            exit()
    print('Yes')


Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

//---------------------------

int main(){
    int d;
    cin >> d;
    if(d == 25) cout << "Christmas";
    else{
        cout << "Christmas ";
        rep(i, 25-d) cout << "Eve ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
//template by I_Love_Totoro, inspired by chamow
//Doing VC Everyday #SpecialistByMarch
//refer cook_book and AC  of/Ubuntu folder _FunWithCP_ dated:16/03/2020- for POC and more insights respectively
//interactive comments ahead! : for the love of CP <3
//note to self:for the love of everything good, uncomment fastread whenever applicable :) 

/* footnotes/ obs
*	can't simply use ansa, ansb ... (variables instead of nx3 matrix)
		+ since we don't know if we'd chosen b/c in the prev step of ansb (ansb is max a,'c')
*/

/*main idea:
*
*/

/*similar to:
*
*/

/*re-learnt/ got better clarity
*
*/

/*corollary
*
*/

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define repn(i,a,n) for(i=n;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define PI (atan(1)*4)
#define INF (int)1e9

#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//typedef vec vector<ll>
typedef long long ll;
typedef long double ld;
typedef long int li;

using namespace std;

ll lcm(ll val1,ll val2)
{
	if(val1==0||val2==0)
		return 0;
	else
		return (val1*val2)/__gcd(val1,val2);
}

ll pw(ll base,ll p)
{
	if(base==1||p==0)				
		return 1;
	if(p%2==0){
		ll interm=pw(base,p/2);
		return interm*interm;

	}
	else
		return base*pw(base,p-1);

}

int main()
{

	//fastread;
	/*
	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    */
	
	ll n, ansa = 0, ansb = 0, ansc = 0;
	cin>>n;

	vector<vector<ll>>dp(n,vector<ll>(3,0));
	vector<ll>a(n),b(n),c(n);

	for (ll i = 0; i < n; i ++) {
		cin>>a[i]>>b[i]>>c[i];

		/*if (i == 0)
			dp[i][0] = a[i], dp[i][1] = b[i], dp[i][2] = c[i];*/
		if (i == 0)
			ansa += a[i],ansb += b[i],ansc += c[i];//dp[i][0] = a, dp[i][1] = b, dp[i][2] = c;
		else {
			ll preva = ansa, prevb = ansb, prevc = ansc;
			/*dp[i][0]*/ansa = max(prevb,prevc) + a[i];
			ansb = max(preva,prevc) + b[i];
			ansc = max(preva,prevb) + c[i];
		}
	}

	/*for (ll i = 1; i < n; i ++) {
		dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a[i];
		dp[]
	}*/
	cout<<max(ansa,max(ansb,ansc))<<"\n";//max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<"\n";
	return 0;
}

Measured memory_bytes: 8064
#include<iostream>
#include<queue>
#include<vector>


using namespace std;
static const int N = 2*1000;
static const int INFTY = (1 << 21);

int n,M[N][N];
int d[N];
int ans[N] = {0};
vector<int> l[N];

void bfs(int s){
    queue<int> q;
    q.push(s);
    for (int i = 0; i < n; i++)
    {
        d[i] = INFTY;
    }
    d[s] = 0;
    int u;
    while(!q.empty()){
        u = q.front();
        q.pop();
        for (int v : l[u])
        {
            if (d[v] != INFTY)
                continue;
            d[v] = d[u] + 1;
            q.push(v);
        }

    }
    for (int i = 0; i < n; i++)
    {
        if(d[i]!=INFTY){
            ans[d[i]]++;
        }
    }
}

int main(){
    int x, y;
    cin >> n >> x >> y;
    x--;
    y--;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            M[i][j] = 0;
        }
    }

    for (int i = 0; i < n-1; i++)
    {
        l[i].push_back(i + 1);
        l[i + 1].push_back(i);
    }
    l[x].push_back(y);
    l[y].push_back(x);

    for (int i = 0; i < n; i++)
    {
        bfs(i);
    }

    for (int i = 1; i < n; i++)
    {
        cout << ans[i]/2 << endl;
    }

    return 0;
}

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

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

    if (s.size() == 2) {
        return cout << (s[0] == s[1] ? "1 2" : "-1 -1") << endl, 0;
    }

    for (int i = 0; i < s.size() - 2; i++) {
        string t = s.substr(i, 3);
        if (t[0] == t[1] || t[1] == t[2] || t[2] == t[0])
            return cout << i + 1 << " " << i + 3 << endl, 0;
    }
    cout << "-1 -1" << endl;
        

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#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 all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif

using namespace std;
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
const ll mod = 1000000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
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;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 1e6 + 10; 

int vis[maxn];

int main()
{
	fastIO;
	
	int k; cin >> k;
	int r = 0,len = 1;
	while(1) 
	{
		r = r * 10 + 7;
		r %= k;
		if(vis[r]) {
			cout << -1 << endl;
			break;
		}
		vis[r]++;
		if(!r) {
			cout << len << endl;
			break;
		}
		len++;
	}

	return 0;
}

Measured memory_bytes: 7472
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    int x, a; cin >> x >> a;
    cout << (x<a ? 0:10) <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main() 
{
int x,y,z;
cin>>x>>y>>z;
if(x%y==0)
{
cout<<(x/y)*z;

}
else
cout<<((x/y)+1)*z;
}

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

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

    int64_t sum = 0;

    for (int i = 0; i <= n; i++){
        if (i % 3 == 0 || i % 5 == 0){

        }
        else{
            sum += i;
        }
    }

    cout << sum << endl;
}


Measured memory_bytes: 3624
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, s: str, t: str):
    
    ans = 0
    for i in range(N):
        m = 0
        for j in range(N):
            if i+j < N and s[i+j] == t[j]:
                m += 1
            else:
                break
        ans = max(ans, m)

    print(2*N-ans)   

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = next(tokens)  # type: str
    t = next(tokens)  # type: str
    solve(N, s, t)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
str = gets.chomp.split('')

str2 = []
str.each do |n|
  if n == '0'
    str2 << n
  elsif n == '1'
    str2 << '1'
  elsif n == 'B'
    if str2.any?
      str2.slice!(str2.length - 1)
    end
  end
end

puts str2.join('')


Measured memory_bytes: 3836
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P>PP;

signed main() {
	int n, k; cin >> n >> k;
	int ans = 0;
	rep(i, n) {
		int x; cin >> x; ans += 2 * min(x, k - x);
	}
	cout << ans << endl;
}


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

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

  int range = (int)sqrt(N);
  int ans = 100;
  for(int i = 1;i <= range;i++) {
    long long B;
    if(N % i == 0) {
      B = N / i;
    }else {
      continue;
    }

    int numb = 0;
    while(B > 0) {
      B /= 10;
      numb++;
    }

    ans = min(ans,numb);
  }

  cout << ans << endl;


}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        long N = scanner.nextLong();
        long A = scanner.nextLong();
        long B = scanner.nextLong();

        long times = N/(A+B);
        long ans = A * times;
        ans += Math.min(A, N%(A+B));
        System.out.println(ans);
    }
}


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

int main(){
  int N;
  cin >> N;
  int S=0;
  int temp=N;
  while(temp!=0){
    S+=temp%10;
    temp=temp/10;
  }
  if(N%S==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n; cin >> n;
  vi a(n);
  REP(i, n) {
    cin >> a[i];
  }

  int ans = 0;
  REP(i, n-1) {
    if(a[i] == i+1) {
      ans++;
      int tmp = a[i];
      a[i] = a[i+1];
      a[i+1] = tmp;
    }
  }

  if(a[n-1] == n) ans++;

  cout << ans << endl;
}


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

#define FOR( i, m, n )   for( int i = m; i < n; i++ )
#define REP( i, n )      FOR( i, 0, n )
#define ALL( a )         (a).begin(), (a).end()

int main(){
  long long n, m, sum = 0, tmp = 0; cin >> n >> m;
  vector<int> a( n ), b( m );
  REP( i, n ){
    cin >> a[i];
    tmp += a[i];
  }
  
  REP( i, m ){
    cin >> b[i];
    sum += b[i] * tmp;
  }

  cout << sum << endl;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;

int main(){
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    vector<int> a(11);
    int r , d;
    cin >> r >> d >> a[0];


    for(int i = 1 ; i <= 10 ; ++i){
        a[i] = r * a[i - 1] - d;
    }


    for(int i = 1 ; i <= 10 ; ++i)
        cout << a[i] << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), q = sc.nextInt();
		String s = sc.next();
		int[] AC = new int[s.length()];
		AC[0] = 0;
		for(int i = 1;i < s.length();i ++) {
			AC[i] = AC[i-1];
			char c1 = s.charAt(i-1),c2 = s.charAt(i);
			if(c1 == 'A' && c2 == 'C') {
				AC[i] ++;
			}
		}
		//System.out.println(Arrays.toString(AC));
		for(int i = 0;i < q;i ++) {
			int L = sc.nextInt();
			int R = sc.nextInt();
			int ans = AC[R-1] - AC[L-1];
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 67256
#include <bits/stdc++.h>
 
using namespace std;
#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

int n, m, sum; 
int a[1000];

void solve() {
  int cnt = 0;
  string r;
  REP(i, n) if (a[i]*4*m >= sum) cnt++;
  if (cnt >= m) r = "Yes";
  else r = "No";
  cout << r;
}

void input() {
  cin >> n >> m;
  REP(i, n) {
    cin >> a[i];
    sum += a[i];
  }
}
 
int main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

a,b=map(int,input().split())
a=make_divisors(a)
b=make_divisors(b)
a=set(a)
b=set(b)
s=sorted(a&b)
ans=[1]
for i in s[1:]:
    switch=0
    for j in ans[1:]:
        if i%j==0:
            switch=1
            break
    if switch==0:
        ans.append(i)
print(len(ans))

Measured memory_bytes: 70884
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;


int main(){

int n,m;
cin >> n >> m;

int a[n],b[n];
rep(i,n) cin >> a[i] >> b[i];

int c[m],d[m];
rep(i,m) cin >> c[i] >> d[i];

int dis;
    
rep(i,n){
int minl = INF;
int count=1;
    rep(j,m){
        dis=abs(a[i]-c[j])+abs(b[i]-d[j]);
        if(dis<minl){
            minl = dis;
            count = j+1;
        }
        
    }
    cout << count << endl;
}




return 0;

}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#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=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define NP next_permutation
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;

const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;

template<class T> bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T> void decimal(T a){cout<<fixed<<setprecision(a);}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

void YesNo(bool a){if(a) out("Yes"); else out("No");}
void yesno(bool a){if(a) out("yes"); else out("no");}
void YESNO(bool a){if(a) out("YES"); else out("NO");}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){ll c=1; while(b>0){if(b&1){c=a*c %mod;}a=a*a %mod;b>>=1;}return c;}
vi calc(ll x){vi res; while(x>0){res.pb(x%10);x/=10;}reverse(all(res)); return res;}

void solve() {
  ll n,a,b;
  cin>>n>>a>>b;
  if((b-a)%2==0) out((b-a)/2);
  else out(min(a,n-b+1)+(b-a-1)/2);
}

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


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

#define ii pair<int, int>
#define lli long long int
#define ll pair<lli, lli>
#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

int main() {
	int len, ans = 0;
	char s[105];
	scanf("%s", s);
	len = strlen(s);
	for (int i = 0; i < (len / 2); i++)
		if (s[i] != s[len - i - 1])
			ans++;
	printf("%d\n", ans);
	return 0;
}

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

p_min = min(data)
p_max = max(data)

ans_min = 100000000000000

for i in range(p_min, p_max+2):
  ans = 0

  for d in data:
    ans += (i-d)**2

  if ans < ans_min:
    ans_min = ans

print(ans_min)


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atc_0030
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();

            for (int i = 0; i < S.Length; i++)
            {
                var t = S.Substring(i, 1);

                if ((i + 1) % 2 == 1)
                {
                    if (t != "R" && t != "U" && t != "D")
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }
                else
                {
                    if (t != "L" && t != "U" && t != "D")
                    {
                        Console.WriteLine("No");
                        return;
                    }

                }   
            }

            Console.WriteLine("Yes");

        }
    }
}


Measured memory_bytes: 25848
#include <bits/stdc++.h>
using namespace std;
int  main(){
 int k,a,b;
  cin>>k>>a>>b;
  for(int i=a;i<=b;i++){
    if(i%k==0){
      cout<<"OK"<<endl;
      return 0;
    }
  }
    cout<<"NG"<<endl;
    return 0;
  

}


Measured memory_bytes: 3596
#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() {
  ll x,money = 100;
  cin >> x;
  if(x <= 100){
    cout << 0 << endl;
    return 0;
  }
  rep(i,3761){
    ll plus = money/100;
    money += plus;
    if(money >= x){
      cout << i+1 << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3620
# encoding: "utf-8"

from collections import defaultdict
from functools import reduce
from itertools import groupby

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]


def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    # print(xs)
    ys = concat_map(xs, lambda x: [x, x+1, x-1])
    ys.sort()
    print(max(map(lambda x: count(x[1]), groupby(ys))))

def concat_map(xs, f):
    return reduce(lambda accum, x: extended(accum, x), map(f, xs))

def extended(xss, xs):
    xss.extend(xs)
    return xss

def count(iterator):
    cnt = 0
    for _ in iterator:
        cnt += 1
    return cnt

if __name__ == "__main__":
    main()

Measured memory_bytes: 18264
#include <string>
#include <iostream>
#include <ctype.h>

using namespace std;

int main(void)
{
	string s;

	cin >> s;

	if(s.length() != 1)
	{
		return 0;
	}

	if ((s >= "a" && s <= "z") || (s >= "A" && s <= "Z"))
	{
		if (s >= "A" && s <= "Z")
		{
			cout << "A" << endl;
		}
		else
		{
			cout << "a" << endl;
		}

	}

	return 0;
}

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

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

    if(k <= a){
        cout << k << endl;
    }
    else if(k <= a+b){
        cout << a << endl;
    }
    else if(k <= a+b+c){
        cout << 2*a+b-k << endl;
    }
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

int main() {
	int A, B, C, D;
	scanf("%d %d %d %d", &A, &B, &C, &D);
	if (A + B > C + D) printf("Left\n");
	else if (A + B < C + D) printf("Right\n");
	else printf("Balanced\n");
	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;
using ll = long long;

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

int gcds(vector<int> as) {
  int ans = as[0];
  for (int i = 1; i < as.size(); i++) {
    ans = gcd(ans, as[i]);
  }
  return ans;
}

int main() {
  int n;
  cin >> n;
  vector<int> as(n);
  rep(i, n) { cin >> as[i]; }
  cout << gcds(as) << endl;
  return 0;
}


Measured memory_bytes: 4048
#include <stdio.h>
int main(void)
{
  long N,K,sa;
  
  scanf("%ld %ld",&N,&K);
  
  sa=N%K;
  
  if(K-sa>sa)
    printf("%ld\n",sa);
  else
    printf("%ld\n",K-sa);
  
 return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
int main(){
	int f[2],a,b,k,large;
	for(int i=0;i<=2;i++)
	cin>>f[i];
	large=max(f[1],f[2]);
	b=max(large,f[0]);
	cin>>k;
	a=b*pow(2,k)+f[0]+f[1]+f[2]-b;
	cout<<a<<endl;
	return 0;
	 
} 

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
using namespace std;

int main(){
  int N; cin >> N;
  if(N%10==9||N/10==9) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
N,M,S=map(int,input().split())
from heapq import heappop,heappush 

inf = float('inf')
cost=[[] for _ in range(N)]
exc=[]


for _ in range(M):
    u,v,a,b=map(int,input().split())
    u,v=u-1,v-1
    cost[u].append((v,a,b))
    cost[v].append((u,a,b))
for _ in range(N):
    c,d=map(int,input().split())
    exc.append((c,d))

di=[inf]*2451*N
if S>2450:
    S=2450
di[S]=0
hq=[(0,S)] #時間,都市名*2451+銀貨

while hq:
    t,v=heappop(hq)
    if t>di[v]:
        continue
    u=v//2451 #都市名
    s=v%2451 #所持金

    for x,a,b in cost[u]:
        if s>=a:
            v_new=x*2451+s-a
            t_new=t+b
            if t_new<di[v_new]:
                di[v_new]=t_new
                heappush(hq,(t_new,v_new))
    
    c,d=exc[u]
    if s+c>2450:
        c=2450-s
    v_new=v+c
    t_new=t+d
    if t_new<di[v_new]:
        di[v_new]=t_new
        heappush(hq,(t_new,v_new))

for i in range(1,N):
    m=di[i*2451]
    for j in range(1,2451):
        m=min(m,di[i*2451+j])
    print(m)

Measured memory_bytes: 86544
n = gets.to_i
A = gets.split(" ").map(&:to_i)
money = 1000
kabu = 0

# i
# A[i] < A[i + 1] => 売却なし　購入
# A[i] > A[i + 1] => 売却　購入なし

(n - 1).times do |i|
  #購入
  if (A[i] < A[i + 1])
    c = money / A[i]
    kabu += c
    money -= c * A[i]
    #売却
  elsif (A[i] > A[i + 1])
    money += kabu * A[i]
    kabu = 0
  end
end

money += kabu * A[n - 1]
print money


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

int main(){
  int n,m;
  cin>>n>>m;
  if(n>=m){
    cout<<0<<endl;
    return 0;
  }
  int vec[m];
  for(int i=0;i<m;i++){
    cin>>vec[i];
  }
  sort(vec,vec+m);
  int vecb[m-1];
  for(int i=0;i<m-1;i++){
    vecb[i]=vec[i+1]-vec[i];
  }
  sort(vecb,vecb+m-1);
  reverse(vecb,vecb+m-1);
  int ans=vec[m-1]-vec[0];
  for(int i=0;i<n-1;i++){
    ans-=vecb[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
//debug
#ifdef grief
#define debug(...) do{\
	fprintf(stderr , "%s - %d : (%s) = " , __PRETTY_FUNCTION__ , __LINE__ , #__VA_ARGS__ );\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){
	cerr<<x<<endl;
}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){
	cerr<<x<<" , ";
	_DO(tail...);
}
#else
#define debug(...)
#endif
//type
typedef long long ll;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef priority_queue<pll,vector<pll>,greater<pll> > heap;
//macro
#define SZ(x) ((ll)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REP1(i,a,b) for(ll i=(a);i<=(b);i++)
#define mkp make_pair
#define pb push_back
const ll INF=1e18;
const ll MA=1e5+5;
const ll MOD=1e9+7;
//}}}
ll n;
ll A[MA],B[MA];
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>A[i]>>B[i];
	ll now=0;
	for(int i=n;i>0;i--){
		ll x=(B[i]-(A[i]+now)%B[i])%B[i];
		now+=x;
		//cout<<now<< '\n';
	}
	cout<<now<< '\n';
	return 0;
}


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

int main(void){
   int n,m;
   cin >> n >> m;
   vector<vector<int> > s(m,vector<int>(n));
   vector<int> k(m),p(m);
   for(int i=0;i<m;i++){
       cin>>k[i];
       for(int j=0;j<k[i];j++){
           cin >> s[i][j];
       }
   }
   for(int i=0;i<m;i++) cin >> p[i];

   int count = 0;
   for (int bit = 0; bit < (1<<n); ++bit) {
       bool is_enable = true;
       for(int i=0;i<m;i++){
        int sum = 0;
            for (int j = 0; j < k[i];j++) {
                if (bit & (1 << s[i][j]-1)) sum++;
            }
        if(sum % 2 != p[i])is_enable = false;
       }
       if(is_enable)count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
using namespace std;
typedef long long ll;

// ??
int main(){
    ll w, h, x, y;
    cin >> w >> h >> x >> y;
    double s = w*h/2.0;
    cout << fixed << setprecision(12) << s << " ";
    int cnt = 0;
    cnt +=  (w%2 == 0 && w/2 == x);
    cnt +=  (h%2 == 0 && h/2 == y);
    if(cnt <= 1 || x == 0 || x == w || y == 0 || y == h)    cout << 0 << endl;
    else                                        cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end()) 
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);


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

  int a, b;
  cin >> a >> b;
  if (b % a == 0) cout << a + b;
  else cout << b - a;
  cout << endl;

  return 0;
}


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

using namespace std;
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    // This is checked so that we can skip  
    // middle five numbers in below loop 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true;
} 

int main(){
    int n;
    cin >> n;
    while(true){
        if(isPrime(n)){
            cout << n << endl;
            break;
        }
        else n++;
    }

}

Measured memory_bytes: 256
#include <iostream>
    using namespace std;
     
    int main() {
	int h,w;
	while(1){
		cin>> h >> w;
		if(h == 0 && w == 0){
			break;
		}
		for (int i=0; i<w ; i++){
			cout<< "#";
		};
		cout << endl;
		for (int j=0; j<h-2 ; j++){
			cout<<"#";
			for (int i=0; i<w-2 ; i++){
			cout<< ".";
		};
		cout << "#"<<endl;
		};
    for (int i=0; i<w ; i++){
			cout<< "#";
	};
	cout << endl;
	 cout <<endl;
	}
   
    return 0;
    }

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

int calc(int a, int b, int x){
  return a*(100+x)/100 + b*(100+x)/100;
}

int main(){
  int x, y, s;
  while(cin >> x >> y >> s){
    if(x+y+s == 0) break;
    int ans = 0;
    for(int i = 1 ; i <= s ; i++){
      for(int j = 1 ; j+i <= s ; j++){
	if(calc(i, j, x) == s) ans = max(ans, calc(i, j, y));
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
    ios_base::sync_with_stdio(false);
    int n,a,b;
    cin >> n >> a >> b;
    if(a*n<b){cout << a*n << endl;}
    else cout << b << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static long[] fac = new long[1000003];
    static long[] finv = new long[1000003];
    static long[] inv = new long[1000003];
    static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        sc.close();
        //前処理
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < 1000003; i++) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }

        if ((x + y) % 3 != 0) {
            System.out.println(0);
            return;
        }

        int n = (x + y) / 3;

        for (int i = 0 ; i <= n ; i++) {
            if (i + 2 * (n - i) == x && i * 2 + n - i == y) {
                System.out.println(comb(n, i));
                return;
            }
        }
        System.out.println(0);

    }

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

}

Measured memory_bytes: 48212
process.stdin.resume();
process.stdin.setEncoding('utf-8');
 
let inputString = '';
let currentLine = 0;
 
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
 
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    
    main();    
});
 
function readLine() {
    return inputString[currentLine++];
}

function main() {
  let k = Number(readLine())
  if (k % 2 === 0 || k % 5 === 0) {
    return console.log(-1)
  }
  if (k % 7 === 0) {
    k /= 7
  }
  k *= 9
  let mod = 1
  let i = 1
  while (true) {
    mod = (mod * 10) % k
    if (mod === 1) {
      return console.log(i)
    }
    i++
  }
}


Measured memory_bytes: 32472
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

ll n;

void dfs(ll i, ll cnt, const string& s) {
  rep(j, cnt) {
    char c = (char)('a'+j);
    if (i != n) dfs(i+1, cnt + (j == cnt-1) , s+c);
    else cout << s << c << endl;
  }
}

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

  cin >> n;
  dfs(1, 1, "");
}


Measured memory_bytes: 1536
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;
const int Maxn=1000;
const int Inf=0x3f3f3f3f;
const int d[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int n,m;
int s_x,s_y,t_x,t_y;
char s[Maxn+5][Maxn+5];
int dis[Maxn+5][Maxn+5];
bool vis[Maxn+5][Maxn+5];
deque<int> q_x,q_y;
void bfs(){
	memset(dis,0x3f,sizeof dis);
	dis[s_x][s_y]=0;
	q_x.push_back(s_x);
	q_y.push_back(s_y);
	while(!q_x.empty()){
		int u_x=q_x.front(),u_y=q_y.front();
		q_x.pop_front();
		q_y.pop_front();
		if(vis[u_x][u_y]){
			continue;
		}
		vis[u_x][u_y]=1;
		for(int i=0;i<4;i++){
			int v_x=u_x+d[i][0],v_y=u_y+d[i][1];
			if(v_x<1||v_y<1||v_x>n||v_y>m||s[v_x][v_y]=='#'){
				continue;
			}
			if(dis[u_x][u_y]<dis[v_x][v_y]){
				dis[v_x][v_y]=dis[u_x][u_y];
				q_x.push_front(v_x);
				q_y.push_front(v_y);
			}
		}
		for(int i=-2;i<=2;i++){
			for(int j=-2;j<=2;j++){
				int v_x=u_x+i,v_y=u_y+j;
				if(v_x<1||v_y<1||v_x>n||v_y>m||s[v_x][v_y]=='#'){
					continue;
				}
				if(dis[u_x][u_y]+1<dis[v_x][v_y]){
					dis[v_x][v_y]=dis[u_x][u_y]+1;
					q_x.push_back(v_x);
					q_y.push_back(v_y);
				}
			}
		}
	}
}
int main(){
	scanf("%d%d",&n,&m);
	scanf("%d%d%d%d",&s_x,&s_y,&t_x,&t_y);
	for(int i=1;i<=n;i++){
		scanf("%s",s[i]+1);
	}
	bfs();
	if(dis[t_x][t_y]==Inf){
		puts("-1");
	}
	else{
		printf("%d\n",dis[t_x][t_y]);
	}
	return 0;
}


Measured memory_bytes: 9152
#include <bits/stdc++.h>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define msg(x) debug() << x
#define int long long
const int xx = 2e5;
const int mod = 1e9 + 7;
double distance(int a , int b , int x , int y){
  int xx = a - x;
  int yy = b - y;
  double v = (double)sqrt(xx*xx + yy*yy);
  return v;
}
signed main(){
 // ios::sync_with_stdio(false);cin.tie(0);

  int n;
  cin >> n;
  vector<int>v;
  for(int i=0;i<n;i++){
    v.push_back(i);
  }
  vector<pair<int,int>>vp;
  for(int i=0;i<n;i++){
    int x, y;
    cin >> x >> y;
    vp.emplace_back(x,y);
  }
  int cnt = 0;
  double av = 0.0;
  do{
    for(int i=0;i<n-1;i++){
      av += distance(vp[v[i]].first , vp[v[i]].second , vp[v[i+1]].first , vp[v[i+1]].second);
    }
    cnt++;
  }
  while(next_permutation(v.begin() , v.end()));
  dg1(cnt);

  av = av / (double)cnt;

  printf("%0.10lf\n",av);

}


Measured memory_bytes: 256
import java.util.*;

class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int[] d = new int[n];
	int cout = 1;
	for(int i = 0; i < n; i++) {
		d[i] = sc.nextInt();
	}
	Arrays.sort(d);
	for(int i = 1; i < n; i++) {
		if(d[i] > d[i - 1]) {
			cout++;
		}
	}
	System.out.println(cout);
}
}


Measured memory_bytes: 21844
use std::io::{self, Read};
use std::str::FromStr;
pub struct Scanner<R: Read> {
    reader: R,
}
impl<R: Read> Scanner<R> {
    pub fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }
    pub fn read<T: FromStr>(&mut self) -> T {
        let s = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.expect("failed to read char") as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        s.parse::<T>().ok().expect("failed to parse token")
    }
}

use std::collections::VecDeque;

// 幅優先探索によるトポロジカルソート
fn toploogical_sort(v_num: usize, edges: &Vec<(usize, usize)>) -> Vec<usize> {
    let mut result = Vec::with_capacity(v_num);
    let mut in_num = vec![0; v_num];    // 頂点に対する入力辺の数を表す

    // 入力辺の数を数える
    for &(_,t) in edges.iter() {
        in_num[t] += 1;
    }

    // 入力数0の頂点をQueueに
    let mut que = VecDeque::new();
    for i in 0..v_num {
        if in_num[i] == 0 {
            que.push_back(i);
        }
    }

    // 幅優先探索で入力数0のものから順にresultに追加
    while let Some(v) = que.pop_front() {
        result.push(v);
        // 頂点vから繋がる頂点の入力数を1減らす
        for &(s,t) in edges.iter() {
            if s == v {
                in_num[t] -= 1;
                // 減らした際に入力数が0となったら、Queueに追加する
                if in_num[t] == 0 {
                    que.push_back(t);
                }
            }
        }
    }
    result
}


fn main() {
    let sin = io::stdin();
    let sin = sin.lock();
    let mut sc = Scanner::new(sin);

    let v: usize = sc.read();
    let e: usize = sc.read();
    let edges: Vec<(usize, usize)> = (0..e)
        .map(|_| {
            (sc.read::<usize>(), sc.read::<usize>())
        }).collect();

    let results = toploogical_sort(v, &edges);
    
    for v in results {
        println!("{}", v);
    }
}



Measured memory_bytes: 5052
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

template<int Modulo = MOD> struct Mint {
	lint val;
	constexpr Mint(lint v = 0) noexcept : val(v % Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		lint a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			lint t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint operator + (const Mint& r) const noexcept { return *this += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return *this -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return *this *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return *this /= r; }
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream &operator << (ostream &os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream &is, Mint<Modulo>& x) noexcept {
		lint tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo> &a, lint n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string S;
	cin >> S;

	vector<vector<mint>> dp(S.size() + 1, vector<mint>(4));
	dp[0][0] = 1;
	for (int i = 0; i < S.size(); i++) {
		for (int j = 0; j <= 3; j++) {
			for (int k = 0; k <= 2; k++) {
				if (!(S[i] != '?' && S[i] != 'A' + k)) {

					dp[i + 1][j] += dp[i][j];

					if (j == k) {
						dp[i + 1][j + 1] += dp[i][j];
					}

				}
			}
		}
	}

	cout << dp[S.size()][3] << "\n";

	return 0;
}


Measured memory_bytes: 7376
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

vector<pll> dp(100);

ll dfs(ll n,ll x){
    if(x==0){return 0;}
    if(dp[n].F<=x){return dp[n].S;}
    x--;
    ll ans=0;
    ans+=dfs(n-1,x);
    x-=dp[n-1].F;
    if(x>0){
        ans++; x--;
        if(x>0){ans+=dfs(n-1,x);}
    }
    return ans;
}



int main(){
    dp[0]={1,1};
    for(int i=1;i<100;i++){
        dp[i]=dp[i-1];
        dp[i].F*=2; dp[i].S*=2;
        dp[i].F+=3; dp[i].S+=1;
    }
    ll n,x;
    cin>>n>>x;
    cout<<dfs(n,x)<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn.readLine

object Main extends App {
  val s = readLine()
  val t = readLine()
  
  def rotate(str: String): String = {
    str.last + str.init
  }
  
  def verify(in: String): String = {
    if (in == t)
      "Yes"
    else
      if (in == s)
        "No"
      else
        verify(rotate(in))
  }
  
  val result = if (s == t)
    "Yes"
  else
    verify(rotate(s))
  
  println(result)
}

Measured memory_bytes: 54540
#include <stdio.h>
#include <math.h>
int main() {
  int n;
  scanf ("%d\n", &n);
  double sum_len = 0;
  int i, j;
  double ans;

  double x[n], y[n];

  for (i = 0; i < n; i++) {
    if (i == n - 1) scanf ("%lf %lf", &x[i], &y[i]);
    else scanf ("%lf %lf\n", &x[i], &y[i]);
  }

  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      sum_len += sqrt (pow (x[i] - x[j], 2) + pow (y[i] - y[j], 2));
    }
  }

  sum_len = sum_len / 2;

  ans = sum_len * 2 / n;

  printf ("%.10lf\n", ans);

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <cstdio>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POSSIBLE(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Possible(i) cout<<(i?"Possible":"Impossible")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=998244353;
//
struct poi{
	int X;int Y;int Z;
	bool operator<(const poi&R)const{
		return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
	}
};
//
ll GCD(ll A,ll B){
  return (B==0)?(A):(GCD(B,A%B));
}
ll LCM(ll A,ll B){
  return A/GCD(A,B)*B;
}
//
//
struct edge{int to;ll cost;};
vector<edge> G[100000];
struct dijkstra{
	//
	int v;
	vector<ll> D;
	vector<int> sub;
	priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> que;
	//
	dijkstra(int n){
		D.resize(n);
		sub.resize(n);
	}
	//
	void add_edge(int from,int to,ll cost){
		G[from].push_back((edge){to,cost});
	}
	//
	vector<ll> dist(int s){
		fill(D.begin(),D.end(),1e15+7);
		fill(sub.begin(),sub.end(),-1);
		D[s]=0LL;
		que.push(make_pair(0,s));
		while(!que.empty()){
			pair<ll,int> p=que.top();que.pop();
			int vv=p.second;
			if(D[vv]<p.first){
				continue;
			}else{
				for(int i=0;i<G[vv].size();i++){
					edge &e=G[vv][i];
					if(D[e.to]>D[vv]+e.cost){
						D[e.to]=D[vv]+e.cost;
						que.push(make_pair(D[e.to],e.to));
						sub[e.to]=vv;
					}
				}
			}
		}
		return D;
	}
	//
	vector<int> getpath(int t){
		vector<int> path;
		for(;t!=-1;t=sub[t]){
			path.push_back(t);
		}
		reverse(path.begin(),path.end());
		return path;
	}
	//
};
//
int main(){
	int N,M,S,T;
	cin>>N>>M>>S>>T;
	S--;T--;
	dijkstra a(N);
	pair<int,int> P[100000];
	int tt[100000];
	FOR(i,0,M){
		int u,v,s,t;
		cin>>u>>v>>s>>t;
		u--;v--;
		a.add_edge(u,v,s);
		a.add_edge(v,u,s);
		P[i]=MA(u,v);
		tt[i]=t;
	}
	vector<ll> ad=a.dist(S);
	vector<int> ap=a.getpath(T);
	FOR(i,0,N){
		G[i].clear();
	}
	dijkstra b(N);
	FOR(i,0,M){
		b.add_edge(P[i].FI,P[i].SE,tt[i]);
		b.add_edge(P[i].SE,P[i].FI,tt[i]);
	}
	vector<ll> bd=b.dist(T);
	vector<ll> re;
	ll ans=0;
	ROF(i,0,N){
		ans=max(ans,(ll)1e15-ad[i]-bd[i]);
		re.PB(ans);
	}
	reverse(re.begin(),re.end());
	FOR(i,0,N){
		cout<<re[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 16244
#include<iostream>
#include<deque>
#include<algorithm>
using namespace std;

int main()
{
  int n;
  while(cin >> n,n)
    {
      deque<long long> p,j;
      p.resize(n),j.resize(n-1);     
      long long sum = 0;
      for(int i=0;i<n;i++)
	cin >> p[i],sum += p[i];
      for(int i=0;i<n-1;i++)
	cin >> j[i];
      sort(j.begin(),j.end(),greater<long long>());
      long long mex = n*sum;
      while(!j.empty())
	{
	  --n;
	  long long renew = 0;
	  sum -= p.front(), renew += p.front(); p.pop_front();
	  sum -= p.front(), renew += p.front(); p.pop_front();
	  renew += j.front(); j.pop_front();
	  sum += renew;
	  p.push_front(renew);
	  if(mex <= n*sum)
	    mex = max(mex,n*sum);
	  else 
	    break;
	}
      cout << mex << endl;
    }
  return 0;
}

Measured memory_bytes: 2292